Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / gcc / config / rs6000 / rs6000.md
1 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
2 ;; Copyright (C) 1990-2013 Free Software Foundation, Inc.
3 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
4
5 ;; This file is part of GCC.
6
7 ;; GCC is free software; you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 3, or (at your
10 ;; option) any later version.
11
12 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15 ;; License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3.  If not see
19 ;; <http://www.gnu.org/licenses/>.
20
21 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
22
23 ;;
24 ;; REGNOS
25 ;;
26
27 (define_constants
28   [(STACK_POINTER_REGNUM        1)
29    (TOC_REGNUM                  2)
30    (STATIC_CHAIN_REGNUM         11)
31    (HARD_FRAME_POINTER_REGNUM   31)
32    (LR_REGNO                    65)
33    (CTR_REGNO                   66)
34    (ARG_POINTER_REGNUM          67)
35    (CR0_REGNO                   68)
36    (CR1_REGNO                   69)
37    (CR2_REGNO                   70)
38    (CR3_REGNO                   71)
39    (CR4_REGNO                   72)
40    (CR5_REGNO                   73)
41    (CR6_REGNO                   74)
42    (CR7_REGNO                   75)
43    (MAX_CR_REGNO                75)
44    (CA_REGNO                    76)
45    (FIRST_ALTIVEC_REGNO         77)
46    (LAST_ALTIVEC_REGNO          108)
47    (VRSAVE_REGNO                109)
48    (VSCR_REGNO                  110)
49    (SPE_ACC_REGNO               111)
50    (SPEFSCR_REGNO               112)
51    (FRAME_POINTER_REGNUM        113)
52
53    ; ABI defined stack offsets for storing the TOC pointer with AIX calls.
54    (TOC_SAVE_OFFSET_32BIT       20)
55    (TOC_SAVE_OFFSET_64BIT       40)
56
57    ; Function TOC offset in the AIX function descriptor.
58    (AIX_FUNC_DESC_TOC_32BIT     4)
59    (AIX_FUNC_DESC_TOC_64BIT     8)
60
61    ; Static chain offset in the AIX function descriptor.
62    (AIX_FUNC_DESC_SC_32BIT      8)
63    (AIX_FUNC_DESC_SC_64BIT      16)
64   ])
65
66 ;;
67 ;; UNSPEC usage
68 ;;
69
70 (define_c_enum "unspec"
71   [UNSPEC_FRSP                  ; frsp for POWER machines
72    UNSPEC_PROBE_STACK           ; probe stack memory reference
73    UNSPEC_TOCPTR                ; address of a word pointing to the TOC
74    UNSPEC_TOC                   ; address of the TOC (more-or-less)
75    UNSPEC_MOVSI_GOT
76    UNSPEC_MV_CR_OV              ; move_from_CR_ov_bit
77    UNSPEC_FCTIWZ
78    UNSPEC_FRIM
79    UNSPEC_FRIN
80    UNSPEC_FRIP
81    UNSPEC_FRIZ
82    UNSPEC_LD_MPIC               ; load_macho_picbase
83    UNSPEC_MPIC_CORRECT          ; macho_correct_pic
84    UNSPEC_TLSGD
85    UNSPEC_TLSLD
86    UNSPEC_MOVESI_FROM_CR
87    UNSPEC_MOVESI_TO_CR
88    UNSPEC_TLSDTPREL
89    UNSPEC_TLSDTPRELHA
90    UNSPEC_TLSDTPRELLO
91    UNSPEC_TLSGOTDTPREL
92    UNSPEC_TLSTPREL
93    UNSPEC_TLSTPRELHA
94    UNSPEC_TLSTPRELLO
95    UNSPEC_TLSGOTTPREL
96    UNSPEC_TLSTLS
97    UNSPEC_FIX_TRUNC_TF          ; fadd, rounding towards zero
98    UNSPEC_MV_CR_GT              ; move_from_CR_gt_bit
99    UNSPEC_STFIWX
100    UNSPEC_POPCNTB
101    UNSPEC_FRES
102    UNSPEC_SP_SET
103    UNSPEC_SP_TEST
104    UNSPEC_SYNC
105    UNSPEC_LWSYNC
106    UNSPEC_SYNC_OP
107    UNSPEC_ATOMIC
108    UNSPEC_CMPXCHG
109    UNSPEC_XCHG
110    UNSPEC_AND
111    UNSPEC_DLMZB
112    UNSPEC_DLMZB_CR
113    UNSPEC_DLMZB_STRLEN
114    UNSPEC_RSQRT
115    UNSPEC_TOCREL
116    UNSPEC_MACHOPIC_OFFSET
117    UNSPEC_BPERM
118    UNSPEC_COPYSIGN
119    UNSPEC_PARITY
120    UNSPEC_FCTIW
121    UNSPEC_FCTID
122    UNSPEC_LFIWAX
123    UNSPEC_LFIWZX
124    UNSPEC_FCTIWUZ
125    UNSPEC_GRP_END_NOP
126   ])
127
128 ;;
129 ;; UNSPEC_VOLATILE usage
130 ;;
131
132 (define_c_enum "unspecv"
133   [UNSPECV_BLOCK
134    UNSPECV_LL                   ; load-locked
135    UNSPECV_SC                   ; store-conditional
136    UNSPECV_PROBE_STACK_RANGE    ; probe range of stack addresses
137    UNSPECV_EH_RR                ; eh_reg_restore
138    UNSPECV_ISYNC                ; isync instruction
139    UNSPECV_MFTB                 ; move from time base
140   ])
141
142 \f
143 ;; Define an insn type attribute.  This is used in function unit delay
144 ;; computations.
145 (define_attr "type" "integer,two,three,load,load_ext,load_ext_u,load_ext_ux,load_ux,load_u,store,store_ux,store_u,fpload,fpload_ux,fpload_u,fpstore,fpstore_ux,fpstore_u,vecload,vecstore,imul,imul2,imul3,lmul,idiv,ldiv,insert_word,branch,cmp,fast_compare,compare,var_delayed_compare,delayed_compare,imul_compare,lmul_compare,fpcompare,cr_logical,delayed_cr,mfcr,mfcrf,mtcr,mfjmpr,mtjmpr,fp,fpsimple,dmul,sdiv,ddiv,ssqrt,dsqrt,jmpreg,brinc,vecsimple,veccomplex,vecdiv,veccmp,veccmpsimple,vecperm,vecfloat,vecfdiv,vecdouble,isync,sync,load_l,store_c,shift,trap,insert_dword,var_shift_rotate,cntlz,exts,mffgpr,mftgpr,isel,popcnt"
146   (const_string "integer"))
147
148 ;; Define floating point instruction sub-types for use with Xfpu.md
149 (define_attr "fp_type" "fp_default,fp_addsub_s,fp_addsub_d,fp_mul_s,fp_mul_d,fp_div_s,fp_div_d,fp_maddsub_s,fp_maddsub_d,fp_sqrt_s,fp_sqrt_d" (const_string "fp_default"))
150
151 ;; Length (in bytes).
152 ; '(pc)' in the following doesn't include the instruction itself; it is
153 ; calculated as if the instruction had zero size.
154 (define_attr "length" ""
155   (if_then_else (eq_attr "type" "branch")
156                 (if_then_else (and (ge (minus (match_dup 0) (pc))
157                                        (const_int -32768))
158                                    (lt (minus (match_dup 0) (pc))
159                                        (const_int 32764)))
160                               (const_int 4)
161                               (const_int 8))
162                 (const_int 4)))
163
164 ;; Processor type -- this attribute must exactly match the processor_type
165 ;; enumeration in rs6000.h.
166
167 (define_attr "cpu" "rs64a,mpccore,ppc403,ppc405,ppc440,ppc476,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,ppc8548,ppce300c2,ppce300c3,ppce500mc,ppce500mc64,ppce5500,ppce6500,power4,power5,power6,power7,cell,ppca2,titan"
168   (const (symbol_ref "rs6000_cpu_attr")))
169
170
171 ;; If this instruction is microcoded on the CELL processor
172 ; The default for load extended, the recorded instructions and rotate/shifts by a variable is always microcoded
173 (define_attr "cell_micro" "not,conditional,always"
174   (if_then_else (eq_attr "type" "compare,delayed_compare,imul_compare,lmul_compare,load_ext,load_ext_ux,var_shift_rotate,var_delayed_compare")
175                 (const_string "always")
176                 (const_string "not")))
177
178 (automata_option "ndfa")
179
180 (include "rs64.md")
181 (include "mpc.md")
182 (include "40x.md")
183 (include "440.md")
184 (include "476.md")
185 (include "601.md")
186 (include "603.md")
187 (include "6xx.md")
188 (include "7xx.md")
189 (include "7450.md")
190 (include "8540.md")
191 (include "e300c2c3.md")
192 (include "e500mc.md")
193 (include "e500mc64.md")
194 (include "e5500.md")
195 (include "e6500.md")
196 (include "power4.md")
197 (include "power5.md")
198 (include "power6.md")
199 (include "power7.md")
200 (include "cell.md")
201 (include "xfpu.md")
202 (include "a2.md")
203 (include "titan.md")
204
205 (include "predicates.md")
206 (include "constraints.md")
207
208 (include "darwin.md")
209
210 \f
211 ;; Mode iterators
212
213 ; This mode iterator allows :GPR to be used to indicate the allowable size
214 ; of whole values in GPRs.
215 (define_mode_iterator GPR [SI (DI "TARGET_POWERPC64")])
216
217 ; Any supported integer mode.
218 (define_mode_iterator INT [QI HI SI DI TI])
219
220 ; Any supported integer mode that fits in one register.
221 (define_mode_iterator INT1 [QI HI SI (DI "TARGET_POWERPC64")])
222
223 ; extend modes for DImode
224 (define_mode_iterator QHSI [QI HI SI])
225
226 ; SImode or DImode, even if DImode doesn't fit in GPRs.
227 (define_mode_iterator SDI [SI DI])
228
229 ; The size of a pointer.  Also, the size of the value that a record-condition
230 ; (one with a '.') will compare; and the size used for arithmetic carries.
231 (define_mode_iterator P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
232
233 ; Any hardware-supported floating-point mode
234 (define_mode_iterator FP [
235   (SF "TARGET_HARD_FLOAT 
236    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) || TARGET_E500_SINGLE)")
237   (DF "TARGET_HARD_FLOAT 
238    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)")
239   (TF "!TARGET_IEEEQUAD
240    && TARGET_HARD_FLOAT
241    && (TARGET_FPRS || TARGET_E500_DOUBLE)
242    && TARGET_LONG_DOUBLE_128")
243   (DD "TARGET_DFP")
244   (TD "TARGET_DFP")])
245
246 ; Any fma capable floating-point mode.
247 (define_mode_iterator FMA_F [
248   (SF "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT")
249   (DF "(TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT)
250        || VECTOR_UNIT_VSX_P (DFmode)")
251   (V2SF "TARGET_PAIRED_FLOAT")
252   (V4SF "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)")
253   (V2DF "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DFmode)")
254   ])
255
256 ; These modes do not fit in integer registers in 32-bit mode.
257 ; but on e500v2, the gpr are 64 bit registers
258 (define_mode_iterator DIFD [DI (DF "!TARGET_E500_DOUBLE") DD])
259
260 ; Iterator for reciprocal estimate instructions
261 (define_mode_iterator RECIPF [SF DF V4SF V2DF])
262
263 ; Iterator for just SF/DF
264 (define_mode_iterator SFDF [SF DF])
265
266 ; Conditional returns.
267 (define_code_iterator any_return [return simple_return])
268 (define_code_attr return_pred [(return "direct_return ()")
269                                (simple_return "1")])
270 (define_code_attr return_str [(return "") (simple_return "simple_")])
271
272 ; Various instructions that come in SI and DI forms.
273 ; A generic w/d attribute, for things like cmpw/cmpd.
274 (define_mode_attr wd [(QI "b") (HI "h") (SI "w") (DI "d")])
275
276 ; DImode bits
277 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
278
279 ;; ISEL/ISEL64 target selection
280 (define_mode_attr sel [(SI "") (DI "64")])
281
282 ;; Suffix for reload patterns
283 (define_mode_attr ptrsize [(SI "32bit")
284                            (DI "64bit")])
285
286 (define_mode_attr tptrsize [(SI "TARGET_32BIT")
287                             (DI "TARGET_64BIT")])
288
289 (define_mode_attr mptrsize [(SI "si")
290                             (DI "di")])
291
292 (define_mode_attr ptrload [(SI "lwz")
293                            (DI "ld")])
294
295 (define_mode_attr ptrm [(SI "m")
296                         (DI "Y")])
297
298 (define_mode_attr rreg [(SF   "f")
299                         (DF   "ws")
300                         (V4SF "wf")
301                         (V2DF "wd")])
302
303 (define_mode_attr rreg2 [(SF   "f")
304                          (DF   "d")])
305
306 (define_mode_attr SI_CONVERT_FP [(SF "TARGET_FCFIDS")
307                                  (DF "TARGET_FCFID")])
308
309 (define_mode_attr E500_CONVERT [(SF "!TARGET_FPRS")
310                                 (DF "TARGET_E500_DOUBLE")])
311
312 (define_mode_attr TARGET_FLOAT [(SF "TARGET_SINGLE_FLOAT")
313                                 (DF "TARGET_DOUBLE_FLOAT")])
314 \f
315 ;; Start with fixed-point load and store insns.  Here we put only the more
316 ;; complex forms.  Basic data transfer is done later.
317
318 (define_expand "zero_extend<mode>di2"
319   [(set (match_operand:DI 0 "gpc_reg_operand" "")
320         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
321   "TARGET_POWERPC64"
322   "")
323
324 (define_insn "*zero_extend<mode>di2_internal1"
325   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
326         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
327   "TARGET_POWERPC64"
328   "@
329    l<wd>z%U1%X1 %0,%1
330    rldicl %0,%1,0,<dbits>"
331   [(set_attr "type" "load,*")])
332
333 (define_insn "*zero_extend<mode>di2_internal2"
334   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
335         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
336                     (const_int 0)))
337    (clobber (match_scratch:DI 2 "=r,r"))]
338   "TARGET_64BIT"
339   "@
340    rldicl. %2,%1,0,<dbits>
341    #"
342   [(set_attr "type" "compare")
343    (set_attr "length" "4,8")])
344
345 (define_split
346   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
347         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
348                     (const_int 0)))
349    (clobber (match_scratch:DI 2 ""))]
350   "TARGET_POWERPC64 && reload_completed"
351   [(set (match_dup 2)
352         (zero_extend:DI (match_dup 1)))
353    (set (match_dup 0)
354         (compare:CC (match_dup 2)
355                     (const_int 0)))]
356   "")
357
358 (define_insn "*zero_extend<mode>di2_internal3"
359   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
360         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
361                     (const_int 0)))
362    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
363         (zero_extend:DI (match_dup 1)))]
364   "TARGET_64BIT"
365   "@
366    rldicl. %0,%1,0,<dbits>
367    #"
368   [(set_attr "type" "compare")
369    (set_attr "length" "4,8")])
370
371 (define_split
372   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
373         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
374                     (const_int 0)))
375    (set (match_operand:DI 0 "gpc_reg_operand" "")
376         (zero_extend:DI (match_dup 1)))]
377   "TARGET_POWERPC64 && reload_completed"
378   [(set (match_dup 0)
379         (zero_extend:DI (match_dup 1)))
380    (set (match_dup 2)
381         (compare:CC (match_dup 0)
382                     (const_int 0)))]
383   "")
384
385 (define_insn "extendqidi2"
386   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
387         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
388   "TARGET_POWERPC64"
389   "extsb %0,%1"
390   [(set_attr "type" "exts")])
391
392 (define_insn ""
393   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
394         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
395                     (const_int 0)))
396    (clobber (match_scratch:DI 2 "=r,r"))]
397   "TARGET_64BIT"
398   "@
399    extsb. %2,%1
400    #"
401   [(set_attr "type" "compare")
402    (set_attr "length" "4,8")])
403
404 (define_split
405   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
406         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
407                     (const_int 0)))
408    (clobber (match_scratch:DI 2 ""))]
409   "TARGET_POWERPC64 && reload_completed"
410   [(set (match_dup 2)
411         (sign_extend:DI (match_dup 1)))
412    (set (match_dup 0)
413         (compare:CC (match_dup 2)
414                     (const_int 0)))]
415   "")
416
417 (define_insn ""
418   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
419         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
420                     (const_int 0)))
421    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
422         (sign_extend:DI (match_dup 1)))]
423   "TARGET_64BIT"
424   "@
425    extsb. %0,%1
426    #"
427   [(set_attr "type" "compare")
428    (set_attr "length" "4,8")])
429
430 (define_split
431   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
432         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
433                     (const_int 0)))
434    (set (match_operand:DI 0 "gpc_reg_operand" "")
435         (sign_extend:DI (match_dup 1)))]
436   "TARGET_POWERPC64 && reload_completed"
437   [(set (match_dup 0)
438         (sign_extend:DI (match_dup 1)))
439    (set (match_dup 2)
440         (compare:CC (match_dup 0)
441                     (const_int 0)))]
442   "")
443
444 (define_expand "extendhidi2"
445   [(set (match_operand:DI 0 "gpc_reg_operand" "")
446         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
447   "TARGET_POWERPC64"
448   "")
449
450 (define_insn ""
451   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
452         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
453   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
454   "@
455    lha%U1%X1 %0,%1
456    extsh %0,%1"
457   [(set_attr "type" "load_ext,exts")])
458
459 (define_insn ""
460   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
461         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r")))]
462   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
463   "extsh %0,%1"
464   [(set_attr "type" "exts")])
465
466 (define_insn ""
467   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
468         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
469                     (const_int 0)))
470    (clobber (match_scratch:DI 2 "=r,r"))]
471   "TARGET_64BIT"
472   "@
473    extsh. %2,%1
474    #"
475   [(set_attr "type" "compare")
476    (set_attr "length" "4,8")])
477
478 (define_split
479   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
480         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
481                     (const_int 0)))
482    (clobber (match_scratch:DI 2 ""))]
483   "TARGET_POWERPC64 && reload_completed"
484   [(set (match_dup 2)
485         (sign_extend:DI (match_dup 1)))
486    (set (match_dup 0)
487         (compare:CC (match_dup 2)
488                     (const_int 0)))]
489   "")
490
491 (define_insn ""
492   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
493         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
494                     (const_int 0)))
495    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
496         (sign_extend:DI (match_dup 1)))]
497   "TARGET_64BIT"
498   "@
499    extsh. %0,%1
500    #"
501   [(set_attr "type" "compare")
502    (set_attr "length" "4,8")])
503
504 (define_split
505   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
506         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
507                     (const_int 0)))
508    (set (match_operand:DI 0 "gpc_reg_operand" "")
509         (sign_extend:DI (match_dup 1)))]
510   "TARGET_POWERPC64 && reload_completed"
511   [(set (match_dup 0)
512         (sign_extend:DI (match_dup 1)))
513    (set (match_dup 2)
514         (compare:CC (match_dup 0)
515                     (const_int 0)))]
516   "")
517
518 (define_expand "extendsidi2"
519   [(set (match_operand:DI 0 "gpc_reg_operand" "")
520         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
521   "TARGET_POWERPC64"
522   "")
523
524 (define_insn ""
525   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
526         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
527   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
528   "@
529    lwa%U1%X1 %0,%1
530    extsw %0,%1"
531   [(set_attr "type" "load_ext,exts")])
532
533 (define_insn ""
534   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
535         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r")))]
536   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
537   "extsw %0,%1"
538   [(set_attr "type" "exts")])
539
540 (define_insn ""
541   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
542         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
543                     (const_int 0)))
544    (clobber (match_scratch:DI 2 "=r,r"))]
545   "TARGET_64BIT"
546   "@
547    extsw. %2,%1
548    #"
549   [(set_attr "type" "compare")
550    (set_attr "length" "4,8")])
551
552 (define_split
553   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
554         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
555                     (const_int 0)))
556    (clobber (match_scratch:DI 2 ""))]
557   "TARGET_POWERPC64 && reload_completed"
558   [(set (match_dup 2)
559         (sign_extend:DI (match_dup 1)))
560    (set (match_dup 0)
561         (compare:CC (match_dup 2)
562                     (const_int 0)))]
563   "")
564
565 (define_insn ""
566   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
567         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
568                     (const_int 0)))
569    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
570         (sign_extend:DI (match_dup 1)))]
571   "TARGET_64BIT"
572   "@
573    extsw. %0,%1
574    #"
575   [(set_attr "type" "compare")
576    (set_attr "length" "4,8")])
577
578 (define_split
579   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
580         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
581                     (const_int 0)))
582    (set (match_operand:DI 0 "gpc_reg_operand" "")
583         (sign_extend:DI (match_dup 1)))]
584   "TARGET_POWERPC64 && reload_completed"
585   [(set (match_dup 0)
586         (sign_extend:DI (match_dup 1)))
587    (set (match_dup 2)
588         (compare:CC (match_dup 0)
589                     (const_int 0)))]
590   "")
591
592 (define_expand "zero_extendqisi2"
593   [(set (match_operand:SI 0 "gpc_reg_operand" "")
594         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
595   ""
596   "")
597
598 (define_insn ""
599   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
600         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
601   ""
602   "@
603    lbz%U1%X1 %0,%1
604    rlwinm %0,%1,0,0xff"
605   [(set_attr "type" "load,*")])
606
607 (define_insn ""
608   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
609         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
610                     (const_int 0)))
611    (clobber (match_scratch:SI 2 "=r,r"))]
612   ""
613   "@
614    andi. %2,%1,0xff
615    #"
616   [(set_attr "type" "fast_compare,compare")
617    (set_attr "length" "4,8")])
618
619 (define_split
620   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
621         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
622                     (const_int 0)))
623    (clobber (match_scratch:SI 2 ""))]
624   "reload_completed"
625   [(set (match_dup 2)
626         (zero_extend:SI (match_dup 1)))
627    (set (match_dup 0)
628         (compare:CC (match_dup 2)
629                     (const_int 0)))]
630   "")
631
632 (define_insn ""
633   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
634         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
635                     (const_int 0)))
636    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
637         (zero_extend:SI (match_dup 1)))]
638   ""
639   "@
640    andi. %0,%1,0xff
641    #"
642   [(set_attr "type" "fast_compare,compare")
643    (set_attr "length" "4,8")])
644
645 (define_split
646   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
647         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
648                     (const_int 0)))
649    (set (match_operand:SI 0 "gpc_reg_operand" "")
650         (zero_extend:SI (match_dup 1)))]
651   "reload_completed"
652   [(set (match_dup 0)
653         (zero_extend:SI (match_dup 1)))
654    (set (match_dup 2)
655         (compare:CC (match_dup 0)
656                     (const_int 0)))]
657   "")
658
659 (define_insn "extendqisi2"
660   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
661         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
662   ""
663   "extsb %0,%1"
664   [(set_attr "type" "exts")])
665
666 (define_insn ""
667   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
668         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
669                     (const_int 0)))
670    (clobber (match_scratch:SI 2 "=r,r"))]
671   ""
672   "@
673    extsb. %2,%1
674    #"
675   [(set_attr "type" "compare")
676    (set_attr "length" "4,8")])
677
678 (define_split
679   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
680         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
681                     (const_int 0)))
682    (clobber (match_scratch:SI 2 ""))]
683   "reload_completed"
684   [(set (match_dup 2)
685         (sign_extend:SI (match_dup 1)))
686    (set (match_dup 0)
687         (compare:CC (match_dup 2)
688                     (const_int 0)))]
689   "")
690
691 (define_insn ""
692   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
693         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
694                     (const_int 0)))
695    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
696         (sign_extend:SI (match_dup 1)))]
697   ""
698   "@
699    extsb. %0,%1
700    #"
701   [(set_attr "type" "compare")
702    (set_attr "length" "4,8")])
703
704 (define_split
705   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
706         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
707                     (const_int 0)))
708    (set (match_operand:SI 0 "gpc_reg_operand" "")
709         (sign_extend:SI (match_dup 1)))]
710   "reload_completed"
711   [(set (match_dup 0)
712         (sign_extend:SI (match_dup 1)))
713    (set (match_dup 2)
714         (compare:CC (match_dup 0)
715                     (const_int 0)))]
716   "")
717
718 (define_insn ""
719   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
720         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
721   ""
722   "@
723    lbz%U1%X1 %0,%1
724    rlwinm %0,%1,0,0xff"
725   [(set_attr "type" "load,*")])
726
727 (define_insn ""
728   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
729         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
730                     (const_int 0)))
731    (clobber (match_scratch:HI 2 "=r,r"))]
732   ""
733   "@
734    andi. %2,%1,0xff
735    #"
736   [(set_attr "type" "fast_compare,compare")
737    (set_attr "length" "4,8")])
738
739 (define_split
740   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
741         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
742                     (const_int 0)))
743    (clobber (match_scratch:HI 2 ""))]
744   "reload_completed"
745   [(set (match_dup 2)
746         (zero_extend:HI (match_dup 1)))
747    (set (match_dup 0)
748         (compare:CC (match_dup 2)
749                     (const_int 0)))]
750   "")
751
752 (define_insn ""
753   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
754         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
755                     (const_int 0)))
756    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
757         (zero_extend:HI (match_dup 1)))]
758   ""
759   "@
760    andi. %0,%1,0xff
761    #"
762   [(set_attr "type" "fast_compare,compare")
763    (set_attr "length" "4,8")])
764
765 (define_split
766   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
767         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
768                     (const_int 0)))
769    (set (match_operand:HI 0 "gpc_reg_operand" "")
770         (zero_extend:HI (match_dup 1)))]
771   "reload_completed"
772   [(set (match_dup 0)
773         (zero_extend:HI (match_dup 1)))
774    (set (match_dup 2)
775         (compare:CC (match_dup 0)
776                     (const_int 0)))]
777   "")
778
779 (define_insn "extendqihi2"
780   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
781         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
782   ""
783   "extsb %0,%1"
784   [(set_attr "type" "exts")])
785
786 (define_insn ""
787   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
788         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
789                     (const_int 0)))
790    (clobber (match_scratch:HI 2 "=r,r"))]
791   ""
792   "@
793    extsb. %2,%1
794    #"
795   [(set_attr "type" "compare")
796    (set_attr "length" "4,8")])
797
798 (define_split
799   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
800         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
801                     (const_int 0)))
802    (clobber (match_scratch:HI 2 ""))]
803   "reload_completed"
804   [(set (match_dup 2)
805         (sign_extend:HI (match_dup 1)))
806    (set (match_dup 0)
807         (compare:CC (match_dup 2)
808                     (const_int 0)))]
809   "")
810
811 (define_insn ""
812   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
813         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
814                     (const_int 0)))
815    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
816         (sign_extend:HI (match_dup 1)))]
817   ""
818   "@
819    extsb. %0,%1
820    #"
821   [(set_attr "type" "compare")
822    (set_attr "length" "4,8")])
823
824 (define_split
825   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
826         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
827                     (const_int 0)))
828    (set (match_operand:HI 0 "gpc_reg_operand" "")
829         (sign_extend:HI (match_dup 1)))]
830   "reload_completed"
831   [(set (match_dup 0)
832         (sign_extend:HI (match_dup 1)))
833    (set (match_dup 2)
834         (compare:CC (match_dup 0)
835                     (const_int 0)))]
836   "")
837
838 (define_expand "zero_extendhisi2"
839   [(set (match_operand:SI 0 "gpc_reg_operand" "")
840         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
841   ""
842   "")
843
844 (define_insn ""
845   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
846         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
847   ""
848   "@
849    lhz%U1%X1 %0,%1
850    rlwinm %0,%1,0,0xffff"
851   [(set_attr "type" "load,*")])
852
853 (define_insn ""
854   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
855         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
856                     (const_int 0)))
857    (clobber (match_scratch:SI 2 "=r,r"))]
858   ""
859   "@
860    andi. %2,%1,0xffff
861    #"
862   [(set_attr "type" "fast_compare,compare")
863    (set_attr "length" "4,8")])
864
865 (define_split
866   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
867         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
868                     (const_int 0)))
869    (clobber (match_scratch:SI 2 ""))]
870   "reload_completed"
871   [(set (match_dup 2)
872         (zero_extend:SI (match_dup 1)))
873    (set (match_dup 0)
874         (compare:CC (match_dup 2)
875                     (const_int 0)))]
876   "")
877
878 (define_insn ""
879   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
880         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
881                     (const_int 0)))
882    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
883         (zero_extend:SI (match_dup 1)))]
884   ""
885   "@
886    andi. %0,%1,0xffff
887    #"
888   [(set_attr "type" "fast_compare,compare")
889    (set_attr "length" "4,8")])
890
891 (define_split
892   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
893         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
894                     (const_int 0)))
895    (set (match_operand:SI 0 "gpc_reg_operand" "")
896         (zero_extend:SI (match_dup 1)))]
897   "reload_completed"
898   [(set (match_dup 0)
899         (zero_extend:SI (match_dup 1)))
900    (set (match_dup 2)
901         (compare:CC (match_dup 0)
902                     (const_int 0)))]
903   "")
904
905 (define_expand "extendhisi2"
906   [(set (match_operand:SI 0 "gpc_reg_operand" "")
907         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
908   ""
909   "")
910
911 (define_insn ""
912   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
913         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
914   "rs6000_gen_cell_microcode"
915   "@
916    lha%U1%X1 %0,%1
917    extsh %0,%1"
918   [(set_attr "type" "load_ext,exts")])
919
920 (define_insn ""
921   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
922         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r")))]
923   "!rs6000_gen_cell_microcode"
924   "extsh %0,%1"
925   [(set_attr "type" "exts")])
926
927 (define_insn ""
928   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
929         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
930                     (const_int 0)))
931    (clobber (match_scratch:SI 2 "=r,r"))]
932   ""
933   "@
934    extsh. %2,%1
935    #"
936   [(set_attr "type" "compare")
937    (set_attr "length" "4,8")])
938
939 (define_split
940   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
941         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
942                     (const_int 0)))
943    (clobber (match_scratch:SI 2 ""))]
944   "reload_completed"
945   [(set (match_dup 2)
946         (sign_extend:SI (match_dup 1)))
947    (set (match_dup 0)
948         (compare:CC (match_dup 2)
949                     (const_int 0)))]
950   "")
951
952 (define_insn ""
953   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
954         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
955                     (const_int 0)))
956    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
957         (sign_extend:SI (match_dup 1)))]
958   ""
959   "@
960    extsh. %0,%1
961    #"
962   [(set_attr "type" "compare")
963    (set_attr "length" "4,8")])
964
965 (define_split
966   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
967         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
968                     (const_int 0)))
969    (set (match_operand:SI 0 "gpc_reg_operand" "")
970         (sign_extend:SI (match_dup 1)))]
971   "reload_completed"
972   [(set (match_dup 0)
973         (sign_extend:SI (match_dup 1)))
974    (set (match_dup 2)
975         (compare:CC (match_dup 0)
976                     (const_int 0)))]
977   "")
978 \f
979 ;; IBM 405, 440, 464 and 476 half-word multiplication operations.
980
981 (define_insn "*macchwc"
982   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
983         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
984                                        (match_operand:SI 2 "gpc_reg_operand" "r")
985                                        (const_int 16))
986                                       (sign_extend:SI
987                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
988                              (match_operand:SI 4 "gpc_reg_operand" "0"))
989                     (const_int 0)))
990    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
991         (plus:SI (mult:SI (ashiftrt:SI
992                            (match_dup 2)
993                            (const_int 16))
994                           (sign_extend:SI
995                            (match_dup 1)))
996                  (match_dup 4)))]
997   "TARGET_MULHW"
998   "macchw. %0,%1,%2"
999   [(set_attr "type" "imul3")])
1000
1001 (define_insn "*macchw"
1002   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1003         (plus:SI (mult:SI (ashiftrt:SI
1004                            (match_operand:SI 2 "gpc_reg_operand" "r")
1005                            (const_int 16))
1006                           (sign_extend:SI
1007                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1008                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1009   "TARGET_MULHW"
1010   "macchw %0,%1,%2"
1011   [(set_attr "type" "imul3")])
1012
1013 (define_insn "*macchwuc"
1014   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1015         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1016                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1017                                        (const_int 16))
1018                                       (zero_extend:SI
1019                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
1020                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1021                     (const_int 0)))
1022    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1023         (plus:SI (mult:SI (lshiftrt:SI
1024                            (match_dup 2)
1025                            (const_int 16))
1026                           (zero_extend:SI
1027                            (match_dup 1)))
1028                  (match_dup 4)))]
1029   "TARGET_MULHW"
1030   "macchwu. %0,%1,%2"
1031   [(set_attr "type" "imul3")])
1032
1033 (define_insn "*macchwu"
1034   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1035         (plus:SI (mult:SI (lshiftrt:SI
1036                            (match_operand:SI 2 "gpc_reg_operand" "r")
1037                            (const_int 16))
1038                           (zero_extend:SI
1039                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1040                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1041   "TARGET_MULHW"
1042   "macchwu %0,%1,%2"
1043   [(set_attr "type" "imul3")])
1044
1045 (define_insn "*machhwc"
1046   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1047         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1048                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1049                                        (const_int 16))
1050                                       (ashiftrt:SI
1051                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1052                                        (const_int 16)))
1053                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1054                     (const_int 0)))
1055    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1056         (plus:SI (mult:SI (ashiftrt:SI
1057                            (match_dup 1)
1058                            (const_int 16))
1059                           (ashiftrt:SI
1060                            (match_dup 2)
1061                            (const_int 16)))
1062                  (match_dup 4)))]
1063   "TARGET_MULHW"
1064   "machhw. %0,%1,%2"
1065   [(set_attr "type" "imul3")])
1066
1067 (define_insn "*machhw"
1068   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1069         (plus:SI (mult:SI (ashiftrt:SI
1070                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1071                            (const_int 16))
1072                           (ashiftrt:SI
1073                            (match_operand:SI 2 "gpc_reg_operand" "r")
1074                            (const_int 16)))
1075                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1076   "TARGET_MULHW"
1077   "machhw %0,%1,%2"
1078   [(set_attr "type" "imul3")])
1079
1080 (define_insn "*machhwuc"
1081   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1082         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1083                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1084                                        (const_int 16))
1085                                       (lshiftrt:SI
1086                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1087                                        (const_int 16)))
1088                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1089                     (const_int 0)))
1090    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1091         (plus:SI (mult:SI (lshiftrt:SI
1092                            (match_dup 1)
1093                            (const_int 16))
1094                           (lshiftrt:SI
1095                            (match_dup 2)
1096                            (const_int 16)))
1097                  (match_dup 4)))]
1098   "TARGET_MULHW"
1099   "machhwu. %0,%1,%2"
1100   [(set_attr "type" "imul3")])
1101
1102 (define_insn "*machhwu"
1103   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1104         (plus:SI (mult:SI (lshiftrt:SI
1105                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1106                            (const_int 16))
1107                           (lshiftrt:SI
1108                            (match_operand:SI 2 "gpc_reg_operand" "r")
1109                            (const_int 16)))
1110                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1111   "TARGET_MULHW"
1112   "machhwu %0,%1,%2"
1113   [(set_attr "type" "imul3")])
1114
1115 (define_insn "*maclhwc"
1116   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1117         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1118                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1119                                       (sign_extend:SI
1120                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1121                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1122                     (const_int 0)))
1123    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1124         (plus:SI (mult:SI (sign_extend:SI
1125                            (match_dup 1))
1126                           (sign_extend:SI
1127                            (match_dup 2)))
1128                  (match_dup 4)))]
1129   "TARGET_MULHW"
1130   "maclhw. %0,%1,%2"
1131   [(set_attr "type" "imul3")])
1132
1133 (define_insn "*maclhw"
1134   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1135         (plus:SI (mult:SI (sign_extend:SI
1136                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1137                           (sign_extend:SI
1138                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1139                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1140   "TARGET_MULHW"
1141   "maclhw %0,%1,%2"
1142   [(set_attr "type" "imul3")])
1143
1144 (define_insn "*maclhwuc"
1145   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1146         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1147                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1148                                       (zero_extend:SI
1149                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1150                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1151                     (const_int 0)))
1152    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1153         (plus:SI (mult:SI (zero_extend:SI
1154                            (match_dup 1))
1155                           (zero_extend:SI
1156                            (match_dup 2)))
1157                  (match_dup 4)))]
1158   "TARGET_MULHW"
1159   "maclhwu. %0,%1,%2"
1160   [(set_attr "type" "imul3")])
1161
1162 (define_insn "*maclhwu"
1163   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1164         (plus:SI (mult:SI (zero_extend:SI
1165                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1166                           (zero_extend:SI
1167                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1168                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1169   "TARGET_MULHW"
1170   "maclhwu %0,%1,%2"
1171   [(set_attr "type" "imul3")])
1172
1173 (define_insn "*nmacchwc"
1174   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1175         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1176                               (mult:SI (ashiftrt:SI
1177                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1178                                         (const_int 16))
1179                                        (sign_extend:SI
1180                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1181                     (const_int 0)))
1182    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1183         (minus:SI (match_dup 4)
1184                   (mult:SI (ashiftrt:SI
1185                             (match_dup 2)
1186                             (const_int 16))
1187                            (sign_extend:SI
1188                             (match_dup 1)))))]
1189   "TARGET_MULHW"
1190   "nmacchw. %0,%1,%2"
1191   [(set_attr "type" "imul3")])
1192
1193 (define_insn "*nmacchw"
1194   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1195         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1196                   (mult:SI (ashiftrt:SI
1197                             (match_operand:SI 2 "gpc_reg_operand" "r")
1198                             (const_int 16))
1199                            (sign_extend:SI
1200                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1201   "TARGET_MULHW"
1202   "nmacchw %0,%1,%2"
1203   [(set_attr "type" "imul3")])
1204
1205 (define_insn "*nmachhwc"
1206   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1207         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1208                               (mult:SI (ashiftrt:SI
1209                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1210                                         (const_int 16))
1211                                        (ashiftrt:SI
1212                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1213                                         (const_int 16))))
1214                     (const_int 0)))
1215    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1216         (minus:SI (match_dup 4)
1217                   (mult:SI (ashiftrt:SI
1218                             (match_dup 1)
1219                             (const_int 16))
1220                            (ashiftrt:SI
1221                             (match_dup 2)
1222                             (const_int 16)))))]
1223   "TARGET_MULHW"
1224   "nmachhw. %0,%1,%2"
1225   [(set_attr "type" "imul3")])
1226
1227 (define_insn "*nmachhw"
1228   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1229         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1230                   (mult:SI (ashiftrt:SI
1231                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1232                             (const_int 16))
1233                            (ashiftrt:SI
1234                             (match_operand:SI 2 "gpc_reg_operand" "r")
1235                             (const_int 16)))))]
1236   "TARGET_MULHW"
1237   "nmachhw %0,%1,%2"
1238   [(set_attr "type" "imul3")])
1239
1240 (define_insn "*nmaclhwc"
1241   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1242         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1243                               (mult:SI (sign_extend:SI
1244                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1245                                        (sign_extend:SI
1246                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1247                     (const_int 0)))
1248    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1249         (minus:SI (match_dup 4)
1250                   (mult:SI (sign_extend:SI
1251                             (match_dup 1))
1252                            (sign_extend:SI
1253                             (match_dup 2)))))]
1254   "TARGET_MULHW"
1255   "nmaclhw. %0,%1,%2"
1256   [(set_attr "type" "imul3")])
1257
1258 (define_insn "*nmaclhw"
1259   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1260         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1261                   (mult:SI (sign_extend:SI
1262                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1263                            (sign_extend:SI
1264                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1265   "TARGET_MULHW"
1266   "nmaclhw %0,%1,%2"
1267   [(set_attr "type" "imul3")])
1268
1269 (define_insn "*mulchwc"
1270   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1271         (compare:CC (mult:SI (ashiftrt:SI
1272                               (match_operand:SI 2 "gpc_reg_operand" "r")
1273                               (const_int 16))
1274                              (sign_extend:SI
1275                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1276                     (const_int 0)))
1277    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1278         (mult:SI (ashiftrt:SI
1279                   (match_dup 2)
1280                   (const_int 16))
1281                  (sign_extend:SI
1282                   (match_dup 1))))]
1283   "TARGET_MULHW"
1284   "mulchw. %0,%1,%2"
1285   [(set_attr "type" "imul3")])
1286
1287 (define_insn "*mulchw"
1288   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1289         (mult:SI (ashiftrt:SI
1290                   (match_operand:SI 2 "gpc_reg_operand" "r")
1291                   (const_int 16))
1292                  (sign_extend:SI
1293                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1294   "TARGET_MULHW"
1295   "mulchw %0,%1,%2"
1296   [(set_attr "type" "imul3")])
1297
1298 (define_insn "*mulchwuc"
1299   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1300         (compare:CC (mult:SI (lshiftrt:SI
1301                               (match_operand:SI 2 "gpc_reg_operand" "r")
1302                               (const_int 16))
1303                              (zero_extend:SI
1304                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1305                     (const_int 0)))
1306    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1307         (mult:SI (lshiftrt:SI
1308                   (match_dup 2)
1309                   (const_int 16))
1310                  (zero_extend:SI
1311                   (match_dup 1))))]
1312   "TARGET_MULHW"
1313   "mulchwu. %0,%1,%2"
1314   [(set_attr "type" "imul3")])
1315
1316 (define_insn "*mulchwu"
1317   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1318         (mult:SI (lshiftrt:SI
1319                   (match_operand:SI 2 "gpc_reg_operand" "r")
1320                   (const_int 16))
1321                  (zero_extend:SI
1322                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1323   "TARGET_MULHW"
1324   "mulchwu %0,%1,%2"
1325   [(set_attr "type" "imul3")])
1326
1327 (define_insn "*mulhhwc"
1328   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1329         (compare:CC (mult:SI (ashiftrt:SI
1330                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1331                               (const_int 16))
1332                              (ashiftrt:SI
1333                               (match_operand:SI 2 "gpc_reg_operand" "r")
1334                               (const_int 16)))
1335                     (const_int 0)))
1336    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1337         (mult:SI (ashiftrt:SI
1338                   (match_dup 1)
1339                   (const_int 16))
1340                  (ashiftrt:SI
1341                   (match_dup 2)
1342                   (const_int 16))))]
1343   "TARGET_MULHW"
1344   "mulhhw. %0,%1,%2"
1345   [(set_attr "type" "imul3")])
1346
1347 (define_insn "*mulhhw"
1348   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1349         (mult:SI (ashiftrt:SI
1350                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1351                   (const_int 16))
1352                  (ashiftrt:SI
1353                   (match_operand:SI 2 "gpc_reg_operand" "r")
1354                   (const_int 16))))]
1355   "TARGET_MULHW"
1356   "mulhhw %0,%1,%2"
1357   [(set_attr "type" "imul3")])
1358
1359 (define_insn "*mulhhwuc"
1360   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1361         (compare:CC (mult:SI (lshiftrt:SI
1362                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1363                               (const_int 16))
1364                              (lshiftrt:SI
1365                               (match_operand:SI 2 "gpc_reg_operand" "r")
1366                               (const_int 16)))
1367                     (const_int 0)))
1368    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1369         (mult:SI (lshiftrt:SI
1370                   (match_dup 1)
1371                   (const_int 16))
1372                  (lshiftrt:SI
1373                   (match_dup 2)
1374                   (const_int 16))))]
1375   "TARGET_MULHW"
1376   "mulhhwu. %0,%1,%2"
1377   [(set_attr "type" "imul3")])
1378
1379 (define_insn "*mulhhwu"
1380   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1381         (mult:SI (lshiftrt:SI
1382                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1383                   (const_int 16))
1384                  (lshiftrt:SI
1385                   (match_operand:SI 2 "gpc_reg_operand" "r")
1386                   (const_int 16))))]
1387   "TARGET_MULHW"
1388   "mulhhwu %0,%1,%2"
1389   [(set_attr "type" "imul3")])
1390
1391 (define_insn "*mullhwc"
1392   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1393         (compare:CC (mult:SI (sign_extend:SI
1394                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1395                              (sign_extend:SI
1396                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1397                     (const_int 0)))
1398    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1399         (mult:SI (sign_extend:SI
1400                   (match_dup 1))
1401                  (sign_extend:SI
1402                   (match_dup 2))))]
1403   "TARGET_MULHW"
1404   "mullhw. %0,%1,%2"
1405   [(set_attr "type" "imul3")])
1406
1407 (define_insn "*mullhw"
1408   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1409         (mult:SI (sign_extend:SI
1410                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1411                  (sign_extend:SI
1412                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1413   "TARGET_MULHW"
1414   "mullhw %0,%1,%2"
1415   [(set_attr "type" "imul3")])
1416
1417 (define_insn "*mullhwuc"
1418   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1419         (compare:CC (mult:SI (zero_extend:SI
1420                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1421                              (zero_extend:SI
1422                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1423                     (const_int 0)))
1424    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1425         (mult:SI (zero_extend:SI
1426                   (match_dup 1))
1427                  (zero_extend:SI
1428                   (match_dup 2))))]
1429   "TARGET_MULHW"
1430   "mullhwu. %0,%1,%2"
1431   [(set_attr "type" "imul3")])
1432
1433 (define_insn "*mullhwu"
1434   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1435         (mult:SI (zero_extend:SI
1436                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1437                  (zero_extend:SI
1438                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1439   "TARGET_MULHW"
1440   "mullhwu %0,%1,%2"
1441   [(set_attr "type" "imul3")])
1442 \f
1443 ;; IBM 405, 440, 464 and 476 string-search dlmzb instruction support.
1444 (define_insn "dlmzb"
1445   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1446         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1447                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1448                    UNSPEC_DLMZB_CR))
1449    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1450         (unspec:SI [(match_dup 1)
1451                     (match_dup 2)]
1452                    UNSPEC_DLMZB))]
1453   "TARGET_DLMZB"
1454   "dlmzb. %0,%1,%2")
1455
1456 (define_expand "strlensi"
1457   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1458         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1459                     (match_operand:QI 2 "const_int_operand" "")
1460                     (match_operand 3 "const_int_operand" "")]
1461                    UNSPEC_DLMZB_STRLEN))
1462    (clobber (match_scratch:CC 4 "=x"))]
1463   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1464 {
1465   rtx result = operands[0];
1466   rtx src = operands[1];
1467   rtx search_char = operands[2];
1468   rtx align = operands[3];
1469   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1470   rtx loop_label, end_label, mem, cr0, cond;
1471   if (search_char != const0_rtx
1472       || GET_CODE (align) != CONST_INT
1473       || INTVAL (align) < 8)
1474         FAIL;
1475   word1 = gen_reg_rtx (SImode);
1476   word2 = gen_reg_rtx (SImode);
1477   scratch_dlmzb = gen_reg_rtx (SImode);
1478   scratch_string = gen_reg_rtx (Pmode);
1479   loop_label = gen_label_rtx ();
1480   end_label = gen_label_rtx ();
1481   addr = force_reg (Pmode, XEXP (src, 0));
1482   emit_move_insn (scratch_string, addr);
1483   emit_label (loop_label);
1484   mem = change_address (src, SImode, scratch_string);
1485   emit_move_insn (word1, mem);
1486   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1487   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1488   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1489   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1490   emit_jump_insn (gen_rtx_SET (VOIDmode,
1491                                pc_rtx,
1492                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1493                                                      cond,
1494                                                      gen_rtx_LABEL_REF
1495                                                        (VOIDmode,
1496                                                         end_label),
1497                                                      pc_rtx)));
1498   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1499   emit_jump_insn (gen_rtx_SET (VOIDmode,
1500                                pc_rtx,
1501                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1502   emit_barrier ();
1503   emit_label (end_label);
1504   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1505   emit_insn (gen_subsi3 (result, scratch_string, addr));
1506   emit_insn (gen_subsi3 (result, result, const1_rtx));
1507   DONE;
1508 })
1509 \f
1510 ;; Fixed-point arithmetic insns.
1511
1512 (define_expand "add<mode>3"
1513   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1514         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1515                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1516   ""
1517 {
1518   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1519     {
1520       if (non_short_cint_operand (operands[2], DImode))
1521         FAIL;
1522     }
1523   else if (GET_CODE (operands[2]) == CONST_INT
1524            && ! add_operand (operands[2], <MODE>mode))
1525     {
1526       rtx tmp = ((!can_create_pseudo_p ()
1527                   || rtx_equal_p (operands[0], operands[1]))
1528                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1529
1530       HOST_WIDE_INT val = INTVAL (operands[2]);
1531       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1532       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1533
1534       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1535         FAIL;
1536
1537       /* The ordering here is important for the prolog expander.
1538          When space is allocated from the stack, adding 'low' first may
1539          produce a temporary deallocation (which would be bad).  */
1540       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1541       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1542       DONE;
1543     }
1544 })
1545
1546 ;; Discourage ai/addic because of carry but provide it in an alternative
1547 ;; allowing register zero as source.
1548 (define_insn "*add<mode>3_internal1"
1549   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1550         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1551                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1552   "!DECIMAL_FLOAT_MODE_P (GET_MODE (operands[0])) && !DECIMAL_FLOAT_MODE_P (GET_MODE (operands[1]))"
1553   "@
1554    add %0,%1,%2
1555    addi %0,%1,%2
1556    addic %0,%1,%2
1557    addis %0,%1,%v2"
1558   [(set_attr "length" "4,4,4,4")])
1559
1560 (define_insn "addsi3_high"
1561   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1562         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1563                  (high:SI (match_operand 2 "" ""))))]
1564   "TARGET_MACHO && !TARGET_64BIT"
1565   "addis %0,%1,ha16(%2)"
1566   [(set_attr "length" "4")])
1567
1568 (define_insn "*add<mode>3_internal2"
1569   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1570         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1571                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1572                     (const_int 0)))
1573    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1574   ""
1575   "@
1576    add. %3,%1,%2
1577    addic. %3,%1,%2
1578    #
1579    #"
1580   [(set_attr "type" "fast_compare,compare,compare,compare")
1581    (set_attr "length" "4,4,8,8")])
1582
1583 (define_split
1584   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1585         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1586                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1587                     (const_int 0)))
1588    (clobber (match_scratch:GPR 3 ""))]
1589   "reload_completed"
1590   [(set (match_dup 3)
1591         (plus:GPR (match_dup 1)
1592                  (match_dup 2)))
1593    (set (match_dup 0)
1594         (compare:CC (match_dup 3)
1595                     (const_int 0)))]
1596   "")
1597
1598 (define_insn "*add<mode>3_internal3"
1599   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1600         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1601                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1602                     (const_int 0)))
1603    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1604         (plus:P (match_dup 1)
1605                 (match_dup 2)))]
1606   ""
1607   "@
1608    add. %0,%1,%2
1609    addic. %0,%1,%2
1610    #
1611    #"
1612   [(set_attr "type" "fast_compare,compare,compare,compare")
1613    (set_attr "length" "4,4,8,8")])
1614
1615 (define_split
1616   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1617         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1618                             (match_operand:P 2 "reg_or_short_operand" ""))
1619                     (const_int 0)))
1620    (set (match_operand:P 0 "gpc_reg_operand" "")
1621         (plus:P (match_dup 1) (match_dup 2)))]
1622   "reload_completed"
1623   [(set (match_dup 0)
1624         (plus:P (match_dup 1)
1625                 (match_dup 2)))
1626    (set (match_dup 3)
1627         (compare:CC (match_dup 0)
1628                     (const_int 0)))]
1629   "")
1630
1631 ;; Split an add that we can't do in one insn into two insns, each of which
1632 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1633 ;; add should be last in case the result gets used in an address.
1634
1635 (define_split
1636   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1637         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1638                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1639   ""
1640   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1641    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1642 {
1643   HOST_WIDE_INT val = INTVAL (operands[2]);
1644   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1645   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1646
1647   operands[4] = GEN_INT (low);
1648   if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1649     operands[3] = GEN_INT (rest);
1650   else if (can_create_pseudo_p ())
1651     {
1652       operands[3] = gen_reg_rtx (DImode);
1653       emit_move_insn (operands[3], operands[2]);
1654       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1655       DONE;
1656     }
1657   else
1658     FAIL;
1659 })
1660
1661 (define_insn "one_cmpl<mode>2"
1662   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1663         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1664   ""
1665   "nor %0,%1,%1")
1666
1667 (define_insn ""
1668   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1669         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1670                     (const_int 0)))
1671    (clobber (match_scratch:P 2 "=r,r"))]
1672   ""
1673   "@
1674    nor. %2,%1,%1
1675    #"
1676   [(set_attr "type" "fast_compare,compare")
1677    (set_attr "length" "4,8")])
1678
1679 (define_split
1680   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
1681         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1682                     (const_int 0)))
1683    (clobber (match_scratch:P 2 ""))]
1684   "reload_completed"
1685   [(set (match_dup 2)
1686         (not:P (match_dup 1)))
1687    (set (match_dup 0)
1688         (compare:CC (match_dup 2)
1689                     (const_int 0)))]
1690   "")
1691
1692 (define_insn ""
1693   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1694         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1695                     (const_int 0)))
1696    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1697         (not:P (match_dup 1)))]
1698   ""
1699   "@
1700    nor. %0,%1,%1
1701    #"
1702   [(set_attr "type" "fast_compare,compare")
1703    (set_attr "length" "4,8")])
1704
1705 (define_split
1706   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
1707         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1708                     (const_int 0)))
1709    (set (match_operand:P 0 "gpc_reg_operand" "")
1710         (not:P (match_dup 1)))]
1711   "reload_completed"
1712   [(set (match_dup 0)
1713         (not:P (match_dup 1)))
1714    (set (match_dup 2)
1715         (compare:CC (match_dup 0)
1716                     (const_int 0)))]
1717   "")
1718
1719 (define_insn ""
1720   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1721         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1722                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1723   ""
1724   "@
1725    subf %0,%2,%1
1726    subfic %0,%2,%1")
1727
1728 (define_insn ""
1729   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1730         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1731                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1732                     (const_int 0)))
1733    (clobber (match_scratch:P 3 "=r,r"))]
1734   ""
1735   "@
1736    subf. %3,%2,%1
1737    #"
1738   [(set_attr "type" "fast_compare")
1739    (set_attr "length" "4,8")])
1740
1741 (define_split
1742   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1743         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1744                              (match_operand:P 2 "gpc_reg_operand" ""))
1745                     (const_int 0)))
1746    (clobber (match_scratch:P 3 ""))]
1747   "reload_completed"
1748   [(set (match_dup 3)
1749         (minus:P (match_dup 1)
1750                   (match_dup 2)))
1751    (set (match_dup 0)
1752         (compare:CC (match_dup 3)
1753                     (const_int 0)))]
1754   "")
1755
1756 (define_insn ""
1757   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1758         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1759                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1760                     (const_int 0)))
1761    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1762         (minus:P (match_dup 1)
1763                   (match_dup 2)))]
1764   ""
1765   "@
1766    subf. %0,%2,%1
1767    #"
1768   [(set_attr "type" "fast_compare")
1769    (set_attr "length" "4,8")])
1770
1771 (define_split
1772   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1773         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1774                              (match_operand:P 2 "gpc_reg_operand" ""))
1775                     (const_int 0)))
1776    (set (match_operand:P 0 "gpc_reg_operand" "")
1777         (minus:P (match_dup 1)
1778                   (match_dup 2)))]
1779   "reload_completed"
1780   [(set (match_dup 0)
1781         (minus:P (match_dup 1)
1782                   (match_dup 2)))
1783    (set (match_dup 3)
1784         (compare:CC (match_dup 0)
1785                     (const_int 0)))]
1786   "")
1787
1788 (define_expand "sub<mode>3"
1789   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1790         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1791                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
1792   ""
1793   "
1794 {
1795   if (GET_CODE (operands[2]) == CONST_INT)
1796     {
1797       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1798                                  negate_rtx (<MODE>mode, operands[2])));
1799       DONE;
1800     }
1801 }")
1802
1803 (define_expand "neg<mode>2"
1804   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1805         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
1806   ""
1807   "")
1808
1809 (define_insn "*neg<mode>2_internal"
1810   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1811         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1812   ""
1813   "neg %0,%1")
1814
1815 (define_insn ""
1816   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1817         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1818                     (const_int 0)))
1819    (clobber (match_scratch:P 2 "=r,r"))]
1820   ""
1821   "@
1822    neg. %2,%1
1823    #"
1824   [(set_attr "type" "fast_compare")
1825    (set_attr "length" "4,8")])
1826
1827 (define_split
1828   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1829         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
1830                     (const_int 0)))
1831    (clobber (match_scratch:P 2 ""))]
1832   "reload_completed"
1833   [(set (match_dup 2)
1834         (neg:P (match_dup 1)))
1835    (set (match_dup 0)
1836         (compare:CC (match_dup 2)
1837                     (const_int 0)))]
1838   "")
1839
1840 (define_insn ""
1841   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1842         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1843                     (const_int 0)))
1844    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1845         (neg:P (match_dup 1)))]
1846   ""
1847   "@
1848    neg. %0,%1
1849    #"
1850   [(set_attr "type" "fast_compare")
1851    (set_attr "length" "4,8")])
1852
1853 (define_split
1854   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1855         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
1856                     (const_int 0)))
1857    (set (match_operand:P 0 "gpc_reg_operand" "")
1858         (neg:P (match_dup 1)))]
1859   "reload_completed"
1860   [(set (match_dup 0)
1861         (neg:P (match_dup 1)))
1862    (set (match_dup 2)
1863         (compare:CC (match_dup 0)
1864                     (const_int 0)))]
1865   "")
1866
1867 (define_insn "clz<mode>2"
1868   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1869         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1870   ""
1871   "cntlz<wd> %0,%1"
1872   [(set_attr "type" "cntlz")])
1873
1874 (define_expand "ctz<mode>2"
1875   [(set (match_dup 2)
1876         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
1877    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
1878                                           (match_dup 2)))
1879               (clobber (scratch:CC))])
1880    (set (match_dup 4) (clz:GPR (match_dup 3)))
1881    (set (match_operand:GPR 0 "gpc_reg_operand" "")
1882         (minus:GPR (match_dup 5) (match_dup 4)))]
1883   ""
1884   {
1885      operands[2] = gen_reg_rtx (<MODE>mode);
1886      operands[3] = gen_reg_rtx (<MODE>mode);
1887      operands[4] = gen_reg_rtx (<MODE>mode);
1888      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
1889   })
1890
1891 (define_expand "ffs<mode>2"
1892   [(set (match_dup 2)
1893         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
1894    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
1895                                           (match_dup 2)))
1896               (clobber (scratch:CC))])
1897    (set (match_dup 4) (clz:GPR (match_dup 3)))
1898    (set (match_operand:GPR 0 "gpc_reg_operand" "")
1899         (minus:GPR (match_dup 5) (match_dup 4)))]
1900   ""
1901   {
1902      operands[2] = gen_reg_rtx (<MODE>mode);
1903      operands[3] = gen_reg_rtx (<MODE>mode);
1904      operands[4] = gen_reg_rtx (<MODE>mode);
1905      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
1906   })
1907
1908 (define_insn "popcntb<mode>2"
1909   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1910         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
1911                      UNSPEC_POPCNTB))]
1912   "TARGET_POPCNTB"
1913   "popcntb %0,%1"
1914   [(set_attr "length" "4")
1915    (set_attr "type" "popcnt")])
1916
1917 (define_insn "popcntd<mode>2"
1918   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1919         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1920   "TARGET_POPCNTD"
1921   "popcnt<wd> %0,%1"
1922   [(set_attr "length" "4")
1923    (set_attr "type" "popcnt")])
1924
1925 (define_expand "popcount<mode>2"
1926   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1927         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
1928   "TARGET_POPCNTB || TARGET_POPCNTD"
1929   {
1930     rs6000_emit_popcount (operands[0], operands[1]);
1931     DONE;
1932   })
1933
1934 (define_insn "parity<mode>2_cmpb"
1935   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1936         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")] UNSPEC_PARITY))]
1937   "TARGET_CMPB && TARGET_POPCNTB"
1938   "prty<wd> %0,%1")
1939
1940 (define_expand "parity<mode>2"
1941   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1942         (parity:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
1943   "TARGET_POPCNTB"
1944   {
1945     rs6000_emit_parity (operands[0], operands[1]);
1946     DONE;
1947   })
1948
1949 ;; Since the hardware zeros the upper part of the register, save generating the
1950 ;; AND immediate if we are converting to unsigned
1951 (define_insn "*bswaphi2_extenddi"
1952   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
1953         (zero_extend:DI
1954          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
1955   "TARGET_POWERPC64"
1956   "lhbrx %0,%y1"
1957   [(set_attr "length" "4")
1958    (set_attr "type" "load")])
1959
1960 (define_insn "*bswaphi2_extendsi"
1961   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1962         (zero_extend:SI
1963          (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
1964   ""
1965   "lhbrx %0,%y1"
1966   [(set_attr "length" "4")
1967    (set_attr "type" "load")])
1968
1969 (define_expand "bswaphi2"
1970   [(parallel [(set (match_operand:HI 0 "reg_or_mem_operand" "")
1971                    (bswap:HI
1972                     (match_operand:HI 1 "reg_or_mem_operand" "")))
1973               (clobber (match_scratch:SI 2 ""))])]
1974   ""
1975 {
1976   if (!REG_P (operands[0]) && !REG_P (operands[1]))
1977     operands[1] = force_reg (HImode, operands[1]);
1978 })
1979
1980 (define_insn "bswaphi2_internal"
1981   [(set (match_operand:HI 0 "reg_or_mem_operand" "=r,Z,&r")
1982         (bswap:HI
1983          (match_operand:HI 1 "reg_or_mem_operand" "Z,r,r")))
1984    (clobber (match_scratch:SI 2 "=X,X,&r"))]
1985   ""
1986   "@
1987    lhbrx %0,%y1
1988    sthbrx %1,%y0
1989    #"
1990   [(set_attr "length" "4,4,12")
1991    (set_attr "type" "load,store,*")])
1992
1993 (define_split
1994   [(set (match_operand:HI 0 "gpc_reg_operand" "")
1995         (bswap:HI (match_operand:HI 1 "gpc_reg_operand" "")))
1996    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
1997   "reload_completed"
1998   [(set (match_dup 3)
1999         (zero_extract:SI (match_dup 4)
2000                          (const_int 8)
2001                          (const_int 16)))
2002    (set (match_dup 2)
2003         (and:SI (ashift:SI (match_dup 4)
2004                            (const_int 8))
2005                 (const_int 65280)))             ;; 0xff00
2006    (set (match_dup 3)
2007         (ior:SI (match_dup 3)
2008                 (match_dup 2)))]
2009   "
2010 {
2011   operands[3] = simplify_gen_subreg (SImode, operands[0], HImode, 0);
2012   operands[4] = simplify_gen_subreg (SImode, operands[1], HImode, 0);
2013 }")
2014
2015 (define_insn "*bswapsi2_extenddi"
2016   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2017         (zero_extend:DI
2018          (bswap:SI (match_operand:SI 1 "memory_operand" "Z"))))]
2019   "TARGET_POWERPC64"
2020   "lwbrx %0,%y1"
2021   [(set_attr "length" "4")
2022    (set_attr "type" "load")])
2023
2024 (define_expand "bswapsi2"
2025   [(set (match_operand:SI 0 "reg_or_mem_operand" "")
2026         (bswap:SI
2027          (match_operand:SI 1 "reg_or_mem_operand" "")))]
2028   ""
2029 {
2030   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2031     operands[1] = force_reg (SImode, operands[1]);
2032 })
2033
2034 (define_insn "*bswapsi2_internal"
2035   [(set (match_operand:SI 0 "reg_or_mem_operand" "=r,Z,&r")
2036         (bswap:SI
2037          (match_operand:SI 1 "reg_or_mem_operand" "Z,r,r")))]
2038   ""
2039   "@
2040    lwbrx %0,%y1
2041    stwbrx %1,%y0
2042    #"
2043   [(set_attr "length" "4,4,12")
2044    (set_attr "type" "load,store,*")])
2045
2046 (define_split
2047   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2048         (bswap:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2049   "reload_completed"
2050   [(set (match_dup 0)
2051         (rotate:SI (match_dup 1) (const_int 8)))
2052    (set (zero_extract:SI (match_dup 0)
2053                          (const_int 8)
2054                          (const_int 0))
2055         (match_dup 1))
2056    (set (zero_extract:SI (match_dup 0)
2057                          (const_int 8)
2058                          (const_int 16))
2059         (rotate:SI (match_dup 1)
2060                    (const_int 16)))]
2061   "")
2062
2063 (define_expand "bswapdi2"
2064   [(parallel [(set (match_operand:DI 0 "reg_or_mem_operand" "")
2065                    (bswap:DI
2066                     (match_operand:DI 1 "reg_or_mem_operand" "")))
2067               (clobber (match_scratch:DI 2 ""))
2068               (clobber (match_scratch:DI 3 ""))
2069               (clobber (match_scratch:DI 4 ""))])]
2070   ""
2071 {
2072   if (!REG_P (operands[0]) && !REG_P (operands[1]))
2073     operands[1] = force_reg (DImode, operands[1]);
2074
2075   if (!TARGET_POWERPC64)
2076     {
2077       /* 32-bit mode needs fewer scratch registers, but 32-bit addressing mode
2078          that uses 64-bit registers needs the same scratch registers as 64-bit
2079          mode.  */
2080       emit_insn (gen_bswapdi2_32bit (operands[0], operands[1]));
2081       DONE;
2082     }
2083 })
2084
2085 ;; Power7/cell has ldbrx/stdbrx, so use it directly
2086 (define_insn "*bswapdi2_ldbrx"
2087   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2088         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2089    (clobber (match_scratch:DI 2 "=X,X,&r"))
2090    (clobber (match_scratch:DI 3 "=X,X,&r"))
2091    (clobber (match_scratch:DI 4 "=X,X,&r"))]
2092   "TARGET_POWERPC64 && TARGET_LDBRX
2093    && (REG_P (operands[0]) || REG_P (operands[1]))"
2094   "@
2095    ldbrx %0,%y1
2096    stdbrx %1,%y0
2097    #"
2098   [(set_attr "length" "4,4,36")
2099    (set_attr "type" "load,store,*")])
2100
2101 ;; Non-power7/cell, fall back to use lwbrx/stwbrx
2102 (define_insn "*bswapdi2_64bit"
2103   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2104         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2105    (clobber (match_scratch:DI 2 "=&b,&b,&r"))
2106    (clobber (match_scratch:DI 3 "=&r,&r,&r"))
2107    (clobber (match_scratch:DI 4 "=&r,X,&r"))]
2108   "TARGET_POWERPC64 && !TARGET_LDBRX
2109    && (REG_P (operands[0]) || REG_P (operands[1]))"
2110   "#"
2111   [(set_attr "length" "16,12,36")])
2112
2113 (define_split
2114   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2115         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2116    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2117    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2118    (clobber (match_operand:DI 4 "gpc_reg_operand" ""))]
2119   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2120   [(const_int 0)]
2121   "
2122 {
2123   rtx dest   = operands[0];
2124   rtx src    = operands[1];
2125   rtx op2    = operands[2];
2126   rtx op3    = operands[3];
2127   rtx op4    = operands[4];
2128   rtx op3_32 = simplify_gen_subreg (SImode, op3, DImode, 4);
2129   rtx op4_32 = simplify_gen_subreg (SImode, op4, DImode, 4);
2130   rtx addr1;
2131   rtx addr2;
2132   rtx word_high;
2133   rtx word_low;
2134
2135   addr1 = XEXP (src, 0);
2136   if (GET_CODE (addr1) == PLUS)
2137     {
2138       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2139       if (TARGET_AVOID_XFORM)
2140         {
2141           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2142           addr2 = op2;
2143         }
2144       else
2145         addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2146     }
2147   else if (TARGET_AVOID_XFORM)
2148     {
2149       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2150       addr2 = op2;
2151     }
2152   else
2153     {
2154       emit_move_insn (op2, GEN_INT (4));
2155       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2156     }
2157
2158   if (BYTES_BIG_ENDIAN)
2159     {
2160       word_high = change_address (src, SImode, addr1);
2161       word_low  = change_address (src, SImode, addr2);
2162     }
2163   else
2164     {
2165       word_high = change_address (src, SImode, addr2);
2166       word_low  = change_address (src, SImode, addr1);
2167     }
2168
2169   emit_insn (gen_bswapsi2 (op3_32, word_low));
2170   emit_insn (gen_bswapsi2 (op4_32, word_high));
2171   emit_insn (gen_ashldi3 (dest, op3, GEN_INT (32)));
2172   emit_insn (gen_iordi3 (dest, dest, op4));
2173 }")
2174
2175 (define_split
2176   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2177         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2178    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2179    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2180    (clobber (match_operand:DI 4 "" ""))]
2181   "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2182   [(const_int 0)]
2183   "
2184 {
2185   rtx dest   = operands[0];
2186   rtx src    = operands[1];
2187   rtx op2    = operands[2];
2188   rtx op3    = operands[3];
2189   rtx src_si = simplify_gen_subreg (SImode, src, DImode, 4);
2190   rtx op3_si = simplify_gen_subreg (SImode, op3, DImode, 4);
2191   rtx addr1;
2192   rtx addr2;
2193   rtx word_high;
2194   rtx word_low;
2195
2196   addr1 = XEXP (dest, 0);
2197   if (GET_CODE (addr1) == PLUS)
2198     {
2199       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2200       if (TARGET_AVOID_XFORM)
2201         {
2202           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2203           addr2 = op2;
2204         }
2205       else
2206         addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2207     }
2208   else if (TARGET_AVOID_XFORM)
2209     {
2210       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2211       addr2 = op2;
2212     }
2213   else
2214     {
2215       emit_move_insn (op2, GEN_INT (4));
2216       addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2217     }
2218
2219   emit_insn (gen_lshrdi3 (op3, src, GEN_INT (32)));
2220   if (BYTES_BIG_ENDIAN)
2221     {
2222       word_high = change_address (dest, SImode, addr1);
2223       word_low  = change_address (dest, SImode, addr2);
2224       emit_insn (gen_bswapsi2 (word_high, src_si));
2225       emit_insn (gen_bswapsi2 (word_low, op3_si));
2226     }
2227   else
2228     {
2229       word_high = change_address (dest, SImode, addr2);
2230       word_low  = change_address (dest, SImode, addr1);
2231       emit_insn (gen_bswapsi2 (word_low, src_si));
2232       emit_insn (gen_bswapsi2 (word_high, op3_si));
2233     }
2234 }")
2235
2236 (define_split
2237   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2238         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2239    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
2240    (clobber (match_operand:DI 3 "gpc_reg_operand" ""))
2241    (clobber (match_operand:DI 4 "" ""))]
2242   "TARGET_POWERPC64 && reload_completed"
2243   [(const_int 0)]
2244   "
2245 {
2246   rtx dest    = operands[0];
2247   rtx src     = operands[1];
2248   rtx op2     = operands[2];
2249   rtx op3     = operands[3];
2250   rtx dest_si = simplify_gen_subreg (SImode, dest, DImode, 4);
2251   rtx src_si  = simplify_gen_subreg (SImode, src, DImode, 4);
2252   rtx op2_si  = simplify_gen_subreg (SImode, op2, DImode, 4);
2253   rtx op3_si  = simplify_gen_subreg (SImode, op3, DImode, 4);
2254
2255   emit_insn (gen_lshrdi3 (op2, src, GEN_INT (32)));
2256   emit_insn (gen_bswapsi2 (dest_si, src_si));
2257   emit_insn (gen_bswapsi2 (op3_si, op2_si));
2258   emit_insn (gen_ashldi3 (dest, dest, GEN_INT (32)));
2259   emit_insn (gen_iordi3 (dest, dest, op3));
2260 }")
2261
2262 (define_insn "bswapdi2_32bit"
2263   [(set (match_operand:DI 0 "reg_or_mem_operand" "=&r,Z,??&r")
2264         (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2265    (clobber (match_scratch:SI 2 "=&b,&b,X"))]
2266   "!TARGET_POWERPC64 && (REG_P (operands[0]) || REG_P (operands[1]))"
2267   "#"
2268   [(set_attr "length" "16,12,36")])
2269
2270 (define_split
2271   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2272         (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "")))
2273    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2274   "!TARGET_POWERPC64 && reload_completed"
2275   [(const_int 0)]
2276   "
2277 {
2278   rtx dest   = operands[0];
2279   rtx src    = operands[1];
2280   rtx op2    = operands[2];
2281   rtx dest_hi = simplify_gen_subreg (SImode, dest, DImode, 0);
2282   rtx dest_lo = simplify_gen_subreg (SImode, dest, DImode, 4);
2283   rtx addr1;
2284   rtx addr2;
2285   rtx word_high;
2286   rtx word_low;
2287
2288   addr1 = XEXP (src, 0);
2289   if (GET_CODE (addr1) == PLUS)
2290     {
2291       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2292       if (TARGET_AVOID_XFORM)
2293         {
2294           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2295           addr2 = op2;
2296         }
2297       else
2298         addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2299     }
2300   else if (TARGET_AVOID_XFORM)
2301     {
2302       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2303       addr2 = op2;
2304     }
2305   else
2306     {
2307       emit_move_insn (op2, GEN_INT (4));
2308       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2309     }
2310
2311   if (BYTES_BIG_ENDIAN)
2312     {
2313       word_high = change_address (src, SImode, addr1);
2314       word_low  = change_address (src, SImode, addr2);
2315     }
2316   else
2317     {
2318       word_high = change_address (src, SImode, addr2);
2319       word_low  = change_address (src, SImode, addr1);
2320     }
2321
2322   emit_insn (gen_bswapsi2 (dest_hi, word_low));
2323   emit_insn (gen_bswapsi2 (dest_lo, word_high));
2324 }")
2325
2326 (define_split
2327   [(set (match_operand:DI 0 "indexed_or_indirect_operand" "")
2328         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2329    (clobber (match_operand:SI 2 "gpc_reg_operand" ""))]
2330   "!TARGET_POWERPC64 && reload_completed"
2331   [(const_int 0)]
2332   "
2333 {
2334   rtx dest     = operands[0];
2335   rtx src      = operands[1];
2336   rtx op2      = operands[2];
2337   rtx src_high = simplify_gen_subreg (SImode, src, DImode, 0);
2338   rtx src_low  = simplify_gen_subreg (SImode, src, DImode, 4);
2339   rtx addr1;
2340   rtx addr2;
2341   rtx word_high;
2342   rtx word_low;
2343
2344   addr1 = XEXP (dest, 0);
2345   if (GET_CODE (addr1) == PLUS)
2346     {
2347       emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2348       if (TARGET_AVOID_XFORM)
2349         {
2350           emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2351           addr2 = op2;
2352         }
2353       else
2354         addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
2355     }
2356   else if (TARGET_AVOID_XFORM)
2357     {
2358       emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2359       addr2 = op2;
2360     }
2361   else
2362     {
2363       emit_move_insn (op2, GEN_INT (4));
2364       addr2 = gen_rtx_PLUS (SImode, op2, addr1);
2365     }
2366
2367   if (BYTES_BIG_ENDIAN)
2368     {
2369       word_high = change_address (dest, SImode, addr1);
2370       word_low  = change_address (dest, SImode, addr2);
2371     }
2372   else
2373     {
2374       word_high = change_address (dest, SImode, addr2);
2375       word_low  = change_address (dest, SImode, addr1);
2376     }
2377
2378   emit_insn (gen_bswapsi2 (word_high, src_low));
2379   emit_insn (gen_bswapsi2 (word_low, src_high));
2380 }")
2381
2382 (define_split
2383   [(set (match_operand:DI 0 "gpc_reg_operand" "")
2384         (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "")))
2385    (clobber (match_operand:SI 2 "" ""))]
2386   "!TARGET_POWERPC64 && reload_completed"
2387   [(const_int 0)]
2388   "
2389 {
2390   rtx dest      = operands[0];
2391   rtx src       = operands[1];
2392   rtx src_high  = simplify_gen_subreg (SImode, src, DImode, 0);
2393   rtx src_low   = simplify_gen_subreg (SImode, src, DImode, 4);
2394   rtx dest_high = simplify_gen_subreg (SImode, dest, DImode, 0);
2395   rtx dest_low  = simplify_gen_subreg (SImode, dest, DImode, 4);
2396
2397   emit_insn (gen_bswapsi2 (dest_high, src_low));
2398   emit_insn (gen_bswapsi2 (dest_low, src_high));
2399 }")
2400
2401 (define_insn "mulsi3"
2402   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2403         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2404                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2405   ""
2406   "@
2407    mullw %0,%1,%2
2408    mulli %0,%1,%2"
2409    [(set (attr "type")
2410       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2411                 (const_string "imul3")
2412              (match_operand:SI 2 "short_cint_operand" "")
2413                 (const_string "imul2")]
2414         (const_string "imul")))])
2415
2416 (define_insn "*mulsi3_internal1"
2417   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2418         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2419                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2420                     (const_int 0)))
2421    (clobber (match_scratch:SI 3 "=r,r"))]
2422   ""
2423   "@
2424    mullw. %3,%1,%2
2425    #"
2426   [(set_attr "type" "imul_compare")
2427    (set_attr "length" "4,8")])
2428
2429 (define_split
2430   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2431         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2432                              (match_operand:SI 2 "gpc_reg_operand" ""))
2433                     (const_int 0)))
2434    (clobber (match_scratch:SI 3 ""))]
2435   "reload_completed"
2436   [(set (match_dup 3)
2437         (mult:SI (match_dup 1) (match_dup 2)))
2438    (set (match_dup 0)
2439         (compare:CC (match_dup 3)
2440                     (const_int 0)))]
2441   "")
2442
2443 (define_insn "*mulsi3_internal2"
2444   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2445         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2446                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2447                     (const_int 0)))
2448    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2449         (mult:SI (match_dup 1) (match_dup 2)))]
2450   ""
2451   "@
2452    mullw. %0,%1,%2
2453    #"
2454   [(set_attr "type" "imul_compare")
2455    (set_attr "length" "4,8")])
2456
2457 (define_split
2458   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2459         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2460                              (match_operand:SI 2 "gpc_reg_operand" ""))
2461                     (const_int 0)))
2462    (set (match_operand:SI 0 "gpc_reg_operand" "")
2463         (mult:SI (match_dup 1) (match_dup 2)))]
2464   "reload_completed"
2465   [(set (match_dup 0)
2466         (mult:SI (match_dup 1) (match_dup 2)))
2467    (set (match_dup 3)
2468         (compare:CC (match_dup 0)
2469                     (const_int 0)))]
2470   "")
2471
2472
2473 (define_insn "udiv<mode>3"
2474   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2475         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2476                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2477   ""
2478   "div<wd>u %0,%1,%2"
2479    [(set (attr "type")
2480       (cond [(match_operand:SI 0 "" "")
2481                 (const_string "idiv")]
2482         (const_string "ldiv")))])
2483
2484
2485 ;; For powers of two we can do srai/aze for divide and then adjust for
2486 ;; modulus.  If it isn't a power of two, force operands into register and do
2487 ;; a normal divide.
2488 (define_expand "div<mode>3"
2489   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2490         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2491                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2492   ""
2493 {
2494   if (GET_CODE (operands[2]) != CONST_INT
2495       || INTVAL (operands[2]) <= 0
2496       || exact_log2 (INTVAL (operands[2])) < 0)
2497     operands[2] = force_reg (<MODE>mode, operands[2]);
2498 })
2499
2500 (define_insn "*div<mode>3"
2501   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2502         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2503                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2504   ""
2505   "div<wd> %0,%1,%2"
2506   [(set (attr "type")
2507      (cond [(match_operand:SI 0 "" "")
2508                 (const_string "idiv")]
2509         (const_string "ldiv")))])
2510
2511 (define_expand "mod<mode>3"
2512   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
2513    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
2514    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
2515   ""
2516   "
2517 {
2518   int i;
2519   rtx temp1;
2520   rtx temp2;
2521
2522   if (GET_CODE (operands[2]) != CONST_INT
2523       || INTVAL (operands[2]) <= 0
2524       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2525     FAIL;
2526
2527   temp1 = gen_reg_rtx (<MODE>mode);
2528   temp2 = gen_reg_rtx (<MODE>mode);
2529
2530   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
2531   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
2532   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
2533   DONE;
2534 }")
2535
2536 (define_insn ""
2537   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2538         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2539                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
2540   ""
2541   "sra<wd>i %0,%1,%p2\;addze %0,%0"
2542   [(set_attr "type" "two")
2543    (set_attr "length" "8")])
2544
2545 (define_insn ""
2546   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2547         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2548                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2549                     (const_int 0)))
2550    (clobber (match_scratch:P 3 "=r,r"))]
2551   ""
2552   "@
2553    sra<wd>i %3,%1,%p2\;addze. %3,%3
2554    #"
2555   [(set_attr "type" "compare")
2556    (set_attr "length" "8,12")
2557    (set_attr "cell_micro" "not")])
2558
2559 (define_split
2560   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2561         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2562                              (match_operand:GPR 2 "exact_log2_cint_operand"
2563                               ""))
2564                     (const_int 0)))
2565    (clobber (match_scratch:GPR 3 ""))]
2566   "reload_completed"
2567   [(set (match_dup 3)
2568         (div:<MODE> (match_dup 1) (match_dup 2)))
2569    (set (match_dup 0)
2570         (compare:CC (match_dup 3)
2571                     (const_int 0)))]
2572   "")
2573
2574 (define_insn ""
2575   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2576         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2577                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2578                     (const_int 0)))
2579    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2580         (div:P (match_dup 1) (match_dup 2)))]
2581   ""
2582   "@
2583    sra<wd>i %0,%1,%p2\;addze. %0,%0
2584    #"
2585   [(set_attr "type" "compare")
2586    (set_attr "length" "8,12")
2587    (set_attr "cell_micro" "not")])
2588
2589 (define_split
2590   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2591         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2592                              (match_operand:GPR 2 "exact_log2_cint_operand"
2593                               ""))
2594                     (const_int 0)))
2595    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2596         (div:GPR (match_dup 1) (match_dup 2)))]
2597   "reload_completed"
2598   [(set (match_dup 0)
2599         (div:<MODE> (match_dup 1) (match_dup 2)))
2600    (set (match_dup 3)
2601         (compare:CC (match_dup 0)
2602                     (const_int 0)))]
2603   "")
2604 \f
2605 ;; Logical instructions
2606 ;; The logical instructions are mostly combined by using match_operator,
2607 ;; but the plain AND insns are somewhat different because there is no
2608 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2609 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2610
2611 (define_expand "andsi3"
2612   [(parallel
2613     [(set (match_operand:SI 0 "gpc_reg_operand" "")
2614           (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2615                   (match_operand:SI 2 "and_operand" "")))
2616      (clobber (match_scratch:CC 3 ""))])]
2617   ""
2618   "")
2619
2620 (define_insn "andsi3_mc"
2621   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2622         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2623                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2624    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2625   "rs6000_gen_cell_microcode"
2626   "@
2627    and %0,%1,%2
2628    rlwinm %0,%1,0,%m2,%M2
2629    andi. %0,%1,%b2
2630    andis. %0,%1,%u2"
2631   [(set_attr "type" "*,*,fast_compare,fast_compare")])
2632
2633 (define_insn "andsi3_nomc"
2634   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2635         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2636                 (match_operand:SI 2 "and_operand" "?r,T")))
2637    (clobber (match_scratch:CC 3 "=X,X"))]
2638   "!rs6000_gen_cell_microcode"
2639   "@
2640    and %0,%1,%2
2641    rlwinm %0,%1,0,%m2,%M2")
2642
2643 (define_insn "andsi3_internal0_nomc"
2644   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2645         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2646                 (match_operand:SI 2 "and_operand" "?r,T")))]
2647   "!rs6000_gen_cell_microcode"
2648   "@
2649    and %0,%1,%2
2650    rlwinm %0,%1,0,%m2,%M2")
2651
2652
2653 ;; Note to set cr's other than cr0 we do the and immediate and then
2654 ;; the test again -- this avoids a mfcr which on the higher end
2655 ;; machines causes an execution serialization
2656
2657 (define_insn "*andsi3_internal2_mc"
2658   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2659         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2660                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2661                     (const_int 0)))
2662    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2663    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2664   "TARGET_32BIT && rs6000_gen_cell_microcode"
2665   "@
2666    and. %3,%1,%2
2667    andi. %3,%1,%b2
2668    andis. %3,%1,%u2
2669    rlwinm. %3,%1,0,%m2,%M2
2670    #
2671    #
2672    #
2673    #"
2674   [(set_attr "type" "fast_compare,fast_compare,fast_compare,delayed_compare,\
2675                      compare,compare,compare,compare")
2676    (set_attr "length" "4,4,4,4,8,8,8,8")])
2677
2678 (define_insn "*andsi3_internal3_mc"
2679   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2680         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2681                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2682                     (const_int 0)))
2683    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2684    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2685   "TARGET_64BIT && rs6000_gen_cell_microcode"
2686   "@
2687    #
2688    andi. %3,%1,%b2
2689    andis. %3,%1,%u2
2690    rlwinm. %3,%1,0,%m2,%M2
2691    #
2692    #
2693    #
2694    #"
2695   [(set_attr "type" "compare,fast_compare,fast_compare,delayed_compare,compare,\
2696                      compare,compare,compare")
2697    (set_attr "length" "8,4,4,4,8,8,8,8")])
2698
2699 (define_split
2700   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2701         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2702                              (match_operand:GPR 2 "and_operand" ""))
2703                     (const_int 0)))
2704    (clobber (match_scratch:GPR 3 ""))
2705    (clobber (match_scratch:CC 4 ""))]
2706   "reload_completed"
2707   [(parallel [(set (match_dup 3)
2708                    (and:<MODE> (match_dup 1)
2709                                (match_dup 2)))
2710               (clobber (match_dup 4))])
2711    (set (match_dup 0)
2712         (compare:CC (match_dup 3)
2713                     (const_int 0)))]
2714   "")
2715
2716 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2717 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2718
2719 (define_split
2720   [(set (match_operand:CC 0 "cc_reg_operand" "")
2721         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2722                             (match_operand:SI 2 "gpc_reg_operand" ""))
2723                     (const_int 0)))
2724    (clobber (match_scratch:SI 3 ""))
2725    (clobber (match_scratch:CC 4 ""))]
2726   "TARGET_POWERPC64 && reload_completed"
2727   [(parallel [(set (match_dup 3)
2728                    (and:SI (match_dup 1)
2729                            (match_dup 2)))
2730               (clobber (match_dup 4))])
2731    (set (match_dup 0)
2732         (compare:CC (match_dup 3)
2733                     (const_int 0)))]
2734   "")
2735
2736 (define_insn "*andsi3_internal4"
2737   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2738         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2739                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2740                     (const_int 0)))
2741    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2742         (and:SI (match_dup 1)
2743                 (match_dup 2)))
2744    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2745   "TARGET_32BIT && rs6000_gen_cell_microcode"
2746   "@
2747    and. %0,%1,%2
2748    andi. %0,%1,%b2
2749    andis. %0,%1,%u2
2750    rlwinm. %0,%1,0,%m2,%M2
2751    #
2752    #
2753    #
2754    #"
2755   [(set_attr "type" "fast_compare,fast_compare,fast_compare,delayed_compare,\
2756                      compare,compare,compare,compare")
2757    (set_attr "length" "4,4,4,4,8,8,8,8")])
2758
2759 (define_insn "*andsi3_internal5_mc"
2760   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2761         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2762                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2763                     (const_int 0)))
2764    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2765         (and:SI (match_dup 1)
2766                 (match_dup 2)))
2767    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2768   "TARGET_64BIT && rs6000_gen_cell_microcode"
2769   "@
2770    #
2771    andi. %0,%1,%b2
2772    andis. %0,%1,%u2
2773    rlwinm. %0,%1,0,%m2,%M2
2774    #
2775    #
2776    #
2777    #"
2778   [(set_attr "type" "compare,fast_compare,fast_compare,delayed_compare,compare,\
2779                      compare,compare,compare")
2780    (set_attr "length" "8,4,4,4,8,8,8,8")])
2781
2782 (define_split
2783   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2784         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2785                             (match_operand:SI 2 "and_operand" ""))
2786                     (const_int 0)))
2787    (set (match_operand:SI 0 "gpc_reg_operand" "")
2788         (and:SI (match_dup 1)
2789                 (match_dup 2)))
2790    (clobber (match_scratch:CC 4 ""))]
2791   "reload_completed"
2792   [(parallel [(set (match_dup 0)
2793                    (and:SI (match_dup 1)
2794                            (match_dup 2)))
2795               (clobber (match_dup 4))])
2796    (set (match_dup 3)
2797         (compare:CC (match_dup 0)
2798                     (const_int 0)))]
2799   "")
2800
2801 (define_split
2802   [(set (match_operand:CC 3 "cc_reg_operand" "")
2803         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2804                             (match_operand:SI 2 "gpc_reg_operand" ""))
2805                     (const_int 0)))
2806    (set (match_operand:SI 0 "gpc_reg_operand" "")
2807         (and:SI (match_dup 1)
2808                 (match_dup 2)))
2809    (clobber (match_scratch:CC 4 ""))]
2810   "TARGET_POWERPC64 && reload_completed"
2811   [(parallel [(set (match_dup 0)
2812                    (and:SI (match_dup 1)
2813                            (match_dup 2)))
2814               (clobber (match_dup 4))])
2815    (set (match_dup 3)
2816         (compare:CC (match_dup 0)
2817                     (const_int 0)))]
2818   "")
2819
2820 ;; Handle the PowerPC64 rlwinm corner case
2821
2822 (define_insn_and_split "*andsi3_internal6"
2823   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2824         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2825                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2826   "TARGET_POWERPC64"
2827   "#"
2828   "TARGET_POWERPC64"
2829   [(set (match_dup 0)
2830         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
2831                 (match_dup 4)))
2832    (set (match_dup 0)
2833         (rotate:SI (match_dup 0) (match_dup 5)))]
2834   "
2835 {
2836   int mb = extract_MB (operands[2]);
2837   int me = extract_ME (operands[2]);
2838   operands[3] = GEN_INT (me + 1);
2839   operands[5] = GEN_INT (32 - (me + 1));
2840   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2841 }"
2842   [(set_attr "length" "8")])
2843
2844 (define_expand "iorsi3"
2845   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2846         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
2847                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2848   ""
2849   "
2850 {
2851   if (GET_CODE (operands[2]) == CONST_INT
2852       && ! logical_operand (operands[2], SImode))
2853     {
2854       HOST_WIDE_INT value = INTVAL (operands[2]);
2855       rtx tmp = ((!can_create_pseudo_p ()
2856                   || rtx_equal_p (operands[0], operands[1]))
2857                  ? operands[0] : gen_reg_rtx (SImode));
2858
2859       emit_insn (gen_iorsi3 (tmp, operands[1],
2860                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2861       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2862       DONE;
2863     }
2864 }")
2865
2866 (define_expand "xorsi3"
2867   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2868         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2869                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2870   ""
2871   "
2872 {
2873   if (GET_CODE (operands[2]) == CONST_INT
2874       && ! logical_operand (operands[2], SImode))
2875     {
2876       HOST_WIDE_INT value = INTVAL (operands[2]);
2877       rtx tmp = ((!can_create_pseudo_p ()
2878                   || rtx_equal_p (operands[0], operands[1]))
2879                  ? operands[0] : gen_reg_rtx (SImode));
2880
2881       emit_insn (gen_xorsi3 (tmp, operands[1],
2882                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2883       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2884       DONE;
2885     }
2886 }")
2887
2888 (define_insn "*boolsi3_internal1"
2889   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2890         (match_operator:SI 3 "boolean_or_operator"
2891          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
2892           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
2893   ""
2894   "@
2895    %q3 %0,%1,%2
2896    %q3i %0,%1,%b2
2897    %q3is %0,%1,%u2")
2898
2899 (define_insn "*boolsi3_internal2"
2900   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2901         (compare:CC (match_operator:SI 4 "boolean_or_operator"
2902          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2903           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2904          (const_int 0)))
2905    (clobber (match_scratch:SI 3 "=r,r"))]
2906   "TARGET_32BIT"
2907   "@
2908    %q4. %3,%1,%2
2909    #"
2910   [(set_attr "type" "fast_compare,compare")
2911    (set_attr "length" "4,8")])
2912
2913 (define_split
2914   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
2915         (compare:CC (match_operator:SI 4 "boolean_operator"
2916          [(match_operand:SI 1 "gpc_reg_operand" "")
2917           (match_operand:SI 2 "gpc_reg_operand" "")])
2918          (const_int 0)))
2919    (clobber (match_scratch:SI 3 ""))]
2920   "TARGET_32BIT && reload_completed"
2921   [(set (match_dup 3) (match_dup 4))
2922    (set (match_dup 0)
2923         (compare:CC (match_dup 3)
2924                     (const_int 0)))]
2925   "")
2926
2927 (define_insn "*boolsi3_internal3"
2928   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2929         (compare:CC (match_operator:SI 4 "boolean_operator"
2930          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2931           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2932          (const_int 0)))
2933    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2934         (match_dup 4))]
2935   "TARGET_32BIT"
2936   "@
2937    %q4. %0,%1,%2
2938    #"
2939   [(set_attr "type" "fast_compare,compare")
2940    (set_attr "length" "4,8")])
2941
2942 (define_split
2943   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
2944         (compare:CC (match_operator:SI 4 "boolean_operator"
2945          [(match_operand:SI 1 "gpc_reg_operand" "")
2946           (match_operand:SI 2 "gpc_reg_operand" "")])
2947          (const_int 0)))
2948    (set (match_operand:SI 0 "gpc_reg_operand" "")
2949         (match_dup 4))]
2950   "TARGET_32BIT && reload_completed"
2951   [(set (match_dup 0) (match_dup 4))
2952    (set (match_dup 3)
2953         (compare:CC (match_dup 0)
2954                     (const_int 0)))]
2955   "")
2956
2957 ;; Split a logical operation that we can't do in one insn into two insns,
2958 ;; each of which does one 16-bit part.  This is used by combine.
2959
2960 (define_split
2961   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2962         (match_operator:SI 3 "boolean_or_operator"
2963          [(match_operand:SI 1 "gpc_reg_operand" "")
2964           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
2965   ""
2966   [(set (match_dup 0) (match_dup 4))
2967    (set (match_dup 0) (match_dup 5))]
2968 "
2969 {
2970   rtx i;
2971   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
2972   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2973                                 operands[1], i);
2974   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
2975   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2976                                 operands[0], i);
2977 }")
2978
2979 (define_insn "*boolcsi3_internal1"
2980   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2981         (match_operator:SI 3 "boolean_operator"
2982          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2983           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
2984   ""
2985   "%q3 %0,%2,%1")
2986
2987 (define_insn "*boolcsi3_internal2"
2988   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2989         (compare:CC (match_operator:SI 4 "boolean_operator"
2990          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2991           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2992          (const_int 0)))
2993    (clobber (match_scratch:SI 3 "=r,r"))]
2994   "TARGET_32BIT"
2995   "@
2996    %q4. %3,%2,%1
2997    #"
2998   [(set_attr "type" "compare")
2999    (set_attr "length" "4,8")])
3000
3001 (define_split
3002   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3003         (compare:CC (match_operator:SI 4 "boolean_operator"
3004          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3005           (match_operand:SI 2 "gpc_reg_operand" "")])
3006          (const_int 0)))
3007    (clobber (match_scratch:SI 3 ""))]
3008   "TARGET_32BIT && reload_completed"
3009   [(set (match_dup 3) (match_dup 4))
3010    (set (match_dup 0)
3011         (compare:CC (match_dup 3)
3012                     (const_int 0)))]
3013   "")
3014
3015 (define_insn "*boolcsi3_internal3"
3016   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3017         (compare:CC (match_operator:SI 4 "boolean_operator"
3018          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3019           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3020          (const_int 0)))
3021    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3022         (match_dup 4))]
3023   "TARGET_32BIT"
3024   "@
3025    %q4. %0,%2,%1
3026    #"
3027   [(set_attr "type" "compare")
3028    (set_attr "length" "4,8")])
3029
3030 (define_split
3031   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3032         (compare:CC (match_operator:SI 4 "boolean_operator"
3033          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3034           (match_operand:SI 2 "gpc_reg_operand" "")])
3035          (const_int 0)))
3036    (set (match_operand:SI 0 "gpc_reg_operand" "")
3037         (match_dup 4))]
3038   "TARGET_32BIT && reload_completed"
3039   [(set (match_dup 0) (match_dup 4))
3040    (set (match_dup 3)
3041         (compare:CC (match_dup 0)
3042                     (const_int 0)))]
3043   "")
3044
3045 (define_insn "*boolccsi3_internal1"
3046   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3047         (match_operator:SI 3 "boolean_operator"
3048          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3049           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3050   ""
3051   "%q3 %0,%1,%2")
3052
3053 (define_insn "*boolccsi3_internal2"
3054   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3055         (compare:CC (match_operator:SI 4 "boolean_operator"
3056          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3057           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3058          (const_int 0)))
3059    (clobber (match_scratch:SI 3 "=r,r"))]
3060   "TARGET_32BIT"
3061   "@
3062    %q4. %3,%1,%2
3063    #"
3064   [(set_attr "type" "fast_compare,compare")
3065    (set_attr "length" "4,8")])
3066
3067 (define_split
3068   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3069         (compare:CC (match_operator:SI 4 "boolean_operator"
3070          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3071           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3072          (const_int 0)))
3073    (clobber (match_scratch:SI 3 ""))]
3074   "TARGET_32BIT && reload_completed"
3075   [(set (match_dup 3) (match_dup 4))
3076    (set (match_dup 0)
3077         (compare:CC (match_dup 3)
3078                     (const_int 0)))]
3079   "")
3080
3081 (define_insn "*boolccsi3_internal3"
3082   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3083         (compare:CC (match_operator:SI 4 "boolean_operator"
3084          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3085           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3086          (const_int 0)))
3087    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3088         (match_dup 4))]
3089   "TARGET_32BIT"
3090   "@
3091    %q4. %0,%1,%2
3092    #"
3093   [(set_attr "type" "fast_compare,compare")
3094    (set_attr "length" "4,8")])
3095
3096 (define_split
3097   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3098         (compare:CC (match_operator:SI 4 "boolean_operator"
3099          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3100           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3101          (const_int 0)))
3102    (set (match_operand:SI 0 "gpc_reg_operand" "")
3103         (match_dup 4))]
3104   "TARGET_32BIT && reload_completed"
3105   [(set (match_dup 0) (match_dup 4))
3106    (set (match_dup 3)
3107         (compare:CC (match_dup 0)
3108                     (const_int 0)))]
3109   "")
3110 \f
3111 ;; Rotate and shift insns, in all their variants.  These support shifts,
3112 ;; field inserts and extracts, and various combinations thereof.
3113 (define_expand "insv"
3114   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
3115                        (match_operand:SI 1 "const_int_operand" "")
3116                        (match_operand:SI 2 "const_int_operand" ""))
3117         (match_operand 3 "gpc_reg_operand" ""))]
3118   ""
3119   "
3120 {
3121   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3122      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3123      compiler if the address of the structure is taken later.  Likewise, do
3124      not handle invalid E500 subregs.  */
3125   if (GET_CODE (operands[0]) == SUBREG
3126       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD
3127           || ((TARGET_E500_DOUBLE || TARGET_SPE)
3128               && invalid_e500_subreg (operands[0], GET_MODE (operands[0])))))
3129     FAIL;
3130
3131   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
3132     emit_insn (gen_insvdi_internal (operands[0], operands[1], operands[2],
3133                                     operands[3]));
3134   else
3135     emit_insn (gen_insvsi_internal (operands[0], operands[1], operands[2],
3136                                     operands[3]));
3137   DONE;
3138 }")
3139
3140 (define_insn "insvsi_internal"
3141   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3142                          (match_operand:SI 1 "const_int_operand" "i")
3143                          (match_operand:SI 2 "const_int_operand" "i"))
3144         (match_operand:SI 3 "gpc_reg_operand" "r"))]
3145   ""
3146   "*
3147 {
3148   int start = INTVAL (operands[2]) & 31;
3149   int size = INTVAL (operands[1]) & 31;
3150
3151   operands[4] = GEN_INT (32 - start - size);
3152   operands[1] = GEN_INT (start + size - 1);
3153   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3154 }"
3155   [(set_attr "type" "insert_word")])
3156
3157 (define_insn "*insvsi_internal1"
3158   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3159                          (match_operand:SI 1 "const_int_operand" "i")
3160                          (match_operand:SI 2 "const_int_operand" "i"))
3161         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3162                    (match_operand:SI 4 "const_int_operand" "i")))]
3163   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3164   "*
3165 {
3166   int shift = INTVAL (operands[4]) & 31;
3167   int start = INTVAL (operands[2]) & 31;
3168   int size = INTVAL (operands[1]) & 31;
3169
3170   operands[4] = GEN_INT (shift - start - size);
3171   operands[1] = GEN_INT (start + size - 1);
3172   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3173 }"
3174   [(set_attr "type" "insert_word")])
3175
3176 (define_insn "*insvsi_internal2"
3177   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3178                          (match_operand:SI 1 "const_int_operand" "i")
3179                          (match_operand:SI 2 "const_int_operand" "i"))
3180         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3181                      (match_operand:SI 4 "const_int_operand" "i")))]
3182   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3183   "*
3184 {
3185   int shift = INTVAL (operands[4]) & 31;
3186   int start = INTVAL (operands[2]) & 31;
3187   int size = INTVAL (operands[1]) & 31;
3188
3189   operands[4] = GEN_INT (32 - shift - start - size);
3190   operands[1] = GEN_INT (start + size - 1);
3191   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3192 }"
3193   [(set_attr "type" "insert_word")])
3194
3195 (define_insn "*insvsi_internal3"
3196   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3197                          (match_operand:SI 1 "const_int_operand" "i")
3198                          (match_operand:SI 2 "const_int_operand" "i"))
3199         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3200                      (match_operand:SI 4 "const_int_operand" "i")))]
3201   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3202   "*
3203 {
3204   int shift = INTVAL (operands[4]) & 31;
3205   int start = INTVAL (operands[2]) & 31;
3206   int size = INTVAL (operands[1]) & 31;
3207
3208   operands[4] = GEN_INT (32 - shift - start - size);
3209   operands[1] = GEN_INT (start + size - 1);
3210   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3211 }"
3212   [(set_attr "type" "insert_word")])
3213
3214 (define_insn "*insvsi_internal4"
3215   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3216                          (match_operand:SI 1 "const_int_operand" "i")
3217                          (match_operand:SI 2 "const_int_operand" "i"))
3218         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3219                          (match_operand:SI 4 "const_int_operand" "i")
3220                          (match_operand:SI 5 "const_int_operand" "i")))]
3221   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3222   "*
3223 {
3224   int extract_start = INTVAL (operands[5]) & 31;
3225   int extract_size = INTVAL (operands[4]) & 31;
3226   int insert_start = INTVAL (operands[2]) & 31;
3227   int insert_size = INTVAL (operands[1]) & 31;
3228
3229 /* Align extract field with insert field */
3230   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3231   operands[1] = GEN_INT (insert_start + insert_size - 1);
3232   return \"rlwimi %0,%3,%h5,%h2,%h1\";
3233 }"
3234   [(set_attr "type" "insert_word")])
3235
3236 ;; combine patterns for rlwimi
3237 (define_insn "*insvsi_internal5"
3238   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3239         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3240                         (match_operand:SI 1 "mask_operand" "i"))
3241                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3242                                      (match_operand:SI 2 "const_int_operand" "i"))
3243                         (match_operand:SI 5 "mask_operand" "i"))))]
3244   "INTVAL(operands[1]) == ~INTVAL(operands[5])"
3245   "*
3246 {
3247  int me = extract_ME(operands[5]);
3248  int mb = extract_MB(operands[5]);
3249  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3250  operands[2] = GEN_INT(mb);
3251  operands[1] = GEN_INT(me);
3252  return \"rlwimi %0,%3,%h4,%h2,%h1\";
3253 }"
3254   [(set_attr "type" "insert_word")])
3255
3256 (define_insn "*insvsi_internal6"
3257   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3258         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3259                                      (match_operand:SI 2 "const_int_operand" "i"))
3260                         (match_operand:SI 5 "mask_operand" "i"))
3261                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3262                         (match_operand:SI 1 "mask_operand" "i"))))]
3263   "INTVAL(operands[1]) == ~INTVAL(operands[5])"
3264   "*
3265 {
3266  int me = extract_ME(operands[5]);
3267  int mb = extract_MB(operands[5]);
3268  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3269  operands[2] = GEN_INT(mb);
3270  operands[1] = GEN_INT(me);
3271  return \"rlwimi %0,%3,%h4,%h2,%h1\";
3272 }"
3273   [(set_attr "type" "insert_word")])
3274
3275 (define_insn "insvdi_internal"
3276   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3277                          (match_operand:SI 1 "const_int_operand" "i")
3278                          (match_operand:SI 2 "const_int_operand" "i"))
3279         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3280   "TARGET_POWERPC64"
3281   "*
3282 {
3283   int start = INTVAL (operands[2]) & 63;
3284   int size = INTVAL (operands[1]) & 63;
3285
3286   operands[1] = GEN_INT (64 - start - size);
3287   return \"rldimi %0,%3,%H1,%H2\";
3288 }"
3289   [(set_attr "type" "insert_dword")])
3290
3291 (define_insn "*insvdi_internal2"
3292   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3293                          (match_operand:SI 1 "const_int_operand" "i")
3294                          (match_operand:SI 2 "const_int_operand" "i"))
3295         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3296                      (match_operand:SI 4 "const_int_operand" "i")))]
3297   "TARGET_POWERPC64
3298    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3299   "*
3300 {
3301   int shift = INTVAL (operands[4]) & 63;
3302   int start = (INTVAL (operands[2]) & 63) - 32;
3303   int size = INTVAL (operands[1]) & 63;
3304
3305   operands[4] = GEN_INT (64 - shift - start - size);
3306   operands[2] = GEN_INT (start);
3307   operands[1] = GEN_INT (start + size - 1);
3308   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3309 }")
3310
3311 (define_insn "*insvdi_internal3"
3312   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3313                          (match_operand:SI 1 "const_int_operand" "i")
3314                          (match_operand:SI 2 "const_int_operand" "i"))
3315         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3316                      (match_operand:SI 4 "const_int_operand" "i")))]
3317   "TARGET_POWERPC64
3318    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3319   "*
3320 {
3321   int shift = INTVAL (operands[4]) & 63;
3322   int start = (INTVAL (operands[2]) & 63) - 32;
3323   int size = INTVAL (operands[1]) & 63;
3324
3325   operands[4] = GEN_INT (64 - shift - start - size);
3326   operands[2] = GEN_INT (start);
3327   operands[1] = GEN_INT (start + size - 1);
3328   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3329 }")
3330
3331 (define_expand "extzv"
3332   [(set (match_operand 0 "gpc_reg_operand" "")
3333         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3334                        (match_operand:SI 2 "const_int_operand" "")
3335                        (match_operand:SI 3 "const_int_operand" "")))]
3336   ""
3337   "
3338 {
3339   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3340      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3341      compiler if the address of the structure is taken later.  */
3342   if (GET_CODE (operands[0]) == SUBREG
3343       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3344     FAIL;
3345
3346   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3347     emit_insn (gen_extzvdi_internal (operands[0], operands[1], operands[2],
3348                                      operands[3]));
3349   else
3350     emit_insn (gen_extzvsi_internal (operands[0], operands[1], operands[2],
3351                                      operands[3]));
3352   DONE;
3353 }")
3354
3355 (define_insn "extzvsi_internal"
3356   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3357         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3358                          (match_operand:SI 2 "const_int_operand" "i")
3359                          (match_operand:SI 3 "const_int_operand" "i")))]
3360   ""
3361   "*
3362 {
3363   int start = INTVAL (operands[3]) & 31;
3364   int size = INTVAL (operands[2]) & 31;
3365
3366   if (start + size >= 32)
3367     operands[3] = const0_rtx;
3368   else
3369     operands[3] = GEN_INT (start + size);
3370   return \"rlwinm %0,%1,%3,%s2,31\";
3371 }")
3372
3373 (define_insn "*extzvsi_internal1"
3374   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3375         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3376                          (match_operand:SI 2 "const_int_operand" "i,i")
3377                          (match_operand:SI 3 "const_int_operand" "i,i"))
3378                     (const_int 0)))
3379    (clobber (match_scratch:SI 4 "=r,r"))]
3380   ""
3381   "*
3382 {
3383   int start = INTVAL (operands[3]) & 31;
3384   int size = INTVAL (operands[2]) & 31;
3385
3386   /* Force split for non-cc0 compare.  */
3387   if (which_alternative == 1)
3388      return \"#\";
3389
3390   /* If the bit-field being tested fits in the upper or lower half of a
3391      word, it is possible to use andiu. or andil. to test it.  This is
3392      useful because the condition register set-use delay is smaller for
3393      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3394      position is 0 because the LT and GT bits may be set wrong.  */
3395
3396   if ((start > 0 && start + size <= 16) || start >= 16)
3397     {
3398       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3399                               - (1 << (16 - (start & 15) - size))));
3400       if (start < 16)
3401         return \"andis. %4,%1,%3\";
3402       else
3403         return \"andi. %4,%1,%3\";
3404     }
3405
3406   if (start + size >= 32)
3407     operands[3] = const0_rtx;
3408   else
3409     operands[3] = GEN_INT (start + size);
3410   return \"rlwinm. %4,%1,%3,%s2,31\";
3411 }"
3412   [(set_attr "type" "delayed_compare")
3413    (set_attr "length" "4,8")])
3414
3415 (define_split
3416   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3417         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3418                          (match_operand:SI 2 "const_int_operand" "")
3419                          (match_operand:SI 3 "const_int_operand" ""))
3420                     (const_int 0)))
3421    (clobber (match_scratch:SI 4 ""))]
3422   "reload_completed"
3423   [(set (match_dup 4)
3424         (zero_extract:SI (match_dup 1) (match_dup 2)
3425                          (match_dup 3)))
3426    (set (match_dup 0)
3427         (compare:CC (match_dup 4)
3428                     (const_int 0)))]
3429   "")
3430
3431 (define_insn "*extzvsi_internal2"
3432   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3433         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3434                          (match_operand:SI 2 "const_int_operand" "i,i")
3435                          (match_operand:SI 3 "const_int_operand" "i,i"))
3436                     (const_int 0)))
3437    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3438         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3439   ""
3440   "*
3441 {
3442   int start = INTVAL (operands[3]) & 31;
3443   int size = INTVAL (operands[2]) & 31;
3444
3445   /* Force split for non-cc0 compare.  */
3446   if (which_alternative == 1)
3447      return \"#\";
3448
3449   /* Since we are using the output value, we can't ignore any need for
3450      a shift.  The bit-field must end at the LSB.  */
3451   if (start >= 16 && start + size == 32)
3452     {
3453       operands[3] = GEN_INT ((1 << size) - 1);
3454       return \"andi. %0,%1,%3\";
3455     }
3456
3457   if (start + size >= 32)
3458     operands[3] = const0_rtx;
3459   else
3460     operands[3] = GEN_INT (start + size);
3461   return \"rlwinm. %0,%1,%3,%s2,31\";
3462 }"
3463   [(set_attr "type" "delayed_compare")
3464    (set_attr "length" "4,8")])
3465
3466 (define_split
3467   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
3468         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3469                          (match_operand:SI 2 "const_int_operand" "")
3470                          (match_operand:SI 3 "const_int_operand" ""))
3471                     (const_int 0)))
3472    (set (match_operand:SI 0 "gpc_reg_operand" "")
3473         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3474   "reload_completed"
3475   [(set (match_dup 0)
3476         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3477    (set (match_dup 4)
3478         (compare:CC (match_dup 0)
3479                     (const_int 0)))]
3480   "")
3481
3482 (define_insn "extzvdi_internal"
3483   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3484         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3485                          (match_operand:SI 2 "const_int_operand" "i")
3486                          (match_operand:SI 3 "const_int_operand" "i")))]
3487   "TARGET_POWERPC64"
3488   "*
3489 {
3490   int start = INTVAL (operands[3]) & 63;
3491   int size = INTVAL (operands[2]) & 63;
3492
3493   if (start + size >= 64)
3494     operands[3] = const0_rtx;
3495   else
3496     operands[3] = GEN_INT (start + size);
3497   operands[2] = GEN_INT (64 - size);
3498   return \"rldicl %0,%1,%3,%2\";
3499 }")
3500
3501 (define_insn "*extzvdi_internal1"
3502   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3503         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3504                          (match_operand:SI 2 "const_int_operand" "i")
3505                          (match_operand:SI 3 "const_int_operand" "i"))
3506                     (const_int 0)))
3507    (clobber (match_scratch:DI 4 "=r"))]
3508   "TARGET_64BIT && rs6000_gen_cell_microcode"
3509   "*
3510 {
3511   int start = INTVAL (operands[3]) & 63;
3512   int size = INTVAL (operands[2]) & 63;
3513
3514   if (start + size >= 64)
3515     operands[3] = const0_rtx;
3516   else
3517     operands[3] = GEN_INT (start + size);
3518   operands[2] = GEN_INT (64 - size);
3519   return \"rldicl. %4,%1,%3,%2\";
3520 }"
3521   [(set_attr "type" "compare")])
3522
3523 (define_insn "*extzvdi_internal2"
3524   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3525         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3526                          (match_operand:SI 2 "const_int_operand" "i")
3527                          (match_operand:SI 3 "const_int_operand" "i"))
3528                     (const_int 0)))
3529    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3530         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3531   "TARGET_64BIT && rs6000_gen_cell_microcode"
3532   "*
3533 {
3534   int start = INTVAL (operands[3]) & 63;
3535   int size = INTVAL (operands[2]) & 63;
3536
3537   if (start + size >= 64)
3538     operands[3] = const0_rtx;
3539   else
3540     operands[3] = GEN_INT (start + size);
3541   operands[2] = GEN_INT (64 - size);
3542   return \"rldicl. %0,%1,%3,%2\";
3543 }"
3544   [(set_attr "type" "compare")])
3545
3546 (define_insn "rotlsi3"
3547   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3548         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3549                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
3550   ""
3551   "@
3552    rlwnm %0,%1,%2,0xffffffff
3553    rlwinm %0,%1,%h2,0xffffffff"
3554   [(set_attr "type" "var_shift_rotate,integer")])
3555
3556 (define_insn "*rotlsi3_64"
3557   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3558         (zero_extend:DI
3559             (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3560                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
3561   "TARGET_64BIT"
3562   "@
3563    rlwnm %0,%1,%2,0xffffffff
3564    rlwinm %0,%1,%h2,0xffffffff"
3565   [(set_attr "type" "var_shift_rotate,integer")])
3566
3567 (define_insn "*rotlsi3_internal2"
3568   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3569         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3570                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3571                     (const_int 0)))
3572    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
3573   ""
3574   "@
3575    rlwnm. %3,%1,%2,0xffffffff
3576    rlwinm. %3,%1,%h2,0xffffffff
3577    #
3578    #"
3579   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3580    (set_attr "length" "4,4,8,8")])
3581
3582 (define_split
3583   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3584         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3585                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3586                     (const_int 0)))
3587    (clobber (match_scratch:SI 3 ""))]
3588   "reload_completed"
3589   [(set (match_dup 3)
3590         (rotate:SI (match_dup 1) (match_dup 2)))
3591    (set (match_dup 0)
3592         (compare:CC (match_dup 3)
3593                     (const_int 0)))]
3594   "")
3595
3596 (define_insn "*rotlsi3_internal3"
3597   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3598         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3599                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3600                     (const_int 0)))
3601    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3602         (rotate:SI (match_dup 1) (match_dup 2)))]
3603   ""
3604   "@
3605    rlwnm. %0,%1,%2,0xffffffff
3606    rlwinm. %0,%1,%h2,0xffffffff
3607    #
3608    #"
3609   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3610    (set_attr "length" "4,4,8,8")])
3611
3612 (define_split
3613   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3614         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3615                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3616                     (const_int 0)))
3617    (set (match_operand:SI 0 "gpc_reg_operand" "")
3618         (rotate:SI (match_dup 1) (match_dup 2)))]
3619   "reload_completed"
3620   [(set (match_dup 0)
3621         (rotate:SI (match_dup 1) (match_dup 2)))
3622    (set (match_dup 3)
3623         (compare:CC (match_dup 0)
3624                     (const_int 0)))]
3625   "")
3626
3627 (define_insn "*rotlsi3_internal4"
3628   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3629         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3630                            (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
3631                 (match_operand:SI 3 "mask_operand" "n,n")))]
3632   ""
3633   "@
3634    rlwnm %0,%1,%2,%m3,%M3
3635    rlwinm %0,%1,%h2,%m3,%M3"
3636   [(set_attr "type" "var_shift_rotate,integer")])
3637
3638 (define_insn "*rotlsi3_internal5"
3639   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3640         (compare:CC (and:SI
3641                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3642                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3643                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
3644                     (const_int 0)))
3645    (clobber (match_scratch:SI 4 "=r,r,r,r"))]
3646   ""
3647   "@
3648    rlwnm. %4,%1,%2,%m3,%M3
3649    rlwinm. %4,%1,%h2,%m3,%M3
3650    #
3651    #"
3652   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3653    (set_attr "length" "4,4,8,8")])
3654
3655 (define_split
3656   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3657         (compare:CC (and:SI
3658                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3659                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3660                      (match_operand:SI 3 "mask_operand" ""))
3661                     (const_int 0)))
3662    (clobber (match_scratch:SI 4 ""))]
3663   "reload_completed"
3664   [(set (match_dup 4)
3665         (and:SI (rotate:SI (match_dup 1)
3666                                 (match_dup 2))
3667                      (match_dup 3)))
3668    (set (match_dup 0)
3669         (compare:CC (match_dup 4)
3670                     (const_int 0)))]
3671   "")
3672
3673 (define_insn "*rotlsi3_internal6"
3674   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
3675         (compare:CC (and:SI
3676                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3677                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3678                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
3679                     (const_int 0)))
3680    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3681         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3682   ""
3683   "@
3684    rlwnm. %0,%1,%2,%m3,%M3
3685    rlwinm. %0,%1,%h2,%m3,%M3
3686    #
3687    #"
3688   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3689    (set_attr "length" "4,4,8,8")])
3690
3691 (define_split
3692   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
3693         (compare:CC (and:SI
3694                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3695                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3696                      (match_operand:SI 3 "mask_operand" ""))
3697                     (const_int 0)))
3698    (set (match_operand:SI 0 "gpc_reg_operand" "")
3699         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3700   "reload_completed"
3701   [(set (match_dup 0)
3702         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3703    (set (match_dup 4)
3704         (compare:CC (match_dup 0)
3705                     (const_int 0)))]
3706   "")
3707
3708 (define_insn "*rotlsi3_internal7"
3709   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3710         (zero_extend:SI
3711          (subreg:QI
3712           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3713                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3714   ""
3715   "rlw%I2nm %0,%1,%h2,0xff"
3716   [(set (attr "cell_micro")
3717      (if_then_else (match_operand:SI 2 "const_int_operand" "")
3718         (const_string "not")
3719         (const_string "always")))])
3720
3721 (define_insn "*rotlsi3_internal8"
3722   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3723         (compare:CC (zero_extend:SI
3724                      (subreg:QI
3725                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3726                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
3727                     (const_int 0)))
3728    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
3729   ""
3730   "@
3731    rlwnm. %3,%1,%2,0xff
3732    rlwinm. %3,%1,%h2,0xff
3733    #
3734    #"
3735   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3736    (set_attr "length" "4,4,8,8")])
3737
3738 (define_split
3739   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3740         (compare:CC (zero_extend:SI
3741                      (subreg:QI
3742                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3743                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3744                     (const_int 0)))
3745    (clobber (match_scratch:SI 3 ""))]
3746   "reload_completed"
3747   [(set (match_dup 3)
3748         (zero_extend:SI (subreg:QI
3749                       (rotate:SI (match_dup 1)
3750                                  (match_dup 2)) 0)))
3751    (set (match_dup 0)
3752         (compare:CC (match_dup 3)
3753                     (const_int 0)))]
3754   "")
3755
3756 (define_insn "*rotlsi3_internal9"
3757   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3758         (compare:CC (zero_extend:SI
3759                      (subreg:QI
3760                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3761                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
3762                     (const_int 0)))
3763    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3764         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3765   ""
3766   "@
3767    rlwnm. %0,%1,%2,0xff
3768    rlwinm. %0,%1,%h2,0xff
3769    #
3770    #"
3771   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3772    (set_attr "length" "4,4,8,8")])
3773
3774 (define_split
3775   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3776         (compare:CC (zero_extend:SI
3777                      (subreg:QI
3778                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3779                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3780                     (const_int 0)))
3781    (set (match_operand:SI 0 "gpc_reg_operand" "")
3782         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3783   "reload_completed"
3784   [(set (match_dup 0)
3785         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3786    (set (match_dup 3)
3787         (compare:CC (match_dup 0)
3788                     (const_int 0)))]
3789   "")
3790
3791 (define_insn "*rotlsi3_internal10"
3792   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3793         (zero_extend:SI
3794          (subreg:HI
3795           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3796                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 0)))]
3797   ""
3798   "@
3799    rlwnm %0,%1,%2,0xffff
3800    rlwinm %0,%1,%h2,0xffff"
3801   [(set_attr "type" "var_shift_rotate,integer")])
3802
3803
3804 (define_insn "*rotlsi3_internal11"
3805   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3806         (compare:CC (zero_extend:SI
3807                      (subreg:HI
3808                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3809                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
3810                     (const_int 0)))
3811    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
3812   ""
3813   "@
3814    rlwnm. %3,%1,%2,0xffff
3815    rlwinm. %3,%1,%h2,0xffff
3816    #
3817    #"
3818   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3819    (set_attr "length" "4,4,8,8")])
3820
3821 (define_split
3822   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3823         (compare:CC (zero_extend:SI
3824                      (subreg:HI
3825                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3826                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3827                     (const_int 0)))
3828    (clobber (match_scratch:SI 3 ""))]
3829   "reload_completed"
3830   [(set (match_dup 3)
3831         (zero_extend:SI (subreg:HI
3832                       (rotate:SI (match_dup 1)
3833                                  (match_dup 2)) 0)))
3834    (set (match_dup 0)
3835         (compare:CC (match_dup 3)
3836                     (const_int 0)))]
3837   "")
3838
3839 (define_insn "*rotlsi3_internal12"
3840   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3841         (compare:CC (zero_extend:SI
3842                      (subreg:HI
3843                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3844                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
3845                     (const_int 0)))
3846    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3847         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3848   ""
3849   "@
3850    rlwnm. %0,%1,%2,0xffff
3851    rlwinm. %0,%1,%h2,0xffff
3852    #
3853    #"
3854   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3855    (set_attr "length" "4,4,8,8")])
3856
3857 (define_split
3858   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
3859         (compare:CC (zero_extend:SI
3860                      (subreg:HI
3861                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3862                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3863                     (const_int 0)))
3864    (set (match_operand:SI 0 "gpc_reg_operand" "")
3865         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3866   "reload_completed"
3867   [(set (match_dup 0)
3868         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3869    (set (match_dup 3)
3870         (compare:CC (match_dup 0)
3871                     (const_int 0)))]
3872   "")
3873
3874 (define_insn "ashlsi3"
3875   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3876         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3877                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
3878   ""
3879   "@
3880    slw %0,%1,%2
3881    slwi %0,%1,%h2"
3882   [(set_attr "type" "var_shift_rotate,shift")])
3883
3884 (define_insn "*ashlsi3_64"
3885   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3886         (zero_extend:DI
3887             (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3888                        (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
3889   "TARGET_POWERPC64"
3890   "@
3891    slw %0,%1,%2
3892    slwi %0,%1,%h2"
3893   [(set_attr "type" "var_shift_rotate,shift")])
3894
3895 (define_insn ""
3896   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3897         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3898                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3899                     (const_int 0)))
3900    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
3901   "TARGET_32BIT"
3902   "@
3903    slw. %3,%1,%2
3904    slwi. %3,%1,%h2
3905    #
3906    #"
3907   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3908    (set_attr "length" "4,4,8,8")])
3909
3910 (define_split
3911   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3912         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3913                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3914                     (const_int 0)))
3915    (clobber (match_scratch:SI 3 ""))]
3916   "TARGET_32BIT && reload_completed"
3917   [(set (match_dup 3)
3918         (ashift:SI (match_dup 1) (match_dup 2)))
3919    (set (match_dup 0)
3920         (compare:CC (match_dup 3)
3921                     (const_int 0)))]
3922   "")
3923
3924 (define_insn ""
3925   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3926         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3927                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3928                     (const_int 0)))
3929    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3930         (ashift:SI (match_dup 1) (match_dup 2)))]
3931   "TARGET_32BIT"
3932   "@
3933    slw. %0,%1,%2
3934    slwi. %0,%1,%h2
3935    #
3936    #"
3937   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3938    (set_attr "length" "4,4,8,8")])
3939
3940 (define_split
3941   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3942         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3943                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3944                     (const_int 0)))
3945    (set (match_operand:SI 0 "gpc_reg_operand" "")
3946         (ashift:SI (match_dup 1) (match_dup 2)))]
3947   "TARGET_32BIT && reload_completed"
3948   [(set (match_dup 0)
3949         (ashift:SI (match_dup 1) (match_dup 2)))
3950    (set (match_dup 3)
3951         (compare:CC (match_dup 0)
3952                     (const_int 0)))]
3953   "")
3954
3955 (define_insn "rlwinm"
3956   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3957         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3958                            (match_operand:SI 2 "const_int_operand" "i"))
3959                 (match_operand:SI 3 "mask_operand" "n")))]
3960   "includes_lshift_p (operands[2], operands[3])"
3961   "rlwinm %0,%1,%h2,%m3,%M3")
3962
3963 (define_insn ""
3964   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3965         (compare:CC
3966          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3967                             (match_operand:SI 2 "const_int_operand" "i,i"))
3968                  (match_operand:SI 3 "mask_operand" "n,n"))
3969          (const_int 0)))
3970    (clobber (match_scratch:SI 4 "=r,r"))]
3971   "includes_lshift_p (operands[2], operands[3])"
3972   "@
3973    rlwinm. %4,%1,%h2,%m3,%M3
3974    #"
3975   [(set_attr "type" "delayed_compare")
3976    (set_attr "length" "4,8")])
3977
3978 (define_split
3979   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
3980         (compare:CC
3981          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3982                             (match_operand:SI 2 "const_int_operand" ""))
3983                  (match_operand:SI 3 "mask_operand" ""))
3984          (const_int 0)))
3985    (clobber (match_scratch:SI 4 ""))]
3986   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3987   [(set (match_dup 4)
3988         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
3989                  (match_dup 3)))
3990    (set (match_dup 0)
3991         (compare:CC (match_dup 4)
3992                     (const_int 0)))]
3993   "")
3994
3995 (define_insn ""
3996   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3997         (compare:CC
3998          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3999                             (match_operand:SI 2 "const_int_operand" "i,i"))
4000                  (match_operand:SI 3 "mask_operand" "n,n"))
4001          (const_int 0)))
4002    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4003         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4004   "includes_lshift_p (operands[2], operands[3])"
4005   "@
4006    rlwinm. %0,%1,%h2,%m3,%M3
4007    #"
4008   [(set_attr "type" "delayed_compare")
4009    (set_attr "length" "4,8")])
4010
4011 (define_split
4012   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4013         (compare:CC
4014          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4015                             (match_operand:SI 2 "const_int_operand" ""))
4016                  (match_operand:SI 3 "mask_operand" ""))
4017          (const_int 0)))
4018    (set (match_operand:SI 0 "gpc_reg_operand" "")
4019         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4020   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4021   [(set (match_dup 0)
4022         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4023    (set (match_dup 4)
4024         (compare:CC (match_dup 0)
4025                     (const_int 0)))]
4026   "")
4027
4028 (define_insn "lshrsi3"
4029   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4030         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4031                      (match_operand:SI 2 "reg_or_cint_operand" "O,r,i")))]
4032   ""
4033   "@
4034   mr %0,%1
4035   srw %0,%1,%2
4036   srwi %0,%1,%h2"
4037   [(set_attr "type" "integer,var_shift_rotate,shift")])
4038
4039 (define_insn "*lshrsi3_64"
4040   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4041         (zero_extend:DI
4042             (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4043                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4044   "TARGET_POWERPC64"
4045   "@
4046   srw %0,%1,%2
4047   srwi %0,%1,%h2"
4048   [(set_attr "type" "var_shift_rotate,shift")])
4049
4050 (define_insn ""
4051   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4052         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4053                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
4054                     (const_int 0)))
4055    (clobber (match_scratch:SI 3 "=X,r,r,X,r,r"))]
4056   "TARGET_32BIT"
4057   "@
4058    mr. %1,%1
4059    srw. %3,%1,%2
4060    srwi. %3,%1,%h2
4061    #
4062    #
4063    #"
4064   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4065    (set_attr "length" "4,4,4,8,8,8")])
4066
4067 (define_split
4068   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4069         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4070                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4071                     (const_int 0)))
4072    (clobber (match_scratch:SI 3 ""))]
4073   "TARGET_32BIT && reload_completed"
4074   [(set (match_dup 3)
4075         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4076    (set (match_dup 0)
4077         (compare:CC (match_dup 3)
4078                     (const_int 0)))]
4079   "")
4080
4081 (define_insn ""
4082   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4083         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4084                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
4085                     (const_int 0)))
4086    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
4087         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4088   "TARGET_32BIT"
4089   "@
4090    mr. %0,%1
4091    srw. %0,%1,%2
4092    srwi. %0,%1,%h2
4093    #
4094    #
4095    #"
4096   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4097    (set_attr "length" "4,4,4,8,8,8")])
4098
4099 (define_split
4100   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4101         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4102                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4103                     (const_int 0)))
4104    (set (match_operand:SI 0 "gpc_reg_operand" "")
4105         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4106   "TARGET_32BIT && reload_completed"
4107   [(set (match_dup 0)
4108         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4109    (set (match_dup 3)
4110         (compare:CC (match_dup 0)
4111                     (const_int 0)))]
4112   "")
4113
4114 (define_insn ""
4115   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4116         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4117                              (match_operand:SI 2 "const_int_operand" "i"))
4118                 (match_operand:SI 3 "mask_operand" "n")))]
4119   "includes_rshift_p (operands[2], operands[3])"
4120   "rlwinm %0,%1,%s2,%m3,%M3")
4121
4122 (define_insn ""
4123   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4124         (compare:CC
4125          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4126                               (match_operand:SI 2 "const_int_operand" "i,i"))
4127                  (match_operand:SI 3 "mask_operand" "n,n"))
4128          (const_int 0)))
4129    (clobber (match_scratch:SI 4 "=r,r"))]
4130   "includes_rshift_p (operands[2], operands[3])"
4131   "@
4132    rlwinm. %4,%1,%s2,%m3,%M3
4133    #"
4134   [(set_attr "type" "delayed_compare")
4135    (set_attr "length" "4,8")])
4136
4137 (define_split
4138   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4139         (compare:CC
4140          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4141                               (match_operand:SI 2 "const_int_operand" ""))
4142                  (match_operand:SI 3 "mask_operand" ""))
4143          (const_int 0)))
4144    (clobber (match_scratch:SI 4 ""))]
4145   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4146   [(set (match_dup 4)
4147         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4148                  (match_dup 3)))
4149    (set (match_dup 0)
4150         (compare:CC (match_dup 4)
4151                     (const_int 0)))]
4152   "")
4153
4154 (define_insn ""
4155   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4156         (compare:CC
4157          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4158                               (match_operand:SI 2 "const_int_operand" "i,i"))
4159                  (match_operand:SI 3 "mask_operand" "n,n"))
4160          (const_int 0)))
4161    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4162         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4163   "includes_rshift_p (operands[2], operands[3])"
4164   "@
4165    rlwinm. %0,%1,%s2,%m3,%M3
4166    #"
4167   [(set_attr "type" "delayed_compare")
4168    (set_attr "length" "4,8")])
4169
4170 (define_split
4171   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
4172         (compare:CC
4173          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4174                               (match_operand:SI 2 "const_int_operand" ""))
4175                  (match_operand:SI 3 "mask_operand" ""))
4176          (const_int 0)))
4177    (set (match_operand:SI 0 "gpc_reg_operand" "")
4178         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4179   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4180   [(set (match_dup 0)
4181         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4182    (set (match_dup 4)
4183         (compare:CC (match_dup 0)
4184                     (const_int 0)))]
4185   "")
4186
4187 (define_insn ""
4188   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4189         (zero_extend:SI
4190          (subreg:QI
4191           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4192                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4193   "includes_rshift_p (operands[2], GEN_INT (255))"
4194   "rlwinm %0,%1,%s2,0xff")
4195
4196 (define_insn ""
4197   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4198         (compare:CC
4199          (zero_extend:SI
4200           (subreg:QI
4201            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4202                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4203          (const_int 0)))
4204    (clobber (match_scratch:SI 3 "=r,r"))]
4205   "includes_rshift_p (operands[2], GEN_INT (255))"
4206   "@
4207    rlwinm. %3,%1,%s2,0xff
4208    #"
4209   [(set_attr "type" "delayed_compare")
4210    (set_attr "length" "4,8")])
4211
4212 (define_split
4213   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4214         (compare:CC
4215          (zero_extend:SI
4216           (subreg:QI
4217            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4218                         (match_operand:SI 2 "const_int_operand" "")) 0))
4219          (const_int 0)))
4220    (clobber (match_scratch:SI 3 ""))]
4221   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4222   [(set (match_dup 3)
4223         (zero_extend:SI (subreg:QI
4224            (lshiftrt:SI (match_dup 1)
4225                         (match_dup 2)) 0)))
4226    (set (match_dup 0)
4227         (compare:CC (match_dup 3)
4228                     (const_int 0)))]
4229   "")
4230
4231 (define_insn ""
4232   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4233         (compare:CC
4234          (zero_extend:SI
4235           (subreg:QI
4236            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4237                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4238          (const_int 0)))
4239    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4240         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4241   "includes_rshift_p (operands[2], GEN_INT (255))"
4242   "@
4243    rlwinm. %0,%1,%s2,0xff
4244    #"
4245   [(set_attr "type" "delayed_compare")
4246    (set_attr "length" "4,8")])
4247
4248 (define_split
4249   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4250         (compare:CC
4251          (zero_extend:SI
4252           (subreg:QI
4253            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4254                         (match_operand:SI 2 "const_int_operand" "")) 0))
4255          (const_int 0)))
4256    (set (match_operand:SI 0 "gpc_reg_operand" "")
4257         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4258   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4259   [(set (match_dup 0)
4260         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4261    (set (match_dup 3)
4262         (compare:CC (match_dup 0)
4263                     (const_int 0)))]
4264   "")
4265
4266 (define_insn ""
4267   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4268         (zero_extend:SI
4269          (subreg:HI
4270           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4271                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4272   "includes_rshift_p (operands[2], GEN_INT (65535))"
4273   "rlwinm %0,%1,%s2,0xffff")
4274
4275 (define_insn ""
4276   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4277         (compare:CC
4278          (zero_extend:SI
4279           (subreg:HI
4280            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4281                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4282          (const_int 0)))
4283    (clobber (match_scratch:SI 3 "=r,r"))]
4284   "includes_rshift_p (operands[2], GEN_INT (65535))"
4285   "@
4286    rlwinm. %3,%1,%s2,0xffff
4287    #"
4288   [(set_attr "type" "delayed_compare")
4289    (set_attr "length" "4,8")])
4290
4291 (define_split
4292   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4293         (compare:CC
4294          (zero_extend:SI
4295           (subreg:HI
4296            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4297                         (match_operand:SI 2 "const_int_operand" "")) 0))
4298          (const_int 0)))
4299    (clobber (match_scratch:SI 3 ""))]
4300   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4301   [(set (match_dup 3)
4302         (zero_extend:SI (subreg:HI
4303            (lshiftrt:SI (match_dup 1)
4304                         (match_dup 2)) 0)))
4305    (set (match_dup 0)
4306         (compare:CC (match_dup 3)
4307                     (const_int 0)))]
4308   "")
4309
4310 (define_insn ""
4311   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4312         (compare:CC
4313          (zero_extend:SI
4314           (subreg:HI
4315            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4316                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4317          (const_int 0)))
4318    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4319         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4320   "includes_rshift_p (operands[2], GEN_INT (65535))"
4321   "@
4322    rlwinm. %0,%1,%s2,0xffff
4323    #"
4324   [(set_attr "type" "delayed_compare")
4325    (set_attr "length" "4,8")])
4326
4327 (define_split
4328   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4329         (compare:CC
4330          (zero_extend:SI
4331           (subreg:HI
4332            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4333                         (match_operand:SI 2 "const_int_operand" "")) 0))
4334          (const_int 0)))
4335    (set (match_operand:SI 0 "gpc_reg_operand" "")
4336         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4337   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4338   [(set (match_dup 0)
4339         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4340    (set (match_dup 3)
4341         (compare:CC (match_dup 0)
4342                     (const_int 0)))]
4343   "")
4344
4345 (define_insn "ashrsi3"
4346   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4347         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4348                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4349   ""
4350   "@
4351    sraw %0,%1,%2
4352    srawi %0,%1,%h2"
4353   [(set_attr "type" "var_shift_rotate,shift")])
4354
4355 (define_insn "*ashrsi3_64"
4356   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4357         (sign_extend:DI
4358             (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4359                          (match_operand:SI 2 "reg_or_cint_operand" "r,i"))))]
4360   "TARGET_POWERPC64"
4361   "@
4362    sraw %0,%1,%2
4363    srawi %0,%1,%h2"
4364   [(set_attr "type" "var_shift_rotate,shift")])
4365
4366 (define_insn ""
4367   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4368         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4369                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4370                     (const_int 0)))
4371    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4372   ""
4373   "@
4374    sraw. %3,%1,%2
4375    srawi. %3,%1,%h2
4376    #
4377    #"
4378   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4379    (set_attr "length" "4,4,8,8")])
4380
4381 (define_split
4382   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
4383         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4384                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4385                     (const_int 0)))
4386    (clobber (match_scratch:SI 3 ""))]
4387   "reload_completed"
4388   [(set (match_dup 3)
4389         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4390    (set (match_dup 0)
4391         (compare:CC (match_dup 3)
4392                     (const_int 0)))]
4393   "")
4394
4395 (define_insn ""
4396   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4397         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4398                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4399                     (const_int 0)))
4400    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4401         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4402   ""
4403   "@
4404    sraw. %0,%1,%2
4405    srawi. %0,%1,%h2
4406    #
4407    #"
4408   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4409    (set_attr "length" "4,4,8,8")])
4410 \f
4411 ;; Builtins to replace a division to generate FRE reciprocal estimate
4412 ;; instructions and the necessary fixup instructions
4413 (define_expand "recip<mode>3"
4414   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
4415    (match_operand:RECIPF 1 "gpc_reg_operand" "")
4416    (match_operand:RECIPF 2 "gpc_reg_operand" "")]
4417   "RS6000_RECIP_HAVE_RE_P (<MODE>mode)"
4418 {
4419    rs6000_emit_swdiv (operands[0], operands[1], operands[2], false);
4420    DONE;
4421 })
4422
4423 ;; Split to create division from FRE/FRES/etc. and fixup instead of the normal
4424 ;; hardware division.  This is only done before register allocation and with
4425 ;; -ffast-math.  This must appear before the divsf3/divdf3 insns.
4426 (define_split
4427   [(set (match_operand:RECIPF 0 "gpc_reg_operand" "")
4428         (div:RECIPF (match_operand 1 "gpc_reg_operand" "")
4429                     (match_operand 2 "gpc_reg_operand" "")))]
4430   "RS6000_RECIP_AUTO_RE_P (<MODE>mode)
4431    && can_create_pseudo_p () && optimize_insn_for_speed_p ()
4432    && flag_finite_math_only && !flag_trapping_math && flag_reciprocal_math"
4433   [(const_int 0)]
4434 {
4435   rs6000_emit_swdiv (operands[0], operands[1], operands[2], true);
4436   DONE;
4437 })
4438
4439 ;; Builtins to replace 1/sqrt(x) with instructions using RSQRTE and the
4440 ;; appropriate fixup.
4441 (define_expand "rsqrt<mode>2"
4442   [(match_operand:RECIPF 0 "gpc_reg_operand" "")
4443    (match_operand:RECIPF 1 "gpc_reg_operand" "")]
4444   "RS6000_RECIP_HAVE_RSQRTE_P (<MODE>mode)"
4445 {
4446   rs6000_emit_swrsqrt (operands[0], operands[1]);
4447   DONE;
4448 })
4449 \f
4450 (define_split
4451   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
4452         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4453                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4454                     (const_int 0)))
4455    (set (match_operand:SI 0 "gpc_reg_operand" "")
4456         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4457   "reload_completed"
4458   [(set (match_dup 0)
4459         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4460    (set (match_dup 3)
4461         (compare:CC (match_dup 0)
4462                     (const_int 0)))]
4463   "")
4464
4465 ;; Floating-point insns, excluding normal data motion.
4466 ;;
4467 ;; PowerPC has a full set of single-precision floating point instructions.
4468 ;;
4469 ;; For the POWER architecture, we pretend that we have both SFmode and
4470 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
4471 ;; The only conversions we will do will be when storing to memory.  In that
4472 ;; case, we will use the "frsp" instruction before storing.
4473 ;;
4474 ;; Note that when we store into a single-precision memory location, we need to
4475 ;; use the frsp insn first.  If the register being stored isn't dead, we
4476 ;; need a scratch register for the frsp.  But this is difficult when the store
4477 ;; is done by reload.  It is not incorrect to do the frsp on the register in
4478 ;; this case, we just lose precision that we would have otherwise gotten but
4479 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
4480
4481 (define_expand "extendsfdf2"
4482   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4483         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
4484   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
4485   "")
4486
4487 (define_insn_and_split "*extendsfdf2_fpr"
4488   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d,d")
4489         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m")))]
4490   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
4491   "@
4492    #
4493    fmr %0,%1
4494    lfs%U1%X1 %0,%1"
4495   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
4496   [(const_int 0)]
4497 {
4498   emit_note (NOTE_INSN_DELETED);
4499   DONE;
4500 }
4501   [(set_attr "type" "fp,fp,fpload")])
4502
4503 (define_expand "truncdfsf2"
4504   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4505         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
4506   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
4507   "")
4508
4509 (define_insn "*truncdfsf2_fpr"
4510   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4511         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "d")))]
4512   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
4513   "frsp %0,%1"
4514   [(set_attr "type" "fp")])
4515
4516 (define_expand "negsf2"
4517   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4518         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4519   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
4520   "")
4521
4522 (define_insn "*negsf2"
4523   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4524         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4525   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4526   "fneg %0,%1"
4527   [(set_attr "type" "fp")])
4528
4529 (define_expand "abssf2"
4530   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4531         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4532   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
4533   "")
4534
4535 (define_insn "*abssf2"
4536   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4537         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4538   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4539   "fabs %0,%1"
4540   [(set_attr "type" "fp")])
4541
4542 (define_insn ""
4543   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4544         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
4545   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4546   "fnabs %0,%1"
4547   [(set_attr "type" "fp")])
4548
4549 (define_expand "addsf3"
4550   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4551         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4552                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4553   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
4554   "")
4555
4556 (define_insn ""
4557   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4558         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4559                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4560   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4561   "fadds %0,%1,%2"
4562   [(set_attr "type" "fp")
4563    (set_attr "fp_type" "fp_addsub_s")])
4564
4565 (define_expand "subsf3"
4566   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4567         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4568                   (match_operand:SF 2 "gpc_reg_operand" "")))]
4569   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
4570   "")
4571
4572 (define_insn ""
4573   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4574         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4575                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4576   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4577   "fsubs %0,%1,%2"
4578   [(set_attr "type" "fp")
4579    (set_attr "fp_type" "fp_addsub_s")])
4580
4581 (define_expand "mulsf3"
4582   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4583         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
4584                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4585   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT"
4586   "")
4587
4588 (define_insn ""
4589   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4590         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4591                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4592   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4593   "fmuls %0,%1,%2"
4594   [(set_attr "type" "fp")
4595    (set_attr "fp_type" "fp_mul_s")])
4596
4597 (define_expand "divsf3"
4598   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4599         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
4600                 (match_operand:SF 2 "gpc_reg_operand" "")))]
4601   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
4602   "")
4603
4604 (define_insn ""
4605   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4606         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4607                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4608   "TARGET_HARD_FLOAT && TARGET_FPRS
4609    && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
4610   "fdivs %0,%1,%2"
4611   [(set_attr "type" "sdiv")])
4612
4613 (define_insn "fres"
4614   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4615         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
4616   "TARGET_FRES"
4617   "fres %0,%1"
4618   [(set_attr "type" "fp")])
4619
4620 ; builtin fmaf support
4621 (define_insn "*fmasf4_fpr"
4622   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4623         (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4624                 (match_operand:SF 2 "gpc_reg_operand" "f")
4625                 (match_operand:SF 3 "gpc_reg_operand" "f")))]
4626   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4627   "fmadds %0,%1,%2,%3"
4628   [(set_attr "type" "fp")
4629    (set_attr "fp_type" "fp_maddsub_s")])
4630
4631 (define_insn "*fmssf4_fpr"
4632   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4633         (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4634                 (match_operand:SF 2 "gpc_reg_operand" "f")
4635                 (neg:SF (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4636   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4637   "fmsubs %0,%1,%2,%3"
4638   [(set_attr "type" "fp")
4639    (set_attr "fp_type" "fp_maddsub_s")])
4640
4641 (define_insn "*nfmasf4_fpr"
4642   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4643         (neg:SF (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4644                         (match_operand:SF 2 "gpc_reg_operand" "f")
4645                         (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4646   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4647   "fnmadds %0,%1,%2,%3"
4648   [(set_attr "type" "fp")
4649    (set_attr "fp_type" "fp_maddsub_s")])
4650
4651 (define_insn "*nfmssf4_fpr"
4652   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4653         (neg:SF (fma:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4654                         (match_operand:SF 2 "gpc_reg_operand" "f")
4655                         (neg:SF (match_operand:SF 3 "gpc_reg_operand" "f")))))]
4656   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4657   "fnmsubs %0,%1,%2,%3"
4658   [(set_attr "type" "fp")
4659    (set_attr "fp_type" "fp_maddsub_s")])
4660
4661 (define_expand "sqrtsf2"
4662   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4663         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4664   "(TARGET_PPC_GPOPT || TARGET_XILINX_FPU)
4665    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
4666    && !TARGET_SIMPLE_FPU"
4667   "")
4668
4669 (define_insn ""
4670   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4671         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4672   "(TARGET_PPC_GPOPT || TARGET_XILINX_FPU) && TARGET_HARD_FLOAT
4673    && TARGET_FPRS && TARGET_SINGLE_FLOAT && !TARGET_SIMPLE_FPU"
4674   "fsqrts %0,%1"
4675   [(set_attr "type" "ssqrt")])
4676
4677 (define_insn "*rsqrtsf_internal1"
4678   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4679         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")]
4680                    UNSPEC_RSQRT))]
4681   "TARGET_FRSQRTES"
4682   "frsqrtes %0,%1"
4683   [(set_attr "type" "fp")])
4684
4685 (define_expand "copysign<mode>3"
4686   [(set (match_dup 3)
4687         (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "")))
4688    (set (match_dup 4)
4689         (neg:SFDF (abs:SFDF (match_dup 1))))
4690    (set (match_operand:SFDF 0 "gpc_reg_operand" "")
4691         (if_then_else:SFDF (ge (match_operand:SFDF 2 "gpc_reg_operand" "")
4692                                (match_dup 5))
4693                          (match_dup 3)
4694                          (match_dup 4)))]
4695   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
4696    && ((TARGET_PPC_GFXOPT
4697         && !HONOR_NANS (<MODE>mode)
4698         && !HONOR_SIGNED_ZEROS (<MODE>mode))
4699        || TARGET_CMPB
4700        || VECTOR_UNIT_VSX_P (<MODE>mode))"
4701 {
4702   if (TARGET_CMPB || VECTOR_UNIT_VSX_P (<MODE>mode))
4703     {
4704       emit_insn (gen_copysign<mode>3_fcpsgn (operands[0], operands[1],
4705                                              operands[2]));
4706       DONE;
4707     }
4708
4709    operands[3] = gen_reg_rtx (<MODE>mode);
4710    operands[4] = gen_reg_rtx (<MODE>mode);
4711    operands[5] = CONST0_RTX (<MODE>mode);
4712   })
4713
4714 ;; Use an unspec rather providing an if-then-else in RTL, to prevent the
4715 ;; compiler from optimizing -0.0
4716 (define_insn "copysign<mode>3_fcpsgn"
4717   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
4718         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")
4719                       (match_operand:SFDF 2 "gpc_reg_operand" "<rreg2>")]
4720                      UNSPEC_COPYSIGN))]
4721   "TARGET_CMPB && !VECTOR_UNIT_VSX_P (<MODE>mode)"
4722   "fcpsgn %0,%2,%1"
4723   [(set_attr "type" "fp")])
4724
4725 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
4726 ;; fsel instruction and some auxiliary computations.  Then we just have a
4727 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
4728 ;; combine.
4729 (define_expand "smaxsf3"
4730   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4731         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4732                              (match_operand:SF 2 "gpc_reg_operand" ""))
4733                          (match_dup 1)
4734                          (match_dup 2)))]
4735   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
4736    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
4737   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
4738
4739 (define_expand "sminsf3"
4740   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4741         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4742                              (match_operand:SF 2 "gpc_reg_operand" ""))
4743                          (match_dup 2)
4744                          (match_dup 1)))]
4745   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
4746    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
4747   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
4748
4749 (define_split
4750   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4751         (match_operator:SF 3 "min_max_operator"
4752          [(match_operand:SF 1 "gpc_reg_operand" "")
4753           (match_operand:SF 2 "gpc_reg_operand" "")]))]
4754   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS 
4755    && TARGET_SINGLE_FLOAT && !flag_trapping_math"
4756   [(const_int 0)]
4757   "
4758 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
4759                       operands[1], operands[2]);
4760   DONE;
4761 }")
4762
4763 (define_expand "mov<mode>cc"
4764    [(set (match_operand:GPR 0 "gpc_reg_operand" "")
4765          (if_then_else:GPR (match_operand 1 "comparison_operator" "")
4766                            (match_operand:GPR 2 "gpc_reg_operand" "")
4767                            (match_operand:GPR 3 "gpc_reg_operand" "")))]
4768   "TARGET_ISEL<sel>"
4769   "
4770 {
4771   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4772     DONE;
4773   else
4774     FAIL;
4775 }")
4776
4777 ;; We use the BASE_REGS for the isel input operands because, if rA is
4778 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
4779 ;; because we may switch the operands and rB may end up being rA.
4780 ;;
4781 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
4782 ;; leave out the mode in operand 4 and use one pattern, but reload can
4783 ;; change the mode underneath our feet and then gets confused trying
4784 ;; to reload the value.
4785 (define_insn "isel_signed_<mode>"
4786   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
4787         (if_then_else:GPR
4788          (match_operator 1 "scc_comparison_operator"
4789                          [(match_operand:CC 4 "cc_reg_operand" "y,y")
4790                           (const_int 0)])
4791          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
4792          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
4793   "TARGET_ISEL<sel>"
4794   "*
4795 { return output_isel (operands); }"
4796   [(set_attr "type" "isel")
4797    (set_attr "length" "4")])
4798
4799 (define_insn "isel_unsigned_<mode>"
4800   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
4801         (if_then_else:GPR
4802          (match_operator 1 "scc_comparison_operator"
4803                          [(match_operand:CCUNS 4 "cc_reg_operand" "y,y")
4804                           (const_int 0)])
4805          (match_operand:GPR 2 "reg_or_cint_operand" "O,b")
4806          (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
4807   "TARGET_ISEL<sel>"
4808   "*
4809 { return output_isel (operands); }"
4810   [(set_attr "type" "isel")
4811    (set_attr "length" "4")])
4812
4813 ;; These patterns can be useful for combine; they let combine know that
4814 ;; isel can handle reversed comparisons so long as the operands are
4815 ;; registers.
4816
4817 (define_insn "*isel_reversed_signed_<mode>"
4818   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4819         (if_then_else:GPR
4820          (match_operator 1 "scc_rev_comparison_operator"
4821                          [(match_operand:CC 4 "cc_reg_operand" "y")
4822                           (const_int 0)])
4823          (match_operand:GPR 2 "gpc_reg_operand" "b")
4824          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
4825   "TARGET_ISEL<sel>"
4826   "*
4827 { return output_isel (operands); }"
4828   [(set_attr "type" "isel")
4829    (set_attr "length" "4")])
4830
4831 (define_insn "*isel_reversed_unsigned_<mode>"
4832   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4833         (if_then_else:GPR
4834          (match_operator 1 "scc_rev_comparison_operator"
4835                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
4836                           (const_int 0)])
4837          (match_operand:GPR 2 "gpc_reg_operand" "b")
4838          (match_operand:GPR 3 "gpc_reg_operand" "b")))]
4839   "TARGET_ISEL<sel>"
4840   "*
4841 { return output_isel (operands); }"
4842   [(set_attr "type" "isel")
4843    (set_attr "length" "4")])
4844
4845 (define_expand "movsfcc"
4846    [(set (match_operand:SF 0 "gpc_reg_operand" "")
4847          (if_then_else:SF (match_operand 1 "comparison_operator" "")
4848                           (match_operand:SF 2 "gpc_reg_operand" "")
4849                           (match_operand:SF 3 "gpc_reg_operand" "")))]
4850   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4851   "
4852 {
4853   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4854     DONE;
4855   else
4856     FAIL;
4857 }")
4858
4859 (define_insn "*fselsfsf4"
4860   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4861         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
4862                              (match_operand:SF 4 "zero_fp_constant" "F"))
4863                          (match_operand:SF 2 "gpc_reg_operand" "f")
4864                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4865   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
4866   "fsel %0,%1,%2,%3"
4867   [(set_attr "type" "fp")])
4868
4869 (define_insn "*fseldfsf4"
4870   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4871         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
4872                              (match_operand:DF 4 "zero_fp_constant" "F"))
4873                          (match_operand:SF 2 "gpc_reg_operand" "f")
4874                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4875   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
4876   "fsel %0,%1,%2,%3"
4877   [(set_attr "type" "fp")])
4878
4879 (define_expand "negdf2"
4880   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4881         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
4882   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
4883   "")
4884
4885 (define_insn "*negdf2_fpr"
4886   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
4887         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
4888   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
4889    && !VECTOR_UNIT_VSX_P (DFmode)"
4890   "fneg %0,%1"
4891   [(set_attr "type" "fp")])
4892
4893 (define_expand "absdf2"
4894   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4895         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
4896   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
4897   "")
4898
4899 (define_insn "*absdf2_fpr"
4900   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
4901         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
4902   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
4903    && !VECTOR_UNIT_VSX_P (DFmode)"
4904   "fabs %0,%1"
4905   [(set_attr "type" "fp")])
4906
4907 (define_insn "*nabsdf2_fpr"
4908   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
4909         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "d"))))]
4910   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
4911    && !VECTOR_UNIT_VSX_P (DFmode)"
4912   "fnabs %0,%1"
4913   [(set_attr "type" "fp")])
4914
4915 (define_expand "adddf3"
4916   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4917         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "")
4918                  (match_operand:DF 2 "gpc_reg_operand" "")))]
4919   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
4920   "")
4921
4922 (define_insn "*adddf3_fpr"
4923   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
4924         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
4925                  (match_operand:DF 2 "gpc_reg_operand" "d")))]
4926   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
4927    && !VECTOR_UNIT_VSX_P (DFmode)"
4928   "fadd %0,%1,%2"
4929   [(set_attr "type" "fp")
4930    (set_attr "fp_type" "fp_addsub_d")])
4931
4932 (define_expand "subdf3"
4933   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4934         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
4935                   (match_operand:DF 2 "gpc_reg_operand" "")))]
4936   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
4937   "")
4938
4939 (define_insn "*subdf3_fpr"
4940   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
4941         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "d")
4942                   (match_operand:DF 2 "gpc_reg_operand" "d")))]
4943   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
4944    && !VECTOR_UNIT_VSX_P (DFmode)"
4945   "fsub %0,%1,%2"
4946   [(set_attr "type" "fp")
4947    (set_attr "fp_type" "fp_addsub_d")])
4948
4949 (define_expand "muldf3"
4950   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4951         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "")
4952                  (match_operand:DF 2 "gpc_reg_operand" "")))]
4953   "TARGET_HARD_FLOAT && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
4954   "")
4955
4956 (define_insn "*muldf3_fpr"
4957   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
4958         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%d")
4959                  (match_operand:DF 2 "gpc_reg_operand" "d")))]
4960   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
4961    && !VECTOR_UNIT_VSX_P (DFmode)"
4962   "fmul %0,%1,%2"
4963   [(set_attr "type" "dmul")
4964    (set_attr "fp_type" "fp_mul_d")])
4965
4966 (define_expand "divdf3"
4967   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4968         (div:DF (match_operand:DF 1 "gpc_reg_operand" "")
4969                 (match_operand:DF 2 "gpc_reg_operand" "")))]
4970   "TARGET_HARD_FLOAT
4971    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)
4972    && !TARGET_SIMPLE_FPU"
4973   "")
4974
4975 (define_insn "*divdf3_fpr"
4976   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
4977         (div:DF (match_operand:DF 1 "gpc_reg_operand" "d")
4978                 (match_operand:DF 2 "gpc_reg_operand" "d")))]
4979   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && !TARGET_SIMPLE_FPU
4980    && !VECTOR_UNIT_VSX_P (DFmode)"
4981   "fdiv %0,%1,%2"
4982   [(set_attr "type" "ddiv")])
4983
4984 (define_insn "*fred_fpr"
4985   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4986         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
4987   "TARGET_FRE && !VECTOR_UNIT_VSX_P (DFmode)"
4988   "fre %0,%1"
4989   [(set_attr "type" "fp")])
4990
4991 (define_insn "*rsqrtdf_internal1"
4992   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
4993         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "d")]
4994                    UNSPEC_RSQRT))]
4995   "TARGET_FRSQRTE && !VECTOR_UNIT_VSX_P (DFmode)"
4996   "frsqrte %0,%1"
4997   [(set_attr "type" "fp")])
4998
4999 ; builtin fma support
5000 (define_insn "*fmadf4_fpr"
5001   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5002         (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5003                 (match_operand:DF 2 "gpc_reg_operand" "f")
5004                 (match_operand:DF 3 "gpc_reg_operand" "f")))]
5005   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5006    && VECTOR_UNIT_NONE_P (DFmode)"
5007   "fmadd %0,%1,%2,%3"
5008   [(set_attr "type" "fp")
5009    (set_attr "fp_type" "fp_maddsub_d")])
5010
5011 (define_insn "*fmsdf4_fpr"
5012   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5013         (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5014                 (match_operand:DF 2 "gpc_reg_operand" "f")
5015                 (neg:DF (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5016   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5017    && VECTOR_UNIT_NONE_P (DFmode)"
5018   "fmsub %0,%1,%2,%3"
5019   [(set_attr "type" "fp")
5020    (set_attr "fp_type" "fp_maddsub_d")])
5021
5022 (define_insn "*nfmadf4_fpr"
5023   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5024         (neg:DF (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5025                         (match_operand:DF 2 "gpc_reg_operand" "f")
5026                         (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5027   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5028    && VECTOR_UNIT_NONE_P (DFmode)"
5029   "fnmadd %0,%1,%2,%3"
5030   [(set_attr "type" "fp")
5031    (set_attr "fp_type" "fp_maddsub_d")])
5032
5033 (define_insn "*nfmsdf4_fpr"
5034   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5035         (neg:DF (fma:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5036                         (match_operand:DF 2 "gpc_reg_operand" "f")
5037                         (neg:DF (match_operand:DF 3 "gpc_reg_operand" "f")))))]
5038   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5039    && VECTOR_UNIT_NONE_P (DFmode)"
5040   "fnmsub %0,%1,%2,%3"
5041   [(set_attr "type" "fp")
5042    (set_attr "fp_type" "fp_maddsub_d")])
5043
5044 (define_expand "sqrtdf2"
5045   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5046         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
5047   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5048   "")
5049
5050 (define_insn "*sqrtdf2_fpr"
5051   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5052         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "d")))]
5053   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5054    && !VECTOR_UNIT_VSX_P (DFmode)"
5055   "fsqrt %0,%1"
5056   [(set_attr "type" "dsqrt")])
5057
5058 ;; The conditional move instructions allow us to perform max and min
5059 ;; operations even when
5060
5061 (define_expand "smaxdf3"
5062   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5063         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5064                              (match_operand:DF 2 "gpc_reg_operand" ""))
5065                          (match_dup 1)
5066                          (match_dup 2)))]
5067   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
5068    && !flag_trapping_math"
5069   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5070
5071 (define_expand "smindf3"
5072   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5073         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5074                              (match_operand:DF 2 "gpc_reg_operand" ""))
5075                          (match_dup 2)
5076                          (match_dup 1)))]
5077   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
5078    && !flag_trapping_math"
5079   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5080
5081 (define_split
5082   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5083         (match_operator:DF 3 "min_max_operator"
5084          [(match_operand:DF 1 "gpc_reg_operand" "")
5085           (match_operand:DF 2 "gpc_reg_operand" "")]))]
5086   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
5087    && !flag_trapping_math"
5088   [(const_int 0)]
5089   "
5090 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5091                       operands[1], operands[2]);
5092   DONE;
5093 }")
5094
5095 (define_expand "movdfcc"
5096    [(set (match_operand:DF 0 "gpc_reg_operand" "")
5097          (if_then_else:DF (match_operand 1 "comparison_operator" "")
5098                           (match_operand:DF 2 "gpc_reg_operand" "")
5099                           (match_operand:DF 3 "gpc_reg_operand" "")))]
5100   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5101   "
5102 {
5103   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5104     DONE;
5105   else
5106     FAIL;
5107 }")
5108
5109 (define_insn "*fseldfdf4"
5110   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5111         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "d")
5112                              (match_operand:DF 4 "zero_fp_constant" "F"))
5113                          (match_operand:DF 2 "gpc_reg_operand" "d")
5114                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
5115   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5116   "fsel %0,%1,%2,%3"
5117   [(set_attr "type" "fp")])
5118
5119 (define_insn "*fselsfdf4"
5120   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5121         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5122                              (match_operand:SF 4 "zero_fp_constant" "F"))
5123                          (match_operand:DF 2 "gpc_reg_operand" "d")
5124                          (match_operand:DF 3 "gpc_reg_operand" "d")))]
5125   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_SINGLE_FLOAT"
5126   "fsel %0,%1,%2,%3"
5127   [(set_attr "type" "fp")])
5128 \f
5129 ;; Conversions to and from floating-point.
5130
5131 ; We don't define lfiwax/lfiwzx with the normal definition, because we
5132 ; don't want to support putting SImode in FPR registers.
5133 (define_insn "lfiwax"
5134   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
5135         (unspec:DI [(match_operand:SI 1 "indexed_or_indirect_operand" "Z")]
5136                    UNSPEC_LFIWAX))]
5137   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX"
5138   "lfiwax %0,%y1"
5139   [(set_attr "type" "fpload")])
5140
5141 ; This split must be run before register allocation because it allocates the
5142 ; memory slot that is needed to move values to/from the FPR.  We don't allocate
5143 ; it earlier to allow for the combiner to merge insns together where it might
5144 ; not be needed and also in case the insns are deleted as dead code.
5145
5146 (define_insn_and_split "floatsi<mode>2_lfiwax"
5147   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5148         (float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r")))
5149    (clobber (match_scratch:DI 2 "=d"))]
5150   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
5151    && <SI_CONVERT_FP> && can_create_pseudo_p ()"
5152   "#"
5153   ""
5154   [(pc)]
5155   "
5156 {
5157   rtx dest = operands[0];
5158   rtx src = operands[1];
5159   rtx tmp;
5160
5161   if (!MEM_P (src) && TARGET_MFPGPR && TARGET_POWERPC64)
5162     tmp = convert_to_mode (DImode, src, false);
5163   else
5164     {
5165       tmp = operands[2];
5166       if (GET_CODE (tmp) == SCRATCH)
5167         tmp = gen_reg_rtx (DImode);
5168       if (MEM_P (src))
5169         {
5170           src = rs6000_address_for_fpconvert (src);
5171           emit_insn (gen_lfiwax (tmp, src));
5172         }
5173       else
5174         {
5175           rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5176           emit_move_insn (stack, src);
5177           emit_insn (gen_lfiwax (tmp, stack));
5178         }
5179     }
5180   emit_insn (gen_floatdi<mode>2 (dest, tmp));
5181   DONE;
5182 }"
5183   [(set_attr "length" "12")
5184    (set_attr "type" "fpload")])
5185
5186 (define_insn_and_split "floatsi<mode>2_lfiwax_mem"
5187   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,<rreg2>")
5188         (float:SFDF
5189          (sign_extend:DI
5190           (match_operand:SI 1 "memory_operand" "Z,Z"))))
5191    (clobber (match_scratch:DI 2 "=0,d"))]
5192   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWAX
5193    && <SI_CONVERT_FP>"
5194   "#"
5195   ""
5196   [(pc)]
5197   "
5198 {
5199   operands[1] = rs6000_address_for_fpconvert (operands[1]);
5200   if (GET_CODE (operands[2]) == SCRATCH)
5201     operands[2] = gen_reg_rtx (DImode);
5202   emit_insn (gen_lfiwax (operands[2], operands[1]));
5203   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
5204   DONE;
5205 }"
5206   [(set_attr "length" "8")
5207    (set_attr "type" "fpload")])
5208
5209 (define_insn "lfiwzx"
5210   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
5211         (unspec:DI [(match_operand:SI 1 "indexed_or_indirect_operand" "Z")]
5212                    UNSPEC_LFIWZX))]
5213   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX"
5214   "lfiwzx %0,%y1"
5215   [(set_attr "type" "fpload")])
5216
5217 (define_insn_and_split "floatunssi<mode>2_lfiwzx"
5218   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5219         (unsigned_float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r")))
5220    (clobber (match_scratch:DI 2 "=d"))]
5221   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
5222    && <SI_CONVERT_FP>"
5223   "#"
5224   ""
5225   [(pc)]
5226   "
5227 {
5228   rtx dest = operands[0];
5229   rtx src = operands[1];
5230   rtx tmp;
5231
5232   if (!MEM_P (src) && TARGET_MFPGPR && TARGET_POWERPC64)
5233     tmp = convert_to_mode (DImode, src, true);
5234   else
5235     {
5236       tmp = operands[2];
5237       if (GET_CODE (tmp) == SCRATCH)
5238         tmp = gen_reg_rtx (DImode);
5239       if (MEM_P (src))
5240         {
5241           src = rs6000_address_for_fpconvert (src);
5242           emit_insn (gen_lfiwzx (tmp, src));
5243         }
5244       else
5245         {
5246           rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5247           emit_move_insn (stack, src);
5248           emit_insn (gen_lfiwzx (tmp, stack));
5249         }
5250     }
5251   emit_insn (gen_floatdi<mode>2 (dest, tmp));
5252   DONE;
5253 }"
5254   [(set_attr "length" "12")
5255    (set_attr "type" "fpload")])
5256
5257 (define_insn_and_split "floatunssi<mode>2_lfiwzx_mem"
5258   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,<rreg2>")
5259         (unsigned_float:SFDF
5260          (zero_extend:DI
5261           (match_operand:SI 1 "memory_operand" "Z,Z"))))
5262    (clobber (match_scratch:DI 2 "=0,d"))]
5263   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LFIWZX
5264    && <SI_CONVERT_FP>"
5265   "#"
5266   ""
5267   [(pc)]
5268   "
5269 {
5270   operands[1] = rs6000_address_for_fpconvert (operands[1]);
5271   if (GET_CODE (operands[2]) == SCRATCH)
5272     operands[2] = gen_reg_rtx (DImode);
5273   emit_insn (gen_lfiwzx (operands[2], operands[1]));
5274   emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
5275   DONE;
5276 }"
5277   [(set_attr "length" "8")
5278    (set_attr "type" "fpload")])
5279
5280 ; For each of these conversions, there is a define_expand, a define_insn
5281 ; with a '#' template, and a define_split (with C code).  The idea is
5282 ; to allow constant folding with the template of the define_insn,
5283 ; then to have the insns split later (between sched1 and final).
5284
5285 (define_expand "floatsidf2"
5286   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5287                    (float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
5288               (use (match_dup 2))
5289               (use (match_dup 3))
5290               (clobber (match_dup 4))
5291               (clobber (match_dup 5))
5292               (clobber (match_dup 6))])]
5293   "TARGET_HARD_FLOAT 
5294    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5295   "
5296 {
5297   if (TARGET_E500_DOUBLE)
5298     {
5299       if (!REG_P (operands[1]))
5300         operands[1] = force_reg (SImode, operands[1]);
5301       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
5302       DONE;
5303     }
5304   else if (TARGET_LFIWAX && TARGET_FCFID)
5305     {
5306       emit_insn (gen_floatsidf2_lfiwax (operands[0], operands[1]));
5307       DONE;
5308     }
5309   else if (TARGET_FCFID)
5310     {
5311       rtx dreg = operands[1];
5312       if (!REG_P (dreg))
5313         dreg = force_reg (SImode, dreg);
5314       dreg = convert_to_mode (DImode, dreg, false);
5315       emit_insn (gen_floatdidf2 (operands[0], dreg));
5316       DONE;
5317     }
5318
5319   if (!REG_P (operands[1]))
5320     operands[1] = force_reg (SImode, operands[1]);
5321   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5322   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5323   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
5324   operands[5] = gen_reg_rtx (DFmode);
5325   operands[6] = gen_reg_rtx (SImode);
5326 }")
5327
5328 (define_insn_and_split "*floatsidf2_internal"
5329   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
5330         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5331    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5332    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
5333    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
5334    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))
5335    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5336   "! TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5337   "#"
5338   ""
5339   [(pc)]
5340   "
5341 {
5342   rtx lowword, highword;
5343   gcc_assert (MEM_P (operands[4]));
5344   highword = adjust_address (operands[4], SImode, 0);
5345   lowword = adjust_address (operands[4], SImode, 4);
5346   if (! WORDS_BIG_ENDIAN)
5347     {
5348       rtx tmp;
5349       tmp = highword; highword = lowword; lowword = tmp;
5350     }
5351
5352   emit_insn (gen_xorsi3 (operands[6], operands[1],
5353                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5354   emit_move_insn (lowword, operands[6]);
5355   emit_move_insn (highword, operands[2]);
5356   emit_move_insn (operands[5], operands[4]);
5357   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5358   DONE;
5359 }"
5360   [(set_attr "length" "24")
5361    (set_attr "type" "fp")])
5362
5363 ;; If we don't have a direct conversion to single precision, don't enable this
5364 ;; conversion for 32-bit without fast math, because we don't have the insn to
5365 ;; generate the fixup swizzle to avoid double rounding problems.
5366 (define_expand "floatunssisf2"
5367   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5368         (unsigned_float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
5369   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
5370    && (!TARGET_FPRS
5371        || (TARGET_FPRS
5372            && ((TARGET_FCFIDUS && TARGET_LFIWZX)
5373                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
5374                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
5375   "
5376 {
5377   if (!TARGET_FPRS)
5378     {
5379       if (!REG_P (operands[1]))
5380         operands[1] = force_reg (SImode, operands[1]);
5381     }
5382   else if (TARGET_LFIWZX && TARGET_FCFIDUS)
5383     {
5384       emit_insn (gen_floatunssisf2_lfiwzx (operands[0], operands[1]));
5385       DONE;
5386     }
5387   else
5388     {
5389       rtx dreg = operands[1];
5390       if (!REG_P (dreg))
5391         dreg = force_reg (SImode, dreg);
5392       dreg = convert_to_mode (DImode, dreg, true);
5393       emit_insn (gen_floatdisf2 (operands[0], dreg));
5394       DONE;
5395     }
5396 }")
5397
5398 (define_expand "floatunssidf2"
5399   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5400                    (unsigned_float:DF (match_operand:SI 1 "nonimmediate_operand" "")))
5401               (use (match_dup 2))
5402               (use (match_dup 3))
5403               (clobber (match_dup 4))
5404               (clobber (match_dup 5))])]
5405   "TARGET_HARD_FLOAT
5406    && ((TARGET_FPRS && TARGET_DOUBLE_FLOAT) || TARGET_E500_DOUBLE)"
5407   "
5408 {
5409   if (TARGET_E500_DOUBLE)
5410     {
5411       if (!REG_P (operands[1]))
5412         operands[1] = force_reg (SImode, operands[1]);
5413       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
5414       DONE;
5415     }
5416   else if (TARGET_LFIWZX && TARGET_FCFID)
5417     {
5418       emit_insn (gen_floatunssidf2_lfiwzx (operands[0], operands[1]));
5419       DONE;
5420     }
5421   else if (TARGET_FCFID)
5422     {
5423       rtx dreg = operands[1];
5424       if (!REG_P (dreg))
5425         dreg = force_reg (SImode, dreg);
5426       dreg = convert_to_mode (DImode, dreg, true);
5427       emit_insn (gen_floatdidf2 (operands[0], dreg));
5428       DONE;
5429     }
5430
5431   if (!REG_P (operands[1]))
5432     operands[1] = force_reg (SImode, operands[1]);
5433   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5434   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5435   operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
5436   operands[5] = gen_reg_rtx (DFmode);
5437 }")
5438
5439 (define_insn_and_split "*floatunssidf2_internal"
5440   [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
5441         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5442    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5443    (use (match_operand:DF 3 "gpc_reg_operand" "d"))
5444    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
5445    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))]
5446   "! TARGET_FCFIDU && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5447    && !(TARGET_FCFID && TARGET_POWERPC64)"
5448   "#"
5449   ""
5450   [(pc)]
5451   "
5452 {
5453   rtx lowword, highword;
5454   gcc_assert (MEM_P (operands[4]));
5455   highword = adjust_address (operands[4], SImode, 0);
5456   lowword = adjust_address (operands[4], SImode, 4);
5457   if (! WORDS_BIG_ENDIAN)
5458     {
5459       rtx tmp;
5460       tmp = highword; highword = lowword; lowword = tmp;
5461     }
5462
5463   emit_move_insn (lowword, operands[1]);
5464   emit_move_insn (highword, operands[2]);
5465   emit_move_insn (operands[5], operands[4]);
5466   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5467   DONE;
5468 }"
5469   [(set_attr "length" "20")
5470    (set_attr "type" "fp")])
5471
5472 (define_expand "fix_trunc<mode>si2"
5473   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5474         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
5475   "TARGET_HARD_FLOAT && ((TARGET_FPRS && <TARGET_FLOAT>) || <E500_CONVERT>)"
5476   "
5477 {
5478   if (!<E500_CONVERT>)
5479     {
5480       rtx tmp, stack;
5481
5482       if (TARGET_STFIWX)
5483         emit_insn (gen_fix_trunc<mode>si2_stfiwx (operands[0], operands[1]));
5484       else
5485         {
5486           tmp = gen_reg_rtx (DImode);
5487           stack = rs6000_allocate_stack_temp (DImode, true, false);
5488           emit_insn (gen_fix_trunc<mode>si2_internal (operands[0], operands[1],
5489                                                       tmp, stack));
5490         }
5491       DONE;
5492     }
5493 }")
5494
5495 ; Like the convert to float patterns, this insn must be split before
5496 ; register allocation so that it can allocate the memory slot if it
5497 ; needed
5498 (define_insn_and_split "fix_trunc<mode>si2_stfiwx"
5499   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
5500         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
5501    (clobber (match_scratch:DI 2 "=d"))]
5502   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5503    && (<MODE>mode != SFmode || TARGET_SINGLE_FLOAT)
5504    && TARGET_STFIWX && can_create_pseudo_p ()"
5505   "#"
5506   ""
5507   [(pc)]
5508 {
5509   rtx dest = operands[0];
5510   rtx src = operands[1];
5511   rtx tmp = operands[2];
5512
5513   if (GET_CODE (tmp) == SCRATCH)
5514     tmp = gen_reg_rtx (DImode);
5515
5516   emit_insn (gen_fctiwz_<mode> (tmp, src));
5517   if (MEM_P (dest))
5518     {
5519       dest = rs6000_address_for_fpconvert (dest);
5520       emit_insn (gen_stfiwx (dest, tmp));
5521       DONE;
5522     }
5523   else if (TARGET_MFPGPR && TARGET_POWERPC64)
5524     {
5525       dest = gen_lowpart (DImode, dest);
5526       emit_move_insn (dest, tmp);
5527       DONE;
5528     }
5529   else
5530     {
5531       rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5532       emit_insn (gen_stfiwx (stack, tmp));
5533       emit_move_insn (dest, stack);
5534       DONE;
5535     }
5536 }
5537   [(set_attr "length" "12")
5538    (set_attr "type" "fp")])
5539
5540 (define_insn_and_split "fix_trunc<mode>si2_internal"
5541   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,?r")
5542         (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d,<rreg>")))
5543    (clobber (match_operand:DI 2 "gpc_reg_operand" "=1,d"))
5544    (clobber (match_operand:DI 3 "offsettable_mem_operand" "=o,o"))]
5545   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5546   "#"
5547   ""
5548   [(pc)]
5549   "
5550 {
5551   rtx lowword;
5552   gcc_assert (MEM_P (operands[3]));
5553   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
5554
5555   emit_insn (gen_fctiwz_<mode> (operands[2], operands[1]));
5556   emit_move_insn (operands[3], operands[2]);
5557   emit_move_insn (operands[0], lowword);
5558   DONE;
5559 }"
5560   [(set_attr "length" "16")
5561    (set_attr "type" "fp")])
5562
5563 (define_expand "fix_trunc<mode>di2"
5564   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5565         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
5566   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
5567    && TARGET_FCFID"
5568   "")
5569
5570 (define_insn "*fix_trunc<mode>di2_fctidz"
5571   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
5572         (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
5573   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
5574     && TARGET_FCFID && !VECTOR_UNIT_VSX_P (<MODE>mode)"
5575   "fctidz %0,%1"
5576   [(set_attr "type" "fp")])
5577
5578 (define_expand "fixuns_trunc<mode>si2"
5579   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5580         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "")))]
5581   "TARGET_HARD_FLOAT
5582    && ((TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ && TARGET_STFIWX)
5583        || <E500_CONVERT>)"
5584   "
5585 {
5586   if (!<E500_CONVERT>)
5587     {
5588       emit_insn (gen_fixuns_trunc<mode>si2_stfiwx (operands[0], operands[1]));
5589       DONE;
5590     }
5591 }")
5592
5593 (define_insn_and_split "fixuns_trunc<mode>si2_stfiwx"
5594   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
5595         (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
5596    (clobber (match_scratch:DI 2 "=d"))]
5597   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ
5598    && TARGET_STFIWX && can_create_pseudo_p ()"
5599   "#"
5600   ""
5601   [(pc)]
5602 {
5603   rtx dest = operands[0];
5604   rtx src = operands[1];
5605   rtx tmp = operands[2];
5606
5607   if (GET_CODE (tmp) == SCRATCH)
5608     tmp = gen_reg_rtx (DImode);
5609
5610   emit_insn (gen_fctiwuz_<mode> (tmp, src));
5611   if (MEM_P (dest))
5612     {
5613       dest = rs6000_address_for_fpconvert (dest);
5614       emit_insn (gen_stfiwx (dest, tmp));
5615       DONE;
5616     }
5617   else if (TARGET_MFPGPR && TARGET_POWERPC64)
5618     {
5619       dest = gen_lowpart (DImode, dest);
5620       emit_move_insn (dest, tmp);
5621       DONE;
5622     }
5623   else
5624     {
5625       rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5626       emit_insn (gen_stfiwx (stack, tmp));
5627       emit_move_insn (dest, stack);
5628       DONE;
5629     }
5630 }
5631   [(set_attr "length" "12")
5632    (set_attr "type" "fp")])
5633
5634 (define_expand "fixuns_trunc<mode>di2"
5635   [(set (match_operand:DI 0 "register_operand" "")
5636         (unsigned_fix:DI (match_operand:SFDF 1 "register_operand" "")))]
5637   "TARGET_HARD_FLOAT && (TARGET_FCTIDUZ || VECTOR_UNIT_VSX_P (<MODE>mode))"
5638   "")
5639
5640 (define_insn "*fixuns_trunc<mode>di2_fctiduz"
5641   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
5642         (unsigned_fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d")))]
5643   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
5644     && TARGET_FCTIDUZ && !VECTOR_UNIT_VSX_P (<MODE>mode)"
5645   "fctiduz %0,%1"
5646   [(set_attr "type" "fp")])
5647
5648 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
5649 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
5650 ; because the first makes it clear that operand 0 is not live
5651 ; before the instruction.
5652 (define_insn "fctiwz_<mode>"
5653   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
5654         (unspec:DI [(fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))]
5655                    UNSPEC_FCTIWZ))]
5656   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
5657   "fctiwz %0,%1"
5658   [(set_attr "type" "fp")])
5659
5660 (define_insn "fctiwuz_<mode>"
5661   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
5662         (unspec:DI [(unsigned_fix:SI
5663                      (match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>"))]
5664                    UNSPEC_FCTIWUZ))]
5665   "TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT> && TARGET_FCTIWUZ"
5666   "fctiwuz %0,%1"
5667   [(set_attr "type" "fp")])
5668
5669 ;; Only optimize (float (fix x)) -> frz if we are in fast-math mode, since
5670 ;; since the friz instruction does not truncate the value if the floating
5671 ;; point value is < LONG_MIN or > LONG_MAX.
5672 (define_insn "*friz"
5673   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5674         (float:DF (fix:DI (match_operand:DF 1 "gpc_reg_operand" "d"))))]
5675   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_FPRND
5676    && !VECTOR_UNIT_VSX_P (DFmode) && flag_unsafe_math_optimizations
5677    && !flag_trapping_math && TARGET_FRIZ"
5678   "friz %0,%1"
5679   [(set_attr "type" "fp")])
5680
5681 ;; Since FCTIWZ doesn't sign extend the upper bits, we have to do a store and a
5682 ;; load to properly sign extend the value, but at least doing a store, load
5683 ;; into a GPR to sign extend, a store from the GPR and a load back into the FPR
5684 ;; if we have 32-bit memory ops
5685 (define_insn_and_split "*round32<mode>2_fprs"
5686   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5687         (float:SFDF
5688          (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
5689    (clobber (match_scratch:DI 2 "=d"))
5690    (clobber (match_scratch:DI 3 "=d"))]
5691   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5692    && <SI_CONVERT_FP> && TARGET_LFIWAX && TARGET_STFIWX && TARGET_FCFID
5693    && can_create_pseudo_p ()"
5694   "#"
5695   ""
5696   [(pc)]
5697 {
5698   rtx dest = operands[0];
5699   rtx src = operands[1];
5700   rtx tmp1 = operands[2];
5701   rtx tmp2 = operands[3];
5702   rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5703
5704   if (GET_CODE (tmp1) == SCRATCH)
5705     tmp1 = gen_reg_rtx (DImode);
5706   if (GET_CODE (tmp2) == SCRATCH)
5707     tmp2 = gen_reg_rtx (DImode);
5708
5709   emit_insn (gen_fctiwz_<mode> (tmp1, src));
5710   emit_insn (gen_stfiwx (stack, tmp1));
5711   emit_insn (gen_lfiwax (tmp2, stack));
5712   emit_insn (gen_floatdi<mode>2 (dest, tmp2));
5713   DONE;
5714 }
5715   [(set_attr "type" "fpload")
5716    (set_attr "length" "16")])
5717
5718 (define_insn_and_split "*roundu32<mode>2_fprs"
5719   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
5720         (unsigned_float:SFDF
5721          (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
5722    (clobber (match_scratch:DI 2 "=d"))
5723    (clobber (match_scratch:DI 3 "=d"))]
5724   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
5725    && TARGET_LFIWZX && TARGET_STFIWX && TARGET_FCFIDU
5726    && can_create_pseudo_p ()"
5727   "#"
5728   ""
5729   [(pc)]
5730 {
5731   rtx dest = operands[0];
5732   rtx src = operands[1];
5733   rtx tmp1 = operands[2];
5734   rtx tmp2 = operands[3];
5735   rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5736
5737   if (GET_CODE (tmp1) == SCRATCH)
5738     tmp1 = gen_reg_rtx (DImode);
5739   if (GET_CODE (tmp2) == SCRATCH)
5740     tmp2 = gen_reg_rtx (DImode);
5741
5742   emit_insn (gen_fctiwuz_<mode> (tmp1, src));
5743   emit_insn (gen_stfiwx (stack, tmp1));
5744   emit_insn (gen_lfiwzx (tmp2, stack));
5745   emit_insn (gen_floatdi<mode>2 (dest, tmp2));
5746   DONE;
5747 }
5748   [(set_attr "type" "fpload")
5749    (set_attr "length" "16")])
5750
5751 ;; No VSX equivalent to fctid
5752 (define_insn "lrint<mode>di2"
5753   [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
5754         (unspec:DI [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
5755                    UNSPEC_FCTID))]
5756   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
5757   "fctid %0,%1"
5758   [(set_attr "type" "fp")])
5759
5760 (define_expand "btrunc<mode>2"
5761   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5762         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "")]
5763                      UNSPEC_FRIZ))]
5764   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
5765   "")
5766
5767 (define_insn "*btrunc<mode>2_fpr"
5768   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
5769         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
5770                      UNSPEC_FRIZ))]
5771   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
5772    && !VECTOR_UNIT_VSX_P (<MODE>mode)"
5773   "friz %0,%1"
5774   [(set_attr "type" "fp")])
5775
5776 (define_expand "ceil<mode>2"
5777   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5778         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "")]
5779                      UNSPEC_FRIP))]
5780   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
5781   "")
5782
5783 (define_insn "*ceil<mode>2_fpr"
5784   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
5785         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
5786                      UNSPEC_FRIP))]
5787   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
5788    && !VECTOR_UNIT_VSX_P (<MODE>mode)"
5789   "frip %0,%1"
5790   [(set_attr "type" "fp")])
5791
5792 (define_expand "floor<mode>2"
5793   [(set (match_operand:SFDF 0 "gpc_reg_operand" "")
5794         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "")]
5795                      UNSPEC_FRIM))]
5796   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
5797   "")
5798
5799 (define_insn "*floor<mode>2_fpr"
5800   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
5801         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
5802                      UNSPEC_FRIM))]
5803   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>
5804    && !VECTOR_UNIT_VSX_P (<MODE>mode)"
5805   "frim %0,%1"
5806   [(set_attr "type" "fp")])
5807
5808 ;; No VSX equivalent to frin
5809 (define_insn "round<mode>2"
5810   [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
5811         (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
5812                      UNSPEC_FRIN))]
5813   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS && <TARGET_FLOAT>"
5814   "frin %0,%1"
5815   [(set_attr "type" "fp")])
5816
5817 ; An UNSPEC is used so we don't have to support SImode in FP registers.
5818 (define_insn "stfiwx"
5819   [(set (match_operand:SI 0 "memory_operand" "=Z")
5820         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "d")]
5821                    UNSPEC_STFIWX))]
5822   "TARGET_PPC_GFXOPT"
5823   "stfiwx %1,%y0"
5824   [(set_attr "type" "fpstore")])
5825
5826 ;; If we don't have a direct conversion to single precision, don't enable this
5827 ;; conversion for 32-bit without fast math, because we don't have the insn to
5828 ;; generate the fixup swizzle to avoid double rounding problems.
5829 (define_expand "floatsisf2"
5830   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5831         (float:SF (match_operand:SI 1 "nonimmediate_operand" "")))]
5832   "TARGET_HARD_FLOAT && TARGET_SINGLE_FLOAT
5833    && (!TARGET_FPRS
5834        || (TARGET_FPRS
5835            && ((TARGET_FCFIDS && TARGET_LFIWAX)
5836                || (TARGET_DOUBLE_FLOAT && TARGET_FCFID
5837                    && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))))"
5838   "
5839 {
5840   if (!TARGET_FPRS)
5841     {
5842       if (!REG_P (operands[1]))
5843         operands[1] = force_reg (SImode, operands[1]);
5844     }
5845   else if (TARGET_FCFIDS && TARGET_LFIWAX)
5846     {
5847       emit_insn (gen_floatsisf2_lfiwax (operands[0], operands[1]));
5848       DONE;
5849     }
5850   else if (TARGET_FCFID && TARGET_LFIWAX)
5851     {
5852       rtx dfreg = gen_reg_rtx (DFmode);
5853       emit_insn (gen_floatsidf2_lfiwax (dfreg, operands[1]));
5854       emit_insn (gen_truncdfsf2 (operands[0], dfreg));
5855       DONE;
5856     }
5857   else
5858     {
5859       rtx dreg = operands[1];
5860       if (!REG_P (dreg))
5861         dreg = force_reg (SImode, dreg);
5862       dreg = convert_to_mode (DImode, dreg, false);
5863       emit_insn (gen_floatdisf2 (operands[0], dreg));
5864       DONE;
5865     }
5866 }")
5867
5868 (define_expand "floatdidf2"
5869   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5870         (float:DF (match_operand:DI 1 "gpc_reg_operand" "")))]
5871   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS"
5872   "")
5873
5874 (define_insn "*floatdidf2_fpr"
5875   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5876         (float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
5877   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
5878    && !VECTOR_UNIT_VSX_P (DFmode)"
5879   "fcfid %0,%1"
5880   [(set_attr "type" "fp")])
5881
5882 ; Allow the combiner to merge source memory operands to the conversion so that
5883 ; the optimizer/register allocator doesn't try to load the value too early in a
5884 ; GPR and then use store/load to move it to a FPR and suffer from a store-load
5885 ; hit.  We will split after reload to avoid the trip through the GPRs
5886
5887 (define_insn_and_split "*floatdidf2_mem"
5888   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5889         (float:DF (match_operand:DI 1 "memory_operand" "m")))
5890    (clobber (match_scratch:DI 2 "=d"))]
5891   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS && TARGET_FCFID"
5892   "#"
5893   "&& reload_completed"
5894   [(set (match_dup 2) (match_dup 1))
5895    (set (match_dup 0) (float:DF (match_dup 2)))]
5896   ""
5897   [(set_attr "length" "8")
5898    (set_attr "type" "fpload")])
5899
5900 (define_expand "floatunsdidf2"
5901   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5902         (unsigned_float:DF
5903          (match_operand:DI 1 "gpc_reg_operand" "")))]
5904   "TARGET_HARD_FLOAT && (TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode))"
5905   "")
5906
5907 (define_insn "*floatunsdidf2_fcfidu"
5908   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5909         (unsigned_float:DF (match_operand:DI 1 "gpc_reg_operand" "d")))]
5910   "TARGET_HARD_FLOAT && TARGET_FCFIDU && !VECTOR_UNIT_VSX_P (DFmode)"
5911   "fcfidu %0,%1"
5912   [(set_attr "type" "fp")
5913    (set_attr "length" "4")])
5914
5915 (define_insn_and_split "*floatunsdidf2_mem"
5916   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
5917         (unsigned_float:DF (match_operand:DI 1 "memory_operand" "m")))
5918    (clobber (match_scratch:DI 2 "=d"))]
5919   "TARGET_HARD_FLOAT && (TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode))"
5920   "#"
5921   "&& reload_completed"
5922   [(set (match_dup 2) (match_dup 1))
5923    (set (match_dup 0) (unsigned_float:DF (match_dup 2)))]
5924   ""
5925   [(set_attr "length" "8")
5926    (set_attr "type" "fpload")])
5927
5928 (define_expand "floatdisf2"
5929   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5930         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
5931   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
5932    && (TARGET_FCFIDS || TARGET_POWERPC64 || flag_unsafe_math_optimizations)"
5933   "
5934 {
5935   if (!TARGET_FCFIDS)
5936     {
5937       rtx val = operands[1];
5938       if (!flag_unsafe_math_optimizations)
5939         {
5940           rtx label = gen_label_rtx ();
5941           val = gen_reg_rtx (DImode);
5942           emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
5943           emit_label (label);
5944         }
5945       emit_insn (gen_floatdisf2_internal1 (operands[0], val));
5946       DONE;
5947     }
5948 }")
5949
5950 (define_insn "floatdisf2_fcfids"
5951   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5952         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
5953   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
5954    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
5955   "fcfids %0,%1"
5956   [(set_attr "type" "fp")])
5957
5958 (define_insn_and_split "*floatdisf2_mem"
5959   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5960         (float:SF (match_operand:DI 1 "memory_operand" "m")))
5961    (clobber (match_scratch:DI 2 "=f"))]
5962   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
5963    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDS"
5964   "#"
5965   "&& reload_completed"
5966   [(pc)]
5967   "
5968 {
5969   emit_move_insn (operands[2], operands[1]);
5970   emit_insn (gen_floatdisf2_fcfids (operands[0], operands[2]));
5971   DONE;
5972 }"
5973   [(set_attr "length" "8")])
5974
5975 ;; This is not IEEE compliant if rounding mode is "round to nearest".
5976 ;; If the DI->DF conversion is inexact, then it's possible to suffer
5977 ;; from double rounding.
5978 ;; Instead of creating a new cpu type for two FP operations, just use fp
5979 (define_insn_and_split "floatdisf2_internal1"
5980   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5981         (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))
5982    (clobber (match_scratch:DF 2 "=d"))]
5983   "TARGET_FCFID && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
5984   "#"
5985   "&& reload_completed"
5986   [(set (match_dup 2)
5987         (float:DF (match_dup 1)))
5988    (set (match_dup 0)
5989         (float_truncate:SF (match_dup 2)))]
5990   ""
5991   [(set_attr "length" "8")
5992    (set_attr "type" "fp")])
5993
5994 ;; Twiddles bits to avoid double rounding.
5995 ;; Bits that might be truncated when converting to DFmode are replaced
5996 ;; by a bit that won't be lost at that stage, but is below the SFmode
5997 ;; rounding position.
5998 (define_expand "floatdisf2_internal2"
5999   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
6000                                    (const_int 53)))
6001    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
6002                                                       (const_int 2047)))
6003               (clobber (scratch:CC))])
6004    (set (match_dup 3) (plus:DI (match_dup 3)
6005                                (const_int 1)))
6006    (set (match_dup 0) (plus:DI (match_dup 0)
6007                                (const_int 2047)))
6008    (set (match_dup 4) (compare:CCUNS (match_dup 3)
6009                                      (const_int 2)))
6010    (set (match_dup 0) (ior:DI (match_dup 0)
6011                               (match_dup 1)))
6012    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
6013                                          (const_int -2048)))
6014               (clobber (scratch:CC))])
6015    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
6016                            (label_ref (match_operand:DI 2 "" ""))
6017                            (pc)))
6018    (set (match_dup 0) (match_dup 1))]
6019   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
6020   "
6021 {
6022   operands[3] = gen_reg_rtx (DImode);
6023   operands[4] = gen_reg_rtx (CCUNSmode);
6024 }")
6025
6026 (define_expand "floatunsdisf2"
6027   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6028         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
6029   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6030    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6031   "")
6032
6033 (define_insn "floatunsdisf2_fcfidus"
6034   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6035         (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))]
6036   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6037    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6038   "fcfidus %0,%1"
6039   [(set_attr "type" "fp")])
6040
6041 (define_insn_and_split "*floatunsdisf2_mem"
6042   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6043         (unsigned_float:SF (match_operand:DI 1 "memory_operand" "m")))
6044    (clobber (match_scratch:DI 2 "=f"))]
6045   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT
6046    && TARGET_DOUBLE_FLOAT && TARGET_FCFIDUS"
6047   "#"
6048   "&& reload_completed"
6049   [(pc)]
6050   "
6051 {
6052   emit_move_insn (operands[2], operands[1]);
6053   emit_insn (gen_floatunsdisf2_fcfidus (operands[0], operands[2]));
6054   DONE;
6055 }"
6056   [(set_attr "length" "8")
6057    (set_attr "type" "fpload")])
6058 \f
6059 ;; Define the DImode operations that can be done in a small number
6060 ;; of instructions.  The & constraints are to prevent the register
6061 ;; allocator from allocating registers that overlap with the inputs
6062 ;; (for example, having an input in 7,8 and an output in 6,7).  We
6063 ;; also allow for the output being the same as one of the inputs.
6064
6065 (define_insn "*adddi3_noppc64"
6066   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
6067         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
6068                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
6069   "! TARGET_POWERPC64"
6070   "*
6071 {
6072   if (WORDS_BIG_ENDIAN)
6073     return (GET_CODE (operands[2])) != CONST_INT
6074             ? \"addc %L0,%L1,%L2\;adde %0,%1,%2\"
6075             : \"addic %L0,%L1,%2\;add%G2e %0,%1\";
6076   else
6077     return (GET_CODE (operands[2])) != CONST_INT
6078             ? \"addc %0,%1,%2\;adde %L0,%L1,%L2\"
6079             : \"addic %0,%1,%2\;add%G2e %L0,%L1\";
6080 }"
6081   [(set_attr "type" "two")
6082    (set_attr "length" "8")])
6083
6084 (define_insn "*subdi3_noppc64"
6085   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
6086         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
6087                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
6088   "! TARGET_POWERPC64"
6089   "*
6090 {
6091   if (WORDS_BIG_ENDIAN)
6092     return (GET_CODE (operands[1]) != CONST_INT)
6093             ? \"subfc %L0,%L2,%L1\;subfe %0,%2,%1\"
6094             : \"subfic %L0,%L2,%1\;subf%G1e %0,%2\";
6095   else
6096     return (GET_CODE (operands[1]) != CONST_INT)
6097             ? \"subfc %0,%2,%1\;subfe %L0,%L2,%L1\"
6098             : \"subfic %0,%2,%1\;subf%G1e %L0,%L2\";
6099 }"
6100   [(set_attr "type" "two")
6101    (set_attr "length" "8")])
6102
6103 (define_insn "*negdi2_noppc64"
6104   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6105         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
6106   "! TARGET_POWERPC64"
6107   "*
6108 {
6109   return (WORDS_BIG_ENDIAN)
6110     ? \"subfic %L0,%L1,0\;subfze %0,%1\"
6111     : \"subfic %0,%1,0\;subfze %L0,%L1\";
6112 }"
6113   [(set_attr "type" "two")
6114    (set_attr "length" "8")])
6115
6116 (define_insn "mulsidi3"
6117   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6118         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6119                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6120   "! TARGET_POWERPC64"
6121 {
6122   return (WORDS_BIG_ENDIAN)
6123     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
6124     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
6125 }
6126   [(set_attr "type" "imul")
6127    (set_attr "length" "8")])
6128
6129 (define_split
6130   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6131         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6132                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6133   "! TARGET_POWERPC64 && reload_completed"
6134   [(set (match_dup 3)
6135         (truncate:SI
6136          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
6137                                (sign_extend:DI (match_dup 2)))
6138                       (const_int 32))))
6139    (set (match_dup 4)
6140         (mult:SI (match_dup 1)
6141                  (match_dup 2)))]
6142   "
6143 {
6144   int endian = (WORDS_BIG_ENDIAN == 0);
6145   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6146   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6147 }")
6148
6149 (define_insn "umulsidi3"
6150   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6151         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6152                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6153   "! TARGET_POWERPC64"
6154   "*
6155 {
6156   return (WORDS_BIG_ENDIAN)
6157     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6158     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6159 }"
6160   [(set_attr "type" "imul")
6161    (set_attr "length" "8")])
6162
6163 (define_split
6164   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6165         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6166                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6167   "! TARGET_POWERPC64 && reload_completed"
6168   [(set (match_dup 3)
6169         (truncate:SI
6170          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
6171                                (zero_extend:DI (match_dup 2)))
6172                       (const_int 32))))
6173    (set (match_dup 4)
6174         (mult:SI (match_dup 1)
6175                  (match_dup 2)))]
6176   "
6177 {
6178   int endian = (WORDS_BIG_ENDIAN == 0);
6179   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6180   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6181 }")
6182
6183 (define_insn "smulsi3_highpart"
6184   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6185         (truncate:SI
6186          (lshiftrt:DI (mult:DI (sign_extend:DI
6187                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6188                                (sign_extend:DI
6189                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6190                       (const_int 32))))]
6191   ""
6192   "mulhw %0,%1,%2"
6193   [(set_attr "type" "imul")])
6194
6195 (define_insn "umulsi3_highpart"
6196   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6197         (truncate:SI
6198          (lshiftrt:DI (mult:DI (zero_extend:DI
6199                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6200                                (zero_extend:DI
6201                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6202                       (const_int 32))))]
6203   ""
6204   "mulhwu %0,%1,%2"
6205   [(set_attr "type" "imul")])
6206
6207 ;; Shift by a variable amount is too complex to be worth open-coding.  We
6208 ;; just handle shifts by constants.
6209 (define_insn "ashrdi3_no_power"
6210   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
6211         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6212                      (match_operand:SI 2 "const_int_operand" "M,i")))]
6213   "TARGET_32BIT && !TARGET_POWERPC64 && WORDS_BIG_ENDIAN"
6214   "@
6215    srawi %0,%1,31\;srawi %L0,%1,%h2
6216    srwi %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;srawi %0,%1,%h2"
6217   [(set_attr "type" "two,three")
6218    (set_attr "length" "8,12")])
6219
6220 (define_insn "*ashrdisi3_noppc64"
6221   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6222         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6223                                 (const_int 32)) 4))]
6224   "TARGET_32BIT && !TARGET_POWERPC64"
6225   "*
6226 {
6227   if (REGNO (operands[0]) == REGNO (operands[1]))
6228     return \"\";
6229   else
6230     return \"mr %0,%1\";
6231 }"
6232    [(set_attr "length" "4")])
6233
6234 \f
6235 ;; PowerPC64 DImode operations.
6236
6237 (define_insn "muldi3"
6238   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6239         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6240                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
6241   "TARGET_POWERPC64"
6242   "@
6243    mulld %0,%1,%2
6244    mulli %0,%1,%2"
6245    [(set (attr "type")
6246       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
6247                 (const_string "imul3")
6248              (match_operand:SI 2 "short_cint_operand" "")
6249                 (const_string "imul2")]
6250         (const_string "lmul")))])
6251
6252 (define_insn "*muldi3_internal1"
6253   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6254         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6255                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6256                     (const_int 0)))
6257    (clobber (match_scratch:DI 3 "=r,r"))]
6258   "TARGET_POWERPC64"
6259   "@
6260    mulld. %3,%1,%2
6261    #"
6262   [(set_attr "type" "lmul_compare")
6263    (set_attr "length" "4,8")])
6264
6265 (define_split
6266   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6267         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6268                              (match_operand:DI 2 "gpc_reg_operand" ""))
6269                     (const_int 0)))
6270    (clobber (match_scratch:DI 3 ""))]
6271   "TARGET_POWERPC64 && reload_completed"
6272   [(set (match_dup 3)
6273         (mult:DI (match_dup 1) (match_dup 2)))
6274    (set (match_dup 0)
6275         (compare:CC (match_dup 3)
6276                     (const_int 0)))]
6277   "")
6278
6279 (define_insn "*muldi3_internal2"
6280   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6281         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6282                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6283                     (const_int 0)))
6284    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6285         (mult:DI (match_dup 1) (match_dup 2)))]
6286   "TARGET_POWERPC64"
6287   "@
6288    mulld. %0,%1,%2
6289    #"
6290   [(set_attr "type" "lmul_compare")
6291    (set_attr "length" "4,8")])
6292
6293 (define_split
6294   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
6295         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6296                              (match_operand:DI 2 "gpc_reg_operand" ""))
6297                     (const_int 0)))
6298    (set (match_operand:DI 0 "gpc_reg_operand" "")
6299         (mult:DI (match_dup 1) (match_dup 2)))]
6300   "TARGET_POWERPC64 && reload_completed"
6301   [(set (match_dup 0)
6302         (mult:DI (match_dup 1) (match_dup 2)))
6303    (set (match_dup 3)
6304         (compare:CC (match_dup 0)
6305                     (const_int 0)))]
6306   "")
6307
6308 (define_insn "smuldi3_highpart"
6309   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6310         (truncate:DI
6311          (lshiftrt:TI (mult:TI (sign_extend:TI
6312                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6313                                (sign_extend:TI
6314                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6315                       (const_int 64))))]
6316   "TARGET_POWERPC64"
6317   "mulhd %0,%1,%2"
6318   [(set_attr "type" "lmul")])
6319
6320 (define_insn "umuldi3_highpart"
6321   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6322         (truncate:DI
6323          (lshiftrt:TI (mult:TI (zero_extend:TI
6324                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6325                                (zero_extend:TI
6326                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6327                       (const_int 64))))]
6328   "TARGET_POWERPC64"
6329   "mulhdu %0,%1,%2"
6330   [(set_attr "type" "lmul")])
6331
6332 (define_expand "mulditi3"
6333   [(set (match_operand:TI 0 "gpc_reg_operand")
6334         (mult:TI (sign_extend:TI (match_operand:DI 1 "gpc_reg_operand"))
6335                  (sign_extend:TI (match_operand:DI 2 "gpc_reg_operand"))))]
6336   "TARGET_POWERPC64"
6337 {
6338   rtx l = gen_reg_rtx (DImode), h = gen_reg_rtx (DImode);
6339   emit_insn (gen_muldi3 (l, operands[1], operands[2]));
6340   emit_insn (gen_smuldi3_highpart (h, operands[1], operands[2]));
6341   emit_move_insn (gen_lowpart (DImode, operands[0]), l);
6342   emit_move_insn (gen_highpart (DImode, operands[0]), h);
6343   DONE;
6344 })
6345
6346 (define_expand "umulditi3"
6347   [(set (match_operand:TI 0 "gpc_reg_operand")
6348         (mult:TI (zero_extend:TI (match_operand:DI 1 "gpc_reg_operand"))
6349                  (zero_extend:TI (match_operand:DI 2 "gpc_reg_operand"))))]
6350   "TARGET_POWERPC64"
6351 {
6352   rtx l = gen_reg_rtx (DImode), h = gen_reg_rtx (DImode);
6353   emit_insn (gen_muldi3 (l, operands[1], operands[2]));
6354   emit_insn (gen_umuldi3_highpart (h, operands[1], operands[2]));
6355   emit_move_insn (gen_lowpart (DImode, operands[0]), l);
6356   emit_move_insn (gen_highpart (DImode, operands[0]), h);
6357   DONE;
6358 })
6359
6360 (define_insn "rotldi3"
6361   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6362         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6363                    (match_operand:DI 2 "reg_or_cint_operand" "r,i")))]
6364   "TARGET_POWERPC64"
6365   "@
6366    rldcl %0,%1,%2,0
6367    rldicl %0,%1,%H2,0"
6368   [(set_attr "type" "var_shift_rotate,integer")])
6369
6370 (define_insn "*rotldi3_internal2"
6371   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6372         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6373                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6374                     (const_int 0)))
6375    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6376   "TARGET_64BIT"
6377   "@
6378    rldcl. %3,%1,%2,0
6379    rldicl. %3,%1,%H2,0
6380    #
6381    #"
6382   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6383    (set_attr "length" "4,4,8,8")])
6384
6385 (define_split
6386   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6387         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6388                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6389                     (const_int 0)))
6390    (clobber (match_scratch:DI 3 ""))]
6391   "TARGET_POWERPC64 && reload_completed"
6392   [(set (match_dup 3)
6393         (rotate:DI (match_dup 1) (match_dup 2)))
6394    (set (match_dup 0)
6395         (compare:CC (match_dup 3)
6396                     (const_int 0)))]
6397   "")
6398
6399 (define_insn "*rotldi3_internal3"
6400   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6401         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6402                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6403                     (const_int 0)))
6404    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6405         (rotate:DI (match_dup 1) (match_dup 2)))]
6406   "TARGET_64BIT"
6407   "@
6408    rldcl. %0,%1,%2,0
6409    rldicl. %0,%1,%H2,0
6410    #
6411    #"
6412   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6413    (set_attr "length" "4,4,8,8")])
6414
6415 (define_split
6416   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
6417         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6418                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6419                     (const_int 0)))
6420    (set (match_operand:DI 0 "gpc_reg_operand" "")
6421         (rotate:DI (match_dup 1) (match_dup 2)))]
6422   "TARGET_POWERPC64 && reload_completed"
6423   [(set (match_dup 0)
6424         (rotate:DI (match_dup 1) (match_dup 2)))
6425    (set (match_dup 3)
6426         (compare:CC (match_dup 0)
6427                     (const_int 0)))]
6428   "")
6429
6430 (define_insn "*rotldi3_internal4"
6431   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6432         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6433                            (match_operand:DI 2 "reg_or_cint_operand" "r,i"))
6434                 (match_operand:DI 3 "mask64_operand" "n,n")))]
6435   "TARGET_POWERPC64"
6436   "@
6437    rldc%B3 %0,%1,%2,%S3
6438    rldic%B3 %0,%1,%H2,%S3"
6439   [(set_attr "type" "var_shift_rotate,integer")])
6440
6441 (define_insn "*rotldi3_internal5"
6442   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6443         (compare:CC (and:DI
6444                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6445                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6446                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
6447                     (const_int 0)))
6448    (clobber (match_scratch:DI 4 "=r,r,r,r"))]
6449   "TARGET_64BIT"
6450   "@
6451    rldc%B3. %4,%1,%2,%S3
6452    rldic%B3. %4,%1,%H2,%S3
6453    #
6454    #"
6455   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6456    (set_attr "length" "4,4,8,8")])
6457
6458 (define_split
6459   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6460         (compare:CC (and:DI
6461                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6462                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6463                      (match_operand:DI 3 "mask64_operand" ""))
6464                     (const_int 0)))
6465    (clobber (match_scratch:DI 4 ""))]
6466   "TARGET_POWERPC64 && reload_completed"
6467   [(set (match_dup 4)
6468         (and:DI (rotate:DI (match_dup 1)
6469                                 (match_dup 2))
6470                      (match_dup 3)))
6471    (set (match_dup 0)
6472         (compare:CC (match_dup 4)
6473                     (const_int 0)))]
6474   "")
6475
6476 (define_insn "*rotldi3_internal6"
6477   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
6478         (compare:CC (and:DI
6479                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6480                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6481                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
6482                     (const_int 0)))
6483    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6484         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6485   "TARGET_64BIT"
6486   "@
6487    rldc%B3. %0,%1,%2,%S3
6488    rldic%B3. %0,%1,%H2,%S3
6489    #
6490    #"
6491   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6492    (set_attr "length" "4,4,8,8")])
6493
6494 (define_split
6495   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
6496         (compare:CC (and:DI
6497                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6498                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6499                      (match_operand:DI 3 "mask64_operand" ""))
6500                     (const_int 0)))
6501    (set (match_operand:DI 0 "gpc_reg_operand" "")
6502         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6503   "TARGET_POWERPC64 && reload_completed"
6504   [(set (match_dup 0)
6505         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6506    (set (match_dup 4)
6507         (compare:CC (match_dup 0)
6508                     (const_int 0)))]
6509   "")
6510
6511 (define_insn "*rotldi3_internal7"
6512   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6513         (zero_extend:DI
6514          (subreg:QI
6515           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6516                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
6517   "TARGET_POWERPC64"
6518   "@
6519    rldcl %0,%1,%2,56
6520    rldicl %0,%1,%H2,56"
6521   [(set_attr "type" "var_shift_rotate,integer")])
6522
6523 (define_insn "*rotldi3_internal8"
6524   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6525         (compare:CC (zero_extend:DI
6526                      (subreg:QI
6527                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6528                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6529                     (const_int 0)))
6530    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6531   "TARGET_64BIT"
6532   "@
6533    rldcl. %3,%1,%2,56
6534    rldicl. %3,%1,%H2,56
6535    #
6536    #"
6537   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6538    (set_attr "length" "4,4,8,8")])
6539
6540 (define_split
6541   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6542         (compare:CC (zero_extend:DI
6543                      (subreg:QI
6544                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6545                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6546                     (const_int 0)))
6547    (clobber (match_scratch:DI 3 ""))]
6548   "TARGET_POWERPC64 && reload_completed"
6549   [(set (match_dup 3)
6550         (zero_extend:DI (subreg:QI
6551                       (rotate:DI (match_dup 1)
6552                                  (match_dup 2)) 0)))
6553    (set (match_dup 0)
6554         (compare:CC (match_dup 3)
6555                     (const_int 0)))]
6556   "")
6557
6558 (define_insn "*rotldi3_internal9"
6559   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6560         (compare:CC (zero_extend:DI
6561                      (subreg:QI
6562                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6563                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6564                     (const_int 0)))
6565    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6566         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6567   "TARGET_64BIT"
6568   "@
6569    rldcl. %0,%1,%2,56
6570    rldicl. %0,%1,%H2,56
6571    #
6572    #"
6573   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6574    (set_attr "length" "4,4,8,8")])
6575
6576 (define_split
6577   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
6578         (compare:CC (zero_extend:DI
6579                      (subreg:QI
6580                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6581                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6582                     (const_int 0)))
6583    (set (match_operand:DI 0 "gpc_reg_operand" "")
6584         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6585   "TARGET_POWERPC64 && reload_completed"
6586   [(set (match_dup 0)
6587         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6588    (set (match_dup 3)
6589         (compare:CC (match_dup 0)
6590                     (const_int 0)))]
6591   "")
6592
6593 (define_insn "*rotldi3_internal10"
6594   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6595         (zero_extend:DI
6596          (subreg:HI
6597           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6598                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
6599   "TARGET_POWERPC64"
6600   "@
6601    rldcl %0,%1,%2,48
6602    rldicl %0,%1,%H2,48"
6603   [(set_attr "type" "var_shift_rotate,integer")])
6604
6605 (define_insn "*rotldi3_internal11"
6606   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6607         (compare:CC (zero_extend:DI
6608                      (subreg:HI
6609                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6610                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6611                     (const_int 0)))
6612    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6613   "TARGET_64BIT"
6614   "@
6615    rldcl. %3,%1,%2,48
6616    rldicl. %3,%1,%H2,48
6617    #
6618    #"
6619   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6620    (set_attr "length" "4,4,8,8")])
6621
6622 (define_split
6623   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6624         (compare:CC (zero_extend:DI
6625                      (subreg:HI
6626                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6627                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6628                     (const_int 0)))
6629    (clobber (match_scratch:DI 3 ""))]
6630   "TARGET_POWERPC64 && reload_completed"
6631   [(set (match_dup 3)
6632         (zero_extend:DI (subreg:HI
6633                       (rotate:DI (match_dup 1)
6634                                  (match_dup 2)) 0)))
6635    (set (match_dup 0)
6636         (compare:CC (match_dup 3)
6637                     (const_int 0)))]
6638   "")
6639
6640 (define_insn "*rotldi3_internal12"
6641   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6642         (compare:CC (zero_extend:DI
6643                      (subreg:HI
6644                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6645                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6646                     (const_int 0)))
6647    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6648         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6649   "TARGET_64BIT"
6650   "@
6651    rldcl. %0,%1,%2,48
6652    rldicl. %0,%1,%H2,48
6653    #
6654    #"
6655   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6656    (set_attr "length" "4,4,8,8")])
6657
6658 (define_split
6659   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
6660         (compare:CC (zero_extend:DI
6661                      (subreg:HI
6662                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6663                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6664                     (const_int 0)))
6665    (set (match_operand:DI 0 "gpc_reg_operand" "")
6666         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6667   "TARGET_POWERPC64 && reload_completed"
6668   [(set (match_dup 0)
6669         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6670    (set (match_dup 3)
6671         (compare:CC (match_dup 0)
6672                     (const_int 0)))]
6673   "")
6674
6675 (define_insn "*rotldi3_internal13"
6676   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6677         (zero_extend:DI
6678          (subreg:SI
6679           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6680                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
6681   "TARGET_POWERPC64"
6682   "@
6683    rldcl %0,%1,%2,32
6684    rldicl %0,%1,%H2,32"
6685   [(set_attr "type" "var_shift_rotate,integer")])
6686
6687 (define_insn "*rotldi3_internal14"
6688   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6689         (compare:CC (zero_extend:DI
6690                      (subreg:SI
6691                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6692                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6693                     (const_int 0)))
6694    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6695   "TARGET_64BIT"
6696   "@
6697    rldcl. %3,%1,%2,32
6698    rldicl. %3,%1,%H2,32
6699    #
6700    #"
6701   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6702    (set_attr "length" "4,4,8,8")])
6703
6704 (define_split
6705   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6706         (compare:CC (zero_extend:DI
6707                      (subreg:SI
6708                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6709                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6710                     (const_int 0)))
6711    (clobber (match_scratch:DI 3 ""))]
6712   "TARGET_POWERPC64 && reload_completed"
6713   [(set (match_dup 3)
6714         (zero_extend:DI (subreg:SI
6715                       (rotate:DI (match_dup 1)
6716                                  (match_dup 2)) 0)))
6717    (set (match_dup 0)
6718         (compare:CC (match_dup 3)
6719                     (const_int 0)))]
6720   "")
6721
6722 (define_insn "*rotldi3_internal15"
6723   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6724         (compare:CC (zero_extend:DI
6725                      (subreg:SI
6726                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6727                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6728                     (const_int 0)))
6729    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6730         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6731   "TARGET_64BIT"
6732   "@
6733    rldcl. %0,%1,%2,32
6734    rldicl. %0,%1,%H2,32
6735    #
6736    #"
6737   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6738    (set_attr "length" "4,4,8,8")])
6739
6740 (define_split
6741   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
6742         (compare:CC (zero_extend:DI
6743                      (subreg:SI
6744                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6745                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6746                     (const_int 0)))
6747    (set (match_operand:DI 0 "gpc_reg_operand" "")
6748         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6749   "TARGET_POWERPC64 && reload_completed"
6750   [(set (match_dup 0)
6751         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6752    (set (match_dup 3)
6753         (compare:CC (match_dup 0)
6754                     (const_int 0)))]
6755   "")
6756
6757 (define_expand "ashldi3"
6758   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6759         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6760                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
6761   "TARGET_POWERPC64"
6762   "")
6763
6764 (define_insn "*ashldi3_internal1"
6765   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6766         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6767                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
6768   "TARGET_POWERPC64"
6769   "@
6770    sld %0,%1,%2
6771    sldi %0,%1,%H2"
6772   [(set_attr "type" "var_shift_rotate,shift")])
6773
6774 (define_insn "*ashldi3_internal2"
6775   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6776         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6777                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
6778                     (const_int 0)))
6779    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6780   "TARGET_64BIT"
6781   "@
6782    sld. %3,%1,%2
6783    sldi. %3,%1,%H2
6784    #
6785    #"
6786   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6787    (set_attr "length" "4,4,8,8")])
6788
6789 (define_split
6790   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6791         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6792                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6793                     (const_int 0)))
6794    (clobber (match_scratch:DI 3 ""))]
6795   "TARGET_POWERPC64 && reload_completed"
6796   [(set (match_dup 3)
6797         (ashift:DI (match_dup 1) (match_dup 2)))
6798    (set (match_dup 0)
6799         (compare:CC (match_dup 3)
6800                     (const_int 0)))]
6801   "")
6802
6803 (define_insn "*ashldi3_internal3"
6804   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6805         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6806                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
6807                     (const_int 0)))
6808    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6809         (ashift:DI (match_dup 1) (match_dup 2)))]
6810   "TARGET_64BIT"
6811   "@
6812    sld. %0,%1,%2
6813    sldi. %0,%1,%H2
6814    #
6815    #"
6816   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6817    (set_attr "length" "4,4,8,8")])
6818
6819 (define_split
6820   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6821         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6822                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6823                     (const_int 0)))
6824    (set (match_operand:DI 0 "gpc_reg_operand" "")
6825         (ashift:DI (match_dup 1) (match_dup 2)))]
6826   "TARGET_POWERPC64 && reload_completed"
6827   [(set (match_dup 0)
6828         (ashift:DI (match_dup 1) (match_dup 2)))
6829    (set (match_dup 3)
6830         (compare:CC (match_dup 0)
6831                     (const_int 0)))]
6832   "")
6833
6834 (define_insn "*ashldi3_internal4"
6835   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6836         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6837                            (match_operand:SI 2 "const_int_operand" "i"))
6838                 (match_operand:DI 3 "const_int_operand" "n")))]
6839   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
6840   "rldic %0,%1,%H2,%W3")
6841
6842 (define_insn "ashldi3_internal5"
6843   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6844         (compare:CC
6845          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6846                             (match_operand:SI 2 "const_int_operand" "i,i"))
6847                  (match_operand:DI 3 "const_int_operand" "n,n"))
6848          (const_int 0)))
6849    (clobber (match_scratch:DI 4 "=r,r"))]
6850   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6851   "@
6852    rldic. %4,%1,%H2,%W3
6853    #"
6854   [(set_attr "type" "compare")
6855    (set_attr "length" "4,8")])
6856
6857 (define_split
6858   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6859         (compare:CC
6860          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6861                             (match_operand:SI 2 "const_int_operand" ""))
6862                  (match_operand:DI 3 "const_int_operand" ""))
6863          (const_int 0)))
6864    (clobber (match_scratch:DI 4 ""))]
6865   "TARGET_POWERPC64 && reload_completed
6866    && includes_rldic_lshift_p (operands[2], operands[3])"
6867   [(set (match_dup 4)
6868         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6869                 (match_dup 3)))
6870    (set (match_dup 0)
6871         (compare:CC (match_dup 4)
6872                     (const_int 0)))]
6873   "")
6874
6875 (define_insn "*ashldi3_internal6"
6876   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6877         (compare:CC
6878          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6879                             (match_operand:SI 2 "const_int_operand" "i,i"))
6880                     (match_operand:DI 3 "const_int_operand" "n,n"))
6881          (const_int 0)))
6882    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6883         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6884   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6885   "@
6886    rldic. %0,%1,%H2,%W3
6887    #"
6888   [(set_attr "type" "compare")
6889    (set_attr "length" "4,8")])
6890
6891 (define_split
6892   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
6893         (compare:CC
6894          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6895                             (match_operand:SI 2 "const_int_operand" ""))
6896                  (match_operand:DI 3 "const_int_operand" ""))
6897          (const_int 0)))
6898    (set (match_operand:DI 0 "gpc_reg_operand" "")
6899         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6900   "TARGET_POWERPC64 && reload_completed
6901    && includes_rldic_lshift_p (operands[2], operands[3])"
6902   [(set (match_dup 0)
6903         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6904                 (match_dup 3)))
6905    (set (match_dup 4)
6906         (compare:CC (match_dup 0)
6907                     (const_int 0)))]
6908   "")
6909
6910 (define_insn "*ashldi3_internal7"
6911   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6912         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6913                            (match_operand:SI 2 "const_int_operand" "i"))
6914                 (match_operand:DI 3 "mask64_operand" "n")))]
6915   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
6916   "rldicr %0,%1,%H2,%S3")
6917
6918 (define_insn "ashldi3_internal8"
6919   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6920         (compare:CC
6921          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6922                             (match_operand:SI 2 "const_int_operand" "i,i"))
6923                  (match_operand:DI 3 "mask64_operand" "n,n"))
6924          (const_int 0)))
6925    (clobber (match_scratch:DI 4 "=r,r"))]
6926   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6927   "@
6928    rldicr. %4,%1,%H2,%S3
6929    #"
6930   [(set_attr "type" "compare")
6931    (set_attr "length" "4,8")])
6932
6933 (define_split
6934   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
6935         (compare:CC
6936          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6937                             (match_operand:SI 2 "const_int_operand" ""))
6938                  (match_operand:DI 3 "mask64_operand" ""))
6939          (const_int 0)))
6940    (clobber (match_scratch:DI 4 ""))]
6941   "TARGET_POWERPC64 && reload_completed
6942    && includes_rldicr_lshift_p (operands[2], operands[3])"
6943   [(set (match_dup 4)
6944         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6945                 (match_dup 3)))
6946    (set (match_dup 0)
6947         (compare:CC (match_dup 4)
6948                     (const_int 0)))]
6949   "")
6950
6951 (define_insn "*ashldi3_internal9"
6952   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6953         (compare:CC
6954          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6955                             (match_operand:SI 2 "const_int_operand" "i,i"))
6956                     (match_operand:DI 3 "mask64_operand" "n,n"))
6957          (const_int 0)))
6958    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6959         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6960   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6961   "@
6962    rldicr. %0,%1,%H2,%S3
6963    #"
6964   [(set_attr "type" "compare")
6965    (set_attr "length" "4,8")])
6966
6967 (define_split
6968   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
6969         (compare:CC
6970          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6971                             (match_operand:SI 2 "const_int_operand" ""))
6972                  (match_operand:DI 3 "mask64_operand" ""))
6973          (const_int 0)))
6974    (set (match_operand:DI 0 "gpc_reg_operand" "")
6975         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6976   "TARGET_POWERPC64 && reload_completed
6977    && includes_rldicr_lshift_p (operands[2], operands[3])"
6978   [(set (match_dup 0)
6979         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6980                 (match_dup 3)))
6981    (set (match_dup 4)
6982         (compare:CC (match_dup 0)
6983                     (const_int 0)))]
6984   "")
6985
6986 (define_expand "lshrdi3"
6987   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6988         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
6989                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
6990   "TARGET_POWERPC64"
6991   "")
6992
6993 (define_insn "*lshrdi3_internal1"
6994   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6995         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6996                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
6997   "TARGET_POWERPC64"
6998   "@
6999    srd %0,%1,%2
7000    srdi %0,%1,%H2"
7001   [(set_attr "type" "var_shift_rotate,shift")])
7002
7003 (define_insn "*lshrdi3_internal2"
7004   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7005         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7006                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7007                     (const_int 0)))
7008    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7009   "TARGET_64BIT "
7010   "@
7011    srd. %3,%1,%2
7012    srdi. %3,%1,%H2
7013    #
7014    #"
7015   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7016    (set_attr "length" "4,4,8,8")])
7017
7018 (define_split
7019   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7020         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7021                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7022                     (const_int 0)))
7023    (clobber (match_scratch:DI 3 ""))]
7024   "TARGET_POWERPC64 && reload_completed"
7025   [(set (match_dup 3)
7026         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7027    (set (match_dup 0)
7028         (compare:CC (match_dup 3)
7029                     (const_int 0)))]
7030   "")
7031
7032 (define_insn "*lshrdi3_internal3"
7033   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7034         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7035                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7036                     (const_int 0)))
7037    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7038         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7039   "TARGET_64BIT"
7040   "@
7041    srd. %0,%1,%2
7042    srdi. %0,%1,%H2
7043    #
7044    #"
7045   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7046    (set_attr "length" "4,4,8,8")])
7047
7048 (define_split
7049   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7050         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7051                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7052                     (const_int 0)))
7053    (set (match_operand:DI 0 "gpc_reg_operand" "")
7054         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7055   "TARGET_POWERPC64 && reload_completed"
7056   [(set (match_dup 0)
7057         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7058    (set (match_dup 3)
7059         (compare:CC (match_dup 0)
7060                     (const_int 0)))]
7061   "")
7062
7063 (define_expand "ashrdi3"
7064   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7065         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7066                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7067   "WORDS_BIG_ENDIAN"
7068   "
7069 {
7070   if (TARGET_POWERPC64)
7071     ;
7072   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
7073            && WORDS_BIG_ENDIAN)
7074     {
7075       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
7076       DONE;
7077     }
7078   else
7079     FAIL;
7080 }")
7081
7082 (define_insn "*ashrdi3_internal1"
7083   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7084         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7085                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7086   "TARGET_POWERPC64"
7087   "@
7088    srad %0,%1,%2
7089    sradi %0,%1,%H2"
7090   [(set_attr "type" "var_shift_rotate,shift")])
7091
7092 (define_insn "*ashrdi3_internal2"
7093   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7094         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7095                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7096                     (const_int 0)))
7097    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7098   "TARGET_64BIT"
7099   "@
7100    srad. %3,%1,%2
7101    sradi. %3,%1,%H2
7102    #
7103    #"
7104   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7105    (set_attr "length" "4,4,8,8")])
7106
7107 (define_split
7108   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7109         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7110                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7111                     (const_int 0)))
7112    (clobber (match_scratch:DI 3 ""))]
7113   "TARGET_POWERPC64 && reload_completed"
7114   [(set (match_dup 3)
7115         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7116    (set (match_dup 0)
7117         (compare:CC (match_dup 3)
7118                     (const_int 0)))]
7119   "")
7120
7121 (define_insn "*ashrdi3_internal3"
7122   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7123         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7124                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7125                     (const_int 0)))
7126    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7127         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7128   "TARGET_64BIT"
7129   "@
7130    srad. %0,%1,%2
7131    sradi. %0,%1,%H2
7132    #
7133    #"
7134   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7135    (set_attr "length" "4,4,8,8")])
7136
7137 (define_split
7138   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7139         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7140                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7141                     (const_int 0)))
7142    (set (match_operand:DI 0 "gpc_reg_operand" "")
7143         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7144   "TARGET_POWERPC64 && reload_completed"
7145   [(set (match_dup 0)
7146         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7147    (set (match_dup 3)
7148         (compare:CC (match_dup 0)
7149                     (const_int 0)))]
7150   "")
7151
7152 (define_expand "anddi3"
7153   [(parallel
7154     [(set (match_operand:DI 0 "gpc_reg_operand" "")
7155           (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7156                   (match_operand:DI 2 "and64_2_operand" "")))
7157      (clobber (match_scratch:CC 3 ""))])]
7158   "TARGET_POWERPC64"
7159   "")
7160
7161 (define_insn "anddi3_mc"
7162   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
7163         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
7164                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
7165    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
7166   "TARGET_POWERPC64 && rs6000_gen_cell_microcode"
7167   "@
7168    and %0,%1,%2
7169    rldic%B2 %0,%1,0,%S2
7170    rlwinm %0,%1,0,%m2,%M2
7171    andi. %0,%1,%b2
7172    andis. %0,%1,%u2
7173    #"
7174   [(set_attr "type" "*,*,*,fast_compare,fast_compare,*")
7175    (set_attr "length" "4,4,4,4,4,8")])
7176
7177 (define_insn "anddi3_nomc"
7178   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7179         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
7180                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,t")))
7181    (clobber (match_scratch:CC 3 "=X,X,X,X"))]
7182   "TARGET_POWERPC64 && !rs6000_gen_cell_microcode"
7183   "@
7184    and %0,%1,%2
7185    rldic%B2 %0,%1,0,%S2
7186    rlwinm %0,%1,0,%m2,%M2
7187    #"
7188   [(set_attr "length" "4,4,4,8")])
7189
7190 (define_split
7191   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7192         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7193                 (match_operand:DI 2 "mask64_2_operand" "")))
7194    (clobber (match_scratch:CC 3 ""))]
7195   "TARGET_POWERPC64
7196     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7197     && !mask_operand (operands[2], DImode)
7198     && !mask64_operand (operands[2], DImode)"
7199   [(set (match_dup 0)
7200         (and:DI (rotate:DI (match_dup 1)
7201                            (match_dup 4))
7202                 (match_dup 5)))
7203    (set (match_dup 0)
7204         (and:DI (rotate:DI (match_dup 0)
7205                            (match_dup 6))
7206                 (match_dup 7)))]
7207 {
7208   build_mask64_2_operands (operands[2], &operands[4]);
7209 })
7210
7211 (define_insn "*anddi3_internal2_mc"
7212   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7213         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7214                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7215                     (const_int 0)))
7216    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r,r,r"))
7217    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7218   "TARGET_64BIT && rs6000_gen_cell_microcode"
7219   "@
7220    and. %3,%1,%2
7221    rldic%B2. %3,%1,0,%S2
7222    rlwinm. %3,%1,0,%m2,%M2
7223    andi. %3,%1,%b2
7224    andis. %3,%1,%u2
7225    #
7226    #
7227    #
7228    #
7229    #
7230    #
7231    #"
7232   [(set_attr "type" "fast_compare,compare,delayed_compare,fast_compare,\
7233                      fast_compare,compare,compare,compare,compare,compare,\
7234                      compare,compare")
7235    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7236
7237 (define_split
7238   [(set (match_operand:CC 0 "cc_reg_operand" "")
7239         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7240                             (match_operand:DI 2 "mask64_2_operand" ""))
7241                     (const_int 0)))
7242    (clobber (match_scratch:DI 3 ""))
7243    (clobber (match_scratch:CC 4 ""))]
7244   "TARGET_64BIT && reload_completed
7245     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7246     && !mask_operand (operands[2], DImode)
7247     && !mask64_operand (operands[2], DImode)"
7248   [(set (match_dup 3)
7249         (and:DI (rotate:DI (match_dup 1)
7250                            (match_dup 5))
7251                 (match_dup 6)))
7252    (parallel [(set (match_dup 0)
7253                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7254                                                   (match_dup 7))
7255                                        (match_dup 8))
7256                                (const_int 0)))
7257               (clobber (match_dup 3))])]
7258   "
7259 {
7260   build_mask64_2_operands (operands[2], &operands[5]);
7261 }")
7262
7263 (define_insn "*anddi3_internal3_mc"
7264   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7265         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7266                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7267                     (const_int 0)))
7268    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r,r,r")
7269         (and:DI (match_dup 1) (match_dup 2)))
7270    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7271   "TARGET_64BIT && rs6000_gen_cell_microcode"
7272   "@
7273    and. %0,%1,%2
7274    rldic%B2. %0,%1,0,%S2
7275    rlwinm. %0,%1,0,%m2,%M2
7276    andi. %0,%1,%b2
7277    andis. %0,%1,%u2
7278    #
7279    #
7280    #
7281    #
7282    #
7283    #
7284    #"
7285   [(set_attr "type" "fast_compare,compare,delayed_compare,fast_compare,\
7286                      fast_compare,compare,compare,compare,compare,compare,\
7287                      compare,compare")
7288    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7289
7290 (define_split
7291   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7292         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7293                             (match_operand:DI 2 "and64_2_operand" ""))
7294                     (const_int 0)))
7295    (set (match_operand:DI 0 "gpc_reg_operand" "")
7296         (and:DI (match_dup 1) (match_dup 2)))
7297    (clobber (match_scratch:CC 4 ""))]
7298   "TARGET_64BIT && reload_completed"
7299   [(parallel [(set (match_dup 0)
7300                     (and:DI (match_dup 1) (match_dup 2)))
7301                (clobber (match_dup 4))])
7302    (set (match_dup 3)
7303         (compare:CC (match_dup 0)
7304                     (const_int 0)))]
7305   "")
7306
7307 (define_split
7308   [(set (match_operand:CC 3 "cc_reg_operand" "")
7309         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7310                             (match_operand:DI 2 "mask64_2_operand" ""))
7311                     (const_int 0)))
7312    (set (match_operand:DI 0 "gpc_reg_operand" "")
7313         (and:DI (match_dup 1) (match_dup 2)))
7314    (clobber (match_scratch:CC 4 ""))]
7315   "TARGET_64BIT && reload_completed
7316     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7317     && !mask_operand (operands[2], DImode)
7318     && !mask64_operand (operands[2], DImode)"
7319   [(set (match_dup 0)
7320         (and:DI (rotate:DI (match_dup 1)
7321                            (match_dup 5))
7322                 (match_dup 6)))
7323    (parallel [(set (match_dup 3)
7324                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7325                                                   (match_dup 7))
7326                                        (match_dup 8))
7327                                (const_int 0)))
7328               (set (match_dup 0)
7329                    (and:DI (rotate:DI (match_dup 0)
7330                                       (match_dup 7))
7331                            (match_dup 8)))])]
7332   "
7333 {
7334   build_mask64_2_operands (operands[2], &operands[5]);
7335 }")
7336
7337 (define_expand "iordi3"
7338   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7339         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7340                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7341   "TARGET_POWERPC64"
7342   "
7343 {
7344   if (non_logical_cint_operand (operands[2], DImode))
7345     {
7346       HOST_WIDE_INT value;
7347       rtx tmp = ((!can_create_pseudo_p ()
7348                   || rtx_equal_p (operands[0], operands[1]))
7349                  ? operands[0] : gen_reg_rtx (DImode));
7350
7351       if (GET_CODE (operands[2]) == CONST_INT)
7352         {
7353           value = INTVAL (operands[2]);
7354           emit_insn (gen_iordi3 (tmp, operands[1],
7355                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7356         }
7357       else
7358         {
7359           value = CONST_DOUBLE_LOW (operands[2]);
7360           emit_insn (gen_iordi3 (tmp, operands[1],
7361                                  immed_double_const (value
7362                                                      & (~ (HOST_WIDE_INT) 0xffff),
7363                                                      0, DImode)));
7364         }
7365
7366       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7367       DONE;
7368     }
7369 }")
7370
7371 (define_expand "xordi3"
7372   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7373         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7374                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7375   "TARGET_POWERPC64"
7376   "
7377 {
7378   if (non_logical_cint_operand (operands[2], DImode))
7379     {
7380       HOST_WIDE_INT value;
7381       rtx tmp = ((!can_create_pseudo_p ()
7382                   || rtx_equal_p (operands[0], operands[1]))
7383                  ? operands[0] : gen_reg_rtx (DImode));
7384
7385       if (GET_CODE (operands[2]) == CONST_INT)
7386         {
7387           value = INTVAL (operands[2]);
7388           emit_insn (gen_xordi3 (tmp, operands[1],
7389                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7390         }
7391       else
7392         {
7393           value = CONST_DOUBLE_LOW (operands[2]);
7394           emit_insn (gen_xordi3 (tmp, operands[1],
7395                                  immed_double_const (value
7396                                                      & (~ (HOST_WIDE_INT) 0xffff),
7397                                                      0, DImode)));
7398         }
7399
7400       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7401       DONE;
7402     }
7403 }")
7404
7405 (define_insn "*booldi3_internal1"
7406   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7407         (match_operator:DI 3 "boolean_or_operator"
7408          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7409           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7410   "TARGET_POWERPC64"
7411   "@
7412    %q3 %0,%1,%2
7413    %q3i %0,%1,%b2
7414    %q3is %0,%1,%u2")
7415
7416 (define_insn "*booldi3_internal2"
7417   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7418         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7419          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7420           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7421          (const_int 0)))
7422    (clobber (match_scratch:DI 3 "=r,r"))]
7423   "TARGET_64BIT"
7424   "@
7425    %q4. %3,%1,%2
7426    #"
7427   [(set_attr "type" "fast_compare,compare")
7428    (set_attr "length" "4,8")])
7429
7430 (define_split
7431   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7432         (compare:CC (match_operator:DI 4 "boolean_operator"
7433          [(match_operand:DI 1 "gpc_reg_operand" "")
7434           (match_operand:DI 2 "gpc_reg_operand" "")])
7435          (const_int 0)))
7436    (clobber (match_scratch:DI 3 ""))]
7437   "TARGET_POWERPC64 && reload_completed"
7438   [(set (match_dup 3) (match_dup 4))
7439    (set (match_dup 0)
7440         (compare:CC (match_dup 3)
7441                     (const_int 0)))]
7442   "")
7443
7444 (define_insn "*booldi3_internal3"
7445   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7446         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7447          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7448           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7449          (const_int 0)))
7450    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7451         (match_dup 4))]
7452   "TARGET_64BIT"
7453   "@
7454    %q4. %0,%1,%2
7455    #"
7456   [(set_attr "type" "fast_compare,compare")
7457    (set_attr "length" "4,8")])
7458
7459 (define_split
7460   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7461         (compare:CC (match_operator:DI 4 "boolean_operator"
7462          [(match_operand:DI 1 "gpc_reg_operand" "")
7463           (match_operand:DI 2 "gpc_reg_operand" "")])
7464          (const_int 0)))
7465    (set (match_operand:DI 0 "gpc_reg_operand" "")
7466         (match_dup 4))]
7467   "TARGET_POWERPC64 && reload_completed"
7468   [(set (match_dup 0) (match_dup 4))
7469    (set (match_dup 3)
7470         (compare:CC (match_dup 0)
7471                     (const_int 0)))]
7472   "")
7473
7474 ;; Split a logical operation that we can't do in one insn into two insns,
7475 ;; each of which does one 16-bit part.  This is used by combine.
7476
7477 (define_split
7478   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7479         (match_operator:DI 3 "boolean_or_operator"
7480          [(match_operand:DI 1 "gpc_reg_operand" "")
7481           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7482   "TARGET_POWERPC64"
7483   [(set (match_dup 0) (match_dup 4))
7484    (set (match_dup 0) (match_dup 5))]
7485 "
7486 {
7487   rtx i3,i4;
7488
7489   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7490     {
7491       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7492       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7493                                         0, DImode);
7494       i4 = GEN_INT (value & 0xffff);
7495     }
7496   else
7497     {
7498       i3 = GEN_INT (INTVAL (operands[2])
7499                              & (~ (HOST_WIDE_INT) 0xffff));
7500       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7501     }
7502   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7503                                 operands[1], i3);
7504   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7505                                 operands[0], i4);
7506 }")
7507
7508 (define_insn "*boolcdi3_internal1"
7509   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7510         (match_operator:DI 3 "boolean_operator"
7511          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7512           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7513   "TARGET_POWERPC64"
7514   "%q3 %0,%2,%1")
7515
7516 (define_insn "*boolcdi3_internal2"
7517   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7518         (compare:CC (match_operator:DI 4 "boolean_operator"
7519          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7520           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7521          (const_int 0)))
7522    (clobber (match_scratch:DI 3 "=r,r"))]
7523   "TARGET_64BIT"
7524   "@
7525    %q4. %3,%2,%1
7526    #"
7527   [(set_attr "type" "fast_compare,compare")
7528    (set_attr "length" "4,8")])
7529
7530 (define_split
7531   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7532         (compare:CC (match_operator:DI 4 "boolean_operator"
7533          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7534           (match_operand:DI 2 "gpc_reg_operand" "")])
7535          (const_int 0)))
7536    (clobber (match_scratch:DI 3 ""))]
7537   "TARGET_POWERPC64 && reload_completed"
7538   [(set (match_dup 3) (match_dup 4))
7539    (set (match_dup 0)
7540         (compare:CC (match_dup 3)
7541                     (const_int 0)))]
7542   "")
7543
7544 (define_insn "*boolcdi3_internal3"
7545   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7546         (compare:CC (match_operator:DI 4 "boolean_operator"
7547          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7548           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7549          (const_int 0)))
7550    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7551         (match_dup 4))]
7552   "TARGET_64BIT"
7553   "@
7554    %q4. %0,%2,%1
7555    #"
7556   [(set_attr "type" "fast_compare,compare")
7557    (set_attr "length" "4,8")])
7558
7559 (define_split
7560   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7561         (compare:CC (match_operator:DI 4 "boolean_operator"
7562          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7563           (match_operand:DI 2 "gpc_reg_operand" "")])
7564          (const_int 0)))
7565    (set (match_operand:DI 0 "gpc_reg_operand" "")
7566         (match_dup 4))]
7567   "TARGET_POWERPC64 && reload_completed"
7568   [(set (match_dup 0) (match_dup 4))
7569    (set (match_dup 3)
7570         (compare:CC (match_dup 0)
7571                     (const_int 0)))]
7572   "")
7573
7574 (define_insn "*boolccdi3_internal1"
7575   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7576         (match_operator:DI 3 "boolean_operator"
7577          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7578           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7579   "TARGET_POWERPC64"
7580   "%q3 %0,%1,%2")
7581
7582 (define_insn "*boolccdi3_internal2"
7583   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7584         (compare:CC (match_operator:DI 4 "boolean_operator"
7585          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7586           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7587          (const_int 0)))
7588    (clobber (match_scratch:DI 3 "=r,r"))]
7589   "TARGET_64BIT"
7590   "@
7591    %q4. %3,%1,%2
7592    #"
7593   [(set_attr "type" "fast_compare,compare")
7594    (set_attr "length" "4,8")])
7595
7596 (define_split
7597   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
7598         (compare:CC (match_operator:DI 4 "boolean_operator"
7599          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7600           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7601          (const_int 0)))
7602    (clobber (match_scratch:DI 3 ""))]
7603   "TARGET_POWERPC64 && reload_completed"
7604   [(set (match_dup 3) (match_dup 4))
7605    (set (match_dup 0)
7606         (compare:CC (match_dup 3)
7607                     (const_int 0)))]
7608   "")
7609
7610 (define_insn "*boolccdi3_internal3"
7611   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7612         (compare:CC (match_operator:DI 4 "boolean_operator"
7613          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7614           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7615          (const_int 0)))
7616    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7617         (match_dup 4))]
7618   "TARGET_64BIT"
7619   "@
7620    %q4. %0,%1,%2
7621    #"
7622   [(set_attr "type" "fast_compare,compare")
7623    (set_attr "length" "4,8")])
7624
7625 (define_split
7626   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
7627         (compare:CC (match_operator:DI 4 "boolean_operator"
7628          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7629           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7630          (const_int 0)))
7631    (set (match_operand:DI 0 "gpc_reg_operand" "")
7632         (match_dup 4))]
7633   "TARGET_POWERPC64 && reload_completed"
7634   [(set (match_dup 0) (match_dup 4))
7635    (set (match_dup 3)
7636         (compare:CC (match_dup 0)
7637                     (const_int 0)))]
7638   "")
7639 \f
7640 ;; Now define ways of moving data around.
7641
7642 ;; Set up a register with a value from the GOT table
7643
7644 (define_expand "movsi_got"
7645   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7646         (unspec:SI [(match_operand:SI 1 "got_operand" "")
7647                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
7648   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7649   "
7650 {
7651   if (GET_CODE (operands[1]) == CONST)
7652     {
7653       rtx offset = const0_rtx;
7654       HOST_WIDE_INT value;
7655
7656       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
7657       value = INTVAL (offset);
7658       if (value != 0)
7659         {
7660           rtx tmp = (!can_create_pseudo_p ()
7661                      ? operands[0]
7662                      : gen_reg_rtx (Pmode));
7663           emit_insn (gen_movsi_got (tmp, operands[1]));
7664           emit_insn (gen_addsi3 (operands[0], tmp, offset));
7665           DONE;
7666         }
7667     }
7668
7669   operands[2] = rs6000_got_register (operands[1]);
7670 }")
7671
7672 (define_insn "*movsi_got_internal"
7673   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7674         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7675                     (match_operand:SI 2 "gpc_reg_operand" "b")]
7676                    UNSPEC_MOVSI_GOT))]
7677   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7678   "lwz %0,%a1@got(%2)"
7679   [(set_attr "type" "load")])
7680
7681 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
7682 ;; didn't get allocated to a hard register.
7683 (define_split
7684   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7685         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7686                     (match_operand:SI 2 "memory_operand" "")]
7687                    UNSPEC_MOVSI_GOT))]
7688   "DEFAULT_ABI == ABI_V4
7689     && flag_pic == 1
7690     && (reload_in_progress || reload_completed)"
7691   [(set (match_dup 0) (match_dup 2))
7692    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
7693                                  UNSPEC_MOVSI_GOT))]
7694   "")
7695
7696 ;; For SI, we special-case integers that can't be loaded in one insn.  We
7697 ;; do the load 16-bits at a time.  We could do this by loading from memory,
7698 ;; and this is even supposed to be faster, but it is simpler not to get
7699 ;; integers in the TOC.
7700 (define_insn "movsi_low"
7701   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7702         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7703                            (match_operand 2 "" ""))))]
7704   "TARGET_MACHO && ! TARGET_64BIT"
7705   "lwz %0,lo16(%2)(%1)"
7706   [(set_attr "type" "load")
7707    (set_attr "length" "4")])
7708
7709 (define_insn "*movsi_internal1"
7710   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,*c*l,*h,*h")
7711         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,*h,r,r,0"))]
7712   "!TARGET_SINGLE_FPU &&
7713    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
7714   "@
7715    mr %0,%1
7716    la %0,%a1
7717    lwz%U1%X1 %0,%1
7718    stw%U0%X0 %1,%0
7719    li %0,%1
7720    lis %0,%v1
7721    #
7722    mf%1 %0
7723    mt%0 %1
7724    mt%0 %1
7725    nop"
7726   [(set_attr "type" "*,*,load,store,*,*,*,mfjmpr,mtjmpr,*,*")
7727    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4")])
7728
7729 (define_insn "*movsi_internal1_single"
7730   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,*c*l,*h,*h,m,*f")
7731         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,*h,r,r,0,f,m"))]
7732   "TARGET_SINGLE_FPU &&
7733    (gpc_reg_operand (operands[0], SImode) || gpc_reg_operand (operands[1], SImode))"
7734   "@
7735    mr %0,%1
7736    la %0,%a1
7737    lwz%U1%X1 %0,%1
7738    stw%U0%X0 %1,%0
7739    li %0,%1
7740    lis %0,%v1
7741    #
7742    mf%1 %0
7743    mt%0 %1
7744    mt%0 %1
7745    nop
7746    stfs%U0%X0 %1,%0
7747    lfs%U1%X1 %0,%1"
7748   [(set_attr "type" "*,*,load,store,*,*,*,mfjmpr,mtjmpr,*,*,*,*")
7749    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
7750
7751 ;; Split a load of a large constant into the appropriate two-insn
7752 ;; sequence.
7753
7754 (define_split
7755   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7756         (match_operand:SI 1 "const_int_operand" ""))]
7757   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
7758    && (INTVAL (operands[1]) & 0xffff) != 0"
7759   [(set (match_dup 0)
7760         (match_dup 2))
7761    (set (match_dup 0)
7762         (ior:SI (match_dup 0)
7763                 (match_dup 3)))]
7764   "
7765 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
7766
7767   if (tem == operands[0])
7768     DONE;
7769   else
7770     FAIL;
7771 }")
7772
7773 (define_insn "*mov<mode>_internal2"
7774   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
7775         (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
7776                     (const_int 0)))
7777    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
7778   ""
7779   "@
7780    cmp<wd>i %2,%0,0
7781    mr. %0,%1
7782    #"
7783   [(set_attr "type" "cmp,compare,cmp")
7784    (set_attr "length" "4,4,8")])
7785
7786 (define_split
7787   [(set (match_operand:CC 2 "cc_reg_not_micro_cr0_operand" "")
7788         (compare:CC (match_operand:P 1 "gpc_reg_operand" "")
7789                     (const_int 0)))
7790    (set (match_operand:P 0 "gpc_reg_operand" "") (match_dup 1))]
7791   "reload_completed"
7792   [(set (match_dup 0) (match_dup 1))
7793    (set (match_dup 2)
7794         (compare:CC (match_dup 0)
7795                     (const_int 0)))]
7796   "")
7797 \f
7798 (define_insn "*movhi_internal"
7799   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*c*l,*h")
7800         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,0"))]
7801   "gpc_reg_operand (operands[0], HImode)
7802    || gpc_reg_operand (operands[1], HImode)"
7803   "@
7804    mr %0,%1
7805    lhz%U1%X1 %0,%1
7806    sth%U0%X0 %1,%0
7807    li %0,%w1
7808    mf%1 %0
7809    mt%0 %1
7810    nop"
7811   [(set_attr "type" "*,load,store,*,mfjmpr,mtjmpr,*")])
7812
7813 (define_expand "mov<mode>"
7814   [(set (match_operand:INT 0 "general_operand" "")
7815         (match_operand:INT 1 "any_operand" ""))]
7816   ""
7817   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
7818
7819 (define_insn "*movqi_internal"
7820   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*c*l,*h")
7821         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,0"))]
7822   "gpc_reg_operand (operands[0], QImode)
7823    || gpc_reg_operand (operands[1], QImode)"
7824   "@
7825    mr %0,%1
7826    lbz%U1%X1 %0,%1
7827    stb%U0%X0 %1,%0
7828    li %0,%1
7829    mf%1 %0
7830    mt%0 %1
7831    nop"
7832   [(set_attr "type" "*,load,store,*,mfjmpr,mtjmpr,*")])
7833 \f
7834 ;; Here is how to move condition codes around.  When we store CC data in
7835 ;; an integer register or memory, we store just the high-order 4 bits.
7836 ;; This lets us not shift in the most common case of CR0.
7837 (define_expand "movcc"
7838   [(set (match_operand:CC 0 "nonimmediate_operand" "")
7839         (match_operand:CC 1 "nonimmediate_operand" ""))]
7840   ""
7841   "")
7842
7843 (define_insn "*movcc_internal1"
7844   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,y,r,r,r,r,r,cl,r,m")
7845         (match_operand:CC 1 "general_operand" "y,r,r,O,x,y,r,I,h,r,m,r"))]
7846   "register_operand (operands[0], CCmode)
7847    || register_operand (operands[1], CCmode)"
7848   "@
7849    mcrf %0,%1
7850    mtcrf 128,%1
7851    rlwinm %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;rlwinm %1,%1,%f0,0xffffffff
7852    crxor %0,%0,%0
7853    mfcr %0%Q1
7854    mfcr %0%Q1\;rlwinm %0,%0,%f1,0xf0000000
7855    mr %0,%1
7856    li %0,%1
7857    mf%1 %0
7858    mt%0 %1
7859    lwz%U1%X1 %0,%1
7860    stw%U0%U1 %1,%0"
7861   [(set (attr "type")
7862      (cond [(eq_attr "alternative" "0,3")
7863                 (const_string "cr_logical")
7864             (eq_attr "alternative" "1,2")
7865                 (const_string "mtcr")
7866             (eq_attr "alternative" "6,7")
7867                 (const_string "integer")
7868             (eq_attr "alternative" "8")
7869                 (const_string "mfjmpr")
7870             (eq_attr "alternative" "9")
7871                 (const_string "mtjmpr")
7872             (eq_attr "alternative" "10")
7873                 (const_string "load")
7874             (eq_attr "alternative" "11")
7875                 (const_string "store")
7876             (match_test "TARGET_MFCRF")
7877                 (const_string "mfcrf")
7878            ]
7879         (const_string "mfcr")))
7880    (set_attr "length" "4,4,12,4,4,8,4,4,4,4,4,4")])
7881 \f
7882 ;; For floating-point, we normally deal with the floating-point registers
7883 ;; unless -msoft-float is used.  The sole exception is that parameter passing
7884 ;; can produce floating-point values in fixed-point registers.  Unless the
7885 ;; value is a simple constant or already in memory, we deal with this by
7886 ;; allocating memory and copying the value explicitly via that memory location.
7887 (define_expand "movsf"
7888   [(set (match_operand:SF 0 "nonimmediate_operand" "")
7889         (match_operand:SF 1 "any_operand" ""))]
7890   ""
7891   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
7892
7893 (define_split
7894   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7895         (match_operand:SF 1 "const_double_operand" ""))]
7896   "reload_completed
7897    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7898        || (GET_CODE (operands[0]) == SUBREG
7899            && GET_CODE (SUBREG_REG (operands[0])) == REG
7900            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7901   [(set (match_dup 2) (match_dup 3))]
7902   "
7903 {
7904   long l;
7905   REAL_VALUE_TYPE rv;
7906
7907   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7908   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
7909
7910   if (! TARGET_POWERPC64)
7911     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
7912   else
7913     operands[2] = gen_lowpart (SImode, operands[0]);
7914
7915   operands[3] = gen_int_mode (l, SImode);
7916 }")
7917
7918 (define_insn "*movsf_hardfloat"
7919   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,*c*l,!r,*h,!r,!r")
7920         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,h,0,G,Fn"))]
7921   "(gpc_reg_operand (operands[0], SFmode)
7922    || gpc_reg_operand (operands[1], SFmode))
7923    && (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT)"
7924   "@
7925    mr %0,%1
7926    lwz%U1%X1 %0,%1
7927    stw%U0%X0 %1,%0
7928    fmr %0,%1
7929    lfs%U1%X1 %0,%1
7930    stfs%U0%X0 %1,%0
7931    mt%0 %1
7932    mf%1 %0
7933    nop
7934    #
7935    #"
7936   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,mfjmpr,*,*,*")
7937    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8")])
7938
7939 (define_insn "*movsf_softfloat"
7940   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,r,r,m,r,r,r,r,*h")
7941         (match_operand:SF 1 "input_operand" "r,r,h,m,r,I,L,G,Fn,0"))]
7942   "(gpc_reg_operand (operands[0], SFmode)
7943    || gpc_reg_operand (operands[1], SFmode))
7944    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
7945   "@
7946    mr %0,%1
7947    mt%0 %1
7948    mf%1 %0
7949    lwz%U1%X1 %0,%1
7950    stw%U0%X0 %1,%0
7951    li %0,%1
7952    lis %0,%v1
7953    #
7954    #
7955    nop"
7956   [(set_attr "type" "*,mtjmpr,mfjmpr,load,store,*,*,*,*,*")
7957    (set_attr "length" "4,4,4,4,4,4,4,4,8,4")])
7958
7959 \f
7960 (define_expand "movdf"
7961   [(set (match_operand:DF 0 "nonimmediate_operand" "")
7962         (match_operand:DF 1 "any_operand" ""))]
7963   ""
7964   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
7965
7966 (define_split
7967   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7968         (match_operand:DF 1 "const_int_operand" ""))]
7969   "! TARGET_POWERPC64 && reload_completed
7970    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7971        || (GET_CODE (operands[0]) == SUBREG
7972            && GET_CODE (SUBREG_REG (operands[0])) == REG
7973            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7974   [(set (match_dup 2) (match_dup 4))
7975    (set (match_dup 3) (match_dup 1))]
7976   "
7977 {
7978   int endian = (WORDS_BIG_ENDIAN == 0);
7979   HOST_WIDE_INT value = INTVAL (operands[1]);
7980
7981   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
7982   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
7983 #if HOST_BITS_PER_WIDE_INT == 32
7984   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
7985 #else
7986   operands[4] = GEN_INT (value >> 32);
7987   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
7988 #endif
7989 }")
7990
7991 (define_split
7992   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7993         (match_operand:DF 1 "const_double_operand" ""))]
7994   "! TARGET_POWERPC64 && reload_completed
7995    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7996        || (GET_CODE (operands[0]) == SUBREG
7997            && GET_CODE (SUBREG_REG (operands[0])) == REG
7998            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7999   [(set (match_dup 2) (match_dup 4))
8000    (set (match_dup 3) (match_dup 5))]
8001   "
8002 {
8003   int endian = (WORDS_BIG_ENDIAN == 0);
8004   long l[2];
8005   REAL_VALUE_TYPE rv;
8006
8007   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8008   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8009
8010   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8011   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8012   operands[4] = gen_int_mode (l[endian], SImode);
8013   operands[5] = gen_int_mode (l[1 - endian], SImode);
8014 }")
8015
8016 (define_split
8017   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8018         (match_operand:DF 1 "const_double_operand" ""))]
8019   "TARGET_POWERPC64 && reload_completed
8020    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8021        || (GET_CODE (operands[0]) == SUBREG
8022            && GET_CODE (SUBREG_REG (operands[0])) == REG
8023            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8024   [(set (match_dup 2) (match_dup 3))]
8025   "
8026 {
8027   int endian = (WORDS_BIG_ENDIAN == 0);
8028   long l[2];
8029   REAL_VALUE_TYPE rv;
8030 #if HOST_BITS_PER_WIDE_INT >= 64
8031   HOST_WIDE_INT val;
8032 #endif
8033
8034   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8035   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8036
8037   operands[2] = gen_lowpart (DImode, operands[0]);
8038   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
8039 #if HOST_BITS_PER_WIDE_INT >= 64
8040   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
8041          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
8042
8043   operands[3] = gen_int_mode (val, DImode);
8044 #else
8045   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
8046 #endif
8047 }")
8048
8049 ;; Don't have reload use general registers to load a constant.  It is
8050 ;; less efficient than loading the constant into an FP register, since
8051 ;; it will probably be used there.
8052
8053 ;; The move constraints are ordered to prefer floating point registers before
8054 ;; general purpose registers to avoid doing a store and a load to get the value
8055 ;; into a floating point register when it is needed for a floating point
8056 ;; operation.  Prefer traditional floating point registers over VSX registers,
8057 ;; since the D-form version of the memory instructions does not need a GPR for
8058 ;; reloading.
8059
8060 (define_insn "*movdf_hardfloat32"
8061   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,d,d,ws,?wa,Z,?Z,ws,?wa,wa,Y,r,!r,!r,!r,!r")
8062         (match_operand:DF 1 "input_operand" "d,m,d,Z,Z,ws,wa,ws,wa,j,r,Y,r,G,H,F"))]
8063   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
8064    && (gpc_reg_operand (operands[0], DFmode)
8065        || gpc_reg_operand (operands[1], DFmode))"
8066   "@
8067    stfd%U0%X0 %1,%0
8068    lfd%U1%X1 %0,%1
8069    fmr %0,%1
8070    lxsd%U1x %x0,%y1
8071    lxsd%U1x %x0,%y1
8072    stxsd%U0x %x1,%y0
8073    stxsd%U0x %x1,%y0
8074    xxlor %x0,%x1,%x1
8075    xxlor %x0,%x1,%x1
8076    xxlxor %x0,%x0,%x0
8077    #
8078    #
8079    #
8080    #
8081    #
8082    #"
8083   [(set_attr "type" "fpstore,fpload,fp,fpload,fpload,fpstore,fpstore,vecsimple,vecsimple,vecsimple,store,load,two,fp,fp,*")
8084    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,8,8,8,12,16")])
8085
8086 (define_insn "*movdf_softfloat32"
8087   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,r,r,r,r")
8088         (match_operand:DF 1 "input_operand" "r,Y,r,G,H,F"))]
8089   "! TARGET_POWERPC64 
8090    && ((TARGET_FPRS && TARGET_SINGLE_FLOAT) 
8091        || TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
8092    && (gpc_reg_operand (operands[0], DFmode)
8093        || gpc_reg_operand (operands[1], DFmode))"
8094   "#"
8095   [(set_attr "type" "store,load,two,*,*,*")
8096    (set_attr "length" "8,8,8,8,12,16")])
8097
8098 ;; Reload patterns to support gpr load/store with misaligned mem.
8099 ;; and multiple gpr load/store at offset >= 0xfffc
8100 (define_expand "reload_<mode>_store"
8101   [(parallel [(match_operand 0 "memory_operand" "=m")
8102               (match_operand 1 "gpc_reg_operand" "r")
8103               (match_operand:GPR 2 "register_operand" "=&b")])]
8104   ""
8105 {
8106   rs6000_secondary_reload_gpr (operands[1], operands[0], operands[2], true);
8107   DONE;
8108 })
8109
8110 (define_expand "reload_<mode>_load"
8111   [(parallel [(match_operand 0 "gpc_reg_operand" "=r")
8112               (match_operand 1 "memory_operand" "m")
8113               (match_operand:GPR 2 "register_operand" "=b")])]
8114   ""
8115 {
8116   rs6000_secondary_reload_gpr (operands[0], operands[1], operands[2], false);
8117   DONE;
8118 })
8119
8120 ; ld/std require word-aligned displacements -> 'Y' constraint.
8121 ; List Y->r and r->Y before r->r for reload.
8122 (define_insn "*movdf_hardfloat64_mfpgpr"
8123   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,ws,?wa,ws,?wa,Z,?Z,m,d,d,wa,*c*l,!r,*h,!r,!r,!r,r,d")
8124         (match_operand:DF 1 "input_operand" "r,Y,r,ws,?wa,Z,Z,ws,wa,d,m,d,j,r,h,0,G,H,F,d,r"))]
8125   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS 
8126    && TARGET_DOUBLE_FLOAT
8127    && (gpc_reg_operand (operands[0], DFmode)
8128        || gpc_reg_operand (operands[1], DFmode))"
8129   "@
8130    std%U0%X0 %1,%0
8131    ld%U1%X1 %0,%1
8132    mr %0,%1
8133    xxlor %x0,%x1,%x1
8134    xxlor %x0,%x1,%x1
8135    lxsd%U1x %x0,%y1
8136    lxsd%U1x %x0,%y1
8137    stxsd%U0x %x1,%y0
8138    stxsd%U0x %x1,%y0
8139    stfd%U0%X0 %1,%0
8140    lfd%U1%X1 %0,%1
8141    fmr %0,%1
8142    xxlxor %x0,%x0,%x0
8143    mt%0 %1
8144    mf%1 %0
8145    nop
8146    #
8147    #
8148    #
8149    mftgpr %0,%1
8150    mffgpr %0,%1"
8151   [(set_attr "type" "store,load,*,fp,fp,fpload,fpload,fpstore,fpstore,fpstore,fpload,fp,vecsimple,mtjmpr,mfjmpr,*,*,*,*,mftgpr,mffgpr")
8152    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16,4,4")])
8153
8154 ; ld/std require word-aligned displacements -> 'Y' constraint.
8155 ; List Y->r and r->Y before r->r for reload.
8156 (define_insn "*movdf_hardfloat64"
8157   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,d,d,Y,r,!r,ws,?wa,Z,?Z,ws,?wa,wa,*c*l,!r,*h,!r,!r,!r")
8158         (match_operand:DF 1 "input_operand" "d,m,d,r,Y,r,Z,Z,ws,wa,ws,wa,j,r,h,0,G,H,F"))]
8159   "TARGET_POWERPC64 && !TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS 
8160    && TARGET_DOUBLE_FLOAT
8161    && (gpc_reg_operand (operands[0], DFmode)
8162        || gpc_reg_operand (operands[1], DFmode))"
8163   "@
8164    stfd%U0%X0 %1,%0
8165    lfd%U1%X1 %0,%1
8166    fmr %0,%1
8167    std%U0%X0 %1,%0
8168    ld%U1%X1 %0,%1
8169    mr %0,%1
8170    lxsd%U1x %x0,%y1
8171    lxsd%U1x %x0,%y1
8172    stxsd%U0x %x1,%y0
8173    stxsd%U0x %x1,%y0
8174    xxlor %x0,%x1,%x1
8175    xxlor %x0,%x1,%x1
8176    xxlxor %x0,%x0,%x0
8177    mt%0 %1
8178    mf%1 %0
8179    nop
8180    #
8181    #
8182    #"
8183   [(set_attr "type" "fpstore,fpload,fp,store,load,*,fpload,fpload,fpstore,fpstore,vecsimple,vecsimple,vecsimple,mtjmpr,mfjmpr,*,*,*,*")
8184    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8,12,16")])
8185
8186 (define_insn "*movdf_softfloat64"
8187   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,r,cl,r,r,r,r,*h")
8188         (match_operand:DF 1 "input_operand" "r,Y,r,r,h,G,H,F,0"))]
8189   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8190    && (gpc_reg_operand (operands[0], DFmode)
8191        || gpc_reg_operand (operands[1], DFmode))"
8192   "@
8193    std%U0%X0 %1,%0
8194    ld%U1%X1 %0,%1
8195    mr %0,%1
8196    mt%0 %1
8197    mf%1 %0
8198    #
8199    #
8200    #
8201    nop"
8202   [(set_attr "type" "store,load,*,mtjmpr,mfjmpr,*,*,*,*")
8203    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
8204 \f
8205 (define_expand "movtf"
8206   [(set (match_operand:TF 0 "general_operand" "")
8207         (match_operand:TF 1 "any_operand" ""))]
8208   "!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128"
8209   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
8210
8211 ;; It's important to list Y->r and r->Y before r->r because otherwise
8212 ;; reload, given m->r, will try to pick r->r and reload it, which
8213 ;; doesn't make progress.
8214 (define_insn_and_split "*movtf_internal"
8215   [(set (match_operand:TF 0 "nonimmediate_operand" "=m,d,d,Y,r,r")
8216         (match_operand:TF 1 "input_operand" "d,m,d,r,YGHF,r"))]
8217   "!TARGET_IEEEQUAD
8218    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
8219    && (gpc_reg_operand (operands[0], TFmode)
8220        || gpc_reg_operand (operands[1], TFmode))"
8221   "#"
8222   "&& reload_completed"
8223   [(pc)]
8224 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8225   [(set_attr "length" "8,8,8,20,20,16")])
8226
8227 (define_insn_and_split "*movtf_softfloat"
8228   [(set (match_operand:TF 0 "rs6000_nonimmediate_operand" "=Y,r,r")
8229         (match_operand:TF 1 "input_operand"         "r,YGHF,r"))]
8230   "!TARGET_IEEEQUAD
8231    && (TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_LONG_DOUBLE_128
8232    && (gpc_reg_operand (operands[0], TFmode)
8233        || gpc_reg_operand (operands[1], TFmode))"
8234   "#"
8235   "&& reload_completed"
8236   [(pc)]
8237 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8238   [(set_attr "length" "20,20,16")])
8239
8240 (define_expand "extenddftf2"
8241   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8242         (float_extend:TF (match_operand:DF 1 "input_operand" "")))]
8243   "!TARGET_IEEEQUAD
8244    && TARGET_HARD_FLOAT
8245    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8246    && TARGET_LONG_DOUBLE_128"
8247 {
8248   if (TARGET_E500_DOUBLE)
8249     emit_insn (gen_spe_extenddftf2 (operands[0], operands[1]));
8250   else
8251     emit_insn (gen_extenddftf2_fprs (operands[0], operands[1]));
8252   DONE;
8253 })
8254
8255 (define_expand "extenddftf2_fprs"
8256   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
8257                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
8258               (use (match_dup 2))])]
8259   "!TARGET_IEEEQUAD
8260    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
8261    && TARGET_LONG_DOUBLE_128"
8262 {
8263   operands[2] = CONST0_RTX (DFmode);
8264   /* Generate GOT reference early for SVR4 PIC.  */
8265   if (DEFAULT_ABI == ABI_V4 && flag_pic)
8266     operands[2] = validize_mem (force_const_mem (DFmode, operands[2]));
8267 })
8268
8269 (define_insn_and_split "*extenddftf2_internal"
8270   [(set (match_operand:TF 0 "nonimmediate_operand" "=m,Y,d,&d,r")
8271        (float_extend:TF (match_operand:DF 1 "input_operand" "d,r,md,md,rmGHF")))
8272    (use (match_operand:DF 2 "zero_reg_mem_operand" "d,r,m,d,n"))]
8273   "!TARGET_IEEEQUAD
8274    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
8275    && TARGET_LONG_DOUBLE_128"
8276   "#"
8277   "&& reload_completed"
8278   [(pc)]
8279 {
8280   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8281   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8282   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
8283                   operands[1]);
8284   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
8285                   operands[2]);
8286   DONE;
8287 })
8288
8289 (define_expand "extendsftf2"
8290   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8291         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
8292   "!TARGET_IEEEQUAD
8293    && TARGET_HARD_FLOAT
8294    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8295    && TARGET_LONG_DOUBLE_128"
8296 {
8297   rtx tmp = gen_reg_rtx (DFmode);
8298   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
8299   emit_insn (gen_extenddftf2 (operands[0], tmp));
8300   DONE;
8301 })
8302
8303 (define_expand "trunctfdf2"
8304   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8305         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
8306   "!TARGET_IEEEQUAD
8307    && TARGET_HARD_FLOAT
8308    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8309    && TARGET_LONG_DOUBLE_128"
8310   "")
8311
8312 (define_insn_and_split "trunctfdf2_internal1"
8313   [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d")
8314         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,d")))]
8315   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
8316    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8317   "@
8318    #
8319    fmr %0,%1"
8320   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
8321   [(const_int 0)]
8322 {
8323   emit_note (NOTE_INSN_DELETED);
8324   DONE;
8325 }
8326   [(set_attr "type" "fp")])
8327
8328 (define_insn "trunctfdf2_internal2"
8329   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
8330         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "d")))]
8331   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
8332    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
8333    && TARGET_LONG_DOUBLE_128"
8334   "fadd %0,%1,%L1"
8335   [(set_attr "type" "fp")
8336    (set_attr "fp_type" "fp_addsub_d")])
8337
8338 (define_expand "trunctfsf2"
8339   [(set (match_operand:SF 0 "gpc_reg_operand" "")
8340         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "")))]
8341   "!TARGET_IEEEQUAD
8342    && TARGET_HARD_FLOAT
8343    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8344    && TARGET_LONG_DOUBLE_128"
8345 {
8346   if (TARGET_E500_DOUBLE)
8347     emit_insn (gen_spe_trunctfsf2 (operands[0], operands[1]));
8348   else
8349     emit_insn (gen_trunctfsf2_fprs (operands[0], operands[1]));
8350   DONE;
8351 })
8352
8353 (define_insn_and_split "trunctfsf2_fprs"
8354   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8355         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "d")))
8356    (clobber (match_scratch:DF 2 "=d"))]
8357   "!TARGET_IEEEQUAD
8358    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT 
8359    && TARGET_LONG_DOUBLE_128"
8360   "#"
8361   "&& reload_completed"
8362   [(set (match_dup 2)
8363         (float_truncate:DF (match_dup 1)))
8364    (set (match_dup 0)
8365         (float_truncate:SF (match_dup 2)))]
8366   "")
8367
8368 (define_expand "floatsitf2"
8369   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8370         (float:TF (match_operand:SI 1 "gpc_reg_operand" "")))]
8371   "!TARGET_IEEEQUAD
8372    && TARGET_HARD_FLOAT
8373    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8374    && TARGET_LONG_DOUBLE_128"
8375 {
8376   rtx tmp = gen_reg_rtx (DFmode);
8377   expand_float (tmp, operands[1], false);
8378   emit_insn (gen_extenddftf2 (operands[0], tmp));
8379   DONE;
8380 })
8381
8382 ; fadd, but rounding towards zero.
8383 ; This is probably not the optimal code sequence.
8384 (define_insn "fix_trunc_helper"
8385   [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
8386         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "d")]
8387                    UNSPEC_FIX_TRUNC_TF))
8388    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&d"))]
8389   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT"
8390   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
8391   [(set_attr "type" "fp")
8392    (set_attr "length" "20")])
8393
8394 (define_expand "fix_trunctfsi2"
8395   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8396         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))]
8397   "!TARGET_IEEEQUAD && TARGET_HARD_FLOAT
8398    && (TARGET_FPRS || TARGET_E500_DOUBLE) && TARGET_LONG_DOUBLE_128"
8399 {
8400   if (TARGET_E500_DOUBLE)
8401     emit_insn (gen_spe_fix_trunctfsi2 (operands[0], operands[1]));
8402   else
8403     emit_insn (gen_fix_trunctfsi2_fprs (operands[0], operands[1]));
8404   DONE;
8405 })
8406
8407 (define_expand "fix_trunctfsi2_fprs"
8408   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
8409                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
8410               (clobber (match_dup 2))
8411               (clobber (match_dup 3))
8412               (clobber (match_dup 4))
8413               (clobber (match_dup 5))])]
8414   "!TARGET_IEEEQUAD
8415    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8416 {
8417   operands[2] = gen_reg_rtx (DFmode);
8418   operands[3] = gen_reg_rtx (DFmode);
8419   operands[4] = gen_reg_rtx (DImode);
8420   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode));
8421 })
8422
8423 (define_insn_and_split "*fix_trunctfsi2_internal"
8424   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8425         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "d")))
8426    (clobber (match_operand:DF 2 "gpc_reg_operand" "=d"))
8427    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&d"))
8428    (clobber (match_operand:DI 4 "gpc_reg_operand" "=d"))
8429    (clobber (match_operand:DI 5 "offsettable_mem_operand" "=o"))]
8430   "!TARGET_IEEEQUAD
8431    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8432   "#"
8433   ""
8434   [(pc)]
8435 {
8436   rtx lowword;
8437   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
8438
8439   gcc_assert (MEM_P (operands[5]));
8440   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
8441
8442   emit_insn (gen_fctiwz_df (operands[4], operands[2]));
8443   emit_move_insn (operands[5], operands[4]);
8444   emit_move_insn (operands[0], lowword);
8445   DONE;
8446 })
8447
8448 (define_expand "negtf2"
8449   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8450         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
8451   "!TARGET_IEEEQUAD
8452    && TARGET_HARD_FLOAT
8453    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8454    && TARGET_LONG_DOUBLE_128"
8455   "")
8456
8457 (define_insn "negtf2_internal"
8458   [(set (match_operand:TF 0 "gpc_reg_operand" "=d")
8459         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "d")))]
8460   "!TARGET_IEEEQUAD
8461    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8462   "*
8463 {
8464   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8465     return \"fneg %L0,%L1\;fneg %0,%1\";
8466   else
8467     return \"fneg %0,%1\;fneg %L0,%L1\";
8468 }"
8469   [(set_attr "type" "fp")
8470    (set_attr "length" "8")])
8471
8472 (define_expand "abstf2"
8473   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8474         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
8475   "!TARGET_IEEEQUAD
8476    && TARGET_HARD_FLOAT
8477    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8478    && TARGET_LONG_DOUBLE_128"
8479   "
8480 {
8481   rtx label = gen_label_rtx ();
8482   if (TARGET_E500_DOUBLE)
8483     {
8484       if (flag_finite_math_only && !flag_trapping_math)
8485         emit_insn (gen_spe_abstf2_tst (operands[0], operands[1], label));
8486       else
8487         emit_insn (gen_spe_abstf2_cmp (operands[0], operands[1], label));
8488     }
8489   else
8490     emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
8491   emit_label (label);
8492   DONE;
8493 }")
8494
8495 (define_expand "abstf2_internal"
8496   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8497         (match_operand:TF 1 "gpc_reg_operand" ""))
8498    (set (match_dup 3) (match_dup 5))
8499    (set (match_dup 5) (abs:DF (match_dup 5)))
8500    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
8501    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
8502                            (label_ref (match_operand 2 "" ""))
8503                            (pc)))
8504    (set (match_dup 6) (neg:DF (match_dup 6)))]
8505   "!TARGET_IEEEQUAD
8506    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT 
8507    && TARGET_LONG_DOUBLE_128"
8508   "
8509 {
8510   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8511   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8512   operands[3] = gen_reg_rtx (DFmode);
8513   operands[4] = gen_reg_rtx (CCFPmode);
8514   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
8515   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
8516 }")
8517 \f
8518 ;; Next come the multi-word integer load and store and the load and store
8519 ;; multiple insns.
8520
8521 ;; List r->r after r->Y, otherwise reload will try to reload a
8522 ;; non-offsettable address by using r->r which won't make progress.
8523 ;; Use of fprs is disparaged slightly otherwise reload prefers to reload
8524 ;; a gpr into a fpr instead of reloading an invalid 'Y' address
8525 (define_insn "*movdi_internal32"
8526   [(set (match_operand:DI 0 "rs6000_nonimmediate_operand" "=Y,r,r,?m,?*d,?*d,r,?wa")
8527         (match_operand:DI 1 "input_operand" "r,Y,r,d,m,d,IJKnGHF,O"))]
8528   "! TARGET_POWERPC64
8529    && (gpc_reg_operand (operands[0], DImode)
8530        || gpc_reg_operand (operands[1], DImode))"
8531   "@
8532    #
8533    #
8534    #
8535    stfd%U0%X0 %1,%0
8536    lfd%U1%X1 %0,%1
8537    fmr %0,%1
8538    #
8539    xxlxor %x0,%x0,%x0"
8540   [(set_attr "type" "store,load,*,fpstore,fpload,fp,*,vecsimple")])
8541
8542 (define_split
8543   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8544         (match_operand:DI 1 "const_int_operand" ""))]
8545   "! TARGET_POWERPC64 && reload_completed
8546    && gpr_or_gpr_p (operands[0], operands[1])"
8547   [(set (match_dup 2) (match_dup 4))
8548    (set (match_dup 3) (match_dup 1))]
8549   "
8550 {
8551   HOST_WIDE_INT value = INTVAL (operands[1]);
8552   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8553                                        DImode);
8554   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8555                                        DImode);
8556 #if HOST_BITS_PER_WIDE_INT == 32
8557   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8558 #else
8559   operands[4] = GEN_INT (value >> 32);
8560   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8561 #endif
8562 }")
8563
8564 (define_split
8565   [(set (match_operand:DIFD 0 "rs6000_nonimmediate_operand" "")
8566         (match_operand:DIFD 1 "input_operand" ""))]
8567   "reload_completed && !TARGET_POWERPC64
8568    && gpr_or_gpr_p (operands[0], operands[1])"
8569   [(pc)]
8570 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8571
8572 (define_insn "*movdi_mfpgpr"
8573   [(set (match_operand:DI 0 "nonimmediate_operand" "=Y,r,r,r,r,r,?m,?*d,?*d,r,*h,*h,r,?*d")
8574         (match_operand:DI 1 "input_operand" "r,Y,r,I,L,nF,d,m,d,*h,r,0,*d,r"))]
8575   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
8576    && (gpc_reg_operand (operands[0], DImode)
8577        || gpc_reg_operand (operands[1], DImode))"
8578   "@
8579    std%U0%X0 %1,%0
8580    ld%U1%X1 %0,%1
8581    mr %0,%1
8582    li %0,%1
8583    lis %0,%v1
8584    #
8585    stfd%U0%X0 %1,%0
8586    lfd%U1%X1 %0,%1
8587    fmr %0,%1
8588    mf%1 %0
8589    mt%0 %1
8590    nop
8591    mftgpr %0,%1
8592    mffgpr %0,%1"
8593   [(set_attr "type" "store,load,*,*,*,*,fpstore,fpload,fp,mfjmpr,mtjmpr,*,mftgpr,mffgpr")
8594    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4,4")])
8595
8596 (define_insn "*movdi_internal64"
8597   [(set (match_operand:DI 0 "nonimmediate_operand" "=Y,r,r,r,r,r,?m,?*d,?*d,r,*h,*h,?wa")
8598         (match_operand:DI 1 "input_operand" "r,Y,r,I,L,nF,d,m,d,*h,r,0,O"))]
8599   "TARGET_POWERPC64 && (!TARGET_MFPGPR || !TARGET_HARD_FLOAT || !TARGET_FPRS)
8600    && (gpc_reg_operand (operands[0], DImode)
8601        || gpc_reg_operand (operands[1], DImode))"
8602   "@
8603    std%U0%X0 %1,%0
8604    ld%U1%X1 %0,%1
8605    mr %0,%1
8606    li %0,%1
8607    lis %0,%v1
8608    #
8609    stfd%U0%X0 %1,%0
8610    lfd%U1%X1 %0,%1
8611    fmr %0,%1
8612    mf%1 %0
8613    mt%0 %1
8614    nop
8615    xxlxor %x0,%x0,%x0"
8616   [(set_attr "type" "store,load,*,*,*,*,fpstore,fpload,fp,mfjmpr,mtjmpr,*,vecsimple")
8617    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
8618
8619 ;; immediate value valid for a single instruction hiding in a const_double
8620 (define_insn ""
8621   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8622         (match_operand:DI 1 "const_double_operand" "F"))]
8623   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
8624    && GET_CODE (operands[1]) == CONST_DOUBLE
8625    && num_insns_constant (operands[1], DImode) == 1"
8626   "*
8627 {
8628   return ((unsigned HOST_WIDE_INT)
8629           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
8630          ? \"li %0,%1\" : \"lis %0,%v1\";
8631 }")
8632
8633 ;; Generate all one-bits and clear left or right.
8634 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
8635 (define_split
8636   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8637         (match_operand:DI 1 "mask64_operand" ""))]
8638   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8639   [(set (match_dup 0) (const_int -1))
8640    (set (match_dup 0)
8641         (and:DI (rotate:DI (match_dup 0)
8642                            (const_int 0))
8643                 (match_dup 1)))]
8644   "")
8645
8646 ;; Split a load of a large constant into the appropriate five-instruction
8647 ;; sequence.  Handle anything in a constant number of insns.
8648 ;; When non-easy constants can go in the TOC, this should use
8649 ;; easy_fp_constant predicate.
8650 (define_split
8651   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8652         (match_operand:DI 1 "const_int_operand" ""))]
8653   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8654   [(set (match_dup 0) (match_dup 2))
8655    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8656   "
8657 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8658
8659   if (tem == operands[0])
8660     DONE;
8661   else
8662     FAIL;
8663 }")
8664
8665 (define_split
8666   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8667         (match_operand:DI 1 "const_double_operand" ""))]
8668   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8669   [(set (match_dup 0) (match_dup 2))
8670    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8671   "
8672 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8673
8674   if (tem == operands[0])
8675     DONE;
8676   else
8677     FAIL;
8678 }")
8679 \f
8680 ;; TImode is similar, except that we usually want to compute the address into
8681 ;; a register and use lsi/stsi (the exception is during reload).
8682
8683 (define_insn "*movti_string"
8684   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,Y,????r,????r,????r,r")
8685         (match_operand:TI 1 "input_operand" "r,r,Q,Y,r,n"))]
8686   "! TARGET_POWERPC64
8687    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8688   "*
8689 {
8690   switch (which_alternative)
8691     {
8692     default:
8693       gcc_unreachable ();
8694     case 0:
8695       if (TARGET_STRING)
8696         return \"stswi %1,%P0,16\";
8697     case 1:
8698       return \"#\";
8699     case 2:
8700       /* If the address is not used in the output, we can use lsi.  Otherwise,
8701          fall through to generating four loads.  */
8702       if (TARGET_STRING
8703           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8704         return \"lswi %0,%P1,16\";
8705       /* ... fall through ...  */
8706     case 3:
8707     case 4:
8708     case 5:
8709       return \"#\";
8710     }
8711 }"
8712   [(set_attr "type" "store_ux,store_ux,load_ux,load_ux,*,*")
8713    (set (attr "cell_micro") (if_then_else (match_test "TARGET_STRING")
8714                                           (const_string "always")
8715                                           (const_string "conditional")))])
8716
8717 (define_insn "*movti_ppc64"
8718   [(set (match_operand:TI 0 "nonimmediate_operand" "=Y,r,r")
8719         (match_operand:TI 1 "input_operand" "r,Y,r"))]
8720   "(TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
8721     || gpc_reg_operand (operands[1], TImode)))
8722    && VECTOR_MEM_NONE_P (TImode)"
8723   "#"
8724   [(set_attr "type" "store,load,*")])
8725
8726 (define_split
8727   [(set (match_operand:TI 0 "gpc_reg_operand" "")
8728         (match_operand:TI 1 "const_double_operand" ""))]
8729   "TARGET_POWERPC64 && VECTOR_MEM_NONE_P (TImode)"
8730   [(set (match_dup 2) (match_dup 4))
8731    (set (match_dup 3) (match_dup 5))]
8732   "
8733 {
8734   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8735                                        TImode);
8736   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8737                                        TImode);
8738   if (GET_CODE (operands[1]) == CONST_DOUBLE)
8739     {
8740       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8741       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
8742     }
8743   else if (GET_CODE (operands[1]) == CONST_INT)
8744     {
8745       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
8746       operands[5] = operands[1];
8747     }
8748   else
8749     FAIL;
8750 }")
8751
8752 (define_split
8753   [(set (match_operand:TI 0 "nonimmediate_operand" "")
8754         (match_operand:TI 1 "input_operand" ""))]
8755   "reload_completed && VECTOR_MEM_NONE_P (TImode)
8756    && gpr_or_gpr_p (operands[0], operands[1])"
8757   [(pc)]
8758 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8759 \f
8760 (define_expand "load_multiple"
8761   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8762                           (match_operand:SI 1 "" ""))
8763                      (use (match_operand:SI 2 "" ""))])]
8764   "TARGET_STRING && !TARGET_POWERPC64"
8765   "
8766 {
8767   int regno;
8768   int count;
8769   rtx op1;
8770   int i;
8771
8772   /* Support only loading a constant number of fixed-point registers from
8773      memory and only bother with this if more than two; the machine
8774      doesn't support more than eight.  */
8775   if (GET_CODE (operands[2]) != CONST_INT
8776       || INTVAL (operands[2]) <= 2
8777       || INTVAL (operands[2]) > 8
8778       || GET_CODE (operands[1]) != MEM
8779       || GET_CODE (operands[0]) != REG
8780       || REGNO (operands[0]) >= 32)
8781     FAIL;
8782
8783   count = INTVAL (operands[2]);
8784   regno = REGNO (operands[0]);
8785
8786   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
8787   op1 = replace_equiv_address (operands[1],
8788                                force_reg (SImode, XEXP (operands[1], 0)));
8789
8790   for (i = 0; i < count; i++)
8791     XVECEXP (operands[3], 0, i)
8792       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
8793                      adjust_address_nv (op1, SImode, i * 4));
8794 }")
8795
8796 (define_insn "*ldmsi8"
8797   [(match_parallel 0 "load_multiple_operation"
8798     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8799           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8800      (set (match_operand:SI 3 "gpc_reg_operand" "")
8801           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8802      (set (match_operand:SI 4 "gpc_reg_operand" "")
8803           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8804      (set (match_operand:SI 5 "gpc_reg_operand" "")
8805           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8806      (set (match_operand:SI 6 "gpc_reg_operand" "")
8807           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8808      (set (match_operand:SI 7 "gpc_reg_operand" "")
8809           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8810      (set (match_operand:SI 8 "gpc_reg_operand" "")
8811           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
8812      (set (match_operand:SI 9 "gpc_reg_operand" "")
8813           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
8814   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
8815   "*
8816 { return rs6000_output_load_multiple (operands); }"
8817   [(set_attr "type" "load_ux")
8818    (set_attr "length" "32")])
8819
8820 (define_insn "*ldmsi7"
8821   [(match_parallel 0 "load_multiple_operation"
8822     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8823           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8824      (set (match_operand:SI 3 "gpc_reg_operand" "")
8825           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8826      (set (match_operand:SI 4 "gpc_reg_operand" "")
8827           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8828      (set (match_operand:SI 5 "gpc_reg_operand" "")
8829           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8830      (set (match_operand:SI 6 "gpc_reg_operand" "")
8831           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8832      (set (match_operand:SI 7 "gpc_reg_operand" "")
8833           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8834      (set (match_operand:SI 8 "gpc_reg_operand" "")
8835           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
8836   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
8837   "*
8838 { return rs6000_output_load_multiple (operands); }"
8839   [(set_attr "type" "load_ux")
8840    (set_attr "length" "32")])
8841
8842 (define_insn "*ldmsi6"
8843   [(match_parallel 0 "load_multiple_operation"
8844     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8845           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8846      (set (match_operand:SI 3 "gpc_reg_operand" "")
8847           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8848      (set (match_operand:SI 4 "gpc_reg_operand" "")
8849           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8850      (set (match_operand:SI 5 "gpc_reg_operand" "")
8851           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8852      (set (match_operand:SI 6 "gpc_reg_operand" "")
8853           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8854      (set (match_operand:SI 7 "gpc_reg_operand" "")
8855           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
8856   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
8857   "*
8858 { return rs6000_output_load_multiple (operands); }"
8859   [(set_attr "type" "load_ux")
8860    (set_attr "length" "32")])
8861
8862 (define_insn "*ldmsi5"
8863   [(match_parallel 0 "load_multiple_operation"
8864     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8865           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8866      (set (match_operand:SI 3 "gpc_reg_operand" "")
8867           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8868      (set (match_operand:SI 4 "gpc_reg_operand" "")
8869           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8870      (set (match_operand:SI 5 "gpc_reg_operand" "")
8871           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8872      (set (match_operand:SI 6 "gpc_reg_operand" "")
8873           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
8874   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
8875   "*
8876 { return rs6000_output_load_multiple (operands); }"
8877   [(set_attr "type" "load_ux")
8878    (set_attr "length" "32")])
8879
8880 (define_insn "*ldmsi4"
8881   [(match_parallel 0 "load_multiple_operation"
8882     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8883           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8884      (set (match_operand:SI 3 "gpc_reg_operand" "")
8885           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8886      (set (match_operand:SI 4 "gpc_reg_operand" "")
8887           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8888      (set (match_operand:SI 5 "gpc_reg_operand" "")
8889           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
8890   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
8891   "*
8892 { return rs6000_output_load_multiple (operands); }"
8893   [(set_attr "type" "load_ux")
8894    (set_attr "length" "32")])
8895
8896 (define_insn "*ldmsi3"
8897   [(match_parallel 0 "load_multiple_operation"
8898     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8899           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8900      (set (match_operand:SI 3 "gpc_reg_operand" "")
8901           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8902      (set (match_operand:SI 4 "gpc_reg_operand" "")
8903           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
8904   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
8905   "*
8906 { return rs6000_output_load_multiple (operands); }"
8907   [(set_attr "type" "load_ux")
8908    (set_attr "length" "32")])
8909
8910 (define_expand "store_multiple"
8911   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8912                           (match_operand:SI 1 "" ""))
8913                      (clobber (scratch:SI))
8914                      (use (match_operand:SI 2 "" ""))])]
8915   "TARGET_STRING && !TARGET_POWERPC64"
8916   "
8917 {
8918   int regno;
8919   int count;
8920   rtx to;
8921   rtx op0;
8922   int i;
8923
8924   /* Support only storing a constant number of fixed-point registers to
8925      memory and only bother with this if more than two; the machine
8926      doesn't support more than eight.  */
8927   if (GET_CODE (operands[2]) != CONST_INT
8928       || INTVAL (operands[2]) <= 2
8929       || INTVAL (operands[2]) > 8
8930       || GET_CODE (operands[0]) != MEM
8931       || GET_CODE (operands[1]) != REG
8932       || REGNO (operands[1]) >= 32)
8933     FAIL;
8934
8935   count = INTVAL (operands[2]);
8936   regno = REGNO (operands[1]);
8937
8938   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
8939   to = force_reg (SImode, XEXP (operands[0], 0));
8940   op0 = replace_equiv_address (operands[0], to);
8941
8942   XVECEXP (operands[3], 0, 0)
8943     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
8944   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
8945                                                  gen_rtx_SCRATCH (SImode));
8946
8947   for (i = 1; i < count; i++)
8948     XVECEXP (operands[3], 0, i + 1)
8949       = gen_rtx_SET (VOIDmode,
8950                      adjust_address_nv (op0, SImode, i * 4),
8951                      gen_rtx_REG (SImode, regno + i));
8952 }")
8953
8954 (define_insn "*stmsi8"
8955   [(match_parallel 0 "store_multiple_operation"
8956     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8957           (match_operand:SI 2 "gpc_reg_operand" "r"))
8958      (clobber (match_scratch:SI 3 "=X"))
8959      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8960           (match_operand:SI 4 "gpc_reg_operand" "r"))
8961      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8962           (match_operand:SI 5 "gpc_reg_operand" "r"))
8963      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8964           (match_operand:SI 6 "gpc_reg_operand" "r"))
8965      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8966           (match_operand:SI 7 "gpc_reg_operand" "r"))
8967      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8968           (match_operand:SI 8 "gpc_reg_operand" "r"))
8969      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8970           (match_operand:SI 9 "gpc_reg_operand" "r"))
8971      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
8972           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
8973   "TARGET_STRING && XVECLEN (operands[0], 0) == 9"
8974   "stswi %2,%1,%O0"
8975   [(set_attr "type" "store_ux")
8976    (set_attr "cell_micro" "always")])
8977
8978 (define_insn "*stmsi7"
8979   [(match_parallel 0 "store_multiple_operation"
8980     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8981           (match_operand:SI 2 "gpc_reg_operand" "r"))
8982      (clobber (match_scratch:SI 3 "=X"))
8983      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8984           (match_operand:SI 4 "gpc_reg_operand" "r"))
8985      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8986           (match_operand:SI 5 "gpc_reg_operand" "r"))
8987      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8988           (match_operand:SI 6 "gpc_reg_operand" "r"))
8989      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8990           (match_operand:SI 7 "gpc_reg_operand" "r"))
8991      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8992           (match_operand:SI 8 "gpc_reg_operand" "r"))
8993      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8994           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
8995   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
8996   "stswi %2,%1,%O0"
8997   [(set_attr "type" "store_ux")
8998    (set_attr "cell_micro" "always")])
8999
9000 (define_insn "*stmsi6"
9001   [(match_parallel 0 "store_multiple_operation"
9002     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9003           (match_operand:SI 2 "gpc_reg_operand" "r"))
9004      (clobber (match_scratch:SI 3 "=X"))
9005      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9006           (match_operand:SI 4 "gpc_reg_operand" "r"))
9007      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9008           (match_operand:SI 5 "gpc_reg_operand" "r"))
9009      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9010           (match_operand:SI 6 "gpc_reg_operand" "r"))
9011      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9012           (match_operand:SI 7 "gpc_reg_operand" "r"))
9013      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9014           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
9015   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
9016   "stswi %2,%1,%O0"
9017   [(set_attr "type" "store_ux")
9018    (set_attr "cell_micro" "always")])
9019
9020 (define_insn "*stmsi5"
9021   [(match_parallel 0 "store_multiple_operation"
9022     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9023           (match_operand:SI 2 "gpc_reg_operand" "r"))
9024      (clobber (match_scratch:SI 3 "=X"))
9025      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9026           (match_operand:SI 4 "gpc_reg_operand" "r"))
9027      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9028           (match_operand:SI 5 "gpc_reg_operand" "r"))
9029      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9030           (match_operand:SI 6 "gpc_reg_operand" "r"))
9031      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9032           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
9033   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
9034   "stswi %2,%1,%O0"
9035   [(set_attr "type" "store_ux")
9036    (set_attr "cell_micro" "always")])
9037
9038 (define_insn "*stmsi4"
9039   [(match_parallel 0 "store_multiple_operation"
9040     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9041           (match_operand:SI 2 "gpc_reg_operand" "r"))
9042      (clobber (match_scratch:SI 3 "=X"))
9043      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9044           (match_operand:SI 4 "gpc_reg_operand" "r"))
9045      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9046           (match_operand:SI 5 "gpc_reg_operand" "r"))
9047      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9048           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9049   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
9050   "stswi %2,%1,%O0"
9051   [(set_attr "type" "store_ux")
9052    (set_attr "cell_micro" "always")])
9053
9054 (define_insn "*stmsi3"
9055   [(match_parallel 0 "store_multiple_operation"
9056     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9057           (match_operand:SI 2 "gpc_reg_operand" "r"))
9058      (clobber (match_scratch:SI 3 "=X"))
9059      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9060           (match_operand:SI 4 "gpc_reg_operand" "r"))
9061      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9062           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9063   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
9064   "stswi %2,%1,%O0"
9065   [(set_attr "type" "store_ux")
9066    (set_attr "cell_micro" "always")])
9067 \f
9068 (define_expand "setmemsi"
9069   [(parallel [(set (match_operand:BLK 0 "" "")
9070                    (match_operand 2 "const_int_operand" ""))
9071               (use (match_operand:SI 1 "" ""))
9072               (use (match_operand:SI 3 "" ""))])]
9073   ""
9074   "
9075 {
9076   /* If value to set is not zero, use the library routine.  */
9077   if (operands[2] != const0_rtx)
9078     FAIL;
9079
9080   if (expand_block_clear (operands))
9081     DONE;
9082   else
9083     FAIL;
9084 }")
9085
9086 ;; String/block move insn.
9087 ;; Argument 0 is the destination
9088 ;; Argument 1 is the source
9089 ;; Argument 2 is the length
9090 ;; Argument 3 is the alignment
9091
9092 (define_expand "movmemsi"
9093   [(parallel [(set (match_operand:BLK 0 "" "")
9094                    (match_operand:BLK 1 "" ""))
9095               (use (match_operand:SI 2 "" ""))
9096               (use (match_operand:SI 3 "" ""))])]
9097   ""
9098   "
9099 {
9100   if (expand_block_move (operands))
9101     DONE;
9102   else
9103     FAIL;
9104 }")
9105
9106 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
9107 ;; register allocator doesn't have a clue about allocating 8 word registers.
9108 ;; rD/rS = r5 is preferred, efficient form.
9109 (define_expand "movmemsi_8reg"
9110   [(parallel [(set (match_operand 0 "" "")
9111                    (match_operand 1 "" ""))
9112               (use (match_operand 2 "" ""))
9113               (use (match_operand 3 "" ""))
9114               (clobber (reg:SI  5))
9115               (clobber (reg:SI  6))
9116               (clobber (reg:SI  7))
9117               (clobber (reg:SI  8))
9118               (clobber (reg:SI  9))
9119               (clobber (reg:SI 10))
9120               (clobber (reg:SI 11))
9121               (clobber (reg:SI 12))
9122               (clobber (match_scratch:SI 4 ""))])]
9123   "TARGET_STRING"
9124   "")
9125
9126 (define_insn ""
9127   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9128         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9129    (use (match_operand:SI 2 "immediate_operand" "i"))
9130    (use (match_operand:SI 3 "immediate_operand" "i"))
9131    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
9132    (clobber (reg:SI  6))
9133    (clobber (reg:SI  7))
9134    (clobber (reg:SI  8))
9135    (clobber (reg:SI  9))
9136    (clobber (reg:SI 10))
9137    (clobber (reg:SI 11))
9138    (clobber (reg:SI 12))
9139    (clobber (match_scratch:SI 5 "=X"))]
9140   "TARGET_STRING
9141    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9142        || INTVAL (operands[2]) == 0)
9143    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9144    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9145    && REGNO (operands[4]) == 5"
9146   "lswi %4,%1,%2\;stswi %4,%0,%2"
9147   [(set_attr "type" "store_ux")
9148    (set_attr "cell_micro" "always")
9149    (set_attr "length" "8")])
9150
9151 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
9152 ;; register allocator doesn't have a clue about allocating 6 word registers.
9153 ;; rD/rS = r5 is preferred, efficient form.
9154 (define_expand "movmemsi_6reg"
9155   [(parallel [(set (match_operand 0 "" "")
9156                    (match_operand 1 "" ""))
9157               (use (match_operand 2 "" ""))
9158               (use (match_operand 3 "" ""))
9159               (clobber (reg:SI  5))
9160               (clobber (reg:SI  6))
9161               (clobber (reg:SI  7))
9162               (clobber (reg:SI  8))
9163               (clobber (reg:SI  9))
9164               (clobber (reg:SI 10))
9165               (clobber (match_scratch:SI 4 ""))])]
9166   "TARGET_STRING"
9167   "")
9168
9169 (define_insn ""
9170   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9171         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9172    (use (match_operand:SI 2 "immediate_operand" "i"))
9173    (use (match_operand:SI 3 "immediate_operand" "i"))
9174    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
9175    (clobber (reg:SI  6))
9176    (clobber (reg:SI  7))
9177    (clobber (reg:SI  8))
9178    (clobber (reg:SI  9))
9179    (clobber (reg:SI 10))
9180    (clobber (match_scratch:SI 5 "=X"))]
9181   "TARGET_STRING
9182    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9183    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9184    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9185    && REGNO (operands[4]) == 5"
9186   "lswi %4,%1,%2\;stswi %4,%0,%2"
9187   [(set_attr "type" "store_ux")
9188    (set_attr "cell_micro" "always")
9189    (set_attr "length" "8")])
9190
9191 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
9192 ;; problems with TImode.
9193 ;; rD/rS = r5 is preferred, efficient form.
9194 (define_expand "movmemsi_4reg"
9195   [(parallel [(set (match_operand 0 "" "")
9196                    (match_operand 1 "" ""))
9197               (use (match_operand 2 "" ""))
9198               (use (match_operand 3 "" ""))
9199               (clobber (reg:SI 5))
9200               (clobber (reg:SI 6))
9201               (clobber (reg:SI 7))
9202               (clobber (reg:SI 8))
9203               (clobber (match_scratch:SI 4 ""))])]
9204   "TARGET_STRING"
9205   "")
9206
9207 (define_insn ""
9208   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9209         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9210    (use (match_operand:SI 2 "immediate_operand" "i"))
9211    (use (match_operand:SI 3 "immediate_operand" "i"))
9212    (clobber (match_operand:SI 4 "gpc_reg_operand" "=&r"))
9213    (clobber (reg:SI 6))
9214    (clobber (reg:SI 7))
9215    (clobber (reg:SI 8))
9216    (clobber (match_scratch:SI 5 "=X"))]
9217   "TARGET_STRING
9218    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9219    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9220    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9221    && REGNO (operands[4]) == 5"
9222   "lswi %4,%1,%2\;stswi %4,%0,%2"
9223   [(set_attr "type" "store_ux")
9224    (set_attr "cell_micro" "always")
9225    (set_attr "length" "8")])
9226
9227 ;; Move up to 8 bytes at a time.
9228 (define_expand "movmemsi_2reg"
9229   [(parallel [(set (match_operand 0 "" "")
9230                    (match_operand 1 "" ""))
9231               (use (match_operand 2 "" ""))
9232               (use (match_operand 3 "" ""))
9233               (clobber (match_scratch:DI 4 ""))
9234               (clobber (match_scratch:SI 5 ""))])]
9235   "TARGET_STRING && ! TARGET_POWERPC64"
9236   "")
9237
9238 (define_insn ""
9239   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9240         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9241    (use (match_operand:SI 2 "immediate_operand" "i"))
9242    (use (match_operand:SI 3 "immediate_operand" "i"))
9243    (clobber (match_scratch:DI 4 "=&r"))
9244    (clobber (match_scratch:SI 5 "=X"))]
9245   "TARGET_STRING && ! TARGET_POWERPC64
9246    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9247   "lswi %4,%1,%2\;stswi %4,%0,%2"
9248   [(set_attr "type" "store_ux")
9249    (set_attr "cell_micro" "always")
9250    (set_attr "length" "8")])
9251
9252 ;; Move up to 4 bytes at a time.
9253 (define_expand "movmemsi_1reg"
9254   [(parallel [(set (match_operand 0 "" "")
9255                    (match_operand 1 "" ""))
9256               (use (match_operand 2 "" ""))
9257               (use (match_operand 3 "" ""))
9258               (clobber (match_scratch:SI 4 ""))
9259               (clobber (match_scratch:SI 5 ""))])]
9260   "TARGET_STRING"
9261   "")
9262
9263 (define_insn ""
9264   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9265         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9266    (use (match_operand:SI 2 "immediate_operand" "i"))
9267    (use (match_operand:SI 3 "immediate_operand" "i"))
9268    (clobber (match_scratch:SI 4 "=&r"))
9269    (clobber (match_scratch:SI 5 "=X"))]
9270   "TARGET_STRING && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9271   "lswi %4,%1,%2\;stswi %4,%0,%2"
9272   [(set_attr "type" "store_ux")
9273    (set_attr "cell_micro" "always")
9274    (set_attr "length" "8")])
9275 \f
9276 ;; Define insns that do load or store with update.  Some of these we can
9277 ;; get by using pre-decrement or pre-increment, but the hardware can also
9278 ;; do cases where the increment is not the size of the object.
9279 ;;
9280 ;; In all these cases, we use operands 0 and 1 for the register being
9281 ;; incremented because those are the operands that local-alloc will
9282 ;; tie and these are the pair most likely to be tieable (and the ones
9283 ;; that will benefit the most).
9284
9285 (define_insn "*movdi_update1"
9286   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9287         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9288                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
9289    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9290         (plus:DI (match_dup 1) (match_dup 2)))]
9291   "TARGET_POWERPC64 && TARGET_UPDATE
9292    && (!avoiding_indexed_address_p (DImode)
9293        || !gpc_reg_operand (operands[2], DImode))"
9294   "@
9295    ldux %3,%0,%2
9296    ldu %3,%2(%0)"
9297   [(set_attr "type" "load_ux,load_u")])
9298
9299 (define_insn "movdi_<mode>_update"
9300   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
9301                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
9302         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9303    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
9304         (plus:P (match_dup 1) (match_dup 2)))]
9305   "TARGET_POWERPC64 && TARGET_UPDATE
9306    && (!avoiding_indexed_address_p (Pmode)
9307        || !gpc_reg_operand (operands[2], Pmode)
9308        || (REG_P (operands[0])
9309            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
9310   "@
9311    stdux %3,%0,%2
9312    stdu %3,%2(%0)"
9313   [(set_attr "type" "store_ux,store_u")])
9314
9315 ;; This pattern is only conditional on TARGET_POWERPC64, as it is
9316 ;; needed for stack allocation, even if the user passes -mno-update.
9317 (define_insn "movdi_<mode>_update_stack"
9318   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
9319                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
9320         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9321    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
9322         (plus:P (match_dup 1) (match_dup 2)))]
9323   "TARGET_POWERPC64"
9324   "@
9325    stdux %3,%0,%2
9326    stdu %3,%2(%0)"
9327   [(set_attr "type" "store_ux,store_u")])
9328
9329 (define_insn "*movsi_update1"
9330   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9331         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9332                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9333    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9334         (plus:SI (match_dup 1) (match_dup 2)))]
9335   "TARGET_UPDATE
9336    && (!avoiding_indexed_address_p (SImode)
9337        || !gpc_reg_operand (operands[2], SImode))"
9338   "@
9339    lwzux %3,%0,%2
9340    lwzu %3,%2(%0)"
9341   [(set_attr "type" "load_ux,load_u")])
9342
9343 (define_insn "*movsi_update2"
9344   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9345         (sign_extend:DI
9346          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9347                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9348    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9349         (plus:DI (match_dup 1) (match_dup 2)))]
9350   "TARGET_POWERPC64 && rs6000_gen_cell_microcode
9351    && !avoiding_indexed_address_p (DImode)"
9352   "lwaux %3,%0,%2"
9353   [(set_attr "type" "load_ext_ux")])
9354
9355 (define_insn "movsi_update"
9356   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9357                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9358         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9359    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9360         (plus:SI (match_dup 1) (match_dup 2)))]
9361   "TARGET_UPDATE
9362    && (!avoiding_indexed_address_p (SImode)
9363        || !gpc_reg_operand (operands[2], SImode)
9364        || (REG_P (operands[0])
9365            && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
9366   "@
9367    stwux %3,%0,%2
9368    stwu %3,%2(%0)"
9369   [(set_attr "type" "store_ux,store_u")])
9370
9371 ;; This is an unconditional pattern; needed for stack allocation, even
9372 ;; if the user passes -mno-update.
9373 (define_insn "movsi_update_stack"
9374   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9375                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9376         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9377    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9378         (plus:SI (match_dup 1) (match_dup 2)))]
9379   ""
9380   "@
9381    stwux %3,%0,%2
9382    stwu %3,%2(%0)"
9383   [(set_attr "type" "store_ux,store_u")])
9384
9385 (define_insn "*movhi_update1"
9386   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9387         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9388                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9389    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9390         (plus:SI (match_dup 1) (match_dup 2)))]
9391   "TARGET_UPDATE
9392    && (!avoiding_indexed_address_p (SImode)
9393        || !gpc_reg_operand (operands[2], SImode))"
9394   "@
9395    lhzux %3,%0,%2
9396    lhzu %3,%2(%0)"
9397   [(set_attr "type" "load_ux,load_u")])
9398
9399 (define_insn "*movhi_update2"
9400   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9401         (zero_extend:SI
9402          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9403                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9404    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9405         (plus:SI (match_dup 1) (match_dup 2)))]
9406   "TARGET_UPDATE
9407    && (!avoiding_indexed_address_p (SImode)
9408        || !gpc_reg_operand (operands[2], SImode))"
9409   "@
9410    lhzux %3,%0,%2
9411    lhzu %3,%2(%0)"
9412   [(set_attr "type" "load_ux,load_u")])
9413
9414 (define_insn "*movhi_update3"
9415   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9416         (sign_extend:SI
9417          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9418                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9419    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9420         (plus:SI (match_dup 1) (match_dup 2)))]
9421   "TARGET_UPDATE && rs6000_gen_cell_microcode
9422    && (!avoiding_indexed_address_p (SImode)
9423        || !gpc_reg_operand (operands[2], SImode))"
9424   "@
9425    lhaux %3,%0,%2
9426    lhau %3,%2(%0)"
9427   [(set_attr "type" "load_ext_ux,load_ext_u")])
9428
9429 (define_insn "*movhi_update4"
9430   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9431                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9432         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
9433    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9434         (plus:SI (match_dup 1) (match_dup 2)))]
9435   "TARGET_UPDATE
9436    && (!avoiding_indexed_address_p (SImode)
9437        || !gpc_reg_operand (operands[2], SImode))"
9438   "@
9439    sthux %3,%0,%2
9440    sthu %3,%2(%0)"
9441   [(set_attr "type" "store_ux,store_u")])
9442
9443 (define_insn "*movqi_update1"
9444   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
9445         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9446                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9447    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9448         (plus:SI (match_dup 1) (match_dup 2)))]
9449   "TARGET_UPDATE
9450    && (!avoiding_indexed_address_p (SImode)
9451        || !gpc_reg_operand (operands[2], SImode))"
9452   "@
9453    lbzux %3,%0,%2
9454    lbzu %3,%2(%0)"
9455   [(set_attr "type" "load_ux,load_u")])
9456
9457 (define_insn "*movqi_update2"
9458   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9459         (zero_extend:SI
9460          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9461                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9462    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9463         (plus:SI (match_dup 1) (match_dup 2)))]
9464   "TARGET_UPDATE
9465    && (!avoiding_indexed_address_p (SImode)
9466        || !gpc_reg_operand (operands[2], SImode))"
9467   "@
9468    lbzux %3,%0,%2
9469    lbzu %3,%2(%0)"
9470   [(set_attr "type" "load_ux,load_u")])
9471
9472 (define_insn "*movqi_update3"
9473   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9474                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9475         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
9476    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9477         (plus:SI (match_dup 1) (match_dup 2)))]
9478   "TARGET_UPDATE
9479    && (!avoiding_indexed_address_p (SImode)
9480        || !gpc_reg_operand (operands[2], SImode))"
9481   "@
9482    stbux %3,%0,%2
9483    stbu %3,%2(%0)"
9484   [(set_attr "type" "store_ux,store_u")])
9485
9486 (define_insn "*movsf_update1"
9487   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
9488         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9489                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9490    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9491         (plus:SI (match_dup 1) (match_dup 2)))]
9492   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
9493    && (!avoiding_indexed_address_p (SImode)
9494        || !gpc_reg_operand (operands[2], SImode))"
9495   "@
9496    lfsux %3,%0,%2
9497    lfsu %3,%2(%0)"
9498   [(set_attr "type" "fpload_ux,fpload_u")])
9499
9500 (define_insn "*movsf_update2"
9501   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9502                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9503         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
9504    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9505         (plus:SI (match_dup 1) (match_dup 2)))]
9506   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT && TARGET_UPDATE
9507    && (!avoiding_indexed_address_p (SImode)
9508        || !gpc_reg_operand (operands[2], SImode))"
9509   "@
9510    stfsux %3,%0,%2
9511    stfsu %3,%2(%0)"
9512   [(set_attr "type" "fpstore_ux,fpstore_u")])
9513
9514 (define_insn "*movsf_update3"
9515   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
9516         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9517                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9518    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9519         (plus:SI (match_dup 1) (match_dup 2)))]
9520   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
9521    && (!avoiding_indexed_address_p (SImode)
9522        || !gpc_reg_operand (operands[2], SImode))"
9523   "@
9524    lwzux %3,%0,%2
9525    lwzu %3,%2(%0)"
9526   [(set_attr "type" "load_ux,load_u")])
9527
9528 (define_insn "*movsf_update4"
9529   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9530                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9531         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
9532    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9533         (plus:SI (match_dup 1) (match_dup 2)))]
9534   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE
9535    && (!avoiding_indexed_address_p (SImode)
9536        || !gpc_reg_operand (operands[2], SImode))"
9537   "@
9538    stwux %3,%0,%2
9539    stwu %3,%2(%0)"
9540   [(set_attr "type" "store_ux,store_u")])
9541
9542 (define_insn "*movdf_update1"
9543   [(set (match_operand:DF 3 "gpc_reg_operand" "=d,d")
9544         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9545                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9546    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9547         (plus:SI (match_dup 1) (match_dup 2)))]
9548   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
9549    && (!avoiding_indexed_address_p (SImode)
9550        || !gpc_reg_operand (operands[2], SImode))"
9551   "@
9552    lfdux %3,%0,%2
9553    lfdu %3,%2(%0)"
9554   [(set_attr "type" "fpload_ux,fpload_u")])
9555
9556 (define_insn "*movdf_update2"
9557   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9558                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9559         (match_operand:DF 3 "gpc_reg_operand" "d,d"))
9560    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9561         (plus:SI (match_dup 1) (match_dup 2)))]
9562   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_UPDATE
9563    && (!avoiding_indexed_address_p (SImode)
9564        || !gpc_reg_operand (operands[2], SImode))"
9565   "@
9566    stfdux %3,%0,%2
9567    stfdu %3,%2(%0)"
9568   [(set_attr "type" "fpstore_ux,fpstore_u")])
9569
9570
9571 ;; After inserting conditional returns we can sometimes have
9572 ;; unnecessary register moves.  Unfortunately we cannot have a
9573 ;; modeless peephole here, because some single SImode sets have early
9574 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
9575 ;; sequences, using get_attr_length here will smash the operands
9576 ;; array.  Neither is there an early_cobbler_p predicate.
9577 ;; Disallow subregs for E500 so we don't munge frob_di_df_2.
9578 (define_peephole2
9579   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9580         (match_operand:DF 1 "any_operand" ""))
9581    (set (match_operand:DF 2 "gpc_reg_operand" "")
9582         (match_dup 0))]
9583   "!(TARGET_E500_DOUBLE && GET_CODE (operands[2]) == SUBREG)
9584    && peep2_reg_dead_p (2, operands[0])"
9585   [(set (match_dup 2) (match_dup 1))])
9586
9587 (define_peephole2
9588   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9589         (match_operand:SF 1 "any_operand" ""))
9590    (set (match_operand:SF 2 "gpc_reg_operand" "")
9591         (match_dup 0))]
9592   "peep2_reg_dead_p (2, operands[0])"
9593   [(set (match_dup 2) (match_dup 1))])
9594
9595 \f
9596 ;; TLS support.
9597
9598 ;; Mode attributes for different ABIs.
9599 (define_mode_iterator TLSmode [(SI "! TARGET_64BIT") (DI "TARGET_64BIT")])
9600 (define_mode_attr tls_abi_suffix [(SI "32") (DI "64")])
9601 (define_mode_attr tls_sysv_suffix [(SI "si") (DI "di")])
9602 (define_mode_attr tls_insn_suffix [(SI "wz") (DI "d")])
9603
9604 (define_insn_and_split "tls_gd_aix<TLSmode:tls_abi_suffix>"
9605   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9606         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
9607               (match_operand 4 "" "g")))
9608    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9609                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9610                    UNSPEC_TLSGD)
9611    (clobber (reg:SI LR_REGNO))]
9612   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX"
9613 {
9614   if (TARGET_CMODEL != CMODEL_SMALL)
9615     return "addis %0,%1,%2@got@tlsgd@ha\;addi %0,%0,%2@got@tlsgd@l\;"
9616            "bl %z3\;nop";
9617   else
9618     return "addi %0,%1,%2@got@tlsgd\;bl %z3\;nop";
9619 }
9620   "&& TARGET_TLS_MARKERS"
9621   [(set (match_dup 0)
9622         (unspec:TLSmode [(match_dup 1)
9623                          (match_dup 2)]
9624                         UNSPEC_TLSGD))
9625    (parallel [(set (match_dup 0)
9626                    (call (mem:TLSmode (match_dup 3))
9627                          (match_dup 4)))
9628               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
9629               (clobber (reg:SI LR_REGNO))])]
9630   ""
9631   [(set_attr "type" "two")
9632    (set (attr "length")
9633      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
9634                    (const_int 16)
9635                    (const_int 12)))])
9636
9637 (define_insn_and_split "tls_gd_sysv<TLSmode:tls_sysv_suffix>"
9638   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9639         (call (mem:TLSmode (match_operand:TLSmode 3 "symbol_ref_operand" "s"))
9640               (match_operand 4 "" "g")))
9641    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9642                     (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9643                    UNSPEC_TLSGD)
9644    (clobber (reg:SI LR_REGNO))]
9645   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
9646 {
9647   if (flag_pic)
9648     {
9649       if (TARGET_SECURE_PLT && flag_pic == 2)
9650         return "addi %0,%1,%2@got@tlsgd\;bl %z3+32768@plt";
9651       else
9652         return "addi %0,%1,%2@got@tlsgd\;bl %z3@plt";
9653     }
9654   else
9655     return "addi %0,%1,%2@got@tlsgd\;bl %z3";
9656 }
9657   "&& TARGET_TLS_MARKERS"
9658   [(set (match_dup 0)
9659         (unspec:TLSmode [(match_dup 1)
9660                          (match_dup 2)]
9661                         UNSPEC_TLSGD))
9662    (parallel [(set (match_dup 0)
9663                    (call (mem:TLSmode (match_dup 3))
9664                          (match_dup 4)))
9665               (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)
9666               (clobber (reg:SI LR_REGNO))])]
9667   ""
9668   [(set_attr "type" "two")
9669    (set_attr "length" "8")])
9670
9671 (define_insn_and_split "*tls_gd<TLSmode:tls_abi_suffix>"
9672   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9673         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9674                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9675                         UNSPEC_TLSGD))]
9676   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
9677   "addi %0,%1,%2@got@tlsgd"
9678   "&& TARGET_CMODEL != CMODEL_SMALL"
9679   [(set (match_dup 3)
9680         (high:TLSmode
9681             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGD)))
9682    (set (match_dup 0)
9683         (lo_sum:TLSmode (match_dup 3)
9684             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGD)))]
9685   "
9686 {
9687   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
9688 }"
9689   [(set (attr "length")
9690      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
9691                    (const_int 8)
9692                    (const_int 4)))])
9693
9694 (define_insn "*tls_gd_high<TLSmode:tls_abi_suffix>"
9695   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9696      (high:TLSmode
9697        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9698                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9699                        UNSPEC_TLSGD)))]
9700   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
9701   "addis %0,%1,%2@got@tlsgd@ha"
9702   [(set_attr "length" "4")])
9703
9704 (define_insn "*tls_gd_low<TLSmode:tls_abi_suffix>"
9705   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9706      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
9707        (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9708                        UNSPEC_TLSGD)))]
9709   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
9710   "addi %0,%1,%2@got@tlsgd@l"
9711   [(set_attr "length" "4")])
9712
9713 (define_insn "*tls_gd_call_aix<TLSmode:tls_abi_suffix>"
9714   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9715         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
9716               (match_operand 2 "" "g")))
9717    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
9718                    UNSPEC_TLSGD)
9719    (clobber (reg:SI LR_REGNO))]
9720   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
9721   "bl %z1(%3@tlsgd)\;nop"
9722   [(set_attr "type" "branch")
9723    (set_attr "length" "8")])
9724
9725 (define_insn "*tls_gd_call_sysv<TLSmode:tls_abi_suffix>"
9726   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9727         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
9728               (match_operand 2 "" "g")))
9729    (unspec:TLSmode [(match_operand:TLSmode 3 "rs6000_tls_symbol_ref" "")]
9730                    UNSPEC_TLSGD)
9731    (clobber (reg:SI LR_REGNO))]
9732   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
9733 {
9734   if (flag_pic)
9735     {
9736       if (TARGET_SECURE_PLT && flag_pic == 2)
9737         return "bl %z1+32768(%3@tlsgd)@plt";
9738       return "bl %z1(%3@tlsgd)@plt";
9739     }
9740   return "bl %z1(%3@tlsgd)";
9741 }
9742   [(set_attr "type" "branch")
9743    (set_attr "length" "4")])
9744
9745 (define_insn_and_split "tls_ld_aix<TLSmode:tls_abi_suffix>"
9746   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9747         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
9748               (match_operand 3 "" "g")))
9749    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
9750                    UNSPEC_TLSLD)
9751    (clobber (reg:SI LR_REGNO))]
9752   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX"
9753 {
9754   if (TARGET_CMODEL != CMODEL_SMALL)
9755     return "addis %0,%1,%&@got@tlsld@ha\;addi %0,%0,%&@got@tlsld@l\;"
9756            "bl %z2\;nop";
9757   else
9758     return "addi %0,%1,%&@got@tlsld\;bl %z2\;nop";
9759 }
9760   "&& TARGET_TLS_MARKERS"
9761   [(set (match_dup 0)
9762         (unspec:TLSmode [(match_dup 1)]
9763                         UNSPEC_TLSLD))
9764    (parallel [(set (match_dup 0)
9765                    (call (mem:TLSmode (match_dup 2))
9766                          (match_dup 3)))
9767               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
9768               (clobber (reg:SI LR_REGNO))])]
9769   ""
9770   [(set_attr "type" "two")
9771    (set (attr "length")
9772      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
9773                    (const_int 16)
9774                    (const_int 12)))])
9775
9776 (define_insn_and_split "tls_ld_sysv<TLSmode:tls_sysv_suffix>"
9777   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9778         (call (mem:TLSmode (match_operand:TLSmode 2 "symbol_ref_operand" "s"))
9779               (match_operand 3 "" "g")))
9780    (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
9781                    UNSPEC_TLSLD)
9782    (clobber (reg:SI LR_REGNO))]
9783   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4"
9784 {
9785   if (flag_pic)
9786     {
9787       if (TARGET_SECURE_PLT && flag_pic == 2)
9788         return "addi %0,%1,%&@got@tlsld\;bl %z2+32768@plt";
9789       else
9790         return "addi %0,%1,%&@got@tlsld\;bl %z2@plt";
9791     }
9792   else
9793     return "addi %0,%1,%&@got@tlsld\;bl %z2";
9794 }
9795   "&& TARGET_TLS_MARKERS"
9796   [(set (match_dup 0)
9797         (unspec:TLSmode [(match_dup 1)]
9798                         UNSPEC_TLSLD))
9799    (parallel [(set (match_dup 0)
9800                    (call (mem:TLSmode (match_dup 2))
9801                          (match_dup 3)))
9802               (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
9803               (clobber (reg:SI LR_REGNO))])]
9804   ""
9805   [(set_attr "length" "8")])
9806
9807 (define_insn_and_split "*tls_ld<TLSmode:tls_abi_suffix>"
9808   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9809         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")]
9810                         UNSPEC_TLSLD))]
9811   "HAVE_AS_TLS && TARGET_TLS_MARKERS"
9812   "addi %0,%1,%&@got@tlsld"
9813   "&& TARGET_CMODEL != CMODEL_SMALL"
9814   [(set (match_dup 2)
9815         (high:TLSmode
9816             (unspec:TLSmode [(const_int 0) (match_dup 1)] UNSPEC_TLSLD)))
9817    (set (match_dup 0)
9818         (lo_sum:TLSmode (match_dup 2)
9819             (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)))]
9820   "
9821 {
9822   operands[2] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
9823 }"
9824   [(set (attr "length")
9825      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
9826                    (const_int 8)
9827                    (const_int 4)))])
9828
9829 (define_insn "*tls_ld_high<TLSmode:tls_abi_suffix>"
9830   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9831      (high:TLSmode
9832        (unspec:TLSmode [(const_int 0)
9833                         (match_operand:TLSmode 1 "gpc_reg_operand" "b")]
9834                        UNSPEC_TLSLD)))]
9835   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
9836   "addis %0,%1,%&@got@tlsld@ha"
9837   [(set_attr "length" "4")])
9838
9839 (define_insn "*tls_ld_low<TLSmode:tls_abi_suffix>"
9840   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9841      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
9842        (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)))]
9843   "HAVE_AS_TLS && TARGET_TLS_MARKERS && TARGET_CMODEL != CMODEL_SMALL"
9844   "addi %0,%1,%&@got@tlsld@l"
9845   [(set_attr "length" "4")])
9846
9847 (define_insn "*tls_ld_call_aix<TLSmode:tls_abi_suffix>"
9848   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9849         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
9850               (match_operand 2 "" "g")))
9851    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
9852    (clobber (reg:SI LR_REGNO))]
9853   "HAVE_AS_TLS && DEFAULT_ABI == ABI_AIX && TARGET_TLS_MARKERS"
9854   "bl %z1(%&@tlsld)\;nop"
9855   [(set_attr "type" "branch")
9856    (set_attr "length" "8")])
9857
9858 (define_insn "*tls_ld_call_sysv<TLSmode:tls_abi_suffix>"
9859   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9860         (call (mem:TLSmode (match_operand:TLSmode 1 "symbol_ref_operand" "s"))
9861               (match_operand 2 "" "g")))
9862    (unspec:TLSmode [(const_int 0)] UNSPEC_TLSLD)
9863    (clobber (reg:SI LR_REGNO))]
9864   "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS"
9865 {
9866   if (flag_pic)
9867     {
9868       if (TARGET_SECURE_PLT && flag_pic == 2)
9869         return "bl %z1+32768(%&@tlsld)@plt";
9870       return "bl %z1(%&@tlsld)@plt";
9871     }
9872   return "bl %z1(%&@tlsld)";
9873 }
9874   [(set_attr "type" "branch")
9875    (set_attr "length" "4")])
9876
9877 (define_insn "tls_dtprel_<TLSmode:tls_abi_suffix>"
9878   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
9879         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9880                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9881                         UNSPEC_TLSDTPREL))]
9882   "HAVE_AS_TLS"
9883   "addi %0,%1,%2@dtprel")
9884
9885 (define_insn "tls_dtprel_ha_<TLSmode:tls_abi_suffix>"
9886   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
9887         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9888                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9889                         UNSPEC_TLSDTPRELHA))]
9890   "HAVE_AS_TLS"
9891   "addis %0,%1,%2@dtprel@ha")
9892
9893 (define_insn "tls_dtprel_lo_<TLSmode:tls_abi_suffix>"
9894   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
9895         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9896                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9897                         UNSPEC_TLSDTPRELLO))]
9898   "HAVE_AS_TLS"
9899   "addi %0,%1,%2@dtprel@l")
9900
9901 (define_insn_and_split "tls_got_dtprel_<TLSmode:tls_abi_suffix>"
9902   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
9903         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9904                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9905                         UNSPEC_TLSGOTDTPREL))]
9906   "HAVE_AS_TLS"
9907   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel(%1)"
9908   "&& TARGET_CMODEL != CMODEL_SMALL"
9909   [(set (match_dup 3)
9910         (high:TLSmode
9911             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTDTPREL)))
9912    (set (match_dup 0)
9913         (lo_sum:TLSmode (match_dup 3)
9914             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTDTPREL)))]
9915   "
9916 {
9917   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
9918 }"
9919   [(set (attr "length")
9920      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
9921                    (const_int 8)
9922                    (const_int 4)))])
9923
9924 (define_insn "*tls_got_dtprel_high<TLSmode:tls_abi_suffix>"
9925   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9926      (high:TLSmode
9927        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9928                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9929                        UNSPEC_TLSGOTDTPREL)))]
9930   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
9931   "addis %0,%1,%2@got@dtprel@ha"
9932   [(set_attr "length" "4")])
9933
9934 (define_insn "*tls_got_dtprel_low<TLSmode:tls_abi_suffix>"
9935   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
9936      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
9937          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9938                          UNSPEC_TLSGOTDTPREL)))]
9939   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
9940   "l<TLSmode:tls_insn_suffix> %0,%2@got@dtprel@l(%1)"
9941   [(set_attr "length" "4")])
9942
9943 (define_insn "tls_tprel_<TLSmode:tls_abi_suffix>"
9944   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
9945         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9946                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9947                         UNSPEC_TLSTPREL))]
9948   "HAVE_AS_TLS"
9949   "addi %0,%1,%2@tprel")
9950
9951 (define_insn "tls_tprel_ha_<TLSmode:tls_abi_suffix>"
9952   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
9953         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9954                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9955                         UNSPEC_TLSTPRELHA))]
9956   "HAVE_AS_TLS"
9957   "addis %0,%1,%2@tprel@ha")
9958
9959 (define_insn "tls_tprel_lo_<TLSmode:tls_abi_suffix>"
9960   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
9961         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9962                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9963                         UNSPEC_TLSTPRELLO))]
9964   "HAVE_AS_TLS"
9965   "addi %0,%1,%2@tprel@l")
9966
9967 ;; "b" output constraint here and on tls_tls input to support linker tls
9968 ;; optimization.  The linker may edit the instructions emitted by a
9969 ;; tls_got_tprel/tls_tls pair to addis,addi.
9970 (define_insn_and_split "tls_got_tprel_<TLSmode:tls_abi_suffix>"
9971   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9972         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9973                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9974                         UNSPEC_TLSGOTTPREL))]
9975   "HAVE_AS_TLS"
9976   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel(%1)"
9977   "&& TARGET_CMODEL != CMODEL_SMALL"
9978   [(set (match_dup 3)
9979         (high:TLSmode
9980             (unspec:TLSmode [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTTPREL)))
9981    (set (match_dup 0)
9982         (lo_sum:TLSmode (match_dup 3)
9983             (unspec:TLSmode [(match_dup 2)] UNSPEC_TLSGOTTPREL)))]
9984   "
9985 {
9986   operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
9987 }"
9988   [(set (attr "length")
9989      (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
9990                    (const_int 8)
9991                    (const_int 4)))])
9992
9993 (define_insn "*tls_got_tprel_high<TLSmode:tls_abi_suffix>"
9994   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=b")
9995      (high:TLSmode
9996        (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
9997                         (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
9998                        UNSPEC_TLSGOTTPREL)))]
9999   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
10000   "addis %0,%1,%2@got@tprel@ha"
10001   [(set_attr "length" "4")])
10002
10003 (define_insn "*tls_got_tprel_low<TLSmode:tls_abi_suffix>"
10004   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
10005      (lo_sum:TLSmode (match_operand:TLSmode 1 "gpc_reg_operand" "b")
10006          (unspec:TLSmode [(match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
10007                          UNSPEC_TLSGOTTPREL)))]
10008   "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
10009   "l<TLSmode:tls_insn_suffix> %0,%2@got@tprel@l(%1)"
10010   [(set_attr "length" "4")])
10011
10012 (define_insn "tls_tls_<TLSmode:tls_abi_suffix>"
10013   [(set (match_operand:TLSmode 0 "gpc_reg_operand" "=r")
10014         (unspec:TLSmode [(match_operand:TLSmode 1 "gpc_reg_operand" "b")
10015                          (match_operand:TLSmode 2 "rs6000_tls_symbol_ref" "")]
10016                         UNSPEC_TLSTLS))]
10017   "TARGET_ELF && HAVE_AS_TLS"
10018   "add %0,%1,%2@tls")
10019
10020 (define_expand "tls_get_tpointer"
10021   [(set (match_operand:SI 0 "gpc_reg_operand" "")
10022         (unspec:SI [(const_int 0)] UNSPEC_TLSTLS))]
10023   "TARGET_XCOFF && HAVE_AS_TLS"
10024   "
10025 {
10026   emit_insn (gen_tls_get_tpointer_internal ());
10027   emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
10028   DONE;
10029 }")
10030
10031 (define_insn "tls_get_tpointer_internal"
10032   [(set (reg:SI 3)
10033         (unspec:SI [(const_int 0)] UNSPEC_TLSTLS))
10034    (clobber (reg:SI LR_REGNO))]
10035   "TARGET_XCOFF && HAVE_AS_TLS"
10036   "bla __get_tpointer")
10037
10038 (define_expand "tls_get_addr<mode>"
10039   [(set (match_operand:P 0 "gpc_reg_operand" "")
10040         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "")
10041                    (match_operand:P 2 "gpc_reg_operand" "")] UNSPEC_TLSTLS))]
10042   "TARGET_XCOFF && HAVE_AS_TLS"
10043   "
10044 {
10045   emit_move_insn (gen_rtx_REG (Pmode, 3), operands[1]);
10046   emit_move_insn (gen_rtx_REG (Pmode, 4), operands[2]);
10047   emit_insn (gen_tls_get_addr_internal<mode> ());
10048   emit_move_insn (operands[0], gen_rtx_REG (Pmode, 3));
10049   DONE;
10050 }")
10051
10052 (define_insn "tls_get_addr_internal<mode>"
10053   [(set (reg:P 3)
10054         (unspec:P [(reg:P 3) (reg:P 4)] UNSPEC_TLSTLS))
10055    (clobber (reg:P 0))
10056    (clobber (reg:P 4))
10057    (clobber (reg:P 5))
10058    (clobber (reg:P 11))
10059    (clobber (reg:CC CR0_REGNO))
10060    (clobber (reg:P LR_REGNO))]
10061   "TARGET_XCOFF && HAVE_AS_TLS"
10062   "bla __tls_get_addr")
10063 \f
10064 ;; Next come insns related to the calling sequence.
10065 ;;
10066 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
10067 ;; We move the back-chain and decrement the stack pointer.
10068
10069 (define_expand "allocate_stack"
10070   [(set (match_operand 0 "gpc_reg_operand" "")
10071         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
10072    (set (reg 1)
10073         (minus (reg 1) (match_dup 1)))]
10074   ""
10075   "
10076 { rtx chain = gen_reg_rtx (Pmode);
10077   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
10078   rtx neg_op0;
10079   rtx insn, par, set, mem;
10080
10081   emit_move_insn (chain, stack_bot);
10082
10083   /* Check stack bounds if necessary.  */
10084   if (crtl->limit_stack)
10085     {
10086       rtx available;
10087       available = expand_binop (Pmode, sub_optab,
10088                                 stack_pointer_rtx, stack_limit_rtx,
10089                                 NULL_RTX, 1, OPTAB_WIDEN);
10090       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
10091     }
10092
10093   if (GET_CODE (operands[1]) != CONST_INT
10094       || INTVAL (operands[1]) < -32767
10095       || INTVAL (operands[1]) > 32768)
10096     {
10097       neg_op0 = gen_reg_rtx (Pmode);
10098       if (TARGET_32BIT)
10099         emit_insn (gen_negsi2 (neg_op0, operands[1]));
10100       else
10101         emit_insn (gen_negdi2 (neg_op0, operands[1]));
10102     }
10103   else
10104     neg_op0 = GEN_INT (- INTVAL (operands[1]));
10105
10106   insn = emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update_stack
10107                                        : gen_movdi_di_update_stack))
10108                         (stack_pointer_rtx, stack_pointer_rtx, neg_op0,
10109                          chain));
10110   /* Since we didn't use gen_frame_mem to generate the MEM, grab
10111      it now and set the alias set/attributes. The above gen_*_update
10112      calls will generate a PARALLEL with the MEM set being the first
10113      operation. */
10114   par = PATTERN (insn);
10115   gcc_assert (GET_CODE (par) == PARALLEL);
10116   set = XVECEXP (par, 0, 0);
10117   gcc_assert (GET_CODE (set) == SET);
10118   mem = SET_DEST (set);
10119   gcc_assert (MEM_P (mem));
10120   MEM_NOTRAP_P (mem) = 1;
10121   set_mem_alias_set (mem, get_frame_alias_set ());
10122
10123   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
10124   DONE;
10125 }")
10126
10127 ;; These patterns say how to save and restore the stack pointer.  We need not
10128 ;; save the stack pointer at function level since we are careful to
10129 ;; preserve the backchain.  At block level, we have to restore the backchain
10130 ;; when we restore the stack pointer.
10131 ;;
10132 ;; For nonlocal gotos, we must save both the stack pointer and its
10133 ;; backchain and restore both.  Note that in the nonlocal case, the
10134 ;; save area is a memory location.
10135
10136 (define_expand "save_stack_function"
10137   [(match_operand 0 "any_operand" "")
10138    (match_operand 1 "any_operand" "")]
10139   ""
10140   "DONE;")
10141
10142 (define_expand "restore_stack_function"
10143   [(match_operand 0 "any_operand" "")
10144    (match_operand 1 "any_operand" "")]
10145   ""
10146   "DONE;")
10147
10148 ;; Adjust stack pointer (op0) to a new value (op1).
10149 ;; First copy old stack backchain to new location, and ensure that the
10150 ;; scheduler won't reorder the sp assignment before the backchain write.
10151 (define_expand "restore_stack_block"
10152   [(set (match_dup 2) (match_dup 3))
10153    (set (match_dup 4) (match_dup 2))
10154    (match_dup 5)
10155    (set (match_operand 0 "register_operand" "")
10156         (match_operand 1 "register_operand" ""))]
10157   ""
10158   "
10159 {
10160   rtvec p;
10161
10162   operands[1] = force_reg (Pmode, operands[1]);
10163   operands[2] = gen_reg_rtx (Pmode);
10164   operands[3] = gen_frame_mem (Pmode, operands[0]);
10165   operands[4] = gen_frame_mem (Pmode, operands[1]);
10166   p = rtvec_alloc (1);
10167   RTVEC_ELT (p, 0) = gen_rtx_SET (VOIDmode,
10168                                   gen_frame_mem (BLKmode, operands[0]),
10169                                   const0_rtx);
10170   operands[5] = gen_rtx_PARALLEL (VOIDmode, p);
10171 }")
10172
10173 (define_expand "save_stack_nonlocal"
10174   [(set (match_dup 3) (match_dup 4))
10175    (set (match_operand 0 "memory_operand" "") (match_dup 3))
10176    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
10177   ""
10178   "
10179 {
10180   int units_per_word = (TARGET_32BIT) ? 4 : 8;
10181
10182   /* Copy the backchain to the first word, sp to the second.  */
10183   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
10184   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
10185   operands[3] = gen_reg_rtx (Pmode);
10186   operands[4] = gen_frame_mem (Pmode, operands[1]);
10187 }")
10188
10189 (define_expand "restore_stack_nonlocal"
10190   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
10191    (set (match_dup 3) (match_dup 4))
10192    (set (match_dup 5) (match_dup 2))
10193    (match_dup 6)
10194    (set (match_operand 0 "register_operand" "") (match_dup 3))]
10195   ""
10196   "
10197 {
10198   int units_per_word = (TARGET_32BIT) ? 4 : 8;
10199   rtvec p;
10200
10201   /* Restore the backchain from the first word, sp from the second.  */
10202   operands[2] = gen_reg_rtx (Pmode);
10203   operands[3] = gen_reg_rtx (Pmode);
10204   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
10205   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
10206   operands[5] = gen_frame_mem (Pmode, operands[3]);
10207   p = rtvec_alloc (1);
10208   RTVEC_ELT (p, 0) = gen_rtx_SET (VOIDmode,
10209                                   gen_frame_mem (BLKmode, operands[0]),
10210                                   const0_rtx);
10211   operands[6] = gen_rtx_PARALLEL (VOIDmode, p);
10212 }")
10213 \f
10214 ;; TOC register handling.
10215
10216 ;; Code to initialize the TOC register...
10217
10218 (define_insn "load_toc_aix_si"
10219   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10220                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
10221               (use (reg:SI 2))])]
10222   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
10223   "*
10224 {
10225   char buf[30];
10226   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10227   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10228   operands[2] = gen_rtx_REG (Pmode, 2);
10229   return \"lwz %0,%1(%2)\";
10230 }"
10231   [(set_attr "type" "load")])
10232
10233 (define_insn "load_toc_aix_di"
10234   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10235                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
10236               (use (reg:DI 2))])]
10237   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
10238   "*
10239 {
10240   char buf[30];
10241 #ifdef TARGET_RELOCATABLE
10242   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
10243                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
10244 #else
10245   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10246 #endif
10247   if (TARGET_ELF)
10248     strcat (buf, \"@toc\");
10249   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10250   operands[2] = gen_rtx_REG (Pmode, 2);
10251   return \"ld %0,%1(%2)\";
10252 }"
10253   [(set_attr "type" "load")])
10254
10255 (define_insn "load_toc_v4_pic_si"
10256   [(set (reg:SI LR_REGNO)
10257         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
10258   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
10259   "bl _GLOBAL_OFFSET_TABLE_@local-4"
10260   [(set_attr "type" "branch")
10261    (set_attr "length" "4")])
10262
10263 (define_expand "load_toc_v4_PIC_1"
10264   [(parallel [(set (reg:SI LR_REGNO)
10265                    (match_operand:SI 0 "immediate_operand" "s"))
10266               (use (unspec [(match_dup 0)] UNSPEC_TOC))])]
10267   "TARGET_ELF && DEFAULT_ABI != ABI_AIX
10268    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
10269   "")
10270
10271 (define_insn "load_toc_v4_PIC_1_normal"
10272   [(set (reg:SI LR_REGNO)
10273         (match_operand:SI 0 "immediate_operand" "s"))
10274    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
10275   "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX
10276    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
10277   "bcl 20,31,%0\\n%0:"
10278   [(set_attr "type" "branch")
10279    (set_attr "length" "4")])
10280
10281 (define_insn "load_toc_v4_PIC_1_476"
10282   [(set (reg:SI LR_REGNO)
10283         (match_operand:SI 0 "immediate_operand" "s"))
10284    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
10285   "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX
10286    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
10287   "*
10288 {
10289   char name[32];
10290   static char templ[32];
10291
10292   get_ppc476_thunk_name (name);
10293   sprintf (templ, \"bl %s\\n%%0:\", name);
10294   return templ;
10295 }"
10296   [(set_attr "type" "branch")
10297    (set_attr "length" "4")])
10298
10299 (define_expand "load_toc_v4_PIC_1b"
10300   [(parallel [(set (reg:SI LR_REGNO)
10301                    (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
10302                                (label_ref (match_operand 1 "" ""))]
10303                            UNSPEC_TOCPTR))
10304               (match_dup 1)])]
10305   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10306   "")
10307
10308 (define_insn "load_toc_v4_PIC_1b_normal"
10309   [(set (reg:SI LR_REGNO)
10310         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
10311                     (label_ref (match_operand 1 "" ""))]
10312                 UNSPEC_TOCPTR))
10313    (match_dup 1)]
10314   "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10315   "bcl 20,31,$+8\;.long %0-$"
10316   [(set_attr "type" "branch")
10317    (set_attr "length" "8")])
10318
10319 (define_insn "load_toc_v4_PIC_1b_476"
10320   [(set (reg:SI LR_REGNO)
10321         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
10322                     (label_ref (match_operand 1 "" ""))]
10323                 UNSPEC_TOCPTR))
10324    (match_dup 1)]
10325   "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10326   "*
10327 {
10328   char name[32];
10329   static char templ[32];
10330
10331   get_ppc476_thunk_name (name);
10332   sprintf (templ, \"bl %s\\n\\tb $+8\\n\\t.long %%0-$\", name);
10333   return templ;
10334 }"
10335   [(set_attr "type" "branch")
10336    (set_attr "length" "16")])
10337
10338 (define_insn "load_toc_v4_PIC_2"
10339   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10340         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10341                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
10342                              (match_operand:SI 3 "immediate_operand" "s")))))]
10343   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10344   "lwz %0,%2-%3(%1)"
10345   [(set_attr "type" "load")])
10346
10347 (define_insn "load_toc_v4_PIC_3b"
10348   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10349         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10350                  (high:SI
10351                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
10352                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
10353   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
10354   "addis %0,%1,%2-%3@ha")
10355
10356 (define_insn "load_toc_v4_PIC_3c"
10357   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10358         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10359                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
10360                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
10361   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
10362   "addi %0,%1,%2-%3@l")
10363
10364 ;; If the TOC is shared over a translation unit, as happens with all
10365 ;; the kinds of PIC that we support, we need to restore the TOC
10366 ;; pointer only when jumping over units of translation.
10367 ;; On Darwin, we need to reload the picbase.
10368
10369 (define_expand "builtin_setjmp_receiver"
10370   [(use (label_ref (match_operand 0 "" "")))]
10371   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10372    || (TARGET_TOC && TARGET_MINIMAL_TOC)
10373    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
10374   "
10375 {
10376 #if TARGET_MACHO
10377   if (DEFAULT_ABI == ABI_DARWIN)
10378     {
10379       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME);
10380       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
10381       rtx tmplabrtx;
10382       char tmplab[20];
10383
10384       crtl->uses_pic_offset_table = 1;
10385       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
10386                                   CODE_LABEL_NUMBER (operands[0]));
10387       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
10388
10389       emit_insn (gen_load_macho_picbase (tmplabrtx));
10390       emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO));
10391       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
10392     }
10393   else
10394 #endif
10395     rs6000_emit_load_toc_table (FALSE);
10396   DONE;
10397 }")
10398
10399 ;; Largetoc support
10400 (define_insn "*largetoc_high"
10401   [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
10402         (high:DI
10403           (unspec [(match_operand:DI 1 "" "")
10404                    (match_operand:DI 2 "gpc_reg_operand" "b")]
10405                   UNSPEC_TOCREL)))]
10406    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
10407    "addis %0,%2,%1@toc@ha")
10408
10409 (define_insn "*largetoc_high_aix<mode>"
10410   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
10411         (high:P
10412           (unspec [(match_operand:P 1 "" "")
10413                    (match_operand:P 2 "gpc_reg_operand" "b")]
10414                   UNSPEC_TOCREL)))]
10415    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
10416    "addis %0,%1@u(%2)")
10417
10418 (define_insn "*largetoc_high_plus"
10419   [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
10420         (high:DI
10421           (plus:DI
10422             (unspec [(match_operand:DI 1 "" "")
10423                      (match_operand:DI 2 "gpc_reg_operand" "b")]
10424                     UNSPEC_TOCREL)
10425             (match_operand 3 "const_int_operand" "n"))))]
10426    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
10427    "addis %0,%2,%1+%3@toc@ha")
10428
10429 (define_insn "*largetoc_high_plus_aix<mode>"
10430   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
10431         (high:P
10432           (plus:P
10433             (unspec [(match_operand:P 1 "" "")
10434                      (match_operand:P 2 "gpc_reg_operand" "b")]
10435                     UNSPEC_TOCREL)
10436             (match_operand 3 "const_int_operand" "n"))))]
10437    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
10438    "addis %0,%1+%3@u(%2)")
10439
10440 (define_insn "*largetoc_low"
10441   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
10442         (lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b,!*r")
10443                    (match_operand:DI 2 "" "")))]
10444    "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
10445    "@
10446     addi %0,%1,%2@l
10447     addic %0,%1,%2@l")
10448
10449 (define_insn "*largetoc_low_aix<mode>"
10450   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
10451         (lo_sum:P (match_operand:P 1 "gpc_reg_operand" "b")
10452                    (match_operand:P 2 "" "")))]
10453    "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
10454    "la %0,%2@l(%1)")
10455
10456 (define_insn_and_split "*tocref<mode>"
10457   [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
10458         (match_operand:P 1 "small_toc_ref" "R"))]
10459    "TARGET_TOC"
10460    "la %0,%a1"
10461    "&& TARGET_CMODEL != CMODEL_SMALL && reload_completed"
10462   [(set (match_dup 0) (high:P (match_dup 1)))
10463    (set (match_dup 0) (lo_sum:P (match_dup 0) (match_dup 1)))])
10464
10465 ;; Elf specific ways of loading addresses for non-PIC code.
10466 ;; The output of this could be r0, but we make a very strong
10467 ;; preference for a base register because it will usually
10468 ;; be needed there.
10469 (define_insn "elf_high"
10470   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
10471         (high:SI (match_operand 1 "" "")))]
10472   "TARGET_ELF && ! TARGET_64BIT"
10473   "lis %0,%1@ha")
10474
10475 (define_insn "elf_low"
10476   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
10477         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
10478                    (match_operand 2 "" "")))]
10479    "TARGET_ELF && ! TARGET_64BIT"
10480    "@
10481     la %0,%2@l(%1)
10482     addic %0,%1,%K2")
10483 \f
10484 ;; Call and call_value insns
10485 (define_expand "call"
10486   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10487                     (match_operand 1 "" ""))
10488               (use (match_operand 2 "" ""))
10489               (clobber (reg:SI LR_REGNO))])]
10490   ""
10491   "
10492 {
10493 #if TARGET_MACHO
10494   if (MACHOPIC_INDIRECT)
10495     operands[0] = machopic_indirect_call_target (operands[0]);
10496 #endif
10497
10498   gcc_assert (GET_CODE (operands[0]) == MEM);
10499   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
10500
10501   operands[0] = XEXP (operands[0], 0);
10502
10503   if (GET_CODE (operands[0]) != SYMBOL_REF
10504       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
10505       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
10506     {
10507       if (INTVAL (operands[2]) & CALL_LONG)
10508         operands[0] = rs6000_longcall_ref (operands[0]);
10509
10510       switch (DEFAULT_ABI)
10511         {
10512         case ABI_V4:
10513         case ABI_DARWIN:
10514           operands[0] = force_reg (Pmode, operands[0]);
10515           break;
10516
10517         case ABI_AIX:
10518           /* AIX function pointers are really pointers to a three word
10519              area.  */
10520           rs6000_call_indirect_aix (NULL_RTX, operands[0], operands[1]);
10521           DONE;
10522
10523         default:
10524           gcc_unreachable ();
10525         }
10526     }
10527 }")
10528
10529 (define_expand "call_value"
10530   [(parallel [(set (match_operand 0 "" "")
10531                    (call (mem:SI (match_operand 1 "address_operand" ""))
10532                          (match_operand 2 "" "")))
10533               (use (match_operand 3 "" ""))
10534               (clobber (reg:SI LR_REGNO))])]
10535   ""
10536   "
10537 {
10538 #if TARGET_MACHO
10539   if (MACHOPIC_INDIRECT)
10540     operands[1] = machopic_indirect_call_target (operands[1]);
10541 #endif
10542
10543   gcc_assert (GET_CODE (operands[1]) == MEM);
10544   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
10545
10546   operands[1] = XEXP (operands[1], 0);
10547
10548   if (GET_CODE (operands[1]) != SYMBOL_REF
10549       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
10550       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
10551     {
10552       if (INTVAL (operands[3]) & CALL_LONG)
10553         operands[1] = rs6000_longcall_ref (operands[1]);
10554
10555       switch (DEFAULT_ABI)
10556         {
10557         case ABI_V4:
10558         case ABI_DARWIN:
10559           operands[1] = force_reg (Pmode, operands[1]);
10560           break;
10561
10562         case ABI_AIX:
10563           /* AIX function pointers are really pointers to a three word
10564              area.  */
10565           rs6000_call_indirect_aix (operands[0], operands[1], operands[2]);
10566           DONE;
10567
10568         default:
10569           gcc_unreachable ();
10570         }
10571     }
10572 }")
10573
10574 ;; Call to function in current module.  No TOC pointer reload needed.
10575 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10576 ;; either the function was not prototyped, or it was prototyped as a
10577 ;; variable argument function.  It is > 0 if FP registers were passed
10578 ;; and < 0 if they were not.
10579
10580 (define_insn "*call_local32"
10581   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10582          (match_operand 1 "" "g,g"))
10583    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10584    (clobber (reg:SI LR_REGNO))]
10585   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10586   "*
10587 {
10588   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10589     output_asm_insn (\"crxor 6,6,6\", operands);
10590
10591   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10592     output_asm_insn (\"creqv 6,6,6\", operands);
10593
10594   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10595 }"
10596   [(set_attr "type" "branch")
10597    (set_attr "length" "4,8")])
10598
10599 (define_insn "*call_local64"
10600   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10601          (match_operand 1 "" "g,g"))
10602    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10603    (clobber (reg:SI LR_REGNO))]
10604   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10605   "*
10606 {
10607   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10608     output_asm_insn (\"crxor 6,6,6\", operands);
10609
10610   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10611     output_asm_insn (\"creqv 6,6,6\", operands);
10612
10613   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10614 }"
10615   [(set_attr "type" "branch")
10616    (set_attr "length" "4,8")])
10617
10618 (define_insn "*call_value_local32"
10619   [(set (match_operand 0 "" "")
10620         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10621               (match_operand 2 "" "g,g")))
10622    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10623    (clobber (reg:SI LR_REGNO))]
10624   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10625   "*
10626 {
10627   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10628     output_asm_insn (\"crxor 6,6,6\", operands);
10629
10630   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10631     output_asm_insn (\"creqv 6,6,6\", operands);
10632
10633   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10634 }"
10635   [(set_attr "type" "branch")
10636    (set_attr "length" "4,8")])
10637
10638
10639 (define_insn "*call_value_local64"
10640   [(set (match_operand 0 "" "")
10641         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10642               (match_operand 2 "" "g,g")))
10643    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10644    (clobber (reg:SI LR_REGNO))]
10645   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10646   "*
10647 {
10648   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10649     output_asm_insn (\"crxor 6,6,6\", operands);
10650
10651   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10652     output_asm_insn (\"creqv 6,6,6\", operands);
10653
10654   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10655 }"
10656   [(set_attr "type" "branch")
10657    (set_attr "length" "4,8")])
10658
10659 ;; Call to indirect functions with the AIX abi using a 3 word descriptor.
10660 ;; Operand0 is the addresss of the function to call
10661 ;; Operand1 is the flag for System V.4 for unprototyped or FP registers
10662 ;; Operand2 is the location in the function descriptor to load r2 from
10663 ;; Operand3 is the stack location to hold the current TOC pointer
10664
10665 (define_insn "call_indirect_aix<ptrsize>"
10666   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
10667          (match_operand 1 "" "g,g"))
10668    (use (match_operand:P 2 "memory_operand" "<ptrm>,<ptrm>"))
10669    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
10670    (use (reg:P STATIC_CHAIN_REGNUM))
10671    (clobber (reg:P LR_REGNO))]
10672   "DEFAULT_ABI == ABI_AIX && TARGET_POINTERS_TO_NESTED_FUNCTIONS"
10673   "<ptrload> 2,%2\;b%T0l\;<ptrload> 2,%3"
10674   [(set_attr "type" "jmpreg")
10675    (set_attr "length" "12")])
10676
10677 ;; Like call_indirect_aix<ptrsize>, but no use of the static chain
10678 ;; Operand0 is the addresss of the function to call
10679 ;; Operand1 is the flag for System V.4 for unprototyped or FP registers
10680 ;; Operand2 is the location in the function descriptor to load r2 from
10681 ;; Operand3 is the stack location to hold the current TOC pointer
10682
10683 (define_insn "call_indirect_aix<ptrsize>_nor11"
10684   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
10685          (match_operand 1 "" "g,g"))
10686    (use (match_operand:P 2 "memory_operand" "<ptrm>,<ptrm>"))
10687    (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
10688    (clobber (reg:P LR_REGNO))]
10689   "DEFAULT_ABI == ABI_AIX && !TARGET_POINTERS_TO_NESTED_FUNCTIONS"
10690   "<ptrload> 2,%2\;b%T0l\;<ptrload> 2,%3"
10691   [(set_attr "type" "jmpreg")
10692    (set_attr "length" "12")])
10693
10694 ;; Operand0 is the return result of the function
10695 ;; Operand1 is the addresss of the function to call
10696 ;; Operand2 is the flag for System V.4 for unprototyped or FP registers
10697 ;; Operand3 is the location in the function descriptor to load r2 from
10698 ;; Operand4 is the stack location to hold the current TOC pointer
10699
10700 (define_insn "call_value_indirect_aix<ptrsize>"
10701   [(set (match_operand 0 "" "")
10702         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
10703               (match_operand 2 "" "g,g")))
10704    (use (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
10705    (set (reg:P TOC_REGNUM) (match_operand:P 4 "memory_operand" "<ptrm>,<ptrm>"))
10706    (use (reg:P STATIC_CHAIN_REGNUM))
10707    (clobber (reg:P LR_REGNO))]
10708   "DEFAULT_ABI == ABI_AIX && TARGET_POINTERS_TO_NESTED_FUNCTIONS"
10709   "<ptrload> 2,%3\;b%T1l\;<ptrload> 2,%4"
10710   [(set_attr "type" "jmpreg")
10711    (set_attr "length" "12")])
10712
10713 ;; Like call_value_indirect_aix<ptrsize>, but no use of the static chain
10714 ;; Operand0 is the return result of the function
10715 ;; Operand1 is the addresss of the function to call
10716 ;; Operand2 is the flag for System V.4 for unprototyped or FP registers
10717 ;; Operand3 is the location in the function descriptor to load r2 from
10718 ;; Operand4 is the stack location to hold the current TOC pointer
10719
10720 (define_insn "call_value_indirect_aix<ptrsize>_nor11"
10721   [(set (match_operand 0 "" "")
10722         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
10723               (match_operand 2 "" "g,g")))
10724    (use (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
10725    (set (reg:P TOC_REGNUM) (match_operand:P 4 "memory_operand" "<ptrm>,<ptrm>"))
10726    (clobber (reg:P LR_REGNO))]
10727   "DEFAULT_ABI == ABI_AIX && !TARGET_POINTERS_TO_NESTED_FUNCTIONS"
10728   "<ptrload> 2,%3\;b%T1l\;<ptrload> 2,%4"
10729   [(set_attr "type" "jmpreg")
10730    (set_attr "length" "12")])
10731
10732 ;; Call to function which may be in another module.  Restore the TOC
10733 ;; pointer (r2) after the call unless this is System V.
10734 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10735 ;; either the function was not prototyped, or it was prototyped as a
10736 ;; variable argument function.  It is > 0 if FP registers were passed
10737 ;; and < 0 if they were not.
10738
10739 (define_insn "*call_nonlocal_aix32"
10740   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10741          (match_operand 1 "" "g"))
10742    (use (match_operand:SI 2 "immediate_operand" "O"))
10743    (clobber (reg:SI LR_REGNO))]
10744   "TARGET_32BIT
10745    && DEFAULT_ABI == ABI_AIX
10746    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10747   "bl %z0\;nop"
10748   [(set_attr "type" "branch")
10749    (set_attr "length" "8")])
10750    
10751 (define_insn "*call_nonlocal_aix64"
10752   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10753          (match_operand 1 "" "g"))
10754    (use (match_operand:SI 2 "immediate_operand" "O"))
10755    (clobber (reg:SI LR_REGNO))]
10756   "TARGET_64BIT
10757    && DEFAULT_ABI == ABI_AIX
10758    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10759   "bl %z0\;nop"
10760   [(set_attr "type" "branch")
10761    (set_attr "length" "8")])
10762
10763 (define_insn "*call_value_nonlocal_aix32"
10764   [(set (match_operand 0 "" "")
10765         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10766               (match_operand 2 "" "g")))
10767    (use (match_operand:SI 3 "immediate_operand" "O"))
10768    (clobber (reg:SI LR_REGNO))]
10769   "TARGET_32BIT
10770    && DEFAULT_ABI == ABI_AIX
10771    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10772   "bl %z1\;nop"
10773   [(set_attr "type" "branch")
10774    (set_attr "length" "8")])
10775
10776 (define_insn "*call_value_nonlocal_aix64"
10777   [(set (match_operand 0 "" "")
10778         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10779               (match_operand 2 "" "g")))
10780    (use (match_operand:SI 3 "immediate_operand" "O"))
10781    (clobber (reg:SI LR_REGNO))]
10782   "TARGET_64BIT
10783    && DEFAULT_ABI == ABI_AIX
10784    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10785   "bl %z1\;nop"
10786   [(set_attr "type" "branch")
10787    (set_attr "length" "8")])
10788
10789 ;; A function pointer under System V is just a normal pointer
10790 ;; operands[0] is the function pointer
10791 ;; operands[1] is the stack size to clean up
10792 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
10793 ;; which indicates how to set cr1
10794
10795 (define_insn "*call_indirect_nonlocal_sysv<mode>"
10796   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
10797          (match_operand 1 "" "g,g,g,g"))
10798    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
10799    (clobber (reg:SI LR_REGNO))]
10800   "DEFAULT_ABI == ABI_V4
10801    || DEFAULT_ABI == ABI_DARWIN"
10802 {
10803   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10804     output_asm_insn ("crxor 6,6,6", operands);
10805
10806   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10807     output_asm_insn ("creqv 6,6,6", operands);
10808
10809   return "b%T0l";
10810 }
10811   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
10812    (set_attr "length" "4,4,8,8")])
10813
10814 (define_insn_and_split "*call_nonlocal_sysv<mode>"
10815   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
10816          (match_operand 1 "" "g,g"))
10817    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10818    (clobber (reg:SI LR_REGNO))]
10819   "(DEFAULT_ABI == ABI_DARWIN
10820    || (DEFAULT_ABI == ABI_V4
10821        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
10822 {
10823   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10824     output_asm_insn ("crxor 6,6,6", operands);
10825
10826   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10827     output_asm_insn ("creqv 6,6,6", operands);
10828
10829 #if TARGET_MACHO
10830   return output_call(insn, operands, 0, 2);
10831 #else
10832   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10833     {
10834       gcc_assert (!TARGET_SECURE_PLT);
10835       return "bl %z0@plt";
10836     }
10837   else
10838     return "bl %z0";
10839 #endif
10840 }
10841   "DEFAULT_ABI == ABI_V4
10842    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
10843    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10844   [(parallel [(call (mem:SI (match_dup 0))
10845                     (match_dup 1))
10846               (use (match_dup 2))
10847               (use (match_dup 3))
10848               (clobber (reg:SI LR_REGNO))])]
10849 {
10850   operands[3] = pic_offset_table_rtx;
10851 }
10852   [(set_attr "type" "branch,branch")
10853    (set_attr "length" "4,8")])
10854
10855 (define_insn "*call_nonlocal_sysv_secure<mode>"
10856   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
10857          (match_operand 1 "" "g,g"))
10858    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10859    (use (match_operand:SI 3 "register_operand" "r,r"))
10860    (clobber (reg:SI LR_REGNO))]
10861   "(DEFAULT_ABI == ABI_V4
10862     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
10863     && (INTVAL (operands[2]) & CALL_LONG) == 0)"
10864 {
10865   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10866     output_asm_insn ("crxor 6,6,6", operands);
10867
10868   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10869     output_asm_insn ("creqv 6,6,6", operands);
10870
10871   if (flag_pic == 2)
10872     /* The magic 32768 offset here and in the other sysv call insns
10873        corresponds to the offset of r30 in .got2, as given by LCTOC1.
10874        See sysv4.h:toc_section.  */
10875     return "bl %z0+32768@plt";
10876   else
10877     return "bl %z0@plt";
10878 }
10879   [(set_attr "type" "branch,branch")
10880    (set_attr "length" "4,8")])
10881
10882 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
10883   [(set (match_operand 0 "" "")
10884         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
10885               (match_operand 2 "" "g,g,g,g")))
10886    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
10887    (clobber (reg:SI LR_REGNO))]
10888   "DEFAULT_ABI == ABI_V4
10889    || DEFAULT_ABI == ABI_DARWIN"
10890 {
10891   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10892     output_asm_insn ("crxor 6,6,6", operands);
10893
10894   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10895     output_asm_insn ("creqv 6,6,6", operands);
10896
10897   return "b%T1l";
10898 }
10899   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
10900    (set_attr "length" "4,4,8,8")])
10901
10902 (define_insn_and_split "*call_value_nonlocal_sysv<mode>"
10903   [(set (match_operand 0 "" "")
10904         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
10905               (match_operand 2 "" "g,g")))
10906    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10907    (clobber (reg:SI LR_REGNO))]
10908   "(DEFAULT_ABI == ABI_DARWIN
10909    || (DEFAULT_ABI == ABI_V4
10910        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
10911 {
10912   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10913     output_asm_insn ("crxor 6,6,6", operands);
10914
10915   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10916     output_asm_insn ("creqv 6,6,6", operands);
10917
10918 #if TARGET_MACHO
10919   return output_call(insn, operands, 1, 3);
10920 #else
10921   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10922     {
10923       gcc_assert (!TARGET_SECURE_PLT);
10924       return "bl %z1@plt";
10925     }
10926   else
10927     return "bl %z1";
10928 #endif
10929 }
10930   "DEFAULT_ABI == ABI_V4
10931    && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
10932    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10933   [(parallel [(set (match_dup 0)
10934                    (call (mem:SI (match_dup 1))
10935                          (match_dup 2)))
10936               (use (match_dup 3))
10937               (use (match_dup 4))
10938               (clobber (reg:SI LR_REGNO))])]
10939 {
10940   operands[4] = pic_offset_table_rtx;
10941 }
10942   [(set_attr "type" "branch,branch")
10943    (set_attr "length" "4,8")])
10944
10945 (define_insn "*call_value_nonlocal_sysv_secure<mode>"
10946   [(set (match_operand 0 "" "")
10947         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
10948               (match_operand 2 "" "g,g")))
10949    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10950    (use (match_operand:SI 4 "register_operand" "r,r"))
10951    (clobber (reg:SI LR_REGNO))]
10952   "(DEFAULT_ABI == ABI_V4
10953     && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
10954     && (INTVAL (operands[3]) & CALL_LONG) == 0)"
10955 {
10956   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10957     output_asm_insn ("crxor 6,6,6", operands);
10958
10959   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10960     output_asm_insn ("creqv 6,6,6", operands);
10961
10962   if (flag_pic == 2)
10963     return "bl %z1+32768@plt";
10964   else
10965     return "bl %z1@plt";
10966 }
10967   [(set_attr "type" "branch,branch")
10968    (set_attr "length" "4,8")])
10969
10970 ;; Call subroutine returning any type.
10971 (define_expand "untyped_call"
10972   [(parallel [(call (match_operand 0 "" "")
10973                     (const_int 0))
10974               (match_operand 1 "" "")
10975               (match_operand 2 "" "")])]
10976   ""
10977   "
10978 {
10979   int i;
10980
10981   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
10982
10983   for (i = 0; i < XVECLEN (operands[2], 0); i++)
10984     {
10985       rtx set = XVECEXP (operands[2], 0, i);
10986       emit_move_insn (SET_DEST (set), SET_SRC (set));
10987     }
10988
10989   /* The optimizer does not know that the call sets the function value
10990      registers we stored in the result block.  We avoid problems by
10991      claiming that all hard registers are used and clobbered at this
10992      point.  */
10993   emit_insn (gen_blockage ());
10994
10995   DONE;
10996 }")
10997
10998 ;; sibling call patterns
10999 (define_expand "sibcall"
11000   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
11001                     (match_operand 1 "" ""))
11002               (use (match_operand 2 "" ""))
11003               (use (reg:SI LR_REGNO))
11004               (simple_return)])]
11005   ""
11006   "
11007 {
11008 #if TARGET_MACHO
11009   if (MACHOPIC_INDIRECT)
11010     operands[0] = machopic_indirect_call_target (operands[0]);
11011 #endif
11012
11013   gcc_assert (GET_CODE (operands[0]) == MEM);
11014   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
11015
11016   operands[0] = XEXP (operands[0], 0);
11017 }")
11018
11019 ;; this and similar patterns must be marked as using LR, otherwise
11020 ;; dataflow will try to delete the store into it.  This is true
11021 ;; even when the actual reg to jump to is in CTR, when LR was
11022 ;; saved and restored around the PIC-setting BCL.
11023 (define_insn "*sibcall_local32"
11024   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
11025          (match_operand 1 "" "g,g"))
11026    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11027    (use (reg:SI LR_REGNO))
11028    (simple_return)]
11029   "(INTVAL (operands[2]) & CALL_LONG) == 0"
11030   "*
11031 {
11032   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11033     output_asm_insn (\"crxor 6,6,6\", operands);
11034
11035   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11036     output_asm_insn (\"creqv 6,6,6\", operands);
11037
11038   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
11039 }"
11040   [(set_attr "type" "branch")
11041    (set_attr "length" "4,8")])
11042
11043 (define_insn "*sibcall_local64"
11044   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
11045          (match_operand 1 "" "g,g"))
11046    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11047    (use (reg:SI LR_REGNO))
11048    (simple_return)]
11049   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
11050   "*
11051 {
11052   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11053     output_asm_insn (\"crxor 6,6,6\", operands);
11054
11055   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11056     output_asm_insn (\"creqv 6,6,6\", operands);
11057
11058   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
11059 }"
11060   [(set_attr "type" "branch")
11061    (set_attr "length" "4,8")])
11062
11063 (define_insn "*sibcall_value_local32"
11064   [(set (match_operand 0 "" "")
11065         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
11066               (match_operand 2 "" "g,g")))
11067    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11068    (use (reg:SI LR_REGNO))
11069    (simple_return)]
11070   "(INTVAL (operands[3]) & CALL_LONG) == 0"
11071   "*
11072 {
11073   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11074     output_asm_insn (\"crxor 6,6,6\", operands);
11075
11076   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11077     output_asm_insn (\"creqv 6,6,6\", operands);
11078
11079   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
11080 }"
11081   [(set_attr "type" "branch")
11082    (set_attr "length" "4,8")])
11083
11084
11085 (define_insn "*sibcall_value_local64"
11086   [(set (match_operand 0 "" "")
11087         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
11088               (match_operand 2 "" "g,g")))
11089    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11090    (use (reg:SI LR_REGNO))
11091    (simple_return)]
11092   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
11093   "*
11094 {
11095   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11096     output_asm_insn (\"crxor 6,6,6\", operands);
11097
11098   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11099     output_asm_insn (\"creqv 6,6,6\", operands);
11100
11101   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
11102 }"
11103   [(set_attr "type" "branch")
11104    (set_attr "length" "4,8")])
11105
11106 (define_insn "*sibcall_nonlocal_aix<mode>"
11107   [(call (mem:SI (match_operand:P 0 "call_operand" "s,c"))
11108          (match_operand 1 "" "g,g"))
11109    (use (match_operand:SI 2 "immediate_operand" "O,O"))
11110    (use (reg:SI LR_REGNO))
11111    (simple_return)]
11112   "DEFAULT_ABI == ABI_AIX
11113    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11114   "@
11115    b %z0
11116    b%T0"
11117   [(set_attr "type" "branch")
11118    (set_attr "length" "4")])
11119
11120 (define_insn "*sibcall_value_nonlocal_aix<mode>"
11121   [(set (match_operand 0 "" "")
11122         (call (mem:SI (match_operand:P 1 "call_operand" "s,c"))
11123               (match_operand 2 "" "g,g")))
11124    (use (match_operand:SI 3 "immediate_operand" "O,O"))
11125    (use (reg:SI LR_REGNO))
11126    (simple_return)]
11127   "DEFAULT_ABI == ABI_AIX
11128    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11129   "@
11130    b %z1
11131    b%T1"
11132   [(set_attr "type" "branch")
11133    (set_attr "length" "4")])
11134
11135 (define_insn "*sibcall_nonlocal_sysv<mode>"
11136   [(call (mem:SI (match_operand:P 0 "call_operand" "s,s,c,c"))
11137          (match_operand 1 "" ""))
11138    (use (match_operand 2 "immediate_operand" "O,n,O,n"))
11139    (use (reg:SI LR_REGNO))
11140    (simple_return)]
11141   "(DEFAULT_ABI == ABI_DARWIN
11142     || DEFAULT_ABI == ABI_V4)
11143    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11144   "*
11145 {
11146   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11147     output_asm_insn (\"crxor 6,6,6\", operands);
11148
11149   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11150     output_asm_insn (\"creqv 6,6,6\", operands);
11151
11152   if (which_alternative >= 2)
11153     return \"b%T0\";
11154   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
11155     {
11156       gcc_assert (!TARGET_SECURE_PLT);
11157       return \"b %z0@plt\";
11158     }
11159   else
11160     return \"b %z0\";
11161 }"
11162   [(set_attr "type" "branch")
11163    (set_attr "length" "4,8,4,8")])
11164
11165 (define_expand "sibcall_value"
11166   [(parallel [(set (match_operand 0 "register_operand" "")
11167                 (call (mem:SI (match_operand 1 "address_operand" ""))
11168                       (match_operand 2 "" "")))
11169               (use (match_operand 3 "" ""))
11170               (use (reg:SI LR_REGNO))
11171               (simple_return)])]
11172   ""
11173   "
11174 {
11175 #if TARGET_MACHO
11176   if (MACHOPIC_INDIRECT)
11177     operands[1] = machopic_indirect_call_target (operands[1]);
11178 #endif
11179
11180   gcc_assert (GET_CODE (operands[1]) == MEM);
11181   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
11182
11183   operands[1] = XEXP (operands[1], 0);
11184 }")
11185
11186 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
11187   [(set (match_operand 0 "" "")
11188         (call (mem:SI (match_operand:P 1 "call_operand" "s,s,c,c"))
11189               (match_operand 2 "" "")))
11190    (use (match_operand:SI 3 "immediate_operand" "O,n,O,n"))
11191    (use (reg:SI LR_REGNO))
11192    (simple_return)]
11193   "(DEFAULT_ABI == ABI_DARWIN
11194     || DEFAULT_ABI == ABI_V4)
11195    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11196   "*
11197 {
11198   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11199     output_asm_insn (\"crxor 6,6,6\", operands);
11200
11201   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11202     output_asm_insn (\"creqv 6,6,6\", operands);
11203
11204   if (which_alternative >= 2)
11205     return \"b%T1\";
11206   else if (DEFAULT_ABI == ABI_V4 && flag_pic)
11207     {
11208       gcc_assert (!TARGET_SECURE_PLT);
11209       return \"b %z1@plt\";
11210     }
11211   else
11212     return \"b %z1\";
11213 }"
11214   [(set_attr "type" "branch")
11215    (set_attr "length" "4,8,4,8")])
11216
11217 (define_expand "sibcall_epilogue"
11218   [(use (const_int 0))]
11219   ""
11220 {
11221   if (!TARGET_SCHED_PROLOG)
11222     emit_insn (gen_blockage ());
11223   rs6000_emit_epilogue (TRUE);
11224   DONE;
11225 })
11226
11227 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
11228 ;; all of memory.  This blocks insns from being moved across this point.
11229
11230 (define_insn "blockage"
11231   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
11232   ""
11233   "")
11234
11235 (define_expand "probe_stack"
11236   [(set (match_operand 0 "memory_operand" "=m")
11237         (unspec [(const_int 0)] UNSPEC_PROBE_STACK))]
11238   ""
11239 {
11240   if (TARGET_64BIT)
11241     emit_insn (gen_probe_stack_di (operands[0]));
11242   else
11243     emit_insn (gen_probe_stack_si (operands[0]));
11244   DONE;
11245 })
11246
11247 (define_insn "probe_stack_<mode>"
11248   [(set (match_operand:P 0 "memory_operand" "=m")
11249         (unspec:P [(const_int 0)] UNSPEC_PROBE_STACK))]
11250   ""
11251 {
11252   operands[1] = gen_rtx_REG (Pmode, 0);
11253   return "st<wd>%U0%X0 %1,%0";
11254 }
11255   [(set_attr "type" "store")
11256    (set_attr "length" "4")])
11257
11258 (define_insn "probe_stack_range<P:mode>"
11259   [(set (match_operand:P 0 "register_operand" "=r")
11260         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
11261                             (match_operand:P 2 "register_operand" "r")]
11262                            UNSPECV_PROBE_STACK_RANGE))]
11263   ""
11264   "* return output_probe_stack_range (operands[0], operands[2]);"
11265   [(set_attr "type" "three")])
11266 \f
11267 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
11268 ;; signed & unsigned, and one type of branch.
11269 ;;
11270 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
11271 ;; insns, and branches.
11272
11273 (define_expand "cbranch<mode>4"
11274   [(use (match_operator 0 "rs6000_cbranch_operator"
11275          [(match_operand:GPR 1 "gpc_reg_operand" "")
11276           (match_operand:GPR 2 "reg_or_short_operand" "")]))
11277    (use (match_operand 3 ""))]
11278   ""
11279   "
11280 {
11281   /* Take care of the possibility that operands[2] might be negative but
11282      this might be a logical operation.  That insn doesn't exist.  */
11283   if (GET_CODE (operands[2]) == CONST_INT
11284       && INTVAL (operands[2]) < 0)
11285     {
11286       operands[2] = force_reg (<MODE>mode, operands[2]);
11287       operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]),
11288                                     GET_MODE (operands[0]),
11289                                     operands[1], operands[2]);
11290    }
11291
11292   rs6000_emit_cbranch (<MODE>mode, operands);
11293   DONE;
11294 }")
11295
11296 (define_expand "cbranch<mode>4"
11297   [(use (match_operator 0 "rs6000_cbranch_operator"
11298          [(match_operand:FP 1 "gpc_reg_operand" "")
11299           (match_operand:FP 2 "gpc_reg_operand" "")]))
11300    (use (match_operand 3 ""))]
11301   ""
11302   "
11303 {
11304   rs6000_emit_cbranch (<MODE>mode, operands);
11305   DONE;
11306 }")
11307
11308 (define_expand "cstore<mode>4"
11309   [(use (match_operator 1 "rs6000_cbranch_operator"
11310          [(match_operand:GPR 2 "gpc_reg_operand" "")
11311           (match_operand:GPR 3 "reg_or_short_operand" "")]))
11312    (clobber (match_operand:SI 0 "register_operand"))]
11313   ""
11314   "
11315 {
11316   /* Take care of the possibility that operands[3] might be negative but
11317      this might be a logical operation.  That insn doesn't exist.  */
11318   if (GET_CODE (operands[3]) == CONST_INT
11319       && INTVAL (operands[3]) < 0)
11320     {
11321       operands[3] = force_reg (<MODE>mode, operands[3]);
11322       operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]),
11323                                     GET_MODE (operands[1]),
11324                                     operands[2], operands[3]);
11325     }
11326
11327   /* For SNE, we would prefer that the xor/abs sequence be used for integers.
11328      For SEQ, likewise, except that comparisons with zero should be done
11329      with an scc insns.  However, due to the order that combine see the
11330      resulting insns, we must, in fact, allow SEQ for integers.  Fail in
11331      the cases we don't want to handle or are best handled by portable
11332      code.  */
11333   if (GET_CODE (operands[1]) == NE)
11334     FAIL;
11335   if ((GET_CODE (operands[1]) == LT || GET_CODE (operands[1]) == LE
11336        || GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GE)
11337       && operands[3] == const0_rtx)
11338     FAIL;
11339   rs6000_emit_sCOND (<MODE>mode, operands);
11340   DONE;
11341 }")
11342
11343 (define_expand "cstore<mode>4"
11344   [(use (match_operator 1 "rs6000_cbranch_operator"
11345          [(match_operand:FP 2 "gpc_reg_operand" "")
11346           (match_operand:FP 3 "gpc_reg_operand" "")]))
11347    (clobber (match_operand:SI 0 "register_operand"))]
11348   ""
11349   "
11350 {
11351   rs6000_emit_sCOND (<MODE>mode, operands);
11352   DONE;
11353 }")
11354
11355
11356 (define_expand "stack_protect_set"
11357   [(match_operand 0 "memory_operand" "")
11358    (match_operand 1 "memory_operand" "")]
11359   ""
11360 {
11361 #ifdef TARGET_THREAD_SSP_OFFSET
11362   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
11363   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
11364   operands[1] = gen_rtx_MEM (Pmode, addr);
11365 #endif
11366   if (TARGET_64BIT)
11367     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
11368   else
11369     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
11370   DONE;
11371 })
11372
11373 (define_insn "stack_protect_setsi"
11374   [(set (match_operand:SI 0 "memory_operand" "=m")
11375         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
11376    (set (match_scratch:SI 2 "=&r") (const_int 0))]
11377   "TARGET_32BIT"
11378   "lwz%U1%X1 %2,%1\;stw%U0%X0 %2,%0\;li %2,0"
11379   [(set_attr "type" "three")
11380    (set_attr "length" "12")])
11381
11382 (define_insn "stack_protect_setdi"
11383   [(set (match_operand:DI 0 "memory_operand" "=Y")
11384         (unspec:DI [(match_operand:DI 1 "memory_operand" "Y")] UNSPEC_SP_SET))
11385    (set (match_scratch:DI 2 "=&r") (const_int 0))]
11386   "TARGET_64BIT"
11387   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;li %2,0"
11388   [(set_attr "type" "three")
11389    (set_attr "length" "12")])
11390
11391 (define_expand "stack_protect_test"
11392   [(match_operand 0 "memory_operand" "")
11393    (match_operand 1 "memory_operand" "")
11394    (match_operand 2 "" "")]
11395   ""
11396 {
11397   rtx test, op0, op1;
11398 #ifdef TARGET_THREAD_SSP_OFFSET
11399   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
11400   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
11401   operands[1] = gen_rtx_MEM (Pmode, addr);
11402 #endif
11403   op0 = operands[0];
11404   op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]), UNSPEC_SP_TEST);
11405   test = gen_rtx_EQ (VOIDmode, op0, op1);
11406   emit_jump_insn (gen_cbranchsi4 (test, op0, op1, operands[2]));
11407   DONE;
11408 })
11409
11410 (define_insn "stack_protect_testsi"
11411   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
11412         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
11413                       (match_operand:SI 2 "memory_operand" "m,m")]
11414                      UNSPEC_SP_TEST))
11415    (set (match_scratch:SI 4 "=r,r") (const_int 0))
11416    (clobber (match_scratch:SI 3 "=&r,&r"))]
11417   "TARGET_32BIT"
11418   "@
11419    lwz%U1%X1 %3,%1\;lwz%U2%X2 %4,%2\;xor. %3,%3,%4\;li %4,0
11420    lwz%U1%X1 %3,%1\;lwz%U2%X2 %4,%2\;cmplw %0,%3,%4\;li %3,0\;li %4,0"
11421   [(set_attr "length" "16,20")])
11422
11423 (define_insn "stack_protect_testdi"
11424   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
11425         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "Y,Y")
11426                       (match_operand:DI 2 "memory_operand" "Y,Y")]
11427                      UNSPEC_SP_TEST))
11428    (set (match_scratch:DI 4 "=r,r") (const_int 0))
11429    (clobber (match_scratch:DI 3 "=&r,&r"))]
11430   "TARGET_64BIT"
11431   "@
11432    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;li %4,0
11433    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;li %3,0\;li %4,0"
11434   [(set_attr "length" "16,20")])
11435
11436 \f
11437 ;; Here are the actual compare insns.
11438 (define_insn "*cmp<mode>_internal1"
11439   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11440         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
11441                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
11442   ""
11443   "cmp<wd>%I2 %0,%1,%2"
11444   [(set_attr "type" "cmp")])
11445
11446 ;; If we are comparing a register for equality with a large constant,
11447 ;; we can do this with an XOR followed by a compare.  But this is profitable
11448 ;; only if the large constant is only used for the comparison (and in this
11449 ;; case we already have a register to reuse as scratch).
11450 ;;
11451 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
11452 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
11453
11454 (define_peephole2
11455   [(set (match_operand:SI 0 "register_operand")
11456         (match_operand:SI 1 "logical_const_operand" ""))
11457    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
11458                        [(match_dup 0)
11459                         (match_operand:SI 2 "logical_const_operand" "")]))
11460    (set (match_operand:CC 4 "cc_reg_operand" "")
11461         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
11462                     (match_dup 0)))
11463    (set (pc)
11464         (if_then_else (match_operator 6 "equality_operator"
11465                        [(match_dup 4) (const_int 0)])
11466                       (match_operand 7 "" "")
11467                       (match_operand 8 "" "")))]
11468   "peep2_reg_dead_p (3, operands[0])
11469    && peep2_reg_dead_p (4, operands[4])"
11470  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
11471   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
11472   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
11473  
11474 {
11475   /* Get the constant we are comparing against, and see what it looks like
11476      when sign-extended from 16 to 32 bits.  Then see what constant we could
11477      XOR with SEXTC to get the sign-extended value.  */
11478   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
11479                                               SImode,
11480                                               operands[1], operands[2]);
11481   HOST_WIDE_INT c = INTVAL (cnst);
11482   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
11483   HOST_WIDE_INT xorv = c ^ sextc;
11484
11485   operands[9] = GEN_INT (xorv);
11486   operands[10] = GEN_INT (sextc);
11487 })
11488
11489 (define_insn "*cmpsi_internal2"
11490   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11491         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11492                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
11493   ""
11494   "cmplw%I2 %0,%1,%b2"
11495   [(set_attr "type" "cmp")])
11496
11497 (define_insn "*cmpdi_internal2"
11498   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11499         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
11500                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
11501   ""
11502   "cmpld%I2 %0,%1,%b2"
11503   [(set_attr "type" "cmp")])
11504
11505 ;; The following two insns don't exist as single insns, but if we provide
11506 ;; them, we can swap an add and compare, which will enable us to overlap more
11507 ;; of the required delay between a compare and branch.  We generate code for
11508 ;; them by splitting.
11509
11510 (define_insn ""
11511   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11512         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11513                     (match_operand:SI 2 "short_cint_operand" "i")))
11514    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11515         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11516   ""
11517   "#"
11518   [(set_attr "length" "8")])
11519
11520 (define_insn ""
11521   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
11522         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11523                        (match_operand:SI 2 "u_short_cint_operand" "i")))
11524    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11525         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11526   ""
11527   "#"
11528   [(set_attr "length" "8")])
11529
11530 (define_split
11531   [(set (match_operand:CC 3 "cc_reg_operand" "")
11532         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11533                     (match_operand:SI 2 "short_cint_operand" "")))
11534    (set (match_operand:SI 0 "gpc_reg_operand" "")
11535         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11536   ""
11537   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
11538    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11539
11540 (define_split
11541   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
11542         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
11543                        (match_operand:SI 2 "u_short_cint_operand" "")))
11544    (set (match_operand:SI 0 "gpc_reg_operand" "")
11545         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11546   ""
11547   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
11548    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11549
11550 (define_insn "*cmpsf_internal1"
11551   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11552         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
11553                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
11554   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT"
11555   "fcmpu %0,%1,%2"
11556   [(set_attr "type" "fpcompare")])
11557
11558 (define_insn "*cmpdf_internal1"
11559   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11560         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "d")
11561                       (match_operand:DF 2 "gpc_reg_operand" "d")))]
11562   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
11563    && !VECTOR_UNIT_VSX_P (DFmode)"
11564   "fcmpu %0,%1,%2"
11565   [(set_attr "type" "fpcompare")])
11566
11567 ;; Only need to compare second words if first words equal
11568 (define_insn "*cmptf_internal1"
11569   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11570         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
11571                       (match_operand:TF 2 "gpc_reg_operand" "d")))]
11572   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
11573    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
11574   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
11575   [(set_attr "type" "fpcompare")
11576    (set_attr "length" "12")])
11577
11578 (define_insn_and_split "*cmptf_internal2"
11579   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11580         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "d")
11581                       (match_operand:TF 2 "gpc_reg_operand" "d")))
11582     (clobber (match_scratch:DF 3 "=d"))
11583     (clobber (match_scratch:DF 4 "=d"))
11584     (clobber (match_scratch:DF 5 "=d"))
11585     (clobber (match_scratch:DF 6 "=d"))
11586     (clobber (match_scratch:DF 7 "=d"))
11587     (clobber (match_scratch:DF 8 "=d"))
11588     (clobber (match_scratch:DF 9 "=d"))
11589     (clobber (match_scratch:DF 10 "=d"))
11590     (clobber (match_scratch:GPR 11 "=b"))]
11591   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
11592    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT && TARGET_LONG_DOUBLE_128"
11593   "#"
11594   "&& reload_completed"
11595   [(set (match_dup 3) (match_dup 14))
11596    (set (match_dup 4) (match_dup 15))
11597    (set (match_dup 9) (abs:DF (match_dup 5)))
11598    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
11599    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
11600                            (label_ref (match_dup 12))
11601                            (pc)))
11602    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
11603    (set (pc) (label_ref (match_dup 13)))
11604    (match_dup 12)
11605    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
11606    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
11607    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
11608    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 4)))
11609    (match_dup 13)]
11610 {
11611   REAL_VALUE_TYPE rv;
11612   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
11613   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
11614
11615   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
11616   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
11617   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
11618   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
11619   operands[12] = gen_label_rtx ();
11620   operands[13] = gen_label_rtx ();
11621   real_inf (&rv);
11622   operands[14] = force_const_mem (DFmode,
11623                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
11624   operands[15] = force_const_mem (DFmode,
11625                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
11626                                                                 DFmode));
11627   if (TARGET_TOC)
11628     {
11629       rtx tocref;
11630       tocref = create_TOC_reference (XEXP (operands[14], 0), operands[11]);
11631       operands[14] = gen_const_mem (DFmode, tocref);
11632       tocref = create_TOC_reference (XEXP (operands[15], 0), operands[11]);
11633       operands[15] = gen_const_mem (DFmode, tocref);
11634       set_mem_alias_set (operands[14], get_TOC_alias_set ());
11635       set_mem_alias_set (operands[15], get_TOC_alias_set ());
11636     }
11637 })
11638 \f
11639 ;; Now we have the scc insns.  We can do some combinations because of the
11640 ;; way the machine works.
11641 ;;
11642 ;; Note that this is probably faster if we can put an insn between the
11643 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
11644 ;; cases the insns below which don't use an intermediate CR field will
11645 ;; be used instead.
11646 (define_insn ""
11647   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11648         (match_operator:SI 1 "scc_comparison_operator"
11649                            [(match_operand 2 "cc_reg_operand" "y")
11650                             (const_int 0)]))]
11651   ""
11652   "mfcr %0%Q2\;rlwinm %0,%0,%J1,1"
11653   [(set (attr "type")
11654      (cond [(match_test "TARGET_MFCRF")
11655                 (const_string "mfcrf")
11656            ]
11657         (const_string "mfcr")))
11658    (set_attr "length" "8")])
11659
11660 ;; Same as above, but get the GT bit.
11661 (define_insn "move_from_CR_gt_bit"
11662   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11663         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
11664   "TARGET_HARD_FLOAT && !TARGET_FPRS"
11665   "mfcr %0\;rlwinm %0,%0,%D1,31,31"
11666   [(set_attr "type" "mfcr")
11667    (set_attr "length" "8")])
11668
11669 ;; Same as above, but get the OV/ORDERED bit.
11670 (define_insn "move_from_CR_ov_bit"
11671   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11672         (unspec:SI [(match_operand:CC 1 "cc_reg_operand" "y")]
11673                    UNSPEC_MV_CR_OV))]
11674   "TARGET_ISEL"
11675   "mfcr %0\;rlwinm %0,%0,%t1,1"
11676   [(set_attr "type" "mfcr")
11677    (set_attr "length" "8")])
11678
11679 (define_insn ""
11680   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11681         (match_operator:DI 1 "scc_comparison_operator"
11682                            [(match_operand 2 "cc_reg_operand" "y")
11683                             (const_int 0)]))]
11684   "TARGET_POWERPC64"
11685   "mfcr %0%Q2\;rlwinm %0,%0,%J1,1"
11686   [(set (attr "type")
11687      (cond [(match_test "TARGET_MFCRF")
11688                 (const_string "mfcrf")
11689            ]
11690         (const_string "mfcr")))
11691    (set_attr "length" "8")])
11692
11693 (define_insn ""
11694   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11695         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11696                                        [(match_operand 2 "cc_reg_operand" "y,y")
11697                                         (const_int 0)])
11698                     (const_int 0)))
11699    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11700         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11701   "TARGET_32BIT"
11702   "@
11703    mfcr %3%Q2\;rlwinm. %3,%3,%J1,1
11704    #"
11705   [(set_attr "type" "delayed_compare")
11706    (set_attr "length" "8,16")])
11707
11708 (define_split
11709   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11710         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11711                                        [(match_operand 2 "cc_reg_operand" "")
11712                                         (const_int 0)])
11713                     (const_int 0)))
11714    (set (match_operand:SI 3 "gpc_reg_operand" "")
11715         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11716   "TARGET_32BIT && reload_completed"
11717   [(set (match_dup 3)
11718         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
11719    (set (match_dup 0)
11720         (compare:CC (match_dup 3)
11721                     (const_int 0)))]
11722   "")
11723
11724 (define_insn ""
11725   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11726         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11727                                       [(match_operand 2 "cc_reg_operand" "y")
11728                                        (const_int 0)])
11729                    (match_operand:SI 3 "const_int_operand" "n")))]
11730   ""
11731   "*
11732 {
11733   int is_bit = ccr_bit (operands[1], 1);
11734   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11735   int count;
11736
11737   if (is_bit >= put_bit)
11738     count = is_bit - put_bit;
11739   else
11740     count = 32 - (put_bit - is_bit);
11741
11742   operands[4] = GEN_INT (count);
11743   operands[5] = GEN_INT (put_bit);
11744
11745   return \"mfcr %0%Q2\;rlwinm %0,%0,%4,%5,%5\";
11746 }"
11747   [(set (attr "type")
11748      (cond [(match_test "TARGET_MFCRF")
11749                 (const_string "mfcrf")
11750            ]
11751         (const_string "mfcr")))
11752    (set_attr "length" "8")])
11753
11754 (define_insn ""
11755   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11756         (compare:CC
11757          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11758                                        [(match_operand 2 "cc_reg_operand" "y,y")
11759                                         (const_int 0)])
11760                     (match_operand:SI 3 "const_int_operand" "n,n"))
11761          (const_int 0)))
11762    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
11763         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11764                    (match_dup 3)))]
11765   ""
11766   "*
11767 {
11768   int is_bit = ccr_bit (operands[1], 1);
11769   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11770   int count;
11771
11772   /* Force split for non-cc0 compare.  */
11773   if (which_alternative == 1)
11774      return \"#\";
11775
11776   if (is_bit >= put_bit)
11777     count = is_bit - put_bit;
11778   else
11779     count = 32 - (put_bit - is_bit);
11780
11781   operands[5] = GEN_INT (count);
11782   operands[6] = GEN_INT (put_bit);
11783
11784   return \"mfcr %4%Q2\;rlwinm. %4,%4,%5,%6,%6\";
11785 }"
11786   [(set_attr "type" "delayed_compare")
11787    (set_attr "length" "8,16")])
11788
11789 (define_split
11790   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
11791         (compare:CC
11792          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11793                                        [(match_operand 2 "cc_reg_operand" "")
11794                                         (const_int 0)])
11795                     (match_operand:SI 3 "const_int_operand" ""))
11796          (const_int 0)))
11797    (set (match_operand:SI 4 "gpc_reg_operand" "")
11798         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11799                    (match_dup 3)))]
11800   "reload_completed"
11801   [(set (match_dup 4)
11802         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11803                    (match_dup 3)))
11804    (set (match_dup 0)
11805         (compare:CC (match_dup 4)
11806                     (const_int 0)))]
11807   "")
11808
11809 ;; There is a 3 cycle delay between consecutive mfcr instructions
11810 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
11811
11812 (define_peephole
11813   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11814         (match_operator:SI 1 "scc_comparison_operator"
11815                            [(match_operand 2 "cc_reg_operand" "y")
11816                             (const_int 0)]))
11817    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
11818         (match_operator:SI 4 "scc_comparison_operator"
11819                            [(match_operand 5 "cc_reg_operand" "y")
11820                             (const_int 0)]))]
11821   "REGNO (operands[2]) != REGNO (operands[5])"
11822   "mfcr %3\;rlwinm %0,%3,%J1,1\;rlwinm %3,%3,%J4,1"
11823   [(set_attr "type" "mfcr")
11824    (set_attr "length" "12")])
11825
11826 (define_peephole
11827   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11828         (match_operator:DI 1 "scc_comparison_operator"
11829                            [(match_operand 2 "cc_reg_operand" "y")
11830                             (const_int 0)]))
11831    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
11832         (match_operator:DI 4 "scc_comparison_operator"
11833                            [(match_operand 5 "cc_reg_operand" "y")
11834                             (const_int 0)]))]
11835   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
11836   "mfcr %3\;rlwinm %0,%3,%J1,1\;rlwinm %3,%3,%J4,1"
11837   [(set_attr "type" "mfcr")
11838    (set_attr "length" "12")])
11839
11840 ;; There are some scc insns that can be done directly, without a compare.
11841 ;; These are faster because they don't involve the communications between
11842 ;; the FXU and branch units.   In fact, we will be replacing all of the
11843 ;; integer scc insns here or in the portable methods in emit_store_flag.
11844 ;;
11845 ;; Also support (neg (scc ..)) since that construct is used to replace
11846 ;; branches, (plus (scc ..) ..) since that construct is common and
11847 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
11848 ;; cases where it is no more expensive than (neg (scc ..)).
11849
11850 ;; Have reload force a constant into a register for the simple insns that
11851 ;; otherwise won't accept constants.  We do this because it is faster than
11852 ;; the cmp/mfcr sequence we would otherwise generate.
11853
11854 (define_mode_attr scc_eq_op2 [(SI "rKLI")
11855                               (DI "rKJI")])
11856
11857 (define_insn_and_split "*eq<mode>"
11858   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
11859         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
11860                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
11861   ""
11862   "#"
11863   ""
11864   [(set (match_dup 0)
11865         (clz:GPR (match_dup 3)))
11866    (set (match_dup 0)
11867         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
11868   {
11869     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
11870       {
11871         /* Use output operand as intermediate.  */
11872         operands[3] = operands[0];
11873
11874         if (logical_operand (operands[2], <MODE>mode))
11875           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
11876                                   gen_rtx_XOR (<MODE>mode,
11877                                                operands[1], operands[2])));
11878         else
11879           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
11880                                   gen_rtx_PLUS (<MODE>mode, operands[1],
11881                                                 negate_rtx (<MODE>mode,
11882                                                             operands[2]))));
11883       }
11884     else
11885       operands[3] = operands[1];
11886
11887     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
11888   })
11889
11890 (define_insn_and_split "*eq<mode>_compare"
11891   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11892         (compare:CC
11893          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
11894                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
11895          (const_int 0)))
11896    (set (match_operand:P 0 "gpc_reg_operand" "=r")
11897         (eq:P (match_dup 1) (match_dup 2)))]
11898   "optimize_size"
11899   "#"
11900   "optimize_size"
11901   [(set (match_dup 0)
11902         (clz:P (match_dup 4)))
11903    (parallel [(set (match_dup 3)
11904                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
11905                                (const_int 0)))
11906               (set (match_dup 0)
11907                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
11908   {
11909     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
11910       {
11911         /* Use output operand as intermediate.  */
11912         operands[4] = operands[0];
11913
11914         if (logical_operand (operands[2], <MODE>mode))
11915           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
11916                                   gen_rtx_XOR (<MODE>mode,
11917                                                operands[1], operands[2])));
11918         else
11919           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
11920                                   gen_rtx_PLUS (<MODE>mode, operands[1],
11921                                                 negate_rtx (<MODE>mode,
11922                                                             operands[2]))));
11923       }
11924     else
11925       operands[4] = operands[1];
11926
11927     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
11928   })
11929
11930 ;; We have insns of the form shown by the first define_insn below.  If
11931 ;; there is something inside the comparison operation, we must split it.
11932 (define_split
11933   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11934         (plus:SI (match_operator 1 "comparison_operator"
11935                                  [(match_operand:SI 2 "" "")
11936                                   (match_operand:SI 3
11937                                                     "reg_or_cint_operand" "")])
11938                  (match_operand:SI 4 "gpc_reg_operand" "")))
11939    (clobber (match_operand:SI 5 "register_operand" ""))]
11940   "! gpc_reg_operand (operands[2], SImode)"
11941   [(set (match_dup 5) (match_dup 2))
11942    (set (match_dup 0) (plus:SI (match_op_dup 1 [(match_dup 5) (match_dup 3)])
11943                                (match_dup 4)))])
11944
11945 (define_insn "*plus_eqsi"
11946   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
11947         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11948                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
11949                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
11950   "TARGET_32BIT"
11951   "@
11952    xor %0,%1,%2\;subfic %0,%0,0\;addze %0,%3
11953    subfic %0,%1,0\;addze %0,%3
11954    xori %0,%1,%b2\;subfic %0,%0,0\;addze %0,%3
11955    xoris %0,%1,%u2\;subfic %0,%0,0\;addze %0,%3
11956    subfic %0,%1,%2\;subfic %0,%0,0\;addze %0,%3"
11957   [(set_attr "type" "three,two,three,three,three")
11958    (set_attr "length" "12,8,12,12,12")])
11959
11960 (define_insn "*compare_plus_eqsi"
11961   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11962         (compare:CC
11963          (plus:SI
11964           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11965                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
11966           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11967          (const_int 0)))
11968    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
11969   "TARGET_32BIT && optimize_size"
11970   "@
11971    xor %4,%1,%2\;subfic %4,%4,0\;addze. %4,%3
11972    subfic %4,%1,0\;addze. %4,%3
11973    xori %4,%1,%b2\;subfic %4,%4,0\;addze. %4,%3
11974    xoris %4,%1,%u2\;subfic %4,%4,0\;addze. %4,%3
11975    subfic %4,%1,%2\;subfic %4,%4,0\;addze. %4,%3
11976    #
11977    #
11978    #
11979    #
11980    #"
11981   [(set_attr "type" "compare")
11982    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11983
11984 (define_split
11985   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11986         (compare:CC
11987          (plus:SI
11988           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11989                  (match_operand:SI 2 "scc_eq_operand" ""))
11990           (match_operand:SI 3 "gpc_reg_operand" ""))
11991          (const_int 0)))
11992    (clobber (match_scratch:SI 4 ""))]
11993   "TARGET_32BIT && optimize_size && reload_completed"
11994   [(set (match_dup 4)
11995         (plus:SI (eq:SI (match_dup 1)
11996                  (match_dup 2))
11997           (match_dup 3)))
11998    (set (match_dup 0)
11999         (compare:CC (match_dup 4)
12000                     (const_int 0)))]
12001   "")
12002
12003 (define_insn "*plus_eqsi_compare"
12004   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
12005         (compare:CC
12006          (plus:SI
12007           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
12008                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
12009           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
12010          (const_int 0)))
12011    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
12012         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12013   "TARGET_32BIT && optimize_size"
12014   "@
12015    xor %0,%1,%2\;subfic %0,%0,0\;addze. %0,%3
12016    subfic %0,%1,0\;addze. %0,%3
12017    xori %0,%1,%b2\;subfic %0,%0,0\;addze. %0,%3
12018    xoris %0,%1,%u2\;subfic %0,%0,0\;addze. %0,%3
12019    subfic %0,%1,%2\;subfic %0,%0,0\;addze. %0,%3
12020    #
12021    #
12022    #
12023    #
12024    #"
12025   [(set_attr "type" "compare")
12026    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
12027
12028 (define_split
12029   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12030         (compare:CC
12031          (plus:SI
12032           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
12033                  (match_operand:SI 2 "scc_eq_operand" ""))
12034           (match_operand:SI 3 "gpc_reg_operand" ""))
12035          (const_int 0)))
12036    (set (match_operand:SI 0 "gpc_reg_operand" "")
12037         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12038   "TARGET_32BIT && optimize_size && reload_completed"
12039   [(set (match_dup 0)
12040         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12041    (set (match_dup 4)
12042         (compare:CC (match_dup 0)
12043                     (const_int 0)))]
12044   "")
12045
12046 (define_insn "*neg_eq0<mode>"
12047   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12048         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
12049                      (const_int 0))))]
12050   ""
12051   "addic %0,%1,-1\;subfe %0,%0,%0"
12052   [(set_attr "type" "two")
12053    (set_attr "length" "8")])
12054
12055 (define_insn_and_split "*neg_eq<mode>"
12056   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12057         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
12058                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
12059   ""
12060   "#"
12061   ""
12062   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
12063   {
12064     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
12065       {
12066         /* Use output operand as intermediate.  */
12067         operands[3] = operands[0];
12068
12069         if (logical_operand (operands[2], <MODE>mode))
12070           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12071                                   gen_rtx_XOR (<MODE>mode,
12072                                                operands[1], operands[2])));
12073         else
12074           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12075                                   gen_rtx_PLUS (<MODE>mode, operands[1],
12076                                                 negate_rtx (<MODE>mode,
12077                                                             operands[2]))));
12078       }
12079     else
12080       operands[3] = operands[1];
12081   })
12082
12083 (define_insn "*ne0_<mode>"
12084   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12085         (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
12086               (const_int 0)))
12087    (clobber (match_scratch:P 2 "=&r"))]
12088   "!(TARGET_32BIT && TARGET_ISEL)"
12089   "addic %2,%1,-1\;subfe %0,%2,%1"
12090   [(set_attr "type" "two")
12091    (set_attr "length" "8")])
12092
12093 (define_insn "*plus_ne0_<mode>"
12094   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12095         (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
12096                       (const_int 0))
12097                 (match_operand:P 2 "gpc_reg_operand" "r")))
12098    (clobber (match_scratch:P 3 "=&r"))]
12099   ""
12100   "addic %3,%1,-1\;addze %0,%2"
12101   [(set_attr "type" "two")
12102    (set_attr "length" "8")])
12103
12104 (define_insn "*compare_plus_ne0_<mode>"
12105   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12106         (compare:CC (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12107                                   (const_int 0))
12108                             (match_operand:P 2 "gpc_reg_operand" "r,r"))
12109                     (const_int 0)))
12110    (clobber (match_scratch:P 3 "=&r,&r"))
12111    (clobber (match_scratch:P 4 "=X,&r"))]
12112   ""
12113   "@
12114    addic %3,%1,-1\;addze. %3,%2
12115    #"
12116   [(set_attr "type" "compare")
12117    (set_attr "length" "8,12")])
12118
12119 (define_split
12120   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
12121         (compare:CC (ne:P (match_operand:SI 1 "gpc_reg_operand" "")
12122                           (const_int 0))
12123                     (neg:P (match_operand:P 2 "gpc_reg_operand" ""))))
12124    (clobber (match_scratch:P 3 ""))
12125    (clobber (match_scratch:P 4 ""))]
12126   "reload_completed"
12127   [(parallel [(set (match_dup 3)
12128                    (plus:P (ne:P (match_dup 1)
12129                                  (const_int 0))
12130                            (match_dup 2)))
12131               (clobber (match_dup 4))])
12132    (set (match_dup 0)
12133         (compare:CC (match_dup 3)
12134                     (const_int 0)))]
12135   "")
12136
12137 ; For combine.
12138 (define_insn "*compare_plus_ne0_<mode>_1"
12139   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12140         (compare:CCEQ (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12141                             (const_int 0))
12142                       (neg:P (match_operand:P 2 "gpc_reg_operand" "r,r"))))
12143    (clobber (match_scratch:P 3 "=&r,&r"))
12144    (clobber (match_scratch:P 4 "=X,&r"))]
12145   ""
12146   "@
12147    addic %3,%1,-1\;addze. %3,%2
12148    #"
12149   [(set_attr "type" "compare")
12150    (set_attr "length" "8,12")])
12151
12152 (define_split
12153   [(set (match_operand:CCEQ 0 "cc_reg_not_micro_cr0_operand" "")
12154         (compare:CCEQ (ne:P (match_operand:SI 1 "gpc_reg_operand" "")
12155                             (const_int 0))
12156                       (neg:P (match_operand:P 2 "gpc_reg_operand" ""))))
12157    (clobber (match_scratch:P 3 ""))
12158    (clobber (match_scratch:P 4 ""))]
12159   "reload_completed"
12160   [(parallel [(set (match_dup 3)
12161                    (plus:P (ne:P (match_dup 1)
12162                                  (const_int 0))
12163                            (match_dup 2)))
12164               (clobber (match_dup 4))])
12165    (set (match_dup 0)
12166         (compare:CC (match_dup 3)
12167                     (const_int 0)))]
12168   "")
12169
12170 (define_insn "*plus_ne0_<mode>_compare"
12171   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12172         (compare:CC
12173          (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12174                        (const_int 0))
12175                  (match_operand:P 2 "gpc_reg_operand" "r,r"))
12176          (const_int 0)))
12177    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12178         (plus:P (ne:P (match_dup 1)
12179                       (const_int 0))
12180                 (match_dup 2)))
12181    (clobber (match_scratch:P 3 "=&r,&r"))]
12182   ""
12183   "@
12184    addic %3,%1,-1\;addze. %0,%2
12185    #"
12186   [(set_attr "type" "compare")
12187    (set_attr "length" "8,12")])
12188
12189 (define_split
12190   [(set (match_operand:CC 4 "cc_reg_not_micro_cr0_operand" "")
12191         (compare:CC
12192          (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "")
12193                        (const_int 0))
12194                  (match_operand:P 2 "gpc_reg_operand" ""))
12195          (const_int 0)))
12196    (set (match_operand:P 0 "gpc_reg_operand" "")
12197         (plus:P (ne:P (match_dup 1)
12198                       (const_int 0))
12199                 (match_dup 2)))
12200    (clobber (match_scratch:P 3 ""))]
12201   "reload_completed"
12202   [(parallel [(set (match_dup 0)
12203                    (plus:P (ne:P (match_dup 1)
12204                                  (const_int 0))
12205                            (match_dup 2)))
12206               (clobber (match_dup 3))])
12207    (set (match_dup 4)
12208         (compare:CC (match_dup 0)
12209                     (const_int 0)))]
12210   "")
12211
12212 (define_insn "*leu<mode>"
12213   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12214         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12215                (match_operand:P 2 "reg_or_short_operand" "rI")))]
12216   ""
12217   "subf%I2c %0,%1,%2\;li %0,0\;adde %0,%0,%0"
12218   [(set_attr "type" "three")
12219    (set_attr "length" "12")])
12220
12221 (define_insn "*leu<mode>_compare"
12222   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12223         (compare:CC
12224          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12225                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
12226          (const_int 0)))
12227    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12228         (leu:P (match_dup 1) (match_dup 2)))]
12229   ""
12230   "@
12231    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
12232    #"
12233   [(set_attr "type" "compare")
12234    (set_attr "length" "12,16")])
12235
12236 (define_split
12237   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12238         (compare:CC
12239          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
12240                 (match_operand:P 2 "reg_or_short_operand" ""))
12241          (const_int 0)))
12242    (set (match_operand:P 0 "gpc_reg_operand" "")
12243         (leu:P (match_dup 1) (match_dup 2)))]
12244   "reload_completed"
12245   [(set (match_dup 0)
12246         (leu:P (match_dup 1) (match_dup 2)))
12247    (set (match_dup 3)
12248         (compare:CC (match_dup 0)
12249                     (const_int 0)))]
12250   "")
12251
12252 (define_insn "*plus_leu<mode>"
12253   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12254         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12255                        (match_operand:P 2 "reg_or_short_operand" "rI"))
12256                 (match_operand:P 3 "gpc_reg_operand" "r")))]
12257   ""
12258   "subf%I2c %0,%1,%2\;addze %0,%3"
12259   [(set_attr "type" "two")
12260    (set_attr "length" "8")])
12261
12262 (define_insn ""
12263   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12264         (compare:CC
12265          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12266                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12267                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12268          (const_int 0)))
12269    (clobber (match_scratch:SI 4 "=&r,&r"))]
12270   "TARGET_32BIT"
12271   "@
12272    subf%I2c %4,%1,%2\;addze. %4,%3
12273    #"
12274   [(set_attr "type" "compare")
12275    (set_attr "length" "8,12")])
12276
12277 (define_split
12278   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12279         (compare:CC
12280          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12281                           (match_operand:SI 2 "reg_or_short_operand" ""))
12282                   (match_operand:SI 3 "gpc_reg_operand" ""))
12283          (const_int 0)))
12284    (clobber (match_scratch:SI 4 ""))]
12285   "TARGET_32BIT && reload_completed"
12286   [(set (match_dup 4)
12287         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12288                   (match_dup 3)))
12289    (set (match_dup 0)
12290         (compare:CC (match_dup 4)
12291                     (const_int 0)))]
12292   "")
12293
12294 (define_insn ""
12295   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12296         (compare:CC
12297          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12298                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12299                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12300          (const_int 0)))
12301    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12302         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12303   "TARGET_32BIT"
12304   "@
12305    subf%I2c %0,%1,%2\;addze. %0,%3
12306    #"
12307   [(set_attr "type" "compare")
12308    (set_attr "length" "8,12")])
12309
12310 (define_split
12311   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12312         (compare:CC
12313          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12314                           (match_operand:SI 2 "reg_or_short_operand" ""))
12315                   (match_operand:SI 3 "gpc_reg_operand" ""))
12316          (const_int 0)))
12317    (set (match_operand:SI 0 "gpc_reg_operand" "")
12318         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12319   "TARGET_32BIT && reload_completed"
12320   [(set (match_dup 0)
12321         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12322    (set (match_dup 4)
12323         (compare:CC (match_dup 0)
12324                     (const_int 0)))]
12325   "")
12326
12327 (define_insn "*neg_leu<mode>"
12328   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12329         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12330                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
12331   ""
12332   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;nand %0,%0,%0"
12333    [(set_attr "type" "three")
12334     (set_attr "length" "12")])
12335
12336 (define_insn "*and_neg_leu<mode>"
12337   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12338         (and:P (neg:P
12339                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12340                         (match_operand:P 2 "reg_or_short_operand" "rI")))
12341                 (match_operand:P 3 "gpc_reg_operand" "r")))]
12342   ""
12343   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;andc %0,%3,%0"
12344   [(set_attr "type" "three")
12345    (set_attr "length" "12")])
12346
12347 (define_insn ""
12348   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12349         (compare:CC
12350          (and:SI (neg:SI
12351                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12352                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12353                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12354          (const_int 0)))
12355    (clobber (match_scratch:SI 4 "=&r,&r"))]
12356   "TARGET_32BIT"
12357   "@
12358    subf%I2c %4,%1,%2\;subfe %4,%4,%4\;andc. %4,%3,%4
12359    #"
12360   [(set_attr "type" "compare")
12361    (set_attr "length" "12,16")])
12362
12363 (define_split
12364   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12365         (compare:CC
12366          (and:SI (neg:SI
12367                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12368                           (match_operand:SI 2 "reg_or_short_operand" "")))
12369                  (match_operand:SI 3 "gpc_reg_operand" ""))
12370          (const_int 0)))
12371    (clobber (match_scratch:SI 4 ""))]
12372   "TARGET_32BIT && reload_completed"
12373   [(set (match_dup 4)
12374         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12375                 (match_dup 3)))
12376    (set (match_dup 0)
12377         (compare:CC (match_dup 4)
12378                     (const_int 0)))]
12379   "")
12380
12381 (define_insn ""
12382   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12383         (compare:CC
12384          (and:SI (neg:SI
12385                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12386                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12387                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12388          (const_int 0)))
12389    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12390         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12391   "TARGET_32BIT"
12392   "@
12393    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;andc. %0,%3,%0
12394    #"
12395   [(set_attr "type" "compare")
12396    (set_attr "length" "12,16")])
12397
12398 (define_split
12399   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12400         (compare:CC
12401          (and:SI (neg:SI
12402                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12403                           (match_operand:SI 2 "reg_or_short_operand" "")))
12404                  (match_operand:SI 3 "gpc_reg_operand" ""))
12405          (const_int 0)))
12406    (set (match_operand:SI 0 "gpc_reg_operand" "")
12407         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12408   "TARGET_32BIT && reload_completed"
12409   [(set (match_dup 0)
12410         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12411                 (match_dup 3)))
12412    (set (match_dup 4)
12413         (compare:CC (match_dup 0)
12414                     (const_int 0)))]
12415   "")
12416
12417 (define_insn_and_split "*ltu<mode>"
12418   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12419         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12420                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
12421   ""
12422   "#"
12423   ""
12424   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12425    (set (match_dup 0) (neg:P (match_dup 0)))]
12426   "")
12427
12428 (define_insn_and_split "*ltu<mode>_compare"
12429   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12430         (compare:CC
12431          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12432                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
12433          (const_int 0)))
12434    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
12435         (ltu:P (match_dup 1) (match_dup 2)))]
12436   ""
12437   "#"
12438   ""
12439   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12440    (parallel [(set (match_dup 3)
12441                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
12442               (set (match_dup 0) (neg:P (match_dup 0)))])]
12443   "")
12444
12445 (define_insn_and_split "*plus_ltu<mode>"
12446   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
12447         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12448                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
12449                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
12450   ""
12451   "#"
12452   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12453   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12454    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
12455   "")
12456
12457 (define_insn_and_split "*plus_ltu<mode>_compare"
12458   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12459         (compare:CC
12460          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12461                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
12462                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
12463          (const_int 0)))
12464    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12465         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
12466   ""
12467   "#"
12468   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12469   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12470    (parallel [(set (match_dup 4)
12471                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
12472                                (const_int 0)))
12473               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
12474   "")
12475
12476 (define_insn "*neg_ltu<mode>"
12477   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12478         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12479                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
12480   ""
12481   "@
12482    subfc %0,%2,%1\;subfe %0,%0,%0
12483    addic %0,%1,%n2\;subfe %0,%0,%0"
12484   [(set_attr "type" "two")
12485    (set_attr "length" "8")])
12486
12487 (define_insn "*geu<mode>"
12488   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12489         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12490                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
12491   ""
12492   "@
12493    subfc %0,%2,%1\;li %0,0\;adde %0,%0,%0
12494    addic %0,%1,%n2\;li %0,0\;adde %0,%0,%0"
12495   [(set_attr "type" "three")
12496    (set_attr "length" "12")])
12497
12498 (define_insn "*geu<mode>_compare"
12499   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12500         (compare:CC
12501          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12502                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
12503          (const_int 0)))
12504    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
12505         (geu:P (match_dup 1) (match_dup 2)))]
12506   ""
12507   "@
12508    subfc %0,%2,%1\;li %0,0\;adde. %0,%0,%0
12509    addic %0,%1,%n2\;li %0,0\;adde. %0,%0,%0
12510    #
12511    #"
12512   [(set_attr "type" "compare")
12513    (set_attr "length" "12,12,16,16")])
12514
12515 (define_split
12516   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
12517         (compare:CC
12518          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
12519                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
12520          (const_int 0)))
12521    (set (match_operand:P 0 "gpc_reg_operand" "")
12522         (geu:P (match_dup 1) (match_dup 2)))]
12523   "reload_completed"
12524   [(set (match_dup 0)
12525         (geu:P (match_dup 1) (match_dup 2)))
12526    (set (match_dup 3)
12527         (compare:CC (match_dup 0)
12528                     (const_int 0)))]
12529   "")
12530
12531 (define_insn "*plus_geu<mode>"
12532   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
12533         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12534                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
12535                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
12536   ""
12537   "@
12538    subfc %0,%2,%1\;addze %0,%3
12539    addic %0,%1,%n2\;addze %0,%3"
12540   [(set_attr "type" "two")
12541    (set_attr "length" "8")])
12542
12543 (define_insn ""
12544   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12545         (compare:CC
12546          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12547                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12548                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12549          (const_int 0)))
12550    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12551   "TARGET_32BIT"
12552   "@
12553    subfc %4,%2,%1\;addze. %4,%3
12554    addic %4,%1,%n2\;addze. %4,%3
12555    #
12556    #"
12557   [(set_attr "type" "compare")
12558    (set_attr "length" "8,8,12,12")])
12559
12560 (define_split
12561   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12562         (compare:CC
12563          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12564                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12565                   (match_operand:SI 3 "gpc_reg_operand" ""))
12566          (const_int 0)))
12567    (clobber (match_scratch:SI 4 ""))]
12568   "TARGET_32BIT && reload_completed"
12569   [(set (match_dup 4)
12570         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
12571                   (match_dup 3)))
12572    (set (match_dup 0)
12573         (compare:CC (match_dup 4)
12574                     (const_int 0)))]
12575   "")
12576
12577 (define_insn ""
12578   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12579         (compare:CC
12580          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12581                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12582                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12583          (const_int 0)))
12584    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12585         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12586   "TARGET_32BIT"
12587   "@
12588    subfc %0,%2,%1\;addze. %0,%3
12589    addic %0,%1,%n2\;addze. %0,%3
12590    #
12591    #"
12592   [(set_attr "type" "compare")
12593    (set_attr "length" "8,8,12,12")])
12594
12595 (define_split
12596   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12597         (compare:CC
12598          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12599                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12600                   (match_operand:SI 3 "gpc_reg_operand" ""))
12601          (const_int 0)))
12602    (set (match_operand:SI 0 "gpc_reg_operand" "")
12603         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12604   "TARGET_32BIT && reload_completed"
12605   [(set (match_dup 0)
12606         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12607    (set (match_dup 4)
12608         (compare:CC (match_dup 0)
12609                     (const_int 0)))]
12610   "")
12611
12612 (define_insn "*neg_geu<mode>"
12613   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12614         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12615                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
12616   ""
12617   "@
12618    subfc %0,%2,%1\;subfe %0,%0,%0\;nand %0,%0,%0
12619    subfic %0,%1,-1\;add%I2c %0,%0,%2\;subfe %0,%0,%0"
12620   [(set_attr "type" "three")
12621    (set_attr "length" "12")])
12622
12623 (define_insn "*and_neg_geu<mode>"
12624   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
12625         (and:P (neg:P
12626                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12627                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
12628                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
12629   ""
12630   "@
12631    subfc %0,%2,%1\;subfe %0,%0,%0\;andc %0,%3,%0
12632    addic %0,%1,%n2\;subfe %0,%0,%0\;andc %0,%3,%0"
12633   [(set_attr "type" "three")
12634    (set_attr "length" "12")])
12635
12636 (define_insn ""
12637   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12638         (compare:CC
12639          (and:SI (neg:SI
12640                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12641                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12642                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12643          (const_int 0)))
12644    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12645   "TARGET_32BIT"
12646   "@
12647    subfc %4,%2,%1\;subfe %4,%4,%4\;andc. %4,%3,%4
12648    addic %4,%1,%n2\;subfe %4,%4,%4\;andc. %4,%3,%4
12649    #
12650    #"
12651   [(set_attr "type" "compare")
12652    (set_attr "length" "12,12,16,16")])
12653
12654 (define_split
12655   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12656         (compare:CC
12657          (and:SI (neg:SI
12658                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12659                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12660                  (match_operand:SI 3 "gpc_reg_operand" ""))
12661          (const_int 0)))
12662    (clobber (match_scratch:SI 4 ""))]
12663   "TARGET_32BIT && reload_completed"
12664   [(set (match_dup 4)
12665         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
12666                 (match_dup 3)))
12667    (set (match_dup 0)
12668         (compare:CC (match_dup 4)
12669                     (const_int 0)))]
12670   "")
12671
12672 (define_insn ""
12673   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12674         (compare:CC
12675          (and:SI (neg:SI
12676                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12677                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12678                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12679          (const_int 0)))
12680    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12681         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12682   "TARGET_32BIT"
12683   "@
12684    subfc %0,%2,%1\;subfe %0,%0,%0\;andc. %0,%3,%0
12685    addic %0,%1,%n2\;subfe %0,%0,%0\;andc. %0,%3,%0
12686    #
12687    #"
12688   [(set_attr "type" "compare")
12689    (set_attr "length" "12,12,16,16")])
12690
12691 (define_split
12692   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12693         (compare:CC
12694          (and:SI (neg:SI
12695                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12696                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12697                  (match_operand:SI 3 "gpc_reg_operand" ""))
12698          (const_int 0)))
12699    (set (match_operand:SI 0 "gpc_reg_operand" "")
12700         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12701   "TARGET_32BIT && reload_completed"
12702   [(set (match_dup 0)
12703         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
12704    (set (match_dup 4)
12705         (compare:CC (match_dup 0)
12706                     (const_int 0)))]
12707   "")
12708
12709 (define_insn "*plus_gt0<mode>"
12710   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12711         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
12712                       (const_int 0))
12713                  (match_operand:P 2 "gpc_reg_operand" "r")))]
12714   ""
12715   "addc %0,%1,%1\;subfe %0,%1,%0\;addze %0,%2"
12716   [(set_attr "type" "three")
12717    (set_attr "length" "12")])
12718
12719 (define_insn ""
12720   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12721         (compare:CC
12722          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12723                          (const_int 0))
12724                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
12725          (const_int 0)))
12726    (clobber (match_scratch:SI 3 "=&r,&r"))]
12727   "TARGET_32BIT"
12728   "@
12729    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
12730    #"
12731   [(set_attr "type" "compare")
12732    (set_attr "length" "12,16")])
12733
12734 (define_split
12735   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12736         (compare:CC
12737          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12738                          (const_int 0))
12739                   (match_operand:SI 2 "gpc_reg_operand" ""))
12740          (const_int 0)))
12741    (clobber (match_scratch:SI 3 ""))]
12742   "TARGET_32BIT && reload_completed"
12743   [(set (match_dup 3)
12744         (plus:SI (gt:SI (match_dup 1) (const_int 0))
12745                   (match_dup 2)))
12746    (set (match_dup 0)
12747         (compare:CC (match_dup 3)
12748                     (const_int 0)))]
12749   "")
12750
12751 (define_insn ""
12752   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12753         (compare:CC
12754          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12755                          (const_int 0))
12756                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12757          (const_int 0)))
12758    (clobber (match_scratch:DI 3 "=&r,&r"))]
12759   "TARGET_64BIT"
12760   "@
12761    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
12762    #"
12763   [(set_attr "type" "compare")
12764    (set_attr "length" "12,16")])
12765
12766 (define_split
12767   [(set (match_operand:CC 0 "cc_reg_not_micro_cr0_operand" "")
12768         (compare:CC
12769          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
12770                          (const_int 0))
12771                   (match_operand:DI 2 "gpc_reg_operand" ""))
12772          (const_int 0)))
12773    (clobber (match_scratch:DI 3 ""))]
12774   "TARGET_64BIT && reload_completed"
12775   [(set (match_dup 3)
12776         (plus:DI (gt:DI (match_dup 1) (const_int 0))
12777                  (match_dup 2)))
12778    (set (match_dup 0)
12779         (compare:CC (match_dup 3)
12780                     (const_int 0)))]
12781   "")
12782
12783 (define_insn ""
12784   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12785         (compare:CC
12786          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12787                          (const_int 0))
12788                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
12789          (const_int 0)))
12790    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12791         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
12792   "TARGET_32BIT"
12793   "@
12794    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
12795    #"
12796   [(set_attr "type" "compare")
12797    (set_attr "length" "12,16")])
12798
12799 (define_split
12800   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12801         (compare:CC
12802          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12803                          (const_int 0))
12804                   (match_operand:SI 2 "gpc_reg_operand" ""))
12805          (const_int 0)))
12806    (set (match_operand:SI 0 "gpc_reg_operand" "")
12807         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
12808   "TARGET_32BIT && reload_completed"
12809   [(set (match_dup 0)
12810         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
12811    (set (match_dup 3)
12812         (compare:CC (match_dup 0)
12813                     (const_int 0)))]
12814   "")
12815
12816 (define_insn ""
12817   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12818         (compare:CC
12819          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12820                          (const_int 0))
12821                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12822          (const_int 0)))
12823    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
12824         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
12825   "TARGET_64BIT"
12826   "@
12827    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
12828    #"
12829   [(set_attr "type" "compare")
12830    (set_attr "length" "12,16")])
12831
12832 (define_split
12833   [(set (match_operand:CC 3 "cc_reg_not_micro_cr0_operand" "")
12834         (compare:CC
12835          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
12836                          (const_int 0))
12837                   (match_operand:DI 2 "gpc_reg_operand" ""))
12838          (const_int 0)))
12839    (set (match_operand:DI 0 "gpc_reg_operand" "")
12840         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
12841   "TARGET_64BIT && reload_completed"
12842   [(set (match_dup 0)
12843         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
12844    (set (match_dup 3)
12845         (compare:CC (match_dup 0)
12846                     (const_int 0)))]
12847   "")
12848
12849 (define_insn_and_split "*gtu<mode>"
12850   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12851         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
12852                (match_operand:P 2 "reg_or_short_operand" "rI")))]
12853   ""
12854   "#"
12855   ""
12856   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
12857    (set (match_dup 0) (neg:P (match_dup 0)))]
12858   "")
12859
12860 (define_insn_and_split "*gtu<mode>_compare"
12861   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12862         (compare:CC
12863          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12864                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
12865          (const_int 0)))
12866    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12867         (gtu:P (match_dup 1) (match_dup 2)))]
12868   ""
12869   "#"
12870   ""
12871   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
12872    (parallel [(set (match_dup 3)
12873                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
12874               (set (match_dup 0) (neg:P (match_dup 0)))])]
12875   "")
12876
12877 (define_insn_and_split "*plus_gtu<mode>"
12878   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12879         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
12880                        (match_operand:P 2 "reg_or_short_operand" "rI"))
12881                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
12882   ""
12883   "#"
12884   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12885   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
12886    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
12887   "")
12888
12889 (define_insn_and_split "*plus_gtu<mode>_compare"
12890   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12891         (compare:CC
12892          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12893                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
12894                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
12895          (const_int 0)))
12896    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12897         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
12898   ""
12899   "#"
12900   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12901   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
12902    (parallel [(set (match_dup 4)
12903                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
12904                                (const_int 0)))
12905               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
12906   "")
12907
12908 (define_insn "*neg_gtu<mode>"
12909   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12910         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
12911                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
12912   ""
12913   "subf%I2c %0,%1,%2\;subfe %0,%0,%0"
12914   [(set_attr "type" "two")
12915    (set_attr "length" "8")])
12916
12917 \f
12918 ;; Define both directions of branch and return.  If we need a reload
12919 ;; register, we'd rather use CR0 since it is much easier to copy a
12920 ;; register CC value to there.
12921
12922 (define_insn ""
12923   [(set (pc)
12924         (if_then_else (match_operator 1 "branch_comparison_operator"
12925                                       [(match_operand 2
12926                                                       "cc_reg_operand" "y")
12927                                        (const_int 0)])
12928                       (label_ref (match_operand 0 "" ""))
12929                       (pc)))]
12930   ""
12931   "*
12932 {
12933   return output_cbranch (operands[1], \"%l0\", 0, insn);
12934 }"
12935   [(set_attr "type" "branch")])
12936
12937 (define_insn ""
12938   [(set (pc)
12939         (if_then_else (match_operator 0 "branch_comparison_operator"
12940                                       [(match_operand 1
12941                                                       "cc_reg_operand" "y")
12942                                        (const_int 0)])
12943                       (any_return)
12944                       (pc)))]
12945   "<return_pred>"
12946   "*
12947 {
12948   return output_cbranch (operands[0], NULL, 0, insn);
12949 }"
12950   [(set_attr "type" "jmpreg")
12951    (set_attr "length" "4")])
12952
12953 (define_insn ""
12954   [(set (pc)
12955         (if_then_else (match_operator 1 "branch_comparison_operator"
12956                                       [(match_operand 2
12957                                                       "cc_reg_operand" "y")
12958                                        (const_int 0)])
12959                       (pc)
12960                       (label_ref (match_operand 0 "" ""))))]
12961   ""
12962   "*
12963 {
12964   return output_cbranch (operands[1], \"%l0\", 1, insn);
12965 }"
12966   [(set_attr "type" "branch")])
12967
12968 (define_insn ""
12969   [(set (pc)
12970         (if_then_else (match_operator 0 "branch_comparison_operator"
12971                                       [(match_operand 1
12972                                                       "cc_reg_operand" "y")
12973                                        (const_int 0)])
12974                       (pc)
12975                       (any_return)))]
12976   "<return_pred>"
12977   "*
12978 {
12979   return output_cbranch (operands[0], NULL, 1, insn);
12980 }"
12981   [(set_attr "type" "jmpreg")
12982    (set_attr "length" "4")])
12983
12984 ;; Logic on condition register values.
12985
12986 ; This pattern matches things like
12987 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
12988 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
12989 ;                                  (const_int 1)))
12990 ; which are generated by the branch logic.
12991 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
12992
12993 (define_insn "*cceq_ior_compare"
12994   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
12995         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
12996                         [(match_operator:SI 2
12997                                       "branch_positive_comparison_operator"
12998                                       [(match_operand 3
12999                                                       "cc_reg_operand" "y,y")
13000                                        (const_int 0)])
13001                          (match_operator:SI 4
13002                                       "branch_positive_comparison_operator"
13003                                       [(match_operand 5
13004                                                       "cc_reg_operand" "0,y")
13005                                        (const_int 0)])])
13006                       (const_int 1)))]
13007   ""
13008   "cr%q1 %E0,%j2,%j4"
13009   [(set_attr "type" "cr_logical,delayed_cr")])
13010
13011 ; Why is the constant -1 here, but 1 in the previous pattern?
13012 ; Because ~1 has all but the low bit set.
13013 (define_insn ""
13014   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13015         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
13016                         [(not:SI (match_operator:SI 2
13017                                       "branch_positive_comparison_operator"
13018                                       [(match_operand 3
13019                                                       "cc_reg_operand" "y,y")
13020                                        (const_int 0)]))
13021                          (match_operator:SI 4
13022                                 "branch_positive_comparison_operator"
13023                                 [(match_operand 5
13024                                                 "cc_reg_operand" "0,y")
13025                                  (const_int 0)])])
13026                       (const_int -1)))]
13027   ""
13028   "cr%q1 %E0,%j2,%j4"
13029   [(set_attr "type" "cr_logical,delayed_cr")])
13030
13031 (define_insn "*cceq_rev_compare"
13032   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13033         (compare:CCEQ (match_operator:SI 1
13034                                       "branch_positive_comparison_operator"
13035                                       [(match_operand 2
13036                                                       "cc_reg_operand" "0,y")
13037                                        (const_int 0)])
13038                       (const_int 0)))]
13039   ""
13040   "crnot %E0,%j1"
13041   [(set_attr "type" "cr_logical,delayed_cr")])
13042
13043 ;; If we are comparing the result of two comparisons, this can be done
13044 ;; using creqv or crxor.
13045
13046 (define_insn_and_split ""
13047   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13048         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13049                               [(match_operand 2 "cc_reg_operand" "y")
13050                                (const_int 0)])
13051                       (match_operator 3 "branch_comparison_operator"
13052                               [(match_operand 4 "cc_reg_operand" "y")
13053                                (const_int 0)])))]
13054   ""
13055   "#"
13056   ""
13057   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13058                                     (match_dup 5)))]
13059   "
13060 {
13061   int positive_1, positive_2;
13062
13063   positive_1 = branch_positive_comparison_operator (operands[1],
13064                                                     GET_MODE (operands[1]));
13065   positive_2 = branch_positive_comparison_operator (operands[3],
13066                                                     GET_MODE (operands[3]));
13067
13068   if (! positive_1)
13069     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
13070                                                             GET_CODE (operands[1])),
13071                                   SImode,
13072                                   operands[2], const0_rtx);
13073   else if (GET_MODE (operands[1]) != SImode)
13074     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
13075                                   operands[2], const0_rtx);
13076
13077   if (! positive_2)
13078     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
13079                                                             GET_CODE (operands[3])),
13080                                   SImode,
13081                                   operands[4], const0_rtx);
13082   else if (GET_MODE (operands[3]) != SImode)
13083     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
13084                                   operands[4], const0_rtx);
13085
13086   if (positive_1 == positive_2)
13087     {
13088       operands[1] = gen_rtx_NOT (SImode, operands[1]);
13089       operands[5] = constm1_rtx;
13090     }
13091   else
13092     {
13093       operands[5] = const1_rtx;
13094     }
13095 }")
13096
13097 ;; Unconditional branch and return.
13098
13099 (define_insn "jump"
13100   [(set (pc)
13101         (label_ref (match_operand 0 "" "")))]
13102   ""
13103   "b %l0"
13104   [(set_attr "type" "branch")])
13105
13106 (define_insn "<return_str>return"
13107   [(any_return)]
13108   "<return_pred>"
13109   "blr"
13110   [(set_attr "type" "jmpreg")])
13111
13112 (define_expand "indirect_jump"
13113   [(set (pc) (match_operand 0 "register_operand" ""))])
13114
13115 (define_insn "*indirect_jump<mode>"
13116   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
13117   ""
13118   "@
13119    bctr
13120    blr"
13121   [(set_attr "type" "jmpreg")])
13122
13123 ;; Table jump for switch statements:
13124 (define_expand "tablejump"
13125   [(use (match_operand 0 "" ""))
13126    (use (label_ref (match_operand 1 "" "")))]
13127   ""
13128   "
13129 {
13130   if (TARGET_32BIT)
13131     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
13132   else
13133     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
13134   DONE;
13135 }")
13136
13137 (define_expand "tablejumpsi"
13138   [(set (match_dup 3)
13139         (plus:SI (match_operand:SI 0 "" "")
13140                  (match_dup 2)))
13141    (parallel [(set (pc) (match_dup 3))
13142               (use (label_ref (match_operand 1 "" "")))])]
13143   "TARGET_32BIT"
13144   "
13145 { operands[0] = force_reg (SImode, operands[0]);
13146   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
13147   operands[3] = gen_reg_rtx (SImode);
13148 }")
13149
13150 (define_expand "tablejumpdi"
13151   [(set (match_dup 4)
13152         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "")))
13153    (set (match_dup 3)
13154         (plus:DI (match_dup 4)
13155                  (match_dup 2)))
13156    (parallel [(set (pc) (match_dup 3))
13157               (use (label_ref (match_operand 1 "" "")))])]
13158   "TARGET_64BIT"
13159   "
13160 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
13161   operands[3] = gen_reg_rtx (DImode);
13162   operands[4] = gen_reg_rtx (DImode);
13163 }")
13164
13165 (define_insn "*tablejump<mode>_internal1"
13166   [(set (pc)
13167         (match_operand:P 0 "register_operand" "c,*l"))
13168    (use (label_ref (match_operand 1 "" "")))]
13169   ""
13170   "@
13171    bctr
13172    blr"
13173   [(set_attr "type" "jmpreg")])
13174
13175 (define_insn "nop"
13176   [(const_int 0)]
13177   ""
13178   "nop")
13179
13180 (define_insn "group_ending_nop"
13181   [(unspec [(const_int 0)] UNSPEC_GRP_END_NOP)]
13182   ""
13183   "*
13184 {
13185   if (rs6000_cpu_attr == CPU_POWER6)
13186     return \"ori 1,1,0\";
13187   return \"ori 2,2,0\";
13188 }")
13189 \f
13190 ;; Define the subtract-one-and-jump insns, starting with the template
13191 ;; so loop.c knows what to generate.
13192
13193 (define_expand "doloop_end"
13194   [(use (match_operand 0 "" ""))        ; loop pseudo
13195    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
13196    (use (match_operand 2 "" ""))        ; max iterations
13197    (use (match_operand 3 "" ""))        ; loop level
13198    (use (match_operand 4 "" ""))        ; label
13199    (use (match_operand 5 "" ""))]       ; flag: 1 if loop entered at top, else 0
13200   ""
13201   "
13202 {
13203   /* Only use this on innermost loops.  */
13204   if (INTVAL (operands[3]) > 1)
13205     FAIL;
13206   if (TARGET_64BIT)
13207     {
13208       if (GET_MODE (operands[0]) != DImode)
13209         FAIL;
13210       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
13211     }
13212   else
13213     {
13214       if (GET_MODE (operands[0]) != SImode)
13215         FAIL;
13216       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
13217     }
13218   DONE;
13219 }")
13220
13221 (define_expand "ctr<mode>"
13222   [(parallel [(set (pc)
13223                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
13224                                      (const_int 1))
13225                                  (label_ref (match_operand 1 "" ""))
13226                                  (pc)))
13227               (set (match_dup 0)
13228                    (plus:P (match_dup 0)
13229                             (const_int -1)))
13230               (clobber (match_scratch:CC 2 ""))
13231               (clobber (match_scratch:P 3 ""))])]
13232   ""
13233   "")
13234
13235 ;; We need to be able to do this for any operand, including MEM, or we
13236 ;; will cause reload to blow up since we don't allow output reloads on
13237 ;; JUMP_INSNs.
13238 ;; For the length attribute to be calculated correctly, the
13239 ;; label MUST be operand 0.
13240
13241 (define_insn "*ctr<mode>_internal1"
13242   [(set (pc)
13243         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13244                           (const_int 1))
13245                       (label_ref (match_operand 0 "" ""))
13246                       (pc)))
13247    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
13248         (plus:P (match_dup 1)
13249                  (const_int -1)))
13250    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13251    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13252   ""
13253   "*
13254 {
13255   if (which_alternative != 0)
13256     return \"#\";
13257   else if (get_attr_length (insn) == 4)
13258     return \"bdnz %l0\";
13259   else
13260     return \"bdz $+8\;b %l0\";
13261 }"
13262   [(set_attr "type" "branch")
13263    (set_attr "length" "*,12,16,16")])
13264
13265 (define_insn "*ctr<mode>_internal2"
13266   [(set (pc)
13267         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13268                           (const_int 1))
13269                       (pc)
13270                       (label_ref (match_operand 0 "" ""))))
13271    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
13272         (plus:P (match_dup 1)
13273                  (const_int -1)))
13274    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13275    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13276   ""
13277   "*
13278 {
13279   if (which_alternative != 0)
13280     return \"#\";
13281   else if (get_attr_length (insn) == 4)
13282     return \"bdz %l0\";
13283   else
13284     return \"bdnz $+8\;b %l0\";
13285 }"
13286   [(set_attr "type" "branch")
13287    (set_attr "length" "*,12,16,16")])
13288
13289 ;; Similar but use EQ
13290
13291 (define_insn "*ctr<mode>_internal5"
13292   [(set (pc)
13293         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13294                           (const_int 1))
13295                       (label_ref (match_operand 0 "" ""))
13296                       (pc)))
13297    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
13298         (plus:P (match_dup 1)
13299                  (const_int -1)))
13300    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13301    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13302   ""
13303   "*
13304 {
13305   if (which_alternative != 0)
13306     return \"#\";
13307   else if (get_attr_length (insn) == 4)
13308     return \"bdz %l0\";
13309   else
13310     return \"bdnz $+8\;b %l0\";
13311 }"
13312   [(set_attr "type" "branch")
13313    (set_attr "length" "*,12,16,16")])
13314
13315 (define_insn "*ctr<mode>_internal6"
13316   [(set (pc)
13317         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13318                           (const_int 1))
13319                       (pc)
13320                       (label_ref (match_operand 0 "" ""))))
13321    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*c*l")
13322         (plus:P (match_dup 1)
13323                  (const_int -1)))
13324    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13325    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13326   ""
13327   "*
13328 {
13329   if (which_alternative != 0)
13330     return \"#\";
13331   else if (get_attr_length (insn) == 4)
13332     return \"bdnz %l0\";
13333   else
13334     return \"bdz $+8\;b %l0\";
13335 }"
13336   [(set_attr "type" "branch")
13337    (set_attr "length" "*,12,16,16")])
13338
13339 ;; Now the splitters if we could not allocate the CTR register
13340
13341 (define_split
13342   [(set (pc)
13343         (if_then_else (match_operator 2 "comparison_operator"
13344                                       [(match_operand:P 1 "gpc_reg_operand" "")
13345                                        (const_int 1)])
13346                       (match_operand 5 "" "")
13347                       (match_operand 6 "" "")))
13348    (set (match_operand:P 0 "gpc_reg_operand" "")
13349         (plus:P (match_dup 1) (const_int -1)))
13350    (clobber (match_scratch:CC 3 ""))
13351    (clobber (match_scratch:P 4 ""))]
13352   "reload_completed"
13353   [(parallel [(set (match_dup 3)
13354                    (compare:CC (plus:P (match_dup 1)
13355                                         (const_int -1))
13356                                (const_int 0)))
13357               (set (match_dup 0)
13358                    (plus:P (match_dup 1)
13359                             (const_int -1)))])
13360    (set (pc) (if_then_else (match_dup 7)
13361                            (match_dup 5)
13362                            (match_dup 6)))]
13363   "
13364 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
13365                                 operands[3], const0_rtx); }")
13366
13367 (define_split
13368   [(set (pc)
13369         (if_then_else (match_operator 2 "comparison_operator"
13370                                       [(match_operand:P 1 "gpc_reg_operand" "")
13371                                        (const_int 1)])
13372                       (match_operand 5 "" "")
13373                       (match_operand 6 "" "")))
13374    (set (match_operand:P 0 "nonimmediate_operand" "")
13375         (plus:P (match_dup 1) (const_int -1)))
13376    (clobber (match_scratch:CC 3 ""))
13377    (clobber (match_scratch:P 4 ""))]
13378   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
13379   [(parallel [(set (match_dup 3)
13380                    (compare:CC (plus:P (match_dup 1)
13381                                         (const_int -1))
13382                                (const_int 0)))
13383               (set (match_dup 4)
13384                    (plus:P (match_dup 1)
13385                             (const_int -1)))])
13386    (set (match_dup 0)
13387         (match_dup 4))
13388    (set (pc) (if_then_else (match_dup 7)
13389                            (match_dup 5)
13390                            (match_dup 6)))]
13391   "
13392 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
13393                                 operands[3], const0_rtx); }")
13394 \f
13395 (define_insn "trap"
13396   [(trap_if (const_int 1) (const_int 0))]
13397   ""
13398   "trap"
13399   [(set_attr "type" "trap")])
13400
13401 (define_expand "ctrap<mode>4"
13402   [(trap_if (match_operator 0 "ordered_comparison_operator"
13403                             [(match_operand:GPR 1 "register_operand")
13404                              (match_operand:GPR 2 "reg_or_short_operand")])
13405             (match_operand 3 "zero_constant" ""))]
13406   ""
13407   "")
13408
13409 (define_insn ""
13410   [(trap_if (match_operator 0 "ordered_comparison_operator"
13411                             [(match_operand:GPR 1 "register_operand" "r")
13412                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
13413             (const_int 0))]
13414   ""
13415   "t<wd>%V0%I2 %1,%2"
13416   [(set_attr "type" "trap")])
13417 \f
13418 ;; Insns related to generating the function prologue and epilogue.
13419
13420 (define_expand "prologue"
13421   [(use (const_int 0))]
13422   ""
13423 {
13424   rs6000_emit_prologue ();
13425   if (!TARGET_SCHED_PROLOG)
13426     emit_insn (gen_blockage ());
13427   DONE;
13428 })
13429
13430 (define_insn "*movesi_from_cr_one"
13431   [(match_parallel 0 "mfcr_operation"
13432                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
13433                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
13434                                      (match_operand 3 "immediate_operand" "n")]
13435                           UNSPEC_MOVESI_FROM_CR))])]
13436   "TARGET_MFCRF"
13437   "*
13438 {
13439   int mask = 0;
13440   int i;
13441   for (i = 0; i < XVECLEN (operands[0], 0); i++)
13442   {
13443     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
13444     operands[4] = GEN_INT (mask);
13445     output_asm_insn (\"mfcr %1,%4\", operands);
13446   }
13447   return \"\";
13448 }"
13449   [(set_attr "type" "mfcrf")])
13450
13451 (define_insn "movesi_from_cr"
13452   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13453         (unspec:SI [(reg:CC CR0_REGNO) (reg:CC CR1_REGNO)
13454                     (reg:CC CR2_REGNO) (reg:CC CR3_REGNO)
13455                     (reg:CC CR4_REGNO) (reg:CC CR5_REGNO)
13456                     (reg:CC CR6_REGNO) (reg:CC CR7_REGNO)]
13457                    UNSPEC_MOVESI_FROM_CR))]
13458   ""
13459   "mfcr %0"
13460   [(set_attr "type" "mfcr")])
13461
13462 (define_insn "*stmw"
13463   [(match_parallel 0 "stmw_operation"
13464                    [(set (match_operand:SI 1 "memory_operand" "=m")
13465                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
13466   "TARGET_MULTIPLE"
13467   "stmw %2,%1"
13468   [(set_attr "type" "store_ux")])
13469
13470 ; The following comment applies to:
13471 ;     save_gpregs_*
13472 ;     save_fpregs_*
13473 ;     restore_gpregs*
13474 ;     return_and_restore_gpregs*
13475 ;     return_and_restore_fpregs*
13476 ;     return_and_restore_fpregs_aix*
13477 ;
13478 ; The out-of-line save / restore functions expects one input argument.
13479 ; Since those are not standard call_insn's, we must avoid using
13480 ; MATCH_OPERAND for that argument. That way the register rename
13481 ; optimization will not try to rename this register.
13482 ; Each pattern is repeated for each possible register number used in 
13483 ; various ABIs (r11, r1, and for some functions r12)
13484
13485 (define_insn "*save_gpregs_<mode>_r11"
13486   [(match_parallel 0 "any_parallel_operand"
13487                    [(clobber (reg:P 65))
13488                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
13489                     (use (reg:P 11))
13490                     (set (match_operand:P 2 "memory_operand" "=m")
13491                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
13492   ""
13493   "bl %1"
13494   [(set_attr "type" "branch")
13495    (set_attr "length" "4")])
13496
13497 (define_insn "*save_gpregs_<mode>_r12"
13498   [(match_parallel 0 "any_parallel_operand"
13499                    [(clobber (reg:P 65))
13500                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
13501                     (use (reg:P 12))
13502                     (set (match_operand:P 2 "memory_operand" "=m")
13503                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
13504   ""
13505   "bl %1"
13506   [(set_attr "type" "branch")
13507    (set_attr "length" "4")])
13508
13509 (define_insn "*save_gpregs_<mode>_r1"
13510   [(match_parallel 0 "any_parallel_operand"
13511                    [(clobber (reg:P 65))
13512                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
13513                     (use (reg:P 1))
13514                     (set (match_operand:P 2 "memory_operand" "=m")
13515                          (match_operand:P 3 "gpc_reg_operand" "r"))])]
13516   ""
13517   "bl %1"
13518   [(set_attr "type" "branch")
13519    (set_attr "length" "4")])
13520
13521 (define_insn "*save_fpregs_<mode>_r11"
13522   [(match_parallel 0 "any_parallel_operand"
13523                    [(clobber (reg:P 65))
13524                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
13525                     (use (reg:P 11))
13526                     (set (match_operand:DF 2 "memory_operand" "=m")
13527                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
13528   ""
13529   "bl %1"
13530   [(set_attr "type" "branch")
13531    (set_attr "length" "4")])
13532
13533 (define_insn "*save_fpregs_<mode>_r12"
13534   [(match_parallel 0 "any_parallel_operand"
13535                    [(clobber (reg:P 65))
13536                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
13537                     (use (reg:P 12))
13538                     (set (match_operand:DF 2 "memory_operand" "=m")
13539                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
13540   ""
13541   "bl %1"
13542   [(set_attr "type" "branch")
13543    (set_attr "length" "4")])
13544
13545 (define_insn "*save_fpregs_<mode>_r1"
13546   [(match_parallel 0 "any_parallel_operand"
13547                    [(clobber (reg:P 65))
13548                     (use (match_operand:P 1 "symbol_ref_operand" "s"))
13549                     (use (reg:P 1))
13550                     (set (match_operand:DF 2 "memory_operand" "=m")
13551                          (match_operand:DF 3 "gpc_reg_operand" "d"))])]
13552   ""
13553   "bl %1"
13554   [(set_attr "type" "branch")
13555    (set_attr "length" "4")])
13556
13557 ; This is to explain that changes to the stack pointer should
13558 ; not be moved over loads from or stores to stack memory.
13559 (define_insn "stack_tie"
13560   [(match_parallel 0 "tie_operand"
13561                    [(set (mem:BLK (reg 1)) (const_int 0))])]
13562   ""
13563   ""
13564   [(set_attr "length" "0")])
13565
13566 (define_expand "epilogue"
13567   [(use (const_int 0))]
13568   ""
13569 {
13570   if (!TARGET_SCHED_PROLOG)
13571     emit_insn (gen_blockage ());
13572   rs6000_emit_epilogue (FALSE);
13573   DONE;
13574 })
13575
13576 ; On some processors, doing the mtcrf one CC register at a time is
13577 ; faster (like on the 604e).  On others, doing them all at once is
13578 ; faster; for instance, on the 601 and 750.
13579
13580 (define_expand "movsi_to_cr_one"
13581   [(set (match_operand:CC 0 "cc_reg_operand" "")
13582         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "")
13583                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
13584   ""
13585   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
13586
13587 (define_insn "*movsi_to_cr"
13588   [(match_parallel 0 "mtcrf_operation"
13589                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
13590                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
13591                                      (match_operand 3 "immediate_operand" "n")]
13592                                     UNSPEC_MOVESI_TO_CR))])]
13593  ""
13594  "*
13595 {
13596   int mask = 0;
13597   int i;
13598   for (i = 0; i < XVECLEN (operands[0], 0); i++)
13599     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
13600   operands[4] = GEN_INT (mask);
13601   return \"mtcrf %4,%2\";
13602 }"
13603   [(set_attr "type" "mtcr")])
13604
13605 (define_insn "*mtcrfsi"
13606   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
13607         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
13608                     (match_operand 2 "immediate_operand" "n")]
13609                    UNSPEC_MOVESI_TO_CR))]
13610   "GET_CODE (operands[0]) == REG
13611    && CR_REGNO_P (REGNO (operands[0]))
13612    && GET_CODE (operands[2]) == CONST_INT
13613    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
13614   "mtcrf %R0,%1"
13615   [(set_attr "type" "mtcr")])
13616
13617 ; The load-multiple instructions have similar properties.
13618 ; Note that "load_multiple" is a name known to the machine-independent
13619 ; code that actually corresponds to the PowerPC load-string.
13620
13621 (define_insn "*lmw"
13622   [(match_parallel 0 "lmw_operation"
13623                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
13624                          (match_operand:SI 2 "memory_operand" "m"))])]
13625   "TARGET_MULTIPLE"
13626   "lmw %1,%2"
13627   [(set_attr "type" "load_ux")
13628    (set_attr "cell_micro" "always")])
13629
13630 (define_insn "*return_internal_<mode>"
13631   [(simple_return)
13632    (use (match_operand:P 0 "register_operand" "lc"))]
13633   ""
13634   "b%T0"
13635   [(set_attr "type" "jmpreg")])
13636
13637 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
13638 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
13639
13640 ; The following comment applies to:
13641 ;     save_gpregs_*
13642 ;     save_fpregs_*
13643 ;     restore_gpregs*
13644 ;     return_and_restore_gpregs*
13645 ;     return_and_restore_fpregs*
13646 ;     return_and_restore_fpregs_aix*
13647 ;
13648 ; The out-of-line save / restore functions expects one input argument.
13649 ; Since those are not standard call_insn's, we must avoid using
13650 ; MATCH_OPERAND for that argument. That way the register rename
13651 ; optimization will not try to rename this register.
13652 ; Each pattern is repeated for each possible register number used in 
13653 ; various ABIs (r11, r1, and for some functions r12)
13654
13655 (define_insn "*restore_gpregs_<mode>_r11"
13656  [(match_parallel 0 "any_parallel_operand"
13657                   [(clobber (match_operand:P 1 "register_operand" "=l"))
13658                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13659                    (use (reg:P 11))
13660                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
13661                         (match_operand:P 4 "memory_operand" "m"))])]
13662  ""
13663  "bl %2"
13664  [(set_attr "type" "branch")
13665   (set_attr "length" "4")])
13666
13667 (define_insn "*restore_gpregs_<mode>_r12"
13668  [(match_parallel 0 "any_parallel_operand"
13669                   [(clobber (match_operand:P 1 "register_operand" "=l"))
13670                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13671                    (use (reg:P 12))
13672                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
13673                         (match_operand:P 4 "memory_operand" "m"))])]
13674  ""
13675  "bl %2"
13676  [(set_attr "type" "branch")
13677   (set_attr "length" "4")])
13678
13679 (define_insn "*restore_gpregs_<mode>_r1"
13680  [(match_parallel 0 "any_parallel_operand"
13681                   [(clobber (match_operand:P 1 "register_operand" "=l"))
13682                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13683                    (use (reg:P 1))
13684                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
13685                         (match_operand:P 4 "memory_operand" "m"))])]
13686  ""
13687  "bl %2"
13688  [(set_attr "type" "branch")
13689   (set_attr "length" "4")])
13690
13691 (define_insn "*return_and_restore_gpregs_<mode>_r11"
13692  [(match_parallel 0 "any_parallel_operand"
13693                   [(return)
13694                    (clobber (match_operand:P 1 "register_operand" "=l"))
13695                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13696                    (use (reg:P 11))
13697                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
13698                         (match_operand:P 4 "memory_operand" "m"))])]
13699  ""
13700  "b %2"
13701  [(set_attr "type" "branch")
13702   (set_attr "length" "4")])
13703
13704 (define_insn "*return_and_restore_gpregs_<mode>_r12"
13705  [(match_parallel 0 "any_parallel_operand"
13706                   [(return)
13707                    (clobber (match_operand:P 1 "register_operand" "=l"))
13708                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13709                    (use (reg:P 12))
13710                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
13711                         (match_operand:P 4 "memory_operand" "m"))])]
13712  ""
13713  "b %2"
13714  [(set_attr "type" "branch")
13715   (set_attr "length" "4")])
13716
13717 (define_insn "*return_and_restore_gpregs_<mode>_r1"
13718  [(match_parallel 0 "any_parallel_operand"
13719                   [(return)
13720                    (clobber (match_operand:P 1 "register_operand" "=l"))
13721                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13722                    (use (reg:P 1))
13723                    (set (match_operand:P 3 "gpc_reg_operand" "=r")
13724                         (match_operand:P 4 "memory_operand" "m"))])]
13725  ""
13726  "b %2"
13727  [(set_attr "type" "branch")
13728   (set_attr "length" "4")])
13729
13730 (define_insn "*return_and_restore_fpregs_<mode>_r11"
13731  [(match_parallel 0 "any_parallel_operand"
13732                   [(return)
13733                    (clobber (match_operand:P 1 "register_operand" "=l"))
13734                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13735                    (use (reg:P 11))
13736                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
13737                         (match_operand:DF 4 "memory_operand" "m"))])]
13738  ""
13739  "b %2"
13740  [(set_attr "type" "branch")
13741   (set_attr "length" "4")])
13742
13743 (define_insn "*return_and_restore_fpregs_<mode>_r12"
13744  [(match_parallel 0 "any_parallel_operand"
13745                   [(return)
13746                    (clobber (match_operand:P 1 "register_operand" "=l"))
13747                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13748                    (use (reg:P 12))
13749                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
13750                         (match_operand:DF 4 "memory_operand" "m"))])]
13751  ""
13752  "b %2"
13753  [(set_attr "type" "branch")
13754   (set_attr "length" "4")])
13755
13756 (define_insn "*return_and_restore_fpregs_<mode>_r1"
13757  [(match_parallel 0 "any_parallel_operand"
13758                   [(return)
13759                    (clobber (match_operand:P 1 "register_operand" "=l"))
13760                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13761                    (use (reg:P 1))
13762                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
13763                         (match_operand:DF 4 "memory_operand" "m"))])]
13764  ""
13765  "b %2"
13766  [(set_attr "type" "branch")
13767   (set_attr "length" "4")])
13768
13769 (define_insn "*return_and_restore_fpregs_aix_<mode>_r11"
13770  [(match_parallel 0 "any_parallel_operand"
13771                   [(return)
13772                    (use (match_operand:P 1 "register_operand" "l"))
13773                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13774                    (use (reg:P 11))
13775                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
13776                         (match_operand:DF 4 "memory_operand" "m"))])]
13777  ""
13778  "b %2"
13779  [(set_attr "type" "branch")
13780   (set_attr "length" "4")])
13781
13782 (define_insn "*return_and_restore_fpregs_aix_<mode>_r1"
13783  [(match_parallel 0 "any_parallel_operand"
13784                   [(return)
13785                    (use (match_operand:P 1 "register_operand" "l"))
13786                    (use (match_operand:P 2 "symbol_ref_operand" "s"))
13787                    (use (reg:P 1))
13788                    (set (match_operand:DF 3 "gpc_reg_operand" "=d")
13789                         (match_operand:DF 4 "memory_operand" "m"))])]
13790  ""
13791  "b %2"
13792  [(set_attr "type" "branch")
13793   (set_attr "length" "4")])
13794
13795 ; This is used in compiling the unwind routines.
13796 (define_expand "eh_return"
13797   [(use (match_operand 0 "general_operand" ""))]
13798   ""
13799   "
13800 {
13801   if (TARGET_32BIT)
13802     emit_insn (gen_eh_set_lr_si (operands[0]));
13803   else
13804     emit_insn (gen_eh_set_lr_di (operands[0]));
13805   DONE;
13806 }")
13807
13808 ; We can't expand this before we know where the link register is stored.
13809 (define_insn "eh_set_lr_<mode>"
13810   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
13811                     UNSPECV_EH_RR)
13812    (clobber (match_scratch:P 1 "=&b"))]
13813   ""
13814   "#")
13815
13816 (define_split
13817   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
13818    (clobber (match_scratch 1 ""))]
13819   "reload_completed"
13820   [(const_int 0)]
13821   "
13822 {
13823   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
13824   DONE;
13825 }")
13826
13827 (define_insn "prefetch"
13828   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
13829              (match_operand:SI 1 "const_int_operand" "n")
13830              (match_operand:SI 2 "const_int_operand" "n"))]
13831   ""
13832   "*
13833 {
13834   if (GET_CODE (operands[0]) == REG)
13835     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
13836   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
13837 }"
13838   [(set_attr "type" "load")])
13839 \f
13840 (define_insn "bpermd_<mode>"
13841   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13842         (unspec:P [(match_operand:P 1 "gpc_reg_operand" "r")
13843                    (match_operand:P 2 "gpc_reg_operand" "r")] UNSPEC_BPERM))]
13844   "TARGET_POPCNTD"
13845   "bpermd %0,%1,%2"
13846   [(set_attr "type" "integer")])
13847
13848 \f
13849 ;; Builtin fma support.  Handle 
13850 ;; Note that the conditions for expansion are in the FMA_F iterator.
13851
13852 (define_expand "fma<mode>4"
13853   [(set (match_operand:FMA_F 0 "register_operand" "")
13854         (fma:FMA_F
13855           (match_operand:FMA_F 1 "register_operand" "")
13856           (match_operand:FMA_F 2 "register_operand" "")
13857           (match_operand:FMA_F 3 "register_operand" "")))]
13858   ""
13859   "")
13860
13861 ; Altivec only has fma and nfms.
13862 (define_expand "fms<mode>4"
13863   [(set (match_operand:FMA_F 0 "register_operand" "")
13864         (fma:FMA_F
13865           (match_operand:FMA_F 1 "register_operand" "")
13866           (match_operand:FMA_F 2 "register_operand" "")
13867           (neg:FMA_F (match_operand:FMA_F 3 "register_operand" ""))))]
13868   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
13869   "")
13870
13871 ;; If signed zeros are ignored, -(a * b - c) = -a * b + c.
13872 (define_expand "fnma<mode>4"
13873   [(set (match_operand:FMA_F 0 "register_operand" "")
13874         (neg:FMA_F
13875           (fma:FMA_F
13876             (match_operand:FMA_F 1 "register_operand" "")
13877             (match_operand:FMA_F 2 "register_operand" "")
13878             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
13879   "!HONOR_SIGNED_ZEROS (<MODE>mode)"
13880   "")
13881
13882 ;; If signed zeros are ignored, -(a * b + c) = -a * b - c.
13883 (define_expand "fnms<mode>4"
13884   [(set (match_operand:FMA_F 0 "register_operand" "")
13885         (neg:FMA_F
13886           (fma:FMA_F
13887             (match_operand:FMA_F 1 "register_operand" "")
13888             (match_operand:FMA_F 2 "register_operand" "")
13889             (match_operand:FMA_F 3 "register_operand" ""))))]
13890   "!HONOR_SIGNED_ZEROS (<MODE>mode) && !VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
13891   "")
13892
13893 ; Not an official optab name, but used from builtins.
13894 (define_expand "nfma<mode>4"
13895   [(set (match_operand:FMA_F 0 "register_operand" "")
13896         (neg:FMA_F
13897           (fma:FMA_F
13898             (match_operand:FMA_F 1 "register_operand" "")
13899             (match_operand:FMA_F 2 "register_operand" "")
13900             (match_operand:FMA_F 3 "register_operand" ""))))]
13901   "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
13902   "")
13903
13904 ; Not an official optab name, but used from builtins.
13905 (define_expand "nfms<mode>4"
13906   [(set (match_operand:FMA_F 0 "register_operand" "")
13907         (neg:FMA_F
13908           (fma:FMA_F
13909             (match_operand:FMA_F 1 "register_operand" "")
13910             (match_operand:FMA_F 2 "register_operand" "")
13911             (neg:FMA_F (match_operand:FMA_F 3 "register_operand" "")))))]
13912   ""
13913   "")
13914
13915 (define_expand "rs6000_get_timebase"
13916   [(use (match_operand:DI 0 "gpc_reg_operand" ""))]
13917   ""
13918 {
13919   if (TARGET_POWERPC64)
13920     emit_insn (gen_rs6000_mftb_di (operands[0]));
13921   else
13922     emit_insn (gen_rs6000_get_timebase_ppc32 (operands[0]));
13923   DONE;
13924 })
13925
13926 (define_insn "rs6000_get_timebase_ppc32"
13927   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13928         (unspec_volatile:DI [(const_int 0)] UNSPECV_MFTB))
13929    (clobber (match_scratch:SI 1 "=r"))
13930    (clobber (match_scratch:CC 2 "=y"))]
13931   "!TARGET_POWERPC64"
13932 {
13933   if (WORDS_BIG_ENDIAN)
13934     if (TARGET_MFCRF)
13935       {
13936         return "mfspr %0,269\;"
13937                "mfspr %L0,268\;"
13938                "mfspr %1,269\;"
13939                "cmpw %2,%0,%1\;"
13940                "bne- %2,$-16";
13941       }
13942     else
13943       {
13944         return "mftbu %0\;"
13945                "mftb %L0\;"
13946                "mftbu %1\;"
13947                "cmpw %2,%0,%1\;"
13948                "bne- %2,$-16";
13949       }
13950   else
13951     if (TARGET_MFCRF)
13952       {
13953         return "mfspr %L0,269\;"
13954                "mfspr %0,268\;"
13955                "mfspr %1,269\;"
13956                "cmpw %2,%L0,%1\;"
13957                "bne- %2,$-16";
13958       }
13959     else
13960       {
13961         return "mftbu %L0\;"
13962                "mftb %0\;"
13963                "mftbu %1\;"
13964                "cmpw %2,%L0,%1\;"
13965                "bne- %2,$-16";
13966       }
13967 })
13968
13969 (define_insn "rs6000_mftb_<mode>"
13970   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13971         (unspec_volatile:P [(const_int 0)] UNSPECV_MFTB))]
13972   ""
13973 {
13974   if (TARGET_MFCRF)
13975     return "mfspr %0,268";
13976   else
13977     return "mftb %0";
13978 })
13979
13980 \f
13981
13982 (include "sync.md")
13983 (include "vector.md")
13984 (include "vsx.md")
13985 (include "altivec.md")
13986 (include "spe.md")
13987 (include "dfp.md")
13988 (include "paired.md")