OSDN Git Service

2008-02-21 Edmar Wienskoski <edmar@freescale.com>
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / rs6000.md
1 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
2 ;; Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 ;; Free Software Foundation, Inc.
5 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
6
7 ;; This file is part of GCC.
8
9 ;; GCC is free software; you can redistribute it and/or modify it
10 ;; under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 3, or (at your
12 ;; option) any later version.
13
14 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
15 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
17 ;; License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GCC; see the file COPYING3.  If not see
21 ;; <http://www.gnu.org/licenses/>.
22
23 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
24
25 ;;
26 ;; REGNOS
27 ;;
28
29 (define_constants
30   [(MQ_REGNO                    64)
31    (LR_REGNO                    65)
32    (CTR_REGNO                   66)
33    (CR0_REGNO                   68)
34    (CR1_REGNO                   69)
35    (CR2_REGNO                   70)
36    (CR3_REGNO                   71)
37    (CR4_REGNO                   72)
38    (CR5_REGNO                   73)
39    (CR6_REGNO                   74)
40    (CR7_REGNO                   75)
41    (MAX_CR_REGNO                75)
42    (XER_REGNO                   76)
43    (FIRST_ALTIVEC_REGNO         77)
44    (LAST_ALTIVEC_REGNO          108)
45    (VRSAVE_REGNO                109)
46    (VSCR_REGNO                  110)
47    (SPE_ACC_REGNO               111)
48    (SPEFSCR_REGNO               112)
49    (SFP_REGNO                   113)
50   ])
51
52 ;;
53 ;; UNSPEC usage
54 ;;
55
56 (define_constants
57   [(UNSPEC_FRSP                 0)      ; frsp for POWER machines
58    (UNSPEC_TIE                  5)      ; tie stack contents and stack pointer
59    (UNSPEC_TOCPTR               6)      ; address of a word pointing to the TOC
60    (UNSPEC_TOC                  7)      ; address of the TOC (more-or-less)
61    (UNSPEC_MOVSI_GOT            8)
62    (UNSPEC_MV_CR_OV             9)      ; move_from_CR_ov_bit
63    (UNSPEC_FCTIWZ               10)
64    (UNSPEC_FRIM                 11)
65    (UNSPEC_FRIN                 12)
66    (UNSPEC_FRIP                 13)
67    (UNSPEC_FRIZ                 14)
68    (UNSPEC_LD_MPIC              15)     ; load_macho_picbase
69    (UNSPEC_MPIC_CORRECT         16)     ; macho_correct_pic
70    (UNSPEC_TLSGD                17)
71    (UNSPEC_TLSLD                18)
72    (UNSPEC_MOVESI_FROM_CR       19)
73    (UNSPEC_MOVESI_TO_CR         20)
74    (UNSPEC_TLSDTPREL            21)
75    (UNSPEC_TLSDTPRELHA          22)
76    (UNSPEC_TLSDTPRELLO          23)
77    (UNSPEC_TLSGOTDTPREL         24)
78    (UNSPEC_TLSTPREL             25)
79    (UNSPEC_TLSTPRELHA           26)
80    (UNSPEC_TLSTPRELLO           27)
81    (UNSPEC_TLSGOTTPREL          28)
82    (UNSPEC_TLSTLS               29)
83    (UNSPEC_FIX_TRUNC_TF         30)     ; fadd, rounding towards zero
84    (UNSPEC_MV_CR_GT             31)     ; move_from_CR_gt_bit
85    (UNSPEC_STFIWX               32)
86    (UNSPEC_POPCNTB              33)
87    (UNSPEC_FRES                 34)
88    (UNSPEC_SP_SET               35)
89    (UNSPEC_SP_TEST              36)
90    (UNSPEC_SYNC                 37)
91    (UNSPEC_LWSYNC               38)
92    (UNSPEC_ISYNC                39)
93    (UNSPEC_SYNC_OP              40)
94    (UNSPEC_ATOMIC               41)
95    (UNSPEC_CMPXCHG              42)
96    (UNSPEC_XCHG                 43)
97    (UNSPEC_AND                  44)
98    (UNSPEC_DLMZB                45)
99    (UNSPEC_DLMZB_CR             46)
100    (UNSPEC_DLMZB_STRLEN         47)
101    (UNSPEC_RSQRT                48)
102   ])
103
104 ;;
105 ;; UNSPEC_VOLATILE usage
106 ;;
107
108 (define_constants
109   [(UNSPECV_BLOCK               0)
110    (UNSPECV_LL                  1)      ; load-locked
111    (UNSPECV_SC                  2)      ; store-conditional
112    (UNSPECV_EH_RR               9)      ; eh_reg_restore
113   ])
114 \f
115 ;; Define an insn type attribute.  This is used in function unit delay
116 ;; computations.
117 (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,isync,sync,load_l,store_c,shift,trap,insert_dword,var_shift_rotate,cntlz,exts,mffgpr,mftgpr"
118   (const_string "integer"))
119
120 ;; Length (in bytes).
121 ; '(pc)' in the following doesn't include the instruction itself; it is
122 ; calculated as if the instruction had zero size.
123 (define_attr "length" ""
124   (if_then_else (eq_attr "type" "branch")
125                 (if_then_else (and (ge (minus (match_dup 0) (pc))
126                                        (const_int -32768))
127                                    (lt (minus (match_dup 0) (pc))
128                                        (const_int 32764)))
129                               (const_int 4)
130                               (const_int 8))
131                 (const_int 4)))
132
133 ;; Processor type -- this attribute must exactly match the processor_type
134 ;; enumeration in rs6000.h.
135
136 (define_attr "cpu" "rios1,rios2,rs64a,mpccore,ppc403,ppc405,ppc440,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,ppce300c2,ppce300c3,power4,power5,power6,cell"
137   (const (symbol_ref "rs6000_cpu_attr")))
138
139
140 ;; If this instruction is microcoded on the CELL processor
141 ; The default for load and stores is conditional
142 ; The default for load extended and the recorded instructions is always microcoded
143 (define_attr "cell_micro" "not,conditional,always"
144   (if_then_else (ior (ior (eq_attr "type" "load")
145                           (eq_attr "type" "store"))
146                      (ior (eq_attr "type" "fpload")
147                           (eq_attr "type" "fpstore")))
148                 (const_string "conditional")
149                 (if_then_else (ior (eq_attr "type" "load_ext")
150                                    (ior (eq_attr "type" "compare")
151                                         (eq_attr "type" "delayed_compare")))
152                               (const_string "always")
153                               (const_string "not"))))
154
155
156 (automata_option "ndfa")
157
158 (include "rios1.md")
159 (include "rios2.md")
160 (include "rs64.md")
161 (include "mpc.md")
162 (include "40x.md")
163 (include "440.md")
164 (include "603.md")
165 (include "6xx.md")
166 (include "7xx.md")
167 (include "7450.md")
168 (include "8540.md")
169 (include "e300c2c3.md")
170 (include "power4.md")
171 (include "power5.md")
172 (include "power6.md")
173 (include "cell.md")
174
175 (include "predicates.md")
176 (include "constraints.md")
177
178 (include "darwin.md")
179
180 \f
181 ;; Mode iterators
182
183 ; This mode iterator allows :GPR to be used to indicate the allowable size
184 ; of whole values in GPRs.
185 (define_mode_iterator GPR [SI (DI "TARGET_POWERPC64")])
186
187 ; Any supported integer mode.
188 (define_mode_iterator INT [QI HI SI DI TI])
189
190 ; Any supported integer mode that fits in one register.
191 (define_mode_iterator INT1 [QI HI SI (DI "TARGET_POWERPC64")])
192
193 ; extend modes for DImode
194 (define_mode_iterator QHSI [QI HI SI])
195
196 ; SImode or DImode, even if DImode doesn't fit in GPRs.
197 (define_mode_iterator SDI [SI DI])
198
199 ; The size of a pointer.  Also, the size of the value that a record-condition
200 ; (one with a '.') will compare.
201 (define_mode_iterator P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
202
203 ; Any hardware-supported floating-point mode
204 (define_mode_iterator FP [(SF "TARGET_HARD_FLOAT")
205   (DF "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)")
206   (TF "!TARGET_IEEEQUAD
207    && TARGET_HARD_FLOAT
208    && (TARGET_FPRS || TARGET_E500_DOUBLE)
209    && TARGET_LONG_DOUBLE_128")
210   (DD "TARGET_DFP")
211   (TD "TARGET_DFP")])
212
213 ; Various instructions that come in SI and DI forms.
214 ; A generic w/d attribute, for things like cmpw/cmpd.
215 (define_mode_attr wd [(QI "b") (HI "h") (SI "w") (DI "d")])
216
217 ; DImode bits
218 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
219
220 \f
221 ;; Start with fixed-point load and store insns.  Here we put only the more
222 ;; complex forms.  Basic data transfer is done later.
223
224 (define_expand "zero_extend<mode>di2"
225   [(set (match_operand:DI 0 "gpc_reg_operand" "")
226         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
227   "TARGET_POWERPC64"
228   "")
229
230 (define_insn "*zero_extend<mode>di2_internal1"
231   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
232         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
233   "TARGET_POWERPC64"
234   "@
235    l<wd>z%U1%X1 %0,%1
236    rldicl %0,%1,0,<dbits>"
237   [(set_attr "type" "load,*")])
238
239 (define_insn "*zero_extend<mode>di2_internal2"
240   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
241         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
242                     (const_int 0)))
243    (clobber (match_scratch:DI 2 "=r,r"))]
244   "TARGET_64BIT"
245   "@
246    rldicl. %2,%1,0,<dbits>
247    #"
248   [(set_attr "type" "compare")
249    (set_attr "length" "4,8")])
250
251 (define_split
252   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
253         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
254                     (const_int 0)))
255    (clobber (match_scratch:DI 2 ""))]
256   "TARGET_POWERPC64 && reload_completed"
257   [(set (match_dup 2)
258         (zero_extend:DI (match_dup 1)))
259    (set (match_dup 0)
260         (compare:CC (match_dup 2)
261                     (const_int 0)))]
262   "")
263
264 (define_insn "*zero_extend<mode>di2_internal3"
265   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
266         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
267                     (const_int 0)))
268    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
269         (zero_extend:DI (match_dup 1)))]
270   "TARGET_64BIT"
271   "@
272    rldicl. %0,%1,0,<dbits>
273    #"
274   [(set_attr "type" "compare")
275    (set_attr "length" "4,8")])
276
277 (define_split
278   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
279         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
280                     (const_int 0)))
281    (set (match_operand:DI 0 "gpc_reg_operand" "")
282         (zero_extend:DI (match_dup 1)))]
283   "TARGET_POWERPC64 && reload_completed"
284   [(set (match_dup 0)
285         (zero_extend:DI (match_dup 1)))
286    (set (match_dup 2)
287         (compare:CC (match_dup 0)
288                     (const_int 0)))]
289   "")
290
291 (define_insn "extendqidi2"
292   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
293         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
294   "TARGET_POWERPC64"
295   "extsb %0,%1"
296   [(set_attr "type" "exts")])
297
298 (define_insn ""
299   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
300         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
301                     (const_int 0)))
302    (clobber (match_scratch:DI 2 "=r,r"))]
303   "TARGET_64BIT"
304   "@
305    extsb. %2,%1
306    #"
307   [(set_attr "type" "compare")
308    (set_attr "length" "4,8")])
309
310 (define_split
311   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
312         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
313                     (const_int 0)))
314    (clobber (match_scratch:DI 2 ""))]
315   "TARGET_POWERPC64 && reload_completed"
316   [(set (match_dup 2)
317         (sign_extend:DI (match_dup 1)))
318    (set (match_dup 0)
319         (compare:CC (match_dup 2)
320                     (const_int 0)))]
321   "")
322
323 (define_insn ""
324   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
325         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
326                     (const_int 0)))
327    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
328         (sign_extend:DI (match_dup 1)))]
329   "TARGET_64BIT"
330   "@
331    extsb. %0,%1
332    #"
333   [(set_attr "type" "compare")
334    (set_attr "length" "4,8")])
335
336 (define_split
337   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
338         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
339                     (const_int 0)))
340    (set (match_operand:DI 0 "gpc_reg_operand" "")
341         (sign_extend:DI (match_dup 1)))]
342   "TARGET_POWERPC64 && reload_completed"
343   [(set (match_dup 0)
344         (sign_extend:DI (match_dup 1)))
345    (set (match_dup 2)
346         (compare:CC (match_dup 0)
347                     (const_int 0)))]
348   "")
349
350 (define_expand "extendhidi2"
351   [(set (match_operand:DI 0 "gpc_reg_operand" "")
352         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
353   "TARGET_POWERPC64"
354   "")
355
356 (define_insn ""
357   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
358         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
359   "TARGET_POWERPC64"
360   "@
361    lha%U1%X1 %0,%1
362    extsh %0,%1"
363   [(set_attr "type" "load_ext,exts")])
364
365 (define_insn ""
366   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
367         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
368                     (const_int 0)))
369    (clobber (match_scratch:DI 2 "=r,r"))]
370   "TARGET_64BIT"
371   "@
372    extsh. %2,%1
373    #"
374   [(set_attr "type" "compare")
375    (set_attr "length" "4,8")])
376
377 (define_split
378   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
379         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
380                     (const_int 0)))
381    (clobber (match_scratch:DI 2 ""))]
382   "TARGET_POWERPC64 && reload_completed"
383   [(set (match_dup 2)
384         (sign_extend:DI (match_dup 1)))
385    (set (match_dup 0)
386         (compare:CC (match_dup 2)
387                     (const_int 0)))]
388   "")
389
390 (define_insn ""
391   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
392         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
393                     (const_int 0)))
394    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
395         (sign_extend:DI (match_dup 1)))]
396   "TARGET_64BIT"
397   "@
398    extsh. %0,%1
399    #"
400   [(set_attr "type" "compare")
401    (set_attr "length" "4,8")])
402
403 (define_split
404   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
405         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
406                     (const_int 0)))
407    (set (match_operand:DI 0 "gpc_reg_operand" "")
408         (sign_extend:DI (match_dup 1)))]
409   "TARGET_POWERPC64 && reload_completed"
410   [(set (match_dup 0)
411         (sign_extend:DI (match_dup 1)))
412    (set (match_dup 2)
413         (compare:CC (match_dup 0)
414                     (const_int 0)))]
415   "")
416
417 (define_expand "extendsidi2"
418   [(set (match_operand:DI 0 "gpc_reg_operand" "")
419         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
420   "TARGET_POWERPC64"
421   "")
422
423 (define_insn ""
424   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
425         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
426   "TARGET_POWERPC64"
427   "@
428    lwa%U1%X1 %0,%1
429    extsw %0,%1"
430   [(set_attr "type" "load_ext,exts")])
431
432 (define_insn ""
433   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
434         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
435                     (const_int 0)))
436    (clobber (match_scratch:DI 2 "=r,r"))]
437   "TARGET_64BIT"
438   "@
439    extsw. %2,%1
440    #"
441   [(set_attr "type" "compare")
442    (set_attr "length" "4,8")])
443
444 (define_split
445   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
446         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
447                     (const_int 0)))
448    (clobber (match_scratch:DI 2 ""))]
449   "TARGET_POWERPC64 && reload_completed"
450   [(set (match_dup 2)
451         (sign_extend:DI (match_dup 1)))
452    (set (match_dup 0)
453         (compare:CC (match_dup 2)
454                     (const_int 0)))]
455   "")
456
457 (define_insn ""
458   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
459         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
460                     (const_int 0)))
461    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
462         (sign_extend:DI (match_dup 1)))]
463   "TARGET_64BIT"
464   "@
465    extsw. %0,%1
466    #"
467   [(set_attr "type" "compare")
468    (set_attr "length" "4,8")])
469
470 (define_split
471   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
472         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
473                     (const_int 0)))
474    (set (match_operand:DI 0 "gpc_reg_operand" "")
475         (sign_extend:DI (match_dup 1)))]
476   "TARGET_POWERPC64 && reload_completed"
477   [(set (match_dup 0)
478         (sign_extend:DI (match_dup 1)))
479    (set (match_dup 2)
480         (compare:CC (match_dup 0)
481                     (const_int 0)))]
482   "")
483
484 (define_expand "zero_extendqisi2"
485   [(set (match_operand:SI 0 "gpc_reg_operand" "")
486         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
487   ""
488   "")
489
490 (define_insn ""
491   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
492         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
493   ""
494   "@
495    lbz%U1%X1 %0,%1
496    {rlinm|rlwinm} %0,%1,0,0xff"
497   [(set_attr "type" "load,*")])
498
499 (define_insn ""
500   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
501         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
502                     (const_int 0)))
503    (clobber (match_scratch:SI 2 "=r,r"))]
504   ""
505   "@
506    {andil.|andi.} %2,%1,0xff
507    #"
508   [(set_attr "type" "compare")
509    (set_attr "length" "4,8")])
510
511 (define_split
512   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
513         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
514                     (const_int 0)))
515    (clobber (match_scratch:SI 2 ""))]
516   "reload_completed"
517   [(set (match_dup 2)
518         (zero_extend:SI (match_dup 1)))
519    (set (match_dup 0)
520         (compare:CC (match_dup 2)
521                     (const_int 0)))]
522   "")
523
524 (define_insn ""
525   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
526         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
527                     (const_int 0)))
528    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
529         (zero_extend:SI (match_dup 1)))]
530   ""
531   "@
532    {andil.|andi.} %0,%1,0xff
533    #"
534   [(set_attr "type" "compare")
535    (set_attr "length" "4,8")])
536
537 (define_split
538   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
539         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
540                     (const_int 0)))
541    (set (match_operand:SI 0 "gpc_reg_operand" "")
542         (zero_extend:SI (match_dup 1)))]
543   "reload_completed"
544   [(set (match_dup 0)
545         (zero_extend:SI (match_dup 1)))
546    (set (match_dup 2)
547         (compare:CC (match_dup 0)
548                     (const_int 0)))]
549   "")
550
551 (define_expand "extendqisi2"
552   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
553    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
554   ""
555   "
556 {
557   if (TARGET_POWERPC)
558     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
559   else if (TARGET_POWER)
560     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
561   else
562     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
563   DONE;
564 }")
565
566 (define_insn "extendqisi2_ppc"
567   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
568         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
569   "TARGET_POWERPC"
570   "extsb %0,%1"
571   [(set_attr "type" "exts")])
572
573 (define_insn ""
574   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
575         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
576                     (const_int 0)))
577    (clobber (match_scratch:SI 2 "=r,r"))]
578   "TARGET_POWERPC"
579   "@
580    extsb. %2,%1
581    #"
582   [(set_attr "type" "compare")
583    (set_attr "length" "4,8")])
584
585 (define_split
586   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
587         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
588                     (const_int 0)))
589    (clobber (match_scratch:SI 2 ""))]
590   "TARGET_POWERPC && reload_completed"
591   [(set (match_dup 2)
592         (sign_extend:SI (match_dup 1)))
593    (set (match_dup 0)
594         (compare:CC (match_dup 2)
595                     (const_int 0)))]
596   "")
597
598 (define_insn ""
599   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
600         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
601                     (const_int 0)))
602    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
603         (sign_extend:SI (match_dup 1)))]
604   "TARGET_POWERPC"
605   "@
606    extsb. %0,%1
607    #"
608   [(set_attr "type" "compare")
609    (set_attr "length" "4,8")])
610
611 (define_split
612   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
613         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
614                     (const_int 0)))
615    (set (match_operand:SI 0 "gpc_reg_operand" "")
616         (sign_extend:SI (match_dup 1)))]
617   "TARGET_POWERPC && reload_completed"
618   [(set (match_dup 0)
619         (sign_extend:SI (match_dup 1)))
620    (set (match_dup 2)
621         (compare:CC (match_dup 0)
622                     (const_int 0)))]
623   "")
624
625 (define_expand "extendqisi2_power"
626   [(parallel [(set (match_dup 2)
627                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
628                               (const_int 24)))
629               (clobber (scratch:SI))])
630    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
631                    (ashiftrt:SI (match_dup 2)
632                                 (const_int 24)))
633               (clobber (scratch:SI))])]
634   "TARGET_POWER"
635   "
636 { operands[1] = gen_lowpart (SImode, operands[1]);
637   operands[2] = gen_reg_rtx (SImode); }")
638
639 (define_expand "extendqisi2_no_power"
640   [(set (match_dup 2)
641         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
642                    (const_int 24)))
643    (set (match_operand:SI 0 "gpc_reg_operand" "")
644         (ashiftrt:SI (match_dup 2)
645                      (const_int 24)))]
646   "! TARGET_POWER && ! TARGET_POWERPC"
647   "
648 { operands[1] = gen_lowpart (SImode, operands[1]);
649   operands[2] = gen_reg_rtx (SImode); }")
650
651 (define_expand "zero_extendqihi2"
652   [(set (match_operand:HI 0 "gpc_reg_operand" "")
653         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
654   ""
655   "")
656
657 (define_insn ""
658   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
659         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
660   ""
661   "@
662    lbz%U1%X1 %0,%1
663    {rlinm|rlwinm} %0,%1,0,0xff"
664   [(set_attr "type" "load,*")])
665
666 (define_insn ""
667   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
668         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
669                     (const_int 0)))
670    (clobber (match_scratch:HI 2 "=r,r"))]
671   ""
672   "@
673    {andil.|andi.} %2,%1,0xff
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_cr0_operand" "")
680         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
681                     (const_int 0)))
682    (clobber (match_scratch:HI 2 ""))]
683   "reload_completed"
684   [(set (match_dup 2)
685         (zero_extend:HI (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 (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
694                     (const_int 0)))
695    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
696         (zero_extend:HI (match_dup 1)))]
697   ""
698   "@
699    {andil.|andi.} %0,%1,0xff
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_cr0_operand" "")
706         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
707                     (const_int 0)))
708    (set (match_operand:HI 0 "gpc_reg_operand" "")
709         (zero_extend:HI (match_dup 1)))]
710   "reload_completed"
711   [(set (match_dup 0)
712         (zero_extend:HI (match_dup 1)))
713    (set (match_dup 2)
714         (compare:CC (match_dup 0)
715                     (const_int 0)))]
716   "")
717
718 (define_expand "extendqihi2"
719   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
720    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
721   ""
722   "
723 {
724   if (TARGET_POWERPC)
725     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
726   else if (TARGET_POWER)
727     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
728   else
729     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
730   DONE;
731 }")
732
733 (define_insn "extendqihi2_ppc"
734   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
735         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
736   "TARGET_POWERPC"
737   "extsb %0,%1"
738   [(set_attr "type" "exts")])
739
740 (define_insn ""
741   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
742         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
743                     (const_int 0)))
744    (clobber (match_scratch:HI 2 "=r,r"))]
745   "TARGET_POWERPC"
746   "@
747    extsb. %2,%1
748    #"
749   [(set_attr "type" "compare")
750    (set_attr "length" "4,8")])
751
752 (define_split
753   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
754         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
755                     (const_int 0)))
756    (clobber (match_scratch:HI 2 ""))]
757   "TARGET_POWERPC && reload_completed"
758   [(set (match_dup 2)
759         (sign_extend:HI (match_dup 1)))
760    (set (match_dup 0)
761         (compare:CC (match_dup 2)
762                     (const_int 0)))]
763   "")
764
765 (define_insn ""
766   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
767         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
768                     (const_int 0)))
769    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
770         (sign_extend:HI (match_dup 1)))]
771   "TARGET_POWERPC"
772   "@
773    extsb. %0,%1
774    #"
775   [(set_attr "type" "compare")
776    (set_attr "length" "4,8")])
777
778 (define_split
779   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
780         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
781                     (const_int 0)))
782    (set (match_operand:HI 0 "gpc_reg_operand" "")
783         (sign_extend:HI (match_dup 1)))]
784   "TARGET_POWERPC && reload_completed"
785   [(set (match_dup 0)
786         (sign_extend:HI (match_dup 1)))
787    (set (match_dup 2)
788         (compare:CC (match_dup 0)
789                     (const_int 0)))]
790   "")
791
792 (define_expand "extendqihi2_power"
793   [(parallel [(set (match_dup 2)
794                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
795                               (const_int 24)))
796               (clobber (scratch:SI))])
797    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
798                    (ashiftrt:SI (match_dup 2)
799                                 (const_int 24)))
800               (clobber (scratch:SI))])]
801   "TARGET_POWER"
802   "
803 { operands[0] = gen_lowpart (SImode, operands[0]);
804   operands[1] = gen_lowpart (SImode, operands[1]);
805   operands[2] = gen_reg_rtx (SImode); }")
806
807 (define_expand "extendqihi2_no_power"
808   [(set (match_dup 2)
809         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
810                    (const_int 24)))
811    (set (match_operand:HI 0 "gpc_reg_operand" "")
812         (ashiftrt:SI (match_dup 2)
813                      (const_int 24)))]
814   "! TARGET_POWER && ! TARGET_POWERPC"
815   "
816 { operands[0] = gen_lowpart (SImode, operands[0]);
817   operands[1] = gen_lowpart (SImode, operands[1]);
818   operands[2] = gen_reg_rtx (SImode); }")
819
820 (define_expand "zero_extendhisi2"
821   [(set (match_operand:SI 0 "gpc_reg_operand" "")
822         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
823   ""
824   "")
825
826 (define_insn ""
827   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
828         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
829   ""
830   "@
831    lhz%U1%X1 %0,%1
832    {rlinm|rlwinm} %0,%1,0,0xffff"
833   [(set_attr "type" "load,*")])
834
835 (define_insn ""
836   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
837         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
838                     (const_int 0)))
839    (clobber (match_scratch:SI 2 "=r,r"))]
840   ""
841   "@
842    {andil.|andi.} %2,%1,0xffff
843    #"
844   [(set_attr "type" "compare")
845    (set_attr "length" "4,8")])
846
847 (define_split
848   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
849         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
850                     (const_int 0)))
851    (clobber (match_scratch:SI 2 ""))]
852   "reload_completed"
853   [(set (match_dup 2)
854         (zero_extend:SI (match_dup 1)))
855    (set (match_dup 0)
856         (compare:CC (match_dup 2)
857                     (const_int 0)))]
858   "")
859
860 (define_insn ""
861   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
862         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
863                     (const_int 0)))
864    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
865         (zero_extend:SI (match_dup 1)))]
866   ""
867   "@
868    {andil.|andi.} %0,%1,0xffff
869    #"
870   [(set_attr "type" "compare")
871    (set_attr "length" "4,8")])
872
873 (define_split
874   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
875         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
876                     (const_int 0)))
877    (set (match_operand:SI 0 "gpc_reg_operand" "")
878         (zero_extend:SI (match_dup 1)))]
879   "reload_completed"
880   [(set (match_dup 0)
881         (zero_extend:SI (match_dup 1)))
882    (set (match_dup 2)
883         (compare:CC (match_dup 0)
884                     (const_int 0)))]
885   "")
886
887 (define_expand "extendhisi2"
888   [(set (match_operand:SI 0 "gpc_reg_operand" "")
889         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
890   ""
891   "")
892
893 (define_insn ""
894   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
895         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
896   ""
897   "@
898    lha%U1%X1 %0,%1
899    {exts|extsh} %0,%1"
900   [(set_attr "type" "load_ext,exts")])
901
902 (define_insn ""
903   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
904         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
905                     (const_int 0)))
906    (clobber (match_scratch:SI 2 "=r,r"))]
907   ""
908   "@
909    {exts.|extsh.} %2,%1
910    #"
911   [(set_attr "type" "compare")
912    (set_attr "length" "4,8")])
913
914 (define_split
915   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
916         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
917                     (const_int 0)))
918    (clobber (match_scratch:SI 2 ""))]
919   "reload_completed"
920   [(set (match_dup 2)
921         (sign_extend:SI (match_dup 1)))
922    (set (match_dup 0)
923         (compare:CC (match_dup 2)
924                     (const_int 0)))]
925   "")
926
927 (define_insn ""
928   [(set (match_operand:CC 2 "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    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
932         (sign_extend:SI (match_dup 1)))]
933   ""
934   "@
935    {exts.|extsh.} %0,%1
936    #"
937   [(set_attr "type" "compare")
938    (set_attr "length" "4,8")])
939 \f
940 ;; IBM 405 and 440 half-word multiplication operations.
941
942 (define_insn "*macchwc"
943   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
944         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
945                                        (match_operand:SI 2 "gpc_reg_operand" "r")
946                                        (const_int 16))
947                                       (sign_extend:SI
948                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
949                              (match_operand:SI 4 "gpc_reg_operand" "0"))
950                     (const_int 0)))
951    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
952         (plus:SI (mult:SI (ashiftrt:SI
953                            (match_dup 2)
954                            (const_int 16))
955                           (sign_extend:SI
956                            (match_dup 1)))
957                  (match_dup 4)))]
958   "TARGET_MULHW"
959   "macchw. %0, %1, %2"
960   [(set_attr "type" "imul3")])
961
962 (define_insn "*macchw"
963   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
964         (plus:SI (mult:SI (ashiftrt:SI
965                            (match_operand:SI 2 "gpc_reg_operand" "r")
966                            (const_int 16))
967                           (sign_extend:SI
968                            (match_operand:HI 1 "gpc_reg_operand" "r")))
969                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
970   "TARGET_MULHW"
971   "macchw %0, %1, %2"
972   [(set_attr "type" "imul3")])
973
974 (define_insn "*macchwuc"
975   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
976         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
977                                        (match_operand:SI 2 "gpc_reg_operand" "r")
978                                        (const_int 16))
979                                       (zero_extend:SI
980                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
981                              (match_operand:SI 4 "gpc_reg_operand" "0"))
982                     (const_int 0)))
983    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
984         (plus:SI (mult:SI (lshiftrt:SI
985                            (match_dup 2)
986                            (const_int 16))
987                           (zero_extend:SI
988                            (match_dup 1)))
989                  (match_dup 4)))]
990   "TARGET_MULHW"
991   "macchwu. %0, %1, %2"
992   [(set_attr "type" "imul3")])
993
994 (define_insn "*macchwu"
995   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
996         (plus:SI (mult:SI (lshiftrt:SI
997                            (match_operand:SI 2 "gpc_reg_operand" "r")
998                            (const_int 16))
999                           (zero_extend:SI
1000                            (match_operand:HI 1 "gpc_reg_operand" "r")))
1001                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1002   "TARGET_MULHW"
1003   "macchwu %0, %1, %2"
1004   [(set_attr "type" "imul3")])
1005
1006 (define_insn "*machhwc"
1007   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1008         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1009                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1010                                        (const_int 16))
1011                                       (ashiftrt:SI
1012                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1013                                        (const_int 16)))
1014                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1015                     (const_int 0)))
1016    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1017         (plus:SI (mult:SI (ashiftrt:SI
1018                            (match_dup 1)
1019                            (const_int 16))
1020                           (ashiftrt:SI
1021                            (match_dup 2)
1022                            (const_int 16)))
1023                  (match_dup 4)))]
1024   "TARGET_MULHW"
1025   "machhw. %0, %1, %2"
1026   [(set_attr "type" "imul3")])
1027
1028 (define_insn "*machhw"
1029   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1030         (plus:SI (mult:SI (ashiftrt:SI
1031                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1032                            (const_int 16))
1033                           (ashiftrt:SI
1034                            (match_operand:SI 2 "gpc_reg_operand" "r")
1035                            (const_int 16)))
1036                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1037   "TARGET_MULHW"
1038   "machhw %0, %1, %2"
1039   [(set_attr "type" "imul3")])
1040
1041 (define_insn "*machhwuc"
1042   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1043         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1044                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
1045                                        (const_int 16))
1046                                       (lshiftrt:SI
1047                                        (match_operand:SI 2 "gpc_reg_operand" "r")
1048                                        (const_int 16)))
1049                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1050                     (const_int 0)))
1051    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1052         (plus:SI (mult:SI (lshiftrt:SI
1053                            (match_dup 1)
1054                            (const_int 16))
1055                           (lshiftrt:SI
1056                            (match_dup 2)
1057                            (const_int 16)))
1058                  (match_dup 4)))]
1059   "TARGET_MULHW"
1060   "machhwu. %0, %1, %2"
1061   [(set_attr "type" "imul3")])
1062
1063 (define_insn "*machhwu"
1064   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1065         (plus:SI (mult:SI (lshiftrt:SI
1066                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1067                            (const_int 16))
1068                           (lshiftrt:SI
1069                            (match_operand:SI 2 "gpc_reg_operand" "r")
1070                            (const_int 16)))
1071                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1072   "TARGET_MULHW"
1073   "machhwu %0, %1, %2"
1074   [(set_attr "type" "imul3")])
1075
1076 (define_insn "*maclhwc"
1077   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1078         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1079                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1080                                       (sign_extend:SI
1081                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1082                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1083                     (const_int 0)))
1084    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1085         (plus:SI (mult:SI (sign_extend:SI
1086                            (match_dup 1))
1087                           (sign_extend:SI
1088                            (match_dup 2)))
1089                  (match_dup 4)))]
1090   "TARGET_MULHW"
1091   "maclhw. %0, %1, %2"
1092   [(set_attr "type" "imul3")])
1093
1094 (define_insn "*maclhw"
1095   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1096         (plus:SI (mult:SI (sign_extend:SI
1097                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1098                           (sign_extend:SI
1099                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1100                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1101   "TARGET_MULHW"
1102   "maclhw %0, %1, %2"
1103   [(set_attr "type" "imul3")])
1104
1105 (define_insn "*maclhwuc"
1106   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1107         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1108                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1109                                       (zero_extend:SI
1110                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1111                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1112                     (const_int 0)))
1113    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1114         (plus:SI (mult:SI (zero_extend:SI
1115                            (match_dup 1))
1116                           (zero_extend:SI
1117                            (match_dup 2)))
1118                  (match_dup 4)))]
1119   "TARGET_MULHW"
1120   "maclhwu. %0, %1, %2"
1121   [(set_attr "type" "imul3")])
1122
1123 (define_insn "*maclhwu"
1124   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1125         (plus:SI (mult:SI (zero_extend:SI
1126                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1127                           (zero_extend:SI
1128                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1129                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1130   "TARGET_MULHW"
1131   "maclhwu %0, %1, %2"
1132   [(set_attr "type" "imul3")])
1133
1134 (define_insn "*nmacchwc"
1135   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1136         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1137                               (mult:SI (ashiftrt:SI
1138                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1139                                         (const_int 16))
1140                                        (sign_extend:SI
1141                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1142                     (const_int 0)))
1143    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1144         (minus:SI (match_dup 4)
1145                   (mult:SI (ashiftrt:SI
1146                             (match_dup 2)
1147                             (const_int 16))
1148                            (sign_extend:SI
1149                             (match_dup 1)))))]
1150   "TARGET_MULHW"
1151   "nmacchw. %0, %1, %2"
1152   [(set_attr "type" "imul3")])
1153
1154 (define_insn "*nmacchw"
1155   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1156         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1157                   (mult:SI (ashiftrt:SI
1158                             (match_operand:SI 2 "gpc_reg_operand" "r")
1159                             (const_int 16))
1160                            (sign_extend:SI
1161                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1162   "TARGET_MULHW"
1163   "nmacchw %0, %1, %2"
1164   [(set_attr "type" "imul3")])
1165
1166 (define_insn "*nmachhwc"
1167   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1168         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1169                               (mult:SI (ashiftrt:SI
1170                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1171                                         (const_int 16))
1172                                        (ashiftrt:SI
1173                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1174                                         (const_int 16))))
1175                     (const_int 0)))
1176    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1177         (minus:SI (match_dup 4)
1178                   (mult:SI (ashiftrt:SI
1179                             (match_dup 1)
1180                             (const_int 16))
1181                            (ashiftrt:SI
1182                             (match_dup 2)
1183                             (const_int 16)))))]
1184   "TARGET_MULHW"
1185   "nmachhw. %0, %1, %2"
1186   [(set_attr "type" "imul3")])
1187
1188 (define_insn "*nmachhw"
1189   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1190         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1191                   (mult:SI (ashiftrt:SI
1192                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1193                             (const_int 16))
1194                            (ashiftrt:SI
1195                             (match_operand:SI 2 "gpc_reg_operand" "r")
1196                             (const_int 16)))))]
1197   "TARGET_MULHW"
1198   "nmachhw %0, %1, %2"
1199   [(set_attr "type" "imul3")])
1200
1201 (define_insn "*nmaclhwc"
1202   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1203         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1204                               (mult:SI (sign_extend:SI
1205                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1206                                        (sign_extend:SI
1207                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1208                     (const_int 0)))
1209    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1210         (minus:SI (match_dup 4)
1211                   (mult:SI (sign_extend:SI
1212                             (match_dup 1))
1213                            (sign_extend:SI
1214                             (match_dup 2)))))]
1215   "TARGET_MULHW"
1216   "nmaclhw. %0, %1, %2"
1217   [(set_attr "type" "imul3")])
1218
1219 (define_insn "*nmaclhw"
1220   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1221         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1222                   (mult:SI (sign_extend:SI
1223                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1224                            (sign_extend:SI
1225                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1226   "TARGET_MULHW"
1227   "nmaclhw %0, %1, %2"
1228   [(set_attr "type" "imul3")])
1229
1230 (define_insn "*mulchwc"
1231   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1232         (compare:CC (mult:SI (ashiftrt:SI
1233                               (match_operand:SI 2 "gpc_reg_operand" "r")
1234                               (const_int 16))
1235                              (sign_extend:SI
1236                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1237                     (const_int 0)))
1238    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1239         (mult:SI (ashiftrt:SI
1240                   (match_dup 2)
1241                   (const_int 16))
1242                  (sign_extend:SI
1243                   (match_dup 1))))]
1244   "TARGET_MULHW"
1245   "mulchw. %0, %1, %2"
1246   [(set_attr "type" "imul3")])
1247
1248 (define_insn "*mulchw"
1249   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1250         (mult:SI (ashiftrt:SI
1251                   (match_operand:SI 2 "gpc_reg_operand" "r")
1252                   (const_int 16))
1253                  (sign_extend:SI
1254                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1255   "TARGET_MULHW"
1256   "mulchw %0, %1, %2"
1257   [(set_attr "type" "imul3")])
1258
1259 (define_insn "*mulchwuc"
1260   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1261         (compare:CC (mult:SI (lshiftrt:SI
1262                               (match_operand:SI 2 "gpc_reg_operand" "r")
1263                               (const_int 16))
1264                              (zero_extend:SI
1265                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1266                     (const_int 0)))
1267    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1268         (mult:SI (lshiftrt:SI
1269                   (match_dup 2)
1270                   (const_int 16))
1271                  (zero_extend:SI
1272                   (match_dup 1))))]
1273   "TARGET_MULHW"
1274   "mulchwu. %0, %1, %2"
1275   [(set_attr "type" "imul3")])
1276
1277 (define_insn "*mulchwu"
1278   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1279         (mult:SI (lshiftrt:SI
1280                   (match_operand:SI 2 "gpc_reg_operand" "r")
1281                   (const_int 16))
1282                  (zero_extend:SI
1283                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1284   "TARGET_MULHW"
1285   "mulchwu %0, %1, %2"
1286   [(set_attr "type" "imul3")])
1287
1288 (define_insn "*mulhhwc"
1289   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1290         (compare:CC (mult:SI (ashiftrt:SI
1291                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1292                               (const_int 16))
1293                              (ashiftrt:SI
1294                               (match_operand:SI 2 "gpc_reg_operand" "r")
1295                               (const_int 16)))
1296                     (const_int 0)))
1297    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1298         (mult:SI (ashiftrt:SI
1299                   (match_dup 1)
1300                   (const_int 16))
1301                  (ashiftrt:SI
1302                   (match_dup 2)
1303                   (const_int 16))))]
1304   "TARGET_MULHW"
1305   "mulhhw. %0, %1, %2"
1306   [(set_attr "type" "imul3")])
1307
1308 (define_insn "*mulhhw"
1309   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1310         (mult:SI (ashiftrt:SI
1311                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1312                   (const_int 16))
1313                  (ashiftrt:SI
1314                   (match_operand:SI 2 "gpc_reg_operand" "r")
1315                   (const_int 16))))]
1316   "TARGET_MULHW"
1317   "mulhhw %0, %1, %2"
1318   [(set_attr "type" "imul3")])
1319
1320 (define_insn "*mulhhwuc"
1321   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1322         (compare:CC (mult:SI (lshiftrt:SI
1323                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1324                               (const_int 16))
1325                              (lshiftrt:SI
1326                               (match_operand:SI 2 "gpc_reg_operand" "r")
1327                               (const_int 16)))
1328                     (const_int 0)))
1329    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1330         (mult:SI (lshiftrt:SI
1331                   (match_dup 1)
1332                   (const_int 16))
1333                  (lshiftrt:SI
1334                   (match_dup 2)
1335                   (const_int 16))))]
1336   "TARGET_MULHW"
1337   "mulhhwu. %0, %1, %2"
1338   [(set_attr "type" "imul3")])
1339
1340 (define_insn "*mulhhwu"
1341   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1342         (mult:SI (lshiftrt:SI
1343                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1344                   (const_int 16))
1345                  (lshiftrt:SI
1346                   (match_operand:SI 2 "gpc_reg_operand" "r")
1347                   (const_int 16))))]
1348   "TARGET_MULHW"
1349   "mulhhwu %0, %1, %2"
1350   [(set_attr "type" "imul3")])
1351
1352 (define_insn "*mullhwc"
1353   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1354         (compare:CC (mult:SI (sign_extend:SI
1355                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1356                              (sign_extend:SI
1357                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1358                     (const_int 0)))
1359    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1360         (mult:SI (sign_extend:SI
1361                   (match_dup 1))
1362                  (sign_extend:SI
1363                   (match_dup 2))))]
1364   "TARGET_MULHW"
1365   "mullhw. %0, %1, %2"
1366   [(set_attr "type" "imul3")])
1367
1368 (define_insn "*mullhw"
1369   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1370         (mult:SI (sign_extend:SI
1371                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1372                  (sign_extend:SI
1373                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1374   "TARGET_MULHW"
1375   "mullhw %0, %1, %2"
1376   [(set_attr "type" "imul3")])
1377
1378 (define_insn "*mullhwuc"
1379   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1380         (compare:CC (mult:SI (zero_extend:SI
1381                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1382                              (zero_extend:SI
1383                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1384                     (const_int 0)))
1385    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1386         (mult:SI (zero_extend:SI
1387                   (match_dup 1))
1388                  (zero_extend:SI
1389                   (match_dup 2))))]
1390   "TARGET_MULHW"
1391   "mullhwu. %0, %1, %2"
1392   [(set_attr "type" "imul3")])
1393
1394 (define_insn "*mullhwu"
1395   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1396         (mult:SI (zero_extend:SI
1397                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1398                  (zero_extend:SI
1399                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1400   "TARGET_MULHW"
1401   "mullhwu %0, %1, %2"
1402   [(set_attr "type" "imul3")])
1403 \f
1404 ;; IBM 405 and 440 string-search dlmzb instruction support.
1405 (define_insn "dlmzb"
1406   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1407         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1408                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1409                    UNSPEC_DLMZB_CR))
1410    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1411         (unspec:SI [(match_dup 1)
1412                     (match_dup 2)]
1413                    UNSPEC_DLMZB))]
1414   "TARGET_DLMZB"
1415   "dlmzb. %0, %1, %2")
1416
1417 (define_expand "strlensi"
1418   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1419         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1420                     (match_operand:QI 2 "const_int_operand" "")
1421                     (match_operand 3 "const_int_operand" "")]
1422                    UNSPEC_DLMZB_STRLEN))
1423    (clobber (match_scratch:CC 4 "=x"))]
1424   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1425 {
1426   rtx result = operands[0];
1427   rtx src = operands[1];
1428   rtx search_char = operands[2];
1429   rtx align = operands[3];
1430   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1431   rtx loop_label, end_label, mem, cr0, cond;
1432   if (search_char != const0_rtx
1433       || GET_CODE (align) != CONST_INT
1434       || INTVAL (align) < 8)
1435         FAIL;
1436   word1 = gen_reg_rtx (SImode);
1437   word2 = gen_reg_rtx (SImode);
1438   scratch_dlmzb = gen_reg_rtx (SImode);
1439   scratch_string = gen_reg_rtx (Pmode);
1440   loop_label = gen_label_rtx ();
1441   end_label = gen_label_rtx ();
1442   addr = force_reg (Pmode, XEXP (src, 0));
1443   emit_move_insn (scratch_string, addr);
1444   emit_label (loop_label);
1445   mem = change_address (src, SImode, scratch_string);
1446   emit_move_insn (word1, mem);
1447   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1448   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1449   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1450   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1451   emit_jump_insn (gen_rtx_SET (VOIDmode,
1452                                pc_rtx,
1453                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1454                                                      cond,
1455                                                      gen_rtx_LABEL_REF
1456                                                        (VOIDmode,
1457                                                         end_label),
1458                                                      pc_rtx)));
1459   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1460   emit_jump_insn (gen_rtx_SET (VOIDmode,
1461                                pc_rtx,
1462                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1463   emit_barrier ();
1464   emit_label (end_label);
1465   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1466   emit_insn (gen_subsi3 (result, scratch_string, addr));
1467   emit_insn (gen_subsi3 (result, result, const1_rtx));
1468   DONE;
1469 })
1470 \f
1471 (define_split
1472   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1473         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1474                     (const_int 0)))
1475    (set (match_operand:SI 0 "gpc_reg_operand" "")
1476         (sign_extend:SI (match_dup 1)))]
1477   "reload_completed"
1478   [(set (match_dup 0)
1479         (sign_extend:SI (match_dup 1)))
1480    (set (match_dup 2)
1481         (compare:CC (match_dup 0)
1482                     (const_int 0)))]
1483   "")
1484
1485 ;; Fixed-point arithmetic insns.
1486
1487 (define_expand "add<mode>3"
1488   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1489         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1490                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1491   ""
1492 {
1493   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1494     {
1495       if (non_short_cint_operand (operands[2], DImode))
1496         FAIL;
1497     }
1498   else if (GET_CODE (operands[2]) == CONST_INT
1499            && ! add_operand (operands[2], <MODE>mode))
1500     {
1501       rtx tmp = ((!can_create_pseudo_p ()
1502                   || rtx_equal_p (operands[0], operands[1]))
1503                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1504
1505       HOST_WIDE_INT val = INTVAL (operands[2]);
1506       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1507       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1508
1509       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1510         FAIL;
1511
1512       /* The ordering here is important for the prolog expander.
1513          When space is allocated from the stack, adding 'low' first may
1514          produce a temporary deallocation (which would be bad).  */
1515       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1516       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1517       DONE;
1518     }
1519 })
1520
1521 ;; Discourage ai/addic because of carry but provide it in an alternative
1522 ;; allowing register zero as source.
1523 (define_insn "*add<mode>3_internal1"
1524   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1525         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1526                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1527   "!DECIMAL_FLOAT_MODE_P (GET_MODE (operands[0])) && !DECIMAL_FLOAT_MODE_P (GET_MODE (operands[1]))"
1528   "@
1529    {cax|add} %0,%1,%2
1530    {cal %0,%2(%1)|addi %0,%1,%2}
1531    {ai|addic} %0,%1,%2
1532    {cau|addis} %0,%1,%v2"
1533   [(set_attr "length" "4,4,4,4")])
1534
1535 (define_insn "addsi3_high"
1536   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1537         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1538                  (high:SI (match_operand 2 "" ""))))]
1539   "TARGET_MACHO && !TARGET_64BIT"
1540   "{cau|addis} %0,%1,ha16(%2)"
1541   [(set_attr "length" "4")])
1542
1543 (define_insn "*add<mode>3_internal2"
1544   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1545         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1546                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1547                     (const_int 0)))
1548    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1549   ""
1550   "@
1551    {cax.|add.} %3,%1,%2
1552    {ai.|addic.} %3,%1,%2
1553    #
1554    #"
1555   [(set_attr "type" "fast_compare,compare,compare,compare")
1556    (set_attr "length" "4,4,8,8")])
1557
1558 (define_split
1559   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1560         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1561                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1562                     (const_int 0)))
1563    (clobber (match_scratch:GPR 3 ""))]
1564   "reload_completed"
1565   [(set (match_dup 3)
1566         (plus:GPR (match_dup 1)
1567                  (match_dup 2)))
1568    (set (match_dup 0)
1569         (compare:CC (match_dup 3)
1570                     (const_int 0)))]
1571   "")
1572
1573 (define_insn "*add<mode>3_internal3"
1574   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1575         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1576                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1577                     (const_int 0)))
1578    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1579         (plus:P (match_dup 1)
1580                 (match_dup 2)))]
1581   ""
1582   "@
1583    {cax.|add.} %0,%1,%2
1584    {ai.|addic.} %0,%1,%2
1585    #
1586    #"
1587   [(set_attr "type" "fast_compare,compare,compare,compare")
1588    (set_attr "length" "4,4,8,8")])
1589
1590 (define_split
1591   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1592         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1593                             (match_operand:P 2 "reg_or_short_operand" ""))
1594                     (const_int 0)))
1595    (set (match_operand:P 0 "gpc_reg_operand" "")
1596         (plus:P (match_dup 1) (match_dup 2)))]
1597   "reload_completed"
1598   [(set (match_dup 0)
1599         (plus:P (match_dup 1)
1600                 (match_dup 2)))
1601    (set (match_dup 3)
1602         (compare:CC (match_dup 0)
1603                     (const_int 0)))]
1604   "")
1605
1606 ;; Split an add that we can't do in one insn into two insns, each of which
1607 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1608 ;; add should be last in case the result gets used in an address.
1609
1610 (define_split
1611   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1612         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1613                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1614   ""
1615   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1616    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1617 {
1618   HOST_WIDE_INT val = INTVAL (operands[2]);
1619   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1620   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1621
1622   operands[4] = GEN_INT (low);
1623   if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1624     operands[3] = GEN_INT (rest);
1625   else if (can_create_pseudo_p ())
1626     {
1627       operands[3] = gen_reg_rtx (DImode);
1628       emit_move_insn (operands[3], operands[2]);
1629       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1630       DONE;
1631     }
1632   else
1633     FAIL;
1634 })
1635
1636 (define_insn "one_cmpl<mode>2"
1637   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1638         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1639   ""
1640   "nor %0,%1,%1")
1641
1642 (define_insn ""
1643   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1644         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1645                     (const_int 0)))
1646    (clobber (match_scratch:P 2 "=r,r"))]
1647   ""
1648   "@
1649    nor. %2,%1,%1
1650    #"
1651   [(set_attr "type" "compare")
1652    (set_attr "length" "4,8")])
1653
1654 (define_split
1655   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1656         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1657                     (const_int 0)))
1658    (clobber (match_scratch:P 2 ""))]
1659   "reload_completed"
1660   [(set (match_dup 2)
1661         (not:P (match_dup 1)))
1662    (set (match_dup 0)
1663         (compare:CC (match_dup 2)
1664                     (const_int 0)))]
1665   "")
1666
1667 (define_insn ""
1668   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1669         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1670                     (const_int 0)))
1671    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1672         (not:P (match_dup 1)))]
1673   ""
1674   "@
1675    nor. %0,%1,%1
1676    #"
1677   [(set_attr "type" "compare")
1678    (set_attr "length" "4,8")])
1679
1680 (define_split
1681   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1682         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1683                     (const_int 0)))
1684    (set (match_operand:P 0 "gpc_reg_operand" "")
1685         (not:P (match_dup 1)))]
1686   "reload_completed"
1687   [(set (match_dup 0)
1688         (not:P (match_dup 1)))
1689    (set (match_dup 2)
1690         (compare:CC (match_dup 0)
1691                     (const_int 0)))]
1692   "")
1693
1694 (define_insn ""
1695   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1696         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1697                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1698   "! TARGET_POWERPC"
1699   "{sf%I1|subf%I1c} %0,%2,%1")
1700
1701 (define_insn ""
1702   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1703         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1704                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1705   "TARGET_POWERPC"
1706   "@
1707    subf %0,%2,%1
1708    subfic %0,%2,%1")
1709
1710 (define_insn ""
1711   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1712         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1713                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1714                     (const_int 0)))
1715    (clobber (match_scratch:SI 3 "=r,r"))]
1716   "! TARGET_POWERPC"
1717   "@
1718    {sf.|subfc.} %3,%2,%1
1719    #"
1720   [(set_attr "type" "compare")
1721    (set_attr "length" "4,8")])
1722
1723 (define_insn ""
1724   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1725         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1726                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1727                     (const_int 0)))
1728    (clobber (match_scratch:P 3 "=r,r"))]
1729   "TARGET_POWERPC"
1730   "@
1731    subf. %3,%2,%1
1732    #"
1733   [(set_attr "type" "fast_compare")
1734    (set_attr "length" "4,8")])
1735
1736 (define_split
1737   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1738         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1739                              (match_operand:P 2 "gpc_reg_operand" ""))
1740                     (const_int 0)))
1741    (clobber (match_scratch:P 3 ""))]
1742   "reload_completed"
1743   [(set (match_dup 3)
1744         (minus:P (match_dup 1)
1745                   (match_dup 2)))
1746    (set (match_dup 0)
1747         (compare:CC (match_dup 3)
1748                     (const_int 0)))]
1749   "")
1750
1751 (define_insn ""
1752   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1753         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1754                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1755                     (const_int 0)))
1756    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1757         (minus:SI (match_dup 1) (match_dup 2)))]
1758   "! TARGET_POWERPC"
1759   "@
1760    {sf.|subfc.} %0,%2,%1
1761    #"
1762   [(set_attr "type" "compare")
1763    (set_attr "length" "4,8")])
1764
1765 (define_insn ""
1766   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1767         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1768                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1769                     (const_int 0)))
1770    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1771         (minus:P (match_dup 1)
1772                   (match_dup 2)))]
1773   "TARGET_POWERPC"
1774   "@
1775    subf. %0,%2,%1
1776    #"
1777   [(set_attr "type" "fast_compare")
1778    (set_attr "length" "4,8")])
1779
1780 (define_split
1781   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1782         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1783                              (match_operand:P 2 "gpc_reg_operand" ""))
1784                     (const_int 0)))
1785    (set (match_operand:P 0 "gpc_reg_operand" "")
1786         (minus:P (match_dup 1)
1787                   (match_dup 2)))]
1788   "reload_completed"
1789   [(set (match_dup 0)
1790         (minus:P (match_dup 1)
1791                   (match_dup 2)))
1792    (set (match_dup 3)
1793         (compare:CC (match_dup 0)
1794                     (const_int 0)))]
1795   "")
1796
1797 (define_expand "sub<mode>3"
1798   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1799         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1800                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
1801   ""
1802   "
1803 {
1804   if (GET_CODE (operands[2]) == CONST_INT)
1805     {
1806       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1807                                  negate_rtx (<MODE>mode, operands[2])));
1808       DONE;
1809     }
1810 }")
1811
1812 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1813 ;; instruction and some auxiliary computations.  Then we just have a single
1814 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1815 ;; combine.
1816
1817 (define_expand "sminsi3"
1818   [(set (match_dup 3)
1819         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1820                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1821                          (const_int 0)
1822                          (minus:SI (match_dup 2) (match_dup 1))))
1823    (set (match_operand:SI 0 "gpc_reg_operand" "")
1824         (minus:SI (match_dup 2) (match_dup 3)))]
1825   "TARGET_POWER || TARGET_ISEL"
1826   "
1827 {
1828   if (TARGET_ISEL)
1829     {
1830       operands[2] = force_reg (SImode, operands[2]);
1831       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1832       DONE;
1833     }
1834
1835   operands[3] = gen_reg_rtx (SImode);
1836 }")
1837
1838 (define_split
1839   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1840         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1841                  (match_operand:SI 2 "reg_or_short_operand" "")))
1842    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1843   "TARGET_POWER"
1844   [(set (match_dup 3)
1845         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1846                          (const_int 0)
1847                          (minus:SI (match_dup 2) (match_dup 1))))
1848    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1849   "")
1850
1851 (define_expand "smaxsi3"
1852   [(set (match_dup 3)
1853         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1854                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1855                          (const_int 0)
1856                          (minus:SI (match_dup 2) (match_dup 1))))
1857    (set (match_operand:SI 0 "gpc_reg_operand" "")
1858         (plus:SI (match_dup 3) (match_dup 1)))]
1859   "TARGET_POWER || TARGET_ISEL"
1860   "
1861 {
1862   if (TARGET_ISEL)
1863     {
1864       operands[2] = force_reg (SImode, operands[2]);
1865       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1866       DONE;
1867     }
1868   operands[3] = gen_reg_rtx (SImode);
1869 }")
1870
1871 (define_split
1872   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1873         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1874                  (match_operand:SI 2 "reg_or_short_operand" "")))
1875    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1876   "TARGET_POWER"
1877   [(set (match_dup 3)
1878         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1879                          (const_int 0)
1880                          (minus:SI (match_dup 2) (match_dup 1))))
1881    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1882   "")
1883
1884 (define_expand "uminsi3"
1885   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1886                               (match_dup 5)))
1887    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1888                               (match_dup 5)))
1889    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1890                                        (const_int 0)
1891                                        (minus:SI (match_dup 4) (match_dup 3))))
1892    (set (match_operand:SI 0 "gpc_reg_operand" "")
1893         (minus:SI (match_dup 2) (match_dup 3)))]
1894   "TARGET_POWER || TARGET_ISEL"
1895   "
1896 {
1897   if (TARGET_ISEL)
1898     {
1899       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1900       DONE;
1901     }
1902   operands[3] = gen_reg_rtx (SImode);
1903   operands[4] = gen_reg_rtx (SImode);
1904   operands[5] = GEN_INT (-2147483647 - 1);
1905 }")
1906
1907 (define_expand "umaxsi3"
1908   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1909                               (match_dup 5)))
1910    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1911                               (match_dup 5)))
1912    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1913                                        (const_int 0)
1914                                        (minus:SI (match_dup 4) (match_dup 3))))
1915    (set (match_operand:SI 0 "gpc_reg_operand" "")
1916         (plus:SI (match_dup 3) (match_dup 1)))]
1917   "TARGET_POWER || TARGET_ISEL"
1918   "
1919 {
1920   if (TARGET_ISEL)
1921     {
1922       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1923       DONE;
1924     }
1925   operands[3] = gen_reg_rtx (SImode);
1926   operands[4] = gen_reg_rtx (SImode);
1927   operands[5] = GEN_INT (-2147483647 - 1);
1928 }")
1929
1930 (define_insn ""
1931   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1932         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1933                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1934                          (const_int 0)
1935                          (minus:SI (match_dup 2) (match_dup 1))))]
1936   "TARGET_POWER"
1937   "doz%I2 %0,%1,%2")
1938
1939 (define_insn ""
1940   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1941         (compare:CC
1942          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1943                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1944                           (const_int 0)
1945                           (minus:SI (match_dup 2) (match_dup 1)))
1946          (const_int 0)))
1947    (clobber (match_scratch:SI 3 "=r,r"))]
1948   "TARGET_POWER"
1949   "@
1950    doz%I2. %3,%1,%2
1951    #"
1952   [(set_attr "type" "delayed_compare")
1953    (set_attr "length" "4,8")])
1954
1955 (define_split
1956   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1957         (compare:CC
1958          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1959                               (match_operand:SI 2 "reg_or_short_operand" ""))
1960                           (const_int 0)
1961                           (minus:SI (match_dup 2) (match_dup 1)))
1962          (const_int 0)))
1963    (clobber (match_scratch:SI 3 ""))]
1964   "TARGET_POWER && reload_completed"
1965   [(set (match_dup 3)
1966         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1967                           (const_int 0)
1968                           (minus:SI (match_dup 2) (match_dup 1))))
1969    (set (match_dup 0)
1970         (compare:CC (match_dup 3)
1971                     (const_int 0)))]
1972   "")
1973
1974 (define_insn ""
1975   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1976         (compare:CC
1977          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1978                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1979                           (const_int 0)
1980                           (minus:SI (match_dup 2) (match_dup 1)))
1981          (const_int 0)))
1982    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1983         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1984                          (const_int 0)
1985                          (minus:SI (match_dup 2) (match_dup 1))))]
1986   "TARGET_POWER"
1987   "@
1988    doz%I2. %0,%1,%2
1989    #"
1990   [(set_attr "type" "delayed_compare")
1991    (set_attr "length" "4,8")])
1992
1993 (define_split
1994   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1995         (compare:CC
1996          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1997                               (match_operand:SI 2 "reg_or_short_operand" ""))
1998                           (const_int 0)
1999                           (minus:SI (match_dup 2) (match_dup 1)))
2000          (const_int 0)))
2001    (set (match_operand:SI 0 "gpc_reg_operand" "")
2002         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2003                          (const_int 0)
2004                          (minus:SI (match_dup 2) (match_dup 1))))]
2005   "TARGET_POWER && reload_completed"
2006   [(set (match_dup 0)
2007         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2008                          (const_int 0)
2009                          (minus:SI (match_dup 2) (match_dup 1))))
2010    (set (match_dup 3)
2011         (compare:CC (match_dup 0)
2012                     (const_int 0)))]
2013   "")
2014
2015 ;; We don't need abs with condition code because such comparisons should
2016 ;; never be done.
2017 (define_expand "abssi2"
2018   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2019         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2020   ""
2021   "
2022 {
2023   if (TARGET_ISEL)
2024     {
2025       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
2026       DONE;
2027     }
2028   else if (! TARGET_POWER)
2029     {
2030       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
2031       DONE;
2032     }
2033 }")
2034
2035 (define_insn "*abssi2_power"
2036   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2037         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
2038   "TARGET_POWER"
2039   "abs %0,%1")
2040
2041 (define_insn_and_split "abssi2_isel"
2042   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2043         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
2044    (clobber (match_scratch:SI 2 "=&b"))
2045    (clobber (match_scratch:CC 3 "=y"))]
2046   "TARGET_ISEL"
2047   "#"
2048   "&& reload_completed"
2049   [(set (match_dup 2) (neg:SI (match_dup 1)))
2050    (set (match_dup 3)
2051         (compare:CC (match_dup 1)
2052                     (const_int 0)))
2053    (set (match_dup 0)
2054         (if_then_else:SI (ge (match_dup 3)
2055                              (const_int 0))
2056                          (match_dup 1)
2057                          (match_dup 2)))]
2058   "")
2059
2060 (define_insn_and_split "abssi2_nopower"
2061   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2062         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
2063    (clobber (match_scratch:SI 2 "=&r,&r"))]
2064   "! TARGET_POWER && ! TARGET_ISEL"
2065   "#"
2066   "&& reload_completed"
2067   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2068    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2069    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
2070   "")
2071
2072 (define_insn "*nabs_power"
2073   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2074         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
2075   "TARGET_POWER"
2076   "nabs %0,%1")
2077
2078 (define_insn_and_split "*nabs_nopower"
2079   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2080         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
2081    (clobber (match_scratch:SI 2 "=&r,&r"))]
2082   "! TARGET_POWER"
2083   "#"
2084   "&& reload_completed"
2085   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2086    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2087    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
2088   "")
2089
2090 (define_expand "neg<mode>2"
2091   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
2092         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
2093   ""
2094   "")
2095
2096 (define_insn "*neg<mode>2_internal"
2097   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2098         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2099   ""
2100   "neg %0,%1")
2101
2102 (define_insn ""
2103   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2104         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2105                     (const_int 0)))
2106    (clobber (match_scratch:P 2 "=r,r"))]
2107   ""
2108   "@
2109    neg. %2,%1
2110    #"
2111   [(set_attr "type" "fast_compare")
2112    (set_attr "length" "4,8")])
2113
2114 (define_split
2115   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2116         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2117                     (const_int 0)))
2118    (clobber (match_scratch:P 2 ""))]
2119   "reload_completed"
2120   [(set (match_dup 2)
2121         (neg:P (match_dup 1)))
2122    (set (match_dup 0)
2123         (compare:CC (match_dup 2)
2124                     (const_int 0)))]
2125   "")
2126
2127 (define_insn ""
2128   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2129         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2130                     (const_int 0)))
2131    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2132         (neg:P (match_dup 1)))]
2133   ""
2134   "@
2135    neg. %0,%1
2136    #"
2137   [(set_attr "type" "fast_compare")
2138    (set_attr "length" "4,8")])
2139
2140 (define_split
2141   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2142         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2143                     (const_int 0)))
2144    (set (match_operand:P 0 "gpc_reg_operand" "")
2145         (neg:P (match_dup 1)))]
2146   "reload_completed"
2147   [(set (match_dup 0)
2148         (neg:P (match_dup 1)))
2149    (set (match_dup 2)
2150         (compare:CC (match_dup 0)
2151                     (const_int 0)))]
2152   "")
2153
2154 (define_insn "clz<mode>2"
2155   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2156         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2157   ""
2158   "{cntlz|cntlz<wd>} %0,%1"
2159   [(set_attr "type" "cntlz")])
2160
2161 (define_expand "ctz<mode>2"
2162   [(set (match_dup 2)
2163         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2164    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2165                                           (match_dup 2)))
2166               (clobber (scratch:CC))])
2167    (set (match_dup 4) (clz:GPR (match_dup 3)))
2168    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2169         (minus:GPR (match_dup 5) (match_dup 4)))]
2170   ""
2171   {
2172      operands[2] = gen_reg_rtx (<MODE>mode);
2173      operands[3] = gen_reg_rtx (<MODE>mode);
2174      operands[4] = gen_reg_rtx (<MODE>mode);
2175      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
2176   })
2177
2178 (define_expand "ffs<mode>2"
2179   [(set (match_dup 2)
2180         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))
2181    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2182                                           (match_dup 2)))
2183               (clobber (scratch:CC))])
2184    (set (match_dup 4) (clz:GPR (match_dup 3)))
2185    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2186         (minus:GPR (match_dup 5) (match_dup 4)))]
2187   ""
2188   {
2189      operands[2] = gen_reg_rtx (<MODE>mode);
2190      operands[3] = gen_reg_rtx (<MODE>mode);
2191      operands[4] = gen_reg_rtx (<MODE>mode);
2192      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
2193   })
2194
2195 (define_insn "popcntb<mode>2"
2196   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2197         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2198                      UNSPEC_POPCNTB))]
2199   "TARGET_POPCNTB"
2200   "popcntb %0,%1")
2201
2202 (define_expand "popcount<mode>2"
2203   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2204         (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2205   "TARGET_POPCNTB"
2206   {
2207     rs6000_emit_popcount (operands[0], operands[1]);
2208     DONE;
2209   })
2210
2211 (define_expand "parity<mode>2"
2212   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2213         (parity:GPR (match_operand:GPR 1 "gpc_reg_operand" "")))]
2214   "TARGET_POPCNTB"
2215   {
2216     rs6000_emit_parity (operands[0], operands[1]);
2217     DONE;
2218   })
2219
2220 (define_insn "bswapsi2"
2221   [(set (match_operand:SI 0 "reg_or_mem_operand" "=r,Z,&r")
2222         (bswap:SI (match_operand:SI 1 "reg_or_mem_operand" "Z,r,r")))]
2223   ""
2224   "@
2225    {lbrx|lwbrx} %0,%y1
2226    {stbrx|stwbrx} %1,%y0
2227    #"
2228   [(set_attr "length" "4,4,12")])
2229
2230 (define_split
2231   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2232         (bswap:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2233   "reload_completed"
2234   [(set (match_dup 0)
2235         (rotate:SI (match_dup 1) (const_int 8)))
2236    (set (zero_extract:SI (match_dup 0)
2237                          (const_int 8)
2238                          (const_int 0))
2239         (match_dup 1))
2240    (set (zero_extract:SI (match_dup 0)
2241                          (const_int 8)
2242                          (const_int 16))
2243         (rotate:SI (match_dup 1)
2244                    (const_int 16)))]
2245   "")
2246
2247 (define_expand "mulsi3"
2248   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2249    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2250    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
2251   ""
2252   "
2253 {
2254   if (TARGET_POWER)
2255     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
2256   else
2257     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
2258   DONE;
2259 }")
2260
2261 (define_insn "mulsi3_mq"
2262   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2263         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2264                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
2265    (clobber (match_scratch:SI 3 "=q,q"))]
2266   "TARGET_POWER"
2267   "@
2268    {muls|mullw} %0,%1,%2
2269    {muli|mulli} %0,%1,%2"
2270    [(set (attr "type")
2271       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2272                 (const_string "imul3")
2273              (match_operand:SI 2 "short_cint_operand" "")
2274                 (const_string "imul2")]
2275         (const_string "imul")))])
2276
2277 (define_insn "mulsi3_no_mq"
2278   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2279         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2280                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2281   "! TARGET_POWER"
2282   "@
2283    {muls|mullw} %0,%1,%2
2284    {muli|mulli} %0,%1,%2"
2285    [(set (attr "type")
2286       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2287                 (const_string "imul3")
2288              (match_operand:SI 2 "short_cint_operand" "")
2289                 (const_string "imul2")]
2290         (const_string "imul")))])
2291
2292 (define_insn "*mulsi3_mq_internal1"
2293   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2294         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2295                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2296                     (const_int 0)))
2297    (clobber (match_scratch:SI 3 "=r,r"))
2298    (clobber (match_scratch:SI 4 "=q,q"))]
2299   "TARGET_POWER"
2300   "@
2301    {muls.|mullw.} %3,%1,%2
2302    #"
2303   [(set_attr "type" "imul_compare")
2304    (set_attr "length" "4,8")])
2305
2306 (define_split
2307   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2308         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2309                              (match_operand:SI 2 "gpc_reg_operand" ""))
2310                     (const_int 0)))
2311    (clobber (match_scratch:SI 3 ""))
2312    (clobber (match_scratch:SI 4 ""))]
2313   "TARGET_POWER && reload_completed"
2314   [(parallel [(set (match_dup 3)
2315         (mult:SI (match_dup 1) (match_dup 2)))
2316    (clobber (match_dup 4))])
2317    (set (match_dup 0)
2318         (compare:CC (match_dup 3)
2319                     (const_int 0)))]
2320   "")
2321
2322 (define_insn "*mulsi3_no_mq_internal1"
2323   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2324         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2325                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2326                     (const_int 0)))
2327    (clobber (match_scratch:SI 3 "=r,r"))]
2328   "! TARGET_POWER"
2329   "@
2330    {muls.|mullw.} %3,%1,%2
2331    #"
2332   [(set_attr "type" "imul_compare")
2333    (set_attr "length" "4,8")])
2334
2335 (define_split
2336   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2337         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2338                              (match_operand:SI 2 "gpc_reg_operand" ""))
2339                     (const_int 0)))
2340    (clobber (match_scratch:SI 3 ""))]
2341   "! TARGET_POWER && reload_completed"
2342   [(set (match_dup 3)
2343         (mult:SI (match_dup 1) (match_dup 2)))
2344    (set (match_dup 0)
2345         (compare:CC (match_dup 3)
2346                     (const_int 0)))]
2347   "")
2348
2349 (define_insn "*mulsi3_mq_internal2"
2350   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2351         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2352                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2353                     (const_int 0)))
2354    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2355         (mult:SI (match_dup 1) (match_dup 2)))
2356    (clobber (match_scratch:SI 4 "=q,q"))]
2357   "TARGET_POWER"
2358   "@
2359    {muls.|mullw.} %0,%1,%2
2360    #"
2361   [(set_attr "type" "imul_compare")
2362    (set_attr "length" "4,8")])
2363
2364 (define_split
2365   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2366         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2367                              (match_operand:SI 2 "gpc_reg_operand" ""))
2368                     (const_int 0)))
2369    (set (match_operand:SI 0 "gpc_reg_operand" "")
2370         (mult:SI (match_dup 1) (match_dup 2)))
2371    (clobber (match_scratch:SI 4 ""))]
2372   "TARGET_POWER && reload_completed"
2373   [(parallel [(set (match_dup 0)
2374         (mult:SI (match_dup 1) (match_dup 2)))
2375    (clobber (match_dup 4))])
2376    (set (match_dup 3)
2377         (compare:CC (match_dup 0)
2378                     (const_int 0)))]
2379   "")
2380
2381 (define_insn "*mulsi3_no_mq_internal2"
2382   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2383         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2384                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2385                     (const_int 0)))
2386    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2387         (mult:SI (match_dup 1) (match_dup 2)))]
2388   "! TARGET_POWER"
2389   "@
2390    {muls.|mullw.} %0,%1,%2
2391    #"
2392   [(set_attr "type" "imul_compare")
2393    (set_attr "length" "4,8")])
2394
2395 (define_split
2396   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2397         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2398                              (match_operand:SI 2 "gpc_reg_operand" ""))
2399                     (const_int 0)))
2400    (set (match_operand:SI 0 "gpc_reg_operand" "")
2401         (mult:SI (match_dup 1) (match_dup 2)))]
2402   "! TARGET_POWER && reload_completed"
2403   [(set (match_dup 0)
2404         (mult:SI (match_dup 1) (match_dup 2)))
2405    (set (match_dup 3)
2406         (compare:CC (match_dup 0)
2407                     (const_int 0)))]
2408   "")
2409
2410 ;; Operand 1 is divided by operand 2; quotient goes to operand
2411 ;; 0 and remainder to operand 3.
2412 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
2413
2414 (define_expand "divmodsi4"
2415   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2416                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2417                            (match_operand:SI 2 "gpc_reg_operand" "")))
2418               (set (match_operand:SI 3 "register_operand" "")
2419                    (mod:SI (match_dup 1) (match_dup 2)))])]
2420   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
2421   "
2422 {
2423   if (! TARGET_POWER && ! TARGET_POWERPC)
2424     {
2425       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2426       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2427       emit_insn (gen_divss_call ());
2428       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2429       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2430       DONE;
2431     }
2432 }")
2433
2434 (define_insn "*divmodsi4_internal"
2435   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2436         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2437                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2438    (set (match_operand:SI 3 "register_operand" "=q")
2439         (mod:SI (match_dup 1) (match_dup 2)))]
2440   "TARGET_POWER"
2441   "divs %0,%1,%2"
2442   [(set_attr "type" "idiv")])
2443
2444 (define_expand "udiv<mode>3"
2445   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2446         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2447                   (match_operand:GPR 2 "gpc_reg_operand" "")))]
2448   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
2449   "
2450 {
2451   if (! TARGET_POWER && ! TARGET_POWERPC)
2452     {
2453       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2454       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2455       emit_insn (gen_quous_call ());
2456       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2457       DONE;
2458     }
2459   else if (TARGET_POWER)
2460     {
2461       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
2462       DONE;
2463     }
2464 }")
2465
2466 (define_insn "udivsi3_mq"
2467   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2468         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2469                  (match_operand:SI 2 "gpc_reg_operand" "r")))
2470    (clobber (match_scratch:SI 3 "=q"))]
2471   "TARGET_POWERPC && TARGET_POWER"
2472   "divwu %0,%1,%2"
2473   [(set_attr "type" "idiv")])
2474
2475 (define_insn "*udivsi3_no_mq"
2476   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2477         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2478                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2479   "TARGET_POWERPC && ! TARGET_POWER"
2480   "div<wd>u %0,%1,%2"
2481    [(set (attr "type")
2482       (cond [(match_operand:SI 0 "" "")
2483                 (const_string "idiv")]
2484         (const_string "ldiv")))])
2485
2486
2487 ;; For powers of two we can do srai/aze for divide and then adjust for
2488 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
2489 ;; used; for PowerPC, force operands into register and do a normal divide;
2490 ;; for AIX common-mode, use quoss call on register operands.
2491 (define_expand "div<mode>3"
2492   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2493         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2494                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2495   ""
2496   "
2497 {
2498   if (GET_CODE (operands[2]) == CONST_INT
2499       && INTVAL (operands[2]) > 0
2500       && exact_log2 (INTVAL (operands[2])) >= 0)
2501     ;
2502   else if (TARGET_POWERPC)
2503     {
2504       operands[2] = force_reg (<MODE>mode, operands[2]);
2505       if (TARGET_POWER)
2506         {
2507           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
2508           DONE;
2509         }
2510     }
2511   else if (TARGET_POWER)
2512     FAIL;
2513   else
2514     {
2515       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2516       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2517       emit_insn (gen_quoss_call ());
2518       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2519       DONE;
2520     }
2521 }")
2522
2523 (define_insn "divsi3_mq"
2524   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2525         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2526                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2527    (clobber (match_scratch:SI 3 "=q"))]
2528   "TARGET_POWERPC && TARGET_POWER"
2529   "divw %0,%1,%2"
2530   [(set_attr "type" "idiv")])
2531
2532 (define_insn "*div<mode>3_no_mq"
2533   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2534         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2535                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2536   "TARGET_POWERPC && ! TARGET_POWER"
2537   "div<wd> %0,%1,%2"
2538   [(set (attr "type")
2539      (cond [(match_operand:SI 0 "" "")
2540                 (const_string "idiv")]
2541         (const_string "ldiv")))])
2542
2543 (define_expand "mod<mode>3"
2544   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
2545    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
2546    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
2547   ""
2548   "
2549 {
2550   int i;
2551   rtx temp1;
2552   rtx temp2;
2553
2554   if (GET_CODE (operands[2]) != CONST_INT
2555       || INTVAL (operands[2]) <= 0
2556       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2557     FAIL;
2558
2559   temp1 = gen_reg_rtx (<MODE>mode);
2560   temp2 = gen_reg_rtx (<MODE>mode);
2561
2562   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
2563   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
2564   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
2565   DONE;
2566 }")
2567
2568 (define_insn ""
2569   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2570         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2571                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
2572   ""
2573   "{srai|sra<wd>i} %0,%1,%p2\;{aze|addze} %0,%0"
2574   [(set_attr "type" "two")
2575    (set_attr "length" "8")])
2576
2577 (define_insn ""
2578   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2579         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2580                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2581                     (const_int 0)))
2582    (clobber (match_scratch:P 3 "=r,r"))]
2583   ""
2584   "@
2585    {srai|sra<wd>i} %3,%1,%p2\;{aze.|addze.} %3,%3
2586    #"
2587   [(set_attr "type" "compare")
2588    (set_attr "length" "8,12")])
2589
2590 (define_split
2591   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2592         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2593                              (match_operand:GPR 2 "exact_log2_cint_operand"
2594                               ""))
2595                     (const_int 0)))
2596    (clobber (match_scratch:GPR 3 ""))]
2597   "reload_completed"
2598   [(set (match_dup 3)
2599         (div:<MODE> (match_dup 1) (match_dup 2)))
2600    (set (match_dup 0)
2601         (compare:CC (match_dup 3)
2602                     (const_int 0)))]
2603   "")
2604
2605 (define_insn ""
2606   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2607         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2608                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2609                     (const_int 0)))
2610    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2611         (div:P (match_dup 1) (match_dup 2)))]
2612   ""
2613   "@
2614    {srai|sra<wd>i} %0,%1,%p2\;{aze.|addze.} %0,%0
2615    #"
2616   [(set_attr "type" "compare")
2617    (set_attr "length" "8,12")])
2618
2619 (define_split
2620   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2621         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2622                              (match_operand:GPR 2 "exact_log2_cint_operand"
2623                               ""))
2624                     (const_int 0)))
2625    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2626         (div:GPR (match_dup 1) (match_dup 2)))]
2627   "reload_completed"
2628   [(set (match_dup 0)
2629         (div:<MODE> (match_dup 1) (match_dup 2)))
2630    (set (match_dup 3)
2631         (compare:CC (match_dup 0)
2632                     (const_int 0)))]
2633   "")
2634
2635 (define_insn ""
2636   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2637         (udiv:SI
2638          (plus:DI (ashift:DI
2639                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
2640                    (const_int 32))
2641                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
2642          (match_operand:SI 3 "gpc_reg_operand" "r")))
2643    (set (match_operand:SI 2 "register_operand" "=*q")
2644         (umod:SI
2645          (plus:DI (ashift:DI
2646                    (zero_extend:DI (match_dup 1)) (const_int 32))
2647                   (zero_extend:DI (match_dup 4)))
2648          (match_dup 3)))]
2649   "TARGET_POWER"
2650   "div %0,%1,%3"
2651   [(set_attr "type" "idiv")])
2652
2653 ;; To do unsigned divide we handle the cases of the divisor looking like a
2654 ;; negative number.  If it is a constant that is less than 2**31, we don't
2655 ;; have to worry about the branches.  So make a few subroutines here.
2656 ;;
2657 ;; First comes the normal case.
2658 (define_expand "udivmodsi4_normal"
2659   [(set (match_dup 4) (const_int 0))
2660    (parallel [(set (match_operand:SI 0 "" "")
2661                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2662                                                 (const_int 32))
2663                                      (zero_extend:DI (match_operand:SI 1 "" "")))
2664                             (match_operand:SI 2 "" "")))
2665               (set (match_operand:SI 3 "" "")
2666                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2667                                                 (const_int 32))
2668                                      (zero_extend:DI (match_dup 1)))
2669                             (match_dup 2)))])]
2670   "TARGET_POWER"
2671   "
2672 { operands[4] = gen_reg_rtx (SImode); }")
2673
2674 ;; This handles the branches.
2675 (define_expand "udivmodsi4_tests"
2676   [(set (match_operand:SI 0 "" "") (const_int 0))
2677    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
2678    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
2679    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
2680                            (label_ref (match_operand:SI 4 "" "")) (pc)))
2681    (set (match_dup 0) (const_int 1))
2682    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
2683    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
2684    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
2685                            (label_ref (match_dup 4)) (pc)))]
2686   "TARGET_POWER"
2687   "
2688 { operands[5] = gen_reg_rtx (CCUNSmode);
2689   operands[6] = gen_reg_rtx (CCmode);
2690 }")
2691
2692 (define_expand "udivmodsi4"
2693   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2694                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2695                             (match_operand:SI 2 "reg_or_cint_operand" "")))
2696               (set (match_operand:SI 3 "gpc_reg_operand" "")
2697                    (umod:SI (match_dup 1) (match_dup 2)))])]
2698   ""
2699   "
2700 {
2701   rtx label = 0;
2702
2703   if (! TARGET_POWER)
2704     {
2705       if (! TARGET_POWERPC)
2706         {
2707           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2708           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2709           emit_insn (gen_divus_call ());
2710           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2711           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2712           DONE;
2713         }
2714       else
2715         FAIL;
2716     }
2717
2718   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
2719     {
2720       operands[2] = force_reg (SImode, operands[2]);
2721       label = gen_label_rtx ();
2722       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
2723                                   operands[3], label));
2724     }
2725   else
2726     operands[2] = force_reg (SImode, operands[2]);
2727
2728   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
2729                                operands[3]));
2730   if (label)
2731     emit_label (label);
2732
2733   DONE;
2734 }")
2735
2736 ;; AIX architecture-independent common-mode multiply (DImode),
2737 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
2738 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
2739 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
2740 ;; assumed unused if generating common-mode, so ignore.
2741 (define_insn "mulh_call"
2742   [(set (reg:SI 3)
2743         (truncate:SI
2744          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
2745                                (sign_extend:DI (reg:SI 4)))
2746                       (const_int 32))))
2747    (clobber (reg:SI LR_REGNO))]
2748   "! TARGET_POWER && ! TARGET_POWERPC"
2749   "bla __mulh"
2750   [(set_attr "type" "imul")])
2751
2752 (define_insn "mull_call"
2753   [(set (reg:DI 3)
2754         (mult:DI (sign_extend:DI (reg:SI 3))
2755                  (sign_extend:DI (reg:SI 4))))
2756    (clobber (reg:SI LR_REGNO))
2757    (clobber (reg:SI 0))]
2758   "! TARGET_POWER && ! TARGET_POWERPC"
2759   "bla __mull"
2760   [(set_attr "type" "imul")])
2761
2762 (define_insn "divss_call"
2763   [(set (reg:SI 3)
2764         (div:SI (reg:SI 3) (reg:SI 4)))
2765    (set (reg:SI 4)
2766         (mod:SI (reg:SI 3) (reg:SI 4)))
2767    (clobber (reg:SI LR_REGNO))
2768    (clobber (reg:SI 0))]
2769   "! TARGET_POWER && ! TARGET_POWERPC"
2770   "bla __divss"
2771   [(set_attr "type" "idiv")])
2772
2773 (define_insn "divus_call"
2774   [(set (reg:SI 3)
2775         (udiv:SI (reg:SI 3) (reg:SI 4)))
2776    (set (reg:SI 4)
2777         (umod:SI (reg:SI 3) (reg:SI 4)))
2778    (clobber (reg:SI LR_REGNO))
2779    (clobber (reg:SI 0))
2780    (clobber (match_scratch:CC 0 "=x"))
2781    (clobber (reg:CC CR1_REGNO))]
2782   "! TARGET_POWER && ! TARGET_POWERPC"
2783   "bla __divus"
2784   [(set_attr "type" "idiv")])
2785
2786 (define_insn "quoss_call"
2787   [(set (reg:SI 3)
2788         (div:SI (reg:SI 3) (reg:SI 4)))
2789    (clobber (reg:SI LR_REGNO))]
2790   "! TARGET_POWER && ! TARGET_POWERPC"
2791   "bla __quoss"
2792   [(set_attr "type" "idiv")])
2793
2794 (define_insn "quous_call"
2795   [(set (reg:SI 3)
2796         (udiv:SI (reg:SI 3) (reg:SI 4)))
2797    (clobber (reg:SI LR_REGNO))
2798    (clobber (reg:SI 0))
2799    (clobber (match_scratch:CC 0 "=x"))
2800    (clobber (reg:CC CR1_REGNO))]
2801   "! TARGET_POWER && ! TARGET_POWERPC"
2802   "bla __quous"
2803   [(set_attr "type" "idiv")])
2804 \f
2805 ;; Logical instructions
2806 ;; The logical instructions are mostly combined by using match_operator,
2807 ;; but the plain AND insns are somewhat different because there is no
2808 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2809 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2810
2811 (define_insn "andsi3"
2812   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2813         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2814                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2815    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2816   ""
2817   "@
2818    and %0,%1,%2
2819    {rlinm|rlwinm} %0,%1,0,%m2,%M2
2820    {andil.|andi.} %0,%1,%b2
2821    {andiu.|andis.} %0,%1,%u2"
2822   [(set_attr "type" "*,*,compare,compare")])
2823
2824 ;; Note to set cr's other than cr0 we do the and immediate and then
2825 ;; the test again -- this avoids a mfcr which on the higher end
2826 ;; machines causes an execution serialization
2827
2828 (define_insn "*andsi3_internal2"
2829   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2830         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2831                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2832                     (const_int 0)))
2833    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2834    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2835   "TARGET_32BIT"
2836   "@
2837    and. %3,%1,%2
2838    {andil.|andi.} %3,%1,%b2
2839    {andiu.|andis.} %3,%1,%u2
2840    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2841    #
2842    #
2843    #
2844    #"
2845   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2846    (set_attr "length" "4,4,4,4,8,8,8,8")])
2847
2848 (define_insn "*andsi3_internal3"
2849   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2850         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2851                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2852                     (const_int 0)))
2853    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2854    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2855   "TARGET_64BIT"
2856   "@
2857    #
2858    {andil.|andi.} %3,%1,%b2
2859    {andiu.|andis.} %3,%1,%u2
2860    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2861    #
2862    #
2863    #
2864    #"
2865   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2866    (set_attr "length" "8,4,4,4,8,8,8,8")])
2867
2868 (define_split
2869   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2870         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2871                              (match_operand:GPR 2 "and_operand" ""))
2872                     (const_int 0)))
2873    (clobber (match_scratch:GPR 3 ""))
2874    (clobber (match_scratch:CC 4 ""))]
2875   "reload_completed"
2876   [(parallel [(set (match_dup 3)
2877                    (and:<MODE> (match_dup 1)
2878                                (match_dup 2)))
2879               (clobber (match_dup 4))])
2880    (set (match_dup 0)
2881         (compare:CC (match_dup 3)
2882                     (const_int 0)))]
2883   "")
2884
2885 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2886 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2887
2888 (define_split
2889   [(set (match_operand:CC 0 "cc_reg_operand" "")
2890         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2891                             (match_operand:SI 2 "gpc_reg_operand" ""))
2892                     (const_int 0)))
2893    (clobber (match_scratch:SI 3 ""))
2894    (clobber (match_scratch:CC 4 ""))]
2895   "TARGET_POWERPC64 && reload_completed"
2896   [(parallel [(set (match_dup 3)
2897                    (and:SI (match_dup 1)
2898                            (match_dup 2)))
2899               (clobber (match_dup 4))])
2900    (set (match_dup 0)
2901         (compare:CC (match_dup 3)
2902                     (const_int 0)))]
2903   "")
2904
2905 (define_insn "*andsi3_internal4"
2906   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2907         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2908                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2909                     (const_int 0)))
2910    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2911         (and:SI (match_dup 1)
2912                 (match_dup 2)))
2913    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2914   "TARGET_32BIT"
2915   "@
2916    and. %0,%1,%2
2917    {andil.|andi.} %0,%1,%b2
2918    {andiu.|andis.} %0,%1,%u2
2919    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2920    #
2921    #
2922    #
2923    #"
2924   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2925    (set_attr "length" "4,4,4,4,8,8,8,8")])
2926
2927 (define_insn "*andsi3_internal5"
2928   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2929         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2930                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2931                     (const_int 0)))
2932    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2933         (and:SI (match_dup 1)
2934                 (match_dup 2)))
2935    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2936   "TARGET_64BIT"
2937   "@
2938    #
2939    {andil.|andi.} %0,%1,%b2
2940    {andiu.|andis.} %0,%1,%u2
2941    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2942    #
2943    #
2944    #
2945    #"
2946   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2947    (set_attr "length" "8,4,4,4,8,8,8,8")])
2948
2949 (define_split
2950   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2951         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2952                             (match_operand:SI 2 "and_operand" ""))
2953                     (const_int 0)))
2954    (set (match_operand:SI 0 "gpc_reg_operand" "")
2955         (and:SI (match_dup 1)
2956                 (match_dup 2)))
2957    (clobber (match_scratch:CC 4 ""))]
2958   "reload_completed"
2959   [(parallel [(set (match_dup 0)
2960                    (and:SI (match_dup 1)
2961                            (match_dup 2)))
2962               (clobber (match_dup 4))])
2963    (set (match_dup 3)
2964         (compare:CC (match_dup 0)
2965                     (const_int 0)))]
2966   "")
2967
2968 (define_split
2969   [(set (match_operand:CC 3 "cc_reg_operand" "")
2970         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2971                             (match_operand:SI 2 "gpc_reg_operand" ""))
2972                     (const_int 0)))
2973    (set (match_operand:SI 0 "gpc_reg_operand" "")
2974         (and:SI (match_dup 1)
2975                 (match_dup 2)))
2976    (clobber (match_scratch:CC 4 ""))]
2977   "TARGET_POWERPC64 && reload_completed"
2978   [(parallel [(set (match_dup 0)
2979                    (and:SI (match_dup 1)
2980                            (match_dup 2)))
2981               (clobber (match_dup 4))])
2982    (set (match_dup 3)
2983         (compare:CC (match_dup 0)
2984                     (const_int 0)))]
2985   "")
2986
2987 ;; Handle the PowerPC64 rlwinm corner case
2988
2989 (define_insn_and_split "*andsi3_internal6"
2990   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2991         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2992                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2993   "TARGET_POWERPC64"
2994   "#"
2995   "TARGET_POWERPC64"
2996   [(set (match_dup 0)
2997         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
2998                 (match_dup 4)))
2999    (set (match_dup 0)
3000         (rotate:SI (match_dup 0) (match_dup 5)))]
3001   "
3002 {
3003   int mb = extract_MB (operands[2]);
3004   int me = extract_ME (operands[2]);
3005   operands[3] = GEN_INT (me + 1);
3006   operands[5] = GEN_INT (32 - (me + 1));
3007   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
3008 }"
3009   [(set_attr "length" "8")])
3010
3011 (define_expand "iorsi3"
3012   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3013         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
3014                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3015   ""
3016   "
3017 {
3018   if (GET_CODE (operands[2]) == CONST_INT
3019       && ! logical_operand (operands[2], SImode))
3020     {
3021       HOST_WIDE_INT value = INTVAL (operands[2]);
3022       rtx tmp = ((!can_create_pseudo_p ()
3023                   || rtx_equal_p (operands[0], operands[1]))
3024                  ? operands[0] : gen_reg_rtx (SImode));
3025
3026       emit_insn (gen_iorsi3 (tmp, operands[1],
3027                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3028       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3029       DONE;
3030     }
3031 }")
3032
3033 (define_expand "xorsi3"
3034   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3035         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3036                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3037   ""
3038   "
3039 {
3040   if (GET_CODE (operands[2]) == CONST_INT
3041       && ! logical_operand (operands[2], SImode))
3042     {
3043       HOST_WIDE_INT value = INTVAL (operands[2]);
3044       rtx tmp = ((!can_create_pseudo_p ()
3045                   || rtx_equal_p (operands[0], operands[1]))
3046                  ? operands[0] : gen_reg_rtx (SImode));
3047
3048       emit_insn (gen_xorsi3 (tmp, operands[1],
3049                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3050       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3051       DONE;
3052     }
3053 }")
3054
3055 (define_insn "*boolsi3_internal1"
3056   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3057         (match_operator:SI 3 "boolean_or_operator"
3058          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
3059           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
3060   ""
3061   "@
3062    %q3 %0,%1,%2
3063    {%q3il|%q3i} %0,%1,%b2
3064    {%q3iu|%q3is} %0,%1,%u2")
3065
3066 (define_insn "*boolsi3_internal2"
3067   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3068         (compare:CC (match_operator:SI 4 "boolean_or_operator"
3069          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3070           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3071          (const_int 0)))
3072    (clobber (match_scratch:SI 3 "=r,r"))]
3073   "TARGET_32BIT"
3074   "@
3075    %q4. %3,%1,%2
3076    #"
3077   [(set_attr "type" "compare")
3078    (set_attr "length" "4,8")])
3079
3080 (define_split
3081   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3082         (compare:CC (match_operator:SI 4 "boolean_operator"
3083          [(match_operand:SI 1 "gpc_reg_operand" "")
3084           (match_operand:SI 2 "gpc_reg_operand" "")])
3085          (const_int 0)))
3086    (clobber (match_scratch:SI 3 ""))]
3087   "TARGET_32BIT && reload_completed"
3088   [(set (match_dup 3) (match_dup 4))
3089    (set (match_dup 0)
3090         (compare:CC (match_dup 3)
3091                     (const_int 0)))]
3092   "")
3093
3094 (define_insn "*boolsi3_internal3"
3095   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3096         (compare:CC (match_operator:SI 4 "boolean_operator"
3097          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3098           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3099          (const_int 0)))
3100    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3101         (match_dup 4))]
3102   "TARGET_32BIT"
3103   "@
3104    %q4. %0,%1,%2
3105    #"
3106   [(set_attr "type" "compare")
3107    (set_attr "length" "4,8")])
3108
3109 (define_split
3110   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3111         (compare:CC (match_operator:SI 4 "boolean_operator"
3112          [(match_operand:SI 1 "gpc_reg_operand" "")
3113           (match_operand:SI 2 "gpc_reg_operand" "")])
3114          (const_int 0)))
3115    (set (match_operand:SI 0 "gpc_reg_operand" "")
3116         (match_dup 4))]
3117   "TARGET_32BIT && reload_completed"
3118   [(set (match_dup 0) (match_dup 4))
3119    (set (match_dup 3)
3120         (compare:CC (match_dup 0)
3121                     (const_int 0)))]
3122   "")
3123
3124 ;; Split a logical operation that we can't do in one insn into two insns,
3125 ;; each of which does one 16-bit part.  This is used by combine.
3126
3127 (define_split
3128   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3129         (match_operator:SI 3 "boolean_or_operator"
3130          [(match_operand:SI 1 "gpc_reg_operand" "")
3131           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
3132   ""
3133   [(set (match_dup 0) (match_dup 4))
3134    (set (match_dup 0) (match_dup 5))]
3135 "
3136 {
3137   rtx i;
3138   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
3139   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3140                                 operands[1], i);
3141   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
3142   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3143                                 operands[0], i);
3144 }")
3145
3146 (define_insn "*boolcsi3_internal1"
3147   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3148         (match_operator:SI 3 "boolean_operator"
3149          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3150           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
3151   ""
3152   "%q3 %0,%2,%1")
3153
3154 (define_insn "*boolcsi3_internal2"
3155   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3156         (compare:CC (match_operator:SI 4 "boolean_operator"
3157          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3158           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3159          (const_int 0)))
3160    (clobber (match_scratch:SI 3 "=r,r"))]
3161   "TARGET_32BIT"
3162   "@
3163    %q4. %3,%2,%1
3164    #"
3165   [(set_attr "type" "compare")
3166    (set_attr "length" "4,8")])
3167
3168 (define_split
3169   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3170         (compare:CC (match_operator:SI 4 "boolean_operator"
3171          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3172           (match_operand:SI 2 "gpc_reg_operand" "")])
3173          (const_int 0)))
3174    (clobber (match_scratch:SI 3 ""))]
3175   "TARGET_32BIT && reload_completed"
3176   [(set (match_dup 3) (match_dup 4))
3177    (set (match_dup 0)
3178         (compare:CC (match_dup 3)
3179                     (const_int 0)))]
3180   "")
3181
3182 (define_insn "*boolcsi3_internal3"
3183   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3184         (compare:CC (match_operator:SI 4 "boolean_operator"
3185          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3186           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3187          (const_int 0)))
3188    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3189         (match_dup 4))]
3190   "TARGET_32BIT"
3191   "@
3192    %q4. %0,%2,%1
3193    #"
3194   [(set_attr "type" "compare")
3195    (set_attr "length" "4,8")])
3196
3197 (define_split
3198   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3199         (compare:CC (match_operator:SI 4 "boolean_operator"
3200          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3201           (match_operand:SI 2 "gpc_reg_operand" "")])
3202          (const_int 0)))
3203    (set (match_operand:SI 0 "gpc_reg_operand" "")
3204         (match_dup 4))]
3205   "TARGET_32BIT && reload_completed"
3206   [(set (match_dup 0) (match_dup 4))
3207    (set (match_dup 3)
3208         (compare:CC (match_dup 0)
3209                     (const_int 0)))]
3210   "")
3211
3212 (define_insn "*boolccsi3_internal1"
3213   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3214         (match_operator:SI 3 "boolean_operator"
3215          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3216           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3217   ""
3218   "%q3 %0,%1,%2")
3219
3220 (define_insn "*boolccsi3_internal2"
3221   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3222         (compare:CC (match_operator:SI 4 "boolean_operator"
3223          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3224           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3225          (const_int 0)))
3226    (clobber (match_scratch:SI 3 "=r,r"))]
3227   "TARGET_32BIT"
3228   "@
3229    %q4. %3,%1,%2
3230    #"
3231   [(set_attr "type" "compare")
3232    (set_attr "length" "4,8")])
3233
3234 (define_split
3235   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3236         (compare:CC (match_operator:SI 4 "boolean_operator"
3237          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3238           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3239          (const_int 0)))
3240    (clobber (match_scratch:SI 3 ""))]
3241   "TARGET_32BIT && reload_completed"
3242   [(set (match_dup 3) (match_dup 4))
3243    (set (match_dup 0)
3244         (compare:CC (match_dup 3)
3245                     (const_int 0)))]
3246   "")
3247
3248 (define_insn "*boolccsi3_internal3"
3249   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3250         (compare:CC (match_operator:SI 4 "boolean_operator"
3251          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3252           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3253          (const_int 0)))
3254    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3255         (match_dup 4))]
3256   "TARGET_32BIT"
3257   "@
3258    %q4. %0,%1,%2
3259    #"
3260   [(set_attr "type" "compare")
3261    (set_attr "length" "4,8")])
3262
3263 (define_split
3264   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3265         (compare:CC (match_operator:SI 4 "boolean_operator"
3266          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3267           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3268          (const_int 0)))
3269    (set (match_operand:SI 0 "gpc_reg_operand" "")
3270         (match_dup 4))]
3271   "TARGET_32BIT && reload_completed"
3272   [(set (match_dup 0) (match_dup 4))
3273    (set (match_dup 3)
3274         (compare:CC (match_dup 0)
3275                     (const_int 0)))]
3276   "")
3277
3278 ;; maskir insn.  We need four forms because things might be in arbitrary
3279 ;; orders.  Don't define forms that only set CR fields because these
3280 ;; would modify an input register.
3281
3282 (define_insn "*maskir_internal1"
3283   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3284         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3285                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3286                 (and:SI (match_dup 2)
3287                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
3288   "TARGET_POWER"
3289   "maskir %0,%3,%2")
3290
3291 (define_insn "*maskir_internal2"
3292   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3293         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3294                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3295                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3296                         (match_dup 2))))]
3297   "TARGET_POWER"
3298   "maskir %0,%3,%2")
3299
3300 (define_insn "*maskir_internal3"
3301   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3302         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
3303                         (match_operand:SI 3 "gpc_reg_operand" "r"))
3304                 (and:SI (not:SI (match_dup 2))
3305                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3306   "TARGET_POWER"
3307   "maskir %0,%3,%2")
3308
3309 (define_insn "*maskir_internal4"
3310   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3311         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3312                         (match_operand:SI 2 "gpc_reg_operand" "r"))
3313                 (and:SI (not:SI (match_dup 2))
3314                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3315   "TARGET_POWER"
3316   "maskir %0,%3,%2")
3317
3318 (define_insn "*maskir_internal5"
3319   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3320         (compare:CC
3321          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3322                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3323                  (and:SI (match_dup 2)
3324                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
3325          (const_int 0)))
3326    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3327         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3328                 (and:SI (match_dup 2) (match_dup 3))))]
3329   "TARGET_POWER"
3330   "@
3331    maskir. %0,%3,%2
3332    #"
3333   [(set_attr "type" "compare")
3334    (set_attr "length" "4,8")])
3335
3336 (define_split
3337   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3338         (compare:CC
3339          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3340                          (match_operand:SI 1 "gpc_reg_operand" ""))
3341                  (and:SI (match_dup 2)
3342                          (match_operand:SI 3 "gpc_reg_operand" "")))
3343          (const_int 0)))
3344    (set (match_operand:SI 0 "gpc_reg_operand" "")
3345         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3346                 (and:SI (match_dup 2) (match_dup 3))))]
3347   "TARGET_POWER && reload_completed"
3348   [(set (match_dup 0)
3349         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3350                 (and:SI (match_dup 2) (match_dup 3))))
3351    (set (match_dup 4)
3352         (compare:CC (match_dup 0)
3353                     (const_int 0)))]
3354   "")
3355
3356 (define_insn "*maskir_internal6"
3357   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3358         (compare:CC
3359          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3360                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3361                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3362                          (match_dup 2)))
3363          (const_int 0)))
3364    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3365         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3366                 (and:SI (match_dup 3) (match_dup 2))))]
3367   "TARGET_POWER"
3368   "@
3369    maskir. %0,%3,%2
3370    #"
3371   [(set_attr "type" "compare")
3372    (set_attr "length" "4,8")])
3373
3374 (define_split
3375   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3376         (compare:CC
3377          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3378                          (match_operand:SI 1 "gpc_reg_operand" ""))
3379                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3380                          (match_dup 2)))
3381          (const_int 0)))
3382    (set (match_operand:SI 0 "gpc_reg_operand" "")
3383         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3384                 (and:SI (match_dup 3) (match_dup 2))))]
3385   "TARGET_POWER && reload_completed"
3386   [(set (match_dup 0)
3387         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3388                 (and:SI (match_dup 3) (match_dup 2))))
3389    (set (match_dup 4)
3390         (compare:CC (match_dup 0)
3391                     (const_int 0)))]
3392   "")
3393
3394 (define_insn "*maskir_internal7"
3395   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3396         (compare:CC
3397          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
3398                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
3399                  (and:SI (not:SI (match_dup 2))
3400                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3401          (const_int 0)))
3402    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3403         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3404                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3405   "TARGET_POWER"
3406   "@
3407    maskir. %0,%3,%2
3408    #"
3409   [(set_attr "type" "compare")
3410    (set_attr "length" "4,8")])
3411
3412 (define_split
3413   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3414         (compare:CC
3415          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
3416                          (match_operand:SI 3 "gpc_reg_operand" ""))
3417                  (and:SI (not:SI (match_dup 2))
3418                          (match_operand:SI 1 "gpc_reg_operand" "")))
3419          (const_int 0)))
3420    (set (match_operand:SI 0 "gpc_reg_operand" "")
3421         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3422                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3423   "TARGET_POWER && reload_completed"
3424   [(set (match_dup 0)
3425         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3426                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3427    (set (match_dup 4)
3428         (compare:CC (match_dup 0)
3429                     (const_int 0)))]
3430   "")
3431
3432 (define_insn "*maskir_internal8"
3433   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3434         (compare:CC
3435          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3436                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3437                  (and:SI (not:SI (match_dup 2))
3438                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3439          (const_int 0)))
3440    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3441         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3442                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3443   "TARGET_POWER"
3444   "@
3445    maskir. %0,%3,%2
3446    #"
3447   [(set_attr "type" "compare")
3448    (set_attr "length" "4,8")])
3449
3450 (define_split
3451   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3452         (compare:CC
3453          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3454                          (match_operand:SI 2 "gpc_reg_operand" ""))
3455                  (and:SI (not:SI (match_dup 2))
3456                          (match_operand:SI 1 "gpc_reg_operand" "")))
3457          (const_int 0)))
3458    (set (match_operand:SI 0 "gpc_reg_operand" "")
3459         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3460                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3461   "TARGET_POWER && reload_completed"
3462   [(set (match_dup 0)
3463         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3464                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3465    (set (match_dup 4)
3466         (compare:CC (match_dup 0)
3467                     (const_int 0)))]
3468   "")
3469 \f
3470 ;; Rotate and shift insns, in all their variants.  These support shifts,
3471 ;; field inserts and extracts, and various combinations thereof.
3472 (define_expand "insv"
3473   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
3474                        (match_operand:SI 1 "const_int_operand" "")
3475                        (match_operand:SI 2 "const_int_operand" ""))
3476         (match_operand 3 "gpc_reg_operand" ""))]
3477   ""
3478   "
3479 {
3480   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3481      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3482      compiler if the address of the structure is taken later.  Likewise, do
3483      not handle invalid E500 subregs.  */
3484   if (GET_CODE (operands[0]) == SUBREG
3485       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD
3486           || ((TARGET_E500_DOUBLE || TARGET_SPE)
3487               && invalid_e500_subreg (operands[0], GET_MODE (operands[0])))))
3488     FAIL;
3489
3490   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
3491     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
3492   else
3493     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
3494   DONE;
3495 }")
3496
3497 (define_insn "insvsi"
3498   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3499                          (match_operand:SI 1 "const_int_operand" "i")
3500                          (match_operand:SI 2 "const_int_operand" "i"))
3501         (match_operand:SI 3 "gpc_reg_operand" "r"))]
3502   ""
3503   "*
3504 {
3505   int start = INTVAL (operands[2]) & 31;
3506   int size = INTVAL (operands[1]) & 31;
3507
3508   operands[4] = GEN_INT (32 - start - size);
3509   operands[1] = GEN_INT (start + size - 1);
3510   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3511 }"
3512   [(set_attr "type" "insert_word")])
3513
3514 (define_insn "*insvsi_internal1"
3515   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3516                          (match_operand:SI 1 "const_int_operand" "i")
3517                          (match_operand:SI 2 "const_int_operand" "i"))
3518         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3519                    (match_operand:SI 4 "const_int_operand" "i")))]
3520   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3521   "*
3522 {
3523   int shift = INTVAL (operands[4]) & 31;
3524   int start = INTVAL (operands[2]) & 31;
3525   int size = INTVAL (operands[1]) & 31;
3526
3527   operands[4] = GEN_INT (shift - start - size);
3528   operands[1] = GEN_INT (start + size - 1);
3529   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3530 }"
3531   [(set_attr "type" "insert_word")])
3532
3533 (define_insn "*insvsi_internal2"
3534   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3535                          (match_operand:SI 1 "const_int_operand" "i")
3536                          (match_operand:SI 2 "const_int_operand" "i"))
3537         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3538                      (match_operand:SI 4 "const_int_operand" "i")))]
3539   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3540   "*
3541 {
3542   int shift = INTVAL (operands[4]) & 31;
3543   int start = INTVAL (operands[2]) & 31;
3544   int size = INTVAL (operands[1]) & 31;
3545
3546   operands[4] = GEN_INT (32 - shift - start - size);
3547   operands[1] = GEN_INT (start + size - 1);
3548   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3549 }"
3550   [(set_attr "type" "insert_word")])
3551
3552 (define_insn "*insvsi_internal3"
3553   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3554                          (match_operand:SI 1 "const_int_operand" "i")
3555                          (match_operand:SI 2 "const_int_operand" "i"))
3556         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3557                      (match_operand:SI 4 "const_int_operand" "i")))]
3558   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3559   "*
3560 {
3561   int shift = INTVAL (operands[4]) & 31;
3562   int start = INTVAL (operands[2]) & 31;
3563   int size = INTVAL (operands[1]) & 31;
3564
3565   operands[4] = GEN_INT (32 - shift - start - size);
3566   operands[1] = GEN_INT (start + size - 1);
3567   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3568 }"
3569   [(set_attr "type" "insert_word")])
3570
3571 (define_insn "*insvsi_internal4"
3572   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3573                          (match_operand:SI 1 "const_int_operand" "i")
3574                          (match_operand:SI 2 "const_int_operand" "i"))
3575         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3576                          (match_operand:SI 4 "const_int_operand" "i")
3577                          (match_operand:SI 5 "const_int_operand" "i")))]
3578   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3579   "*
3580 {
3581   int extract_start = INTVAL (operands[5]) & 31;
3582   int extract_size = INTVAL (operands[4]) & 31;
3583   int insert_start = INTVAL (operands[2]) & 31;
3584   int insert_size = INTVAL (operands[1]) & 31;
3585
3586 /* Align extract field with insert field */
3587   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3588   operands[1] = GEN_INT (insert_start + insert_size - 1);
3589   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
3590 }"
3591   [(set_attr "type" "insert_word")])
3592
3593 ;; combine patterns for rlwimi
3594 (define_insn "*insvsi_internal5"
3595   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3596         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3597                         (match_operand:SI 1 "mask_operand" "i"))
3598                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3599                                      (match_operand:SI 2 "const_int_operand" "i"))
3600                         (match_operand:SI 5 "mask_operand" "i"))))]
3601   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3602   "*
3603 {
3604  int me = extract_ME(operands[5]);
3605  int mb = extract_MB(operands[5]);
3606  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3607  operands[2] = GEN_INT(mb);
3608  operands[1] = GEN_INT(me);
3609  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3610 }"
3611   [(set_attr "type" "insert_word")])
3612
3613 (define_insn "*insvsi_internal6"
3614   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3615         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3616                                      (match_operand:SI 2 "const_int_operand" "i"))
3617                         (match_operand:SI 5 "mask_operand" "i"))
3618                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3619                         (match_operand:SI 1 "mask_operand" "i"))))]
3620   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3621   "*
3622 {
3623  int me = extract_ME(operands[5]);
3624  int mb = extract_MB(operands[5]);
3625  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3626  operands[2] = GEN_INT(mb);
3627  operands[1] = GEN_INT(me);
3628  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3629 }"
3630   [(set_attr "type" "insert_word")])
3631
3632 (define_insn "insvdi"
3633   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3634                          (match_operand:SI 1 "const_int_operand" "i")
3635                          (match_operand:SI 2 "const_int_operand" "i"))
3636         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3637   "TARGET_POWERPC64"
3638   "*
3639 {
3640   int start = INTVAL (operands[2]) & 63;
3641   int size = INTVAL (operands[1]) & 63;
3642
3643   operands[1] = GEN_INT (64 - start - size);
3644   return \"rldimi %0,%3,%H1,%H2\";
3645 }"
3646   [(set_attr "type" "insert_dword")])
3647
3648 (define_insn "*insvdi_internal2"
3649   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3650                          (match_operand:SI 1 "const_int_operand" "i")
3651                          (match_operand:SI 2 "const_int_operand" "i"))
3652         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3653                      (match_operand:SI 4 "const_int_operand" "i")))]
3654   "TARGET_POWERPC64
3655    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3656   "*
3657 {
3658   int shift = INTVAL (operands[4]) & 63;
3659   int start = (INTVAL (operands[2]) & 63) - 32;
3660   int size = INTVAL (operands[1]) & 63;
3661
3662   operands[4] = GEN_INT (64 - shift - start - size);
3663   operands[2] = GEN_INT (start);
3664   operands[1] = GEN_INT (start + size - 1);
3665   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3666 }")
3667
3668 (define_insn "*insvdi_internal3"
3669   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3670                          (match_operand:SI 1 "const_int_operand" "i")
3671                          (match_operand:SI 2 "const_int_operand" "i"))
3672         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3673                      (match_operand:SI 4 "const_int_operand" "i")))]
3674   "TARGET_POWERPC64
3675    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3676   "*
3677 {
3678   int shift = INTVAL (operands[4]) & 63;
3679   int start = (INTVAL (operands[2]) & 63) - 32;
3680   int size = INTVAL (operands[1]) & 63;
3681
3682   operands[4] = GEN_INT (64 - shift - start - size);
3683   operands[2] = GEN_INT (start);
3684   operands[1] = GEN_INT (start + size - 1);
3685   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3686 }")
3687
3688 (define_expand "extzv"
3689   [(set (match_operand 0 "gpc_reg_operand" "")
3690         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3691                        (match_operand:SI 2 "const_int_operand" "")
3692                        (match_operand:SI 3 "const_int_operand" "")))]
3693   ""
3694   "
3695 {
3696   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3697      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3698      compiler if the address of the structure is taken later.  */
3699   if (GET_CODE (operands[0]) == SUBREG
3700       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3701     FAIL;
3702
3703   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3704     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
3705   else
3706     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
3707   DONE;
3708 }")
3709
3710 (define_insn "extzvsi"
3711   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3712         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3713                          (match_operand:SI 2 "const_int_operand" "i")
3714                          (match_operand:SI 3 "const_int_operand" "i")))]
3715   ""
3716   "*
3717 {
3718   int start = INTVAL (operands[3]) & 31;
3719   int size = INTVAL (operands[2]) & 31;
3720
3721   if (start + size >= 32)
3722     operands[3] = const0_rtx;
3723   else
3724     operands[3] = GEN_INT (start + size);
3725   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
3726 }")
3727
3728 (define_insn "*extzvsi_internal1"
3729   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3730         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3731                          (match_operand:SI 2 "const_int_operand" "i,i")
3732                          (match_operand:SI 3 "const_int_operand" "i,i"))
3733                     (const_int 0)))
3734    (clobber (match_scratch:SI 4 "=r,r"))]
3735   ""
3736   "*
3737 {
3738   int start = INTVAL (operands[3]) & 31;
3739   int size = INTVAL (operands[2]) & 31;
3740
3741   /* Force split for non-cc0 compare.  */
3742   if (which_alternative == 1)
3743      return \"#\";
3744
3745   /* If the bit-field being tested fits in the upper or lower half of a
3746      word, it is possible to use andiu. or andil. to test it.  This is
3747      useful because the condition register set-use delay is smaller for
3748      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3749      position is 0 because the LT and GT bits may be set wrong.  */
3750
3751   if ((start > 0 && start + size <= 16) || start >= 16)
3752     {
3753       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3754                               - (1 << (16 - (start & 15) - size))));
3755       if (start < 16)
3756         return \"{andiu.|andis.} %4,%1,%3\";
3757       else
3758         return \"{andil.|andi.} %4,%1,%3\";
3759     }
3760
3761   if (start + size >= 32)
3762     operands[3] = const0_rtx;
3763   else
3764     operands[3] = GEN_INT (start + size);
3765   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
3766 }"
3767   [(set_attr "type" "delayed_compare")
3768    (set_attr "length" "4,8")])
3769
3770 (define_split
3771   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3772         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3773                          (match_operand:SI 2 "const_int_operand" "")
3774                          (match_operand:SI 3 "const_int_operand" ""))
3775                     (const_int 0)))
3776    (clobber (match_scratch:SI 4 ""))]
3777   "reload_completed"
3778   [(set (match_dup 4)
3779         (zero_extract:SI (match_dup 1) (match_dup 2)
3780                          (match_dup 3)))
3781    (set (match_dup 0)
3782         (compare:CC (match_dup 4)
3783                     (const_int 0)))]
3784   "")
3785
3786 (define_insn "*extzvsi_internal2"
3787   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3788         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3789                          (match_operand:SI 2 "const_int_operand" "i,i")
3790                          (match_operand:SI 3 "const_int_operand" "i,i"))
3791                     (const_int 0)))
3792    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3793         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3794   ""
3795   "*
3796 {
3797   int start = INTVAL (operands[3]) & 31;
3798   int size = INTVAL (operands[2]) & 31;
3799
3800   /* Force split for non-cc0 compare.  */
3801   if (which_alternative == 1)
3802      return \"#\";
3803
3804   /* Since we are using the output value, we can't ignore any need for
3805      a shift.  The bit-field must end at the LSB.  */
3806   if (start >= 16 && start + size == 32)
3807     {
3808       operands[3] = GEN_INT ((1 << size) - 1);
3809       return \"{andil.|andi.} %0,%1,%3\";
3810     }
3811
3812   if (start + size >= 32)
3813     operands[3] = const0_rtx;
3814   else
3815     operands[3] = GEN_INT (start + size);
3816   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
3817 }"
3818   [(set_attr "type" "delayed_compare")
3819    (set_attr "length" "4,8")])
3820
3821 (define_split
3822   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3823         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3824                          (match_operand:SI 2 "const_int_operand" "")
3825                          (match_operand:SI 3 "const_int_operand" ""))
3826                     (const_int 0)))
3827    (set (match_operand:SI 0 "gpc_reg_operand" "")
3828         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3829   "reload_completed"
3830   [(set (match_dup 0)
3831         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3832    (set (match_dup 4)
3833         (compare:CC (match_dup 0)
3834                     (const_int 0)))]
3835   "")
3836
3837 (define_insn "extzvdi"
3838   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3839         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3840                          (match_operand:SI 2 "const_int_operand" "i")
3841                          (match_operand:SI 3 "const_int_operand" "i")))]
3842   "TARGET_POWERPC64"
3843   "*
3844 {
3845   int start = INTVAL (operands[3]) & 63;
3846   int size = INTVAL (operands[2]) & 63;
3847
3848   if (start + size >= 64)
3849     operands[3] = const0_rtx;
3850   else
3851     operands[3] = GEN_INT (start + size);
3852   operands[2] = GEN_INT (64 - size);
3853   return \"rldicl %0,%1,%3,%2\";
3854 }")
3855
3856 (define_insn "*extzvdi_internal1"
3857   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3858         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3859                          (match_operand:SI 2 "const_int_operand" "i")
3860                          (match_operand:SI 3 "const_int_operand" "i"))
3861                     (const_int 0)))
3862    (clobber (match_scratch:DI 4 "=r"))]
3863   "TARGET_64BIT"
3864   "*
3865 {
3866   int start = INTVAL (operands[3]) & 63;
3867   int size = INTVAL (operands[2]) & 63;
3868
3869   if (start + size >= 64)
3870     operands[3] = const0_rtx;
3871   else
3872     operands[3] = GEN_INT (start + size);
3873   operands[2] = GEN_INT (64 - size);
3874   return \"rldicl. %4,%1,%3,%2\";
3875 }"
3876   [(set_attr "type" "compare")])
3877
3878 (define_insn "*extzvdi_internal2"
3879   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3880         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3881                          (match_operand:SI 2 "const_int_operand" "i")
3882                          (match_operand:SI 3 "const_int_operand" "i"))
3883                     (const_int 0)))
3884    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3885         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3886   "TARGET_64BIT"
3887   "*
3888 {
3889   int start = INTVAL (operands[3]) & 63;
3890   int size = INTVAL (operands[2]) & 63;
3891
3892   if (start + size >= 64)
3893     operands[3] = const0_rtx;
3894   else
3895     operands[3] = GEN_INT (start + size);
3896   operands[2] = GEN_INT (64 - size);
3897   return \"rldicl. %0,%1,%3,%2\";
3898 }"
3899   [(set_attr "type" "compare")])
3900
3901 (define_insn "rotlsi3"
3902   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3903         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3904                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
3905   ""
3906   "@
3907    {rlnm|rlwnm} %0,%1,%2,0xffffffff
3908    {rlinm|rlwinm} %0,%1,%h2,0xffffffff"
3909   [(set_attr "type" "var_shift_rotate,integer")])
3910
3911 (define_insn "*rotlsi3_internal2"
3912   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3913         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3914                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3915                     (const_int 0)))
3916    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
3917   ""
3918   "@
3919    {rlnm.|rlwnm.} %3,%1,%2,0xffffffff
3920    {rlinm.|rlwinm.} %3,%1,%h2,0xffffffff
3921    #
3922    #"
3923   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3924    (set_attr "length" "4,4,8,8")])
3925
3926 (define_split
3927   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3928         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3929                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3930                     (const_int 0)))
3931    (clobber (match_scratch:SI 3 ""))]
3932   "reload_completed"
3933   [(set (match_dup 3)
3934         (rotate:SI (match_dup 1) (match_dup 2)))
3935    (set (match_dup 0)
3936         (compare:CC (match_dup 3)
3937                     (const_int 0)))]
3938   "")
3939
3940 (define_insn "*rotlsi3_internal3"
3941   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3942         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3943                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3944                     (const_int 0)))
3945    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3946         (rotate:SI (match_dup 1) (match_dup 2)))]
3947   ""
3948   "@
3949    {rlnm.|rlwnm.} %0,%1,%2,0xffffffff
3950    {rlinm.|rlwinm.} %0,%1,%h2,0xffffffff
3951    #
3952    #"
3953   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3954    (set_attr "length" "4,4,8,8")])
3955
3956 (define_split
3957   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3958         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3959                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3960                     (const_int 0)))
3961    (set (match_operand:SI 0 "gpc_reg_operand" "")
3962         (rotate:SI (match_dup 1) (match_dup 2)))]
3963   "reload_completed"
3964   [(set (match_dup 0)
3965         (rotate:SI (match_dup 1) (match_dup 2)))
3966    (set (match_dup 3)
3967         (compare:CC (match_dup 0)
3968                     (const_int 0)))]
3969   "")
3970
3971 (define_insn "*rotlsi3_internal4"
3972   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3973         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3974                            (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
3975                 (match_operand:SI 3 "mask_operand" "n,n")))]
3976   ""
3977   "@
3978    {rlnm|rlwnm} %0,%1,%2,%m3,%M3
3979    {rlinm|rlwinm} %0,%1,%h2,%m3,%M3"
3980   [(set_attr "type" "var_shift_rotate,integer")])
3981
3982 (define_insn "*rotlsi3_internal5"
3983   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3984         (compare:CC (and:SI
3985                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3986                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3987                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
3988                     (const_int 0)))
3989    (clobber (match_scratch:SI 4 "=r,r,r,r"))]
3990   ""
3991   "@
3992    {rlnm.|rlwnm.} %4,%1,%2,%m3,%M3
3993    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
3994    #
3995    #"
3996   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
3997    (set_attr "length" "4,4,8,8")])
3998
3999 (define_split
4000   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4001         (compare:CC (and:SI
4002                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4003                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
4004                      (match_operand:SI 3 "mask_operand" ""))
4005                     (const_int 0)))
4006    (clobber (match_scratch:SI 4 ""))]
4007   "reload_completed"
4008   [(set (match_dup 4)
4009         (and:SI (rotate:SI (match_dup 1)
4010                                 (match_dup 2))
4011                      (match_dup 3)))
4012    (set (match_dup 0)
4013         (compare:CC (match_dup 4)
4014                     (const_int 0)))]
4015   "")
4016
4017 (define_insn "*rotlsi3_internal6"
4018   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
4019         (compare:CC (and:SI
4020                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4021                                 (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4022                      (match_operand:SI 3 "mask_operand" "n,n,n,n"))
4023                     (const_int 0)))
4024    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4025         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4026   ""
4027   "@
4028    {rlnm.|rlwnm.} %0,%1,%2,%m3,%M3
4029    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
4030    #
4031    #"
4032   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4033    (set_attr "length" "4,4,8,8")])
4034
4035 (define_split
4036   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4037         (compare:CC (and:SI
4038                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4039                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
4040                      (match_operand:SI 3 "mask_operand" ""))
4041                     (const_int 0)))
4042    (set (match_operand:SI 0 "gpc_reg_operand" "")
4043         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4044   "reload_completed"
4045   [(set (match_dup 0)
4046         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4047    (set (match_dup 4)
4048         (compare:CC (match_dup 0)
4049                     (const_int 0)))]
4050   "")
4051
4052 (define_insn "*rotlsi3_internal7"
4053   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4054         (zero_extend:SI
4055          (subreg:QI
4056           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4057                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
4058   ""
4059   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
4060
4061 (define_insn "*rotlsi3_internal8"
4062   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4063         (compare:CC (zero_extend:SI
4064                      (subreg:QI
4065                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4066                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4067                     (const_int 0)))
4068    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4069   ""
4070   "@
4071    {rlnm.|rlwnm.} %3,%1,%2,0xff
4072    {rlinm.|rlwinm.} %3,%1,%h2,0xff
4073    #
4074    #"
4075   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4076    (set_attr "length" "4,4,8,8")])
4077
4078 (define_split
4079   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4080         (compare:CC (zero_extend:SI
4081                      (subreg:QI
4082                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4083                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4084                     (const_int 0)))
4085    (clobber (match_scratch:SI 3 ""))]
4086   "reload_completed"
4087   [(set (match_dup 3)
4088         (zero_extend:SI (subreg:QI
4089                       (rotate:SI (match_dup 1)
4090                                  (match_dup 2)) 0)))
4091    (set (match_dup 0)
4092         (compare:CC (match_dup 3)
4093                     (const_int 0)))]
4094   "")
4095
4096 (define_insn "*rotlsi3_internal9"
4097   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4098         (compare:CC (zero_extend:SI
4099                      (subreg:QI
4100                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4101                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4102                     (const_int 0)))
4103    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4104         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4105   ""
4106   "@
4107    {rlnm.|rlwnm.} %0,%1,%2,0xff
4108    {rlinm.|rlwinm.} %0,%1,%h2,0xff
4109    #
4110    #"
4111   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4112    (set_attr "length" "4,4,8,8")])
4113
4114 (define_split
4115   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4116         (compare:CC (zero_extend:SI
4117                      (subreg:QI
4118                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4119                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4120                     (const_int 0)))
4121    (set (match_operand:SI 0 "gpc_reg_operand" "")
4122         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4123   "reload_completed"
4124   [(set (match_dup 0)
4125         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4126    (set (match_dup 3)
4127         (compare:CC (match_dup 0)
4128                     (const_int 0)))]
4129   "")
4130
4131 (define_insn "*rotlsi3_internal10"
4132   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4133         (zero_extend:SI
4134          (subreg:HI
4135           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4136                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")) 0)))]
4137   ""
4138   "@
4139    {rlnm|rlwnm} %0,%1,%2,0xffff
4140    {rlinm|rlwinm} %0,%1,%h2,0xffff"
4141   [(set_attr "type" "var_shift_rotate,integer")])
4142
4143
4144 (define_insn "*rotlsi3_internal11"
4145   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4146         (compare:CC (zero_extend:SI
4147                      (subreg:HI
4148                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4149                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4150                     (const_int 0)))
4151    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4152   ""
4153   "@
4154    {rlnm.|rlwnm.} %3,%1,%2,0xffff
4155    {rlinm.|rlwinm.} %3,%1,%h2,0xffff
4156    #
4157    #"
4158   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4159    (set_attr "length" "4,4,8,8")])
4160
4161 (define_split
4162   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4163         (compare:CC (zero_extend:SI
4164                      (subreg:HI
4165                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4166                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4167                     (const_int 0)))
4168    (clobber (match_scratch:SI 3 ""))]
4169   "reload_completed"
4170   [(set (match_dup 3)
4171         (zero_extend:SI (subreg:HI
4172                       (rotate:SI (match_dup 1)
4173                                  (match_dup 2)) 0)))
4174    (set (match_dup 0)
4175         (compare:CC (match_dup 3)
4176                     (const_int 0)))]
4177   "")
4178
4179 (define_insn "*rotlsi3_internal12"
4180   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4181         (compare:CC (zero_extend:SI
4182                      (subreg:HI
4183                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4184                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
4185                     (const_int 0)))
4186    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4187         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4188   ""
4189   "@
4190    {rlnm.|rlwnm.} %0,%1,%2,0xffff
4191    {rlinm.|rlwinm.} %0,%1,%h2,0xffff
4192    #
4193    #"
4194   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4195    (set_attr "length" "4,4,8,8")])
4196
4197 (define_split
4198   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4199         (compare:CC (zero_extend:SI
4200                      (subreg:HI
4201                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4202                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4203                     (const_int 0)))
4204    (set (match_operand:SI 0 "gpc_reg_operand" "")
4205         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4206   "reload_completed"
4207   [(set (match_dup 0)
4208         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4209    (set (match_dup 3)
4210         (compare:CC (match_dup 0)
4211                     (const_int 0)))]
4212   "")
4213
4214 ;; Note that we use "sle." instead of "sl." so that we can set
4215 ;; SHIFT_COUNT_TRUNCATED.
4216
4217 (define_expand "ashlsi3"
4218   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4219    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4220    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4221   ""
4222   "
4223 {
4224   if (TARGET_POWER)
4225     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
4226   else
4227     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
4228   DONE;
4229 }")
4230
4231 (define_insn "ashlsi3_power"
4232   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4233         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4234                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4235    (clobber (match_scratch:SI 3 "=q,X"))]
4236   "TARGET_POWER"
4237   "@
4238    sle %0,%1,%2
4239    {sli|slwi} %0,%1,%h2")
4240
4241 (define_insn "ashlsi3_no_power"
4242   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4243         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4244                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4245   "! TARGET_POWER"
4246   "@
4247    {sl|slw} %0,%1,%2
4248    {sli|slwi} %0,%1,%h2"
4249   [(set_attr "type" "var_shift_rotate,shift")])
4250
4251 (define_insn ""
4252   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4253         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4254                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4255                     (const_int 0)))
4256    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4257    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4258   "TARGET_POWER"
4259   "@
4260    sle. %3,%1,%2
4261    {sli.|slwi.} %3,%1,%h2
4262    #
4263    #"
4264   [(set_attr "type" "delayed_compare")
4265    (set_attr "length" "4,4,8,8")])
4266
4267 (define_split
4268   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4269         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4270                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4271                     (const_int 0)))
4272    (clobber (match_scratch:SI 3 ""))
4273    (clobber (match_scratch:SI 4 ""))]
4274   "TARGET_POWER && reload_completed"
4275   [(parallel [(set (match_dup 3)
4276         (ashift:SI (match_dup 1) (match_dup 2)))
4277    (clobber (match_dup 4))])
4278    (set (match_dup 0)
4279         (compare:CC (match_dup 3)
4280                     (const_int 0)))]
4281   "")
4282
4283 (define_insn ""
4284   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4285         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4286                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4287                     (const_int 0)))
4288    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4289   "! TARGET_POWER && TARGET_32BIT"
4290   "@
4291    {sl.|slw.} %3,%1,%2
4292    {sli.|slwi.} %3,%1,%h2
4293    #
4294    #"
4295   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4296    (set_attr "length" "4,4,8,8")])
4297
4298 (define_split
4299   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4300         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4301                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4302                     (const_int 0)))
4303    (clobber (match_scratch:SI 3 ""))]
4304   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4305   [(set (match_dup 3)
4306         (ashift:SI (match_dup 1) (match_dup 2)))
4307    (set (match_dup 0)
4308         (compare:CC (match_dup 3)
4309                     (const_int 0)))]
4310   "")
4311
4312 (define_insn ""
4313   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4314         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4315                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4316                     (const_int 0)))
4317    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4318         (ashift:SI (match_dup 1) (match_dup 2)))
4319    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4320   "TARGET_POWER"
4321   "@
4322    sle. %0,%1,%2
4323    {sli.|slwi.} %0,%1,%h2
4324    #
4325    #"
4326   [(set_attr "type" "delayed_compare")
4327    (set_attr "length" "4,4,8,8")])
4328
4329 (define_split
4330   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4331         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4332                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4333                     (const_int 0)))
4334    (set (match_operand:SI 0 "gpc_reg_operand" "")
4335         (ashift:SI (match_dup 1) (match_dup 2)))
4336    (clobber (match_scratch:SI 4 ""))]
4337   "TARGET_POWER && reload_completed"
4338   [(parallel [(set (match_dup 0)
4339         (ashift:SI (match_dup 1) (match_dup 2)))
4340    (clobber (match_dup 4))])
4341    (set (match_dup 3)
4342         (compare:CC (match_dup 0)
4343                     (const_int 0)))]
4344   "")
4345
4346 (define_insn ""
4347   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4348         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4349                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4350                     (const_int 0)))
4351    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4352         (ashift:SI (match_dup 1) (match_dup 2)))]
4353   "! TARGET_POWER && TARGET_32BIT"
4354   "@
4355    {sl.|slw.} %0,%1,%2
4356    {sli.|slwi.} %0,%1,%h2
4357    #
4358    #"
4359   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4360    (set_attr "length" "4,4,8,8")])
4361
4362 (define_split
4363   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4364         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4365                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4366                     (const_int 0)))
4367    (set (match_operand:SI 0 "gpc_reg_operand" "")
4368         (ashift:SI (match_dup 1) (match_dup 2)))]
4369   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4370   [(set (match_dup 0)
4371         (ashift:SI (match_dup 1) (match_dup 2)))
4372    (set (match_dup 3)
4373         (compare:CC (match_dup 0)
4374                     (const_int 0)))]
4375   "")
4376
4377 (define_insn "rlwinm"
4378   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4379         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4380                            (match_operand:SI 2 "const_int_operand" "i"))
4381                 (match_operand:SI 3 "mask_operand" "n")))]
4382   "includes_lshift_p (operands[2], operands[3])"
4383   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
4384
4385 (define_insn ""
4386   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4387         (compare:CC
4388          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4389                             (match_operand:SI 2 "const_int_operand" "i,i"))
4390                  (match_operand:SI 3 "mask_operand" "n,n"))
4391          (const_int 0)))
4392    (clobber (match_scratch:SI 4 "=r,r"))]
4393   "includes_lshift_p (operands[2], operands[3])"
4394   "@
4395    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
4396    #"
4397   [(set_attr "type" "delayed_compare")
4398    (set_attr "length" "4,8")])
4399
4400 (define_split
4401   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4402         (compare:CC
4403          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4404                             (match_operand:SI 2 "const_int_operand" ""))
4405                  (match_operand:SI 3 "mask_operand" ""))
4406          (const_int 0)))
4407    (clobber (match_scratch:SI 4 ""))]
4408   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4409   [(set (match_dup 4)
4410         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
4411                  (match_dup 3)))
4412    (set (match_dup 0)
4413         (compare:CC (match_dup 4)
4414                     (const_int 0)))]
4415   "")
4416
4417 (define_insn ""
4418   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4419         (compare:CC
4420          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4421                             (match_operand:SI 2 "const_int_operand" "i,i"))
4422                  (match_operand:SI 3 "mask_operand" "n,n"))
4423          (const_int 0)))
4424    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4425         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4426   "includes_lshift_p (operands[2], operands[3])"
4427   "@
4428    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
4429    #"
4430   [(set_attr "type" "delayed_compare")
4431    (set_attr "length" "4,8")])
4432
4433 (define_split
4434   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4435         (compare:CC
4436          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4437                             (match_operand:SI 2 "const_int_operand" ""))
4438                  (match_operand:SI 3 "mask_operand" ""))
4439          (const_int 0)))
4440    (set (match_operand:SI 0 "gpc_reg_operand" "")
4441         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4442   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4443   [(set (match_dup 0)
4444         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4445    (set (match_dup 4)
4446         (compare:CC (match_dup 0)
4447                     (const_int 0)))]
4448   "")
4449
4450 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
4451 ;; "sli x,x,0".
4452 (define_expand "lshrsi3"
4453   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4454    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4455    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4456   ""
4457   "
4458 {
4459   if (TARGET_POWER)
4460     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
4461   else
4462     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
4463   DONE;
4464 }")
4465
4466 (define_insn "lshrsi3_power"
4467   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4468         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4469                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
4470    (clobber (match_scratch:SI 3 "=q,X,X"))]
4471   "TARGET_POWER"
4472   "@
4473   sre %0,%1,%2
4474   mr %0,%1
4475   {s%A2i|s%A2wi} %0,%1,%h2")
4476
4477 (define_insn "lshrsi3_no_power"
4478   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4479         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4480                      (match_operand:SI 2 "reg_or_cint_operand" "O,r,i")))]
4481   "! TARGET_POWER"
4482   "@
4483   mr %0,%1
4484   {sr|srw} %0,%1,%2
4485   {sri|srwi} %0,%1,%h2"
4486   [(set_attr "type" "integer,var_shift_rotate,shift")])
4487
4488 (define_insn ""
4489   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4490         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4491                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
4492                     (const_int 0)))
4493    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
4494    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
4495   "TARGET_POWER"
4496   "@
4497   sre. %3,%1,%2
4498   mr. %1,%1
4499   {s%A2i.|s%A2wi.} %3,%1,%h2
4500   #
4501   #
4502   #"
4503   [(set_attr "type" "delayed_compare")
4504    (set_attr "length" "4,4,4,8,8,8")])
4505
4506 (define_split
4507   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4508         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4509                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4510                     (const_int 0)))
4511    (clobber (match_scratch:SI 3 ""))
4512    (clobber (match_scratch:SI 4 ""))]
4513   "TARGET_POWER && reload_completed"
4514   [(parallel [(set (match_dup 3)
4515         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4516    (clobber (match_dup 4))])
4517    (set (match_dup 0)
4518         (compare:CC (match_dup 3)
4519                     (const_int 0)))]
4520   "")
4521
4522 (define_insn ""
4523   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4524         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4525                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
4526                     (const_int 0)))
4527    (clobber (match_scratch:SI 3 "=X,r,r,X,r,r"))]
4528   "! TARGET_POWER && TARGET_32BIT"
4529   "@
4530    mr. %1,%1
4531    {sr.|srw.} %3,%1,%2
4532    {sri.|srwi.} %3,%1,%h2
4533    #
4534    #
4535    #"
4536   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4537    (set_attr "length" "4,4,4,8,8,8")])
4538
4539 (define_split
4540   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4541         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4542                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4543                     (const_int 0)))
4544    (clobber (match_scratch:SI 3 ""))]
4545   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4546   [(set (match_dup 3)
4547         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4548    (set (match_dup 0)
4549         (compare:CC (match_dup 3)
4550                     (const_int 0)))]
4551   "")
4552
4553 (define_insn ""
4554   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4555         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4556                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
4557                     (const_int 0)))
4558    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
4559         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4560    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
4561   "TARGET_POWER"
4562   "@
4563   sre. %0,%1,%2
4564   mr. %0,%1
4565   {s%A2i.|s%A2wi.} %0,%1,%h2
4566   #
4567   #
4568   #"
4569   [(set_attr "type" "delayed_compare")
4570    (set_attr "length" "4,4,4,8,8,8")])
4571
4572 (define_split
4573   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4574         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4575                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4576                     (const_int 0)))
4577    (set (match_operand:SI 0 "gpc_reg_operand" "")
4578         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4579    (clobber (match_scratch:SI 4 ""))]
4580   "TARGET_POWER && reload_completed"
4581   [(parallel [(set (match_dup 0)
4582         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4583    (clobber (match_dup 4))])
4584    (set (match_dup 3)
4585         (compare:CC (match_dup 0)
4586                     (const_int 0)))]
4587   "")
4588
4589 (define_insn ""
4590   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4591         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4592                                  (match_operand:SI 2 "reg_or_cint_operand" "O,r,i,O,r,i"))
4593                     (const_int 0)))
4594    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
4595         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4596   "! TARGET_POWER && TARGET_32BIT"
4597   "@
4598    mr. %0,%1
4599    {sr.|srw.} %0,%1,%2
4600    {sri.|srwi.} %0,%1,%h2
4601    #
4602    #
4603    #"
4604   [(set_attr "type" "delayed_compare,var_delayed_compare,delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4605    (set_attr "length" "4,4,4,8,8,8")])
4606
4607 (define_split
4608   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4609         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4610                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4611                     (const_int 0)))
4612    (set (match_operand:SI 0 "gpc_reg_operand" "")
4613         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4614   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4615   [(set (match_dup 0)
4616         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4617    (set (match_dup 3)
4618         (compare:CC (match_dup 0)
4619                     (const_int 0)))]
4620   "")
4621
4622 (define_insn ""
4623   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4624         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4625                              (match_operand:SI 2 "const_int_operand" "i"))
4626                 (match_operand:SI 3 "mask_operand" "n")))]
4627   "includes_rshift_p (operands[2], operands[3])"
4628   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
4629
4630 (define_insn ""
4631   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4632         (compare:CC
4633          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4634                               (match_operand:SI 2 "const_int_operand" "i,i"))
4635                  (match_operand:SI 3 "mask_operand" "n,n"))
4636          (const_int 0)))
4637    (clobber (match_scratch:SI 4 "=r,r"))]
4638   "includes_rshift_p (operands[2], operands[3])"
4639   "@
4640    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
4641    #"
4642   [(set_attr "type" "delayed_compare")
4643    (set_attr "length" "4,8")])
4644
4645 (define_split
4646   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4647         (compare:CC
4648          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4649                               (match_operand:SI 2 "const_int_operand" ""))
4650                  (match_operand:SI 3 "mask_operand" ""))
4651          (const_int 0)))
4652    (clobber (match_scratch:SI 4 ""))]
4653   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4654   [(set (match_dup 4)
4655         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4656                  (match_dup 3)))
4657    (set (match_dup 0)
4658         (compare:CC (match_dup 4)
4659                     (const_int 0)))]
4660   "")
4661
4662 (define_insn ""
4663   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4664         (compare:CC
4665          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4666                               (match_operand:SI 2 "const_int_operand" "i,i"))
4667                  (match_operand:SI 3 "mask_operand" "n,n"))
4668          (const_int 0)))
4669    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4670         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4671   "includes_rshift_p (operands[2], operands[3])"
4672   "@
4673    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
4674    #"
4675   [(set_attr "type" "delayed_compare")
4676    (set_attr "length" "4,8")])
4677
4678 (define_split
4679   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4680         (compare:CC
4681          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4682                               (match_operand:SI 2 "const_int_operand" ""))
4683                  (match_operand:SI 3 "mask_operand" ""))
4684          (const_int 0)))
4685    (set (match_operand:SI 0 "gpc_reg_operand" "")
4686         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4687   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4688   [(set (match_dup 0)
4689         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4690    (set (match_dup 4)
4691         (compare:CC (match_dup 0)
4692                     (const_int 0)))]
4693   "")
4694
4695 (define_insn ""
4696   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4697         (zero_extend:SI
4698          (subreg:QI
4699           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4700                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4701   "includes_rshift_p (operands[2], GEN_INT (255))"
4702   "{rlinm|rlwinm} %0,%1,%s2,0xff")
4703
4704 (define_insn ""
4705   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4706         (compare:CC
4707          (zero_extend:SI
4708           (subreg:QI
4709            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4710                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4711          (const_int 0)))
4712    (clobber (match_scratch:SI 3 "=r,r"))]
4713   "includes_rshift_p (operands[2], GEN_INT (255))"
4714   "@
4715    {rlinm.|rlwinm.} %3,%1,%s2,0xff
4716    #"
4717   [(set_attr "type" "delayed_compare")
4718    (set_attr "length" "4,8")])
4719
4720 (define_split
4721   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4722         (compare:CC
4723          (zero_extend:SI
4724           (subreg:QI
4725            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4726                         (match_operand:SI 2 "const_int_operand" "")) 0))
4727          (const_int 0)))
4728    (clobber (match_scratch:SI 3 ""))]
4729   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4730   [(set (match_dup 3)
4731         (zero_extend:SI (subreg:QI
4732            (lshiftrt:SI (match_dup 1)
4733                         (match_dup 2)) 0)))
4734    (set (match_dup 0)
4735         (compare:CC (match_dup 3)
4736                     (const_int 0)))]
4737   "")
4738
4739 (define_insn ""
4740   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4741         (compare:CC
4742          (zero_extend:SI
4743           (subreg:QI
4744            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4745                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4746          (const_int 0)))
4747    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4748         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4749   "includes_rshift_p (operands[2], GEN_INT (255))"
4750   "@
4751    {rlinm.|rlwinm.} %0,%1,%s2,0xff
4752    #"
4753   [(set_attr "type" "delayed_compare")
4754    (set_attr "length" "4,8")])
4755
4756 (define_split
4757   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4758         (compare:CC
4759          (zero_extend:SI
4760           (subreg:QI
4761            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4762                         (match_operand:SI 2 "const_int_operand" "")) 0))
4763          (const_int 0)))
4764    (set (match_operand:SI 0 "gpc_reg_operand" "")
4765         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4766   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4767   [(set (match_dup 0)
4768         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4769    (set (match_dup 3)
4770         (compare:CC (match_dup 0)
4771                     (const_int 0)))]
4772   "")
4773
4774 (define_insn ""
4775   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4776         (zero_extend:SI
4777          (subreg:HI
4778           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4779                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4780   "includes_rshift_p (operands[2], GEN_INT (65535))"
4781   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
4782
4783 (define_insn ""
4784   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4785         (compare:CC
4786          (zero_extend:SI
4787           (subreg:HI
4788            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4789                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4790          (const_int 0)))
4791    (clobber (match_scratch:SI 3 "=r,r"))]
4792   "includes_rshift_p (operands[2], GEN_INT (65535))"
4793   "@
4794    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
4795    #"
4796   [(set_attr "type" "delayed_compare")
4797    (set_attr "length" "4,8")])
4798
4799 (define_split
4800   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4801         (compare:CC
4802          (zero_extend:SI
4803           (subreg:HI
4804            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4805                         (match_operand:SI 2 "const_int_operand" "")) 0))
4806          (const_int 0)))
4807    (clobber (match_scratch:SI 3 ""))]
4808   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4809   [(set (match_dup 3)
4810         (zero_extend:SI (subreg:HI
4811            (lshiftrt:SI (match_dup 1)
4812                         (match_dup 2)) 0)))
4813    (set (match_dup 0)
4814         (compare:CC (match_dup 3)
4815                     (const_int 0)))]
4816   "")
4817
4818 (define_insn ""
4819   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4820         (compare:CC
4821          (zero_extend:SI
4822           (subreg:HI
4823            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4824                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4825          (const_int 0)))
4826    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4827         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4828   "includes_rshift_p (operands[2], GEN_INT (65535))"
4829   "@
4830    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
4831    #"
4832   [(set_attr "type" "delayed_compare")
4833    (set_attr "length" "4,8")])
4834
4835 (define_split
4836   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4837         (compare:CC
4838          (zero_extend:SI
4839           (subreg:HI
4840            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4841                         (match_operand:SI 2 "const_int_operand" "")) 0))
4842          (const_int 0)))
4843    (set (match_operand:SI 0 "gpc_reg_operand" "")
4844         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4845   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4846   [(set (match_dup 0)
4847         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4848    (set (match_dup 3)
4849         (compare:CC (match_dup 0)
4850                     (const_int 0)))]
4851   "")
4852
4853 (define_insn ""
4854   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4855                          (const_int 1)
4856                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4857         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4858                      (const_int 31)))]
4859   "TARGET_POWER"
4860   "rrib %0,%1,%2")
4861
4862 (define_insn ""
4863   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4864                          (const_int 1)
4865                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4866         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4867                      (const_int 31)))]
4868   "TARGET_POWER"
4869   "rrib %0,%1,%2")
4870
4871 (define_insn ""
4872   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4873                          (const_int 1)
4874                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4875         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4876                          (const_int 1)
4877                          (const_int 0)))]
4878   "TARGET_POWER"
4879   "rrib %0,%1,%2")
4880
4881 (define_expand "ashrsi3"
4882   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4883         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4884                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4885   ""
4886   "
4887 {
4888   if (TARGET_POWER)
4889     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
4890   else
4891     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
4892   DONE;
4893 }")
4894
4895 (define_insn "ashrsi3_power"
4896   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4897         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4898                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4899    (clobber (match_scratch:SI 3 "=q,X"))]
4900   "TARGET_POWER"
4901   "@
4902    srea %0,%1,%2
4903    {srai|srawi} %0,%1,%h2"
4904   [(set_attr "type" "shift")])
4905
4906 (define_insn "ashrsi3_no_power"
4907   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4908         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4909                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
4910   "! TARGET_POWER"
4911   "@
4912    {sra|sraw} %0,%1,%2
4913    {srai|srawi} %0,%1,%h2"
4914   [(set_attr "type" "var_shift_rotate,shift")])
4915
4916 (define_insn ""
4917   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4918         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4919                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4920                     (const_int 0)))
4921    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4922    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4923   "TARGET_POWER"
4924   "@
4925    srea. %3,%1,%2
4926    {srai.|srawi.} %3,%1,%h2
4927    #
4928    #"
4929   [(set_attr "type" "delayed_compare")
4930    (set_attr "length" "4,4,8,8")])
4931
4932 (define_split
4933   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4934         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4935                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4936                     (const_int 0)))
4937    (clobber (match_scratch:SI 3 ""))
4938    (clobber (match_scratch:SI 4 ""))]
4939   "TARGET_POWER && reload_completed"
4940   [(parallel [(set (match_dup 3)
4941         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4942    (clobber (match_dup 4))])
4943    (set (match_dup 0)
4944         (compare:CC (match_dup 3)
4945                     (const_int 0)))]
4946   "")
4947
4948 (define_insn ""
4949   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4950         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4951                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4952                     (const_int 0)))
4953    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
4954   "! TARGET_POWER"
4955   "@
4956    {sra.|sraw.} %3,%1,%2
4957    {srai.|srawi.} %3,%1,%h2
4958    #
4959    #"
4960   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
4961    (set_attr "length" "4,4,8,8")])
4962
4963 (define_split
4964   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4965         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4966                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4967                     (const_int 0)))
4968    (clobber (match_scratch:SI 3 ""))]
4969   "! TARGET_POWER && reload_completed"
4970   [(set (match_dup 3)
4971         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4972    (set (match_dup 0)
4973         (compare:CC (match_dup 3)
4974                     (const_int 0)))]
4975   "")
4976
4977 (define_insn ""
4978   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4979         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4980                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4981                     (const_int 0)))
4982    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4983         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4984    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4985   "TARGET_POWER"
4986   "@
4987    srea. %0,%1,%2
4988    {srai.|srawi.} %0,%1,%h2
4989    #
4990    #"
4991   [(set_attr "type" "delayed_compare")
4992    (set_attr "length" "4,4,8,8")])
4993
4994 (define_split
4995   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4996         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4997                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4998                     (const_int 0)))
4999    (set (match_operand:SI 0 "gpc_reg_operand" "")
5000         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5001    (clobber (match_scratch:SI 4 ""))]
5002   "TARGET_POWER && reload_completed"
5003   [(parallel [(set (match_dup 0)
5004         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5005    (clobber (match_dup 4))])
5006    (set (match_dup 3)
5007         (compare:CC (match_dup 0)
5008                     (const_int 0)))]
5009   "")
5010
5011 (define_insn ""
5012   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5013         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5014                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5015                     (const_int 0)))
5016    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
5017         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5018   "! TARGET_POWER"
5019   "@
5020    {sra.|sraw.} %0,%1,%2
5021    {srai.|srawi.} %0,%1,%h2
5022    #
5023    #"
5024   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
5025    (set_attr "length" "4,4,8,8")])
5026 \f
5027 (define_split
5028   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5029         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5030                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5031                     (const_int 0)))
5032    (set (match_operand:SI 0 "gpc_reg_operand" "")
5033         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5034   "! TARGET_POWER && reload_completed"
5035   [(set (match_dup 0)
5036         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5037    (set (match_dup 3)
5038         (compare:CC (match_dup 0)
5039                     (const_int 0)))]
5040   "")
5041
5042 ;; Floating-point insns, excluding normal data motion.
5043 ;;
5044 ;; PowerPC has a full set of single-precision floating point instructions.
5045 ;;
5046 ;; For the POWER architecture, we pretend that we have both SFmode and
5047 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
5048 ;; The only conversions we will do will be when storing to memory.  In that
5049 ;; case, we will use the "frsp" instruction before storing.
5050 ;;
5051 ;; Note that when we store into a single-precision memory location, we need to
5052 ;; use the frsp insn first.  If the register being stored isn't dead, we
5053 ;; need a scratch register for the frsp.  But this is difficult when the store
5054 ;; is done by reload.  It is not incorrect to do the frsp on the register in
5055 ;; this case, we just lose precision that we would have otherwise gotten but
5056 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
5057
5058 (define_expand "extendsfdf2"
5059   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5060         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
5061   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5062   "")
5063
5064 (define_insn_and_split "*extendsfdf2_fpr"
5065   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f,f")
5066         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m")))]
5067   "TARGET_HARD_FLOAT && TARGET_FPRS"
5068   "@
5069    #
5070    fmr %0,%1
5071    lfs%U1%X1 %0,%1"
5072   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
5073   [(const_int 0)]
5074 {
5075   emit_note (NOTE_INSN_DELETED);
5076   DONE;
5077 }
5078   [(set_attr "type" "fp,fp,fpload")])
5079
5080 (define_expand "truncdfsf2"
5081   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5082         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
5083   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5084   "")
5085
5086 (define_insn "*truncdfsf2_fpr"
5087   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5088         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5089   "TARGET_HARD_FLOAT && TARGET_FPRS"
5090   "frsp %0,%1"
5091   [(set_attr "type" "fp")])
5092
5093 (define_insn "aux_truncdfsf2"
5094   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5095         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
5096   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5097   "frsp %0,%1"
5098   [(set_attr "type" "fp")])
5099
5100 (define_expand "negsf2"
5101   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5102         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5103   "TARGET_HARD_FLOAT"
5104   "")
5105
5106 (define_insn "*negsf2"
5107   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5108         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5109   "TARGET_HARD_FLOAT && TARGET_FPRS"
5110   "fneg %0,%1"
5111   [(set_attr "type" "fp")])
5112
5113 (define_expand "abssf2"
5114   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5115         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5116   "TARGET_HARD_FLOAT"
5117   "")
5118
5119 (define_insn "*abssf2"
5120   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5121         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5122   "TARGET_HARD_FLOAT && TARGET_FPRS"
5123   "fabs %0,%1"
5124   [(set_attr "type" "fp")])
5125
5126 (define_insn ""
5127   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5128         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
5129   "TARGET_HARD_FLOAT && TARGET_FPRS"
5130   "fnabs %0,%1"
5131   [(set_attr "type" "fp")])
5132
5133 (define_expand "addsf3"
5134   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5135         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5136                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5137   "TARGET_HARD_FLOAT"
5138   "")
5139
5140 (define_insn ""
5141   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5142         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5143                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5144   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5145   "fadds %0,%1,%2"
5146   [(set_attr "type" "fp")])
5147
5148 (define_insn ""
5149   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5150         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5151                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5152   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5153   "{fa|fadd} %0,%1,%2"
5154   [(set_attr "type" "fp")])
5155
5156 (define_expand "subsf3"
5157   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5158         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5159                   (match_operand:SF 2 "gpc_reg_operand" "")))]
5160   "TARGET_HARD_FLOAT"
5161   "")
5162
5163 (define_insn ""
5164   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5165         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5166                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5167   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5168   "fsubs %0,%1,%2"
5169   [(set_attr "type" "fp")])
5170
5171 (define_insn ""
5172   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5173         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5174                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5175   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5176   "{fs|fsub} %0,%1,%2"
5177   [(set_attr "type" "fp")])
5178
5179 (define_expand "mulsf3"
5180   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5181         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
5182                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5183   "TARGET_HARD_FLOAT"
5184   "")
5185
5186 (define_insn ""
5187   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5188         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5189                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5190   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5191   "fmuls %0,%1,%2"
5192   [(set_attr "type" "fp")])
5193
5194 (define_insn ""
5195   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5196         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5197                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5198   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5199   "{fm|fmul} %0,%1,%2"
5200   [(set_attr "type" "dmul")])
5201
5202 (define_expand "divsf3"
5203   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5204         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
5205                 (match_operand:SF 2 "gpc_reg_operand" "")))]
5206   "TARGET_HARD_FLOAT"
5207   "")
5208
5209 (define_insn ""
5210   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5211         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5212                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5213   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5214   "fdivs %0,%1,%2"
5215   [(set_attr "type" "sdiv")])
5216
5217 (define_insn ""
5218   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5219         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5220                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5221   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5222   "{fd|fdiv} %0,%1,%2"
5223   [(set_attr "type" "ddiv")])
5224
5225 (define_expand "recipsf3"
5226   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5227         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")
5228                     (match_operand:SF 2 "gpc_reg_operand" "f")]
5229                    UNSPEC_FRES))]
5230   "TARGET_RECIP && TARGET_HARD_FLOAT && TARGET_PPC_GFXOPT && !optimize_size
5231    && flag_finite_math_only && !flag_trapping_math"
5232 {
5233    rs6000_emit_swdivsf (operands[0], operands[1], operands[2]);
5234    DONE;
5235 })
5236
5237 (define_insn "fres"
5238   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5239         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5240   "TARGET_PPC_GFXOPT && flag_finite_math_only"
5241   "fres %0,%1"
5242   [(set_attr "type" "fp")])
5243
5244 (define_insn ""
5245   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5246         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5247                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5248                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5249   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5250   "fmadds %0,%1,%2,%3"
5251   [(set_attr "type" "fp")])
5252
5253 (define_insn ""
5254   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5255         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5256                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5257                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5258   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5259   "{fma|fmadd} %0,%1,%2,%3"
5260   [(set_attr "type" "dmul")])
5261
5262 (define_insn ""
5263   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5264         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5265                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5266                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5267   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5268   "fmsubs %0,%1,%2,%3"
5269   [(set_attr "type" "fp")])
5270
5271 (define_insn ""
5272   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5273         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5274                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5275                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5276   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5277   "{fms|fmsub} %0,%1,%2,%3"
5278   [(set_attr "type" "dmul")])
5279
5280 (define_insn ""
5281   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5282         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5283                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5284                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5285   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5286    && HONOR_SIGNED_ZEROS (SFmode)"
5287   "fnmadds %0,%1,%2,%3"
5288   [(set_attr "type" "fp")])
5289
5290 (define_insn ""
5291   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5292         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5293                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5294                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5295   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5296    && ! HONOR_SIGNED_ZEROS (SFmode)"
5297   "fnmadds %0,%1,%2,%3"
5298   [(set_attr "type" "fp")])
5299
5300 (define_insn ""
5301   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5302         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5303                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5304                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5305   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5306   "{fnma|fnmadd} %0,%1,%2,%3"
5307   [(set_attr "type" "dmul")])
5308
5309 (define_insn ""
5310   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5311         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5312                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5313                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5314   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5315    && ! HONOR_SIGNED_ZEROS (SFmode)"
5316   "{fnma|fnmadd} %0,%1,%2,%3"
5317   [(set_attr "type" "dmul")])
5318
5319 (define_insn ""
5320   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5321         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5322                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5323                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5324   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5325    && HONOR_SIGNED_ZEROS (SFmode)"
5326   "fnmsubs %0,%1,%2,%3"
5327   [(set_attr "type" "fp")])
5328
5329 (define_insn ""
5330   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5331         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
5332                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5333                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
5334   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5335    && ! HONOR_SIGNED_ZEROS (SFmode)"
5336   "fnmsubs %0,%1,%2,%3"
5337   [(set_attr "type" "fp")])
5338
5339 (define_insn ""
5340   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5341         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5342                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5343                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5344   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5345   "{fnms|fnmsub} %0,%1,%2,%3"
5346   [(set_attr "type" "dmul")])
5347
5348 (define_insn ""
5349   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5350         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
5351                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5352                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
5353   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5354    && ! HONOR_SIGNED_ZEROS (SFmode)"
5355   "{fnms|fnmsub} %0,%1,%2,%3"
5356   [(set_attr "type" "dmul")])
5357
5358 (define_expand "sqrtsf2"
5359   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5360         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5361   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
5362   "")
5363
5364 (define_insn ""
5365   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5366         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5367   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5368   "fsqrts %0,%1"
5369   [(set_attr "type" "ssqrt")])
5370
5371 (define_insn ""
5372   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5373         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5374   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS"
5375   "fsqrt %0,%1"
5376   [(set_attr "type" "dsqrt")])
5377
5378 (define_expand "rsqrtsf2"
5379   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5380         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")]
5381                    UNSPEC_RSQRT))]
5382   "TARGET_RECIP && TARGET_HARD_FLOAT && TARGET_PPC_GFXOPT && !optimize_size
5383    && flag_finite_math_only && !flag_trapping_math"
5384 {
5385   rs6000_emit_swrsqrtsf (operands[0], operands[1]);
5386   DONE;
5387 })
5388
5389 (define_insn "*rsqrt_internal1"
5390   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5391         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")]
5392                    UNSPEC_RSQRT))]
5393   "TARGET_HARD_FLOAT && TARGET_PPC_GFXOPT"
5394   "frsqrte %0,%1"
5395   [(set_attr "type" "fp")])
5396
5397 (define_expand "copysignsf3"
5398   [(set (match_dup 3)
5399         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))
5400    (set (match_dup 4)
5401         (neg:SF (abs:SF (match_dup 1))))
5402    (set (match_operand:SF 0 "gpc_reg_operand" "")
5403         (if_then_else:SF (ge (match_operand:SF 2 "gpc_reg_operand" "")
5404                              (match_dup 5))
5405                          (match_dup 3)
5406                          (match_dup 4)))]
5407   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS
5408    && !HONOR_NANS (SFmode) && !HONOR_SIGNED_ZEROS (SFmode)"
5409   {
5410      operands[3] = gen_reg_rtx (SFmode);
5411      operands[4] = gen_reg_rtx (SFmode);
5412      operands[5] = CONST0_RTX (SFmode);
5413   })
5414
5415 (define_expand "copysigndf3"
5416   [(set (match_dup 3)
5417         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))
5418    (set (match_dup 4)
5419         (neg:DF (abs:DF (match_dup 1))))
5420    (set (match_operand:DF 0 "gpc_reg_operand" "")
5421         (if_then_else:DF (ge (match_operand:DF 2 "gpc_reg_operand" "")
5422                              (match_dup 5))
5423                          (match_dup 3)
5424                          (match_dup 4)))]
5425   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS
5426    && !HONOR_NANS (DFmode) && !HONOR_SIGNED_ZEROS (DFmode)"
5427   {
5428      operands[3] = gen_reg_rtx (DFmode);
5429      operands[4] = gen_reg_rtx (DFmode);
5430      operands[5] = CONST0_RTX (DFmode);
5431   })
5432
5433 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
5434 ;; fsel instruction and some auxiliary computations.  Then we just have a
5435 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
5436 ;; combine.
5437 (define_expand "smaxsf3"
5438   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5439         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
5440                              (match_operand:SF 2 "gpc_reg_operand" ""))
5441                          (match_dup 1)
5442                          (match_dup 2)))]
5443   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5444   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5445
5446 (define_expand "sminsf3"
5447   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5448         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
5449                              (match_operand:SF 2 "gpc_reg_operand" ""))
5450                          (match_dup 2)
5451                          (match_dup 1)))]
5452   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5453   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5454
5455 (define_split
5456   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5457         (match_operator:SF 3 "min_max_operator"
5458          [(match_operand:SF 1 "gpc_reg_operand" "")
5459           (match_operand:SF 2 "gpc_reg_operand" "")]))]
5460   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5461   [(const_int 0)]
5462   "
5463 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5464                       operands[1], operands[2]);
5465   DONE;
5466 }")
5467
5468 (define_expand "movsicc"
5469    [(set (match_operand:SI 0 "gpc_reg_operand" "")
5470          (if_then_else:SI (match_operand 1 "comparison_operator" "")
5471                           (match_operand:SI 2 "gpc_reg_operand" "")
5472                           (match_operand:SI 3 "gpc_reg_operand" "")))]
5473   "TARGET_ISEL"
5474   "
5475 {
5476   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5477     DONE;
5478   else
5479     FAIL;
5480 }")
5481
5482 ;; We use the BASE_REGS for the isel input operands because, if rA is
5483 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
5484 ;; because we may switch the operands and rB may end up being rA.
5485 ;;
5486 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
5487 ;; leave out the mode in operand 4 and use one pattern, but reload can
5488 ;; change the mode underneath our feet and then gets confused trying
5489 ;; to reload the value.
5490 (define_insn "isel_signed"
5491   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5492         (if_then_else:SI
5493          (match_operator 1 "comparison_operator"
5494                          [(match_operand:CC 4 "cc_reg_operand" "y")
5495                           (const_int 0)])
5496          (match_operand:SI 2 "gpc_reg_operand" "b")
5497          (match_operand:SI 3 "gpc_reg_operand" "b")))]
5498   "TARGET_ISEL"
5499   "*
5500 { return output_isel (operands); }"
5501   [(set_attr "length" "4")])
5502
5503 (define_insn "isel_unsigned"
5504   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5505         (if_then_else:SI
5506          (match_operator 1 "comparison_operator"
5507                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
5508                           (const_int 0)])
5509          (match_operand:SI 2 "gpc_reg_operand" "b")
5510          (match_operand:SI 3 "gpc_reg_operand" "b")))]
5511   "TARGET_ISEL"
5512   "*
5513 { return output_isel (operands); }"
5514   [(set_attr "length" "4")])
5515
5516 (define_expand "movsfcc"
5517    [(set (match_operand:SF 0 "gpc_reg_operand" "")
5518          (if_then_else:SF (match_operand 1 "comparison_operator" "")
5519                           (match_operand:SF 2 "gpc_reg_operand" "")
5520                           (match_operand:SF 3 "gpc_reg_operand" "")))]
5521   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5522   "
5523 {
5524   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5525     DONE;
5526   else
5527     FAIL;
5528 }")
5529
5530 (define_insn "*fselsfsf4"
5531   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5532         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5533                              (match_operand:SF 4 "zero_fp_constant" "F"))
5534                          (match_operand:SF 2 "gpc_reg_operand" "f")
5535                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5536   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5537   "fsel %0,%1,%2,%3"
5538   [(set_attr "type" "fp")])
5539
5540 (define_insn "*fseldfsf4"
5541   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5542         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
5543                              (match_operand:DF 4 "zero_fp_constant" "F"))
5544                          (match_operand:SF 2 "gpc_reg_operand" "f")
5545                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5546   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5547   "fsel %0,%1,%2,%3"
5548   [(set_attr "type" "fp")])
5549
5550 (define_expand "negdf2"
5551   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5552         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
5553   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5554   "")
5555
5556 (define_insn "*negdf2_fpr"
5557   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5558         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5559   "TARGET_HARD_FLOAT && TARGET_FPRS"
5560   "fneg %0,%1"
5561   [(set_attr "type" "fp")])
5562
5563 (define_expand "absdf2"
5564   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5565         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
5566   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5567   "")
5568
5569 (define_insn "*absdf2_fpr"
5570   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5571         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5572   "TARGET_HARD_FLOAT && TARGET_FPRS"
5573   "fabs %0,%1"
5574   [(set_attr "type" "fp")])
5575
5576 (define_insn "*nabsdf2_fpr"
5577   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5578         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
5579   "TARGET_HARD_FLOAT && TARGET_FPRS"
5580   "fnabs %0,%1"
5581   [(set_attr "type" "fp")])
5582
5583 (define_expand "adddf3"
5584   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5585         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "")
5586                  (match_operand:DF 2 "gpc_reg_operand" "")))]
5587   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5588   "")
5589
5590 (define_insn "*adddf3_fpr"
5591   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5592         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5593                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
5594   "TARGET_HARD_FLOAT && TARGET_FPRS"
5595   "{fa|fadd} %0,%1,%2"
5596   [(set_attr "type" "fp")])
5597
5598 (define_expand "subdf3"
5599   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5600         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
5601                   (match_operand:DF 2 "gpc_reg_operand" "")))]
5602   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5603   "")
5604
5605 (define_insn "*subdf3_fpr"
5606   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5607         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5608                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
5609   "TARGET_HARD_FLOAT && TARGET_FPRS"
5610   "{fs|fsub} %0,%1,%2"
5611   [(set_attr "type" "fp")])
5612
5613 (define_expand "muldf3"
5614   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5615         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "")
5616                  (match_operand:DF 2 "gpc_reg_operand" "")))]
5617   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5618   "")
5619
5620 (define_insn "*muldf3_fpr"
5621   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5622         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5623                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
5624   "TARGET_HARD_FLOAT && TARGET_FPRS"
5625   "{fm|fmul} %0,%1,%2"
5626   [(set_attr "type" "dmul")])
5627
5628 (define_expand "divdf3"
5629   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5630         (div:DF (match_operand:DF 1 "gpc_reg_operand" "")
5631                 (match_operand:DF 2 "gpc_reg_operand" "")))]
5632   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5633   "")
5634
5635 (define_insn "*divdf3_fpr"
5636   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5637         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5638                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
5639   "TARGET_HARD_FLOAT && TARGET_FPRS"
5640   "{fd|fdiv} %0,%1,%2"
5641   [(set_attr "type" "ddiv")])
5642
5643 (define_expand "recipdf3"
5644   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5645         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")
5646                     (match_operand:DF 2 "gpc_reg_operand" "f")]
5647                    UNSPEC_FRES))]
5648   "TARGET_RECIP && TARGET_HARD_FLOAT && TARGET_POPCNTB && !optimize_size
5649    && flag_finite_math_only && !flag_trapping_math"
5650 {
5651    rs6000_emit_swdivdf (operands[0], operands[1], operands[2]);
5652    DONE;
5653 })
5654
5655 (define_insn "fred"
5656   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5657         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5658   "TARGET_POPCNTB && flag_finite_math_only"
5659   "fre %0,%1"
5660   [(set_attr "type" "fp")])
5661
5662 (define_insn ""
5663   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5664         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5665                           (match_operand:DF 2 "gpc_reg_operand" "f"))
5666                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
5667   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5668   "{fma|fmadd} %0,%1,%2,%3"
5669   [(set_attr "type" "dmul")])
5670
5671 (define_insn ""
5672   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5673         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5674                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5675                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5676   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5677   "{fms|fmsub} %0,%1,%2,%3"
5678   [(set_attr "type" "dmul")])
5679
5680 (define_insn ""
5681   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5682         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5683                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
5684                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5685   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5686    && HONOR_SIGNED_ZEROS (DFmode)"
5687   "{fnma|fnmadd} %0,%1,%2,%3"
5688   [(set_attr "type" "dmul")])
5689
5690 (define_insn ""
5691   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5692         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f"))
5693                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5694                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5695   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5696    && ! HONOR_SIGNED_ZEROS (DFmode)"
5697   "{fnma|fnmadd} %0,%1,%2,%3"
5698   [(set_attr "type" "dmul")])
5699
5700 (define_insn ""
5701   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5702         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5703                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
5704                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5705   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5706    && HONOR_SIGNED_ZEROS (DFmode)"
5707   "{fnms|fnmsub} %0,%1,%2,%3"
5708   [(set_attr "type" "dmul")])
5709
5710 (define_insn ""
5711   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5712         (minus:DF (match_operand:DF 3 "gpc_reg_operand" "f")
5713                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5714                            (match_operand:DF 2 "gpc_reg_operand" "f"))))]
5715   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5716    && ! HONOR_SIGNED_ZEROS (DFmode)"
5717   "{fnms|fnmsub} %0,%1,%2,%3"
5718   [(set_attr "type" "dmul")])
5719
5720 (define_insn "sqrtdf2"
5721   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5722         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5723   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
5724   "fsqrt %0,%1"
5725   [(set_attr "type" "dsqrt")])
5726
5727 ;; The conditional move instructions allow us to perform max and min
5728 ;; operations even when
5729
5730 (define_expand "smaxdf3"
5731   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5732         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5733                              (match_operand:DF 2 "gpc_reg_operand" ""))
5734                          (match_dup 1)
5735                          (match_dup 2)))]
5736   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5737   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5738
5739 (define_expand "smindf3"
5740   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5741         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5742                              (match_operand:DF 2 "gpc_reg_operand" ""))
5743                          (match_dup 2)
5744                          (match_dup 1)))]
5745   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5746   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5747
5748 (define_split
5749   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5750         (match_operator:DF 3 "min_max_operator"
5751          [(match_operand:DF 1 "gpc_reg_operand" "")
5752           (match_operand:DF 2 "gpc_reg_operand" "")]))]
5753   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5754   [(const_int 0)]
5755   "
5756 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5757                       operands[1], operands[2]);
5758   DONE;
5759 }")
5760
5761 (define_expand "movdfcc"
5762    [(set (match_operand:DF 0 "gpc_reg_operand" "")
5763          (if_then_else:DF (match_operand 1 "comparison_operator" "")
5764                           (match_operand:DF 2 "gpc_reg_operand" "")
5765                           (match_operand:DF 3 "gpc_reg_operand" "")))]
5766   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5767   "
5768 {
5769   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5770     DONE;
5771   else
5772     FAIL;
5773 }")
5774
5775 (define_insn "*fseldfdf4"
5776   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5777         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
5778                              (match_operand:DF 4 "zero_fp_constant" "F"))
5779                          (match_operand:DF 2 "gpc_reg_operand" "f")
5780                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5781   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5782   "fsel %0,%1,%2,%3"
5783   [(set_attr "type" "fp")])
5784
5785 (define_insn "*fselsfdf4"
5786   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5787         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5788                              (match_operand:SF 4 "zero_fp_constant" "F"))
5789                          (match_operand:DF 2 "gpc_reg_operand" "f")
5790                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5791   "TARGET_PPC_GFXOPT"
5792   "fsel %0,%1,%2,%3"
5793   [(set_attr "type" "fp")])
5794 \f
5795 ;; Conversions to and from floating-point.
5796
5797 (define_expand "fixuns_truncsfsi2"
5798   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5799         (unsigned_fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5800   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5801   "")
5802
5803 (define_expand "fix_truncsfsi2"
5804   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5805         (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5806   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5807   "")
5808
5809 ; For each of these conversions, there is a define_expand, a define_insn
5810 ; with a '#' template, and a define_split (with C code).  The idea is
5811 ; to allow constant folding with the template of the define_insn,
5812 ; then to have the insns split later (between sched1 and final).
5813
5814 (define_expand "floatsidf2"
5815   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5816                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5817               (use (match_dup 2))
5818               (use (match_dup 3))
5819               (clobber (match_dup 4))
5820               (clobber (match_dup 5))
5821               (clobber (match_dup 6))])]
5822   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5823   "
5824 {
5825   if (TARGET_E500_DOUBLE)
5826     {
5827       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
5828       DONE;
5829     }
5830   if (TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS)
5831     {
5832       rtx t1 = gen_reg_rtx (DImode);
5833       emit_insn (gen_floatsidf_ppc64_mfpgpr (operands[0], operands[1], t1));
5834       DONE;
5835     }
5836   if (TARGET_POWERPC64)
5837     {
5838       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5839       rtx t1 = gen_reg_rtx (DImode);
5840       rtx t2 = gen_reg_rtx (DImode);
5841       emit_insn (gen_floatsidf_ppc64 (operands[0], operands[1], mem, t1, t2));
5842       DONE;
5843     }
5844
5845   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5846   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5847   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5848   operands[5] = gen_reg_rtx (DFmode);
5849   operands[6] = gen_reg_rtx (SImode);
5850 }")
5851
5852 (define_insn_and_split "*floatsidf2_internal"
5853   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5854         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5855    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5856    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5857    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
5858    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))
5859    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5860   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5861   "#"
5862   "&& (can_create_pseudo_p () || offsettable_nonstrict_memref_p (operands[4]))"
5863   [(pc)]
5864   "
5865 {
5866   rtx lowword, highword;
5867   gcc_assert (MEM_P (operands[4]));
5868   highword = adjust_address (operands[4], SImode, 0);
5869   lowword = adjust_address (operands[4], SImode, 4);
5870   if (! WORDS_BIG_ENDIAN)
5871     {
5872       rtx tmp;
5873       tmp = highword; highword = lowword; lowword = tmp;
5874     }
5875
5876   emit_insn (gen_xorsi3 (operands[6], operands[1],
5877                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5878   emit_move_insn (lowword, operands[6]);
5879   emit_move_insn (highword, operands[2]);
5880   emit_move_insn (operands[5], operands[4]);
5881   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5882   DONE;
5883 }"
5884   [(set_attr "length" "24")])
5885
5886 (define_expand "floatunssisf2"
5887   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5888         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5889   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5890   "")
5891
5892 (define_expand "floatunssidf2"
5893   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5894                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5895               (use (match_dup 2))
5896               (use (match_dup 3))
5897               (clobber (match_dup 4))
5898               (clobber (match_dup 5))])]
5899   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5900   "
5901 {
5902   if (TARGET_E500_DOUBLE)
5903     {
5904       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
5905       DONE;
5906     }
5907   if (TARGET_POWERPC64)
5908     {
5909       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5910       rtx t1 = gen_reg_rtx (DImode);
5911       rtx t2 = gen_reg_rtx (DImode);
5912       emit_insn (gen_floatunssidf_ppc64 (operands[0], operands[1], mem,
5913                                          t1, t2));
5914       DONE;
5915     }
5916
5917   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5918   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5919   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5920   operands[5] = gen_reg_rtx (DFmode);
5921 }")
5922
5923 (define_insn_and_split "*floatunssidf2_internal"
5924   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5925         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5926    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5927    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5928    (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
5929    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))]
5930   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5931   "#"
5932   "&& (can_create_pseudo_p () || offsettable_nonstrict_memref_p (operands[4]))"
5933   [(pc)]
5934   "
5935 {
5936   rtx lowword, highword;
5937   gcc_assert (MEM_P (operands[4]));
5938   highword = adjust_address (operands[4], SImode, 0);
5939   lowword = adjust_address (operands[4], SImode, 4);
5940   if (! WORDS_BIG_ENDIAN)
5941     {
5942       rtx tmp;
5943       tmp = highword; highword = lowword; lowword = tmp;
5944     }
5945
5946   emit_move_insn (lowword, operands[1]);
5947   emit_move_insn (highword, operands[2]);
5948   emit_move_insn (operands[5], operands[4]);
5949   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5950   DONE;
5951 }"
5952   [(set_attr "length" "20")])
5953
5954 (define_expand "fix_truncdfsi2"
5955   [(parallel [(set (match_operand:SI 0 "fix_trunc_dest_operand" "")
5956                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5957               (clobber (match_dup 2))
5958               (clobber (match_dup 3))])]
5959   "(TARGET_POWER2 || TARGET_POWERPC)
5960    && TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5961   "
5962 {
5963   if (TARGET_E500_DOUBLE)
5964     {
5965      emit_insn (gen_spe_fix_truncdfsi2 (operands[0], operands[1]));
5966      DONE;
5967     }
5968   operands[2] = gen_reg_rtx (DImode);
5969   if (TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
5970       && gpc_reg_operand(operands[0], GET_MODE (operands[0])))
5971     {
5972       operands[3] = gen_reg_rtx (DImode);
5973       emit_insn (gen_fix_truncdfsi2_mfpgpr (operands[0], operands[1],
5974                                             operands[2], operands[3]));
5975       DONE;
5976     }
5977   if (TARGET_PPC_GFXOPT)
5978     {
5979       rtx orig_dest = operands[0];
5980       if (! memory_operand (orig_dest, GET_MODE (orig_dest)))
5981         operands[0] = assign_stack_temp (SImode, GET_MODE_SIZE (SImode), 0);
5982       emit_insn (gen_fix_truncdfsi2_internal_gfxopt (operands[0], operands[1],
5983                                                      operands[2]));
5984       if (operands[0] != orig_dest)
5985         emit_move_insn (orig_dest, operands[0]);
5986       DONE;
5987     }
5988   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5989 }")
5990
5991 (define_insn_and_split "*fix_truncdfsi2_internal"
5992   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5993         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5994    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
5995    (clobber (match_operand:DI 3 "offsettable_mem_operand" "=o"))]
5996   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5997   "#"
5998   "&& (can_create_pseudo_p () || offsettable_nonstrict_memref_p (operands[3]))"
5999   [(pc)]
6000   "
6001 {
6002   rtx lowword;
6003   gcc_assert (MEM_P (operands[3]));
6004   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
6005
6006   emit_insn (gen_fctiwz (operands[2], operands[1]));
6007   emit_move_insn (operands[3], operands[2]);
6008   emit_move_insn (operands[0], lowword);
6009   DONE;
6010 }"
6011   [(set_attr "length" "16")])
6012
6013 (define_insn_and_split "fix_truncdfsi2_internal_gfxopt"
6014   [(set (match_operand:SI 0 "memory_operand" "=Z")
6015         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
6016    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))]
6017   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS
6018    && TARGET_PPC_GFXOPT"
6019   "#"
6020   "&& 1"
6021   [(pc)]
6022   "
6023 {
6024   emit_insn (gen_fctiwz (operands[2], operands[1]));
6025   emit_insn (gen_stfiwx (operands[0], operands[2]));
6026   DONE;
6027 }"
6028   [(set_attr "length" "16")])
6029
6030 (define_insn_and_split "fix_truncdfsi2_mfpgpr"
6031   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6032         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
6033    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
6034    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))]
6035   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS"
6036   "#"
6037   "&& 1"
6038   [(set (match_dup 2) (unspec:DI [(fix:SI (match_dup 1))] UNSPEC_FCTIWZ))
6039    (set (match_dup 3) (match_dup 2))
6040    (set (match_dup 0) (subreg:SI (match_dup 3) 4))]
6041   ""
6042   [(set_attr "length" "12")])
6043
6044 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
6045 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
6046 ; because the first makes it clear that operand 0 is not live
6047 ; before the instruction.
6048 (define_insn "fctiwz"
6049   [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
6050         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))]
6051                    UNSPEC_FCTIWZ))]
6052   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
6053   "{fcirz|fctiwz} %0,%1"
6054   [(set_attr "type" "fp")])
6055
6056 (define_insn "btruncdf2"
6057   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6058         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIZ))]
6059   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6060   "friz %0,%1"
6061   [(set_attr "type" "fp")])
6062
6063 (define_insn "btruncsf2"
6064   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6065         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIZ))]
6066   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6067   "friz %0,%1"
6068   [(set_attr "type" "fp")])
6069
6070 (define_insn "ceildf2"
6071   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6072         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIP))]
6073   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6074   "frip %0,%1"
6075   [(set_attr "type" "fp")])
6076
6077 (define_insn "ceilsf2"
6078  [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6079         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIP))]
6080   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6081   "frip %0,%1"
6082   [(set_attr "type" "fp")])
6083
6084 (define_insn "floordf2"
6085   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6086         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIM))]
6087   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6088   "frim %0,%1"
6089   [(set_attr "type" "fp")])
6090
6091 (define_insn "floorsf2"
6092   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6093         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIM))]
6094   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6095   "frim %0,%1"
6096   [(set_attr "type" "fp")])
6097
6098 (define_insn "rounddf2"
6099   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6100         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIN))]
6101   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6102   "frin %0,%1"
6103   [(set_attr "type" "fp")])
6104
6105 (define_insn "roundsf2"
6106   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6107         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIN))]
6108   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
6109   "frin %0,%1"
6110   [(set_attr "type" "fp")])
6111
6112 ; An UNSPEC is used so we don't have to support SImode in FP registers.
6113 (define_insn "stfiwx"
6114   [(set (match_operand:SI 0 "memory_operand" "=Z")
6115         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "f")]
6116                    UNSPEC_STFIWX))]
6117   "TARGET_PPC_GFXOPT"
6118   "stfiwx %1,%y0"
6119   [(set_attr "type" "fpstore")])
6120
6121 (define_expand "floatsisf2"
6122   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6123         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
6124   "TARGET_HARD_FLOAT && !TARGET_FPRS"
6125   "")
6126
6127 (define_insn "floatdidf2"
6128   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6129         (float:DF (match_operand:DI 1 "gpc_reg_operand" "*f")))]
6130   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
6131   "fcfid %0,%1"
6132   [(set_attr "type" "fp")])
6133
6134 (define_insn_and_split "floatsidf_ppc64_mfpgpr"
6135   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6136         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6137    (clobber (match_operand:DI 2 "gpc_reg_operand" "=r"))]
6138   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS"
6139   "#"
6140   "&& 1"
6141   [(set (match_dup 2) (sign_extend:DI (match_dup 1)))
6142    (set (match_dup 0) (float:DF (match_dup 2)))]
6143   "")
6144
6145 (define_insn_and_split "floatsidf_ppc64"
6146   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6147         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6148    (clobber (match_operand:DI 2 "offsettable_mem_operand" "=o"))
6149    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
6150    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
6151   "TARGET_POWERPC64 && !TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS"
6152   "#"
6153   "&& 1"
6154   [(set (match_dup 3) (sign_extend:DI (match_dup 1)))
6155    (set (match_dup 2) (match_dup 3))
6156    (set (match_dup 4) (match_dup 2))
6157    (set (match_dup 0) (float:DF (match_dup 4)))]
6158   "")
6159
6160 (define_insn_and_split "floatunssidf_ppc64"
6161   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6162         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6163    (clobber (match_operand:DI 2 "offsettable_mem_operand" "=o"))
6164    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
6165    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
6166   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
6167   "#"
6168   "&& 1"
6169   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
6170    (set (match_dup 2) (match_dup 3))
6171    (set (match_dup 4) (match_dup 2))
6172    (set (match_dup 0) (float:DF (match_dup 4)))]
6173   "")
6174
6175 (define_insn "fix_truncdfdi2"
6176   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
6177         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
6178   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
6179   "fctidz %0,%1"
6180   [(set_attr "type" "fp")])
6181
6182 (define_expand "floatdisf2"
6183   [(set (match_operand:SF 0 "gpc_reg_operand" "")
6184         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
6185   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
6186   "
6187 {
6188   rtx val = operands[1];
6189   if (!flag_unsafe_math_optimizations)
6190     {
6191       rtx label = gen_label_rtx ();
6192       val = gen_reg_rtx (DImode);
6193       emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
6194       emit_label (label);
6195     }
6196   emit_insn (gen_floatdisf2_internal1 (operands[0], val));
6197   DONE;
6198 }")
6199
6200 ;; This is not IEEE compliant if rounding mode is "round to nearest".
6201 ;; If the DI->DF conversion is inexact, then it's possible to suffer
6202 ;; from double rounding.
6203 (define_insn_and_split "floatdisf2_internal1"
6204   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
6205         (float:SF (match_operand:DI 1 "gpc_reg_operand" "*f")))
6206    (clobber (match_scratch:DF 2 "=f"))]
6207   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
6208   "#"
6209   "&& reload_completed"
6210   [(set (match_dup 2)
6211         (float:DF (match_dup 1)))
6212    (set (match_dup 0)
6213         (float_truncate:SF (match_dup 2)))]
6214   "")
6215
6216 ;; Twiddles bits to avoid double rounding.
6217 ;; Bits that might be truncated when converting to DFmode are replaced
6218 ;; by a bit that won't be lost at that stage, but is below the SFmode
6219 ;; rounding position.
6220 (define_expand "floatdisf2_internal2"
6221   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
6222                                    (const_int 53)))
6223    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
6224                                                       (const_int 2047)))
6225               (clobber (scratch:CC))])
6226    (set (match_dup 3) (plus:DI (match_dup 3)
6227                                (const_int 1)))
6228    (set (match_dup 0) (plus:DI (match_dup 0)
6229                                (const_int 2047)))
6230    (set (match_dup 4) (compare:CCUNS (match_dup 3)
6231                                      (const_int 2)))
6232    (set (match_dup 0) (ior:DI (match_dup 0)
6233                               (match_dup 1)))
6234    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
6235                                          (const_int -2048)))
6236               (clobber (scratch:CC))])
6237    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
6238                            (label_ref (match_operand:DI 2 "" ""))
6239                            (pc)))
6240    (set (match_dup 0) (match_dup 1))]
6241   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
6242   "
6243 {
6244   operands[3] = gen_reg_rtx (DImode);
6245   operands[4] = gen_reg_rtx (CCUNSmode);
6246 }")
6247 \f
6248 ;; Define the DImode operations that can be done in a small number
6249 ;; of instructions.  The & constraints are to prevent the register
6250 ;; allocator from allocating registers that overlap with the inputs
6251 ;; (for example, having an input in 7,8 and an output in 6,7).  We
6252 ;; also allow for the output being the same as one of the inputs.
6253
6254 (define_insn "*adddi3_noppc64"
6255   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
6256         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
6257                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
6258   "! TARGET_POWERPC64"
6259   "*
6260 {
6261   if (WORDS_BIG_ENDIAN)
6262     return (GET_CODE (operands[2])) != CONST_INT
6263             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
6264             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
6265   else
6266     return (GET_CODE (operands[2])) != CONST_INT
6267             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
6268             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
6269 }"
6270   [(set_attr "type" "two")
6271    (set_attr "length" "8")])
6272
6273 (define_insn "*subdi3_noppc64"
6274   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
6275         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
6276                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
6277   "! TARGET_POWERPC64"
6278   "*
6279 {
6280   if (WORDS_BIG_ENDIAN)
6281     return (GET_CODE (operands[1]) != CONST_INT)
6282             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
6283             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
6284   else
6285     return (GET_CODE (operands[1]) != CONST_INT)
6286             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
6287             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
6288 }"
6289   [(set_attr "type" "two")
6290    (set_attr "length" "8")])
6291
6292 (define_insn "*negdi2_noppc64"
6293   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6294         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
6295   "! TARGET_POWERPC64"
6296   "*
6297 {
6298   return (WORDS_BIG_ENDIAN)
6299     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
6300     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
6301 }"
6302   [(set_attr "type" "two")
6303    (set_attr "length" "8")])
6304
6305 (define_expand "mulsidi3"
6306   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6307         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6308                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6309   "! TARGET_POWERPC64"
6310   "
6311 {
6312   if (! TARGET_POWER && ! TARGET_POWERPC)
6313     {
6314       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
6315       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
6316       emit_insn (gen_mull_call ());
6317       if (WORDS_BIG_ENDIAN)
6318         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
6319       else
6320         {
6321           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
6322                           gen_rtx_REG (SImode, 3));
6323           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
6324                           gen_rtx_REG (SImode, 4));
6325         }
6326       DONE;
6327     }
6328   else if (TARGET_POWER)
6329     {
6330       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
6331       DONE;
6332     }
6333 }")
6334
6335 (define_insn "mulsidi3_mq"
6336   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6337         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6338                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
6339    (clobber (match_scratch:SI 3 "=q"))]
6340   "TARGET_POWER"
6341   "mul %0,%1,%2\;mfmq %L0"
6342   [(set_attr "type" "imul")
6343    (set_attr "length" "8")])
6344
6345 (define_insn "*mulsidi3_no_mq"
6346   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6347         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6348                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6349   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
6350   "*
6351 {
6352   return (WORDS_BIG_ENDIAN)
6353     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
6354     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
6355 }"
6356   [(set_attr "type" "imul")
6357    (set_attr "length" "8")])
6358
6359 (define_split
6360   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6361         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6362                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6363   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
6364   [(set (match_dup 3)
6365         (truncate:SI
6366          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
6367                                (sign_extend:DI (match_dup 2)))
6368                       (const_int 32))))
6369    (set (match_dup 4)
6370         (mult:SI (match_dup 1)
6371                  (match_dup 2)))]
6372   "
6373 {
6374   int endian = (WORDS_BIG_ENDIAN == 0);
6375   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6376   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6377 }")
6378
6379 (define_expand "umulsidi3"
6380   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6381         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6382                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6383   "TARGET_POWERPC && ! TARGET_POWERPC64"
6384   "
6385 {
6386   if (TARGET_POWER)
6387     {
6388       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
6389       DONE;
6390     }
6391 }")
6392
6393 (define_insn "umulsidi3_mq"
6394   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6395         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6396                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
6397    (clobber (match_scratch:SI 3 "=q"))]
6398   "TARGET_POWERPC && TARGET_POWER"
6399   "*
6400 {
6401   return (WORDS_BIG_ENDIAN)
6402     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6403     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6404 }"
6405   [(set_attr "type" "imul")
6406    (set_attr "length" "8")])
6407
6408 (define_insn "*umulsidi3_no_mq"
6409   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6410         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6411                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6412   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
6413   "*
6414 {
6415   return (WORDS_BIG_ENDIAN)
6416     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6417     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6418 }"
6419   [(set_attr "type" "imul")
6420    (set_attr "length" "8")])
6421
6422 (define_split
6423   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6424         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6425                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6426   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
6427   [(set (match_dup 3)
6428         (truncate:SI
6429          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
6430                                (zero_extend:DI (match_dup 2)))
6431                       (const_int 32))))
6432    (set (match_dup 4)
6433         (mult:SI (match_dup 1)
6434                  (match_dup 2)))]
6435   "
6436 {
6437   int endian = (WORDS_BIG_ENDIAN == 0);
6438   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6439   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6440 }")
6441
6442 (define_expand "smulsi3_highpart"
6443   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6444         (truncate:SI
6445          (lshiftrt:DI (mult:DI (sign_extend:DI
6446                                 (match_operand:SI 1 "gpc_reg_operand" ""))
6447                                (sign_extend:DI
6448                                 (match_operand:SI 2 "gpc_reg_operand" "")))
6449                       (const_int 32))))]
6450   ""
6451   "
6452 {
6453   if (! TARGET_POWER && ! TARGET_POWERPC)
6454     {
6455       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
6456       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
6457       emit_insn (gen_mulh_call ());
6458       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
6459       DONE;
6460     }
6461   else if (TARGET_POWER)
6462     {
6463       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
6464       DONE;
6465     }
6466 }")
6467
6468 (define_insn "smulsi3_highpart_mq"
6469   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6470         (truncate:SI
6471          (lshiftrt:DI (mult:DI (sign_extend:DI
6472                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6473                                (sign_extend:DI
6474                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6475                       (const_int 32))))
6476    (clobber (match_scratch:SI 3 "=q"))]
6477   "TARGET_POWER"
6478   "mul %0,%1,%2"
6479   [(set_attr "type" "imul")])
6480
6481 (define_insn "*smulsi3_highpart_no_mq"
6482   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6483         (truncate:SI
6484          (lshiftrt:DI (mult:DI (sign_extend:DI
6485                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6486                                (sign_extend:DI
6487                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6488                       (const_int 32))))]
6489   "TARGET_POWERPC && ! TARGET_POWER"
6490   "mulhw %0,%1,%2"
6491   [(set_attr "type" "imul")])
6492
6493 (define_expand "umulsi3_highpart"
6494   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6495         (truncate:SI
6496          (lshiftrt:DI (mult:DI (zero_extend:DI
6497                                 (match_operand:SI 1 "gpc_reg_operand" ""))
6498                                (zero_extend:DI
6499                                 (match_operand:SI 2 "gpc_reg_operand" "")))
6500                       (const_int 32))))]
6501   "TARGET_POWERPC"
6502   "
6503 {
6504   if (TARGET_POWER)
6505     {
6506       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
6507       DONE;
6508     }
6509 }")
6510
6511 (define_insn "umulsi3_highpart_mq"
6512   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6513         (truncate:SI
6514          (lshiftrt:DI (mult:DI (zero_extend:DI
6515                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6516                                (zero_extend:DI
6517                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6518                       (const_int 32))))
6519    (clobber (match_scratch:SI 3 "=q"))]
6520   "TARGET_POWERPC && TARGET_POWER"
6521   "mulhwu %0,%1,%2"
6522   [(set_attr "type" "imul")])
6523
6524 (define_insn "*umulsi3_highpart_no_mq"
6525   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6526         (truncate:SI
6527          (lshiftrt:DI (mult:DI (zero_extend:DI
6528                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6529                                (zero_extend:DI
6530                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6531                       (const_int 32))))]
6532   "TARGET_POWERPC && ! TARGET_POWER"
6533   "mulhwu %0,%1,%2"
6534   [(set_attr "type" "imul")])
6535
6536 ;; If operands 0 and 2 are in the same register, we have a problem.  But
6537 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
6538 ;; why we have the strange constraints below.
6539 (define_insn "ashldi3_power"
6540   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
6541         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
6542                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
6543    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
6544   "TARGET_POWER"
6545   "@
6546    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
6547    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
6548    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
6549    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
6550   [(set_attr "length" "8")])
6551
6552 (define_insn "lshrdi3_power"
6553   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
6554         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
6555                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
6556    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
6557   "TARGET_POWER"
6558   "@
6559    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
6560    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
6561    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
6562    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
6563   [(set_attr "length" "8")])
6564
6565 ;; Shift by a variable amount is too complex to be worth open-coding.  We
6566 ;; just handle shifts by constants.
6567 (define_insn "ashrdi3_power"
6568   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6569         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6570                      (match_operand:SI 2 "const_int_operand" "M,i")))
6571    (clobber (match_scratch:SI 3 "=X,q"))]
6572   "TARGET_POWER"
6573   "@
6574    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
6575    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
6576   [(set_attr "type" "shift")
6577    (set_attr "length" "8")])
6578
6579 (define_insn "ashrdi3_no_power"
6580   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
6581         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6582                      (match_operand:SI 2 "const_int_operand" "M,i")))]
6583   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER && WORDS_BIG_ENDIAN"
6584   "@
6585    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
6586    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
6587   [(set_attr "type" "two,three")
6588    (set_attr "length" "8,12")])
6589
6590 (define_insn "*ashrdisi3_noppc64"
6591   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6592         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6593                                 (const_int 32)) 4))]
6594   "TARGET_32BIT && !TARGET_POWERPC64"
6595   "*
6596 {
6597   if (REGNO (operands[0]) == REGNO (operands[1]))
6598     return \"\";
6599   else
6600     return \"mr %0,%1\";
6601 }"
6602    [(set_attr "length" "4")])
6603
6604 \f
6605 ;; PowerPC64 DImode operations.
6606
6607 (define_insn_and_split "absdi2"
6608   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6609         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
6610    (clobber (match_scratch:DI 2 "=&r,&r"))]
6611   "TARGET_POWERPC64"
6612   "#"
6613   "&& reload_completed"
6614   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
6615    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
6616    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
6617   "")
6618
6619 (define_insn_and_split "*nabsdi2"
6620   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6621         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
6622    (clobber (match_scratch:DI 2 "=&r,&r"))]
6623   "TARGET_POWERPC64"
6624   "#"
6625   "&& reload_completed"
6626   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
6627    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
6628    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
6629   "")
6630
6631 (define_insn "muldi3"
6632   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6633         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6634                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
6635   "TARGET_POWERPC64"
6636   "@
6637    mulld %0,%1,%2
6638    mulli %0,%1,%2"
6639    [(set (attr "type")
6640       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
6641                 (const_string "imul3")
6642              (match_operand:SI 2 "short_cint_operand" "")
6643                 (const_string "imul2")]
6644         (const_string "lmul")))])
6645
6646 (define_insn "*muldi3_internal1"
6647   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6648         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6649                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6650                     (const_int 0)))
6651    (clobber (match_scratch:DI 3 "=r,r"))]
6652   "TARGET_POWERPC64"
6653   "@
6654    mulld. %3,%1,%2
6655    #"
6656   [(set_attr "type" "lmul_compare")
6657    (set_attr "length" "4,8")])
6658
6659 (define_split
6660   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6661         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6662                              (match_operand:DI 2 "gpc_reg_operand" ""))
6663                     (const_int 0)))
6664    (clobber (match_scratch:DI 3 ""))]
6665   "TARGET_POWERPC64 && reload_completed"
6666   [(set (match_dup 3)
6667         (mult:DI (match_dup 1) (match_dup 2)))
6668    (set (match_dup 0)
6669         (compare:CC (match_dup 3)
6670                     (const_int 0)))]
6671   "")
6672
6673 (define_insn "*muldi3_internal2"
6674   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6675         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6676                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6677                     (const_int 0)))
6678    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6679         (mult:DI (match_dup 1) (match_dup 2)))]
6680   "TARGET_POWERPC64"
6681   "@
6682    mulld. %0,%1,%2
6683    #"
6684   [(set_attr "type" "lmul_compare")
6685    (set_attr "length" "4,8")])
6686
6687 (define_split
6688   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6689         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6690                              (match_operand:DI 2 "gpc_reg_operand" ""))
6691                     (const_int 0)))
6692    (set (match_operand:DI 0 "gpc_reg_operand" "")
6693         (mult:DI (match_dup 1) (match_dup 2)))]
6694   "TARGET_POWERPC64 && reload_completed"
6695   [(set (match_dup 0)
6696         (mult:DI (match_dup 1) (match_dup 2)))
6697    (set (match_dup 3)
6698         (compare:CC (match_dup 0)
6699                     (const_int 0)))]
6700   "")
6701
6702 (define_insn "smuldi3_highpart"
6703   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6704         (truncate:DI
6705          (lshiftrt:TI (mult:TI (sign_extend:TI
6706                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6707                                (sign_extend:TI
6708                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6709                       (const_int 64))))]
6710   "TARGET_POWERPC64"
6711   "mulhd %0,%1,%2"
6712   [(set_attr "type" "lmul")])
6713
6714 (define_insn "umuldi3_highpart"
6715   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6716         (truncate:DI
6717          (lshiftrt:TI (mult:TI (zero_extend:TI
6718                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6719                                (zero_extend:TI
6720                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6721                       (const_int 64))))]
6722   "TARGET_POWERPC64"
6723   "mulhdu %0,%1,%2"
6724   [(set_attr "type" "lmul")])
6725
6726 (define_insn "rotldi3"
6727   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6728         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6729                    (match_operand:DI 2 "reg_or_cint_operand" "r,i")))]
6730   "TARGET_POWERPC64"
6731   "@
6732    rldcl %0,%1,%2,0
6733    rldicl %0,%1,%H2,0"
6734   [(set_attr "type" "var_shift_rotate,integer")])
6735
6736 (define_insn "*rotldi3_internal2"
6737   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6738         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6739                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6740                     (const_int 0)))
6741    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6742   "TARGET_64BIT"
6743   "@
6744    rldcl. %3,%1,%2,0
6745    rldicl. %3,%1,%H2,0
6746    #
6747    #"
6748   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6749    (set_attr "length" "4,4,8,8")])
6750
6751 (define_split
6752   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6753         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6754                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6755                     (const_int 0)))
6756    (clobber (match_scratch:DI 3 ""))]
6757   "TARGET_POWERPC64 && reload_completed"
6758   [(set (match_dup 3)
6759         (rotate:DI (match_dup 1) (match_dup 2)))
6760    (set (match_dup 0)
6761         (compare:CC (match_dup 3)
6762                     (const_int 0)))]
6763   "")
6764
6765 (define_insn "*rotldi3_internal3"
6766   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6767         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6768                                (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6769                     (const_int 0)))
6770    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6771         (rotate:DI (match_dup 1) (match_dup 2)))]
6772   "TARGET_64BIT"
6773   "@
6774    rldcl. %0,%1,%2,0
6775    rldicl. %0,%1,%H2,0
6776    #
6777    #"
6778   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6779    (set_attr "length" "4,4,8,8")])
6780
6781 (define_split
6782   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6783         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6784                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6785                     (const_int 0)))
6786    (set (match_operand:DI 0 "gpc_reg_operand" "")
6787         (rotate:DI (match_dup 1) (match_dup 2)))]
6788   "TARGET_POWERPC64 && reload_completed"
6789   [(set (match_dup 0)
6790         (rotate:DI (match_dup 1) (match_dup 2)))
6791    (set (match_dup 3)
6792         (compare:CC (match_dup 0)
6793                     (const_int 0)))]
6794   "")
6795
6796 (define_insn "*rotldi3_internal4"
6797   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6798         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6799                            (match_operand:DI 2 "reg_or_cint_operand" "r,i"))
6800                 (match_operand:DI 3 "mask64_operand" "n,n")))]
6801   "TARGET_POWERPC64"
6802   "@
6803    rldc%B3 %0,%1,%2,%S3
6804    rldic%B3 %0,%1,%H2,%S3"
6805   [(set_attr "type" "var_shift_rotate,integer")])
6806
6807 (define_insn "*rotldi3_internal5"
6808   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6809         (compare:CC (and:DI
6810                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6811                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6812                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
6813                     (const_int 0)))
6814    (clobber (match_scratch:DI 4 "=r,r,r,r"))]
6815   "TARGET_64BIT"
6816   "@
6817    rldc%B3. %4,%1,%2,%S3
6818    rldic%B3. %4,%1,%H2,%S3
6819    #
6820    #"
6821   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6822    (set_attr "length" "4,4,8,8")])
6823
6824 (define_split
6825   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6826         (compare:CC (and:DI
6827                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6828                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6829                      (match_operand:DI 3 "mask64_operand" ""))
6830                     (const_int 0)))
6831    (clobber (match_scratch:DI 4 ""))]
6832   "TARGET_POWERPC64 && reload_completed"
6833   [(set (match_dup 4)
6834         (and:DI (rotate:DI (match_dup 1)
6835                                 (match_dup 2))
6836                      (match_dup 3)))
6837    (set (match_dup 0)
6838         (compare:CC (match_dup 4)
6839                     (const_int 0)))]
6840   "")
6841
6842 (define_insn "*rotldi3_internal6"
6843   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
6844         (compare:CC (and:DI
6845                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6846                                 (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i"))
6847                      (match_operand:DI 3 "mask64_operand" "n,n,n,n"))
6848                     (const_int 0)))
6849    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6850         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6851   "TARGET_64BIT"
6852   "@
6853    rldc%B3. %0,%1,%2,%S3
6854    rldic%B3. %0,%1,%H2,%S3
6855    #
6856    #"
6857   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6858    (set_attr "length" "4,4,8,8")])
6859
6860 (define_split
6861   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6862         (compare:CC (and:DI
6863                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6864                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6865                      (match_operand:DI 3 "mask64_operand" ""))
6866                     (const_int 0)))
6867    (set (match_operand:DI 0 "gpc_reg_operand" "")
6868         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6869   "TARGET_POWERPC64 && reload_completed"
6870   [(set (match_dup 0)
6871         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6872    (set (match_dup 4)
6873         (compare:CC (match_dup 0)
6874                     (const_int 0)))]
6875   "")
6876
6877 (define_insn "*rotldi3_internal7"
6878   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6879         (zero_extend:DI
6880          (subreg:QI
6881           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6882                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
6883   "TARGET_POWERPC64"
6884   "@
6885    rldcl %0,%1,%2,56
6886    rldicl %0,%1,%H2,56"
6887   [(set_attr "type" "var_shift_rotate,integer")])
6888
6889 (define_insn "*rotldi3_internal8"
6890   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6891         (compare:CC (zero_extend:DI
6892                      (subreg:QI
6893                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6894                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6895                     (const_int 0)))
6896    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6897   "TARGET_64BIT"
6898   "@
6899    rldcl. %3,%1,%2,56
6900    rldicl. %3,%1,%H2,56
6901    #
6902    #"
6903   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6904    (set_attr "length" "4,4,8,8")])
6905
6906 (define_split
6907   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6908         (compare:CC (zero_extend:DI
6909                      (subreg:QI
6910                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6911                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6912                     (const_int 0)))
6913    (clobber (match_scratch:DI 3 ""))]
6914   "TARGET_POWERPC64 && reload_completed"
6915   [(set (match_dup 3)
6916         (zero_extend:DI (subreg:QI
6917                       (rotate:DI (match_dup 1)
6918                                  (match_dup 2)) 0)))
6919    (set (match_dup 0)
6920         (compare:CC (match_dup 3)
6921                     (const_int 0)))]
6922   "")
6923
6924 (define_insn "*rotldi3_internal9"
6925   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6926         (compare:CC (zero_extend:DI
6927                      (subreg:QI
6928                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6929                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6930                     (const_int 0)))
6931    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6932         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6933   "TARGET_64BIT"
6934   "@
6935    rldcl. %0,%1,%2,56
6936    rldicl. %0,%1,%H2,56
6937    #
6938    #"
6939   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6940    (set_attr "length" "4,4,8,8")])
6941
6942 (define_split
6943   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6944         (compare:CC (zero_extend:DI
6945                      (subreg:QI
6946                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6947                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6948                     (const_int 0)))
6949    (set (match_operand:DI 0 "gpc_reg_operand" "")
6950         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6951   "TARGET_POWERPC64 && reload_completed"
6952   [(set (match_dup 0)
6953         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6954    (set (match_dup 3)
6955         (compare:CC (match_dup 0)
6956                     (const_int 0)))]
6957   "")
6958
6959 (define_insn "*rotldi3_internal10"
6960   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6961         (zero_extend:DI
6962          (subreg:HI
6963           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6964                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
6965   "TARGET_POWERPC64"
6966   "@
6967    rldcl %0,%1,%2,48
6968    rldicl %0,%1,%H2,48"
6969   [(set_attr "type" "var_shift_rotate,integer")])
6970
6971 (define_insn "*rotldi3_internal11"
6972   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6973         (compare:CC (zero_extend:DI
6974                      (subreg:HI
6975                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
6976                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
6977                     (const_int 0)))
6978    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6979   "TARGET_64BIT"
6980   "@
6981    rldcl. %3,%1,%2,48
6982    rldicl. %3,%1,%H2,48
6983    #
6984    #"
6985   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
6986    (set_attr "length" "4,4,8,8")])
6987
6988 (define_split
6989   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6990         (compare:CC (zero_extend:DI
6991                      (subreg:HI
6992                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6993                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6994                     (const_int 0)))
6995    (clobber (match_scratch:DI 3 ""))]
6996   "TARGET_POWERPC64 && reload_completed"
6997   [(set (match_dup 3)
6998         (zero_extend:DI (subreg:HI
6999                       (rotate:DI (match_dup 1)
7000                                  (match_dup 2)) 0)))
7001    (set (match_dup 0)
7002         (compare:CC (match_dup 3)
7003                     (const_int 0)))]
7004   "")
7005
7006 (define_insn "*rotldi3_internal12"
7007   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7008         (compare:CC (zero_extend:DI
7009                      (subreg:HI
7010                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7011                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7012                     (const_int 0)))
7013    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7014         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7015   "TARGET_64BIT"
7016   "@
7017    rldcl. %0,%1,%2,48
7018    rldicl. %0,%1,%H2,48
7019    #
7020    #"
7021   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7022    (set_attr "length" "4,4,8,8")])
7023
7024 (define_split
7025   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7026         (compare:CC (zero_extend:DI
7027                      (subreg:HI
7028                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7029                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7030                     (const_int 0)))
7031    (set (match_operand:DI 0 "gpc_reg_operand" "")
7032         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7033   "TARGET_POWERPC64 && reload_completed"
7034   [(set (match_dup 0)
7035         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7036    (set (match_dup 3)
7037         (compare:CC (match_dup 0)
7038                     (const_int 0)))]
7039   "")
7040
7041 (define_insn "*rotldi3_internal13"
7042   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7043         (zero_extend:DI
7044          (subreg:SI
7045           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7046                      (match_operand:DI 2 "reg_or_cint_operand" "r,i")) 0)))]
7047   "TARGET_POWERPC64"
7048   "@
7049    rldcl %0,%1,%2,32
7050    rldicl %0,%1,%H2,32"
7051   [(set_attr "type" "var_shift_rotate,integer")])
7052
7053 (define_insn "*rotldi3_internal14"
7054   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7055         (compare:CC (zero_extend:DI
7056                      (subreg:SI
7057                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7058                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7059                     (const_int 0)))
7060    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7061   "TARGET_64BIT"
7062   "@
7063    rldcl. %3,%1,%2,32
7064    rldicl. %3,%1,%H2,32
7065    #
7066    #"
7067   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7068    (set_attr "length" "4,4,8,8")])
7069
7070 (define_split
7071   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7072         (compare:CC (zero_extend:DI
7073                      (subreg:SI
7074                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7075                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7076                     (const_int 0)))
7077    (clobber (match_scratch:DI 3 ""))]
7078   "TARGET_POWERPC64 && reload_completed"
7079   [(set (match_dup 3)
7080         (zero_extend:DI (subreg:SI
7081                       (rotate:DI (match_dup 1)
7082                                  (match_dup 2)) 0)))
7083    (set (match_dup 0)
7084         (compare:CC (match_dup 3)
7085                     (const_int 0)))]
7086   "")
7087
7088 (define_insn "*rotldi3_internal15"
7089   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7090         (compare:CC (zero_extend:DI
7091                      (subreg:SI
7092                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7093                                  (match_operand:DI 2 "reg_or_cint_operand" "r,i,r,i")) 0))
7094                     (const_int 0)))
7095    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7096         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7097   "TARGET_64BIT"
7098   "@
7099    rldcl. %0,%1,%2,32
7100    rldicl. %0,%1,%H2,32
7101    #
7102    #"
7103   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7104    (set_attr "length" "4,4,8,8")])
7105
7106 (define_split
7107   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7108         (compare:CC (zero_extend:DI
7109                      (subreg:SI
7110                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7111                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7112                     (const_int 0)))
7113    (set (match_operand:DI 0 "gpc_reg_operand" "")
7114         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7115   "TARGET_POWERPC64 && reload_completed"
7116   [(set (match_dup 0)
7117         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7118    (set (match_dup 3)
7119         (compare:CC (match_dup 0)
7120                     (const_int 0)))]
7121   "")
7122
7123 (define_expand "ashldi3"
7124   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7125         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7126                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
7127   "TARGET_POWERPC64 || TARGET_POWER"
7128   "
7129 {
7130   if (TARGET_POWERPC64)
7131     ;
7132   else if (TARGET_POWER)
7133     {
7134       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
7135       DONE;
7136     }
7137   else
7138     FAIL;
7139 }")
7140
7141 (define_insn "*ashldi3_internal1"
7142   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7143         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7144                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7145   "TARGET_POWERPC64"
7146   "@
7147    sld %0,%1,%2
7148    sldi %0,%1,%H2"
7149   [(set_attr "type" "var_shift_rotate,shift")])
7150
7151 (define_insn "*ashldi3_internal2"
7152   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7153         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7154                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7155                     (const_int 0)))
7156    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7157   "TARGET_64BIT"
7158   "@
7159    sld. %3,%1,%2
7160    sldi. %3,%1,%H2
7161    #
7162    #"
7163   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7164    (set_attr "length" "4,4,8,8")])
7165
7166 (define_split
7167   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7168         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7169                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7170                     (const_int 0)))
7171    (clobber (match_scratch:DI 3 ""))]
7172   "TARGET_POWERPC64 && reload_completed"
7173   [(set (match_dup 3)
7174         (ashift:DI (match_dup 1) (match_dup 2)))
7175    (set (match_dup 0)
7176         (compare:CC (match_dup 3)
7177                     (const_int 0)))]
7178   "")
7179
7180 (define_insn "*ashldi3_internal3"
7181   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7182         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7183                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7184                     (const_int 0)))
7185    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7186         (ashift:DI (match_dup 1) (match_dup 2)))]
7187   "TARGET_64BIT"
7188   "@
7189    sld. %0,%1,%2
7190    sldi. %0,%1,%H2
7191    #
7192    #"
7193   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7194    (set_attr "length" "4,4,8,8")])
7195
7196 (define_split
7197   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7198         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7199                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7200                     (const_int 0)))
7201    (set (match_operand:DI 0 "gpc_reg_operand" "")
7202         (ashift:DI (match_dup 1) (match_dup 2)))]
7203   "TARGET_POWERPC64 && reload_completed"
7204   [(set (match_dup 0)
7205         (ashift:DI (match_dup 1) (match_dup 2)))
7206    (set (match_dup 3)
7207         (compare:CC (match_dup 0)
7208                     (const_int 0)))]
7209   "")
7210
7211 (define_insn "*ashldi3_internal4"
7212   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7213         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7214                            (match_operand:SI 2 "const_int_operand" "i"))
7215                 (match_operand:DI 3 "const_int_operand" "n")))]
7216   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
7217   "rldic %0,%1,%H2,%W3")
7218
7219 (define_insn "ashldi3_internal5"
7220   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7221         (compare:CC
7222          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7223                             (match_operand:SI 2 "const_int_operand" "i,i"))
7224                  (match_operand:DI 3 "const_int_operand" "n,n"))
7225          (const_int 0)))
7226    (clobber (match_scratch:DI 4 "=r,r"))]
7227   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7228   "@
7229    rldic. %4,%1,%H2,%W3
7230    #"
7231   [(set_attr "type" "compare")
7232    (set_attr "length" "4,8")])
7233
7234 (define_split
7235   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7236         (compare:CC
7237          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7238                             (match_operand:SI 2 "const_int_operand" ""))
7239                  (match_operand:DI 3 "const_int_operand" ""))
7240          (const_int 0)))
7241    (clobber (match_scratch:DI 4 ""))]
7242   "TARGET_POWERPC64 && reload_completed
7243    && includes_rldic_lshift_p (operands[2], operands[3])"
7244   [(set (match_dup 4)
7245         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7246                 (match_dup 3)))
7247    (set (match_dup 0)
7248         (compare:CC (match_dup 4)
7249                     (const_int 0)))]
7250   "")
7251
7252 (define_insn "*ashldi3_internal6"
7253   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7254         (compare:CC
7255          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7256                             (match_operand:SI 2 "const_int_operand" "i,i"))
7257                     (match_operand:DI 3 "const_int_operand" "n,n"))
7258          (const_int 0)))
7259    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7260         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7261   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7262   "@
7263    rldic. %0,%1,%H2,%W3
7264    #"
7265   [(set_attr "type" "compare")
7266    (set_attr "length" "4,8")])
7267
7268 (define_split
7269   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
7270         (compare:CC
7271          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7272                             (match_operand:SI 2 "const_int_operand" ""))
7273                  (match_operand:DI 3 "const_int_operand" ""))
7274          (const_int 0)))
7275    (set (match_operand:DI 0 "gpc_reg_operand" "")
7276         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7277   "TARGET_POWERPC64 && reload_completed
7278    && includes_rldic_lshift_p (operands[2], operands[3])"
7279   [(set (match_dup 0)
7280         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7281                 (match_dup 3)))
7282    (set (match_dup 4)
7283         (compare:CC (match_dup 0)
7284                     (const_int 0)))]
7285   "")
7286
7287 (define_insn "*ashldi3_internal7"
7288   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7289         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7290                            (match_operand:SI 2 "const_int_operand" "i"))
7291                 (match_operand:DI 3 "mask64_operand" "n")))]
7292   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
7293   "rldicr %0,%1,%H2,%S3")
7294
7295 (define_insn "ashldi3_internal8"
7296   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7297         (compare:CC
7298          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7299                             (match_operand:SI 2 "const_int_operand" "i,i"))
7300                  (match_operand:DI 3 "mask64_operand" "n,n"))
7301          (const_int 0)))
7302    (clobber (match_scratch:DI 4 "=r,r"))]
7303   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7304   "@
7305    rldicr. %4,%1,%H2,%S3
7306    #"
7307   [(set_attr "type" "compare")
7308    (set_attr "length" "4,8")])
7309
7310 (define_split
7311   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7312         (compare:CC
7313          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7314                             (match_operand:SI 2 "const_int_operand" ""))
7315                  (match_operand:DI 3 "mask64_operand" ""))
7316          (const_int 0)))
7317    (clobber (match_scratch:DI 4 ""))]
7318   "TARGET_POWERPC64 && reload_completed
7319    && includes_rldicr_lshift_p (operands[2], operands[3])"
7320   [(set (match_dup 4)
7321         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7322                 (match_dup 3)))
7323    (set (match_dup 0)
7324         (compare:CC (match_dup 4)
7325                     (const_int 0)))]
7326   "")
7327
7328 (define_insn "*ashldi3_internal9"
7329   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7330         (compare:CC
7331          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7332                             (match_operand:SI 2 "const_int_operand" "i,i"))
7333                     (match_operand:DI 3 "mask64_operand" "n,n"))
7334          (const_int 0)))
7335    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7336         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7337   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7338   "@
7339    rldicr. %0,%1,%H2,%S3
7340    #"
7341   [(set_attr "type" "compare")
7342    (set_attr "length" "4,8")])
7343
7344 (define_split
7345   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
7346         (compare:CC
7347          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7348                             (match_operand:SI 2 "const_int_operand" ""))
7349                  (match_operand:DI 3 "mask64_operand" ""))
7350          (const_int 0)))
7351    (set (match_operand:DI 0 "gpc_reg_operand" "")
7352         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7353   "TARGET_POWERPC64 && reload_completed
7354    && includes_rldicr_lshift_p (operands[2], operands[3])"
7355   [(set (match_dup 0)
7356         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7357                 (match_dup 3)))
7358    (set (match_dup 4)
7359         (compare:CC (match_dup 0)
7360                     (const_int 0)))]
7361   "")
7362
7363 (define_expand "lshrdi3"
7364   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7365         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7366                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7367   "TARGET_POWERPC64 || TARGET_POWER"
7368   "
7369 {
7370   if (TARGET_POWERPC64)
7371     ;
7372   else if (TARGET_POWER)
7373     {
7374       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
7375       DONE;
7376     }
7377   else
7378     FAIL;
7379 }")
7380
7381 (define_insn "*lshrdi3_internal1"
7382   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7383         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7384                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7385   "TARGET_POWERPC64"
7386   "@
7387    srd %0,%1,%2
7388    srdi %0,%1,%H2"
7389   [(set_attr "type" "var_shift_rotate,shift")])
7390
7391 (define_insn "*lshrdi3_internal2"
7392   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7393         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7394                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7395                     (const_int 0)))
7396    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7397   "TARGET_64BIT "
7398   "@
7399    srd. %3,%1,%2
7400    srdi. %3,%1,%H2
7401    #
7402    #"
7403   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7404    (set_attr "length" "4,4,8,8")])
7405
7406 (define_split
7407   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7408         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7409                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7410                     (const_int 0)))
7411    (clobber (match_scratch:DI 3 ""))]
7412   "TARGET_POWERPC64 && reload_completed"
7413   [(set (match_dup 3)
7414         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7415    (set (match_dup 0)
7416         (compare:CC (match_dup 3)
7417                     (const_int 0)))]
7418   "")
7419
7420 (define_insn "*lshrdi3_internal3"
7421   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7422         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7423                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7424                     (const_int 0)))
7425    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7426         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7427   "TARGET_64BIT"
7428   "@
7429    srd. %0,%1,%2
7430    srdi. %0,%1,%H2
7431    #
7432    #"
7433   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7434    (set_attr "length" "4,4,8,8")])
7435
7436 (define_split
7437   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7438         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7439                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7440                     (const_int 0)))
7441    (set (match_operand:DI 0 "gpc_reg_operand" "")
7442         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7443   "TARGET_POWERPC64 && reload_completed"
7444   [(set (match_dup 0)
7445         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7446    (set (match_dup 3)
7447         (compare:CC (match_dup 0)
7448                     (const_int 0)))]
7449   "")
7450
7451 (define_expand "ashrdi3"
7452   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7453         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7454                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7455   "WORDS_BIG_ENDIAN"
7456   "
7457 {
7458   if (TARGET_POWERPC64)
7459     ;
7460   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
7461     {
7462       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
7463       DONE;
7464     }
7465   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
7466            && WORDS_BIG_ENDIAN)
7467     {
7468       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
7469       DONE;
7470     }
7471   else
7472     FAIL;
7473 }")
7474
7475 (define_insn "*ashrdi3_internal1"
7476   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7477         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7478                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))]
7479   "TARGET_POWERPC64"
7480   "@
7481    srad %0,%1,%2
7482    sradi %0,%1,%H2"
7483   [(set_attr "type" "var_shift_rotate,shift")])
7484
7485 (define_insn "*ashrdi3_internal2"
7486   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
7487         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7488                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7489                     (const_int 0)))
7490    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
7491   "TARGET_64BIT"
7492   "@
7493    srad. %3,%1,%2
7494    sradi. %3,%1,%H2
7495    #
7496    #"
7497   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7498    (set_attr "length" "4,4,8,8")])
7499
7500 (define_split
7501   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7502         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7503                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7504                     (const_int 0)))
7505    (clobber (match_scratch:DI 3 ""))]
7506   "TARGET_POWERPC64 && reload_completed"
7507   [(set (match_dup 3)
7508         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7509    (set (match_dup 0)
7510         (compare:CC (match_dup 3)
7511                     (const_int 0)))]
7512   "")
7513
7514 (define_insn "*ashrdi3_internal3"
7515   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
7516         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
7517                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
7518                     (const_int 0)))
7519    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
7520         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7521   "TARGET_64BIT"
7522   "@
7523    srad. %0,%1,%2
7524    sradi. %0,%1,%H2
7525    #
7526    #"
7527   [(set_attr "type" "var_delayed_compare,delayed_compare,var_delayed_compare,delayed_compare")
7528    (set_attr "length" "4,4,8,8")])
7529
7530 (define_split
7531   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7532         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7533                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7534                     (const_int 0)))
7535    (set (match_operand:DI 0 "gpc_reg_operand" "")
7536         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7537   "TARGET_POWERPC64 && reload_completed"
7538   [(set (match_dup 0)
7539         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7540    (set (match_dup 3)
7541         (compare:CC (match_dup 0)
7542                     (const_int 0)))]
7543   "")
7544
7545 (define_insn "anddi3"
7546   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
7547         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
7548                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
7549    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
7550   "TARGET_POWERPC64"
7551   "@
7552    and %0,%1,%2
7553    rldic%B2 %0,%1,0,%S2
7554    rlwinm %0,%1,0,%m2,%M2
7555    andi. %0,%1,%b2
7556    andis. %0,%1,%u2
7557    #"
7558   [(set_attr "type" "*,*,*,compare,compare,*")
7559    (set_attr "length" "4,4,4,4,4,8")])
7560
7561 (define_split
7562   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7563         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7564                 (match_operand:DI 2 "mask64_2_operand" "")))
7565    (clobber (match_scratch:CC 3 ""))]
7566   "TARGET_POWERPC64
7567     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7568     && !mask_operand (operands[2], DImode)
7569     && !mask64_operand (operands[2], DImode)"
7570   [(set (match_dup 0)
7571         (and:DI (rotate:DI (match_dup 1)
7572                            (match_dup 4))
7573                 (match_dup 5)))
7574    (set (match_dup 0)
7575         (and:DI (rotate:DI (match_dup 0)
7576                            (match_dup 6))
7577                 (match_dup 7)))]
7578 {
7579   build_mask64_2_operands (operands[2], &operands[4]);
7580 })
7581
7582 (define_insn "*anddi3_internal2"
7583   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7584         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7585                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7586                     (const_int 0)))
7587    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r,r,r"))
7588    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7589   "TARGET_64BIT"
7590   "@
7591    and. %3,%1,%2
7592    rldic%B2. %3,%1,0,%S2
7593    rlwinm. %3,%1,0,%m2,%M2
7594    andi. %3,%1,%b2
7595    andis. %3,%1,%u2
7596    #
7597    #
7598    #
7599    #
7600    #
7601    #
7602    #"
7603   [(set_attr "type" "compare,compare,delayed_compare,compare,compare,compare,compare,compare,compare,compare,compare,compare")
7604    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7605
7606 (define_split
7607   [(set (match_operand:CC 0 "cc_reg_operand" "")
7608         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7609                             (match_operand:DI 2 "mask64_2_operand" ""))
7610                     (const_int 0)))
7611    (clobber (match_scratch:DI 3 ""))
7612    (clobber (match_scratch:CC 4 ""))]
7613   "TARGET_64BIT && reload_completed
7614     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7615     && !mask_operand (operands[2], DImode)
7616     && !mask64_operand (operands[2], DImode)"
7617   [(set (match_dup 3)
7618         (and:DI (rotate:DI (match_dup 1)
7619                            (match_dup 5))
7620                 (match_dup 6)))
7621    (parallel [(set (match_dup 0)
7622                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7623                                                   (match_dup 7))
7624                                        (match_dup 8))
7625                                (const_int 0)))
7626               (clobber (match_dup 3))])]
7627   "
7628 {
7629   build_mask64_2_operands (operands[2], &operands[5]);
7630 }")
7631
7632 (define_insn "*anddi3_internal3"
7633   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7634         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7635                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7636                     (const_int 0)))
7637    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r,r,r")
7638         (and:DI (match_dup 1) (match_dup 2)))
7639    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7640   "TARGET_64BIT"
7641   "@
7642    and. %0,%1,%2
7643    rldic%B2. %0,%1,0,%S2
7644    rlwinm. %0,%1,0,%m2,%M2
7645    andi. %0,%1,%b2
7646    andis. %0,%1,%u2
7647    #
7648    #
7649    #
7650    #
7651    #
7652    #
7653    #"
7654   [(set_attr "type" "compare,compare,delayed_compare,compare,compare,compare,compare,compare,compare,compare,compare,compare")
7655    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7656
7657 (define_split
7658   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7659         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7660                             (match_operand:DI 2 "and64_2_operand" ""))
7661                     (const_int 0)))
7662    (set (match_operand:DI 0 "gpc_reg_operand" "")
7663         (and:DI (match_dup 1) (match_dup 2)))
7664    (clobber (match_scratch:CC 4 ""))]
7665   "TARGET_64BIT && reload_completed"
7666   [(parallel [(set (match_dup 0)
7667                     (and:DI (match_dup 1) (match_dup 2)))
7668                (clobber (match_dup 4))])
7669    (set (match_dup 3)
7670         (compare:CC (match_dup 0)
7671                     (const_int 0)))]
7672   "")
7673
7674 (define_split
7675   [(set (match_operand:CC 3 "cc_reg_operand" "")
7676         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7677                             (match_operand:DI 2 "mask64_2_operand" ""))
7678                     (const_int 0)))
7679    (set (match_operand:DI 0 "gpc_reg_operand" "")
7680         (and:DI (match_dup 1) (match_dup 2)))
7681    (clobber (match_scratch:CC 4 ""))]
7682   "TARGET_64BIT && reload_completed
7683     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7684     && !mask_operand (operands[2], DImode)
7685     && !mask64_operand (operands[2], DImode)"
7686   [(set (match_dup 0)
7687         (and:DI (rotate:DI (match_dup 1)
7688                            (match_dup 5))
7689                 (match_dup 6)))
7690    (parallel [(set (match_dup 3)
7691                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7692                                                   (match_dup 7))
7693                                        (match_dup 8))
7694                                (const_int 0)))
7695               (set (match_dup 0)
7696                    (and:DI (rotate:DI (match_dup 0)
7697                                       (match_dup 7))
7698                            (match_dup 8)))])]
7699   "
7700 {
7701   build_mask64_2_operands (operands[2], &operands[5]);
7702 }")
7703
7704 (define_expand "iordi3"
7705   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7706         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7707                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7708   "TARGET_POWERPC64"
7709   "
7710 {
7711   if (non_logical_cint_operand (operands[2], DImode))
7712     {
7713       HOST_WIDE_INT value;
7714       rtx tmp = ((!can_create_pseudo_p ()
7715                   || rtx_equal_p (operands[0], operands[1]))
7716                  ? operands[0] : gen_reg_rtx (DImode));
7717
7718       if (GET_CODE (operands[2]) == CONST_INT)
7719         {
7720           value = INTVAL (operands[2]);
7721           emit_insn (gen_iordi3 (tmp, operands[1],
7722                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7723         }
7724       else
7725         {
7726           value = CONST_DOUBLE_LOW (operands[2]);
7727           emit_insn (gen_iordi3 (tmp, operands[1],
7728                                  immed_double_const (value
7729                                                      & (~ (HOST_WIDE_INT) 0xffff),
7730                                                      0, DImode)));
7731         }
7732
7733       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7734       DONE;
7735     }
7736 }")
7737
7738 (define_expand "xordi3"
7739   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7740         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7741                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7742   "TARGET_POWERPC64"
7743   "
7744 {
7745   if (non_logical_cint_operand (operands[2], DImode))
7746     {
7747       HOST_WIDE_INT value;
7748       rtx tmp = ((!can_create_pseudo_p ()
7749                   || rtx_equal_p (operands[0], operands[1]))
7750                  ? operands[0] : gen_reg_rtx (DImode));
7751
7752       if (GET_CODE (operands[2]) == CONST_INT)
7753         {
7754           value = INTVAL (operands[2]);
7755           emit_insn (gen_xordi3 (tmp, operands[1],
7756                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7757         }
7758       else
7759         {
7760           value = CONST_DOUBLE_LOW (operands[2]);
7761           emit_insn (gen_xordi3 (tmp, operands[1],
7762                                  immed_double_const (value
7763                                                      & (~ (HOST_WIDE_INT) 0xffff),
7764                                                      0, DImode)));
7765         }
7766
7767       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7768       DONE;
7769     }
7770 }")
7771
7772 (define_insn "*booldi3_internal1"
7773   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7774         (match_operator:DI 3 "boolean_or_operator"
7775          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7776           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7777   "TARGET_POWERPC64"
7778   "@
7779    %q3 %0,%1,%2
7780    %q3i %0,%1,%b2
7781    %q3is %0,%1,%u2")
7782
7783 (define_insn "*booldi3_internal2"
7784   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7785         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7786          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7787           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7788          (const_int 0)))
7789    (clobber (match_scratch:DI 3 "=r,r"))]
7790   "TARGET_64BIT"
7791   "@
7792    %q4. %3,%1,%2
7793    #"
7794   [(set_attr "type" "compare")
7795    (set_attr "length" "4,8")])
7796
7797 (define_split
7798   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7799         (compare:CC (match_operator:DI 4 "boolean_operator"
7800          [(match_operand:DI 1 "gpc_reg_operand" "")
7801           (match_operand:DI 2 "gpc_reg_operand" "")])
7802          (const_int 0)))
7803    (clobber (match_scratch:DI 3 ""))]
7804   "TARGET_POWERPC64 && reload_completed"
7805   [(set (match_dup 3) (match_dup 4))
7806    (set (match_dup 0)
7807         (compare:CC (match_dup 3)
7808                     (const_int 0)))]
7809   "")
7810
7811 (define_insn "*booldi3_internal3"
7812   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7813         (compare:CC (match_operator:DI 4 "boolean_operator"
7814          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7815           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7816          (const_int 0)))
7817    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7818         (match_dup 4))]
7819   "TARGET_64BIT"
7820   "@
7821    %q4. %0,%1,%2
7822    #"
7823   [(set_attr "type" "compare")
7824    (set_attr "length" "4,8")])
7825
7826 (define_split
7827   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7828         (compare:CC (match_operator:DI 4 "boolean_operator"
7829          [(match_operand:DI 1 "gpc_reg_operand" "")
7830           (match_operand:DI 2 "gpc_reg_operand" "")])
7831          (const_int 0)))
7832    (set (match_operand:DI 0 "gpc_reg_operand" "")
7833         (match_dup 4))]
7834   "TARGET_POWERPC64 && reload_completed"
7835   [(set (match_dup 0) (match_dup 4))
7836    (set (match_dup 3)
7837         (compare:CC (match_dup 0)
7838                     (const_int 0)))]
7839   "")
7840
7841 ;; Split a logical operation that we can't do in one insn into two insns,
7842 ;; each of which does one 16-bit part.  This is used by combine.
7843
7844 (define_split
7845   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7846         (match_operator:DI 3 "boolean_or_operator"
7847          [(match_operand:DI 1 "gpc_reg_operand" "")
7848           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7849   "TARGET_POWERPC64"
7850   [(set (match_dup 0) (match_dup 4))
7851    (set (match_dup 0) (match_dup 5))]
7852 "
7853 {
7854   rtx i3,i4;
7855
7856   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7857     {
7858       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7859       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7860                                         0, DImode);
7861       i4 = GEN_INT (value & 0xffff);
7862     }
7863   else
7864     {
7865       i3 = GEN_INT (INTVAL (operands[2])
7866                              & (~ (HOST_WIDE_INT) 0xffff));
7867       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7868     }
7869   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7870                                 operands[1], i3);
7871   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7872                                 operands[0], i4);
7873 }")
7874
7875 (define_insn "*boolcdi3_internal1"
7876   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7877         (match_operator:DI 3 "boolean_operator"
7878          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7879           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7880   "TARGET_POWERPC64"
7881   "%q3 %0,%2,%1")
7882
7883 (define_insn "*boolcdi3_internal2"
7884   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7885         (compare:CC (match_operator:DI 4 "boolean_operator"
7886          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7887           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7888          (const_int 0)))
7889    (clobber (match_scratch:DI 3 "=r,r"))]
7890   "TARGET_64BIT"
7891   "@
7892    %q4. %3,%2,%1
7893    #"
7894   [(set_attr "type" "compare")
7895    (set_attr "length" "4,8")])
7896
7897 (define_split
7898   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7899         (compare:CC (match_operator:DI 4 "boolean_operator"
7900          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7901           (match_operand:DI 2 "gpc_reg_operand" "")])
7902          (const_int 0)))
7903    (clobber (match_scratch:DI 3 ""))]
7904   "TARGET_POWERPC64 && reload_completed"
7905   [(set (match_dup 3) (match_dup 4))
7906    (set (match_dup 0)
7907         (compare:CC (match_dup 3)
7908                     (const_int 0)))]
7909   "")
7910
7911 (define_insn "*boolcdi3_internal3"
7912   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7913         (compare:CC (match_operator:DI 4 "boolean_operator"
7914          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7915           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7916          (const_int 0)))
7917    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7918         (match_dup 4))]
7919   "TARGET_64BIT"
7920   "@
7921    %q4. %0,%2,%1
7922    #"
7923   [(set_attr "type" "compare")
7924    (set_attr "length" "4,8")])
7925
7926 (define_split
7927   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7928         (compare:CC (match_operator:DI 4 "boolean_operator"
7929          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7930           (match_operand:DI 2 "gpc_reg_operand" "")])
7931          (const_int 0)))
7932    (set (match_operand:DI 0 "gpc_reg_operand" "")
7933         (match_dup 4))]
7934   "TARGET_POWERPC64 && reload_completed"
7935   [(set (match_dup 0) (match_dup 4))
7936    (set (match_dup 3)
7937         (compare:CC (match_dup 0)
7938                     (const_int 0)))]
7939   "")
7940
7941 (define_insn "*boolccdi3_internal1"
7942   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7943         (match_operator:DI 3 "boolean_operator"
7944          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7945           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7946   "TARGET_POWERPC64"
7947   "%q3 %0,%1,%2")
7948
7949 (define_insn "*boolccdi3_internal2"
7950   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7951         (compare:CC (match_operator:DI 4 "boolean_operator"
7952          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7953           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7954          (const_int 0)))
7955    (clobber (match_scratch:DI 3 "=r,r"))]
7956   "TARGET_64BIT"
7957   "@
7958    %q4. %3,%1,%2
7959    #"
7960   [(set_attr "type" "compare")
7961    (set_attr "length" "4,8")])
7962
7963 (define_split
7964   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7965         (compare:CC (match_operator:DI 4 "boolean_operator"
7966          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7967           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7968          (const_int 0)))
7969    (clobber (match_scratch:DI 3 ""))]
7970   "TARGET_POWERPC64 && reload_completed"
7971   [(set (match_dup 3) (match_dup 4))
7972    (set (match_dup 0)
7973         (compare:CC (match_dup 3)
7974                     (const_int 0)))]
7975   "")
7976
7977 (define_insn "*boolccdi3_internal3"
7978   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7979         (compare:CC (match_operator:DI 4 "boolean_operator"
7980          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7981           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7982          (const_int 0)))
7983    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7984         (match_dup 4))]
7985   "TARGET_64BIT"
7986   "@
7987    %q4. %0,%1,%2
7988    #"
7989   [(set_attr "type" "compare")
7990    (set_attr "length" "4,8")])
7991
7992 (define_split
7993   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7994         (compare:CC (match_operator:DI 4 "boolean_operator"
7995          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7996           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7997          (const_int 0)))
7998    (set (match_operand:DI 0 "gpc_reg_operand" "")
7999         (match_dup 4))]
8000   "TARGET_POWERPC64 && reload_completed"
8001   [(set (match_dup 0) (match_dup 4))
8002    (set (match_dup 3)
8003         (compare:CC (match_dup 0)
8004                     (const_int 0)))]
8005   "")
8006 \f
8007 ;; Now define ways of moving data around.
8008
8009 ;; Set up a register with a value from the GOT table
8010
8011 (define_expand "movsi_got"
8012   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8013         (unspec:SI [(match_operand:SI 1 "got_operand" "")
8014                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
8015   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8016   "
8017 {
8018   if (GET_CODE (operands[1]) == CONST)
8019     {
8020       rtx offset = const0_rtx;
8021       HOST_WIDE_INT value;
8022
8023       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
8024       value = INTVAL (offset);
8025       if (value != 0)
8026         {
8027           rtx tmp = (!can_create_pseudo_p ()
8028                      ? operands[0]
8029                      : gen_reg_rtx (Pmode));
8030           emit_insn (gen_movsi_got (tmp, operands[1]));
8031           emit_insn (gen_addsi3 (operands[0], tmp, offset));
8032           DONE;
8033         }
8034     }
8035
8036   operands[2] = rs6000_got_register (operands[1]);
8037 }")
8038
8039 (define_insn "*movsi_got_internal"
8040   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8041         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8042                     (match_operand:SI 2 "gpc_reg_operand" "b")]
8043                    UNSPEC_MOVSI_GOT))]
8044   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8045   "{l|lwz} %0,%a1@got(%2)"
8046   [(set_attr "type" "load")])
8047
8048 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
8049 ;; didn't get allocated to a hard register.
8050 (define_split
8051   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8052         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8053                     (match_operand:SI 2 "memory_operand" "")]
8054                    UNSPEC_MOVSI_GOT))]
8055   "DEFAULT_ABI == ABI_V4
8056     && flag_pic == 1
8057     && (reload_in_progress || reload_completed)"
8058   [(set (match_dup 0) (match_dup 2))
8059    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
8060                                  UNSPEC_MOVSI_GOT))]
8061   "")
8062
8063 ;; For SI, we special-case integers that can't be loaded in one insn.  We
8064 ;; do the load 16-bits at a time.  We could do this by loading from memory,
8065 ;; and this is even supposed to be faster, but it is simpler not to get
8066 ;; integers in the TOC.
8067 (define_insn "movsi_low"
8068   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8069         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
8070                            (match_operand 2 "" ""))))]
8071   "TARGET_MACHO && ! TARGET_64BIT"
8072   "{l|lwz} %0,lo16(%2)(%1)"
8073   [(set_attr "type" "load")
8074    (set_attr "length" "4")])
8075
8076 (define_insn "*movsi_internal1"
8077   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
8078         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
8079   "gpc_reg_operand (operands[0], SImode)
8080    || gpc_reg_operand (operands[1], SImode)"
8081   "@
8082    mr %0,%1
8083    {cal|la} %0,%a1
8084    {l%U1%X1|lwz%U1%X1} %0,%1
8085    {st%U0%X0|stw%U0%X0} %1,%0
8086    {lil|li} %0,%1
8087    {liu|lis} %0,%v1
8088    #
8089    {cal|la} %0,%a1
8090    mf%1 %0
8091    mt%0 %1
8092    mt%0 %1
8093    mt%0 %1
8094    {cror 0,0,0|nop}"
8095   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
8096    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
8097
8098 ;; Split a load of a large constant into the appropriate two-insn
8099 ;; sequence.
8100
8101 (define_split
8102   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8103         (match_operand:SI 1 "const_int_operand" ""))]
8104   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
8105    && (INTVAL (operands[1]) & 0xffff) != 0"
8106   [(set (match_dup 0)
8107         (match_dup 2))
8108    (set (match_dup 0)
8109         (ior:SI (match_dup 0)
8110                 (match_dup 3)))]
8111   "
8112 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
8113
8114   if (tem == operands[0])
8115     DONE;
8116   else
8117     FAIL;
8118 }")
8119
8120 (define_insn "*mov<mode>_internal2"
8121   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
8122         (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
8123                     (const_int 0)))
8124    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
8125   ""
8126   "@
8127    {cmpi|cmp<wd>i} %2,%0,0
8128    mr. %0,%1
8129    #"
8130   [(set_attr "type" "cmp,compare,cmp")
8131    (set_attr "length" "4,4,8")])
8132
8133 (define_split
8134   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
8135         (compare:CC (match_operand:P 1 "gpc_reg_operand" "")
8136                     (const_int 0)))
8137    (set (match_operand:P 0 "gpc_reg_operand" "") (match_dup 1))]
8138   "reload_completed"
8139   [(set (match_dup 0) (match_dup 1))
8140    (set (match_dup 2)
8141         (compare:CC (match_dup 0)
8142                     (const_int 0)))]
8143   "")
8144 \f
8145 (define_insn "*movhi_internal"
8146   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
8147         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
8148   "gpc_reg_operand (operands[0], HImode)
8149    || gpc_reg_operand (operands[1], HImode)"
8150   "@
8151    mr %0,%1
8152    lhz%U1%X1 %0,%1
8153    sth%U0%X0 %1,%0
8154    {lil|li} %0,%w1
8155    mf%1 %0
8156    mt%0 %1
8157    mt%0 %1
8158    {cror 0,0,0|nop}"
8159   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
8160
8161 (define_expand "mov<mode>"
8162   [(set (match_operand:INT 0 "general_operand" "")
8163         (match_operand:INT 1 "any_operand" ""))]
8164   ""
8165   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
8166
8167 (define_insn "*movqi_internal"
8168   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
8169         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
8170   "gpc_reg_operand (operands[0], QImode)
8171    || gpc_reg_operand (operands[1], QImode)"
8172   "@
8173    mr %0,%1
8174    lbz%U1%X1 %0,%1
8175    stb%U0%X0 %1,%0
8176    {lil|li} %0,%1
8177    mf%1 %0
8178    mt%0 %1
8179    mt%0 %1
8180    {cror 0,0,0|nop}"
8181   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
8182 \f
8183 ;; Here is how to move condition codes around.  When we store CC data in
8184 ;; an integer register or memory, we store just the high-order 4 bits.
8185 ;; This lets us not shift in the most common case of CR0.
8186 (define_expand "movcc"
8187   [(set (match_operand:CC 0 "nonimmediate_operand" "")
8188         (match_operand:CC 1 "nonimmediate_operand" ""))]
8189   ""
8190   "")
8191
8192 (define_insn "*movcc_internal1"
8193   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,y,r,r,r,r,r,q,cl,r,m")
8194         (match_operand:CC 1 "general_operand" "y,r,r,O,x,y,r,I,h,r,r,m,r"))]
8195   "register_operand (operands[0], CCmode)
8196    || register_operand (operands[1], CCmode)"
8197   "@
8198    mcrf %0,%1
8199    mtcrf 128,%1
8200    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
8201    crxor %0,%0,%0
8202    mfcr %0%Q1
8203    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
8204    mr %0,%1
8205    {lil|li} %0,%1
8206    mf%1 %0
8207    mt%0 %1
8208    mt%0 %1
8209    {l%U1%X1|lwz%U1%X1} %0,%1
8210    {st%U0%U1|stw%U0%U1} %1,%0"
8211   [(set (attr "type")
8212      (cond [(eq_attr "alternative" "0,3")
8213                 (const_string "cr_logical")
8214             (eq_attr "alternative" "1,2")
8215                 (const_string "mtcr")
8216             (eq_attr "alternative" "6,7,9")
8217                 (const_string "integer")
8218             (eq_attr "alternative" "8")
8219                 (const_string "mfjmpr")
8220             (eq_attr "alternative" "10")
8221                 (const_string "mtjmpr")
8222             (eq_attr "alternative" "11")
8223                 (const_string "load")
8224             (eq_attr "alternative" "12")
8225                 (const_string "store")
8226             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
8227                 (const_string "mfcrf")
8228            ]
8229         (const_string "mfcr")))
8230    (set_attr "length" "4,4,12,4,4,8,4,4,4,4,4,4,4")])
8231 \f
8232 ;; For floating-point, we normally deal with the floating-point registers
8233 ;; unless -msoft-float is used.  The sole exception is that parameter passing
8234 ;; can produce floating-point values in fixed-point registers.  Unless the
8235 ;; value is a simple constant or already in memory, we deal with this by
8236 ;; allocating memory and copying the value explicitly via that memory location.
8237 (define_expand "movsf"
8238   [(set (match_operand:SF 0 "nonimmediate_operand" "")
8239         (match_operand:SF 1 "any_operand" ""))]
8240   ""
8241   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
8242
8243 (define_split
8244   [(set (match_operand:SF 0 "gpc_reg_operand" "")
8245         (match_operand:SF 1 "const_double_operand" ""))]
8246   "reload_completed
8247    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8248        || (GET_CODE (operands[0]) == SUBREG
8249            && GET_CODE (SUBREG_REG (operands[0])) == REG
8250            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8251   [(set (match_dup 2) (match_dup 3))]
8252   "
8253 {
8254   long l;
8255   REAL_VALUE_TYPE rv;
8256
8257   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8258   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
8259
8260   if (! TARGET_POWERPC64)
8261     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
8262   else
8263     operands[2] = gen_lowpart (SImode, operands[0]);
8264
8265   operands[3] = gen_int_mode (l, SImode);
8266 }")
8267
8268 (define_insn "*movsf_hardfloat"
8269   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,*c*l,*q,!r,*h,!r,!r")
8270         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,0,G,Fn"))]
8271   "(gpc_reg_operand (operands[0], SFmode)
8272    || gpc_reg_operand (operands[1], SFmode))
8273    && (TARGET_HARD_FLOAT && TARGET_FPRS)"
8274   "@
8275    mr %0,%1
8276    {l%U1%X1|lwz%U1%X1} %0,%1
8277    {st%U0%X0|stw%U0%X0} %1,%0
8278    fmr %0,%1
8279    lfs%U1%X1 %0,%1
8280    stfs%U0%X0 %1,%0
8281    mt%0 %1
8282    mt%0 %1
8283    mf%1 %0
8284    {cror 0,0,0|nop}
8285    #
8286    #"
8287   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,mfjmpr,*,*,*")
8288    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,8")])
8289
8290 (define_insn "*movsf_softfloat"
8291   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
8292         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
8293   "(gpc_reg_operand (operands[0], SFmode)
8294    || gpc_reg_operand (operands[1], SFmode))
8295    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
8296   "@
8297    mr %0,%1
8298    mt%0 %1
8299    mt%0 %1
8300    mf%1 %0
8301    {l%U1%X1|lwz%U1%X1} %0,%1
8302    {st%U0%X0|stw%U0%X0} %1,%0
8303    {lil|li} %0,%1
8304    {liu|lis} %0,%v1
8305    {cal|la} %0,%a1
8306    #
8307    #
8308    {cror 0,0,0|nop}"
8309   [(set_attr "type" "*,mtjmpr,*,mfjmpr,load,store,*,*,*,*,*,*")
8310    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
8311
8312 \f
8313 (define_expand "movdf"
8314   [(set (match_operand:DF 0 "nonimmediate_operand" "")
8315         (match_operand:DF 1 "any_operand" ""))]
8316   ""
8317   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
8318
8319 (define_split
8320   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8321         (match_operand:DF 1 "const_int_operand" ""))]
8322   "! TARGET_POWERPC64 && reload_completed
8323    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8324        || (GET_CODE (operands[0]) == SUBREG
8325            && GET_CODE (SUBREG_REG (operands[0])) == REG
8326            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8327   [(set (match_dup 2) (match_dup 4))
8328    (set (match_dup 3) (match_dup 1))]
8329   "
8330 {
8331   int endian = (WORDS_BIG_ENDIAN == 0);
8332   HOST_WIDE_INT value = INTVAL (operands[1]);
8333
8334   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8335   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8336 #if HOST_BITS_PER_WIDE_INT == 32
8337   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8338 #else
8339   operands[4] = GEN_INT (value >> 32);
8340   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8341 #endif
8342 }")
8343
8344 (define_split
8345   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8346         (match_operand:DF 1 "const_double_operand" ""))]
8347   "! TARGET_POWERPC64 && reload_completed
8348    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8349        || (GET_CODE (operands[0]) == SUBREG
8350            && GET_CODE (SUBREG_REG (operands[0])) == REG
8351            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8352   [(set (match_dup 2) (match_dup 4))
8353    (set (match_dup 3) (match_dup 5))]
8354   "
8355 {
8356   int endian = (WORDS_BIG_ENDIAN == 0);
8357   long l[2];
8358   REAL_VALUE_TYPE rv;
8359
8360   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8361   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8362
8363   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8364   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8365   operands[4] = gen_int_mode (l[endian], SImode);
8366   operands[5] = gen_int_mode (l[1 - endian], SImode);
8367 }")
8368
8369 (define_split
8370   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8371         (match_operand:DF 1 "const_double_operand" ""))]
8372   "TARGET_POWERPC64 && reload_completed
8373    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8374        || (GET_CODE (operands[0]) == SUBREG
8375            && GET_CODE (SUBREG_REG (operands[0])) == REG
8376            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8377   [(set (match_dup 2) (match_dup 3))]
8378   "
8379 {
8380   int endian = (WORDS_BIG_ENDIAN == 0);
8381   long l[2];
8382   REAL_VALUE_TYPE rv;
8383 #if HOST_BITS_PER_WIDE_INT >= 64
8384   HOST_WIDE_INT val;
8385 #endif
8386
8387   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8388   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8389
8390   operands[2] = gen_lowpart (DImode, operands[0]);
8391   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
8392 #if HOST_BITS_PER_WIDE_INT >= 64
8393   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
8394          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
8395
8396   operands[3] = gen_int_mode (val, DImode);
8397 #else
8398   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
8399 #endif
8400 }")
8401
8402 ;; Don't have reload use general registers to load a constant.  First,
8403 ;; it might not work if the output operand is the equivalent of
8404 ;; a non-offsettable memref, but also it is less efficient than loading
8405 ;; the constant into an FP register, since it will probably be used there.
8406 ;; The "??" is a kludge until we can figure out a more reasonable way
8407 ;; of handling these non-offsettable values.
8408 (define_insn "*movdf_hardfloat32"
8409   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,f,f,m,!r,!r,!r")
8410         (match_operand:DF 1 "input_operand" "r,m,r,f,m,f,G,H,F"))]
8411   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8412    && (gpc_reg_operand (operands[0], DFmode)
8413        || gpc_reg_operand (operands[1], DFmode))"
8414   "*
8415 {
8416   switch (which_alternative)
8417     {
8418     default:
8419       gcc_unreachable ();
8420     case 0:
8421       /* We normally copy the low-numbered register first.  However, if
8422          the first register operand 0 is the same as the second register
8423          of operand 1, we must copy in the opposite order.  */
8424       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8425         return \"mr %L0,%L1\;mr %0,%1\";
8426       else
8427         return \"mr %0,%1\;mr %L0,%L1\";
8428     case 1:
8429       if (rs6000_offsettable_memref_p (operands[1])
8430           || (GET_CODE (operands[1]) == MEM
8431               && (GET_CODE (XEXP (operands[1], 0)) == LO_SUM
8432                   || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
8433                   || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC
8434                   || GET_CODE (XEXP (operands[1], 0)) == PRE_MODIFY)))
8435         {
8436           /* If the low-address word is used in the address, we must load
8437              it last.  Otherwise, load it first.  Note that we cannot have
8438              auto-increment in that case since the address register is
8439              known to be dead.  */
8440           if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8441                                  operands[1], 0))
8442             return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8443           else
8444             return \"{l%U1%X1|lwz%U1%X1} %0,%1\;{l|lwz} %L0,%L1\";
8445         }
8446       else
8447         {
8448           rtx addreg;
8449
8450           addreg = find_addr_reg (XEXP (operands[1], 0));
8451           if (refers_to_regno_p (REGNO (operands[0]),
8452                                  REGNO (operands[0]) + 1,
8453                                  operands[1], 0))
8454             {
8455               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8456               output_asm_insn (\"{l%X1|lwz%X1} %L0,%1\", operands);
8457               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8458               return \"{l%X1|lwz%X1} %0,%1\";
8459             }
8460           else
8461             {
8462               output_asm_insn (\"{l%X1|lwz%X1} %0,%1\", operands);
8463               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8464               output_asm_insn (\"{l%X1|lwz%X1} %L0,%1\", operands);
8465               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8466               return \"\";
8467             }
8468         }
8469     case 2:
8470       if (rs6000_offsettable_memref_p (operands[0])
8471           || (GET_CODE (operands[0]) == MEM
8472               && (GET_CODE (XEXP (operands[0], 0)) == LO_SUM
8473                   || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
8474                   || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
8475                   || GET_CODE (XEXP (operands[0], 0)) == PRE_MODIFY)))
8476         return \"{st%U0%X0|stw%U0%X0} %1,%0\;{st|stw} %L1,%L0\";
8477       else
8478         {
8479           rtx addreg;
8480
8481           addreg = find_addr_reg (XEXP (operands[0], 0));
8482           output_asm_insn (\"{st%X0|stw%X0} %1,%0\", operands);
8483           output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8484           output_asm_insn (\"{st%X0|stw%X0} %L1,%0\", operands);
8485           output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8486           return \"\";
8487         }
8488     case 3:
8489       return \"fmr %0,%1\";
8490     case 4:
8491       return \"lfd%U1%X1 %0,%1\";
8492     case 5:
8493       return \"stfd%U0%X0 %1,%0\";
8494     case 6:
8495     case 7:
8496     case 8:
8497       return \"#\";
8498     }
8499 }"
8500   [(set_attr "type" "two,load,store,fp,fpload,fpstore,*,*,*")
8501    (set_attr "length" "8,16,16,4,4,4,8,12,16")])
8502
8503 (define_insn "*movdf_softfloat32"
8504   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
8505         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
8506   "! TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
8507    && (gpc_reg_operand (operands[0], DFmode)
8508        || gpc_reg_operand (operands[1], DFmode))"
8509   "*
8510 {
8511   switch (which_alternative)
8512     {
8513     default:
8514       gcc_unreachable ();
8515     case 0:
8516       /* We normally copy the low-numbered register first.  However, if
8517          the first register operand 0 is the same as the second register of
8518          operand 1, we must copy in the opposite order.  */
8519       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8520         return \"mr %L0,%L1\;mr %0,%1\";
8521       else
8522         return \"mr %0,%1\;mr %L0,%L1\";
8523     case 1:
8524       /* If the low-address word is used in the address, we must load
8525          it last.  Otherwise, load it first.  Note that we cannot have
8526          auto-increment in that case since the address register is
8527          known to be dead.  */
8528       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8529                              operands[1], 0))
8530         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8531       else
8532         return \"{l%U1%X1|lwz%U1%X1} %0,%1\;{l|lwz} %L0,%L1\";
8533     case 2:
8534       return \"{st%U0%X0|stw%U0%X0} %1,%0\;{st|stw} %L1,%L0\";
8535     case 3:
8536     case 4:
8537     case 5:
8538       return \"#\";
8539     }
8540 }"
8541   [(set_attr "type" "two,load,store,*,*,*")
8542    (set_attr "length" "8,8,8,8,12,16")])
8543
8544 ; ld/std require word-aligned displacements -> 'Y' constraint.
8545 ; List Y->r and r->Y before r->r for reload.
8546 (define_insn "*movdf_hardfloat64_mfpgpr"
8547   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,f,f,m,*c*l,!r,*h,!r,!r,!r,r,f")
8548         (match_operand:DF 1 "input_operand" "r,Y,r,f,m,f,r,h,0,G,H,F,f,r"))]
8549   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
8550    && (gpc_reg_operand (operands[0], DFmode)
8551        || gpc_reg_operand (operands[1], DFmode))"
8552   "@
8553    std%U0%X0 %1,%0
8554    ld%U1%X1 %0,%1
8555    mr %0,%1
8556    fmr %0,%1
8557    lfd%U1%X1 %0,%1
8558    stfd%U0%X0 %1,%0
8559    mt%0 %1
8560    mf%1 %0
8561    {cror 0,0,0|nop}
8562    #
8563    #
8564    #
8565    mftgpr %0,%1
8566    mffgpr %0,%1"
8567   [(set_attr "type" "store,load,*,fp,fpload,fpstore,mtjmpr,mfjmpr,*,*,*,*,mftgpr,mffgpr")
8568    (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16,4,4")])
8569
8570 ; ld/std require word-aligned displacements -> 'Y' constraint.
8571 ; List Y->r and r->Y before r->r for reload.
8572 (define_insn "*movdf_hardfloat64"
8573   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,f,f,m,*c*l,!r,*h,!r,!r,!r")
8574         (match_operand:DF 1 "input_operand" "r,Y,r,f,m,f,r,h,0,G,H,F"))]
8575   "TARGET_POWERPC64 && !TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
8576    && (gpc_reg_operand (operands[0], DFmode)
8577        || gpc_reg_operand (operands[1], DFmode))"
8578   "@
8579    std%U0%X0 %1,%0
8580    ld%U1%X1 %0,%1
8581    mr %0,%1
8582    fmr %0,%1
8583    lfd%U1%X1 %0,%1
8584    stfd%U0%X0 %1,%0
8585    mt%0 %1
8586    mf%1 %0
8587    {cror 0,0,0|nop}
8588    #
8589    #
8590    #"
8591   [(set_attr "type" "store,load,*,fp,fpload,fpstore,mtjmpr,mfjmpr,*,*,*,*")
8592    (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16")])
8593
8594 (define_insn "*movdf_softfloat64"
8595   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
8596         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
8597   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8598    && (gpc_reg_operand (operands[0], DFmode)
8599        || gpc_reg_operand (operands[1], DFmode))"
8600   "@
8601    ld%U1%X1 %0,%1
8602    std%U0%X0 %1,%0
8603    mr %0,%1
8604    mt%0 %1
8605    mf%1 %0
8606    #
8607    #
8608    #
8609    {cror 0,0,0|nop}"
8610   [(set_attr "type" "load,store,*,mtjmpr,mfjmpr,*,*,*,*")
8611    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
8612 \f
8613 (define_expand "movtf"
8614   [(set (match_operand:TF 0 "general_operand" "")
8615         (match_operand:TF 1 "any_operand" ""))]
8616   "!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128"
8617   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
8618
8619 ; It's important to list the o->f and f->o moves before f->f because
8620 ; otherwise reload, given m->f, will try to pick f->f and reload it,
8621 ; which doesn't make progress.  Likewise r->Y must be before r->r.
8622 (define_insn_and_split "*movtf_internal"
8623   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,f,r,Y,r")
8624         (match_operand:TF 1 "input_operand"         "f,o,f,YGHF,r,r"))]
8625   "!TARGET_IEEEQUAD
8626    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
8627    && (gpc_reg_operand (operands[0], TFmode)
8628        || gpc_reg_operand (operands[1], TFmode))"
8629   "#"
8630   "&& reload_completed"
8631   [(pc)]
8632 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8633   [(set_attr "length" "8,8,8,20,20,16")])
8634
8635 (define_insn_and_split "*movtf_softfloat"
8636   [(set (match_operand:TF 0 "rs6000_nonimmediate_operand" "=r,Y,r")
8637         (match_operand:TF 1 "input_operand"         "YGHF,r,r"))]
8638   "!TARGET_IEEEQUAD
8639    && (TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_LONG_DOUBLE_128
8640    && (gpc_reg_operand (operands[0], TFmode)
8641        || gpc_reg_operand (operands[1], TFmode))"
8642   "#"
8643   "&& reload_completed"
8644   [(pc)]
8645 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8646   [(set_attr "length" "20,20,16")])
8647
8648 (define_expand "extenddftf2"
8649   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8650         (float_extend:TF (match_operand:DF 1 "input_operand" "")))]
8651   "!TARGET_IEEEQUAD
8652    && TARGET_HARD_FLOAT
8653    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8654    && TARGET_LONG_DOUBLE_128"
8655 {
8656   if (TARGET_E500_DOUBLE)
8657     emit_insn (gen_spe_extenddftf2 (operands[0], operands[1]));
8658   else
8659     emit_insn (gen_extenddftf2_fprs (operands[0], operands[1]));
8660   DONE;
8661 })
8662
8663 (define_expand "extenddftf2_fprs"
8664   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
8665                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
8666               (use (match_dup 2))])]
8667   "!TARGET_IEEEQUAD
8668    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8669 {
8670   operands[2] = CONST0_RTX (DFmode);
8671   /* Generate GOT reference early for SVR4 PIC.  */
8672   if (DEFAULT_ABI == ABI_V4 && flag_pic)
8673     operands[2] = validize_mem (force_const_mem (DFmode, operands[2]));
8674 })
8675
8676 (define_insn_and_split "*extenddftf2_internal"
8677   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,&f,r")
8678        (float_extend:TF (match_operand:DF 1 "input_operand" "fr,mf,mf,rmGHF")))
8679    (use (match_operand:DF 2 "zero_reg_mem_operand" "rf,m,f,n"))]
8680   "!TARGET_IEEEQUAD
8681    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8682   "#"
8683   "&& reload_completed"
8684   [(pc)]
8685 {
8686   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8687   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8688   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
8689                   operands[1]);
8690   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
8691                   operands[2]);
8692   DONE;
8693 })
8694
8695 (define_expand "extendsftf2"
8696   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8697         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
8698   "!TARGET_IEEEQUAD
8699    && TARGET_HARD_FLOAT
8700    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8701    && TARGET_LONG_DOUBLE_128"
8702 {
8703   rtx tmp = gen_reg_rtx (DFmode);
8704   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
8705   emit_insn (gen_extenddftf2 (operands[0], tmp));
8706   DONE;
8707 })
8708
8709 (define_expand "trunctfdf2"
8710   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8711         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
8712   "!TARGET_IEEEQUAD
8713    && TARGET_HARD_FLOAT
8714    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8715    && TARGET_LONG_DOUBLE_128"
8716   "")
8717
8718 (define_insn_and_split "trunctfdf2_internal1"
8719   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f")
8720         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,f")))]
8721   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
8722    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8723   "@
8724    #
8725    fmr %0,%1"
8726   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
8727   [(const_int 0)]
8728 {
8729   emit_note (NOTE_INSN_DELETED);
8730   DONE;
8731 }
8732   [(set_attr "type" "fp")])
8733
8734 (define_insn "trunctfdf2_internal2"
8735   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8736         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8737   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
8738    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8739   "fadd %0,%1,%L1"
8740   [(set_attr "type" "fp")])
8741
8742 (define_expand "trunctfsf2"
8743   [(set (match_operand:SF 0 "gpc_reg_operand" "")
8744         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "")))]
8745   "!TARGET_IEEEQUAD
8746    && TARGET_HARD_FLOAT
8747    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8748    && TARGET_LONG_DOUBLE_128"
8749 {
8750   if (TARGET_E500_DOUBLE)
8751     emit_insn (gen_spe_trunctfsf2 (operands[0], operands[1]));
8752   else
8753     emit_insn (gen_trunctfsf2_fprs (operands[0], operands[1]));
8754   DONE;
8755 })
8756
8757 (define_insn_and_split "trunctfsf2_fprs"
8758   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8759         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "f")))
8760    (clobber (match_scratch:DF 2 "=f"))]
8761   "!TARGET_IEEEQUAD
8762    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8763   "#"
8764   "&& reload_completed"
8765   [(set (match_dup 2)
8766         (float_truncate:DF (match_dup 1)))
8767    (set (match_dup 0)
8768         (float_truncate:SF (match_dup 2)))]
8769   "")
8770
8771 (define_expand "floatsitf2"
8772   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8773         (float:TF (match_operand:SI 1 "gpc_reg_operand" "")))]
8774   "!TARGET_IEEEQUAD
8775    && TARGET_HARD_FLOAT
8776    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8777    && TARGET_LONG_DOUBLE_128"
8778 {
8779   rtx tmp = gen_reg_rtx (DFmode);
8780   expand_float (tmp, operands[1], false);
8781   emit_insn (gen_extenddftf2 (operands[0], tmp));
8782   DONE;
8783 })
8784
8785 ; fadd, but rounding towards zero.
8786 ; This is probably not the optimal code sequence.
8787 (define_insn "fix_trunc_helper"
8788   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8789         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "f")]
8790                    UNSPEC_FIX_TRUNC_TF))
8791    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&f"))]
8792   "TARGET_HARD_FLOAT && TARGET_FPRS"
8793   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
8794   [(set_attr "type" "fp")
8795    (set_attr "length" "20")])
8796
8797 (define_expand "fix_trunctfsi2"
8798   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8799         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))]
8800   "!TARGET_IEEEQUAD
8801    && (TARGET_POWER2 || TARGET_POWERPC)
8802    && TARGET_HARD_FLOAT
8803    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8804    && TARGET_LONG_DOUBLE_128"
8805 {
8806   if (TARGET_E500_DOUBLE)
8807     emit_insn (gen_spe_fix_trunctfsi2 (operands[0], operands[1]));
8808   else
8809     emit_insn (gen_fix_trunctfsi2_fprs (operands[0], operands[1]));
8810   DONE;
8811 })
8812
8813 (define_expand "fix_trunctfsi2_fprs"
8814   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
8815                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
8816               (clobber (match_dup 2))
8817               (clobber (match_dup 3))
8818               (clobber (match_dup 4))
8819               (clobber (match_dup 5))])]
8820   "!TARGET_IEEEQUAD
8821    && (TARGET_POWER2 || TARGET_POWERPC)
8822    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8823 {
8824   operands[2] = gen_reg_rtx (DFmode);
8825   operands[3] = gen_reg_rtx (DFmode);
8826   operands[4] = gen_reg_rtx (DImode);
8827   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
8828 })
8829
8830 (define_insn_and_split "*fix_trunctfsi2_internal"
8831   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8832         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "f")))
8833    (clobber (match_operand:DF 2 "gpc_reg_operand" "=f"))
8834    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&f"))
8835    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))
8836    (clobber (match_operand:DI 5 "offsettable_mem_operand" "=o"))]
8837   "!TARGET_IEEEQUAD
8838    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8839   "#"
8840   "&& (can_create_pseudo_p () || offsettable_nonstrict_memref_p (operands[5]))"
8841   [(pc)]
8842 {
8843   rtx lowword;
8844   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
8845
8846   gcc_assert (MEM_P (operands[5]));
8847   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
8848
8849   emit_insn (gen_fctiwz (operands[4], operands[2]));
8850   emit_move_insn (operands[5], operands[4]);
8851   emit_move_insn (operands[0], lowword);
8852   DONE;
8853 })
8854
8855 (define_expand "negtf2"
8856   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8857         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
8858   "!TARGET_IEEEQUAD
8859    && TARGET_HARD_FLOAT
8860    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8861    && TARGET_LONG_DOUBLE_128"
8862   "")
8863
8864 (define_insn "negtf2_internal"
8865   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8866         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8867   "!TARGET_IEEEQUAD
8868    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8869   "*
8870 {
8871   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8872     return \"fneg %L0,%L1\;fneg %0,%1\";
8873   else
8874     return \"fneg %0,%1\;fneg %L0,%L1\";
8875 }"
8876   [(set_attr "type" "fp")
8877    (set_attr "length" "8")])
8878
8879 (define_expand "abstf2"
8880   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8881         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "")))]
8882   "!TARGET_IEEEQUAD
8883    && TARGET_HARD_FLOAT
8884    && (TARGET_FPRS || TARGET_E500_DOUBLE)
8885    && TARGET_LONG_DOUBLE_128"
8886   "
8887 {
8888   rtx label = gen_label_rtx ();
8889   if (TARGET_E500_DOUBLE)
8890     {
8891       if (flag_unsafe_math_optimizations)
8892         emit_insn (gen_spe_abstf2_tst (operands[0], operands[1], label));
8893       else
8894         emit_insn (gen_spe_abstf2_cmp (operands[0], operands[1], label));
8895     }
8896   else
8897     emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
8898   emit_label (label);
8899   DONE;
8900 }")
8901
8902 (define_expand "abstf2_internal"
8903   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8904         (match_operand:TF 1 "gpc_reg_operand" ""))
8905    (set (match_dup 3) (match_dup 5))
8906    (set (match_dup 5) (abs:DF (match_dup 5)))
8907    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
8908    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
8909                            (label_ref (match_operand 2 "" ""))
8910                            (pc)))
8911    (set (match_dup 6) (neg:DF (match_dup 6)))]
8912   "!TARGET_IEEEQUAD
8913    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8914   "
8915 {
8916   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8917   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8918   operands[3] = gen_reg_rtx (DFmode);
8919   operands[4] = gen_reg_rtx (CCFPmode);
8920   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
8921   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
8922 }")
8923 \f
8924 ;; Next come the multi-word integer load and store and the load and store
8925 ;; multiple insns.
8926
8927 ; List r->r after r->"o<>", otherwise reload will try to reload a
8928 ; non-offsettable address by using r->r which won't make progress.
8929 (define_insn "*movdi_internal32"
8930   [(set (match_operand:DI 0 "rs6000_nonimmediate_operand" "=o<>,r,r,*f,*f,m,r")
8931         (match_operand:DI 1 "input_operand" "r,r,m,f,m,f,IJKnGHF"))]
8932   "! TARGET_POWERPC64
8933    && (gpc_reg_operand (operands[0], DImode)
8934        || gpc_reg_operand (operands[1], DImode))"
8935   "@
8936    #
8937    #
8938    #
8939    fmr %0,%1
8940    lfd%U1%X1 %0,%1
8941    stfd%U0%X0 %1,%0
8942    #"
8943   [(set_attr "type" "load,*,store,fp,fpload,fpstore,*")])
8944
8945 (define_split
8946   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8947         (match_operand:DI 1 "const_int_operand" ""))]
8948   "! TARGET_POWERPC64 && reload_completed"
8949   [(set (match_dup 2) (match_dup 4))
8950    (set (match_dup 3) (match_dup 1))]
8951   "
8952 {
8953   HOST_WIDE_INT value = INTVAL (operands[1]);
8954   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8955                                        DImode);
8956   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8957                                        DImode);
8958 #if HOST_BITS_PER_WIDE_INT == 32
8959   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8960 #else
8961   operands[4] = GEN_INT (value >> 32);
8962   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8963 #endif
8964 }")
8965
8966 (define_split
8967   [(set (match_operand:DI 0 "rs6000_nonimmediate_operand" "")
8968         (match_operand:DI 1 "input_operand" ""))]
8969   "reload_completed && !TARGET_POWERPC64
8970    && gpr_or_gpr_p (operands[0], operands[1])"
8971   [(pc)]
8972 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8973
8974 (define_insn "*movdi_mfpgpr"
8975   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*f,*f,m,r,*h,*h,r,*f")
8976         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,f,m,f,*h,r,0,*f,r"))]
8977   "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
8978    && (gpc_reg_operand (operands[0], DImode)
8979        || gpc_reg_operand (operands[1], DImode))"
8980   "@
8981    mr %0,%1
8982    ld%U1%X1 %0,%1
8983    std%U0%X0 %1,%0
8984    li %0,%1
8985    lis %0,%v1
8986    #
8987    {cal|la} %0,%a1
8988    fmr %0,%1
8989    lfd%U1%X1 %0,%1
8990    stfd%U0%X0 %1,%0
8991    mf%1 %0
8992    mt%0 %1
8993    {cror 0,0,0|nop}
8994    mftgpr %0,%1
8995    mffgpr %0,%1"
8996   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*,mftgpr,mffgpr")
8997    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4,4,4")])
8998
8999 (define_insn "*movdi_internal64"
9000   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*f,*f,m,r,*h,*h")
9001         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,f,m,f,*h,r,0"))]
9002   "TARGET_POWERPC64 && (!TARGET_MFPGPR || !TARGET_HARD_FLOAT || !TARGET_FPRS)
9003    && (gpc_reg_operand (operands[0], DImode)
9004        || gpc_reg_operand (operands[1], DImode))"
9005   "@
9006    mr %0,%1
9007    ld%U1%X1 %0,%1
9008    std%U0%X0 %1,%0
9009    li %0,%1
9010    lis %0,%v1
9011    #
9012    {cal|la} %0,%a1
9013    fmr %0,%1
9014    lfd%U1%X1 %0,%1
9015    stfd%U0%X0 %1,%0
9016    mf%1 %0
9017    mt%0 %1
9018    {cror 0,0,0|nop}"
9019   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
9020    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
9021
9022 ;; immediate value valid for a single instruction hiding in a const_double
9023 (define_insn ""
9024   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9025         (match_operand:DI 1 "const_double_operand" "F"))]
9026   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
9027    && GET_CODE (operands[1]) == CONST_DOUBLE
9028    && num_insns_constant (operands[1], DImode) == 1"
9029   "*
9030 {
9031   return ((unsigned HOST_WIDE_INT)
9032           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
9033          ? \"li %0,%1\" : \"lis %0,%v1\";
9034 }")
9035
9036 ;; Generate all one-bits and clear left or right.
9037 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
9038 (define_split
9039   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9040         (match_operand:DI 1 "mask64_operand" ""))]
9041   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9042   [(set (match_dup 0) (const_int -1))
9043    (set (match_dup 0)
9044         (and:DI (rotate:DI (match_dup 0)
9045                            (const_int 0))
9046                 (match_dup 1)))]
9047   "")
9048
9049 ;; Split a load of a large constant into the appropriate five-instruction
9050 ;; sequence.  Handle anything in a constant number of insns.
9051 ;; When non-easy constants can go in the TOC, this should use
9052 ;; easy_fp_constant predicate.
9053 (define_split
9054   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9055         (match_operand:DI 1 "const_int_operand" ""))]
9056   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9057   [(set (match_dup 0) (match_dup 2))
9058    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
9059   "
9060 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
9061
9062   if (tem == operands[0])
9063     DONE;
9064   else
9065     FAIL;
9066 }")
9067
9068 (define_split
9069   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9070         (match_operand:DI 1 "const_double_operand" ""))]
9071   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9072   [(set (match_dup 0) (match_dup 2))
9073    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
9074   "
9075 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
9076
9077   if (tem == operands[0])
9078     DONE;
9079   else
9080     FAIL;
9081 }")
9082 \f
9083 ;; TImode is similar, except that we usually want to compute the address into
9084 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
9085 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
9086
9087 ;; We say that MQ is clobbered in the last alternative because the first
9088 ;; alternative would never get used otherwise since it would need a reload
9089 ;; while the 2nd alternative would not.  We put memory cases first so they
9090 ;; are preferred.  Otherwise, we'd try to reload the output instead of
9091 ;; giving the SCRATCH mq.
9092
9093 (define_insn "*movti_power"
9094   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r,r")
9095         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))
9096    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X,X"))]
9097   "TARGET_POWER && ! TARGET_POWERPC64
9098    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
9099   "*
9100 {
9101   switch (which_alternative)
9102     {
9103     default:
9104       gcc_unreachable ();
9105
9106     case 0:
9107       if (TARGET_STRING)
9108         return \"{stsi|stswi} %1,%P0,16\";
9109     case 1:
9110     case 2:
9111       return \"#\";
9112     case 3:
9113       /* If the address is not used in the output, we can use lsi.  Otherwise,
9114          fall through to generating four loads.  */
9115       if (TARGET_STRING
9116           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
9117         return \"{lsi|lswi} %0,%P1,16\";
9118       /* ... fall through ...  */
9119     case 4:
9120     case 5:
9121       return \"#\";
9122     }
9123 }"
9124   [(set_attr "type" "store,store,*,load,load,*")])
9125
9126 (define_insn "*movti_string"
9127   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,o<>,????r,????r,????r,r")
9128         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))]
9129   "! TARGET_POWER && ! TARGET_POWERPC64
9130    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
9131   "*
9132 {
9133   switch (which_alternative)
9134     {
9135     default:
9136       gcc_unreachable ();
9137     case 0:
9138       if (TARGET_STRING)
9139         return \"{stsi|stswi} %1,%P0,16\";
9140     case 1:
9141     case 2:
9142       return \"#\";
9143     case 3:
9144       /* If the address is not used in the output, we can use lsi.  Otherwise,
9145          fall through to generating four loads.  */
9146       if (TARGET_STRING
9147           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
9148         return \"{lsi|lswi} %0,%P1,16\";
9149       /* ... fall through ...  */
9150     case 4:
9151     case 5:
9152       return \"#\";
9153     }
9154 }"
9155   [(set_attr "type" "store_ux,store_ux,*,load_ux,load_ux,*")])
9156
9157 (define_insn "*movti_ppc64"
9158   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,o<>,r")
9159         (match_operand:TI 1 "input_operand" "r,r,m"))]
9160   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
9161    || gpc_reg_operand (operands[1], TImode))"
9162   "#"
9163   [(set_attr "type" "*,load,store")])
9164
9165 (define_split
9166   [(set (match_operand:TI 0 "gpc_reg_operand" "")
9167         (match_operand:TI 1 "const_double_operand" ""))]
9168   "TARGET_POWERPC64"
9169   [(set (match_dup 2) (match_dup 4))
9170    (set (match_dup 3) (match_dup 5))]
9171   "
9172 {
9173   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
9174                                        TImode);
9175   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
9176                                        TImode);
9177   if (GET_CODE (operands[1]) == CONST_DOUBLE)
9178     {
9179       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
9180       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
9181     }
9182   else if (GET_CODE (operands[1]) == CONST_INT)
9183     {
9184       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
9185       operands[5] = operands[1];
9186     }
9187   else
9188     FAIL;
9189 }")
9190
9191 (define_split
9192   [(set (match_operand:TI 0 "nonimmediate_operand" "")
9193         (match_operand:TI 1 "input_operand" ""))]
9194   "reload_completed
9195    && gpr_or_gpr_p (operands[0], operands[1])"
9196   [(pc)]
9197 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
9198 \f
9199 (define_expand "load_multiple"
9200   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
9201                           (match_operand:SI 1 "" ""))
9202                      (use (match_operand:SI 2 "" ""))])]
9203   "TARGET_STRING && !TARGET_POWERPC64"
9204   "
9205 {
9206   int regno;
9207   int count;
9208   rtx op1;
9209   int i;
9210
9211   /* Support only loading a constant number of fixed-point registers from
9212      memory and only bother with this if more than two; the machine
9213      doesn't support more than eight.  */
9214   if (GET_CODE (operands[2]) != CONST_INT
9215       || INTVAL (operands[2]) <= 2
9216       || INTVAL (operands[2]) > 8
9217       || GET_CODE (operands[1]) != MEM
9218       || GET_CODE (operands[0]) != REG
9219       || REGNO (operands[0]) >= 32)
9220     FAIL;
9221
9222   count = INTVAL (operands[2]);
9223   regno = REGNO (operands[0]);
9224
9225   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
9226   op1 = replace_equiv_address (operands[1],
9227                                force_reg (SImode, XEXP (operands[1], 0)));
9228
9229   for (i = 0; i < count; i++)
9230     XVECEXP (operands[3], 0, i)
9231       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
9232                      adjust_address_nv (op1, SImode, i * 4));
9233 }")
9234
9235 (define_insn "*ldmsi8"
9236   [(match_parallel 0 "load_multiple_operation"
9237     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9238           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9239      (set (match_operand:SI 3 "gpc_reg_operand" "")
9240           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9241      (set (match_operand:SI 4 "gpc_reg_operand" "")
9242           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9243      (set (match_operand:SI 5 "gpc_reg_operand" "")
9244           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
9245      (set (match_operand:SI 6 "gpc_reg_operand" "")
9246           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
9247      (set (match_operand:SI 7 "gpc_reg_operand" "")
9248           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
9249      (set (match_operand:SI 8 "gpc_reg_operand" "")
9250           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
9251      (set (match_operand:SI 9 "gpc_reg_operand" "")
9252           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
9253   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
9254   "*
9255 { return rs6000_output_load_multiple (operands); }"
9256   [(set_attr "type" "load_ux")
9257    (set_attr "length" "32")])
9258
9259 (define_insn "*ldmsi7"
9260   [(match_parallel 0 "load_multiple_operation"
9261     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9262           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9263      (set (match_operand:SI 3 "gpc_reg_operand" "")
9264           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9265      (set (match_operand:SI 4 "gpc_reg_operand" "")
9266           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9267      (set (match_operand:SI 5 "gpc_reg_operand" "")
9268           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
9269      (set (match_operand:SI 6 "gpc_reg_operand" "")
9270           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
9271      (set (match_operand:SI 7 "gpc_reg_operand" "")
9272           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
9273      (set (match_operand:SI 8 "gpc_reg_operand" "")
9274           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
9275   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
9276   "*
9277 { return rs6000_output_load_multiple (operands); }"
9278   [(set_attr "type" "load_ux")
9279    (set_attr "length" "32")])
9280
9281 (define_insn "*ldmsi6"
9282   [(match_parallel 0 "load_multiple_operation"
9283     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9284           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9285      (set (match_operand:SI 3 "gpc_reg_operand" "")
9286           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9287      (set (match_operand:SI 4 "gpc_reg_operand" "")
9288           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9289      (set (match_operand:SI 5 "gpc_reg_operand" "")
9290           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
9291      (set (match_operand:SI 6 "gpc_reg_operand" "")
9292           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
9293      (set (match_operand:SI 7 "gpc_reg_operand" "")
9294           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
9295   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
9296   "*
9297 { return rs6000_output_load_multiple (operands); }"
9298   [(set_attr "type" "load_ux")
9299    (set_attr "length" "32")])
9300
9301 (define_insn "*ldmsi5"
9302   [(match_parallel 0 "load_multiple_operation"
9303     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9304           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9305      (set (match_operand:SI 3 "gpc_reg_operand" "")
9306           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9307      (set (match_operand:SI 4 "gpc_reg_operand" "")
9308           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9309      (set (match_operand:SI 5 "gpc_reg_operand" "")
9310           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
9311      (set (match_operand:SI 6 "gpc_reg_operand" "")
9312           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
9313   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
9314   "*
9315 { return rs6000_output_load_multiple (operands); }"
9316   [(set_attr "type" "load_ux")
9317    (set_attr "length" "32")])
9318
9319 (define_insn "*ldmsi4"
9320   [(match_parallel 0 "load_multiple_operation"
9321     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9322           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9323      (set (match_operand:SI 3 "gpc_reg_operand" "")
9324           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9325      (set (match_operand:SI 4 "gpc_reg_operand" "")
9326           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
9327      (set (match_operand:SI 5 "gpc_reg_operand" "")
9328           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
9329   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
9330   "*
9331 { return rs6000_output_load_multiple (operands); }"
9332   [(set_attr "type" "load_ux")
9333    (set_attr "length" "32")])
9334
9335 (define_insn "*ldmsi3"
9336   [(match_parallel 0 "load_multiple_operation"
9337     [(set (match_operand:SI 2 "gpc_reg_operand" "")
9338           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
9339      (set (match_operand:SI 3 "gpc_reg_operand" "")
9340           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
9341      (set (match_operand:SI 4 "gpc_reg_operand" "")
9342           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
9343   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
9344   "*
9345 { return rs6000_output_load_multiple (operands); }"
9346   [(set_attr "type" "load_ux")
9347    (set_attr "length" "32")])
9348
9349 (define_expand "store_multiple"
9350   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
9351                           (match_operand:SI 1 "" ""))
9352                      (clobber (scratch:SI))
9353                      (use (match_operand:SI 2 "" ""))])]
9354   "TARGET_STRING && !TARGET_POWERPC64"
9355   "
9356 {
9357   int regno;
9358   int count;
9359   rtx to;
9360   rtx op0;
9361   int i;
9362
9363   /* Support only storing a constant number of fixed-point registers to
9364      memory and only bother with this if more than two; the machine
9365      doesn't support more than eight.  */
9366   if (GET_CODE (operands[2]) != CONST_INT
9367       || INTVAL (operands[2]) <= 2
9368       || INTVAL (operands[2]) > 8
9369       || GET_CODE (operands[0]) != MEM
9370       || GET_CODE (operands[1]) != REG
9371       || REGNO (operands[1]) >= 32)
9372     FAIL;
9373
9374   count = INTVAL (operands[2]);
9375   regno = REGNO (operands[1]);
9376
9377   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
9378   to = force_reg (SImode, XEXP (operands[0], 0));
9379   op0 = replace_equiv_address (operands[0], to);
9380
9381   XVECEXP (operands[3], 0, 0)
9382     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
9383   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
9384                                                  gen_rtx_SCRATCH (SImode));
9385
9386   for (i = 1; i < count; i++)
9387     XVECEXP (operands[3], 0, i + 1)
9388       = gen_rtx_SET (VOIDmode,
9389                      adjust_address_nv (op0, SImode, i * 4),
9390                      gen_rtx_REG (SImode, regno + i));
9391 }")
9392
9393 (define_insn "*stmsi8"
9394   [(match_parallel 0 "store_multiple_operation"
9395     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9396           (match_operand:SI 2 "gpc_reg_operand" "r"))
9397      (clobber (match_scratch:SI 3 "=X"))
9398      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9399           (match_operand:SI 4 "gpc_reg_operand" "r"))
9400      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9401           (match_operand:SI 5 "gpc_reg_operand" "r"))
9402      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9403           (match_operand:SI 6 "gpc_reg_operand" "r"))
9404      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9405           (match_operand:SI 7 "gpc_reg_operand" "r"))
9406      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9407           (match_operand:SI 8 "gpc_reg_operand" "r"))
9408      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9409           (match_operand:SI 9 "gpc_reg_operand" "r"))
9410      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
9411           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
9412   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
9413   "{stsi|stswi} %2,%1,%O0"
9414   [(set_attr "type" "store_ux")])
9415
9416 (define_insn "*stmsi7"
9417   [(match_parallel 0 "store_multiple_operation"
9418     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9419           (match_operand:SI 2 "gpc_reg_operand" "r"))
9420      (clobber (match_scratch:SI 3 "=X"))
9421      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9422           (match_operand:SI 4 "gpc_reg_operand" "r"))
9423      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9424           (match_operand:SI 5 "gpc_reg_operand" "r"))
9425      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9426           (match_operand:SI 6 "gpc_reg_operand" "r"))
9427      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9428           (match_operand:SI 7 "gpc_reg_operand" "r"))
9429      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9430           (match_operand:SI 8 "gpc_reg_operand" "r"))
9431      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9432           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
9433   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
9434   "{stsi|stswi} %2,%1,%O0"
9435   [(set_attr "type" "store_ux")])
9436
9437 (define_insn "*stmsi6"
9438   [(match_parallel 0 "store_multiple_operation"
9439     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9440           (match_operand:SI 2 "gpc_reg_operand" "r"))
9441      (clobber (match_scratch:SI 3 "=X"))
9442      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9443           (match_operand:SI 4 "gpc_reg_operand" "r"))
9444      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9445           (match_operand:SI 5 "gpc_reg_operand" "r"))
9446      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9447           (match_operand:SI 6 "gpc_reg_operand" "r"))
9448      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9449           (match_operand:SI 7 "gpc_reg_operand" "r"))
9450      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9451           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
9452   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
9453   "{stsi|stswi} %2,%1,%O0"
9454   [(set_attr "type" "store_ux")])
9455
9456 (define_insn "*stmsi5"
9457   [(match_parallel 0 "store_multiple_operation"
9458     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9459           (match_operand:SI 2 "gpc_reg_operand" "r"))
9460      (clobber (match_scratch:SI 3 "=X"))
9461      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9462           (match_operand:SI 4 "gpc_reg_operand" "r"))
9463      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9464           (match_operand:SI 5 "gpc_reg_operand" "r"))
9465      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9466           (match_operand:SI 6 "gpc_reg_operand" "r"))
9467      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9468           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
9469   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
9470   "{stsi|stswi} %2,%1,%O0"
9471   [(set_attr "type" "store_ux")])
9472
9473 (define_insn "*stmsi4"
9474   [(match_parallel 0 "store_multiple_operation"
9475     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9476           (match_operand:SI 2 "gpc_reg_operand" "r"))
9477      (clobber (match_scratch:SI 3 "=X"))
9478      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9479           (match_operand:SI 4 "gpc_reg_operand" "r"))
9480      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9481           (match_operand:SI 5 "gpc_reg_operand" "r"))
9482      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9483           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9484   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
9485   "{stsi|stswi} %2,%1,%O0"
9486   [(set_attr "type" "store_ux")])
9487
9488 (define_insn "*stmsi3"
9489   [(match_parallel 0 "store_multiple_operation"
9490     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9491           (match_operand:SI 2 "gpc_reg_operand" "r"))
9492      (clobber (match_scratch:SI 3 "=X"))
9493      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9494           (match_operand:SI 4 "gpc_reg_operand" "r"))
9495      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9496           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9497   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
9498   "{stsi|stswi} %2,%1,%O0"
9499   [(set_attr "type" "store_ux")])
9500
9501 (define_insn "*stmsi8_power"
9502   [(match_parallel 0 "store_multiple_operation"
9503     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9504           (match_operand:SI 2 "gpc_reg_operand" "r"))
9505      (clobber (match_scratch:SI 3 "=q"))
9506      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9507           (match_operand:SI 4 "gpc_reg_operand" "r"))
9508      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9509           (match_operand:SI 5 "gpc_reg_operand" "r"))
9510      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9511           (match_operand:SI 6 "gpc_reg_operand" "r"))
9512      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9513           (match_operand:SI 7 "gpc_reg_operand" "r"))
9514      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9515           (match_operand:SI 8 "gpc_reg_operand" "r"))
9516      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9517           (match_operand:SI 9 "gpc_reg_operand" "r"))
9518      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
9519           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
9520   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 9"
9521   "{stsi|stswi} %2,%1,%O0"
9522   [(set_attr "type" "store_ux")])
9523
9524 (define_insn "*stmsi7_power"
9525   [(match_parallel 0 "store_multiple_operation"
9526     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9527           (match_operand:SI 2 "gpc_reg_operand" "r"))
9528      (clobber (match_scratch:SI 3 "=q"))
9529      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9530           (match_operand:SI 4 "gpc_reg_operand" "r"))
9531      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9532           (match_operand:SI 5 "gpc_reg_operand" "r"))
9533      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9534           (match_operand:SI 6 "gpc_reg_operand" "r"))
9535      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9536           (match_operand:SI 7 "gpc_reg_operand" "r"))
9537      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9538           (match_operand:SI 8 "gpc_reg_operand" "r"))
9539      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9540           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
9541   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 8"
9542   "{stsi|stswi} %2,%1,%O0"
9543   [(set_attr "type" "store_ux")])
9544
9545 (define_insn "*stmsi6_power"
9546   [(match_parallel 0 "store_multiple_operation"
9547     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9548           (match_operand:SI 2 "gpc_reg_operand" "r"))
9549      (clobber (match_scratch:SI 3 "=q"))
9550      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9551           (match_operand:SI 4 "gpc_reg_operand" "r"))
9552      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9553           (match_operand:SI 5 "gpc_reg_operand" "r"))
9554      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9555           (match_operand:SI 6 "gpc_reg_operand" "r"))
9556      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9557           (match_operand:SI 7 "gpc_reg_operand" "r"))
9558      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9559           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
9560   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 7"
9561   "{stsi|stswi} %2,%1,%O0"
9562   [(set_attr "type" "store_ux")])
9563
9564 (define_insn "*stmsi5_power"
9565   [(match_parallel 0 "store_multiple_operation"
9566     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9567           (match_operand:SI 2 "gpc_reg_operand" "r"))
9568      (clobber (match_scratch:SI 3 "=q"))
9569      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9570           (match_operand:SI 4 "gpc_reg_operand" "r"))
9571      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9572           (match_operand:SI 5 "gpc_reg_operand" "r"))
9573      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9574           (match_operand:SI 6 "gpc_reg_operand" "r"))
9575      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9576           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
9577   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 6"
9578   "{stsi|stswi} %2,%1,%O0"
9579   [(set_attr "type" "store_ux")])
9580
9581 (define_insn "*stmsi4_power"
9582   [(match_parallel 0 "store_multiple_operation"
9583     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9584           (match_operand:SI 2 "gpc_reg_operand" "r"))
9585      (clobber (match_scratch:SI 3 "=q"))
9586      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9587           (match_operand:SI 4 "gpc_reg_operand" "r"))
9588      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9589           (match_operand:SI 5 "gpc_reg_operand" "r"))
9590      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9591           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9592   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 5"
9593   "{stsi|stswi} %2,%1,%O0"
9594   [(set_attr "type" "store_ux")])
9595
9596 (define_insn "*stmsi3_power"
9597   [(match_parallel 0 "store_multiple_operation"
9598     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9599           (match_operand:SI 2 "gpc_reg_operand" "r"))
9600      (clobber (match_scratch:SI 3 "=q"))
9601      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9602           (match_operand:SI 4 "gpc_reg_operand" "r"))
9603      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9604           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9605   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 4"
9606   "{stsi|stswi} %2,%1,%O0"
9607   [(set_attr "type" "store_ux")])
9608 \f
9609 (define_expand "setmemsi"
9610   [(parallel [(set (match_operand:BLK 0 "" "")
9611                    (match_operand 2 "const_int_operand" ""))
9612               (use (match_operand:SI 1 "" ""))
9613               (use (match_operand:SI 3 "" ""))])]
9614   ""
9615   "
9616 {
9617   /* If value to set is not zero, use the library routine.  */
9618   if (operands[2] != const0_rtx)
9619     FAIL;
9620
9621   if (expand_block_clear (operands))
9622     DONE;
9623   else
9624     FAIL;
9625 }")
9626
9627 ;; String/block move insn.
9628 ;; Argument 0 is the destination
9629 ;; Argument 1 is the source
9630 ;; Argument 2 is the length
9631 ;; Argument 3 is the alignment
9632
9633 (define_expand "movmemsi"
9634   [(parallel [(set (match_operand:BLK 0 "" "")
9635                    (match_operand:BLK 1 "" ""))
9636               (use (match_operand:SI 2 "" ""))
9637               (use (match_operand:SI 3 "" ""))])]
9638   ""
9639   "
9640 {
9641   if (expand_block_move (operands))
9642     DONE;
9643   else
9644     FAIL;
9645 }")
9646
9647 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
9648 ;; register allocator doesn't have a clue about allocating 8 word registers.
9649 ;; rD/rS = r5 is preferred, efficient form.
9650 (define_expand "movmemsi_8reg"
9651   [(parallel [(set (match_operand 0 "" "")
9652                    (match_operand 1 "" ""))
9653               (use (match_operand 2 "" ""))
9654               (use (match_operand 3 "" ""))
9655               (clobber (reg:SI  5))
9656               (clobber (reg:SI  6))
9657               (clobber (reg:SI  7))
9658               (clobber (reg:SI  8))
9659               (clobber (reg:SI  9))
9660               (clobber (reg:SI 10))
9661               (clobber (reg:SI 11))
9662               (clobber (reg:SI 12))
9663               (clobber (match_scratch:SI 4 ""))])]
9664   "TARGET_STRING"
9665   "")
9666
9667 (define_insn ""
9668   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9669         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9670    (use (match_operand:SI 2 "immediate_operand" "i"))
9671    (use (match_operand:SI 3 "immediate_operand" "i"))
9672    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9673    (clobber (reg:SI  6))
9674    (clobber (reg:SI  7))
9675    (clobber (reg:SI  8))
9676    (clobber (reg:SI  9))
9677    (clobber (reg:SI 10))
9678    (clobber (reg:SI 11))
9679    (clobber (reg:SI 12))
9680    (clobber (match_scratch:SI 5 "=q"))]
9681   "TARGET_STRING && TARGET_POWER
9682    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9683        || INTVAL (operands[2]) == 0)
9684    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9685    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9686    && REGNO (operands[4]) == 5"
9687   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9688   [(set_attr "type" "store_ux")
9689    (set_attr "length" "8")])
9690
9691 (define_insn ""
9692   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9693         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9694    (use (match_operand:SI 2 "immediate_operand" "i"))
9695    (use (match_operand:SI 3 "immediate_operand" "i"))
9696    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9697    (clobber (reg:SI  6))
9698    (clobber (reg:SI  7))
9699    (clobber (reg:SI  8))
9700    (clobber (reg:SI  9))
9701    (clobber (reg:SI 10))
9702    (clobber (reg:SI 11))
9703    (clobber (reg:SI 12))
9704    (clobber (match_scratch:SI 5 "=X"))]
9705   "TARGET_STRING && ! TARGET_POWER
9706    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9707        || INTVAL (operands[2]) == 0)
9708    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9709    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9710    && REGNO (operands[4]) == 5"
9711   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9712   [(set_attr "type" "store_ux")
9713    (set_attr "length" "8")])
9714
9715 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
9716 ;; register allocator doesn't have a clue about allocating 6 word registers.
9717 ;; rD/rS = r5 is preferred, efficient form.
9718 (define_expand "movmemsi_6reg"
9719   [(parallel [(set (match_operand 0 "" "")
9720                    (match_operand 1 "" ""))
9721               (use (match_operand 2 "" ""))
9722               (use (match_operand 3 "" ""))
9723               (clobber (reg:SI  5))
9724               (clobber (reg:SI  6))
9725               (clobber (reg:SI  7))
9726               (clobber (reg:SI  8))
9727               (clobber (reg:SI  9))
9728               (clobber (reg:SI 10))
9729               (clobber (match_scratch:SI 4 ""))])]
9730   "TARGET_STRING"
9731   "")
9732
9733 (define_insn ""
9734   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9735         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9736    (use (match_operand:SI 2 "immediate_operand" "i"))
9737    (use (match_operand:SI 3 "immediate_operand" "i"))
9738    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9739    (clobber (reg:SI  6))
9740    (clobber (reg:SI  7))
9741    (clobber (reg:SI  8))
9742    (clobber (reg:SI  9))
9743    (clobber (reg:SI 10))
9744    (clobber (match_scratch:SI 5 "=q"))]
9745   "TARGET_STRING && TARGET_POWER
9746    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
9747    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9748    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9749    && REGNO (operands[4]) == 5"
9750   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9751   [(set_attr "type" "store_ux")
9752    (set_attr "length" "8")])
9753
9754 (define_insn ""
9755   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9756         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9757    (use (match_operand:SI 2 "immediate_operand" "i"))
9758    (use (match_operand:SI 3 "immediate_operand" "i"))
9759    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9760    (clobber (reg:SI  6))
9761    (clobber (reg:SI  7))
9762    (clobber (reg:SI  8))
9763    (clobber (reg:SI  9))
9764    (clobber (reg:SI 10))
9765    (clobber (match_scratch:SI 5 "=X"))]
9766   "TARGET_STRING && ! TARGET_POWER
9767    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9768    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9769    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9770    && REGNO (operands[4]) == 5"
9771   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9772   [(set_attr "type" "store_ux")
9773    (set_attr "length" "8")])
9774
9775 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
9776 ;; problems with TImode.
9777 ;; rD/rS = r5 is preferred, efficient form.
9778 (define_expand "movmemsi_4reg"
9779   [(parallel [(set (match_operand 0 "" "")
9780                    (match_operand 1 "" ""))
9781               (use (match_operand 2 "" ""))
9782               (use (match_operand 3 "" ""))
9783               (clobber (reg:SI 5))
9784               (clobber (reg:SI 6))
9785               (clobber (reg:SI 7))
9786               (clobber (reg:SI 8))
9787               (clobber (match_scratch:SI 4 ""))])]
9788   "TARGET_STRING"
9789   "")
9790
9791 (define_insn ""
9792   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9793         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9794    (use (match_operand:SI 2 "immediate_operand" "i"))
9795    (use (match_operand:SI 3 "immediate_operand" "i"))
9796    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9797    (clobber (reg:SI 6))
9798    (clobber (reg:SI 7))
9799    (clobber (reg:SI 8))
9800    (clobber (match_scratch:SI 5 "=q"))]
9801   "TARGET_STRING && TARGET_POWER
9802    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9803    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9804    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9805    && REGNO (operands[4]) == 5"
9806   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9807   [(set_attr "type" "store_ux")
9808    (set_attr "length" "8")])
9809
9810 (define_insn ""
9811   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9812         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9813    (use (match_operand:SI 2 "immediate_operand" "i"))
9814    (use (match_operand:SI 3 "immediate_operand" "i"))
9815    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9816    (clobber (reg:SI 6))
9817    (clobber (reg:SI 7))
9818    (clobber (reg:SI 8))
9819    (clobber (match_scratch:SI 5 "=X"))]
9820   "TARGET_STRING && ! TARGET_POWER
9821    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9822    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9823    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9824    && REGNO (operands[4]) == 5"
9825   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9826   [(set_attr "type" "store_ux")
9827    (set_attr "length" "8")])
9828
9829 ;; Move up to 8 bytes at a time.
9830 (define_expand "movmemsi_2reg"
9831   [(parallel [(set (match_operand 0 "" "")
9832                    (match_operand 1 "" ""))
9833               (use (match_operand 2 "" ""))
9834               (use (match_operand 3 "" ""))
9835               (clobber (match_scratch:DI 4 ""))
9836               (clobber (match_scratch:SI 5 ""))])]
9837   "TARGET_STRING && ! TARGET_POWERPC64"
9838   "")
9839
9840 (define_insn ""
9841   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9842         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9843    (use (match_operand:SI 2 "immediate_operand" "i"))
9844    (use (match_operand:SI 3 "immediate_operand" "i"))
9845    (clobber (match_scratch:DI 4 "=&r"))
9846    (clobber (match_scratch:SI 5 "=q"))]
9847   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
9848    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9849   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9850   [(set_attr "type" "store_ux")
9851    (set_attr "length" "8")])
9852
9853 (define_insn ""
9854   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9855         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9856    (use (match_operand:SI 2 "immediate_operand" "i"))
9857    (use (match_operand:SI 3 "immediate_operand" "i"))
9858    (clobber (match_scratch:DI 4 "=&r"))
9859    (clobber (match_scratch:SI 5 "=X"))]
9860   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
9861    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9862   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9863   [(set_attr "type" "store_ux")
9864    (set_attr "length" "8")])
9865
9866 ;; Move up to 4 bytes at a time.
9867 (define_expand "movmemsi_1reg"
9868   [(parallel [(set (match_operand 0 "" "")
9869                    (match_operand 1 "" ""))
9870               (use (match_operand 2 "" ""))
9871               (use (match_operand 3 "" ""))
9872               (clobber (match_scratch:SI 4 ""))
9873               (clobber (match_scratch:SI 5 ""))])]
9874   "TARGET_STRING"
9875   "")
9876
9877 (define_insn ""
9878   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9879         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9880    (use (match_operand:SI 2 "immediate_operand" "i"))
9881    (use (match_operand:SI 3 "immediate_operand" "i"))
9882    (clobber (match_scratch:SI 4 "=&r"))
9883    (clobber (match_scratch:SI 5 "=q"))]
9884   "TARGET_STRING && TARGET_POWER
9885    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9886   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9887   [(set_attr "type" "store_ux")
9888    (set_attr "length" "8")])
9889
9890 (define_insn ""
9891   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9892         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9893    (use (match_operand:SI 2 "immediate_operand" "i"))
9894    (use (match_operand:SI 3 "immediate_operand" "i"))
9895    (clobber (match_scratch:SI 4 "=&r"))
9896    (clobber (match_scratch:SI 5 "=X"))]
9897   "TARGET_STRING && ! TARGET_POWER
9898    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9899   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9900   [(set_attr "type" "store_ux")
9901    (set_attr "length" "8")])
9902 \f
9903 ;; Define insns that do load or store with update.  Some of these we can
9904 ;; get by using pre-decrement or pre-increment, but the hardware can also
9905 ;; do cases where the increment is not the size of the object.
9906 ;;
9907 ;; In all these cases, we use operands 0 and 1 for the register being
9908 ;; incremented because those are the operands that local-alloc will
9909 ;; tie and these are the pair most likely to be tieable (and the ones
9910 ;; that will benefit the most).
9911
9912 (define_insn "*movdi_update1"
9913   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9914         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9915                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
9916    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9917         (plus:DI (match_dup 1) (match_dup 2)))]
9918   "TARGET_POWERPC64 && TARGET_UPDATE"
9919   "@
9920    ldux %3,%0,%2
9921    ldu %3,%2(%0)"
9922   [(set_attr "type" "load_ux,load_u")])
9923
9924 (define_insn "movdi_<mode>_update"
9925   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
9926                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
9927         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9928    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
9929         (plus:P (match_dup 1) (match_dup 2)))]
9930   "TARGET_POWERPC64 && TARGET_UPDATE"
9931   "@
9932    stdux %3,%0,%2
9933    stdu %3,%2(%0)"
9934   [(set_attr "type" "store_ux,store_u")])
9935
9936 (define_insn "*movsi_update1"
9937   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9938         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9939                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9940    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9941         (plus:SI (match_dup 1) (match_dup 2)))]
9942   "TARGET_UPDATE"
9943   "@
9944    {lux|lwzux} %3,%0,%2
9945    {lu|lwzu} %3,%2(%0)"
9946   [(set_attr "type" "load_ux,load_u")])
9947
9948 (define_insn "*movsi_update2"
9949   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9950         (sign_extend:DI
9951          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9952                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9953    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9954         (plus:DI (match_dup 1) (match_dup 2)))]
9955   "TARGET_POWERPC64"
9956   "lwaux %3,%0,%2"
9957   [(set_attr "type" "load_ext_ux")])
9958
9959 (define_insn "movsi_update"
9960   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9961                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9962         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9963    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9964         (plus:SI (match_dup 1) (match_dup 2)))]
9965   "TARGET_UPDATE"
9966   "@
9967    {stux|stwux} %3,%0,%2
9968    {stu|stwu} %3,%2(%0)"
9969   [(set_attr "type" "store_ux,store_u")])
9970
9971 (define_insn "*movhi_update1"
9972   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9973         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9974                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9975    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9976         (plus:SI (match_dup 1) (match_dup 2)))]
9977   "TARGET_UPDATE"
9978   "@
9979    lhzux %3,%0,%2
9980    lhzu %3,%2(%0)"
9981   [(set_attr "type" "load_ux,load_u")])
9982
9983 (define_insn "*movhi_update2"
9984   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9985         (zero_extend:SI
9986          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9987                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9988    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9989         (plus:SI (match_dup 1) (match_dup 2)))]
9990   "TARGET_UPDATE"
9991   "@
9992    lhzux %3,%0,%2
9993    lhzu %3,%2(%0)"
9994   [(set_attr "type" "load_ux,load_u")])
9995
9996 (define_insn "*movhi_update3"
9997   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9998         (sign_extend:SI
9999          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10000                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10001    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10002         (plus:SI (match_dup 1) (match_dup 2)))]
10003   "TARGET_UPDATE"
10004   "@
10005    lhaux %3,%0,%2
10006    lhau %3,%2(%0)"
10007   [(set_attr "type" "load_ext_ux,load_ext_u")])
10008
10009 (define_insn "*movhi_update4"
10010   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10011                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10012         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
10013    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10014         (plus:SI (match_dup 1) (match_dup 2)))]
10015   "TARGET_UPDATE"
10016   "@
10017    sthux %3,%0,%2
10018    sthu %3,%2(%0)"
10019   [(set_attr "type" "store_ux,store_u")])
10020
10021 (define_insn "*movqi_update1"
10022   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
10023         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10024                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10025    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10026         (plus:SI (match_dup 1) (match_dup 2)))]
10027   "TARGET_UPDATE"
10028   "@
10029    lbzux %3,%0,%2
10030    lbzu %3,%2(%0)"
10031   [(set_attr "type" "load_ux,load_u")])
10032
10033 (define_insn "*movqi_update2"
10034   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10035         (zero_extend:SI
10036          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10037                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
10038    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10039         (plus:SI (match_dup 1) (match_dup 2)))]
10040   "TARGET_UPDATE"
10041   "@
10042    lbzux %3,%0,%2
10043    lbzu %3,%2(%0)"
10044   [(set_attr "type" "load_ux,load_u")])
10045
10046 (define_insn "*movqi_update3"
10047   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10048                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10049         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
10050    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10051         (plus:SI (match_dup 1) (match_dup 2)))]
10052   "TARGET_UPDATE"
10053   "@
10054    stbux %3,%0,%2
10055    stbu %3,%2(%0)"
10056   [(set_attr "type" "store_ux,store_u")])
10057
10058 (define_insn "*movsf_update1"
10059   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
10060         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10061                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10062    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10063         (plus:SI (match_dup 1) (match_dup 2)))]
10064   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
10065   "@
10066    lfsux %3,%0,%2
10067    lfsu %3,%2(%0)"
10068   [(set_attr "type" "fpload_ux,fpload_u")])
10069
10070 (define_insn "*movsf_update2"
10071   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10072                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10073         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
10074    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10075         (plus:SI (match_dup 1) (match_dup 2)))]
10076   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
10077   "@
10078    stfsux %3,%0,%2
10079    stfsu %3,%2(%0)"
10080   [(set_attr "type" "fpstore_ux,fpstore_u")])
10081
10082 (define_insn "*movsf_update3"
10083   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
10084         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10085                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10086    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10087         (plus:SI (match_dup 1) (match_dup 2)))]
10088   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
10089   "@
10090    {lux|lwzux} %3,%0,%2
10091    {lu|lwzu} %3,%2(%0)"
10092   [(set_attr "type" "load_ux,load_u")])
10093
10094 (define_insn "*movsf_update4"
10095   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10096                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10097         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
10098    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10099         (plus:SI (match_dup 1) (match_dup 2)))]
10100   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
10101   "@
10102    {stux|stwux} %3,%0,%2
10103    {stu|stwu} %3,%2(%0)"
10104   [(set_attr "type" "store_ux,store_u")])
10105
10106 (define_insn "*movdf_update1"
10107   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
10108         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10109                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
10110    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10111         (plus:SI (match_dup 1) (match_dup 2)))]
10112   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
10113   "@
10114    lfdux %3,%0,%2
10115    lfdu %3,%2(%0)"
10116   [(set_attr "type" "fpload_ux,fpload_u")])
10117
10118 (define_insn "*movdf_update2"
10119   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10120                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10121         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
10122    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10123         (plus:SI (match_dup 1) (match_dup 2)))]
10124   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
10125   "@
10126    stfdux %3,%0,%2
10127    stfdu %3,%2(%0)"
10128   [(set_attr "type" "fpstore_ux,fpstore_u")])
10129
10130 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
10131
10132 (define_insn "*lfq_power2"
10133   [(set (match_operand:V2DF 0 "gpc_reg_operand" "=f")
10134         (match_operand:V2DF 1 "memory_operand" ""))]
10135   "TARGET_POWER2
10136    && TARGET_HARD_FLOAT && TARGET_FPRS"
10137   "lfq%U1%X1 %0,%1")
10138
10139 (define_peephole2
10140   [(set (match_operand:DF 0 "gpc_reg_operand" "")
10141         (match_operand:DF 1 "memory_operand" ""))
10142    (set (match_operand:DF 2 "gpc_reg_operand" "")
10143         (match_operand:DF 3 "memory_operand" ""))]
10144   "TARGET_POWER2
10145    && TARGET_HARD_FLOAT && TARGET_FPRS
10146    && registers_ok_for_quad_peep (operands[0], operands[2])
10147    && mems_ok_for_quad_peep (operands[1], operands[3])"
10148   [(set (match_dup 0)
10149         (match_dup 1))]
10150   "operands[1] = widen_memory_access (operands[1], V2DFmode, 0);
10151    operands[0] = gen_rtx_REG (V2DFmode, REGNO (operands[0]));")
10152
10153 (define_insn "*stfq_power2"
10154   [(set (match_operand:V2DF 0 "memory_operand" "")
10155         (match_operand:V2DF 1 "gpc_reg_operand" "f"))]
10156   "TARGET_POWER2
10157    && TARGET_HARD_FLOAT && TARGET_FPRS"
10158   "stfq%U0%X0 %1,%0")
10159
10160
10161 (define_peephole2
10162   [(set (match_operand:DF 0 "memory_operand" "")
10163         (match_operand:DF 1 "gpc_reg_operand" ""))
10164    (set (match_operand:DF 2 "memory_operand" "")
10165         (match_operand:DF 3 "gpc_reg_operand" ""))]
10166   "TARGET_POWER2
10167    && TARGET_HARD_FLOAT && TARGET_FPRS
10168    && registers_ok_for_quad_peep (operands[1], operands[3])
10169    && mems_ok_for_quad_peep (operands[0], operands[2])"
10170   [(set (match_dup 0)
10171         (match_dup 1))]
10172   "operands[0] = widen_memory_access (operands[0], V2DFmode, 0);
10173    operands[1] = gen_rtx_REG (V2DFmode, REGNO (operands[1]));")
10174
10175 ;; After inserting conditional returns we can sometimes have
10176 ;; unnecessary register moves.  Unfortunately we cannot have a
10177 ;; modeless peephole here, because some single SImode sets have early
10178 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
10179 ;; sequences, using get_attr_length here will smash the operands
10180 ;; array.  Neither is there an early_cobbler_p predicate.
10181 ;; Disallow subregs for E500 so we don't munge frob_di_df_2.
10182 (define_peephole2
10183   [(set (match_operand:DF 0 "gpc_reg_operand" "")
10184         (match_operand:DF 1 "any_operand" ""))
10185    (set (match_operand:DF 2 "gpc_reg_operand" "")
10186         (match_dup 0))]
10187   "!(TARGET_E500_DOUBLE && GET_CODE (operands[2]) == SUBREG)
10188    && peep2_reg_dead_p (2, operands[0])"
10189   [(set (match_dup 2) (match_dup 1))])
10190
10191 (define_peephole2
10192   [(set (match_operand:SF 0 "gpc_reg_operand" "")
10193         (match_operand:SF 1 "any_operand" ""))
10194    (set (match_operand:SF 2 "gpc_reg_operand" "")
10195         (match_dup 0))]
10196   "peep2_reg_dead_p (2, operands[0])"
10197   [(set (match_dup 2) (match_dup 1))])
10198
10199 \f
10200 ;; TLS support.
10201
10202 ;; "b" output constraint here and on tls_ld to support tls linker optimization.
10203 (define_insn "tls_gd_32"
10204   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
10205         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10206                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10207                    UNSPEC_TLSGD))]
10208   "HAVE_AS_TLS && !TARGET_64BIT"
10209   "addi %0,%1,%2@got@tlsgd")
10210
10211 (define_insn "tls_gd_64"
10212   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
10213         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10214                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10215                    UNSPEC_TLSGD))]
10216   "HAVE_AS_TLS && TARGET_64BIT"
10217   "addi %0,%1,%2@got@tlsgd")
10218
10219 (define_insn "tls_ld_32"
10220   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
10221         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")]
10222                    UNSPEC_TLSLD))]
10223   "HAVE_AS_TLS && !TARGET_64BIT"
10224   "addi %0,%1,%&@got@tlsld")
10225
10226 (define_insn "tls_ld_64"
10227   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
10228         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")]
10229                    UNSPEC_TLSLD))]
10230   "HAVE_AS_TLS && TARGET_64BIT"
10231   "addi %0,%1,%&@got@tlsld")
10232
10233 (define_insn "tls_dtprel_32"
10234   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10235         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10236                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10237                    UNSPEC_TLSDTPREL))]
10238   "HAVE_AS_TLS && !TARGET_64BIT"
10239   "addi %0,%1,%2@dtprel")
10240
10241 (define_insn "tls_dtprel_64"
10242   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10243         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10244                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10245                    UNSPEC_TLSDTPREL))]
10246   "HAVE_AS_TLS && TARGET_64BIT"
10247   "addi %0,%1,%2@dtprel")
10248
10249 (define_insn "tls_dtprel_ha_32"
10250   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10251         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10252                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10253                    UNSPEC_TLSDTPRELHA))]
10254   "HAVE_AS_TLS && !TARGET_64BIT"
10255   "addis %0,%1,%2@dtprel@ha")
10256
10257 (define_insn "tls_dtprel_ha_64"
10258   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10259         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10260                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10261                    UNSPEC_TLSDTPRELHA))]
10262   "HAVE_AS_TLS && TARGET_64BIT"
10263   "addis %0,%1,%2@dtprel@ha")
10264
10265 (define_insn "tls_dtprel_lo_32"
10266   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10267         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10268                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10269                    UNSPEC_TLSDTPRELLO))]
10270   "HAVE_AS_TLS && !TARGET_64BIT"
10271   "addi %0,%1,%2@dtprel@l")
10272
10273 (define_insn "tls_dtprel_lo_64"
10274   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10275         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10276                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10277                    UNSPEC_TLSDTPRELLO))]
10278   "HAVE_AS_TLS && TARGET_64BIT"
10279   "addi %0,%1,%2@dtprel@l")
10280
10281 (define_insn "tls_got_dtprel_32"
10282   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10283         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10284                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10285                    UNSPEC_TLSGOTDTPREL))]
10286   "HAVE_AS_TLS && !TARGET_64BIT"
10287   "lwz %0,%2@got@dtprel(%1)")
10288
10289 (define_insn "tls_got_dtprel_64"
10290   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10291         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10292                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10293                    UNSPEC_TLSGOTDTPREL))]
10294   "HAVE_AS_TLS && TARGET_64BIT"
10295   "ld %0,%2@got@dtprel(%1)")
10296
10297 (define_insn "tls_tprel_32"
10298   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10299         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10300                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10301                    UNSPEC_TLSTPREL))]
10302   "HAVE_AS_TLS && !TARGET_64BIT"
10303   "addi %0,%1,%2@tprel")
10304
10305 (define_insn "tls_tprel_64"
10306   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10307         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10308                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10309                    UNSPEC_TLSTPREL))]
10310   "HAVE_AS_TLS && TARGET_64BIT"
10311   "addi %0,%1,%2@tprel")
10312
10313 (define_insn "tls_tprel_ha_32"
10314   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10315         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10316                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10317                    UNSPEC_TLSTPRELHA))]
10318   "HAVE_AS_TLS && !TARGET_64BIT"
10319   "addis %0,%1,%2@tprel@ha")
10320
10321 (define_insn "tls_tprel_ha_64"
10322   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10323         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10324                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10325                    UNSPEC_TLSTPRELHA))]
10326   "HAVE_AS_TLS && TARGET_64BIT"
10327   "addis %0,%1,%2@tprel@ha")
10328
10329 (define_insn "tls_tprel_lo_32"
10330   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10331         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10332                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10333                    UNSPEC_TLSTPRELLO))]
10334   "HAVE_AS_TLS && !TARGET_64BIT"
10335   "addi %0,%1,%2@tprel@l")
10336
10337 (define_insn "tls_tprel_lo_64"
10338   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10339         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10340                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10341                    UNSPEC_TLSTPRELLO))]
10342   "HAVE_AS_TLS && TARGET_64BIT"
10343   "addi %0,%1,%2@tprel@l")
10344
10345 ;; "b" output constraint here and on tls_tls input to support linker tls
10346 ;; optimization.  The linker may edit the instructions emitted by a
10347 ;; tls_got_tprel/tls_tls pair to addis,addi.
10348 (define_insn "tls_got_tprel_32"
10349   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
10350         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10351                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10352                    UNSPEC_TLSGOTTPREL))]
10353   "HAVE_AS_TLS && !TARGET_64BIT"
10354   "lwz %0,%2@got@tprel(%1)")
10355
10356 (define_insn "tls_got_tprel_64"
10357   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
10358         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10359                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10360                    UNSPEC_TLSGOTTPREL))]
10361   "HAVE_AS_TLS && TARGET_64BIT"
10362   "ld %0,%2@got@tprel(%1)")
10363
10364 (define_insn "tls_tls_32"
10365   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10366         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
10367                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
10368                    UNSPEC_TLSTLS))]
10369   "HAVE_AS_TLS && !TARGET_64BIT"
10370   "add %0,%1,%2@tls")
10371
10372 (define_insn "tls_tls_64"
10373   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10374         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
10375                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
10376                    UNSPEC_TLSTLS))]
10377   "HAVE_AS_TLS && TARGET_64BIT"
10378   "add %0,%1,%2@tls")
10379 \f
10380 ;; Next come insns related to the calling sequence.
10381 ;;
10382 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
10383 ;; We move the back-chain and decrement the stack pointer.
10384
10385 (define_expand "allocate_stack"
10386   [(set (match_operand 0 "gpc_reg_operand" "")
10387         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
10388    (set (reg 1)
10389         (minus (reg 1) (match_dup 1)))]
10390   ""
10391   "
10392 { rtx chain = gen_reg_rtx (Pmode);
10393   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
10394   rtx neg_op0;
10395
10396   emit_move_insn (chain, stack_bot);
10397
10398   /* Check stack bounds if necessary.  */
10399   if (current_function_limit_stack)
10400     {
10401       rtx available;
10402       available = expand_binop (Pmode, sub_optab,
10403                                 stack_pointer_rtx, stack_limit_rtx,
10404                                 NULL_RTX, 1, OPTAB_WIDEN);
10405       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
10406     }
10407
10408   if (GET_CODE (operands[1]) != CONST_INT
10409       || INTVAL (operands[1]) < -32767
10410       || INTVAL (operands[1]) > 32768)
10411     {
10412       neg_op0 = gen_reg_rtx (Pmode);
10413       if (TARGET_32BIT)
10414         emit_insn (gen_negsi2 (neg_op0, operands[1]));
10415       else
10416         emit_insn (gen_negdi2 (neg_op0, operands[1]));
10417     }
10418   else
10419     neg_op0 = GEN_INT (- INTVAL (operands[1]));
10420
10421   if (TARGET_UPDATE)
10422     emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update : gen_movdi_di_update))
10423                 (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
10424
10425   else
10426     {
10427       emit_insn ((* ((TARGET_32BIT) ? gen_addsi3 : gen_adddi3))
10428                  (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
10429       emit_move_insn (gen_rtx_MEM (Pmode, stack_pointer_rtx), chain);
10430     }
10431
10432   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
10433   DONE;
10434 }")
10435
10436 ;; These patterns say how to save and restore the stack pointer.  We need not
10437 ;; save the stack pointer at function level since we are careful to
10438 ;; preserve the backchain.  At block level, we have to restore the backchain
10439 ;; when we restore the stack pointer.
10440 ;;
10441 ;; For nonlocal gotos, we must save both the stack pointer and its
10442 ;; backchain and restore both.  Note that in the nonlocal case, the
10443 ;; save area is a memory location.
10444
10445 (define_expand "save_stack_function"
10446   [(match_operand 0 "any_operand" "")
10447    (match_operand 1 "any_operand" "")]
10448   ""
10449   "DONE;")
10450
10451 (define_expand "restore_stack_function"
10452   [(match_operand 0 "any_operand" "")
10453    (match_operand 1 "any_operand" "")]
10454   ""
10455   "DONE;")
10456
10457 ;; Adjust stack pointer (op0) to a new value (op1).
10458 ;; First copy old stack backchain to new location, and ensure that the
10459 ;; scheduler won't reorder the sp assignment before the backchain write.
10460 (define_expand "restore_stack_block"
10461   [(set (match_dup 2) (match_dup 3))
10462    (set (match_dup 4) (match_dup 2))
10463    (set (match_dup 5) (unspec:BLK [(match_dup 5)] UNSPEC_TIE))
10464    (set (match_operand 0 "register_operand" "")
10465         (match_operand 1 "register_operand" ""))]
10466   ""
10467   "
10468 {
10469   operands[1] = force_reg (Pmode, operands[1]);
10470   operands[2] = gen_reg_rtx (Pmode);
10471   operands[3] = gen_frame_mem (Pmode, operands[0]);
10472   operands[4] = gen_frame_mem (Pmode, operands[1]);
10473   operands[5] = gen_frame_mem (BLKmode, operands[0]);
10474 }")
10475
10476 (define_expand "save_stack_nonlocal"
10477   [(set (match_dup 3) (match_dup 4))
10478    (set (match_operand 0 "memory_operand" "") (match_dup 3))
10479    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
10480   ""
10481   "
10482 {
10483   int units_per_word = (TARGET_32BIT) ? 4 : 8;
10484
10485   /* Copy the backchain to the first word, sp to the second.  */
10486   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
10487   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
10488   operands[3] = gen_reg_rtx (Pmode);
10489   operands[4] = gen_frame_mem (Pmode, operands[1]);
10490 }")
10491
10492 (define_expand "restore_stack_nonlocal"
10493   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
10494    (set (match_dup 3) (match_dup 4))
10495    (set (match_dup 5) (match_dup 2))
10496    (set (match_dup 6) (unspec:BLK [(match_dup 6)] UNSPEC_TIE))
10497    (set (match_operand 0 "register_operand" "") (match_dup 3))]
10498   ""
10499   "
10500 {
10501   int units_per_word = (TARGET_32BIT) ? 4 : 8;
10502
10503   /* Restore the backchain from the first word, sp from the second.  */
10504   operands[2] = gen_reg_rtx (Pmode);
10505   operands[3] = gen_reg_rtx (Pmode);
10506   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
10507   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
10508   operands[5] = gen_frame_mem (Pmode, operands[3]);
10509   operands[6] = gen_frame_mem (BLKmode, operands[0]);
10510 }")
10511 \f
10512 ;; TOC register handling.
10513
10514 ;; Code to initialize the TOC register...
10515
10516 (define_insn "load_toc_aix_si"
10517   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10518                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
10519               (use (reg:SI 2))])]
10520   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
10521   "*
10522 {
10523   char buf[30];
10524   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10525   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10526   operands[2] = gen_rtx_REG (Pmode, 2);
10527   return \"{l|lwz} %0,%1(%2)\";
10528 }"
10529   [(set_attr "type" "load")])
10530
10531 (define_insn "load_toc_aix_di"
10532   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10533                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
10534               (use (reg:DI 2))])]
10535   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
10536   "*
10537 {
10538   char buf[30];
10539 #ifdef TARGET_RELOCATABLE
10540   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
10541                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
10542 #else
10543   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10544 #endif
10545   if (TARGET_ELF)
10546     strcat (buf, \"@toc\");
10547   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10548   operands[2] = gen_rtx_REG (Pmode, 2);
10549   return \"ld %0,%1(%2)\";
10550 }"
10551   [(set_attr "type" "load")])
10552
10553 (define_insn "load_toc_v4_pic_si"
10554   [(set (reg:SI LR_REGNO)
10555         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
10556   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
10557   "bl _GLOBAL_OFFSET_TABLE_@local-4"
10558   [(set_attr "type" "branch")
10559    (set_attr "length" "4")])
10560
10561 (define_insn "load_toc_v4_PIC_1"
10562   [(set (reg:SI LR_REGNO)
10563         (match_operand:SI 0 "immediate_operand" "s"))
10564    (use (unspec [(match_dup 0)] UNSPEC_TOC))]
10565   "TARGET_ELF && DEFAULT_ABI != ABI_AIX
10566    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
10567   "bcl 20,31,%0\\n%0:"
10568   [(set_attr "type" "branch")
10569    (set_attr "length" "4")])
10570
10571 (define_insn "load_toc_v4_PIC_1b"
10572   [(set (reg:SI LR_REGNO)
10573         (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")]
10574                 UNSPEC_TOCPTR))]
10575   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10576   "bcl 20,31,$+8\\n\\t.long %0-$"
10577   [(set_attr "type" "branch")
10578    (set_attr "length" "8")])
10579
10580 (define_insn "load_toc_v4_PIC_2"
10581   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10582         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10583                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
10584                              (match_operand:SI 3 "immediate_operand" "s")))))]
10585   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10586   "{l|lwz} %0,%2-%3(%1)"
10587   [(set_attr "type" "load")])
10588
10589 (define_insn "load_toc_v4_PIC_3b"
10590   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
10591         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
10592                  (high:SI
10593                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
10594                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
10595   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
10596   "{cau|addis} %0,%1,%2-%3@ha")
10597
10598 (define_insn "load_toc_v4_PIC_3c"
10599   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10600         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10601                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
10602                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
10603   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
10604   "{cal|addi} %0,%1,%2-%3@l")
10605
10606 ;; If the TOC is shared over a translation unit, as happens with all
10607 ;; the kinds of PIC that we support, we need to restore the TOC
10608 ;; pointer only when jumping over units of translation.
10609 ;; On Darwin, we need to reload the picbase.
10610
10611 (define_expand "builtin_setjmp_receiver"
10612   [(use (label_ref (match_operand 0 "" "")))]
10613   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10614    || (TARGET_TOC && TARGET_MINIMAL_TOC)
10615    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
10616   "
10617 {
10618 #if TARGET_MACHO
10619   if (DEFAULT_ABI == ABI_DARWIN)
10620     {
10621       const char *picbase = machopic_function_base_name ();
10622       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (picbase));
10623       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
10624       rtx tmplabrtx;
10625       char tmplab[20];
10626
10627       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
10628                                   CODE_LABEL_NUMBER (operands[0]));
10629       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
10630
10631       emit_insn (gen_load_macho_picbase (tmplabrtx));
10632       emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO));
10633       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
10634     }
10635   else
10636 #endif
10637     rs6000_emit_load_toc_table (FALSE);
10638   DONE;
10639 }")
10640
10641 ;; Elf specific ways of loading addresses for non-PIC code.
10642 ;; The output of this could be r0, but we make a very strong
10643 ;; preference for a base register because it will usually
10644 ;; be needed there.
10645 (define_insn "elf_high"
10646   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
10647         (high:SI (match_operand 1 "" "")))]
10648   "TARGET_ELF && ! TARGET_64BIT"
10649   "{liu|lis} %0,%1@ha")
10650
10651 (define_insn "elf_low"
10652   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
10653         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
10654                    (match_operand 2 "" "")))]
10655    "TARGET_ELF && ! TARGET_64BIT"
10656    "@
10657     {cal|la} %0,%2@l(%1)
10658     {ai|addic} %0,%1,%K2")
10659 \f
10660 ;; A function pointer under AIX is a pointer to a data area whose first word
10661 ;; contains the actual address of the function, whose second word contains a
10662 ;; pointer to its TOC, and whose third word contains a value to place in the
10663 ;; static chain register (r11).  Note that if we load the static chain, our
10664 ;; "trampoline" need not have any executable code.
10665
10666 (define_expand "call_indirect_aix32"
10667   [(set (match_dup 2)
10668         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
10669    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10670         (reg:SI 2))
10671    (set (reg:SI 2)
10672         (mem:SI (plus:SI (match_dup 0)
10673                          (const_int 4))))
10674    (set (reg:SI 11)
10675         (mem:SI (plus:SI (match_dup 0)
10676                          (const_int 8))))
10677    (parallel [(call (mem:SI (match_dup 2))
10678                     (match_operand 1 "" ""))
10679               (use (reg:SI 2))
10680               (use (reg:SI 11))
10681               (set (reg:SI 2)
10682                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10683               (clobber (reg:SI LR_REGNO))])]
10684   "TARGET_32BIT"
10685   "
10686 { operands[2] = gen_reg_rtx (SImode); }")
10687
10688 (define_expand "call_indirect_aix64"
10689   [(set (match_dup 2)
10690         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
10691    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10692         (reg:DI 2))
10693    (set (reg:DI 2)
10694         (mem:DI (plus:DI (match_dup 0)
10695                          (const_int 8))))
10696    (set (reg:DI 11)
10697         (mem:DI (plus:DI (match_dup 0)
10698                          (const_int 16))))
10699    (parallel [(call (mem:SI (match_dup 2))
10700                     (match_operand 1 "" ""))
10701               (use (reg:DI 2))
10702               (use (reg:DI 11))
10703               (set (reg:DI 2)
10704                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10705               (clobber (reg:SI LR_REGNO))])]
10706   "TARGET_64BIT"
10707   "
10708 { operands[2] = gen_reg_rtx (DImode); }")
10709
10710 (define_expand "call_value_indirect_aix32"
10711   [(set (match_dup 3)
10712         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
10713    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10714         (reg:SI 2))
10715    (set (reg:SI 2)
10716         (mem:SI (plus:SI (match_dup 1)
10717                          (const_int 4))))
10718    (set (reg:SI 11)
10719         (mem:SI (plus:SI (match_dup 1)
10720                          (const_int 8))))
10721    (parallel [(set (match_operand 0 "" "")
10722                    (call (mem:SI (match_dup 3))
10723                          (match_operand 2 "" "")))
10724               (use (reg:SI 2))
10725               (use (reg:SI 11))
10726               (set (reg:SI 2)
10727                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10728               (clobber (reg:SI LR_REGNO))])]
10729   "TARGET_32BIT"
10730   "
10731 { operands[3] = gen_reg_rtx (SImode); }")
10732
10733 (define_expand "call_value_indirect_aix64"
10734   [(set (match_dup 3)
10735         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
10736    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10737         (reg:DI 2))
10738    (set (reg:DI 2)
10739         (mem:DI (plus:DI (match_dup 1)
10740                          (const_int 8))))
10741    (set (reg:DI 11)
10742         (mem:DI (plus:DI (match_dup 1)
10743                          (const_int 16))))
10744    (parallel [(set (match_operand 0 "" "")
10745                    (call (mem:SI (match_dup 3))
10746                          (match_operand 2 "" "")))
10747               (use (reg:DI 2))
10748               (use (reg:DI 11))
10749               (set (reg:DI 2)
10750                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10751               (clobber (reg:SI LR_REGNO))])]
10752   "TARGET_64BIT"
10753   "
10754 { operands[3] = gen_reg_rtx (DImode); }")
10755
10756 ;; Now the definitions for the call and call_value insns
10757 (define_expand "call"
10758   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10759                     (match_operand 1 "" ""))
10760               (use (match_operand 2 "" ""))
10761               (clobber (reg:SI LR_REGNO))])]
10762   ""
10763   "
10764 {
10765 #if TARGET_MACHO
10766   if (MACHOPIC_INDIRECT)
10767     operands[0] = machopic_indirect_call_target (operands[0]);
10768 #endif
10769
10770   gcc_assert (GET_CODE (operands[0]) == MEM);
10771   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
10772
10773   operands[0] = XEXP (operands[0], 0);
10774
10775   if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT
10776       && flag_pic
10777       && GET_CODE (operands[0]) == SYMBOL_REF
10778       && !SYMBOL_REF_LOCAL_P (operands[0]))
10779     {
10780       rtx call;
10781       rtvec tmp;
10782
10783       tmp = gen_rtvec (3,
10784                        gen_rtx_CALL (VOIDmode,
10785                                      gen_rtx_MEM (SImode, operands[0]),
10786                                      operands[1]),
10787                        gen_rtx_USE (VOIDmode, operands[2]),
10788                        gen_rtx_CLOBBER (VOIDmode,
10789                                         gen_rtx_REG (Pmode, LR_REGNO)));
10790       call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp));
10791       use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx);
10792       DONE;
10793     }
10794
10795   if (GET_CODE (operands[0]) != SYMBOL_REF
10796       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
10797       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
10798     {
10799       if (INTVAL (operands[2]) & CALL_LONG)
10800         operands[0] = rs6000_longcall_ref (operands[0]);
10801
10802       switch (DEFAULT_ABI)
10803         {
10804         case ABI_V4:
10805         case ABI_DARWIN:
10806           operands[0] = force_reg (Pmode, operands[0]);
10807           break;
10808
10809         case ABI_AIX:
10810           /* AIX function pointers are really pointers to a three word
10811              area.  */
10812           emit_call_insn (TARGET_32BIT
10813                           ? gen_call_indirect_aix32 (force_reg (SImode,
10814                                                                 operands[0]),
10815                                                      operands[1])
10816                           : gen_call_indirect_aix64 (force_reg (DImode,
10817                                                                 operands[0]),
10818                                                      operands[1]));
10819           DONE;
10820
10821         default:
10822           gcc_unreachable ();
10823         }
10824     }
10825 }")
10826
10827 (define_expand "call_value"
10828   [(parallel [(set (match_operand 0 "" "")
10829                    (call (mem:SI (match_operand 1 "address_operand" ""))
10830                          (match_operand 2 "" "")))
10831               (use (match_operand 3 "" ""))
10832               (clobber (reg:SI LR_REGNO))])]
10833   ""
10834   "
10835 {
10836 #if TARGET_MACHO
10837   if (MACHOPIC_INDIRECT)
10838     operands[1] = machopic_indirect_call_target (operands[1]);
10839 #endif
10840
10841   gcc_assert (GET_CODE (operands[1]) == MEM);
10842   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
10843
10844   operands[1] = XEXP (operands[1], 0);
10845
10846   if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT
10847       && flag_pic
10848       && GET_CODE (operands[1]) == SYMBOL_REF
10849       && !SYMBOL_REF_LOCAL_P (operands[1]))
10850     {
10851       rtx call;
10852       rtvec tmp;
10853
10854       tmp = gen_rtvec (3,
10855                        gen_rtx_SET (VOIDmode,
10856                                     operands[0],
10857                                     gen_rtx_CALL (VOIDmode,
10858                                                   gen_rtx_MEM (SImode,
10859                                                                operands[1]),
10860                                                   operands[2])),
10861                        gen_rtx_USE (VOIDmode, operands[3]),
10862                        gen_rtx_CLOBBER (VOIDmode, 
10863                                         gen_rtx_REG (Pmode, LR_REGNO)));
10864       call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp));
10865       use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx);
10866       DONE;
10867     }
10868
10869   if (GET_CODE (operands[1]) != SYMBOL_REF
10870       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
10871       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
10872     {
10873       if (INTVAL (operands[3]) & CALL_LONG)
10874         operands[1] = rs6000_longcall_ref (operands[1]);
10875
10876       switch (DEFAULT_ABI)
10877         {
10878         case ABI_V4:
10879         case ABI_DARWIN:
10880           operands[1] = force_reg (Pmode, operands[1]);
10881           break;
10882
10883         case ABI_AIX:
10884           /* AIX function pointers are really pointers to a three word
10885              area.  */
10886           emit_call_insn (TARGET_32BIT
10887                           ? gen_call_value_indirect_aix32 (operands[0],
10888                                                            force_reg (SImode,
10889                                                                       operands[1]),
10890                                                            operands[2])
10891                           : gen_call_value_indirect_aix64 (operands[0],
10892                                                            force_reg (DImode,
10893                                                                       operands[1]),
10894                                                            operands[2]));
10895           DONE;
10896
10897         default:
10898           gcc_unreachable ();
10899         }
10900     }
10901 }")
10902
10903 ;; Call to function in current module.  No TOC pointer reload needed.
10904 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10905 ;; either the function was not prototyped, or it was prototyped as a
10906 ;; variable argument function.  It is > 0 if FP registers were passed
10907 ;; and < 0 if they were not.
10908
10909 (define_insn "*call_local32"
10910   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10911          (match_operand 1 "" "g,g"))
10912    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10913    (clobber (reg:SI LR_REGNO))]
10914   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10915   "*
10916 {
10917   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10918     output_asm_insn (\"crxor 6,6,6\", operands);
10919
10920   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10921     output_asm_insn (\"creqv 6,6,6\", operands);
10922
10923   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10924 }"
10925   [(set_attr "type" "branch")
10926    (set_attr "length" "4,8")])
10927
10928 (define_insn "*call_local64"
10929   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10930          (match_operand 1 "" "g,g"))
10931    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10932    (clobber (reg:SI LR_REGNO))]
10933   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10934   "*
10935 {
10936   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10937     output_asm_insn (\"crxor 6,6,6\", operands);
10938
10939   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10940     output_asm_insn (\"creqv 6,6,6\", operands);
10941
10942   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10943 }"
10944   [(set_attr "type" "branch")
10945    (set_attr "length" "4,8")])
10946
10947 (define_insn "*call_value_local32"
10948   [(set (match_operand 0 "" "")
10949         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10950               (match_operand 2 "" "g,g")))
10951    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10952    (clobber (reg:SI LR_REGNO))]
10953   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10954   "*
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   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10963 }"
10964   [(set_attr "type" "branch")
10965    (set_attr "length" "4,8")])
10966
10967
10968 (define_insn "*call_value_local64"
10969   [(set (match_operand 0 "" "")
10970         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10971               (match_operand 2 "" "g,g")))
10972    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10973    (clobber (reg:SI LR_REGNO))]
10974   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10975   "*
10976 {
10977   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10978     output_asm_insn (\"crxor 6,6,6\", operands);
10979
10980   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10981     output_asm_insn (\"creqv 6,6,6\", operands);
10982
10983   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10984 }"
10985   [(set_attr "type" "branch")
10986    (set_attr "length" "4,8")])
10987
10988 ;; Call to function which may be in another module.  Restore the TOC
10989 ;; pointer (r2) after the call unless this is System V.
10990 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10991 ;; either the function was not prototyped, or it was prototyped as a
10992 ;; variable argument function.  It is > 0 if FP registers were passed
10993 ;; and < 0 if they were not.
10994
10995 (define_insn "*call_indirect_nonlocal_aix32"
10996   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l"))
10997          (match_operand 1 "" "g,g"))
10998    (use (reg:SI 2))
10999    (use (reg:SI 11))
11000    (set (reg:SI 2)
11001         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11002    (clobber (reg:SI LR_REGNO))]
11003   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
11004   "b%T0l\;{l|lwz} 2,20(1)"
11005   [(set_attr "type" "jmpreg")
11006    (set_attr "length" "8")])
11007
11008 (define_insn "*call_nonlocal_aix32"
11009   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
11010          (match_operand 1 "" "g"))
11011    (use (match_operand:SI 2 "immediate_operand" "O"))
11012    (clobber (reg:SI LR_REGNO))]
11013   "TARGET_32BIT
11014    && DEFAULT_ABI == ABI_AIX
11015    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11016   "bl %z0\;%."
11017   [(set_attr "type" "branch")
11018    (set_attr "length" "8")])
11019
11020 (define_insn "*call_indirect_nonlocal_aix64"
11021   [(call (mem:SI (match_operand:DI 0 "register_operand" "c,*l"))
11022          (match_operand 1 "" "g,g"))
11023    (use (reg:DI 2))
11024    (use (reg:DI 11))
11025    (set (reg:DI 2)
11026         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11027    (clobber (reg:SI LR_REGNO))]
11028   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
11029   "b%T0l\;ld 2,40(1)"
11030   [(set_attr "type" "jmpreg")
11031    (set_attr "length" "8")])
11032
11033 (define_insn "*call_nonlocal_aix64"
11034   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
11035          (match_operand 1 "" "g"))
11036    (use (match_operand:SI 2 "immediate_operand" "O"))
11037    (clobber (reg:SI LR_REGNO))]
11038   "TARGET_64BIT
11039    && DEFAULT_ABI == ABI_AIX
11040    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11041   "bl %z0\;%."
11042   [(set_attr "type" "branch")
11043    (set_attr "length" "8")])
11044
11045 (define_insn "*call_value_indirect_nonlocal_aix32"
11046   [(set (match_operand 0 "" "")
11047         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l"))
11048               (match_operand 2 "" "g,g")))
11049    (use (reg:SI 2))
11050    (use (reg:SI 11))
11051    (set (reg:SI 2)
11052         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
11053    (clobber (reg:SI LR_REGNO))]
11054   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
11055   "b%T1l\;{l|lwz} 2,20(1)"
11056   [(set_attr "type" "jmpreg")
11057    (set_attr "length" "8")])
11058
11059 (define_insn "*call_value_nonlocal_aix32"
11060   [(set (match_operand 0 "" "")
11061         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
11062               (match_operand 2 "" "g")))
11063    (use (match_operand:SI 3 "immediate_operand" "O"))
11064    (clobber (reg:SI LR_REGNO))]
11065   "TARGET_32BIT
11066    && DEFAULT_ABI == ABI_AIX
11067    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11068   "bl %z1\;%."
11069   [(set_attr "type" "branch")
11070    (set_attr "length" "8")])
11071
11072 (define_insn "*call_value_indirect_nonlocal_aix64"
11073   [(set (match_operand 0 "" "")
11074         (call (mem:SI (match_operand:DI 1 "register_operand" "c,*l"))
11075               (match_operand 2 "" "g,g")))
11076    (use (reg:DI 2))
11077    (use (reg:DI 11))
11078    (set (reg:DI 2)
11079         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
11080    (clobber (reg:SI LR_REGNO))]
11081   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
11082   "b%T1l\;ld 2,40(1)"
11083   [(set_attr "type" "jmpreg")
11084    (set_attr "length" "8")])
11085
11086 (define_insn "*call_value_nonlocal_aix64"
11087   [(set (match_operand 0 "" "")
11088         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
11089               (match_operand 2 "" "g")))
11090    (use (match_operand:SI 3 "immediate_operand" "O"))
11091    (clobber (reg:SI LR_REGNO))]
11092   "TARGET_64BIT
11093    && DEFAULT_ABI == ABI_AIX
11094    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11095   "bl %z1\;%."
11096   [(set_attr "type" "branch")
11097    (set_attr "length" "8")])
11098
11099 ;; A function pointer under System V is just a normal pointer
11100 ;; operands[0] is the function pointer
11101 ;; operands[1] is the stack size to clean up
11102 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
11103 ;; which indicates how to set cr1
11104
11105 (define_insn "*call_indirect_nonlocal_sysv<mode>"
11106   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
11107          (match_operand 1 "" "g,g,g,g"))
11108    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
11109    (clobber (reg:SI LR_REGNO))]
11110   "DEFAULT_ABI == ABI_V4
11111    || DEFAULT_ABI == ABI_DARWIN"
11112 {
11113   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11114     output_asm_insn ("crxor 6,6,6", operands);
11115
11116   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11117     output_asm_insn ("creqv 6,6,6", operands);
11118
11119   return "b%T0l";
11120 }
11121   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
11122    (set_attr "length" "4,4,8,8")])
11123
11124 (define_insn "*call_nonlocal_sysv<mode>"
11125   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
11126          (match_operand 1 "" "g,g"))
11127    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11128    (clobber (reg:SI LR_REGNO))]
11129   "(DEFAULT_ABI == ABI_DARWIN
11130    || (DEFAULT_ABI == ABI_V4
11131        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
11132 {
11133   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11134     output_asm_insn ("crxor 6,6,6", operands);
11135
11136   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11137     output_asm_insn ("creqv 6,6,6", operands);
11138
11139 #if TARGET_MACHO
11140   return output_call(insn, operands, 0, 2);
11141 #else
11142   if (DEFAULT_ABI == ABI_V4 && flag_pic)
11143     {
11144       if (TARGET_SECURE_PLT && flag_pic == 2)
11145         /* The magic 32768 offset here and in the other sysv call insns
11146            corresponds to the offset of r30 in .got2, as given by LCTOC1.
11147            See sysv4.h:toc_section.  */
11148         return "bl %z0+32768@plt";
11149       else
11150         return "bl %z0@plt";
11151     }
11152   else
11153     return "bl %z0";
11154 #endif
11155 }
11156   [(set_attr "type" "branch,branch")
11157    (set_attr "length" "4,8")])
11158
11159 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
11160   [(set (match_operand 0 "" "")
11161         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
11162               (match_operand 2 "" "g,g,g,g")))
11163    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
11164    (clobber (reg:SI LR_REGNO))]
11165   "DEFAULT_ABI == ABI_V4
11166    || DEFAULT_ABI == ABI_DARWIN"
11167 {
11168   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11169     output_asm_insn ("crxor 6,6,6", operands);
11170
11171   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11172     output_asm_insn ("creqv 6,6,6", operands);
11173
11174   return "b%T1l";
11175 }
11176   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
11177    (set_attr "length" "4,4,8,8")])
11178
11179 (define_insn "*call_value_nonlocal_sysv<mode>"
11180   [(set (match_operand 0 "" "")
11181         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
11182               (match_operand 2 "" "g,g")))
11183    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11184    (clobber (reg:SI LR_REGNO))]
11185   "(DEFAULT_ABI == ABI_DARWIN
11186    || (DEFAULT_ABI == ABI_V4
11187        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
11188 {
11189   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11190     output_asm_insn ("crxor 6,6,6", operands);
11191
11192   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11193     output_asm_insn ("creqv 6,6,6", operands);
11194
11195 #if TARGET_MACHO
11196   return output_call(insn, operands, 1, 3);
11197 #else
11198   if (DEFAULT_ABI == ABI_V4 && flag_pic)
11199     {
11200       if (TARGET_SECURE_PLT && flag_pic == 2)
11201         return "bl %z1+32768@plt";
11202       else
11203         return "bl %z1@plt";
11204     }
11205   else
11206     return "bl %z1";
11207 #endif
11208 }
11209   [(set_attr "type" "branch,branch")
11210    (set_attr "length" "4,8")])
11211
11212 ;; Call subroutine returning any type.
11213 (define_expand "untyped_call"
11214   [(parallel [(call (match_operand 0 "" "")
11215                     (const_int 0))
11216               (match_operand 1 "" "")
11217               (match_operand 2 "" "")])]
11218   ""
11219   "
11220 {
11221   int i;
11222
11223   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
11224
11225   for (i = 0; i < XVECLEN (operands[2], 0); i++)
11226     {
11227       rtx set = XVECEXP (operands[2], 0, i);
11228       emit_move_insn (SET_DEST (set), SET_SRC (set));
11229     }
11230
11231   /* The optimizer does not know that the call sets the function value
11232      registers we stored in the result block.  We avoid problems by
11233      claiming that all hard registers are used and clobbered at this
11234      point.  */
11235   emit_insn (gen_blockage ());
11236
11237   DONE;
11238 }")
11239
11240 ;; sibling call patterns
11241 (define_expand "sibcall"
11242   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
11243                     (match_operand 1 "" ""))
11244               (use (match_operand 2 "" ""))
11245               (use (reg:SI LR_REGNO))
11246               (return)])]
11247   ""
11248   "
11249 {
11250 #if TARGET_MACHO
11251   if (MACHOPIC_INDIRECT)
11252     operands[0] = machopic_indirect_call_target (operands[0]);
11253 #endif
11254
11255   gcc_assert (GET_CODE (operands[0]) == MEM);
11256   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
11257
11258   operands[0] = XEXP (operands[0], 0);
11259 }")
11260
11261 ;; this and similar patterns must be marked as using LR, otherwise
11262 ;; dataflow will try to delete the store into it.  This is true
11263 ;; even when the actual reg to jump to is in CTR, when LR was
11264 ;; saved and restored around the PIC-setting BCL.
11265 (define_insn "*sibcall_local32"
11266   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
11267          (match_operand 1 "" "g,g"))
11268    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11269    (use (reg:SI LR_REGNO))
11270    (return)]
11271   "(INTVAL (operands[2]) & CALL_LONG) == 0"
11272   "*
11273 {
11274   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11275     output_asm_insn (\"crxor 6,6,6\", operands);
11276
11277   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11278     output_asm_insn (\"creqv 6,6,6\", operands);
11279
11280   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
11281 }"
11282   [(set_attr "type" "branch")
11283    (set_attr "length" "4,8")])
11284
11285 (define_insn "*sibcall_local64"
11286   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
11287          (match_operand 1 "" "g,g"))
11288    (use (match_operand:SI 2 "immediate_operand" "O,n"))
11289    (use (reg:SI LR_REGNO))
11290    (return)]
11291   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
11292   "*
11293 {
11294   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11295     output_asm_insn (\"crxor 6,6,6\", operands);
11296
11297   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11298     output_asm_insn (\"creqv 6,6,6\", operands);
11299
11300   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
11301 }"
11302   [(set_attr "type" "branch")
11303    (set_attr "length" "4,8")])
11304
11305 (define_insn "*sibcall_value_local32"
11306   [(set (match_operand 0 "" "")
11307         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
11308               (match_operand 2 "" "g,g")))
11309    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11310    (use (reg:SI LR_REGNO))
11311    (return)]
11312   "(INTVAL (operands[3]) & CALL_LONG) == 0"
11313   "*
11314 {
11315   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11316     output_asm_insn (\"crxor 6,6,6\", operands);
11317
11318   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11319     output_asm_insn (\"creqv 6,6,6\", operands);
11320
11321   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
11322 }"
11323   [(set_attr "type" "branch")
11324    (set_attr "length" "4,8")])
11325
11326
11327 (define_insn "*sibcall_value_local64"
11328   [(set (match_operand 0 "" "")
11329         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
11330               (match_operand 2 "" "g,g")))
11331    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11332    (use (reg:SI LR_REGNO))
11333    (return)]
11334   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
11335   "*
11336 {
11337   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11338     output_asm_insn (\"crxor 6,6,6\", operands);
11339
11340   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11341     output_asm_insn (\"creqv 6,6,6\", operands);
11342
11343   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
11344 }"
11345   [(set_attr "type" "branch")
11346    (set_attr "length" "4,8")])
11347
11348 (define_insn "*sibcall_nonlocal_aix32"
11349   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
11350          (match_operand 1 "" "g"))
11351    (use (match_operand:SI 2 "immediate_operand" "O"))
11352    (use (reg:SI LR_REGNO))
11353    (return)]
11354   "TARGET_32BIT
11355    && DEFAULT_ABI == ABI_AIX
11356    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11357   "b %z0"
11358   [(set_attr "type" "branch")
11359    (set_attr "length" "4")])
11360
11361 (define_insn "*sibcall_nonlocal_aix64"
11362   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
11363          (match_operand 1 "" "g"))
11364    (use (match_operand:SI 2 "immediate_operand" "O"))
11365    (use (reg:SI LR_REGNO))
11366    (return)]
11367   "TARGET_64BIT
11368    && DEFAULT_ABI == ABI_AIX
11369    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11370   "b %z0"
11371   [(set_attr "type" "branch")
11372    (set_attr "length" "4")])
11373
11374 (define_insn "*sibcall_value_nonlocal_aix32"
11375   [(set (match_operand 0 "" "")
11376         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
11377               (match_operand 2 "" "g")))
11378    (use (match_operand:SI 3 "immediate_operand" "O"))
11379    (use (reg:SI LR_REGNO))
11380    (return)]
11381   "TARGET_32BIT
11382    && DEFAULT_ABI == ABI_AIX
11383    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11384   "b %z1"
11385   [(set_attr "type" "branch")
11386    (set_attr "length" "4")])
11387
11388 (define_insn "*sibcall_value_nonlocal_aix64"
11389   [(set (match_operand 0 "" "")
11390         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
11391               (match_operand 2 "" "g")))
11392    (use (match_operand:SI 3 "immediate_operand" "O"))
11393    (use (reg:SI LR_REGNO))
11394    (return)]
11395   "TARGET_64BIT
11396    && DEFAULT_ABI == ABI_AIX
11397    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11398   "b %z1"
11399   [(set_attr "type" "branch")
11400    (set_attr "length" "4")])
11401
11402 (define_insn "*sibcall_nonlocal_sysv<mode>"
11403   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
11404          (match_operand 1 "" ""))
11405    (use (match_operand 2 "immediate_operand" "O,n"))
11406    (use (reg:SI LR_REGNO))
11407    (return)]
11408   "(DEFAULT_ABI == ABI_DARWIN
11409      || DEFAULT_ABI == ABI_V4)
11410    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11411   "*
11412 {
11413   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11414     output_asm_insn (\"crxor 6,6,6\", operands);
11415
11416   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11417     output_asm_insn (\"creqv 6,6,6\", operands);
11418
11419   if (DEFAULT_ABI == ABI_V4 && flag_pic)
11420     {
11421       if (TARGET_SECURE_PLT && flag_pic == 2)
11422         return \"b %z0+32768@plt\";
11423       else
11424         return \"b %z0@plt\";
11425     }
11426   else
11427     return \"b %z0\";
11428 }"
11429   [(set_attr "type" "branch,branch")
11430    (set_attr "length" "4,8")])
11431
11432 (define_expand "sibcall_value"
11433   [(parallel [(set (match_operand 0 "register_operand" "")
11434                 (call (mem:SI (match_operand 1 "address_operand" ""))
11435                       (match_operand 2 "" "")))
11436               (use (match_operand 3 "" ""))
11437               (use (reg:SI LR_REGNO))
11438               (return)])]
11439   ""
11440   "
11441 {
11442 #if TARGET_MACHO
11443   if (MACHOPIC_INDIRECT)
11444     operands[1] = machopic_indirect_call_target (operands[1]);
11445 #endif
11446
11447   gcc_assert (GET_CODE (operands[1]) == MEM);
11448   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
11449
11450   operands[1] = XEXP (operands[1], 0);
11451 }")
11452
11453 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
11454   [(set (match_operand 0 "" "")
11455         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
11456               (match_operand 2 "" "")))
11457    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11458    (use (reg:SI LR_REGNO))
11459    (return)]
11460   "(DEFAULT_ABI == ABI_DARWIN
11461        || DEFAULT_ABI == ABI_V4)
11462    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11463   "*
11464 {
11465   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11466     output_asm_insn (\"crxor 6,6,6\", operands);
11467
11468   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11469     output_asm_insn (\"creqv 6,6,6\", operands);
11470
11471   if (DEFAULT_ABI == ABI_V4 && flag_pic)
11472     {
11473       if (TARGET_SECURE_PLT && flag_pic == 2)
11474         return \"b %z1+32768@plt\";
11475       else
11476         return \"b %z1@plt\";
11477     }
11478   else
11479     return \"b %z1\";
11480 }"
11481   [(set_attr "type" "branch,branch")
11482    (set_attr "length" "4,8")])
11483
11484 (define_expand "sibcall_epilogue"
11485   [(use (const_int 0))]
11486   "TARGET_SCHED_PROLOG"
11487   "
11488 {
11489       rs6000_emit_epilogue (TRUE);
11490       DONE;
11491 }")
11492
11493 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
11494 ;; all of memory.  This blocks insns from being moved across this point.
11495
11496 (define_insn "blockage"
11497   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
11498   ""
11499   "")
11500 \f
11501 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
11502 ;; signed & unsigned, and one type of branch.
11503 ;;
11504 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
11505 ;; insns, and branches.  We store the operands of compares until we see
11506 ;; how it is used.
11507 (define_expand "cmp<mode>"
11508   [(set (cc0)
11509         (compare (match_operand:GPR 0 "gpc_reg_operand" "")
11510                  (match_operand:GPR 1 "reg_or_short_operand" "")))]
11511   ""
11512   "
11513 {
11514   /* Take care of the possibility that operands[1] might be negative but
11515      this might be a logical operation.  That insn doesn't exist.  */
11516   if (GET_CODE (operands[1]) == CONST_INT
11517       && INTVAL (operands[1]) < 0)
11518     operands[1] = force_reg (<MODE>mode, operands[1]);
11519
11520   rs6000_compare_op0 = operands[0];
11521   rs6000_compare_op1 = operands[1];
11522   rs6000_compare_fp_p = 0;
11523   DONE;
11524 }")
11525
11526 (define_expand "cmp<mode>"
11527   [(set (cc0) (compare (match_operand:FP 0 "gpc_reg_operand" "")
11528                        (match_operand:FP 1 "gpc_reg_operand" "")))]
11529   ""
11530   "
11531 {
11532   rs6000_compare_op0 = operands[0];
11533   rs6000_compare_op1 = operands[1];
11534   rs6000_compare_fp_p = 1;
11535   DONE;
11536 }")
11537
11538 (define_expand "beq"
11539   [(use (match_operand 0 "" ""))]
11540   ""
11541   "{ rs6000_emit_cbranch (EQ, operands[0]); DONE; }")
11542
11543 (define_expand "bne"
11544   [(use (match_operand 0 "" ""))]
11545   ""
11546   "{ rs6000_emit_cbranch (NE, operands[0]); DONE; }")
11547
11548 (define_expand "bge"
11549   [(use (match_operand 0 "" ""))]
11550   ""
11551   "{ rs6000_emit_cbranch (GE, operands[0]); DONE; }")
11552
11553 (define_expand "bgt"
11554   [(use (match_operand 0 "" ""))]
11555   ""
11556   "{ rs6000_emit_cbranch (GT, operands[0]); DONE; }")
11557
11558 (define_expand "ble"
11559   [(use (match_operand 0 "" ""))]
11560   ""
11561   "{ rs6000_emit_cbranch (LE, operands[0]); DONE; }")
11562
11563 (define_expand "blt"
11564   [(use (match_operand 0 "" ""))]
11565   ""
11566   "{ rs6000_emit_cbranch (LT, operands[0]); DONE; }")
11567
11568 (define_expand "bgeu"
11569   [(use (match_operand 0 "" ""))]
11570   ""
11571   "{ rs6000_emit_cbranch (GEU, operands[0]); DONE; }")
11572
11573 (define_expand "bgtu"
11574   [(use (match_operand 0 "" ""))]
11575   ""
11576   "{ rs6000_emit_cbranch (GTU, operands[0]); DONE; }")
11577
11578 (define_expand "bleu"
11579   [(use (match_operand 0 "" ""))]
11580   ""
11581   "{ rs6000_emit_cbranch (LEU, operands[0]); DONE; }")
11582
11583 (define_expand "bltu"
11584   [(use (match_operand 0 "" ""))]
11585   ""
11586   "{ rs6000_emit_cbranch (LTU, operands[0]); DONE; }")
11587
11588 (define_expand "bunordered"
11589   [(use (match_operand 0 "" ""))]
11590   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11591   "{ rs6000_emit_cbranch (UNORDERED, operands[0]); DONE; }")
11592
11593 (define_expand "bordered"
11594   [(use (match_operand 0 "" ""))]
11595   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11596   "{ rs6000_emit_cbranch (ORDERED, operands[0]); DONE; }")
11597
11598 (define_expand "buneq"
11599   [(use (match_operand 0 "" ""))]
11600   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11601   "{ rs6000_emit_cbranch (UNEQ, operands[0]); DONE; }")
11602
11603 (define_expand "bunge"
11604   [(use (match_operand 0 "" ""))]
11605   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11606   "{ rs6000_emit_cbranch (UNGE, operands[0]); DONE; }")
11607
11608 (define_expand "bungt"
11609   [(use (match_operand 0 "" ""))]
11610   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11611   "{ rs6000_emit_cbranch (UNGT, operands[0]); DONE; }")
11612
11613 (define_expand "bunle"
11614   [(use (match_operand 0 "" ""))]
11615   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11616   "{ rs6000_emit_cbranch (UNLE, operands[0]); DONE; }")
11617
11618 (define_expand "bunlt"
11619   [(use (match_operand 0 "" ""))]
11620   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11621   "{ rs6000_emit_cbranch (UNLT, operands[0]); DONE; }")
11622
11623 (define_expand "bltgt"
11624   [(use (match_operand 0 "" ""))]
11625   ""
11626   "{ rs6000_emit_cbranch (LTGT, operands[0]); DONE; }")
11627
11628 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
11629 ;; For SEQ, likewise, except that comparisons with zero should be done
11630 ;; with an scc insns.  However, due to the order that combine see the
11631 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
11632 ;; the cases we don't want to handle.
11633 (define_expand "seq"
11634   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11635   ""
11636   "{ rs6000_emit_sCOND (EQ, operands[0]); DONE; }")
11637
11638 (define_expand "sne"
11639   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11640   ""
11641   "
11642 {
11643   if (! rs6000_compare_fp_p)
11644     FAIL;
11645
11646   rs6000_emit_sCOND (NE, operands[0]);
11647   DONE;
11648 }")
11649
11650 ;; A >= 0 is best done the portable way for A an integer.
11651 (define_expand "sge"
11652   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11653   ""
11654   "
11655 {
11656   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11657     FAIL;
11658
11659   rs6000_emit_sCOND (GE, operands[0]);
11660   DONE;
11661 }")
11662
11663 ;; A > 0 is best done using the portable sequence, so fail in that case.
11664 (define_expand "sgt"
11665   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11666   ""
11667   "
11668 {
11669   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11670     FAIL;
11671
11672   rs6000_emit_sCOND (GT, operands[0]);
11673   DONE;
11674 }")
11675
11676 ;; A <= 0 is best done the portable way for A an integer.
11677 (define_expand "sle"
11678   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11679   ""
11680   "
11681 {
11682   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11683     FAIL;
11684
11685   rs6000_emit_sCOND (LE, operands[0]);
11686   DONE;
11687 }")
11688
11689 ;; A < 0 is best done in the portable way for A an integer.
11690 (define_expand "slt"
11691   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11692   ""
11693   "
11694 {
11695   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11696     FAIL;
11697
11698   rs6000_emit_sCOND (LT, operands[0]);
11699   DONE;
11700 }")
11701
11702 (define_expand "sgeu"
11703   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11704   ""
11705   "{ rs6000_emit_sCOND (GEU, operands[0]); DONE; }")
11706
11707 (define_expand "sgtu"
11708   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11709   ""
11710   "{ rs6000_emit_sCOND (GTU, operands[0]); DONE; }")
11711
11712 (define_expand "sleu"
11713   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11714   ""
11715   "{ rs6000_emit_sCOND (LEU, operands[0]); DONE; }")
11716
11717 (define_expand "sltu"
11718   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11719   ""
11720   "{ rs6000_emit_sCOND (LTU, operands[0]); DONE; }")
11721
11722 (define_expand "sunordered"
11723   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11724   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11725   "{ rs6000_emit_sCOND (UNORDERED, operands[0]); DONE; }")
11726
11727 (define_expand "sordered"
11728   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11729   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11730   "{ rs6000_emit_sCOND (ORDERED, operands[0]); DONE; }")
11731
11732 (define_expand "suneq"
11733   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11734   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11735   "{ rs6000_emit_sCOND (UNEQ, operands[0]); DONE; }")
11736
11737 (define_expand "sunge"
11738   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11739   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11740   "{ rs6000_emit_sCOND (UNGE, operands[0]); DONE; }")
11741
11742 (define_expand "sungt"
11743   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11744   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11745   "{ rs6000_emit_sCOND (UNGT, operands[0]); DONE; }")
11746
11747 (define_expand "sunle"
11748   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11749   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11750   "{ rs6000_emit_sCOND (UNLE, operands[0]); DONE; }")
11751
11752 (define_expand "sunlt"
11753   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11754   "! (TARGET_HARD_FLOAT && !TARGET_FPRS)"
11755   "{ rs6000_emit_sCOND (UNLT, operands[0]); DONE; }")
11756
11757 (define_expand "sltgt"
11758   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11759   ""
11760   "{ rs6000_emit_sCOND (LTGT, operands[0]); DONE; }")
11761
11762 (define_expand "stack_protect_set"
11763   [(match_operand 0 "memory_operand" "")
11764    (match_operand 1 "memory_operand" "")]
11765   ""
11766 {
11767 #ifdef TARGET_THREAD_SSP_OFFSET
11768   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
11769   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
11770   operands[1] = gen_rtx_MEM (Pmode, addr);
11771 #endif
11772   if (TARGET_64BIT)
11773     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
11774   else
11775     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
11776   DONE;
11777 })
11778
11779 (define_insn "stack_protect_setsi"
11780   [(set (match_operand:SI 0 "memory_operand" "=m")
11781         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
11782    (set (match_scratch:SI 2 "=&r") (const_int 0))]
11783   "TARGET_32BIT"
11784   "{l%U1%X1|lwz%U1%X1} %2,%1\;{st%U0%X0|stw%U0%X0} %2,%0\;{lil|li} %2,0"
11785   [(set_attr "type" "three")
11786    (set_attr "length" "12")])
11787
11788 (define_insn "stack_protect_setdi"
11789   [(set (match_operand:DI 0 "memory_operand" "=m")
11790         (unspec:DI [(match_operand:DI 1 "memory_operand" "m")] UNSPEC_SP_SET))
11791    (set (match_scratch:DI 2 "=&r") (const_int 0))]
11792   "TARGET_64BIT"
11793   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;{lil|li} %2,0"
11794   [(set_attr "type" "three")
11795    (set_attr "length" "12")])
11796
11797 (define_expand "stack_protect_test"
11798   [(match_operand 0 "memory_operand" "")
11799    (match_operand 1 "memory_operand" "")
11800    (match_operand 2 "" "")]
11801   ""
11802 {
11803 #ifdef TARGET_THREAD_SSP_OFFSET
11804   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
11805   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
11806   operands[1] = gen_rtx_MEM (Pmode, addr);
11807 #endif
11808   rs6000_compare_op0 = operands[0];
11809   rs6000_compare_op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]),
11810                                        UNSPEC_SP_TEST);
11811   rs6000_compare_fp_p = 0;
11812   emit_jump_insn (gen_beq (operands[2]));
11813   DONE;
11814 })
11815
11816 (define_insn "stack_protect_testsi"
11817   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
11818         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
11819                       (match_operand:SI 2 "memory_operand" "m,m")]
11820                      UNSPEC_SP_TEST))
11821    (set (match_scratch:SI 4 "=r,r") (const_int 0))
11822    (clobber (match_scratch:SI 3 "=&r,&r"))]
11823   "TARGET_32BIT"
11824   "@
11825    {l%U1%X1|lwz%U1%X1} %3,%1\;{l%U2%X2|lwz%U2%X2} %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
11826    {l%U1%X1|lwz%U1%X1} %3,%1\;{l%U2%X2|lwz%U2%X2} %4,%2\;{cmpl|cmplw} %0,%3,%4\;{lil|li} %3,0\;{lil|li} %4,0"
11827   [(set_attr "length" "16,20")])
11828
11829 (define_insn "stack_protect_testdi"
11830   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
11831         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "m,m")
11832                       (match_operand:DI 2 "memory_operand" "m,m")]
11833                      UNSPEC_SP_TEST))
11834    (set (match_scratch:DI 4 "=r,r") (const_int 0))
11835    (clobber (match_scratch:DI 3 "=&r,&r"))]
11836   "TARGET_64BIT"
11837   "@
11838    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
11839    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;{lil|li} %3,0\;{lil|li} %4,0"
11840   [(set_attr "length" "16,20")])
11841
11842 \f
11843 ;; Here are the actual compare insns.
11844 (define_insn "*cmp<mode>_internal1"
11845   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11846         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
11847                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
11848   ""
11849   "{cmp%I2|cmp<wd>%I2} %0,%1,%2"
11850   [(set_attr "type" "cmp")])
11851
11852 ;; If we are comparing a register for equality with a large constant,
11853 ;; we can do this with an XOR followed by a compare.  But this is profitable
11854 ;; only if the large constant is only used for the comparison (and in this
11855 ;; case we already have a register to reuse as scratch).
11856 ;;
11857 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
11858 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
11859
11860 (define_peephole2
11861   [(set (match_operand:SI 0 "register_operand")
11862         (match_operand:SI 1 "logical_const_operand" ""))
11863    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
11864                        [(match_dup 0)
11865                         (match_operand:SI 2 "logical_const_operand" "")]))
11866    (set (match_operand:CC 4 "cc_reg_operand" "")
11867         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
11868                     (match_dup 0)))
11869    (set (pc)
11870         (if_then_else (match_operator 6 "equality_operator"
11871                        [(match_dup 4) (const_int 0)])
11872                       (match_operand 7 "" "")
11873                       (match_operand 8 "" "")))]
11874   "peep2_reg_dead_p (3, operands[0])
11875    && peep2_reg_dead_p (4, operands[4])"
11876  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
11877   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
11878   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
11879  
11880 {
11881   /* Get the constant we are comparing against, and see what it looks like
11882      when sign-extended from 16 to 32 bits.  Then see what constant we could
11883      XOR with SEXTC to get the sign-extended value.  */
11884   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
11885                                               SImode,
11886                                               operands[1], operands[2]);
11887   HOST_WIDE_INT c = INTVAL (cnst);
11888   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
11889   HOST_WIDE_INT xorv = c ^ sextc;
11890
11891   operands[9] = GEN_INT (xorv);
11892   operands[10] = GEN_INT (sextc);
11893 })
11894
11895 (define_insn "*cmpsi_internal2"
11896   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11897         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11898                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
11899   ""
11900   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
11901   [(set_attr "type" "cmp")])
11902
11903 (define_insn "*cmpdi_internal2"
11904   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11905         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
11906                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
11907   ""
11908   "cmpld%I2 %0,%1,%b2"
11909   [(set_attr "type" "cmp")])
11910
11911 ;; The following two insns don't exist as single insns, but if we provide
11912 ;; them, we can swap an add and compare, which will enable us to overlap more
11913 ;; of the required delay between a compare and branch.  We generate code for
11914 ;; them by splitting.
11915
11916 (define_insn ""
11917   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11918         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11919                     (match_operand:SI 2 "short_cint_operand" "i")))
11920    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11921         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11922   ""
11923   "#"
11924   [(set_attr "length" "8")])
11925
11926 (define_insn ""
11927   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
11928         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11929                        (match_operand:SI 2 "u_short_cint_operand" "i")))
11930    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11931         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11932   ""
11933   "#"
11934   [(set_attr "length" "8")])
11935
11936 (define_split
11937   [(set (match_operand:CC 3 "cc_reg_operand" "")
11938         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11939                     (match_operand:SI 2 "short_cint_operand" "")))
11940    (set (match_operand:SI 0 "gpc_reg_operand" "")
11941         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11942   ""
11943   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
11944    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11945
11946 (define_split
11947   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
11948         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
11949                        (match_operand:SI 2 "u_short_cint_operand" "")))
11950    (set (match_operand:SI 0 "gpc_reg_operand" "")
11951         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11952   ""
11953   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
11954    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11955
11956 (define_insn "*cmpsf_internal1"
11957   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11958         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
11959                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
11960   "TARGET_HARD_FLOAT && TARGET_FPRS"
11961   "fcmpu %0,%1,%2"
11962   [(set_attr "type" "fpcompare")])
11963
11964 (define_insn "*cmpdf_internal1"
11965   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11966         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
11967                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
11968   "TARGET_HARD_FLOAT && TARGET_FPRS"
11969   "fcmpu %0,%1,%2"
11970   [(set_attr "type" "fpcompare")])
11971
11972 ;; Only need to compare second words if first words equal
11973 (define_insn "*cmptf_internal1"
11974   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11975         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11976                       (match_operand:TF 2 "gpc_reg_operand" "f")))]
11977   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
11978    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11979   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
11980   [(set_attr "type" "fpcompare")
11981    (set_attr "length" "12")])
11982
11983 (define_insn_and_split "*cmptf_internal2"
11984   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11985         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11986                       (match_operand:TF 2 "gpc_reg_operand" "f")))
11987     (clobber (match_scratch:DF 3 "=f"))
11988     (clobber (match_scratch:DF 4 "=f"))
11989     (clobber (match_scratch:DF 5 "=f"))
11990     (clobber (match_scratch:DF 6 "=f"))
11991     (clobber (match_scratch:DF 7 "=f"))
11992     (clobber (match_scratch:DF 8 "=f"))
11993     (clobber (match_scratch:DF 9 "=f"))
11994     (clobber (match_scratch:DF 10 "=f"))]
11995   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
11996    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11997   "#"
11998   "&& reload_completed"
11999   [(set (match_dup 3) (match_dup 13))
12000    (set (match_dup 4) (match_dup 14))
12001    (set (match_dup 9) (abs:DF (match_dup 5)))
12002    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
12003    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
12004                            (label_ref (match_dup 11))
12005                            (pc)))
12006    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
12007    (set (pc) (label_ref (match_dup 12)))
12008    (match_dup 11)
12009    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
12010    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
12011    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
12012    (set (match_dup 0) (compare:CCFP (match_dup 7) (match_dup 4)))
12013    (match_dup 12)]
12014 {
12015   REAL_VALUE_TYPE rv;
12016   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
12017   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
12018
12019   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
12020   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
12021   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
12022   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
12023   operands[11] = gen_label_rtx ();
12024   operands[12] = gen_label_rtx ();
12025   real_inf (&rv);
12026   operands[13] = force_const_mem (DFmode,
12027                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
12028   operands[14] = force_const_mem (DFmode,
12029                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
12030                                                                 DFmode));
12031   if (TARGET_TOC)
12032     {
12033       operands[13] = gen_const_mem (DFmode,
12034                                     create_TOC_reference (XEXP (operands[13], 0)));
12035       operands[14] = gen_const_mem (DFmode,
12036                                     create_TOC_reference (XEXP (operands[14], 0)));
12037       set_mem_alias_set (operands[13], get_TOC_alias_set ());
12038       set_mem_alias_set (operands[14], get_TOC_alias_set ());
12039     }
12040 })
12041 \f
12042 ;; Now we have the scc insns.  We can do some combinations because of the
12043 ;; way the machine works.
12044 ;;
12045 ;; Note that this is probably faster if we can put an insn between the
12046 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
12047 ;; cases the insns below which don't use an intermediate CR field will
12048 ;; be used instead.
12049 (define_insn ""
12050   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12051         (match_operator:SI 1 "scc_comparison_operator"
12052                            [(match_operand 2 "cc_reg_operand" "y")
12053                             (const_int 0)]))]
12054   ""
12055   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
12056   [(set (attr "type")
12057      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
12058                 (const_string "mfcrf")
12059            ]
12060         (const_string "mfcr")))
12061    (set_attr "length" "8")])
12062
12063 ;; Same as above, but get the GT bit.
12064 (define_insn "move_from_CR_gt_bit"
12065   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12066         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
12067   "TARGET_E500"
12068   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,31,31"
12069   [(set_attr "type" "mfcr")
12070    (set_attr "length" "8")])
12071
12072 ;; Same as above, but get the OV/ORDERED bit.
12073 (define_insn "move_from_CR_ov_bit"
12074   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12075         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
12076   "TARGET_ISEL"
12077   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
12078   [(set_attr "type" "mfcr")
12079    (set_attr "length" "8")])
12080
12081 (define_insn ""
12082   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12083         (match_operator:DI 1 "scc_comparison_operator"
12084                            [(match_operand 2 "cc_reg_operand" "y")
12085                             (const_int 0)]))]
12086   "TARGET_POWERPC64"
12087   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
12088   [(set (attr "type")
12089      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
12090                 (const_string "mfcrf")
12091            ]
12092         (const_string "mfcr")))
12093    (set_attr "length" "8")])
12094
12095 (define_insn ""
12096   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12097         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
12098                                        [(match_operand 2 "cc_reg_operand" "y,y")
12099                                         (const_int 0)])
12100                     (const_int 0)))
12101    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
12102         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
12103   "TARGET_32BIT"
12104   "@
12105    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
12106    #"
12107   [(set_attr "type" "delayed_compare")
12108    (set_attr "length" "8,16")])
12109
12110 (define_split
12111   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12112         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
12113                                        [(match_operand 2 "cc_reg_operand" "")
12114                                         (const_int 0)])
12115                     (const_int 0)))
12116    (set (match_operand:SI 3 "gpc_reg_operand" "")
12117         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
12118   "TARGET_32BIT && reload_completed"
12119   [(set (match_dup 3)
12120         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
12121    (set (match_dup 0)
12122         (compare:CC (match_dup 3)
12123                     (const_int 0)))]
12124   "")
12125
12126 (define_insn ""
12127   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12128         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
12129                                       [(match_operand 2 "cc_reg_operand" "y")
12130                                        (const_int 0)])
12131                    (match_operand:SI 3 "const_int_operand" "n")))]
12132   ""
12133   "*
12134 {
12135   int is_bit = ccr_bit (operands[1], 1);
12136   int put_bit = 31 - (INTVAL (operands[3]) & 31);
12137   int count;
12138
12139   if (is_bit >= put_bit)
12140     count = is_bit - put_bit;
12141   else
12142     count = 32 - (put_bit - is_bit);
12143
12144   operands[4] = GEN_INT (count);
12145   operands[5] = GEN_INT (put_bit);
12146
12147   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
12148 }"
12149   [(set (attr "type")
12150      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
12151                 (const_string "mfcrf")
12152            ]
12153         (const_string "mfcr")))
12154    (set_attr "length" "8")])
12155
12156 (define_insn ""
12157   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12158         (compare:CC
12159          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
12160                                        [(match_operand 2 "cc_reg_operand" "y,y")
12161                                         (const_int 0)])
12162                     (match_operand:SI 3 "const_int_operand" "n,n"))
12163          (const_int 0)))
12164    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
12165         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
12166                    (match_dup 3)))]
12167   ""
12168   "*
12169 {
12170   int is_bit = ccr_bit (operands[1], 1);
12171   int put_bit = 31 - (INTVAL (operands[3]) & 31);
12172   int count;
12173
12174   /* Force split for non-cc0 compare.  */
12175   if (which_alternative == 1)
12176      return \"#\";
12177
12178   if (is_bit >= put_bit)
12179     count = is_bit - put_bit;
12180   else
12181     count = 32 - (put_bit - is_bit);
12182
12183   operands[5] = GEN_INT (count);
12184   operands[6] = GEN_INT (put_bit);
12185
12186   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
12187 }"
12188   [(set_attr "type" "delayed_compare")
12189    (set_attr "length" "8,16")])
12190
12191 (define_split
12192   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12193         (compare:CC
12194          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
12195                                        [(match_operand 2 "cc_reg_operand" "")
12196                                         (const_int 0)])
12197                     (match_operand:SI 3 "const_int_operand" ""))
12198          (const_int 0)))
12199    (set (match_operand:SI 4 "gpc_reg_operand" "")
12200         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
12201                    (match_dup 3)))]
12202   "reload_completed"
12203   [(set (match_dup 4)
12204         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
12205                    (match_dup 3)))
12206    (set (match_dup 0)
12207         (compare:CC (match_dup 4)
12208                     (const_int 0)))]
12209   "")
12210
12211 ;; There is a 3 cycle delay between consecutive mfcr instructions
12212 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
12213
12214 (define_peephole
12215   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12216         (match_operator:SI 1 "scc_comparison_operator"
12217                            [(match_operand 2 "cc_reg_operand" "y")
12218                             (const_int 0)]))
12219    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
12220         (match_operator:SI 4 "scc_comparison_operator"
12221                            [(match_operand 5 "cc_reg_operand" "y")
12222                             (const_int 0)]))]
12223   "REGNO (operands[2]) != REGNO (operands[5])"
12224   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
12225   [(set_attr "type" "mfcr")
12226    (set_attr "length" "12")])
12227
12228 (define_peephole
12229   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12230         (match_operator:DI 1 "scc_comparison_operator"
12231                            [(match_operand 2 "cc_reg_operand" "y")
12232                             (const_int 0)]))
12233    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
12234         (match_operator:DI 4 "scc_comparison_operator"
12235                            [(match_operand 5 "cc_reg_operand" "y")
12236                             (const_int 0)]))]
12237   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
12238   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
12239   [(set_attr "type" "mfcr")
12240    (set_attr "length" "12")])
12241
12242 ;; There are some scc insns that can be done directly, without a compare.
12243 ;; These are faster because they don't involve the communications between
12244 ;; the FXU and branch units.   In fact, we will be replacing all of the
12245 ;; integer scc insns here or in the portable methods in emit_store_flag.
12246 ;;
12247 ;; Also support (neg (scc ..)) since that construct is used to replace
12248 ;; branches, (plus (scc ..) ..) since that construct is common and
12249 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
12250 ;; cases where it is no more expensive than (neg (scc ..)).
12251
12252 ;; Have reload force a constant into a register for the simple insns that
12253 ;; otherwise won't accept constants.  We do this because it is faster than
12254 ;; the cmp/mfcr sequence we would otherwise generate.
12255
12256 (define_mode_attr scc_eq_op2 [(SI "rKLI")
12257                               (DI "rKJI")])
12258
12259 (define_insn_and_split "*eq<mode>"
12260   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
12261         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
12262                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
12263   "!TARGET_POWER"
12264   "#"
12265   "!TARGET_POWER"
12266   [(set (match_dup 0)
12267         (clz:GPR (match_dup 3)))
12268    (set (match_dup 0)
12269         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
12270   {
12271     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
12272       {
12273         /* Use output operand as intermediate.  */
12274         operands[3] = operands[0];
12275
12276         if (logical_operand (operands[2], <MODE>mode))
12277           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12278                                   gen_rtx_XOR (<MODE>mode,
12279                                                operands[1], operands[2])));
12280         else
12281           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12282                                   gen_rtx_PLUS (<MODE>mode, operands[1],
12283                                                 negate_rtx (<MODE>mode,
12284                                                             operands[2]))));
12285       }
12286     else
12287       operands[3] = operands[1];
12288
12289     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
12290   })
12291
12292 (define_insn_and_split "*eq<mode>_compare"
12293   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
12294         (compare:CC
12295          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
12296                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
12297          (const_int 0)))
12298    (set (match_operand:P 0 "gpc_reg_operand" "=r")
12299         (eq:P (match_dup 1) (match_dup 2)))]
12300   "!TARGET_POWER && optimize_size"
12301   "#"
12302   "!TARGET_POWER && optimize_size"
12303   [(set (match_dup 0)
12304         (clz:P (match_dup 4)))
12305    (parallel [(set (match_dup 3)
12306                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
12307                                (const_int 0)))
12308               (set (match_dup 0)
12309                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
12310   {
12311     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
12312       {
12313         /* Use output operand as intermediate.  */
12314         operands[4] = operands[0];
12315
12316         if (logical_operand (operands[2], <MODE>mode))
12317           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
12318                                   gen_rtx_XOR (<MODE>mode,
12319                                                operands[1], operands[2])));
12320         else
12321           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
12322                                   gen_rtx_PLUS (<MODE>mode, operands[1],
12323                                                 negate_rtx (<MODE>mode,
12324                                                             operands[2]))));
12325       }
12326     else
12327       operands[4] = operands[1];
12328
12329     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
12330   })
12331
12332 (define_insn "*eqsi_power"
12333   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
12334         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
12335                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
12336    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
12337   "TARGET_POWER"
12338   "@
12339    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
12340    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
12341    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
12342    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
12343    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
12344   [(set_attr "type" "three,two,three,three,three")
12345    (set_attr "length" "12,8,12,12,12")])
12346
12347 ;; We have insns of the form shown by the first define_insn below.  If
12348 ;; there is something inside the comparison operation, we must split it.
12349 (define_split
12350   [(set (match_operand:SI 0 "gpc_reg_operand" "")
12351         (plus:SI (match_operator 1 "comparison_operator"
12352                                  [(match_operand:SI 2 "" "")
12353                                   (match_operand:SI 3
12354                                                     "reg_or_cint_operand" "")])
12355                  (match_operand:SI 4 "gpc_reg_operand" "")))
12356    (clobber (match_operand:SI 5 "register_operand" ""))]
12357   "! gpc_reg_operand (operands[2], SImode)"
12358   [(set (match_dup 5) (match_dup 2))
12359    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
12360                                (match_dup 4)))])
12361
12362 (define_insn "*plus_eqsi"
12363   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
12364         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
12365                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
12366                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
12367   "TARGET_32BIT"
12368   "@
12369    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
12370    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
12371    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
12372    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
12373    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
12374   [(set_attr "type" "three,two,three,three,three")
12375    (set_attr "length" "12,8,12,12,12")])
12376
12377 (define_insn "*compare_plus_eqsi"
12378   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
12379         (compare:CC
12380          (plus:SI
12381           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
12382                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
12383           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
12384          (const_int 0)))
12385    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
12386   "TARGET_32BIT && optimize_size"
12387   "@
12388    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12389    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
12390    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12391    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12392    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12393    #
12394    #
12395    #
12396    #
12397    #"
12398   [(set_attr "type" "compare")
12399    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
12400
12401 (define_split
12402   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12403         (compare:CC
12404          (plus:SI
12405           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
12406                  (match_operand:SI 2 "scc_eq_operand" ""))
12407           (match_operand:SI 3 "gpc_reg_operand" ""))
12408          (const_int 0)))
12409    (clobber (match_scratch:SI 4 ""))]
12410   "TARGET_32BIT && optimize_size && reload_completed"
12411   [(set (match_dup 4)
12412         (plus:SI (eq:SI (match_dup 1)
12413                  (match_dup 2))
12414           (match_dup 3)))
12415    (set (match_dup 0)
12416         (compare:CC (match_dup 4)
12417                     (const_int 0)))]
12418   "")
12419
12420 (define_insn "*plus_eqsi_compare"
12421   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
12422         (compare:CC
12423          (plus:SI
12424           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
12425                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
12426           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
12427          (const_int 0)))
12428    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
12429         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12430   "TARGET_32BIT && optimize_size"
12431   "@
12432    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12433    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
12434    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12435    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12436    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12437    #
12438    #
12439    #
12440    #
12441    #"
12442   [(set_attr "type" "compare")
12443    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
12444
12445 (define_split
12446   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12447         (compare:CC
12448          (plus:SI
12449           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
12450                  (match_operand:SI 2 "scc_eq_operand" ""))
12451           (match_operand:SI 3 "gpc_reg_operand" ""))
12452          (const_int 0)))
12453    (set (match_operand:SI 0 "gpc_reg_operand" "")
12454         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12455   "TARGET_32BIT && optimize_size && reload_completed"
12456   [(set (match_dup 0)
12457         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12458    (set (match_dup 4)
12459         (compare:CC (match_dup 0)
12460                     (const_int 0)))]
12461   "")
12462
12463 (define_insn "*neg_eq0<mode>"
12464   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12465         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
12466                      (const_int 0))))]
12467   ""
12468   "{ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0"
12469   [(set_attr "type" "two")
12470    (set_attr "length" "8")])
12471
12472 (define_insn_and_split "*neg_eq<mode>"
12473   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12474         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
12475                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
12476   ""
12477   "#"
12478   ""
12479   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
12480   {
12481     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
12482       {
12483         /* Use output operand as intermediate.  */
12484         operands[3] = operands[0];
12485
12486         if (logical_operand (operands[2], <MODE>mode))
12487           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12488                                   gen_rtx_XOR (<MODE>mode,
12489                                                operands[1], operands[2])));
12490         else
12491           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12492                                   gen_rtx_PLUS (<MODE>mode, operands[1],
12493                                                 negate_rtx (<MODE>mode,
12494                                                             operands[2]))));
12495       }
12496     else
12497       operands[3] = operands[1];
12498   })
12499
12500 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
12501 ;; since it nabs/sr is just as fast.
12502 (define_insn "*ne0si"
12503   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12504         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
12505                      (const_int 31)))
12506    (clobber (match_scratch:SI 2 "=&r"))]
12507   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
12508   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
12509   [(set_attr "type" "two")
12510    (set_attr "length" "8")])
12511
12512 (define_insn "*ne0di"
12513   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12514         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
12515                      (const_int 63)))
12516    (clobber (match_scratch:DI 2 "=&r"))]
12517   "TARGET_64BIT"
12518   "addic %2,%1,-1\;subfe %0,%2,%1"
12519   [(set_attr "type" "two")
12520    (set_attr "length" "8")])
12521
12522 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
12523 (define_insn "*plus_ne0si"
12524   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12525         (plus:SI (lshiftrt:SI
12526                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
12527                   (const_int 31))
12528                  (match_operand:SI 2 "gpc_reg_operand" "r")))
12529    (clobber (match_scratch:SI 3 "=&r"))]
12530   "TARGET_32BIT"
12531   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
12532   [(set_attr "type" "two")
12533    (set_attr "length" "8")])
12534
12535 (define_insn "*plus_ne0di"
12536   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12537         (plus:DI (lshiftrt:DI
12538                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
12539                   (const_int 63))
12540                  (match_operand:DI 2 "gpc_reg_operand" "r")))
12541    (clobber (match_scratch:DI 3 "=&r"))]
12542   "TARGET_64BIT"
12543   "addic %3,%1,-1\;addze %0,%2"
12544   [(set_attr "type" "two")
12545    (set_attr "length" "8")])
12546
12547 (define_insn "*compare_plus_ne0si"
12548   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12549         (compare:CC
12550          (plus:SI (lshiftrt:SI
12551                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
12552                    (const_int 31))
12553                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
12554          (const_int 0)))
12555    (clobber (match_scratch:SI 3 "=&r,&r"))
12556    (clobber (match_scratch:SI 4 "=X,&r"))]
12557   "TARGET_32BIT"
12558   "@
12559    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
12560    #"
12561   [(set_attr "type" "compare")
12562    (set_attr "length" "8,12")])
12563
12564 (define_split
12565   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12566         (compare:CC
12567          (plus:SI (lshiftrt:SI
12568                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
12569                    (const_int 31))
12570                   (match_operand:SI 2 "gpc_reg_operand" ""))
12571          (const_int 0)))
12572    (clobber (match_scratch:SI 3 ""))
12573    (clobber (match_scratch:SI 4 ""))]
12574   "TARGET_32BIT && reload_completed"
12575   [(parallel [(set (match_dup 3)
12576                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
12577                                          (const_int 31))
12578                             (match_dup 2)))
12579               (clobber (match_dup 4))])
12580    (set (match_dup 0)
12581         (compare:CC (match_dup 3)
12582                     (const_int 0)))]
12583   "")
12584
12585 (define_insn "*compare_plus_ne0di"
12586   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12587         (compare:CC
12588          (plus:DI (lshiftrt:DI
12589                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
12590                    (const_int 63))
12591                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12592          (const_int 0)))
12593    (clobber (match_scratch:DI 3 "=&r,&r"))]
12594   "TARGET_64BIT"
12595   "@
12596    addic %3,%1,-1\;addze. %3,%2
12597    #"
12598   [(set_attr "type" "compare")
12599    (set_attr "length" "8,12")])
12600
12601 (define_split
12602   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12603         (compare:CC
12604          (plus:DI (lshiftrt:DI
12605                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
12606                    (const_int 63))
12607                   (match_operand:DI 2 "gpc_reg_operand" ""))
12608          (const_int 0)))
12609    (clobber (match_scratch:DI 3 ""))]
12610   "TARGET_64BIT && reload_completed"
12611   [(set (match_dup 3)
12612         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
12613                    (const_int 63))
12614                   (match_dup 2)))
12615    (set (match_dup 0)
12616         (compare:CC (match_dup 3)
12617                     (const_int 0)))]
12618   "")
12619
12620 (define_insn "*plus_ne0si_compare"
12621   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12622         (compare:CC
12623          (plus:SI (lshiftrt:SI
12624                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
12625                    (const_int 31))
12626                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
12627          (const_int 0)))
12628    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12629         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
12630                  (match_dup 2)))
12631    (clobber (match_scratch:SI 3 "=&r,&r"))]
12632   "TARGET_32BIT"
12633   "@
12634    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
12635    #"
12636   [(set_attr "type" "compare")
12637    (set_attr "length" "8,12")])
12638
12639 (define_split
12640   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12641         (compare:CC
12642          (plus:SI (lshiftrt:SI
12643                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
12644                    (const_int 31))
12645                   (match_operand:SI 2 "gpc_reg_operand" ""))
12646          (const_int 0)))
12647    (set (match_operand:SI 0 "gpc_reg_operand" "")
12648         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
12649                  (match_dup 2)))
12650    (clobber (match_scratch:SI 3 ""))]
12651   "TARGET_32BIT && reload_completed"
12652   [(parallel [(set (match_dup 0)
12653         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
12654                  (match_dup 2)))
12655    (clobber (match_dup 3))])
12656    (set (match_dup 4)
12657         (compare:CC (match_dup 0)
12658                     (const_int 0)))]
12659   "")
12660
12661 (define_insn "*plus_ne0di_compare"
12662   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12663         (compare:CC
12664          (plus:DI (lshiftrt:DI
12665                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
12666                    (const_int 63))
12667                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12668          (const_int 0)))
12669    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12670         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12671                  (match_dup 2)))
12672    (clobber (match_scratch:DI 3 "=&r,&r"))]
12673   "TARGET_64BIT"
12674   "@
12675    addic %3,%1,-1\;addze. %0,%2
12676    #"
12677   [(set_attr "type" "compare")
12678    (set_attr "length" "8,12")])
12679
12680 (define_split
12681   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12682         (compare:CC
12683          (plus:DI (lshiftrt:DI
12684                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
12685                    (const_int 63))
12686                   (match_operand:DI 2 "gpc_reg_operand" ""))
12687          (const_int 0)))
12688    (set (match_operand:DI 0 "gpc_reg_operand" "")
12689         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12690                  (match_dup 2)))
12691    (clobber (match_scratch:DI 3 ""))]
12692   "TARGET_64BIT && reload_completed"
12693   [(parallel [(set (match_dup 0)
12694         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12695                  (match_dup 2)))
12696    (clobber (match_dup 3))])
12697    (set (match_dup 4)
12698         (compare:CC (match_dup 0)
12699                     (const_int 0)))]
12700   "")
12701
12702 (define_insn ""
12703   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12704         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12705                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
12706    (clobber (match_scratch:SI 3 "=r,X"))]
12707   "TARGET_POWER"
12708   "@
12709    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
12710    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
12711   [(set_attr "length" "12")])
12712
12713 (define_insn ""
12714   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12715         (compare:CC
12716          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12717                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12718          (const_int 0)))
12719    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12720         (le:SI (match_dup 1) (match_dup 2)))
12721    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
12722   "TARGET_POWER"
12723   "@
12724    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12725    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
12726    #
12727    #"
12728   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
12729    (set_attr "length" "12,12,16,16")])
12730
12731 (define_split
12732   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12733         (compare:CC
12734          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12735                 (match_operand:SI 2 "reg_or_short_operand" ""))
12736          (const_int 0)))
12737    (set (match_operand:SI 0 "gpc_reg_operand" "")
12738         (le:SI (match_dup 1) (match_dup 2)))
12739    (clobber (match_scratch:SI 3 ""))]
12740   "TARGET_POWER && reload_completed"
12741   [(parallel [(set (match_dup 0)
12742         (le:SI (match_dup 1) (match_dup 2)))
12743    (clobber (match_dup 3))])
12744    (set (match_dup 4)
12745         (compare:CC (match_dup 0)
12746                     (const_int 0)))]
12747   "")
12748
12749 (define_insn ""
12750   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12751         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12752                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
12753                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12754   "TARGET_POWER"
12755   "@
12756    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
12757    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
12758   [(set_attr "length" "12")])
12759
12760 (define_insn ""
12761   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12762         (compare:CC
12763          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12764                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12765                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12766          (const_int 0)))
12767    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12768   "TARGET_POWER"
12769   "@
12770    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12771    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
12772    #
12773    #"
12774   [(set_attr "type" "compare")
12775    (set_attr "length" "12,12,16,16")])
12776
12777 (define_split
12778   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12779         (compare:CC
12780          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12781                          (match_operand:SI 2 "reg_or_short_operand" ""))
12782                   (match_operand:SI 3 "gpc_reg_operand" ""))
12783          (const_int 0)))
12784    (clobber (match_scratch:SI 4 ""))]
12785   "TARGET_POWER && reload_completed"
12786   [(set (match_dup 4)
12787         (plus:SI (le:SI (match_dup 1) (match_dup 2))
12788                  (match_dup 3)))
12789    (set (match_dup 0)
12790         (compare:CC (match_dup 4)
12791                     (const_int 0)))]
12792   "")
12793
12794 (define_insn ""
12795   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12796         (compare:CC
12797          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12798                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12799                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12800          (const_int 0)))
12801    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12802         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12803   "TARGET_POWER"
12804   "@
12805    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12806    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
12807    #
12808    #"
12809   [(set_attr "type" "compare")
12810    (set_attr "length" "12,12,16,16")])
12811
12812 (define_split
12813   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12814         (compare:CC
12815          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12816                          (match_operand:SI 2 "reg_or_short_operand" ""))
12817                   (match_operand:SI 3 "gpc_reg_operand" ""))
12818          (const_int 0)))
12819    (set (match_operand:SI 0 "gpc_reg_operand" "")
12820         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12821   "TARGET_POWER && reload_completed"
12822   [(set (match_dup 0)
12823         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12824    (set (match_dup 4)
12825         (compare:CC (match_dup 0)
12826                     (const_int 0)))]
12827   "")
12828
12829 (define_insn ""
12830   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12831         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12832                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
12833   "TARGET_POWER"
12834   "@
12835    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
12836    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
12837   [(set_attr "length" "12")])
12838
12839 (define_insn "*leu<mode>"
12840   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12841         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12842                (match_operand:P 2 "reg_or_short_operand" "rI")))]
12843   ""
12844   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12845   [(set_attr "type" "three")
12846    (set_attr "length" "12")])
12847
12848 (define_insn "*leu<mode>_compare"
12849   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12850         (compare:CC
12851          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12852                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
12853          (const_int 0)))
12854    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12855         (leu:P (match_dup 1) (match_dup 2)))]
12856   ""
12857   "@
12858    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12859    #"
12860   [(set_attr "type" "compare")
12861    (set_attr "length" "12,16")])
12862
12863 (define_split
12864   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12865         (compare:CC
12866          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
12867                 (match_operand:P 2 "reg_or_short_operand" ""))
12868          (const_int 0)))
12869    (set (match_operand:P 0 "gpc_reg_operand" "")
12870         (leu:P (match_dup 1) (match_dup 2)))]
12871   "reload_completed"
12872   [(set (match_dup 0)
12873         (leu:P (match_dup 1) (match_dup 2)))
12874    (set (match_dup 3)
12875         (compare:CC (match_dup 0)
12876                     (const_int 0)))]
12877   "")
12878
12879 (define_insn "*plus_leu<mode>"
12880   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12881         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12882                        (match_operand:P 2 "reg_or_short_operand" "rI"))
12883                 (match_operand:P 3 "gpc_reg_operand" "r")))]
12884   ""
12885   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
12886   [(set_attr "type" "two")
12887    (set_attr "length" "8")])
12888
12889 (define_insn ""
12890   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12891         (compare:CC
12892          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12893                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12894                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12895          (const_int 0)))
12896    (clobber (match_scratch:SI 4 "=&r,&r"))]
12897   "TARGET_32BIT"
12898   "@
12899    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
12900    #"
12901   [(set_attr "type" "compare")
12902    (set_attr "length" "8,12")])
12903
12904 (define_split
12905   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12906         (compare:CC
12907          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12908                           (match_operand:SI 2 "reg_or_short_operand" ""))
12909                   (match_operand:SI 3 "gpc_reg_operand" ""))
12910          (const_int 0)))
12911    (clobber (match_scratch:SI 4 ""))]
12912   "TARGET_32BIT && reload_completed"
12913   [(set (match_dup 4)
12914         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12915                   (match_dup 3)))
12916    (set (match_dup 0)
12917         (compare:CC (match_dup 4)
12918                     (const_int 0)))]
12919   "")
12920
12921 (define_insn ""
12922   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12923         (compare:CC
12924          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12925                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12926                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12927          (const_int 0)))
12928    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12929         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12930   "TARGET_32BIT"
12931   "@
12932    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
12933    #"
12934   [(set_attr "type" "compare")
12935    (set_attr "length" "8,12")])
12936
12937 (define_split
12938   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12939         (compare:CC
12940          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12941                           (match_operand:SI 2 "reg_or_short_operand" ""))
12942                   (match_operand:SI 3 "gpc_reg_operand" ""))
12943          (const_int 0)))
12944    (set (match_operand:SI 0 "gpc_reg_operand" "")
12945         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12946   "TARGET_32BIT && reload_completed"
12947   [(set (match_dup 0)
12948         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12949    (set (match_dup 4)
12950         (compare:CC (match_dup 0)
12951                     (const_int 0)))]
12952   "")
12953
12954 (define_insn "*neg_leu<mode>"
12955   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12956         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12957                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
12958   ""
12959   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
12960    [(set_attr "type" "three")
12961     (set_attr "length" "12")])
12962
12963 (define_insn "*and_neg_leu<mode>"
12964   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12965         (and:P (neg:P
12966                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12967                         (match_operand:P 2 "reg_or_short_operand" "rI")))
12968                 (match_operand:P 3 "gpc_reg_operand" "r")))]
12969   ""
12970   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12971   [(set_attr "type" "three")
12972    (set_attr "length" "12")])
12973
12974 (define_insn ""
12975   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12976         (compare:CC
12977          (and:SI (neg:SI
12978                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12979                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12980                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12981          (const_int 0)))
12982    (clobber (match_scratch:SI 4 "=&r,&r"))]
12983   "TARGET_32BIT"
12984   "@
12985    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12986    #"
12987   [(set_attr "type" "compare")
12988    (set_attr "length" "12,16")])
12989
12990 (define_split
12991   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12992         (compare:CC
12993          (and:SI (neg:SI
12994                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12995                           (match_operand:SI 2 "reg_or_short_operand" "")))
12996                  (match_operand:SI 3 "gpc_reg_operand" ""))
12997          (const_int 0)))
12998    (clobber (match_scratch:SI 4 ""))]
12999   "TARGET_32BIT && reload_completed"
13000   [(set (match_dup 4)
13001         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
13002                 (match_dup 3)))
13003    (set (match_dup 0)
13004         (compare:CC (match_dup 4)
13005                     (const_int 0)))]
13006   "")
13007
13008 (define_insn ""
13009   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13010         (compare:CC
13011          (and:SI (neg:SI
13012                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13013                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
13014                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13015          (const_int 0)))
13016    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13017         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13018   "TARGET_32BIT"
13019   "@
13020    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
13021    #"
13022   [(set_attr "type" "compare")
13023    (set_attr "length" "12,16")])
13024
13025 (define_split
13026   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13027         (compare:CC
13028          (and:SI (neg:SI
13029                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13030                           (match_operand:SI 2 "reg_or_short_operand" "")))
13031                  (match_operand:SI 3 "gpc_reg_operand" ""))
13032          (const_int 0)))
13033    (set (match_operand:SI 0 "gpc_reg_operand" "")
13034         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13035   "TARGET_32BIT && reload_completed"
13036   [(set (match_dup 0)
13037         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
13038                 (match_dup 3)))
13039    (set (match_dup 4)
13040         (compare:CC (match_dup 0)
13041                     (const_int 0)))]
13042   "")
13043
13044 (define_insn ""
13045   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13046         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13047                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
13048   "TARGET_POWER"
13049   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13050    [(set_attr "length" "12")])
13051
13052 (define_insn ""
13053   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13054         (compare:CC
13055          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13056                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13057          (const_int 0)))
13058    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13059         (lt:SI (match_dup 1) (match_dup 2)))]
13060   "TARGET_POWER"
13061   "@
13062    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13063    #"
13064   [(set_attr "type" "delayed_compare")
13065    (set_attr "length" "12,16")])
13066
13067 (define_split
13068   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13069         (compare:CC
13070          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13071                 (match_operand:SI 2 "reg_or_short_operand" ""))
13072          (const_int 0)))
13073    (set (match_operand:SI 0 "gpc_reg_operand" "")
13074         (lt:SI (match_dup 1) (match_dup 2)))]
13075   "TARGET_POWER && reload_completed"
13076   [(set (match_dup 0)
13077         (lt:SI (match_dup 1) (match_dup 2)))
13078    (set (match_dup 3)
13079         (compare:CC (match_dup 0)
13080                     (const_int 0)))]
13081   "")
13082
13083 (define_insn ""
13084   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13085         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13086                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
13087                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13088   "TARGET_POWER"
13089   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13090   [(set_attr "length" "12")])
13091
13092 (define_insn ""
13093   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13094         (compare:CC
13095          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13096                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13097                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13098          (const_int 0)))
13099    (clobber (match_scratch:SI 4 "=&r,&r"))]
13100   "TARGET_POWER"
13101   "@
13102    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13103    #"
13104   [(set_attr "type" "compare")
13105    (set_attr "length" "12,16")])
13106
13107 (define_split
13108   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13109         (compare:CC
13110          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13111                          (match_operand:SI 2 "reg_or_short_operand" ""))
13112                   (match_operand:SI 3 "gpc_reg_operand" ""))
13113          (const_int 0)))
13114    (clobber (match_scratch:SI 4 ""))]
13115   "TARGET_POWER && reload_completed"
13116   [(set (match_dup 4)
13117         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
13118                  (match_dup 3)))
13119    (set (match_dup 0)
13120         (compare:CC (match_dup 4)
13121                     (const_int 0)))]
13122   "")
13123
13124 (define_insn ""
13125   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13126         (compare:CC
13127          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13128                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13129                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13130          (const_int 0)))
13131    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13132         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13133   "TARGET_POWER"
13134   "@
13135    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13136    #"
13137   [(set_attr "type" "compare")
13138    (set_attr "length" "12,16")])
13139
13140 (define_split
13141   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13142         (compare:CC
13143          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13144                          (match_operand:SI 2 "reg_or_short_operand" ""))
13145                   (match_operand:SI 3 "gpc_reg_operand" ""))
13146          (const_int 0)))
13147    (set (match_operand:SI 0 "gpc_reg_operand" "")
13148         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13149   "TARGET_POWER && reload_completed"
13150   [(set (match_dup 0)
13151         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13152    (set (match_dup 4)
13153         (compare:CC (match_dup 0)
13154                     (const_int 0)))]
13155   "")
13156
13157 (define_insn ""
13158   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13159         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13160                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
13161   "TARGET_POWER"
13162   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13163   [(set_attr "length" "12")])
13164
13165 (define_insn_and_split "*ltu<mode>"
13166   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13167         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13168                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
13169   ""
13170   "#"
13171   ""
13172   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13173    (set (match_dup 0) (neg:P (match_dup 0)))]
13174   "")
13175
13176 (define_insn_and_split "*ltu<mode>_compare"
13177   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
13178         (compare:CC
13179          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13180                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13181          (const_int 0)))
13182    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
13183         (ltu:P (match_dup 1) (match_dup 2)))]
13184   ""
13185   "#"
13186   ""
13187   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13188    (parallel [(set (match_dup 3)
13189                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
13190               (set (match_dup 0) (neg:P (match_dup 0)))])]
13191   "")
13192
13193 (define_insn_and_split "*plus_ltu<mode>"
13194   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
13195         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13196                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
13197                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
13198   ""
13199   "#"
13200   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13201   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13202    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
13203   "")
13204
13205 (define_insn_and_split "*plus_ltu<mode>_compare"
13206   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13207         (compare:CC
13208          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13209                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13210                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
13211          (const_int 0)))
13212    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13213         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
13214   ""
13215   "#"
13216   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13217   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
13218    (parallel [(set (match_dup 4)
13219                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
13220                                (const_int 0)))
13221               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
13222   "")
13223
13224 (define_insn "*neg_ltu<mode>"
13225   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13226         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13227                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
13228   ""
13229   "@
13230    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
13231    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
13232   [(set_attr "type" "two")
13233    (set_attr "length" "8")])
13234
13235 (define_insn ""
13236   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13237         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13238                (match_operand:SI 2 "reg_or_short_operand" "rI")))
13239    (clobber (match_scratch:SI 3 "=r"))]
13240   "TARGET_POWER"
13241   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
13242    [(set_attr "length" "12")])
13243
13244 (define_insn ""
13245   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13246         (compare:CC
13247          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13248                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13249          (const_int 0)))
13250    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13251         (ge:SI (match_dup 1) (match_dup 2)))
13252    (clobber (match_scratch:SI 3 "=r,r"))]
13253   "TARGET_POWER"
13254   "@
13255    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
13256    #"
13257   [(set_attr "type" "compare")
13258    (set_attr "length" "12,16")])
13259
13260 (define_split
13261   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13262         (compare:CC
13263          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
13264                 (match_operand:SI 2 "reg_or_short_operand" ""))
13265          (const_int 0)))
13266    (set (match_operand:SI 0 "gpc_reg_operand" "")
13267         (ge:SI (match_dup 1) (match_dup 2)))
13268    (clobber (match_scratch:SI 3 ""))]
13269   "TARGET_POWER && reload_completed"
13270   [(parallel [(set (match_dup 0)
13271                    (ge:SI (match_dup 1) (match_dup 2)))
13272               (clobber (match_dup 3))])
13273    (set (match_dup 4)
13274         (compare:CC (match_dup 0)
13275                     (const_int 0)))]
13276   "")
13277
13278 (define_insn ""
13279   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13280         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13281                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
13282                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13283   "TARGET_POWER"
13284   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
13285   [(set_attr "length" "12")])
13286
13287 (define_insn ""
13288   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13289         (compare:CC
13290          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13291                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13292                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13293          (const_int 0)))
13294    (clobber (match_scratch:SI 4 "=&r,&r"))]
13295   "TARGET_POWER"
13296   "@
13297    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
13298    #"
13299   [(set_attr "type" "compare")
13300    (set_attr "length" "12,16")])
13301
13302 (define_split
13303   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13304         (compare:CC
13305          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
13306                          (match_operand:SI 2 "reg_or_short_operand" ""))
13307                   (match_operand:SI 3 "gpc_reg_operand" ""))
13308          (const_int 0)))
13309    (clobber (match_scratch:SI 4 ""))]
13310   "TARGET_POWER && reload_completed"
13311   [(set (match_dup 4)
13312         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
13313                  (match_dup 3)))
13314    (set (match_dup 0)
13315         (compare:CC (match_dup 4)
13316                     (const_int 0)))]
13317   "")
13318
13319 (define_insn ""
13320   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13321         (compare:CC
13322          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13323                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13324                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13325          (const_int 0)))
13326    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13327         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13328   "TARGET_POWER"
13329   "@
13330    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
13331    #"
13332   [(set_attr "type" "compare")
13333    (set_attr "length" "12,16")])
13334
13335 (define_split
13336   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13337         (compare:CC
13338          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
13339                          (match_operand:SI 2 "reg_or_short_operand" ""))
13340                   (match_operand:SI 3 "gpc_reg_operand" ""))
13341          (const_int 0)))
13342    (set (match_operand:SI 0 "gpc_reg_operand" "")
13343         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13344   "TARGET_POWER && reload_completed"
13345   [(set (match_dup 0)
13346         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13347    (set (match_dup 4)
13348         (compare:CC (match_dup 0)
13349                     (const_int 0)))]
13350   "")
13351
13352 (define_insn ""
13353   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13354         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13355                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
13356   "TARGET_POWER"
13357   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
13358   [(set_attr "length" "12")])
13359
13360 (define_insn "*geu<mode>"
13361   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13362         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13363                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
13364   ""
13365   "@
13366    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
13367    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
13368   [(set_attr "type" "three")
13369    (set_attr "length" "12")])
13370
13371 (define_insn "*geu<mode>_compare"
13372   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
13373         (compare:CC
13374          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13375                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
13376          (const_int 0)))
13377    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
13378         (geu:P (match_dup 1) (match_dup 2)))]
13379   ""
13380   "@
13381    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
13382    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
13383    #
13384    #"
13385   [(set_attr "type" "compare")
13386    (set_attr "length" "12,12,16,16")])
13387
13388 (define_split
13389   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13390         (compare:CC
13391          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
13392                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
13393          (const_int 0)))
13394    (set (match_operand:P 0 "gpc_reg_operand" "")
13395         (geu:P (match_dup 1) (match_dup 2)))]
13396   "reload_completed"
13397   [(set (match_dup 0)
13398         (geu:P (match_dup 1) (match_dup 2)))
13399    (set (match_dup 3)
13400         (compare:CC (match_dup 0)
13401                     (const_int 0)))]
13402   "")
13403
13404 (define_insn "*plus_geu<mode>"
13405   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
13406         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13407                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
13408                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
13409   ""
13410   "@
13411    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
13412    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
13413   [(set_attr "type" "two")
13414    (set_attr "length" "8")])
13415
13416 (define_insn ""
13417   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13418         (compare:CC
13419          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13420                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
13421                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13422          (const_int 0)))
13423    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13424   "TARGET_32BIT"
13425   "@
13426    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
13427    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
13428    #
13429    #"
13430   [(set_attr "type" "compare")
13431    (set_attr "length" "8,8,12,12")])
13432
13433 (define_split
13434   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13435         (compare:CC
13436          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13437                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
13438                   (match_operand:SI 3 "gpc_reg_operand" ""))
13439          (const_int 0)))
13440    (clobber (match_scratch:SI 4 ""))]
13441   "TARGET_32BIT && reload_completed"
13442   [(set (match_dup 4)
13443         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
13444                   (match_dup 3)))
13445    (set (match_dup 0)
13446         (compare:CC (match_dup 4)
13447                     (const_int 0)))]
13448   "")
13449
13450 (define_insn ""
13451   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13452         (compare:CC
13453          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13454                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
13455                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13456          (const_int 0)))
13457    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13458         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13459   "TARGET_32BIT"
13460   "@
13461    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
13462    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
13463    #
13464    #"
13465   [(set_attr "type" "compare")
13466    (set_attr "length" "8,8,12,12")])
13467
13468 (define_split
13469   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13470         (compare:CC
13471          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13472                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
13473                   (match_operand:SI 3 "gpc_reg_operand" ""))
13474          (const_int 0)))
13475    (set (match_operand:SI 0 "gpc_reg_operand" "")
13476         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13477   "TARGET_32BIT && reload_completed"
13478   [(set (match_dup 0)
13479         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13480    (set (match_dup 4)
13481         (compare:CC (match_dup 0)
13482                     (const_int 0)))]
13483   "")
13484
13485 (define_insn "*neg_geu<mode>"
13486   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13487         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13488                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
13489   ""
13490   "@
13491    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
13492    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
13493   [(set_attr "type" "three")
13494    (set_attr "length" "12")])
13495
13496 (define_insn "*and_neg_geu<mode>"
13497   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
13498         (and:P (neg:P
13499                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13500                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
13501                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
13502   ""
13503   "@
13504    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
13505    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
13506   [(set_attr "type" "three")
13507    (set_attr "length" "12")])
13508
13509 (define_insn ""
13510   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13511         (compare:CC
13512          (and:SI (neg:SI
13513                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13514                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
13515                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13516          (const_int 0)))
13517    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13518   "TARGET_32BIT"
13519   "@
13520    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
13521    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
13522    #
13523    #"
13524   [(set_attr "type" "compare")
13525    (set_attr "length" "12,12,16,16")])
13526
13527 (define_split
13528   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13529         (compare:CC
13530          (and:SI (neg:SI
13531                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13532                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
13533                  (match_operand:SI 3 "gpc_reg_operand" ""))
13534          (const_int 0)))
13535    (clobber (match_scratch:SI 4 ""))]
13536   "TARGET_32BIT && reload_completed"
13537   [(set (match_dup 4)
13538         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
13539                 (match_dup 3)))
13540    (set (match_dup 0)
13541         (compare:CC (match_dup 4)
13542                     (const_int 0)))]
13543   "")
13544
13545 (define_insn ""
13546   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13547         (compare:CC
13548          (and:SI (neg:SI
13549                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13550                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
13551                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13552          (const_int 0)))
13553    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13554         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13555   "TARGET_32BIT"
13556   "@
13557    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
13558    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
13559    #
13560    #"
13561   [(set_attr "type" "compare")
13562    (set_attr "length" "12,12,16,16")])
13563
13564 (define_split
13565   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13566         (compare:CC
13567          (and:SI (neg:SI
13568                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13569                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
13570                  (match_operand:SI 3 "gpc_reg_operand" ""))
13571          (const_int 0)))
13572    (set (match_operand:SI 0 "gpc_reg_operand" "")
13573         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13574   "TARGET_32BIT && reload_completed"
13575   [(set (match_dup 0)
13576         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
13577    (set (match_dup 4)
13578         (compare:CC (match_dup 0)
13579                     (const_int 0)))]
13580   "")
13581
13582 (define_insn ""
13583   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13584         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13585                (match_operand:SI 2 "reg_or_short_operand" "r")))]
13586   "TARGET_POWER"
13587   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13588   [(set_attr "length" "12")])
13589
13590 (define_insn ""
13591   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13592         (compare:CC
13593          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13594                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13595          (const_int 0)))
13596    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13597         (gt:SI (match_dup 1) (match_dup 2)))]
13598   "TARGET_POWER"
13599   "@
13600    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13601    #"
13602   [(set_attr "type" "delayed_compare")
13603    (set_attr "length" "12,16")])
13604
13605 (define_split
13606   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13607         (compare:CC
13608          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13609                 (match_operand:SI 2 "reg_or_short_operand" ""))
13610          (const_int 0)))
13611    (set (match_operand:SI 0 "gpc_reg_operand" "")
13612         (gt:SI (match_dup 1) (match_dup 2)))]
13613   "TARGET_POWER && reload_completed"
13614   [(set (match_dup 0)
13615         (gt:SI (match_dup 1) (match_dup 2)))
13616    (set (match_dup 3)
13617         (compare:CC (match_dup 0)
13618                     (const_int 0)))]
13619   "")
13620
13621 (define_insn "*plus_gt0<mode>"
13622   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13623         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
13624                       (const_int 0))
13625                  (match_operand:P 2 "gpc_reg_operand" "r")))]
13626   ""
13627   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
13628   [(set_attr "type" "three")
13629    (set_attr "length" "12")])
13630
13631 (define_insn ""
13632   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13633         (compare:CC
13634          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13635                          (const_int 0))
13636                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13637          (const_int 0)))
13638    (clobber (match_scratch:SI 3 "=&r,&r"))]
13639   "TARGET_32BIT"
13640   "@
13641    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
13642    #"
13643   [(set_attr "type" "compare")
13644    (set_attr "length" "12,16")])
13645
13646 (define_split
13647   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13648         (compare:CC
13649          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13650                          (const_int 0))
13651                   (match_operand:SI 2 "gpc_reg_operand" ""))
13652          (const_int 0)))
13653    (clobber (match_scratch:SI 3 ""))]
13654   "TARGET_32BIT && reload_completed"
13655   [(set (match_dup 3)
13656         (plus:SI (gt:SI (match_dup 1) (const_int 0))
13657                   (match_dup 2)))
13658    (set (match_dup 0)
13659         (compare:CC (match_dup 3)
13660                     (const_int 0)))]
13661   "")
13662
13663 (define_insn ""
13664   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13665         (compare:CC
13666          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13667                          (const_int 0))
13668                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13669          (const_int 0)))
13670    (clobber (match_scratch:DI 3 "=&r,&r"))]
13671   "TARGET_64BIT"
13672   "@
13673    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
13674    #"
13675   [(set_attr "type" "compare")
13676    (set_attr "length" "12,16")])
13677
13678 (define_split
13679   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13680         (compare:CC
13681          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13682                          (const_int 0))
13683                   (match_operand:DI 2 "gpc_reg_operand" ""))
13684          (const_int 0)))
13685    (clobber (match_scratch:DI 3 ""))]
13686   "TARGET_64BIT && reload_completed"
13687   [(set (match_dup 3)
13688         (plus:DI (gt:DI (match_dup 1) (const_int 0))
13689                  (match_dup 2)))
13690    (set (match_dup 0)
13691         (compare:CC (match_dup 3)
13692                     (const_int 0)))]
13693   "")
13694
13695 (define_insn ""
13696   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13697         (compare:CC
13698          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13699                          (const_int 0))
13700                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13701          (const_int 0)))
13702    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13703         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13704   "TARGET_32BIT"
13705   "@
13706    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
13707    #"
13708   [(set_attr "type" "compare")
13709    (set_attr "length" "12,16")])
13710
13711 (define_split
13712   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13713         (compare:CC
13714          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13715                          (const_int 0))
13716                   (match_operand:SI 2 "gpc_reg_operand" ""))
13717          (const_int 0)))
13718    (set (match_operand:SI 0 "gpc_reg_operand" "")
13719         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13720   "TARGET_32BIT && reload_completed"
13721   [(set (match_dup 0)
13722         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
13723    (set (match_dup 3)
13724         (compare:CC (match_dup 0)
13725                     (const_int 0)))]
13726   "")
13727
13728 (define_insn ""
13729   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13730         (compare:CC
13731          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13732                          (const_int 0))
13733                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13734          (const_int 0)))
13735    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13736         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13737   "TARGET_64BIT"
13738   "@
13739    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
13740    #"
13741   [(set_attr "type" "compare")
13742    (set_attr "length" "12,16")])
13743
13744 (define_split
13745   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13746         (compare:CC
13747          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13748                          (const_int 0))
13749                   (match_operand:DI 2 "gpc_reg_operand" ""))
13750          (const_int 0)))
13751    (set (match_operand:DI 0 "gpc_reg_operand" "")
13752         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13753   "TARGET_64BIT && reload_completed"
13754   [(set (match_dup 0)
13755         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
13756    (set (match_dup 3)
13757         (compare:CC (match_dup 0)
13758                     (const_int 0)))]
13759   "")
13760
13761 (define_insn ""
13762   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13763         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13764                         (match_operand:SI 2 "reg_or_short_operand" "r"))
13765                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13766   "TARGET_POWER"
13767   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13768   [(set_attr "length" "12")])
13769
13770 (define_insn ""
13771   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13772         (compare:CC
13773          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13774                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13775                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13776          (const_int 0)))
13777    (clobber (match_scratch:SI 4 "=&r,&r"))]
13778   "TARGET_POWER"
13779   "@
13780    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13781    #"
13782   [(set_attr "type" "compare")
13783    (set_attr "length" "12,16")])
13784
13785 (define_split
13786   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13787         (compare:CC
13788          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13789                          (match_operand:SI 2 "reg_or_short_operand" ""))
13790                   (match_operand:SI 3 "gpc_reg_operand" ""))
13791          (const_int 0)))
13792    (clobber (match_scratch:SI 4 ""))]
13793   "TARGET_POWER && reload_completed"
13794   [(set (match_dup 4)
13795         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13796    (set (match_dup 0)
13797         (compare:CC (match_dup 4)
13798                     (const_int 0)))]
13799   "")
13800
13801 (define_insn ""
13802   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13803         (compare:CC
13804          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13805                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13806                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13807          (const_int 0)))
13808    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13809         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13810   "TARGET_POWER"
13811   "@
13812    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13813    #"
13814   [(set_attr "type" "compare")
13815    (set_attr "length" "12,16")])
13816
13817 (define_split
13818   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13819         (compare:CC
13820          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13821                          (match_operand:SI 2 "reg_or_short_operand" ""))
13822                   (match_operand:SI 3 "gpc_reg_operand" ""))
13823          (const_int 0)))
13824    (set (match_operand:SI 0 "gpc_reg_operand" "")
13825         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13826   "TARGET_POWER && reload_completed"
13827   [(set (match_dup 0)
13828         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13829    (set (match_dup 4)
13830         (compare:CC (match_dup 0)
13831                     (const_int 0)))]
13832   "")
13833
13834 (define_insn ""
13835   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13836         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13837                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
13838   "TARGET_POWER"
13839   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13840   [(set_attr "length" "12")])
13841
13842 (define_insn_and_split "*gtu<mode>"
13843   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13844         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
13845                (match_operand:P 2 "reg_or_short_operand" "rI")))]
13846   ""
13847   "#"
13848   ""
13849   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13850    (set (match_dup 0) (neg:P (match_dup 0)))]
13851   "")
13852
13853 (define_insn_and_split "*gtu<mode>_compare"
13854   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13855         (compare:CC
13856          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13857                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
13858          (const_int 0)))
13859    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13860         (gtu:P (match_dup 1) (match_dup 2)))]
13861   ""
13862   "#"
13863   ""
13864   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13865    (parallel [(set (match_dup 3)
13866                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
13867               (set (match_dup 0) (neg:P (match_dup 0)))])]
13868   "")
13869
13870 (define_insn_and_split "*plus_gtu<mode>"
13871   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13872         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
13873                        (match_operand:P 2 "reg_or_short_operand" "rI"))
13874                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
13875   ""
13876   "#"
13877   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13878   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13879    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
13880   "")
13881
13882 (define_insn_and_split "*plus_gtu<mode>_compare"
13883   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13884         (compare:CC
13885          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13886                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
13887                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
13888          (const_int 0)))
13889    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13890         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
13891   ""
13892   "#"
13893   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13894   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13895    (parallel [(set (match_dup 4)
13896                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
13897                                (const_int 0)))
13898               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
13899   "")
13900
13901 (define_insn "*neg_gtu<mode>"
13902   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13903         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
13904                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
13905   ""
13906   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
13907   [(set_attr "type" "two")
13908    (set_attr "length" "8")])
13909
13910 \f
13911 ;; Define both directions of branch and return.  If we need a reload
13912 ;; register, we'd rather use CR0 since it is much easier to copy a
13913 ;; register CC value to there.
13914
13915 (define_insn ""
13916   [(set (pc)
13917         (if_then_else (match_operator 1 "branch_comparison_operator"
13918                                       [(match_operand 2
13919                                                       "cc_reg_operand" "y")
13920                                        (const_int 0)])
13921                       (label_ref (match_operand 0 "" ""))
13922                       (pc)))]
13923   ""
13924   "*
13925 {
13926   return output_cbranch (operands[1], \"%l0\", 0, insn);
13927 }"
13928   [(set_attr "type" "branch")])
13929
13930 (define_insn ""
13931   [(set (pc)
13932         (if_then_else (match_operator 0 "branch_comparison_operator"
13933                                       [(match_operand 1
13934                                                       "cc_reg_operand" "y")
13935                                        (const_int 0)])
13936                       (return)
13937                       (pc)))]
13938   "direct_return ()"
13939   "*
13940 {
13941   return output_cbranch (operands[0], NULL, 0, insn);
13942 }"
13943   [(set_attr "type" "jmpreg")
13944    (set_attr "length" "4")])
13945
13946 (define_insn ""
13947   [(set (pc)
13948         (if_then_else (match_operator 1 "branch_comparison_operator"
13949                                       [(match_operand 2
13950                                                       "cc_reg_operand" "y")
13951                                        (const_int 0)])
13952                       (pc)
13953                       (label_ref (match_operand 0 "" ""))))]
13954   ""
13955   "*
13956 {
13957   return output_cbranch (operands[1], \"%l0\", 1, insn);
13958 }"
13959   [(set_attr "type" "branch")])
13960
13961 (define_insn ""
13962   [(set (pc)
13963         (if_then_else (match_operator 0 "branch_comparison_operator"
13964                                       [(match_operand 1
13965                                                       "cc_reg_operand" "y")
13966                                        (const_int 0)])
13967                       (pc)
13968                       (return)))]
13969   "direct_return ()"
13970   "*
13971 {
13972   return output_cbranch (operands[0], NULL, 1, insn);
13973 }"
13974   [(set_attr "type" "jmpreg")
13975    (set_attr "length" "4")])
13976
13977 ;; Logic on condition register values.
13978
13979 ; This pattern matches things like
13980 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13981 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
13982 ;                                  (const_int 1)))
13983 ; which are generated by the branch logic.
13984 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
13985
13986 (define_insn "*cceq_ior_compare"
13987   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13988         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13989                         [(match_operator:SI 2
13990                                       "branch_positive_comparison_operator"
13991                                       [(match_operand 3
13992                                                       "cc_reg_operand" "y,y")
13993                                        (const_int 0)])
13994                          (match_operator:SI 4
13995                                       "branch_positive_comparison_operator"
13996                                       [(match_operand 5
13997                                                       "cc_reg_operand" "0,y")
13998                                        (const_int 0)])])
13999                       (const_int 1)))]
14000   ""
14001   "cr%q1 %E0,%j2,%j4"
14002   [(set_attr "type" "cr_logical,delayed_cr")])
14003
14004 ; Why is the constant -1 here, but 1 in the previous pattern?
14005 ; Because ~1 has all but the low bit set.
14006 (define_insn ""
14007   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14008         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
14009                         [(not:SI (match_operator:SI 2
14010                                       "branch_positive_comparison_operator"
14011                                       [(match_operand 3
14012                                                       "cc_reg_operand" "y,y")
14013                                        (const_int 0)]))
14014                          (match_operator:SI 4
14015                                 "branch_positive_comparison_operator"
14016                                 [(match_operand 5
14017                                                 "cc_reg_operand" "0,y")
14018                                  (const_int 0)])])
14019                       (const_int -1)))]
14020   ""
14021   "cr%q1 %E0,%j2,%j4"
14022   [(set_attr "type" "cr_logical,delayed_cr")])
14023
14024 (define_insn "*cceq_rev_compare"
14025   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
14026         (compare:CCEQ (match_operator:SI 1
14027                                       "branch_positive_comparison_operator"
14028                                       [(match_operand 2
14029                                                       "cc_reg_operand" "0,y")
14030                                        (const_int 0)])
14031                       (const_int 0)))]
14032   ""
14033   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
14034   [(set_attr "type" "cr_logical,delayed_cr")])
14035
14036 ;; If we are comparing the result of two comparisons, this can be done
14037 ;; using creqv or crxor.
14038
14039 (define_insn_and_split ""
14040   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
14041         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
14042                               [(match_operand 2 "cc_reg_operand" "y")
14043                                (const_int 0)])
14044                       (match_operator 3 "branch_comparison_operator"
14045                               [(match_operand 4 "cc_reg_operand" "y")
14046                                (const_int 0)])))]
14047   ""
14048   "#"
14049   ""
14050   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
14051                                     (match_dup 5)))]
14052   "
14053 {
14054   int positive_1, positive_2;
14055
14056   positive_1 = branch_positive_comparison_operator (operands[1],
14057                                                     GET_MODE (operands[1]));
14058   positive_2 = branch_positive_comparison_operator (operands[3],
14059                                                     GET_MODE (operands[3]));
14060
14061   if (! positive_1)
14062     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
14063                                                             GET_CODE (operands[1])),
14064                                   SImode,
14065                                   operands[2], const0_rtx);
14066   else if (GET_MODE (operands[1]) != SImode)
14067     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
14068                                   operands[2], const0_rtx);
14069
14070   if (! positive_2)
14071     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
14072                                                             GET_CODE (operands[3])),
14073                                   SImode,
14074                                   operands[4], const0_rtx);
14075   else if (GET_MODE (operands[3]) != SImode)
14076     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
14077                                   operands[4], const0_rtx);
14078
14079   if (positive_1 == positive_2)
14080     {
14081       operands[1] = gen_rtx_NOT (SImode, operands[1]);
14082       operands[5] = constm1_rtx;
14083     }
14084   else
14085     {
14086       operands[5] = const1_rtx;
14087     }
14088 }")
14089
14090 ;; Unconditional branch and return.
14091
14092 (define_insn "jump"
14093   [(set (pc)
14094         (label_ref (match_operand 0 "" "")))]
14095   ""
14096   "b %l0"
14097   [(set_attr "type" "branch")])
14098
14099 (define_insn "return"
14100   [(return)]
14101   "direct_return ()"
14102   "{br|blr}"
14103   [(set_attr "type" "jmpreg")])
14104
14105 (define_expand "indirect_jump"
14106   [(set (pc) (match_operand 0 "register_operand" ""))])
14107
14108 (define_insn "*indirect_jump<mode>"
14109   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
14110   ""
14111   "@
14112    bctr
14113    {br|blr}"
14114   [(set_attr "type" "jmpreg")])
14115
14116 ;; Table jump for switch statements:
14117 (define_expand "tablejump"
14118   [(use (match_operand 0 "" ""))
14119    (use (label_ref (match_operand 1 "" "")))]
14120   ""
14121   "
14122 {
14123   if (TARGET_32BIT)
14124     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
14125   else
14126     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
14127   DONE;
14128 }")
14129
14130 (define_expand "tablejumpsi"
14131   [(set (match_dup 3)
14132         (plus:SI (match_operand:SI 0 "" "")
14133                  (match_dup 2)))
14134    (parallel [(set (pc) (match_dup 3))
14135               (use (label_ref (match_operand 1 "" "")))])]
14136   "TARGET_32BIT"
14137   "
14138 { operands[0] = force_reg (SImode, operands[0]);
14139   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
14140   operands[3] = gen_reg_rtx (SImode);
14141 }")
14142
14143 (define_expand "tablejumpdi"
14144   [(set (match_dup 4)
14145         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "")))
14146    (set (match_dup 3)
14147         (plus:DI (match_dup 4)
14148                  (match_dup 2)))
14149    (parallel [(set (pc) (match_dup 3))
14150               (use (label_ref (match_operand 1 "" "")))])]
14151   "TARGET_64BIT"
14152   "
14153 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
14154   operands[3] = gen_reg_rtx (DImode);
14155   operands[4] = gen_reg_rtx (DImode);
14156 }")
14157
14158 (define_insn "*tablejump<mode>_internal1"
14159   [(set (pc)
14160         (match_operand:P 0 "register_operand" "c,*l"))
14161    (use (label_ref (match_operand 1 "" "")))]
14162   ""
14163   "@
14164    bctr
14165    {br|blr}"
14166   [(set_attr "type" "jmpreg")])
14167
14168 (define_insn "nop"
14169   [(const_int 0)]
14170   ""
14171   "{cror 0,0,0|nop}")
14172 \f
14173 ;; Define the subtract-one-and-jump insns, starting with the template
14174 ;; so loop.c knows what to generate.
14175
14176 (define_expand "doloop_end"
14177   [(use (match_operand 0 "" ""))        ; loop pseudo
14178    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
14179    (use (match_operand 2 "" ""))        ; max iterations
14180    (use (match_operand 3 "" ""))        ; loop level
14181    (use (match_operand 4 "" ""))]       ; label
14182   ""
14183   "
14184 {
14185   /* Only use this on innermost loops.  */
14186   if (INTVAL (operands[3]) > 1)
14187     FAIL;
14188   if (TARGET_64BIT)
14189     {
14190       if (GET_MODE (operands[0]) != DImode)
14191         FAIL;
14192       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
14193     }
14194   else
14195     {
14196       if (GET_MODE (operands[0]) != SImode)
14197         FAIL;
14198       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
14199     }
14200   DONE;
14201 }")
14202
14203 (define_expand "ctr<mode>"
14204   [(parallel [(set (pc)
14205                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
14206                                      (const_int 1))
14207                                  (label_ref (match_operand 1 "" ""))
14208                                  (pc)))
14209               (set (match_dup 0)
14210                    (plus:P (match_dup 0)
14211                             (const_int -1)))
14212               (clobber (match_scratch:CC 2 ""))
14213               (clobber (match_scratch:P 3 ""))])]
14214   ""
14215   "")
14216
14217 ;; We need to be able to do this for any operand, including MEM, or we
14218 ;; will cause reload to blow up since we don't allow output reloads on
14219 ;; JUMP_INSNs.
14220 ;; For the length attribute to be calculated correctly, the
14221 ;; label MUST be operand 0.
14222
14223 (define_insn "*ctr<mode>_internal1"
14224   [(set (pc)
14225         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14226                           (const_int 1))
14227                       (label_ref (match_operand 0 "" ""))
14228                       (pc)))
14229    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14230         (plus:P (match_dup 1)
14231                  (const_int -1)))
14232    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14233    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14234   ""
14235   "*
14236 {
14237   if (which_alternative != 0)
14238     return \"#\";
14239   else if (get_attr_length (insn) == 4)
14240     return \"{bdn|bdnz} %l0\";
14241   else
14242     return \"bdz $+8\;b %l0\";
14243 }"
14244   [(set_attr "type" "branch")
14245    (set_attr "length" "*,12,16,16")])
14246
14247 (define_insn "*ctr<mode>_internal2"
14248   [(set (pc)
14249         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14250                           (const_int 1))
14251                       (pc)
14252                       (label_ref (match_operand 0 "" ""))))
14253    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14254         (plus:P (match_dup 1)
14255                  (const_int -1)))
14256    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14257    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14258   ""
14259   "*
14260 {
14261   if (which_alternative != 0)
14262     return \"#\";
14263   else if (get_attr_length (insn) == 4)
14264     return \"bdz %l0\";
14265   else
14266     return \"{bdn|bdnz} $+8\;b %l0\";
14267 }"
14268   [(set_attr "type" "branch")
14269    (set_attr "length" "*,12,16,16")])
14270
14271 ;; Similar but use EQ
14272
14273 (define_insn "*ctr<mode>_internal5"
14274   [(set (pc)
14275         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14276                           (const_int 1))
14277                       (label_ref (match_operand 0 "" ""))
14278                       (pc)))
14279    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14280         (plus:P (match_dup 1)
14281                  (const_int -1)))
14282    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14283    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14284   ""
14285   "*
14286 {
14287   if (which_alternative != 0)
14288     return \"#\";
14289   else if (get_attr_length (insn) == 4)
14290     return \"bdz %l0\";
14291   else
14292     return \"{bdn|bdnz} $+8\;b %l0\";
14293 }"
14294   [(set_attr "type" "branch")
14295    (set_attr "length" "*,12,16,16")])
14296
14297 (define_insn "*ctr<mode>_internal6"
14298   [(set (pc)
14299         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
14300                           (const_int 1))
14301                       (pc)
14302                       (label_ref (match_operand 0 "" ""))))
14303    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14304         (plus:P (match_dup 1)
14305                  (const_int -1)))
14306    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14307    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
14308   ""
14309   "*
14310 {
14311   if (which_alternative != 0)
14312     return \"#\";
14313   else if (get_attr_length (insn) == 4)
14314     return \"{bdn|bdnz} %l0\";
14315   else
14316     return \"bdz $+8\;b %l0\";
14317 }"
14318   [(set_attr "type" "branch")
14319    (set_attr "length" "*,12,16,16")])
14320
14321 ;; Now the splitters if we could not allocate the CTR register
14322
14323 (define_split
14324   [(set (pc)
14325         (if_then_else (match_operator 2 "comparison_operator"
14326                                       [(match_operand:P 1 "gpc_reg_operand" "")
14327                                        (const_int 1)])
14328                       (match_operand 5 "" "")
14329                       (match_operand 6 "" "")))
14330    (set (match_operand:P 0 "gpc_reg_operand" "")
14331         (plus:P (match_dup 1) (const_int -1)))
14332    (clobber (match_scratch:CC 3 ""))
14333    (clobber (match_scratch:P 4 ""))]
14334   "reload_completed"
14335   [(parallel [(set (match_dup 3)
14336                    (compare:CC (plus:P (match_dup 1)
14337                                         (const_int -1))
14338                                (const_int 0)))
14339               (set (match_dup 0)
14340                    (plus:P (match_dup 1)
14341                             (const_int -1)))])
14342    (set (pc) (if_then_else (match_dup 7)
14343                            (match_dup 5)
14344                            (match_dup 6)))]
14345   "
14346 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14347                                 operands[3], const0_rtx); }")
14348
14349 (define_split
14350   [(set (pc)
14351         (if_then_else (match_operator 2 "comparison_operator"
14352                                       [(match_operand:P 1 "gpc_reg_operand" "")
14353                                        (const_int 1)])
14354                       (match_operand 5 "" "")
14355                       (match_operand 6 "" "")))
14356    (set (match_operand:P 0 "nonimmediate_operand" "")
14357         (plus:P (match_dup 1) (const_int -1)))
14358    (clobber (match_scratch:CC 3 ""))
14359    (clobber (match_scratch:P 4 ""))]
14360   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
14361   [(parallel [(set (match_dup 3)
14362                    (compare:CC (plus:P (match_dup 1)
14363                                         (const_int -1))
14364                                (const_int 0)))
14365               (set (match_dup 4)
14366                    (plus:P (match_dup 1)
14367                             (const_int -1)))])
14368    (set (match_dup 0)
14369         (match_dup 4))
14370    (set (pc) (if_then_else (match_dup 7)
14371                            (match_dup 5)
14372                            (match_dup 6)))]
14373   "
14374 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14375                                 operands[3], const0_rtx); }")
14376 \f
14377 (define_insn "trap"
14378   [(trap_if (const_int 1) (const_int 0))]
14379   ""
14380   "{t 31,0,0|trap}"
14381   [(set_attr "type" "trap")])
14382
14383 (define_expand "conditional_trap"
14384   [(trap_if (match_operator 0 "trap_comparison_operator"
14385                             [(match_dup 2) (match_dup 3)])
14386             (match_operand 1 "const_int_operand" ""))]
14387   ""
14388   "if (rs6000_compare_fp_p || operands[1] != const0_rtx) FAIL;
14389    operands[2] = rs6000_compare_op0;
14390    operands[3] = rs6000_compare_op1;")
14391
14392 (define_insn ""
14393   [(trap_if (match_operator 0 "trap_comparison_operator"
14394                             [(match_operand:GPR 1 "register_operand" "r")
14395                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
14396             (const_int 0))]
14397   ""
14398   "{t|t<wd>}%V0%I2 %1,%2"
14399   [(set_attr "type" "trap")])
14400 \f
14401 ;; Insns related to generating the function prologue and epilogue.
14402
14403 (define_expand "prologue"
14404   [(use (const_int 0))]
14405   "TARGET_SCHED_PROLOG"
14406   "
14407 {
14408       rs6000_emit_prologue ();
14409       DONE;
14410 }")
14411
14412 (define_insn "*movesi_from_cr_one"
14413   [(match_parallel 0 "mfcr_operation"
14414                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14415                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14416                                      (match_operand 3 "immediate_operand" "n")]
14417                           UNSPEC_MOVESI_FROM_CR))])]
14418   "TARGET_MFCRF"
14419   "*
14420 {
14421   int mask = 0;
14422   int i;
14423   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14424   {
14425     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14426     operands[4] = GEN_INT (mask);
14427     output_asm_insn (\"mfcr %1,%4\", operands);
14428   }
14429   return \"\";
14430 }"
14431   [(set_attr "type" "mfcrf")])
14432
14433 (define_insn "movesi_from_cr"
14434   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14435         (unspec:SI [(reg:CC CR0_REGNO) (reg:CC CR1_REGNO)
14436                     (reg:CC CR2_REGNO) (reg:CC CR3_REGNO)
14437                     (reg:CC CR4_REGNO) (reg:CC CR5_REGNO)
14438                     (reg:CC CR6_REGNO) (reg:CC CR7_REGNO)]
14439                    UNSPEC_MOVESI_FROM_CR))]
14440   ""
14441   "mfcr %0"
14442   [(set_attr "type" "mfcr")])
14443
14444 (define_insn "*stmw"
14445   [(match_parallel 0 "stmw_operation"
14446                    [(set (match_operand:SI 1 "memory_operand" "=m")
14447                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14448   "TARGET_MULTIPLE"
14449   "{stm|stmw} %2,%1"
14450   [(set_attr "type" "store_ux")])
14451
14452 (define_insn "*save_fpregs_<mode>"
14453   [(match_parallel 0 "any_parallel_operand"
14454                    [(clobber (reg:P 65))
14455                     (use (match_operand:P 1 "call_operand" "s"))
14456                     (set (match_operand:DF 2 "memory_operand" "=m")
14457                          (match_operand:DF 3 "gpc_reg_operand" "f"))])]
14458   ""
14459   "bl %z1"
14460   [(set_attr "type" "branch")
14461    (set_attr "length" "4")])
14462
14463 ; These are to explain that changes to the stack pointer should
14464 ; not be moved over stores to stack memory.
14465 (define_insn "stack_tie"
14466   [(set (match_operand:BLK 0 "memory_operand" "+m")
14467         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
14468   ""
14469   ""
14470   [(set_attr "length" "0")])
14471
14472
14473 (define_expand "epilogue"
14474   [(use (const_int 0))]
14475   "TARGET_SCHED_PROLOG"
14476   "
14477 {
14478       rs6000_emit_epilogue (FALSE);
14479       DONE;
14480 }")
14481
14482 ; On some processors, doing the mtcrf one CC register at a time is
14483 ; faster (like on the 604e).  On others, doing them all at once is
14484 ; faster; for instance, on the 601 and 750.
14485
14486 (define_expand "movsi_to_cr_one"
14487   [(set (match_operand:CC 0 "cc_reg_operand" "")
14488         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "")
14489                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
14490   ""
14491   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
14492
14493 (define_insn "*movsi_to_cr"
14494   [(match_parallel 0 "mtcrf_operation"
14495                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14496                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14497                                      (match_operand 3 "immediate_operand" "n")]
14498                                     UNSPEC_MOVESI_TO_CR))])]
14499  ""
14500  "*
14501 {
14502   int mask = 0;
14503   int i;
14504   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14505     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14506   operands[4] = GEN_INT (mask);
14507   return \"mtcrf %4,%2\";
14508 }"
14509   [(set_attr "type" "mtcr")])
14510
14511 (define_insn "*mtcrfsi"
14512   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14513         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14514                     (match_operand 2 "immediate_operand" "n")]
14515                    UNSPEC_MOVESI_TO_CR))]
14516   "GET_CODE (operands[0]) == REG
14517    && CR_REGNO_P (REGNO (operands[0]))
14518    && GET_CODE (operands[2]) == CONST_INT
14519    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
14520   "mtcrf %R0,%1"
14521   [(set_attr "type" "mtcr")])
14522
14523 ; The load-multiple instructions have similar properties.
14524 ; Note that "load_multiple" is a name known to the machine-independent
14525 ; code that actually corresponds to the PowerPC load-string.
14526
14527 (define_insn "*lmw"
14528   [(match_parallel 0 "lmw_operation"
14529                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14530                          (match_operand:SI 2 "memory_operand" "m"))])]
14531   "TARGET_MULTIPLE"
14532   "{lm|lmw} %1,%2"
14533   [(set_attr "type" "load_ux")])
14534
14535 (define_insn "*return_internal_<mode>"
14536   [(return)
14537    (use (match_operand:P 0 "register_operand" "lc"))]
14538   ""
14539   "b%T0"
14540   [(set_attr "type" "jmpreg")])
14541
14542 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
14543 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
14544
14545 (define_insn "*return_and_restore_fpregs_<mode>"
14546  [(match_parallel 0 "any_parallel_operand"
14547                   [(return)
14548                    (use (reg:P 65))
14549                    (use (match_operand:P 1 "call_operand" "s"))
14550                    (set (match_operand:DF 2 "gpc_reg_operand" "=f")
14551                         (match_operand:DF 3 "memory_operand" "m"))])]
14552  ""
14553  "b %z1")
14554
14555 ; This is used in compiling the unwind routines.
14556 (define_expand "eh_return"
14557   [(use (match_operand 0 "general_operand" ""))]
14558   ""
14559   "
14560 {
14561   if (TARGET_32BIT)
14562     emit_insn (gen_eh_set_lr_si (operands[0]));
14563   else
14564     emit_insn (gen_eh_set_lr_di (operands[0]));
14565   DONE;
14566 }")
14567
14568 ; We can't expand this before we know where the link register is stored.
14569 (define_insn "eh_set_lr_<mode>"
14570   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
14571                     UNSPECV_EH_RR)
14572    (clobber (match_scratch:P 1 "=&b"))]
14573   ""
14574   "#")
14575
14576 (define_split
14577   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
14578    (clobber (match_scratch 1 ""))]
14579   "reload_completed"
14580   [(const_int 0)]
14581   "
14582 {
14583   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
14584   DONE;
14585 }")
14586
14587 (define_insn "prefetch"
14588   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
14589              (match_operand:SI 1 "const_int_operand" "n")
14590              (match_operand:SI 2 "const_int_operand" "n"))]
14591   "TARGET_POWERPC"
14592   "*
14593 {
14594   if (GET_CODE (operands[0]) == REG)
14595     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
14596   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
14597 }"
14598   [(set_attr "type" "load")])
14599 \f
14600
14601 (include "sync.md")
14602 (include "altivec.md")
14603 (include "spe.md")
14604 (include "dfp.md")
14605 (include "paired.md")