re PR testsuite/61415 (PowerPC test gcc.target/powerpc/tfmode_off.c fails if -mlong...
[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 ;; Suffix for reload patterns
442 (define_mode_attr ptrsize [(SI "32bit")
443                            (DI "64bit")])
444
445 (define_mode_attr tptrsize [(SI "TARGET_32BIT")
446                             (DI "TARGET_64BIT")])
447
448 (define_mode_attr mptrsize [(SI "si")
449                             (DI "di")])
450
451 (define_mode_attr ptrload [(SI "lwz")
452                            (DI "ld")])
453
454 (define_mode_attr ptrm [(SI "m")
455                         (DI "Y")])
456
457 (define_mode_attr rreg [(SF   "f")
458                         (DF   "ws")
459                         (TF   "f")
460                         (TD   "f")
461                         (V4SF "wf")
462                         (V2DF "wd")])
463
464 (define_mode_attr rreg2 [(SF   "f")
465                          (DF   "d")])
466
467 (define_mode_attr SI_CONVERT_FP [(SF "TARGET_FCFIDS")
468                                  (DF "TARGET_FCFID")])
469
470 (define_mode_attr E500_CONVERT [(SF "!TARGET_FPRS")
471                                 (DF "TARGET_E500_DOUBLE")])
472
473 (define_mode_attr TARGET_FLOAT [(SF "TARGET_SINGLE_FLOAT")
474                                 (DF "TARGET_DOUBLE_FLOAT")])
475
476 ;; Mode iterator for logical operations on 128-bit types
477 (define_mode_iterator BOOL_128          [TI
478                                          PTI
479                                          (V16QI "TARGET_ALTIVEC")
480                                          (V8HI  "TARGET_ALTIVEC")
481                                          (V4SI  "TARGET_ALTIVEC")
482                                          (V4SF  "TARGET_ALTIVEC")
483                                          (V2DI  "TARGET_ALTIVEC")
484                                          (V2DF  "TARGET_ALTIVEC")
485                                          (V1TI  "TARGET_ALTIVEC")])
486
487 ;; For the GPRs we use 3 constraints for register outputs, two that are the
488 ;; same as the output register, and a third where the output register is an
489 ;; early clobber, so we don't have to deal with register overlaps.  For the
490 ;; vector types, we prefer to use the vector registers.  For TI mode, allow
491 ;; either.
492
493 ;; Mode attribute for boolean operation register constraints for output
494 (define_mode_attr BOOL_REGS_OUTPUT      [(TI    "&r,r,r,wa,v")
495                                          (PTI   "&r,r,r")
496                                          (V16QI "wa,v,&?r,?r,?r")
497                                          (V8HI  "wa,v,&?r,?r,?r")
498                                          (V4SI  "wa,v,&?r,?r,?r")
499                                          (V4SF  "wa,v,&?r,?r,?r")
500                                          (V2DI  "wa,v,&?r,?r,?r")
501                                          (V2DF  "wa,v,&?r,?r,?r")
502                                          (V1TI  "wa,v,&?r,?r,?r")])
503
504 ;; Mode attribute for boolean operation register constraints for operand1
505 (define_mode_attr BOOL_REGS_OP1         [(TI    "r,0,r,wa,v")
506                                          (PTI   "r,0,r")
507                                          (V16QI "wa,v,r,0,r")
508                                          (V8HI  "wa,v,r,0,r")
509                                          (V4SI  "wa,v,r,0,r")
510                                          (V4SF  "wa,v,r,0,r")
511                                          (V2DI  "wa,v,r,0,r")
512                                          (V2DF  "wa,v,r,0,r")
513                                          (V1TI  "wa,v,r,0,r")])
514
515 ;; Mode attribute for boolean operation register constraints for operand2
516 (define_mode_attr BOOL_REGS_OP2         [(TI    "r,r,0,wa,v")
517                                          (PTI   "r,r,0")
518                                          (V16QI "wa,v,r,r,0")
519                                          (V8HI  "wa,v,r,r,0")
520                                          (V4SI  "wa,v,r,r,0")
521                                          (V4SF  "wa,v,r,r,0")
522                                          (V2DI  "wa,v,r,r,0")
523                                          (V2DF  "wa,v,r,r,0")
524                                          (V1TI  "wa,v,r,r,0")])
525
526 ;; Mode attribute for boolean operation register constraints for operand1
527 ;; for one_cmpl.  To simplify things, we repeat the constraint where 0
528 ;; is used for operand1 or operand2
529 (define_mode_attr BOOL_REGS_UNARY       [(TI    "r,0,0,wa,v")
530                                          (PTI   "r,0,0")
531                                          (V16QI "wa,v,r,0,0")
532                                          (V8HI  "wa,v,r,0,0")
533                                          (V4SI  "wa,v,r,0,0")
534                                          (V4SF  "wa,v,r,0,0")
535                                          (V2DI  "wa,v,r,0,0")
536                                          (V2DF  "wa,v,r,0,0")
537                                          (V1TI  "wa,v,r,0,0")])
538
539 ;; Mode attribute for the clobber of CC0 for AND expansion.
540 ;; For the 128-bit types, we never do AND immediate, but we need to
541 ;; get the correct number of X's for the number of operands.
542 (define_mode_attr BOOL_REGS_AND_CR0     [(TI    "X,X,X,X,X")
543                                          (PTI   "X,X,X")
544                                          (V16QI "X,X,X,X,X")
545                                          (V8HI  "X,X,X,X,X")
546                                          (V4SI  "X,X,X,X,X")
547                                          (V4SF  "X,X,X,X,X")
548                                          (V2DI  "X,X,X,X,X")
549                                          (V2DF  "X,X,X,X,X")
550                                          (V1TI  "X,X,X,X,X")])
551 \f
552 ;; Start with fixed-point load and store insns.  Here we put only the more
553 ;; complex forms.  Basic data transfer is done later.
554
555 (define_expand "zero_extend<mode>di2"
556   [(set (match_operand:DI 0 "gpc_reg_operand" "")
557         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
558   "TARGET_POWERPC64"
559   "")
560
561 (define_insn "*zero_extend<mode>di2_internal1"
562   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
563         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
564   "TARGET_POWERPC64 && (<MODE>mode != SImode || !TARGET_LFIWZX)"
565   "@
566    l<wd>z%U1%X1 %0,%1
567    rldicl %0,%1,0,<dbits>"
568   [(set_attr "type" "load,shift")])
569
570 (define_insn "*zero_extend<mode>di2_internal2"
571   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
572         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
573                     (const_int 0)))
574    (clobber (match_scratch:DI 2 "=r,r"))]
575   "TARGET_64BIT"
576   "@
577    rldicl. %2,%1,0,<dbits>
578    #"
579   [(set_attr "type" "shift")
580    (set_attr "dot" "yes")
581    (set_attr "length" "4,8")])
582
583 (define_split
584   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
585         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
586                     (const_int 0)))
587    (clobber (match_scratch:DI 2 ""))]
588   "TARGET_POWERPC64 && reload_completed"
589   [(set (match_dup 2)
590         (zero_extend:DI (match_dup 1)))
591    (set (match_dup 0)
592         (compare:CC (match_dup 2)
593                     (const_int 0)))]
594   "")
595
596 (define_insn "*zero_extend<mode>di2_internal3"
597   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
598         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
599                     (const_int 0)))
600    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
601         (zero_extend:DI (match_dup 1)))]
602   "TARGET_64BIT"
603   "@
604    rldicl. %0,%1,0,<dbits>
605    #"
606   [(set_attr "type" "shift")
607    (set_attr "dot" "yes")
608    (set_attr "length" "4,8")])
609
610 (define_split
611   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
612         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
613                     (const_int 0)))
614    (set (match_operand:DI 0 "gpc_reg_operand" "")
615         (zero_extend:DI (match_dup 1)))]
616   "TARGET_POWERPC64 && reload_completed"
617   [(set (match_dup 0)
618         (zero_extend:DI (match_dup 1)))
619    (set (match_dup 2)
620         (compare:CC (match_dup 0)
621                     (const_int 0)))]
622   "")
623
624 (define_insn "*zero_extendsidi2_lfiwzx"
625   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,??wm,!wz,!wu")
626         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r,r,Z,Z")))]
627   "TARGET_POWERPC64 && TARGET_LFIWZX"
628   "@
629    lwz%U1%X1 %0,%1
630    rldicl %0,%1,0,32
631    mtvsrwz %x0,%1
632    lfiwzx %0,%y1
633    lxsiwzx %x0,%y1"
634   [(set_attr "type" "load,shift,mffgpr,fpload,fpload")])
635
636 (define_insn "extendqidi2"
637   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
638         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
639   "TARGET_POWERPC64"
640   "extsb %0,%1"
641   [(set_attr "type" "exts")])
642
643 (define_insn ""
644   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
645         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
646                     (const_int 0)))
647    (clobber (match_scratch:DI 2 "=r,r"))]
648   "TARGET_64BIT"
649   "@
650    extsb. %2,%1
651    #"
652   [(set_attr "type" "compare")
653    (set_attr "length" "4,8")])
654
655 (define_split
656   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
657         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
658                     (const_int 0)))
659    (clobber (match_scratch:DI 2 ""))]
660   "TARGET_POWERPC64 && reload_completed"
661   [(set (match_dup 2)
662         (sign_extend:DI (match_dup 1)))
663    (set (match_dup 0)
664         (compare:CC (match_dup 2)
665                     (const_int 0)))]
666   "")
667
668 (define_insn ""
669   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
670         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
671                     (const_int 0)))
672    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
673         (sign_extend:DI (match_dup 1)))]
674   "TARGET_64BIT"
675   "@
676    extsb. %0,%1
677    #"
678   [(set_attr "type" "compare")
679    (set_attr "length" "4,8")])
680
681 (define_split
682   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
683         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
684                     (const_int 0)))
685    (set (match_operand:DI 0 "gpc_reg_operand" "")
686         (sign_extend:DI (match_dup 1)))]
687   "TARGET_POWERPC64 && reload_completed"
688   [(set (match_dup 0)
689         (sign_extend:DI (match_dup 1)))
690    (set (match_dup 2)
691         (compare:CC (match_dup 0)
692                     (const_int 0)))]
693   "")
694
695 (define_expand "extendhidi2"
696   [(set (match_operand:DI 0 "gpc_reg_operand" "")
697         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
698   "TARGET_POWERPC64"
699   "")
700
701 (define_insn ""
702   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
703         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
704   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
705   "@
706    lha%U1%X1 %0,%1
707    extsh %0,%1"
708   [(set_attr "type" "load,exts")
709    (set_attr "sign_extend" "yes")])
710
711 (define_insn ""
712   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
713         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r")))]
714   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
715   "extsh %0,%1"
716   [(set_attr "type" "exts")])
717
718 (define_insn ""
719   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
720         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
721                     (const_int 0)))
722    (clobber (match_scratch:DI 2 "=r,r"))]
723   "TARGET_64BIT"
724   "@
725    extsh. %2,%1
726    #"
727   [(set_attr "type" "compare")
728    (set_attr "length" "4,8")])
729
730 (define_split
731   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
732         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
733                     (const_int 0)))
734    (clobber (match_scratch:DI 2 ""))]
735   "TARGET_POWERPC64 && reload_completed"
736   [(set (match_dup 2)
737         (sign_extend:DI (match_dup 1)))
738    (set (match_dup 0)
739         (compare:CC (match_dup 2)
740                     (const_int 0)))]
741   "")
742
743 (define_insn ""
744   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
745         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
746                     (const_int 0)))
747    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
748         (sign_extend:DI (match_dup 1)))]
749   "TARGET_64BIT"
750   "@
751    extsh. %0,%1
752    #"
753   [(set_attr "type" "compare")
754    (set_attr "length" "4,8")])
755
756 (define_split
757   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
758         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
759                     (const_int 0)))
760    (set (match_operand:DI 0 "gpc_reg_operand" "")
761         (sign_extend:DI (match_dup 1)))]
762   "TARGET_POWERPC64 && reload_completed"
763   [(set (match_dup 0)
764         (sign_extend:DI (match_dup 1)))
765    (set (match_dup 2)
766         (compare:CC (match_dup 0)
767                     (const_int 0)))]
768   "")
769
770 (define_expand "extendsidi2"
771   [(set (match_operand:DI 0 "gpc_reg_operand" "")
772         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
773   "TARGET_POWERPC64"
774   "")
775
776 (define_insn "*extendsidi2_lfiwax"
777   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,??wm,!wl,!wu")
778         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "Y,r,r,Z,Z")))]
779   "TARGET_POWERPC64 && TARGET_LFIWAX"
780   "@
781    lwa%U1%X1 %0,%1
782    extsw %0,%1
783    mtvsrwa %x0,%1
784    lfiwax %0,%y1
785    lxsiwax %x0,%y1"
786   [(set_attr "type" "load,exts,mffgpr,fpload,fpload")
787    (set_attr "sign_extend" "yes")])
788
789 (define_insn "*extendsidi2_nocell"
790   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
791         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "Y,r")))]
792   "TARGET_POWERPC64 && rs6000_gen_cell_microcode && !TARGET_LFIWAX"
793   "@
794    lwa%U1%X1 %0,%1
795    extsw %0,%1"
796   [(set_attr "type" "load,exts")
797    (set_attr "sign_extend" "yes")])
798
799 (define_insn "*extendsidi2_nocell"
800   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
801         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r")))]
802   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
803   "extsw %0,%1"
804   [(set_attr "type" "exts")])
805
806 (define_insn ""
807   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
808         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
809                     (const_int 0)))
810    (clobber (match_scratch:DI 2 "=r,r"))]
811   "TARGET_64BIT"
812   "@
813    extsw. %2,%1
814    #"
815   [(set_attr "type" "compare")
816    (set_attr "length" "4,8")])
817
818 (define_split
819   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
820         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
821                     (const_int 0)))
822    (clobber (match_scratch:DI 2 ""))]
823   "TARGET_POWERPC64 && reload_completed"
824   [(set (match_dup 2)
825         (sign_extend:DI (match_dup 1)))
826    (set (match_dup 0)
827         (compare:CC (match_dup 2)
828                     (const_int 0)))]
829   "")
830
831 (define_insn ""
832   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
833         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
834                     (const_int 0)))
835    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
836         (sign_extend:DI (match_dup 1)))]
837   "TARGET_64BIT"
838   "@
839    extsw. %0,%1
840    #"
841   [(set_attr "type" "compare")
842    (set_attr "length" "4,8")])
843
844 (define_split
845   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
846         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
847                     (const_int 0)))
848    (set (match_operand:DI 0 "gpc_reg_operand" "")
849         (sign_extend:DI (match_dup 1)))]
850   "TARGET_POWERPC64 && reload_completed"
851   [(set (match_dup 0)
852         (sign_extend:DI (match_dup 1)))
853    (set (match_dup 2)
854         (compare:CC (match_dup 0)
855                     (const_int 0)))]
856   "")
857
858 (define_expand "zero_extendqisi2"
859   [(set (match_operand:SI 0 "gpc_reg_operand" "")
860         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
861   ""
862   "")
863
864 (define_insn ""
865   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
866         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
867   ""
868   "@
869    lbz%U1%X1 %0,%1
870    rlwinm %0,%1,0,0xff"
871   [(set_attr "type" "load,shift")])
872
873 (define_insn ""
874   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
875         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
876                     (const_int 0)))
877    (clobber (match_scratch:SI 2 "=r,r"))]
878   ""
879   "@
880    andi. %2,%1,0xff
881    #"
882   [(set_attr "type" "logical,compare")
883    (set_attr "dot" "yes")
884    (set_attr "length" "4,8")])
885
886 (define_split
887   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
888         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
889                     (const_int 0)))
890    (clobber (match_scratch:SI 2 ""))]
891   "reload_completed"
892   [(set (match_dup 2)
893         (zero_extend:SI (match_dup 1)))
894    (set (match_dup 0)
895         (compare:CC (match_dup 2)
896                     (const_int 0)))]
897   "")
898
899 (define_insn ""
900   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
901         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
902                     (const_int 0)))
903    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
904         (zero_extend:SI (match_dup 1)))]
905   ""
906   "@
907    andi. %0,%1,0xff
908    #"
909   [(set_attr "type" "logical,compare")
910    (set_attr "dot" "yes")
911    (set_attr "length" "4,8")])
912
913 (define_split
914   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
915         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
916                     (const_int 0)))
917    (set (match_operand:SI 0 "gpc_reg_operand" "")
918         (zero_extend:SI (match_dup 1)))]
919   "reload_completed"
920   [(set (match_dup 0)
921         (zero_extend:SI (match_dup 1)))
922    (set (match_dup 2)
923         (compare:CC (match_dup 0)
924                     (const_int 0)))]
925   "")
926
927 (define_insn "extendqisi2"
928   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
929         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
930   ""
931   "extsb %0,%1"
932   [(set_attr "type" "exts")])
933
934 (define_insn ""
935   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
936         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
937                     (const_int 0)))
938    (clobber (match_scratch:SI 2 "=r,r"))]
939   ""
940   "@
941    extsb. %2,%1
942    #"
943   [(set_attr "type" "compare")
944    (set_attr "length" "4,8")])
945
946 (define_split
947   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
948         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
949                     (const_int 0)))
950    (clobber (match_scratch:SI 2 ""))]
951   "reload_completed"
952   [(set (match_dup 2)
953         (sign_extend:SI (match_dup 1)))
954    (set (match_dup 0)
955         (compare:CC (match_dup 2)
956                     (const_int 0)))]
957   "")
958
959 (define_insn ""
960   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
961         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
962                     (const_int 0)))
963    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
964         (sign_extend:SI (match_dup 1)))]
965   ""
966   "@
967    extsb. %0,%1
968    #"
969   [(set_attr "type" "compare")
970    (set_attr "length" "4,8")])
971
972 (define_split
973   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
974         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
975                     (const_int 0)))
976    (set (match_operand:SI 0 "gpc_reg_operand" "")
977         (sign_extend:SI (match_dup 1)))]
978   "reload_completed"
979   [(set (match_dup 0)
980         (sign_extend:SI (match_dup 1)))
981    (set (match_dup 2)
982         (compare:CC (match_dup 0)
983                     (const_int 0)))]
984   "")
985
986 (define_insn ""
987   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
988         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
989   ""
990   "@
991    lbz%U1%X1 %0,%1
992    rlwinm %0,%1,0,0xff"
993   [(set_attr "type" "load,shift")])
994
995 (define_insn ""
996   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
997         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
998                     (const_int 0)))
999    (clobber (match_scratch:HI 2 "=r,r"))]
1000   ""
1001   "@
1002    andi. %2,%1,0xff
1003    #"
1004   [(set_attr "type" "logical,compare")
1005    (set_attr "dot" "yes")
1006    (set_attr "length" "4,8")])
1007
1008 (define_split
1009   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1010         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1011                     (const_int 0)))
1012    (clobber (match_scratch:HI 2 ""))]
1013   "reload_completed"
1014   [(set (match_dup 2)
1015         (zero_extend:HI (match_dup 1)))
1016    (set (match_dup 0)
1017         (compare:CC (match_dup 2)
1018                     (const_int 0)))]
1019   "")
1020
1021 (define_insn ""
1022   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1023         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1024                     (const_int 0)))
1025    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
1026         (zero_extend:HI (match_dup 1)))]
1027   ""
1028   "@
1029    andi. %0,%1,0xff
1030    #"
1031   [(set_attr "type" "logical,compare")
1032    (set_attr "dot" "yes")
1033    (set_attr "length" "4,8")])
1034
1035 (define_split
1036   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1037         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1038                     (const_int 0)))
1039    (set (match_operand:HI 0 "gpc_reg_operand" "")
1040         (zero_extend:HI (match_dup 1)))]
1041   "reload_completed"
1042   [(set (match_dup 0)
1043         (zero_extend:HI (match_dup 1)))
1044    (set (match_dup 2)
1045         (compare:CC (match_dup 0)
1046                     (const_int 0)))]
1047   "")
1048
1049 (define_insn "extendqihi2"
1050   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
1051         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
1052   ""
1053   "extsb %0,%1"
1054   [(set_attr "type" "exts")])
1055
1056 (define_insn ""
1057   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1058         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1059                     (const_int 0)))
1060    (clobber (match_scratch:HI 2 "=r,r"))]
1061   ""
1062   "@
1063    extsb. %2,%1
1064    #"
1065   [(set_attr "type" "compare")
1066    (set_attr "length" "4,8")])
1067
1068 (define_split
1069   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1070         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1071                     (const_int 0)))
1072    (clobber (match_scratch:HI 2 ""))]
1073   "reload_completed"
1074   [(set (match_dup 2)
1075         (sign_extend:HI (match_dup 1)))
1076    (set (match_dup 0)
1077         (compare:CC (match_dup 2)
1078                     (const_int 0)))]
1079   "")
1080
1081 (define_insn ""
1082   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1083         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1084                     (const_int 0)))
1085    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
1086         (sign_extend:HI (match_dup 1)))]
1087   ""
1088   "@
1089    extsb. %0,%1
1090    #"
1091   [(set_attr "type" "compare")
1092    (set_attr "length" "4,8")])
1093
1094 (define_split
1095   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1096         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1097                     (const_int 0)))
1098    (set (match_operand:HI 0 "gpc_reg_operand" "")
1099         (sign_extend:HI (match_dup 1)))]
1100   "reload_completed"
1101   [(set (match_dup 0)
1102         (sign_extend:HI (match_dup 1)))
1103    (set (match_dup 2)
1104         (compare:CC (match_dup 0)
1105                     (const_int 0)))]
1106   "")
1107
1108 (define_expand "zero_extendhisi2"
1109   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1110         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
1111   ""
1112   "")
1113
1114 (define_insn ""
1115   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1116         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
1117   ""
1118   "@
1119    lhz%U1%X1 %0,%1
1120    rlwinm %0,%1,0,0xffff"
1121   [(set_attr "type" "load,shift")])
1122
1123 (define_insn ""
1124   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1125         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1126                     (const_int 0)))
1127    (clobber (match_scratch:SI 2 "=r,r"))]
1128   ""
1129   "@
1130    andi. %2,%1,0xffff
1131    #"
1132   [(set_attr "type" "logical,compare")
1133    (set_attr "dot" "yes")
1134    (set_attr "length" "4,8")])
1135
1136 (define_split
1137   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1138         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1139                     (const_int 0)))
1140    (clobber (match_scratch:SI 2 ""))]
1141   "reload_completed"
1142   [(set (match_dup 2)
1143         (zero_extend:SI (match_dup 1)))
1144    (set (match_dup 0)
1145         (compare:CC (match_dup 2)
1146                     (const_int 0)))]
1147   "")
1148
1149 (define_insn ""
1150   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1151         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1152                     (const_int 0)))
1153    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1154         (zero_extend:SI (match_dup 1)))]
1155   ""
1156   "@
1157    andi. %0,%1,0xffff
1158    #"
1159   [(set_attr "type" "logical,compare")
1160    (set_attr "dot" "yes")
1161    (set_attr "length" "4,8")])
1162
1163 (define_split
1164   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1165         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1166                     (const_int 0)))
1167    (set (match_operand:SI 0 "gpc_reg_operand" "")
1168         (zero_extend:SI (match_dup 1)))]
1169   "reload_completed"
1170   [(set (match_dup 0)
1171         (zero_extend:SI (match_dup 1)))
1172    (set (match_dup 2)
1173         (compare:CC (match_dup 0)
1174                     (const_int 0)))]
1175   "")
1176
1177 (define_expand "extendhisi2"
1178   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1179         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
1180   ""
1181   "")
1182
1183 (define_insn ""
1184   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1185         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
1186   "rs6000_gen_cell_microcode"
1187   "@
1188    lha%U1%X1 %0,%1
1189    extsh %0,%1"
1190   [(set_attr "type" "load,exts")
1191    (set_attr "sign_extend" "yes")])
1192
1193 (define_insn ""
1194   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1195         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r")))]
1196   "!rs6000_gen_cell_microcode"
1197   "extsh %0,%1"
1198   [(set_attr "type" "exts")])
1199
1200 (define_insn ""
1201   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1202         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1203                     (const_int 0)))
1204    (clobber (match_scratch:SI 2 "=r,r"))]
1205   ""
1206   "@
1207    extsh. %2,%1
1208    #"
1209   [(set_attr "type" "compare")
1210    (set_attr "length" "4,8")])
1211
1212 (define_split
1213   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1214         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1215                     (const_int 0)))
1216    (clobber (match_scratch:SI 2 ""))]
1217   "reload_completed"
1218   [(set (match_dup 2)
1219         (sign_extend:SI (match_dup 1)))
1220    (set (match_dup 0)
1221         (compare:CC (match_dup 2)
1222                     (const_int 0)))]
1223   "")
1224
1225 (define_insn ""
1226   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1227         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1228                     (const_int 0)))
1229    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1230         (sign_extend:SI (match_dup 1)))]
1231   ""
1232   "@
1233    extsh. %0,%1
1234    #"
1235   [(set_attr "type" "compare")
1236    (set_attr "length" "4,8")])
1237
1238 (define_split
1239   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1240         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1241                     (const_int 0)))
1242    (set (match_operand:SI 0 "gpc_reg_operand" "")
1243         (sign_extend:SI (match_dup 1)))]
1244   "reload_completed"
1245   [(set (match_dup 0)
1246         (sign_extend:SI (match_dup 1)))
1247    (set (match_dup 2)
1248         (compare:CC (match_dup 0)
1249                     (const_int 0)))]
1250   "")
1251 \f
1252 ;; IBM 405, 440, 464 and 476 half-word multiplication operations.
1253
1254 (define_insn "*macchwc"
1255   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1256         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1257                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1258                                        (const_int 16))
1259                                       (sign_extend:SI
1260                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1261                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1262                     (const_int 0)))
1263    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1264         (plus:SI (mult:SI (ashiftrt:SI
1265                            (match_dup 2)
1266                            (const_int 16))
1267                           (sign_extend:SI
1268                            (match_dup 1)))
1269                  (match_dup 4)))]
1270   "TARGET_MULHW"
1271   "macchw. %0,%1,%2"
1272   [(set_attr "type" "halfmul")])
1273
1274 (define_insn "*macchw"
1275   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1276         (plus:SI (mult:SI (ashiftrt:SI
1277                            (match_operand:SI 2 "gpc_reg_operand" "r")
1278                            (const_int 16))
1279                           (sign_extend:SI
1280                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1281                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1282   "TARGET_MULHW"
1283   "macchw %0,%1,%2"
1284   [(set_attr "type" "halfmul")])
1285
1286 (define_insn "*macchwuc"
1287   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1288         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1289                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1290                                        (const_int 16))
1291                                       (zero_extend:SI
1292                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1293                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1294                     (const_int 0)))
1295    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1296         (plus:SI (mult:SI (lshiftrt:SI
1297                            (match_dup 2)
1298                            (const_int 16))
1299                           (zero_extend:SI
1300                            (match_dup 1)))
1301                  (match_dup 4)))]
1302   "TARGET_MULHW"
1303   "macchwu. %0,%1,%2"
1304   [(set_attr "type" "halfmul")])
1305
1306 (define_insn "*macchwu"
1307   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1308         (plus:SI (mult:SI (lshiftrt:SI
1309                            (match_operand:SI 2 "gpc_reg_operand" "r")
1310                            (const_int 16))
1311                           (zero_extend:SI
1312                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1313                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1314   "TARGET_MULHW"
1315   "macchwu %0,%1,%2"
1316   [(set_attr "type" "halfmul")])
1317
1318 (define_insn "*machhwc"
1319   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1320         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1321                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1322                                        (const_int 16))
1323                                       (ashiftrt:SI
1324                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1325                                        (const_int 16)))
1326                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1327                     (const_int 0)))
1328    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1329         (plus:SI (mult:SI (ashiftrt:SI
1330                            (match_dup 1)
1331                            (const_int 16))
1332                           (ashiftrt:SI
1333                            (match_dup 2)
1334                            (const_int 16)))
1335                  (match_dup 4)))]
1336   "TARGET_MULHW"
1337   "machhw. %0,%1,%2"
1338   [(set_attr "type" "halfmul")])
1339
1340 (define_insn "*machhw"
1341   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1342         (plus:SI (mult:SI (ashiftrt:SI
1343                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1344                            (const_int 16))
1345                           (ashiftrt:SI
1346                            (match_operand:SI 2 "gpc_reg_operand" "r")
1347                            (const_int 16)))
1348                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1349   "TARGET_MULHW"
1350   "machhw %0,%1,%2"
1351   [(set_attr "type" "halfmul")])
1352
1353 (define_insn "*machhwuc"
1354   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1355         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1356                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1357                                        (const_int 16))
1358                                       (lshiftrt:SI
1359                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1360                                        (const_int 16)))
1361                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1362                     (const_int 0)))
1363    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1364         (plus:SI (mult:SI (lshiftrt:SI
1365                            (match_dup 1)
1366                            (const_int 16))
1367                           (lshiftrt:SI
1368                            (match_dup 2)
1369                            (const_int 16)))
1370                  (match_dup 4)))]
1371   "TARGET_MULHW"
1372   "machhwu. %0,%1,%2"
1373   [(set_attr "type" "halfmul")])
1374
1375 (define_insn "*machhwu"
1376   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1377         (plus:SI (mult:SI (lshiftrt:SI
1378                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1379                            (const_int 16))
1380                           (lshiftrt:SI
1381                            (match_operand:SI 2 "gpc_reg_operand" "r")
1382                            (const_int 16)))
1383                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1384   "TARGET_MULHW"
1385   "machhwu %0,%1,%2"
1386   [(set_attr "type" "halfmul")])
1387
1388 (define_insn "*maclhwc"
1389   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1390         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1391                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1392                                       (sign_extend:SI
1393                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1394                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1395                     (const_int 0)))
1396    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1397         (plus:SI (mult:SI (sign_extend:SI
1398                            (match_dup 1))
1399                           (sign_extend:SI
1400                            (match_dup 2)))
1401                  (match_dup 4)))]
1402   "TARGET_MULHW"
1403   "maclhw. %0,%1,%2"
1404   [(set_attr "type" "halfmul")])
1405
1406 (define_insn "*maclhw"
1407   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1408         (plus:SI (mult:SI (sign_extend:SI
1409                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1410                           (sign_extend:SI
1411                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1412                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1413   "TARGET_MULHW"
1414   "maclhw %0,%1,%2"
1415   [(set_attr "type" "halfmul")])
1416
1417 (define_insn "*maclhwuc"
1418   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1419         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1420                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1421                                       (zero_extend:SI
1422                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1423                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1424                     (const_int 0)))
1425    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1426         (plus:SI (mult:SI (zero_extend:SI
1427                            (match_dup 1))
1428                           (zero_extend:SI
1429                            (match_dup 2)))
1430                  (match_dup 4)))]
1431   "TARGET_MULHW"
1432   "maclhwu. %0,%1,%2"
1433   [(set_attr "type" "halfmul")])
1434
1435 (define_insn "*maclhwu"
1436   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1437         (plus:SI (mult:SI (zero_extend:SI
1438                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1439                           (zero_extend:SI
1440                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1441                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1442   "TARGET_MULHW"
1443   "maclhwu %0,%1,%2"
1444   [(set_attr "type" "halfmul")])
1445
1446 (define_insn "*nmacchwc"
1447   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1448         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1449                               (mult:SI (ashiftrt:SI
1450                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1451                                         (const_int 16))
1452                                        (sign_extend:SI
1453                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1454                     (const_int 0)))
1455    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1456         (minus:SI (match_dup 4)
1457                   (mult:SI (ashiftrt:SI
1458                             (match_dup 2)
1459                             (const_int 16))
1460                            (sign_extend:SI
1461                             (match_dup 1)))))]
1462   "TARGET_MULHW"
1463   "nmacchw. %0,%1,%2"
1464   [(set_attr "type" "halfmul")])
1465
1466 (define_insn "*nmacchw"
1467   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1468         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1469                   (mult:SI (ashiftrt:SI
1470                             (match_operand:SI 2 "gpc_reg_operand" "r")
1471                             (const_int 16))
1472                            (sign_extend:SI
1473                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1474   "TARGET_MULHW"
1475   "nmacchw %0,%1,%2"
1476   [(set_attr "type" "halfmul")])
1477
1478 (define_insn "*nmachhwc"
1479   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1480         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1481                               (mult:SI (ashiftrt:SI
1482                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1483                                         (const_int 16))
1484                                        (ashiftrt:SI
1485                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1486                                         (const_int 16))))
1487                     (const_int 0)))
1488    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1489         (minus:SI (match_dup 4)
1490                   (mult:SI (ashiftrt:SI
1491                             (match_dup 1)
1492                             (const_int 16))
1493                            (ashiftrt:SI
1494                             (match_dup 2)
1495                             (const_int 16)))))]
1496   "TARGET_MULHW"
1497   "nmachhw. %0,%1,%2"
1498   [(set_attr "type" "halfmul")])
1499
1500 (define_insn "*nmachhw"
1501   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1502         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1503                   (mult:SI (ashiftrt:SI
1504                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1505                             (const_int 16))
1506                            (ashiftrt:SI
1507                             (match_operand:SI 2 "gpc_reg_operand" "r")
1508                             (const_int 16)))))]
1509   "TARGET_MULHW"
1510   "nmachhw %0,%1,%2"
1511   [(set_attr "type" "halfmul")])
1512
1513 (define_insn "*nmaclhwc"
1514   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1515         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1516                               (mult:SI (sign_extend:SI
1517                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1518                                        (sign_extend:SI
1519                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1520                     (const_int 0)))
1521    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1522         (minus:SI (match_dup 4)
1523                   (mult:SI (sign_extend:SI
1524                             (match_dup 1))
1525                            (sign_extend:SI
1526                             (match_dup 2)))))]
1527   "TARGET_MULHW"
1528   "nmaclhw. %0,%1,%2"
1529   [(set_attr "type" "halfmul")])
1530
1531 (define_insn "*nmaclhw"
1532   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1533         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1534                   (mult:SI (sign_extend:SI
1535                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1536                            (sign_extend:SI
1537                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1538   "TARGET_MULHW"
1539   "nmaclhw %0,%1,%2"
1540   [(set_attr "type" "halfmul")])
1541
1542 (define_insn "*mulchwc"
1543   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1544         (compare:CC (mult:SI (ashiftrt:SI
1545                               (match_operand:SI 2 "gpc_reg_operand" "r")
1546                               (const_int 16))
1547                              (sign_extend:SI
1548                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1549                     (const_int 0)))
1550    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1551         (mult:SI (ashiftrt:SI
1552                   (match_dup 2)
1553                   (const_int 16))
1554                  (sign_extend:SI
1555                   (match_dup 1))))]
1556   "TARGET_MULHW"
1557   "mulchw. %0,%1,%2"
1558   [(set_attr "type" "halfmul")])
1559
1560 (define_insn "*mulchw"
1561   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1562         (mult:SI (ashiftrt:SI
1563                   (match_operand:SI 2 "gpc_reg_operand" "r")
1564                   (const_int 16))
1565                  (sign_extend:SI
1566                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1567   "TARGET_MULHW"
1568   "mulchw %0,%1,%2"
1569   [(set_attr "type" "halfmul")])
1570
1571 (define_insn "*mulchwuc"
1572   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1573         (compare:CC (mult:SI (lshiftrt:SI
1574                               (match_operand:SI 2 "gpc_reg_operand" "r")
1575                               (const_int 16))
1576                              (zero_extend:SI
1577                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1578                     (const_int 0)))
1579    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1580         (mult:SI (lshiftrt:SI
1581                   (match_dup 2)
1582                   (const_int 16))
1583                  (zero_extend:SI
1584                   (match_dup 1))))]
1585   "TARGET_MULHW"
1586   "mulchwu. %0,%1,%2"
1587   [(set_attr "type" "halfmul")])
1588
1589 (define_insn "*mulchwu"
1590   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1591         (mult:SI (lshiftrt:SI
1592                   (match_operand:SI 2 "gpc_reg_operand" "r")
1593                   (const_int 16))
1594                  (zero_extend:SI
1595                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1596   "TARGET_MULHW"
1597   "mulchwu %0,%1,%2"
1598   [(set_attr "type" "halfmul")])
1599
1600 (define_insn "*mulhhwc"
1601   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1602         (compare:CC (mult:SI (ashiftrt:SI
1603                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1604                               (const_int 16))
1605                              (ashiftrt:SI
1606                               (match_operand:SI 2 "gpc_reg_operand" "r")
1607                               (const_int 16)))
1608                     (const_int 0)))
1609    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1610         (mult:SI (ashiftrt:SI
1611                   (match_dup 1)
1612                   (const_int 16))
1613                  (ashiftrt:SI
1614                   (match_dup 2)
1615                   (const_int 16))))]
1616   "TARGET_MULHW"
1617   "mulhhw. %0,%1,%2"
1618   [(set_attr "type" "halfmul")])
1619
1620 (define_insn "*mulhhw"
1621   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1622         (mult:SI (ashiftrt:SI
1623                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1624                   (const_int 16))
1625                  (ashiftrt:SI
1626                   (match_operand:SI 2 "gpc_reg_operand" "r")
1627                   (const_int 16))))]
1628   "TARGET_MULHW"
1629   "mulhhw %0,%1,%2"
1630   [(set_attr "type" "halfmul")])
1631
1632 (define_insn "*mulhhwuc"
1633   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1634         (compare:CC (mult:SI (lshiftrt:SI
1635                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1636                               (const_int 16))
1637                              (lshiftrt:SI
1638                               (match_operand:SI 2 "gpc_reg_operand" "r")
1639                               (const_int 16)))
1640                     (const_int 0)))
1641    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1642         (mult:SI (lshiftrt:SI
1643                   (match_dup 1)
1644                   (const_int 16))
1645                  (lshiftrt:SI
1646                   (match_dup 2)
1647                   (const_int 16))))]
1648   "TARGET_MULHW"
1649   "mulhhwu. %0,%1,%2"
1650   [(set_attr "type" "halfmul")])
1651
1652 (define_insn "*mulhhwu"
1653   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1654         (mult:SI (lshiftrt:SI
1655                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1656                   (const_int 16))
1657                  (lshiftrt:SI
1658                   (match_operand:SI 2 "gpc_reg_operand" "r")
1659                   (const_int 16))))]
1660   "TARGET_MULHW"
1661   "mulhhwu %0,%1,%2"
1662   [(set_attr "type" "halfmul")])
1663
1664 (define_insn "*mullhwc"
1665   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1666         (compare:CC (mult:SI (sign_extend:SI
1667                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1668                              (sign_extend:SI
1669                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1670                     (const_int 0)))
1671    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1672         (mult:SI (sign_extend:SI
1673                   (match_dup 1))
1674                  (sign_extend:SI
1675                   (match_dup 2))))]
1676   "TARGET_MULHW"
1677   "mullhw. %0,%1,%2"
1678   [(set_attr "type" "halfmul")])
1679
1680 (define_insn "*mullhw"
1681   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1682         (mult:SI (sign_extend:SI
1683                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1684                  (sign_extend:SI
1685                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1686   "TARGET_MULHW"
1687   "mullhw %0,%1,%2"
1688   [(set_attr "type" "halfmul")])
1689
1690 (define_insn "*mullhwuc"
1691   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1692         (compare:CC (mult:SI (zero_extend:SI
1693                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1694                              (zero_extend:SI
1695                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1696                     (const_int 0)))
1697    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1698         (mult:SI (zero_extend:SI
1699                   (match_dup 1))
1700                  (zero_extend:SI
1701                   (match_dup 2))))]
1702   "TARGET_MULHW"
1703   "mullhwu. %0,%1,%2"
1704   [(set_attr "type" "halfmul")])
1705
1706 (define_insn "*mullhwu"
1707   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1708         (mult:SI (zero_extend:SI
1709                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1710                  (zero_extend:SI
1711                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1712   "TARGET_MULHW"
1713   "mullhwu %0,%1,%2"
1714   [(set_attr "type" "halfmul")])
1715 \f
1716 ;; IBM 405, 440, 464 and 476 string-search dlmzb instruction support.
1717 (define_insn "dlmzb"
1718   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1719         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1720                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1721                    UNSPEC_DLMZB_CR))
1722    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1723         (unspec:SI [(match_dup 1)
1724                     (match_dup 2)]
1725                    UNSPEC_DLMZB))]
1726   "TARGET_DLMZB"
1727   "dlmzb. %0,%1,%2")
1728
1729 (define_expand "strlensi"
1730   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1731         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1732                     (match_operand:QI 2 "const_int_operand" "")
1733                     (match_operand 3 "const_int_operand" "")]
1734                    UNSPEC_DLMZB_STRLEN))
1735    (clobber (match_scratch:CC 4 "=x"))]
1736   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1737 {
1738   rtx result = operands[0];
1739   rtx src = operands[1];
1740   rtx search_char = operands[2];
1741   rtx align = operands[3];
1742   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1743   rtx loop_label, end_label, mem, cr0, cond;
1744   if (search_char != const0_rtx
1745       || GET_CODE (align) != CONST_INT
1746       || INTVAL (align) < 8)
1747         FAIL;
1748   word1 = gen_reg_rtx (SImode);
1749   word2 = gen_reg_rtx (SImode);
1750   scratch_dlmzb = gen_reg_rtx (SImode);
1751   scratch_string = gen_reg_rtx (Pmode);
1752   loop_label = gen_label_rtx ();
1753   end_label = gen_label_rtx ();
1754   addr = force_reg (Pmode, XEXP (src, 0));
1755   emit_move_insn (scratch_string, addr);
1756   emit_label (loop_label);
1757   mem = change_address (src, SImode, scratch_string);
1758   emit_move_insn (word1, mem);
1759   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1760   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1761   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1762   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1763   emit_jump_insn (gen_rtx_SET (VOIDmode,
1764                                pc_rtx,
1765                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1766                                                      cond,
1767                                                      gen_rtx_LABEL_REF
1768                                                        (VOIDmode,
1769                                                         end_label),
1770                                                      pc_rtx)));
1771   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1772   emit_jump_insn (gen_rtx_SET (VOIDmode,
1773                                pc_rtx,
1774                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1775   emit_barrier ();
1776   emit_label (end_label);
1777   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1778   emit_insn (gen_subsi3 (result, scratch_string, addr));
1779   emit_insn (gen_subsi3 (result, result, const1_rtx));
1780   DONE;
1781 })
1782 \f
1783 ;; Fixed-point arithmetic insns.
1784
1785 (define_expand "add<mode>3"
1786   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1787         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1788                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1789   ""
1790 {
1791   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1792     {
1793       if (non_short_cint_operand (operands[2], DImode))
1794         FAIL;
1795     }
1796   else if (GET_CODE (operands[2]) == CONST_INT
1797            && ! add_operand (operands[2], <MODE>mode))
1798     {
1799       rtx tmp = ((!can_create_pseudo_p ()
1800                   || rtx_equal_p (operands[0], operands[1]))
1801                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1802
1803       HOST_WIDE_INT val = INTVAL (operands[2]);
1804       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1805       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1806
1807       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1808         FAIL;
1809
1810       /* The ordering here is important for the prolog expander.
1811          When space is allocated from the stack, adding 'low' first may
1812          produce a temporary deallocation (which would be bad).  */
1813       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1814       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1815       DONE;
1816     }
1817 })
1818
1819 ;; Discourage ai/addic because of carry but provide it in an alternative
1820 ;; allowing register zero as source.
1821 (define_insn "*add<mode>3_internal1"
1822   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1823         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1824                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1825   "!DECIMAL_FLOAT_MODE_P (GET_MODE (operands[0])) && !DECIMAL_FLOAT_MODE_P (GET_MODE (operands[1]))"
1826   "@
1827    add %0,%1,%2
1828    addi %0,%1,%2
1829    addic %0,%1,%2
1830    addis %0,%1,%v2"
1831   [(set_attr "type" "add")])
1832
1833 (define_insn "addsi3_high"
1834   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1835         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1836                  (high:SI (match_operand 2 "" ""))))]
1837   "TARGET_MACHO && !TARGET_64BIT"
1838   "addis %0,%1,ha16(%2)"
1839   [(set_attr "type" "add")])
1840
1841 (define_insn "*add<mode>3_internal2"
1842   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1843         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1844                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1845                     (const_int 0)))
1846    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1847   ""
1848   "@
1849    add. %3,%1,%2
1850    addic. %3,%1,%2
1851    #
1852    #"
1853   [(set_attr "type" "add,compare,compare,compare")
1854    (set_attr "dot" "yes")
1855    (set_attr "length" "4,4,8,8")])
1856
1857 (define_split
1858   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1859         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1860                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1861                     (const_int 0)))
1862    (clobber (match_scratch:GPR 3 ""))]
1863   "reload_completed"
1864   [(set (match_dup 3)
1865         (plus:GPR (match_dup 1)
1866                  (match_dup 2)))
1867    (set (match_dup 0)
1868         (compare:CC (match_dup 3)
1869                     (const_int 0)))]
1870   "")
1871
1872 (define_insn "*add<mode>3_internal3"
1873   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1874         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1875                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1876                     (const_int 0)))
1877    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1878         (plus:P (match_dup 1)
1879                 (match_dup 2)))]
1880   ""
1881   "@
1882    add. %0,%1,%2
1883    addic. %0,%1,%2
1884    #
1885    #"
1886   [(set_attr "type" "add,compare,compare,compare")
1887    (set_attr "dot" "yes")
1888    (set_attr "length" "4,4,8,8")])
1889
1890 (define_split
1891   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1892         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1893                             (match_operand:P 2 "reg_or_short_operand" ""))
1894                     (const_int 0)))
1895    (set (match_operand:P 0 "gpc_reg_operand" "")
1896         (plus:P (match_dup 1) (match_dup 2)))]
1897   "reload_completed"
1898   [(set (match_dup 0)
1899         (plus:P (match_dup 1)
1900                 (match_dup 2)))
1901    (set (match_dup 3)
1902         (compare:CC (match_dup 0)
1903                     (const_int 0)))]
1904   "")
1905
1906 ;; Split an add that we can't do in one insn into two insns, each of which
1907 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1908 ;; add should be last in case the result gets used in an address.
1909
1910 (define_split
1911   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1912         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1913                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1914   ""
1915   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1916    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1917 {
1918   HOST_WIDE_INT val = INTVAL (operands[2]);
1919   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1920   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1921
1922   operands[4] = GEN_INT (low);
1923   if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1924     operands[3] = GEN_INT (rest);
1925   else if (can_create_pseudo_p ())
1926     {
1927       operands[3] = gen_reg_rtx (DImode);
1928       emit_move_insn (operands[3], operands[2]);
1929       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1930       DONE;
1931     }
1932   else
1933     FAIL;
1934 })
1935
1936 (define_expand "one_cmpl<mode>2"
1937   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1938         (not:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
1939   ""
1940 {
1941   if (<MODE>mode == DImode && !TARGET_POWERPC64)
1942     {
1943       rs6000_split_logical (operands, NOT, false, false, false, NULL_RTX);
1944       DONE;
1945     }
1946 })
1947
1948 (define_insn "*one_cmpl<mode>2"
1949   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1950         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1951   ""
1952   "nor %0,%1,%1")
1953
1954 (define_insn ""
1955   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1956         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1957                     (const_int 0)))
1958    (clobber (match_scratch:P 2 "=r,r"))]
1959   ""
1960   "@
1961    nor. %2,%1,%1
1962    #"
1963   [(set_attr "type" "logical,compare")
1964    (set_attr "dot" "yes")
1965    (set_attr "length" "4,8")])
1966
1967 (define_split
1968   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1969         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1970                     (const_int 0)))
1971    (clobber (match_scratch:P 2 ""))]
1972   "reload_completed"
1973   [(set (match_dup 2)
1974         (not:P (match_dup 1)))
1975    (set (match_dup 0)
1976         (compare:CC (match_dup 2)
1977                     (const_int 0)))]
1978   "")
1979
1980 (define_insn ""
1981   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1982         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1983                     (const_int 0)))
1984    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1985         (not:P (match_dup 1)))]
1986   ""
1987   "@
1988    nor. %0,%1,%1
1989    #"
1990   [(set_attr "type" "logical,compare")
1991    (set_attr "dot" "yes")
1992    (set_attr "length" "4,8")])
1993
1994 (define_split
1995   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1996         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1997                     (const_int 0)))
1998    (set (match_operand:P 0 "gpc_reg_operand" "")
1999         (not:P (match_dup 1)))]
2000   "reload_completed"
2001   [(set (match_dup 0)
2002         (not:P (match_dup 1)))
2003    (set (match_dup 2)
2004         (compare:CC (match_dup 0)
2005                     (const_int 0)))]
2006   "")
2007
2008 (define_insn ""
2009   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
2010         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
2011                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
2012   ""
2013   "@
2014    subf %0,%2,%1
2015    subfic %0,%2,%1"
2016   [(set_attr "type" "add")])
2017
2018 (define_insn ""
2019   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2020         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2021                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
2022                     (const_int 0)))
2023    (clobber (match_scratch:P 3 "=r,r"))]
2024   ""
2025   "@
2026    subf. %3,%2,%1
2027    #"
2028   [(set_attr "type" "add")
2029    (set_attr "dot" "yes")
2030    (set_attr "length" "4,8")])
2031
2032 (define_split
2033   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2034         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
2035                              (match_operand:P 2 "gpc_reg_operand" ""))
2036                     (const_int 0)))
2037    (clobber (match_scratch:P 3 ""))]
2038   "reload_completed"
2039   [(set (match_dup 3)
2040         (minus:P (match_dup 1)
2041                   (match_dup 2)))
2042    (set (match_dup 0)
2043         (compare:CC (match_dup 3)
2044                     (const_int 0)))]
2045   "")
2046
2047 (define_insn ""
2048   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2049         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2050                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
2051                     (const_int 0)))
2052    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2053         (minus:P (match_dup 1)
2054                   (match_dup 2)))]
2055   ""
2056   "@
2057    subf. %0,%2,%1
2058    #"
2059   [(set_attr "type" "add")
2060    (set_attr "dot" "yes")
2061    (set_attr "length" "4,8")])
2062
2063 (define_split
2064   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2065         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
2066                              (match_operand:P 2 "gpc_reg_operand" ""))
2067                     (const_int 0)))
2068    (set (match_operand:P 0 "gpc_reg_operand" "")
2069         (minus:P (match_dup 1)
2070                   (match_dup 2)))]
2071   "reload_completed"
2072   [(set (match_dup 0)
2073         (minus:P (match_dup 1)
2074                   (match_dup 2)))
2075    (set (match_dup 3)
2076         (compare:CC (match_dup 0)
2077                     (const_int 0)))]
2078   "")
2079
2080 (define_expand "sub<mode>3"
2081   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
2082         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
2083                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
2084   ""
2085   "
2086 {
2087   if (GET_CODE (operands[2]) == CONST_INT)
2088     {
2089       emit_insn (gen_add<mode>3 (operands[0], operands[1],
2090                                  negate_rtx (<MODE>mode, operands[2])));
2091       DONE;
2092     }
2093 }")
2094
2095 (define_expand "neg<mode>2"
2096   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
2097         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
2098   ""
2099   "")
2100
2101 (define_insn "*neg<mode>2_internal"
2102   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2103         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2104   ""
2105   "neg %0,%1"
2106   [(set_attr "type" "add")])
2107
2108 (define_insn ""
2109   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2110         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2111                     (const_int 0)))
2112    (clobber (match_scratch:P 2 "=r,r"))]
2113   ""
2114   "@
2115    neg. %2,%1
2116    #"
2117   [(set_attr "type" "add")
2118    (set_attr "dot" "yes")
2119    (set_attr "length" "4,8")])
2120
2121 (define_split
2122   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2123         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2124                     (const_int 0)))
2125    (clobber (match_scratch:P 2 ""))]
2126   "reload_completed"
2127   [(set (match_dup 2)
2128         (neg:P (match_dup 1)))
2129    (set (match_dup 0)
2130         (compare:CC (match_dup 2)
2131                     (const_int 0)))]
2132   "")
2133
2134 (define_insn ""
2135   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2136         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2137                     (const_int 0)))
2138    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2139         (neg:P (match_dup 1)))]
2140   ""
2141   "@
2142    neg. %0,%1
2143    #"
2144   [(set_attr "type" "add")
2145    (set_attr "dot" "yes")
2146    (set_attr "length" "4,8")])
2147
2148 (define_split
2149   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2150         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2151                     (const_int 0)))
2152    (set (match_operand:P 0 "gpc_reg_operand" "")
2153         (neg:P (match_dup 1)))]
2154   "reload_completed"
2155   [(set (match_dup 0)
2156         (neg:P (match_dup 1)))
2157    (set (match_dup 2)
2158         (compare:CC (match_dup 0)
2159                     (const_int 0)))]
2160   "")
2161
2162 (define_insn "clz<mode>2"
2163   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2164         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2165   ""
2166   "cntlz<wd> %0,%1"
2167   [(set_attr "type" "cntlz")])
2168
2169 (define_expand "ctz<mode>2"
2170   [(set (match_dup 2)
2171         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2172    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2173                                           (match_dup 2)))
2174               (clobber (scratch:CC))])
2175    (set (match_dup 4) (clz:GPR (match_dup 3)))
2176    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2177         (minus:GPR (match_dup 5) (match_dup 4)))]
2178   ""
2179   {
2180      operands[2] = gen_reg_rtx (<MODE>mode);
2181      operands[3] = gen_reg_rtx (<MODE>mode);
2182      operands[4] = gen_reg_rtx (<MODE>mode);
2183      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
2184   })
2185
2186 (define_expand "ffs<mode>2"
2187   [(set (match_dup 2)
2188         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2189    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2190                                           (match_dup 2)))
2191               (clobber (scratch:CC))])
2192    (set (match_dup 4) (clz:GPR (match_dup 3)))
2193    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2194         (minus:GPR (match_dup 5) (match_dup 4)))]
2195   ""
2196   {
2197      operands[2] = gen_reg_rtx (<MODE>mode);
2198      operands[3] = gen_reg_rtx (<MODE>mode);
2199      operands[4] = gen_reg_rtx (<MODE>mode);
2200      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
2201   })
2202
2203 (define_insn "popcntb<mode>2"
2204   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2205         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2206                      UNSPEC_POPCNTB))]
2207   "TARGET_POPCNTB"
2208   "popcntb %0,%1"
2209   [(set_attr "length" "4")
2210    (set_attr "type" "popcnt")])
2211
2212 (define_insn "popcntd<mode>2"
2213   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2214         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2215   "TARGET_POPCNTD"
2216   "popcnt<wd> %0,%1"
2217   [(set_attr "length" "4")
2218    (set_attr "type" "popcnt")])
2219
2220 (define_expand "popcount<mode>2"
2221   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2222         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2223   "TARGET_POPCNTB || TARGET_POPCNTD"
2224   {
2225     rs6000_emit_popcount (operands[0], operands[1]);
2226     DONE;
2227   })
2228
2229 (define_insn "parity<mode>2_cmpb"
2230   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2231         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")] UNSPEC_PARITY))]
2232   "TARGET_CMPB && TARGET_POPCNTB"
2233   "prty<wd> %0,%1"
2234   [(set_attr "length" "4")
2235    (set_attr "type" "popcnt")])
2236
2237 (define_expand "parity<mode>2"
2238   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2239         (parity:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2240   "TARGET_POPCNTB"
2241   {
2242     rs6000_emit_parity (operands[0], operands[1]);
2243     DONE;
2244   })
2245
2246 ;; Since the hardware zeros the upper part of the register, save generating the
2247 ;; AND immediate if we are converting to unsigned
2248 (define_insn "*bswaphi2_extenddi"
2249   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2250         (zero_extend:DI
2251          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2252   "TARGET_POWERPC64"
2253   "lhbrx %0,%y1"
2254   [(set_attr "length" "4")
2255    (set_attr "type" "load")])
2256
2257 (define_insn "*bswaphi2_extendsi"
2258   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2259         (zero_extend:SI
2260          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2261   ""
2262   "lhbrx %0,%y1"
2263   [(set_attr "length" "4")
2264    (set_attr "type" "load")])
2265
2266 (define_expand "bswaphi2"
2267   [(parallel [(set (match_operand:HI 0 "reg_or_mem_operand" "")
2268                    (bswap:HI
2269                     (match_operand:HI 1 "reg_or_mem_operand" "")))
2270               (clobber (match_scratch:SI 2 ""))])]
2271   ""
2272 {
2273   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2274     operands[1] = force_reg (HImode, operands[1]);
2275 })
2276
2277 (define_insn "bswaphi2_internal"
2278   [(set (match_operand:HI 0 "reg_or_mem_operand" "=r,Z,&r")
2279         (bswap:HI
2280          (match_operand:HI 1 "reg_or_mem_operand" "Z,r,r")))
2281    (clobber (match_scratch:SI 2 "=X,X,&r"))]
2282   ""
2283   "@
2284    lhbrx %0,%y1
2285    sthbrx %1,%y0
2286    #"
2287   [(set_attr "length" "4,4,12")
2288    (set_attr "type" "load,store,*")])
2289
2290 ;; We are always BITS_BIG_ENDIAN, so the (const_int 16) below is
2291 ;; correct for -mlittle as well as -mbig.
2292 (define_split
2293   [(set (match_operand:HI 0 "gpc_reg_operand" "")
2294         (bswap:HI (match_operand:HI 1 "gpc_reg_operand" "")))
2295    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2296   "reload_completed"
2297   [(set (match_dup 3)
2298         (zero_extract:SI (match_dup 4)
2299                          (const_int 8)
2300                          (const_int 16)))
2301    (set (match_dup 2)
2302         (and:SI (ashift:SI (match_dup 4)
2303                            (const_int 8))
2304                 (const_int 65280)))             ;; 0xff00
2305    (set (match_dup 3)
2306         (ior:SI (match_dup 3)
2307                 (match_dup 2)))]
2308   "
2309 {
2310   operands[3] = simplify_gen_subreg (SImode, operands[0], HImode, 0);
2311   operands[4] = simplify_gen_subreg (SImode, operands[1], HImode, 0);
2312 }")
2313
2314 (define_insn "*bswapsi2_extenddi"
2315   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2316         (zero_extend:DI
2317          (bswap:SI (match_operand:SI 1 "memory_operand" "Z"))))]
2318   "TARGET_POWERPC64"
2319   "lwbrx %0,%y1"
2320   [(set_attr "length" "4")
2321    (set_attr "type" "load")])
2322
2323 (define_expand "bswapsi2"
2324   [(set (match_operand:SI 0 "reg_or_mem_operand" "")
2325         (bswap:SI
2326          (match_operand:SI 1 "reg_or_mem_operand" "")))]
2327   ""
2328 {
2329   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2330     operands[1] = force_reg (SImode, operands[1]);
2331 })
2332
2333 (define_insn "*bswapsi2_internal"
2334   [(set (match_operand:SI 0 "reg_or_mem_operand" "=r,Z,&r")
2335         (bswap:SI
2336          (match_operand:SI 1 "reg_or_mem_operand" "Z,r,r")))]
2337   ""
2338   "@
2339    lwbrx %0,%y1
2340    stwbrx %1,%y0
2341    #"
2342   [(set_attr "length" "4,4,12")
2343    (set_attr "type" "load,store,*")])
2344
2345 ;; We are always BITS_BIG_ENDIAN, so the bit positions below in
2346 ;; zero_extract insns do not change for -mlittle.
2347 (define_split
2348   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2349         (bswap:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2350   "reload_completed"
2351   [(set (match_dup 0)
2352         (rotate:SI (match_dup 1) (const_int 8)))
2353    (set (zero_extract:SI (match_dup 0)
2354                          (const_int 8)
2355                          (const_int 0))
2356         (match_dup 1))
2357    (set (zero_extract:SI (match_dup 0)
2358                          (const_int 8)
2359                          (const_int 16))
2360         (rotate:SI (match_dup 1)
2361                    (const_int 16)))]
2362   "")
2363
2364 (define_expand "bswapdi2"
2365   [(parallel [(set (match_operand:DI 0 "reg_or_mem_operand" "")
2366                    (bswap:DI
2367                     (match_operand:DI 1 "reg_or_mem_operand" "")))
2368               (clobber (match_scratch:DI 2 ""))
2369               (clobber (match_scratch:DI 3 ""))
2370               (clobber (match_scratch:DI 4 ""))])]
2371   ""
2372 {
2373   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2374     operands[1] = force_reg (DImode, operands[1]);
2375
2376   if (!TARGET_POWERPC64)
2377     {
2378       /* 32-bit mode needs fewer scratch registers, but 32-bit addressing mode
2379          that uses 64-bit registers needs the same scratch registers as 64-bit
2380          mode.  */
2381       emit_insn (gen_bswapdi2_32bit (operands[0], operands[1]));
2382       DONE;
2383     }
2384 })
2385
2386 ;; Power7/cell has ldbrx/stdbrx, so use it directly
2387 (define_insn "*bswapdi2_ldbrx"
2388   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2389         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2390    (clobber (match_scratch:DI 2 "=X,X,&r"))
2391    (clobber (match_scratch:DI 3 "=X,X,&r"))
2392    (clobber (match_scratch:DI 4 "=X,X,&r"))]
2393   "TARGET_POWERPC64 && TARGET_LDBRX
2394    && (REG_P (operands[0]) || REG_P (operands[1]))"
2395   "@
2396    ldbrx %0,%y1
2397    stdbrx %1,%y0
2398    #"
2399   [(set_attr "length" "4,4,36")
2400    (set_attr "type" "load,store,*")])
2401
2402 ;; Non-power7/cell, fall back to use lwbrx/stwbrx
2403 (define_insn "*bswapdi2_64bit"
2404   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,&r")
2405         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2406    (clobber (match_scratch:DI 2 "=&b,&b,&r"))
2407    (clobber (match_scratch:DI 3 "=&r,&r,&r"))
2408    (clobber (match_scratch:DI 4 "=&r,X,&r"))]
2409   "TARGET_POWERPC64 && !TARGET_LDBRX
2410    && (REG_P (operands[0]) || REG_P (operands[1]))
2411    && !(MEM_P (operands[0]) && MEM_VOLATILE_P (operands[0]))
2412    && !(MEM_P (operands[1]) && MEM_VOLATILE_P (operands[1]))"
2413   "#"
2414   [(set_attr "length" "16,12,36")])
2415
2416 (define_split
2417   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2418         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2419    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2420    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2421    (clobber (match_operand:DI 4 "gpc_reg_operand" ""))]
2422   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2423   [(const_int 0)]
2424   "
2425 {
2426   rtx dest   = operands[0];
2427   rtx src    = operands[1];
2428   rtx op2    = operands[2];
2429   rtx op3    = operands[3];
2430   rtx op4    = operands[4];
2431   rtx op3_32 = simplify_gen_subreg (SImode, op3, DImode,
2432                                     BYTES_BIG_ENDIAN ? 4 : 0);
2433   rtx op4_32 = simplify_gen_subreg (SImode, op4, DImode,
2434                                     BYTES_BIG_ENDIAN ? 4 : 0);
2435   rtx addr1;
2436   rtx addr2;
2437   rtx word_high;
2438   rtx word_low;
2439
2440   addr1 = XEXP (src, 0);
2441   if (GET_CODE (addr1) == PLUS)
2442     {
2443       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2444       if (TARGET_AVOID_XFORM)
2445         {
2446           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2447           addr2 = op2;
2448         }
2449       else
2450         addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2451     }
2452   else if (TARGET_AVOID_XFORM)
2453     {
2454       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2455       addr2 = op2;
2456     }
2457   else
2458     {
2459       emit_move_insn (op2, GEN_INT (4));
2460       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2461     }
2462
2463   if (BYTES_BIG_ENDIAN)
2464     {
2465       word_high = change_address (src, SImode, addr1);
2466       word_low  = change_address (src, SImode, addr2);
2467     }
2468   else
2469     {
2470       word_high = change_address (src, SImode, addr2);
2471       word_low  = change_address (src, SImode, addr1);
2472     }
2473
2474   emit_insn (gen_bswapsi2 (op3_32, word_low));
2475   emit_insn (gen_bswapsi2 (op4_32, word_high));
2476   emit_insn (gen_ashldi3 (dest, op3, GEN_INT (32)));
2477   emit_insn (gen_iordi3 (dest, dest, op4));
2478 }")
2479
2480 (define_split
2481   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2482         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2483    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2484    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2485    (clobber (match_operand:DI 4 "" ""))]
2486   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2487   [(const_int 0)]
2488   "
2489 {
2490   rtx dest   = operands[0];
2491   rtx src    = operands[1];
2492   rtx op2    = operands[2];
2493   rtx op3    = operands[3];
2494   rtx src_si = simplify_gen_subreg (SImode, src, DImode,
2495                                     BYTES_BIG_ENDIAN ? 4 : 0);
2496   rtx op3_si = simplify_gen_subreg (SImode, op3, DImode,
2497                                     BYTES_BIG_ENDIAN ? 4 : 0);
2498   rtx addr1;
2499   rtx addr2;
2500   rtx word_high;
2501   rtx word_low;
2502
2503   addr1 = XEXP (dest, 0);
2504   if (GET_CODE (addr1) == PLUS)
2505     {
2506       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2507       if (TARGET_AVOID_XFORM)
2508         {
2509           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2510           addr2 = op2;
2511         }
2512       else
2513         addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2514     }
2515   else if (TARGET_AVOID_XFORM)
2516     {
2517       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2518       addr2 = op2;
2519     }
2520   else
2521     {
2522       emit_move_insn (op2, GEN_INT (4));
2523       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2524     }
2525
2526   emit_insn (gen_lshrdi3 (op3, src, GEN_INT (32)));
2527   if (BYTES_BIG_ENDIAN)
2528     {
2529       word_high = change_address (dest, SImode, addr1);
2530       word_low  = change_address (dest, SImode, addr2);
2531     }
2532   else
2533     {
2534       word_high = change_address (dest, SImode, addr2);
2535       word_low  = change_address (dest, SImode, addr1);
2536     }
2537   emit_insn (gen_bswapsi2 (word_high, src_si));
2538   emit_insn (gen_bswapsi2 (word_low, op3_si));
2539 }")
2540
2541 (define_split
2542   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2543         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2544    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2545    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2546    (clobber (match_operand:DI 4 "" ""))]
2547   "TARGET_POWERPC64 && reload_completed"
2548   [(const_int 0)]
2549   "
2550 {
2551   rtx dest    = operands[0];
2552   rtx src     = operands[1];
2553   rtx op2     = operands[2];
2554   rtx op3     = operands[3];
2555   int lo_off  = BYTES_BIG_ENDIAN ? 4 : 0;
2556   rtx dest_si = simplify_gen_subreg (SImode, dest, DImode, lo_off);
2557   rtx src_si  = simplify_gen_subreg (SImode, src, DImode, lo_off);
2558   rtx op2_si  = simplify_gen_subreg (SImode, op2, DImode, lo_off);
2559   rtx op3_si  = simplify_gen_subreg (SImode, op3, DImode, lo_off);
2560
2561   emit_insn (gen_lshrdi3 (op2, src, GEN_INT (32)));
2562   emit_insn (gen_bswapsi2 (dest_si, src_si));
2563   emit_insn (gen_bswapsi2 (op3_si, op2_si));
2564   emit_insn (gen_ashldi3 (dest, dest, GEN_INT (32)));
2565   emit_insn (gen_iordi3 (dest, dest, op3));
2566 }")
2567
2568 (define_insn "bswapdi2_32bit"
2569   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,&r")
2570         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2571    (clobber (match_scratch:SI 2 "=&b,&b,X"))]
2572   "!TARGET_POWERPC64 && (REG_P (operands[0]) || REG_P (operands[1]))"
2573   "#"
2574   [(set_attr "length" "16,12,36")])
2575
2576 (define_split
2577   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2578         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2579    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2580   "!TARGET_POWERPC64 && reload_completed"
2581   [(const_int 0)]
2582   "
2583 {
2584   rtx dest  = operands[0];
2585   rtx src   = operands[1];
2586   rtx op2   = operands[2];
2587   rtx dest1 = simplify_gen_subreg (SImode, dest, DImode, 0);
2588   rtx dest2 = simplify_gen_subreg (SImode, dest, DImode, 4);
2589   rtx addr1;
2590   rtx addr2;
2591   rtx word1;
2592   rtx word2;
2593
2594   addr1 = XEXP (src, 0);
2595   if (GET_CODE (addr1) == PLUS)
2596     {
2597       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2598       if (TARGET_AVOID_XFORM)
2599         {
2600           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2601           addr2 = op2;
2602         }
2603       else
2604         addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2605     }
2606   else if (TARGET_AVOID_XFORM)
2607     {
2608       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2609       addr2 = op2;
2610     }
2611   else
2612     {
2613       emit_move_insn (op2, GEN_INT (4));
2614       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2615     }
2616
2617   word1 = change_address (src, SImode, addr1);
2618   word2 = change_address (src, SImode, addr2);
2619
2620   emit_insn (gen_bswapsi2 (dest2, word1));
2621   emit_insn (gen_bswapsi2 (dest1, word2));
2622 }")
2623
2624 (define_split
2625   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2626         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2627    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2628   "!TARGET_POWERPC64 && reload_completed"
2629   [(const_int 0)]
2630   "
2631 {
2632   rtx dest = operands[0];
2633   rtx src  = operands[1];
2634   rtx op2  = operands[2];
2635   rtx src1 = simplify_gen_subreg (SImode, src, DImode, 0);
2636   rtx src2 = simplify_gen_subreg (SImode, src, DImode, 4);
2637   rtx addr1;
2638   rtx addr2;
2639   rtx word1;
2640   rtx word2;
2641
2642   addr1 = XEXP (dest, 0);
2643   if (GET_CODE (addr1) == PLUS)
2644     {
2645       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2646       if (TARGET_AVOID_XFORM)
2647         {
2648           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2649           addr2 = op2;
2650         }
2651       else
2652         addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2653     }
2654   else if (TARGET_AVOID_XFORM)
2655     {
2656       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2657       addr2 = op2;
2658     }
2659   else
2660     {
2661       emit_move_insn (op2, GEN_INT (4));
2662       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2663     }
2664
2665   word1 = change_address (dest, SImode, addr1);
2666   word2 = change_address (dest, SImode, addr2);
2667
2668   emit_insn (gen_bswapsi2 (word2, src1));
2669   emit_insn (gen_bswapsi2 (word1, src2));
2670 }")
2671
2672 (define_split
2673   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2674         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2675    (clobber (match_operand:SI 2 "" ""))]
2676   "!TARGET_POWERPC64 && reload_completed"
2677   [(const_int 0)]
2678   "
2679 {
2680   rtx dest  = operands[0];
2681   rtx src   = operands[1];
2682   rtx src1  = simplify_gen_subreg (SImode, src, DImode, 0);
2683   rtx src2  = simplify_gen_subreg (SImode, src, DImode, 4);
2684   rtx dest1 = simplify_gen_subreg (SImode, dest, DImode, 0);
2685   rtx dest2 = simplify_gen_subreg (SImode, dest, DImode, 4);
2686
2687   emit_insn (gen_bswapsi2 (dest1, src2));
2688   emit_insn (gen_bswapsi2 (dest2, src1));
2689 }")
2690
2691 (define_insn "mulsi3"
2692   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2693         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2694                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2695   ""
2696   "@
2697    mullw %0,%1,%2
2698    mulli %0,%1,%2"
2699    [(set_attr "type" "mul")
2700     (set (attr "size")
2701       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2702                 (const_string "8")
2703              (match_operand:SI 2 "short_cint_operand" "")
2704                 (const_string "16")]
2705         (const_string "32")))])
2706
2707 (define_insn "*mulsi3_internal1"
2708   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2709         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2710                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2711                     (const_int 0)))
2712    (clobber (match_scratch:SI 3 "=r,r"))]
2713   "TARGET_32BIT"
2714   "@
2715    mullw. %3,%1,%2
2716    #"
2717   [(set_attr "type" "mul")
2718    (set_attr "dot" "yes")
2719    (set_attr "length" "4,8")])
2720
2721 (define_split
2722   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2723         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2724                              (match_operand:SI 2 "gpc_reg_operand" ""))
2725                     (const_int 0)))
2726    (clobber (match_scratch:SI 3 ""))]
2727   "TARGET_32BIT && reload_completed"
2728   [(set (match_dup 3)
2729         (mult:SI (match_dup 1) (match_dup 2)))
2730    (set (match_dup 0)
2731         (compare:CC (match_dup 3)
2732                     (const_int 0)))]
2733   "")
2734
2735 (define_insn "*mulsi3_internal2"
2736   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2737         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2738                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2739                     (const_int 0)))
2740    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2741         (mult:SI (match_dup 1) (match_dup 2)))]
2742   "TARGET_32BIT"
2743   "@
2744    mullw. %0,%1,%2
2745    #"
2746   [(set_attr "type" "mul")
2747    (set_attr "dot" "yes")
2748    (set_attr "length" "4,8")])
2749
2750 (define_split
2751   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2752         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2753                              (match_operand:SI 2 "gpc_reg_operand" ""))
2754                     (const_int 0)))
2755    (set (match_operand:SI 0 "gpc_reg_operand" "")
2756         (mult:SI (match_dup 1) (match_dup 2)))]
2757   "TARGET_32BIT && reload_completed"
2758   [(set (match_dup 0)
2759         (mult:SI (match_dup 1) (match_dup 2)))
2760    (set (match_dup 3)
2761         (compare:CC (match_dup 0)
2762                     (const_int 0)))]
2763   "")
2764
2765
2766 (define_insn "udiv<mode>3"
2767   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2768         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2769                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2770   ""
2771   "div<wd>u %0,%1,%2"
2772   [(set_attr "type" "div")
2773    (set_attr "size" "<bits>")])
2774
2775
2776 ;; For powers of two we can do srai/aze for divide and then adjust for
2777 ;; modulus.  If it isn't a power of two, force operands into register and do
2778 ;; a normal divide.
2779 (define_expand "div<mode>3"
2780   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2781         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2782                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2783   ""
2784 {
2785   if (GET_CODE (operands[2]) != CONST_INT
2786       || INTVAL (operands[2]) <= 0
2787       || exact_log2 (INTVAL (operands[2])) < 0)
2788     operands[2] = force_reg (<MODE>mode, operands[2]);
2789 })
2790
2791 (define_insn "*div<mode>3"
2792   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2793         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2794                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2795   ""
2796   "div<wd> %0,%1,%2"
2797   [(set_attr "type" "div")
2798    (set_attr "size" "<bits>")])
2799
2800 (define_expand "mod<mode>3"
2801   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
2802    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
2803    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
2804   ""
2805   "
2806 {
2807   int i;
2808   rtx temp1;
2809   rtx temp2;
2810
2811   if (GET_CODE (operands[2]) != CONST_INT
2812       || INTVAL (operands[2]) <= 0
2813       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2814     FAIL;
2815
2816   temp1 = gen_reg_rtx (<MODE>mode);
2817   temp2 = gen_reg_rtx (<MODE>mode);
2818
2819   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
2820   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
2821   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
2822   DONE;
2823 }")
2824
2825 (define_insn ""
2826   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2827         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2828                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
2829   ""
2830   "sra<wd>i %0,%1,%p2\;addze %0,%0"
2831   [(set_attr "type" "two")
2832    (set_attr "length" "8")])
2833
2834 (define_insn ""
2835   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2836         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2837                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2838                     (const_int 0)))
2839    (clobber (match_scratch:P 3 "=r,r"))]
2840   ""
2841   "@
2842    sra<wd>i %3,%1,%p2\;addze. %3,%3
2843    #"
2844   [(set_attr "type" "compare")
2845    (set_attr "length" "8,12")
2846    (set_attr "cell_micro" "not")])
2847
2848 (define_split
2849   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2850         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2851                              (match_operand:GPR 2 "exact_log2_cint_operand"
2852                               ""))
2853                     (const_int 0)))
2854    (clobber (match_scratch:GPR 3 ""))]
2855   "reload_completed"
2856   [(set (match_dup 3)
2857         (div:<MODE> (match_dup 1) (match_dup 2)))
2858    (set (match_dup 0)
2859         (compare:CC (match_dup 3)
2860                     (const_int 0)))]
2861   "")
2862
2863 (define_insn ""
2864   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2865         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2866                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2867                     (const_int 0)))
2868    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2869         (div:P (match_dup 1) (match_dup 2)))]
2870   ""
2871   "@
2872    sra<wd>i %0,%1,%p2\;addze. %0,%0
2873    #"
2874   [(set_attr "type" "compare")
2875    (set_attr "length" "8,12")
2876    (set_attr "cell_micro" "not")])
2877
2878 (define_split
2879   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2880         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2881                              (match_operand:GPR 2 "exact_log2_cint_operand"
2882                               ""))
2883                     (const_int 0)))
2884    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2885         (div:GPR (match_dup 1) (match_dup 2)))]
2886   "reload_completed"
2887   [(set (match_dup 0)
2888         (div:<MODE> (match_dup 1) (match_dup 2)))
2889    (set (match_dup 3)
2890         (compare:CC (match_dup 0)
2891                     (const_int 0)))]
2892   "")
2893 \f
2894 ;; Logical instructions
2895 ;; The logical instructions are mostly combined by using match_operator,
2896 ;; but the plain AND insns are somewhat different because there is no
2897 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2898 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2899
2900 (define_expand "andsi3"
2901   [(parallel
2902     [(set (match_operand:SI 0 "gpc_reg_operand" "")
2903           (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2904                   (match_operand:SI 2 "and_operand" "")))
2905      (clobber (match_scratch:CC 3 ""))])]
2906   ""
2907   "")
2908
2909 (define_insn "andsi3_mc"
2910   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2911         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2912                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2913    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2914   "rs6000_gen_cell_microcode"
2915   "@
2916    and %0,%1,%2
2917    rlwinm %0,%1,0,%m2,%M2
2918    andi. %0,%1,%b2
2919    andis. %0,%1,%u2"
2920   [(set_attr "type" "*,shift,logical,logical")
2921    (set_attr "dot" "no,no,yes,yes")])
2922
2923 (define_insn "andsi3_nomc"
2924   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2925         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2926                 (match_operand:SI 2 "and_operand" "?r,T")))
2927    (clobber (match_scratch:CC 3 "=X,X"))]
2928   "!rs6000_gen_cell_microcode"
2929   "@
2930    and %0,%1,%2
2931    rlwinm %0,%1,0,%m2,%M2"
2932   [(set_attr "type" "logical,shift")])
2933
2934 (define_insn "andsi3_internal0_nomc"
2935   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2936         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2937                 (match_operand:SI 2 "and_operand" "?r,T")))]
2938   "!rs6000_gen_cell_microcode"
2939   "@
2940    and %0,%1,%2
2941    rlwinm %0,%1,0,%m2,%M2"
2942   [(set_attr "type" "logical,shift")])
2943
2944
2945 ;; Note to set cr's other than cr0 we do the and immediate and then
2946 ;; the test again -- this avoids a mfcr which on the higher end
2947 ;; machines causes an execution serialization
2948
2949 (define_insn "*andsi3_internal2_mc"
2950   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2951         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2952                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2953                     (const_int 0)))
2954    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2955    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2956   "TARGET_32BIT && rs6000_gen_cell_microcode"
2957   "@
2958    and. %3,%1,%2
2959    andi. %3,%1,%b2
2960    andis. %3,%1,%u2
2961    rlwinm. %3,%1,0,%m2,%M2
2962    #
2963    #
2964    #
2965    #"
2966   [(set_attr "type" "logical,logical,logical,shift,\
2967                      compare,compare,compare,compare")
2968    (set_attr "dot" "yes")
2969    (set_attr "length" "4,4,4,4,8,8,8,8")])
2970
2971 (define_insn "*andsi3_internal3_mc"
2972   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2973         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2974                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2975                     (const_int 0)))
2976    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2977    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2978   "TARGET_64BIT && rs6000_gen_cell_microcode"
2979   "@
2980    #
2981    andi. %3,%1,%b2
2982    andis. %3,%1,%u2
2983    rlwinm. %3,%1,0,%m2,%M2
2984    #
2985    #
2986    #
2987    #"
2988   [(set_attr "type" "compare,logical,logical,shift,compare,\
2989                      compare,compare,compare")
2990    (set_attr "dot" "yes")
2991    (set_attr "length" "8,4,4,4,8,8,8,8")])
2992
2993 (define_split
2994   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2995         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2996                              (match_operand:GPR 2 "and_operand" ""))
2997                     (const_int 0)))
2998    (clobber (match_scratch:GPR 3 ""))
2999    (clobber (match_scratch:CC 4 ""))]
3000   "reload_completed"
3001   [(parallel [(set (match_dup 3)
3002                    (and:<MODE> (match_dup 1)
3003                                (match_dup 2)))
3004               (clobber (match_dup 4))])
3005    (set (match_dup 0)
3006         (compare:CC (match_dup 3)
3007                     (const_int 0)))]
3008   "")
3009
3010 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
3011 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
3012
3013 (define_split
3014   [(set (match_operand:CC 0 "cc_reg_operand" "")
3015         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3016                             (match_operand:SI 2 "gpc_reg_operand" ""))
3017                     (const_int 0)))
3018    (clobber (match_scratch:SI 3 ""))
3019    (clobber (match_scratch:CC 4 ""))]
3020   "TARGET_POWERPC64 && reload_completed"
3021   [(parallel [(set (match_dup 3)
3022                    (and:SI (match_dup 1)
3023                            (match_dup 2)))
3024               (clobber (match_dup 4))])
3025    (set (match_dup 0)
3026         (compare:CC (match_dup 3)
3027                     (const_int 0)))]
3028   "")
3029
3030 (define_insn "*andsi3_internal4"
3031   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3032         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3033                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3034                     (const_int 0)))
3035    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
3036         (and:SI (match_dup 1)
3037                 (match_dup 2)))
3038    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3039   "TARGET_32BIT && rs6000_gen_cell_microcode"
3040   "@
3041    and. %0,%1,%2
3042    andi. %0,%1,%b2
3043    andis. %0,%1,%u2
3044    rlwinm. %0,%1,0,%m2,%M2
3045    #
3046    #
3047    #
3048    #"
3049   [(set_attr "type" "logical,logical,logical,shift,\
3050                      compare,compare,compare,compare")
3051    (set_attr "dot" "yes")
3052    (set_attr "length" "4,4,4,4,8,8,8,8")])
3053
3054 (define_insn "*andsi3_internal5_mc"
3055   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3056         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3057                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3058                     (const_int 0)))
3059    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
3060         (and:SI (match_dup 1)
3061                 (match_dup 2)))
3062    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3063   "TARGET_64BIT && rs6000_gen_cell_microcode"
3064   "@
3065    #
3066    andi. %0,%1,%b2
3067    andis. %0,%1,%u2
3068    rlwinm. %0,%1,0,%m2,%M2
3069    #
3070    #
3071    #
3072    #"
3073   [(set_attr "type" "compare,logical,logical,shift,compare,\
3074                      compare,compare,compare")
3075    (set_attr "dot" "yes")
3076    (set_attr "length" "8,4,4,4,8,8,8,8")])
3077
3078 (define_split
3079   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3080         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3081                             (match_operand:SI 2 "and_operand" ""))
3082                     (const_int 0)))
3083    (set (match_operand:SI 0 "gpc_reg_operand" "")
3084         (and:SI (match_dup 1)
3085                 (match_dup 2)))
3086    (clobber (match_scratch:CC 4 ""))]
3087   "reload_completed"
3088   [(parallel [(set (match_dup 0)
3089                    (and:SI (match_dup 1)
3090                            (match_dup 2)))
3091               (clobber (match_dup 4))])
3092    (set (match_dup 3)
3093         (compare:CC (match_dup 0)
3094                     (const_int 0)))]
3095   "")
3096
3097 (define_split
3098   [(set (match_operand:CC 3 "cc_reg_operand" "")
3099         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3100                             (match_operand:SI 2 "gpc_reg_operand" ""))
3101                     (const_int 0)))
3102    (set (match_operand:SI 0 "gpc_reg_operand" "")
3103         (and:SI (match_dup 1)
3104                 (match_dup 2)))
3105    (clobber (match_scratch:CC 4 ""))]
3106   "TARGET_POWERPC64 && reload_completed"
3107   [(parallel [(set (match_dup 0)
3108                    (and:SI (match_dup 1)
3109                            (match_dup 2)))
3110               (clobber (match_dup 4))])
3111    (set (match_dup 3)
3112         (compare:CC (match_dup 0)
3113                     (const_int 0)))]
3114   "")
3115
3116 ;; Handle the PowerPC64 rlwinm corner case
3117
3118 (define_insn_and_split "*andsi3_internal6"
3119   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3120         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3121                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
3122   "TARGET_POWERPC64"
3123   "#"
3124   "TARGET_POWERPC64"
3125   [(set (match_dup 0)
3126         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
3127                 (match_dup 4)))
3128    (set (match_dup 0)
3129         (rotate:SI (match_dup 0) (match_dup 5)))]
3130   "
3131 {
3132   int mb = extract_MB (operands[2]);
3133   int me = extract_ME (operands[2]);
3134   operands[3] = GEN_INT (me + 1);
3135   operands[5] = GEN_INT (32 - (me + 1));
3136   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
3137 }"
3138   [(set_attr "length" "8")])
3139
3140 (define_expand "iorsi3"
3141   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3142         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
3143                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3144   ""
3145   "
3146 {
3147   if (GET_CODE (operands[2]) == CONST_INT
3148       && ! logical_operand (operands[2], SImode))
3149     {
3150       HOST_WIDE_INT value = INTVAL (operands[2]);
3151       rtx tmp = ((!can_create_pseudo_p ()
3152                   || rtx_equal_p (operands[0], operands[1]))
3153                  ? operands[0] : gen_reg_rtx (SImode));
3154
3155       emit_insn (gen_iorsi3 (tmp, operands[1],
3156                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3157       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3158       DONE;
3159     }
3160 }")
3161
3162 (define_expand "xorsi3"
3163   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3164         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3165                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3166   ""
3167   "
3168 {
3169   if (GET_CODE (operands[2]) == CONST_INT
3170       && ! logical_operand (operands[2], SImode))
3171     {
3172       HOST_WIDE_INT value = INTVAL (operands[2]);
3173       rtx tmp = ((!can_create_pseudo_p ()
3174                   || rtx_equal_p (operands[0], operands[1]))
3175                  ? operands[0] : gen_reg_rtx (SImode));
3176
3177       emit_insn (gen_xorsi3 (tmp, operands[1],
3178                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3179       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3180       DONE;
3181     }
3182 }")
3183
3184 (define_insn "*boolsi3_internal1"
3185   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3186         (match_operator:SI 3 "boolean_or_operator"
3187          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
3188           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
3189   ""
3190   "@
3191    %q3 %0,%1,%2
3192    %q3i %0,%1,%b2
3193    %q3is %0,%1,%u2")
3194
3195 (define_insn "*boolsi3_internal2"
3196   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3197         (compare:CC (match_operator:SI 4 "boolean_or_operator"
3198          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3199           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3200          (const_int 0)))
3201    (clobber (match_scratch:SI 3 "=r,r"))]
3202   "TARGET_32BIT"
3203   "@
3204    %q4. %3,%1,%2
3205    #"
3206   [(set_attr "type" "logical,compare")
3207    (set_attr "dot" "yes")
3208    (set_attr "length" "4,8")])
3209
3210 (define_split
3211   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3212         (compare:CC (match_operator:SI 4 "boolean_operator"
3213          [(match_operand:SI 1 "gpc_reg_operand" "")
3214           (match_operand:SI 2 "gpc_reg_operand" "")])
3215          (const_int 0)))
3216    (clobber (match_scratch:SI 3 ""))]
3217   "TARGET_32BIT && reload_completed"
3218   [(set (match_dup 3) (match_dup 4))
3219    (set (match_dup 0)
3220         (compare:CC (match_dup 3)
3221                     (const_int 0)))]
3222   "")
3223
3224 (define_insn "*boolsi3_internal3"
3225   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3226         (compare:CC (match_operator:SI 4 "boolean_operator"
3227          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3228           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3229          (const_int 0)))
3230    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3231         (match_dup 4))]
3232   "TARGET_32BIT"
3233   "@
3234    %q4. %0,%1,%2
3235    #"
3236   [(set_attr "type" "logical,compare")
3237    (set_attr "dot" "yes")
3238    (set_attr "length" "4,8")])
3239
3240 (define_split
3241   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3242         (compare:CC (match_operator:SI 4 "boolean_operator"
3243          [(match_operand:SI 1 "gpc_reg_operand" "")
3244           (match_operand:SI 2 "gpc_reg_operand" "")])
3245          (const_int 0)))
3246    (set (match_operand:SI 0 "gpc_reg_operand" "")
3247         (match_dup 4))]
3248   "TARGET_32BIT && reload_completed"
3249   [(set (match_dup 0) (match_dup 4))
3250    (set (match_dup 3)
3251         (compare:CC (match_dup 0)
3252                     (const_int 0)))]
3253   "")
3254
3255 ;; Split a logical operation that we can't do in one insn into two insns,
3256 ;; each of which does one 16-bit part.  This is used by combine.
3257
3258 (define_split
3259   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3260         (match_operator:SI 3 "boolean_or_operator"
3261          [(match_operand:SI 1 "gpc_reg_operand" "")
3262           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
3263   ""
3264   [(set (match_dup 0) (match_dup 4))
3265    (set (match_dup 0) (match_dup 5))]
3266 "
3267 {
3268   rtx i;
3269   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
3270   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3271                                 operands[1], i);
3272   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
3273   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3274                                 operands[0], i);
3275 }")
3276
3277 (define_insn "*boolcsi3_internal1"
3278   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3279         (match_operator:SI 3 "boolean_operator"
3280          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3281           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
3282   ""
3283   "%q3 %0,%2,%1")
3284
3285 (define_insn "*boolcsi3_internal2"
3286   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3287         (compare:CC (match_operator:SI 4 "boolean_operator"
3288          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3289           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3290          (const_int 0)))
3291    (clobber (match_scratch:SI 3 "=r,r"))]
3292   "TARGET_32BIT"
3293   "@
3294    %q4. %3,%2,%1
3295    #"
3296   [(set_attr "type" "compare")
3297    (set_attr "length" "4,8")])
3298
3299 (define_split
3300   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3301         (compare:CC (match_operator:SI 4 "boolean_operator"
3302          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3303           (match_operand:SI 2 "gpc_reg_operand" "")])
3304          (const_int 0)))
3305    (clobber (match_scratch:SI 3 ""))]
3306   "TARGET_32BIT && reload_completed"
3307   [(set (match_dup 3) (match_dup 4))
3308    (set (match_dup 0)
3309         (compare:CC (match_dup 3)
3310                     (const_int 0)))]
3311   "")
3312
3313 (define_insn "*boolcsi3_internal3"
3314   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3315         (compare:CC (match_operator:SI 4 "boolean_operator"
3316          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3317           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3318          (const_int 0)))
3319    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3320         (match_dup 4))]
3321   "TARGET_32BIT"
3322   "@
3323    %q4. %0,%2,%1
3324    #"
3325   [(set_attr "type" "compare")
3326    (set_attr "length" "4,8")])
3327
3328 (define_split
3329   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3330         (compare:CC (match_operator:SI 4 "boolean_operator"
3331          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3332           (match_operand:SI 2 "gpc_reg_operand" "")])
3333          (const_int 0)))
3334    (set (match_operand:SI 0 "gpc_reg_operand" "")
3335         (match_dup 4))]
3336   "TARGET_32BIT && reload_completed"
3337   [(set (match_dup 0) (match_dup 4))
3338    (set (match_dup 3)
3339         (compare:CC (match_dup 0)
3340                     (const_int 0)))]
3341   "")
3342
3343 (define_insn "*boolccsi3_internal1"
3344   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3345         (match_operator:SI 3 "boolean_operator"
3346          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3347           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3348   ""
3349   "%q3 %0,%1,%2")
3350
3351 (define_insn "*boolccsi3_internal2"
3352   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3353         (compare:CC (match_operator:SI 4 "boolean_operator"
3354          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3355           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3356          (const_int 0)))
3357    (clobber (match_scratch:SI 3 "=r,r"))]
3358   "TARGET_32BIT"
3359   "@
3360    %q4. %3,%1,%2
3361    #"
3362   [(set_attr "type" "logical,compare")
3363    (set_attr "dot" "yes")
3364    (set_attr "length" "4,8")])
3365
3366 (define_split
3367   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3368         (compare:CC (match_operator:SI 4 "boolean_operator"
3369          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3370           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3371          (const_int 0)))
3372    (clobber (match_scratch:SI 3 ""))]
3373   "TARGET_32BIT && reload_completed"
3374   [(set (match_dup 3) (match_dup 4))
3375    (set (match_dup 0)
3376         (compare:CC (match_dup 3)
3377                     (const_int 0)))]
3378   "")
3379
3380 (define_insn "*boolccsi3_internal3"
3381   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3382         (compare:CC (match_operator:SI 4 "boolean_operator"
3383          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3384           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3385          (const_int 0)))
3386    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3387         (match_dup 4))]
3388   "TARGET_32BIT"
3389   "@
3390    %q4. %0,%1,%2
3391    #"
3392   [(set_attr "type" "logical,compare")
3393    (set_attr "dot" "yes")
3394    (set_attr "length" "4,8")])
3395
3396 (define_split
3397   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3398         (compare:CC (match_operator:SI 4 "boolean_operator"
3399          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3400           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3401          (const_int 0)))
3402    (set (match_operand:SI 0 "gpc_reg_operand" "")
3403         (match_dup 4))]
3404   "TARGET_32BIT && reload_completed"
3405   [(set (match_dup 0) (match_dup 4))
3406    (set (match_dup 3)
3407         (compare:CC (match_dup 0)
3408                     (const_int 0)))]
3409   "")
3410 \f
3411 ;; Rotate and shift insns, in all their variants.  These support shifts,
3412 ;; field inserts and extracts, and various combinations thereof.
3413 (define_expand "insv"
3414   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
3415                        (match_operand:SI 1 "const_int_operand" "")
3416                        (match_operand:SI 2 "const_int_operand" ""))
3417         (match_operand 3 "gpc_reg_operand" ""))]
3418   ""
3419   "
3420 {
3421   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3422      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3423      compiler if the address of the structure is taken later.  Likewise, do
3424      not handle invalid E500 subregs.  */
3425   if (GET_CODE (operands[0]) == SUBREG
3426       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD
3427           || ((TARGET_E500_DOUBLE || TARGET_SPE)
3428               && invalid_e500_subreg (operands[0], GET_MODE (operands[0])))))
3429     FAIL;
3430
3431   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
3432     emit_insn (gen_insvdi_internal (operands[0], operands[1], operands[2],
3433                                     operands[3]));
3434   else
3435     emit_insn (gen_insvsi_internal (operands[0], operands[1], operands[2],
3436                                     operands[3]));
3437   DONE;
3438 }")
3439
3440 (define_insn "insvsi_internal"
3441   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3442                          (match_operand:SI 1 "const_int_operand" "i")
3443                          (match_operand:SI 2 "const_int_operand" "i"))
3444         (match_operand:SI 3 "gpc_reg_operand" "r"))]
3445   ""
3446   "*
3447 {
3448   int start = INTVAL (operands[2]) & 31;
3449   int size = INTVAL (operands[1]) & 31;
3450
3451   operands[4] = GEN_INT (32 - start - size);
3452   operands[1] = GEN_INT (start + size - 1);
3453   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3454 }"
3455   [(set_attr "type" "insert")])
3456
3457 (define_insn "*insvsi_internal1"
3458   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3459                          (match_operand:SI 1 "const_int_operand" "i")
3460                          (match_operand:SI 2 "const_int_operand" "i"))
3461         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3462                    (match_operand:SI 4 "const_int_operand" "i")))]
3463   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3464   "*
3465 {
3466   int shift = INTVAL (operands[4]) & 31;
3467   int start = INTVAL (operands[2]) & 31;
3468   int size = INTVAL (operands[1]) & 31;
3469
3470   operands[4] = GEN_INT (shift - start - size);
3471   operands[1] = GEN_INT (start + size - 1);
3472   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3473 }"
3474   [(set_attr "type" "insert")])
3475
3476 (define_insn "*insvsi_internal2"
3477   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3478                          (match_operand:SI 1 "const_int_operand" "i")
3479                          (match_operand:SI 2 "const_int_operand" "i"))
3480         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3481                      (match_operand:SI 4 "const_int_operand" "i")))]
3482   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3483   "*
3484 {
3485   int shift = INTVAL (operands[4]) & 31;
3486   int start = INTVAL (operands[2]) & 31;
3487   int size = INTVAL (operands[1]) & 31;
3488
3489   operands[4] = GEN_INT (32 - shift - start - size);
3490   operands[1] = GEN_INT (start + size - 1);
3491   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3492 }"
3493   [(set_attr "type" "insert")])
3494
3495 (define_insn "*insvsi_internal3"
3496   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3497                          (match_operand:SI 1 "const_int_operand" "i")
3498                          (match_operand:SI 2 "const_int_operand" "i"))
3499         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3500                      (match_operand:SI 4 "const_int_operand" "i")))]
3501   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3502   "*
3503 {
3504   int shift = INTVAL (operands[4]) & 31;
3505   int start = INTVAL (operands[2]) & 31;
3506   int size = INTVAL (operands[1]) & 31;
3507
3508   operands[4] = GEN_INT (32 - shift - start - size);
3509   operands[1] = GEN_INT (start + size - 1);
3510   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3511 }"
3512   [(set_attr "type" "insert")])
3513
3514 (define_insn "*insvsi_internal4"
3515   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3516                          (match_operand:SI 1 "const_int_operand" "i")
3517                          (match_operand:SI 2 "const_int_operand" "i"))
3518         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3519                          (match_operand:SI 4 "const_int_operand" "i")
3520                          (match_operand:SI 5 "const_int_operand" "i")))]
3521   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3522   "*
3523 {
3524   int extract_start = INTVAL (operands[5]) & 31;
3525   int extract_size = INTVAL (operands[4]) & 31;
3526   int insert_start = INTVAL (operands[2]) & 31;
3527   int insert_size = INTVAL (operands[1]) & 31;
3528
3529 /* Align extract field with insert field */
3530   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3531   operands[1] = GEN_INT (insert_start + insert_size - 1);
3532   return \"rlwimi %0,%3,%h5,%h2,%h1\";
3533 }"
3534   [(set_attr "type" "insert")])
3535
3536 ;; combine patterns for rlwimi
3537 (define_insn "*insvsi_internal5"
3538   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3539         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3540                         (match_operand:SI 1 "mask_operand" "i"))
3541                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3542                                      (match_operand:SI 2 "const_int_operand" "i"))
3543                         (match_operand:SI 5 "mask_operand" "i"))))]
3544   "INTVAL(operands[1]) == ~INTVAL(operands[5])"
3545   "*
3546 {
3547  int me = extract_ME(operands[5]);
3548  int mb = extract_MB(operands[5]);
3549  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3550  operands[2] = GEN_INT(mb);
3551  operands[1] = GEN_INT(me);
3552  return \"rlwimi %0,%3,%h4,%h2,%h1\";
3553 }"
3554   [(set_attr "type" "insert")])
3555
3556 (define_insn "*insvsi_internal6"
3557   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3558         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3559                                      (match_operand:SI 2 "const_int_operand" "i"))
3560                         (match_operand:SI 5 "mask_operand" "i"))
3561                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3562                         (match_operand:SI 1 "mask_operand" "i"))))]
3563   "INTVAL(operands[1]) == ~INTVAL(operands[5])"
3564   "*
3565 {
3566  int me = extract_ME(operands[5]);
3567  int mb = extract_MB(operands[5]);
3568  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3569  operands[2] = GEN_INT(mb);
3570  operands[1] = GEN_INT(me);
3571  return \"rlwimi %0,%3,%h4,%h2,%h1\";
3572 }"
3573   [(set_attr "type" "insert")])
3574
3575 (define_insn "insvdi_internal"
3576   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3577                          (match_operand:SI 1 "const_int_operand" "i")
3578                          (match_operand:SI 2 "const_int_operand" "i"))
3579         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3580   "TARGET_POWERPC64"
3581   "*
3582 {
3583   int start = INTVAL (operands[2]) & 63;
3584   int size = INTVAL (operands[1]) & 63;
3585
3586   operands[1] = GEN_INT (64 - start - size);
3587   return \"rldimi %0,%3,%H1,%H2\";
3588 }"
3589   [(set_attr "type" "insert")
3590    (set_attr "size" "64")])
3591
3592 (define_insn "*insvdi_internal2"
3593   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3594                          (match_operand:SI 1 "const_int_operand" "i")
3595                          (match_operand:SI 2 "const_int_operand" "i"))
3596         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3597                      (match_operand:SI 4 "const_int_operand" "i")))]
3598   "TARGET_POWERPC64
3599    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3600   "*
3601 {
3602   int shift = INTVAL (operands[4]) & 63;
3603   int start = (INTVAL (operands[2]) & 63) - 32;
3604   int size = INTVAL (operands[1]) & 63;
3605
3606   operands[4] = GEN_INT (64 - shift - start - size);
3607   operands[2] = GEN_INT (start);
3608   operands[1] = GEN_INT (start + size - 1);
3609   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3610 }")
3611
3612 (define_insn "*insvdi_internal3"
3613   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3614                          (match_operand:SI 1 "const_int_operand" "i")
3615                          (match_operand:SI 2 "const_int_operand" "i"))
3616         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3617                      (match_operand:SI 4 "const_int_operand" "i")))]
3618   "TARGET_POWERPC64
3619    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3620   "*
3621 {
3622   int shift = INTVAL (operands[4]) & 63;
3623   int start = (INTVAL (operands[2]) & 63) - 32;
3624   int size = INTVAL (operands[1]) & 63;
3625
3626   operands[4] = GEN_INT (64 - shift - start - size);
3627   operands[2] = GEN_INT (start);
3628   operands[1] = GEN_INT (start + size - 1);
3629   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3630 }")
3631
3632 (define_expand "extzv"
3633   [(set (match_operand 0 "gpc_reg_operand" "")
3634         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3635                        (match_operand:SI 2 "const_int_operand" "")
3636                        (match_operand:SI 3 "const_int_operand" "")))]
3637   ""
3638   "
3639 {
3640   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3641      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3642      compiler if the address of the structure is taken later.  */
3643   if (GET_CODE (operands[0]) == SUBREG
3644       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3645     FAIL;
3646
3647   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3648     emit_insn (gen_extzvdi_internal (operands[0], operands[1], operands[2],
3649                                      operands[3]));
3650   else
3651     emit_insn (gen_extzvsi_internal (operands[0], operands[1], operands[2],
3652                                      operands[3]));
3653   DONE;
3654 }")
3655
3656 (define_insn "extzvsi_internal"
3657   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3658         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3659                          (match_operand:SI 2 "const_int_operand" "i")
3660                          (match_operand:SI 3 "const_int_operand" "i")))]
3661   ""
3662   "*
3663 {
3664   int start = INTVAL (operands[3]) & 31;
3665   int size = INTVAL (operands[2]) & 31;
3666
3667   if (start + size >= 32)
3668     operands[3] = const0_rtx;
3669   else
3670     operands[3] = GEN_INT (start + size);
3671   return \"rlwinm %0,%1,%3,%s2,31\";
3672 }"
3673   [(set_attr "type" "shift")])
3674
3675 (define_insn "*extzvsi_internal1"
3676   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3677         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3678                          (match_operand:SI 2 "const_int_operand" "i,i")
3679                          (match_operand:SI 3 "const_int_operand" "i,i"))
3680                     (const_int 0)))
3681    (clobber (match_scratch:SI 4 "=r,r"))]
3682   ""
3683   "*
3684 {
3685   int start = INTVAL (operands[3]) & 31;
3686   int size = INTVAL (operands[2]) & 31;
3687
3688   /* Force split for non-cc0 compare.  */
3689   if (which_alternative == 1)
3690      return \"#\";
3691
3692   /* If the bit-field being tested fits in the upper or lower half of a
3693      word, it is possible to use andiu. or andil. to test it.  This is
3694      useful because the condition register set-use delay is smaller for
3695      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3696      position is 0 because the LT and GT bits may be set wrong.  */
3697
3698   if ((start > 0 && start + size <= 16) || start >= 16)
3699     {
3700       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3701                               - (1 << (16 - (start & 15) - size))));
3702       if (start < 16)
3703         return \"andis. %4,%1,%3\";
3704       else
3705         return \"andi. %4,%1,%3\";
3706     }
3707
3708   if (start + size >= 32)
3709     operands[3] = const0_rtx;
3710   else
3711     operands[3] = GEN_INT (start + size);
3712   return \"rlwinm. %4,%1,%3,%s2,31\";
3713 }"
3714   [(set_attr "type" "shift")
3715    (set_attr "dot" "yes")
3716    (set_attr "length" "4,8")])
3717
3718 (define_split
3719   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3720         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3721                          (match_operand:SI 2 "const_int_operand" "")
3722                          (match_operand:SI 3 "const_int_operand" ""))
3723                     (const_int 0)))
3724    (clobber (match_scratch:SI 4 ""))]
3725   "reload_completed"
3726   [(set (match_dup 4)
3727         (zero_extract:SI (match_dup 1) (match_dup 2)
3728                          (match_dup 3)))
3729    (set (match_dup 0)
3730         (compare:CC (match_dup 4)
3731                     (const_int 0)))]
3732   "")
3733
3734 (define_insn "*extzvsi_internal2"
3735   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3736         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3737                          (match_operand:SI 2 "const_int_operand" "i,i")
3738                          (match_operand:SI 3 "const_int_operand" "i,i"))
3739                     (const_int 0)))
3740    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3741         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3742   ""
3743   "*
3744 {
3745   int start = INTVAL (operands[3]) & 31;
3746   int size = INTVAL (operands[2]) & 31;
3747
3748   /* Force split for non-cc0 compare.  */
3749   if (which_alternative == 1)
3750      return \"#\";
3751
3752   /* Since we are using the output value, we can't ignore any need for
3753      a shift.  The bit-field must end at the LSB.  */
3754   if (start >= 16 && start + size == 32)
3755     {
3756       operands[3] = GEN_INT ((1 << size) - 1);
3757       return \"andi. %0,%1,%3\";
3758     }
3759
3760   if (start + size >= 32)
3761     operands[3] = const0_rtx;
3762   else
3763     operands[3] = GEN_INT (start + size);
3764   return \"rlwinm. %0,%1,%3,%s2,31\";
3765 }"
3766   [(set_attr "type" "shift")
3767    (set_attr "dot" "yes")
3768    (set_attr "length" "4,8")])
3769
3770 (define_split
3771   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
3772         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3773                          (match_operand:SI 2 "const_int_operand" "")
3774                          (match_operand:SI 3 "const_int_operand" ""))
3775                     (const_int 0)))
3776    (set (match_operand:SI 0 "gpc_reg_operand" "")
3777         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3778   "reload_completed"
3779   [(set (match_dup 0)
3780         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3781    (set (match_dup 4)
3782         (compare:CC (match_dup 0)
3783                     (const_int 0)))]
3784   "")
3785
3786 (define_insn "extzvdi_internal"
3787   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3788         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3789                          (match_operand:SI 2 "const_int_operand" "i")
3790                          (match_operand:SI 3 "const_int_operand" "i")))]
3791   "TARGET_POWERPC64"
3792   "*
3793 {
3794   int start = INTVAL (operands[3]) & 63;
3795   int size = INTVAL (operands[2]) & 63;
3796
3797   if (start + size >= 64)
3798     operands[3] = const0_rtx;
3799   else
3800     operands[3] = GEN_INT (start + size);
3801   operands[2] = GEN_INT (64 - size);
3802   return \"rldicl %0,%1,%3,%2\";
3803 }"
3804   [(set_attr "type" "shift")])
3805
3806 (define_insn "*extzvdi_internal1"
3807   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3808         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3809                          (match_operand:SI 2 "const_int_operand" "i")
3810                          (match_operand:SI 3 "const_int_operand" "i"))
3811                     (const_int 0)))
3812    (clobber (match_scratch:DI 4 "=r"))]
3813   "TARGET_64BIT && rs6000_gen_cell_microcode"
3814   "*
3815 {
3816   int start = INTVAL (operands[3]) & 63;
3817   int size = INTVAL (operands[2]) & 63;
3818
3819   if (start + size >= 64)
3820     operands[3] = const0_rtx;
3821   else
3822     operands[3] = GEN_INT (start + size);
3823   operands[2] = GEN_INT (64 - size);
3824   return \"rldicl. %4,%1,%3,%2\";
3825 }"
3826   [(set_attr "type" "shift")
3827    (set_attr "dot" "yes")])
3828
3829 (define_insn "*extzvdi_internal2"
3830   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3831         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3832                          (match_operand:SI 2 "const_int_operand" "i")
3833                          (match_operand:SI 3 "const_int_operand" "i"))
3834                     (const_int 0)))
3835    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3836         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3837   "TARGET_64BIT && rs6000_gen_cell_microcode"
3838   "*
3839 {
3840   int start = INTVAL (operands[3]) & 63;
3841   int size = INTVAL (operands[2]) & 63;
3842
3843   if (start + size >= 64)
3844     operands[3] = const0_rtx;
3845   else
3846     operands[3] = GEN_INT (start + size);
3847   operands[2] = GEN_INT (64 - size);
3848   return \"rldicl. %0,%1,%3,%2\";
3849 }"
3850   [(set_attr "type" "shift")
3851    (set_attr "dot" "yes")])
3852
3853 (define_insn "rotlsi3"
3854   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3855         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3856                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
3857   ""
3858   "@
3859    rlwnm %0,%1,%2,0xffffffff
3860    rlwinm %0,%1,%h2,0xffffffff"
3861   [(set_attr "type" "shift")
3862    (set_attr "var_shift" "yes,no")])
3863
3864 (define_insn "*rotlsi3_64"
3865   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3866         (zero_extend:DI
3867             (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3868                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
3869   "TARGET_64BIT"
3870   "@
3871    rlwnm %0,%1,%2,0xffffffff
3872    rlwinm %0,%1,%h2,0xffffffff"
3873   [(set_attr "type" "shift")
3874    (set_attr "var_shift" "yes,no")])
3875
3876 (define_insn "*rotlsi3_internal2"
3877   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3878         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3879                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3880                     (const_int 0)))
3881    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
3882   ""
3883   "@
3884    rlwnm. %3,%1,%2,0xffffffff
3885    rlwinm. %3,%1,%h2,0xffffffff
3886    #
3887    #"
3888   [(set_attr "type" "shift")
3889    (set_attr "var_shift" "yes,no,yes,no")
3890    (set_attr "dot" "yes")
3891    (set_attr "length" "4,4,8,8")])
3892
3893 (define_split
3894   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3895         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3896                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3897                     (const_int 0)))
3898    (clobber (match_scratch:SI 3 ""))]
3899   "reload_completed"
3900   [(set (match_dup 3)
3901         (rotate:SI (match_dup 1) (match_dup 2)))
3902    (set (match_dup 0)
3903         (compare:CC (match_dup 3)
3904                     (const_int 0)))]
3905   "")
3906
3907 (define_insn "*rotlsi3_internal3"
3908   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3909         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3910                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3911                     (const_int 0)))
3912    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3913         (rotate:SI (match_dup 1) (match_dup 2)))]
3914   ""
3915   "@
3916    rlwnm. %0,%1,%2,0xffffffff
3917    rlwinm. %0,%1,%h2,0xffffffff
3918    #
3919    #"
3920   [(set_attr "type" "shift")
3921    (set_attr "var_shift" "yes,no,yes,no")
3922    (set_attr "dot" "yes")
3923    (set_attr "length" "4,4,8,8")])
3924
3925 (define_split
3926   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3927         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3928                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3929                     (const_int 0)))
3930    (set (match_operand:SI 0 "gpc_reg_operand" "")
3931         (rotate:SI (match_dup 1) (match_dup 2)))]
3932   "reload_completed"
3933   [(set (match_dup 0)
3934         (rotate:SI (match_dup 1) (match_dup 2)))
3935    (set (match_dup 3)
3936         (compare:CC (match_dup 0)
3937                     (const_int 0)))]
3938   "")
3939
3940 (define_insn "*rotlsi3_internal4"
3941   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3942         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3943                            (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
3944                 (match_operand:SI 3 "mask_operand" "n,n")))]
3945   ""
3946   "@
3947    rlwnm %0,%1,%2,%m3,%M3
3948    rlwinm %0,%1,%h2,%m3,%M3"
3949   [(set_attr "type" "shift")
3950    (set_attr "var_shift" "yes,no")])
3951
3952 (define_insn "*rotlsi3_internal5"
3953   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3954         (compare:CC (and:SI
3955                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3956                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3957                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
3958                     (const_int 0)))
3959    (clobber (match_scratch:SI 4 "=r,r,r,r"))]
3960   ""
3961   "@
3962    rlwnm. %4,%1,%2,%m3,%M3
3963    rlwinm. %4,%1,%h2,%m3,%M3
3964    #
3965    #"
3966   [(set_attr "type" "shift")
3967    (set_attr "var_shift" "yes,no,yes,no")
3968    (set_attr "dot" "yes")
3969    (set_attr "length" "4,4,8,8")])
3970
3971 (define_split
3972   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3973         (compare:CC (and:SI
3974                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3975                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3976                      (match_operand:SI 3 "mask_operand" ""))
3977                     (const_int 0)))
3978    (clobber (match_scratch:SI 4 ""))]
3979   "reload_completed"
3980   [(set (match_dup 4)
3981         (and:SI (rotate:SI (match_dup 1)
3982                                 (match_dup 2))
3983                      (match_dup 3)))
3984    (set (match_dup 0)
3985         (compare:CC (match_dup 4)
3986                     (const_int 0)))]
3987   "")
3988
3989 (define_insn "*rotlsi3_internal6"
3990   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
3991         (compare:CC (and:SI
3992                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3993                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3994                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
3995                     (const_int 0)))
3996    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3997         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3998   ""
3999   "@
4000    rlwnm. %0,%1,%2,%m3,%M3
4001    rlwinm. %0,%1,%h2,%m3,%M3
4002    #
4003    #"
4004   [(set_attr "type" "shift")
4005    (set_attr "var_shift" "yes,no,yes,no")
4006    (set_attr "dot" "yes")
4007    (set_attr "length" "4,4,8,8")])
4008
4009 (define_split
4010   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4011         (compare:CC (and:SI
4012                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4013                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
4014                      (match_operand:SI 3 "mask_operand" ""))
4015                     (const_int 0)))
4016    (set (match_operand:SI 0 "gpc_reg_operand" "")
4017         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4018   "reload_completed"
4019   [(set (match_dup 0)
4020         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4021    (set (match_dup 4)
4022         (compare:CC (match_dup 0)
4023                     (const_int 0)))]
4024   "")
4025
4026 (define_insn "*rotlsi3_internal7le"
4027   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4028         (zero_extend:SI
4029          (subreg:QI
4030           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4031                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
4032   "!BYTES_BIG_ENDIAN"
4033   "rlw%I2nm %0,%1,%h2,0xff"
4034   [(set (attr "cell_micro")
4035      (if_then_else (match_operand:SI 2 "const_int_operand" "")
4036         (const_string "not")
4037         (const_string "always")))
4038    (set_attr "type" "shift")])
4039
4040 (define_insn "*rotlsi3_internal7be"
4041   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4042         (zero_extend:SI
4043          (subreg:QI
4044           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4045                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 3)))]
4046   "BYTES_BIG_ENDIAN"
4047   "rlw%I2nm %0,%1,%h2,0xff"
4048   [(set (attr "cell_micro")
4049      (if_then_else (match_operand:SI 2 "const_int_operand" "")
4050         (const_string "not")
4051         (const_string "always")))
4052    (set_attr "type" "shift")])
4053
4054 (define_insn "*rotlsi3_internal8le"
4055   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4056         (compare:CC (zero_extend:SI
4057                      (subreg:QI
4058                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4059                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4060                     (const_int 0)))
4061    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4062   "!BYTES_BIG_ENDIAN"
4063   "@
4064    rlwnm. %3,%1,%2,0xff
4065    rlwinm. %3,%1,%h2,0xff
4066    #
4067    #"
4068   [(set_attr "type" "shift")
4069    (set_attr "var_shift" "yes,no,yes,no")
4070    (set_attr "dot" "yes")
4071    (set_attr "length" "4,4,8,8")])
4072
4073 (define_insn "*rotlsi3_internal8be"
4074   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4075         (compare:CC (zero_extend:SI
4076                      (subreg:QI
4077                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4078                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 3))
4079                     (const_int 0)))
4080    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4081   "BYTES_BIG_ENDIAN"
4082   "@
4083    rlwnm. %3,%1,%2,0xff
4084    rlwinm. %3,%1,%h2,0xff
4085    #
4086    #"
4087   [(set_attr "type" "shift")
4088    (set_attr "var_shift" "yes,no,yes,no")
4089    (set_attr "dot" "yes")
4090    (set_attr "length" "4,4,8,8")])
4091
4092 (define_split
4093   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4094         (compare:CC (zero_extend:SI
4095                      (subreg:QI
4096                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4097                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4098                     (const_int 0)))
4099    (clobber (match_scratch:SI 3 ""))]
4100   "!BYTES_BIG_ENDIAN && reload_completed"
4101   [(set (match_dup 3)
4102         (zero_extend:SI (subreg:QI
4103                       (rotate:SI (match_dup 1)
4104                                  (match_dup 2)) 0)))
4105    (set (match_dup 0)
4106         (compare:CC (match_dup 3)
4107                     (const_int 0)))]
4108   "")
4109
4110 (define_split
4111   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4112         (compare:CC (zero_extend:SI
4113                      (subreg:QI
4114                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4115                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 3))
4116                     (const_int 0)))
4117    (clobber (match_scratch:SI 3 ""))]
4118   "BYTES_BIG_ENDIAN && reload_completed"
4119   [(set (match_dup 3)
4120         (zero_extend:SI (subreg:QI
4121                       (rotate:SI (match_dup 1)
4122                                  (match_dup 2)) 3)))
4123    (set (match_dup 0)
4124         (compare:CC (match_dup 3)
4125                     (const_int 0)))]
4126   "")
4127
4128 (define_insn "*rotlsi3_internal9le"
4129   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4130         (compare:CC (zero_extend:SI
4131                      (subreg:QI
4132                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4133                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4134                     (const_int 0)))
4135    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4136         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4137   "!BYTES_BIG_ENDIAN"
4138   "@
4139    rlwnm. %0,%1,%2,0xff
4140    rlwinm. %0,%1,%h2,0xff
4141    #
4142    #"
4143   [(set_attr "type" "shift")
4144    (set_attr "var_shift" "yes,no,yes,no")
4145    (set_attr "dot" "yes")
4146    (set_attr "length" "4,4,8,8")])
4147
4148 (define_insn "*rotlsi3_internal9be"
4149   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4150         (compare:CC (zero_extend:SI
4151                      (subreg:QI
4152                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4153                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 3))
4154                     (const_int 0)))
4155    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4156         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 3)))]
4157   "BYTES_BIG_ENDIAN"
4158   "@
4159    rlwnm. %0,%1,%2,0xff
4160    rlwinm. %0,%1,%h2,0xff
4161    #
4162    #"
4163   [(set_attr "type" "shift")
4164    (set_attr "var_shift" "yes,no,yes,no")
4165    (set_attr "dot" "yes")
4166    (set_attr "length" "4,4,8,8")])
4167
4168 (define_split
4169   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4170         (compare:CC (zero_extend:SI
4171                      (subreg:QI
4172                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4173                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4174                     (const_int 0)))
4175    (set (match_operand:SI 0 "gpc_reg_operand" "")
4176         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4177   "!BYTES_BIG_ENDIAN && reload_completed"
4178   [(set (match_dup 0)
4179         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4180    (set (match_dup 3)
4181         (compare:CC (match_dup 0)
4182                     (const_int 0)))]
4183   "")
4184
4185 (define_split
4186   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4187         (compare:CC (zero_extend:SI
4188                      (subreg:QI
4189                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4190                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 3))
4191                     (const_int 0)))
4192    (set (match_operand:SI 0 "gpc_reg_operand" "")
4193         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 3)))]
4194   "BYTES_BIG_ENDIAN && reload_completed"
4195   [(set (match_dup 0)
4196         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 3)))
4197    (set (match_dup 3)
4198         (compare:CC (match_dup 0)
4199                     (const_int 0)))]
4200   "")
4201
4202 (define_insn "*rotlsi3_internal10le"
4203   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4204         (zero_extend:SI
4205          (subreg:HI
4206           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4207                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 0)))]
4208   "!BYTES_BIG_ENDIAN"
4209   "@
4210    rlwnm %0,%1,%2,0xffff
4211    rlwinm %0,%1,%h2,0xffff"
4212   [(set_attr "type" "shift")
4213    (set_attr "var_shift" "yes,no")])
4214
4215 (define_insn "*rotlsi3_internal10be"
4216   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4217         (zero_extend:SI
4218          (subreg:HI
4219           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4220                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 2)))]
4221   "BYTES_BIG_ENDIAN"
4222   "@
4223    rlwnm %0,%1,%2,0xffff
4224    rlwinm %0,%1,%h2,0xffff"
4225   [(set_attr "type" "shift")
4226    (set_attr "var_shift" "yes,no")])
4227
4228 (define_insn "*rotlsi3_internal11le"
4229   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4230         (compare:CC (zero_extend:SI
4231                      (subreg:HI
4232                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4233                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4234                     (const_int 0)))
4235    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4236   "!BYTES_BIG_ENDIAN"
4237   "@
4238    rlwnm. %3,%1,%2,0xffff
4239    rlwinm. %3,%1,%h2,0xffff
4240    #
4241    #"
4242   [(set_attr "type" "shift")
4243    (set_attr "var_shift" "yes,no,yes,no")
4244    (set_attr "dot" "yes")
4245    (set_attr "length" "4,4,8,8")])
4246
4247 (define_insn "*rotlsi3_internal11be"
4248   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4249         (compare:CC (zero_extend:SI
4250                      (subreg:HI
4251                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4252                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 2))
4253                     (const_int 0)))
4254    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4255   "BYTES_BIG_ENDIAN"
4256   "@
4257    rlwnm. %3,%1,%2,0xffff
4258    rlwinm. %3,%1,%h2,0xffff
4259    #
4260    #"
4261   [(set_attr "type" "shift")
4262    (set_attr "var_shift" "yes,no,yes,no")
4263    (set_attr "dot" "yes")
4264    (set_attr "length" "4,4,8,8")])
4265
4266 (define_split
4267   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4268         (compare:CC (zero_extend:SI
4269                      (subreg:HI
4270                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4271                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4272                     (const_int 0)))
4273    (clobber (match_scratch:SI 3 ""))]
4274   "!BYTES_BIG_ENDIAN && reload_completed"
4275   [(set (match_dup 3)
4276         (zero_extend:SI (subreg:HI
4277                       (rotate:SI (match_dup 1)
4278                                  (match_dup 2)) 0)))
4279    (set (match_dup 0)
4280         (compare:CC (match_dup 3)
4281                     (const_int 0)))]
4282   "")
4283
4284 (define_split
4285   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4286         (compare:CC (zero_extend:SI
4287                      (subreg:HI
4288                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4289                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 2))
4290                     (const_int 0)))
4291    (clobber (match_scratch:SI 3 ""))]
4292   "BYTES_BIG_ENDIAN && reload_completed"
4293   [(set (match_dup 3)
4294         (zero_extend:SI (subreg:HI
4295                       (rotate:SI (match_dup 1)
4296                                  (match_dup 2)) 2)))
4297    (set (match_dup 0)
4298         (compare:CC (match_dup 3)
4299                     (const_int 0)))]
4300   "")
4301
4302 (define_insn "*rotlsi3_internal12le"
4303   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4304         (compare:CC (zero_extend:SI
4305                      (subreg:HI
4306                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4307                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4308                     (const_int 0)))
4309    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4310         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4311   "!BYTES_BIG_ENDIAN"
4312   "@
4313    rlwnm. %0,%1,%2,0xffff
4314    rlwinm. %0,%1,%h2,0xffff
4315    #
4316    #"
4317   [(set_attr "type" "shift")
4318    (set_attr "var_shift" "yes,no,yes,no")
4319    (set_attr "dot" "yes")
4320    (set_attr "length" "4,4,8,8")])
4321
4322 (define_insn "*rotlsi3_internal12be"
4323   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4324         (compare:CC (zero_extend:SI
4325                      (subreg:HI
4326                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4327                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 2))
4328                     (const_int 0)))
4329    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4330         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 2)))]
4331   "BYTES_BIG_ENDIAN"
4332   "@
4333    rlwnm. %0,%1,%2,0xffff
4334    rlwinm. %0,%1,%h2,0xffff
4335    #
4336    #"
4337   [(set_attr "type" "shift")
4338    (set_attr "var_shift" "yes,no,yes,no")
4339    (set_attr "dot" "yes")
4340    (set_attr "length" "4,4,8,8")])
4341
4342 (define_split
4343   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4344         (compare:CC (zero_extend:SI
4345                      (subreg:HI
4346                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4347                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4348                     (const_int 0)))
4349    (set (match_operand:SI 0 "gpc_reg_operand" "")
4350         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4351   "!BYTES_BIG_ENDIAN && reload_completed"
4352   [(set (match_dup 0)
4353         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4354    (set (match_dup 3)
4355         (compare:CC (match_dup 0)
4356                     (const_int 0)))]
4357   "")
4358
4359 (define_split
4360   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4361         (compare:CC (zero_extend:SI
4362                      (subreg:HI
4363                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4364                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 2))
4365                     (const_int 0)))
4366    (set (match_operand:SI 0 "gpc_reg_operand" "")
4367         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 2)))]
4368   "BYTES_BIG_ENDIAN && reload_completed"
4369   [(set (match_dup 0)
4370         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 2)))
4371    (set (match_dup 3)
4372         (compare:CC (match_dup 0)
4373                     (const_int 0)))]
4374   "")
4375
4376 (define_insn "ashlsi3"
4377   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4378         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4379                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4380   ""
4381   "@
4382    slw %0,%1,%2
4383    slwi %0,%1,%h2"
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,i"))))]
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 ""
4400   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4401         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4402                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4403                     (const_int 0)))
4404    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4405   "TARGET_32BIT"
4406   "@
4407    slw. %3,%1,%2
4408    slwi. %3,%1,%h2
4409    #
4410    #"
4411   [(set_attr "type" "shift")
4412    (set_attr "var_shift" "yes,no,yes,no")
4413    (set_attr "dot" "yes")
4414    (set_attr "length" "4,4,8,8")])
4415
4416 (define_split
4417   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4418         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4419                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4420                     (const_int 0)))
4421    (clobber (match_scratch:SI 3 ""))]
4422   "TARGET_32BIT && reload_completed"
4423   [(set (match_dup 3)
4424         (ashift:SI (match_dup 1) (match_dup 2)))
4425    (set (match_dup 0)
4426         (compare:CC (match_dup 3)
4427                     (const_int 0)))]
4428   "")
4429
4430 (define_insn ""
4431   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4432         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4433                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4434                     (const_int 0)))
4435    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4436         (ashift:SI (match_dup 1) (match_dup 2)))]
4437   "TARGET_32BIT"
4438   "@
4439    slw. %0,%1,%2
4440    slwi. %0,%1,%h2
4441    #
4442    #"
4443   [(set_attr "type" "shift")
4444    (set_attr "var_shift" "yes,no,yes,no")
4445    (set_attr "dot" "yes")
4446    (set_attr "length" "4,4,8,8")])
4447
4448 (define_split
4449   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4450         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4451                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4452                     (const_int 0)))
4453    (set (match_operand:SI 0 "gpc_reg_operand" "")
4454         (ashift:SI (match_dup 1) (match_dup 2)))]
4455   "TARGET_32BIT && reload_completed"
4456   [(set (match_dup 0)
4457         (ashift:SI (match_dup 1) (match_dup 2)))
4458    (set (match_dup 3)
4459         (compare:CC (match_dup 0)
4460                     (const_int 0)))]
4461   "")
4462
4463 (define_insn "rlwinm"
4464   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4465         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4466                            (match_operand:SI 2 "const_int_operand" "i"))
4467                 (match_operand:SI 3 "mask_operand" "n")))]
4468   "includes_lshift_p (operands[2], operands[3])"
4469   "rlwinm %0,%1,%h2,%m3,%M3"
4470   [(set_attr "type" "shift")])
4471
4472 (define_insn ""
4473   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4474         (compare:CC
4475          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4476                             (match_operand:SI 2 "const_int_operand" "i,i"))
4477                  (match_operand:SI 3 "mask_operand" "n,n"))
4478          (const_int 0)))
4479    (clobber (match_scratch:SI 4 "=r,r"))]
4480   "includes_lshift_p (operands[2], operands[3])"
4481   "@
4482    rlwinm. %4,%1,%h2,%m3,%M3
4483    #"
4484   [(set_attr "type" "shift")
4485    (set_attr "dot" "yes")
4486    (set_attr "length" "4,8")])
4487
4488 (define_split
4489   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4490         (compare:CC
4491          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4492                             (match_operand:SI 2 "const_int_operand" ""))
4493                  (match_operand:SI 3 "mask_operand" ""))
4494          (const_int 0)))
4495    (clobber (match_scratch:SI 4 ""))]
4496   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4497   [(set (match_dup 4)
4498         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
4499                  (match_dup 3)))
4500    (set (match_dup 0)
4501         (compare:CC (match_dup 4)
4502                     (const_int 0)))]
4503   "")
4504
4505 (define_insn ""
4506   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4507         (compare:CC
4508          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4509                             (match_operand:SI 2 "const_int_operand" "i,i"))
4510                  (match_operand:SI 3 "mask_operand" "n,n"))
4511          (const_int 0)))
4512    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4513         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4514   "includes_lshift_p (operands[2], operands[3])"
4515   "@
4516    rlwinm. %0,%1,%h2,%m3,%M3
4517    #"
4518   [(set_attr "type" "shift")
4519    (set_attr "dot" "yes")
4520    (set_attr "length" "4,8")])
4521
4522 (define_split
4523   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4524         (compare:CC
4525          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4526                             (match_operand:SI 2 "const_int_operand" ""))
4527                  (match_operand:SI 3 "mask_operand" ""))
4528          (const_int 0)))
4529    (set (match_operand:SI 0 "gpc_reg_operand" "")
4530         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4531   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4532   [(set (match_dup 0)
4533         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4534    (set (match_dup 4)
4535         (compare:CC (match_dup 0)
4536                     (const_int 0)))]
4537   "")
4538
4539 (define_insn "lshrsi3"
4540   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4541         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4542                      (match_operand:SI 2 "reg_or_cint_operand" "O,r,i")))]
4543   ""
4544   "@
4545   mr %0,%1
4546   srw %0,%1,%2
4547   srwi %0,%1,%h2"
4548   [(set_attr "type" "integer,shift,shift")
4549    (set_attr "var_shift" "no,yes,no")])
4550
4551 (define_insn "*lshrsi3_64"
4552   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4553         (zero_extend:DI
4554             (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4555                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4556   "TARGET_POWERPC64"
4557   "@
4558   srw %0,%1,%2
4559   srwi %0,%1,%h2"
4560   [(set_attr "type" "shift")
4561    (set_attr "var_shift" "yes,no")])
4562
4563 (define_insn ""
4564   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4565         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4566                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
4567                     (const_int 0)))
4568    (clobber (match_scratch:SI 3 "=X,r,r,X,r,r"))]
4569   "TARGET_32BIT"
4570   "@
4571    mr. %1,%1
4572    srw. %3,%1,%2
4573    srwi. %3,%1,%h2
4574    #
4575    #
4576    #"
4577   [(set_attr "type" "logical,shift,shift,shift,shift,shift")
4578    (set_attr "var_shift" "no,yes,no,no,yes,no")
4579    (set_attr "dot" "yes")
4580    (set_attr "length" "4,4,4,8,8,8")])
4581
4582 (define_split
4583   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4584         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4585                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4586                     (const_int 0)))
4587    (clobber (match_scratch:SI 3 ""))]
4588   "TARGET_32BIT && reload_completed"
4589   [(set (match_dup 3)
4590         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4591    (set (match_dup 0)
4592         (compare:CC (match_dup 3)
4593                     (const_int 0)))]
4594   "")
4595
4596 (define_insn ""
4597   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4598         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4599                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
4600                     (const_int 0)))
4601    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
4602         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4603   "TARGET_32BIT"
4604   "@
4605    mr. %0,%1
4606    srw. %0,%1,%2
4607    srwi. %0,%1,%h2
4608    #
4609    #
4610    #"
4611   [(set_attr "type" "logical,shift,shift,shift,shift,shift")
4612    (set_attr "var_shift" "no,yes,no,no,yes,no")
4613    (set_attr "dot" "yes")
4614    (set_attr "length" "4,4,4,8,8,8")])
4615
4616 (define_split
4617   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4618         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4619                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4620                     (const_int 0)))
4621    (set (match_operand:SI 0 "gpc_reg_operand" "")
4622         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4623   "TARGET_32BIT && reload_completed"
4624   [(set (match_dup 0)
4625         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4626    (set (match_dup 3)
4627         (compare:CC (match_dup 0)
4628                     (const_int 0)))]
4629   "")
4630
4631 (define_insn ""
4632   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4633         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4634                              (match_operand:SI 2 "const_int_operand" "i"))
4635                 (match_operand:SI 3 "mask_operand" "n")))]
4636   "includes_rshift_p (operands[2], operands[3])"
4637   "rlwinm %0,%1,%s2,%m3,%M3"
4638   [(set_attr "type" "shift")])
4639
4640 (define_insn ""
4641   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4642         (compare:CC
4643          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4644                               (match_operand:SI 2 "const_int_operand" "i,i"))
4645                  (match_operand:SI 3 "mask_operand" "n,n"))
4646          (const_int 0)))
4647    (clobber (match_scratch:SI 4 "=r,r"))]
4648   "includes_rshift_p (operands[2], operands[3])"
4649   "@
4650    rlwinm. %4,%1,%s2,%m3,%M3
4651    #"
4652   [(set_attr "type" "shift")
4653    (set_attr "dot" "yes")
4654    (set_attr "length" "4,8")])
4655
4656 (define_split
4657   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4658         (compare:CC
4659          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4660                               (match_operand:SI 2 "const_int_operand" ""))
4661                  (match_operand:SI 3 "mask_operand" ""))
4662          (const_int 0)))
4663    (clobber (match_scratch:SI 4 ""))]
4664   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4665   [(set (match_dup 4)
4666         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4667                  (match_dup 3)))
4668    (set (match_dup 0)
4669         (compare:CC (match_dup 4)
4670                     (const_int 0)))]
4671   "")
4672
4673 (define_insn ""
4674   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4675         (compare:CC
4676          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4677                               (match_operand:SI 2 "const_int_operand" "i,i"))
4678                  (match_operand:SI 3 "mask_operand" "n,n"))
4679          (const_int 0)))
4680    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4681         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4682   "includes_rshift_p (operands[2], operands[3])"
4683   "@
4684    rlwinm. %0,%1,%s2,%m3,%M3
4685    #"
4686   [(set_attr "type" "shift")
4687    (set_attr "dot" "yes")
4688    (set_attr "length" "4,8")])
4689
4690 (define_split
4691   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4692         (compare:CC
4693          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4694                               (match_operand:SI 2 "const_int_operand" ""))
4695                  (match_operand:SI 3 "mask_operand" ""))
4696          (const_int 0)))
4697    (set (match_operand:SI 0 "gpc_reg_operand" "")
4698         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4699   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4700   [(set (match_dup 0)
4701         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4702    (set (match_dup 4)
4703         (compare:CC (match_dup 0)
4704                     (const_int 0)))]
4705   "")
4706
4707 (define_insn "*lshiftrt_internal1le"
4708   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4709         (zero_extend:SI
4710          (subreg:QI
4711           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4712                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4713   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4714   "rlwinm %0,%1,%s2,0xff"
4715   [(set_attr "type" "shift")])
4716
4717 (define_insn "*lshiftrt_internal1be"
4718   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4719         (zero_extend:SI
4720          (subreg:QI
4721           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4722                        (match_operand:SI 2 "const_int_operand" "i")) 3)))]
4723   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4724   "rlwinm %0,%1,%s2,0xff"
4725   [(set_attr "type" "shift")])
4726
4727 (define_insn "*lshiftrt_internal2le"
4728   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4729         (compare:CC
4730          (zero_extend:SI
4731           (subreg:QI
4732            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4733                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4734          (const_int 0)))
4735    (clobber (match_scratch:SI 3 "=r,r"))]
4736   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4737   "@
4738    rlwinm. %3,%1,%s2,0xff
4739    #"
4740   [(set_attr "type" "shift")
4741    (set_attr "dot" "yes")
4742    (set_attr "length" "4,8")])
4743
4744 (define_insn "*lshiftrt_internal2be"
4745   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4746         (compare:CC
4747          (zero_extend:SI
4748           (subreg:QI
4749            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4750                         (match_operand:SI 2 "const_int_operand" "i,i")) 3))
4751          (const_int 0)))
4752    (clobber (match_scratch:SI 3 "=r,r"))]
4753   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4754   "@
4755    rlwinm. %3,%1,%s2,0xff
4756    #"
4757   [(set_attr "type" "shift")
4758    (set_attr "dot" "yes")
4759    (set_attr "length" "4,8")])
4760
4761 (define_split
4762   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4763         (compare:CC
4764          (zero_extend:SI
4765           (subreg:QI
4766            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4767                         (match_operand:SI 2 "const_int_operand" "")) 0))
4768          (const_int 0)))
4769    (clobber (match_scratch:SI 3 ""))]
4770   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4771   [(set (match_dup 3)
4772         (zero_extend:SI (subreg:QI
4773            (lshiftrt:SI (match_dup 1)
4774                         (match_dup 2)) 0)))
4775    (set (match_dup 0)
4776         (compare:CC (match_dup 3)
4777                     (const_int 0)))]
4778   "")
4779
4780 (define_split
4781   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4782         (compare:CC
4783          (zero_extend:SI
4784           (subreg:QI
4785            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4786                         (match_operand:SI 2 "const_int_operand" "")) 3))
4787          (const_int 0)))
4788    (clobber (match_scratch:SI 3 ""))]
4789   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4790   [(set (match_dup 3)
4791         (zero_extend:SI (subreg:QI
4792            (lshiftrt:SI (match_dup 1)
4793                         (match_dup 2)) 3)))
4794    (set (match_dup 0)
4795         (compare:CC (match_dup 3)
4796                     (const_int 0)))]
4797   "")
4798
4799 (define_insn "*lshiftrt_internal3le"
4800   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4801         (compare:CC
4802          (zero_extend:SI
4803           (subreg:QI
4804            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4805                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4806          (const_int 0)))
4807    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4808         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4809   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4810   "@
4811    rlwinm. %0,%1,%s2,0xff
4812    #"
4813   [(set_attr "type" "shift")
4814    (set_attr "dot" "yes")
4815    (set_attr "length" "4,8")])
4816
4817 (define_insn "*lshiftrt_internal3be"
4818   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4819         (compare:CC
4820          (zero_extend:SI
4821           (subreg:QI
4822            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4823                         (match_operand:SI 2 "const_int_operand" "i,i")) 3))
4824          (const_int 0)))
4825    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4826         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 3)))]
4827   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255))"
4828   "@
4829    rlwinm. %0,%1,%s2,0xff
4830    #"
4831   [(set_attr "type" "shift")
4832    (set_attr "dot" "yes")
4833    (set_attr "length" "4,8")])
4834
4835 (define_split
4836   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4837         (compare:CC
4838          (zero_extend:SI
4839           (subreg:QI
4840            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4841                         (match_operand:SI 2 "const_int_operand" "")) 0))
4842          (const_int 0)))
4843    (set (match_operand:SI 0 "gpc_reg_operand" "")
4844         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4845   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4846   [(set (match_dup 0)
4847         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4848    (set (match_dup 3)
4849         (compare:CC (match_dup 0)
4850                     (const_int 0)))]
4851   "")
4852
4853 (define_split
4854   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4855         (compare:CC
4856          (zero_extend:SI
4857           (subreg:QI
4858            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4859                         (match_operand:SI 2 "const_int_operand" "")) 3))
4860          (const_int 0)))
4861    (set (match_operand:SI 0 "gpc_reg_operand" "")
4862         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 3)))]
4863   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4864   [(set (match_dup 0)
4865         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 3)))
4866    (set (match_dup 3)
4867         (compare:CC (match_dup 0)
4868                     (const_int 0)))]
4869   "")
4870
4871 (define_insn "*lshiftrt_internal4le"
4872   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4873         (zero_extend:SI
4874          (subreg:HI
4875           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4876                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4877   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4878   "rlwinm %0,%1,%s2,0xffff"
4879   [(set_attr "type" "shift")])
4880
4881 (define_insn "*lshiftrt_internal4be"
4882   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4883         (zero_extend:SI
4884          (subreg:HI
4885           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4886                        (match_operand:SI 2 "const_int_operand" "i")) 2)))]
4887   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4888   "rlwinm %0,%1,%s2,0xffff"
4889   [(set_attr "type" "shift")])
4890
4891 (define_insn "*lshiftrt_internal5le"
4892   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4893         (compare:CC
4894          (zero_extend:SI
4895           (subreg:HI
4896            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4897                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4898          (const_int 0)))
4899    (clobber (match_scratch:SI 3 "=r,r"))]
4900   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4901   "@
4902    rlwinm. %3,%1,%s2,0xffff
4903    #"
4904   [(set_attr "type" "shift")
4905    (set_attr "dot" "yes")
4906    (set_attr "length" "4,8")])
4907
4908 (define_insn "*lshiftrt_internal5be"
4909   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4910         (compare:CC
4911          (zero_extend:SI
4912           (subreg:HI
4913            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4914                         (match_operand:SI 2 "const_int_operand" "i,i")) 2))
4915          (const_int 0)))
4916    (clobber (match_scratch:SI 3 "=r,r"))]
4917   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4918   "@
4919    rlwinm. %3,%1,%s2,0xffff
4920    #"
4921   [(set_attr "type" "shift")
4922    (set_attr "dot" "yes")
4923    (set_attr "length" "4,8")])
4924
4925 (define_split
4926   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4927         (compare:CC
4928          (zero_extend:SI
4929           (subreg:HI
4930            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4931                         (match_operand:SI 2 "const_int_operand" "")) 0))
4932          (const_int 0)))
4933    (clobber (match_scratch:SI 3 ""))]
4934   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4935   [(set (match_dup 3)
4936         (zero_extend:SI (subreg:HI
4937            (lshiftrt:SI (match_dup 1)
4938                         (match_dup 2)) 0)))
4939    (set (match_dup 0)
4940         (compare:CC (match_dup 3)
4941                     (const_int 0)))]
4942   "")
4943
4944 (define_split
4945   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4946         (compare:CC
4947          (zero_extend:SI
4948           (subreg:HI
4949            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4950                         (match_operand:SI 2 "const_int_operand" "")) 2))
4951          (const_int 0)))
4952    (clobber (match_scratch:SI 3 ""))]
4953   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4954   [(set (match_dup 3)
4955         (zero_extend:SI (subreg:HI
4956            (lshiftrt:SI (match_dup 1)
4957                         (match_dup 2)) 2)))
4958    (set (match_dup 0)
4959         (compare:CC (match_dup 3)
4960                     (const_int 0)))]
4961   "")
4962
4963 (define_insn "*lshiftrt_internal5le"
4964   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4965         (compare:CC
4966          (zero_extend:SI
4967           (subreg:HI
4968            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4969                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4970          (const_int 0)))
4971    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4972         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4973   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4974   "@
4975    rlwinm. %0,%1,%s2,0xffff
4976    #"
4977   [(set_attr "type" "shift")
4978    (set_attr "dot" "yes")
4979    (set_attr "length" "4,8")])
4980
4981 (define_insn "*lshiftrt_internal5be"
4982   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4983         (compare:CC
4984          (zero_extend:SI
4985           (subreg:HI
4986            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4987                         (match_operand:SI 2 "const_int_operand" "i,i")) 2))
4988          (const_int 0)))
4989    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4990         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 2)))]
4991   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535))"
4992   "@
4993    rlwinm. %0,%1,%s2,0xffff
4994    #"
4995   [(set_attr "type" "shift")
4996    (set_attr "dot" "yes")
4997    (set_attr "length" "4,8")])
4998
4999 (define_split
5000   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5001         (compare:CC
5002          (zero_extend:SI
5003           (subreg:HI
5004            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5005                         (match_operand:SI 2 "const_int_operand" "")) 0))
5006          (const_int 0)))
5007    (set (match_operand:SI 0 "gpc_reg_operand" "")
5008         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
5009   "!BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
5010   [(set (match_dup 0)
5011         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
5012    (set (match_dup 3)
5013         (compare:CC (match_dup 0)
5014                     (const_int 0)))]
5015   "")
5016
5017 (define_split
5018   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5019         (compare:CC
5020          (zero_extend:SI
5021           (subreg:HI
5022            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5023                         (match_operand:SI 2 "const_int_operand" "")) 2))
5024          (const_int 0)))
5025    (set (match_operand:SI 0 "gpc_reg_operand" "")
5026         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 2)))]
5027   "BYTES_BIG_ENDIAN && includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
5028   [(set (match_dup 0)
5029         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 2)))
5030    (set (match_dup 3)
5031         (compare:CC (match_dup 0)
5032                     (const_int 0)))]
5033   "")
5034
5035 (define_insn "ashrsi3"
5036   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5037         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5038                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
5039   ""
5040   "@
5041    sraw %0,%1,%2
5042    srawi %0,%1,%h2"
5043   [(set_attr "type" "shift")
5044    (set_attr "var_shift" "yes,no")])
5045
5046 (define_insn "*ashrsi3_64"
5047   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5048         (sign_extend:DI
5049             (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5050                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
5051   "TARGET_POWERPC64"
5052   "@
5053    sraw %0,%1,%2
5054    srawi %0,%1,%h2"
5055   [(set_attr "type" "shift")
5056    (set_attr "var_shift" "yes,no")])
5057
5058 (define_insn ""
5059   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5060         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5061                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5062                     (const_int 0)))
5063    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
5064   ""
5065   "@
5066    sraw. %3,%1,%2
5067    srawi. %3,%1,%h2
5068    #
5069    #"
5070   [(set_attr "type" "shift")
5071    (set_attr "var_shift" "yes,no,yes,no")
5072    (set_attr "dot" "yes")
5073    (set_attr "length" "4,4,8,8")])
5074
5075 (define_split
5076   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
5077         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5078                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5079                     (const_int 0)))
5080    (clobber (match_scratch:SI 3 ""))]
5081   "reload_completed"
5082   [(set (match_dup 3)
5083         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5084    (set (match_dup 0)
5085         (compare:CC (match_dup 3)
5086                     (const_int 0)))]
5087   "")
5088
5089 (define_insn ""
5090   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5091         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5092                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5093                     (const_int 0)))
5094    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
5095         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5096   ""
5097   "@
5098    sraw. %0,%1,%2
5099    srawi. %0,%1,%h2
5100    #
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 (define_split
5147   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
5148         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5149                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5150                     (const_int 0)))
5151    (set (match_operand:SI 0 "gpc_reg_operand" "")
5152         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5153   "reload_completed"
5154   [(set (match_dup 0)
5155         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5156    (set (match_dup 3)
5157         (compare:CC (match_dup 0)
5158                     (const_int 0)))]
5159   "")
5160
5161 \f
5162 ;; Floating-point insns, excluding normal data motion.  We combine the SF/DF
5163 ;; modes here, and also add in conditional vsx/power8-vector support to access
5164 ;; values in the traditional Altivec registers if the appropriate
5165 ;; -mupper-regs-{df,sf} option is enabled.
5166
5167 (define_expand "abs<mode>2"
5168   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5169         (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")))]
5170   "TARGET_<MODE>_INSN"
5171   "")
5172
5173 (define_insn "*abs<mode>2_fpr"
5174   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5175         (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")))]
5176   "TARGET_<MODE>_FPR"
5177   "@
5178    fabs %0,%1
5179    xsabsdp %x0,%x1"
5180   [(set_attr "type" "fp")
5181    (set_attr "fp_type" "fp_addsub_<Fs>")])
5182
5183 (define_insn "*nabs<mode>2_fpr"
5184   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5185         (neg:SFDF
5186          (abs:SFDF
5187           (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>"))))]
5188   "TARGET_<MODE>_FPR"
5189   "@
5190    fnabs %0,%1
5191    xsnabsdp %x0,%x1"
5192   [(set_attr "type" "fp")
5193    (set_attr "fp_type" "fp_addsub_<Fs>")])
5194
5195 (define_expand "neg<mode>2"
5196   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5197         (neg:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")))]
5198   "TARGET_<MODE>_INSN"
5199   "")
5200
5201 (define_insn "*neg<mode>2_fpr"
5202   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5203         (neg:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")))]
5204   "TARGET_<MODE>_FPR"
5205   "@
5206    fneg %0,%1
5207    xsnegdp %x0,%x1"
5208   [(set_attr "type" "fp")
5209    (set_attr "fp_type" "fp_addsub_<Fs>")])
5210
5211 (define_expand "add<mode>3"
5212   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5213         (plus:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")
5214                    (match_operand:SFDF 2 "gpc_reg_operand" "")))]
5215   "TARGET_<MODE>_INSN"
5216   "")
5217
5218 (define_insn "*add<mode>3_fpr"
5219   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5220         (plus:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "%<Ff>,<Fv>")
5221                    (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5222   "TARGET_<MODE>_FPR"
5223   "@
5224    fadd<Ftrad> %0,%1,%2
5225    xsadd<Fvsx> %x0,%x1,%x2"
5226   [(set_attr "type" "fp")
5227    (set_attr "fp_type" "fp_addsub_<Fs>")])
5228
5229 (define_expand "sub<mode>3"
5230   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5231         (minus:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")
5232                     (match_operand:SFDF 2 "gpc_reg_operand" "")))]
5233   "TARGET_<MODE>_INSN"
5234   "")
5235
5236 (define_insn "*sub<mode>3_fpr"
5237   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5238         (minus:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")
5239                     (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5240   "TARGET_<MODE>_FPR"
5241   "@
5242    fsub<Ftrad> %0,%1,%2
5243    xssub<Fvsx> %x0,%x1,%x2"
5244   [(set_attr "type" "fp")
5245    (set_attr "fp_type" "fp_addsub_<Fs>")])
5246
5247 (define_expand "mul<mode>3"
5248   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5249         (mult:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")
5250                    (match_operand:SFDF 2 "gpc_reg_operand" "")))]
5251   "TARGET_<MODE>_INSN"
5252   "")
5253
5254 (define_insn "*mul<mode>3_fpr"
5255   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5256         (mult:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "%<Ff>,<Fv>")
5257                    (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5258   "TARGET_<MODE>_FPR"
5259   "@
5260    fmul<Ftrad> %0,%1,%2
5261    xsmul<Fvsx> %x0,%x1,%x2"
5262   [(set_attr "type" "dmul")
5263    (set_attr "fp_type" "fp_mul_<Fs>")])
5264
5265 (define_expand "div<mode>3"
5266   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5267         (div:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")
5268                   (match_operand:SFDF 2 "gpc_reg_operand" "")))]
5269   "TARGET_<MODE>_INSN && !TARGET_SIMPLE_FPU"
5270   "")
5271
5272 (define_insn "*div<mode>3_fpr"
5273   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5274         (div:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")
5275                   (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5276   "TARGET_<MODE>_FPR && !TARGET_SIMPLE_FPU"
5277   "@
5278    fdiv<Ftrad> %0,%1,%2
5279    xsdiv<Fvsx> %x0,%x1,%x2"
5280   [(set_attr "type" "<Fs>div")
5281    (set_attr "fp_type" "fp_div_<Fs>")])
5282
5283 (define_insn "sqrt<mode>2"
5284   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5285         (sqrt:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")))]
5286   "TARGET_<MODE>_FPR && !TARGET_SIMPLE_FPU
5287    && (TARGET_PPC_GPOPT || (<MODE>mode == SFmode && TARGET_XILINX_FPU))"
5288   "@
5289    fsqrt<Ftrad> %0,%1
5290    xssqrt<Fvsx> %x0,%x1"
5291   [(set_attr "type" "<Fs>sqrt")
5292    (set_attr "fp_type" "fp_sqrt_<Fs>")])
5293
5294 ;; Floating point reciprocal approximation
5295 (define_insn "fre<Fs>"
5296   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5297         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")]
5298                      UNSPEC_FRES))]
5299   "TARGET_<FFRE>"
5300   "@
5301    fre<Ftrad> %0,%1
5302    xsre<Fvsx> %x0,%x1"
5303   [(set_attr "type" "fp")])
5304
5305 (define_insn "*rsqrt<mode>2"
5306   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5307         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")]
5308                      UNSPEC_RSQRT))]
5309   "RS6000_RECIP_HAVE_RSQRTE_P (<MODE>mode)"
5310   "@
5311    frsqrte<Ftrad> %0,%1
5312    xsrsqrte<Fvsx> %x0,%x1"
5313   [(set_attr "type" "fp")])
5314
5315 ;; Floating point comparisons
5316 (define_insn "*cmp<mode>_fpr"
5317   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y,y")
5318         (compare:CCFP (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")
5319                       (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5320   "TARGET_<MODE>_FPR"
5321   "@
5322    fcmpu %0,%1,%2
5323    xscmpudp %0,%x1,%x2"
5324   [(set_attr "type" "fpcompare")])
5325
5326 ;; Floating point conversions
5327 (define_expand "extendsfdf2"
5328   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5329         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
5330   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5331   "")
5332
5333 (define_insn_and_split "*extendsfdf2_fpr"
5334   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d,d,ws,?ws,wv")
5335         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m,0,wy,Z")))]
5336   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5337   "@
5338    #
5339    fmr %0,%1
5340    lfs%U1%X1 %0,%1
5341    #
5342    xxlor %x0,%x1,%x1
5343    lxsspx %x0,%y1"
5344   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
5345   [(const_int 0)]
5346 {
5347   emit_note (NOTE_INSN_DELETED);
5348   DONE;
5349 }
5350   [(set_attr "type" "fp,fp,fpload,fp,vecsimple,fpload")])
5351
5352 (define_expand "truncdfsf2"
5353   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5354         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
5355   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5356   "")
5357
5358 (define_insn "*truncdfsf2_fpr"
5359   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5360         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "d")))]
5361   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5362   "frsp %0,%1"
5363   [(set_attr "type" "fp")])
5364
5365 ;; This expander is here to avoid FLOAT_WORDS_BIGENDIAN tests in
5366 ;; builtins.c and optabs.c that are not correct for IBM long double
5367 ;; when little-endian.
5368 (define_expand "signbittf2"
5369   [(set (match_dup 2)
5370         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))
5371    (set (match_dup 3)
5372         (subreg:DI (match_dup 2) 0))
5373    (set (match_dup 4)
5374         (match_dup 5))
5375    (set (match_operand:SI 0 "gpc_reg_operand" "")
5376         (match_dup 6))]
5377   "!TARGET_IEEEQUAD
5378    && TARGET_HARD_FLOAT
5379    && (TARGET_FPRS || TARGET_E500_DOUBLE)
5380    && TARGET_LONG_DOUBLE_128"
5381 {
5382   operands[2] = gen_reg_rtx (DFmode);
5383   operands[3] = gen_reg_rtx (DImode);
5384   if (TARGET_POWERPC64)
5385     {
5386       operands[4] = gen_reg_rtx (DImode);
5387       operands[5] = gen_rtx_LSHIFTRT (DImode, operands[3], GEN_INT (63));
5388       operands[6] = gen_rtx_SUBREG (SImode, operands[4],
5389                                     WORDS_BIG_ENDIAN ? 4 : 0);
5390     }
5391   else
5392     {
5393       operands[4] = gen_reg_rtx (SImode);
5394       operands[5] = gen_rtx_SUBREG (SImode, operands[3],
5395                                     WORDS_BIG_ENDIAN ? 0 : 4);
5396       operands[6] = gen_rtx_LSHIFTRT (SImode, operands[4], GEN_INT (31));
5397     }
5398 })
5399
5400 (define_expand "copysign<mode>3"
5401   [(set (match_dup 3)
5402         (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")))
5403    (set (match_dup 4)
5404         (neg:SFDF (abs:SFDF (match_dup 1))))
5405    (set (match_operand:SFDF 0 "gpc_reg_operand" "")
5406         (if_then_else:SFDF (ge (match_operand:SFDF 2 "gpc_reg_operand" "")
5407                                (match_dup 5))
5408                          (match_dup 3)
5409                          (match_dup 4)))]
5410   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
5411    && ((TARGET_PPC_GFXOPT
5412         && !HONOR_NANS (<MODE>mode)
5413         && !HONOR_SIGNED_ZEROS (<MODE>mode))
5414        || TARGET_CMPB
5415        || VECTOR_UNIT_VSX_P (<MODE>mode))"
5416 {
5417   if (TARGET_CMPB || VECTOR_UNIT_VSX_P (<MODE>mode))
5418     {
5419       emit_insn (gen_copysign<mode>3_fcpsgn (operands[0], operands[1],
5420                                              operands[2]));
5421       DONE;
5422     }
5423
5424    operands[3] = gen_reg_rtx (<MODE>mode);
5425    operands[4] = gen_reg_rtx (<MODE>mode);
5426    operands[5] = CONST0_RTX (<MODE>mode);
5427   })
5428
5429 ;; Use an unspec rather providing an if-then-else in RTL, to prevent the
5430 ;; compiler from optimizing -0.0
5431 (define_insn "copysign<mode>3_fcpsgn"
5432   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5433         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")
5434                       (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")]
5435                      UNSPEC_COPYSIGN))]
5436   "TARGET_<MODE>_FPR && TARGET_CMPB"
5437   "@
5438    fcpsgn %0,%2,%1
5439    xscpsgn<Fvsx> %x0,%x2,%x1"
5440   [(set_attr "type" "fp")])
5441
5442 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
5443 ;; fsel instruction and some auxiliary computations.  Then we just have a
5444 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
5445 ;; combine.
5446 ;; For MIN, MAX on non-VSX machines, and conditional move all of the time, we
5447 ;; use DEFINE_EXPAND's that involve a fsel instruction and some auxiliary
5448 ;; computations.  Then we just have a single DEFINE_INSN for fsel and the
5449 ;; define_splits to make them if made by combine.  On VSX machines we have the
5450 ;; min/max instructions.
5451 ;;
5452 ;; On VSX, we only check for TARGET_VSX instead of checking for a vsx/p8 vector
5453 ;; to allow either DF/SF to use only traditional registers.
5454
5455 (define_expand "smax<mode>3"
5456   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5457         (if_then_else:SFDF (ge (match_operand:SFDF 1 "gpc_reg_operand" "")
5458                                (match_operand:SFDF 2 "gpc_reg_operand" ""))
5459                            (match_dup 1)
5460                            (match_dup 2)))]
5461   "TARGET_<MODE>_FPR && TARGET_PPC_GFXOPT && !flag_trapping_math"
5462 {
5463   rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
5464   DONE;
5465 })
5466
5467 (define_insn "*smax<mode>3_vsx"
5468   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5469         (smax:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "%<Ff>,<Fv>")
5470                    (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5471   "TARGET_<MODE>_FPR && TARGET_VSX"
5472   "xsmaxdp %x0,%x1,%x2"
5473   [(set_attr "type" "fp")])
5474
5475 (define_expand "smin<mode>3"
5476   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5477         (if_then_else:SFDF (ge (match_operand:SFDF 1 "gpc_reg_operand" "")
5478                                (match_operand:SFDF 2 "gpc_reg_operand" ""))
5479                            (match_dup 2)
5480                            (match_dup 1)))]
5481   "TARGET_<MODE>_FPR && TARGET_PPC_GFXOPT && !flag_trapping_math"
5482 {
5483   rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
5484   DONE;
5485 })
5486
5487 (define_insn "*smin<mode>3_vsx"
5488   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
5489         (smin:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "%<Ff>,<Fv>")
5490                    (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>")))]
5491   "TARGET_<MODE>_FPR && TARGET_VSX"
5492   "xsmindp %x0,%x1,%x2"
5493   [(set_attr "type" "fp")])
5494
5495 (define_split
5496   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5497         (match_operator:SFDF 3 "min_max_operator"
5498          [(match_operand:SFDF 1 "gpc_reg_operand" "")
5499           (match_operand:SFDF 2 "gpc_reg_operand" "")]))]
5500   "TARGET_<MODE>_FPR && TARGET_PPC_GFXOPT && !flag_trapping_math
5501    && !TARGET_VSX"
5502   [(const_int 0)]
5503 {
5504   rs6000_emit_minmax (operands[0], GET_CODE (operands[3]), operands[1],
5505                       operands[2]);
5506   DONE;
5507 })
5508
5509 (define_split
5510   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5511         (match_operator:SF 3 "min_max_operator"
5512          [(match_operand:SF 1 "gpc_reg_operand" "")
5513           (match_operand:SF 2 "gpc_reg_operand" "")]))]
5514   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
5515    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
5516   [(const_int 0)]
5517   "
5518 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5519                       operands[1], operands[2]);
5520   DONE;
5521 }")
5522
5523 (define_expand "mov<mode>cc"
5524    [(set (match_operand:GPR 0 "gpc_reg_operand" "")
5525          (if_then_else:GPR (match_operand 1 "comparison_operator" "")
5526                            (match_operand:GPR 2 "gpc_reg_operand" "")
5527                            (match_operand:GPR 3 "gpc_reg_operand" "")))]
5528   "TARGET_ISEL<sel>"
5529   "
5530 {
5531   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5532     DONE;
5533   else
5534     FAIL;
5535 }")
5536
5537 ;; We use the BASE_REGS for the isel input operands because, if rA is
5538 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
5539 ;; because we may switch the operands and rB may end up being rA.
5540 ;;
5541 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
5542 ;; leave out the mode in operand 4 and use one pattern, but reload can
5543 ;; change the mode underneath our feet and then gets confused trying
5544 ;; to reload the value.
5545 (define_insn "isel_signed_<mode>"
5546   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
5547         (if_then_else:GPR
5548          (match_operator 1 "scc_comparison_operator"
5549                          [(match_operand:CC 4 "cc_reg_operand" "y,y")
5550                           (const_int 0)])
5551          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
5552          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
5553   "TARGET_ISEL<sel>"
5554   "*
5555 { return output_isel (operands); }"
5556   [(set_attr "type" "isel")
5557    (set_attr "length" "4")])
5558
5559 (define_insn "isel_unsigned_<mode>"
5560   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
5561         (if_then_else:GPR
5562          (match_operator 1 "scc_comparison_operator"
5563                          [(match_operand:CCUNS 4 "cc_reg_operand" "y,y")
5564                           (const_int 0)])
5565          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
5566          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
5567   "TARGET_ISEL<sel>"
5568   "*
5569 { return output_isel (operands); }"
5570   [(set_attr "type" "isel")
5571    (set_attr "length" "4")])
5572
5573 ;; These patterns can be useful for combine; they let combine know that
5574 ;; isel can handle reversed comparisons so long as the operands are
5575 ;; registers.
5576
5577 (define_insn "*isel_reversed_signed_<mode>"
5578   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
5579         (if_then_else:GPR
5580          (match_operator 1 "scc_rev_comparison_operator"
5581                          [(match_operand:CC 4 "cc_reg_operand" "y")
5582                           (const_int 0)])
5583          (match_operand:GPR 2 "gpc_reg_operand" "b")
5584          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
5585   "TARGET_ISEL<sel>"
5586   "*
5587 { return output_isel (operands); }"
5588   [(set_attr "type" "isel")
5589    (set_attr "length" "4")])
5590
5591 (define_insn "*isel_reversed_unsigned_<mode>"
5592   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
5593         (if_then_else:GPR
5594          (match_operator 1 "scc_rev_comparison_operator"
5595                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
5596                           (const_int 0)])
5597          (match_operand:GPR 2 "gpc_reg_operand" "b")
5598          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
5599   "TARGET_ISEL<sel>"
5600   "*
5601 { return output_isel (operands); }"
5602   [(set_attr "type" "isel")
5603    (set_attr "length" "4")])
5604
5605 (define_expand "movsfcc"
5606    [(set (match_operand:SF 0 "gpc_reg_operand" "")
5607          (if_then_else:SF (match_operand 1 "comparison_operator" "")
5608                           (match_operand:SF 2 "gpc_reg_operand" "")
5609                           (match_operand:SF 3 "gpc_reg_operand" "")))]
5610   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5611   "
5612 {
5613   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5614     DONE;
5615   else
5616     FAIL;
5617 }")
5618
5619 (define_insn "*fselsfsf4"
5620   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5621         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5622                              (match_operand:SF 4 "zero_fp_constant" "F"))
5623                          (match_operand:SF 2 "gpc_reg_operand" "f")
5624                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5625   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5626   "fsel %0,%1,%2,%3"
5627   [(set_attr "type" "fp")])
5628
5629 (define_insn "*fseldfsf4"
5630   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5631         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
5632                              (match_operand:DF 4 "zero_fp_constant" "F"))
5633                          (match_operand:SF 2 "gpc_reg_operand" "f")
5634                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5635   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
5636   "fsel %0,%1,%2,%3"
5637   [(set_attr "type" "fp")])
5638
5639 ;; The conditional move instructions allow us to perform max and min
5640 ;; operations even when
5641
5642 (define_split
5643   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5644         (match_operator:DF 3 "min_max_operator"
5645          [(match_operand:DF 1 "gpc_reg_operand" "")
5646           (match_operand:DF 2 "gpc_reg_operand" "")]))]
5647   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
5648    && !flag_trapping_math"
5649   [(const_int 0)]
5650   "
5651 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5652                       operands[1], operands[2]);
5653   DONE;
5654 }")
5655
5656 (define_expand "movdfcc"
5657    [(set (match_operand:DF 0 "gpc_reg_operand" "")
5658          (if_then_else:DF (match_operand 1 "comparison_operator" "")
5659                           (match_operand:DF 2 "gpc_reg_operand" "")
5660                           (match_operand:DF 3 "gpc_reg_operand" "")))]
5661   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5662   "
5663 {
5664   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5665     DONE;
5666   else
5667     FAIL;
5668 }")
5669
5670 (define_insn "*fseldfdf4"
5671   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5672         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
5673                              (match_operand:DF 4 "zero_fp_constant" "F"))
5674                          (match_operand:DF 2 "gpc_reg_operand" "d")
5675                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
5676   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5677   "fsel %0,%1,%2,%3"
5678   [(set_attr "type" "fp")])
5679
5680 (define_insn "*fselsfdf4"
5681   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5682         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5683                              (match_operand:SF 4 "zero_fp_constant" "F"))
5684                          (match_operand:DF 2 "gpc_reg_operand" "d")
5685                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
5686   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
5687   "fsel %0,%1,%2,%3"
5688   [(set_attr "type" "fp")])
5689 \f
5690 ;; Conversions to and from floating-point.
5691
5692 ; We don't define lfiwax/lfiwzx with the normal definition, because we
5693 ; don't want to support putting SImode in FPR registers.
5694 (define_insn "lfiwax"
5695   [(set (match_operand:DI 0 "gpc_reg_operand" "=d,wm,!wm")
5696         (unspec:DI [(match_operand:SI 1 "reg_or_indexed_operand" "Z,Z,r")]
5697                    UNSPEC_LFIWAX))]
5698   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX"
5699   "@
5700    lfiwax %0,%y1
5701    lxsiwax %x0,%y1
5702    mtvsrwa %x0,%1"
5703   [(set_attr "type" "fpload,fpload,mffgpr")])
5704
5705 ; This split must be run before register allocation because it allocates the
5706 ; memory slot that is needed to move values to/from the FPR.  We don't allocate
5707 ; it earlier to allow for the combiner to merge insns together where it might
5708 ; not be needed and also in case the insns are deleted as dead code.
5709
5710 (define_insn_and_split "floatsi<mode>2_lfiwax"
5711   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5712         (float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r")))
5713    (clobber (match_scratch:DI 2 "=d"))]
5714   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
5715    && <SI_CONVERT_FP> && can_create_pseudo_p ()"
5716   "#"
5717   ""
5718   [(pc)]
5719   "
5720 {
5721   rtx dest = operands[0];
5722   rtx src = operands[1];
5723   rtx tmp;
5724
5725   if (!MEM_P (src) && TARGET_POWERPC64
5726       && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
5727     tmp = convert_to_mode (DImode, src, false);
5728   else
5729     {
5730       tmp = operands[2];
5731       if (GET_CODE (tmp) == SCRATCH)
5732         tmp = gen_reg_rtx (DImode);
5733       if (MEM_P (src))
5734         {
5735           src = rs6000_address_for_fpconvert (src);
5736           emit_insn (gen_lfiwax (tmp, src));
5737         }
5738       else
5739         {
5740           rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5741           emit_move_insn (stack, src);
5742           emit_insn (gen_lfiwax (tmp, stack));
5743         }
5744     }
5745   emit_insn (gen_floatdi<mode>2 (dest, tmp));
5746   DONE;
5747 }"
5748   [(set_attr "length" "12")
5749    (set_attr "type" "fpload")])
5750
5751 (define_insn_and_split "floatsi<mode>2_lfiwax_mem"
5752   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,<rreg2>")
5753         (float:SFDF
5754          (sign_extend:DI
5755           (match_operand:SI 1 "memory_operand" "Z,Z"))))
5756    (clobber (match_scratch:DI 2 "=0,d"))]
5757   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
5758    && <SI_CONVERT_FP>"
5759   "#"
5760   ""
5761   [(pc)]
5762   "
5763 {
5764   operands[1] = rs6000_address_for_fpconvert (operands[1]);
5765   if (GET_CODE (operands[2]) == SCRATCH)
5766     operands[2] = gen_reg_rtx (DImode);
5767   emit_insn (gen_lfiwax (operands[2], operands[1]));
5768   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
5769   DONE;
5770 }"
5771   [(set_attr "length" "8")
5772    (set_attr "type" "fpload")])
5773
5774 (define_insn "lfiwzx"
5775   [(set (match_operand:DI 0 "gpc_reg_operand" "=d,wm,!wm")
5776         (unspec:DI [(match_operand:SI 1 "reg_or_indexed_operand" "Z,Z,r")]
5777                    UNSPEC_LFIWZX))]
5778   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX"
5779   "@
5780    lfiwzx %0,%y1
5781    lxsiwzx %x0,%y1
5782    mtvsrwz %x0,%1"
5783   [(set_attr "type" "fpload,fpload,mftgpr")])
5784
5785 (define_insn_and_split "floatunssi<mode>2_lfiwzx"
5786   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5787         (unsigned_float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r")))
5788    (clobber (match_scratch:DI 2 "=d"))]
5789   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
5790    && <SI_CONVERT_FP>"
5791   "#"
5792   ""
5793   [(pc)]
5794   "
5795 {
5796   rtx dest = operands[0];
5797   rtx src = operands[1];
5798   rtx tmp;
5799
5800   if (!MEM_P (src) && TARGET_POWERPC64
5801       && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
5802     tmp = convert_to_mode (DImode, src, true);
5803   else
5804     {
5805       tmp = operands[2];
5806       if (GET_CODE (tmp) == SCRATCH)
5807         tmp = gen_reg_rtx (DImode);
5808       if (MEM_P (src))
5809         {
5810           src = rs6000_address_for_fpconvert (src);
5811           emit_insn (gen_lfiwzx (tmp, src));
5812         }
5813       else
5814         {
5815           rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5816           emit_move_insn (stack, src);
5817           emit_insn (gen_lfiwzx (tmp, stack));
5818         }
5819     }
5820   emit_insn (gen_floatdi<mode>2 (dest, tmp));
5821   DONE;
5822 }"
5823   [(set_attr "length" "12")
5824    (set_attr "type" "fpload")])
5825
5826 (define_insn_and_split "floatunssi<mode>2_lfiwzx_mem"
5827   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,<rreg2>")
5828         (unsigned_float:SFDF
5829          (zero_extend:DI
5830           (match_operand:SI 1 "memory_operand" "Z,Z"))))
5831    (clobber (match_scratch:DI 2 "=0,d"))]
5832   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
5833    && <SI_CONVERT_FP>"
5834   "#"
5835   ""
5836   [(pc)]
5837   "
5838 {
5839   operands[1] = rs6000_address_for_fpconvert (operands[1]);
5840   if (GET_CODE (operands[2]) == SCRATCH)
5841     operands[2] = gen_reg_rtx (DImode);
5842   emit_insn (gen_lfiwzx (operands[2], operands[1]));
5843   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
5844   DONE;
5845 }"
5846   [(set_attr "length" "8")
5847    (set_attr "type" "fpload")])
5848
5849 ; For each of these conversions, there is a define_expand, a define_insn
5850 ; with a '#' template, and a define_split (with C code).  The idea is
5851 ; to allow constant folding with the template of the define_insn,
5852 ; then to have the insns split later (between sched1 and final).
5853
5854 (define_expand "floatsidf2"
5855   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5856                    (float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
5857               (use (match_dup 2))
5858               (use (match_dup 3))
5859               (clobber (match_dup 4))
5860               (clobber (match_dup 5))
5861               (clobber (match_dup 6))])]
5862   "TARGET_HARD_FLOAT 
5863    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5864   "
5865 {
5866   if (TARGET_E500_DOUBLE)
5867     {
5868       if (!REG_P (operands[1]))
5869         operands[1] = force_reg (SImode, operands[1]);
5870       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
5871       DONE;
5872     }
5873   else if (TARGET_LFIWAX && TARGET_FCFID)
5874     {
5875       emit_insn (gen_floatsidf2_lfiwax (operands[0], operands[1]));
5876       DONE;
5877     }
5878   else if (TARGET_FCFID)
5879     {
5880       rtx dreg = operands[1];
5881       if (!REG_P (dreg))
5882         dreg = force_reg (SImode, dreg);
5883       dreg = convert_to_mode (DImode, dreg, false);
5884       emit_insn (gen_floatdidf2 (operands[0], dreg));
5885       DONE;
5886     }
5887
5888   if (!REG_P (operands[1]))
5889     operands[1] = force_reg (SImode, operands[1]);
5890   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5891   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5892   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
5893   operands[5] = gen_reg_rtx (DFmode);
5894   operands[6] = gen_reg_rtx (SImode);
5895 }")
5896
5897 (define_insn_and_split "*floatsidf2_internal"
5898   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
5899         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5900    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5901    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
5902    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
5903    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))
5904    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5905   "! TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5906   "#"
5907   ""
5908   [(pc)]
5909   "
5910 {
5911   rtx lowword, highword;
5912   gcc_assert (MEM_P (operands[4]));
5913   highword = adjust_address (operands[4], SImode, 0);
5914   lowword = adjust_address (operands[4], SImode, 4);
5915   if (! WORDS_BIG_ENDIAN)
5916     {
5917       rtx tmp;
5918       tmp = highword; highword = lowword; lowword = tmp;
5919     }
5920
5921   emit_insn (gen_xorsi3 (operands[6], operands[1],
5922                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5923   emit_move_insn (lowword, operands[6]);
5924   emit_move_insn (highword, operands[2]);
5925   emit_move_insn (operands[5], operands[4]);
5926   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5927   DONE;
5928 }"
5929   [(set_attr "length" "24")
5930    (set_attr "type" "fp")])
5931
5932 ;; If we don't have a direct conversion to single precision, don't enable this
5933 ;; conversion for 32-bit without fast math, because we don't have the insn to
5934 ;; generate the fixup swizzle to avoid double rounding problems.
5935 (define_expand "floatunssisf2"
5936   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5937         (unsigned_float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
5938   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
5939    && (!TARGET_FPRS
5940        || (TARGET_FPRS
5941            && ((TARGET_FCFIDUS && TARGET_LFIWZX)
5942                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
5943                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
5944   "
5945 {
5946   if (!TARGET_FPRS)
5947     {
5948       if (!REG_P (operands[1]))
5949         operands[1] = force_reg (SImode, operands[1]);
5950     }
5951   else if (TARGET_LFIWZX && TARGET_FCFIDUS)
5952     {
5953       emit_insn (gen_floatunssisf2_lfiwzx (operands[0], operands[1]));
5954       DONE;
5955     }
5956   else
5957     {
5958       rtx dreg = operands[1];
5959       if (!REG_P (dreg))
5960         dreg = force_reg (SImode, dreg);
5961       dreg = convert_to_mode (DImode, dreg, true);
5962       emit_insn (gen_floatdisf2 (operands[0], dreg));
5963       DONE;
5964     }
5965 }")
5966
5967 (define_expand "floatunssidf2"
5968   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5969                    (unsigned_float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
5970               (use (match_dup 2))
5971               (use (match_dup 3))
5972               (clobber (match_dup 4))
5973               (clobber (match_dup 5))])]
5974   "TARGET_HARD_FLOAT
5975    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5976   "
5977 {
5978   if (TARGET_E500_DOUBLE)
5979     {
5980       if (!REG_P (operands[1]))
5981         operands[1] = force_reg (SImode, operands[1]);
5982       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
5983       DONE;
5984     }
5985   else if (TARGET_LFIWZX && TARGET_FCFID)
5986     {
5987       emit_insn (gen_floatunssidf2_lfiwzx (operands[0], operands[1]));
5988       DONE;
5989     }
5990   else if (TARGET_FCFID)
5991     {
5992       rtx dreg = operands[1];
5993       if (!REG_P (dreg))
5994         dreg = force_reg (SImode, dreg);
5995       dreg = convert_to_mode (DImode, dreg, true);
5996       emit_insn (gen_floatdidf2 (operands[0], dreg));
5997       DONE;
5998     }
5999
6000   if (!REG_P (operands[1]))
6001     operands[1] = force_reg (SImode, operands[1]);
6002   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
6003   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
6004   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
6005   operands[5] = gen_reg_rtx (DFmode);
6006 }")
6007
6008 (define_insn_and_split "*floatunssidf2_internal"
6009   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
6010         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6011    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
6012    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
6013    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
6014    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))]
6015   "! TARGET_FCFIDU && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6016    && !(TARGET_FCFID && TARGET_POWERPC64)"
6017   "#"
6018   ""
6019   [(pc)]
6020   "
6021 {
6022   rtx lowword, highword;
6023   gcc_assert (MEM_P (operands[4]));
6024   highword = adjust_address (operands[4], SImode, 0);
6025   lowword = adjust_address (operands[4], SImode, 4);
6026   if (! WORDS_BIG_ENDIAN)
6027     {
6028       rtx tmp;
6029       tmp = highword; highword = lowword; lowword = tmp;
6030     }
6031
6032   emit_move_insn (lowword, operands[1]);
6033   emit_move_insn (highword, operands[2]);
6034   emit_move_insn (operands[5], operands[4]);
6035   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
6036   DONE;
6037 }"
6038   [(set_attr "length" "20")
6039    (set_attr "type" "fp")])
6040
6041 (define_expand "fix_trunc<mode>si2"
6042   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6043         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6044   "TARGET_HARD_FLOAT && ((TARGET_FPRS && <TARGET_FLOAT>) || <E500_CONVERT>)"
6045   "
6046 {
6047   if (!<E500_CONVERT>)
6048     {
6049       rtx tmp, stack;
6050
6051       if (TARGET_STFIWX)
6052         emit_insn (gen_fix_trunc<mode>si2_stfiwx (operands[0], operands[1]));
6053       else
6054         {
6055           tmp = gen_reg_rtx (DImode);
6056           stack = rs6000_allocate_stack_temp (DImode, true, false);
6057           emit_insn (gen_fix_trunc<mode>si2_internal (operands[0], operands[1],
6058                                                       tmp, stack));
6059         }
6060       DONE;
6061     }
6062 }")
6063
6064 ; Like the convert to float patterns, this insn must be split before
6065 ; register allocation so that it can allocate the memory slot if it
6066 ; needed
6067 (define_insn_and_split "fix_trunc<mode>si2_stfiwx"
6068   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
6069         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
6070    (clobber (match_scratch:DI 2 "=d"))]
6071   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6072    && (<MODE>mode != SFmode || TARGET_SINGLE_FLOAT)
6073    && TARGET_STFIWX && can_create_pseudo_p ()"
6074   "#"
6075   ""
6076   [(pc)]
6077 {
6078   rtx dest = operands[0];
6079   rtx src = operands[1];
6080   rtx tmp = operands[2];
6081
6082   if (GET_CODE (tmp) == SCRATCH)
6083     tmp = gen_reg_rtx (DImode);
6084
6085   emit_insn (gen_fctiwz_<mode> (tmp, src));
6086   if (MEM_P (dest))
6087     {
6088       dest = rs6000_address_for_fpconvert (dest);
6089       emit_insn (gen_stfiwx (dest, tmp));
6090       DONE;
6091     }
6092   else if (TARGET_POWERPC64 && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
6093     {
6094       dest = gen_lowpart (DImode, dest);
6095       emit_move_insn (dest, tmp);
6096       DONE;
6097     }
6098   else
6099     {
6100       rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6101       emit_insn (gen_stfiwx (stack, tmp));
6102       emit_move_insn (dest, stack);
6103       DONE;
6104     }
6105 }
6106   [(set_attr "length" "12")
6107    (set_attr "type" "fp")])
6108
6109 (define_insn_and_split "fix_trunc<mode>si2_internal"
6110   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,?r")
6111         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d,<rreg>")))
6112    (clobber (match_operand:DI 2 "gpc_reg_operand" "=1,d"))
6113    (clobber (match_operand:DI 3 "offsettable_mem_operand" "=o,o"))]
6114   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6115   "#"
6116   ""
6117   [(pc)]
6118   "
6119 {
6120   rtx lowword;
6121   gcc_assert (MEM_P (operands[3]));
6122   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
6123
6124   emit_insn (gen_fctiwz_<mode> (operands[2], operands[1]));
6125   emit_move_insn (operands[3], operands[2]);
6126   emit_move_insn (operands[0], lowword);
6127   DONE;
6128 }"
6129   [(set_attr "length" "16")
6130    (set_attr "type" "fp")])
6131
6132 (define_expand "fix_trunc<mode>di2"
6133   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6134         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6135   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6136    && TARGET_FCFID"
6137   "")
6138
6139 (define_insn "*fix_trunc<mode>di2_fctidz"
6140   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6141         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
6142   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6143     && TARGET_FCFID && !VECTOR_UNIT_VSX_P (<MODE>mode)"
6144   "fctidz %0,%1"
6145   [(set_attr "type" "fp")])
6146
6147 (define_expand "fixuns_trunc<mode>si2"
6148   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6149         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
6150   "TARGET_HARD_FLOAT
6151    && ((TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ && TARGET_STFIWX)
6152        || <E500_CONVERT>)"
6153   "
6154 {
6155   if (!<E500_CONVERT>)
6156     {
6157       emit_insn (gen_fixuns_trunc<mode>si2_stfiwx (operands[0], operands[1]));
6158       DONE;
6159     }
6160 }")
6161
6162 (define_insn_and_split "fixuns_trunc<mode>si2_stfiwx"
6163   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
6164         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
6165    (clobber (match_scratch:DI 2 "=d"))]
6166   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ
6167    && TARGET_STFIWX && can_create_pseudo_p ()"
6168   "#"
6169   ""
6170   [(pc)]
6171 {
6172   rtx dest = operands[0];
6173   rtx src = operands[1];
6174   rtx tmp = operands[2];
6175
6176   if (GET_CODE (tmp) == SCRATCH)
6177     tmp = gen_reg_rtx (DImode);
6178
6179   emit_insn (gen_fctiwuz_<mode> (tmp, src));
6180   if (MEM_P (dest))
6181     {
6182       dest = rs6000_address_for_fpconvert (dest);
6183       emit_insn (gen_stfiwx (dest, tmp));
6184       DONE;
6185     }
6186   else if (TARGET_POWERPC64 && (TARGET_MFPGPR || TARGET_DIRECT_MOVE))
6187     {
6188       dest = gen_lowpart (DImode, dest);
6189       emit_move_insn (dest, tmp);
6190       DONE;
6191     }
6192   else
6193     {
6194       rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6195       emit_insn (gen_stfiwx (stack, tmp));
6196       emit_move_insn (dest, stack);
6197       DONE;
6198     }
6199 }
6200   [(set_attr "length" "12")
6201    (set_attr "type" "fp")])
6202
6203 (define_expand "fixuns_trunc<mode>di2"
6204   [(set (match_operand:DI 0 "register_operand" "")
6205         (unsigned_fix:DI (match_operand:SFDF 1 "register_operand" "")))]
6206   "TARGET_HARD_FLOAT && (TARGET_FCTIDUZ || VECTOR_UNIT_VSX_P (<MODE>mode))"
6207   "")
6208
6209 (define_insn "*fixuns_trunc<mode>di2_fctiduz"
6210   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6211         (unsigned_fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
6212   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6213     && TARGET_FCTIDUZ && !VECTOR_UNIT_VSX_P (<MODE>mode)"
6214   "fctiduz %0,%1"
6215   [(set_attr "type" "fp")])
6216
6217 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
6218 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
6219 ; because the first makes it clear that operand 0 is not live
6220 ; before the instruction.
6221 (define_insn "fctiwz_<mode>"
6222   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6223         (unspec:DI [(fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))]
6224                    UNSPEC_FCTIWZ))]
6225   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
6226   "fctiwz %0,%1"
6227   [(set_attr "type" "fp")])
6228
6229 (define_insn "fctiwuz_<mode>"
6230   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6231         (unspec:DI [(unsigned_fix:SI
6232                      (match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>"))]
6233                    UNSPEC_FCTIWUZ))]
6234   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ"
6235   "fctiwuz %0,%1"
6236   [(set_attr "type" "fp")])
6237
6238 ;; Only optimize (float (fix x)) -> frz if we are in fast-math mode, since
6239 ;; since the friz instruction does not truncate the value if the floating
6240 ;; point value is < LONG_MIN or > LONG_MAX.
6241 (define_insn "*friz"
6242   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6243         (float:DF (fix:DI (match_operand:DF 1 "gpc_reg_operand" "d"))))]
6244   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_FPRND
6245    && !VECTOR_UNIT_VSX_P (DFmode) && flag_unsafe_math_optimizations
6246    && !flag_trapping_math && TARGET_FRIZ"
6247   "friz %0,%1"
6248   [(set_attr "type" "fp")])
6249
6250 ;; Since FCTIWZ doesn't sign extend the upper bits, we have to do a store and a
6251 ;; load to properly sign extend the value, but at least doing a store, load
6252 ;; into a GPR to sign extend, a store from the GPR and a load back into the FPR
6253 ;; if we have 32-bit memory ops
6254 (define_insn_and_split "*round32<mode>2_fprs"
6255   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
6256         (float:SFDF
6257          (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
6258    (clobber (match_scratch:DI 2 "=d"))
6259    (clobber (match_scratch:DI 3 "=d"))]
6260   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6261    && <SI_CONVERT_FP> && TARGET_LFIWAX && TARGET_STFIWX && TARGET_FCFID
6262    && can_create_pseudo_p ()"
6263   "#"
6264   ""
6265   [(pc)]
6266 {
6267   rtx dest = operands[0];
6268   rtx src = operands[1];
6269   rtx tmp1 = operands[2];
6270   rtx tmp2 = operands[3];
6271   rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6272
6273   if (GET_CODE (tmp1) == SCRATCH)
6274     tmp1 = gen_reg_rtx (DImode);
6275   if (GET_CODE (tmp2) == SCRATCH)
6276     tmp2 = gen_reg_rtx (DImode);
6277
6278   emit_insn (gen_fctiwz_<mode> (tmp1, src));
6279   emit_insn (gen_stfiwx (stack, tmp1));
6280   emit_insn (gen_lfiwax (tmp2, stack));
6281   emit_insn (gen_floatdi<mode>2 (dest, tmp2));
6282   DONE;
6283 }
6284   [(set_attr "type" "fpload")
6285    (set_attr "length" "16")])
6286
6287 (define_insn_and_split "*roundu32<mode>2_fprs"
6288   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
6289         (unsigned_float:SFDF
6290          (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
6291    (clobber (match_scratch:DI 2 "=d"))
6292    (clobber (match_scratch:DI 3 "=d"))]
6293   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6294    && TARGET_LFIWZX && TARGET_STFIWX && TARGET_FCFIDU
6295    && can_create_pseudo_p ()"
6296   "#"
6297   ""
6298   [(pc)]
6299 {
6300   rtx dest = operands[0];
6301   rtx src = operands[1];
6302   rtx tmp1 = operands[2];
6303   rtx tmp2 = operands[3];
6304   rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6305
6306   if (GET_CODE (tmp1) == SCRATCH)
6307     tmp1 = gen_reg_rtx (DImode);
6308   if (GET_CODE (tmp2) == SCRATCH)
6309     tmp2 = gen_reg_rtx (DImode);
6310
6311   emit_insn (gen_fctiwuz_<mode> (tmp1, src));
6312   emit_insn (gen_stfiwx (stack, tmp1));
6313   emit_insn (gen_lfiwzx (tmp2, stack));
6314   emit_insn (gen_floatdi<mode>2 (dest, tmp2));
6315   DONE;
6316 }
6317   [(set_attr "type" "fpload")
6318    (set_attr "length" "16")])
6319
6320 ;; No VSX equivalent to fctid
6321 (define_insn "lrint<mode>di2"
6322   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6323         (unspec:DI [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6324                    UNSPEC_FCTID))]
6325   "TARGET_<MODE>_FPR && TARGET_FPRND"
6326   "fctid %0,%1"
6327   [(set_attr "type" "fp")])
6328
6329 (define_insn "btrunc<mode>2"
6330   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
6331         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")]
6332                      UNSPEC_FRIZ))]
6333   "TARGET_<MODE>_FPR && TARGET_FPRND"
6334   "@
6335    friz %0,%1
6336    xsrdpiz %x0,%x1"
6337   [(set_attr "type" "fp")
6338    (set_attr "fp_type" "fp_addsub_<Fs>")])
6339
6340 (define_insn "ceil<mode>2"
6341   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
6342         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")]
6343                      UNSPEC_FRIP))]
6344   "TARGET_<MODE>_FPR && TARGET_FPRND"
6345   "@
6346    frip %0,%1
6347    xsrdpip %x0,%x1"
6348   [(set_attr "type" "fp")
6349    (set_attr "fp_type" "fp_addsub_<Fs>")])
6350
6351 (define_insn "floor<mode>2"
6352   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>")
6353         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>")]
6354                      UNSPEC_FRIM))]
6355   "TARGET_<MODE>_FPR && TARGET_FPRND"
6356   "@
6357    frim %0,%1
6358    xsrdpim %x0,%x1"
6359   [(set_attr "type" "fp")
6360    (set_attr "fp_type" "fp_addsub_<Fs>")])
6361
6362 ;; No VSX equivalent to frin
6363 (define_insn "round<mode>2"
6364   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
6365         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6366                      UNSPEC_FRIN))]
6367   "TARGET_<MODE>_FPR && TARGET_FPRND"
6368   "frin %0,%1"
6369   [(set_attr "type" "fp")
6370    (set_attr "fp_type" "fp_addsub_<Fs>")])
6371
6372 ; An UNSPEC is used so we don't have to support SImode in FP registers.
6373 (define_insn "stfiwx"
6374   [(set (match_operand:SI 0 "memory_operand" "=Z")
6375         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "d")]
6376                    UNSPEC_STFIWX))]
6377   "TARGET_PPC_GFXOPT"
6378   "stfiwx %1,%y0"
6379   [(set_attr "type" "fpstore")])
6380
6381 ;; If we don't have a direct conversion to single precision, don't enable this
6382 ;; conversion for 32-bit without fast math, because we don't have the insn to
6383 ;; generate the fixup swizzle to avoid double rounding problems.
6384 (define_expand "floatsisf2"
6385   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6386         (float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
6387   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
6388    && (!TARGET_FPRS
6389        || (TARGET_FPRS
6390            && ((TARGET_FCFIDS && TARGET_LFIWAX)
6391                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
6392                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
6393   "
6394 {
6395   if (!TARGET_FPRS)
6396     {
6397       if (!REG_P (operands[1]))
6398         operands[1] = force_reg (SImode, operands[1]);
6399     }
6400   else if (TARGET_FCFIDS && TARGET_LFIWAX)
6401     {
6402       emit_insn (gen_floatsisf2_lfiwax (operands[0], operands[1]));
6403       DONE;
6404     }
6405   else if (TARGET_FCFID && TARGET_LFIWAX)
6406     {
6407       rtx dfreg = gen_reg_rtx (DFmode);
6408       emit_insn (gen_floatsidf2_lfiwax (dfreg, operands[1]));
6409       emit_insn (gen_truncdfsf2 (operands[0], dfreg));
6410       DONE;
6411     }
6412   else
6413     {
6414       rtx dreg = operands[1];
6415       if (!REG_P (dreg))
6416         dreg = force_reg (SImode, dreg);
6417       dreg = convert_to_mode (DImode, dreg, false);
6418       emit_insn (gen_floatdisf2 (operands[0], dreg));
6419       DONE;
6420     }
6421 }")
6422
6423 (define_expand "floatdidf2"
6424   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6425         (float:DF (match_operand:DI 1 "gpc_reg_operand" "")))]
6426   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS"
6427   "")
6428
6429 (define_insn "*floatdidf2_fpr"
6430   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6431         (float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6432   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
6433    && !VECTOR_UNIT_VSX_P (DFmode)"
6434   "fcfid %0,%1"
6435   [(set_attr "type" "fp")])
6436
6437 ; Allow the combiner to merge source memory operands to the conversion so that
6438 ; the optimizer/register allocator doesn't try to load the value too early in a
6439 ; GPR and then use store/load to move it to a FPR and suffer from a store-load
6440 ; hit.  We will split after reload to avoid the trip through the GPRs
6441
6442 (define_insn_and_split "*floatdidf2_mem"
6443   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6444         (float:DF (match_operand:DI 1 "memory_operand" "m")))
6445    (clobber (match_scratch:DI 2 "=d"))]
6446   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS && TARGET_FCFID"
6447   "#"
6448   "&& reload_completed"
6449   [(set (match_dup 2) (match_dup 1))
6450    (set (match_dup 0) (float:DF (match_dup 2)))]
6451   ""
6452   [(set_attr "length" "8")
6453    (set_attr "type" "fpload")])
6454
6455 (define_expand "floatunsdidf2"
6456   [(set (match_operand:DF 0 "gpc_reg_operand" "")
6457         (unsigned_float:DF
6458          (match_operand:DI 1 "gpc_reg_operand" "")))]
6459   "TARGET_HARD_FLOAT && (TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode))"
6460   "")
6461
6462 (define_insn "*floatunsdidf2_fcfidu"
6463   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6464         (unsigned_float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6465   "TARGET_HARD_FLOAT && TARGET_FCFIDU && !VECTOR_UNIT_VSX_P (DFmode)"
6466   "fcfidu %0,%1"
6467   [(set_attr "type" "fp")
6468    (set_attr "length" "4")])
6469
6470 (define_insn_and_split "*floatunsdidf2_mem"
6471   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6472         (unsigned_float:DF (match_operand:DI 1 "memory_operand" "m")))
6473    (clobber (match_scratch:DI 2 "=d"))]
6474   "TARGET_HARD_FLOAT && (TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode))"
6475   "#"
6476   "&& reload_completed"
6477   [(set (match_dup 2) (match_dup 1))
6478    (set (match_dup 0) (unsigned_float:DF (match_dup 2)))]
6479   ""
6480   [(set_attr "length" "8")
6481    (set_attr "type" "fpload")])
6482
6483 (define_expand "floatdisf2"
6484   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6485         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
6486   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6487    && (TARGET_FCFIDS || TARGET_POWERPC64 || flag_unsafe_math_optimizations)"
6488   "
6489 {
6490   if (!TARGET_FCFIDS)
6491     {
6492       rtx val = operands[1];
6493       if (!flag_unsafe_math_optimizations)
6494         {
6495           rtx label = gen_label_rtx ();
6496           val = gen_reg_rtx (DImode);
6497           emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
6498           emit_label (label);
6499         }
6500       emit_insn (gen_floatdisf2_internal1 (operands[0], val));
6501       DONE;
6502     }
6503 }")
6504
6505 (define_insn "floatdisf2_fcfids"
6506   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6507         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6508   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6509    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
6510   "fcfids %0,%1"
6511   [(set_attr "type" "fp")])
6512
6513 (define_insn_and_split "*floatdisf2_mem"
6514   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6515         (float:SF (match_operand:DI 1 "memory_operand" "m")))
6516    (clobber (match_scratch:DI 2 "=f"))]
6517   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6518    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
6519   "#"
6520   "&& reload_completed"
6521   [(pc)]
6522   "
6523 {
6524   emit_move_insn (operands[2], operands[1]);
6525   emit_insn (gen_floatdisf2_fcfids (operands[0], operands[2]));
6526   DONE;
6527 }"
6528   [(set_attr "length" "8")])
6529
6530 ;; This is not IEEE compliant if rounding mode is "round to nearest".
6531 ;; If the DI->DF conversion is inexact, then it's possible to suffer
6532 ;; from double rounding.
6533 ;; Instead of creating a new cpu type for two FP operations, just use fp
6534 (define_insn_and_split "floatdisf2_internal1"
6535   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6536         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))
6537    (clobber (match_scratch:DF 2 "=d"))]
6538   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6539   "#"
6540   "&& reload_completed"
6541   [(set (match_dup 2)
6542         (float:DF (match_dup 1)))
6543    (set (match_dup 0)
6544         (float_truncate:SF (match_dup 2)))]
6545   ""
6546   [(set_attr "length" "8")
6547    (set_attr "type" "fp")])
6548
6549 ;; Twiddles bits to avoid double rounding.
6550 ;; Bits that might be truncated when converting to DFmode are replaced
6551 ;; by a bit that won't be lost at that stage, but is below the SFmode
6552 ;; rounding position.
6553 (define_expand "floatdisf2_internal2"
6554   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
6555                                    (const_int 53)))
6556    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
6557                                                       (const_int 2047)))
6558               (clobber (scratch:CC))])
6559    (set (match_dup 3) (plus:DI (match_dup 3)
6560                                (const_int 1)))
6561    (set (match_dup 0) (plus:DI (match_dup 0)
6562                                (const_int 2047)))
6563    (set (match_dup 4) (compare:CCUNS (match_dup 3)
6564                                      (const_int 2)))
6565    (set (match_dup 0) (ior:DI (match_dup 0)
6566                               (match_dup 1)))
6567    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
6568                                          (const_int -2048)))
6569               (clobber (scratch:CC))])
6570    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
6571                            (label_ref (match_operand:DI 2 "" ""))
6572                            (pc)))
6573    (set (match_dup 0) (match_dup 1))]
6574   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6575   "
6576 {
6577   operands[3] = gen_reg_rtx (DImode);
6578   operands[4] = gen_reg_rtx (CCUNSmode);
6579 }")
6580
6581 (define_expand "floatunsdisf2"
6582   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6583         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
6584   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6585    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6586   "")
6587
6588 (define_insn "floatunsdisf2_fcfidus"
6589   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6590         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6591   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6592    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6593   "fcfidus %0,%1"
6594   [(set_attr "type" "fp")])
6595
6596 (define_insn_and_split "*floatunsdisf2_mem"
6597   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6598         (unsigned_float:SF (match_operand:DI 1 "memory_operand" "m")))
6599    (clobber (match_scratch:DI 2 "=f"))]
6600   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6601    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6602   "#"
6603   "&& reload_completed"
6604   [(pc)]
6605   "
6606 {
6607   emit_move_insn (operands[2], operands[1]);
6608   emit_insn (gen_floatunsdisf2_fcfidus (operands[0], operands[2]));
6609   DONE;
6610 }"
6611   [(set_attr "length" "8")
6612    (set_attr "type" "fpload")])
6613 \f
6614 ;; Define the TImode operations that can be done in a small number
6615 ;; of instructions.  The & constraints are to prevent the register
6616 ;; allocator from allocating registers that overlap with the inputs
6617 ;; (for example, having an input in 7,8 and an output in 6,7).  We
6618 ;; also allow for the output being the same as one of the inputs.
6619
6620 (define_insn "addti3"
6621   [(set (match_operand:TI 0 "gpc_reg_operand" "=&r,&r,r,r")
6622         (plus:TI (match_operand:TI 1 "gpc_reg_operand" "%r,r,0,0")
6623                  (match_operand:TI 2 "reg_or_short_operand" "r,I,r,I")))]
6624   "TARGET_64BIT"
6625 {
6626   if (WORDS_BIG_ENDIAN)
6627     return (GET_CODE (operands[2])) != CONST_INT
6628             ? \"addc %L0,%L1,%L2\;adde %0,%1,%2\"
6629             : \"addic %L0,%L1,%2\;add%G2e %0,%1\";
6630   else
6631     return (GET_CODE (operands[2])) != CONST_INT
6632             ? \"addc %0,%1,%2\;adde %L0,%L1,%L2\"
6633             : \"addic %0,%1,%2\;add%G2e %L0,%L1\";
6634 }
6635   [(set_attr "type" "two")
6636    (set_attr "length" "8")])
6637
6638 (define_insn "subti3"
6639   [(set (match_operand:TI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
6640         (minus:TI (match_operand:TI 1 "reg_or_short_operand" "r,I,0,r,I")
6641                   (match_operand:TI 2 "gpc_reg_operand" "r,r,r,0,0")))]
6642   "TARGET_64BIT"
6643 {
6644   if (WORDS_BIG_ENDIAN)
6645     return (GET_CODE (operands[1]) != CONST_INT)
6646             ? \"subfc %L0,%L2,%L1\;subfe %0,%2,%1\"
6647             : \"subfic %L0,%L2,%1\;subf%G1e %0,%2\";
6648   else
6649     return (GET_CODE (operands[1]) != CONST_INT)
6650             ? \"subfc %0,%2,%1\;subfe %L0,%L2,%L1\"
6651             : \"subfic %0,%2,%1\;subf%G1e %L0,%L2\";
6652 }
6653   [(set_attr "type" "two")
6654    (set_attr "length" "8")])
6655
6656
6657 ;; Define the DImode operations that can be done in a small number
6658 ;; of instructions.  The & constraints are to prevent the register
6659 ;; allocator from allocating registers that overlap with the inputs
6660 ;; (for example, having an input in 7,8 and an output in 6,7).  We
6661 ;; also allow for the output being the same as one of the inputs.
6662
6663 (define_insn "*adddi3_noppc64"
6664   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
6665         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
6666                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
6667   "! TARGET_POWERPC64"
6668   "*
6669 {
6670   if (WORDS_BIG_ENDIAN)
6671     return (GET_CODE (operands[2])) != CONST_INT
6672             ? \"addc %L0,%L1,%L2\;adde %0,%1,%2\"
6673             : \"addic %L0,%L1,%2\;add%G2e %0,%1\";
6674   else
6675     return (GET_CODE (operands[2])) != CONST_INT
6676             ? \"addc %0,%1,%2\;adde %L0,%L1,%L2\"
6677             : \"addic %0,%1,%2\;add%G2e %L0,%L1\";
6678 }"
6679   [(set_attr "type" "two")
6680    (set_attr "length" "8")])
6681
6682 (define_insn "*subdi3_noppc64"
6683   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
6684         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
6685                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
6686   "! TARGET_POWERPC64"
6687   "*
6688 {
6689   if (WORDS_BIG_ENDIAN)
6690     return (GET_CODE (operands[1]) != CONST_INT)
6691             ? \"subfc %L0,%L2,%L1\;subfe %0,%2,%1\"
6692             : \"subfic %L0,%L2,%1\;subf%G1e %0,%2\";
6693   else
6694     return (GET_CODE (operands[1]) != CONST_INT)
6695             ? \"subfc %0,%2,%1\;subfe %L0,%L2,%L1\"
6696             : \"subfic %0,%2,%1\;subf%G1e %L0,%L2\";
6697 }"
6698   [(set_attr "type" "two")
6699    (set_attr "length" "8")])
6700
6701 (define_insn "*negdi2_noppc64"
6702   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6703         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
6704   "! TARGET_POWERPC64"
6705   "*
6706 {
6707   return (WORDS_BIG_ENDIAN)
6708     ? \"subfic %L0,%L1,0\;subfze %0,%1\"
6709     : \"subfic %0,%1,0\;subfze %L0,%L1\";
6710 }"
6711   [(set_attr "type" "two")
6712    (set_attr "length" "8")])
6713
6714 (define_insn "mulsidi3"
6715   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6716         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6717                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6718   "! TARGET_POWERPC64"
6719 {
6720   return (WORDS_BIG_ENDIAN)
6721     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
6722     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
6723 }
6724   [(set_attr "type" "mul")
6725    (set_attr "length" "8")])
6726
6727 (define_split
6728   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6729         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6730                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6731   "! TARGET_POWERPC64 && reload_completed"
6732   [(set (match_dup 3)
6733         (truncate:SI
6734          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
6735                                (sign_extend:DI (match_dup 2)))
6736                       (const_int 32))))
6737    (set (match_dup 4)
6738         (mult:SI (match_dup 1)
6739                  (match_dup 2)))]
6740   "
6741 {
6742   int endian = (WORDS_BIG_ENDIAN == 0);
6743   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6744   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6745 }")
6746
6747 (define_insn "umulsidi3"
6748   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6749         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6750                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6751   "! TARGET_POWERPC64"
6752   "*
6753 {
6754   return (WORDS_BIG_ENDIAN)
6755     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6756     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6757 }"
6758   [(set_attr "type" "mul")
6759    (set_attr "length" "8")])
6760
6761 (define_split
6762   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6763         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6764                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6765   "! TARGET_POWERPC64 && reload_completed"
6766   [(set (match_dup 3)
6767         (truncate:SI
6768          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
6769                                (zero_extend:DI (match_dup 2)))
6770                       (const_int 32))))
6771    (set (match_dup 4)
6772         (mult:SI (match_dup 1)
6773                  (match_dup 2)))]
6774   "
6775 {
6776   int endian = (WORDS_BIG_ENDIAN == 0);
6777   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6778   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6779 }")
6780
6781 (define_insn "smulsi3_highpart"
6782   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6783         (truncate:SI
6784          (lshiftrt:DI (mult:DI (sign_extend:DI
6785                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6786                                (sign_extend:DI
6787                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6788                       (const_int 32))))]
6789   ""
6790   "mulhw %0,%1,%2"
6791   [(set_attr "type" "mul")])
6792
6793 (define_insn "umulsi3_highpart"
6794   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6795         (truncate:SI
6796          (lshiftrt:DI (mult:DI (zero_extend:DI
6797                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6798                                (zero_extend:DI
6799                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6800                       (const_int 32))))]
6801   ""
6802   "mulhwu %0,%1,%2"
6803   [(set_attr "type" "mul")])
6804
6805 ;; Shift by a variable amount is too complex to be worth open-coding.  We
6806 ;; just handle shifts by constants.
6807 (define_insn "ashrdi3_no_power"
6808   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
6809         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6810                      (match_operand:SI 2 "const_int_operand" "M,i")))]
6811   "!TARGET_POWERPC64"
6812   "*
6813 {
6814   switch (which_alternative)
6815     {
6816     default:
6817       gcc_unreachable ();
6818     case 0:
6819       if (WORDS_BIG_ENDIAN)
6820         return \"srawi %0,%1,31\;srawi %L0,%1,%h2\";
6821       else
6822         return \"srawi %L0,%L1,31\;srawi %0,%L1,%h2\";
6823     case 1:
6824       if (WORDS_BIG_ENDIAN)
6825         return \"srwi %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;srawi %0,%1,%h2\";
6826       else
6827         return \"srwi %0,%1,%h2\;insrwi %0,%L1,%h2,0\;srawi %L0,%L1,%h2\";
6828     }
6829 }"
6830   [(set_attr "type" "two,three")
6831    (set_attr "length" "8,12")])
6832
6833 (define_insn "*ashrdisi3_noppc64be"
6834   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6835         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6836                                 (const_int 32)) 4))]
6837   "TARGET_32BIT && !TARGET_POWERPC64 && WORDS_BIG_ENDIAN"
6838   "*
6839 {
6840   if (REGNO (operands[0]) == REGNO (operands[1]))
6841     return \"\";
6842   else
6843     return \"mr %0,%1\";
6844 }"
6845    [(set_attr "length" "4")])
6846
6847 \f
6848 ;; PowerPC64 DImode operations.
6849
6850 (define_insn "muldi3"
6851   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6852         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6853                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
6854   "TARGET_POWERPC64"
6855   "@
6856    mulld %0,%1,%2
6857    mulli %0,%1,%2"
6858    [(set_attr "type" "mul")
6859     (set (attr "size")
6860       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
6861                 (const_string "8")
6862              (match_operand:SI 2 "short_cint_operand" "")
6863                 (const_string "16")]
6864         (const_string "64")))])
6865
6866 (define_insn "*muldi3_internal1"
6867   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6868         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6869                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6870                     (const_int 0)))
6871    (clobber (match_scratch:DI 3 "=r,r"))]
6872   "TARGET_POWERPC64"
6873   "@
6874    mulld. %3,%1,%2
6875    #"
6876   [(set_attr "type" "mul")
6877    (set_attr "size" "64")
6878    (set_attr "dot" "yes")
6879    (set_attr "length" "4,8")])
6880
6881 (define_split
6882   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6883         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6884                              (match_operand:DI 2 "gpc_reg_operand" ""))
6885                     (const_int 0)))
6886    (clobber (match_scratch:DI 3 ""))]
6887   "TARGET_POWERPC64 && reload_completed"
6888   [(set (match_dup 3)
6889         (mult:DI (match_dup 1) (match_dup 2)))
6890    (set (match_dup 0)
6891         (compare:CC (match_dup 3)
6892                     (const_int 0)))]
6893   "")
6894
6895 (define_insn "*muldi3_internal2"
6896   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6897         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6898                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6899                     (const_int 0)))
6900    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6901         (mult:DI (match_dup 1) (match_dup 2)))]
6902   "TARGET_POWERPC64"
6903   "@
6904    mulld. %0,%1,%2
6905    #"
6906   [(set_attr "type" "mul")
6907    (set_attr "size" "64")
6908    (set_attr "dot" "yes")
6909    (set_attr "length" "4,8")])
6910
6911 (define_split
6912   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
6913         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6914                              (match_operand:DI 2 "gpc_reg_operand" ""))
6915                     (const_int 0)))
6916    (set (match_operand:DI 0 "gpc_reg_operand" "")
6917         (mult:DI (match_dup 1) (match_dup 2)))]
6918   "TARGET_POWERPC64 && reload_completed"
6919   [(set (match_dup 0)
6920         (mult:DI (match_dup 1) (match_dup 2)))
6921    (set (match_dup 3)
6922         (compare:CC (match_dup 0)
6923                     (const_int 0)))]
6924   "")
6925
6926 (define_insn "smuldi3_highpart"
6927   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6928         (truncate:DI
6929          (lshiftrt:TI (mult:TI (sign_extend:TI
6930                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6931                                (sign_extend:TI
6932                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6933                       (const_int 64))))]
6934   "TARGET_POWERPC64"
6935   "mulhd %0,%1,%2"
6936   [(set_attr "type" "mul")
6937    (set_attr "size" "64")])
6938
6939 (define_insn "umuldi3_highpart"
6940   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6941         (truncate:DI
6942          (lshiftrt:TI (mult:TI (zero_extend:TI
6943                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6944                                (zero_extend:TI
6945                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6946                       (const_int 64))))]
6947   "TARGET_POWERPC64"
6948   "mulhdu %0,%1,%2"
6949   [(set_attr "type" "mul")
6950    (set_attr "size" "64")])
6951
6952 (define_expand "mulditi3"
6953   [(set (match_operand:TI 0 "gpc_reg_operand")
6954         (mult:TI (sign_extend:TI (match_operand:DI 1 "gpc_reg_operand"))
6955                  (sign_extend:TI (match_operand:DI 2 "gpc_reg_operand"))))]
6956   "TARGET_POWERPC64"
6957 {
6958   rtx l = gen_reg_rtx (DImode), h = gen_reg_rtx (DImode);
6959   emit_insn (gen_muldi3 (l, operands[1], operands[2]));
6960   emit_insn (gen_smuldi3_highpart (h, operands[1], operands[2]));
6961   emit_move_insn (gen_lowpart (DImode, operands[0]), l);
6962   emit_move_insn (gen_highpart (DImode, operands[0]), h);
6963   DONE;
6964 })
6965
6966 (define_expand "umulditi3"
6967   [(set (match_operand:TI 0 "gpc_reg_operand")
6968         (mult:TI (zero_extend:TI (match_operand:DI 1 "gpc_reg_operand"))
6969                  (zero_extend:TI (match_operand:DI 2 "gpc_reg_operand"))))]
6970   "TARGET_POWERPC64"
6971 {
6972   rtx l = gen_reg_rtx (DImode), h = gen_reg_rtx (DImode);
6973   emit_insn (gen_muldi3 (l, operands[1], operands[2]));
6974   emit_insn (gen_umuldi3_highpart (h, operands[1], operands[2]));
6975   emit_move_insn (gen_lowpart (DImode, operands[0]), l);
6976   emit_move_insn (gen_highpart (DImode, operands[0]), h);
6977   DONE;
6978 })
6979
6980 (define_insn "rotldi3"
6981   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6982         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6983                    (match_operand:DI 2 "reg_or_cint_operand" "r,i")))]
6984   "TARGET_POWERPC64"
6985   "@
6986    rldcl %0,%1,%2,0
6987    rldicl %0,%1,%H2,0"
6988   [(set_attr "type" "shift")
6989    (set_attr "var_shift" "yes,no")])
6990
6991 (define_insn "*rotldi3_internal2"
6992   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6993         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6994                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6995                     (const_int 0)))
6996    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6997   "TARGET_64BIT"
6998   "@
6999    rldcl. %3,%1,%2,0
7000    rldicl. %3,%1,%H2,0
7001    #
7002    #"
7003   [(set_attr "type" "shift")
7004    (set_attr "var_shift" "yes,no,yes,no")
7005    (set_attr "dot" "yes")
7006    (set_attr "length" "4,4,8,8")])
7007
7008 (define_split
7009   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7010         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7011                                (match_operand:DI 2 "reg_or_cint_operand" ""))
7012                     (const_int 0)))
7013    (clobber (match_scratch:DI 3 ""))]
7014   "TARGET_POWERPC64 && reload_completed"
7015   [(set (match_dup 3)
7016         (rotate:DI (match_dup 1) (match_dup 2)))
7017    (set (match_dup 0)
7018         (compare:CC (match_dup 3)
7019                     (const_int 0)))]
7020   "")
7021
7022 (define_insn "*rotldi3_internal3"
7023   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7024         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7025                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7026                     (const_int 0)))
7027    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7028         (rotate:DI (match_dup 1) (match_dup 2)))]
7029   "TARGET_64BIT"
7030   "@
7031    rldcl. %0,%1,%2,0
7032    rldicl. %0,%1,%H2,0
7033    #
7034    #"
7035   [(set_attr "type" "shift")
7036    (set_attr "var_shift" "yes,no,yes,no")
7037    (set_attr "dot" "yes")
7038    (set_attr "length" "4,4,8,8")])
7039
7040 (define_split
7041   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7042         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7043                                (match_operand:DI 2 "reg_or_cint_operand" ""))
7044                     (const_int 0)))
7045    (set (match_operand:DI 0 "gpc_reg_operand" "")
7046         (rotate:DI (match_dup 1) (match_dup 2)))]
7047   "TARGET_POWERPC64 && reload_completed"
7048   [(set (match_dup 0)
7049         (rotate:DI (match_dup 1) (match_dup 2)))
7050    (set (match_dup 3)
7051         (compare:CC (match_dup 0)
7052                     (const_int 0)))]
7053   "")
7054
7055 (define_insn "*rotldi3_internal4"
7056   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7057         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7058                            (match_operand:DI 2 "reg_or_cint_operand" "r,i"))
7059                 (match_operand:DI 3 "mask64_operand" "n,n")))]
7060   "TARGET_POWERPC64"
7061   "@
7062    rldc%B3 %0,%1,%2,%S3
7063    rldic%B3 %0,%1,%H2,%S3"
7064   [(set_attr "type" "shift")
7065    (set_attr "var_shift" "yes,no")])
7066
7067 (define_insn "*rotldi3_internal5"
7068   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7069         (compare:CC (and:DI
7070                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7071                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7072                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
7073                     (const_int 0)))
7074    (clobber (match_scratch:DI 4 "=r,r,r,r"))]
7075   "TARGET_64BIT"
7076   "@
7077    rldc%B3. %4,%1,%2,%S3
7078    rldic%B3. %4,%1,%H2,%S3
7079    #
7080    #"
7081   [(set_attr "type" "shift")
7082    (set_attr "var_shift" "yes,no,yes,no")
7083    (set_attr "dot" "yes")
7084    (set_attr "length" "4,4,8,8")])
7085
7086 (define_split
7087   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7088         (compare:CC (and:DI
7089                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7090                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
7091                      (match_operand:DI 3 "mask64_operand" ""))
7092                     (const_int 0)))
7093    (clobber (match_scratch:DI 4 ""))]
7094   "TARGET_POWERPC64 && reload_completed"
7095   [(set (match_dup 4)
7096         (and:DI (rotate:DI (match_dup 1)
7097                                 (match_dup 2))
7098                      (match_dup 3)))
7099    (set (match_dup 0)
7100         (compare:CC (match_dup 4)
7101                     (const_int 0)))]
7102   "")
7103
7104 (define_insn "*rotldi3_internal6"
7105   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
7106         (compare:CC (and:DI
7107                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7108                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
7109                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
7110                     (const_int 0)))
7111    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7112         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7113   "TARGET_64BIT"
7114   "@
7115    rldc%B3. %0,%1,%2,%S3
7116    rldic%B3. %0,%1,%H2,%S3
7117    #
7118    #"
7119   [(set_attr "type" "shift")
7120    (set_attr "var_shift" "yes,no,yes,no")
7121    (set_attr "dot" "yes")
7122    (set_attr "length" "4,4,8,8")])
7123
7124 (define_split
7125   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7126         (compare:CC (and:DI
7127                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7128                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
7129                      (match_operand:DI 3 "mask64_operand" ""))
7130                     (const_int 0)))
7131    (set (match_operand:DI 0 "gpc_reg_operand" "")
7132         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7133   "TARGET_POWERPC64 && reload_completed"
7134   [(set (match_dup 0)
7135         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
7136    (set (match_dup 4)
7137         (compare:CC (match_dup 0)
7138                     (const_int 0)))]
7139   "")
7140
7141 (define_insn "*rotldi3_internal7le"
7142   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7143         (zero_extend:DI
7144          (subreg:QI
7145           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7146                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7147   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN"
7148   "@
7149    rldcl %0,%1,%2,56
7150    rldicl %0,%1,%H2,56"
7151   [(set_attr "type" "shift")
7152    (set_attr "var_shift" "yes,no")])
7153
7154 (define_insn "*rotldi3_internal7be"
7155   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7156         (zero_extend:DI
7157          (subreg:QI
7158           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7159                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 7)))]
7160   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN"
7161   "@
7162    rldcl %0,%1,%2,56
7163    rldicl %0,%1,%H2,56"
7164   [(set_attr "type" "shift")
7165    (set_attr "var_shift" "yes,no")])
7166
7167 (define_insn "*rotldi3_internal8le"
7168   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7169         (compare:CC (zero_extend:DI
7170                      (subreg:QI
7171                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7172                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7173                     (const_int 0)))
7174    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7175   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7176   "@
7177    rldcl. %3,%1,%2,56
7178    rldicl. %3,%1,%H2,56
7179    #
7180    #"
7181   [(set_attr "type" "shift")
7182    (set_attr "var_shift" "yes,no,yes,no")
7183    (set_attr "dot" "yes")
7184    (set_attr "length" "4,4,8,8")])
7185
7186 (define_insn "*rotldi3_internal8be"
7187   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7188         (compare:CC (zero_extend:DI
7189                      (subreg:QI
7190                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7191                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 7))
7192                     (const_int 0)))
7193    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7194   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7195   "@
7196    rldcl. %3,%1,%2,56
7197    rldicl. %3,%1,%H2,56
7198    #
7199    #"
7200   [(set_attr "type" "shift")
7201    (set_attr "var_shift" "yes,no,yes,no")
7202    (set_attr "dot" "yes")
7203    (set_attr "length" "4,4,8,8")])
7204
7205 (define_split
7206   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7207         (compare:CC (zero_extend:DI
7208                      (subreg:QI
7209                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7210                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7211                     (const_int 0)))
7212    (clobber (match_scratch:DI 3 ""))]
7213   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7214   [(set (match_dup 3)
7215         (zero_extend:DI (subreg:QI
7216                       (rotate:DI (match_dup 1)
7217                                  (match_dup 2)) 0)))
7218    (set (match_dup 0)
7219         (compare:CC (match_dup 3)
7220                     (const_int 0)))]
7221   "")
7222
7223 (define_split
7224   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7225         (compare:CC (zero_extend:DI
7226                      (subreg:QI
7227                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7228                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 7))
7229                     (const_int 0)))
7230    (clobber (match_scratch:DI 3 ""))]
7231   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7232   [(set (match_dup 3)
7233         (zero_extend:DI (subreg:QI
7234                       (rotate:DI (match_dup 1)
7235                                  (match_dup 2)) 7)))
7236    (set (match_dup 0)
7237         (compare:CC (match_dup 3)
7238                     (const_int 0)))]
7239   "")
7240
7241 (define_insn "*rotldi3_internal9le"
7242   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7243         (compare:CC (zero_extend:DI
7244                      (subreg:QI
7245                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7246                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7247                     (const_int 0)))
7248    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7249         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7250   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7251   "@
7252    rldcl. %0,%1,%2,56
7253    rldicl. %0,%1,%H2,56
7254    #
7255    #"
7256   [(set_attr "type" "shift")
7257    (set_attr "var_shift" "yes,no,yes,no")
7258    (set_attr "dot" "yes")
7259    (set_attr "length" "4,4,8,8")])
7260
7261 (define_insn "*rotldi3_internal9be"
7262   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7263         (compare:CC (zero_extend:DI
7264                      (subreg:QI
7265                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7266                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 7))
7267                     (const_int 0)))
7268    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7269         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 7)))]
7270   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7271   "@
7272    rldcl. %0,%1,%2,56
7273    rldicl. %0,%1,%H2,56
7274    #
7275    #"
7276   [(set_attr "type" "shift")
7277    (set_attr "var_shift" "yes,no,yes,no")
7278    (set_attr "dot" "yes")
7279    (set_attr "length" "4,4,8,8")])
7280
7281 (define_split
7282   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7283         (compare:CC (zero_extend:DI
7284                      (subreg:QI
7285                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7286                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7287                     (const_int 0)))
7288    (set (match_operand:DI 0 "gpc_reg_operand" "")
7289         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7290   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7291   [(set (match_dup 0)
7292         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7293    (set (match_dup 3)
7294         (compare:CC (match_dup 0)
7295                     (const_int 0)))]
7296   "")
7297
7298 (define_split
7299   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7300         (compare:CC (zero_extend:DI
7301                      (subreg:QI
7302                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7303                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 7))
7304                     (const_int 0)))
7305    (set (match_operand:DI 0 "gpc_reg_operand" "")
7306         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 7)))]
7307   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7308   [(set (match_dup 0)
7309         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 7)))
7310    (set (match_dup 3)
7311         (compare:CC (match_dup 0)
7312                     (const_int 0)))]
7313   "")
7314
7315 (define_insn "*rotldi3_internal10le"
7316   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7317         (zero_extend:DI
7318          (subreg:HI
7319           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7320                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7321   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN"
7322   "@
7323    rldcl %0,%1,%2,48
7324    rldicl %0,%1,%H2,48"
7325   [(set_attr "type" "shift")
7326    (set_attr "var_shift" "yes,no")])
7327
7328 (define_insn "*rotldi3_internal10be"
7329   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7330         (zero_extend:DI
7331          (subreg:HI
7332           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7333                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 6)))]
7334   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN"
7335   "@
7336    rldcl %0,%1,%2,48
7337    rldicl %0,%1,%H2,48"
7338   [(set_attr "type" "shift")
7339    (set_attr "var_shift" "yes,no")])
7340
7341 (define_insn "*rotldi3_internal11le"
7342   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7343         (compare:CC (zero_extend:DI
7344                      (subreg:HI
7345                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7346                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7347                     (const_int 0)))
7348    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7349   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7350   "@
7351    rldcl. %3,%1,%2,48
7352    rldicl. %3,%1,%H2,48
7353    #
7354    #"
7355   [(set_attr "type" "shift")
7356    (set_attr "var_shift" "yes,no,yes,no")
7357    (set_attr "dot" "yes")
7358    (set_attr "length" "4,4,8,8")])
7359
7360 (define_insn "*rotldi3_internal11be"
7361   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7362         (compare:CC (zero_extend:DI
7363                      (subreg:HI
7364                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7365                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 6))
7366                     (const_int 0)))
7367    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7368   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7369   "@
7370    rldcl. %3,%1,%2,48
7371    rldicl. %3,%1,%H2,48
7372    #
7373    #"
7374   [(set_attr "type" "shift")
7375    (set_attr "var_shift" "yes,no,yes,no")
7376    (set_attr "dot" "yes")
7377    (set_attr "length" "4,4,8,8")])
7378
7379 (define_split
7380   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7381         (compare:CC (zero_extend:DI
7382                      (subreg:HI
7383                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7384                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7385                     (const_int 0)))
7386    (clobber (match_scratch:DI 3 ""))]
7387   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7388   [(set (match_dup 3)
7389         (zero_extend:DI (subreg:HI
7390                       (rotate:DI (match_dup 1)
7391                                  (match_dup 2)) 0)))
7392    (set (match_dup 0)
7393         (compare:CC (match_dup 3)
7394                     (const_int 0)))]
7395   "")
7396
7397 (define_split
7398   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7399         (compare:CC (zero_extend:DI
7400                      (subreg:HI
7401                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7402                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 6))
7403                     (const_int 0)))
7404    (clobber (match_scratch:DI 3 ""))]
7405   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7406   [(set (match_dup 3)
7407         (zero_extend:DI (subreg:HI
7408                       (rotate:DI (match_dup 1)
7409                                  (match_dup 2)) 6)))
7410    (set (match_dup 0)
7411         (compare:CC (match_dup 3)
7412                     (const_int 0)))]
7413   "")
7414
7415 (define_insn "*rotldi3_internal12le"
7416   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7417         (compare:CC (zero_extend:DI
7418                      (subreg:HI
7419                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7420                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7421                     (const_int 0)))
7422    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7423         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7424   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7425   "@
7426    rldcl. %0,%1,%2,48
7427    rldicl. %0,%1,%H2,48
7428    #
7429    #"
7430   [(set_attr "type" "shift")
7431    (set_attr "var_shift" "yes,no,yes,no")
7432    (set_attr "dot" "yes")
7433    (set_attr "length" "4,4,8,8")])
7434
7435 (define_insn "*rotldi3_internal12be"
7436   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7437         (compare:CC (zero_extend:DI
7438                      (subreg:HI
7439                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7440                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 6))
7441                     (const_int 0)))
7442    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7443         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 6)))]
7444   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7445   "@
7446    rldcl. %0,%1,%2,48
7447    rldicl. %0,%1,%H2,48
7448    #
7449    #"
7450   [(set_attr "type" "shift")
7451    (set_attr "var_shift" "yes,no,yes,no")
7452    (set_attr "dot" "yes")
7453    (set_attr "length" "4,4,8,8")])
7454
7455 (define_split
7456   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7457         (compare:CC (zero_extend:DI
7458                      (subreg:HI
7459                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7460                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7461                     (const_int 0)))
7462    (set (match_operand:DI 0 "gpc_reg_operand" "")
7463         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7464   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7465   [(set (match_dup 0)
7466         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7467    (set (match_dup 3)
7468         (compare:CC (match_dup 0)
7469                     (const_int 0)))]
7470   "")
7471
7472 (define_split
7473   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7474         (compare:CC (zero_extend:DI
7475                      (subreg:HI
7476                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7477                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 6))
7478                     (const_int 0)))
7479    (set (match_operand:DI 0 "gpc_reg_operand" "")
7480         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 6)))]
7481   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7482   [(set (match_dup 0)
7483         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 6)))
7484    (set (match_dup 3)
7485         (compare:CC (match_dup 0)
7486                     (const_int 0)))]
7487   "")
7488
7489 (define_insn "*rotldi3_internal13le"
7490   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7491         (zero_extend:DI
7492          (subreg:SI
7493           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7494                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7495   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN"
7496   "@
7497    rldcl %0,%1,%2,32
7498    rldicl %0,%1,%H2,32"
7499   [(set_attr "type" "shift")
7500    (set_attr "var_shift" "yes,no")])
7501
7502 (define_insn "*rotldi3_internal13be"
7503   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7504         (zero_extend:DI
7505          (subreg:SI
7506           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7507                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 4)))]
7508   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN"
7509   "@
7510    rldcl %0,%1,%2,32
7511    rldicl %0,%1,%H2,32"
7512   [(set_attr "type" "shift")
7513    (set_attr "var_shift" "yes,no")])
7514
7515 (define_insn "*rotldi3_internal14le"
7516   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7517         (compare:CC (zero_extend:DI
7518                      (subreg:SI
7519                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7520                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7521                     (const_int 0)))
7522    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7523   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7524   "@
7525    rldcl. %3,%1,%2,32
7526    rldicl. %3,%1,%H2,32
7527    #
7528    #"
7529   [(set_attr "type" "shift")
7530    (set_attr "var_shift" "yes,no,yes,no")
7531    (set_attr "dot" "yes")
7532    (set_attr "length" "4,4,8,8")])
7533
7534 (define_insn "*rotldi3_internal14be"
7535   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7536         (compare:CC (zero_extend:DI
7537                      (subreg:SI
7538                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7539                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 4))
7540                     (const_int 0)))
7541    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7542   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7543   "@
7544    rldcl. %3,%1,%2,32
7545    rldicl. %3,%1,%H2,32
7546    #
7547    #"
7548   [(set_attr "type" "shift")
7549    (set_attr "var_shift" "yes,no,yes,no")
7550    (set_attr "dot" "yes")
7551    (set_attr "length" "4,4,8,8")])
7552
7553 (define_split
7554   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7555         (compare:CC (zero_extend:DI
7556                      (subreg:SI
7557                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7558                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7559                     (const_int 0)))
7560    (clobber (match_scratch:DI 3 ""))]
7561   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7562   [(set (match_dup 3)
7563         (zero_extend:DI (subreg:SI
7564                       (rotate:DI (match_dup 1)
7565                                  (match_dup 2)) 0)))
7566    (set (match_dup 0)
7567         (compare:CC (match_dup 3)
7568                     (const_int 0)))]
7569   "")
7570
7571 (define_split
7572   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7573         (compare:CC (zero_extend:DI
7574                      (subreg:SI
7575                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7576                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 4))
7577                     (const_int 0)))
7578    (clobber (match_scratch:DI 3 ""))]
7579   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7580   [(set (match_dup 3)
7581         (zero_extend:DI (subreg:SI
7582                       (rotate:DI (match_dup 1)
7583                                  (match_dup 2)) 4)))
7584    (set (match_dup 0)
7585         (compare:CC (match_dup 3)
7586                     (const_int 0)))]
7587   "")
7588
7589 (define_insn "*rotldi3_internal15le"
7590   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7591         (compare:CC (zero_extend:DI
7592                      (subreg:SI
7593                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7594                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7595                     (const_int 0)))
7596    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7597         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7598   "TARGET_64BIT && !BYTES_BIG_ENDIAN"
7599   "@
7600    rldcl. %0,%1,%2,32
7601    rldicl. %0,%1,%H2,32
7602    #
7603    #"
7604   [(set_attr "type" "shift")
7605    (set_attr "var_shift" "yes,no,yes,no")
7606    (set_attr "dot" "yes")
7607    (set_attr "length" "4,4,8,8")])
7608
7609 (define_insn "*rotldi3_internal15be"
7610   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7611         (compare:CC (zero_extend:DI
7612                      (subreg:SI
7613                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7614                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 4))
7615                     (const_int 0)))
7616    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7617         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 4)))]
7618   "TARGET_64BIT && BYTES_BIG_ENDIAN"
7619   "@
7620    rldcl. %0,%1,%2,32
7621    rldicl. %0,%1,%H2,32
7622    #
7623    #"
7624   [(set_attr "type" "shift")
7625    (set_attr "var_shift" "yes,no,yes,no")
7626    (set_attr "dot" "yes")
7627    (set_attr "length" "4,4,8,8")])
7628
7629 (define_split
7630   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7631         (compare:CC (zero_extend:DI
7632                      (subreg:SI
7633                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7634                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7635                     (const_int 0)))
7636    (set (match_operand:DI 0 "gpc_reg_operand" "")
7637         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7638   "TARGET_POWERPC64 && !BYTES_BIG_ENDIAN && reload_completed"
7639   [(set (match_dup 0)
7640         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7641    (set (match_dup 3)
7642         (compare:CC (match_dup 0)
7643                     (const_int 0)))]
7644   "")
7645
7646 (define_split
7647   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7648         (compare:CC (zero_extend:DI
7649                      (subreg:SI
7650                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7651                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 4))
7652                     (const_int 0)))
7653    (set (match_operand:DI 0 "gpc_reg_operand" "")
7654         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 4)))]
7655   "TARGET_POWERPC64 && BYTES_BIG_ENDIAN && reload_completed"
7656   [(set (match_dup 0)
7657         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 4)))
7658    (set (match_dup 3)
7659         (compare:CC (match_dup 0)
7660                     (const_int 0)))]
7661   "")
7662
7663 (define_expand "ashldi3"
7664   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7665         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7666                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
7667   "TARGET_POWERPC64"
7668   "")
7669
7670 (define_insn "*ashldi3_internal1"
7671   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7672         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7673                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7674   "TARGET_POWERPC64"
7675   "@
7676    sld %0,%1,%2
7677    sldi %0,%1,%H2"
7678   [(set_attr "type" "shift")
7679    (set_attr "var_shift" "yes,no")])
7680
7681 (define_insn "*ashldi3_internal2"
7682   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7683         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7684                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7685                     (const_int 0)))
7686    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7687   "TARGET_64BIT"
7688   "@
7689    sld. %3,%1,%2
7690    sldi. %3,%1,%H2
7691    #
7692    #"
7693   [(set_attr "type" "shift")
7694    (set_attr "var_shift" "yes,no,yes,no")
7695    (set_attr "dot" "yes")
7696    (set_attr "length" "4,4,8,8")])
7697
7698 (define_split
7699   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7700         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7701                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7702                     (const_int 0)))
7703    (clobber (match_scratch:DI 3 ""))]
7704   "TARGET_POWERPC64 && reload_completed"
7705   [(set (match_dup 3)
7706         (ashift:DI (match_dup 1) (match_dup 2)))
7707    (set (match_dup 0)
7708         (compare:CC (match_dup 3)
7709                     (const_int 0)))]
7710   "")
7711
7712 (define_insn "*ashldi3_internal3"
7713   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7714         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7715                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7716                     (const_int 0)))
7717    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7718         (ashift:DI (match_dup 1) (match_dup 2)))]
7719   "TARGET_64BIT"
7720   "@
7721    sld. %0,%1,%2
7722    sldi. %0,%1,%H2
7723    #
7724    #"
7725   [(set_attr "type" "shift")
7726    (set_attr "var_shift" "yes,no,yes,no")
7727    (set_attr "dot" "yes")
7728    (set_attr "length" "4,4,8,8")])
7729
7730 (define_split
7731   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7732         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7733                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7734                     (const_int 0)))
7735    (set (match_operand:DI 0 "gpc_reg_operand" "")
7736         (ashift:DI (match_dup 1) (match_dup 2)))]
7737   "TARGET_POWERPC64 && reload_completed"
7738   [(set (match_dup 0)
7739         (ashift:DI (match_dup 1) (match_dup 2)))
7740    (set (match_dup 3)
7741         (compare:CC (match_dup 0)
7742                     (const_int 0)))]
7743   "")
7744
7745 (define_insn "*ashldi3_internal4"
7746   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7747         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7748                            (match_operand:SI 2 "const_int_operand" "i"))
7749                 (match_operand:DI 3 "const_int_operand" "n")))]
7750   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
7751   "rldic %0,%1,%H2,%W3"
7752   [(set_attr "type" "shift")])
7753
7754 (define_insn "ashldi3_internal5"
7755   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7756         (compare:CC
7757          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7758                             (match_operand:SI 2 "const_int_operand" "i,i"))
7759                  (match_operand:DI 3 "const_int_operand" "n,n"))
7760          (const_int 0)))
7761    (clobber (match_scratch:DI 4 "=r,r"))]
7762   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7763   "@
7764    rldic. %4,%1,%H2,%W3
7765    #"
7766   [(set_attr "type" "shift")
7767    (set_attr "dot" "yes")
7768    (set_attr "length" "4,8")])
7769
7770 (define_split
7771   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7772         (compare:CC
7773          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7774                             (match_operand:SI 2 "const_int_operand" ""))
7775                  (match_operand:DI 3 "const_int_operand" ""))
7776          (const_int 0)))
7777    (clobber (match_scratch:DI 4 ""))]
7778   "TARGET_POWERPC64 && reload_completed
7779    && includes_rldic_lshift_p (operands[2], operands[3])"
7780   [(set (match_dup 4)
7781         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7782                 (match_dup 3)))
7783    (set (match_dup 0)
7784         (compare:CC (match_dup 4)
7785                     (const_int 0)))]
7786   "")
7787
7788 (define_insn "*ashldi3_internal6"
7789   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7790         (compare:CC
7791          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7792                             (match_operand:SI 2 "const_int_operand" "i,i"))
7793                     (match_operand:DI 3 "const_int_operand" "n,n"))
7794          (const_int 0)))
7795    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7796         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7797   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7798   "@
7799    rldic. %0,%1,%H2,%W3
7800    #"
7801   [(set_attr "type" "shift")
7802    (set_attr "dot" "yes")
7803    (set_attr "length" "4,8")])
7804
7805 (define_split
7806   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7807         (compare:CC
7808          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7809                             (match_operand:SI 2 "const_int_operand" ""))
7810                  (match_operand:DI 3 "const_int_operand" ""))
7811          (const_int 0)))
7812    (set (match_operand:DI 0 "gpc_reg_operand" "")
7813         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7814   "TARGET_POWERPC64 && reload_completed
7815    && includes_rldic_lshift_p (operands[2], operands[3])"
7816   [(set (match_dup 0)
7817         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7818                 (match_dup 3)))
7819    (set (match_dup 4)
7820         (compare:CC (match_dup 0)
7821                     (const_int 0)))]
7822   "")
7823
7824 (define_insn "*ashldi3_internal7"
7825   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7826         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7827                            (match_operand:SI 2 "const_int_operand" "i"))
7828                 (match_operand:DI 3 "mask64_operand" "n")))]
7829   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
7830   "rldicr %0,%1,%H2,%S3"
7831   [(set_attr "type" "shift")])
7832
7833 (define_insn "ashldi3_internal8"
7834   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7835         (compare:CC
7836          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7837                             (match_operand:SI 2 "const_int_operand" "i,i"))
7838                  (match_operand:DI 3 "mask64_operand" "n,n"))
7839          (const_int 0)))
7840    (clobber (match_scratch:DI 4 "=r,r"))]
7841   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7842   "@
7843    rldicr. %4,%1,%H2,%S3
7844    #"
7845   [(set_attr "type" "shift")
7846    (set_attr "dot" "yes")
7847    (set_attr "length" "4,8")])
7848
7849 (define_split
7850   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7851         (compare:CC
7852          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7853                             (match_operand:SI 2 "const_int_operand" ""))
7854                  (match_operand:DI 3 "mask64_operand" ""))
7855          (const_int 0)))
7856    (clobber (match_scratch:DI 4 ""))]
7857   "TARGET_POWERPC64 && reload_completed
7858    && includes_rldicr_lshift_p (operands[2], operands[3])"
7859   [(set (match_dup 4)
7860         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7861                 (match_dup 3)))
7862    (set (match_dup 0)
7863         (compare:CC (match_dup 4)
7864                     (const_int 0)))]
7865   "")
7866
7867 (define_insn "*ashldi3_internal9"
7868   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7869         (compare:CC
7870          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7871                             (match_operand:SI 2 "const_int_operand" "i,i"))
7872                     (match_operand:DI 3 "mask64_operand" "n,n"))
7873          (const_int 0)))
7874    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7875         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7876   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7877   "@
7878    rldicr. %0,%1,%H2,%S3
7879    #"
7880   [(set_attr "type" "shift")
7881    (set_attr "dot" "yes")
7882    (set_attr "length" "4,8")])
7883
7884 (define_split
7885   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
7886         (compare:CC
7887          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7888                             (match_operand:SI 2 "const_int_operand" ""))
7889                  (match_operand:DI 3 "mask64_operand" ""))
7890          (const_int 0)))
7891    (set (match_operand:DI 0 "gpc_reg_operand" "")
7892         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7893   "TARGET_POWERPC64 && reload_completed
7894    && includes_rldicr_lshift_p (operands[2], operands[3])"
7895   [(set (match_dup 0)
7896         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7897                 (match_dup 3)))
7898    (set (match_dup 4)
7899         (compare:CC (match_dup 0)
7900                     (const_int 0)))]
7901   "")
7902
7903 (define_expand "lshrdi3"
7904   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7905         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7906                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7907   "TARGET_POWERPC64"
7908   "")
7909
7910 (define_insn "*lshrdi3_internal1"
7911   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7912         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7913                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7914   "TARGET_POWERPC64"
7915   "@
7916    srd %0,%1,%2
7917    srdi %0,%1,%H2"
7918   [(set_attr "type" "shift")
7919    (set_attr "var_shift" "yes,no")])
7920
7921 (define_insn "*lshrdi3_internal2"
7922   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7923         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7924                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7925                     (const_int 0)))
7926    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7927   "TARGET_64BIT "
7928   "@
7929    srd. %3,%1,%2
7930    srdi. %3,%1,%H2
7931    #
7932    #"
7933   [(set_attr "type" "shift")
7934    (set_attr "var_shift" "yes,no,yes,no")
7935    (set_attr "dot" "yes")
7936    (set_attr "length" "4,4,8,8")])
7937
7938 (define_split
7939   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7940         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7941                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7942                     (const_int 0)))
7943    (clobber (match_scratch:DI 3 ""))]
7944   "TARGET_POWERPC64 && reload_completed"
7945   [(set (match_dup 3)
7946         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7947    (set (match_dup 0)
7948         (compare:CC (match_dup 3)
7949                     (const_int 0)))]
7950   "")
7951
7952 (define_insn "*lshrdi3_internal3"
7953   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7954         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7955                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7956                     (const_int 0)))
7957    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7958         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7959   "TARGET_64BIT"
7960   "@
7961    srd. %0,%1,%2
7962    srdi. %0,%1,%H2
7963    #
7964    #"
7965   [(set_attr "type" "shift")
7966    (set_attr "var_shift" "yes,no,yes,no")
7967    (set_attr "dot" "yes")
7968    (set_attr "length" "4,4,8,8")])
7969
7970 (define_split
7971   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7972         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7973                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7974                     (const_int 0)))
7975    (set (match_operand:DI 0 "gpc_reg_operand" "")
7976         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7977   "TARGET_POWERPC64 && reload_completed"
7978   [(set (match_dup 0)
7979         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7980    (set (match_dup 3)
7981         (compare:CC (match_dup 0)
7982                     (const_int 0)))]
7983   "")
7984
7985 (define_expand "ashrdi3"
7986   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7987         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7988                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7989   ""
7990   "
7991 {
7992   if (TARGET_POWERPC64)
7993     ;
7994   else if (GET_CODE (operands[2]) == CONST_INT)
7995     {
7996       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
7997       DONE;
7998     }
7999   else
8000     FAIL;
8001 }")
8002
8003 (define_insn "*ashrdi3_internal1"
8004   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8005         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
8006                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
8007   "TARGET_POWERPC64"
8008   "@
8009    srad %0,%1,%2
8010    sradi %0,%1,%H2"
8011   [(set_attr "type" "shift")
8012    (set_attr "var_shift" "yes,no")])
8013
8014 (define_insn "*ashrdi3_internal2"
8015   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
8016         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8017                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8018                     (const_int 0)))
8019    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
8020   "TARGET_64BIT"
8021   "@
8022    srad. %3,%1,%2
8023    sradi. %3,%1,%H2
8024    #
8025    #"
8026   [(set_attr "type" "shift")
8027    (set_attr "var_shift" "yes,no,yes,no")
8028    (set_attr "dot" "yes")
8029    (set_attr "length" "4,4,8,8")])
8030
8031 (define_split
8032   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
8033         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8034                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8035                     (const_int 0)))
8036    (clobber (match_scratch:DI 3 ""))]
8037   "TARGET_POWERPC64 && reload_completed"
8038   [(set (match_dup 3)
8039         (ashiftrt:DI (match_dup 1) (match_dup 2)))
8040    (set (match_dup 0)
8041         (compare:CC (match_dup 3)
8042                     (const_int 0)))]
8043   "")
8044
8045 (define_insn "*ashrdi3_internal3"
8046   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
8047         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
8048                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
8049                     (const_int 0)))
8050    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8051         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
8052   "TARGET_64BIT"
8053   "@
8054    srad. %0,%1,%2
8055    sradi. %0,%1,%H2
8056    #
8057    #"
8058   [(set_attr "type" "shift")
8059    (set_attr "var_shift" "yes,no,yes,no")
8060    (set_attr "dot" "yes")
8061    (set_attr "length" "4,4,8,8")])
8062
8063 (define_split
8064   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
8065         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
8066                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
8067                     (const_int 0)))
8068    (set (match_operand:DI 0 "gpc_reg_operand" "")
8069         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
8070   "TARGET_POWERPC64 && reload_completed"
8071   [(set (match_dup 0)
8072         (ashiftrt:DI (match_dup 1) (match_dup 2)))
8073    (set (match_dup 3)
8074         (compare:CC (match_dup 0)
8075                     (const_int 0)))]
8076   "")
8077
8078 (define_expand "anddi3"
8079   [(parallel
8080     [(set (match_operand:DI 0 "gpc_reg_operand" "")
8081           (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8082                   (match_operand:DI 2 "reg_or_cint_operand" "")))
8083      (clobber (match_scratch:CC 3 ""))])]
8084   ""
8085 {
8086   if (!TARGET_POWERPC64)
8087     {
8088       rtx cc = gen_rtx_SCRATCH (CCmode);
8089       rs6000_split_logical (operands, AND, false, false, false, cc);
8090       DONE;
8091     }
8092   else if (!and64_2_operand (operands[2], DImode))
8093     operands[2] = force_reg (DImode, operands[2]);
8094 })
8095
8096 (define_insn "anddi3_mc"
8097   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
8098         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
8099                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
8100    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
8101   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
8102   "@
8103    and %0,%1,%2
8104    rldic%B2 %0,%1,0,%S2
8105    rlwinm %0,%1,0,%m2,%M2
8106    andi. %0,%1,%b2
8107    andis. %0,%1,%u2
8108    #"
8109   [(set_attr "type" "*,shift,shift,logical,logical,*")
8110    (set_attr "dot" "no,no,no,yes,yes,no")
8111    (set_attr "length" "4,4,4,4,4,8")])
8112
8113 (define_insn "anddi3_nomc"
8114   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
8115         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
8116                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,t")))
8117    (clobber (match_scratch:CC 3 "=X,X,X,X"))]
8118   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
8119   "@
8120    and %0,%1,%2
8121    rldic%B2 %0,%1,0,%S2
8122    rlwinm %0,%1,0,%m2,%M2
8123    #"
8124   [(set_attr "type" "*,shift,shift,*")
8125    (set_attr "length" "4,4,4,8")])
8126
8127 (define_split
8128   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8129         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8130                 (match_operand:DI 2 "mask64_2_operand" "")))
8131    (clobber (match_scratch:CC 3 ""))]
8132   "TARGET_POWERPC64
8133     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8134     && !mask_operand (operands[2], DImode)
8135     && !mask64_operand (operands[2], DImode)"
8136   [(set (match_dup 0)
8137         (and:DI (rotate:DI (match_dup 1)
8138                            (match_dup 4))
8139                 (match_dup 5)))
8140    (set (match_dup 0)
8141         (and:DI (rotate:DI (match_dup 0)
8142                            (match_dup 6))
8143                 (match_dup 7)))]
8144 {
8145   build_mask64_2_operands (operands[2], &operands[4]);
8146 })
8147
8148 (define_insn "*anddi3_internal2_mc"
8149   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
8150         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
8151                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
8152                     (const_int 0)))
8153    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r,r,r"))
8154    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
8155   "TARGET_64BIT && rs6000_gen_cell_microcode"
8156   "@
8157    and. %3,%1,%2
8158    rldic%B2. %3,%1,0,%S2
8159    rlwinm. %3,%1,0,%m2,%M2
8160    andi. %3,%1,%b2
8161    andis. %3,%1,%u2
8162    #
8163    #
8164    #
8165    #
8166    #
8167    #
8168    #"
8169   [(set_attr "type" "logical,shift,shift,logical,\
8170                      logical,compare,compare,compare,compare,compare,\
8171                      compare,compare")
8172    (set_attr "dot" "yes")
8173    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
8174
8175 (define_split
8176   [(set (match_operand:CC 0 "cc_reg_operand" "")
8177         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8178                             (match_operand:DI 2 "mask64_2_operand" ""))
8179                     (const_int 0)))
8180    (clobber (match_scratch:DI 3 ""))
8181    (clobber (match_scratch:CC 4 ""))]
8182   "TARGET_64BIT && reload_completed
8183     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8184     && !mask_operand (operands[2], DImode)
8185     && !mask64_operand (operands[2], DImode)"
8186   [(set (match_dup 3)
8187         (and:DI (rotate:DI (match_dup 1)
8188                            (match_dup 5))
8189                 (match_dup 6)))
8190    (parallel [(set (match_dup 0)
8191                    (compare:CC (and:DI (rotate:DI (match_dup 3)
8192                                                   (match_dup 7))
8193                                        (match_dup 8))
8194                                (const_int 0)))
8195               (clobber (match_dup 3))])]
8196   "
8197 {
8198   build_mask64_2_operands (operands[2], &operands[5]);
8199 }")
8200
8201 (define_insn "*anddi3_internal3_mc"
8202   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
8203         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
8204                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
8205                     (const_int 0)))
8206    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r,r,r")
8207         (and:DI (match_dup 1) (match_dup 2)))
8208    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
8209   "TARGET_64BIT && rs6000_gen_cell_microcode"
8210   "@
8211    and. %0,%1,%2
8212    rldic%B2. %0,%1,0,%S2
8213    rlwinm. %0,%1,0,%m2,%M2
8214    andi. %0,%1,%b2
8215    andis. %0,%1,%u2
8216    #
8217    #
8218    #
8219    #
8220    #
8221    #
8222    #"
8223   [(set_attr "type" "logical,shift,shift,logical,\
8224                      logical,compare,compare,compare,compare,compare,\
8225                      compare,compare")
8226    (set_attr "dot" "yes")
8227    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
8228
8229 (define_split
8230   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8231         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8232                             (match_operand:DI 2 "and64_2_operand" ""))
8233                     (const_int 0)))
8234    (set (match_operand:DI 0 "gpc_reg_operand" "")
8235         (and:DI (match_dup 1) (match_dup 2)))
8236    (clobber (match_scratch:CC 4 ""))]
8237   "TARGET_64BIT && reload_completed"
8238   [(parallel [(set (match_dup 0)
8239                     (and:DI (match_dup 1) (match_dup 2)))
8240                (clobber (match_dup 4))])
8241    (set (match_dup 3)
8242         (compare:CC (match_dup 0)
8243                     (const_int 0)))]
8244   "")
8245
8246 (define_split
8247   [(set (match_operand:CC 3 "cc_reg_operand" "")
8248         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
8249                             (match_operand:DI 2 "mask64_2_operand" ""))
8250                     (const_int 0)))
8251    (set (match_operand:DI 0 "gpc_reg_operand" "")
8252         (and:DI (match_dup 1) (match_dup 2)))
8253    (clobber (match_scratch:CC 4 ""))]
8254   "TARGET_64BIT && reload_completed
8255     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
8256     && !mask_operand (operands[2], DImode)
8257     && !mask64_operand (operands[2], DImode)"
8258   [(set (match_dup 0)
8259         (and:DI (rotate:DI (match_dup 1)
8260                            (match_dup 5))
8261                 (match_dup 6)))
8262    (parallel [(set (match_dup 3)
8263                    (compare:CC (and:DI (rotate:DI (match_dup 0)
8264                                                   (match_dup 7))
8265                                        (match_dup 8))
8266                                (const_int 0)))
8267               (set (match_dup 0)
8268                    (and:DI (rotate:DI (match_dup 0)
8269                                       (match_dup 7))
8270                            (match_dup 8)))])]
8271   "
8272 {
8273   build_mask64_2_operands (operands[2], &operands[5]);
8274 }")
8275
8276 (define_expand "iordi3"
8277   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8278         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
8279                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
8280   ""
8281 {
8282   if (!TARGET_POWERPC64)
8283     {
8284       rs6000_split_logical (operands, IOR, false, false, false, NULL_RTX);
8285       DONE;
8286     }
8287   else if (!reg_or_logical_cint_operand (operands[2], DImode))
8288     operands[2] = force_reg (DImode, operands[2]);
8289   else if (non_logical_cint_operand (operands[2], DImode))
8290     {
8291       HOST_WIDE_INT value;
8292       rtx tmp = ((!can_create_pseudo_p ()
8293                   || rtx_equal_p (operands[0], operands[1]))
8294                  ? operands[0] : gen_reg_rtx (DImode));
8295
8296       value = INTVAL (operands[2]);
8297       emit_insn (gen_iordi3 (tmp, operands[1],
8298                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
8299
8300       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
8301       DONE;
8302     }
8303 })
8304
8305 (define_expand "xordi3"
8306   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8307         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
8308                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
8309   ""
8310 {
8311   if (!TARGET_POWERPC64)
8312     {
8313       rs6000_split_logical (operands, XOR, false, false, false, NULL_RTX);
8314       DONE;
8315     }
8316   else if (!reg_or_logical_cint_operand (operands[2], DImode))
8317     operands[2] = force_reg (DImode, operands[2]);
8318   if (non_logical_cint_operand (operands[2], DImode))
8319     {
8320       HOST_WIDE_INT value;
8321       rtx tmp = ((!can_create_pseudo_p ()
8322                   || rtx_equal_p (operands[0], operands[1]))
8323                  ? operands[0] : gen_reg_rtx (DImode));
8324
8325       value = INTVAL (operands[2]);
8326       emit_insn (gen_xordi3 (tmp, operands[1],
8327                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
8328
8329       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
8330       DONE;
8331     }
8332 })
8333
8334 (define_insn "*booldi3_internal1"
8335   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
8336         (match_operator:DI 3 "boolean_or_operator"
8337          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
8338           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
8339   "TARGET_POWERPC64"
8340   "@
8341    %q3 %0,%1,%2
8342    %q3i %0,%1,%b2
8343    %q3is %0,%1,%u2")
8344
8345 (define_insn "*booldi3_internal2"
8346   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8347         (compare:CC (match_operator:DI 4 "boolean_or_operator"
8348          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
8349           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8350          (const_int 0)))
8351    (clobber (match_scratch:DI 3 "=r,r"))]
8352   "TARGET_64BIT"
8353   "@
8354    %q4. %3,%1,%2
8355    #"
8356   [(set_attr "type" "logical,compare")
8357    (set_attr "dot" "yes")
8358    (set_attr "length" "4,8")])
8359
8360 (define_split
8361   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8362         (compare:CC (match_operator:DI 4 "boolean_operator"
8363          [(match_operand:DI 1 "gpc_reg_operand" "")
8364           (match_operand:DI 2 "gpc_reg_operand" "")])
8365          (const_int 0)))
8366    (clobber (match_scratch:DI 3 ""))]
8367   "TARGET_POWERPC64 && reload_completed"
8368   [(set (match_dup 3) (match_dup 4))
8369    (set (match_dup 0)
8370         (compare:CC (match_dup 3)
8371                     (const_int 0)))]
8372   "")
8373
8374 (define_insn "*booldi3_internal3"
8375   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8376         (compare:CC (match_operator:DI 4 "boolean_or_operator"
8377          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
8378           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8379          (const_int 0)))
8380    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8381         (match_dup 4))]
8382   "TARGET_64BIT"
8383   "@
8384    %q4. %0,%1,%2
8385    #"
8386   [(set_attr "type" "logical,compare")
8387    (set_attr "dot" "yes")
8388    (set_attr "length" "4,8")])
8389
8390 (define_split
8391   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8392         (compare:CC (match_operator:DI 4 "boolean_operator"
8393          [(match_operand:DI 1 "gpc_reg_operand" "")
8394           (match_operand:DI 2 "gpc_reg_operand" "")])
8395          (const_int 0)))
8396    (set (match_operand:DI 0 "gpc_reg_operand" "")
8397         (match_dup 4))]
8398   "TARGET_POWERPC64 && reload_completed"
8399   [(set (match_dup 0) (match_dup 4))
8400    (set (match_dup 3)
8401         (compare:CC (match_dup 0)
8402                     (const_int 0)))]
8403   "")
8404
8405 ;; Split a logical operation that we can't do in one insn into two insns,
8406 ;; each of which does one 16-bit part.  This is used by combine.
8407
8408 (define_split
8409   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8410         (match_operator:DI 3 "boolean_or_operator"
8411          [(match_operand:DI 1 "gpc_reg_operand" "")
8412           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
8413   "TARGET_POWERPC64"
8414   [(set (match_dup 0) (match_dup 4))
8415    (set (match_dup 0) (match_dup 5))]
8416 "
8417 {
8418   rtx i3,i4;
8419
8420   i3 = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
8421   i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
8422   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
8423                                 operands[1], i3);
8424   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
8425                                 operands[0], i4);
8426 }")
8427
8428 (define_insn "*boolcdi3_internal1"
8429   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8430         (match_operator:DI 3 "boolean_operator"
8431          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
8432           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
8433   "TARGET_POWERPC64"
8434   "%q3 %0,%2,%1")
8435
8436 (define_insn "*boolcdi3_internal2"
8437   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8438         (compare:CC (match_operator:DI 4 "boolean_operator"
8439          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
8440           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8441          (const_int 0)))
8442    (clobber (match_scratch:DI 3 "=r,r"))]
8443   "TARGET_64BIT"
8444   "@
8445    %q4. %3,%2,%1
8446    #"
8447   [(set_attr "type" "logical,compare")
8448    (set_attr "dot" "yes")
8449    (set_attr "length" "4,8")])
8450
8451 (define_split
8452   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8453         (compare:CC (match_operator:DI 4 "boolean_operator"
8454          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8455           (match_operand:DI 2 "gpc_reg_operand" "")])
8456          (const_int 0)))
8457    (clobber (match_scratch:DI 3 ""))]
8458   "TARGET_POWERPC64 && reload_completed"
8459   [(set (match_dup 3) (match_dup 4))
8460    (set (match_dup 0)
8461         (compare:CC (match_dup 3)
8462                     (const_int 0)))]
8463   "")
8464
8465 (define_insn "*boolcdi3_internal3"
8466   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8467         (compare:CC (match_operator:DI 4 "boolean_operator"
8468          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
8469           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
8470          (const_int 0)))
8471    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8472         (match_dup 4))]
8473   "TARGET_64BIT"
8474   "@
8475    %q4. %0,%2,%1
8476    #"
8477   [(set_attr "type" "logical,compare")
8478    (set_attr "dot" "yes")
8479    (set_attr "length" "4,8")])
8480
8481 (define_split
8482   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8483         (compare:CC (match_operator:DI 4 "boolean_operator"
8484          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8485           (match_operand:DI 2 "gpc_reg_operand" "")])
8486          (const_int 0)))
8487    (set (match_operand:DI 0 "gpc_reg_operand" "")
8488         (match_dup 4))]
8489   "TARGET_POWERPC64 && reload_completed"
8490   [(set (match_dup 0) (match_dup 4))
8491    (set (match_dup 3)
8492         (compare:CC (match_dup 0)
8493                     (const_int 0)))]
8494   "")
8495
8496 (define_insn "*boolccdi3_internal1"
8497   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8498         (match_operator:DI 3 "boolean_operator"
8499          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
8500           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
8501   "TARGET_POWERPC64"
8502   "%q3 %0,%1,%2")
8503
8504 (define_insn "*boolccdi3_internal2"
8505   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
8506         (compare:CC (match_operator:DI 4 "boolean_operator"
8507          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
8508           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
8509          (const_int 0)))
8510    (clobber (match_scratch:DI 3 "=r,r"))]
8511   "TARGET_64BIT"
8512   "@
8513    %q4. %3,%1,%2
8514    #"
8515   [(set_attr "type" "logical,compare")
8516    (set_attr "dot" "yes")
8517    (set_attr "length" "4,8")])
8518
8519 (define_split
8520   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
8521         (compare:CC (match_operator:DI 4 "boolean_operator"
8522          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8523           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
8524          (const_int 0)))
8525    (clobber (match_scratch:DI 3 ""))]
8526   "TARGET_POWERPC64 && reload_completed"
8527   [(set (match_dup 3) (match_dup 4))
8528    (set (match_dup 0)
8529         (compare:CC (match_dup 3)
8530                     (const_int 0)))]
8531   "")
8532
8533 (define_insn "*boolccdi3_internal3"
8534   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
8535         (compare:CC (match_operator:DI 4 "boolean_operator"
8536          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
8537           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
8538          (const_int 0)))
8539    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
8540         (match_dup 4))]
8541   "TARGET_64BIT"
8542   "@
8543    %q4. %0,%1,%2
8544    #"
8545   [(set_attr "type" "logical,compare")
8546    (set_attr "dot" "yes")
8547    (set_attr "length" "4,8")])
8548
8549 (define_split
8550   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
8551         (compare:CC (match_operator:DI 4 "boolean_operator"
8552          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
8553           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
8554          (const_int 0)))
8555    (set (match_operand:DI 0 "gpc_reg_operand" "")
8556         (match_dup 4))]
8557   "TARGET_POWERPC64 && reload_completed"
8558   [(set (match_dup 0) (match_dup 4))
8559    (set (match_dup 3)
8560         (compare:CC (match_dup 0)
8561                     (const_int 0)))]
8562   "")
8563
8564 ;; Eqv operation.
8565 (define_insn "*eqv<mode>3"
8566   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
8567         (not:GPR
8568          (xor:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
8569                   (match_operand:GPR 2 "gpc_reg_operand" "r"))))]
8570   ""
8571   "eqv %0,%1,%2"
8572   [(set_attr "type" "integer")
8573    (set_attr "length" "4")])
8574
8575 \f
8576 ;; 128-bit logical operations expanders
8577
8578 (define_expand "and<mode>3"
8579   [(parallel [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8580                    (and:BOOL_128
8581                     (match_operand:BOOL_128 1 "vlogical_operand" "")
8582                     (match_operand:BOOL_128 2 "vlogical_operand" "")))
8583               (clobber (match_scratch:CC 3 ""))])]
8584   ""
8585   "")
8586
8587 (define_expand "ior<mode>3"
8588   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8589         (ior:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" "")
8590                       (match_operand:BOOL_128 2 "vlogical_operand" "")))]
8591   ""
8592   "")
8593
8594 (define_expand "xor<mode>3"
8595   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8596         (xor:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" "")
8597                       (match_operand:BOOL_128 2 "vlogical_operand" "")))]
8598   ""
8599   "")
8600
8601 (define_expand "one_cmpl<mode>2"
8602   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8603         (not:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" "")))]
8604   ""
8605   "")
8606
8607 (define_expand "nor<mode>3"
8608   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8609         (and:BOOL_128
8610          (not:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" ""))
8611          (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand" ""))))]
8612   ""
8613   "")
8614
8615 (define_expand "andc<mode>3"
8616   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8617         (and:BOOL_128
8618          (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand" ""))
8619          (match_operand:BOOL_128 1 "vlogical_operand" "")))]
8620   ""
8621   "")
8622
8623 ;; Power8 vector logical instructions.
8624 (define_expand "eqv<mode>3"
8625   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8626         (not:BOOL_128
8627          (xor:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" "")
8628                        (match_operand:BOOL_128 2 "vlogical_operand" ""))))]
8629   "<MODE>mode == TImode || <MODE>mode == PTImode || TARGET_P8_VECTOR"
8630   "")
8631
8632 ;; Rewrite nand into canonical form
8633 (define_expand "nand<mode>3"
8634   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8635         (ior:BOOL_128
8636          (not:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand" ""))
8637          (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand" ""))))]
8638   "<MODE>mode == TImode || <MODE>mode == PTImode || TARGET_P8_VECTOR"
8639   "")
8640
8641 ;; The canonical form is to have the negated element first, so we need to
8642 ;; reverse arguments.
8643 (define_expand "orc<mode>3"
8644   [(set (match_operand:BOOL_128 0 "vlogical_operand" "")
8645         (ior:BOOL_128
8646          (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand" ""))
8647          (match_operand:BOOL_128 1 "vlogical_operand" "")))]
8648   "<MODE>mode == TImode || <MODE>mode == PTImode || TARGET_P8_VECTOR"
8649   "")
8650
8651 ;; 128-bit logical operations insns and split operations
8652 (define_insn_and_split "*and<mode>3_internal"
8653   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8654         (and:BOOL_128
8655          (match_operand:BOOL_128 1 "vlogical_operand" "%<BOOL_REGS_OP1>")
8656          (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>")))
8657    (clobber (match_scratch:CC 3 "<BOOL_REGS_AND_CR0>"))]
8658   ""
8659 {
8660   if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
8661     return "xxland %x0,%x1,%x2";
8662
8663   if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
8664     return "vand %0,%1,%2";
8665
8666   return "#";
8667 }
8668   "reload_completed && int_reg_operand (operands[0], <MODE>mode)"
8669   [(const_int 0)]
8670 {
8671   rs6000_split_logical (operands, AND, false, false, false, operands[3]);
8672   DONE;
8673 }
8674   [(set (attr "type")
8675       (if_then_else
8676         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8677         (const_string "vecsimple")
8678         (const_string "integer")))
8679    (set (attr "length")
8680       (if_then_else
8681         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8682         (const_string "4")
8683         (if_then_else
8684          (match_test "TARGET_POWERPC64")
8685          (const_string "8")
8686          (const_string "16"))))])
8687
8688 ;; 128-bit IOR/XOR
8689 (define_insn_and_split "*bool<mode>3_internal"
8690   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8691         (match_operator:BOOL_128 3 "boolean_or_operator"
8692          [(match_operand:BOOL_128 1 "vlogical_operand" "%<BOOL_REGS_OP1>")
8693           (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>")]))]
8694   ""
8695 {
8696   if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
8697     return "xxl%q3 %x0,%x1,%x2";
8698
8699   if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
8700     return "v%q3 %0,%1,%2";
8701
8702   return "#";
8703 }
8704   "reload_completed && int_reg_operand (operands[0], <MODE>mode)"
8705   [(const_int 0)]
8706 {
8707   rs6000_split_logical (operands, GET_CODE (operands[3]), false, false, false,
8708                         NULL_RTX);
8709   DONE;
8710 }
8711   [(set (attr "type")
8712       (if_then_else
8713         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8714         (const_string "vecsimple")
8715         (const_string "integer")))
8716    (set (attr "length")
8717       (if_then_else
8718         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8719         (const_string "4")
8720         (if_then_else
8721          (match_test "TARGET_POWERPC64")
8722          (const_string "8")
8723          (const_string "16"))))])
8724
8725 ;; 128-bit ANDC/ORC
8726 (define_insn_and_split "*boolc<mode>3_internal1"
8727   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8728         (match_operator:BOOL_128 3 "boolean_operator"
8729          [(not:BOOL_128
8730            (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP1>"))
8731           (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_OP2>")]))]
8732   "TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND)"
8733 {
8734   if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
8735     return "xxl%q3 %x0,%x1,%x2";
8736
8737   if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
8738     return "v%q3 %0,%1,%2";
8739
8740   return "#";
8741 }
8742   "(TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND))
8743    && reload_completed && int_reg_operand (operands[0], <MODE>mode)"
8744   [(const_int 0)]
8745 {
8746   rs6000_split_logical (operands, GET_CODE (operands[3]), false, true, false,
8747                         NULL_RTX);
8748   DONE;
8749 }
8750   [(set (attr "type")
8751       (if_then_else
8752         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8753         (const_string "vecsimple")
8754         (const_string "integer")))
8755    (set (attr "length")
8756       (if_then_else
8757         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8758         (const_string "4")
8759         (if_then_else
8760          (match_test "TARGET_POWERPC64")
8761          (const_string "8")
8762          (const_string "16"))))])
8763
8764 (define_insn_and_split "*boolc<mode>3_internal2"
8765   [(set (match_operand:TI2 0 "int_reg_operand" "=&r,r,r")
8766         (match_operator:TI2 3 "boolean_operator"
8767          [(not:TI2
8768            (match_operand:TI2 1 "int_reg_operand" "r,0,r"))
8769           (match_operand:TI2 2 "int_reg_operand" "r,r,0")]))]
8770   "!TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
8771   "#"
8772   "reload_completed && !TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
8773   [(const_int 0)]
8774 {
8775   rs6000_split_logical (operands, GET_CODE (operands[3]), false, true, false,
8776                         NULL_RTX);
8777   DONE;
8778 }
8779   [(set_attr "type" "integer")
8780    (set (attr "length")
8781         (if_then_else
8782          (match_test "TARGET_POWERPC64")
8783          (const_string "8")
8784          (const_string "16")))])
8785
8786 ;; 128-bit NAND/NOR
8787 (define_insn_and_split "*boolcc<mode>3_internal1"
8788   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8789         (match_operator:BOOL_128 3 "boolean_operator"
8790          [(not:BOOL_128
8791            (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_OP1>"))
8792           (not:BOOL_128
8793            (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>"))]))]
8794   "TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND)"
8795 {
8796   if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
8797     return "xxl%q3 %x0,%x1,%x2";
8798
8799   if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
8800     return "v%q3 %0,%1,%2";
8801
8802   return "#";
8803 }
8804   "(TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND))
8805    && reload_completed && int_reg_operand (operands[0], <MODE>mode)"
8806   [(const_int 0)]
8807 {
8808   rs6000_split_logical (operands, GET_CODE (operands[3]), false, true, true,
8809                         NULL_RTX);
8810   DONE;
8811 }
8812   [(set (attr "type")
8813       (if_then_else
8814         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8815         (const_string "vecsimple")
8816         (const_string "integer")))
8817    (set (attr "length")
8818       (if_then_else
8819         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8820         (const_string "4")
8821         (if_then_else
8822          (match_test "TARGET_POWERPC64")
8823          (const_string "8")
8824          (const_string "16"))))])
8825
8826 (define_insn_and_split "*boolcc<mode>3_internal2"
8827   [(set (match_operand:TI2 0 "int_reg_operand" "=&r,r,r")
8828         (match_operator:TI2 3 "boolean_operator"
8829          [(not:TI2
8830            (match_operand:TI2 1 "int_reg_operand" "r,0,r"))
8831           (not:TI2
8832            (match_operand:TI2 2 "int_reg_operand" "r,r,0"))]))]
8833   "!TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
8834   "#"
8835   "reload_completed && !TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
8836   [(const_int 0)]
8837 {
8838   rs6000_split_logical (operands, GET_CODE (operands[3]), false, true, true,
8839                         NULL_RTX);
8840   DONE;
8841 }
8842   [(set_attr "type" "integer")
8843    (set (attr "length")
8844         (if_then_else
8845          (match_test "TARGET_POWERPC64")
8846          (const_string "8")
8847          (const_string "16")))])
8848
8849
8850 ;; 128-bit EQV
8851 (define_insn_and_split "*eqv<mode>3_internal1"
8852   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8853         (not:BOOL_128
8854          (xor:BOOL_128
8855           (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_OP1>")
8856           (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>"))))]
8857   "TARGET_P8_VECTOR"
8858 {
8859   if (vsx_register_operand (operands[0], <MODE>mode))
8860     return "xxleqv %x0,%x1,%x2";
8861
8862   return "#";
8863 }
8864   "TARGET_P8_VECTOR && reload_completed
8865    && int_reg_operand (operands[0], <MODE>mode)"
8866   [(const_int 0)]
8867 {
8868   rs6000_split_logical (operands, XOR, true, false, false, NULL_RTX);
8869   DONE;
8870 }
8871   [(set (attr "type")
8872       (if_then_else
8873         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8874         (const_string "vecsimple")
8875         (const_string "integer")))
8876    (set (attr "length")
8877       (if_then_else
8878         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8879         (const_string "4")
8880         (if_then_else
8881          (match_test "TARGET_POWERPC64")
8882          (const_string "8")
8883          (const_string "16"))))])
8884
8885 (define_insn_and_split "*eqv<mode>3_internal2"
8886   [(set (match_operand:TI2 0 "int_reg_operand" "=&r,r,r")
8887         (not:TI2
8888          (xor:TI2
8889           (match_operand:TI2 1 "int_reg_operand" "r,0,r")
8890           (match_operand:TI2 2 "int_reg_operand" "r,r,0"))))]
8891   "!TARGET_P8_VECTOR"
8892   "#"
8893   "reload_completed && !TARGET_P8_VECTOR"
8894   [(const_int 0)]
8895 {
8896   rs6000_split_logical (operands, XOR, true, false, false, NULL_RTX);
8897   DONE;
8898 }
8899   [(set_attr "type" "integer")
8900    (set (attr "length")
8901         (if_then_else
8902          (match_test "TARGET_POWERPC64")
8903          (const_string "8")
8904          (const_string "16")))])
8905
8906 ;; 128-bit one's complement
8907 (define_insn_and_split "*one_cmpl<mode>3_internal"
8908   [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
8909         (not:BOOL_128
8910           (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_UNARY>")))]
8911   ""
8912 {
8913   if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
8914     return "xxlnor %x0,%x1,%x1";
8915
8916   if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
8917     return "vnor %0,%1,%1";
8918
8919   return "#";
8920 }
8921   "reload_completed && int_reg_operand (operands[0], <MODE>mode)"
8922   [(const_int 0)]
8923 {
8924   rs6000_split_logical (operands, NOT, false, false, false, NULL_RTX);
8925   DONE;
8926 }
8927   [(set (attr "type")
8928       (if_then_else
8929         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8930         (const_string "vecsimple")
8931         (const_string "integer")))
8932    (set (attr "length")
8933       (if_then_else
8934         (match_test "vsx_register_operand (operands[0], <MODE>mode)")
8935         (const_string "4")
8936         (if_then_else
8937          (match_test "TARGET_POWERPC64")
8938          (const_string "8")
8939          (const_string "16"))))])
8940
8941 \f
8942 ;; Now define ways of moving data around.
8943
8944 ;; Set up a register with a value from the GOT table
8945
8946 (define_expand "movsi_got"
8947   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8948         (unspec:SI [(match_operand:SI 1 "got_operand" "")
8949                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
8950   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8951   "
8952 {
8953   if (GET_CODE (operands[1]) == CONST)
8954     {
8955       rtx offset = const0_rtx;
8956       HOST_WIDE_INT value;
8957
8958       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
8959       value = INTVAL (offset);
8960       if (value != 0)
8961         {
8962           rtx tmp = (!can_create_pseudo_p ()
8963                      ? operands[0]
8964                      : gen_reg_rtx (Pmode));
8965           emit_insn (gen_movsi_got (tmp, operands[1]));
8966           emit_insn (gen_addsi3 (operands[0], tmp, offset));
8967           DONE;
8968         }
8969     }
8970
8971   operands[2] = rs6000_got_register (operands[1]);
8972 }")
8973
8974 (define_insn "*movsi_got_internal"
8975   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8976         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8977                     (match_operand:SI 2 "gpc_reg_operand" "b")]
8978                    UNSPEC_MOVSI_GOT))]
8979   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8980   "lwz %0,%a1@got(%2)"
8981   [(set_attr "type" "load")])
8982
8983 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
8984 ;; didn't get allocated to a hard register.
8985 (define_split
8986   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8987         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8988                     (match_operand:SI 2 "memory_operand" "")]
8989                    UNSPEC_MOVSI_GOT))]
8990   "DEFAULT_ABI == ABI_V4
8991     && flag_pic == 1
8992     && (reload_in_progress || reload_completed)"
8993   [(set (match_dup 0) (match_dup 2))
8994    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
8995                                  UNSPEC_MOVSI_GOT))]
8996   "")
8997
8998 ;; For SI, we special-case integers that can't be loaded in one insn.  We
8999 ;; do the load 16-bits at a time.  We could do this by loading from memory,
9000 ;; and this is even supposed to be faster, but it is simpler not to get
9001 ;; integers in the TOC.
9002 (define_insn "movsi_low"
9003   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9004         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
9005                            (match_operand 2 "" ""))))]
9006   "TARGET_MACHO && ! TARGET_64BIT"
9007   "lwz %0,lo16(%2)(%1)"
9008   [(set_attr "type" "load")
9009    (set_attr "length" "4")])
9010
9011 (define_insn "*movsi_internal1"
9012   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,*c*l,*h,*h")
9013         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,*h,r,r,0"))]
9014   "!TARGET_SINGLE_FPU &&
9015    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
9016   "@
9017    mr %0,%1
9018    la %0,%a1
9019    lwz%U1%X1 %0,%1
9020    stw%U0%X0 %1,%0
9021    li %0,%1
9022    lis %0,%v1
9023    #
9024    mf%1 %0
9025    mt%0 %1
9026    mt%0 %1
9027    nop"
9028   [(set_attr "type" "*,*,load,store,*,*,*,mfjmpr,mtjmpr,*,*")
9029    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4")])
9030
9031 (define_insn "*movsi_internal1_single"
9032   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,*c*l,*h,*h,m,*f")
9033         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,*h,r,r,0,f,m"))]
9034   "TARGET_SINGLE_FPU &&
9035    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
9036   "@
9037    mr %0,%1
9038    la %0,%a1
9039    lwz%U1%X1 %0,%1
9040    stw%U0%X0 %1,%0
9041    li %0,%1
9042    lis %0,%v1
9043    #
9044    mf%1 %0
9045    mt%0 %1
9046    mt%0 %1
9047    nop
9048    stfs%U0%X0 %1,%0
9049    lfs%U1%X1 %0,%1"
9050   [(set_attr "type" "*,*,load,store,*,*,*,mfjmpr,mtjmpr,*,*,fpstore,fpload")
9051    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
9052
9053 ;; Split a load of a large constant into the appropriate two-insn
9054 ;; sequence.
9055
9056 (define_split
9057   [(set (match_operand:SI 0 "gpc_reg_operand" "")
9058         (match_operand:SI 1 "const_int_operand" ""))]
9059   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
9060    && (INTVAL (operands[1]) & 0xffff) != 0"
9061   [(set (match_dup 0)
9062         (match_dup 2))
9063    (set (match_dup 0)
9064         (ior:SI (match_dup 0)
9065                 (match_dup 3)))]
9066   "
9067 {
9068   if (rs6000_emit_set_const (operands[0], operands[1]))
9069     DONE;
9070   else
9071     FAIL;
9072 }")
9073
9074 (define_insn "*mov<mode>_internal2"
9075   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
9076         (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
9077                     (const_int 0)))
9078    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
9079   ""
9080   "@
9081    cmp<wd>i %2,%0,0
9082    mr. %0,%1
9083    #"
9084   [(set_attr "type" "cmp,logical,cmp")
9085    (set_attr "dot" "yes")
9086    (set_attr "length" "4,4,8")])
9087
9088 (define_split
9089   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
9090         (compare:CC (match_operand:P 1 "gpc_reg_operand" "")
9091                     (const_int 0)))
9092    (set (match_operand:P 0 "gpc_reg_operand" "") (match_dup 1))]
9093   "reload_completed"
9094   [(set (match_dup 0) (match_dup 1))
9095    (set (match_dup 2)
9096         (compare:CC (match_dup 0)
9097                     (const_int 0)))]
9098   "")
9099 \f
9100 (define_insn "*movhi_internal"
9101   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*c*l,*h")
9102         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,0"))]
9103   "gpc_reg_operand (operands[0], HImode)
9104    || gpc_reg_operand (operands[1], HImode)"
9105   "@
9106    mr %0,%1
9107    lhz%U1%X1 %0,%1
9108    sth%U0%X0 %1,%0
9109    li %0,%w1
9110    mf%1 %0
9111    mt%0 %1
9112    nop"
9113   [(set_attr "type" "*,load,store,*,mfjmpr,mtjmpr,*")])
9114
9115 (define_expand "mov<mode>"
9116   [(set (match_operand:INT 0 "general_operand" "")
9117         (match_operand:INT 1 "any_operand" ""))]
9118   ""
9119   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
9120
9121 (define_insn "*movqi_internal"
9122   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*c*l,*h")
9123         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,0"))]
9124   "gpc_reg_operand (operands[0], QImode)
9125    || gpc_reg_operand (operands[1], QImode)"
9126   "@
9127    mr %0,%1
9128    lbz%U1%X1 %0,%1
9129    stb%U0%X0 %1,%0
9130    li %0,%1
9131    mf%1 %0
9132    mt%0 %1
9133    nop"
9134   [(set_attr "type" "*,load,store,*,mfjmpr,mtjmpr,*")])
9135 \f
9136 ;; Here is how to move condition codes around.  When we store CC data in
9137 ;; an integer register or memory, we store just the high-order 4 bits.
9138 ;; This lets us not shift in the most common case of CR0.
9139 (define_expand "movcc"
9140   [(set (match_operand:CC 0 "nonimmediate_operand" "")
9141         (match_operand:CC 1 "nonimmediate_operand" ""))]
9142   ""
9143   "")
9144
9145 (define_insn "*movcc_internal1"
9146   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,y,r,r,r,r,r,cl,r,m")
9147         (match_operand:CC 1 "general_operand" "y,r,r,O,x,y,r,I,h,r,m,r"))]
9148   "register_operand (operands[0], CCmode)
9149    || register_operand (operands[1], CCmode)"
9150   "@
9151    mcrf %0,%1
9152    mtcrf 128,%1
9153    rlwinm %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;rlwinm %1,%1,%f0,0xffffffff
9154    crxor %0,%0,%0
9155    mfcr %0%Q1
9156    mfcr %0%Q1\;rlwinm %0,%0,%f1,0xf0000000
9157    mr %0,%1
9158    li %0,%1
9159    mf%1 %0
9160    mt%0 %1
9161    lwz%U1%X1 %0,%1
9162    stw%U0%X0 %1,%0"
9163   [(set (attr "type")
9164      (cond [(eq_attr "alternative" "0,3")
9165                 (const_string "cr_logical")
9166             (eq_attr "alternative" "1,2")
9167                 (const_string "mtcr")
9168             (eq_attr "alternative" "6,7")
9169                 (const_string "integer")
9170             (eq_attr "alternative" "8")
9171                 (const_string "mfjmpr")
9172             (eq_attr "alternative" "9")
9173                 (const_string "mtjmpr")
9174             (eq_attr "alternative" "10")
9175                 (const_string "load")
9176             (eq_attr "alternative" "11")
9177                 (const_string "store")
9178             (match_test "TARGET_MFCRF")
9179                 (const_string "mfcrf")
9180            ]
9181         (const_string "mfcr")))
9182    (set_attr "length" "4,4,12,4,4,8,4,4,4,4,4,4")])
9183 \f
9184 ;; For floating-point, we normally deal with the floating-point registers
9185 ;; unless -msoft-float is used.  The sole exception is that parameter passing
9186 ;; can produce floating-point values in fixed-point registers.  Unless the
9187 ;; value is a simple constant or already in memory, we deal with this by
9188 ;; allocating memory and copying the value explicitly via that memory location.
9189
9190 ;; Move 32-bit binary/decimal floating point
9191 (define_expand "mov<mode>"
9192   [(set (match_operand:FMOVE32 0 "nonimmediate_operand" "")
9193         (match_operand:FMOVE32 1 "any_operand" ""))]
9194   "<fmove_ok>"
9195   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
9196
9197 (define_split
9198   [(set (match_operand:FMOVE32 0 "gpc_reg_operand" "")
9199         (match_operand:FMOVE32 1 "const_double_operand" ""))]
9200   "reload_completed
9201    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9202        || (GET_CODE (operands[0]) == SUBREG
9203            && GET_CODE (SUBREG_REG (operands[0])) == REG
9204            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9205   [(set (match_dup 2) (match_dup 3))]
9206   "
9207 {
9208   long l;
9209   REAL_VALUE_TYPE rv;
9210
9211   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9212   <real_value_to_target> (rv, l);
9213
9214   if (! TARGET_POWERPC64)
9215     operands[2] = operand_subword (operands[0], 0, 0, <MODE>mode);
9216   else
9217     operands[2] = gen_lowpart (SImode, operands[0]);
9218
9219   operands[3] = gen_int_mode (l, SImode);
9220 }")
9221
9222 (define_insn "mov<mode>_hardfloat"
9223   [(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")
9224         (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"))]
9225   "(gpc_reg_operand (operands[0], <MODE>mode)
9226    || gpc_reg_operand (operands[1], <MODE>mode))
9227    && (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT)"
9228   "@
9229    mr %0,%1
9230    lwz%U1%X1 %0,%1
9231    stw%U0%X0 %1,%0
9232    fmr %0,%1
9233    xxlor %x0,%x1,%x1
9234    xxlxor %x0,%x0,%x0
9235    <f32_li>
9236    <f32_si>
9237    <f32_lv>
9238    <f32_sv>
9239    mtvsrwz %x0,%1
9240    mfvsrwz %0,%x1
9241    mt%0 %1
9242    mf%1 %0
9243    nop
9244    #
9245    #"
9246   [(set_attr "type" "*,load,store,fp,vecsimple,vecsimple,fpload,fpstore,fpload,fpstore,mftgpr,mffgpr,mtjmpr,mfjmpr,*,*,*")
9247    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8")])
9248
9249 (define_insn "*mov<mode>_softfloat"
9250   [(set (match_operand:FMOVE32 0 "nonimmediate_operand" "=r,cl,r,r,m,r,r,r,r,*h")
9251         (match_operand:FMOVE32 1 "input_operand" "r,r,h,m,r,I,L,G,Fn,0"))]
9252   "(gpc_reg_operand (operands[0], <MODE>mode)
9253    || gpc_reg_operand (operands[1], <MODE>mode))
9254    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
9255   "@
9256    mr %0,%1
9257    mt%0 %1
9258    mf%1 %0
9259    lwz%U1%X1 %0,%1
9260    stw%U0%X0 %1,%0
9261    li %0,%1
9262    lis %0,%v1
9263    #
9264    #
9265    nop"
9266   [(set_attr "type" "*,mtjmpr,mfjmpr,load,store,*,*,*,*,*")
9267    (set_attr "length" "4,4,4,4,4,4,4,4,8,4")])
9268
9269 \f
9270 ;; Move 64-bit binary/decimal floating point
9271 (define_expand "mov<mode>"
9272   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "")
9273         (match_operand:FMOVE64 1 "any_operand" ""))]
9274   ""
9275   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
9276
9277 (define_split
9278   [(set (match_operand:FMOVE64 0 "gpc_reg_operand" "")
9279         (match_operand:FMOVE64 1 "const_int_operand" ""))]
9280   "! TARGET_POWERPC64 && reload_completed
9281    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9282        || (GET_CODE (operands[0]) == SUBREG
9283            && GET_CODE (SUBREG_REG (operands[0])) == REG
9284            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9285   [(set (match_dup 2) (match_dup 4))
9286    (set (match_dup 3) (match_dup 1))]
9287   "
9288 {
9289   int endian = (WORDS_BIG_ENDIAN == 0);
9290   HOST_WIDE_INT value = INTVAL (operands[1]);
9291
9292   operands[2] = operand_subword (operands[0], endian, 0, <MODE>mode);
9293   operands[3] = operand_subword (operands[0], 1 - endian, 0, <MODE>mode);
9294   operands[4] = GEN_INT (value >> 32);
9295   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
9296 }")
9297
9298 (define_split
9299   [(set (match_operand:FMOVE64 0 "gpc_reg_operand" "")
9300         (match_operand:FMOVE64 1 "const_double_operand" ""))]
9301   "! TARGET_POWERPC64 && reload_completed
9302    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9303        || (GET_CODE (operands[0]) == SUBREG
9304            && GET_CODE (SUBREG_REG (operands[0])) == REG
9305            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9306   [(set (match_dup 2) (match_dup 4))
9307    (set (match_dup 3) (match_dup 5))]
9308   "
9309 {
9310   int endian = (WORDS_BIG_ENDIAN == 0);
9311   long l[2];
9312   REAL_VALUE_TYPE rv;
9313
9314   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9315   <real_value_to_target> (rv, l);
9316
9317   operands[2] = operand_subword (operands[0], endian, 0, <MODE>mode);
9318   operands[3] = operand_subword (operands[0], 1 - endian, 0, <MODE>mode);
9319   operands[4] = gen_int_mode (l[endian], SImode);
9320   operands[5] = gen_int_mode (l[1 - endian], SImode);
9321 }")
9322
9323 (define_split
9324   [(set (match_operand:FMOVE64 0 "gpc_reg_operand" "")
9325         (match_operand:FMOVE64 1 "const_double_operand" ""))]
9326   "TARGET_POWERPC64 && reload_completed
9327    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
9328        || (GET_CODE (operands[0]) == SUBREG
9329            && GET_CODE (SUBREG_REG (operands[0])) == REG
9330            && REGNO (SUBREG_REG (operands[0])) <= 31))"
9331   [(set (match_dup 2) (match_dup 3))]
9332   "
9333 {
9334   int endian = (WORDS_BIG_ENDIAN == 0);
9335   long l[2];
9336   REAL_VALUE_TYPE rv;
9337   HOST_WIDE_INT val;
9338
9339   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
9340   <real_value_to_target> (rv, l);
9341
9342   operands[2] = gen_lowpart (DImode, operands[0]);
9343   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
9344   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
9345          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
9346
9347   operands[3] = gen_int_mode (val, DImode);
9348 }")
9349
9350 ;; Don't have reload use general registers to load a constant.  It is
9351 ;; less efficient than loading the constant into an FP register, since
9352 ;; it will probably be used there.
9353
9354 ;; The move constraints are ordered to prefer floating point registers before
9355 ;; general purpose registers to avoid doing a store and a load to get the value
9356 ;; into a floating point register when it is needed for a floating point
9357 ;; operation.  Prefer traditional floating point registers over VSX registers,
9358 ;; since the D-form version of the memory instructions does not need a GPR for
9359 ;; reloading.
9360
9361 (define_insn "*mov<mode>_hardfloat32"
9362   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "=m,d,d,wv,Z,wa,wa,Y,r,!r,!r,!r,!r")
9363         (match_operand:FMOVE64 1 "input_operand" "d,m,d,Z,wv,wa,j,r,Y,r,G,H,F"))]
9364   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9365    && (gpc_reg_operand (operands[0], <MODE>mode)
9366        || gpc_reg_operand (operands[1], <MODE>mode))"
9367   "@
9368    stfd%U0%X0 %1,%0
9369    lfd%U1%X1 %0,%1
9370    fmr %0,%1
9371    lxsd%U1x %x0,%y1
9372    stxsd%U0x %x1,%y0
9373    xxlor %x0,%x1,%x1
9374    xxlxor %x0,%x0,%x0
9375    #
9376    #
9377    #
9378    #
9379    #
9380    #"
9381   [(set_attr "type" "fpstore,fpload,fp,fpload,fpstore,vecsimple,vecsimple,store,load,two,fp,fp,*")
9382    (set_attr "length" "4,4,4,4,4,4,4,8,8,8,8,12,16")])
9383
9384 (define_insn "*mov<mode>_softfloat32"
9385   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "=Y,r,r,r,r,r")
9386         (match_operand:FMOVE64 1 "input_operand" "r,Y,r,G,H,F"))]
9387   "! TARGET_POWERPC64 
9388    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) 
9389        || TARGET_SOFT_FLOAT || TARGET_E500_SINGLE
9390        || (<MODE>mode == DDmode && TARGET_E500_DOUBLE))
9391    && (gpc_reg_operand (operands[0], <MODE>mode)
9392        || gpc_reg_operand (operands[1], <MODE>mode))"
9393   "#"
9394   [(set_attr "type" "store,load,two,*,*,*")
9395    (set_attr "length" "8,8,8,8,12,16")])
9396
9397 ; ld/std require word-aligned displacements -> 'Y' constraint.
9398 ; List Y->r and r->Y before r->r for reload.
9399 (define_insn "*mov<mode>_hardfloat64"
9400   [(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")
9401         (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"))]
9402   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
9403    && (gpc_reg_operand (operands[0], <MODE>mode)
9404        || gpc_reg_operand (operands[1], <MODE>mode))"
9405   "@
9406    stfd%U0%X0 %1,%0
9407    lfd%U1%X1 %0,%1
9408    fmr %0,%1
9409    lxsd%U1x %x0,%y1
9410    stxsd%U0x %x1,%y0
9411    xxlor %x0,%x1,%x1
9412    xxlxor %x0,%x0,%x0
9413    std%U0%X0 %1,%0
9414    ld%U1%X1 %0,%1
9415    mr %0,%1
9416    mt%0 %1
9417    mf%1 %0
9418    nop
9419    #
9420    #
9421    #
9422    mftgpr %0,%1
9423    mffgpr %0,%1
9424    mfvsrd %0,%x1
9425    mtvsrd %x0,%1"
9426   [(set_attr "type" "fpstore,fpload,fp,fpload,fpstore,vecsimple,vecsimple,store,load,*,mtjmpr,mfjmpr,*,*,*,*,mftgpr,mffgpr,mftgpr,mffgpr")
9427    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16,4,4,4,4")])
9428
9429 (define_insn "*mov<mode>_softfloat64"
9430   [(set (match_operand:FMOVE64 0 "nonimmediate_operand" "=Y,r,r,cl,r,r,r,r,*h")
9431         (match_operand:FMOVE64 1 "input_operand" "r,Y,r,r,h,G,H,F,0"))]
9432   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
9433    && (gpc_reg_operand (operands[0], <MODE>mode)
9434        || gpc_reg_operand (operands[1], <MODE>mode))"
9435   "@
9436    std%U0%X0 %1,%0
9437    ld%U1%X1 %0,%1
9438    mr %0,%1
9439    mt%0 %1
9440    mf%1 %0
9441    #
9442    #
9443    #
9444    nop"
9445   [(set_attr "type" "store,load,*,mtjmpr,mfjmpr,*,*,*,*")
9446    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
9447 \f
9448 (define_expand "mov<mode>"
9449   [(set (match_operand:FMOVE128 0 "general_operand" "")
9450         (match_operand:FMOVE128 1 "any_operand" ""))]
9451   ""
9452   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
9453
9454 ;; It's important to list Y->r and r->Y before r->r because otherwise
9455 ;; reload, given m->r, will try to pick r->r and reload it, which
9456 ;; doesn't make progress.
9457
9458 ;; We can't split little endian direct moves of TDmode, because the words are
9459 ;; not swapped like they are for TImode or TFmode.  Subregs therefore are
9460 ;; problematical.  Don't allow direct move for this case.
9461
9462 (define_insn_and_split "*mov<mode>_64bit_dm"
9463   [(set (match_operand:FMOVE128 0 "nonimmediate_operand" "=m,d,d,Y,r,r,r,wm")
9464         (match_operand:FMOVE128 1 "input_operand" "d,m,d,r,YGHF,r,wm,r"))]
9465   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_POWERPC64
9466    && (<MODE>mode != TDmode || WORDS_BIG_ENDIAN)
9467    && (gpc_reg_operand (operands[0], <MODE>mode)
9468        || gpc_reg_operand (operands[1], <MODE>mode))"
9469   "#"
9470   "&& reload_completed"
9471   [(pc)]
9472 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9473   [(set_attr "length" "8,8,8,12,12,8,8,8")])
9474
9475 (define_insn_and_split "*movtd_64bit_nodm"
9476   [(set (match_operand:TD 0 "nonimmediate_operand" "=m,d,d,Y,r,r")
9477         (match_operand:TD 1 "input_operand" "d,m,d,r,YGHF,r"))]
9478   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_POWERPC64 && !WORDS_BIG_ENDIAN
9479    && (gpc_reg_operand (operands[0], TDmode)
9480        || gpc_reg_operand (operands[1], TDmode))"
9481   "#"
9482   "&& reload_completed"
9483   [(pc)]
9484 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9485   [(set_attr "length" "8,8,8,12,12,8")])
9486
9487 (define_insn_and_split "*mov<mode>_32bit"
9488   [(set (match_operand:FMOVE128 0 "nonimmediate_operand" "=m,d,d,Y,r,r")
9489         (match_operand:FMOVE128 1 "input_operand" "d,m,d,r,YGHF,r"))]
9490   "TARGET_HARD_FLOAT && TARGET_FPRS && !TARGET_POWERPC64
9491    && (gpc_reg_operand (operands[0], <MODE>mode)
9492        || gpc_reg_operand (operands[1], <MODE>mode))"
9493   "#"
9494   "&& reload_completed"
9495   [(pc)]
9496 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9497   [(set_attr "length" "8,8,8,20,20,16")])
9498
9499 (define_insn_and_split "*mov<mode>_softfloat"
9500   [(set (match_operand:FMOVE128 0 "rs6000_nonimmediate_operand" "=Y,r,r")
9501         (match_operand:FMOVE128 1 "input_operand" "r,YGHF,r"))]
9502   "(TARGET_SOFT_FLOAT || !TARGET_FPRS)
9503    && (gpc_reg_operand (operands[0], <MODE>mode)
9504        || gpc_reg_operand (operands[1], <MODE>mode))"
9505   "#"
9506   "&& reload_completed"
9507   [(pc)]
9508 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
9509   [(set_attr "length" "20,20,16")])
9510
9511 (define_expand "extenddftf2"
9512   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9513         (float_extend:TF (match_operand:DF 1 "input_operand" "")))]
9514   "!TARGET_IEEEQUAD
9515    && TARGET_HARD_FLOAT
9516    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9517    && TARGET_LONG_DOUBLE_128"
9518 {
9519   if (TARGET_E500_DOUBLE)
9520     emit_insn (gen_spe_extenddftf2 (operands[0], operands[1]));
9521   else
9522     emit_insn (gen_extenddftf2_fprs (operands[0], operands[1]));
9523   DONE;
9524 })
9525
9526 (define_expand "extenddftf2_fprs"
9527   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
9528                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
9529               (use (match_dup 2))])]
9530   "!TARGET_IEEEQUAD
9531    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9532    && TARGET_LONG_DOUBLE_128"
9533 {
9534   operands[2] = CONST0_RTX (DFmode);
9535   /* Generate GOT reference early for SVR4 PIC.  */
9536   if (DEFAULT_ABI == ABI_V4 && flag_pic)
9537     operands[2] = validize_mem (force_const_mem (DFmode, operands[2]));
9538 })
9539
9540 (define_insn_and_split "*extenddftf2_internal"
9541   [(set (match_operand:TF 0 "nonimmediate_operand" "=m,Y,d,&d,r")
9542        (float_extend:TF (match_operand:DF 1 "input_operand" "d,r,md,md,rmGHF")))
9543    (use (match_operand:DF 2 "zero_reg_mem_operand" "d,r,m,d,n"))]
9544   "!TARGET_IEEEQUAD
9545    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9546    && TARGET_LONG_DOUBLE_128"
9547   "#"
9548   "&& reload_completed"
9549   [(pc)]
9550 {
9551   const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
9552   const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
9553   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
9554                   operands[1]);
9555   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
9556                   operands[2]);
9557   DONE;
9558 })
9559
9560 (define_expand "extendsftf2"
9561   [(set (match_operand:TF 0 "nonimmediate_operand" "")
9562         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
9563   "!TARGET_IEEEQUAD
9564    && TARGET_HARD_FLOAT
9565    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9566    && TARGET_LONG_DOUBLE_128"
9567 {
9568   rtx tmp = gen_reg_rtx (DFmode);
9569   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
9570   emit_insn (gen_extenddftf2 (operands[0], tmp));
9571   DONE;
9572 })
9573
9574 (define_expand "trunctfdf2"
9575   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9576         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
9577   "!TARGET_IEEEQUAD
9578    && TARGET_HARD_FLOAT
9579    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9580    && TARGET_LONG_DOUBLE_128"
9581   "")
9582
9583 (define_insn_and_split "trunctfdf2_internal1"
9584   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d")
9585         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,d")))]
9586   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
9587    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9588   "@
9589    #
9590    fmr %0,%1"
9591   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
9592   [(const_int 0)]
9593 {
9594   emit_note (NOTE_INSN_DELETED);
9595   DONE;
9596 }
9597   [(set_attr "type" "fp")])
9598
9599 (define_insn "trunctfdf2_internal2"
9600   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
9601         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "d")))]
9602   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
9603    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9604    && TARGET_LONG_DOUBLE_128"
9605   "fadd %0,%1,%L1"
9606   [(set_attr "type" "fp")
9607    (set_attr "fp_type" "fp_addsub_d")])
9608
9609 (define_expand "trunctfsf2"
9610   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9611         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "")))]
9612   "!TARGET_IEEEQUAD
9613    && TARGET_HARD_FLOAT
9614    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9615    && TARGET_LONG_DOUBLE_128"
9616 {
9617   if (TARGET_E500_DOUBLE)
9618     emit_insn (gen_spe_trunctfsf2 (operands[0], operands[1]));
9619   else
9620     emit_insn (gen_trunctfsf2_fprs (operands[0], operands[1]));
9621   DONE;
9622 })
9623
9624 (define_insn_and_split "trunctfsf2_fprs"
9625   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
9626         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "d")))
9627    (clobber (match_scratch:DF 2 "=d"))]
9628   "!TARGET_IEEEQUAD
9629    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT 
9630    && TARGET_LONG_DOUBLE_128"
9631   "#"
9632   "&& reload_completed"
9633   [(set (match_dup 2)
9634         (float_truncate:DF (match_dup 1)))
9635    (set (match_dup 0)
9636         (float_truncate:SF (match_dup 2)))]
9637   "")
9638
9639 (define_expand "floatsitf2"
9640   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9641         (float:TF (match_operand:SI 1 "gpc_reg_operand" "")))]
9642   "!TARGET_IEEEQUAD
9643    && TARGET_HARD_FLOAT
9644    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9645    && TARGET_LONG_DOUBLE_128"
9646 {
9647   rtx tmp = gen_reg_rtx (DFmode);
9648   expand_float (tmp, operands[1], false);
9649   emit_insn (gen_extenddftf2 (operands[0], tmp));
9650   DONE;
9651 })
9652
9653 ; fadd, but rounding towards zero.
9654 ; This is probably not the optimal code sequence.
9655 (define_insn "fix_trunc_helper"
9656   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
9657         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "d")]
9658                    UNSPEC_FIX_TRUNC_TF))
9659    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&d"))]
9660   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
9661   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
9662   [(set_attr "type" "fp")
9663    (set_attr "length" "20")])
9664
9665 (define_expand "fix_trunctfsi2"
9666   [(set (match_operand:SI 0 "gpc_reg_operand" "")
9667         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))]
9668   "!TARGET_IEEEQUAD && TARGET_HARD_FLOAT
9669    && (TARGET_FPRS || TARGET_E500_DOUBLE) && TARGET_LONG_DOUBLE_128"
9670 {
9671   if (TARGET_E500_DOUBLE)
9672     emit_insn (gen_spe_fix_trunctfsi2 (operands[0], operands[1]));
9673   else
9674     emit_insn (gen_fix_trunctfsi2_fprs (operands[0], operands[1]));
9675   DONE;
9676 })
9677
9678 (define_expand "fix_trunctfsi2_fprs"
9679   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
9680                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
9681               (clobber (match_dup 2))
9682               (clobber (match_dup 3))
9683               (clobber (match_dup 4))
9684               (clobber (match_dup 5))])]
9685   "!TARGET_IEEEQUAD
9686    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9687 {
9688   operands[2] = gen_reg_rtx (DFmode);
9689   operands[3] = gen_reg_rtx (DFmode);
9690   operands[4] = gen_reg_rtx (DImode);
9691   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode));
9692 })
9693
9694 (define_insn_and_split "*fix_trunctfsi2_internal"
9695   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9696         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "d")))
9697    (clobber (match_operand:DF 2 "gpc_reg_operand" "=d"))
9698    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&d"))
9699    (clobber (match_operand:DI 4 "gpc_reg_operand" "=d"))
9700    (clobber (match_operand:DI 5 "offsettable_mem_operand" "=o"))]
9701   "!TARGET_IEEEQUAD
9702    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9703   "#"
9704   ""
9705   [(pc)]
9706 {
9707   rtx lowword;
9708   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
9709
9710   gcc_assert (MEM_P (operands[5]));
9711   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
9712
9713   emit_insn (gen_fctiwz_df (operands[4], operands[2]));
9714   emit_move_insn (operands[5], operands[4]);
9715   emit_move_insn (operands[0], lowword);
9716   DONE;
9717 })
9718
9719 (define_expand "negtf2"
9720   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9721         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
9722   "!TARGET_IEEEQUAD
9723    && TARGET_HARD_FLOAT
9724    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9725    && TARGET_LONG_DOUBLE_128"
9726   "")
9727
9728 (define_insn "negtf2_internal"
9729   [(set (match_operand:TF 0 "gpc_reg_operand" "=d")
9730         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "d")))]
9731   "!TARGET_IEEEQUAD
9732    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
9733   "*
9734 {
9735   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
9736     return \"fneg %L0,%L1\;fneg %0,%1\";
9737   else
9738     return \"fneg %0,%1\;fneg %L0,%L1\";
9739 }"
9740   [(set_attr "type" "fp")
9741    (set_attr "length" "8")])
9742
9743 (define_expand "abstf2"
9744   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9745         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
9746   "!TARGET_IEEEQUAD
9747    && TARGET_HARD_FLOAT
9748    && (TARGET_FPRS || TARGET_E500_DOUBLE)
9749    && TARGET_LONG_DOUBLE_128"
9750   "
9751 {
9752   rtx label = gen_label_rtx ();
9753   if (TARGET_E500_DOUBLE)
9754     {
9755       if (flag_finite_math_only && !flag_trapping_math)
9756         emit_insn (gen_spe_abstf2_tst (operands[0], operands[1], label));
9757       else
9758         emit_insn (gen_spe_abstf2_cmp (operands[0], operands[1], label));
9759     }
9760   else
9761     emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
9762   emit_label (label);
9763   DONE;
9764 }")
9765
9766 (define_expand "abstf2_internal"
9767   [(set (match_operand:TF 0 "gpc_reg_operand" "")
9768         (match_operand:TF 1 "gpc_reg_operand" ""))
9769    (set (match_dup 3) (match_dup 5))
9770    (set (match_dup 5) (abs:DF (match_dup 5)))
9771    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
9772    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
9773                            (label_ref (match_operand 2 "" ""))
9774                            (pc)))
9775    (set (match_dup 6) (neg:DF (match_dup 6)))]
9776   "!TARGET_IEEEQUAD
9777    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
9778    && TARGET_LONG_DOUBLE_128"
9779   "
9780 {
9781   const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
9782   const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
9783   operands[3] = gen_reg_rtx (DFmode);
9784   operands[4] = gen_reg_rtx (CCFPmode);
9785   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
9786   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
9787 }")
9788 \f
9789 ;; Reload helper functions used by rs6000_secondary_reload.  The patterns all
9790 ;; must have 3 arguments, and scratch register constraint must be a single
9791 ;; constraint.
9792
9793 ;; Reload patterns to support gpr load/store with misaligned mem.
9794 ;; and multiple gpr load/store at offset >= 0xfffc
9795 (define_expand "reload_<mode>_store"
9796   [(parallel [(match_operand 0 "memory_operand" "=m")
9797               (match_operand 1 "gpc_reg_operand" "r")
9798               (match_operand:GPR 2 "register_operand" "=&b")])]
9799   ""
9800 {
9801   rs6000_secondary_reload_gpr (operands[1], operands[0], operands[2], true);
9802   DONE;
9803 })
9804
9805 (define_expand "reload_<mode>_load"
9806   [(parallel [(match_operand 0 "gpc_reg_operand" "=r")
9807               (match_operand 1 "memory_operand" "m")
9808               (match_operand:GPR 2 "register_operand" "=b")])]
9809   ""
9810 {
9811   rs6000_secondary_reload_gpr (operands[0], operands[1], operands[2], false);
9812   DONE;
9813 })
9814
9815 \f
9816 ;; Power8 merge instructions to allow direct move to/from floating point
9817 ;; registers in 32-bit mode.  We use TF mode to get two registers to move the
9818 ;; individual 32-bit parts across.  Subreg doesn't work too well on the TF
9819 ;; value, since it is allocated in reload and not all of the flow information
9820 ;; is setup for it.  We have two patterns to do the two moves between gprs and
9821 ;; fprs.  There isn't a dependancy between the two, but we could potentially
9822 ;; schedule other instructions between the two instructions.  TFmode is
9823 ;; currently limited to traditional FPR registers.  If/when this is changed, we
9824 ;; will need to revist %L to make sure it works with VSX registers, or add an
9825 ;; %x version of %L.
9826
9827 (define_insn "p8_fmrgow_<mode>"
9828   [(set (match_operand:FMOVE64X 0 "register_operand" "=d")
9829         (unspec:FMOVE64X [(match_operand:TF 1 "register_operand" "d")]
9830                          UNSPEC_P8V_FMRGOW))]
9831   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9832   "fmrgow %0,%1,%L1"
9833   [(set_attr "type" "vecperm")])
9834
9835 (define_insn "p8_mtvsrwz_1"
9836   [(set (match_operand:TF 0 "register_operand" "=d")
9837         (unspec:TF [(match_operand:SI 1 "register_operand" "r")]
9838                    UNSPEC_P8V_MTVSRWZ))]
9839   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9840   "mtvsrwz %x0,%1"
9841   [(set_attr "type" "mftgpr")])
9842
9843 (define_insn "p8_mtvsrwz_2"
9844   [(set (match_operand:TF 0 "register_operand" "+d")
9845         (unspec:TF [(match_dup 0)
9846                     (match_operand:SI 1 "register_operand" "r")]
9847                    UNSPEC_P8V_MTVSRWZ))]
9848   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9849   "mtvsrwz %L0,%1"
9850   [(set_attr "type" "mftgpr")])
9851
9852 (define_insn_and_split "reload_fpr_from_gpr<mode>"
9853   [(set (match_operand:FMOVE64X 0 "register_operand" "=ws")
9854         (unspec:FMOVE64X [(match_operand:FMOVE64X 1 "register_operand" "r")]
9855                          UNSPEC_P8V_RELOAD_FROM_GPR))
9856    (clobber (match_operand:TF 2 "register_operand" "=d"))]
9857   "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9858   "#"
9859   "&& reload_completed"
9860   [(const_int 0)]
9861 {
9862   rtx dest = operands[0];
9863   rtx src = operands[1];
9864   rtx tmp = operands[2];
9865   rtx gpr_hi_reg = gen_highpart (SImode, src);
9866   rtx gpr_lo_reg = gen_lowpart (SImode, src);
9867
9868   emit_insn (gen_p8_mtvsrwz_1 (tmp, gpr_hi_reg));
9869   emit_insn (gen_p8_mtvsrwz_2 (tmp, gpr_lo_reg));
9870   emit_insn (gen_p8_fmrgow_<mode> (dest, tmp));
9871   DONE;
9872 }
9873   [(set_attr "length" "12")
9874    (set_attr "type" "three")])
9875
9876 ;; Move 128 bit values from GPRs to VSX registers in 64-bit mode
9877 (define_insn "p8_mtvsrd_1"
9878   [(set (match_operand:TF 0 "register_operand" "=ws")
9879         (unspec:TF [(match_operand:DI 1 "register_operand" "r")]
9880                    UNSPEC_P8V_MTVSRD))]
9881   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9882   "mtvsrd %0,%1"
9883   [(set_attr "type" "mftgpr")])
9884
9885 (define_insn "p8_mtvsrd_2"
9886   [(set (match_operand:TF 0 "register_operand" "+ws")
9887         (unspec:TF [(match_dup 0)
9888                     (match_operand:DI 1 "register_operand" "r")]
9889                    UNSPEC_P8V_MTVSRD))]
9890   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9891   "mtvsrd %L0,%1"
9892   [(set_attr "type" "mftgpr")])
9893
9894 (define_insn "p8_xxpermdi_<mode>"
9895   [(set (match_operand:FMOVE128_GPR 0 "register_operand" "=wa")
9896         (unspec:FMOVE128_GPR [(match_operand:TF 1 "register_operand" "ws")]
9897                              UNSPEC_P8V_XXPERMDI))]
9898   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9899   "xxpermdi %x0,%1,%L1,0"
9900   [(set_attr "type" "vecperm")])
9901
9902 (define_insn_and_split "reload_vsx_from_gpr<mode>"
9903   [(set (match_operand:FMOVE128_GPR 0 "register_operand" "=wa")
9904         (unspec:FMOVE128_GPR
9905          [(match_operand:FMOVE128_GPR 1 "register_operand" "r")]
9906          UNSPEC_P8V_RELOAD_FROM_GPR))
9907    (clobber (match_operand:TF 2 "register_operand" "=ws"))]
9908   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9909   "#"
9910   "&& reload_completed"
9911   [(const_int 0)]
9912 {
9913   rtx dest = operands[0];
9914   rtx src = operands[1];
9915   rtx tmp = operands[2];
9916   rtx gpr_hi_reg = gen_highpart (DImode, src);
9917   rtx gpr_lo_reg = gen_lowpart (DImode, src);
9918
9919   emit_insn (gen_p8_mtvsrd_1 (tmp, gpr_hi_reg));
9920   emit_insn (gen_p8_mtvsrd_2 (tmp, gpr_lo_reg));
9921   emit_insn (gen_p8_xxpermdi_<mode> (dest, tmp));
9922 }
9923   [(set_attr "length" "12")
9924    (set_attr "type" "three")])
9925
9926 (define_split
9927   [(set (match_operand:FMOVE128_GPR 0 "nonimmediate_operand" "")
9928         (match_operand:FMOVE128_GPR 1 "input_operand" ""))]
9929   "reload_completed
9930    && (int_reg_operand (operands[0], <MODE>mode)
9931        || int_reg_operand (operands[1], <MODE>mode))"
9932   [(pc)]
9933 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
9934
9935 ;; Move SFmode to a VSX from a GPR register.  Because scalar floating point
9936 ;; type is stored internally as double precision in the VSX registers, we have
9937 ;; to convert it from the vector format.
9938
9939 (define_insn_and_split "reload_vsx_from_gprsf"
9940   [(set (match_operand:SF 0 "register_operand" "=wa")
9941         (unspec:SF [(match_operand:SF 1 "register_operand" "r")]
9942                    UNSPEC_P8V_RELOAD_FROM_GPR))
9943    (clobber (match_operand:DI 2 "register_operand" "=r"))]
9944   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9945   "#"
9946   "&& reload_completed"
9947   [(const_int 0)]
9948 {
9949   rtx op0 = operands[0];
9950   rtx op1 = operands[1];
9951   rtx op2 = operands[2];
9952   /* Also use the destination register to hold the unconverted DImode value.
9953      This is conceptually a separate value from OP0, so we use gen_rtx_REG
9954      rather than simplify_gen_subreg.  */
9955   rtx op0_di = gen_rtx_REG (DImode, REGNO (op0));
9956   rtx op1_di = simplify_gen_subreg (DImode, op1, SFmode, 0);
9957
9958   /* Move SF value to upper 32-bits for xscvspdpn.  */
9959   emit_insn (gen_ashldi3 (op2, op1_di, GEN_INT (32)));
9960   emit_move_insn (op0_di, op2);
9961   emit_insn (gen_vsx_xscvspdpn_directmove (op0, op0_di));
9962   DONE;
9963 }
9964   [(set_attr "length" "8")
9965    (set_attr "type" "two")])
9966
9967 ;; Move 128 bit values from VSX registers to GPRs in 64-bit mode by doing a
9968 ;; normal 64-bit move, followed by an xxpermdi to get the bottom 64-bit value,
9969 ;; and then doing a move of that.
9970 (define_insn "p8_mfvsrd_3_<mode>"
9971   [(set (match_operand:DF 0 "register_operand" "=r")
9972         (unspec:DF [(match_operand:FMOVE128_GPR 1 "register_operand" "wa")]
9973                    UNSPEC_P8V_RELOAD_FROM_VSX))]
9974   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9975   "mfvsrd %0,%x1"
9976   [(set_attr "type" "mftgpr")])
9977
9978 (define_insn_and_split "reload_gpr_from_vsx<mode>"
9979   [(set (match_operand:FMOVE128_GPR 0 "register_operand" "=r")
9980         (unspec:FMOVE128_GPR
9981          [(match_operand:FMOVE128_GPR 1 "register_operand" "wa")]
9982          UNSPEC_P8V_RELOAD_FROM_VSX))
9983    (clobber (match_operand:FMOVE128_GPR 2 "register_operand" "=wa"))]
9984   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9985   "#"
9986   "&& reload_completed"
9987   [(const_int 0)]
9988 {
9989   rtx dest = operands[0];
9990   rtx src = operands[1];
9991   rtx tmp = operands[2];
9992   rtx gpr_hi_reg = gen_highpart (DFmode, dest);
9993   rtx gpr_lo_reg = gen_lowpart (DFmode, dest);
9994
9995   emit_insn (gen_p8_mfvsrd_3_<mode> (gpr_hi_reg, src));
9996   emit_insn (gen_vsx_xxpermdi_<mode> (tmp, src, src, GEN_INT (3)));
9997   emit_insn (gen_p8_mfvsrd_3_<mode> (gpr_lo_reg, tmp));
9998 }
9999   [(set_attr "length" "12")
10000    (set_attr "type" "three")])
10001
10002 ;; Move SFmode to a GPR from a VSX register.  Because scalar floating point
10003 ;; type is stored internally as double precision, we have to convert it to the
10004 ;; vector format.
10005
10006 (define_insn_and_split "reload_gpr_from_vsxsf"
10007   [(set (match_operand:SF 0 "register_operand" "=r")
10008         (unspec:SF [(match_operand:SF 1 "register_operand" "wa")]
10009                    UNSPEC_P8V_RELOAD_FROM_VSX))
10010    (clobber (match_operand:V4SF 2 "register_operand" "=wa"))]
10011   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
10012   "#"
10013   "&& reload_completed"
10014   [(const_int 0)]
10015 {
10016   rtx op0 = operands[0];
10017   rtx op1 = operands[1];
10018   rtx op2 = operands[2];
10019   rtx diop0 = simplify_gen_subreg (DImode, op0, SFmode, 0);
10020
10021   emit_insn (gen_vsx_xscvdpspn_scalar (op2, op1));
10022   emit_insn (gen_p8_mfvsrd_4_disf (diop0, op2));
10023   emit_insn (gen_lshrdi3 (diop0, diop0, GEN_INT (32)));
10024   DONE;
10025 }
10026   [(set_attr "length" "12")
10027    (set_attr "type" "three")])
10028
10029 (define_insn "p8_mfvsrd_4_disf"
10030   [(set (match_operand:DI 0 "register_operand" "=r")
10031         (unspec:DI [(match_operand:V4SF 1 "register_operand" "wa")]
10032                    UNSPEC_P8V_RELOAD_FROM_VSX))]
10033   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
10034   "mfvsrd %0,%x1"
10035   [(set_attr "type" "mftgpr")])
10036
10037 \f
10038 ;; Next come the multi-word integer load and store and the load and store
10039 ;; multiple insns.
10040
10041 ;; List r->r after r->Y, otherwise reload will try to reload a
10042 ;; non-offsettable address by using r->r which won't make progress.
10043 ;; Use of fprs is disparaged slightly otherwise reload prefers to reload
10044 ;; a gpr into a fpr instead of reloading an invalid 'Y' address
10045 (define_insn "*movdi_internal32"
10046   [(set (match_operand:DI 0 "rs6000_nonimmediate_operand" "=Y,r,r,?m,?*d,?*d,r")
10047         (match_operand:DI 1 "input_operand" "r,Y,r,d,m,d,IJKnGHF"))]
10048   "! TARGET_POWERPC64
10049    && (gpc_reg_operand (operands[0], DImode)
10050        || gpc_reg_operand (operands[1], DImode))"
10051   "@
10052    #
10053    #
10054    #
10055    stfd%U0%X0 %1,%0
10056    lfd%U1%X1 %0,%1
10057    fmr %0,%1
10058    #"
10059   [(set_attr "type" "store,load,*,fpstore,fpload,fp,*")])
10060
10061 (define_split
10062   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10063         (match_operand:DI 1 "const_int_operand" ""))]
10064   "! TARGET_POWERPC64 && reload_completed
10065    && gpr_or_gpr_p (operands[0], operands[1])
10066    && !direct_move_p (operands[0], operands[1])"
10067   [(set (match_dup 2) (match_dup 4))
10068    (set (match_dup 3) (match_dup 1))]
10069   "
10070 {
10071   HOST_WIDE_INT value = INTVAL (operands[1]);
10072   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
10073                                        DImode);
10074   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
10075                                        DImode);
10076   operands[4] = GEN_INT (value >> 32);
10077   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
10078 }")
10079
10080 (define_split
10081   [(set (match_operand:DIFD 0 "rs6000_nonimmediate_operand" "")
10082         (match_operand:DIFD 1 "input_operand" ""))]
10083   "reload_completed && !TARGET_POWERPC64
10084    && gpr_or_gpr_p (operands[0], operands[1])
10085    && !direct_move_p (operands[0], operands[1])"
10086   [(pc)]
10087 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
10088
10089 (define_insn "*movdi_internal64"
10090   [(set (match_operand:DI 0 "nonimmediate_operand" "=Y,r,r,r,r,r,?m,?*d,?*d,r,*h,*h,r,?*wg,r,?*wm")
10091         (match_operand:DI 1 "input_operand" "r,Y,r,I,L,nF,d,m,d,*h,r,0,*wg,r,*wm,r"))]
10092   "TARGET_POWERPC64
10093    && (gpc_reg_operand (operands[0], DImode)
10094        || gpc_reg_operand (operands[1], DImode))"
10095   "@
10096    std%U0%X0 %1,%0
10097    ld%U1%X1 %0,%1
10098    mr %0,%1
10099    li %0,%1
10100    lis %0,%v1
10101    #
10102    stfd%U0%X0 %1,%0
10103    lfd%U1%X1 %0,%1
10104    fmr %0,%1
10105    mf%1 %0
10106    mt%0 %1
10107    nop
10108    mftgpr %0,%1
10109    mffgpr %0,%1
10110    mfvsrd %0,%x1
10111    mtvsrd %x0,%1"
10112   [(set_attr "type" "store,load,*,*,*,*,fpstore,fpload,fp,mfjmpr,mtjmpr,*,mftgpr,mffgpr,mftgpr,mffgpr")
10113    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4,4,4,4")])
10114
10115 ;; Generate all one-bits and clear left or right.
10116 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
10117 (define_split
10118   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10119         (match_operand:DI 1 "mask64_operand" ""))]
10120   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
10121   [(set (match_dup 0) (const_int -1))
10122    (set (match_dup 0)
10123         (and:DI (rotate:DI (match_dup 0)
10124                            (const_int 0))
10125                 (match_dup 1)))]
10126   "")
10127
10128 ;; Split a load of a large constant into the appropriate five-instruction
10129 ;; sequence.  Handle anything in a constant number of insns.
10130 ;; When non-easy constants can go in the TOC, this should use
10131 ;; easy_fp_constant predicate.
10132 (define_split
10133   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10134         (match_operand:DI 1 "const_int_operand" ""))]
10135   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
10136   [(set (match_dup 0) (match_dup 2))
10137    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
10138   "
10139 {
10140   if (rs6000_emit_set_const (operands[0], operands[1]))
10141     DONE;
10142   else
10143     FAIL;
10144 }")
10145
10146 (define_split
10147   [(set (match_operand:DI 0 "gpc_reg_operand" "")
10148         (match_operand:DI 1 "const_scalar_int_operand" ""))]
10149   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
10150   [(set (match_dup 0) (match_dup 2))
10151    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
10152   "
10153 {
10154   if (rs6000_emit_set_const (operands[0], operands[1]))
10155     DONE;
10156   else
10157     FAIL;
10158 }")
10159 \f
10160 ;; TImode/PTImode is similar, except that we usually want to compute the
10161 ;; address into a register and use lsi/stsi (the exception is during reload).
10162
10163 (define_insn "*mov<mode>_string"
10164   [(set (match_operand:TI2 0 "reg_or_mem_operand" "=Q,Y,????r,????r,????r,r")
10165         (match_operand:TI2 1 "input_operand" "r,r,Q,Y,r,n"))]
10166   "! TARGET_POWERPC64
10167    && (<MODE>mode != TImode || VECTOR_MEM_NONE_P (TImode))
10168    && (gpc_reg_operand (operands[0], <MODE>mode)
10169        || gpc_reg_operand (operands[1], <MODE>mode))"
10170   "*
10171 {
10172   switch (which_alternative)
10173     {
10174     default:
10175       gcc_unreachable ();
10176     case 0:
10177       if (TARGET_STRING)
10178         return \"stswi %1,%P0,16\";
10179     case 1:
10180       return \"#\";
10181     case 2:
10182       /* If the address is not used in the output, we can use lsi.  Otherwise,
10183          fall through to generating four loads.  */
10184       if (TARGET_STRING
10185           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
10186         return \"lswi %0,%P1,16\";
10187       /* ... fall through ...  */
10188     case 3:
10189     case 4:
10190     case 5:
10191       return \"#\";
10192     }
10193 }"
10194   [(set_attr "type" "store,store,load,load,*,*")
10195    (set_attr "update" "yes")
10196    (set_attr "indexed" "yes")
10197    (set (attr "cell_micro") (if_then_else (match_test "TARGET_STRING")
10198                                           (const_string "always")
10199                                           (const_string "conditional")))])
10200
10201 (define_insn "*mov<mode>_ppc64"
10202   [(set (match_operand:TI2 0 "nonimmediate_operand" "=wQ,Y,r,r,r,r")
10203         (match_operand:TI2 1 "input_operand" "r,r,wQ,Y,r,n"))]
10204   "(TARGET_POWERPC64 && VECTOR_MEM_NONE_P (<MODE>mode)
10205    && (gpc_reg_operand (operands[0], <MODE>mode)
10206        || gpc_reg_operand (operands[1], <MODE>mode)))"
10207 {
10208   return rs6000_output_move_128bit (operands);
10209 }
10210   [(set_attr "type" "store,store,load,load,*,*")
10211    (set_attr "length" "8")])
10212
10213 (define_split
10214   [(set (match_operand:TI2 0 "int_reg_operand" "")
10215         (match_operand:TI2 1 "const_scalar_int_operand" ""))]
10216   "TARGET_POWERPC64
10217    && (VECTOR_MEM_NONE_P (<MODE>mode)
10218        || (reload_completed && INT_REGNO_P (REGNO (operands[0]))))"
10219   [(set (match_dup 2) (match_dup 4))
10220    (set (match_dup 3) (match_dup 5))]
10221   "
10222 {
10223   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
10224                                        <MODE>mode);
10225   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
10226                                        <MODE>mode);
10227   if (CONST_WIDE_INT_P (operands[1]))
10228     {
10229       operands[4] = GEN_INT (CONST_WIDE_INT_ELT (operands[1], 1));
10230       operands[5] = GEN_INT (CONST_WIDE_INT_ELT (operands[1], 0));
10231     }
10232   else if (CONST_INT_P (operands[1]))
10233     {
10234       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
10235       operands[5] = operands[1];
10236     }
10237   else
10238     FAIL;
10239 }")
10240
10241 (define_split
10242   [(set (match_operand:TI2 0 "nonimmediate_operand" "")
10243         (match_operand:TI2 1 "input_operand" ""))]
10244   "reload_completed
10245    && gpr_or_gpr_p (operands[0], operands[1])
10246    && !direct_move_p (operands[0], operands[1])
10247    && !quad_load_store_p (operands[0], operands[1])"
10248   [(pc)]
10249 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
10250 \f
10251 (define_expand "load_multiple"
10252   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
10253                           (match_operand:SI 1 "" ""))
10254                      (use (match_operand:SI 2 "" ""))])]
10255   "TARGET_STRING && !TARGET_POWERPC64"
10256   "
10257 {
10258   int regno;
10259   int count;
10260   rtx op1;
10261   int i;
10262
10263   /* Support only loading a constant number of fixed-point registers from
10264      memory and only bother with this if more than two; the machine
10265      doesn't support more than eight.  */
10266   if (GET_CODE (operands[2]) != CONST_INT
10267       || INTVAL (operands[2]) <= 2
10268       || INTVAL (operands[2]) > 8
10269       || GET_CODE (operands[1]) != MEM
10270       || GET_CODE (operands[0]) != REG
10271       || REGNO (operands[0]) >= 32)
10272     FAIL;
10273
10274   count = INTVAL (operands[2]);
10275   regno = REGNO (operands[0]);
10276
10277   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
10278   op1 = replace_equiv_address (operands[1],
10279                                force_reg (SImode, XEXP (operands[1], 0)));
10280
10281   for (i = 0; i < count; i++)
10282     XVECEXP (operands[3], 0, i)
10283       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
10284                      adjust_address_nv (op1, SImode, i * 4));
10285 }")
10286
10287 (define_insn "*ldmsi8"
10288   [(match_parallel 0 "load_multiple_operation"
10289     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10290           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10291      (set (match_operand:SI 3 "gpc_reg_operand" "")
10292           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10293      (set (match_operand:SI 4 "gpc_reg_operand" "")
10294           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10295      (set (match_operand:SI 5 "gpc_reg_operand" "")
10296           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10297      (set (match_operand:SI 6 "gpc_reg_operand" "")
10298           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10299      (set (match_operand:SI 7 "gpc_reg_operand" "")
10300           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
10301      (set (match_operand:SI 8 "gpc_reg_operand" "")
10302           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
10303      (set (match_operand:SI 9 "gpc_reg_operand" "")
10304           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
10305   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
10306   "*
10307 { return rs6000_output_load_multiple (operands); }"
10308   [(set_attr "type" "load")
10309    (set_attr "update" "yes")
10310    (set_attr "indexed" "yes")
10311    (set_attr "length" "32")])
10312
10313 (define_insn "*ldmsi7"
10314   [(match_parallel 0 "load_multiple_operation"
10315     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10316           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10317      (set (match_operand:SI 3 "gpc_reg_operand" "")
10318           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10319      (set (match_operand:SI 4 "gpc_reg_operand" "")
10320           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10321      (set (match_operand:SI 5 "gpc_reg_operand" "")
10322           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10323      (set (match_operand:SI 6 "gpc_reg_operand" "")
10324           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10325      (set (match_operand:SI 7 "gpc_reg_operand" "")
10326           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
10327      (set (match_operand:SI 8 "gpc_reg_operand" "")
10328           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
10329   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
10330   "*
10331 { return rs6000_output_load_multiple (operands); }"
10332   [(set_attr "type" "load")
10333    (set_attr "update" "yes")
10334    (set_attr "indexed" "yes")
10335    (set_attr "length" "32")])
10336
10337 (define_insn "*ldmsi6"
10338   [(match_parallel 0 "load_multiple_operation"
10339     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10340           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10341      (set (match_operand:SI 3 "gpc_reg_operand" "")
10342           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10343      (set (match_operand:SI 4 "gpc_reg_operand" "")
10344           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10345      (set (match_operand:SI 5 "gpc_reg_operand" "")
10346           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10347      (set (match_operand:SI 6 "gpc_reg_operand" "")
10348           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
10349      (set (match_operand:SI 7 "gpc_reg_operand" "")
10350           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
10351   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
10352   "*
10353 { return rs6000_output_load_multiple (operands); }"
10354   [(set_attr "type" "load")
10355    (set_attr "update" "yes")
10356    (set_attr "indexed" "yes")
10357    (set_attr "length" "32")])
10358
10359 (define_insn "*ldmsi5"
10360   [(match_parallel 0 "load_multiple_operation"
10361     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10362           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10363      (set (match_operand:SI 3 "gpc_reg_operand" "")
10364           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10365      (set (match_operand:SI 4 "gpc_reg_operand" "")
10366           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10367      (set (match_operand:SI 5 "gpc_reg_operand" "")
10368           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
10369      (set (match_operand:SI 6 "gpc_reg_operand" "")
10370           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
10371   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
10372   "*
10373 { return rs6000_output_load_multiple (operands); }"
10374   [(set_attr "type" "load")
10375    (set_attr "update" "yes")
10376    (set_attr "indexed" "yes")
10377    (set_attr "length" "32")])
10378
10379 (define_insn "*ldmsi4"
10380   [(match_parallel 0 "load_multiple_operation"
10381     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10382           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10383      (set (match_operand:SI 3 "gpc_reg_operand" "")
10384           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10385      (set (match_operand:SI 4 "gpc_reg_operand" "")
10386           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
10387      (set (match_operand:SI 5 "gpc_reg_operand" "")
10388           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
10389   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
10390   "*
10391 { return rs6000_output_load_multiple (operands); }"
10392   [(set_attr "type" "load")
10393    (set_attr "update" "yes")
10394    (set_attr "indexed" "yes")
10395    (set_attr "length" "32")])
10396
10397 (define_insn "*ldmsi3"
10398   [(match_parallel 0 "load_multiple_operation"
10399     [(set (match_operand:SI 2 "gpc_reg_operand" "")
10400           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
10401      (set (match_operand:SI 3 "gpc_reg_operand" "")
10402           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
10403      (set (match_operand:SI 4 "gpc_reg_operand" "")
10404           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
10405   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
10406   "*
10407 { return rs6000_output_load_multiple (operands); }"
10408   [(set_attr "type" "load")
10409    (set_attr "update" "yes")
10410    (set_attr "indexed" "yes")
10411    (set_attr "length" "32")])
10412
10413 (define_expand "store_multiple"
10414   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
10415                           (match_operand:SI 1 "" ""))
10416                      (clobber (scratch:SI))
10417                      (use (match_operand:SI 2 "" ""))])]
10418   "TARGET_STRING && !TARGET_POWERPC64"
10419   "
10420 {
10421   int regno;
10422   int count;
10423   rtx to;
10424   rtx op0;
10425   int i;
10426
10427   /* Support only storing a constant number of fixed-point registers to
10428      memory and only bother with this if more than two; the machine
10429      doesn't support more than eight.  */
10430   if (GET_CODE (operands[2]) != CONST_INT
10431       || INTVAL (operands[2]) <= 2
10432       || INTVAL (operands[2]) > 8
10433       || GET_CODE (operands[0]) != MEM
10434       || GET_CODE (operands[1]) != REG
10435       || REGNO (operands[1]) >= 32)
10436     FAIL;
10437
10438   count = INTVAL (operands[2]);
10439   regno = REGNO (operands[1]);
10440
10441   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
10442   to = force_reg (SImode, XEXP (operands[0], 0));
10443   op0 = replace_equiv_address (operands[0], to);
10444
10445   XVECEXP (operands[3], 0, 0)
10446     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
10447   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
10448                                                  gen_rtx_SCRATCH (SImode));
10449
10450   for (i = 1; i < count; i++)
10451     XVECEXP (operands[3], 0, i + 1)
10452       = gen_rtx_SET (VOIDmode,
10453                      adjust_address_nv (op0, SImode, i * 4),
10454                      gen_rtx_REG (SImode, regno + i));
10455 }")
10456
10457 (define_insn "*stmsi8"
10458   [(match_parallel 0 "store_multiple_operation"
10459     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10460           (match_operand:SI 2 "gpc_reg_operand" "r"))
10461      (clobber (match_scratch:SI 3 "=X"))
10462      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10463           (match_operand:SI 4 "gpc_reg_operand" "r"))
10464      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10465           (match_operand:SI 5 "gpc_reg_operand" "r"))
10466      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10467           (match_operand:SI 6 "gpc_reg_operand" "r"))
10468      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10469           (match_operand:SI 7 "gpc_reg_operand" "r"))
10470      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10471           (match_operand:SI 8 "gpc_reg_operand" "r"))
10472      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10473           (match_operand:SI 9 "gpc_reg_operand" "r"))
10474      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
10475           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
10476   "TARGET_STRING && XVECLEN (operands[0], 0) == 9"
10477   "stswi %2,%1,%O0"
10478   [(set_attr "type" "store")
10479    (set_attr "update" "yes")
10480    (set_attr "indexed" "yes")
10481    (set_attr "cell_micro" "always")])
10482
10483 (define_insn "*stmsi7"
10484   [(match_parallel 0 "store_multiple_operation"
10485     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10486           (match_operand:SI 2 "gpc_reg_operand" "r"))
10487      (clobber (match_scratch:SI 3 "=X"))
10488      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10489           (match_operand:SI 4 "gpc_reg_operand" "r"))
10490      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10491           (match_operand:SI 5 "gpc_reg_operand" "r"))
10492      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10493           (match_operand:SI 6 "gpc_reg_operand" "r"))
10494      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10495           (match_operand:SI 7 "gpc_reg_operand" "r"))
10496      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10497           (match_operand:SI 8 "gpc_reg_operand" "r"))
10498      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
10499           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
10500   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
10501   "stswi %2,%1,%O0"
10502   [(set_attr "type" "store")
10503    (set_attr "update" "yes")
10504    (set_attr "indexed" "yes")
10505    (set_attr "cell_micro" "always")])
10506
10507 (define_insn "*stmsi6"
10508   [(match_parallel 0 "store_multiple_operation"
10509     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10510           (match_operand:SI 2 "gpc_reg_operand" "r"))
10511      (clobber (match_scratch:SI 3 "=X"))
10512      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10513           (match_operand:SI 4 "gpc_reg_operand" "r"))
10514      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10515           (match_operand:SI 5 "gpc_reg_operand" "r"))
10516      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10517           (match_operand:SI 6 "gpc_reg_operand" "r"))
10518      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10519           (match_operand:SI 7 "gpc_reg_operand" "r"))
10520      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
10521           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
10522   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
10523   "stswi %2,%1,%O0"
10524   [(set_attr "type" "store")
10525    (set_attr "update" "yes")
10526    (set_attr "indexed" "yes")
10527    (set_attr "cell_micro" "always")])
10528
10529 (define_insn "*stmsi5"
10530   [(match_parallel 0 "store_multiple_operation"
10531     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10532           (match_operand:SI 2 "gpc_reg_operand" "r"))
10533      (clobber (match_scratch:SI 3 "=X"))
10534      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10535           (match_operand:SI 4 "gpc_reg_operand" "r"))
10536      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10537           (match_operand:SI 5 "gpc_reg_operand" "r"))
10538      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10539           (match_operand:SI 6 "gpc_reg_operand" "r"))
10540      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
10541           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
10542   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
10543   "stswi %2,%1,%O0"
10544   [(set_attr "type" "store")
10545    (set_attr "update" "yes")
10546    (set_attr "indexed" "yes")
10547    (set_attr "cell_micro" "always")])
10548
10549 (define_insn "*stmsi4"
10550   [(match_parallel 0 "store_multiple_operation"
10551     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10552           (match_operand:SI 2 "gpc_reg_operand" "r"))
10553      (clobber (match_scratch:SI 3 "=X"))
10554      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10555           (match_operand:SI 4 "gpc_reg_operand" "r"))
10556      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10557           (match_operand:SI 5 "gpc_reg_operand" "r"))
10558      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
10559           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
10560   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
10561   "stswi %2,%1,%O0"
10562   [(set_attr "type" "store")
10563    (set_attr "update" "yes")
10564    (set_attr "indexed" "yes")
10565    (set_attr "cell_micro" "always")])
10566
10567 (define_insn "*stmsi3"
10568   [(match_parallel 0 "store_multiple_operation"
10569     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
10570           (match_operand:SI 2 "gpc_reg_operand" "r"))
10571      (clobber (match_scratch:SI 3 "=X"))
10572      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
10573           (match_operand:SI 4 "gpc_reg_operand" "r"))
10574      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
10575           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
10576   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
10577   "stswi %2,%1,%O0"
10578   [(set_attr "type" "store")
10579    (set_attr "update" "yes")
10580    (set_attr "indexed" "yes")
10581    (set_attr "cell_micro" "always")])
10582 \f
10583 (define_expand "setmemsi"
10584   [(parallel [(set (match_operand:BLK 0 "" "")
10585                    (match_operand 2 "const_int_operand" ""))
10586               (use (match_operand:SI 1 "" ""))
10587               (use (match_operand:SI 3 "" ""))])]
10588   ""
10589   "
10590 {
10591   /* If value to set is not zero, use the library routine.  */
10592   if (operands[2] != const0_rtx)
10593     FAIL;
10594
10595   if (expand_block_clear (operands))
10596     DONE;
10597   else
10598     FAIL;
10599 }")
10600
10601 ;; String/block move insn.
10602 ;; Argument 0 is the destination
10603 ;; Argument 1 is the source
10604 ;; Argument 2 is the length
10605 ;; Argument 3 is the alignment
10606
10607 (define_expand "movmemsi"
10608   [(parallel [(set (match_operand:BLK 0 "" "")
10609                    (match_operand:BLK 1 "" ""))
10610               (use (match_operand:SI 2 "" ""))
10611               (use (match_operand:SI 3 "" ""))])]
10612   ""
10613   "
10614 {
10615   if (expand_block_move (operands))
10616     DONE;
10617   else
10618     FAIL;
10619 }")
10620
10621 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
10622 ;; register allocator doesn't have a clue about allocating 8 word registers.
10623 ;; rD/rS = r5 is preferred, efficient form.
10624 (define_expand "movmemsi_8reg"
10625   [(parallel [(set (match_operand 0 "" "")
10626                    (match_operand 1 "" ""))
10627               (use (match_operand 2 "" ""))
10628               (use (match_operand 3 "" ""))
10629               (clobber (reg:SI  5))
10630               (clobber (reg:SI  6))
10631               (clobber (reg:SI  7))
10632               (clobber (reg:SI  8))
10633               (clobber (reg:SI  9))
10634               (clobber (reg:SI 10))
10635               (clobber (reg:SI 11))
10636               (clobber (reg:SI 12))
10637               (clobber (match_scratch:SI 4 ""))])]
10638   "TARGET_STRING"
10639   "")
10640
10641 (define_insn ""
10642   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10643         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10644    (use (match_operand:SI 2 "immediate_operand" "i"))
10645    (use (match_operand:SI 3 "immediate_operand" "i"))
10646    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10647    (clobber (reg:SI  6))
10648    (clobber (reg:SI  7))
10649    (clobber (reg:SI  8))
10650    (clobber (reg:SI  9))
10651    (clobber (reg:SI 10))
10652    (clobber (reg:SI 11))
10653    (clobber (reg:SI 12))
10654    (clobber (match_scratch:SI 5 "=X"))]
10655   "TARGET_STRING
10656    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
10657        || INTVAL (operands[2]) == 0)
10658    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
10659    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
10660    && REGNO (operands[4]) == 5"
10661   "lswi %4,%1,%2\;stswi %4,%0,%2"
10662   [(set_attr "type" "store")
10663    (set_attr "update" "yes")
10664    (set_attr "indexed" "yes")
10665    (set_attr "cell_micro" "always")
10666    (set_attr "length" "8")])
10667
10668 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
10669 ;; register allocator doesn't have a clue about allocating 6 word registers.
10670 ;; rD/rS = r5 is preferred, efficient form.
10671 (define_expand "movmemsi_6reg"
10672   [(parallel [(set (match_operand 0 "" "")
10673                    (match_operand 1 "" ""))
10674               (use (match_operand 2 "" ""))
10675               (use (match_operand 3 "" ""))
10676               (clobber (reg:SI  5))
10677               (clobber (reg:SI  6))
10678               (clobber (reg:SI  7))
10679               (clobber (reg:SI  8))
10680               (clobber (reg:SI  9))
10681               (clobber (reg:SI 10))
10682               (clobber (match_scratch:SI 4 ""))])]
10683   "TARGET_STRING"
10684   "")
10685
10686 (define_insn ""
10687   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10688         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10689    (use (match_operand:SI 2 "immediate_operand" "i"))
10690    (use (match_operand:SI 3 "immediate_operand" "i"))
10691    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10692    (clobber (reg:SI  6))
10693    (clobber (reg:SI  7))
10694    (clobber (reg:SI  8))
10695    (clobber (reg:SI  9))
10696    (clobber (reg:SI 10))
10697    (clobber (match_scratch:SI 5 "=X"))]
10698   "TARGET_STRING
10699    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
10700    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
10701    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
10702    && REGNO (operands[4]) == 5"
10703   "lswi %4,%1,%2\;stswi %4,%0,%2"
10704   [(set_attr "type" "store")
10705    (set_attr "update" "yes")
10706    (set_attr "indexed" "yes")
10707    (set_attr "cell_micro" "always")
10708    (set_attr "length" "8")])
10709
10710 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
10711 ;; problems with TImode.
10712 ;; rD/rS = r5 is preferred, efficient form.
10713 (define_expand "movmemsi_4reg"
10714   [(parallel [(set (match_operand 0 "" "")
10715                    (match_operand 1 "" ""))
10716               (use (match_operand 2 "" ""))
10717               (use (match_operand 3 "" ""))
10718               (clobber (reg:SI 5))
10719               (clobber (reg:SI 6))
10720               (clobber (reg:SI 7))
10721               (clobber (reg:SI 8))
10722               (clobber (match_scratch:SI 4 ""))])]
10723   "TARGET_STRING"
10724   "")
10725
10726 (define_insn ""
10727   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10728         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10729    (use (match_operand:SI 2 "immediate_operand" "i"))
10730    (use (match_operand:SI 3 "immediate_operand" "i"))
10731    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
10732    (clobber (reg:SI 6))
10733    (clobber (reg:SI 7))
10734    (clobber (reg:SI 8))
10735    (clobber (match_scratch:SI 5 "=X"))]
10736   "TARGET_STRING
10737    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
10738    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
10739    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
10740    && REGNO (operands[4]) == 5"
10741   "lswi %4,%1,%2\;stswi %4,%0,%2"
10742   [(set_attr "type" "store")
10743    (set_attr "update" "yes")
10744    (set_attr "indexed" "yes")
10745    (set_attr "cell_micro" "always")
10746    (set_attr "length" "8")])
10747
10748 ;; Move up to 8 bytes at a time.
10749 (define_expand "movmemsi_2reg"
10750   [(parallel [(set (match_operand 0 "" "")
10751                    (match_operand 1 "" ""))
10752               (use (match_operand 2 "" ""))
10753               (use (match_operand 3 "" ""))
10754               (clobber (match_scratch:DI 4 ""))
10755               (clobber (match_scratch:SI 5 ""))])]
10756   "TARGET_STRING && ! TARGET_POWERPC64"
10757   "")
10758
10759 (define_insn ""
10760   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
10761         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
10762    (use (match_operand:SI 2 "immediate_operand" "i"))
10763    (use (match_operand:SI 3 "immediate_operand" "i"))
10764    (clobber (match_scratch:DI 4 "=&r"))
10765    (clobber (match_scratch:SI 5 "=X"))]
10766   "TARGET_STRING && ! TARGET_POWERPC64
10767    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
10768   "lswi %4,%1,%2\;stswi %4,%0,%2"
10769   [(set_attr "type" "store")
10770    (set_attr "update" "yes")
10771    (set_attr "indexed" "yes")
10772    (set_attr "cell_micro" "always")
10773    (set_attr "length" "8")])
10774
10775 ;; Move up to 4 bytes at a time.
10776 (define_expand "movmemsi_1reg"
10777   [(parallel [(set (match_operand 0 "" "")
10778                    (match_operand 1 "" ""))
10779               (use (match_operand 2 "" ""))
10780               (use (match_operand 3 "" ""))
10781               (clobber (match_scratch:SI 4 ""))
10782               (clobber (match_scratch:SI 5 ""))])]
10783   "TARGET_STRING"
10784   "")
10785
10786 (define_insn ""
10787   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
10788         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
10789    (use (match_operand:SI 2 "immediate_operand" "i"))
10790    (use (match_operand:SI 3 "immediate_operand" "i"))
10791    (clobber (match_scratch:SI 4 "=&r"))
10792    (clobber (match_scratch:SI 5 "=X"))]
10793   "TARGET_STRING && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
10794   "lswi %4,%1,%2\;stswi %4,%0,%2"
10795   [(set_attr "type" "store")
10796    (set_attr "update" "yes")
10797    (set_attr "indexed" "yes")
10798    (set_attr "cell_micro" "always")
10799    (set_attr "length" "8")])
10800 \f
10801 ;; Define insns that do load or store with update.  Some of these we can
10802 ;; get by using pre-decrement or pre-increment, but the hardware can also
10803 ;; do cases where the increment is not the size of the object.
10804 ;;
10805 ;; In all these cases, we use operands 0 and 1 for the register being
10806 ;; incremented because those are the operands that local-alloc will
10807 ;; tie and these are the pair most likely to be tieable (and the ones
10808 ;; that will benefit the most).
10809
10810 (define_insn "*movdi_update1"
10811   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
10812         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
10813                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
10814    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
10815         (plus:DI (match_dup 1) (match_dup 2)))]
10816   "TARGET_POWERPC64 && TARGET_UPDATE
10817    && (!avoiding_indexed_address_p (DImode)
10818        || !gpc_reg_operand (operands[2], DImode))"
10819   "@
10820    ldux %3,%0,%2
10821    ldu %3,%2(%0)"
10822   [(set_attr "type" "load")
10823    (set_attr "update" "yes")
10824    (set_attr "indexed" "yes,no")])
10825
10826 (define_insn "movdi_<mode>_update"
10827   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10828                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
10829         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
10830    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10831         (plus:P (match_dup 1) (match_dup 2)))]
10832   "TARGET_POWERPC64 && TARGET_UPDATE
10833    && (!avoiding_indexed_address_p (Pmode)
10834        || !gpc_reg_operand (operands[2], Pmode)
10835        || (REG_P (operands[0])
10836            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
10837   "@
10838    stdux %3,%0,%2
10839    stdu %3,%2(%0)"
10840   [(set_attr "type" "store")
10841    (set_attr "update" "yes")
10842    (set_attr "indexed" "yes,no")])
10843
10844 ;; This pattern is only conditional on TARGET_POWERPC64, as it is
10845 ;; needed for stack allocation, even if the user passes -mno-update.
10846 (define_insn "movdi_<mode>_update_stack"
10847   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10848                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
10849         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
10850    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10851         (plus:P (match_dup 1) (match_dup 2)))]
10852   "TARGET_POWERPC64"
10853   "@
10854    stdux %3,%0,%2
10855    stdu %3,%2(%0)"
10856   [(set_attr "type" "store")
10857    (set_attr "update" "yes")
10858    (set_attr "indexed" "yes,no")])
10859
10860 (define_insn "*movsi_update1"
10861   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10862         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10863                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10864    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10865         (plus:SI (match_dup 1) (match_dup 2)))]
10866   "TARGET_UPDATE
10867    && (!avoiding_indexed_address_p (SImode)
10868        || !gpc_reg_operand (operands[2], SImode))"
10869   "@
10870    lwzux %3,%0,%2
10871    lwzu %3,%2(%0)"
10872   [(set_attr "type" "load")
10873    (set_attr "update" "yes")
10874    (set_attr "indexed" "yes,no")])
10875
10876 (define_insn "*movsi_update2"
10877   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
10878         (sign_extend:DI
10879          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
10880                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
10881    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
10882         (plus:DI (match_dup 1) (match_dup 2)))]
10883   "TARGET_POWERPC64 && rs6000_gen_cell_microcode
10884    && !avoiding_indexed_address_p (DImode)"
10885   "lwaux %3,%0,%2"
10886   [(set_attr "type" "load")
10887    (set_attr "sign_extend" "yes")
10888    (set_attr "update" "yes")
10889    (set_attr "indexed" "yes")])
10890
10891 (define_insn "movsi_update"
10892   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10893                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10894         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
10895    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10896         (plus:SI (match_dup 1) (match_dup 2)))]
10897   "TARGET_UPDATE
10898    && (!avoiding_indexed_address_p (SImode)
10899        || !gpc_reg_operand (operands[2], SImode)
10900        || (REG_P (operands[0])
10901            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
10902   "@
10903    stwux %3,%0,%2
10904    stwu %3,%2(%0)"
10905   [(set_attr "type" "store")
10906    (set_attr "update" "yes")
10907    (set_attr "indexed" "yes,no")])
10908
10909 ;; This is an unconditional pattern; needed for stack allocation, even
10910 ;; if the user passes -mno-update.
10911 (define_insn "movsi_update_stack"
10912   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10913                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10914         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
10915    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10916         (plus:SI (match_dup 1) (match_dup 2)))]
10917   ""
10918   "@
10919    stwux %3,%0,%2
10920    stwu %3,%2(%0)"
10921   [(set_attr "type" "store")
10922    (set_attr "update" "yes")
10923    (set_attr "indexed" "yes,no")])
10924
10925 (define_insn "*movhi_update1"
10926   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
10927         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10928                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10929    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10930         (plus:SI (match_dup 1) (match_dup 2)))]
10931   "TARGET_UPDATE
10932    && (!avoiding_indexed_address_p (SImode)
10933        || !gpc_reg_operand (operands[2], SImode))"
10934   "@
10935    lhzux %3,%0,%2
10936    lhzu %3,%2(%0)"
10937   [(set_attr "type" "load")
10938    (set_attr "update" "yes")
10939    (set_attr "indexed" "yes,no")])
10940
10941 (define_insn "*movhi_update2"
10942   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10943         (zero_extend:SI
10944          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10945                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10946    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10947         (plus:SI (match_dup 1) (match_dup 2)))]
10948   "TARGET_UPDATE
10949    && (!avoiding_indexed_address_p (SImode)
10950        || !gpc_reg_operand (operands[2], SImode))"
10951   "@
10952    lhzux %3,%0,%2
10953    lhzu %3,%2(%0)"
10954   [(set_attr "type" "load")
10955    (set_attr "update" "yes")
10956    (set_attr "indexed" "yes,no")])
10957
10958 (define_insn "*movhi_update3"
10959   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10960         (sign_extend:SI
10961          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10962                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10963    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10964         (plus:SI (match_dup 1) (match_dup 2)))]
10965   "TARGET_UPDATE && rs6000_gen_cell_microcode
10966    && (!avoiding_indexed_address_p (SImode)
10967        || !gpc_reg_operand (operands[2], SImode))"
10968   "@
10969    lhaux %3,%0,%2
10970    lhau %3,%2(%0)"
10971   [(set_attr "type" "load")
10972    (set_attr "sign_extend" "yes")
10973    (set_attr "update" "yes")
10974    (set_attr "indexed" "yes,no")])
10975
10976 (define_insn "*movhi_update4"
10977   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10978                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10979         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
10980    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10981         (plus:SI (match_dup 1) (match_dup 2)))]
10982   "TARGET_UPDATE
10983    && (!avoiding_indexed_address_p (SImode)
10984        || !gpc_reg_operand (operands[2], SImode))"
10985   "@
10986    sthux %3,%0,%2
10987    sthu %3,%2(%0)"
10988   [(set_attr "type" "store")
10989    (set_attr "update" "yes")
10990    (set_attr "indexed" "yes,no")])
10991
10992 (define_insn "*movqi_update1"
10993   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
10994         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10995                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10996    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10997         (plus:SI (match_dup 1) (match_dup 2)))]
10998   "TARGET_UPDATE
10999    && (!avoiding_indexed_address_p (SImode)
11000        || !gpc_reg_operand (operands[2], SImode))"
11001   "@
11002    lbzux %3,%0,%2
11003    lbzu %3,%2(%0)"
11004   [(set_attr "type" "load")
11005    (set_attr "update" "yes")
11006    (set_attr "indexed" "yes,no")])
11007
11008 (define_insn "*movqi_update2"
11009   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11010         (zero_extend:SI
11011          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11012                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
11013    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11014         (plus:SI (match_dup 1) (match_dup 2)))]
11015   "TARGET_UPDATE
11016    && (!avoiding_indexed_address_p (SImode)
11017        || !gpc_reg_operand (operands[2], SImode))"
11018   "@
11019    lbzux %3,%0,%2
11020    lbzu %3,%2(%0)"
11021   [(set_attr "type" "load")
11022    (set_attr "update" "yes")
11023    (set_attr "indexed" "yes,no")])
11024
11025 (define_insn "*movqi_update3"
11026   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11027                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11028         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
11029    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11030         (plus:SI (match_dup 1) (match_dup 2)))]
11031   "TARGET_UPDATE
11032    && (!avoiding_indexed_address_p (SImode)
11033        || !gpc_reg_operand (operands[2], SImode))"
11034   "@
11035    stbux %3,%0,%2
11036    stbu %3,%2(%0)"
11037   [(set_attr "type" "store")
11038    (set_attr "update" "yes")
11039    (set_attr "indexed" "yes,no")])
11040
11041 (define_insn "*movsf_update1"
11042   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
11043         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11044                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11045    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11046         (plus:SI (match_dup 1) (match_dup 2)))]
11047   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
11048    && (!avoiding_indexed_address_p (SImode)
11049        || !gpc_reg_operand (operands[2], SImode))"
11050   "@
11051    lfsux %3,%0,%2
11052    lfsu %3,%2(%0)"
11053   [(set_attr "type" "fpload")
11054    (set_attr "update" "yes")
11055    (set_attr "indexed" "yes,no")])
11056
11057 (define_insn "*movsf_update2"
11058   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11059                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11060         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
11061    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11062         (plus:SI (match_dup 1) (match_dup 2)))]
11063   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
11064    && (!avoiding_indexed_address_p (SImode)
11065        || !gpc_reg_operand (operands[2], SImode))"
11066   "@
11067    stfsux %3,%0,%2
11068    stfsu %3,%2(%0)"
11069   [(set_attr "type" "fpstore")
11070    (set_attr "update" "yes")
11071    (set_attr "indexed" "yes,no")])
11072
11073 (define_insn "*movsf_update3"
11074   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
11075         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11076                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11077    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11078         (plus:SI (match_dup 1) (match_dup 2)))]
11079   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
11080    && (!avoiding_indexed_address_p (SImode)
11081        || !gpc_reg_operand (operands[2], SImode))"
11082   "@
11083    lwzux %3,%0,%2
11084    lwzu %3,%2(%0)"
11085   [(set_attr "type" "load")
11086    (set_attr "update" "yes")
11087    (set_attr "indexed" "yes,no")])
11088
11089 (define_insn "*movsf_update4"
11090   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11091                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11092         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
11093    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11094         (plus:SI (match_dup 1) (match_dup 2)))]
11095   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
11096    && (!avoiding_indexed_address_p (SImode)
11097        || !gpc_reg_operand (operands[2], SImode))"
11098   "@
11099    stwux %3,%0,%2
11100    stwu %3,%2(%0)"
11101   [(set_attr "type" "store")
11102    (set_attr "update" "yes")
11103    (set_attr "indexed" "yes,no")])
11104
11105 (define_insn "*movdf_update1"
11106   [(set (match_operand:DF 3 "gpc_reg_operand" "=d,d")
11107         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11108                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
11109    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11110         (plus:SI (match_dup 1) (match_dup 2)))]
11111   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
11112    && (!avoiding_indexed_address_p (SImode)
11113        || !gpc_reg_operand (operands[2], SImode))"
11114   "@
11115    lfdux %3,%0,%2
11116    lfdu %3,%2(%0)"
11117   [(set_attr "type" "fpload")
11118    (set_attr "update" "yes")
11119    (set_attr "indexed" "yes,no")])
11120
11121 (define_insn "*movdf_update2"
11122   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
11123                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
11124         (match_operand:DF 3 "gpc_reg_operand" "d,d"))
11125    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
11126         (plus:SI (match_dup 1) (match_dup 2)))]
11127   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
11128    && (!avoiding_indexed_address_p (SImode)
11129        || !gpc_reg_operand (operands[2], SImode))"
11130   "@
11131    stfdux %3,%0,%2
11132    stfdu %3,%2(%0)"
11133   [(set_attr "type" "fpstore")
11134    (set_attr "update" "yes")
11135    (set_attr "indexed" "yes,no")])
11136
11137
11138 ;; After inserting conditional returns we can sometimes have
11139 ;; unnecessary register moves.  Unfortunately we cannot have a
11140 ;; modeless peephole here, because some single SImode sets have early
11141 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
11142 ;; sequences, using get_attr_length here will smash the operands
11143 ;; array.  Neither is there an early_cobbler_p predicate.
11144 ;; Disallow subregs for E500 so we don't munge frob_di_df_2.
11145 (define_peephole2
11146   [(set (match_operand:DF 0 "gpc_reg_operand" "")
11147         (match_operand:DF 1 "any_operand" ""))
11148    (set (match_operand:DF 2 "gpc_reg_operand" "")
11149         (match_dup 0))]
11150   "!(TARGET_E500_DOUBLE && GET_CODE (operands[2]) == SUBREG)
11151    && peep2_reg_dead_p (2, operands[0])"
11152   [(set (match_dup 2) (match_dup 1))])
11153
11154 (define_peephole2
11155   [(set (match_operand:SF 0 "gpc_reg_operand" "")
11156         (match_operand:SF 1 "any_operand" ""))
11157    (set (match_operand:SF 2 "gpc_reg_operand" "")
11158         (match_dup 0))]
11159   "peep2_reg_dead_p (2, operands[0])"
11160   [(set (match_dup 2) (match_dup 1))])
11161
11162 \f
11163 ;; TLS support.
11164
11165 ;; Mode attributes for different ABIs.
11166 (define_mode_iterator TLSmode [(SI "! TARGET_64BIT") (DI "TARGET_64BIT")])
11167 (define_mode_attr tls_abi_suffix [(SI "32") (DI "64")])
11168 (define_mode_attr tls_sysv_suffix [(SI "si") (DI "di")])
11169 (define_mode_attr tls_insn_suffix [(SI "wz") (DI "d")])
11170
11171 (define_insn_and_split "tls_gd_aix<TLSmode:tls_abi_suffix>"
11172   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11173         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
11174               (match_operand 4 "" "g")))
11175    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11176                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11177                    UNSPEC_TLSGD)
11178    (clobber (reg:SI LR_REGNO))]
11179   "HAVE_AS_TLS && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)"
11180 {
11181   if (TARGET_CMODEL != CMODEL_SMALL)
11182     return "addis %0,%1,%2@got@tlsgd@ha\;addi %0,%0,%2@got@tlsgd@l\;"
11183            "bl %z3\;nop";
11184   else
11185     return "addi %0,%1,%2@got@tlsgd\;bl %z3\;nop";
11186 }
11187   "&& TARGET_TLS_MARKERS"
11188   [(set (match_dup 0)
11189         (unspec:TLSmode [(match_dup 1)
11190                          (match_dup 2)]
11191                         UNSPEC_TLSGD))
11192    (parallel [(set (match_dup 0)
11193                    (call (mem:TLSmode (match_dup 3))
11194                          (match_dup 4)))
11195               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
11196               (clobber (reg:SI LR_REGNO))])]
11197   ""
11198   [(set_attr "type" "two")
11199    (set (attr "length")
11200      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11201                    (const_int 16)
11202                    (const_int 12)))])
11203
11204 (define_insn_and_split "tls_gd_sysv<TLSmode:tls_sysv_suffix>"
11205   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11206         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
11207               (match_operand 4 "" "g")))
11208    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11209                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11210                    UNSPEC_TLSGD)
11211    (clobber (reg:SI LR_REGNO))]
11212   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
11213 {
11214   if (flag_pic)
11215     {
11216       if (TARGET_SECURE_PLT && flag_pic == 2)
11217         return "addi %0,%1,%2@got@tlsgd\;bl %z3+32768@plt";
11218       else
11219         return "addi %0,%1,%2@got@tlsgd\;bl %z3@plt";
11220     }
11221   else
11222     return "addi %0,%1,%2@got@tlsgd\;bl %z3";
11223 }
11224   "&& TARGET_TLS_MARKERS"
11225   [(set (match_dup 0)
11226         (unspec:TLSmode [(match_dup 1)
11227                          (match_dup 2)]
11228                         UNSPEC_TLSGD))
11229    (parallel [(set (match_dup 0)
11230                    (call (mem:TLSmode (match_dup 3))
11231                          (match_dup 4)))
11232               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
11233               (clobber (reg:SI LR_REGNO))])]
11234   ""
11235   [(set_attr "type" "two")
11236    (set_attr "length" "8")])
11237
11238 (define_insn_and_split "*tls_gd<TLSmode:tls_abi_suffix>"
11239   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11240         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11241                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11242                         UNSPEC_TLSGD))]
11243   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11244   "addi %0,%1,%2@got@tlsgd"
11245   "&& TARGET_CMODEL != CMODEL_SMALL"
11246   [(set (match_dup 3)
11247         (high:TLSmode
11248             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGD)))
11249    (set (match_dup 0)
11250         (lo_sum:TLSmode (match_dup 3)
11251             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGD)))]
11252   "
11253 {
11254   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11255 }"
11256   [(set (attr "length")
11257      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11258                    (const_int 8)
11259                    (const_int 4)))])
11260
11261 (define_insn "*tls_gd_high<TLSmode:tls_abi_suffix>"
11262   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11263      (high:TLSmode
11264        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11265                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11266                        UNSPEC_TLSGD)))]
11267   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11268   "addis %0,%1,%2@got@tlsgd@ha"
11269   [(set_attr "length" "4")])
11270
11271 (define_insn "*tls_gd_low<TLSmode:tls_abi_suffix>"
11272   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11273      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11274        (unspec:TLSmode [(match_operand:TLSmode 3 "gpc_reg_operand" "b")
11275                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11276                        UNSPEC_TLSGD)))]
11277   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11278   "addi %0,%1,%2@got@tlsgd@l"
11279   [(set_attr "length" "4")])
11280
11281 (define_insn "*tls_gd_call_aix<TLSmode:tls_abi_suffix>"
11282   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11283         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11284               (match_operand 2 "" "g")))
11285    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11286                    UNSPEC_TLSGD)
11287    (clobber (reg:SI LR_REGNO))]
11288   "HAVE_AS_TLS && TARGET_TLS_MARKERS
11289    && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)"
11290   "bl %z1(%3@tlsgd)\;nop"
11291   [(set_attr "type" "branch")
11292    (set_attr "length" "8")])
11293
11294 (define_insn "*tls_gd_call_sysv<TLSmode:tls_abi_suffix>"
11295   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11296         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11297               (match_operand 2 "" "g")))
11298    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
11299                    UNSPEC_TLSGD)
11300    (clobber (reg:SI LR_REGNO))]
11301   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11302 {
11303   if (flag_pic)
11304     {
11305       if (TARGET_SECURE_PLT && flag_pic == 2)
11306         return "bl %z1+32768(%3@tlsgd)@plt";
11307       return "bl %z1(%3@tlsgd)@plt";
11308     }
11309   return "bl %z1(%3@tlsgd)";
11310 }
11311   [(set_attr "type" "branch")
11312    (set_attr "length" "4")])
11313
11314 (define_insn_and_split "tls_ld_aix<TLSmode:tls_abi_suffix>"
11315   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11316         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11317               (match_operand 3 "" "g")))
11318    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11319                    UNSPEC_TLSLD)
11320    (clobber (reg:SI LR_REGNO))]
11321   "HAVE_AS_TLS && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)"
11322 {
11323   if (TARGET_CMODEL != CMODEL_SMALL)
11324     return "addis %0,%1,%&@got@tlsld@ha\;addi %0,%0,%&@got@tlsld@l\;"
11325            "bl %z2\;nop";
11326   else
11327     return "addi %0,%1,%&@got@tlsld\;bl %z2\;nop";
11328 }
11329   "&& TARGET_TLS_MARKERS"
11330   [(set (match_dup 0)
11331         (unspec:TLSmode [(match_dup 1)]
11332                         UNSPEC_TLSLD))
11333    (parallel [(set (match_dup 0)
11334                    (call (mem:TLSmode (match_dup 2))
11335                          (match_dup 3)))
11336               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11337               (clobber (reg:SI LR_REGNO))])]
11338   ""
11339   [(set_attr "type" "two")
11340    (set (attr "length")
11341      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11342                    (const_int 16)
11343                    (const_int 12)))])
11344
11345 (define_insn_and_split "tls_ld_sysv<TLSmode:tls_sysv_suffix>"
11346   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11347         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
11348               (match_operand 3 "" "g")))
11349    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11350                    UNSPEC_TLSLD)
11351    (clobber (reg:SI LR_REGNO))]
11352   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
11353 {
11354   if (flag_pic)
11355     {
11356       if (TARGET_SECURE_PLT && flag_pic == 2)
11357         return "addi %0,%1,%&@got@tlsld\;bl %z2+32768@plt";
11358       else
11359         return "addi %0,%1,%&@got@tlsld\;bl %z2@plt";
11360     }
11361   else
11362     return "addi %0,%1,%&@got@tlsld\;bl %z2";
11363 }
11364   "&& TARGET_TLS_MARKERS"
11365   [(set (match_dup 0)
11366         (unspec:TLSmode [(match_dup 1)]
11367                         UNSPEC_TLSLD))
11368    (parallel [(set (match_dup 0)
11369                    (call (mem:TLSmode (match_dup 2))
11370                          (match_dup 3)))
11371               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11372               (clobber (reg:SI LR_REGNO))])]
11373   ""
11374   [(set_attr "length" "8")])
11375
11376 (define_insn_and_split "*tls_ld<TLSmode:tls_abi_suffix>"
11377   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11378         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11379                         UNSPEC_TLSLD))]
11380   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
11381   "addi %0,%1,%&@got@tlsld"
11382   "&& TARGET_CMODEL != CMODEL_SMALL"
11383   [(set (match_dup 2)
11384         (high:TLSmode
11385             (unspec:TLSmode [(const_int 0) (match_dup 1)] UNSPEC_TLSLD)))
11386    (set (match_dup 0)
11387         (lo_sum:TLSmode (match_dup 2)
11388             (unspec:TLSmode [(const_int 0) (match_dup 1)] UNSPEC_TLSLD)))]
11389   "
11390 {
11391   operands[2] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11392 }"
11393   [(set (attr "length")
11394      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11395                    (const_int 8)
11396                    (const_int 4)))])
11397
11398 (define_insn "*tls_ld_high<TLSmode:tls_abi_suffix>"
11399   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11400      (high:TLSmode
11401        (unspec:TLSmode [(const_int 0)
11402                         (match_operand:TLSmode 1 "gpc_reg_operand" "b")]
11403                        UNSPEC_TLSLD)))]
11404   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11405   "addis %0,%1,%&@got@tlsld@ha"
11406   [(set_attr "length" "4")])
11407
11408 (define_insn "*tls_ld_low<TLSmode:tls_abi_suffix>"
11409   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11410      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11411        (unspec:TLSmode [(const_int 0)
11412                         (match_operand:TLSmode 2 "gpc_reg_operand" "b")]
11413                        UNSPEC_TLSLD)))]
11414   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
11415   "addi %0,%1,%&@got@tlsld@l"
11416   [(set_attr "length" "4")])
11417
11418 (define_insn "*tls_ld_call_aix<TLSmode:tls_abi_suffix>"
11419   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11420         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11421               (match_operand 2 "" "g")))
11422    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11423    (clobber (reg:SI LR_REGNO))]
11424   "HAVE_AS_TLS && TARGET_TLS_MARKERS
11425    && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)"
11426   "bl %z1(%&@tlsld)\;nop"
11427   [(set_attr "type" "branch")
11428    (set_attr "length" "8")])
11429
11430 (define_insn "*tls_ld_call_sysv<TLSmode:tls_abi_suffix>"
11431   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11432         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
11433               (match_operand 2 "" "g")))
11434    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
11435    (clobber (reg:SI LR_REGNO))]
11436   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
11437 {
11438   if (flag_pic)
11439     {
11440       if (TARGET_SECURE_PLT && flag_pic == 2)
11441         return "bl %z1+32768(%&@tlsld)@plt";
11442       return "bl %z1(%&@tlsld)@plt";
11443     }
11444   return "bl %z1(%&@tlsld)";
11445 }
11446   [(set_attr "type" "branch")
11447    (set_attr "length" "4")])
11448
11449 (define_insn "tls_dtprel_<TLSmode:tls_abi_suffix>"
11450   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11451         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11452                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11453                         UNSPEC_TLSDTPREL))]
11454   "HAVE_AS_TLS"
11455   "addi %0,%1,%2@dtprel")
11456
11457 (define_insn "tls_dtprel_ha_<TLSmode:tls_abi_suffix>"
11458   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11459         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11460                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11461                         UNSPEC_TLSDTPRELHA))]
11462   "HAVE_AS_TLS"
11463   "addis %0,%1,%2@dtprel@ha")
11464
11465 (define_insn "tls_dtprel_lo_<TLSmode:tls_abi_suffix>"
11466   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11467         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11468                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11469                         UNSPEC_TLSDTPRELLO))]
11470   "HAVE_AS_TLS"
11471   "addi %0,%1,%2@dtprel@l")
11472
11473 (define_insn_and_split "tls_got_dtprel_<TLSmode:tls_abi_suffix>"
11474   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11475         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11476                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11477                         UNSPEC_TLSGOTDTPREL))]
11478   "HAVE_AS_TLS"
11479   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel(%1)"
11480   "&& TARGET_CMODEL != CMODEL_SMALL"
11481   [(set (match_dup 3)
11482         (high:TLSmode
11483             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTDTPREL)))
11484    (set (match_dup 0)
11485         (lo_sum:TLSmode (match_dup 3)
11486             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTDTPREL)))]
11487   "
11488 {
11489   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11490 }"
11491   [(set (attr "length")
11492      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11493                    (const_int 8)
11494                    (const_int 4)))])
11495
11496 (define_insn "*tls_got_dtprel_high<TLSmode:tls_abi_suffix>"
11497   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11498      (high:TLSmode
11499        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11500                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11501                        UNSPEC_TLSGOTDTPREL)))]
11502   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11503   "addis %0,%1,%2@got@dtprel@ha"
11504   [(set_attr "length" "4")])
11505
11506 (define_insn "*tls_got_dtprel_low<TLSmode:tls_abi_suffix>"
11507   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11508      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11509          (unspec:TLSmode [(match_operand:TLSmode 3 "gpc_reg_operand" "b")
11510                           (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11511                          UNSPEC_TLSGOTDTPREL)))]
11512   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11513   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel@l(%1)"
11514   [(set_attr "length" "4")])
11515
11516 (define_insn "tls_tprel_<TLSmode:tls_abi_suffix>"
11517   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11518         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11519                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11520                         UNSPEC_TLSTPREL))]
11521   "HAVE_AS_TLS"
11522   "addi %0,%1,%2@tprel")
11523
11524 (define_insn "tls_tprel_ha_<TLSmode:tls_abi_suffix>"
11525   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11526         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11527                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11528                         UNSPEC_TLSTPRELHA))]
11529   "HAVE_AS_TLS"
11530   "addis %0,%1,%2@tprel@ha")
11531
11532 (define_insn "tls_tprel_lo_<TLSmode:tls_abi_suffix>"
11533   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11534         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11535                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11536                         UNSPEC_TLSTPRELLO))]
11537   "HAVE_AS_TLS"
11538   "addi %0,%1,%2@tprel@l")
11539
11540 ;; "b" output constraint here and on tls_tls input to support linker tls
11541 ;; optimization.  The linker may edit the instructions emitted by a
11542 ;; tls_got_tprel/tls_tls pair to addis,addi.
11543 (define_insn_and_split "tls_got_tprel_<TLSmode:tls_abi_suffix>"
11544   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11545         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11546                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11547                         UNSPEC_TLSGOTTPREL))]
11548   "HAVE_AS_TLS"
11549   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel(%1)"
11550   "&& TARGET_CMODEL != CMODEL_SMALL"
11551   [(set (match_dup 3)
11552         (high:TLSmode
11553             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTTPREL)))
11554    (set (match_dup 0)
11555         (lo_sum:TLSmode (match_dup 3)
11556             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTTPREL)))]
11557   "
11558 {
11559   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
11560 }"
11561   [(set (attr "length")
11562      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
11563                    (const_int 8)
11564                    (const_int 4)))])
11565
11566 (define_insn "*tls_got_tprel_high<TLSmode:tls_abi_suffix>"
11567   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
11568      (high:TLSmode
11569        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11570                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11571                        UNSPEC_TLSGOTTPREL)))]
11572   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11573   "addis %0,%1,%2@got@tprel@ha"
11574   [(set_attr "length" "4")])
11575
11576 (define_insn "*tls_got_tprel_low<TLSmode:tls_abi_suffix>"
11577   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11578      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
11579          (unspec:TLSmode [(match_operand:TLSmode 3 "gpc_reg_operand" "b")
11580                           (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11581                          UNSPEC_TLSGOTTPREL)))]
11582   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
11583   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel@l(%1)"
11584   [(set_attr "length" "4")])
11585
11586 (define_insn "tls_tls_<TLSmode:tls_abi_suffix>"
11587   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
11588         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
11589                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
11590                         UNSPEC_TLSTLS))]
11591   "TARGET_ELF && HAVE_AS_TLS"
11592   "add %0,%1,%2@tls")
11593
11594 (define_expand "tls_get_tpointer"
11595   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11596         (unspec:SI [(const_int 0)] UNSPEC_TLSTLS))]
11597   "TARGET_XCOFF && HAVE_AS_TLS"
11598   "
11599 {
11600   emit_insn (gen_tls_get_tpointer_internal ());
11601   emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
11602   DONE;
11603 }")
11604
11605 (define_insn "tls_get_tpointer_internal"
11606   [(set (reg:SI 3)
11607         (unspec:SI [(const_int 0)] UNSPEC_TLSTLS))
11608    (clobber (reg:SI LR_REGNO))]
11609   "TARGET_XCOFF && HAVE_AS_TLS"
11610   "bla __get_tpointer")
11611
11612 (define_expand "tls_get_addr<mode>"
11613   [(set (match_operand:P 0 "gpc_reg_operand" "")
11614         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "")
11615                    (match_operand:P 2 "gpc_reg_operand" "")] UNSPEC_TLSTLS))]
11616   "TARGET_XCOFF && HAVE_AS_TLS"
11617   "
11618 {
11619   emit_move_insn (gen_rtx_REG (Pmode, 3), operands[1]);
11620   emit_move_insn (gen_rtx_REG (Pmode, 4), operands[2]);
11621   emit_insn (gen_tls_get_addr_internal<mode> ());
11622   emit_move_insn (operands[0], gen_rtx_REG (Pmode, 3));
11623   DONE;
11624 }")
11625
11626 (define_insn "tls_get_addr_internal<mode>"
11627   [(set (reg:P 3)
11628         (unspec:P [(reg:P 3) (reg:P 4)] UNSPEC_TLSTLS))
11629    (clobber (reg:P 0))
11630    (clobber (reg:P 4))
11631    (clobber (reg:P 5))
11632    (clobber (reg:P 11))
11633    (clobber (reg:CC CR0_REGNO))
11634    (clobber (reg:P LR_REGNO))]
11635   "TARGET_XCOFF && HAVE_AS_TLS"
11636   "bla __tls_get_addr")
11637 \f
11638 ;; Next come insns related to the calling sequence.
11639 ;;
11640 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
11641 ;; We move the back-chain and decrement the stack pointer.
11642
11643 (define_expand "allocate_stack"
11644   [(set (match_operand 0 "gpc_reg_operand" "")
11645         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
11646    (set (reg 1)
11647         (minus (reg 1) (match_dup 1)))]
11648   ""
11649   "
11650 { rtx chain = gen_reg_rtx (Pmode);
11651   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
11652   rtx neg_op0;
11653   rtx insn, par, set, mem;
11654
11655   emit_move_insn (chain, stack_bot);
11656
11657   /* Check stack bounds if necessary.  */
11658   if (crtl->limit_stack)
11659     {
11660       rtx available;
11661       available = expand_binop (Pmode, sub_optab,
11662                                 stack_pointer_rtx, stack_limit_rtx,
11663                                 NULL_RTX, 1, OPTAB_WIDEN);
11664       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
11665     }
11666
11667   if (GET_CODE (operands[1]) != CONST_INT
11668       || INTVAL (operands[1]) < -32767
11669       || INTVAL (operands[1]) > 32768)
11670     {
11671       neg_op0 = gen_reg_rtx (Pmode);
11672       if (TARGET_32BIT)
11673         emit_insn (gen_negsi2 (neg_op0, operands[1]));
11674       else
11675         emit_insn (gen_negdi2 (neg_op0, operands[1]));
11676     }
11677   else
11678     neg_op0 = GEN_INT (- INTVAL (operands[1]));
11679
11680   insn = emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update_stack
11681                                        : gen_movdi_di_update_stack))
11682                         (stack_pointer_rtx, stack_pointer_rtx, neg_op0,
11683                          chain));
11684   /* Since we didn't use gen_frame_mem to generate the MEM, grab
11685      it now and set the alias set/attributes. The above gen_*_update
11686      calls will generate a PARALLEL with the MEM set being the first
11687      operation. */
11688   par = PATTERN (insn);
11689   gcc_assert (GET_CODE (par) == PARALLEL);
11690   set = XVECEXP (par, 0, 0);
11691   gcc_assert (GET_CODE (set) == SET);
11692   mem = SET_DEST (set);
11693   gcc_assert (MEM_P (mem));
11694   MEM_NOTRAP_P (mem) = 1;
11695   set_mem_alias_set (mem, get_frame_alias_set ());
11696
11697   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
11698   DONE;
11699 }")
11700
11701 ;; These patterns say how to save and restore the stack pointer.  We need not
11702 ;; save the stack pointer at function level since we are careful to
11703 ;; preserve the backchain.  At block level, we have to restore the backchain
11704 ;; when we restore the stack pointer.
11705 ;;
11706 ;; For nonlocal gotos, we must save both the stack pointer and its
11707 ;; backchain and restore both.  Note that in the nonlocal case, the
11708 ;; save area is a memory location.
11709
11710 (define_expand "save_stack_function"
11711   [(match_operand 0 "any_operand" "")
11712    (match_operand 1 "any_operand" "")]
11713   ""
11714   "DONE;")
11715
11716 (define_expand "restore_stack_function"
11717   [(match_operand 0 "any_operand" "")
11718    (match_operand 1 "any_operand" "")]
11719   ""
11720   "DONE;")
11721
11722 ;; Adjust stack pointer (op0) to a new value (op1).
11723 ;; First copy old stack backchain to new location, and ensure that the
11724 ;; scheduler won't reorder the sp assignment before the backchain write.
11725 (define_expand "restore_stack_block"
11726   [(set (match_dup 2) (match_dup 3))
11727    (set (match_dup 4) (match_dup 2))
11728    (match_dup 5)
11729    (set (match_operand 0 "register_operand" "")
11730         (match_operand 1 "register_operand" ""))]
11731   ""
11732   "
11733 {
11734   rtvec p;
11735
11736   operands[1] = force_reg (Pmode, operands[1]);
11737   operands[2] = gen_reg_rtx (Pmode);
11738   operands[3] = gen_frame_mem (Pmode, operands[0]);
11739   operands[4] = gen_frame_mem (Pmode, operands[1]);
11740   p = rtvec_alloc (1);
11741   RTVEC_ELT (p, 0) = gen_rtx_SET (VOIDmode,
11742                                   gen_frame_mem (BLKmode, operands[0]),
11743                                   const0_rtx);
11744   operands[5] = gen_rtx_PARALLEL (VOIDmode, p);
11745 }")
11746
11747 (define_expand "save_stack_nonlocal"
11748   [(set (match_dup 3) (match_dup 4))
11749    (set (match_operand 0 "memory_operand" "") (match_dup 3))
11750    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
11751   ""
11752   "
11753 {
11754   int units_per_word = (TARGET_32BIT) ? 4 : 8;
11755
11756   /* Copy the backchain to the first word, sp to the second.  */
11757   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
11758   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
11759   operands[3] = gen_reg_rtx (Pmode);
11760   operands[4] = gen_frame_mem (Pmode, operands[1]);
11761 }")
11762
11763 (define_expand "restore_stack_nonlocal"
11764   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
11765    (set (match_dup 3) (match_dup 4))
11766    (set (match_dup 5) (match_dup 2))
11767    (match_dup 6)
11768    (set (match_operand 0 "register_operand" "") (match_dup 3))]
11769   ""
11770   "
11771 {
11772   int units_per_word = (TARGET_32BIT) ? 4 : 8;
11773   rtvec p;
11774
11775   /* Restore the backchain from the first word, sp from the second.  */
11776   operands[2] = gen_reg_rtx (Pmode);
11777   operands[3] = gen_reg_rtx (Pmode);
11778   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
11779   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
11780   operands[5] = gen_frame_mem (Pmode, operands[3]);
11781   p = rtvec_alloc (1);
11782   RTVEC_ELT (p, 0) = gen_rtx_SET (VOIDmode,
11783                                   gen_frame_mem (BLKmode, operands[0]),
11784                                   const0_rtx);
11785   operands[6] = gen_rtx_PARALLEL (VOIDmode, p);
11786 }")
11787 \f
11788 ;; TOC register handling.
11789
11790 ;; Code to initialize the TOC register...
11791
11792 (define_insn "load_toc_aix_si"
11793   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11794                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
11795               (use (reg:SI 2))])]
11796   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2) && TARGET_32BIT"
11797   "*
11798 {
11799   char buf[30];
11800   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
11801   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11802   operands[2] = gen_rtx_REG (Pmode, 2);
11803   return \"lwz %0,%1(%2)\";
11804 }"
11805   [(set_attr "type" "load")
11806    (set_attr "update" "no")
11807    (set_attr "indexed" "no")])
11808
11809 (define_insn "load_toc_aix_di"
11810   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11811                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
11812               (use (reg:DI 2))])]
11813   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2) && TARGET_64BIT"
11814   "*
11815 {
11816   char buf[30];
11817 #ifdef TARGET_RELOCATABLE
11818   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
11819                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
11820 #else
11821   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
11822 #endif
11823   if (TARGET_ELF)
11824     strcat (buf, \"@toc\");
11825   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11826   operands[2] = gen_rtx_REG (Pmode, 2);
11827   return \"ld %0,%1(%2)\";
11828 }"
11829   [(set_attr "type" "load")
11830    (set_attr "update" "no")
11831    (set_attr "indexed" "no")])
11832
11833 (define_insn "load_toc_v4_pic_si"
11834   [(set (reg:SI LR_REGNO)
11835         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
11836   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
11837   "bl _GLOBAL_OFFSET_TABLE_@local-4"
11838   [(set_attr "type" "branch")
11839    (set_attr "length" "4")])
11840
11841 (define_expand "load_toc_v4_PIC_1"
11842   [(parallel [(set (reg:SI LR_REGNO)
11843                    (match_operand:SI 0 "immediate_operand" "s"))
11844               (use (unspec [(match_dup 0)] UNSPEC_TOC))])]
11845   "TARGET_ELF && DEFAULT_ABI == ABI_V4
11846    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11847   "")
11848
11849 (define_insn "load_toc_v4_PIC_1_normal"
11850   [(set (reg:SI LR_REGNO)
11851         (match_operand:SI 0 "immediate_operand" "s"))
11852    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
11853   "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4
11854    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11855   "bcl 20,31,%0\\n%0:"
11856   [(set_attr "type" "branch")
11857    (set_attr "length" "4")])
11858
11859 (define_insn "load_toc_v4_PIC_1_476"
11860   [(set (reg:SI LR_REGNO)
11861         (match_operand:SI 0 "immediate_operand" "s"))
11862    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
11863   "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4
11864    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11865   "*
11866 {
11867   char name[32];
11868   static char templ[32];
11869
11870   get_ppc476_thunk_name (name);
11871   sprintf (templ, \"bl %s\\n%%0:\", name);
11872   return templ;
11873 }"
11874   [(set_attr "type" "branch")
11875    (set_attr "length" "4")])
11876
11877 (define_expand "load_toc_v4_PIC_1b"
11878   [(parallel [(set (reg:SI LR_REGNO)
11879                    (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11880                                (label_ref (match_operand 1 "" ""))]
11881                            UNSPEC_TOCPTR))
11882               (match_dup 1)])]
11883   "TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11884   "")
11885
11886 (define_insn "load_toc_v4_PIC_1b_normal"
11887   [(set (reg:SI LR_REGNO)
11888         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11889                     (label_ref (match_operand 1 "" ""))]
11890                 UNSPEC_TOCPTR))
11891    (match_dup 1)]
11892   "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11893   "bcl 20,31,$+8\;.long %0-$"
11894   [(set_attr "type" "branch")
11895    (set_attr "length" "8")])
11896
11897 (define_insn "load_toc_v4_PIC_1b_476"
11898   [(set (reg:SI LR_REGNO)
11899         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11900                     (label_ref (match_operand 1 "" ""))]
11901                 UNSPEC_TOCPTR))
11902    (match_dup 1)]
11903   "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11904   "*
11905 {
11906   char name[32];
11907   static char templ[32];
11908
11909   get_ppc476_thunk_name (name);
11910   sprintf (templ, \"bl %s\\n\\tb $+8\\n\\t.long %%0-$\", name);
11911   return templ;
11912 }"
11913   [(set_attr "type" "branch")
11914    (set_attr "length" "16")])
11915
11916 (define_insn "load_toc_v4_PIC_2"
11917   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11918         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11919                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
11920                              (match_operand:SI 3 "immediate_operand" "s")))))]
11921   "TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11922   "lwz %0,%2-%3(%1)"
11923   [(set_attr "type" "load")])
11924
11925 (define_insn "load_toc_v4_PIC_3b"
11926   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11927         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11928                  (high:SI
11929                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11930                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
11931   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI == ABI_V4 && flag_pic"
11932   "addis %0,%1,%2-%3@ha")
11933
11934 (define_insn "load_toc_v4_PIC_3c"
11935   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11936         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11937                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11938                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
11939   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI == ABI_V4 && flag_pic"
11940   "addi %0,%1,%2-%3@l")
11941
11942 ;; If the TOC is shared over a translation unit, as happens with all
11943 ;; the kinds of PIC that we support, we need to restore the TOC
11944 ;; pointer only when jumping over units of translation.
11945 ;; On Darwin, we need to reload the picbase.
11946
11947 (define_expand "builtin_setjmp_receiver"
11948   [(use (label_ref (match_operand 0 "" "")))]
11949   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
11950    || (TARGET_TOC && TARGET_MINIMAL_TOC)
11951    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
11952   "
11953 {
11954 #if TARGET_MACHO
11955   if (DEFAULT_ABI == ABI_DARWIN)
11956     {
11957       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME);
11958       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
11959       rtx tmplabrtx;
11960       char tmplab[20];
11961
11962       crtl->uses_pic_offset_table = 1;
11963       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
11964                                   CODE_LABEL_NUMBER (operands[0]));
11965       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
11966
11967       emit_insn (gen_load_macho_picbase (tmplabrtx));
11968       emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO));
11969       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
11970     }
11971   else
11972 #endif
11973     rs6000_emit_load_toc_table (FALSE);
11974   DONE;
11975 }")
11976
11977 ;; Largetoc support
11978 (define_insn "*largetoc_high"
11979   [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
11980         (high:DI
11981           (unspec [(match_operand:DI 1 "" "")
11982                    (match_operand:DI 2 "gpc_reg_operand" "b")]
11983                   UNSPEC_TOCREL)))]
11984    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
11985    "addis %0,%2,%1@toc@ha")
11986
11987 (define_insn "*largetoc_high_aix<mode>"
11988   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
11989         (high:P
11990           (unspec [(match_operand:P 1 "" "")
11991                    (match_operand:P 2 "gpc_reg_operand" "b")]
11992                   UNSPEC_TOCREL)))]
11993    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
11994    "addis %0,%1@u(%2)")
11995
11996 (define_insn "*largetoc_high_plus"
11997   [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
11998         (high:DI
11999           (plus:DI
12000             (unspec [(match_operand:DI 1 "" "")
12001                      (match_operand:DI 2 "gpc_reg_operand" "b")]
12002                     UNSPEC_TOCREL)
12003             (match_operand:DI 3 "add_cint_operand" "n"))))]
12004    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
12005    "addis %0,%2,%1+%3@toc@ha")
12006
12007 (define_insn "*largetoc_high_plus_aix<mode>"
12008   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
12009         (high:P
12010           (plus:P
12011             (unspec [(match_operand:P 1 "" "")
12012                      (match_operand:P 2 "gpc_reg_operand" "b")]
12013                     UNSPEC_TOCREL)
12014             (match_operand:P 3 "add_cint_operand" "n"))))]
12015    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
12016    "addis %0,%1+%3@u(%2)")
12017
12018 (define_insn "*largetoc_low"
12019   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12020         (lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b,!*r")
12021                    (match_operand:DI 2 "" "")))]
12022    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
12023    "@
12024     addi %0,%1,%2@l
12025     addic %0,%1,%2@l")
12026
12027 (define_insn "*largetoc_low_aix<mode>"
12028   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12029         (lo_sum:P (match_operand:P 1 "gpc_reg_operand" "b")
12030                    (match_operand:P 2 "" "")))]
12031    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
12032    "la %0,%2@l(%1)")
12033
12034 (define_insn_and_split "*tocref<mode>"
12035   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
12036         (match_operand:P 1 "small_toc_ref" "R"))]
12037    "TARGET_TOC"
12038    "la %0,%a1"
12039    "&& TARGET_CMODEL != CMODEL_SMALL && reload_completed"
12040   [(set (match_dup 0) (high:P (match_dup 1)))
12041    (set (match_dup 0) (lo_sum:P (match_dup 0) (match_dup 1)))])
12042
12043 ;; Elf specific ways of loading addresses for non-PIC code.
12044 ;; The output of this could be r0, but we make a very strong
12045 ;; preference for a base register because it will usually
12046 ;; be needed there.
12047 (define_insn "elf_high"
12048   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
12049         (high:SI (match_operand 1 "" "")))]
12050   "TARGET_ELF && ! TARGET_64BIT"
12051   "lis %0,%1@ha")
12052
12053 (define_insn "elf_low"
12054   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12055         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
12056                    (match_operand 2 "" "")))]
12057    "TARGET_ELF && ! TARGET_64BIT"
12058    "@
12059     la %0,%2@l(%1)
12060     addic %0,%1,%K2")
12061 \f
12062 ;; Call and call_value insns
12063 (define_expand "call"
12064   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
12065                     (match_operand 1 "" ""))
12066               (use (match_operand 2 "" ""))
12067               (clobber (reg:SI LR_REGNO))])]
12068   ""
12069   "
12070 {
12071 #if TARGET_MACHO
12072   if (MACHOPIC_INDIRECT)
12073     operands[0] = machopic_indirect_call_target (operands[0]);
12074 #endif
12075
12076   gcc_assert (GET_CODE (operands[0]) == MEM);
12077   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
12078
12079   operands[0] = XEXP (operands[0], 0);
12080
12081   if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
12082     {
12083       rs6000_call_aix (NULL_RTX, operands[0], operands[1], operands[2]);
12084       DONE;
12085     }
12086
12087   if (GET_CODE (operands[0]) != SYMBOL_REF
12088       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
12089     {
12090       if (INTVAL (operands[2]) & CALL_LONG)
12091         operands[0] = rs6000_longcall_ref (operands[0]);
12092
12093       switch (DEFAULT_ABI)
12094         {
12095         case ABI_V4:
12096         case ABI_DARWIN:
12097           operands[0] = force_reg (Pmode, operands[0]);
12098           break;
12099
12100         default:
12101           gcc_unreachable ();
12102         }
12103     }
12104 }")
12105
12106 (define_expand "call_value"
12107   [(parallel [(set (match_operand 0 "" "")
12108                    (call (mem:SI (match_operand 1 "address_operand" ""))
12109                          (match_operand 2 "" "")))
12110               (use (match_operand 3 "" ""))
12111               (clobber (reg:SI LR_REGNO))])]
12112   ""
12113   "
12114 {
12115 #if TARGET_MACHO
12116   if (MACHOPIC_INDIRECT)
12117     operands[1] = machopic_indirect_call_target (operands[1]);
12118 #endif
12119
12120   gcc_assert (GET_CODE (operands[1]) == MEM);
12121   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
12122
12123   operands[1] = XEXP (operands[1], 0);
12124
12125   if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
12126     {
12127       rs6000_call_aix (operands[0], operands[1], operands[2], operands[3]);
12128       DONE;
12129     }
12130
12131   if (GET_CODE (operands[1]) != SYMBOL_REF
12132       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
12133     {
12134       if (INTVAL (operands[3]) & CALL_LONG)
12135         operands[1] = rs6000_longcall_ref (operands[1]);
12136
12137       switch (DEFAULT_ABI)
12138         {
12139         case ABI_V4:
12140         case ABI_DARWIN:
12141           operands[1] = force_reg (Pmode, operands[1]);
12142           break;
12143
12144         default:
12145           gcc_unreachable ();
12146         }
12147     }
12148 }")
12149
12150 ;; Call to function in current module.  No TOC pointer reload needed.
12151 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
12152 ;; either the function was not prototyped, or it was prototyped as a
12153 ;; variable argument function.  It is > 0 if FP registers were passed
12154 ;; and < 0 if they were not.
12155
12156 (define_insn "*call_local32"
12157   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
12158          (match_operand 1 "" "g,g"))
12159    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12160    (clobber (reg:SI LR_REGNO))]
12161   "(INTVAL (operands[2]) & CALL_LONG) == 0"
12162   "*
12163 {
12164   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12165     output_asm_insn (\"crxor 6,6,6\", operands);
12166
12167   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12168     output_asm_insn (\"creqv 6,6,6\", operands);
12169
12170   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
12171 }"
12172   [(set_attr "type" "branch")
12173    (set_attr "length" "4,8")])
12174
12175 (define_insn "*call_local64"
12176   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
12177          (match_operand 1 "" "g,g"))
12178    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12179    (clobber (reg:SI LR_REGNO))]
12180   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
12181   "*
12182 {
12183   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12184     output_asm_insn (\"crxor 6,6,6\", operands);
12185
12186   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12187     output_asm_insn (\"creqv 6,6,6\", operands);
12188
12189   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
12190 }"
12191   [(set_attr "type" "branch")
12192    (set_attr "length" "4,8")])
12193
12194 (define_insn "*call_value_local32"
12195   [(set (match_operand 0 "" "")
12196         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
12197               (match_operand 2 "" "g,g")))
12198    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12199    (clobber (reg:SI LR_REGNO))]
12200   "(INTVAL (operands[3]) & CALL_LONG) == 0"
12201   "*
12202 {
12203   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12204     output_asm_insn (\"crxor 6,6,6\", operands);
12205
12206   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12207     output_asm_insn (\"creqv 6,6,6\", operands);
12208
12209   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
12210 }"
12211   [(set_attr "type" "branch")
12212    (set_attr "length" "4,8")])
12213
12214
12215 (define_insn "*call_value_local64"
12216   [(set (match_operand 0 "" "")
12217         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
12218               (match_operand 2 "" "g,g")))
12219    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12220    (clobber (reg:SI LR_REGNO))]
12221   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
12222   "*
12223 {
12224   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12225     output_asm_insn (\"crxor 6,6,6\", operands);
12226
12227   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12228     output_asm_insn (\"creqv 6,6,6\", operands);
12229
12230   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
12231 }"
12232   [(set_attr "type" "branch")
12233    (set_attr "length" "4,8")])
12234
12235
12236 ;; A function pointer under System V is just a normal pointer
12237 ;; operands[0] is the function pointer
12238 ;; operands[1] is the stack size to clean up
12239 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
12240 ;; which indicates how to set cr1
12241
12242 (define_insn "*call_indirect_nonlocal_sysv<mode>"
12243   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
12244          (match_operand 1 "" "g,g,g,g"))
12245    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
12246    (clobber (reg:SI LR_REGNO))]
12247   "DEFAULT_ABI == ABI_V4
12248    || DEFAULT_ABI == ABI_DARWIN"
12249 {
12250   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12251     output_asm_insn ("crxor 6,6,6", operands);
12252
12253   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12254     output_asm_insn ("creqv 6,6,6", operands);
12255
12256   return "b%T0l";
12257 }
12258   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12259    (set_attr "length" "4,4,8,8")])
12260
12261 (define_insn_and_split "*call_nonlocal_sysv<mode>"
12262   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12263          (match_operand 1 "" "g,g"))
12264    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12265    (clobber (reg:SI LR_REGNO))]
12266   "(DEFAULT_ABI == ABI_DARWIN
12267    || (DEFAULT_ABI == ABI_V4
12268        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
12269 {
12270   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12271     output_asm_insn ("crxor 6,6,6", operands);
12272
12273   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12274     output_asm_insn ("creqv 6,6,6", operands);
12275
12276 #if TARGET_MACHO
12277   return output_call(insn, operands, 0, 2);
12278 #else
12279   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12280     {
12281       gcc_assert (!TARGET_SECURE_PLT);
12282       return "bl %z0@plt";
12283     }
12284   else
12285     return "bl %z0";
12286 #endif
12287 }
12288   "DEFAULT_ABI == ABI_V4
12289    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12290    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12291   [(parallel [(call (mem:SI (match_dup 0))
12292                     (match_dup 1))
12293               (use (match_dup 2))
12294               (use (match_dup 3))
12295               (clobber (reg:SI LR_REGNO))])]
12296 {
12297   operands[3] = pic_offset_table_rtx;
12298 }
12299   [(set_attr "type" "branch,branch")
12300    (set_attr "length" "4,8")])
12301
12302 (define_insn "*call_nonlocal_sysv_secure<mode>"
12303   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
12304          (match_operand 1 "" "g,g"))
12305    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12306    (use (match_operand:SI 3 "register_operand" "r,r"))
12307    (clobber (reg:SI LR_REGNO))]
12308   "(DEFAULT_ABI == ABI_V4
12309     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
12310     && (INTVAL (operands[2]) & CALL_LONG) == 0)"
12311 {
12312   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12313     output_asm_insn ("crxor 6,6,6", operands);
12314
12315   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12316     output_asm_insn ("creqv 6,6,6", operands);
12317
12318   if (flag_pic == 2)
12319     /* The magic 32768 offset here and in the other sysv call insns
12320        corresponds to the offset of r30 in .got2, as given by LCTOC1.
12321        See sysv4.h:toc_section.  */
12322     return "bl %z0+32768@plt";
12323   else
12324     return "bl %z0@plt";
12325 }
12326   [(set_attr "type" "branch,branch")
12327    (set_attr "length" "4,8")])
12328
12329 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
12330   [(set (match_operand 0 "" "")
12331         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
12332               (match_operand 2 "" "g,g,g,g")))
12333    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
12334    (clobber (reg:SI LR_REGNO))]
12335   "DEFAULT_ABI == ABI_V4
12336    || DEFAULT_ABI == ABI_DARWIN"
12337 {
12338   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12339     output_asm_insn ("crxor 6,6,6", operands);
12340
12341   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12342     output_asm_insn ("creqv 6,6,6", operands);
12343
12344   return "b%T1l";
12345 }
12346   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
12347    (set_attr "length" "4,4,8,8")])
12348
12349 (define_insn_and_split "*call_value_nonlocal_sysv<mode>"
12350   [(set (match_operand 0 "" "")
12351         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12352               (match_operand 2 "" "g,g")))
12353    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12354    (clobber (reg:SI LR_REGNO))]
12355   "(DEFAULT_ABI == ABI_DARWIN
12356    || (DEFAULT_ABI == ABI_V4
12357        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
12358 {
12359   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12360     output_asm_insn ("crxor 6,6,6", operands);
12361
12362   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12363     output_asm_insn ("creqv 6,6,6", operands);
12364
12365 #if TARGET_MACHO
12366   return output_call(insn, operands, 1, 3);
12367 #else
12368   if (DEFAULT_ABI == ABI_V4 && flag_pic)
12369     {
12370       gcc_assert (!TARGET_SECURE_PLT);
12371       return "bl %z1@plt";
12372     }
12373   else
12374     return "bl %z1";
12375 #endif
12376 }
12377   "DEFAULT_ABI == ABI_V4
12378    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12379    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12380   [(parallel [(set (match_dup 0)
12381                    (call (mem:SI (match_dup 1))
12382                          (match_dup 2)))
12383               (use (match_dup 3))
12384               (use (match_dup 4))
12385               (clobber (reg:SI LR_REGNO))])]
12386 {
12387   operands[4] = pic_offset_table_rtx;
12388 }
12389   [(set_attr "type" "branch,branch")
12390    (set_attr "length" "4,8")])
12391
12392 (define_insn "*call_value_nonlocal_sysv_secure<mode>"
12393   [(set (match_operand 0 "" "")
12394         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12395               (match_operand 2 "" "g,g")))
12396    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12397    (use (match_operand:SI 4 "register_operand" "r,r"))
12398    (clobber (reg:SI LR_REGNO))]
12399   "(DEFAULT_ABI == ABI_V4
12400     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
12401     && (INTVAL (operands[3]) & CALL_LONG) == 0)"
12402 {
12403   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12404     output_asm_insn ("crxor 6,6,6", operands);
12405
12406   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12407     output_asm_insn ("creqv 6,6,6", operands);
12408
12409   if (flag_pic == 2)
12410     return "bl %z1+32768@plt";
12411   else
12412     return "bl %z1@plt";
12413 }
12414   [(set_attr "type" "branch,branch")
12415    (set_attr "length" "4,8")])
12416
12417
12418 ;; Call to AIX abi function in the same module.
12419
12420 (define_insn "*call_local_aix<mode>"
12421   [(call (mem:SI (match_operand:P 0 "current_file_function_operand" "s"))
12422          (match_operand 1 "" "g"))
12423    (clobber (reg:P LR_REGNO))]
12424   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12425   "bl %z0"
12426   [(set_attr "type" "branch")
12427    (set_attr "length" "4")])
12428
12429 (define_insn "*call_value_local_aix<mode>"
12430   [(set (match_operand 0 "" "")
12431         (call (mem:SI (match_operand:P 1 "current_file_function_operand" "s"))
12432               (match_operand 2 "" "g")))
12433    (clobber (reg:P LR_REGNO))]
12434   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12435   "bl %z1"
12436   [(set_attr "type" "branch")
12437    (set_attr "length" "4")])
12438
12439 ;; Call to AIX abi function which may be in another module.
12440 ;; Restore the TOC pointer (r2) after the call.
12441
12442 (define_insn "*call_nonlocal_aix<mode>"
12443   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s"))
12444          (match_operand 1 "" "g"))
12445    (clobber (reg:P LR_REGNO))]
12446   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12447   "bl %z0\;nop"
12448   [(set_attr "type" "branch")
12449    (set_attr "length" "8")])
12450
12451 (define_insn "*call_value_nonlocal_aix<mode>"
12452   [(set (match_operand 0 "" "")
12453         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s"))
12454               (match_operand 2 "" "g")))
12455    (clobber (reg:P LR_REGNO))]
12456   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12457   "bl %z1\;nop"
12458   [(set_attr "type" "branch")
12459    (set_attr "length" "8")])
12460
12461 ;; Call to indirect functions with the AIX abi using a 3 word descriptor.
12462 ;; Operand0 is the addresss of the function to call
12463 ;; Operand2 is the location in the function descriptor to load r2 from
12464 ;; Operand3 is the stack location to hold the current TOC pointer
12465
12466 (define_insn "*call_indirect_aix<mode>"
12467   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
12468          (match_operand 1 "" "g,g"))
12469    (use (match_operand:P 2 "memory_operand" "<ptrm>,<ptrm>"))
12470    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
12471    (clobber (reg:P LR_REGNO))]
12472   "DEFAULT_ABI == ABI_AIX"
12473   "<ptrload> 2,%2\;b%T0l\;<ptrload> 2,%3"
12474   [(set_attr "type" "jmpreg")
12475    (set_attr "length" "12")])
12476
12477 (define_insn "*call_value_indirect_aix<mode>"
12478   [(set (match_operand 0 "" "")
12479         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
12480               (match_operand 2 "" "g,g")))
12481    (use (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
12482    (set (reg:P TOC_REGNUM) (match_operand:P 4 "memory_operand" "<ptrm>,<ptrm>"))
12483    (clobber (reg:P LR_REGNO))]
12484   "DEFAULT_ABI == ABI_AIX"
12485   "<ptrload> 2,%3\;b%T1l\;<ptrload> 2,%4"
12486   [(set_attr "type" "jmpreg")
12487    (set_attr "length" "12")])
12488
12489 ;; Call to indirect functions with the ELFv2 ABI.
12490 ;; Operand0 is the addresss of the function to call
12491 ;; Operand2 is the stack location to hold the current TOC pointer
12492
12493 (define_insn "*call_indirect_elfv2<mode>"
12494   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
12495          (match_operand 1 "" "g,g"))
12496    (set (reg:P TOC_REGNUM) (match_operand:P 2 "memory_operand" "<ptrm>,<ptrm>"))
12497    (clobber (reg:P LR_REGNO))]
12498   "DEFAULT_ABI == ABI_ELFv2"
12499   "b%T0l\;<ptrload> 2,%2"
12500   [(set_attr "type" "jmpreg")
12501    (set_attr "length" "8")])
12502
12503 (define_insn "*call_value_indirect_elfv2<mode>"
12504   [(set (match_operand 0 "" "")
12505         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
12506               (match_operand 2 "" "g,g")))
12507    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
12508    (clobber (reg:P LR_REGNO))]
12509   "DEFAULT_ABI == ABI_ELFv2"
12510   "b%T1l\;<ptrload> 2,%3"
12511   [(set_attr "type" "jmpreg")
12512    (set_attr "length" "8")])
12513
12514
12515 ;; Call subroutine returning any type.
12516 (define_expand "untyped_call"
12517   [(parallel [(call (match_operand 0 "" "")
12518                     (const_int 0))
12519               (match_operand 1 "" "")
12520               (match_operand 2 "" "")])]
12521   ""
12522   "
12523 {
12524   int i;
12525
12526   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
12527
12528   for (i = 0; i < XVECLEN (operands[2], 0); i++)
12529     {
12530       rtx set = XVECEXP (operands[2], 0, i);
12531       emit_move_insn (SET_DEST (set), SET_SRC (set));
12532     }
12533
12534   /* The optimizer does not know that the call sets the function value
12535      registers we stored in the result block.  We avoid problems by
12536      claiming that all hard registers are used and clobbered at this
12537      point.  */
12538   emit_insn (gen_blockage ());
12539
12540   DONE;
12541 }")
12542
12543 ;; sibling call patterns
12544 (define_expand "sibcall"
12545   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
12546                     (match_operand 1 "" ""))
12547               (use (match_operand 2 "" ""))
12548               (use (reg:SI LR_REGNO))
12549               (simple_return)])]
12550   ""
12551   "
12552 {
12553 #if TARGET_MACHO
12554   if (MACHOPIC_INDIRECT)
12555     operands[0] = machopic_indirect_call_target (operands[0]);
12556 #endif
12557
12558   gcc_assert (GET_CODE (operands[0]) == MEM);
12559   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
12560
12561   operands[0] = XEXP (operands[0], 0);
12562
12563   if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
12564     {
12565       rs6000_sibcall_aix (NULL_RTX, operands[0], operands[1], operands[2]);
12566       DONE;
12567     }
12568 }")
12569
12570 (define_expand "sibcall_value"
12571   [(parallel [(set (match_operand 0 "register_operand" "")
12572                 (call (mem:SI (match_operand 1 "address_operand" ""))
12573                       (match_operand 2 "" "")))
12574               (use (match_operand 3 "" ""))
12575               (use (reg:SI LR_REGNO))
12576               (simple_return)])]
12577   ""
12578   "
12579 {
12580 #if TARGET_MACHO
12581   if (MACHOPIC_INDIRECT)
12582     operands[1] = machopic_indirect_call_target (operands[1]);
12583 #endif
12584
12585   gcc_assert (GET_CODE (operands[1]) == MEM);
12586   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
12587
12588   operands[1] = XEXP (operands[1], 0);
12589
12590   if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
12591     {
12592       rs6000_sibcall_aix (operands[0], operands[1], operands[2], operands[3]);
12593       DONE;
12594     }
12595 }")
12596
12597 ;; this and similar patterns must be marked as using LR, otherwise
12598 ;; dataflow will try to delete the store into it.  This is true
12599 ;; even when the actual reg to jump to is in CTR, when LR was
12600 ;; saved and restored around the PIC-setting BCL.
12601 (define_insn "*sibcall_local32"
12602   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
12603          (match_operand 1 "" "g,g"))
12604    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12605    (use (reg:SI LR_REGNO))
12606    (simple_return)]
12607   "(INTVAL (operands[2]) & CALL_LONG) == 0"
12608   "*
12609 {
12610   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12611     output_asm_insn (\"crxor 6,6,6\", operands);
12612
12613   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12614     output_asm_insn (\"creqv 6,6,6\", operands);
12615
12616   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12617 }"
12618   [(set_attr "type" "branch")
12619    (set_attr "length" "4,8")])
12620
12621 (define_insn "*sibcall_local64"
12622   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
12623          (match_operand 1 "" "g,g"))
12624    (use (match_operand:SI 2 "immediate_operand" "O,n"))
12625    (use (reg:SI LR_REGNO))
12626    (simple_return)]
12627   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
12628   "*
12629 {
12630   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12631     output_asm_insn (\"crxor 6,6,6\", operands);
12632
12633   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12634     output_asm_insn (\"creqv 6,6,6\", operands);
12635
12636   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
12637 }"
12638   [(set_attr "type" "branch")
12639    (set_attr "length" "4,8")])
12640
12641 (define_insn "*sibcall_value_local32"
12642   [(set (match_operand 0 "" "")
12643         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
12644               (match_operand 2 "" "g,g")))
12645    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12646    (use (reg:SI LR_REGNO))
12647    (simple_return)]
12648   "(INTVAL (operands[3]) & CALL_LONG) == 0"
12649   "*
12650 {
12651   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12652     output_asm_insn (\"crxor 6,6,6\", operands);
12653
12654   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12655     output_asm_insn (\"creqv 6,6,6\", operands);
12656
12657   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12658 }"
12659   [(set_attr "type" "branch")
12660    (set_attr "length" "4,8")])
12661
12662 (define_insn "*sibcall_value_local64"
12663   [(set (match_operand 0 "" "")
12664         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
12665               (match_operand 2 "" "g,g")))
12666    (use (match_operand:SI 3 "immediate_operand" "O,n"))
12667    (use (reg:SI LR_REGNO))
12668    (simple_return)]
12669   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
12670   "*
12671 {
12672   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12673     output_asm_insn (\"crxor 6,6,6\", operands);
12674
12675   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12676     output_asm_insn (\"creqv 6,6,6\", operands);
12677
12678   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
12679 }"
12680   [(set_attr "type" "branch")
12681    (set_attr "length" "4,8")])
12682
12683 (define_insn "*sibcall_nonlocal_sysv<mode>"
12684   [(call (mem:SI (match_operand:P 0 "call_operand" "s,s,c,c"))
12685          (match_operand 1 "" ""))
12686    (use (match_operand 2 "immediate_operand" "O,n,O,n"))
12687    (use (reg:SI LR_REGNO))
12688    (simple_return)]
12689   "(DEFAULT_ABI == ABI_DARWIN
12690     || DEFAULT_ABI == ABI_V4)
12691    && (INTVAL (operands[2]) & CALL_LONG) == 0"
12692   "*
12693 {
12694   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12695     output_asm_insn (\"crxor 6,6,6\", operands);
12696
12697   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12698     output_asm_insn (\"creqv 6,6,6\", operands);
12699
12700   if (which_alternative >= 2)
12701     return \"b%T0\";
12702   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
12703     {
12704       gcc_assert (!TARGET_SECURE_PLT);
12705       return \"b %z0@plt\";
12706     }
12707   else
12708     return \"b %z0\";
12709 }"
12710   [(set_attr "type" "branch")
12711    (set_attr "length" "4,8,4,8")])
12712
12713 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
12714   [(set (match_operand 0 "" "")
12715         (call (mem:SI (match_operand:P 1 "call_operand" "s,s,c,c"))
12716               (match_operand 2 "" "")))
12717    (use (match_operand:SI 3 "immediate_operand" "O,n,O,n"))
12718    (use (reg:SI LR_REGNO))
12719    (simple_return)]
12720   "(DEFAULT_ABI == ABI_DARWIN
12721     || DEFAULT_ABI == ABI_V4)
12722    && (INTVAL (operands[3]) & CALL_LONG) == 0"
12723   "*
12724 {
12725   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12726     output_asm_insn (\"crxor 6,6,6\", operands);
12727
12728   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12729     output_asm_insn (\"creqv 6,6,6\", operands);
12730
12731   if (which_alternative >= 2)
12732     return \"b%T1\";
12733   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
12734     {
12735       gcc_assert (!TARGET_SECURE_PLT);
12736       return \"b %z1@plt\";
12737     }
12738   else
12739     return \"b %z1\";
12740 }"
12741   [(set_attr "type" "branch")
12742    (set_attr "length" "4,8,4,8")])
12743
12744 ;; AIX ABI sibling call patterns.
12745
12746 (define_insn "*sibcall_aix<mode>"
12747   [(call (mem:SI (match_operand:P 0 "call_operand" "s,c"))
12748          (match_operand 1 "" "g,g"))
12749    (simple_return)]
12750   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12751   "@
12752    b %z0
12753    b%T0"
12754   [(set_attr "type" "branch")
12755    (set_attr "length" "4")])
12756
12757 (define_insn "*sibcall_value_aix<mode>"
12758   [(set (match_operand 0 "" "")
12759         (call (mem:SI (match_operand:P 1 "call_operand" "s,c"))
12760               (match_operand 2 "" "g,g")))
12761    (simple_return)]
12762   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12763   "@
12764    b %z1
12765    b%T1"
12766   [(set_attr "type" "branch")
12767    (set_attr "length" "4")])
12768
12769 (define_expand "sibcall_epilogue"
12770   [(use (const_int 0))]
12771   ""
12772 {
12773   if (!TARGET_SCHED_PROLOG)
12774     emit_insn (gen_blockage ());
12775   rs6000_emit_epilogue (TRUE);
12776   DONE;
12777 })
12778
12779 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
12780 ;; all of memory.  This blocks insns from being moved across this point.
12781
12782 (define_insn "blockage"
12783   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
12784   ""
12785   "")
12786
12787 (define_expand "probe_stack"
12788   [(set (match_operand 0 "memory_operand" "=m")
12789         (unspec [(const_int 0)] UNSPEC_PROBE_STACK))]
12790   ""
12791 {
12792   if (TARGET_64BIT)
12793     emit_insn (gen_probe_stack_di (operands[0]));
12794   else
12795     emit_insn (gen_probe_stack_si (operands[0]));
12796   DONE;
12797 })
12798
12799 (define_insn "probe_stack_<mode>"
12800   [(set (match_operand:P 0 "memory_operand" "=m")
12801         (unspec:P [(const_int 0)] UNSPEC_PROBE_STACK))]
12802   ""
12803 {
12804   operands[1] = gen_rtx_REG (Pmode, 0);
12805   return "st<wd>%U0%X0 %1,%0";
12806 }
12807   [(set_attr "type" "store")
12808    (set (attr "update")
12809         (if_then_else (match_operand 0 "update_address_mem")
12810                       (const_string "yes")
12811                       (const_string "no")))
12812    (set (attr "indexed")
12813         (if_then_else (match_operand 0 "indexed_address_mem")
12814                       (const_string "yes")
12815                       (const_string "no")))
12816    (set_attr "length" "4")])
12817
12818 (define_insn "probe_stack_range<P:mode>"
12819   [(set (match_operand:P 0 "register_operand" "=r")
12820         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
12821                             (match_operand:P 2 "register_operand" "r")]
12822                            UNSPECV_PROBE_STACK_RANGE))]
12823   ""
12824   "* return output_probe_stack_range (operands[0], operands[2]);"
12825   [(set_attr "type" "three")])
12826 \f
12827 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
12828 ;; signed & unsigned, and one type of branch.
12829 ;;
12830 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
12831 ;; insns, and branches.
12832
12833 (define_expand "cbranch<mode>4"
12834   [(use (match_operator 0 "rs6000_cbranch_operator"
12835          [(match_operand:GPR 1 "gpc_reg_operand" "")
12836           (match_operand:GPR 2 "reg_or_short_operand" "")]))
12837    (use (match_operand 3 ""))]
12838   ""
12839   "
12840 {
12841   /* Take care of the possibility that operands[2] might be negative but
12842      this might be a logical operation.  That insn doesn't exist.  */
12843   if (GET_CODE (operands[2]) == CONST_INT
12844       && INTVAL (operands[2]) < 0)
12845     {
12846       operands[2] = force_reg (<MODE>mode, operands[2]);
12847       operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]),
12848                                     GET_MODE (operands[0]),
12849                                     operands[1], operands[2]);
12850    }
12851
12852   rs6000_emit_cbranch (<MODE>mode, operands);
12853   DONE;
12854 }")
12855
12856 (define_expand "cbranch<mode>4"
12857   [(use (match_operator 0 "rs6000_cbranch_operator"
12858          [(match_operand:FP 1 "gpc_reg_operand" "")
12859           (match_operand:FP 2 "gpc_reg_operand" "")]))
12860    (use (match_operand 3 ""))]
12861   ""
12862   "
12863 {
12864   rs6000_emit_cbranch (<MODE>mode, operands);
12865   DONE;
12866 }")
12867
12868 (define_expand "cstore<mode>4"
12869   [(use (match_operator 1 "rs6000_cbranch_operator"
12870          [(match_operand:GPR 2 "gpc_reg_operand" "")
12871           (match_operand:GPR 3 "reg_or_short_operand" "")]))
12872    (clobber (match_operand:SI 0 "register_operand"))]
12873   ""
12874   "
12875 {
12876   /* Take care of the possibility that operands[3] might be negative but
12877      this might be a logical operation.  That insn doesn't exist.  */
12878   if (GET_CODE (operands[3]) == CONST_INT
12879       && INTVAL (operands[3]) < 0)
12880     {
12881       operands[3] = force_reg (<MODE>mode, operands[3]);
12882       operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]),
12883                                     GET_MODE (operands[1]),
12884                                     operands[2], operands[3]);
12885     }
12886
12887   /* For SNE, we would prefer that the xor/abs sequence be used for integers.
12888      For SEQ, likewise, except that comparisons with zero should be done
12889      with an scc insns.  However, due to the order that combine see the
12890      resulting insns, we must, in fact, allow SEQ for integers.  Fail in
12891      the cases we don't want to handle or are best handled by portable
12892      code.  */
12893   if (GET_CODE (operands[1]) == NE)
12894     FAIL;
12895   if ((GET_CODE (operands[1]) == LT || GET_CODE (operands[1]) == LE
12896        || GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GE)
12897       && operands[3] == const0_rtx)
12898     FAIL;
12899   rs6000_emit_sCOND (<MODE>mode, operands);
12900   DONE;
12901 }")
12902
12903 (define_expand "cstore<mode>4"
12904   [(use (match_operator 1 "rs6000_cbranch_operator"
12905          [(match_operand:FP 2 "gpc_reg_operand" "")
12906           (match_operand:FP 3 "gpc_reg_operand" "")]))
12907    (clobber (match_operand:SI 0 "register_operand"))]
12908   ""
12909   "
12910 {
12911   rs6000_emit_sCOND (<MODE>mode, operands);
12912   DONE;
12913 }")
12914
12915
12916 (define_expand "stack_protect_set"
12917   [(match_operand 0 "memory_operand" "")
12918    (match_operand 1 "memory_operand" "")]
12919   ""
12920 {
12921 #ifdef TARGET_THREAD_SSP_OFFSET
12922   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
12923   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
12924   operands[1] = gen_rtx_MEM (Pmode, addr);
12925 #endif
12926   if (TARGET_64BIT)
12927     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
12928   else
12929     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
12930   DONE;
12931 })
12932
12933 (define_insn "stack_protect_setsi"
12934   [(set (match_operand:SI 0 "memory_operand" "=m")
12935         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
12936    (set (match_scratch:SI 2 "=&r") (const_int 0))]
12937   "TARGET_32BIT"
12938   "lwz%U1%X1 %2,%1\;stw%U0%X0 %2,%0\;li %2,0"
12939   [(set_attr "type" "three")
12940    (set_attr "length" "12")])
12941
12942 (define_insn "stack_protect_setdi"
12943   [(set (match_operand:DI 0 "memory_operand" "=Y")
12944         (unspec:DI [(match_operand:DI 1 "memory_operand" "Y")] UNSPEC_SP_SET))
12945    (set (match_scratch:DI 2 "=&r") (const_int 0))]
12946   "TARGET_64BIT"
12947   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;li %2,0"
12948   [(set_attr "type" "three")
12949    (set_attr "length" "12")])
12950
12951 (define_expand "stack_protect_test"
12952   [(match_operand 0 "memory_operand" "")
12953    (match_operand 1 "memory_operand" "")
12954    (match_operand 2 "" "")]
12955   ""
12956 {
12957   rtx test, op0, op1;
12958 #ifdef TARGET_THREAD_SSP_OFFSET
12959   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
12960   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
12961   operands[1] = gen_rtx_MEM (Pmode, addr);
12962 #endif
12963   op0 = operands[0];
12964   op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]), UNSPEC_SP_TEST);
12965   test = gen_rtx_EQ (VOIDmode, op0, op1);
12966   emit_jump_insn (gen_cbranchsi4 (test, op0, op1, operands[2]));
12967   DONE;
12968 })
12969
12970 (define_insn "stack_protect_testsi"
12971   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12972         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
12973                       (match_operand:SI 2 "memory_operand" "m,m")]
12974                      UNSPEC_SP_TEST))
12975    (set (match_scratch:SI 4 "=r,r") (const_int 0))
12976    (clobber (match_scratch:SI 3 "=&r,&r"))]
12977   "TARGET_32BIT"
12978   "@
12979    lwz%U1%X1 %3,%1\;lwz%U2%X2 %4,%2\;xor. %3,%3,%4\;li %4,0
12980    lwz%U1%X1 %3,%1\;lwz%U2%X2 %4,%2\;cmplw %0,%3,%4\;li %3,0\;li %4,0"
12981   [(set_attr "length" "16,20")])
12982
12983 (define_insn "stack_protect_testdi"
12984   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12985         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "Y,Y")
12986                       (match_operand:DI 2 "memory_operand" "Y,Y")]
12987                      UNSPEC_SP_TEST))
12988    (set (match_scratch:DI 4 "=r,r") (const_int 0))
12989    (clobber (match_scratch:DI 3 "=&r,&r"))]
12990   "TARGET_64BIT"
12991   "@
12992    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;li %4,0
12993    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;li %3,0\;li %4,0"
12994   [(set_attr "length" "16,20")])
12995
12996 \f
12997 ;; Here are the actual compare insns.
12998 (define_insn "*cmp<mode>_internal1"
12999   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
13000         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
13001                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
13002   ""
13003   "cmp<wd>%I2 %0,%1,%2"
13004   [(set_attr "type" "cmp")])
13005
13006 ;; If we are comparing a register for equality with a large constant,
13007 ;; we can do this with an XOR followed by a compare.  But this is profitable
13008 ;; only if the large constant is only used for the comparison (and in this
13009 ;; case we already have a register to reuse as scratch).
13010 ;;
13011 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
13012 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
13013
13014 (define_peephole2
13015   [(set (match_operand:SI 0 "register_operand")
13016         (match_operand:SI 1 "logical_const_operand" ""))
13017    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
13018                        [(match_dup 0)
13019                         (match_operand:SI 2 "logical_const_operand" "")]))
13020    (set (match_operand:CC 4 "cc_reg_operand" "")
13021         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
13022                     (match_dup 0)))
13023    (set (pc)
13024         (if_then_else (match_operator 6 "equality_operator"
13025                        [(match_dup 4) (const_int 0)])
13026                       (match_operand 7 "" "")
13027                       (match_operand 8 "" "")))]
13028   "peep2_reg_dead_p (3, operands[0])
13029    && peep2_reg_dead_p (4, operands[4])"
13030  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
13031   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
13032   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
13033  
13034 {
13035   /* Get the constant we are comparing against, and see what it looks like
13036      when sign-extended from 16 to 32 bits.  Then see what constant we could
13037      XOR with SEXTC to get the sign-extended value.  */
13038   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
13039                                               SImode,
13040                                               operands[1], operands[2]);
13041   HOST_WIDE_INT c = INTVAL (cnst);
13042   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
13043   HOST_WIDE_INT xorv = c ^ sextc;
13044
13045   operands[9] = GEN_INT (xorv);
13046   operands[10] = GEN_INT (sextc);
13047 })
13048
13049 (define_insn "*cmpsi_internal2"
13050   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
13051         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
13052                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
13053   ""
13054   "cmplw%I2 %0,%1,%b2"
13055   [(set_attr "type" "cmp")])
13056
13057 (define_insn "*cmpdi_internal2"
13058   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
13059         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
13060                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
13061   ""
13062   "cmpld%I2 %0,%1,%b2"
13063   [(set_attr "type" "cmp")])
13064
13065 ;; The following two insns don't exist as single insns, but if we provide
13066 ;; them, we can swap an add and compare, which will enable us to overlap more
13067 ;; of the required delay between a compare and branch.  We generate code for
13068 ;; them by splitting.
13069
13070 (define_insn ""
13071   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
13072         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
13073                     (match_operand:SI 2 "short_cint_operand" "i")))
13074    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
13075         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
13076   ""
13077   "#"
13078   [(set_attr "length" "8")])
13079
13080 (define_insn ""
13081   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
13082         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
13083                        (match_operand:SI 2 "u_short_cint_operand" "i")))
13084    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
13085         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
13086   ""
13087   "#"
13088   [(set_attr "length" "8")])
13089
13090 (define_split
13091   [(set (match_operand:CC 3 "cc_reg_operand" "")
13092         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
13093                     (match_operand:SI 2 "short_cint_operand" "")))
13094    (set (match_operand:SI 0 "gpc_reg_operand" "")
13095         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
13096   ""
13097   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
13098    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
13099
13100 (define_split
13101   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
13102         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
13103                        (match_operand:SI 2 "u_short_cint_operand" "")))
13104    (set (match_operand:SI 0 "gpc_reg_operand" "")
13105         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
13106   ""
13107   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
13108    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
13109
13110 ;; Only need to compare second words if first words equal
13111 (define_insn "*cmptf_internal1"
13112   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13113         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
13114                       (match_operand:TF 2 "gpc_reg_operand" "d")))]
13115   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
13116    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
13117   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
13118   [(set_attr "type" "fpcompare")
13119    (set_attr "length" "12")])
13120
13121 (define_insn_and_split "*cmptf_internal2"
13122   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
13123         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
13124                       (match_operand:TF 2 "gpc_reg_operand" "d")))
13125     (clobber (match_scratch:DF 3 "=d"))
13126     (clobber (match_scratch:DF 4 "=d"))
13127     (clobber (match_scratch:DF 5 "=d"))
13128     (clobber (match_scratch:DF 6 "=d"))
13129     (clobber (match_scratch:DF 7 "=d"))
13130     (clobber (match_scratch:DF 8 "=d"))
13131     (clobber (match_scratch:DF 9 "=d"))
13132     (clobber (match_scratch:DF 10 "=d"))
13133     (clobber (match_scratch:GPR 11 "=b"))]
13134   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
13135    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
13136   "#"
13137   "&& reload_completed"
13138   [(set (match_dup 3) (match_dup 14))
13139    (set (match_dup 4) (match_dup 15))
13140    (set (match_dup 9) (abs:DF (match_dup 5)))
13141    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
13142    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
13143                            (label_ref (match_dup 12))
13144                            (pc)))
13145    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
13146    (set (pc) (label_ref (match_dup 13)))
13147    (match_dup 12)
13148    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
13149    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
13150    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
13151    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 4)))
13152    (match_dup 13)]
13153 {
13154   REAL_VALUE_TYPE rv;
13155   const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
13156   const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
13157
13158   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
13159   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
13160   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
13161   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
13162   operands[12] = gen_label_rtx ();
13163   operands[13] = gen_label_rtx ();
13164   real_inf (&rv);
13165   operands[14] = force_const_mem (DFmode,
13166                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
13167   operands[15] = force_const_mem (DFmode,
13168                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
13169                                                                 DFmode));
13170   if (TARGET_TOC)
13171     {
13172       rtx tocref;
13173       tocref = create_TOC_reference (XEXP (operands[14], 0), operands[11]);
13174       operands[14] = gen_const_mem (DFmode, tocref);
13175       tocref = create_TOC_reference (XEXP (operands[15], 0), operands[11]);
13176       operands[15] = gen_const_mem (DFmode, tocref);
13177       set_mem_alias_set (operands[14], get_TOC_alias_set ());
13178       set_mem_alias_set (operands[15], get_TOC_alias_set ());
13179     }
13180 })
13181 \f
13182 ;; Now we have the scc insns.  We can do some combinations because of the
13183 ;; way the machine works.
13184 ;;
13185 ;; Note that this is probably faster if we can put an insn between the
13186 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
13187 ;; cases the insns below which don't use an intermediate CR field will
13188 ;; be used instead.
13189 (define_insn ""
13190   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13191         (match_operator:SI 1 "scc_comparison_operator"
13192                            [(match_operand 2 "cc_reg_operand" "y")
13193                             (const_int 0)]))]
13194   ""
13195   "mfcr %0%Q2\;rlwinm %0,%0,%J1,1"
13196   [(set (attr "type")
13197      (cond [(match_test "TARGET_MFCRF")
13198                 (const_string "mfcrf")
13199            ]
13200         (const_string "mfcr")))
13201    (set_attr "length" "8")])
13202
13203 ;; Same as above, but get the GT bit.
13204 (define_insn "move_from_CR_gt_bit"
13205   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13206         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
13207   "TARGET_HARD_FLOAT && !TARGET_FPRS"
13208   "mfcr %0\;rlwinm %0,%0,%D1,31,31"
13209   [(set_attr "type" "mfcr")
13210    (set_attr "length" "8")])
13211
13212 ;; Same as above, but get the OV/ORDERED bit.
13213 (define_insn "move_from_CR_ov_bit"
13214   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13215         (unspec:SI [(match_operand:CC 1 "cc_reg_operand" "y")]
13216                    UNSPEC_MV_CR_OV))]
13217   "TARGET_ISEL"
13218   "mfcr %0\;rlwinm %0,%0,%t1,1"
13219   [(set_attr "type" "mfcr")
13220    (set_attr "length" "8")])
13221
13222 (define_insn ""
13223   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13224         (match_operator:DI 1 "scc_comparison_operator"
13225                            [(match_operand 2 "cc_reg_operand" "y")
13226                             (const_int 0)]))]
13227   "TARGET_POWERPC64"
13228   "mfcr %0%Q2\;rlwinm %0,%0,%J1,1"
13229   [(set (attr "type")
13230      (cond [(match_test "TARGET_MFCRF")
13231                 (const_string "mfcrf")
13232            ]
13233         (const_string "mfcr")))
13234    (set_attr "length" "8")])
13235
13236 (define_insn ""
13237   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13238         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
13239                                        [(match_operand 2 "cc_reg_operand" "y,y")
13240                                         (const_int 0)])
13241                     (const_int 0)))
13242    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
13243         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
13244   "TARGET_32BIT"
13245   "@
13246    mfcr %3%Q2\;rlwinm. %3,%3,%J1,1
13247    #"
13248   [(set_attr "type" "shift")
13249    (set_attr "dot" "yes")
13250    (set_attr "length" "8,16")])
13251
13252 (define_split
13253   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13254         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
13255                                        [(match_operand 2 "cc_reg_operand" "")
13256                                         (const_int 0)])
13257                     (const_int 0)))
13258    (set (match_operand:SI 3 "gpc_reg_operand" "")
13259         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
13260   "TARGET_32BIT && reload_completed"
13261   [(set (match_dup 3)
13262         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
13263    (set (match_dup 0)
13264         (compare:CC (match_dup 3)
13265                     (const_int 0)))]
13266   "")
13267
13268 (define_insn ""
13269   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13270         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13271                                       [(match_operand 2 "cc_reg_operand" "y")
13272                                        (const_int 0)])
13273                    (match_operand:SI 3 "const_int_operand" "n")))]
13274   ""
13275   "*
13276 {
13277   int is_bit = ccr_bit (operands[1], 1);
13278   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13279   int count;
13280
13281   if (is_bit >= put_bit)
13282     count = is_bit - put_bit;
13283   else
13284     count = 32 - (put_bit - is_bit);
13285
13286   operands[4] = GEN_INT (count);
13287   operands[5] = GEN_INT (put_bit);
13288
13289   return \"mfcr %0%Q2\;rlwinm %0,%0,%4,%5,%5\";
13290 }"
13291   [(set (attr "type")
13292      (cond [(match_test "TARGET_MFCRF")
13293                 (const_string "mfcrf")
13294            ]
13295         (const_string "mfcr")))
13296    (set_attr "length" "8")])
13297
13298 (define_insn ""
13299   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13300         (compare:CC
13301          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13302                                        [(match_operand 2 "cc_reg_operand" "y,y")
13303                                         (const_int 0)])
13304                     (match_operand:SI 3 "const_int_operand" "n,n"))
13305          (const_int 0)))
13306    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
13307         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13308                    (match_dup 3)))]
13309   ""
13310   "*
13311 {
13312   int is_bit = ccr_bit (operands[1], 1);
13313   int put_bit = 31 - (INTVAL (operands[3]) & 31);
13314   int count;
13315
13316   /* Force split for non-cc0 compare.  */
13317   if (which_alternative == 1)
13318      return \"#\";
13319
13320   if (is_bit >= put_bit)
13321     count = is_bit - put_bit;
13322   else
13323     count = 32 - (put_bit - is_bit);
13324
13325   operands[5] = GEN_INT (count);
13326   operands[6] = GEN_INT (put_bit);
13327
13328   return \"mfcr %4%Q2\;rlwinm. %4,%4,%5,%6,%6\";
13329 }"
13330   [(set_attr "type" "shift")
13331    (set_attr "dot" "yes")
13332    (set_attr "length" "8,16")])
13333
13334 (define_split
13335   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13336         (compare:CC
13337          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
13338                                        [(match_operand 2 "cc_reg_operand" "")
13339                                         (const_int 0)])
13340                     (match_operand:SI 3 "const_int_operand" ""))
13341          (const_int 0)))
13342    (set (match_operand:SI 4 "gpc_reg_operand" "")
13343         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13344                    (match_dup 3)))]
13345   "reload_completed"
13346   [(set (match_dup 4)
13347         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
13348                    (match_dup 3)))
13349    (set (match_dup 0)
13350         (compare:CC (match_dup 4)
13351                     (const_int 0)))]
13352   "")
13353
13354 ;; There is a 3 cycle delay between consecutive mfcr instructions
13355 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
13356
13357 (define_peephole
13358   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13359         (match_operator:SI 1 "scc_comparison_operator"
13360                            [(match_operand 2 "cc_reg_operand" "y")
13361                             (const_int 0)]))
13362    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
13363         (match_operator:SI 4 "scc_comparison_operator"
13364                            [(match_operand 5 "cc_reg_operand" "y")
13365                             (const_int 0)]))]
13366   "REGNO (operands[2]) != REGNO (operands[5])"
13367   "mfcr %3\;rlwinm %0,%3,%J1,1\;rlwinm %3,%3,%J4,1"
13368   [(set_attr "type" "mfcr")
13369    (set_attr "length" "12")])
13370
13371 (define_peephole
13372   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13373         (match_operator:DI 1 "scc_comparison_operator"
13374                            [(match_operand 2 "cc_reg_operand" "y")
13375                             (const_int 0)]))
13376    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
13377         (match_operator:DI 4 "scc_comparison_operator"
13378                            [(match_operand 5 "cc_reg_operand" "y")
13379                             (const_int 0)]))]
13380   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
13381   "mfcr %3\;rlwinm %0,%3,%J1,1\;rlwinm %3,%3,%J4,1"
13382   [(set_attr "type" "mfcr")
13383    (set_attr "length" "12")])
13384
13385 ;; There are some scc insns that can be done directly, without a compare.
13386 ;; These are faster because they don't involve the communications between
13387 ;; the FXU and branch units.   In fact, we will be replacing all of the
13388 ;; integer scc insns here or in the portable methods in emit_store_flag.
13389 ;;
13390 ;; Also support (neg (scc ..)) since that construct is used to replace
13391 ;; branches, (plus (scc ..) ..) since that construct is common and
13392 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
13393 ;; cases where it is no more expensive than (neg (scc ..)).
13394
13395 ;; Have reload force a constant into a register for the simple insns that
13396 ;; otherwise won't accept constants.  We do this because it is faster than
13397 ;; the cmp/mfcr sequence we would otherwise generate.
13398
13399 (define_mode_attr scc_eq_op2 [(SI "rKLI")
13400                               (DI "rKJI")])
13401
13402 (define_insn_and_split "*eq<mode>"
13403   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
13404         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
13405                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
13406   ""
13407   "#"
13408   ""
13409   [(set (match_dup 0)
13410         (clz:GPR (match_dup 3)))
13411    (set (match_dup 0)
13412         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
13413   {
13414     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13415       {
13416         /* Use output operand as intermediate.  */
13417         operands[3] = operands[0];
13418
13419         if (logical_operand (operands[2], <MODE>mode))
13420           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13421                                   gen_rtx_XOR (<MODE>mode,
13422                                                operands[1], operands[2])));
13423         else
13424           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13425                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13426                                                 negate_rtx (<MODE>mode,
13427                                                             operands[2]))));
13428       }
13429     else
13430       operands[3] = operands[1];
13431
13432     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13433   })
13434
13435 (define_insn_and_split "*eq<mode>_compare"
13436   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
13437         (compare:CC
13438          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
13439                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
13440          (const_int 0)))
13441    (set (match_operand:P 0 "gpc_reg_operand" "=r")
13442         (eq:P (match_dup 1) (match_dup 2)))]
13443   "optimize_size"
13444   "#"
13445   "optimize_size"
13446   [(set (match_dup 0)
13447         (clz:P (match_dup 4)))
13448    (parallel [(set (match_dup 3)
13449                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
13450                                (const_int 0)))
13451               (set (match_dup 0)
13452                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
13453   {
13454     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13455       {
13456         /* Use output operand as intermediate.  */
13457         operands[4] = operands[0];
13458
13459         if (logical_operand (operands[2], <MODE>mode))
13460           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13461                                   gen_rtx_XOR (<MODE>mode,
13462                                                operands[1], operands[2])));
13463         else
13464           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
13465                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13466                                                 negate_rtx (<MODE>mode,
13467                                                             operands[2]))));
13468       }
13469     else
13470       operands[4] = operands[1];
13471
13472     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
13473   })
13474
13475 ;; We have insns of the form shown by the first define_insn below.  If
13476 ;; there is something inside the comparison operation, we must split it.
13477 (define_split
13478   [(set (match_operand:SI 0 "gpc_reg_operand" "")
13479         (plus:SI (match_operator 1 "comparison_operator"
13480                                  [(match_operand:SI 2 "" "")
13481                                   (match_operand:SI 3
13482                                                     "reg_or_cint_operand" "")])
13483                  (match_operand:SI 4 "gpc_reg_operand" "")))
13484    (clobber (match_operand:SI 5 "register_operand" ""))]
13485   "! gpc_reg_operand (operands[2], SImode)"
13486   [(set (match_dup 5) (match_dup 2))
13487    (set (match_dup 0) (plus:SI (match_op_dup 1 [(match_dup 5) (match_dup 3)])
13488                                (match_dup 4)))])
13489
13490 (define_insn "*plus_eqsi"
13491   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
13492         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
13493                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
13494                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
13495   "TARGET_32BIT"
13496   "@
13497    xor %0,%1,%2\;subfic %0,%0,0\;addze %0,%3
13498    subfic %0,%1,0\;addze %0,%3
13499    xori %0,%1,%b2\;subfic %0,%0,0\;addze %0,%3
13500    xoris %0,%1,%u2\;subfic %0,%0,0\;addze %0,%3
13501    subfic %0,%1,%2\;subfic %0,%0,0\;addze %0,%3"
13502   [(set_attr "type" "three,two,three,three,three")
13503    (set_attr "length" "12,8,12,12,12")])
13504
13505 (define_insn "*compare_plus_eqsi"
13506   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13507         (compare:CC
13508          (plus:SI
13509           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13510                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13511           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13512          (const_int 0)))
13513    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
13514   "TARGET_32BIT && optimize_size"
13515   "@
13516    xor %4,%1,%2\;subfic %4,%4,0\;addze. %4,%3
13517    subfic %4,%1,0\;addze. %4,%3
13518    xori %4,%1,%b2\;subfic %4,%4,0\;addze. %4,%3
13519    xoris %4,%1,%u2\;subfic %4,%4,0\;addze. %4,%3
13520    subfic %4,%1,%2\;subfic %4,%4,0\;addze. %4,%3
13521    #
13522    #
13523    #
13524    #
13525    #"
13526   [(set_attr "type" "compare")
13527    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13528
13529 (define_split
13530   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13531         (compare:CC
13532          (plus:SI
13533           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13534                  (match_operand:SI 2 "scc_eq_operand" ""))
13535           (match_operand:SI 3 "gpc_reg_operand" ""))
13536          (const_int 0)))
13537    (clobber (match_scratch:SI 4 ""))]
13538   "TARGET_32BIT && optimize_size && reload_completed"
13539   [(set (match_dup 4)
13540         (plus:SI (eq:SI (match_dup 1)
13541                  (match_dup 2))
13542           (match_dup 3)))
13543    (set (match_dup 0)
13544         (compare:CC (match_dup 4)
13545                     (const_int 0)))]
13546   "")
13547
13548 (define_insn "*plus_eqsi_compare"
13549   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
13550         (compare:CC
13551          (plus:SI
13552           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
13553                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
13554           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
13555          (const_int 0)))
13556    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
13557         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13558   "TARGET_32BIT && optimize_size"
13559   "@
13560    xor %0,%1,%2\;subfic %0,%0,0\;addze. %0,%3
13561    subfic %0,%1,0\;addze. %0,%3
13562    xori %0,%1,%b2\;subfic %0,%0,0\;addze. %0,%3
13563    xoris %0,%1,%u2\;subfic %0,%0,0\;addze. %0,%3
13564    subfic %0,%1,%2\;subfic %0,%0,0\;addze. %0,%3
13565    #
13566    #
13567    #
13568    #
13569    #"
13570   [(set_attr "type" "compare")
13571    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
13572
13573 (define_split
13574   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13575         (compare:CC
13576          (plus:SI
13577           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
13578                  (match_operand:SI 2 "scc_eq_operand" ""))
13579           (match_operand:SI 3 "gpc_reg_operand" ""))
13580          (const_int 0)))
13581    (set (match_operand:SI 0 "gpc_reg_operand" "")
13582         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13583   "TARGET_32BIT && optimize_size && reload_completed"
13584   [(set (match_dup 0)
13585         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13586    (set (match_dup 4)
13587         (compare:CC (match_dup 0)
13588                     (const_int 0)))]
13589   "")
13590
13591 (define_insn "*neg_eq0<mode>"
13592   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13593         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
13594                      (const_int 0))))]
13595   ""
13596   "addic %0,%1,-1\;subfe %0,%0,%0"
13597   [(set_attr "type" "two")
13598    (set_attr "length" "8")])
13599
13600 (define_insn_and_split "*neg_eq<mode>"
13601   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13602         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
13603                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
13604   ""
13605   "#"
13606   ""
13607   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
13608   {
13609     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
13610       {
13611         /* Use output operand as intermediate.  */
13612         operands[3] = operands[0];
13613
13614         if (logical_operand (operands[2], <MODE>mode))
13615           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13616                                   gen_rtx_XOR (<MODE>mode,
13617                                                operands[1], operands[2])));
13618         else
13619           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
13620                                   gen_rtx_PLUS (<MODE>mode, operands[1],
13621                                                 negate_rtx (<MODE>mode,
13622                                                             operands[2]))));
13623       }
13624     else
13625       operands[3] = operands[1];
13626   })
13627
13628 (define_insn "*ne0_<mode>"
13629   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13630         (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
13631               (const_int 0)))
13632    (clobber (match_scratch:P 2 "=&r"))]
13633   "!(TARGET_32BIT && TARGET_ISEL)"
13634   "addic %2,%1,-1\;subfe %0,%2,%1"
13635   [(set_attr "type" "two")
13636    (set_attr "length" "8")])
13637
13638 (define_insn "*plus_ne0_<mode>"
13639   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13640         (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
13641                       (const_int 0))
13642                 (match_operand:P 2 "gpc_reg_operand" "r")))
13643    (clobber (match_scratch:P 3 "=&r"))]
13644   ""
13645   "addic %3,%1,-1\;addze %0,%2"
13646   [(set_attr "type" "two")
13647    (set_attr "length" "8")])
13648
13649 (define_insn "*compare_plus_ne0_<mode>"
13650   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13651         (compare:CC (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13652                                   (const_int 0))
13653                             (match_operand:P 2 "gpc_reg_operand" "r,r"))
13654                     (const_int 0)))
13655    (clobber (match_scratch:P 3 "=&r,&r"))
13656    (clobber (match_scratch:P 4 "=X,&r"))]
13657   ""
13658   "@
13659    addic %3,%1,-1\;addze. %3,%2
13660    #"
13661   [(set_attr "type" "compare")
13662    (set_attr "length" "8,12")])
13663
13664 (define_split
13665   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
13666         (compare:CC (ne:P (match_operand:SI 1 "gpc_reg_operand" "")
13667                           (const_int 0))
13668                     (neg:P (match_operand:P 2 "gpc_reg_operand" ""))))
13669    (clobber (match_scratch:P 3 ""))
13670    (clobber (match_scratch:P 4 ""))]
13671   "reload_completed"
13672   [(parallel [(set (match_dup 3)
13673                    (plus:P (ne:P (match_dup 1)
13674                                  (const_int 0))
13675                            (match_dup 2)))
13676               (clobber (match_dup 4))])
13677    (set (match_dup 0)
13678         (compare:CC (match_dup 3)
13679                     (const_int 0)))]
13680   "")
13681
13682 ; For combine.
13683 (define_insn "*compare_plus_ne0_<mode>_1"
13684   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
13685         (compare:CCEQ (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13686                             (const_int 0))
13687                       (neg:P (match_operand:P 2 "gpc_reg_operand" "r,r"))))
13688    (clobber (match_scratch:P 3 "=&r,&r"))
13689    (clobber (match_scratch:P 4 "=X,&r"))]
13690   ""
13691   "@
13692    addic %3,%1,-1\;addze. %3,%2
13693    #"
13694   [(set_attr "type" "compare")
13695    (set_attr "length" "8,12")])
13696
13697 (define_split
13698   [(set (match_operand:CCEQ 0 "cc_reg_not_micro_cr0_operand" "")
13699         (compare:CCEQ (ne:P (match_operand:SI 1 "gpc_reg_operand" "")
13700                             (const_int 0))
13701                       (neg:P (match_operand:P 2 "gpc_reg_operand" ""))))
13702    (clobber (match_scratch:P 3 ""))
13703    (clobber (match_scratch:P 4 ""))]
13704   "reload_completed"
13705   [(parallel [(set (match_dup 3)
13706                    (plus:P (ne:P (match_dup 1)
13707                                  (const_int 0))
13708                            (match_dup 2)))
13709               (clobber (match_dup 4))])
13710    (set (match_dup 0)
13711         (compare:CC (match_dup 3)
13712                     (const_int 0)))]
13713   "")
13714
13715 (define_insn "*plus_ne0_<mode>_compare"
13716   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13717         (compare:CC
13718          (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13719                        (const_int 0))
13720                  (match_operand:P 2 "gpc_reg_operand" "r,r"))
13721          (const_int 0)))
13722    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13723         (plus:P (ne:P (match_dup 1)
13724                       (const_int 0))
13725                 (match_dup 2)))
13726    (clobber (match_scratch:P 3 "=&r,&r"))]
13727   ""
13728   "@
13729    addic %3,%1,-1\;addze. %0,%2
13730    #"
13731   [(set_attr "type" "compare")
13732    (set_attr "length" "8,12")])
13733
13734 (define_split
13735   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
13736         (compare:CC
13737          (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "")
13738                        (const_int 0))
13739                  (match_operand:P 2 "gpc_reg_operand" ""))
13740          (const_int 0)))
13741    (set (match_operand:P 0 "gpc_reg_operand" "")
13742         (plus:P (ne:P (match_dup 1)
13743                       (const_int 0))
13744                 (match_dup 2)))
13745    (clobber (match_scratch:P 3 ""))]
13746   "reload_completed"
13747   [(parallel [(set (match_dup 0)
13748                    (plus:P (ne:P (match_dup 1)
13749                                  (const_int 0))
13750                            (match_dup 2)))
13751               (clobber (match_dup 3))])
13752    (set (match_dup 4)
13753         (compare:CC (match_dup 0)
13754                     (const_int 0)))]
13755   "")
13756
13757 (define_insn "*leu<mode>"
13758   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13759         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13760                (match_operand:P 2 "reg_or_short_operand" "rI")))]
13761   ""
13762   "subf%I2c %0,%1,%2\;li %0,0\;adde %0,%0,%0"
13763   [(set_attr "type" "three")
13764    (set_attr "length" "12")])
13765
13766 (define_insn "*leu<mode>_compare"
13767   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13768         (compare:CC
13769          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13770                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
13771          (const_int 0)))
13772    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13773         (leu:P (match_dup 1) (match_dup 2)))]
13774   ""
13775   "@
13776    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
13777    #"
13778   [(set_attr "type" "compare")
13779    (set_attr "length" "12,16")])
13780
13781 (define_split
13782   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13783         (compare:CC
13784          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
13785                 (match_operand:P 2 "reg_or_short_operand" ""))
13786          (const_int 0)))
13787    (set (match_operand:P 0 "gpc_reg_operand" "")
13788         (leu:P (match_dup 1) (match_dup 2)))]
13789   "reload_completed"
13790   [(set (match_dup 0)
13791         (leu:P (match_dup 1) (match_dup 2)))
13792    (set (match_dup 3)
13793         (compare:CC (match_dup 0)
13794                     (const_int 0)))]
13795   "")
13796
13797 (define_insn "*plus_leu<mode>"
13798   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13799         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13800                        (match_operand:P 2 "reg_or_short_operand" "rI"))
13801                 (match_operand:P 3 "gpc_reg_operand" "r")))]
13802   ""
13803   "subf%I2c %0,%1,%2\;addze %0,%3"
13804   [(set_attr "type" "two")
13805    (set_attr "length" "8")])
13806
13807 (define_insn ""
13808   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13809         (compare:CC
13810          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13811                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13812                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13813          (const_int 0)))
13814    (clobber (match_scratch:SI 4 "=&r,&r"))]
13815   "TARGET_32BIT"
13816   "@
13817    subf%I2c %4,%1,%2\;addze. %4,%3
13818    #"
13819   [(set_attr "type" "compare")
13820    (set_attr "length" "8,12")])
13821
13822 (define_split
13823   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13824         (compare:CC
13825          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13826                           (match_operand:SI 2 "reg_or_short_operand" ""))
13827                   (match_operand:SI 3 "gpc_reg_operand" ""))
13828          (const_int 0)))
13829    (clobber (match_scratch:SI 4 ""))]
13830   "TARGET_32BIT && reload_completed"
13831   [(set (match_dup 4)
13832         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
13833                   (match_dup 3)))
13834    (set (match_dup 0)
13835         (compare:CC (match_dup 4)
13836                     (const_int 0)))]
13837   "")
13838
13839 (define_insn ""
13840   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13841         (compare:CC
13842          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13843                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13844                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13845          (const_int 0)))
13846    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13847         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13848   "TARGET_32BIT"
13849   "@
13850    subf%I2c %0,%1,%2\;addze. %0,%3
13851    #"
13852   [(set_attr "type" "compare")
13853    (set_attr "length" "8,12")])
13854
13855 (define_split
13856   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13857         (compare:CC
13858          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13859                           (match_operand:SI 2 "reg_or_short_operand" ""))
13860                   (match_operand:SI 3 "gpc_reg_operand" ""))
13861          (const_int 0)))
13862    (set (match_operand:SI 0 "gpc_reg_operand" "")
13863         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13864   "TARGET_32BIT && reload_completed"
13865   [(set (match_dup 0)
13866         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13867    (set (match_dup 4)
13868         (compare:CC (match_dup 0)
13869                     (const_int 0)))]
13870   "")
13871
13872 (define_insn "*neg_leu<mode>"
13873   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13874         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13875                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
13876   ""
13877   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;nand %0,%0,%0"
13878    [(set_attr "type" "three")
13879     (set_attr "length" "12")])
13880
13881 (define_insn "*and_neg_leu<mode>"
13882   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13883         (and:P (neg:P
13884                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
13885                         (match_operand:P 2 "reg_or_short_operand" "rI")))
13886                 (match_operand:P 3 "gpc_reg_operand" "r")))]
13887   ""
13888   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;andc %0,%3,%0"
13889   [(set_attr "type" "three")
13890    (set_attr "length" "12")])
13891
13892 (define_insn ""
13893   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13894         (compare:CC
13895          (and:SI (neg:SI
13896                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13897                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
13898                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13899          (const_int 0)))
13900    (clobber (match_scratch:SI 4 "=&r,&r"))]
13901   "TARGET_32BIT"
13902   "@
13903    subf%I2c %4,%1,%2\;subfe %4,%4,%4\;andc. %4,%3,%4
13904    #"
13905   [(set_attr "type" "compare")
13906    (set_attr "length" "12,16")])
13907
13908 (define_split
13909   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13910         (compare:CC
13911          (and:SI (neg:SI
13912                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13913                           (match_operand:SI 2 "reg_or_short_operand" "")))
13914                  (match_operand:SI 3 "gpc_reg_operand" ""))
13915          (const_int 0)))
13916    (clobber (match_scratch:SI 4 ""))]
13917   "TARGET_32BIT && reload_completed"
13918   [(set (match_dup 4)
13919         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
13920                 (match_dup 3)))
13921    (set (match_dup 0)
13922         (compare:CC (match_dup 4)
13923                     (const_int 0)))]
13924   "")
13925
13926 (define_insn ""
13927   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13928         (compare:CC
13929          (and:SI (neg:SI
13930                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13931                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
13932                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13933          (const_int 0)))
13934    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13935         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13936   "TARGET_32BIT"
13937   "@
13938    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;andc. %0,%3,%0
13939    #"
13940   [(set_attr "type" "compare")
13941    (set_attr "length" "12,16")])
13942
13943 (define_split
13944   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13945         (compare:CC
13946          (and:SI (neg:SI
13947                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13948                           (match_operand:SI 2 "reg_or_short_operand" "")))
13949                  (match_operand:SI 3 "gpc_reg_operand" ""))
13950          (const_int 0)))
13951    (set (match_operand:SI 0 "gpc_reg_operand" "")
13952         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13953   "TARGET_32BIT && reload_completed"
13954   [(set (match_dup 0)
13955         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
13956                 (match_dup 3)))
13957    (set (match_dup 4)
13958         (compare:CC (match_dup 0)
13959                     (const_int 0)))]
13960   "")
13961
13962 (define_insn_and_split "*ltu<mode>"
13963   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13964         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13965                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
13966   ""
13967   "#"
13968   ""
13969   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13970    (set (match_dup 0) (neg:P (match_dup 0)))]
13971   "")
13972
13973 (define_insn_and_split "*ltu<mode>_compare"
13974   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
13975         (compare:CC
13976          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13977                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13978          (const_int 0)))
13979    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
13980         (ltu:P (match_dup 1) (match_dup 2)))]
13981   ""
13982   "#"
13983   ""
13984   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13985    (parallel [(set (match_dup 3)
13986                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
13987               (set (match_dup 0) (neg:P (match_dup 0)))])]
13988   "")
13989
13990 (define_insn_and_split "*plus_ltu<mode>"
13991   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
13992         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13993                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
13994                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
13995   ""
13996   "#"
13997   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13998   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13999    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
14000   "")
14001
14002 (define_insn_and_split "*plus_ltu<mode>_compare"
14003   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14004         (compare:CC
14005          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14006                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14007                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
14008          (const_int 0)))
14009    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14010         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
14011   ""
14012   "#"
14013   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14014   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
14015    (parallel [(set (match_dup 4)
14016                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
14017                                (const_int 0)))
14018               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
14019   "")
14020
14021 (define_insn "*neg_ltu<mode>"
14022   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14023         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14024                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
14025   ""
14026   "@
14027    subfc %0,%2,%1\;subfe %0,%0,%0
14028    addic %0,%1,%n2\;subfe %0,%0,%0"
14029   [(set_attr "type" "two")
14030    (set_attr "length" "8")])
14031
14032 (define_insn "*geu<mode>"
14033   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14034         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14035                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
14036   ""
14037   "@
14038    subfc %0,%2,%1\;li %0,0\;adde %0,%0,%0
14039    addic %0,%1,%n2\;li %0,0\;adde %0,%0,%0"
14040   [(set_attr "type" "three")
14041    (set_attr "length" "12")])
14042
14043 (define_insn "*geu<mode>_compare"
14044   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
14045         (compare:CC
14046          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14047                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
14048          (const_int 0)))
14049    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
14050         (geu:P (match_dup 1) (match_dup 2)))]
14051   ""
14052   "@
14053    subfc %0,%2,%1\;li %0,0\;adde. %0,%0,%0
14054    addic %0,%1,%n2\;li %0,0\;adde. %0,%0,%0
14055    #
14056    #"
14057   [(set_attr "type" "compare")
14058    (set_attr "length" "12,12,16,16")])
14059
14060 (define_split
14061   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
14062         (compare:CC
14063          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
14064                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
14065          (const_int 0)))
14066    (set (match_operand:P 0 "gpc_reg_operand" "")
14067         (geu:P (match_dup 1) (match_dup 2)))]
14068   "reload_completed"
14069   [(set (match_dup 0)
14070         (geu:P (match_dup 1) (match_dup 2)))
14071    (set (match_dup 3)
14072         (compare:CC (match_dup 0)
14073                     (const_int 0)))]
14074   "")
14075
14076 (define_insn "*plus_geu<mode>"
14077   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
14078         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14079                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
14080                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
14081   ""
14082   "@
14083    subfc %0,%2,%1\;addze %0,%3
14084    addic %0,%1,%n2\;addze %0,%3"
14085   [(set_attr "type" "two")
14086    (set_attr "length" "8")])
14087
14088 (define_insn ""
14089   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14090         (compare:CC
14091          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14092                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
14093                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14094          (const_int 0)))
14095    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14096   "TARGET_32BIT"
14097   "@
14098    subfc %4,%2,%1\;addze. %4,%3
14099    addic %4,%1,%n2\;addze. %4,%3
14100    #
14101    #"
14102   [(set_attr "type" "compare")
14103    (set_attr "length" "8,8,12,12")])
14104
14105 (define_split
14106   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14107         (compare:CC
14108          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14109                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
14110                   (match_operand:SI 3 "gpc_reg_operand" ""))
14111          (const_int 0)))
14112    (clobber (match_scratch:SI 4 ""))]
14113   "TARGET_32BIT && reload_completed"
14114   [(set (match_dup 4)
14115         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
14116                   (match_dup 3)))
14117    (set (match_dup 0)
14118         (compare:CC (match_dup 4)
14119                     (const_int 0)))]
14120   "")
14121
14122 (define_insn ""
14123   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14124         (compare:CC
14125          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14126                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
14127                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14128          (const_int 0)))
14129    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14130         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14131   "TARGET_32BIT"
14132   "@
14133    subfc %0,%2,%1\;addze. %0,%3
14134    addic %0,%1,%n2\;addze. %0,%3
14135    #
14136    #"
14137   [(set_attr "type" "compare")
14138    (set_attr "length" "8,8,12,12")])
14139
14140 (define_split
14141   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14142         (compare:CC
14143          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14144                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
14145                   (match_operand:SI 3 "gpc_reg_operand" ""))
14146          (const_int 0)))
14147    (set (match_operand:SI 0 "gpc_reg_operand" "")
14148         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
14149   "TARGET_32BIT && reload_completed"
14150   [(set (match_dup 0)
14151         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
14152    (set (match_dup 4)
14153         (compare:CC (match_dup 0)
14154                     (const_int 0)))]
14155   "")
14156
14157 (define_insn "*neg_geu<mode>"
14158   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14159         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14160                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
14161   ""
14162   "@
14163    subfc %0,%2,%1\;subfe %0,%0,%0\;nand %0,%0,%0
14164    subfic %0,%1,-1\;add%I2c %0,%0,%2\;subfe %0,%0,%0"
14165   [(set_attr "type" "three")
14166    (set_attr "length" "12")])
14167
14168 (define_insn "*and_neg_geu<mode>"
14169   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
14170         (and:P (neg:P
14171                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14172                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
14173                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
14174   ""
14175   "@
14176    subfc %0,%2,%1\;subfe %0,%0,%0\;andc %0,%3,%0
14177    addic %0,%1,%n2\;subfe %0,%0,%0\;andc %0,%3,%0"
14178   [(set_attr "type" "three")
14179    (set_attr "length" "12")])
14180
14181 (define_insn ""
14182   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
14183         (compare:CC
14184          (and:SI (neg:SI
14185                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14186                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
14187                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14188          (const_int 0)))
14189    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
14190   "TARGET_32BIT"
14191   "@
14192    subfc %4,%2,%1\;subfe %4,%4,%4\;andc. %4,%3,%4
14193    addic %4,%1,%n2\;subfe %4,%4,%4\;andc. %4,%3,%4
14194    #
14195    #"
14196   [(set_attr "type" "compare")
14197    (set_attr "length" "12,12,16,16")])
14198
14199 (define_split
14200   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14201         (compare:CC
14202          (and:SI (neg:SI
14203                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14204                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
14205                  (match_operand:SI 3 "gpc_reg_operand" ""))
14206          (const_int 0)))
14207    (clobber (match_scratch:SI 4 ""))]
14208   "TARGET_32BIT && reload_completed"
14209   [(set (match_dup 4)
14210         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
14211                 (match_dup 3)))
14212    (set (match_dup 0)
14213         (compare:CC (match_dup 4)
14214                     (const_int 0)))]
14215   "")
14216
14217 (define_insn ""
14218   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14219         (compare:CC
14220          (and:SI (neg:SI
14221                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
14222                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
14223                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
14224          (const_int 0)))
14225    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14226         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14227   "TARGET_32BIT"
14228   "@
14229    subfc %0,%2,%1\;subfe %0,%0,%0\;andc. %0,%3,%0
14230    addic %0,%1,%n2\;subfe %0,%0,%0\;andc. %0,%3,%0
14231    #
14232    #"
14233   [(set_attr "type" "compare")
14234    (set_attr "length" "12,12,16,16")])
14235
14236 (define_split
14237   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
14238         (compare:CC
14239          (and:SI (neg:SI
14240                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
14241                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
14242                  (match_operand:SI 3 "gpc_reg_operand" ""))
14243          (const_int 0)))
14244    (set (match_operand:SI 0 "gpc_reg_operand" "")
14245         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
14246   "TARGET_32BIT && reload_completed"
14247   [(set (match_dup 0)
14248         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
14249    (set (match_dup 4)
14250         (compare:CC (match_dup 0)
14251                     (const_int 0)))]
14252   "")
14253
14254 (define_insn "*plus_gt0<mode>"
14255   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14256         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
14257                       (const_int 0))
14258                  (match_operand:P 2 "gpc_reg_operand" "r")))]
14259   ""
14260   "addc %0,%1,%1\;subfe %0,%1,%0\;addze %0,%2"
14261   [(set_attr "type" "three")
14262    (set_attr "length" "12")])
14263
14264 (define_insn ""
14265   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14266         (compare:CC
14267          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14268                          (const_int 0))
14269                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14270          (const_int 0)))
14271    (clobber (match_scratch:SI 3 "=&r,&r"))]
14272   "TARGET_32BIT"
14273   "@
14274    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
14275    #"
14276   [(set_attr "type" "compare")
14277    (set_attr "length" "12,16")])
14278
14279 (define_split
14280   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
14281         (compare:CC
14282          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14283                          (const_int 0))
14284                   (match_operand:SI 2 "gpc_reg_operand" ""))
14285          (const_int 0)))
14286    (clobber (match_scratch:SI 3 ""))]
14287   "TARGET_32BIT && reload_completed"
14288   [(set (match_dup 3)
14289         (plus:SI (gt:SI (match_dup 1) (const_int 0))
14290                   (match_dup 2)))
14291    (set (match_dup 0)
14292         (compare:CC (match_dup 3)
14293                     (const_int 0)))]
14294   "")
14295
14296 (define_insn ""
14297   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
14298         (compare:CC
14299          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
14300                          (const_int 0))
14301                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14302          (const_int 0)))
14303    (clobber (match_scratch:DI 3 "=&r,&r"))]
14304   "TARGET_64BIT"
14305   "@
14306    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
14307    #"
14308   [(set_attr "type" "compare")
14309    (set_attr "length" "12,16")])
14310
14311 (define_split
14312   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
14313         (compare:CC
14314          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
14315                          (const_int 0))
14316                   (match_operand:DI 2 "gpc_reg_operand" ""))
14317          (const_int 0)))
14318    (clobber (match_scratch:DI 3 ""))]
14319   "TARGET_64BIT && reload_completed"
14320   [(set (match_dup 3)
14321         (plus:DI (gt:DI (match_dup 1) (const_int 0))
14322                  (match_dup 2)))
14323    (set (match_dup 0)
14324         (compare:CC (match_dup 3)
14325                     (const_int 0)))]
14326   "")
14327
14328 (define_insn ""
14329   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14330         (compare:CC
14331          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14332                          (const_int 0))
14333                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
14334          (const_int 0)))
14335    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
14336         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
14337   "TARGET_32BIT"
14338   "@
14339    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
14340    #"
14341   [(set_attr "type" "compare")
14342    (set_attr "length" "12,16")])
14343
14344 (define_split
14345   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
14346         (compare:CC
14347          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
14348                          (const_int 0))
14349                   (match_operand:SI 2 "gpc_reg_operand" ""))
14350          (const_int 0)))
14351    (set (match_operand:SI 0 "gpc_reg_operand" "")
14352         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
14353   "TARGET_32BIT && reload_completed"
14354   [(set (match_dup 0)
14355         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
14356    (set (match_dup 3)
14357         (compare:CC (match_dup 0)
14358                     (const_int 0)))]
14359   "")
14360
14361 (define_insn ""
14362   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14363         (compare:CC
14364          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
14365                          (const_int 0))
14366                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
14367          (const_int 0)))
14368    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
14369         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
14370   "TARGET_64BIT"
14371   "@
14372    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
14373    #"
14374   [(set_attr "type" "compare")
14375    (set_attr "length" "12,16")])
14376
14377 (define_split
14378   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
14379         (compare:CC
14380          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
14381                          (const_int 0))
14382                   (match_operand:DI 2 "gpc_reg_operand" ""))
14383          (const_int 0)))
14384    (set (match_operand:DI 0 "gpc_reg_operand" "")
14385         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
14386   "TARGET_64BIT && reload_completed"
14387   [(set (match_dup 0)
14388         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
14389    (set (match_dup 3)
14390         (compare:CC (match_dup 0)
14391                     (const_int 0)))]
14392   "")
14393
14394 (define_insn_and_split "*gtu<mode>"
14395   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14396         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14397                (match_operand:P 2 "reg_or_short_operand" "rI")))]
14398   ""
14399   "#"
14400   ""
14401   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14402    (set (match_dup 0) (neg:P (match_dup 0)))]
14403   "")
14404
14405 (define_insn_and_split "*gtu<mode>_compare"
14406   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
14407         (compare:CC
14408          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
14409                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
14410          (const_int 0)))
14411    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
14412         (gtu:P (match_dup 1) (match_dup 2)))]
14413   ""
14414   "#"
14415   ""
14416   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14417    (parallel [(set (match_dup 3)
14418                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
14419               (set (match_dup 0) (neg:P (match_dup 0)))])]
14420   "")
14421
14422 (define_insn_and_split "*plus_gtu<mode>"
14423   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
14424         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14425                        (match_operand:P 2 "reg_or_short_operand" "rI"))
14426                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
14427   ""
14428   "#"
14429   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14430   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14431    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
14432   "")
14433
14434 (define_insn_and_split "*plus_gtu<mode>_compare"
14435   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
14436         (compare:CC
14437          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
14438                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
14439                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
14440          (const_int 0)))
14441    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
14442         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
14443   ""
14444   "#"
14445   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
14446   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
14447    (parallel [(set (match_dup 4)
14448                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
14449                                (const_int 0)))
14450               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
14451   "")
14452
14453 (define_insn "*neg_gtu<mode>"
14454   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14455         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
14456                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
14457   ""
14458   "subf%I2c %0,%1,%2\;subfe %0,%0,%0"
14459   [(set_attr "type" "two")
14460    (set_attr "length" "8")])
14461
14462 \f
14463 ;; Define both directions of branch and return.  If we need a reload
14464 ;; register, we'd rather use CR0 since it is much easier to copy a
14465 ;; register CC value to there.
14466
14467 (define_insn ""
14468   [(set (pc)
14469         (if_then_else (match_operator 1 "branch_comparison_operator"
14470                                       [(match_operand 2
14471                                                       "cc_reg_operand" "y")
14472                                        (const_int 0)])
14473                       (label_ref (match_operand 0 "" ""))
14474                       (pc)))]
14475   ""
14476   "*
14477 {
14478   return output_cbranch (operands[1], \"%l0\", 0, insn);
14479 }"
14480   [(set_attr "type" "branch")])
14481
14482 (define_insn ""
14483   [(set (pc)
14484         (if_then_else (match_operator 0 "branch_comparison_operator"
14485                                       [(match_operand 1
14486                                                       "cc_reg_operand" "y")
14487                                        (const_int 0)])
14488                       (any_return)
14489                       (pc)))]
14490   "<return_pred>"
14491   "*
14492 {
14493   return output_cbranch (operands[0], NULL, 0, insn);
14494 }"
14495   [(set_attr "type" "jmpreg")
14496    (set_attr "length" "4")])
14497
14498 (define_insn ""
14499   [(set (pc)
14500         (if_then_else (match_operator 1 "branch_comparison_operator"
14501                                       [(match_operand 2
14502                                                       "cc_reg_operand" "y")
14503                                        (const_int 0)])
14504                       (pc)
14505                       (label_ref (match_operand 0 "" ""))))]
14506   ""
14507   "*
14508 {
14509   return output_cbranch (operands[1], \"%l0\", 1, insn);
14510 }"
14511   [(set_attr "type" "branch")])
14512
14513 (define_insn ""
14514   [(set (pc)
14515         (if_then_else (match_operator 0 "branch_comparison_operator"
14516                                       [(match_operand 1
14517                                                       "cc_reg_operand" "y")
14518                                        (const_int 0)])
14519                       (pc)
14520                       (any_return)))]
14521   "<return_pred>"
14522   "*
14523 {
14524   return output_cbranch (operands[0], NULL, 1, insn);
14525 }"
14526   [(set_attr "type" "jmpreg")
14527    (set_attr "length" "4")])
14528
14529 ;; Logic on condition register values.
14530
14531 ; This pattern matches things like
14532 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
14533 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
14534 ;                                  (const_int 1)))
14535 ; which are generated by the branch logic.
14536 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
14537
14538 (define_insn "*cceq_ior_compare"
14539   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14540         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
14541                         [(match_operator:SI 2
14542                                       "branch_positive_comparison_operator"
14543                                       [(match_operand 3
14544                                                       "cc_reg_operand" "y,y")
14545                                        (const_int 0)])
14546                          (match_operator:SI 4
14547                                       "branch_positive_comparison_operator"
14548                                       [(match_operand 5
14549                                                       "cc_reg_operand" "0,y")
14550                                        (const_int 0)])])
14551                       (const_int 1)))]
14552   ""
14553   "cr%q1 %E0,%j2,%j4"
14554   [(set_attr "type" "cr_logical,delayed_cr")])
14555
14556 ; Why is the constant -1 here, but 1 in the previous pattern?
14557 ; Because ~1 has all but the low bit set.
14558 (define_insn ""
14559   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14560         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
14561                         [(not:SI (match_operator:SI 2
14562                                       "branch_positive_comparison_operator"
14563                                       [(match_operand 3
14564                                                       "cc_reg_operand" "y,y")
14565                                        (const_int 0)]))
14566                          (match_operator:SI 4
14567                                 "branch_positive_comparison_operator"
14568                                 [(match_operand 5
14569                                                 "cc_reg_operand" "0,y")
14570                                  (const_int 0)])])
14571                       (const_int -1)))]
14572   ""
14573   "cr%q1 %E0,%j2,%j4"
14574   [(set_attr "type" "cr_logical,delayed_cr")])
14575
14576 (define_insn "*cceq_rev_compare"
14577   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14578         (compare:CCEQ (match_operator:SI 1
14579                                       "branch_positive_comparison_operator"
14580                                       [(match_operand 2
14581                                                       "cc_reg_operand" "0,y")
14582                                        (const_int 0)])
14583                       (const_int 0)))]
14584   ""
14585   "crnot %E0,%j1"
14586   [(set_attr "type" "cr_logical,delayed_cr")])
14587
14588 ;; If we are comparing the result of two comparisons, this can be done
14589 ;; using creqv or crxor.
14590
14591 (define_insn_and_split ""
14592   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
14593         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
14594                               [(match_operand 2 "cc_reg_operand" "y")
14595                                (const_int 0)])
14596                       (match_operator 3 "branch_comparison_operator"
14597                               [(match_operand 4 "cc_reg_operand" "y")
14598                                (const_int 0)])))]
14599   ""
14600   "#"
14601   ""
14602   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
14603                                     (match_dup 5)))]
14604   "
14605 {
14606   int positive_1, positive_2;
14607
14608   positive_1 = branch_positive_comparison_operator (operands[1],
14609                                                     GET_MODE (operands[1]));
14610   positive_2 = branch_positive_comparison_operator (operands[3],
14611                                                     GET_MODE (operands[3]));
14612
14613   if (! positive_1)
14614     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
14615                                                             GET_CODE (operands[1])),
14616                                   SImode,
14617                                   operands[2], const0_rtx);
14618   else if (GET_MODE (operands[1]) != SImode)
14619     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
14620                                   operands[2], const0_rtx);
14621
14622   if (! positive_2)
14623     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
14624                                                             GET_CODE (operands[3])),
14625                                   SImode,
14626                                   operands[4], const0_rtx);
14627   else if (GET_MODE (operands[3]) != SImode)
14628     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
14629                                   operands[4], const0_rtx);
14630
14631   if (positive_1 == positive_2)
14632     {
14633       operands[1] = gen_rtx_NOT (SImode, operands[1]);
14634       operands[5] = constm1_rtx;
14635     }
14636   else
14637     {
14638       operands[5] = const1_rtx;
14639     }
14640 }")
14641
14642 ;; Unconditional branch and return.
14643
14644 (define_insn "jump"
14645   [(set (pc)
14646         (label_ref (match_operand 0 "" "")))]
14647   ""
14648   "b %l0"
14649   [(set_attr "type" "branch")])
14650
14651 (define_insn "<return_str>return"
14652   [(any_return)]
14653   "<return_pred>"
14654   "blr"
14655   [(set_attr "type" "jmpreg")])
14656
14657 (define_expand "indirect_jump"
14658   [(set (pc) (match_operand 0 "register_operand" ""))])
14659
14660 (define_insn "*indirect_jump<mode>"
14661   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
14662   ""
14663   "@
14664    bctr
14665    blr"
14666   [(set_attr "type" "jmpreg")])
14667
14668 ;; Table jump for switch statements:
14669 (define_expand "tablejump"
14670   [(use (match_operand 0 "" ""))
14671    (use (label_ref (match_operand 1 "" "")))]
14672   ""
14673   "
14674 {
14675   if (TARGET_32BIT)
14676     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
14677   else
14678     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
14679   DONE;
14680 }")
14681
14682 (define_expand "tablejumpsi"
14683   [(set (match_dup 3)
14684         (plus:SI (match_operand:SI 0 "" "")
14685                  (match_dup 2)))
14686    (parallel [(set (pc) (match_dup 3))
14687               (use (label_ref (match_operand 1 "" "")))])]
14688   "TARGET_32BIT"
14689   "
14690 { operands[0] = force_reg (SImode, operands[0]);
14691   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
14692   operands[3] = gen_reg_rtx (SImode);
14693 }")
14694
14695 (define_expand "tablejumpdi"
14696   [(set (match_dup 4)
14697         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "")))
14698    (set (match_dup 3)
14699         (plus:DI (match_dup 4)
14700                  (match_dup 2)))
14701    (parallel [(set (pc) (match_dup 3))
14702               (use (label_ref (match_operand 1 "" "")))])]
14703   "TARGET_64BIT"
14704   "
14705 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
14706   operands[3] = gen_reg_rtx (DImode);
14707   operands[4] = gen_reg_rtx (DImode);
14708 }")
14709
14710 (define_insn "*tablejump<mode>_internal1"
14711   [(set (pc)
14712         (match_operand:P 0 "register_operand" "c,*l"))
14713    (use (label_ref (match_operand 1 "" "")))]
14714   ""
14715   "@
14716    bctr
14717    blr"
14718   [(set_attr "type" "jmpreg")])
14719
14720 (define_insn "nop"
14721   [(const_int 0)]
14722   ""
14723   "nop")
14724
14725 (define_insn "group_ending_nop"
14726   [(unspec [(const_int 0)] UNSPEC_GRP_END_NOP)]
14727   ""
14728   "*
14729 {
14730   if (rs6000_cpu_attr == CPU_POWER6)
14731     return \"ori 1,1,0\";
14732   return \"ori 2,2,0\";
14733 }")
14734 \f
14735 ;; Define the subtract-one-and-jump insns, starting with the template
14736 ;; so loop.c knows what to generate.
14737
14738 (define_expand "doloop_end"
14739   [(use (match_operand 0 "" ""))        ; loop pseudo
14740    (use (match_operand 1 "" ""))]       ; label
14741   ""
14742   "
14743 {
14744   if (TARGET_64BIT)
14745     {
14746       if (GET_MODE (operands[0]) != DImode)
14747         FAIL;
14748       emit_jump_insn (gen_ctrdi (operands[0], operands[1]));
14749     }
14750   else
14751     {
14752       if (GET_MODE (operands[0]) != SImode)
14753         FAIL;
14754       emit_jump_insn (gen_ctrsi (operands[0], operands[1]));
14755     }
14756   DONE;
14757 }")
14758
14759 (define_expand "ctr<mode>"
14760   [(parallel [(set (pc)
14761                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
14762                                      (const_int 1))
14763                                  (label_ref (match_operand 1 "" ""))
14764                                  (pc)))
14765               (set (match_dup 0)
14766                    (plus:P (match_dup 0)
14767                             (const_int -1)))
14768               (clobber (match_scratch:CC 2 ""))
14769               (clobber (match_scratch:P 3 ""))])]
14770   ""
14771   "")
14772
14773 ;; We need to be able to do this for any operand, including MEM, or we
14774 ;; will cause reload to blow up since we don't allow output reloads on
14775 ;; JUMP_INSNs.
14776 ;; For the length attribute to be calculated correctly, the
14777 ;; label MUST be operand 0.
14778
14779 (define_insn "*ctr<mode>_internal1"
14780   [(set (pc)
14781         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14782                           (const_int 1))
14783                       (label_ref (match_operand 0 "" ""))
14784                       (pc)))
14785    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14786         (plus:P (match_dup 1)
14787                  (const_int -1)))
14788    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14789    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14790   ""
14791   "*
14792 {
14793   if (which_alternative != 0)
14794     return \"#\";
14795   else if (get_attr_length (insn) == 4)
14796     return \"bdnz %l0\";
14797   else
14798     return \"bdz $+8\;b %l0\";
14799 }"
14800   [(set_attr "type" "branch")
14801    (set_attr "length" "*,12,16,16")])
14802
14803 (define_insn "*ctr<mode>_internal2"
14804   [(set (pc)
14805         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14806                           (const_int 1))
14807                       (pc)
14808                       (label_ref (match_operand 0 "" ""))))
14809    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14810         (plus:P (match_dup 1)
14811                  (const_int -1)))
14812    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14813    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14814   ""
14815   "*
14816 {
14817   if (which_alternative != 0)
14818     return \"#\";
14819   else if (get_attr_length (insn) == 4)
14820     return \"bdz %l0\";
14821   else
14822     return \"bdnz $+8\;b %l0\";
14823 }"
14824   [(set_attr "type" "branch")
14825    (set_attr "length" "*,12,16,16")])
14826
14827 ;; Similar but use EQ
14828
14829 (define_insn "*ctr<mode>_internal5"
14830   [(set (pc)
14831         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14832                           (const_int 1))
14833                       (label_ref (match_operand 0 "" ""))
14834                       (pc)))
14835    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14836         (plus:P (match_dup 1)
14837                  (const_int -1)))
14838    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14839    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14840   ""
14841   "*
14842 {
14843   if (which_alternative != 0)
14844     return \"#\";
14845   else if (get_attr_length (insn) == 4)
14846     return \"bdz %l0\";
14847   else
14848     return \"bdnz $+8\;b %l0\";
14849 }"
14850   [(set_attr "type" "branch")
14851    (set_attr "length" "*,12,16,16")])
14852
14853 (define_insn "*ctr<mode>_internal6"
14854   [(set (pc)
14855         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14856                           (const_int 1))
14857                       (pc)
14858                       (label_ref (match_operand 0 "" ""))))
14859    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14860         (plus:P (match_dup 1)
14861                  (const_int -1)))
14862    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14863    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14864   ""
14865   "*
14866 {
14867   if (which_alternative != 0)
14868     return \"#\";
14869   else if (get_attr_length (insn) == 4)
14870     return \"bdnz %l0\";
14871   else
14872     return \"bdz $+8\;b %l0\";
14873 }"
14874   [(set_attr "type" "branch")
14875    (set_attr "length" "*,12,16,16")])
14876
14877 ;; Now the splitters if we could not allocate the CTR register
14878
14879 (define_split
14880   [(set (pc)
14881         (if_then_else (match_operator 2 "comparison_operator"
14882                                       [(match_operand:P 1 "gpc_reg_operand" "")
14883                                        (const_int 1)])
14884                       (match_operand 5 "" "")
14885                       (match_operand 6 "" "")))
14886    (set (match_operand:P 0 "gpc_reg_operand" "")
14887         (plus:P (match_dup 1) (const_int -1)))
14888    (clobber (match_scratch:CC 3 ""))
14889    (clobber (match_scratch:P 4 ""))]
14890   "reload_completed"
14891   [(parallel [(set (match_dup 3)
14892                    (compare:CC (plus:P (match_dup 1)
14893                                         (const_int -1))
14894                                (const_int 0)))
14895               (set (match_dup 0)
14896                    (plus:P (match_dup 1)
14897                             (const_int -1)))])
14898    (set (pc) (if_then_else (match_dup 7)
14899                            (match_dup 5)
14900                            (match_dup 6)))]
14901   "
14902 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14903                                 operands[3], const0_rtx); }")
14904
14905 (define_split
14906   [(set (pc)
14907         (if_then_else (match_operator 2 "comparison_operator"
14908                                       [(match_operand:P 1 "gpc_reg_operand" "")
14909                                        (const_int 1)])
14910                       (match_operand 5 "" "")
14911                       (match_operand 6 "" "")))
14912    (set (match_operand:P 0 "nonimmediate_operand" "")
14913         (plus:P (match_dup 1) (const_int -1)))
14914    (clobber (match_scratch:CC 3 ""))
14915    (clobber (match_scratch:P 4 ""))]
14916   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
14917   [(parallel [(set (match_dup 3)
14918                    (compare:CC (plus:P (match_dup 1)
14919                                         (const_int -1))
14920                                (const_int 0)))
14921               (set (match_dup 4)
14922                    (plus:P (match_dup 1)
14923                             (const_int -1)))])
14924    (set (match_dup 0)
14925         (match_dup 4))
14926    (set (pc) (if_then_else (match_dup 7)
14927                            (match_dup 5)
14928                            (match_dup 6)))]
14929   "
14930 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14931                                 operands[3], const0_rtx); }")
14932 \f
14933 (define_insn "trap"
14934   [(trap_if (const_int 1) (const_int 0))]
14935   ""
14936   "trap"
14937   [(set_attr "type" "trap")])
14938
14939 (define_expand "ctrap<mode>4"
14940   [(trap_if (match_operator 0 "ordered_comparison_operator"
14941                             [(match_operand:GPR 1 "register_operand")
14942                              (match_operand:GPR 2 "reg_or_short_operand")])
14943             (match_operand 3 "zero_constant" ""))]
14944   ""
14945   "")
14946
14947 (define_insn ""
14948   [(trap_if (match_operator 0 "ordered_comparison_operator"
14949                             [(match_operand:GPR 1 "register_operand" "r")
14950                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
14951             (const_int 0))]
14952   ""
14953   "t<wd>%V0%I2 %1,%2"
14954   [(set_attr "type" "trap")])
14955 \f
14956 ;; Insns related to generating the function prologue and epilogue.
14957
14958 (define_expand "prologue"
14959   [(use (const_int 0))]
14960   ""
14961 {
14962   rs6000_emit_prologue ();
14963   if (!TARGET_SCHED_PROLOG)
14964     emit_insn (gen_blockage ());
14965   DONE;
14966 })
14967
14968 (define_insn "*movesi_from_cr_one"
14969   [(match_parallel 0 "mfcr_operation"
14970                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14971                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14972                                      (match_operand 3 "immediate_operand" "n")]
14973                           UNSPEC_MOVESI_FROM_CR))])]
14974   "TARGET_MFCRF"
14975   "*
14976 {
14977   int mask = 0;
14978   int i;
14979   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14980   {
14981     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14982     operands[4] = GEN_INT (mask);
14983     output_asm_insn (\"mfcr %1,%4\", operands);
14984   }
14985   return \"\";
14986 }"
14987   [(set_attr "type" "mfcrf")])
14988
14989 (define_insn "movesi_from_cr"
14990   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14991         (unspec:SI [(reg:CC CR0_REGNO) (reg:CC CR1_REGNO)
14992                     (reg:CC CR2_REGNO) (reg:CC CR3_REGNO)
14993                     (reg:CC CR4_REGNO) (reg:CC CR5_REGNO)
14994                     (reg:CC CR6_REGNO) (reg:CC CR7_REGNO)]
14995                    UNSPEC_MOVESI_FROM_CR))]
14996   ""
14997   "mfcr %0"
14998   [(set_attr "type" "mfcr")])
14999
15000 (define_insn "*crsave"
15001   [(match_parallel 0 "crsave_operation"
15002                    [(set (match_operand:SI 1 "memory_operand" "=m")
15003                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
15004   ""
15005   "stw %2,%1"
15006   [(set_attr "type" "store")])
15007
15008 (define_insn "*stmw"
15009   [(match_parallel 0 "stmw_operation"
15010                    [(set (match_operand:SI 1 "memory_operand" "=m")
15011                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
15012   "TARGET_MULTIPLE"
15013   "stmw %2,%1"
15014   [(set_attr "type" "store")
15015    (set_attr "update" "yes")
15016    (set_attr "indexed" "yes")])
15017
15018 ; The following comment applies to:
15019 ;     save_gpregs_*
15020 ;     save_fpregs_*
15021 ;     restore_gpregs*
15022 ;     return_and_restore_gpregs*
15023 ;     return_and_restore_fpregs*
15024 ;     return_and_restore_fpregs_aix*
15025 ;
15026 ; The out-of-line save / restore functions expects one input argument.
15027 ; Since those are not standard call_insn's, we must avoid using
15028 ; MATCH_OPERAND for that argument. That way the register rename
15029 ; optimization will not try to rename this register.
15030 ; Each pattern is repeated for each possible register number used in 
15031 ; various ABIs (r11, r1, and for some functions r12)
15032
15033 (define_insn "*save_gpregs_<mode>_r11"
15034   [(match_parallel 0 "any_parallel_operand"
15035                    [(clobber (reg:P 65))
15036                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15037                     (use (reg:P 11))
15038                     (set (match_operand:P 2 "memory_operand" "=m")
15039                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
15040   ""
15041   "bl %1"
15042   [(set_attr "type" "branch")
15043    (set_attr "length" "4")])
15044
15045 (define_insn "*save_gpregs_<mode>_r12"
15046   [(match_parallel 0 "any_parallel_operand"
15047                    [(clobber (reg:P 65))
15048                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15049                     (use (reg:P 12))
15050                     (set (match_operand:P 2 "memory_operand" "=m")
15051                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
15052   ""
15053   "bl %1"
15054   [(set_attr "type" "branch")
15055    (set_attr "length" "4")])
15056
15057 (define_insn "*save_gpregs_<mode>_r1"
15058   [(match_parallel 0 "any_parallel_operand"
15059                    [(clobber (reg:P 65))
15060                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15061                     (use (reg:P 1))
15062                     (set (match_operand:P 2 "memory_operand" "=m")
15063                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
15064   ""
15065   "bl %1"
15066   [(set_attr "type" "branch")
15067    (set_attr "length" "4")])
15068
15069 (define_insn "*save_fpregs_<mode>_r11"
15070   [(match_parallel 0 "any_parallel_operand"
15071                    [(clobber (reg:P 65))
15072                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15073                     (use (reg:P 11))
15074                     (set (match_operand:DF 2 "memory_operand" "=m")
15075                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
15076   ""
15077   "bl %1"
15078   [(set_attr "type" "branch")
15079    (set_attr "length" "4")])
15080
15081 (define_insn "*save_fpregs_<mode>_r12"
15082   [(match_parallel 0 "any_parallel_operand"
15083                    [(clobber (reg:P 65))
15084                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15085                     (use (reg:P 12))
15086                     (set (match_operand:DF 2 "memory_operand" "=m")
15087                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
15088   ""
15089   "bl %1"
15090   [(set_attr "type" "branch")
15091    (set_attr "length" "4")])
15092
15093 (define_insn "*save_fpregs_<mode>_r1"
15094   [(match_parallel 0 "any_parallel_operand"
15095                    [(clobber (reg:P 65))
15096                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
15097                     (use (reg:P 1))
15098                     (set (match_operand:DF 2 "memory_operand" "=m")
15099                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
15100   ""
15101   "bl %1"
15102   [(set_attr "type" "branch")
15103    (set_attr "length" "4")])
15104
15105 ; This is to explain that changes to the stack pointer should
15106 ; not be moved over loads from or stores to stack memory.
15107 (define_insn "stack_tie"
15108   [(match_parallel 0 "tie_operand"
15109                    [(set (mem:BLK (reg 1)) (const_int 0))])]
15110   ""
15111   ""
15112   [(set_attr "length" "0")])
15113
15114 (define_expand "epilogue"
15115   [(use (const_int 0))]
15116   ""
15117 {
15118   if (!TARGET_SCHED_PROLOG)
15119     emit_insn (gen_blockage ());
15120   rs6000_emit_epilogue (FALSE);
15121   DONE;
15122 })
15123
15124 ; On some processors, doing the mtcrf one CC register at a time is
15125 ; faster (like on the 604e).  On others, doing them all at once is
15126 ; faster; for instance, on the 601 and 750.
15127
15128 (define_expand "movsi_to_cr_one"
15129   [(set (match_operand:CC 0 "cc_reg_operand" "")
15130         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "")
15131                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
15132   ""
15133   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
15134
15135 (define_insn "*movsi_to_cr"
15136   [(match_parallel 0 "mtcrf_operation"
15137                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
15138                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
15139                                      (match_operand 3 "immediate_operand" "n")]
15140                                     UNSPEC_MOVESI_TO_CR))])]
15141  ""
15142  "*
15143 {
15144   int mask = 0;
15145   int i;
15146   for (i = 0; i < XVECLEN (operands[0], 0); i++)
15147     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
15148   operands[4] = GEN_INT (mask);
15149   return \"mtcrf %4,%2\";
15150 }"
15151   [(set_attr "type" "mtcr")])
15152
15153 (define_insn "*mtcrfsi"
15154   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
15155         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
15156                     (match_operand 2 "immediate_operand" "n")]
15157                    UNSPEC_MOVESI_TO_CR))]
15158   "GET_CODE (operands[0]) == REG
15159    && CR_REGNO_P (REGNO (operands[0]))
15160    && GET_CODE (operands[2]) == CONST_INT
15161    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
15162   "mtcrf %R0,%1"
15163   [(set_attr "type" "mtcr")])
15164
15165 ; The load-multiple instructions have similar properties.
15166 ; Note that "load_multiple" is a name known to the machine-independent
15167 ; code that actually corresponds to the PowerPC load-string.
15168
15169 (define_insn "*lmw"
15170   [(match_parallel 0 "lmw_operation"
15171                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
15172                          (match_operand:SI 2 "memory_operand" "m"))])]
15173   "TARGET_MULTIPLE"
15174   "lmw %1,%2"
15175   [(set_attr "type" "load")
15176    (set_attr "update" "yes")
15177    (set_attr "indexed" "yes")
15178    (set_attr "cell_micro" "always")])
15179
15180 (define_insn "*return_internal_<mode>"
15181   [(simple_return)
15182    (use (match_operand:P 0 "register_operand" "lc"))]
15183   ""
15184   "b%T0"
15185   [(set_attr "type" "jmpreg")])
15186
15187 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
15188 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
15189
15190 ; The following comment applies to:
15191 ;     save_gpregs_*
15192 ;     save_fpregs_*
15193 ;     restore_gpregs*
15194 ;     return_and_restore_gpregs*
15195 ;     return_and_restore_fpregs*
15196 ;     return_and_restore_fpregs_aix*
15197 ;
15198 ; The out-of-line save / restore functions expects one input argument.
15199 ; Since those are not standard call_insn's, we must avoid using
15200 ; MATCH_OPERAND for that argument. That way the register rename
15201 ; optimization will not try to rename this register.
15202 ; Each pattern is repeated for each possible register number used in 
15203 ; various ABIs (r11, r1, and for some functions r12)
15204
15205 (define_insn "*restore_gpregs_<mode>_r11"
15206  [(match_parallel 0 "any_parallel_operand"
15207                   [(clobber (match_operand:P 1 "register_operand" "=l"))
15208                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15209                    (use (reg:P 11))
15210                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
15211                         (match_operand:P 4 "memory_operand" "m"))])]
15212  ""
15213  "bl %2"
15214  [(set_attr "type" "branch")
15215   (set_attr "length" "4")])
15216
15217 (define_insn "*restore_gpregs_<mode>_r12"
15218  [(match_parallel 0 "any_parallel_operand"
15219                   [(clobber (match_operand:P 1 "register_operand" "=l"))
15220                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15221                    (use (reg:P 12))
15222                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
15223                         (match_operand:P 4 "memory_operand" "m"))])]
15224  ""
15225  "bl %2"
15226  [(set_attr "type" "branch")
15227   (set_attr "length" "4")])
15228
15229 (define_insn "*restore_gpregs_<mode>_r1"
15230  [(match_parallel 0 "any_parallel_operand"
15231                   [(clobber (match_operand:P 1 "register_operand" "=l"))
15232                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15233                    (use (reg:P 1))
15234                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
15235                         (match_operand:P 4 "memory_operand" "m"))])]
15236  ""
15237  "bl %2"
15238  [(set_attr "type" "branch")
15239   (set_attr "length" "4")])
15240
15241 (define_insn "*return_and_restore_gpregs_<mode>_r11"
15242  [(match_parallel 0 "any_parallel_operand"
15243                   [(return)
15244                    (clobber (match_operand:P 1 "register_operand" "=l"))
15245                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15246                    (use (reg:P 11))
15247                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
15248                         (match_operand:P 4 "memory_operand" "m"))])]
15249  ""
15250  "b %2"
15251  [(set_attr "type" "branch")
15252   (set_attr "length" "4")])
15253
15254 (define_insn "*return_and_restore_gpregs_<mode>_r12"
15255  [(match_parallel 0 "any_parallel_operand"
15256                   [(return)
15257                    (clobber (match_operand:P 1 "register_operand" "=l"))
15258                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15259                    (use (reg:P 12))
15260                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
15261                         (match_operand:P 4 "memory_operand" "m"))])]
15262  ""
15263  "b %2"
15264  [(set_attr "type" "branch")
15265   (set_attr "length" "4")])
15266
15267 (define_insn "*return_and_restore_gpregs_<mode>_r1"
15268  [(match_parallel 0 "any_parallel_operand"
15269                   [(return)
15270                    (clobber (match_operand:P 1 "register_operand" "=l"))
15271                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15272                    (use (reg:P 1))
15273                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
15274                         (match_operand:P 4 "memory_operand" "m"))])]
15275  ""
15276  "b %2"
15277  [(set_attr "type" "branch")
15278   (set_attr "length" "4")])
15279
15280 (define_insn "*return_and_restore_fpregs_<mode>_r11"
15281  [(match_parallel 0 "any_parallel_operand"
15282                   [(return)
15283                    (clobber (match_operand:P 1 "register_operand" "=l"))
15284                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15285                    (use (reg:P 11))
15286                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
15287                         (match_operand:DF 4 "memory_operand" "m"))])]
15288  ""
15289  "b %2"
15290  [(set_attr "type" "branch")
15291   (set_attr "length" "4")])
15292
15293 (define_insn "*return_and_restore_fpregs_<mode>_r12"
15294  [(match_parallel 0 "any_parallel_operand"
15295                   [(return)
15296                    (clobber (match_operand:P 1 "register_operand" "=l"))
15297                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15298                    (use (reg:P 12))
15299                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
15300                         (match_operand:DF 4 "memory_operand" "m"))])]
15301  ""
15302  "b %2"
15303  [(set_attr "type" "branch")
15304   (set_attr "length" "4")])
15305
15306 (define_insn "*return_and_restore_fpregs_<mode>_r1"
15307  [(match_parallel 0 "any_parallel_operand"
15308                   [(return)
15309                    (clobber (match_operand:P 1 "register_operand" "=l"))
15310                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15311                    (use (reg:P 1))
15312                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
15313                         (match_operand:DF 4 "memory_operand" "m"))])]
15314  ""
15315  "b %2"
15316  [(set_attr "type" "branch")
15317   (set_attr "length" "4")])
15318
15319 (define_insn "*return_and_restore_fpregs_aix_<mode>_r11"
15320  [(match_parallel 0 "any_parallel_operand"
15321                   [(return)
15322                    (use (match_operand:P 1 "register_operand" "l"))
15323                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15324                    (use (reg:P 11))
15325                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
15326                         (match_operand:DF 4 "memory_operand" "m"))])]
15327  ""
15328  "b %2"
15329  [(set_attr "type" "branch")
15330   (set_attr "length" "4")])
15331
15332 (define_insn "*return_and_restore_fpregs_aix_<mode>_r1"
15333  [(match_parallel 0 "any_parallel_operand"
15334                   [(return)
15335                    (use (match_operand:P 1 "register_operand" "l"))
15336                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
15337                    (use (reg:P 1))
15338                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
15339                         (match_operand:DF 4 "memory_operand" "m"))])]
15340  ""
15341  "b %2"
15342  [(set_attr "type" "branch")
15343   (set_attr "length" "4")])
15344
15345 ; This is used in compiling the unwind routines.
15346 (define_expand "eh_return"
15347   [(use (match_operand 0 "general_operand" ""))]
15348   ""
15349   "
15350 {
15351   if (TARGET_32BIT)
15352     emit_insn (gen_eh_set_lr_si (operands[0]));
15353   else
15354     emit_insn (gen_eh_set_lr_di (operands[0]));
15355   DONE;
15356 }")
15357
15358 ; We can't expand this before we know where the link register is stored.
15359 (define_insn "eh_set_lr_<mode>"
15360   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
15361                     UNSPECV_EH_RR)
15362    (clobber (match_scratch:P 1 "=&b"))]
15363   ""
15364   "#")
15365
15366 (define_split
15367   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
15368    (clobber (match_scratch 1 ""))]
15369   "reload_completed"
15370   [(const_int 0)]
15371   "
15372 {
15373   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
15374   DONE;
15375 }")
15376
15377 (define_insn "prefetch"
15378   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
15379              (match_operand:SI 1 "const_int_operand" "n")
15380              (match_operand:SI 2 "const_int_operand" "n"))]
15381   ""
15382   "*
15383 {
15384   if (GET_CODE (operands[0]) == REG)
15385     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
15386   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
15387 }"
15388   [(set_attr "type" "load")])
15389 \f
15390 (define_insn "bpermd_<mode>"
15391   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15392         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "r")
15393                    (match_operand:P 2 "gpc_reg_operand" "r")] UNSPEC_BPERM))]
15394   "TARGET_POPCNTD"
15395   "bpermd %0,%1,%2"
15396   [(set_attr "type" "popcnt")])
15397
15398 \f
15399 ;; Builtin fma support.  Handle 
15400 ;; Note that the conditions for expansion are in the FMA_F iterator.
15401
15402 (define_expand "fma<mode>4"
15403   [(set (match_operand:FMA_F 0 "register_operand" "")
15404         (fma:FMA_F
15405           (match_operand:FMA_F 1 "register_operand" "")
15406           (match_operand:FMA_F 2 "register_operand" "")
15407           (match_operand:FMA_F 3 "register_operand" "")))]
15408   ""
15409   "")
15410
15411 (define_insn "*fma<mode>4_fpr"
15412   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>,<Fv>")
15413         (fma:SFDF
15414           (match_operand:SFDF 1 "gpc_reg_operand" "%<Ff>,<Fv>,<Fv>")
15415           (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>,0")
15416           (match_operand:SFDF 3 "gpc_reg_operand" "<Ff>,0,<Fv>")))]
15417   "TARGET_<MODE>_FPR"
15418   "@
15419    fmadd<Ftrad> %0,%1,%2,%3
15420    xsmadda<Fvsx> %x0,%x1,%x2
15421    xsmaddm<Fvsx> %x0,%x1,%x3"
15422   [(set_attr "type" "fp")
15423    (set_attr "fp_type" "fp_maddsub_<Fs>")])
15424
15425 ; Altivec only has fma and nfms.
15426 (define_expand "fms<mode>4"
15427   [(set (match_operand:FMA_F 0 "register_operand" "")
15428         (fma:FMA_F
15429           (match_operand:FMA_F 1 "register_operand" "")
15430           (match_operand:FMA_F 2 "register_operand" "")
15431           (neg:FMA_F (match_operand:FMA_F 3 "register_operand" ""))))]
15432   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
15433   "")
15434
15435 (define_insn "*fms<mode>4_fpr"
15436   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>,<Fv>")
15437         (fma:SFDF
15438          (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>,<Fv>")
15439          (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>,0")
15440          (neg:SFDF (match_operand:SFDF 3 "gpc_reg_operand" "<Ff>,0,<Fv>"))))]
15441   "TARGET_<MODE>_FPR"
15442   "@
15443    fmsub<Ftrad> %0,%1,%2,%3
15444    xsmsuba<Fvsx> %x0,%x1,%x2
15445    xsmsubm<Fvsx> %x0,%x1,%x3"
15446   [(set_attr "type" "fp")
15447    (set_attr "fp_type" "fp_maddsub_<Fs>")])
15448
15449 ;; If signed zeros are ignored, -(a * b - c) = -a * b + c.
15450 (define_expand "fnma<mode>4"
15451   [(set (match_operand:FMA_F 0 "register_operand" "")
15452         (neg:FMA_F
15453           (fma:FMA_F
15454             (match_operand:FMA_F 1 "register_operand" "")
15455             (match_operand:FMA_F 2 "register_operand" "")
15456             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
15457   "!HONOR_SIGNED_ZEROS (<MODE>mode)"
15458   "")
15459
15460 ;; If signed zeros are ignored, -(a * b + c) = -a * b - c.
15461 (define_expand "fnms<mode>4"
15462   [(set (match_operand:FMA_F 0 "register_operand" "")
15463         (neg:FMA_F
15464           (fma:FMA_F
15465             (match_operand:FMA_F 1 "register_operand" "")
15466             (match_operand:FMA_F 2 "register_operand" "")
15467             (match_operand:FMA_F 3 "register_operand" ""))))]
15468   "!HONOR_SIGNED_ZEROS (<MODE>mode) && !VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
15469   "")
15470
15471 ; Not an official optab name, but used from builtins.
15472 (define_expand "nfma<mode>4"
15473   [(set (match_operand:FMA_F 0 "register_operand" "")
15474         (neg:FMA_F
15475           (fma:FMA_F
15476             (match_operand:FMA_F 1 "register_operand" "")
15477             (match_operand:FMA_F 2 "register_operand" "")
15478             (match_operand:FMA_F 3 "register_operand" ""))))]
15479   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
15480   "")
15481
15482 (define_insn "*nfma<mode>4_fpr"
15483   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>,<Fv>")
15484         (neg:SFDF
15485          (fma:SFDF
15486           (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>,<Fv>")
15487           (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>,0")
15488           (match_operand:SFDF 3 "gpc_reg_operand" "<Ff>,0,<Fv>"))))]
15489   "TARGET_<MODE>_FPR"
15490   "@
15491    fnmadd<Ftrad> %0,%1,%2,%3
15492    xsnmadda<Fvsx> %x0,%x1,%x2
15493    xsnmaddm<Fvsx> %x0,%x1,%x3"
15494   [(set_attr "type" "fp")
15495    (set_attr "fp_type" "fp_maddsub_<Fs>")])
15496
15497 ; Not an official optab name, but used from builtins.
15498 (define_expand "nfms<mode>4"
15499   [(set (match_operand:FMA_F 0 "register_operand" "")
15500         (neg:FMA_F
15501           (fma:FMA_F
15502             (match_operand:FMA_F 1 "register_operand" "")
15503             (match_operand:FMA_F 2 "register_operand" "")
15504             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
15505   ""
15506   "")
15507
15508 (define_insn "*nfmssf4_fpr"
15509   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<Ff>,<Fv>,<Fv>")
15510         (neg:SFDF
15511          (fma:SFDF
15512           (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fv>,<Fv>")
15513           (match_operand:SFDF 2 "gpc_reg_operand" "<Ff>,<Fv>,0")
15514           (neg:SFDF
15515            (match_operand:SFDF 3 "gpc_reg_operand" "<Ff>,0,<Fv>")))))]
15516   "TARGET_<MODE>_FPR"
15517   "@
15518    fnmsub<Ftrad> %0,%1,%2,%3
15519    xsnmsuba<Fvsx> %x0,%x1,%x2
15520    xsnmsubm<Fvsx> %x0,%x1,%x3"
15521   [(set_attr "type" "fp")
15522    (set_attr "fp_type" "fp_maddsub_<Fs>")])
15523
15524 \f
15525 (define_expand "rs6000_get_timebase"
15526   [(use (match_operand:DI 0 "gpc_reg_operand" ""))]
15527   ""
15528 {
15529   if (TARGET_POWERPC64)
15530     emit_insn (gen_rs6000_mftb_di (operands[0]));
15531   else
15532     emit_insn (gen_rs6000_get_timebase_ppc32 (operands[0]));
15533   DONE;
15534 })
15535
15536 (define_insn "rs6000_get_timebase_ppc32"
15537   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
15538         (unspec_volatile:DI [(const_int 0)] UNSPECV_MFTB))
15539    (clobber (match_scratch:SI 1 "=r"))
15540    (clobber (match_scratch:CC 2 "=y"))]
15541   "!TARGET_POWERPC64"
15542 {
15543   if (WORDS_BIG_ENDIAN)
15544     if (TARGET_MFCRF)
15545       {
15546         return "mfspr %0,269\;"
15547                "mfspr %L0,268\;"
15548                "mfspr %1,269\;"
15549                "cmpw %2,%0,%1\;"
15550                "bne- %2,$-16";
15551       }
15552     else
15553       {
15554         return "mftbu %0\;"
15555                "mftb %L0\;"
15556                "mftbu %1\;"
15557                "cmpw %2,%0,%1\;"
15558                "bne- %2,$-16";
15559       }
15560   else
15561     if (TARGET_MFCRF)
15562       {
15563         return "mfspr %L0,269\;"
15564                "mfspr %0,268\;"
15565                "mfspr %1,269\;"
15566                "cmpw %2,%L0,%1\;"
15567                "bne- %2,$-16";
15568       }
15569     else
15570       {
15571         return "mftbu %L0\;"
15572                "mftb %0\;"
15573                "mftbu %1\;"
15574                "cmpw %2,%L0,%1\;"
15575                "bne- %2,$-16";
15576       }
15577 }
15578   [(set_attr "length" "20")])
15579
15580 (define_insn "rs6000_mftb_<mode>"
15581   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
15582         (unspec_volatile:P [(const_int 0)] UNSPECV_MFTB))]
15583   ""
15584 {
15585   if (TARGET_MFCRF)
15586     return "mfspr %0,268";
15587   else
15588     return "mftb %0";
15589 })
15590
15591 \f
15592 (define_insn "rs6000_mffs"
15593   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
15594         (unspec_volatile:DF [(const_int 0)] UNSPECV_MFFS))]
15595   "TARGET_HARD_FLOAT && TARGET_FPRS"
15596   "mffs %0")
15597
15598 (define_insn "rs6000_mtfsf"
15599   [(unspec_volatile [(match_operand:SI 0 "const_int_operand" "i")
15600                      (match_operand:DF 1 "gpc_reg_operand" "d")]
15601                     UNSPECV_MTFSF)]
15602   "TARGET_HARD_FLOAT && TARGET_FPRS"
15603   "mtfsf %0,%1")
15604
15605 \f
15606 ;; Power8 fusion support for fusing an addis instruction with a D-form load of
15607 ;; a GPR.  The addis instruction must be adjacent to the load, and use the same
15608 ;; register that is being loaded.  The fused ops must be physically adjacent.
15609
15610 ;; We use define_peephole for the actual addis/load, and the register used to
15611 ;; hold the addis value must be the same as the register being loaded.  We use
15612 ;; define_peephole2 to change the register used for addis to be the register
15613 ;; being loaded, since we can look at whether it is dead after the load insn.
15614
15615 (define_peephole
15616   [(set (match_operand:P 0 "base_reg_operand" "")
15617         (match_operand:P 1 "fusion_gpr_addis" ""))
15618    (set (match_operand:INT1 2 "base_reg_operand" "")
15619         (match_operand:INT1 3 "fusion_gpr_mem_load" ""))]
15620   "TARGET_P8_FUSION && fusion_gpr_load_p (operands, false)"
15621 {
15622   return emit_fusion_gpr_load (operands);
15623 }
15624   [(set_attr "type" "load")
15625    (set_attr "length" "8")])
15626
15627 (define_peephole2
15628   [(set (match_operand:P 0 "base_reg_operand" "")
15629         (match_operand:P 1 "fusion_gpr_addis" ""))
15630    (set (match_operand:INT1 2 "base_reg_operand" "")
15631         (match_operand:INT1 3 "fusion_gpr_mem_load" ""))]
15632   "TARGET_P8_FUSION
15633    && (REGNO (operands[0]) != REGNO (operands[2])
15634        || GET_CODE (operands[3]) == SIGN_EXTEND)
15635    && fusion_gpr_load_p (operands, true)"
15636   [(const_int 0)]
15637 {
15638   expand_fusion_gpr_load (operands);
15639   DONE;
15640 })
15641
15642 \f
15643 ;; Miscellaneous ISA 2.06 (power7) instructions
15644 (define_insn "addg6s"
15645   [(set (match_operand:SI 0 "register_operand" "=r")
15646         (unspec:SI [(match_operand:SI 1 "register_operand" "r")
15647                     (match_operand:SI 2 "register_operand" "r")]
15648                    UNSPEC_ADDG6S))]
15649   "TARGET_POPCNTD"
15650   "addg6s %0,%1,%2"
15651   [(set_attr "type" "integer")
15652    (set_attr "length" "4")])
15653
15654 (define_insn "cdtbcd"
15655   [(set (match_operand:SI 0 "register_operand" "=r")
15656         (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
15657                    UNSPEC_CDTBCD))]
15658   "TARGET_POPCNTD"
15659   "cdtbcd %0,%1"
15660   [(set_attr "type" "integer")
15661    (set_attr "length" "4")])
15662
15663 (define_insn "cbcdtd"
15664   [(set (match_operand:SI 0 "register_operand" "=r")
15665         (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
15666                    UNSPEC_CBCDTD))]
15667   "TARGET_POPCNTD"
15668   "cbcdtd %0,%1"
15669   [(set_attr "type" "integer")
15670    (set_attr "length" "4")])
15671
15672 (define_int_iterator UNSPEC_DIV_EXTEND [UNSPEC_DIVE
15673                                         UNSPEC_DIVEO
15674                                         UNSPEC_DIVEU
15675                                         UNSPEC_DIVEUO])
15676
15677 (define_int_attr div_extend [(UNSPEC_DIVE       "e")
15678                              (UNSPEC_DIVEO      "eo")
15679                              (UNSPEC_DIVEU      "eu")
15680                              (UNSPEC_DIVEUO     "euo")])
15681
15682 (define_insn "div<div_extend>_<mode>"
15683   [(set (match_operand:GPR 0 "register_operand" "=r")
15684         (unspec:GPR [(match_operand:GPR 1 "register_operand" "r")
15685                      (match_operand:GPR 2 "register_operand" "r")]
15686                     UNSPEC_DIV_EXTEND))]
15687   "TARGET_POPCNTD"
15688   "div<wd><div_extend> %0,%1,%2"
15689   [(set_attr "type" "div")
15690    (set_attr "size" "<bits>")])
15691
15692 \f
15693 ;; Pack/unpack 128-bit floating point types that take 2 scalar registers
15694
15695 ; Type of the 64-bit part when packing/unpacking 128-bit floating point types
15696 (define_mode_attr FP128_64 [(TF "DF") (TD "DI")])
15697
15698 (define_expand "unpack<mode>"
15699   [(set (match_operand:<FP128_64> 0 "nonimmediate_operand" "")
15700         (unspec:<FP128_64>
15701          [(match_operand:FMOVE128 1 "register_operand" "")
15702           (match_operand:QI 2 "const_0_to_1_operand" "")]
15703          UNSPEC_UNPACK_128BIT))]
15704   ""
15705   "")
15706
15707 (define_insn_and_split "unpack<mode>_dm"
15708   [(set (match_operand:<FP128_64> 0 "nonimmediate_operand" "=d,m,d,r,m")
15709         (unspec:<FP128_64>
15710          [(match_operand:FMOVE128 1 "register_operand" "d,d,r,d,r")
15711           (match_operand:QI 2 "const_0_to_1_operand" "i,i,i,i,i")]
15712          UNSPEC_UNPACK_128BIT))]
15713   "TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
15714   "#"
15715   "&& reload_completed"
15716   [(set (match_dup 0) (match_dup 3))]
15717 {
15718   unsigned fp_regno = REGNO (operands[1]) + UINTVAL (operands[2]);
15719
15720   if (REG_P (operands[0]) && REGNO (operands[0]) == fp_regno)
15721     {
15722       emit_note (NOTE_INSN_DELETED);
15723       DONE;
15724     }
15725
15726   operands[3] = gen_rtx_REG (<FP128_64>mode, fp_regno);
15727 }
15728   [(set_attr "type" "fp,fpstore,mffgpr,mftgpr,store")
15729    (set_attr "length" "4")])
15730
15731 (define_insn_and_split "unpack<mode>_nodm"
15732   [(set (match_operand:<FP128_64> 0 "nonimmediate_operand" "=d,m")
15733         (unspec:<FP128_64>
15734          [(match_operand:FMOVE128 1 "register_operand" "d,d")
15735           (match_operand:QI 2 "const_0_to_1_operand" "i,i")]
15736          UNSPEC_UNPACK_128BIT))]
15737   "!TARGET_POWERPC64 || !TARGET_DIRECT_MOVE"
15738   "#"
15739   "&& reload_completed"
15740   [(set (match_dup 0) (match_dup 3))]
15741 {
15742   unsigned fp_regno = REGNO (operands[1]) + UINTVAL (operands[2]);
15743
15744   if (REG_P (operands[0]) && REGNO (operands[0]) == fp_regno)
15745     {
15746       emit_note (NOTE_INSN_DELETED);
15747       DONE;
15748     }
15749
15750   operands[3] = gen_rtx_REG (<FP128_64>mode, fp_regno);
15751 }
15752   [(set_attr "type" "fp,fpstore")
15753    (set_attr "length" "4")])
15754
15755 (define_insn_and_split "pack<mode>"
15756   [(set (match_operand:FMOVE128 0 "register_operand" "=d,&d")
15757         (unspec:FMOVE128
15758          [(match_operand:<FP128_64> 1 "register_operand" "0,d")
15759           (match_operand:<FP128_64> 2 "register_operand" "d,d")]
15760          UNSPEC_PACK_128BIT))]
15761   ""
15762   "@
15763    fmr %L0,%2
15764    #"
15765   "&& reload_completed && REGNO (operands[0]) != REGNO (operands[1])"
15766   [(set (match_dup 3) (match_dup 1))
15767    (set (match_dup 4) (match_dup 2))]
15768 {
15769   unsigned dest_hi = REGNO (operands[0]);
15770   unsigned dest_lo = dest_hi + 1;
15771
15772   gcc_assert (!IN_RANGE (REGNO (operands[1]), dest_hi, dest_lo));
15773   gcc_assert (!IN_RANGE (REGNO (operands[2]), dest_hi, dest_lo));
15774
15775   operands[3] = gen_rtx_REG (<FP128_64>mode, dest_hi);
15776   operands[4] = gen_rtx_REG (<FP128_64>mode, dest_lo);
15777 }
15778   [(set_attr "type" "fp,fp")
15779    (set_attr "length" "4,8")])
15780
15781 (define_insn "unpackv1ti"
15782   [(set (match_operand:DI 0 "register_operand" "=d,d")
15783         (unspec:DI [(match_operand:V1TI 1 "register_operand" "0,wa")
15784                     (match_operand:QI 2 "const_0_to_1_operand" "O,i")]
15785          UNSPEC_UNPACK_128BIT))]
15786   "TARGET_VSX"
15787 {
15788   if (REGNO (operands[0]) == REGNO (operands[1]) && INTVAL (operands[2]) == 0)
15789     return ASM_COMMENT_START " xxpermdi to same register";
15790
15791   operands[3] = GEN_INT (INTVAL (operands[2]) == 0 ? 0 : 3);
15792   return "xxpermdi %x0,%x1,%x1,%3";
15793 }
15794   [(set_attr "type" "vecperm")
15795    (set_attr "length" "4")])
15796
15797 (define_insn "packv1ti"
15798   [(set (match_operand:V1TI 0 "register_operand" "=wa")
15799         (unspec:V1TI
15800          [(match_operand:DI 1 "register_operand" "d")
15801           (match_operand:DI 2 "register_operand" "d")]
15802          UNSPEC_PACK_128BIT))]
15803   "TARGET_VSX"
15804   "xxpermdi %x0,%x1,%x2,0"
15805   [(set_attr "type" "vecperm")
15806    (set_attr "length" "4")])
15807
15808 \f
15809
15810 (include "sync.md")
15811 (include "vector.md")
15812 (include "vsx.md")
15813 (include "altivec.md")
15814 (include "spe.md")
15815 (include "dfp.md")
15816 (include "paired.md")
15817 (include "crypto.md")
15818 (include "htm.md")