OSDN Git Service

PR target/28753
[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
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 2, 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 COPYING.  If not, write to the
21 ;; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
22 ;; MA 02110-1301, USA.
23
24 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
25
26 ;;
27 ;; UNSPEC usage
28 ;;
29
30 (define_constants
31   [(UNSPEC_FRSP                 0)      ; frsp for POWER machines
32    (UNSPEC_TIE                  5)      ; tie stack contents and stack pointer
33    (UNSPEC_TOCPTR               6)      ; address of a word pointing to the TOC
34    (UNSPEC_TOC                  7)      ; address of the TOC (more-or-less)
35    (UNSPEC_MOVSI_GOT            8)
36    (UNSPEC_MV_CR_OV             9)      ; move_from_CR_ov_bit
37    (UNSPEC_FCTIWZ               10)
38    (UNSPEC_FRIM                 11)
39    (UNSPEC_FRIN                 12)
40    (UNSPEC_FRIP                 13)
41    (UNSPEC_FRIZ                 14)
42    (UNSPEC_LD_MPIC              15)     ; load_macho_picbase
43    (UNSPEC_MPIC_CORRECT         16)     ; macho_correct_pic
44    (UNSPEC_TLSGD                17)
45    (UNSPEC_TLSLD                18)
46    (UNSPEC_MOVESI_FROM_CR       19)
47    (UNSPEC_MOVESI_TO_CR         20)
48    (UNSPEC_TLSDTPREL            21)
49    (UNSPEC_TLSDTPRELHA          22)
50    (UNSPEC_TLSDTPRELLO          23)
51    (UNSPEC_TLSGOTDTPREL         24)
52    (UNSPEC_TLSTPREL             25)
53    (UNSPEC_TLSTPRELHA           26)
54    (UNSPEC_TLSTPRELLO           27)
55    (UNSPEC_TLSGOTTPREL          28)
56    (UNSPEC_TLSTLS               29)
57    (UNSPEC_FIX_TRUNC_TF         30)     ; fadd, rounding towards zero
58    (UNSPEC_MV_CR_GT             31)     ; move_from_CR_gt_bit
59    (UNSPEC_STFIWX               32)
60    (UNSPEC_POPCNTB              33)
61    (UNSPEC_FRES                 34)
62    (UNSPEC_SP_SET               35)
63    (UNSPEC_SP_TEST              36)
64    (UNSPEC_SYNC                 37)
65    (UNSPEC_LWSYNC               38)
66    (UNSPEC_ISYNC                39)
67    (UNSPEC_SYNC_OP              40)
68    (UNSPEC_ATOMIC               41)
69    (UNSPEC_CMPXCHG              42)
70    (UNSPEC_XCHG                 43)
71    (UNSPEC_AND                  44)
72    (UNSPEC_DLMZB                45)
73    (UNSPEC_DLMZB_CR             46)
74    (UNSPEC_DLMZB_STRLEN         47)
75   ])
76
77 ;;
78 ;; UNSPEC_VOLATILE usage
79 ;;
80
81 (define_constants
82   [(UNSPECV_BLOCK               0)
83    (UNSPECV_LL                  1)      ; load-locked
84    (UNSPECV_SC                  2)      ; store-conditional
85    (UNSPECV_EH_RR               9)      ; eh_reg_restore
86   ])
87 \f
88 ;; Define an insn type attribute.  This is used in function unit delay
89 ;; computations.
90 (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,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"
91   (const_string "integer"))
92
93 ;; Length (in bytes).
94 ; '(pc)' in the following doesn't include the instruction itself; it is
95 ; calculated as if the instruction had zero size.
96 (define_attr "length" ""
97   (if_then_else (eq_attr "type" "branch")
98                 (if_then_else (and (ge (minus (match_dup 0) (pc))
99                                        (const_int -32768))
100                                    (lt (minus (match_dup 0) (pc))
101                                        (const_int 32764)))
102                               (const_int 4)
103                               (const_int 8))
104                 (const_int 4)))
105
106 ;; Processor type -- this attribute must exactly match the processor_type
107 ;; enumeration in rs6000.h.
108
109 (define_attr "cpu" "rios1,rios2,rs64a,mpccore,ppc403,ppc405,ppc440,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,power4,power5"
110   (const (symbol_ref "rs6000_cpu_attr")))
111
112 (automata_option "ndfa")
113
114 (include "rios1.md")
115 (include "rios2.md")
116 (include "rs64.md")
117 (include "mpc.md")
118 (include "40x.md")
119 (include "440.md")
120 (include "603.md")
121 (include "6xx.md")
122 (include "7xx.md")
123 (include "7450.md")
124 (include "8540.md")
125 (include "power4.md")
126 (include "power5.md")
127
128 (include "predicates.md")
129 (include "constraints.md")
130
131 (include "darwin.md")
132
133 \f
134 ;; Mode macros
135
136 ; This mode macro allows :GPR to be used to indicate the allowable size
137 ; of whole values in GPRs.
138 (define_mode_macro GPR [SI (DI "TARGET_POWERPC64")])
139
140 ; Any supported integer mode.
141 (define_mode_macro INT [QI HI SI DI TI])
142
143 ; Any supported integer mode that fits in one register.
144 (define_mode_macro INT1 [QI HI SI (DI "TARGET_POWERPC64")])
145
146 ; extend modes for DImode
147 (define_mode_macro QHSI [QI HI SI])
148
149 ; SImode or DImode, even if DImode doesn't fit in GPRs.
150 (define_mode_macro SDI [SI DI])
151
152 ; The size of a pointer.  Also, the size of the value that a record-condition
153 ; (one with a '.') will compare.
154 (define_mode_macro P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
155
156 ; Any hardware-supported floating-point mode
157 (define_mode_macro FP [(SF "TARGET_HARD_FLOAT")
158   (DF "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)")
159   (TF "!TARGET_IEEEQUAD
160    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128")])
161
162 ; Various instructions that come in SI and DI forms.
163 ; A generic w/d attribute, for things like cmpw/cmpd.
164 (define_mode_attr wd [(QI "b") (HI "h") (SI "w") (DI "d")])
165
166 ; DImode bits
167 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
168
169 \f
170 ;; Start with fixed-point load and store insns.  Here we put only the more
171 ;; complex forms.  Basic data transfer is done later.
172
173 (define_expand "zero_extend<mode>di2"
174   [(set (match_operand:DI 0 "gpc_reg_operand" "")
175         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
176   "TARGET_POWERPC64"
177   "")
178
179 (define_insn "*zero_extend<mode>di2_internal1"
180   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
181         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
182   "TARGET_POWERPC64"
183   "@
184    l<wd>z%U1%X1 %0,%1
185    rldicl %0,%1,0,<dbits>"
186   [(set_attr "type" "load,*")])
187
188 (define_insn "*zero_extend<mode>di2_internal2"
189   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
190         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
191                     (const_int 0)))
192    (clobber (match_scratch:DI 2 "=r,r"))]
193   "TARGET_64BIT"
194   "@
195    rldicl. %2,%1,0,<dbits>
196    #"
197   [(set_attr "type" "compare")
198    (set_attr "length" "4,8")])
199
200 (define_split
201   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
202         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
203                     (const_int 0)))
204    (clobber (match_scratch:DI 2 ""))]
205   "TARGET_POWERPC64 && reload_completed"
206   [(set (match_dup 2)
207         (zero_extend:DI (match_dup 1)))
208    (set (match_dup 0)
209         (compare:CC (match_dup 2)
210                     (const_int 0)))]
211   "")
212
213 (define_insn "*zero_extend<mode>di2_internal3"
214   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
215         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
216                     (const_int 0)))
217    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
218         (zero_extend:DI (match_dup 1)))]
219   "TARGET_64BIT"
220   "@
221    rldicl. %0,%1,0,<dbits>
222    #"
223   [(set_attr "type" "compare")
224    (set_attr "length" "4,8")])
225
226 (define_split
227   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
228         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
229                     (const_int 0)))
230    (set (match_operand:DI 0 "gpc_reg_operand" "")
231         (zero_extend:DI (match_dup 1)))]
232   "TARGET_POWERPC64 && reload_completed"
233   [(set (match_dup 0)
234         (zero_extend:DI (match_dup 1)))
235    (set (match_dup 2)
236         (compare:CC (match_dup 0)
237                     (const_int 0)))]
238   "")
239
240 (define_insn "extendqidi2"
241   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
242         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
243   "TARGET_POWERPC64"
244   "extsb %0,%1")
245
246 (define_insn ""
247   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
248         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
249                     (const_int 0)))
250    (clobber (match_scratch:DI 2 "=r,r"))]
251   "TARGET_64BIT"
252   "@
253    extsb. %2,%1
254    #"
255   [(set_attr "type" "compare")
256    (set_attr "length" "4,8")])
257
258 (define_split
259   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
260         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
261                     (const_int 0)))
262    (clobber (match_scratch:DI 2 ""))]
263   "TARGET_POWERPC64 && reload_completed"
264   [(set (match_dup 2)
265         (sign_extend:DI (match_dup 1)))
266    (set (match_dup 0)
267         (compare:CC (match_dup 2)
268                     (const_int 0)))]
269   "")
270
271 (define_insn ""
272   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
273         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
274                     (const_int 0)))
275    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
276         (sign_extend:DI (match_dup 1)))]
277   "TARGET_64BIT"
278   "@
279    extsb. %0,%1
280    #"
281   [(set_attr "type" "compare")
282    (set_attr "length" "4,8")])
283
284 (define_split
285   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
286         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
287                     (const_int 0)))
288    (set (match_operand:DI 0 "gpc_reg_operand" "")
289         (sign_extend:DI (match_dup 1)))]
290   "TARGET_POWERPC64 && reload_completed"
291   [(set (match_dup 0)
292         (sign_extend:DI (match_dup 1)))
293    (set (match_dup 2)
294         (compare:CC (match_dup 0)
295                     (const_int 0)))]
296   "")
297
298 (define_expand "extendhidi2"
299   [(set (match_operand:DI 0 "gpc_reg_operand" "")
300         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
301   "TARGET_POWERPC64"
302   "")
303
304 (define_insn ""
305   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
306         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
307   "TARGET_POWERPC64"
308   "@
309    lha%U1%X1 %0,%1
310    extsh %0,%1"
311   [(set_attr "type" "load_ext,*")])
312
313 (define_insn ""
314   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
315         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
316                     (const_int 0)))
317    (clobber (match_scratch:DI 2 "=r,r"))]
318   "TARGET_64BIT"
319   "@
320    extsh. %2,%1
321    #"
322   [(set_attr "type" "compare")
323    (set_attr "length" "4,8")])
324
325 (define_split
326   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
327         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
328                     (const_int 0)))
329    (clobber (match_scratch:DI 2 ""))]
330   "TARGET_POWERPC64 && reload_completed"
331   [(set (match_dup 2)
332         (sign_extend:DI (match_dup 1)))
333    (set (match_dup 0)
334         (compare:CC (match_dup 2)
335                     (const_int 0)))]
336   "")
337
338 (define_insn ""
339   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
340         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
341                     (const_int 0)))
342    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
343         (sign_extend:DI (match_dup 1)))]
344   "TARGET_64BIT"
345   "@
346    extsh. %0,%1
347    #"
348   [(set_attr "type" "compare")
349    (set_attr "length" "4,8")])
350
351 (define_split
352   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
353         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
354                     (const_int 0)))
355    (set (match_operand:DI 0 "gpc_reg_operand" "")
356         (sign_extend:DI (match_dup 1)))]
357   "TARGET_POWERPC64 && reload_completed"
358   [(set (match_dup 0)
359         (sign_extend:DI (match_dup 1)))
360    (set (match_dup 2)
361         (compare:CC (match_dup 0)
362                     (const_int 0)))]
363   "")
364
365 (define_expand "extendsidi2"
366   [(set (match_operand:DI 0 "gpc_reg_operand" "")
367         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
368   "TARGET_POWERPC64"
369   "")
370
371 (define_insn ""
372   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
373         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
374   "TARGET_POWERPC64"
375   "@
376    lwa%U1%X1 %0,%1
377    extsw %0,%1"
378   [(set_attr "type" "load_ext,*")])
379
380 (define_insn ""
381   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
382         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
383                     (const_int 0)))
384    (clobber (match_scratch:DI 2 "=r,r"))]
385   "TARGET_64BIT"
386   "@
387    extsw. %2,%1
388    #"
389   [(set_attr "type" "compare")
390    (set_attr "length" "4,8")])
391
392 (define_split
393   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
394         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
395                     (const_int 0)))
396    (clobber (match_scratch:DI 2 ""))]
397   "TARGET_POWERPC64 && reload_completed"
398   [(set (match_dup 2)
399         (sign_extend:DI (match_dup 1)))
400    (set (match_dup 0)
401         (compare:CC (match_dup 2)
402                     (const_int 0)))]
403   "")
404
405 (define_insn ""
406   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
407         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
408                     (const_int 0)))
409    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
410         (sign_extend:DI (match_dup 1)))]
411   "TARGET_64BIT"
412   "@
413    extsw. %0,%1
414    #"
415   [(set_attr "type" "compare")
416    (set_attr "length" "4,8")])
417
418 (define_split
419   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
420         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
421                     (const_int 0)))
422    (set (match_operand:DI 0 "gpc_reg_operand" "")
423         (sign_extend:DI (match_dup 1)))]
424   "TARGET_POWERPC64 && reload_completed"
425   [(set (match_dup 0)
426         (sign_extend:DI (match_dup 1)))
427    (set (match_dup 2)
428         (compare:CC (match_dup 0)
429                     (const_int 0)))]
430   "")
431
432 (define_expand "zero_extendqisi2"
433   [(set (match_operand:SI 0 "gpc_reg_operand" "")
434         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
435   ""
436   "")
437
438 (define_insn ""
439   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
440         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
441   ""
442   "@
443    lbz%U1%X1 %0,%1
444    {rlinm|rlwinm} %0,%1,0,0xff"
445   [(set_attr "type" "load,*")])
446
447 (define_insn ""
448   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
449         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
450                     (const_int 0)))
451    (clobber (match_scratch:SI 2 "=r,r"))]
452   ""
453   "@
454    {andil.|andi.} %2,%1,0xff
455    #"
456   [(set_attr "type" "compare")
457    (set_attr "length" "4,8")])
458
459 (define_split
460   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
461         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
462                     (const_int 0)))
463    (clobber (match_scratch:SI 2 ""))]
464   "reload_completed"
465   [(set (match_dup 2)
466         (zero_extend:SI (match_dup 1)))
467    (set (match_dup 0)
468         (compare:CC (match_dup 2)
469                     (const_int 0)))]
470   "")
471
472 (define_insn ""
473   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
474         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
475                     (const_int 0)))
476    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
477         (zero_extend:SI (match_dup 1)))]
478   ""
479   "@
480    {andil.|andi.} %0,%1,0xff
481    #"
482   [(set_attr "type" "compare")
483    (set_attr "length" "4,8")])
484
485 (define_split
486   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
487         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
488                     (const_int 0)))
489    (set (match_operand:SI 0 "gpc_reg_operand" "")
490         (zero_extend:SI (match_dup 1)))]
491   "reload_completed"
492   [(set (match_dup 0)
493         (zero_extend:SI (match_dup 1)))
494    (set (match_dup 2)
495         (compare:CC (match_dup 0)
496                     (const_int 0)))]
497   "")
498
499 (define_expand "extendqisi2"
500   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
501    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
502   ""
503   "
504 {
505   if (TARGET_POWERPC)
506     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
507   else if (TARGET_POWER)
508     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
509   else
510     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
511   DONE;
512 }")
513
514 (define_insn "extendqisi2_ppc"
515   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
516         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
517   "TARGET_POWERPC"
518   "extsb %0,%1")
519
520 (define_insn ""
521   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
522         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
523                     (const_int 0)))
524    (clobber (match_scratch:SI 2 "=r,r"))]
525   "TARGET_POWERPC"
526   "@
527    extsb. %2,%1
528    #"
529   [(set_attr "type" "compare")
530    (set_attr "length" "4,8")])
531
532 (define_split
533   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
534         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
535                     (const_int 0)))
536    (clobber (match_scratch:SI 2 ""))]
537   "TARGET_POWERPC && reload_completed"
538   [(set (match_dup 2)
539         (sign_extend:SI (match_dup 1)))
540    (set (match_dup 0)
541         (compare:CC (match_dup 2)
542                     (const_int 0)))]
543   "")
544
545 (define_insn ""
546   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
547         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
548                     (const_int 0)))
549    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
550         (sign_extend:SI (match_dup 1)))]
551   "TARGET_POWERPC"
552   "@
553    extsb. %0,%1
554    #"
555   [(set_attr "type" "compare")
556    (set_attr "length" "4,8")])
557
558 (define_split
559   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
560         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
561                     (const_int 0)))
562    (set (match_operand:SI 0 "gpc_reg_operand" "")
563         (sign_extend:SI (match_dup 1)))]
564   "TARGET_POWERPC && reload_completed"
565   [(set (match_dup 0)
566         (sign_extend:SI (match_dup 1)))
567    (set (match_dup 2)
568         (compare:CC (match_dup 0)
569                     (const_int 0)))]
570   "")
571
572 (define_expand "extendqisi2_power"
573   [(parallel [(set (match_dup 2)
574                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
575                               (const_int 24)))
576               (clobber (scratch:SI))])
577    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
578                    (ashiftrt:SI (match_dup 2)
579                                 (const_int 24)))
580               (clobber (scratch:SI))])]
581   "TARGET_POWER"
582   "
583 { operands[1] = gen_lowpart (SImode, operands[1]);
584   operands[2] = gen_reg_rtx (SImode); }")
585
586 (define_expand "extendqisi2_no_power"
587   [(set (match_dup 2)
588         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
589                    (const_int 24)))
590    (set (match_operand:SI 0 "gpc_reg_operand" "")
591         (ashiftrt:SI (match_dup 2)
592                      (const_int 24)))]
593   "! TARGET_POWER && ! TARGET_POWERPC"
594   "
595 { operands[1] = gen_lowpart (SImode, operands[1]);
596   operands[2] = gen_reg_rtx (SImode); }")
597
598 (define_expand "zero_extendqihi2"
599   [(set (match_operand:HI 0 "gpc_reg_operand" "")
600         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
601   ""
602   "")
603
604 (define_insn ""
605   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
606         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
607   ""
608   "@
609    lbz%U1%X1 %0,%1
610    {rlinm|rlwinm} %0,%1,0,0xff"
611   [(set_attr "type" "load,*")])
612
613 (define_insn ""
614   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
615         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
616                     (const_int 0)))
617    (clobber (match_scratch:HI 2 "=r,r"))]
618   ""
619   "@
620    {andil.|andi.} %2,%1,0xff
621    #"
622   [(set_attr "type" "compare")
623    (set_attr "length" "4,8")])
624
625 (define_split
626   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
627         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
628                     (const_int 0)))
629    (clobber (match_scratch:HI 2 ""))]
630   "reload_completed"
631   [(set (match_dup 2)
632         (zero_extend:HI (match_dup 1)))
633    (set (match_dup 0)
634         (compare:CC (match_dup 2)
635                     (const_int 0)))]
636   "")
637
638 (define_insn ""
639   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
640         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
641                     (const_int 0)))
642    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
643         (zero_extend:HI (match_dup 1)))]
644   ""
645   "@
646    {andil.|andi.} %0,%1,0xff
647    #"
648   [(set_attr "type" "compare")
649    (set_attr "length" "4,8")])
650
651 (define_split
652   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
653         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
654                     (const_int 0)))
655    (set (match_operand:HI 0 "gpc_reg_operand" "")
656         (zero_extend:HI (match_dup 1)))]
657   "reload_completed"
658   [(set (match_dup 0)
659         (zero_extend:HI (match_dup 1)))
660    (set (match_dup 2)
661         (compare:CC (match_dup 0)
662                     (const_int 0)))]
663   "")
664
665 (define_expand "extendqihi2"
666   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
667    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
668   ""
669   "
670 {
671   if (TARGET_POWERPC)
672     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
673   else if (TARGET_POWER)
674     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
675   else
676     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
677   DONE;
678 }")
679
680 (define_insn "extendqihi2_ppc"
681   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
682         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
683   "TARGET_POWERPC"
684   "extsb %0,%1")
685
686 (define_insn ""
687   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
688         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
689                     (const_int 0)))
690    (clobber (match_scratch:HI 2 "=r,r"))]
691   "TARGET_POWERPC"
692   "@
693    extsb. %2,%1
694    #"
695   [(set_attr "type" "compare")
696    (set_attr "length" "4,8")])
697
698 (define_split
699   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
700         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
701                     (const_int 0)))
702    (clobber (match_scratch:HI 2 ""))]
703   "TARGET_POWERPC && reload_completed"
704   [(set (match_dup 2)
705         (sign_extend:HI (match_dup 1)))
706    (set (match_dup 0)
707         (compare:CC (match_dup 2)
708                     (const_int 0)))]
709   "")
710
711 (define_insn ""
712   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
713         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
714                     (const_int 0)))
715    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
716         (sign_extend:HI (match_dup 1)))]
717   "TARGET_POWERPC"
718   "@
719    extsb. %0,%1
720    #"
721   [(set_attr "type" "compare")
722    (set_attr "length" "4,8")])
723
724 (define_split
725   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
726         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
727                     (const_int 0)))
728    (set (match_operand:HI 0 "gpc_reg_operand" "")
729         (sign_extend:HI (match_dup 1)))]
730   "TARGET_POWERPC && reload_completed"
731   [(set (match_dup 0)
732         (sign_extend:HI (match_dup 1)))
733    (set (match_dup 2)
734         (compare:CC (match_dup 0)
735                     (const_int 0)))]
736   "")
737
738 (define_expand "extendqihi2_power"
739   [(parallel [(set (match_dup 2)
740                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
741                               (const_int 24)))
742               (clobber (scratch:SI))])
743    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
744                    (ashiftrt:SI (match_dup 2)
745                                 (const_int 24)))
746               (clobber (scratch:SI))])]
747   "TARGET_POWER"
748   "
749 { operands[0] = gen_lowpart (SImode, operands[0]);
750   operands[1] = gen_lowpart (SImode, operands[1]);
751   operands[2] = gen_reg_rtx (SImode); }")
752
753 (define_expand "extendqihi2_no_power"
754   [(set (match_dup 2)
755         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
756                    (const_int 24)))
757    (set (match_operand:HI 0 "gpc_reg_operand" "")
758         (ashiftrt:SI (match_dup 2)
759                      (const_int 24)))]
760   "! TARGET_POWER && ! TARGET_POWERPC"
761   "
762 { operands[0] = gen_lowpart (SImode, operands[0]);
763   operands[1] = gen_lowpart (SImode, operands[1]);
764   operands[2] = gen_reg_rtx (SImode); }")
765
766 (define_expand "zero_extendhisi2"
767   [(set (match_operand:SI 0 "gpc_reg_operand" "")
768         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
769   ""
770   "")
771
772 (define_insn ""
773   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
774         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
775   ""
776   "@
777    lhz%U1%X1 %0,%1
778    {rlinm|rlwinm} %0,%1,0,0xffff"
779   [(set_attr "type" "load,*")])
780
781 (define_insn ""
782   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
783         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
784                     (const_int 0)))
785    (clobber (match_scratch:SI 2 "=r,r"))]
786   ""
787   "@
788    {andil.|andi.} %2,%1,0xffff
789    #"
790   [(set_attr "type" "compare")
791    (set_attr "length" "4,8")])
792
793 (define_split
794   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
795         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
796                     (const_int 0)))
797    (clobber (match_scratch:SI 2 ""))]
798   "reload_completed"
799   [(set (match_dup 2)
800         (zero_extend:SI (match_dup 1)))
801    (set (match_dup 0)
802         (compare:CC (match_dup 2)
803                     (const_int 0)))]
804   "")
805
806 (define_insn ""
807   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
808         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
809                     (const_int 0)))
810    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
811         (zero_extend:SI (match_dup 1)))]
812   ""
813   "@
814    {andil.|andi.} %0,%1,0xffff
815    #"
816   [(set_attr "type" "compare")
817    (set_attr "length" "4,8")])
818
819 (define_split
820   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
821         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
822                     (const_int 0)))
823    (set (match_operand:SI 0 "gpc_reg_operand" "")
824         (zero_extend:SI (match_dup 1)))]
825   "reload_completed"
826   [(set (match_dup 0)
827         (zero_extend:SI (match_dup 1)))
828    (set (match_dup 2)
829         (compare:CC (match_dup 0)
830                     (const_int 0)))]
831   "")
832
833 (define_expand "extendhisi2"
834   [(set (match_operand:SI 0 "gpc_reg_operand" "")
835         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
836   ""
837   "")
838
839 (define_insn ""
840   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
841         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
842   ""
843   "@
844    lha%U1%X1 %0,%1
845    {exts|extsh} %0,%1"
846   [(set_attr "type" "load_ext,*")])
847
848 (define_insn ""
849   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
850         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
851                     (const_int 0)))
852    (clobber (match_scratch:SI 2 "=r,r"))]
853   ""
854   "@
855    {exts.|extsh.} %2,%1
856    #"
857   [(set_attr "type" "compare")
858    (set_attr "length" "4,8")])
859
860 (define_split
861   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
862         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
863                     (const_int 0)))
864    (clobber (match_scratch:SI 2 ""))]
865   "reload_completed"
866   [(set (match_dup 2)
867         (sign_extend:SI (match_dup 1)))
868    (set (match_dup 0)
869         (compare:CC (match_dup 2)
870                     (const_int 0)))]
871   "")
872
873 (define_insn ""
874   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
875         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
876                     (const_int 0)))
877    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
878         (sign_extend:SI (match_dup 1)))]
879   ""
880   "@
881    {exts.|extsh.} %0,%1
882    #"
883   [(set_attr "type" "compare")
884    (set_attr "length" "4,8")])
885 \f
886 ;; IBM 405 and 440 half-word multiplication operations.
887
888 (define_insn "*macchwc"
889   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
890         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
891                                        (match_operand:SI 2 "gpc_reg_operand" "r")
892                                        (const_int 16))
893                                       (sign_extend:SI
894                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
895                              (match_operand:SI 4 "gpc_reg_operand" "0"))
896                     (const_int 0)))
897    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
898         (plus:SI (mult:SI (ashiftrt:SI
899                            (match_dup 2)
900                            (const_int 16))
901                           (sign_extend:SI
902                            (match_dup 1)))
903                  (match_dup 4)))]
904   "TARGET_MULHW"
905   "macchw. %0, %1, %2"
906   [(set_attr "type" "imul3")])
907
908 (define_insn "*macchw"
909   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
910         (plus:SI (mult:SI (ashiftrt:SI
911                            (match_operand:SI 2 "gpc_reg_operand" "r")
912                            (const_int 16))
913                           (sign_extend:SI
914                            (match_operand:HI 1 "gpc_reg_operand" "r")))
915                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
916   "TARGET_MULHW"
917   "macchw %0, %1, %2"
918   [(set_attr "type" "imul3")])
919
920 (define_insn "*macchwuc"
921   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
922         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
923                                        (match_operand:SI 2 "gpc_reg_operand" "r")
924                                        (const_int 16))
925                                       (zero_extend:SI
926                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
927                              (match_operand:SI 4 "gpc_reg_operand" "0"))
928                     (const_int 0)))
929    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
930         (plus:SI (mult:SI (lshiftrt:SI
931                            (match_dup 2)
932                            (const_int 16))
933                           (zero_extend:SI
934                            (match_dup 1)))
935                  (match_dup 4)))]
936   "TARGET_MULHW"
937   "macchwu. %0, %1, %2"
938   [(set_attr "type" "imul3")])
939
940 (define_insn "*macchwu"
941   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
942         (plus:SI (mult:SI (lshiftrt:SI
943                            (match_operand:SI 2 "gpc_reg_operand" "r")
944                            (const_int 16))
945                           (zero_extend:SI
946                            (match_operand:HI 1 "gpc_reg_operand" "r")))
947                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
948   "TARGET_MULHW"
949   "macchwu %0, %1, %2"
950   [(set_attr "type" "imul3")])
951
952 (define_insn "*machhwc"
953   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
954         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
955                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
956                                        (const_int 16))
957                                       (ashiftrt:SI
958                                        (match_operand:SI 2 "gpc_reg_operand" "r")
959                                        (const_int 16)))
960                              (match_operand:SI 4 "gpc_reg_operand" "0"))
961                     (const_int 0)))
962    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
963         (plus:SI (mult:SI (ashiftrt:SI
964                            (match_dup 1)
965                            (const_int 16))
966                           (ashiftrt:SI
967                            (match_dup 2)
968                            (const_int 16)))
969                  (match_dup 4)))]
970   "TARGET_MULHW"
971   "machhw. %0, %1, %2"
972   [(set_attr "type" "imul3")])
973
974 (define_insn "*machhw"
975   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
976         (plus:SI (mult:SI (ashiftrt:SI
977                            (match_operand:SI 1 "gpc_reg_operand" "%r")
978                            (const_int 16))
979                           (ashiftrt:SI
980                            (match_operand:SI 2 "gpc_reg_operand" "r")
981                            (const_int 16)))
982                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
983   "TARGET_MULHW"
984   "machhw %0, %1, %2"
985   [(set_attr "type" "imul3")])
986
987 (define_insn "*machhwuc"
988   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
989         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
990                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
991                                        (const_int 16))
992                                       (lshiftrt:SI
993                                        (match_operand:SI 2 "gpc_reg_operand" "r")
994                                        (const_int 16)))
995                              (match_operand:SI 4 "gpc_reg_operand" "0"))
996                     (const_int 0)))
997    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
998         (plus:SI (mult:SI (lshiftrt:SI
999                            (match_dup 1)
1000                            (const_int 16))
1001                           (lshiftrt:SI
1002                            (match_dup 2)
1003                            (const_int 16)))
1004                  (match_dup 4)))]
1005   "TARGET_MULHW"
1006   "machhwu. %0, %1, %2"
1007   [(set_attr "type" "imul3")])
1008
1009 (define_insn "*machhwu"
1010   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1011         (plus:SI (mult:SI (lshiftrt:SI
1012                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1013                            (const_int 16))
1014                           (lshiftrt:SI
1015                            (match_operand:SI 2 "gpc_reg_operand" "r")
1016                            (const_int 16)))
1017                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1018   "TARGET_MULHW"
1019   "machhwu %0, %1, %2"
1020   [(set_attr "type" "imul3")])
1021
1022 (define_insn "*maclhwc"
1023   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1024         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1025                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1026                                       (sign_extend:SI
1027                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1028                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1029                     (const_int 0)))
1030    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1031         (plus:SI (mult:SI (sign_extend:SI
1032                            (match_dup 1))
1033                           (sign_extend:SI
1034                            (match_dup 2)))
1035                  (match_dup 4)))]
1036   "TARGET_MULHW"
1037   "maclhw. %0, %1, %2"
1038   [(set_attr "type" "imul3")])
1039
1040 (define_insn "*maclhw"
1041   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1042         (plus:SI (mult:SI (sign_extend:SI
1043                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1044                           (sign_extend:SI
1045                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1046                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1047   "TARGET_MULHW"
1048   "maclhw %0, %1, %2"
1049   [(set_attr "type" "imul3")])
1050
1051 (define_insn "*maclhwuc"
1052   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1053         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1054                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1055                                       (zero_extend:SI
1056                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1057                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1058                     (const_int 0)))
1059    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1060         (plus:SI (mult:SI (zero_extend:SI
1061                            (match_dup 1))
1062                           (zero_extend:SI
1063                            (match_dup 2)))
1064                  (match_dup 4)))]
1065   "TARGET_MULHW"
1066   "maclhwu. %0, %1, %2"
1067   [(set_attr "type" "imul3")])
1068
1069 (define_insn "*maclhwu"
1070   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1071         (plus:SI (mult:SI (zero_extend:SI
1072                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1073                           (zero_extend:SI
1074                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1075                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1076   "TARGET_MULHW"
1077   "maclhwu %0, %1, %2"
1078   [(set_attr "type" "imul3")])
1079
1080 (define_insn "*nmacchwc"
1081   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1082         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1083                               (mult:SI (ashiftrt:SI
1084                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1085                                         (const_int 16))
1086                                        (sign_extend:SI
1087                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1088                     (const_int 0)))
1089    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1090         (minus:SI (match_dup 4)
1091                   (mult:SI (ashiftrt:SI
1092                             (match_dup 2)
1093                             (const_int 16))
1094                            (sign_extend:SI
1095                             (match_dup 1)))))]
1096   "TARGET_MULHW"
1097   "nmacchw. %0, %1, %2"
1098   [(set_attr "type" "imul3")])
1099
1100 (define_insn "*nmacchw"
1101   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1102         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1103                   (mult:SI (ashiftrt:SI
1104                             (match_operand:SI 2 "gpc_reg_operand" "r")
1105                             (const_int 16))
1106                            (sign_extend:SI
1107                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1108   "TARGET_MULHW"
1109   "nmacchw %0, %1, %2"
1110   [(set_attr "type" "imul3")])
1111
1112 (define_insn "*nmachhwc"
1113   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1114         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1115                               (mult:SI (ashiftrt:SI
1116                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1117                                         (const_int 16))
1118                                        (ashiftrt:SI
1119                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1120                                         (const_int 16))))
1121                     (const_int 0)))
1122    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1123         (minus:SI (match_dup 4)
1124                   (mult:SI (ashiftrt:SI
1125                             (match_dup 1)
1126                             (const_int 16))
1127                            (ashiftrt:SI
1128                             (match_dup 2)
1129                             (const_int 16)))))]
1130   "TARGET_MULHW"
1131   "nmachhw. %0, %1, %2"
1132   [(set_attr "type" "imul3")])
1133
1134 (define_insn "*nmachhw"
1135   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1136         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1137                   (mult:SI (ashiftrt:SI
1138                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1139                             (const_int 16))
1140                            (ashiftrt:SI
1141                             (match_operand:SI 2 "gpc_reg_operand" "r")
1142                             (const_int 16)))))]
1143   "TARGET_MULHW"
1144   "nmachhw %0, %1, %2"
1145   [(set_attr "type" "imul3")])
1146
1147 (define_insn "*nmaclhwc"
1148   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1149         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1150                               (mult:SI (sign_extend:SI
1151                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1152                                        (sign_extend:SI
1153                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1154                     (const_int 0)))
1155    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1156         (minus:SI (match_dup 4)
1157                   (mult:SI (sign_extend:SI
1158                             (match_dup 1))
1159                            (sign_extend:SI
1160                             (match_dup 2)))))]
1161   "TARGET_MULHW"
1162   "nmaclhw. %0, %1, %2"
1163   [(set_attr "type" "imul3")])
1164
1165 (define_insn "*nmaclhw"
1166   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1167         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1168                   (mult:SI (sign_extend:SI
1169                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1170                            (sign_extend:SI
1171                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1172   "TARGET_MULHW"
1173   "nmaclhw %0, %1, %2"
1174   [(set_attr "type" "imul3")])
1175
1176 (define_insn "*mulchwc"
1177   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1178         (compare:CC (mult:SI (ashiftrt:SI
1179                               (match_operand:SI 2 "gpc_reg_operand" "r")
1180                               (const_int 16))
1181                              (sign_extend:SI
1182                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1183                     (const_int 0)))
1184    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1185         (mult:SI (ashiftrt:SI
1186                   (match_dup 2)
1187                   (const_int 16))
1188                  (sign_extend:SI
1189                   (match_dup 1))))]
1190   "TARGET_MULHW"
1191   "mulchw. %0, %1, %2"
1192   [(set_attr "type" "imul3")])
1193
1194 (define_insn "*mulchw"
1195   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1196         (mult:SI (ashiftrt:SI
1197                   (match_operand:SI 2 "gpc_reg_operand" "r")
1198                   (const_int 16))
1199                  (sign_extend:SI
1200                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1201   "TARGET_MULHW"
1202   "mulchw %0, %1, %2"
1203   [(set_attr "type" "imul3")])
1204
1205 (define_insn "*mulchwuc"
1206   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1207         (compare:CC (mult:SI (lshiftrt:SI
1208                               (match_operand:SI 2 "gpc_reg_operand" "r")
1209                               (const_int 16))
1210                              (zero_extend:SI
1211                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1212                     (const_int 0)))
1213    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1214         (mult:SI (lshiftrt:SI
1215                   (match_dup 2)
1216                   (const_int 16))
1217                  (zero_extend:SI
1218                   (match_dup 1))))]
1219   "TARGET_MULHW"
1220   "mulchwu. %0, %1, %2"
1221   [(set_attr "type" "imul3")])
1222
1223 (define_insn "*mulchwu"
1224   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1225         (mult:SI (lshiftrt:SI
1226                   (match_operand:SI 2 "gpc_reg_operand" "r")
1227                   (const_int 16))
1228                  (zero_extend:SI
1229                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1230   "TARGET_MULHW"
1231   "mulchwu %0, %1, %2"
1232   [(set_attr "type" "imul3")])
1233
1234 (define_insn "*mulhhwc"
1235   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1236         (compare:CC (mult:SI (ashiftrt:SI
1237                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1238                               (const_int 16))
1239                              (ashiftrt:SI
1240                               (match_operand:SI 2 "gpc_reg_operand" "r")
1241                               (const_int 16)))
1242                     (const_int 0)))
1243    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1244         (mult:SI (ashiftrt:SI
1245                   (match_dup 1)
1246                   (const_int 16))
1247                  (ashiftrt:SI
1248                   (match_dup 2)
1249                   (const_int 16))))]
1250   "TARGET_MULHW"
1251   "mulhhw. %0, %1, %2"
1252   [(set_attr "type" "imul3")])
1253
1254 (define_insn "*mulhhw"
1255   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1256         (mult:SI (ashiftrt:SI
1257                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1258                   (const_int 16))
1259                  (ashiftrt:SI
1260                   (match_operand:SI 2 "gpc_reg_operand" "r")
1261                   (const_int 16))))]
1262   "TARGET_MULHW"
1263   "mulhhw %0, %1, %2"
1264   [(set_attr "type" "imul3")])
1265
1266 (define_insn "*mulhhwuc"
1267   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1268         (compare:CC (mult:SI (lshiftrt:SI
1269                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1270                               (const_int 16))
1271                              (lshiftrt:SI
1272                               (match_operand:SI 2 "gpc_reg_operand" "r")
1273                               (const_int 16)))
1274                     (const_int 0)))
1275    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1276         (mult:SI (lshiftrt:SI
1277                   (match_dup 1)
1278                   (const_int 16))
1279                  (lshiftrt:SI
1280                   (match_dup 2)
1281                   (const_int 16))))]
1282   "TARGET_MULHW"
1283   "mulhhwu. %0, %1, %2"
1284   [(set_attr "type" "imul3")])
1285
1286 (define_insn "*mulhhwu"
1287   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1288         (mult:SI (lshiftrt:SI
1289                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1290                   (const_int 16))
1291                  (lshiftrt:SI
1292                   (match_operand:SI 2 "gpc_reg_operand" "r")
1293                   (const_int 16))))]
1294   "TARGET_MULHW"
1295   "mulhhwu %0, %1, %2"
1296   [(set_attr "type" "imul3")])
1297
1298 (define_insn "*mullhwc"
1299   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1300         (compare:CC (mult:SI (sign_extend:SI
1301                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1302                              (sign_extend:SI
1303                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1304                     (const_int 0)))
1305    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1306         (mult:SI (sign_extend:SI
1307                   (match_dup 1))
1308                  (sign_extend:SI
1309                   (match_dup 2))))]
1310   "TARGET_MULHW"
1311   "mullhw. %0, %1, %2"
1312   [(set_attr "type" "imul3")])
1313
1314 (define_insn "*mullhw"
1315   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1316         (mult:SI (sign_extend:SI
1317                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1318                  (sign_extend:SI
1319                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1320   "TARGET_MULHW"
1321   "mullhw %0, %1, %2"
1322   [(set_attr "type" "imul3")])
1323
1324 (define_insn "*mullhwuc"
1325   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1326         (compare:CC (mult:SI (zero_extend:SI
1327                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1328                              (zero_extend:SI
1329                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1330                     (const_int 0)))
1331    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1332         (mult:SI (zero_extend:SI
1333                   (match_dup 1))
1334                  (zero_extend:SI
1335                   (match_dup 2))))]
1336   "TARGET_MULHW"
1337   "mullhwu. %0, %1, %2"
1338   [(set_attr "type" "imul3")])
1339
1340 (define_insn "*mullhwu"
1341   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1342         (mult:SI (zero_extend:SI
1343                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1344                  (zero_extend:SI
1345                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1346   "TARGET_MULHW"
1347   "mullhwu %0, %1, %2"
1348   [(set_attr "type" "imul3")])
1349 \f
1350 ;; IBM 405 and 440 string-search dlmzb instruction support.
1351 (define_insn "dlmzb"
1352   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1353         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1354                     (match_operand:SI 2 "gpc_reg_operand" "r")]
1355                    UNSPEC_DLMZB_CR))
1356    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1357         (unspec:SI [(match_dup 1)
1358                     (match_dup 2)]
1359                    UNSPEC_DLMZB))]
1360   "TARGET_DLMZB"
1361   "dlmzb. %0, %1, %2")
1362
1363 (define_expand "strlensi"
1364   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1365         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
1366                     (match_operand:QI 2 "const_int_operand" "")
1367                     (match_operand 3 "const_int_operand" "")]
1368                    UNSPEC_DLMZB_STRLEN))
1369    (clobber (match_scratch:CC 4 "=x"))]
1370   "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1371 {
1372   rtx result = operands[0];
1373   rtx src = operands[1];
1374   rtx search_char = operands[2];
1375   rtx align = operands[3];
1376   rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1377   rtx loop_label, end_label, mem, cr0, cond;
1378   if (search_char != const0_rtx
1379       || GET_CODE (align) != CONST_INT
1380       || INTVAL (align) < 8)
1381         FAIL;
1382   word1 = gen_reg_rtx (SImode);
1383   word2 = gen_reg_rtx (SImode);
1384   scratch_dlmzb = gen_reg_rtx (SImode);
1385   scratch_string = gen_reg_rtx (Pmode);
1386   loop_label = gen_label_rtx ();
1387   end_label = gen_label_rtx ();
1388   addr = force_reg (Pmode, XEXP (src, 0));
1389   emit_move_insn (scratch_string, addr);
1390   emit_label (loop_label);
1391   mem = change_address (src, SImode, scratch_string);
1392   emit_move_insn (word1, mem);
1393   emit_move_insn (word2, adjust_address (mem, SImode, 4));
1394   cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1395   emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1396   cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1397   emit_jump_insn (gen_rtx_SET (VOIDmode,
1398                                pc_rtx,
1399                                gen_rtx_IF_THEN_ELSE (VOIDmode,
1400                                                      cond,
1401                                                      gen_rtx_LABEL_REF
1402                                                        (VOIDmode,
1403                                                         end_label),
1404                                                      pc_rtx)));
1405   emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1406   emit_jump_insn (gen_rtx_SET (VOIDmode,
1407                                pc_rtx,
1408                                gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1409   emit_barrier ();
1410   emit_label (end_label);
1411   emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1412   emit_insn (gen_subsi3 (result, scratch_string, addr));
1413   emit_insn (gen_subsi3 (result, result, const1_rtx));
1414   DONE;
1415 })
1416 \f
1417 (define_split
1418   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1419         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1420                     (const_int 0)))
1421    (set (match_operand:SI 0 "gpc_reg_operand" "")
1422         (sign_extend:SI (match_dup 1)))]
1423   "reload_completed"
1424   [(set (match_dup 0)
1425         (sign_extend:SI (match_dup 1)))
1426    (set (match_dup 2)
1427         (compare:CC (match_dup 0)
1428                     (const_int 0)))]
1429   "")
1430
1431 ;; Fixed-point arithmetic insns.
1432
1433 (define_expand "add<mode>3"
1434   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1435         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1436                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1437   ""
1438 {
1439   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1440     {
1441       if (non_short_cint_operand (operands[2], DImode))
1442         FAIL;
1443     }
1444   else if (GET_CODE (operands[2]) == CONST_INT
1445            && ! add_operand (operands[2], <MODE>mode))
1446     {
1447       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
1448                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1449
1450       HOST_WIDE_INT val = INTVAL (operands[2]);
1451       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1452       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1453
1454       if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1455         FAIL;
1456
1457       /* The ordering here is important for the prolog expander.
1458          When space is allocated from the stack, adding 'low' first may
1459          produce a temporary deallocation (which would be bad).  */
1460       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1461       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1462       DONE;
1463     }
1464 })
1465
1466 ;; Discourage ai/addic because of carry but provide it in an alternative
1467 ;; allowing register zero as source.
1468 (define_insn "*add<mode>3_internal1"
1469   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1470         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1471                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1472   ""
1473   "@
1474    {cax|add} %0,%1,%2
1475    {cal %0,%2(%1)|addi %0,%1,%2}
1476    {ai|addic} %0,%1,%2
1477    {cau|addis} %0,%1,%v2"
1478   [(set_attr "length" "4,4,4,4")])
1479
1480 (define_insn "addsi3_high"
1481   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1482         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1483                  (high:SI (match_operand 2 "" ""))))]
1484   "TARGET_MACHO && !TARGET_64BIT"
1485   "{cau|addis} %0,%1,ha16(%2)"
1486   [(set_attr "length" "4")])
1487
1488 (define_insn "*add<mode>3_internal2"
1489   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1490         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1491                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1492                     (const_int 0)))
1493    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1494   ""
1495   "@
1496    {cax.|add.} %3,%1,%2
1497    {ai.|addic.} %3,%1,%2
1498    #
1499    #"
1500   [(set_attr "type" "fast_compare,compare,compare,compare")
1501    (set_attr "length" "4,4,8,8")])
1502
1503 (define_split
1504   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1505         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1506                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1507                     (const_int 0)))
1508    (clobber (match_scratch:GPR 3 ""))]
1509   "reload_completed"
1510   [(set (match_dup 3)
1511         (plus:GPR (match_dup 1)
1512                  (match_dup 2)))
1513    (set (match_dup 0)
1514         (compare:CC (match_dup 3)
1515                     (const_int 0)))]
1516   "")
1517
1518 (define_insn "*add<mode>3_internal3"
1519   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1520         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1521                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1522                     (const_int 0)))
1523    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1524         (plus:P (match_dup 1)
1525                 (match_dup 2)))]
1526   ""
1527   "@
1528    {cax.|add.} %0,%1,%2
1529    {ai.|addic.} %0,%1,%2
1530    #
1531    #"
1532   [(set_attr "type" "fast_compare,compare,compare,compare")
1533    (set_attr "length" "4,4,8,8")])
1534
1535 (define_split
1536   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1537         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1538                             (match_operand:P 2 "reg_or_short_operand" ""))
1539                     (const_int 0)))
1540    (set (match_operand:P 0 "gpc_reg_operand" "")
1541         (plus:P (match_dup 1) (match_dup 2)))]
1542   "reload_completed"
1543   [(set (match_dup 0)
1544         (plus:P (match_dup 1)
1545                 (match_dup 2)))
1546    (set (match_dup 3)
1547         (compare:CC (match_dup 0)
1548                     (const_int 0)))]
1549   "")
1550
1551 ;; Split an add that we can't do in one insn into two insns, each of which
1552 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1553 ;; add should be last in case the result gets used in an address.
1554
1555 (define_split
1556   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1557         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1558                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1559   ""
1560   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1561    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1562 {
1563   HOST_WIDE_INT val = INTVAL (operands[2]);
1564   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1565   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1566
1567   operands[4] = GEN_INT (low);
1568   if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1569     operands[3] = GEN_INT (rest);
1570   else if (! no_new_pseudos)
1571     {
1572       operands[3] = gen_reg_rtx (DImode);
1573       emit_move_insn (operands[3], operands[2]);
1574       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1575       DONE;
1576     }
1577   else
1578     FAIL;
1579 })
1580
1581 (define_insn "one_cmpl<mode>2"
1582   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1583         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1584   ""
1585   "nor %0,%1,%1")
1586
1587 (define_insn ""
1588   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1589         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1590                     (const_int 0)))
1591    (clobber (match_scratch:P 2 "=r,r"))]
1592   ""
1593   "@
1594    nor. %2,%1,%1
1595    #"
1596   [(set_attr "type" "compare")
1597    (set_attr "length" "4,8")])
1598
1599 (define_split
1600   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1601         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1602                     (const_int 0)))
1603    (clobber (match_scratch:P 2 ""))]
1604   "reload_completed"
1605   [(set (match_dup 2)
1606         (not:P (match_dup 1)))
1607    (set (match_dup 0)
1608         (compare:CC (match_dup 2)
1609                     (const_int 0)))]
1610   "")
1611
1612 (define_insn ""
1613   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1614         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1615                     (const_int 0)))
1616    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1617         (not:P (match_dup 1)))]
1618   ""
1619   "@
1620    nor. %0,%1,%1
1621    #"
1622   [(set_attr "type" "compare")
1623    (set_attr "length" "4,8")])
1624
1625 (define_split
1626   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1627         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1628                     (const_int 0)))
1629    (set (match_operand:P 0 "gpc_reg_operand" "")
1630         (not:P (match_dup 1)))]
1631   "reload_completed"
1632   [(set (match_dup 0)
1633         (not:P (match_dup 1)))
1634    (set (match_dup 2)
1635         (compare:CC (match_dup 0)
1636                     (const_int 0)))]
1637   "")
1638
1639 (define_insn ""
1640   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1641         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1642                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1643   "! TARGET_POWERPC"
1644   "{sf%I1|subf%I1c} %0,%2,%1")
1645
1646 (define_insn ""
1647   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1648         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1649                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1650   "TARGET_POWERPC"
1651   "@
1652    subf %0,%2,%1
1653    subfic %0,%2,%1")
1654
1655 (define_insn ""
1656   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1657         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1658                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1659                     (const_int 0)))
1660    (clobber (match_scratch:SI 3 "=r,r"))]
1661   "! TARGET_POWERPC"
1662   "@
1663    {sf.|subfc.} %3,%2,%1
1664    #"
1665   [(set_attr "type" "compare")
1666    (set_attr "length" "4,8")])
1667
1668 (define_insn ""
1669   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1670         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1671                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1672                     (const_int 0)))
1673    (clobber (match_scratch:P 3 "=r,r"))]
1674   "TARGET_POWERPC"
1675   "@
1676    subf. %3,%2,%1
1677    #"
1678   [(set_attr "type" "fast_compare")
1679    (set_attr "length" "4,8")])
1680
1681 (define_split
1682   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1683         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1684                              (match_operand:P 2 "gpc_reg_operand" ""))
1685                     (const_int 0)))
1686    (clobber (match_scratch:P 3 ""))]
1687   "reload_completed"
1688   [(set (match_dup 3)
1689         (minus:P (match_dup 1)
1690                   (match_dup 2)))
1691    (set (match_dup 0)
1692         (compare:CC (match_dup 3)
1693                     (const_int 0)))]
1694   "")
1695
1696 (define_insn ""
1697   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1698         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1699                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1700                     (const_int 0)))
1701    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1702         (minus:SI (match_dup 1) (match_dup 2)))]
1703   "! TARGET_POWERPC"
1704   "@
1705    {sf.|subfc.} %0,%2,%1
1706    #"
1707   [(set_attr "type" "compare")
1708    (set_attr "length" "4,8")])
1709
1710 (define_insn ""
1711   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1712         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1713                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1714                     (const_int 0)))
1715    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1716         (minus:P (match_dup 1)
1717                   (match_dup 2)))]
1718   "TARGET_POWERPC"
1719   "@
1720    subf. %0,%2,%1
1721    #"
1722   [(set_attr "type" "fast_compare")
1723    (set_attr "length" "4,8")])
1724
1725 (define_split
1726   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1727         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1728                              (match_operand:P 2 "gpc_reg_operand" ""))
1729                     (const_int 0)))
1730    (set (match_operand:P 0 "gpc_reg_operand" "")
1731         (minus:P (match_dup 1)
1732                   (match_dup 2)))]
1733   "reload_completed"
1734   [(set (match_dup 0)
1735         (minus:P (match_dup 1)
1736                   (match_dup 2)))
1737    (set (match_dup 3)
1738         (compare:CC (match_dup 0)
1739                     (const_int 0)))]
1740   "")
1741
1742 (define_expand "sub<mode>3"
1743   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1744         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1745                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
1746   ""
1747   "
1748 {
1749   if (GET_CODE (operands[2]) == CONST_INT)
1750     {
1751       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1752                                  negate_rtx (<MODE>mode, operands[2])));
1753       DONE;
1754     }
1755 }")
1756
1757 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1758 ;; instruction and some auxiliary computations.  Then we just have a single
1759 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1760 ;; combine.
1761
1762 (define_expand "sminsi3"
1763   [(set (match_dup 3)
1764         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1765                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1766                          (const_int 0)
1767                          (minus:SI (match_dup 2) (match_dup 1))))
1768    (set (match_operand:SI 0 "gpc_reg_operand" "")
1769         (minus:SI (match_dup 2) (match_dup 3)))]
1770   "TARGET_POWER || TARGET_ISEL"
1771   "
1772 {
1773   if (TARGET_ISEL)
1774     {
1775       operands[2] = force_reg (SImode, operands[2]);
1776       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1777       DONE;
1778     }
1779
1780   operands[3] = gen_reg_rtx (SImode);
1781 }")
1782
1783 (define_split
1784   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1785         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1786                  (match_operand:SI 2 "reg_or_short_operand" "")))
1787    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1788   "TARGET_POWER"
1789   [(set (match_dup 3)
1790         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1791                          (const_int 0)
1792                          (minus:SI (match_dup 2) (match_dup 1))))
1793    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1794   "")
1795
1796 (define_expand "smaxsi3"
1797   [(set (match_dup 3)
1798         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1799                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1800                          (const_int 0)
1801                          (minus:SI (match_dup 2) (match_dup 1))))
1802    (set (match_operand:SI 0 "gpc_reg_operand" "")
1803         (plus:SI (match_dup 3) (match_dup 1)))]
1804   "TARGET_POWER || TARGET_ISEL"
1805   "
1806 {
1807   if (TARGET_ISEL)
1808     {
1809       operands[2] = force_reg (SImode, operands[2]);
1810       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1811       DONE;
1812     }
1813   operands[3] = gen_reg_rtx (SImode);
1814 }")
1815
1816 (define_split
1817   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1818         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1819                  (match_operand:SI 2 "reg_or_short_operand" "")))
1820    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1821   "TARGET_POWER"
1822   [(set (match_dup 3)
1823         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1824                          (const_int 0)
1825                          (minus:SI (match_dup 2) (match_dup 1))))
1826    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1827   "")
1828
1829 (define_expand "uminsi3"
1830   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1831                               (match_dup 5)))
1832    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1833                               (match_dup 5)))
1834    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1835                                        (const_int 0)
1836                                        (minus:SI (match_dup 4) (match_dup 3))))
1837    (set (match_operand:SI 0 "gpc_reg_operand" "")
1838         (minus:SI (match_dup 2) (match_dup 3)))]
1839   "TARGET_POWER || TARGET_ISEL"
1840   "
1841 {
1842   if (TARGET_ISEL)
1843     {
1844       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1845       DONE;
1846     }
1847   operands[3] = gen_reg_rtx (SImode);
1848   operands[4] = gen_reg_rtx (SImode);
1849   operands[5] = GEN_INT (-2147483647 - 1);
1850 }")
1851
1852 (define_expand "umaxsi3"
1853   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1854                               (match_dup 5)))
1855    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1856                               (match_dup 5)))
1857    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1858                                        (const_int 0)
1859                                        (minus:SI (match_dup 4) (match_dup 3))))
1860    (set (match_operand:SI 0 "gpc_reg_operand" "")
1861         (plus:SI (match_dup 3) (match_dup 1)))]
1862   "TARGET_POWER || TARGET_ISEL"
1863   "
1864 {
1865   if (TARGET_ISEL)
1866     {
1867       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1868       DONE;
1869     }
1870   operands[3] = gen_reg_rtx (SImode);
1871   operands[4] = gen_reg_rtx (SImode);
1872   operands[5] = GEN_INT (-2147483647 - 1);
1873 }")
1874
1875 (define_insn ""
1876   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1877         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1878                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1879                          (const_int 0)
1880                          (minus:SI (match_dup 2) (match_dup 1))))]
1881   "TARGET_POWER"
1882   "doz%I2 %0,%1,%2")
1883
1884 (define_insn ""
1885   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1886         (compare:CC
1887          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1888                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1889                           (const_int 0)
1890                           (minus:SI (match_dup 2) (match_dup 1)))
1891          (const_int 0)))
1892    (clobber (match_scratch:SI 3 "=r,r"))]
1893   "TARGET_POWER"
1894   "@
1895    doz%I2. %3,%1,%2
1896    #"
1897   [(set_attr "type" "delayed_compare")
1898    (set_attr "length" "4,8")])
1899
1900 (define_split
1901   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1902         (compare:CC
1903          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1904                               (match_operand:SI 2 "reg_or_short_operand" ""))
1905                           (const_int 0)
1906                           (minus:SI (match_dup 2) (match_dup 1)))
1907          (const_int 0)))
1908    (clobber (match_scratch:SI 3 ""))]
1909   "TARGET_POWER && reload_completed"
1910   [(set (match_dup 3)
1911         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1912                           (const_int 0)
1913                           (minus:SI (match_dup 2) (match_dup 1))))
1914    (set (match_dup 0)
1915         (compare:CC (match_dup 3)
1916                     (const_int 0)))]
1917   "")
1918
1919 (define_insn ""
1920   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1921         (compare:CC
1922          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1923                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1924                           (const_int 0)
1925                           (minus:SI (match_dup 2) (match_dup 1)))
1926          (const_int 0)))
1927    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1928         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1929                          (const_int 0)
1930                          (minus:SI (match_dup 2) (match_dup 1))))]
1931   "TARGET_POWER"
1932   "@
1933    doz%I2. %0,%1,%2
1934    #"
1935   [(set_attr "type" "delayed_compare")
1936    (set_attr "length" "4,8")])
1937
1938 (define_split
1939   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1940         (compare:CC
1941          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1942                               (match_operand:SI 2 "reg_or_short_operand" ""))
1943                           (const_int 0)
1944                           (minus:SI (match_dup 2) (match_dup 1)))
1945          (const_int 0)))
1946    (set (match_operand:SI 0 "gpc_reg_operand" "")
1947         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1948                          (const_int 0)
1949                          (minus:SI (match_dup 2) (match_dup 1))))]
1950   "TARGET_POWER && reload_completed"
1951   [(set (match_dup 0)
1952         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1953                          (const_int 0)
1954                          (minus:SI (match_dup 2) (match_dup 1))))
1955    (set (match_dup 3)
1956         (compare:CC (match_dup 0)
1957                     (const_int 0)))]
1958   "")
1959
1960 ;; We don't need abs with condition code because such comparisons should
1961 ;; never be done.
1962 (define_expand "abssi2"
1963   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1964         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1965   ""
1966   "
1967 {
1968   if (TARGET_ISEL)
1969     {
1970       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
1971       DONE;
1972     }
1973   else if (! TARGET_POWER)
1974     {
1975       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1976       DONE;
1977     }
1978 }")
1979
1980 (define_insn "*abssi2_power"
1981   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1982         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1983   "TARGET_POWER"
1984   "abs %0,%1")
1985
1986 (define_insn_and_split "abssi2_isel"
1987   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1988         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
1989    (clobber (match_scratch:SI 2 "=&b"))
1990    (clobber (match_scratch:CC 3 "=y"))]
1991   "TARGET_ISEL"
1992   "#"
1993   "&& reload_completed"
1994   [(set (match_dup 2) (neg:SI (match_dup 1)))
1995    (set (match_dup 3)
1996         (compare:CC (match_dup 1)
1997                     (const_int 0)))
1998    (set (match_dup 0)
1999         (if_then_else:SI (ge (match_dup 3)
2000                              (const_int 0))
2001                          (match_dup 1)
2002                          (match_dup 2)))]
2003   "")
2004
2005 (define_insn_and_split "abssi2_nopower"
2006   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2007         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
2008    (clobber (match_scratch:SI 2 "=&r,&r"))]
2009   "! TARGET_POWER && ! TARGET_ISEL"
2010   "#"
2011   "&& reload_completed"
2012   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2013    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2014    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
2015   "")
2016
2017 (define_insn "*nabs_power"
2018   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2019         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
2020   "TARGET_POWER"
2021   "nabs %0,%1")
2022
2023 (define_insn_and_split "*nabs_nopower"
2024   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2025         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
2026    (clobber (match_scratch:SI 2 "=&r,&r"))]
2027   "! TARGET_POWER"
2028   "#"
2029   "&& reload_completed"
2030   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2031    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2032    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
2033   "")
2034
2035 (define_expand "neg<mode>2"
2036   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
2037         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
2038   ""
2039   "")
2040
2041 (define_insn "*neg<mode>2_internal"
2042   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2043         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2044   ""
2045   "neg %0,%1")
2046
2047 (define_insn ""
2048   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2049         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2050                     (const_int 0)))
2051    (clobber (match_scratch:P 2 "=r,r"))]
2052   ""
2053   "@
2054    neg. %2,%1
2055    #"
2056   [(set_attr "type" "fast_compare")
2057    (set_attr "length" "4,8")])
2058
2059 (define_split
2060   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2061         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2062                     (const_int 0)))
2063    (clobber (match_scratch:P 2 ""))]
2064   "reload_completed"
2065   [(set (match_dup 2)
2066         (neg:P (match_dup 1)))
2067    (set (match_dup 0)
2068         (compare:CC (match_dup 2)
2069                     (const_int 0)))]
2070   "")
2071
2072 (define_insn ""
2073   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2074         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2075                     (const_int 0)))
2076    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2077         (neg:P (match_dup 1)))]
2078   ""
2079   "@
2080    neg. %0,%1
2081    #"
2082   [(set_attr "type" "fast_compare")
2083    (set_attr "length" "4,8")])
2084
2085 (define_split
2086   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2087         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2088                     (const_int 0)))
2089    (set (match_operand:P 0 "gpc_reg_operand" "")
2090         (neg:P (match_dup 1)))]
2091   "reload_completed"
2092   [(set (match_dup 0)
2093         (neg:P (match_dup 1)))
2094    (set (match_dup 2)
2095         (compare:CC (match_dup 0)
2096                     (const_int 0)))]
2097   "")
2098
2099 (define_insn "clz<mode>2"
2100   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2101         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2102   ""
2103   "{cntlz|cntlz<wd>} %0,%1")
2104
2105 (define_expand "ctz<mode>2"
2106   [(set (match_dup 2)
2107         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))
2108    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2109                                           (match_dup 2)))
2110               (clobber (scratch:CC))])
2111    (set (match_dup 4) (clz:GPR (match_dup 3)))
2112    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2113         (minus:GPR (match_dup 5) (match_dup 4)))]
2114   ""
2115   {
2116      operands[2] = gen_reg_rtx (<MODE>mode);
2117      operands[3] = gen_reg_rtx (<MODE>mode);
2118      operands[4] = gen_reg_rtx (<MODE>mode);
2119      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
2120   })
2121
2122 (define_expand "ffs<mode>2"
2123   [(set (match_dup 2)
2124         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))
2125    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2126                                           (match_dup 2)))
2127               (clobber (scratch:CC))])
2128    (set (match_dup 4) (clz:GPR (match_dup 3)))
2129    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2130         (minus:GPR (match_dup 5) (match_dup 4)))]
2131   ""
2132   {
2133      operands[2] = gen_reg_rtx (<MODE>mode);
2134      operands[3] = gen_reg_rtx (<MODE>mode);
2135      operands[4] = gen_reg_rtx (<MODE>mode);
2136      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
2137   })
2138
2139 (define_expand "popcount<mode>2"
2140   [(set (match_dup 2)
2141         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2142                      UNSPEC_POPCNTB))
2143    (set (match_dup 3)
2144         (mult:GPR (match_dup 2) (match_dup 4)))
2145    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2146         (lshiftrt:GPR (match_dup 3) (match_dup 5)))]
2147   "TARGET_POPCNTB"
2148   {
2149     operands[2] = gen_reg_rtx (<MODE>mode);
2150     operands[3] = gen_reg_rtx (<MODE>mode);
2151     operands[4] = force_reg (<MODE>mode,
2152                              <MODE>mode == SImode
2153                              ? GEN_INT (0x01010101)
2154                              : GEN_INT ((HOST_WIDE_INT)
2155                                         0x01010101 << 32 | 0x01010101));
2156     operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 8);
2157   })
2158
2159 (define_insn "popcntb<mode>2"
2160   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2161         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2162                      UNSPEC_POPCNTB))]
2163   "TARGET_POPCNTB"
2164   "popcntb %0,%1")
2165
2166 (define_expand "mulsi3"
2167   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2168    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2169    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
2170   ""
2171   "
2172 {
2173   if (TARGET_POWER)
2174     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
2175   else
2176     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
2177   DONE;
2178 }")
2179
2180 (define_insn "mulsi3_mq"
2181   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2182         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2183                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
2184    (clobber (match_scratch:SI 3 "=q,q"))]
2185   "TARGET_POWER"
2186   "@
2187    {muls|mullw} %0,%1,%2
2188    {muli|mulli} %0,%1,%2"
2189    [(set (attr "type")
2190       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2191                 (const_string "imul3")
2192              (match_operand:SI 2 "short_cint_operand" "")
2193                 (const_string "imul2")]
2194         (const_string "imul")))])
2195
2196 (define_insn "mulsi3_no_mq"
2197   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2198         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2199                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2200   "! TARGET_POWER"
2201   "@
2202    {muls|mullw} %0,%1,%2
2203    {muli|mulli} %0,%1,%2"
2204    [(set (attr "type")
2205       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2206                 (const_string "imul3")
2207              (match_operand:SI 2 "short_cint_operand" "")
2208                 (const_string "imul2")]
2209         (const_string "imul")))])
2210
2211 (define_insn "*mulsi3_mq_internal1"
2212   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2213         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2214                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2215                     (const_int 0)))
2216    (clobber (match_scratch:SI 3 "=r,r"))
2217    (clobber (match_scratch:SI 4 "=q,q"))]
2218   "TARGET_POWER"
2219   "@
2220    {muls.|mullw.} %3,%1,%2
2221    #"
2222   [(set_attr "type" "imul_compare")
2223    (set_attr "length" "4,8")])
2224
2225 (define_split
2226   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2227         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2228                              (match_operand:SI 2 "gpc_reg_operand" ""))
2229                     (const_int 0)))
2230    (clobber (match_scratch:SI 3 ""))
2231    (clobber (match_scratch:SI 4 ""))]
2232   "TARGET_POWER && reload_completed"
2233   [(parallel [(set (match_dup 3)
2234         (mult:SI (match_dup 1) (match_dup 2)))
2235    (clobber (match_dup 4))])
2236    (set (match_dup 0)
2237         (compare:CC (match_dup 3)
2238                     (const_int 0)))]
2239   "")
2240
2241 (define_insn "*mulsi3_no_mq_internal1"
2242   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2243         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2244                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2245                     (const_int 0)))
2246    (clobber (match_scratch:SI 3 "=r,r"))]
2247   "! TARGET_POWER"
2248   "@
2249    {muls.|mullw.} %3,%1,%2
2250    #"
2251   [(set_attr "type" "imul_compare")
2252    (set_attr "length" "4,8")])
2253
2254 (define_split
2255   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2256         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2257                              (match_operand:SI 2 "gpc_reg_operand" ""))
2258                     (const_int 0)))
2259    (clobber (match_scratch:SI 3 ""))]
2260   "! TARGET_POWER && reload_completed"
2261   [(set (match_dup 3)
2262         (mult:SI (match_dup 1) (match_dup 2)))
2263    (set (match_dup 0)
2264         (compare:CC (match_dup 3)
2265                     (const_int 0)))]
2266   "")
2267
2268 (define_insn "*mulsi3_mq_internal2"
2269   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2270         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2271                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2272                     (const_int 0)))
2273    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2274         (mult:SI (match_dup 1) (match_dup 2)))
2275    (clobber (match_scratch:SI 4 "=q,q"))]
2276   "TARGET_POWER"
2277   "@
2278    {muls.|mullw.} %0,%1,%2
2279    #"
2280   [(set_attr "type" "imul_compare")
2281    (set_attr "length" "4,8")])
2282
2283 (define_split
2284   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2285         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2286                              (match_operand:SI 2 "gpc_reg_operand" ""))
2287                     (const_int 0)))
2288    (set (match_operand:SI 0 "gpc_reg_operand" "")
2289         (mult:SI (match_dup 1) (match_dup 2)))
2290    (clobber (match_scratch:SI 4 ""))]
2291   "TARGET_POWER && reload_completed"
2292   [(parallel [(set (match_dup 0)
2293         (mult:SI (match_dup 1) (match_dup 2)))
2294    (clobber (match_dup 4))])
2295    (set (match_dup 3)
2296         (compare:CC (match_dup 0)
2297                     (const_int 0)))]
2298   "")
2299
2300 (define_insn "*mulsi3_no_mq_internal2"
2301   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2302         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2303                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2304                     (const_int 0)))
2305    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2306         (mult:SI (match_dup 1) (match_dup 2)))]
2307   "! TARGET_POWER"
2308   "@
2309    {muls.|mullw.} %0,%1,%2
2310    #"
2311   [(set_attr "type" "imul_compare")
2312    (set_attr "length" "4,8")])
2313
2314 (define_split
2315   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2316         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2317                              (match_operand:SI 2 "gpc_reg_operand" ""))
2318                     (const_int 0)))
2319    (set (match_operand:SI 0 "gpc_reg_operand" "")
2320         (mult:SI (match_dup 1) (match_dup 2)))]
2321   "! TARGET_POWER && reload_completed"
2322   [(set (match_dup 0)
2323         (mult:SI (match_dup 1) (match_dup 2)))
2324    (set (match_dup 3)
2325         (compare:CC (match_dup 0)
2326                     (const_int 0)))]
2327   "")
2328
2329 ;; Operand 1 is divided by operand 2; quotient goes to operand
2330 ;; 0 and remainder to operand 3.
2331 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
2332
2333 (define_expand "divmodsi4"
2334   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2335                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2336                            (match_operand:SI 2 "gpc_reg_operand" "")))
2337               (set (match_operand:SI 3 "register_operand" "")
2338                    (mod:SI (match_dup 1) (match_dup 2)))])]
2339   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
2340   "
2341 {
2342   if (! TARGET_POWER && ! TARGET_POWERPC)
2343     {
2344       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2345       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2346       emit_insn (gen_divss_call ());
2347       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2348       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2349       DONE;
2350     }
2351 }")
2352
2353 (define_insn "*divmodsi4_internal"
2354   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2355         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2356                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2357    (set (match_operand:SI 3 "register_operand" "=q")
2358         (mod:SI (match_dup 1) (match_dup 2)))]
2359   "TARGET_POWER"
2360   "divs %0,%1,%2"
2361   [(set_attr "type" "idiv")])
2362
2363 (define_expand "udiv<mode>3"
2364   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2365         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2366                   (match_operand:GPR 2 "gpc_reg_operand" "")))]
2367   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
2368   "
2369 {
2370   if (! TARGET_POWER && ! TARGET_POWERPC)
2371     {
2372       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2373       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2374       emit_insn (gen_quous_call ());
2375       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2376       DONE;
2377     }
2378   else if (TARGET_POWER)
2379     {
2380       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
2381       DONE;
2382     }
2383 }")
2384
2385 (define_insn "udivsi3_mq"
2386   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2387         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2388                  (match_operand:SI 2 "gpc_reg_operand" "r")))
2389    (clobber (match_scratch:SI 3 "=q"))]
2390   "TARGET_POWERPC && TARGET_POWER"
2391   "divwu %0,%1,%2"
2392   [(set_attr "type" "idiv")])
2393
2394 (define_insn "*udivsi3_no_mq"
2395   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2396         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2397                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2398   "TARGET_POWERPC && ! TARGET_POWER"
2399   "div<wd>u %0,%1,%2"
2400   [(set_attr "type" "idiv")])
2401
2402 ;; For powers of two we can do srai/aze for divide and then adjust for
2403 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
2404 ;; used; for PowerPC, force operands into register and do a normal divide;
2405 ;; for AIX common-mode, use quoss call on register operands.
2406 (define_expand "div<mode>3"
2407   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2408         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2409                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2410   ""
2411   "
2412 {
2413   if (GET_CODE (operands[2]) == CONST_INT
2414       && INTVAL (operands[2]) > 0
2415       && exact_log2 (INTVAL (operands[2])) >= 0)
2416     ;
2417   else if (TARGET_POWERPC)
2418     {
2419       operands[2] = force_reg (SImode, operands[2]);
2420       if (TARGET_POWER)
2421         {
2422           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
2423           DONE;
2424         }
2425     }
2426   else if (TARGET_POWER)
2427     FAIL;
2428   else
2429     {
2430       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2431       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2432       emit_insn (gen_quoss_call ());
2433       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2434       DONE;
2435     }
2436 }")
2437
2438 (define_insn "divsi3_mq"
2439   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2440         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2441                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2442    (clobber (match_scratch:SI 3 "=q"))]
2443   "TARGET_POWERPC && TARGET_POWER"
2444   "divw %0,%1,%2"
2445   [(set_attr "type" "idiv")])
2446
2447 (define_insn "*div<mode>3_no_mq"
2448   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2449         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2450                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2451   "TARGET_POWERPC && ! TARGET_POWER"
2452   "div<wd> %0,%1,%2"
2453   [(set_attr "type" "idiv")])
2454
2455 (define_expand "mod<mode>3"
2456   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
2457    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
2458    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
2459   ""
2460   "
2461 {
2462   int i;
2463   rtx temp1;
2464   rtx temp2;
2465
2466   if (GET_CODE (operands[2]) != CONST_INT
2467       || INTVAL (operands[2]) <= 0
2468       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2469     FAIL;
2470
2471   temp1 = gen_reg_rtx (<MODE>mode);
2472   temp2 = gen_reg_rtx (<MODE>mode);
2473
2474   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
2475   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
2476   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
2477   DONE;
2478 }")
2479
2480 (define_insn ""
2481   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2482         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2483                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
2484   ""
2485   "{srai|sra<wd>i} %0,%1,%p2\;{aze|addze} %0,%0"
2486   [(set_attr "type" "two")
2487    (set_attr "length" "8")])
2488
2489 (define_insn ""
2490   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2491         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2492                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2493                     (const_int 0)))
2494    (clobber (match_scratch:P 3 "=r,r"))]
2495   ""
2496   "@
2497    {srai|sra<wd>i} %3,%1,%p2\;{aze.|addze.} %3,%3
2498    #"
2499   [(set_attr "type" "compare")
2500    (set_attr "length" "8,12")])
2501
2502 (define_split
2503   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2504         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2505                              (match_operand:GPR 2 "exact_log2_cint_operand"
2506                               ""))
2507                     (const_int 0)))
2508    (clobber (match_scratch:GPR 3 ""))]
2509   "reload_completed"
2510   [(set (match_dup 3)
2511         (div:<MODE> (match_dup 1) (match_dup 2)))
2512    (set (match_dup 0)
2513         (compare:CC (match_dup 3)
2514                     (const_int 0)))]
2515   "")
2516
2517 (define_insn ""
2518   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2519         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2520                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2521                     (const_int 0)))
2522    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2523         (div:P (match_dup 1) (match_dup 2)))]
2524   ""
2525   "@
2526    {srai|sra<wd>i} %0,%1,%p2\;{aze.|addze.} %0,%0
2527    #"
2528   [(set_attr "type" "compare")
2529    (set_attr "length" "8,12")])
2530
2531 (define_split
2532   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2533         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2534                              (match_operand:GPR 2 "exact_log2_cint_operand"
2535                               ""))
2536                     (const_int 0)))
2537    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2538         (div:GPR (match_dup 1) (match_dup 2)))]
2539   "reload_completed"
2540   [(set (match_dup 0)
2541         (div:<MODE> (match_dup 1) (match_dup 2)))
2542    (set (match_dup 3)
2543         (compare:CC (match_dup 0)
2544                     (const_int 0)))]
2545   "")
2546
2547 (define_insn ""
2548   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2549         (udiv:SI
2550          (plus:DI (ashift:DI
2551                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
2552                    (const_int 32))
2553                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
2554          (match_operand:SI 3 "gpc_reg_operand" "r")))
2555    (set (match_operand:SI 2 "register_operand" "=*q")
2556         (umod:SI
2557          (plus:DI (ashift:DI
2558                    (zero_extend:DI (match_dup 1)) (const_int 32))
2559                   (zero_extend:DI (match_dup 4)))
2560          (match_dup 3)))]
2561   "TARGET_POWER"
2562   "div %0,%1,%3"
2563   [(set_attr "type" "idiv")])
2564
2565 ;; To do unsigned divide we handle the cases of the divisor looking like a
2566 ;; negative number.  If it is a constant that is less than 2**31, we don't
2567 ;; have to worry about the branches.  So make a few subroutines here.
2568 ;;
2569 ;; First comes the normal case.
2570 (define_expand "udivmodsi4_normal"
2571   [(set (match_dup 4) (const_int 0))
2572    (parallel [(set (match_operand:SI 0 "" "")
2573                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2574                                                 (const_int 32))
2575                                      (zero_extend:DI (match_operand:SI 1 "" "")))
2576                             (match_operand:SI 2 "" "")))
2577               (set (match_operand:SI 3 "" "")
2578                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2579                                                 (const_int 32))
2580                                      (zero_extend:DI (match_dup 1)))
2581                             (match_dup 2)))])]
2582   "TARGET_POWER"
2583   "
2584 { operands[4] = gen_reg_rtx (SImode); }")
2585
2586 ;; This handles the branches.
2587 (define_expand "udivmodsi4_tests"
2588   [(set (match_operand:SI 0 "" "") (const_int 0))
2589    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
2590    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
2591    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
2592                            (label_ref (match_operand:SI 4 "" "")) (pc)))
2593    (set (match_dup 0) (const_int 1))
2594    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
2595    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
2596    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
2597                            (label_ref (match_dup 4)) (pc)))]
2598   "TARGET_POWER"
2599   "
2600 { operands[5] = gen_reg_rtx (CCUNSmode);
2601   operands[6] = gen_reg_rtx (CCmode);
2602 }")
2603
2604 (define_expand "udivmodsi4"
2605   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2606                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2607                             (match_operand:SI 2 "reg_or_cint_operand" "")))
2608               (set (match_operand:SI 3 "gpc_reg_operand" "")
2609                    (umod:SI (match_dup 1) (match_dup 2)))])]
2610   ""
2611   "
2612 {
2613   rtx label = 0;
2614
2615   if (! TARGET_POWER)
2616     {
2617       if (! TARGET_POWERPC)
2618         {
2619           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2620           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2621           emit_insn (gen_divus_call ());
2622           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2623           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2624           DONE;
2625         }
2626       else
2627         FAIL;
2628     }
2629
2630   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
2631     {
2632       operands[2] = force_reg (SImode, operands[2]);
2633       label = gen_label_rtx ();
2634       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
2635                                   operands[3], label));
2636     }
2637   else
2638     operands[2] = force_reg (SImode, operands[2]);
2639
2640   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
2641                                operands[3]));
2642   if (label)
2643     emit_label (label);
2644
2645   DONE;
2646 }")
2647
2648 ;; AIX architecture-independent common-mode multiply (DImode),
2649 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
2650 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
2651 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
2652 ;; assumed unused if generating common-mode, so ignore.
2653 (define_insn "mulh_call"
2654   [(set (reg:SI 3)
2655         (truncate:SI
2656          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
2657                                (sign_extend:DI (reg:SI 4)))
2658                       (const_int 32))))
2659    (clobber (match_scratch:SI 0 "=l"))]
2660   "! TARGET_POWER && ! TARGET_POWERPC"
2661   "bla __mulh"
2662   [(set_attr "type" "imul")])
2663
2664 (define_insn "mull_call"
2665   [(set (reg:DI 3)
2666         (mult:DI (sign_extend:DI (reg:SI 3))
2667                  (sign_extend:DI (reg:SI 4))))
2668    (clobber (match_scratch:SI 0 "=l"))
2669    (clobber (reg:SI 0))]
2670   "! TARGET_POWER && ! TARGET_POWERPC"
2671   "bla __mull"
2672   [(set_attr "type" "imul")])
2673
2674 (define_insn "divss_call"
2675   [(set (reg:SI 3)
2676         (div:SI (reg:SI 3) (reg:SI 4)))
2677    (set (reg:SI 4)
2678         (mod:SI (reg:SI 3) (reg:SI 4)))
2679    (clobber (match_scratch:SI 0 "=l"))
2680    (clobber (reg:SI 0))]
2681   "! TARGET_POWER && ! TARGET_POWERPC"
2682   "bla __divss"
2683   [(set_attr "type" "idiv")])
2684
2685 (define_insn "divus_call"
2686   [(set (reg:SI 3)
2687         (udiv:SI (reg:SI 3) (reg:SI 4)))
2688    (set (reg:SI 4)
2689         (umod:SI (reg:SI 3) (reg:SI 4)))
2690    (clobber (match_scratch:SI 0 "=l"))
2691    (clobber (reg:SI 0))
2692    (clobber (match_scratch:CC 1 "=x"))
2693    (clobber (reg:CC 69))]
2694   "! TARGET_POWER && ! TARGET_POWERPC"
2695   "bla __divus"
2696   [(set_attr "type" "idiv")])
2697
2698 (define_insn "quoss_call"
2699   [(set (reg:SI 3)
2700         (div:SI (reg:SI 3) (reg:SI 4)))
2701    (clobber (match_scratch:SI 0 "=l"))]
2702   "! TARGET_POWER && ! TARGET_POWERPC"
2703   "bla __quoss"
2704   [(set_attr "type" "idiv")])
2705
2706 (define_insn "quous_call"
2707   [(set (reg:SI 3)
2708         (udiv:SI (reg:SI 3) (reg:SI 4)))
2709    (clobber (match_scratch:SI 0 "=l"))
2710    (clobber (reg:SI 0))
2711    (clobber (match_scratch:CC 1 "=x"))
2712    (clobber (reg:CC 69))]
2713   "! TARGET_POWER && ! TARGET_POWERPC"
2714   "bla __quous"
2715   [(set_attr "type" "idiv")])
2716 \f
2717 ;; Logical instructions
2718 ;; The logical instructions are mostly combined by using match_operator,
2719 ;; but the plain AND insns are somewhat different because there is no
2720 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2721 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2722
2723 (define_insn "andsi3"
2724   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2725         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2726                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2727    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2728   ""
2729   "@
2730    and %0,%1,%2
2731    {rlinm|rlwinm} %0,%1,0,%m2,%M2
2732    {andil.|andi.} %0,%1,%b2
2733    {andiu.|andis.} %0,%1,%u2"
2734   [(set_attr "type" "*,*,compare,compare")])
2735
2736 ;; Note to set cr's other than cr0 we do the and immediate and then
2737 ;; the test again -- this avoids a mfcr which on the higher end
2738 ;; machines causes an execution serialization
2739
2740 (define_insn "*andsi3_internal2"
2741   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2742         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2743                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2744                     (const_int 0)))
2745    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2746    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2747   "TARGET_32BIT"
2748   "@
2749    and. %3,%1,%2
2750    {andil.|andi.} %3,%1,%b2
2751    {andiu.|andis.} %3,%1,%u2
2752    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2753    #
2754    #
2755    #
2756    #"
2757   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2758    (set_attr "length" "4,4,4,4,8,8,8,8")])
2759
2760 (define_insn "*andsi3_internal3"
2761   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2762         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2763                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2764                     (const_int 0)))
2765    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2766    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2767   "TARGET_64BIT"
2768   "@
2769    #
2770    {andil.|andi.} %3,%1,%b2
2771    {andiu.|andis.} %3,%1,%u2
2772    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2773    #
2774    #
2775    #
2776    #"
2777   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2778    (set_attr "length" "8,4,4,4,8,8,8,8")])
2779
2780 (define_split
2781   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2782         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2783                              (match_operand:GPR 2 "and_operand" ""))
2784                     (const_int 0)))
2785    (clobber (match_scratch:GPR 3 ""))
2786    (clobber (match_scratch:CC 4 ""))]
2787   "reload_completed"
2788   [(parallel [(set (match_dup 3)
2789                    (and:<MODE> (match_dup 1)
2790                                (match_dup 2)))
2791               (clobber (match_dup 4))])
2792    (set (match_dup 0)
2793         (compare:CC (match_dup 3)
2794                     (const_int 0)))]
2795   "")
2796
2797 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2798 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2799
2800 (define_split
2801   [(set (match_operand:CC 0 "cc_reg_operand" "")
2802         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2803                             (match_operand:SI 2 "gpc_reg_operand" ""))
2804                     (const_int 0)))
2805    (clobber (match_scratch:SI 3 ""))
2806    (clobber (match_scratch:CC 4 ""))]
2807   "TARGET_POWERPC64 && reload_completed"
2808   [(parallel [(set (match_dup 3)
2809                    (and:SI (match_dup 1)
2810                            (match_dup 2)))
2811               (clobber (match_dup 4))])
2812    (set (match_dup 0)
2813         (compare:CC (match_dup 3)
2814                     (const_int 0)))]
2815   "")
2816
2817 (define_insn "*andsi3_internal4"
2818   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2819         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2820                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2821                     (const_int 0)))
2822    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2823         (and:SI (match_dup 1)
2824                 (match_dup 2)))
2825    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2826   "TARGET_32BIT"
2827   "@
2828    and. %0,%1,%2
2829    {andil.|andi.} %0,%1,%b2
2830    {andiu.|andis.} %0,%1,%u2
2831    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2832    #
2833    #
2834    #
2835    #"
2836   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2837    (set_attr "length" "4,4,4,4,8,8,8,8")])
2838
2839 (define_insn "*andsi3_internal5"
2840   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2841         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2842                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2843                     (const_int 0)))
2844    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2845         (and:SI (match_dup 1)
2846                 (match_dup 2)))
2847    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2848   "TARGET_64BIT"
2849   "@
2850    #
2851    {andil.|andi.} %0,%1,%b2
2852    {andiu.|andis.} %0,%1,%u2
2853    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2854    #
2855    #
2856    #
2857    #"
2858   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2859    (set_attr "length" "8,4,4,4,8,8,8,8")])
2860
2861 (define_split
2862   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2863         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2864                             (match_operand:SI 2 "and_operand" ""))
2865                     (const_int 0)))
2866    (set (match_operand:SI 0 "gpc_reg_operand" "")
2867         (and:SI (match_dup 1)
2868                 (match_dup 2)))
2869    (clobber (match_scratch:CC 4 ""))]
2870   "reload_completed"
2871   [(parallel [(set (match_dup 0)
2872                    (and:SI (match_dup 1)
2873                            (match_dup 2)))
2874               (clobber (match_dup 4))])
2875    (set (match_dup 3)
2876         (compare:CC (match_dup 0)
2877                     (const_int 0)))]
2878   "")
2879
2880 (define_split
2881   [(set (match_operand:CC 3 "cc_reg_operand" "")
2882         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2883                             (match_operand:SI 2 "gpc_reg_operand" ""))
2884                     (const_int 0)))
2885    (set (match_operand:SI 0 "gpc_reg_operand" "")
2886         (and:SI (match_dup 1)
2887                 (match_dup 2)))
2888    (clobber (match_scratch:CC 4 ""))]
2889   "TARGET_POWERPC64 && reload_completed"
2890   [(parallel [(set (match_dup 0)
2891                    (and:SI (match_dup 1)
2892                            (match_dup 2)))
2893               (clobber (match_dup 4))])
2894    (set (match_dup 3)
2895         (compare:CC (match_dup 0)
2896                     (const_int 0)))]
2897   "")
2898
2899 ;; Handle the PowerPC64 rlwinm corner case
2900
2901 (define_insn_and_split "*andsi3_internal6"
2902   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2903         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2904                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2905   "TARGET_POWERPC64"
2906   "#"
2907   "TARGET_POWERPC64"
2908   [(set (match_dup 0)
2909         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
2910                 (match_dup 4)))
2911    (set (match_dup 0)
2912         (rotate:SI (match_dup 0) (match_dup 5)))]
2913   "
2914 {
2915   int mb = extract_MB (operands[2]);
2916   int me = extract_ME (operands[2]);
2917   operands[3] = GEN_INT (me + 1);
2918   operands[5] = GEN_INT (32 - (me + 1));
2919   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2920 }"
2921   [(set_attr "length" "8")])
2922
2923 (define_expand "iorsi3"
2924   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2925         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
2926                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2927   ""
2928   "
2929 {
2930   if (GET_CODE (operands[2]) == CONST_INT
2931       && ! logical_operand (operands[2], SImode))
2932     {
2933       HOST_WIDE_INT value = INTVAL (operands[2]);
2934       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2935                  ? operands[0] : gen_reg_rtx (SImode));
2936
2937       emit_insn (gen_iorsi3 (tmp, operands[1],
2938                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2939       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2940       DONE;
2941     }
2942 }")
2943
2944 (define_expand "xorsi3"
2945   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2946         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2947                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2948   ""
2949   "
2950 {
2951   if (GET_CODE (operands[2]) == CONST_INT
2952       && ! logical_operand (operands[2], SImode))
2953     {
2954       HOST_WIDE_INT value = INTVAL (operands[2]);
2955       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2956                  ? operands[0] : gen_reg_rtx (SImode));
2957
2958       emit_insn (gen_xorsi3 (tmp, operands[1],
2959                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2960       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2961       DONE;
2962     }
2963 }")
2964
2965 (define_insn "*boolsi3_internal1"
2966   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2967         (match_operator:SI 3 "boolean_or_operator"
2968          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
2969           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
2970   ""
2971   "@
2972    %q3 %0,%1,%2
2973    {%q3il|%q3i} %0,%1,%b2
2974    {%q3iu|%q3is} %0,%1,%u2")
2975
2976 (define_insn "*boolsi3_internal2"
2977   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2978         (compare:CC (match_operator:SI 4 "boolean_or_operator"
2979          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2980           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2981          (const_int 0)))
2982    (clobber (match_scratch:SI 3 "=r,r"))]
2983   "TARGET_32BIT"
2984   "@
2985    %q4. %3,%1,%2
2986    #"
2987   [(set_attr "type" "compare")
2988    (set_attr "length" "4,8")])
2989
2990 (define_split
2991   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2992         (compare:CC (match_operator:SI 4 "boolean_operator"
2993          [(match_operand:SI 1 "gpc_reg_operand" "")
2994           (match_operand:SI 2 "gpc_reg_operand" "")])
2995          (const_int 0)))
2996    (clobber (match_scratch:SI 3 ""))]
2997   "TARGET_32BIT && reload_completed"
2998   [(set (match_dup 3) (match_dup 4))
2999    (set (match_dup 0)
3000         (compare:CC (match_dup 3)
3001                     (const_int 0)))]
3002   "")
3003
3004 (define_insn "*boolsi3_internal3"
3005   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3006         (compare:CC (match_operator:SI 4 "boolean_operator"
3007          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3008           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3009          (const_int 0)))
3010    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3011         (match_dup 4))]
3012   "TARGET_32BIT"
3013   "@
3014    %q4. %0,%1,%2
3015    #"
3016   [(set_attr "type" "compare")
3017    (set_attr "length" "4,8")])
3018
3019 (define_split
3020   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3021         (compare:CC (match_operator:SI 4 "boolean_operator"
3022          [(match_operand:SI 1 "gpc_reg_operand" "")
3023           (match_operand:SI 2 "gpc_reg_operand" "")])
3024          (const_int 0)))
3025    (set (match_operand:SI 0 "gpc_reg_operand" "")
3026         (match_dup 4))]
3027   "TARGET_32BIT && reload_completed"
3028   [(set (match_dup 0) (match_dup 4))
3029    (set (match_dup 3)
3030         (compare:CC (match_dup 0)
3031                     (const_int 0)))]
3032   "")
3033
3034 ;; Split a logical operation that we can't do in one insn into two insns,
3035 ;; each of which does one 16-bit part.  This is used by combine.
3036
3037 (define_split
3038   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3039         (match_operator:SI 3 "boolean_or_operator"
3040          [(match_operand:SI 1 "gpc_reg_operand" "")
3041           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
3042   ""
3043   [(set (match_dup 0) (match_dup 4))
3044    (set (match_dup 0) (match_dup 5))]
3045 "
3046 {
3047   rtx i;
3048   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
3049   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3050                                 operands[1], i);
3051   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
3052   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3053                                 operands[0], i);
3054 }")
3055
3056 (define_insn "*boolcsi3_internal1"
3057   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3058         (match_operator:SI 3 "boolean_operator"
3059          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3060           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
3061   ""
3062   "%q3 %0,%2,%1")
3063
3064 (define_insn "*boolcsi3_internal2"
3065   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3066         (compare:CC (match_operator:SI 4 "boolean_operator"
3067          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3068           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3069          (const_int 0)))
3070    (clobber (match_scratch:SI 3 "=r,r"))]
3071   "TARGET_32BIT"
3072   "@
3073    %q4. %3,%2,%1
3074    #"
3075   [(set_attr "type" "compare")
3076    (set_attr "length" "4,8")])
3077
3078 (define_split
3079   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3080         (compare:CC (match_operator:SI 4 "boolean_operator"
3081          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3082           (match_operand:SI 2 "gpc_reg_operand" "")])
3083          (const_int 0)))
3084    (clobber (match_scratch:SI 3 ""))]
3085   "TARGET_32BIT && reload_completed"
3086   [(set (match_dup 3) (match_dup 4))
3087    (set (match_dup 0)
3088         (compare:CC (match_dup 3)
3089                     (const_int 0)))]
3090   "")
3091
3092 (define_insn "*boolcsi3_internal3"
3093   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3094         (compare:CC (match_operator:SI 4 "boolean_operator"
3095          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3096           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3097          (const_int 0)))
3098    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3099         (match_dup 4))]
3100   "TARGET_32BIT"
3101   "@
3102    %q4. %0,%2,%1
3103    #"
3104   [(set_attr "type" "compare")
3105    (set_attr "length" "4,8")])
3106
3107 (define_split
3108   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3109         (compare:CC (match_operator:SI 4 "boolean_operator"
3110          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3111           (match_operand:SI 2 "gpc_reg_operand" "")])
3112          (const_int 0)))
3113    (set (match_operand:SI 0 "gpc_reg_operand" "")
3114         (match_dup 4))]
3115   "TARGET_32BIT && reload_completed"
3116   [(set (match_dup 0) (match_dup 4))
3117    (set (match_dup 3)
3118         (compare:CC (match_dup 0)
3119                     (const_int 0)))]
3120   "")
3121
3122 (define_insn "*boolccsi3_internal1"
3123   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3124         (match_operator:SI 3 "boolean_operator"
3125          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3126           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3127   ""
3128   "%q3 %0,%1,%2")
3129
3130 (define_insn "*boolccsi3_internal2"
3131   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3132         (compare:CC (match_operator:SI 4 "boolean_operator"
3133          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3134           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3135          (const_int 0)))
3136    (clobber (match_scratch:SI 3 "=r,r"))]
3137   "TARGET_32BIT"
3138   "@
3139    %q4. %3,%1,%2
3140    #"
3141   [(set_attr "type" "compare")
3142    (set_attr "length" "4,8")])
3143
3144 (define_split
3145   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3146         (compare:CC (match_operator:SI 4 "boolean_operator"
3147          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3148           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3149          (const_int 0)))
3150    (clobber (match_scratch:SI 3 ""))]
3151   "TARGET_32BIT && reload_completed"
3152   [(set (match_dup 3) (match_dup 4))
3153    (set (match_dup 0)
3154         (compare:CC (match_dup 3)
3155                     (const_int 0)))]
3156   "")
3157
3158 (define_insn "*boolccsi3_internal3"
3159   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3160         (compare:CC (match_operator:SI 4 "boolean_operator"
3161          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3162           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3163          (const_int 0)))
3164    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3165         (match_dup 4))]
3166   "TARGET_32BIT"
3167   "@
3168    %q4. %0,%1,%2
3169    #"
3170   [(set_attr "type" "compare")
3171    (set_attr "length" "4,8")])
3172
3173 (define_split
3174   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3175         (compare:CC (match_operator:SI 4 "boolean_operator"
3176          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3177           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3178          (const_int 0)))
3179    (set (match_operand:SI 0 "gpc_reg_operand" "")
3180         (match_dup 4))]
3181   "TARGET_32BIT && reload_completed"
3182   [(set (match_dup 0) (match_dup 4))
3183    (set (match_dup 3)
3184         (compare:CC (match_dup 0)
3185                     (const_int 0)))]
3186   "")
3187
3188 ;; maskir insn.  We need four forms because things might be in arbitrary
3189 ;; orders.  Don't define forms that only set CR fields because these
3190 ;; would modify an input register.
3191
3192 (define_insn "*maskir_internal1"
3193   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3194         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3195                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3196                 (and:SI (match_dup 2)
3197                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
3198   "TARGET_POWER"
3199   "maskir %0,%3,%2")
3200
3201 (define_insn "*maskir_internal2"
3202   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3203         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3204                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3205                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3206                         (match_dup 2))))]
3207   "TARGET_POWER"
3208   "maskir %0,%3,%2")
3209
3210 (define_insn "*maskir_internal3"
3211   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3212         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
3213                         (match_operand:SI 3 "gpc_reg_operand" "r"))
3214                 (and:SI (not:SI (match_dup 2))
3215                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3216   "TARGET_POWER"
3217   "maskir %0,%3,%2")
3218
3219 (define_insn "*maskir_internal4"
3220   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3221         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3222                         (match_operand:SI 2 "gpc_reg_operand" "r"))
3223                 (and:SI (not:SI (match_dup 2))
3224                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3225   "TARGET_POWER"
3226   "maskir %0,%3,%2")
3227
3228 (define_insn "*maskir_internal5"
3229   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3230         (compare:CC
3231          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3232                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3233                  (and:SI (match_dup 2)
3234                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
3235          (const_int 0)))
3236    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3237         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3238                 (and:SI (match_dup 2) (match_dup 3))))]
3239   "TARGET_POWER"
3240   "@
3241    maskir. %0,%3,%2
3242    #"
3243   [(set_attr "type" "compare")
3244    (set_attr "length" "4,8")])
3245
3246 (define_split
3247   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3248         (compare:CC
3249          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3250                          (match_operand:SI 1 "gpc_reg_operand" ""))
3251                  (and:SI (match_dup 2)
3252                          (match_operand:SI 3 "gpc_reg_operand" "")))
3253          (const_int 0)))
3254    (set (match_operand:SI 0 "gpc_reg_operand" "")
3255         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3256                 (and:SI (match_dup 2) (match_dup 3))))]
3257   "TARGET_POWER && reload_completed"
3258   [(set (match_dup 0)
3259         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3260                 (and:SI (match_dup 2) (match_dup 3))))
3261    (set (match_dup 4)
3262         (compare:CC (match_dup 0)
3263                     (const_int 0)))]
3264   "")
3265
3266 (define_insn "*maskir_internal6"
3267   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3268         (compare:CC
3269          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3270                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3271                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3272                          (match_dup 2)))
3273          (const_int 0)))
3274    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3275         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3276                 (and:SI (match_dup 3) (match_dup 2))))]
3277   "TARGET_POWER"
3278   "@
3279    maskir. %0,%3,%2
3280    #"
3281   [(set_attr "type" "compare")
3282    (set_attr "length" "4,8")])
3283
3284 (define_split
3285   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3286         (compare:CC
3287          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3288                          (match_operand:SI 1 "gpc_reg_operand" ""))
3289                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3290                          (match_dup 2)))
3291          (const_int 0)))
3292    (set (match_operand:SI 0 "gpc_reg_operand" "")
3293         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3294                 (and:SI (match_dup 3) (match_dup 2))))]
3295   "TARGET_POWER && reload_completed"
3296   [(set (match_dup 0)
3297         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3298                 (and:SI (match_dup 3) (match_dup 2))))
3299    (set (match_dup 4)
3300         (compare:CC (match_dup 0)
3301                     (const_int 0)))]
3302   "")
3303
3304 (define_insn "*maskir_internal7"
3305   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3306         (compare:CC
3307          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
3308                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
3309                  (and:SI (not:SI (match_dup 2))
3310                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3311          (const_int 0)))
3312    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3313         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3314                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3315   "TARGET_POWER"
3316   "@
3317    maskir. %0,%3,%2
3318    #"
3319   [(set_attr "type" "compare")
3320    (set_attr "length" "4,8")])
3321
3322 (define_split
3323   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3324         (compare:CC
3325          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
3326                          (match_operand:SI 3 "gpc_reg_operand" ""))
3327                  (and:SI (not:SI (match_dup 2))
3328                          (match_operand:SI 1 "gpc_reg_operand" "")))
3329          (const_int 0)))
3330    (set (match_operand:SI 0 "gpc_reg_operand" "")
3331         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3332                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3333   "TARGET_POWER && reload_completed"
3334   [(set (match_dup 0)
3335         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3336                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3337    (set (match_dup 4)
3338         (compare:CC (match_dup 0)
3339                     (const_int 0)))]
3340   "")
3341
3342 (define_insn "*maskir_internal8"
3343   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3344         (compare:CC
3345          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3346                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3347                  (and:SI (not:SI (match_dup 2))
3348                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3349          (const_int 0)))
3350    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3351         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3352                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3353   "TARGET_POWER"
3354   "@
3355    maskir. %0,%3,%2
3356    #"
3357   [(set_attr "type" "compare")
3358    (set_attr "length" "4,8")])
3359
3360 (define_split
3361   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3362         (compare:CC
3363          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3364                          (match_operand:SI 2 "gpc_reg_operand" ""))
3365                  (and:SI (not:SI (match_dup 2))
3366                          (match_operand:SI 1 "gpc_reg_operand" "")))
3367          (const_int 0)))
3368    (set (match_operand:SI 0 "gpc_reg_operand" "")
3369         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3370                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3371   "TARGET_POWER && reload_completed"
3372   [(set (match_dup 0)
3373         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3374                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3375    (set (match_dup 4)
3376         (compare:CC (match_dup 0)
3377                     (const_int 0)))]
3378   "")
3379 \f
3380 ;; Rotate and shift insns, in all their variants.  These support shifts,
3381 ;; field inserts and extracts, and various combinations thereof.
3382 (define_expand "insv"
3383   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
3384                        (match_operand:SI 1 "const_int_operand" "")
3385                        (match_operand:SI 2 "const_int_operand" ""))
3386         (match_operand 3 "gpc_reg_operand" ""))]
3387   ""
3388   "
3389 {
3390   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3391      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3392      compiler if the address of the structure is taken later.  */
3393   if (GET_CODE (operands[0]) == SUBREG
3394       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3395     FAIL;
3396
3397   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
3398     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
3399   else
3400     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
3401   DONE;
3402 }")
3403
3404 (define_insn "insvsi"
3405   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3406                          (match_operand:SI 1 "const_int_operand" "i")
3407                          (match_operand:SI 2 "const_int_operand" "i"))
3408         (match_operand:SI 3 "gpc_reg_operand" "r"))]
3409   ""
3410   "*
3411 {
3412   int start = INTVAL (operands[2]) & 31;
3413   int size = INTVAL (operands[1]) & 31;
3414
3415   operands[4] = GEN_INT (32 - start - size);
3416   operands[1] = GEN_INT (start + size - 1);
3417   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3418 }"
3419   [(set_attr "type" "insert_word")])
3420
3421 (define_insn "*insvsi_internal1"
3422   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3423                          (match_operand:SI 1 "const_int_operand" "i")
3424                          (match_operand:SI 2 "const_int_operand" "i"))
3425         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3426                    (match_operand:SI 4 "const_int_operand" "i")))]
3427   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3428   "*
3429 {
3430   int shift = INTVAL (operands[4]) & 31;
3431   int start = INTVAL (operands[2]) & 31;
3432   int size = INTVAL (operands[1]) & 31;
3433
3434   operands[4] = GEN_INT (shift - start - size);
3435   operands[1] = GEN_INT (start + size - 1);
3436   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3437 }"
3438   [(set_attr "type" "insert_word")])
3439
3440 (define_insn "*insvsi_internal2"
3441   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3442                          (match_operand:SI 1 "const_int_operand" "i")
3443                          (match_operand:SI 2 "const_int_operand" "i"))
3444         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3445                      (match_operand:SI 4 "const_int_operand" "i")))]
3446   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3447   "*
3448 {
3449   int shift = INTVAL (operands[4]) & 31;
3450   int start = INTVAL (operands[2]) & 31;
3451   int size = INTVAL (operands[1]) & 31;
3452
3453   operands[4] = GEN_INT (32 - shift - start - size);
3454   operands[1] = GEN_INT (start + size - 1);
3455   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3456 }"
3457   [(set_attr "type" "insert_word")])
3458
3459 (define_insn "*insvsi_internal3"
3460   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3461                          (match_operand:SI 1 "const_int_operand" "i")
3462                          (match_operand:SI 2 "const_int_operand" "i"))
3463         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3464                      (match_operand:SI 4 "const_int_operand" "i")))]
3465   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3466   "*
3467 {
3468   int shift = INTVAL (operands[4]) & 31;
3469   int start = INTVAL (operands[2]) & 31;
3470   int size = INTVAL (operands[1]) & 31;
3471
3472   operands[4] = GEN_INT (32 - shift - start - size);
3473   operands[1] = GEN_INT (start + size - 1);
3474   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3475 }"
3476   [(set_attr "type" "insert_word")])
3477
3478 (define_insn "*insvsi_internal4"
3479   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3480                          (match_operand:SI 1 "const_int_operand" "i")
3481                          (match_operand:SI 2 "const_int_operand" "i"))
3482         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3483                          (match_operand:SI 4 "const_int_operand" "i")
3484                          (match_operand:SI 5 "const_int_operand" "i")))]
3485   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3486   "*
3487 {
3488   int extract_start = INTVAL (operands[5]) & 31;
3489   int extract_size = INTVAL (operands[4]) & 31;
3490   int insert_start = INTVAL (operands[2]) & 31;
3491   int insert_size = INTVAL (operands[1]) & 31;
3492
3493 /* Align extract field with insert field */
3494   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3495   operands[1] = GEN_INT (insert_start + insert_size - 1);
3496   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
3497 }"
3498   [(set_attr "type" "insert_word")])
3499
3500 ;; combine patterns for rlwimi
3501 (define_insn "*insvsi_internal5"
3502   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3503         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3504                         (match_operand:SI 1 "mask_operand" "i"))
3505                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3506                                      (match_operand:SI 2 "const_int_operand" "i"))
3507                         (match_operand:SI 5 "mask_operand" "i"))))]
3508   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3509   "*
3510 {
3511  int me = extract_ME(operands[5]);
3512  int mb = extract_MB(operands[5]);
3513  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3514  operands[2] = GEN_INT(mb);
3515  operands[1] = GEN_INT(me);
3516  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3517 }"
3518   [(set_attr "type" "insert_word")])
3519
3520 (define_insn "*insvsi_internal6"
3521   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3522         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3523                                      (match_operand:SI 2 "const_int_operand" "i"))
3524                         (match_operand:SI 5 "mask_operand" "i"))
3525                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3526                         (match_operand:SI 1 "mask_operand" "i"))))]
3527   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3528   "*
3529 {
3530  int me = extract_ME(operands[5]);
3531  int mb = extract_MB(operands[5]);
3532  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3533  operands[2] = GEN_INT(mb);
3534  operands[1] = GEN_INT(me);
3535  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3536 }"
3537   [(set_attr "type" "insert_word")])
3538
3539 (define_insn "insvdi"
3540   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3541                          (match_operand:SI 1 "const_int_operand" "i")
3542                          (match_operand:SI 2 "const_int_operand" "i"))
3543         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3544   "TARGET_POWERPC64"
3545   "*
3546 {
3547   int start = INTVAL (operands[2]) & 63;
3548   int size = INTVAL (operands[1]) & 63;
3549
3550   operands[1] = GEN_INT (64 - start - size);
3551   return \"rldimi %0,%3,%H1,%H2\";
3552 }")
3553
3554 (define_insn "*insvdi_internal2"
3555   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3556                          (match_operand:SI 1 "const_int_operand" "i")
3557                          (match_operand:SI 2 "const_int_operand" "i"))
3558         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3559                      (match_operand:SI 4 "const_int_operand" "i")))]
3560   "TARGET_POWERPC64
3561    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3562   "*
3563 {
3564   int shift = INTVAL (operands[4]) & 63;
3565   int start = (INTVAL (operands[2]) & 63) - 32;
3566   int size = INTVAL (operands[1]) & 63;
3567
3568   operands[4] = GEN_INT (64 - shift - start - size);
3569   operands[2] = GEN_INT (start);
3570   operands[1] = GEN_INT (start + size - 1);
3571   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3572 }")
3573
3574 (define_insn "*insvdi_internal3"
3575   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3576                          (match_operand:SI 1 "const_int_operand" "i")
3577                          (match_operand:SI 2 "const_int_operand" "i"))
3578         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3579                      (match_operand:SI 4 "const_int_operand" "i")))]
3580   "TARGET_POWERPC64
3581    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3582   "*
3583 {
3584   int shift = INTVAL (operands[4]) & 63;
3585   int start = (INTVAL (operands[2]) & 63) - 32;
3586   int size = INTVAL (operands[1]) & 63;
3587
3588   operands[4] = GEN_INT (64 - shift - start - size);
3589   operands[2] = GEN_INT (start);
3590   operands[1] = GEN_INT (start + size - 1);
3591   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3592 }")
3593
3594 (define_expand "extzv"
3595   [(set (match_operand 0 "gpc_reg_operand" "")
3596         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3597                        (match_operand:SI 2 "const_int_operand" "")
3598                        (match_operand:SI 3 "const_int_operand" "")))]
3599   ""
3600   "
3601 {
3602   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3603      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3604      compiler if the address of the structure is taken later.  */
3605   if (GET_CODE (operands[0]) == SUBREG
3606       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3607     FAIL;
3608
3609   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3610     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
3611   else
3612     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
3613   DONE;
3614 }")
3615
3616 (define_insn "extzvsi"
3617   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3618         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3619                          (match_operand:SI 2 "const_int_operand" "i")
3620                          (match_operand:SI 3 "const_int_operand" "i")))]
3621   ""
3622   "*
3623 {
3624   int start = INTVAL (operands[3]) & 31;
3625   int size = INTVAL (operands[2]) & 31;
3626
3627   if (start + size >= 32)
3628     operands[3] = const0_rtx;
3629   else
3630     operands[3] = GEN_INT (start + size);
3631   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
3632 }")
3633
3634 (define_insn "*extzvsi_internal1"
3635   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3636         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3637                          (match_operand:SI 2 "const_int_operand" "i,i")
3638                          (match_operand:SI 3 "const_int_operand" "i,i"))
3639                     (const_int 0)))
3640    (clobber (match_scratch:SI 4 "=r,r"))]
3641   ""
3642   "*
3643 {
3644   int start = INTVAL (operands[3]) & 31;
3645   int size = INTVAL (operands[2]) & 31;
3646
3647   /* Force split for non-cc0 compare.  */
3648   if (which_alternative == 1)
3649      return \"#\";
3650
3651   /* If the bit-field being tested fits in the upper or lower half of a
3652      word, it is possible to use andiu. or andil. to test it.  This is
3653      useful because the condition register set-use delay is smaller for
3654      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3655      position is 0 because the LT and GT bits may be set wrong.  */
3656
3657   if ((start > 0 && start + size <= 16) || start >= 16)
3658     {
3659       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3660                               - (1 << (16 - (start & 15) - size))));
3661       if (start < 16)
3662         return \"{andiu.|andis.} %4,%1,%3\";
3663       else
3664         return \"{andil.|andi.} %4,%1,%3\";
3665     }
3666
3667   if (start + size >= 32)
3668     operands[3] = const0_rtx;
3669   else
3670     operands[3] = GEN_INT (start + size);
3671   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
3672 }"
3673   [(set_attr "type" "compare")
3674    (set_attr "length" "4,8")])
3675
3676 (define_split
3677   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3678         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3679                          (match_operand:SI 2 "const_int_operand" "")
3680                          (match_operand:SI 3 "const_int_operand" ""))
3681                     (const_int 0)))
3682    (clobber (match_scratch:SI 4 ""))]
3683   "reload_completed"
3684   [(set (match_dup 4)
3685         (zero_extract:SI (match_dup 1) (match_dup 2)
3686                          (match_dup 3)))
3687    (set (match_dup 0)
3688         (compare:CC (match_dup 4)
3689                     (const_int 0)))]
3690   "")
3691
3692 (define_insn "*extzvsi_internal2"
3693   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3694         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3695                          (match_operand:SI 2 "const_int_operand" "i,i")
3696                          (match_operand:SI 3 "const_int_operand" "i,i"))
3697                     (const_int 0)))
3698    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3699         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3700   ""
3701   "*
3702 {
3703   int start = INTVAL (operands[3]) & 31;
3704   int size = INTVAL (operands[2]) & 31;
3705
3706   /* Force split for non-cc0 compare.  */
3707   if (which_alternative == 1)
3708      return \"#\";
3709
3710   /* Since we are using the output value, we can't ignore any need for
3711      a shift.  The bit-field must end at the LSB.  */
3712   if (start >= 16 && start + size == 32)
3713     {
3714       operands[3] = GEN_INT ((1 << size) - 1);
3715       return \"{andil.|andi.} %0,%1,%3\";
3716     }
3717
3718   if (start + size >= 32)
3719     operands[3] = const0_rtx;
3720   else
3721     operands[3] = GEN_INT (start + size);
3722   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
3723 }"
3724   [(set_attr "type" "compare")
3725    (set_attr "length" "4,8")])
3726
3727 (define_split
3728   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3729         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3730                          (match_operand:SI 2 "const_int_operand" "")
3731                          (match_operand:SI 3 "const_int_operand" ""))
3732                     (const_int 0)))
3733    (set (match_operand:SI 0 "gpc_reg_operand" "")
3734         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3735   "reload_completed"
3736   [(set (match_dup 0)
3737         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3738    (set (match_dup 4)
3739         (compare:CC (match_dup 0)
3740                     (const_int 0)))]
3741   "")
3742
3743 (define_insn "extzvdi"
3744   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3745         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3746                          (match_operand:SI 2 "const_int_operand" "i")
3747                          (match_operand:SI 3 "const_int_operand" "i")))]
3748   "TARGET_POWERPC64"
3749   "*
3750 {
3751   int start = INTVAL (operands[3]) & 63;
3752   int size = INTVAL (operands[2]) & 63;
3753
3754   if (start + size >= 64)
3755     operands[3] = const0_rtx;
3756   else
3757     operands[3] = GEN_INT (start + size);
3758   operands[2] = GEN_INT (64 - size);
3759   return \"rldicl %0,%1,%3,%2\";
3760 }")
3761
3762 (define_insn "*extzvdi_internal1"
3763   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3764         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3765                          (match_operand:SI 2 "const_int_operand" "i")
3766                          (match_operand:SI 3 "const_int_operand" "i"))
3767                     (const_int 0)))
3768    (clobber (match_scratch:DI 4 "=r"))]
3769   "TARGET_64BIT"
3770   "*
3771 {
3772   int start = INTVAL (operands[3]) & 63;
3773   int size = INTVAL (operands[2]) & 63;
3774
3775   if (start + size >= 64)
3776     operands[3] = const0_rtx;
3777   else
3778     operands[3] = GEN_INT (start + size);
3779   operands[2] = GEN_INT (64 - size);
3780   return \"rldicl. %4,%1,%3,%2\";
3781 }"
3782   [(set_attr "type" "compare")])
3783
3784 (define_insn "*extzvdi_internal2"
3785   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3786         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3787                          (match_operand:SI 2 "const_int_operand" "i")
3788                          (match_operand:SI 3 "const_int_operand" "i"))
3789                     (const_int 0)))
3790    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3791         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3792   "TARGET_64BIT"
3793   "*
3794 {
3795   int start = INTVAL (operands[3]) & 63;
3796   int size = INTVAL (operands[2]) & 63;
3797
3798   if (start + size >= 64)
3799     operands[3] = const0_rtx;
3800   else
3801     operands[3] = GEN_INT (start + size);
3802   operands[2] = GEN_INT (64 - size);
3803   return \"rldicl. %0,%1,%3,%2\";
3804 }"
3805   [(set_attr "type" "compare")])
3806
3807 (define_insn "rotlsi3"
3808   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3809         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3810                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3811   ""
3812   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
3813
3814 (define_insn "*rotlsi3_internal2"
3815   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3816         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3817                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3818                     (const_int 0)))
3819    (clobber (match_scratch:SI 3 "=r,r"))]
3820   ""
3821   "@
3822    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff
3823    #"
3824   [(set_attr "type" "delayed_compare")
3825    (set_attr "length" "4,8")])
3826
3827 (define_split
3828   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3829         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3830                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3831                     (const_int 0)))
3832    (clobber (match_scratch:SI 3 ""))]
3833   "reload_completed"
3834   [(set (match_dup 3)
3835         (rotate:SI (match_dup 1) (match_dup 2)))
3836    (set (match_dup 0)
3837         (compare:CC (match_dup 3)
3838                     (const_int 0)))]
3839   "")
3840
3841 (define_insn "*rotlsi3_internal3"
3842   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3843         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3844                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3845                     (const_int 0)))
3846    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3847         (rotate:SI (match_dup 1) (match_dup 2)))]
3848   ""
3849   "@
3850    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff
3851    #"
3852   [(set_attr "type" "delayed_compare")
3853    (set_attr "length" "4,8")])
3854
3855 (define_split
3856   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3857         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3858                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3859                     (const_int 0)))
3860    (set (match_operand:SI 0 "gpc_reg_operand" "")
3861         (rotate:SI (match_dup 1) (match_dup 2)))]
3862   "reload_completed"
3863   [(set (match_dup 0)
3864         (rotate:SI (match_dup 1) (match_dup 2)))
3865    (set (match_dup 3)
3866         (compare:CC (match_dup 0)
3867                     (const_int 0)))]
3868   "")
3869
3870 (define_insn "*rotlsi3_internal4"
3871   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3872         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3873                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
3874                 (match_operand:SI 3 "mask_operand" "n")))]
3875   ""
3876   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
3877
3878 (define_insn "*rotlsi3_internal5"
3879   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3880         (compare:CC (and:SI
3881                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3882                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3883                      (match_operand:SI 3 "mask_operand" "n,n"))
3884                     (const_int 0)))
3885    (clobber (match_scratch:SI 4 "=r,r"))]
3886   ""
3887   "@
3888    {rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3
3889    #"
3890   [(set_attr "type" "delayed_compare")
3891    (set_attr "length" "4,8")])
3892
3893 (define_split
3894   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3895         (compare:CC (and:SI
3896                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3897                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3898                      (match_operand:SI 3 "mask_operand" ""))
3899                     (const_int 0)))
3900    (clobber (match_scratch:SI 4 ""))]
3901   "reload_completed"
3902   [(set (match_dup 4)
3903         (and:SI (rotate:SI (match_dup 1)
3904                                 (match_dup 2))
3905                      (match_dup 3)))
3906    (set (match_dup 0)
3907         (compare:CC (match_dup 4)
3908                     (const_int 0)))]
3909   "")
3910
3911 (define_insn "*rotlsi3_internal6"
3912   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3913         (compare:CC (and:SI
3914                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3915                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3916                      (match_operand:SI 3 "mask_operand" "n,n"))
3917                     (const_int 0)))
3918    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3919         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3920   ""
3921   "@
3922    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3
3923    #"
3924   [(set_attr "type" "delayed_compare")
3925    (set_attr "length" "4,8")])
3926
3927 (define_split
3928   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3929         (compare:CC (and:SI
3930                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3931                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3932                      (match_operand:SI 3 "mask_operand" ""))
3933                     (const_int 0)))
3934    (set (match_operand:SI 0 "gpc_reg_operand" "")
3935         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3936   "reload_completed"
3937   [(set (match_dup 0)
3938         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3939    (set (match_dup 4)
3940         (compare:CC (match_dup 0)
3941                     (const_int 0)))]
3942   "")
3943
3944 (define_insn "*rotlsi3_internal7"
3945   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3946         (zero_extend:SI
3947          (subreg:QI
3948           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3949                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3950   ""
3951   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
3952
3953 (define_insn "*rotlsi3_internal8"
3954   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3955         (compare:CC (zero_extend:SI
3956                      (subreg:QI
3957                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3958                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3959                     (const_int 0)))
3960    (clobber (match_scratch:SI 3 "=r,r"))]
3961   ""
3962   "@
3963    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff
3964    #"
3965   [(set_attr "type" "delayed_compare")
3966    (set_attr "length" "4,8")])
3967
3968 (define_split
3969   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3970         (compare:CC (zero_extend:SI
3971                      (subreg:QI
3972                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3973                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3974                     (const_int 0)))
3975    (clobber (match_scratch:SI 3 ""))]
3976   "reload_completed"
3977   [(set (match_dup 3)
3978         (zero_extend:SI (subreg:QI
3979                       (rotate:SI (match_dup 1)
3980                                  (match_dup 2)) 0)))
3981    (set (match_dup 0)
3982         (compare:CC (match_dup 3)
3983                     (const_int 0)))]
3984   "")
3985
3986 (define_insn "*rotlsi3_internal9"
3987   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3988         (compare:CC (zero_extend:SI
3989                      (subreg:QI
3990                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3991                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3992                     (const_int 0)))
3993    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3994         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3995   ""
3996   "@
3997    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff
3998    #"
3999   [(set_attr "type" "delayed_compare")
4000    (set_attr "length" "4,8")])
4001
4002 (define_split
4003   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4004         (compare:CC (zero_extend:SI
4005                      (subreg:QI
4006                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4007                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4008                     (const_int 0)))
4009    (set (match_operand:SI 0 "gpc_reg_operand" "")
4010         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4011   "reload_completed"
4012   [(set (match_dup 0)
4013         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4014    (set (match_dup 3)
4015         (compare:CC (match_dup 0)
4016                     (const_int 0)))]
4017   "")
4018
4019 (define_insn "*rotlsi3_internal10"
4020   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4021         (zero_extend:SI
4022          (subreg:HI
4023           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4024                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
4025   ""
4026   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
4027
4028 (define_insn "*rotlsi3_internal11"
4029   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4030         (compare:CC (zero_extend:SI
4031                      (subreg:HI
4032                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4033                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
4034                     (const_int 0)))
4035    (clobber (match_scratch:SI 3 "=r,r"))]
4036   ""
4037   "@
4038    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff
4039    #"
4040   [(set_attr "type" "delayed_compare")
4041    (set_attr "length" "4,8")])
4042
4043 (define_split
4044   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4045         (compare:CC (zero_extend:SI
4046                      (subreg:HI
4047                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4048                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4049                     (const_int 0)))
4050    (clobber (match_scratch:SI 3 ""))]
4051   "reload_completed"
4052   [(set (match_dup 3)
4053         (zero_extend:SI (subreg:HI
4054                       (rotate:SI (match_dup 1)
4055                                  (match_dup 2)) 0)))
4056    (set (match_dup 0)
4057         (compare:CC (match_dup 3)
4058                     (const_int 0)))]
4059   "")
4060
4061 (define_insn "*rotlsi3_internal12"
4062   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4063         (compare:CC (zero_extend:SI
4064                      (subreg:HI
4065                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4066                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
4067                     (const_int 0)))
4068    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4069         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4070   ""
4071   "@
4072    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff
4073    #"
4074   [(set_attr "type" "delayed_compare")
4075    (set_attr "length" "4,8")])
4076
4077 (define_split
4078   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4079         (compare:CC (zero_extend:SI
4080                      (subreg:HI
4081                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4082                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4083                     (const_int 0)))
4084    (set (match_operand:SI 0 "gpc_reg_operand" "")
4085         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4086   "reload_completed"
4087   [(set (match_dup 0)
4088         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4089    (set (match_dup 3)
4090         (compare:CC (match_dup 0)
4091                     (const_int 0)))]
4092   "")
4093
4094 ;; Note that we use "sle." instead of "sl." so that we can set
4095 ;; SHIFT_COUNT_TRUNCATED.
4096
4097 (define_expand "ashlsi3"
4098   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4099    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4100    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4101   ""
4102   "
4103 {
4104   if (TARGET_POWER)
4105     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
4106   else
4107     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
4108   DONE;
4109 }")
4110
4111 (define_insn "ashlsi3_power"
4112   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4113         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4114                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4115    (clobber (match_scratch:SI 3 "=q,X"))]
4116   "TARGET_POWER"
4117   "@
4118    sle %0,%1,%2
4119    {sli|slwi} %0,%1,%h2")
4120
4121 (define_insn "ashlsi3_no_power"
4122   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4123         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4124                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4125   "! TARGET_POWER"
4126   "{sl|slw}%I2 %0,%1,%h2")
4127
4128 (define_insn ""
4129   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4130         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4131                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4132                     (const_int 0)))
4133    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4134    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4135   "TARGET_POWER"
4136   "@
4137    sle. %3,%1,%2
4138    {sli.|slwi.} %3,%1,%h2
4139    #
4140    #"
4141   [(set_attr "type" "delayed_compare")
4142    (set_attr "length" "4,4,8,8")])
4143
4144 (define_split
4145   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4146         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4147                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4148                     (const_int 0)))
4149    (clobber (match_scratch:SI 3 ""))
4150    (clobber (match_scratch:SI 4 ""))]
4151   "TARGET_POWER && reload_completed"
4152   [(parallel [(set (match_dup 3)
4153         (ashift:SI (match_dup 1) (match_dup 2)))
4154    (clobber (match_dup 4))])
4155    (set (match_dup 0)
4156         (compare:CC (match_dup 3)
4157                     (const_int 0)))]
4158   "")
4159
4160 (define_insn ""
4161   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4162         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4163                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4164                     (const_int 0)))
4165    (clobber (match_scratch:SI 3 "=r,r"))]
4166   "! TARGET_POWER && TARGET_32BIT"
4167   "@
4168    {sl|slw}%I2. %3,%1,%h2
4169    #"
4170   [(set_attr "type" "delayed_compare")
4171    (set_attr "length" "4,8")])
4172
4173 (define_split
4174   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4175         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4176                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4177                     (const_int 0)))
4178    (clobber (match_scratch:SI 3 ""))]
4179   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4180   [(set (match_dup 3)
4181         (ashift:SI (match_dup 1) (match_dup 2)))
4182    (set (match_dup 0)
4183         (compare:CC (match_dup 3)
4184                     (const_int 0)))]
4185   "")
4186
4187 (define_insn ""
4188   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4189         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4190                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4191                     (const_int 0)))
4192    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4193         (ashift:SI (match_dup 1) (match_dup 2)))
4194    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4195   "TARGET_POWER"
4196   "@
4197    sle. %0,%1,%2
4198    {sli.|slwi.} %0,%1,%h2
4199    #
4200    #"
4201   [(set_attr "type" "delayed_compare")
4202    (set_attr "length" "4,4,8,8")])
4203
4204 (define_split
4205   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4206         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4207                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4208                     (const_int 0)))
4209    (set (match_operand:SI 0 "gpc_reg_operand" "")
4210         (ashift:SI (match_dup 1) (match_dup 2)))
4211    (clobber (match_scratch:SI 4 ""))]
4212   "TARGET_POWER && reload_completed"
4213   [(parallel [(set (match_dup 0)
4214         (ashift:SI (match_dup 1) (match_dup 2)))
4215    (clobber (match_dup 4))])
4216    (set (match_dup 3)
4217         (compare:CC (match_dup 0)
4218                     (const_int 0)))]
4219   "")
4220
4221 (define_insn ""
4222   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4223         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4224                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4225                     (const_int 0)))
4226    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4227         (ashift:SI (match_dup 1) (match_dup 2)))]
4228   "! TARGET_POWER && TARGET_32BIT"
4229   "@
4230    {sl|slw}%I2. %0,%1,%h2
4231    #"
4232   [(set_attr "type" "delayed_compare")
4233    (set_attr "length" "4,8")])
4234
4235 (define_split
4236   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4237         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4238                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4239                     (const_int 0)))
4240    (set (match_operand:SI 0 "gpc_reg_operand" "")
4241         (ashift:SI (match_dup 1) (match_dup 2)))]
4242   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4243   [(set (match_dup 0)
4244         (ashift:SI (match_dup 1) (match_dup 2)))
4245    (set (match_dup 3)
4246         (compare:CC (match_dup 0)
4247                     (const_int 0)))]
4248   "")
4249
4250 (define_insn "rlwinm"
4251   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4252         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4253                            (match_operand:SI 2 "const_int_operand" "i"))
4254                 (match_operand:SI 3 "mask_operand" "n")))]
4255   "includes_lshift_p (operands[2], operands[3])"
4256   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
4257
4258 (define_insn ""
4259   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4260         (compare:CC
4261          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4262                             (match_operand:SI 2 "const_int_operand" "i,i"))
4263                  (match_operand:SI 3 "mask_operand" "n,n"))
4264          (const_int 0)))
4265    (clobber (match_scratch:SI 4 "=r,r"))]
4266   "includes_lshift_p (operands[2], operands[3])"
4267   "@
4268    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
4269    #"
4270   [(set_attr "type" "delayed_compare")
4271    (set_attr "length" "4,8")])
4272
4273 (define_split
4274   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4275         (compare:CC
4276          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4277                             (match_operand:SI 2 "const_int_operand" ""))
4278                  (match_operand:SI 3 "mask_operand" ""))
4279          (const_int 0)))
4280    (clobber (match_scratch:SI 4 ""))]
4281   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4282   [(set (match_dup 4)
4283         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
4284                  (match_dup 3)))
4285    (set (match_dup 0)
4286         (compare:CC (match_dup 4)
4287                     (const_int 0)))]
4288   "")
4289
4290 (define_insn ""
4291   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4292         (compare:CC
4293          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4294                             (match_operand:SI 2 "const_int_operand" "i,i"))
4295                  (match_operand:SI 3 "mask_operand" "n,n"))
4296          (const_int 0)))
4297    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4298         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4299   "includes_lshift_p (operands[2], operands[3])"
4300   "@
4301    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
4302    #"
4303   [(set_attr "type" "delayed_compare")
4304    (set_attr "length" "4,8")])
4305
4306 (define_split
4307   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4308         (compare:CC
4309          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4310                             (match_operand:SI 2 "const_int_operand" ""))
4311                  (match_operand:SI 3 "mask_operand" ""))
4312          (const_int 0)))
4313    (set (match_operand:SI 0 "gpc_reg_operand" "")
4314         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4315   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4316   [(set (match_dup 0)
4317         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4318    (set (match_dup 4)
4319         (compare:CC (match_dup 0)
4320                     (const_int 0)))]
4321   "")
4322
4323 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
4324 ;; "sli x,x,0".
4325 (define_expand "lshrsi3"
4326   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4327    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4328    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4329   ""
4330   "
4331 {
4332   if (TARGET_POWER)
4333     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
4334   else
4335     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
4336   DONE;
4337 }")
4338
4339 (define_insn "lshrsi3_power"
4340   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4341         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4342                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
4343    (clobber (match_scratch:SI 3 "=q,X,X"))]
4344   "TARGET_POWER"
4345   "@
4346   sre %0,%1,%2
4347   mr %0,%1
4348   {s%A2i|s%A2wi} %0,%1,%h2")
4349
4350 (define_insn "lshrsi3_no_power"
4351   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4352         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4353                      (match_operand:SI 2 "reg_or_cint_operand" "O,ri")))]
4354   "! TARGET_POWER"
4355   "@
4356   mr %0,%1
4357   {sr|srw}%I2 %0,%1,%h2")
4358
4359 (define_insn ""
4360   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4361         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4362                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
4363                     (const_int 0)))
4364    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
4365    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
4366   "TARGET_POWER"
4367   "@
4368   sre. %3,%1,%2
4369   mr. %1,%1
4370   {s%A2i.|s%A2wi.} %3,%1,%h2
4371   #
4372   #
4373   #"
4374   [(set_attr "type" "delayed_compare")
4375    (set_attr "length" "4,4,4,8,8,8")])
4376
4377 (define_split
4378   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4379         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4380                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4381                     (const_int 0)))
4382    (clobber (match_scratch:SI 3 ""))
4383    (clobber (match_scratch:SI 4 ""))]
4384   "TARGET_POWER && reload_completed"
4385   [(parallel [(set (match_dup 3)
4386         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4387    (clobber (match_dup 4))])
4388    (set (match_dup 0)
4389         (compare:CC (match_dup 3)
4390                     (const_int 0)))]
4391   "")
4392
4393 (define_insn ""
4394   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4395         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4396                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
4397                     (const_int 0)))
4398    (clobber (match_scratch:SI 3 "=X,r,X,r"))]
4399   "! TARGET_POWER && TARGET_32BIT"
4400   "@
4401    mr. %1,%1
4402    {sr|srw}%I2. %3,%1,%h2
4403    #
4404    #"
4405   [(set_attr "type" "delayed_compare")
4406    (set_attr "length" "4,4,8,8")])
4407
4408 (define_split
4409   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4410         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4411                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4412                     (const_int 0)))
4413    (clobber (match_scratch:SI 3 ""))]
4414   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4415   [(set (match_dup 3)
4416         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4417    (set (match_dup 0)
4418         (compare:CC (match_dup 3)
4419                     (const_int 0)))]
4420   "")
4421
4422 (define_insn ""
4423   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4424         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4425                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
4426                     (const_int 0)))
4427    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
4428         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4429    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
4430   "TARGET_POWER"
4431   "@
4432   sre. %0,%1,%2
4433   mr. %0,%1
4434   {s%A2i.|s%A2wi.} %0,%1,%h2
4435   #
4436   #
4437   #"
4438   [(set_attr "type" "delayed_compare")
4439    (set_attr "length" "4,4,4,8,8,8")])
4440
4441 (define_split
4442   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4443         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4444                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4445                     (const_int 0)))
4446    (set (match_operand:SI 0 "gpc_reg_operand" "")
4447         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4448    (clobber (match_scratch:SI 4 ""))]
4449   "TARGET_POWER && reload_completed"
4450   [(parallel [(set (match_dup 0)
4451         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4452    (clobber (match_dup 4))])
4453    (set (match_dup 3)
4454         (compare:CC (match_dup 0)
4455                     (const_int 0)))]
4456   "")
4457
4458 (define_insn ""
4459   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4460         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4461                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
4462                     (const_int 0)))
4463    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4464         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4465   "! TARGET_POWER && TARGET_32BIT"
4466   "@
4467    mr. %0,%1
4468    {sr|srw}%I2. %0,%1,%h2
4469    #
4470    #"
4471   [(set_attr "type" "delayed_compare")
4472    (set_attr "length" "4,4,8,8")])
4473
4474 (define_split
4475   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4476         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4477                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4478                     (const_int 0)))
4479    (set (match_operand:SI 0 "gpc_reg_operand" "")
4480         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4481   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4482   [(set (match_dup 0)
4483         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4484    (set (match_dup 3)
4485         (compare:CC (match_dup 0)
4486                     (const_int 0)))]
4487   "")
4488
4489 (define_insn ""
4490   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4491         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4492                              (match_operand:SI 2 "const_int_operand" "i"))
4493                 (match_operand:SI 3 "mask_operand" "n")))]
4494   "includes_rshift_p (operands[2], operands[3])"
4495   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
4496
4497 (define_insn ""
4498   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4499         (compare:CC
4500          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4501                               (match_operand:SI 2 "const_int_operand" "i,i"))
4502                  (match_operand:SI 3 "mask_operand" "n,n"))
4503          (const_int 0)))
4504    (clobber (match_scratch:SI 4 "=r,r"))]
4505   "includes_rshift_p (operands[2], operands[3])"
4506   "@
4507    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
4508    #"
4509   [(set_attr "type" "delayed_compare")
4510    (set_attr "length" "4,8")])
4511
4512 (define_split
4513   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4514         (compare:CC
4515          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4516                               (match_operand:SI 2 "const_int_operand" ""))
4517                  (match_operand:SI 3 "mask_operand" ""))
4518          (const_int 0)))
4519    (clobber (match_scratch:SI 4 ""))]
4520   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4521   [(set (match_dup 4)
4522         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4523                  (match_dup 3)))
4524    (set (match_dup 0)
4525         (compare:CC (match_dup 4)
4526                     (const_int 0)))]
4527   "")
4528
4529 (define_insn ""
4530   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4531         (compare:CC
4532          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4533                               (match_operand:SI 2 "const_int_operand" "i,i"))
4534                  (match_operand:SI 3 "mask_operand" "n,n"))
4535          (const_int 0)))
4536    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4537         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4538   "includes_rshift_p (operands[2], operands[3])"
4539   "@
4540    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
4541    #"
4542   [(set_attr "type" "delayed_compare")
4543    (set_attr "length" "4,8")])
4544
4545 (define_split
4546   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4547         (compare:CC
4548          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4549                               (match_operand:SI 2 "const_int_operand" ""))
4550                  (match_operand:SI 3 "mask_operand" ""))
4551          (const_int 0)))
4552    (set (match_operand:SI 0 "gpc_reg_operand" "")
4553         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4554   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4555   [(set (match_dup 0)
4556         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4557    (set (match_dup 4)
4558         (compare:CC (match_dup 0)
4559                     (const_int 0)))]
4560   "")
4561
4562 (define_insn ""
4563   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4564         (zero_extend:SI
4565          (subreg:QI
4566           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4567                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4568   "includes_rshift_p (operands[2], GEN_INT (255))"
4569   "{rlinm|rlwinm} %0,%1,%s2,0xff")
4570
4571 (define_insn ""
4572   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4573         (compare:CC
4574          (zero_extend:SI
4575           (subreg:QI
4576            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4577                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4578          (const_int 0)))
4579    (clobber (match_scratch:SI 3 "=r,r"))]
4580   "includes_rshift_p (operands[2], GEN_INT (255))"
4581   "@
4582    {rlinm.|rlwinm.} %3,%1,%s2,0xff
4583    #"
4584   [(set_attr "type" "delayed_compare")
4585    (set_attr "length" "4,8")])
4586
4587 (define_split
4588   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4589         (compare:CC
4590          (zero_extend:SI
4591           (subreg:QI
4592            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4593                         (match_operand:SI 2 "const_int_operand" "")) 0))
4594          (const_int 0)))
4595    (clobber (match_scratch:SI 3 ""))]
4596   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4597   [(set (match_dup 3)
4598         (zero_extend:SI (subreg:QI
4599            (lshiftrt:SI (match_dup 1)
4600                         (match_dup 2)) 0)))
4601    (set (match_dup 0)
4602         (compare:CC (match_dup 3)
4603                     (const_int 0)))]
4604   "")
4605
4606 (define_insn ""
4607   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4608         (compare:CC
4609          (zero_extend:SI
4610           (subreg:QI
4611            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4612                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4613          (const_int 0)))
4614    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4615         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4616   "includes_rshift_p (operands[2], GEN_INT (255))"
4617   "@
4618    {rlinm.|rlwinm.} %0,%1,%s2,0xff
4619    #"
4620   [(set_attr "type" "delayed_compare")
4621    (set_attr "length" "4,8")])
4622
4623 (define_split
4624   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4625         (compare:CC
4626          (zero_extend:SI
4627           (subreg:QI
4628            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4629                         (match_operand:SI 2 "const_int_operand" "")) 0))
4630          (const_int 0)))
4631    (set (match_operand:SI 0 "gpc_reg_operand" "")
4632         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4633   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4634   [(set (match_dup 0)
4635         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4636    (set (match_dup 3)
4637         (compare:CC (match_dup 0)
4638                     (const_int 0)))]
4639   "")
4640
4641 (define_insn ""
4642   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4643         (zero_extend:SI
4644          (subreg:HI
4645           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4646                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4647   "includes_rshift_p (operands[2], GEN_INT (65535))"
4648   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
4649
4650 (define_insn ""
4651   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4652         (compare:CC
4653          (zero_extend:SI
4654           (subreg:HI
4655            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4656                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4657          (const_int 0)))
4658    (clobber (match_scratch:SI 3 "=r,r"))]
4659   "includes_rshift_p (operands[2], GEN_INT (65535))"
4660   "@
4661    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
4662    #"
4663   [(set_attr "type" "delayed_compare")
4664    (set_attr "length" "4,8")])
4665
4666 (define_split
4667   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4668         (compare:CC
4669          (zero_extend:SI
4670           (subreg:HI
4671            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4672                         (match_operand:SI 2 "const_int_operand" "")) 0))
4673          (const_int 0)))
4674    (clobber (match_scratch:SI 3 ""))]
4675   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4676   [(set (match_dup 3)
4677         (zero_extend:SI (subreg:HI
4678            (lshiftrt:SI (match_dup 1)
4679                         (match_dup 2)) 0)))
4680    (set (match_dup 0)
4681         (compare:CC (match_dup 3)
4682                     (const_int 0)))]
4683   "")
4684
4685 (define_insn ""
4686   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4687         (compare:CC
4688          (zero_extend:SI
4689           (subreg:HI
4690            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4691                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4692          (const_int 0)))
4693    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4694         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4695   "includes_rshift_p (operands[2], GEN_INT (65535))"
4696   "@
4697    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
4698    #"
4699   [(set_attr "type" "delayed_compare")
4700    (set_attr "length" "4,8")])
4701
4702 (define_split
4703   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4704         (compare:CC
4705          (zero_extend:SI
4706           (subreg:HI
4707            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4708                         (match_operand:SI 2 "const_int_operand" "")) 0))
4709          (const_int 0)))
4710    (set (match_operand:SI 0 "gpc_reg_operand" "")
4711         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4712   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4713   [(set (match_dup 0)
4714         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4715    (set (match_dup 3)
4716         (compare:CC (match_dup 0)
4717                     (const_int 0)))]
4718   "")
4719
4720 (define_insn ""
4721   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4722                          (const_int 1)
4723                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4724         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4725                      (const_int 31)))]
4726   "TARGET_POWER"
4727   "rrib %0,%1,%2")
4728
4729 (define_insn ""
4730   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4731                          (const_int 1)
4732                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4733         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4734                      (const_int 31)))]
4735   "TARGET_POWER"
4736   "rrib %0,%1,%2")
4737
4738 (define_insn ""
4739   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4740                          (const_int 1)
4741                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4742         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4743                          (const_int 1)
4744                          (const_int 0)))]
4745   "TARGET_POWER"
4746   "rrib %0,%1,%2")
4747
4748 (define_expand "ashrsi3"
4749   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4750         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4751                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4752   ""
4753   "
4754 {
4755   if (TARGET_POWER)
4756     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
4757   else
4758     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
4759   DONE;
4760 }")
4761
4762 (define_insn "ashrsi3_power"
4763   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4764         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4765                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4766    (clobber (match_scratch:SI 3 "=q,X"))]
4767   "TARGET_POWER"
4768   "@
4769    srea %0,%1,%2
4770    {srai|srawi} %0,%1,%h2")
4771
4772 (define_insn "ashrsi3_no_power"
4773   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4774         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4775                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4776   "! TARGET_POWER"
4777   "{sra|sraw}%I2 %0,%1,%h2")
4778
4779 (define_insn ""
4780   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4781         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4782                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4783                     (const_int 0)))
4784    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4785    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4786   "TARGET_POWER"
4787   "@
4788    srea. %3,%1,%2
4789    {srai.|srawi.} %3,%1,%h2
4790    #
4791    #"
4792   [(set_attr "type" "delayed_compare")
4793    (set_attr "length" "4,4,8,8")])
4794
4795 (define_split
4796   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4797         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4798                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4799                     (const_int 0)))
4800    (clobber (match_scratch:SI 3 ""))
4801    (clobber (match_scratch:SI 4 ""))]
4802   "TARGET_POWER && reload_completed"
4803   [(parallel [(set (match_dup 3)
4804         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4805    (clobber (match_dup 4))])
4806    (set (match_dup 0)
4807         (compare:CC (match_dup 3)
4808                     (const_int 0)))]
4809   "")
4810
4811 (define_insn ""
4812   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4813         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4814                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4815                     (const_int 0)))
4816    (clobber (match_scratch:SI 3 "=r,r"))]
4817   "! TARGET_POWER"
4818   "@
4819    {sra|sraw}%I2. %3,%1,%h2
4820    #"
4821   [(set_attr "type" "delayed_compare")
4822    (set_attr "length" "4,8")])
4823
4824 (define_split
4825   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4826         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4827                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4828                     (const_int 0)))
4829    (clobber (match_scratch:SI 3 ""))]
4830   "! TARGET_POWER && reload_completed"
4831   [(set (match_dup 3)
4832         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4833    (set (match_dup 0)
4834         (compare:CC (match_dup 3)
4835                     (const_int 0)))]
4836   "")
4837
4838 (define_insn ""
4839   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4840         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4841                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4842                     (const_int 0)))
4843    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4844         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4845    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4846   "TARGET_POWER"
4847   "@
4848    srea. %0,%1,%2
4849    {srai.|srawi.} %0,%1,%h2
4850    #
4851    #"
4852   [(set_attr "type" "delayed_compare")
4853    (set_attr "length" "4,4,8,8")])
4854
4855 (define_split
4856   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4857         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4858                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4859                     (const_int 0)))
4860    (set (match_operand:SI 0 "gpc_reg_operand" "")
4861         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4862    (clobber (match_scratch:SI 4 ""))]
4863   "TARGET_POWER && reload_completed"
4864   [(parallel [(set (match_dup 0)
4865         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4866    (clobber (match_dup 4))])
4867    (set (match_dup 3)
4868         (compare:CC (match_dup 0)
4869                     (const_int 0)))]
4870   "")
4871
4872 (define_insn ""
4873   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4874         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4875                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4876                     (const_int 0)))
4877    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4878         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4879   "! TARGET_POWER"
4880   "@
4881    {sra|sraw}%I2. %0,%1,%h2
4882    #"
4883   [(set_attr "type" "delayed_compare")
4884    (set_attr "length" "4,8")])
4885 \f
4886 (define_split
4887   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4888         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4889                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4890                     (const_int 0)))
4891    (set (match_operand:SI 0 "gpc_reg_operand" "")
4892         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4893   "! TARGET_POWER && reload_completed"
4894   [(set (match_dup 0)
4895         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4896    (set (match_dup 3)
4897         (compare:CC (match_dup 0)
4898                     (const_int 0)))]
4899   "")
4900
4901 ;; Floating-point insns, excluding normal data motion.
4902 ;;
4903 ;; PowerPC has a full set of single-precision floating point instructions.
4904 ;;
4905 ;; For the POWER architecture, we pretend that we have both SFmode and
4906 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
4907 ;; The only conversions we will do will be when storing to memory.  In that
4908 ;; case, we will use the "frsp" instruction before storing.
4909 ;;
4910 ;; Note that when we store into a single-precision memory location, we need to
4911 ;; use the frsp insn first.  If the register being stored isn't dead, we
4912 ;; need a scratch register for the frsp.  But this is difficult when the store
4913 ;; is done by reload.  It is not incorrect to do the frsp on the register in
4914 ;; this case, we just lose precision that we would have otherwise gotten but
4915 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
4916
4917 (define_expand "extendsfdf2"
4918   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4919         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
4920   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4921   "")
4922
4923 (define_insn_and_split "*extendsfdf2_fpr"
4924   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f,f")
4925         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m")))]
4926   "TARGET_HARD_FLOAT && TARGET_FPRS"
4927   "@
4928    #
4929    fmr %0,%1
4930    lfs%U1%X1 %0,%1"
4931   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
4932   [(const_int 0)]
4933 {
4934   emit_note (NOTE_INSN_DELETED);
4935   DONE;
4936 }
4937   [(set_attr "type" "fp,fp,fpload")])
4938
4939 (define_expand "truncdfsf2"
4940   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4941         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
4942   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4943   "")
4944
4945 (define_insn "*truncdfsf2_fpr"
4946   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4947         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4948   "TARGET_HARD_FLOAT && TARGET_FPRS"
4949   "frsp %0,%1"
4950   [(set_attr "type" "fp")])
4951
4952 (define_insn "aux_truncdfsf2"
4953   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4954         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
4955   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4956   "frsp %0,%1"
4957   [(set_attr "type" "fp")])
4958
4959 (define_expand "negsf2"
4960   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4961         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4962   "TARGET_HARD_FLOAT"
4963   "")
4964
4965 (define_insn "*negsf2"
4966   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4967         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4968   "TARGET_HARD_FLOAT && TARGET_FPRS"
4969   "fneg %0,%1"
4970   [(set_attr "type" "fp")])
4971
4972 (define_expand "abssf2"
4973   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4974         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4975   "TARGET_HARD_FLOAT"
4976   "")
4977
4978 (define_insn "*abssf2"
4979   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4980         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4981   "TARGET_HARD_FLOAT && TARGET_FPRS"
4982   "fabs %0,%1"
4983   [(set_attr "type" "fp")])
4984
4985 (define_insn ""
4986   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4987         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
4988   "TARGET_HARD_FLOAT && TARGET_FPRS"
4989   "fnabs %0,%1"
4990   [(set_attr "type" "fp")])
4991
4992 (define_expand "addsf3"
4993   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4994         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4995                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4996   "TARGET_HARD_FLOAT"
4997   "")
4998
4999 (define_insn ""
5000   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5001         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5002                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5003   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5004   "fadds %0,%1,%2"
5005   [(set_attr "type" "fp")])
5006
5007 (define_insn ""
5008   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5009         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5010                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5011   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5012   "{fa|fadd} %0,%1,%2"
5013   [(set_attr "type" "fp")])
5014
5015 (define_expand "subsf3"
5016   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5017         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5018                   (match_operand:SF 2 "gpc_reg_operand" "")))]
5019   "TARGET_HARD_FLOAT"
5020   "")
5021
5022 (define_insn ""
5023   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5024         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5025                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5026   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5027   "fsubs %0,%1,%2"
5028   [(set_attr "type" "fp")])
5029
5030 (define_insn ""
5031   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5032         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5033                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5034   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5035   "{fs|fsub} %0,%1,%2"
5036   [(set_attr "type" "fp")])
5037
5038 (define_expand "mulsf3"
5039   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5040         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
5041                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5042   "TARGET_HARD_FLOAT"
5043   "")
5044
5045 (define_insn ""
5046   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5047         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5048                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5049   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5050   "fmuls %0,%1,%2"
5051   [(set_attr "type" "fp")])
5052
5053 (define_insn ""
5054   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5055         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5056                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5057   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5058   "{fm|fmul} %0,%1,%2"
5059   [(set_attr "type" "dmul")])
5060
5061 (define_insn "fres"
5062   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5063         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5064   "TARGET_PPC_GFXOPT && flag_finite_math_only"
5065   "fres %0,%1"
5066   [(set_attr "type" "fp")])
5067
5068 (define_expand "divsf3"
5069   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5070         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
5071                 (match_operand:SF 2 "gpc_reg_operand" "")))]
5072   "TARGET_HARD_FLOAT"
5073 {
5074   if (swdiv && !optimize_size && TARGET_PPC_GFXOPT
5075   && flag_finite_math_only && !flag_trapping_math)
5076     {
5077       rs6000_emit_swdivsf (operands[0], operands[1], operands[2]);
5078       DONE;
5079     }
5080 })
5081
5082 (define_insn ""
5083   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5084         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5085                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5086   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5087   "fdivs %0,%1,%2"
5088   [(set_attr "type" "sdiv")])
5089
5090 (define_insn ""
5091   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5092         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5093                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5094   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5095   "{fd|fdiv} %0,%1,%2"
5096   [(set_attr "type" "ddiv")])
5097
5098 (define_insn ""
5099   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5100         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5101                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5102                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5103   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5104   "fmadds %0,%1,%2,%3"
5105   [(set_attr "type" "fp")])
5106
5107 (define_insn ""
5108   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5109         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5110                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5111                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5112   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5113   "{fma|fmadd} %0,%1,%2,%3"
5114   [(set_attr "type" "dmul")])
5115
5116 (define_insn ""
5117   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5118         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5119                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5120                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5121   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5122   "fmsubs %0,%1,%2,%3"
5123   [(set_attr "type" "fp")])
5124
5125 (define_insn ""
5126   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5127         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5128                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5129                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5130   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5131   "{fms|fmsub} %0,%1,%2,%3"
5132   [(set_attr "type" "dmul")])
5133
5134 (define_insn ""
5135   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5136         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5137                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5138                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5139   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5140    && HONOR_SIGNED_ZEROS (SFmode)"
5141   "fnmadds %0,%1,%2,%3"
5142   [(set_attr "type" "fp")])
5143
5144 (define_insn ""
5145   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5146         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5147                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5148                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5149   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5150    && ! HONOR_SIGNED_ZEROS (SFmode)"
5151   "fnmadds %0,%1,%2,%3"
5152   [(set_attr "type" "fp")])
5153
5154 (define_insn ""
5155   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5156         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5157                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5158                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5159   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5160   "{fnma|fnmadd} %0,%1,%2,%3"
5161   [(set_attr "type" "dmul")])
5162
5163 (define_insn ""
5164   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5165         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5166                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5167                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5168   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5169    && ! HONOR_SIGNED_ZEROS (SFmode)"
5170   "{fnma|fnmadd} %0,%1,%2,%3"
5171   [(set_attr "type" "dmul")])
5172
5173 (define_insn ""
5174   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5175         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5176                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5177                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5178   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5179    && HONOR_SIGNED_ZEROS (SFmode)"
5180   "fnmsubs %0,%1,%2,%3"
5181   [(set_attr "type" "fp")])
5182
5183 (define_insn ""
5184   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5185         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
5186                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5187                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
5188   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5189    && ! HONOR_SIGNED_ZEROS (SFmode)"
5190   "fnmsubs %0,%1,%2,%3"
5191   [(set_attr "type" "fp")])
5192
5193 (define_insn ""
5194   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5195         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5196                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5197                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5198   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5199   "{fnms|fnmsub} %0,%1,%2,%3"
5200   [(set_attr "type" "dmul")])
5201
5202 (define_insn ""
5203   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5204         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
5205                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5206                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
5207   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5208    && ! HONOR_SIGNED_ZEROS (SFmode)"
5209   "{fnms|fnmsub} %0,%1,%2,%3"
5210   [(set_attr "type" "dmul")])
5211
5212 (define_expand "sqrtsf2"
5213   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5214         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5215   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
5216   "")
5217
5218 (define_insn ""
5219   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5220         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5221   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5222   "fsqrts %0,%1"
5223   [(set_attr "type" "ssqrt")])
5224
5225 (define_insn ""
5226   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5227         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5228   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS"
5229   "fsqrt %0,%1"
5230   [(set_attr "type" "dsqrt")])
5231
5232 (define_expand "copysignsf3"
5233   [(set (match_dup 3)
5234         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))
5235    (set (match_dup 4)
5236         (neg:SF (abs:SF (match_dup 1))))
5237    (set (match_operand:SF 0 "gpc_reg_operand" "")
5238         (if_then_else:SF (ge (match_operand:SF 2 "gpc_reg_operand" "")
5239                              (match_dup 5))
5240                          (match_dup 3)
5241                          (match_dup 4)))]
5242   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS
5243    && !HONOR_NANS (SFmode) && !HONOR_SIGNED_ZEROS (SFmode)"
5244   {
5245      operands[3] = gen_reg_rtx (SFmode);
5246      operands[4] = gen_reg_rtx (SFmode);
5247      operands[5] = CONST0_RTX (SFmode);
5248   })
5249
5250 (define_expand "copysigndf3"
5251   [(set (match_dup 3)
5252         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))
5253    (set (match_dup 4)
5254         (neg:DF (abs:DF (match_dup 1))))
5255    (set (match_operand:DF 0 "gpc_reg_operand" "")
5256         (if_then_else:DF (ge (match_operand:DF 2 "gpc_reg_operand" "")
5257                              (match_dup 5))
5258                          (match_dup 3)
5259                          (match_dup 4)))]
5260   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS
5261    && !HONOR_NANS (DFmode) && !HONOR_SIGNED_ZEROS (DFmode)"
5262   {
5263      operands[3] = gen_reg_rtx (DFmode);
5264      operands[4] = gen_reg_rtx (DFmode);
5265      operands[5] = CONST0_RTX (DFmode);
5266   })
5267
5268 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
5269 ;; fsel instruction and some auxiliary computations.  Then we just have a
5270 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
5271 ;; combine.
5272 (define_expand "smaxsf3"
5273   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5274         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
5275                              (match_operand:SF 2 "gpc_reg_operand" ""))
5276                          (match_dup 1)
5277                          (match_dup 2)))]
5278   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5279   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5280
5281 (define_expand "sminsf3"
5282   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5283         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
5284                              (match_operand:SF 2 "gpc_reg_operand" ""))
5285                          (match_dup 2)
5286                          (match_dup 1)))]
5287   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5288   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5289
5290 (define_split
5291   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5292         (match_operator:SF 3 "min_max_operator"
5293          [(match_operand:SF 1 "gpc_reg_operand" "")
5294           (match_operand:SF 2 "gpc_reg_operand" "")]))]
5295   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5296   [(const_int 0)]
5297   "
5298 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5299                       operands[1], operands[2]);
5300   DONE;
5301 }")
5302
5303 (define_expand "movsicc"
5304    [(set (match_operand:SI 0 "gpc_reg_operand" "")
5305          (if_then_else:SI (match_operand 1 "comparison_operator" "")
5306                           (match_operand:SI 2 "gpc_reg_operand" "")
5307                           (match_operand:SI 3 "gpc_reg_operand" "")))]
5308   "TARGET_ISEL"
5309   "
5310 {
5311   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5312     DONE;
5313   else
5314     FAIL;
5315 }")
5316
5317 ;; We use the BASE_REGS for the isel input operands because, if rA is
5318 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
5319 ;; because we may switch the operands and rB may end up being rA.
5320 ;;
5321 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
5322 ;; leave out the mode in operand 4 and use one pattern, but reload can
5323 ;; change the mode underneath our feet and then gets confused trying
5324 ;; to reload the value.
5325 (define_insn "isel_signed"
5326   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5327         (if_then_else:SI
5328          (match_operator 1 "comparison_operator"
5329                          [(match_operand:CC 4 "cc_reg_operand" "y")
5330                           (const_int 0)])
5331          (match_operand:SI 2 "gpc_reg_operand" "b")
5332          (match_operand:SI 3 "gpc_reg_operand" "b")))]
5333   "TARGET_ISEL"
5334   "*
5335 { return output_isel (operands); }"
5336   [(set_attr "length" "4")])
5337
5338 (define_insn "isel_unsigned"
5339   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5340         (if_then_else:SI
5341          (match_operator 1 "comparison_operator"
5342                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
5343                           (const_int 0)])
5344          (match_operand:SI 2 "gpc_reg_operand" "b")
5345          (match_operand:SI 3 "gpc_reg_operand" "b")))]
5346   "TARGET_ISEL"
5347   "*
5348 { return output_isel (operands); }"
5349   [(set_attr "length" "4")])
5350
5351 (define_expand "movsfcc"
5352    [(set (match_operand:SF 0 "gpc_reg_operand" "")
5353          (if_then_else:SF (match_operand 1 "comparison_operator" "")
5354                           (match_operand:SF 2 "gpc_reg_operand" "")
5355                           (match_operand:SF 3 "gpc_reg_operand" "")))]
5356   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5357   "
5358 {
5359   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5360     DONE;
5361   else
5362     FAIL;
5363 }")
5364
5365 (define_insn "*fselsfsf4"
5366   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5367         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5368                              (match_operand:SF 4 "zero_fp_constant" "F"))
5369                          (match_operand:SF 2 "gpc_reg_operand" "f")
5370                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5371   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5372   "fsel %0,%1,%2,%3"
5373   [(set_attr "type" "fp")])
5374
5375 (define_insn "*fseldfsf4"
5376   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5377         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
5378                              (match_operand:DF 4 "zero_fp_constant" "F"))
5379                          (match_operand:SF 2 "gpc_reg_operand" "f")
5380                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5381   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5382   "fsel %0,%1,%2,%3"
5383   [(set_attr "type" "fp")])
5384
5385 (define_expand "negdf2"
5386   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5387         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
5388   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5389   "")
5390
5391 (define_insn "*negdf2_fpr"
5392   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5393         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5394   "TARGET_HARD_FLOAT && TARGET_FPRS"
5395   "fneg %0,%1"
5396   [(set_attr "type" "fp")])
5397
5398 (define_expand "absdf2"
5399   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5400         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
5401   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5402   "")
5403
5404 (define_insn "*absdf2_fpr"
5405   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5406         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5407   "TARGET_HARD_FLOAT && TARGET_FPRS"
5408   "fabs %0,%1"
5409   [(set_attr "type" "fp")])
5410
5411 (define_insn "*nabsdf2_fpr"
5412   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5413         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
5414   "TARGET_HARD_FLOAT && TARGET_FPRS"
5415   "fnabs %0,%1"
5416   [(set_attr "type" "fp")])
5417
5418 (define_expand "adddf3"
5419   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5420         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "")
5421                  (match_operand:DF 2 "gpc_reg_operand" "")))]
5422   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5423   "")
5424
5425 (define_insn "*adddf3_fpr"
5426   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5427         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5428                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
5429   "TARGET_HARD_FLOAT && TARGET_FPRS"
5430   "{fa|fadd} %0,%1,%2"
5431   [(set_attr "type" "fp")])
5432
5433 (define_expand "subdf3"
5434   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5435         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
5436                   (match_operand:DF 2 "gpc_reg_operand" "")))]
5437   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5438   "")
5439
5440 (define_insn "*subdf3_fpr"
5441   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5442         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5443                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
5444   "TARGET_HARD_FLOAT && TARGET_FPRS"
5445   "{fs|fsub} %0,%1,%2"
5446   [(set_attr "type" "fp")])
5447
5448 (define_expand "muldf3"
5449   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5450         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "")
5451                  (match_operand:DF 2 "gpc_reg_operand" "")))]
5452   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5453   "")
5454
5455 (define_insn "*muldf3_fpr"
5456   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5457         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5458                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
5459   "TARGET_HARD_FLOAT && TARGET_FPRS"
5460   "{fm|fmul} %0,%1,%2"
5461   [(set_attr "type" "dmul")])
5462
5463 (define_insn "fred"
5464   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5465         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5466   "TARGET_POPCNTB && flag_finite_math_only"
5467   "fre %0,%1"
5468   [(set_attr "type" "fp")])
5469
5470 (define_expand "divdf3"
5471   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5472         (div:DF (match_operand:DF 1 "gpc_reg_operand" "")
5473                 (match_operand:DF 2 "gpc_reg_operand" "")))]
5474   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5475 {
5476   if (swdiv && !optimize_size && TARGET_POPCNTB
5477   && flag_finite_math_only && !flag_trapping_math)
5478     {
5479       rs6000_emit_swdivdf (operands[0], operands[1], operands[2]);
5480       DONE;
5481     }
5482 })
5483
5484 (define_insn "*divdf3_fpr"
5485   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5486         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5487                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
5488   "TARGET_HARD_FLOAT && TARGET_FPRS"
5489   "{fd|fdiv} %0,%1,%2"
5490   [(set_attr "type" "ddiv")])
5491
5492 (define_insn ""
5493   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5494         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5495                           (match_operand:DF 2 "gpc_reg_operand" "f"))
5496                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
5497   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5498   "{fma|fmadd} %0,%1,%2,%3"
5499   [(set_attr "type" "dmul")])
5500
5501 (define_insn ""
5502   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5503         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5504                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5505                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5506   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5507   "{fms|fmsub} %0,%1,%2,%3"
5508   [(set_attr "type" "dmul")])
5509
5510 (define_insn ""
5511   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5512         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5513                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
5514                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5515   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5516    && HONOR_SIGNED_ZEROS (DFmode)"
5517   "{fnma|fnmadd} %0,%1,%2,%3"
5518   [(set_attr "type" "dmul")])
5519
5520 (define_insn ""
5521   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5522         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f"))
5523                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5524                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5525   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5526    && ! HONOR_SIGNED_ZEROS (DFmode)"
5527   "{fnma|fnmadd} %0,%1,%2,%3"
5528   [(set_attr "type" "dmul")])
5529
5530 (define_insn ""
5531   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5532         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5533                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
5534                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5535   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5536    && HONOR_SIGNED_ZEROS (DFmode)"
5537   "{fnms|fnmsub} %0,%1,%2,%3"
5538   [(set_attr "type" "dmul")])
5539
5540 (define_insn ""
5541   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5542         (minus:DF (match_operand:DF 3 "gpc_reg_operand" "f")
5543                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5544                            (match_operand:DF 2 "gpc_reg_operand" "f"))))]
5545   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5546    && ! HONOR_SIGNED_ZEROS (DFmode)"
5547   "{fnms|fnmsub} %0,%1,%2,%3"
5548   [(set_attr "type" "dmul")])
5549
5550 (define_insn "sqrtdf2"
5551   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5552         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5553   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
5554   "fsqrt %0,%1"
5555   [(set_attr "type" "dsqrt")])
5556
5557 ;; The conditional move instructions allow us to perform max and min
5558 ;; operations even when
5559
5560 (define_expand "smaxdf3"
5561   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5562         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5563                              (match_operand:DF 2 "gpc_reg_operand" ""))
5564                          (match_dup 1)
5565                          (match_dup 2)))]
5566   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5567   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5568
5569 (define_expand "smindf3"
5570   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5571         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5572                              (match_operand:DF 2 "gpc_reg_operand" ""))
5573                          (match_dup 2)
5574                          (match_dup 1)))]
5575   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5576   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5577
5578 (define_split
5579   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5580         (match_operator:DF 3 "min_max_operator"
5581          [(match_operand:DF 1 "gpc_reg_operand" "")
5582           (match_operand:DF 2 "gpc_reg_operand" "")]))]
5583   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5584   [(const_int 0)]
5585   "
5586 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5587                       operands[1], operands[2]);
5588   DONE;
5589 }")
5590
5591 (define_expand "movdfcc"
5592    [(set (match_operand:DF 0 "gpc_reg_operand" "")
5593          (if_then_else:DF (match_operand 1 "comparison_operator" "")
5594                           (match_operand:DF 2 "gpc_reg_operand" "")
5595                           (match_operand:DF 3 "gpc_reg_operand" "")))]
5596   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5597   "
5598 {
5599   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5600     DONE;
5601   else
5602     FAIL;
5603 }")
5604
5605 (define_insn "*fseldfdf4"
5606   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5607         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
5608                              (match_operand:DF 4 "zero_fp_constant" "F"))
5609                          (match_operand:DF 2 "gpc_reg_operand" "f")
5610                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5611   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5612   "fsel %0,%1,%2,%3"
5613   [(set_attr "type" "fp")])
5614
5615 (define_insn "*fselsfdf4"
5616   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5617         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5618                              (match_operand:SF 4 "zero_fp_constant" "F"))
5619                          (match_operand:DF 2 "gpc_reg_operand" "f")
5620                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5621   "TARGET_PPC_GFXOPT"
5622   "fsel %0,%1,%2,%3"
5623   [(set_attr "type" "fp")])
5624 \f
5625 ;; Conversions to and from floating-point.
5626
5627 (define_expand "fixuns_truncsfsi2"
5628   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5629         (unsigned_fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5630   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5631   "")
5632
5633 (define_expand "fix_truncsfsi2"
5634   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5635         (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5636   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5637   "")
5638
5639 ; For each of these conversions, there is a define_expand, a define_insn
5640 ; with a '#' template, and a define_split (with C code).  The idea is
5641 ; to allow constant folding with the template of the define_insn,
5642 ; then to have the insns split later (between sched1 and final).
5643
5644 (define_expand "floatsidf2"
5645   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5646                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5647               (use (match_dup 2))
5648               (use (match_dup 3))
5649               (clobber (match_dup 4))
5650               (clobber (match_dup 5))
5651               (clobber (match_dup 6))])]
5652   "TARGET_HARD_FLOAT && TARGET_FPRS"
5653   "
5654 {
5655   if (TARGET_E500_DOUBLE)
5656     {
5657       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
5658       DONE;
5659     }
5660   if (TARGET_POWERPC64)
5661     {
5662       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5663       rtx t1 = gen_reg_rtx (DImode);
5664       rtx t2 = gen_reg_rtx (DImode);
5665       emit_insn (gen_floatsidf_ppc64 (operands[0], operands[1], mem, t1, t2));
5666       DONE;
5667     }
5668
5669   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5670   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5671   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5672   operands[5] = gen_reg_rtx (DFmode);
5673   operands[6] = gen_reg_rtx (SImode);
5674 }")
5675
5676 (define_insn_and_split "*floatsidf2_internal"
5677   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5678         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5679    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5680    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5681    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5682    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))
5683    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5684   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5685   "#"
5686   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[4]))"
5687   [(pc)]
5688   "
5689 {
5690   rtx lowword, highword;
5691   gcc_assert (MEM_P (operands[4]));
5692   highword = adjust_address (operands[4], SImode, 0);
5693   lowword = adjust_address (operands[4], SImode, 4);
5694   if (! WORDS_BIG_ENDIAN)
5695     {
5696       rtx tmp;
5697       tmp = highword; highword = lowword; lowword = tmp;
5698     }
5699
5700   emit_insn (gen_xorsi3 (operands[6], operands[1],
5701                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5702   emit_move_insn (lowword, operands[6]);
5703   emit_move_insn (highword, operands[2]);
5704   emit_move_insn (operands[5], operands[4]);
5705   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5706   DONE;
5707 }"
5708   [(set_attr "length" "24")])
5709
5710 (define_expand "floatunssisf2"
5711   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5712         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5713   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5714   "")
5715
5716 (define_expand "floatunssidf2"
5717   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5718                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5719               (use (match_dup 2))
5720               (use (match_dup 3))
5721               (clobber (match_dup 4))
5722               (clobber (match_dup 5))])]
5723   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5724   "
5725 {
5726   if (TARGET_E500_DOUBLE)
5727     {
5728       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
5729       DONE;
5730     }
5731   if (TARGET_POWERPC64)
5732     {
5733       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5734       rtx t1 = gen_reg_rtx (DImode);
5735       rtx t2 = gen_reg_rtx (DImode);
5736       emit_insn (gen_floatunssidf_ppc64 (operands[0], operands[1], mem,
5737                                          t1, t2));
5738       DONE;
5739     }
5740
5741   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5742   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5743   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5744   operands[5] = gen_reg_rtx (DFmode);
5745 }")
5746
5747 (define_insn_and_split "*floatunssidf2_internal"
5748   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5749         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5750    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5751    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5752    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5753    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))]
5754   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5755   "#"
5756   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[4]))"
5757   [(pc)]
5758   "
5759 {
5760   rtx lowword, highword;
5761   gcc_assert (MEM_P (operands[4]));
5762   highword = adjust_address (operands[4], SImode, 0);
5763   lowword = adjust_address (operands[4], SImode, 4);
5764   if (! WORDS_BIG_ENDIAN)
5765     {
5766       rtx tmp;
5767       tmp = highword; highword = lowword; lowword = tmp;
5768     }
5769
5770   emit_move_insn (lowword, operands[1]);
5771   emit_move_insn (highword, operands[2]);
5772   emit_move_insn (operands[5], operands[4]);
5773   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5774   DONE;
5775 }"
5776   [(set_attr "length" "20")])
5777
5778 (define_expand "fix_truncdfsi2"
5779   [(parallel [(set (match_operand:SI 0 "fix_trunc_dest_operand" "")
5780                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5781               (clobber (match_dup 2))
5782               (clobber (match_dup 3))])]
5783   "(TARGET_POWER2 || TARGET_POWERPC)
5784    && TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5785   "
5786 {
5787   if (TARGET_E500_DOUBLE)
5788     {
5789      emit_insn (gen_spe_fix_truncdfsi2 (operands[0], operands[1]));
5790      DONE;
5791     }
5792   operands[2] = gen_reg_rtx (DImode);
5793   if (TARGET_PPC_GFXOPT)
5794     {
5795       rtx orig_dest = operands[0];
5796       if (! memory_operand (orig_dest, GET_MODE (orig_dest)))
5797         operands[0] = assign_stack_temp (SImode, GET_MODE_SIZE (SImode), 0);
5798       emit_insn (gen_fix_truncdfsi2_internal_gfxopt (operands[0], operands[1],
5799                                                      operands[2]));
5800       if (operands[0] != orig_dest)
5801         emit_move_insn (orig_dest, operands[0]);
5802       DONE;
5803     }
5804   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5805 }")
5806
5807 (define_insn_and_split "*fix_truncdfsi2_internal"
5808   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5809         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5810    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
5811    (clobber (match_operand:DI 3 "memory_operand" "=o"))]
5812   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5813   "#"
5814   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[3]))"
5815   [(pc)]
5816   "
5817 {
5818   rtx lowword;
5819   gcc_assert (MEM_P (operands[3]));
5820   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
5821
5822   emit_insn (gen_fctiwz (operands[2], operands[1]));
5823   emit_move_insn (operands[3], operands[2]);
5824   emit_move_insn (operands[0], lowword);
5825   DONE;
5826 }"
5827   [(set_attr "length" "16")])
5828
5829 (define_insn_and_split "fix_truncdfsi2_internal_gfxopt"
5830   [(set (match_operand:SI 0 "memory_operand" "=Z")
5831         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5832    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))]
5833   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS
5834    && TARGET_PPC_GFXOPT"
5835   "#"
5836   "&& 1"
5837   [(pc)]
5838   "
5839 {
5840   emit_insn (gen_fctiwz (operands[2], operands[1]));
5841   emit_insn (gen_stfiwx (operands[0], operands[2]));
5842   DONE;
5843 }"
5844   [(set_attr "length" "16")])
5845
5846 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
5847 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
5848 ; because the first makes it clear that operand 0 is not live
5849 ; before the instruction.
5850 (define_insn "fctiwz"
5851   [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
5852         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))]
5853                    UNSPEC_FCTIWZ))]
5854   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5855   "{fcirz|fctiwz} %0,%1"
5856   [(set_attr "type" "fp")])
5857
5858 (define_insn "btruncdf2"
5859   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5860         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIZ))]
5861   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5862   "friz %0,%1"
5863   [(set_attr "type" "fp")])
5864
5865 (define_insn "btruncsf2"
5866   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5867         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIZ))]
5868   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5869   "friz %0,%1"
5870   [(set_attr "type" "fp")])
5871
5872 (define_insn "ceildf2"
5873   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5874         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIP))]
5875   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5876   "frip %0,%1"
5877   [(set_attr "type" "fp")])
5878
5879 (define_insn "ceilsf2"
5880  [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5881         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIP))]
5882   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5883   "frip %0,%1"
5884   [(set_attr "type" "fp")])
5885
5886 (define_insn "floordf2"
5887   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5888         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIM))]
5889   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5890   "frim %0,%1"
5891   [(set_attr "type" "fp")])
5892
5893 (define_insn "floorsf2"
5894   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5895         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIM))]
5896   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5897   "frim %0,%1"
5898   [(set_attr "type" "fp")])
5899
5900 (define_insn "rounddf2"
5901   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5902         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIN))]
5903   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5904   "frin %0,%1"
5905   [(set_attr "type" "fp")])
5906
5907 (define_insn "roundsf2"
5908   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5909         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIN))]
5910   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5911   "frin %0,%1"
5912   [(set_attr "type" "fp")])
5913
5914 ; An UNSPEC is used so we don't have to support SImode in FP registers.
5915 (define_insn "stfiwx"
5916   [(set (match_operand:SI 0 "memory_operand" "=Z")
5917         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "f")]
5918                    UNSPEC_STFIWX))]
5919   "TARGET_PPC_GFXOPT"
5920   "stfiwx %1,%y0"
5921   [(set_attr "type" "fpstore")])
5922
5923 (define_expand "floatsisf2"
5924   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5925         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5926   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5927   "")
5928
5929 (define_insn "floatdidf2"
5930   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5931         (float:DF (match_operand:DI 1 "gpc_reg_operand" "*f")))]
5932   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5933   "fcfid %0,%1"
5934   [(set_attr "type" "fp")])
5935
5936 (define_insn_and_split "floatsidf_ppc64"
5937   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5938         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5939    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5940    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5941    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5942   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5943   "#"
5944   "&& 1"
5945   [(set (match_dup 3) (sign_extend:DI (match_dup 1)))
5946    (set (match_dup 2) (match_dup 3))
5947    (set (match_dup 4) (match_dup 2))
5948    (set (match_dup 0) (float:DF (match_dup 4)))]
5949   "")
5950
5951 (define_insn_and_split "floatunssidf_ppc64"
5952   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5953         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5954    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5955    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5956    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5957   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5958   "#"
5959   "&& 1"
5960   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
5961    (set (match_dup 2) (match_dup 3))
5962    (set (match_dup 4) (match_dup 2))
5963    (set (match_dup 0) (float:DF (match_dup 4)))]
5964   "")
5965
5966 (define_insn "fix_truncdfdi2"
5967   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5968         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
5969   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5970   "fctidz %0,%1"
5971   [(set_attr "type" "fp")])
5972
5973 (define_expand "floatdisf2"
5974   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5975         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
5976   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5977   "
5978 {
5979   rtx val = operands[1];
5980   if (!flag_unsafe_math_optimizations)
5981     {
5982       rtx label = gen_label_rtx ();
5983       val = gen_reg_rtx (DImode);
5984       emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
5985       emit_label (label);
5986     }
5987   emit_insn (gen_floatdisf2_internal1 (operands[0], val));
5988   DONE;
5989 }")
5990
5991 ;; This is not IEEE compliant if rounding mode is "round to nearest".
5992 ;; If the DI->DF conversion is inexact, then it's possible to suffer
5993 ;; from double rounding.
5994 (define_insn_and_split "floatdisf2_internal1"
5995   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5996         (float:SF (match_operand:DI 1 "gpc_reg_operand" "*f")))
5997    (clobber (match_scratch:DF 2 "=f"))]
5998   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5999   "#"
6000   "&& reload_completed"
6001   [(set (match_dup 2)
6002         (float:DF (match_dup 1)))
6003    (set (match_dup 0)
6004         (float_truncate:SF (match_dup 2)))]
6005   "")
6006
6007 ;; Twiddles bits to avoid double rounding.
6008 ;; Bits that might be truncated when converting to DFmode are replaced
6009 ;; by a bit that won't be lost at that stage, but is below the SFmode
6010 ;; rounding position.
6011 (define_expand "floatdisf2_internal2"
6012   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
6013                                    (const_int 53)))
6014    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
6015                                                       (const_int 2047)))
6016               (clobber (scratch:CC))])
6017    (set (match_dup 3) (plus:DI (match_dup 3)
6018                                (const_int 1)))
6019    (set (match_dup 0) (plus:DI (match_dup 0)
6020                                (const_int 2047)))
6021    (set (match_dup 4) (compare:CCUNS (match_dup 3)
6022                                      (const_int 2)))
6023    (set (match_dup 0) (ior:DI (match_dup 0)
6024                               (match_dup 1)))
6025    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
6026                                          (const_int -2048)))
6027               (clobber (scratch:CC))])
6028    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
6029                            (label_ref (match_operand:DI 2 "" ""))
6030                            (pc)))
6031    (set (match_dup 0) (match_dup 1))]
6032   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
6033   "
6034 {
6035   operands[3] = gen_reg_rtx (DImode);
6036   operands[4] = gen_reg_rtx (CCUNSmode);
6037 }")
6038 \f
6039 ;; Define the DImode operations that can be done in a small number
6040 ;; of instructions.  The & constraints are to prevent the register
6041 ;; allocator from allocating registers that overlap with the inputs
6042 ;; (for example, having an input in 7,8 and an output in 6,7).  We
6043 ;; also allow for the output being the same as one of the inputs.
6044
6045 (define_insn "*adddi3_noppc64"
6046   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
6047         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
6048                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
6049   "! TARGET_POWERPC64"
6050   "*
6051 {
6052   if (WORDS_BIG_ENDIAN)
6053     return (GET_CODE (operands[2])) != CONST_INT
6054             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
6055             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
6056   else
6057     return (GET_CODE (operands[2])) != CONST_INT
6058             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
6059             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
6060 }"
6061   [(set_attr "type" "two")
6062    (set_attr "length" "8")])
6063
6064 (define_insn "*subdi3_noppc64"
6065   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
6066         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
6067                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
6068   "! TARGET_POWERPC64"
6069   "*
6070 {
6071   if (WORDS_BIG_ENDIAN)
6072     return (GET_CODE (operands[1]) != CONST_INT)
6073             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
6074             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
6075   else
6076     return (GET_CODE (operands[1]) != CONST_INT)
6077             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
6078             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
6079 }"
6080   [(set_attr "type" "two")
6081    (set_attr "length" "8")])
6082
6083 (define_insn "*negdi2_noppc64"
6084   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6085         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
6086   "! TARGET_POWERPC64"
6087   "*
6088 {
6089   return (WORDS_BIG_ENDIAN)
6090     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
6091     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
6092 }"
6093   [(set_attr "type" "two")
6094    (set_attr "length" "8")])
6095
6096 (define_expand "mulsidi3"
6097   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6098         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6099                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6100   "! TARGET_POWERPC64"
6101   "
6102 {
6103   if (! TARGET_POWER && ! TARGET_POWERPC)
6104     {
6105       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
6106       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
6107       emit_insn (gen_mull_call ());
6108       if (WORDS_BIG_ENDIAN)
6109         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
6110       else
6111         {
6112           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
6113                           gen_rtx_REG (SImode, 3));
6114           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
6115                           gen_rtx_REG (SImode, 4));
6116         }
6117       DONE;
6118     }
6119   else if (TARGET_POWER)
6120     {
6121       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
6122       DONE;
6123     }
6124 }")
6125
6126 (define_insn "mulsidi3_mq"
6127   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6128         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6129                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
6130    (clobber (match_scratch:SI 3 "=q"))]
6131   "TARGET_POWER"
6132   "mul %0,%1,%2\;mfmq %L0"
6133   [(set_attr "type" "imul")
6134    (set_attr "length" "8")])
6135
6136 (define_insn "*mulsidi3_no_mq"
6137   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6138         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6139                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6140   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
6141   "*
6142 {
6143   return (WORDS_BIG_ENDIAN)
6144     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
6145     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
6146 }"
6147   [(set_attr "type" "imul")
6148    (set_attr "length" "8")])
6149
6150 (define_split
6151   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6152         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6153                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6154   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
6155   [(set (match_dup 3)
6156         (truncate:SI
6157          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
6158                                (sign_extend:DI (match_dup 2)))
6159                       (const_int 32))))
6160    (set (match_dup 4)
6161         (mult:SI (match_dup 1)
6162                  (match_dup 2)))]
6163   "
6164 {
6165   int endian = (WORDS_BIG_ENDIAN == 0);
6166   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6167   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6168 }")
6169
6170 (define_expand "umulsidi3"
6171   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6172         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6173                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6174   "TARGET_POWERPC && ! TARGET_POWERPC64"
6175   "
6176 {
6177   if (TARGET_POWER)
6178     {
6179       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
6180       DONE;
6181     }
6182 }")
6183
6184 (define_insn "umulsidi3_mq"
6185   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6186         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6187                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
6188    (clobber (match_scratch:SI 3 "=q"))]
6189   "TARGET_POWERPC && TARGET_POWER"
6190   "*
6191 {
6192   return (WORDS_BIG_ENDIAN)
6193     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6194     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6195 }"
6196   [(set_attr "type" "imul")
6197    (set_attr "length" "8")])
6198
6199 (define_insn "*umulsidi3_no_mq"
6200   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6201         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6202                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6203   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
6204   "*
6205 {
6206   return (WORDS_BIG_ENDIAN)
6207     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6208     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6209 }"
6210   [(set_attr "type" "imul")
6211    (set_attr "length" "8")])
6212
6213 (define_split
6214   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6215         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6216                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6217   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
6218   [(set (match_dup 3)
6219         (truncate:SI
6220          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
6221                                (zero_extend:DI (match_dup 2)))
6222                       (const_int 32))))
6223    (set (match_dup 4)
6224         (mult:SI (match_dup 1)
6225                  (match_dup 2)))]
6226   "
6227 {
6228   int endian = (WORDS_BIG_ENDIAN == 0);
6229   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6230   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6231 }")
6232
6233 (define_expand "smulsi3_highpart"
6234   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6235         (truncate:SI
6236          (lshiftrt:DI (mult:DI (sign_extend:DI
6237                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6238                                (sign_extend:DI
6239                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6240                       (const_int 32))))]
6241   ""
6242   "
6243 {
6244   if (! TARGET_POWER && ! TARGET_POWERPC)
6245     {
6246       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
6247       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
6248       emit_insn (gen_mulh_call ());
6249       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
6250       DONE;
6251     }
6252   else if (TARGET_POWER)
6253     {
6254       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
6255       DONE;
6256     }
6257 }")
6258
6259 (define_insn "smulsi3_highpart_mq"
6260   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6261         (truncate:SI
6262          (lshiftrt:DI (mult:DI (sign_extend:DI
6263                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6264                                (sign_extend:DI
6265                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6266                       (const_int 32))))
6267    (clobber (match_scratch:SI 3 "=q"))]
6268   "TARGET_POWER"
6269   "mul %0,%1,%2"
6270   [(set_attr "type" "imul")])
6271
6272 (define_insn "*smulsi3_highpart_no_mq"
6273   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6274         (truncate:SI
6275          (lshiftrt:DI (mult:DI (sign_extend:DI
6276                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6277                                (sign_extend:DI
6278                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6279                       (const_int 32))))]
6280   "TARGET_POWERPC && ! TARGET_POWER"
6281   "mulhw %0,%1,%2"
6282   [(set_attr "type" "imul")])
6283
6284 (define_expand "umulsi3_highpart"
6285   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6286         (truncate:SI
6287          (lshiftrt:DI (mult:DI (zero_extend:DI
6288                                 (match_operand:SI 1 "gpc_reg_operand" ""))
6289                                (zero_extend:DI
6290                                 (match_operand:SI 2 "gpc_reg_operand" "")))
6291                       (const_int 32))))]
6292   "TARGET_POWERPC"
6293   "
6294 {
6295   if (TARGET_POWER)
6296     {
6297       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
6298       DONE;
6299     }
6300 }")
6301
6302 (define_insn "umulsi3_highpart_mq"
6303   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6304         (truncate:SI
6305          (lshiftrt:DI (mult:DI (zero_extend:DI
6306                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6307                                (zero_extend:DI
6308                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6309                       (const_int 32))))
6310    (clobber (match_scratch:SI 3 "=q"))]
6311   "TARGET_POWERPC && TARGET_POWER"
6312   "mulhwu %0,%1,%2"
6313   [(set_attr "type" "imul")])
6314
6315 (define_insn "*umulsi3_highpart_no_mq"
6316   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6317         (truncate:SI
6318          (lshiftrt:DI (mult:DI (zero_extend:DI
6319                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6320                                (zero_extend:DI
6321                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6322                       (const_int 32))))]
6323   "TARGET_POWERPC && ! TARGET_POWER"
6324   "mulhwu %0,%1,%2"
6325   [(set_attr "type" "imul")])
6326
6327 ;; If operands 0 and 2 are in the same register, we have a problem.  But
6328 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
6329 ;; why we have the strange constraints below.
6330 (define_insn "ashldi3_power"
6331   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
6332         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
6333                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
6334    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
6335   "TARGET_POWER"
6336   "@
6337    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
6338    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
6339    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
6340    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
6341   [(set_attr "length" "8")])
6342
6343 (define_insn "lshrdi3_power"
6344   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
6345         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
6346                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
6347    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
6348   "TARGET_POWER"
6349   "@
6350    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
6351    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
6352    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
6353    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
6354   [(set_attr "length" "8")])
6355
6356 ;; Shift by a variable amount is too complex to be worth open-coding.  We
6357 ;; just handle shifts by constants.
6358 (define_insn "ashrdi3_power"
6359   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6360         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6361                      (match_operand:SI 2 "const_int_operand" "M,i")))
6362    (clobber (match_scratch:SI 3 "=X,q"))]
6363   "TARGET_POWER"
6364   "@
6365    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
6366    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
6367   [(set_attr "length" "8")])
6368
6369 (define_insn "ashrdi3_no_power"
6370   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
6371         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6372                      (match_operand:SI 2 "const_int_operand" "M,i")))]
6373   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER && WORDS_BIG_ENDIAN"
6374   "@
6375    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
6376    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
6377   [(set_attr "type" "two,three")
6378    (set_attr "length" "8,12")])
6379
6380 (define_insn "*ashrdisi3_noppc64"
6381   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6382         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6383                                 (const_int 32)) 4))]
6384   "TARGET_32BIT && !TARGET_POWERPC64"
6385   "*
6386 {
6387   if (REGNO (operands[0]) == REGNO (operands[1]))
6388     return \"\";
6389   else
6390     return \"mr %0,%1\";
6391 }"
6392    [(set_attr "length" "4")])
6393
6394 \f
6395 ;; PowerPC64 DImode operations.
6396
6397 (define_insn_and_split "absdi2"
6398   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6399         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
6400    (clobber (match_scratch:DI 2 "=&r,&r"))]
6401   "TARGET_POWERPC64"
6402   "#"
6403   "&& reload_completed"
6404   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
6405    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
6406    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
6407   "")
6408
6409 (define_insn_and_split "*nabsdi2"
6410   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6411         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
6412    (clobber (match_scratch:DI 2 "=&r,&r"))]
6413   "TARGET_POWERPC64"
6414   "#"
6415   "&& reload_completed"
6416   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
6417    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
6418    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
6419   "")
6420
6421 (define_insn "muldi3"
6422   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6423         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6424                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
6425   "TARGET_POWERPC64"
6426   "@
6427    mulld %0,%1,%2
6428    mulli %0,%1,%2"
6429    [(set (attr "type")
6430       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
6431                 (const_string "imul3")
6432              (match_operand:SI 2 "short_cint_operand" "")
6433                 (const_string "imul2")]
6434         (const_string "lmul")))])
6435
6436 (define_insn "*muldi3_internal1"
6437   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6438         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6439                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6440                     (const_int 0)))
6441    (clobber (match_scratch:DI 3 "=r,r"))]
6442   "TARGET_POWERPC64"
6443   "@
6444    mulld. %3,%1,%2
6445    #"
6446   [(set_attr "type" "lmul_compare")
6447    (set_attr "length" "4,8")])
6448
6449 (define_split
6450   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6451         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6452                              (match_operand:DI 2 "gpc_reg_operand" ""))
6453                     (const_int 0)))
6454    (clobber (match_scratch:DI 3 ""))]
6455   "TARGET_POWERPC64 && reload_completed"
6456   [(set (match_dup 3)
6457         (mult:DI (match_dup 1) (match_dup 2)))
6458    (set (match_dup 0)
6459         (compare:CC (match_dup 3)
6460                     (const_int 0)))]
6461   "")
6462
6463 (define_insn "*muldi3_internal2"
6464   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6465         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6466                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6467                     (const_int 0)))
6468    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6469         (mult:DI (match_dup 1) (match_dup 2)))]
6470   "TARGET_POWERPC64"
6471   "@
6472    mulld. %0,%1,%2
6473    #"
6474   [(set_attr "type" "lmul_compare")
6475    (set_attr "length" "4,8")])
6476
6477 (define_split
6478   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6479         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6480                              (match_operand:DI 2 "gpc_reg_operand" ""))
6481                     (const_int 0)))
6482    (set (match_operand:DI 0 "gpc_reg_operand" "")
6483         (mult:DI (match_dup 1) (match_dup 2)))]
6484   "TARGET_POWERPC64 && reload_completed"
6485   [(set (match_dup 0)
6486         (mult:DI (match_dup 1) (match_dup 2)))
6487    (set (match_dup 3)
6488         (compare:CC (match_dup 0)
6489                     (const_int 0)))]
6490   "")
6491
6492 (define_insn "smuldi3_highpart"
6493   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6494         (truncate:DI
6495          (lshiftrt:TI (mult:TI (sign_extend:TI
6496                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6497                                (sign_extend:TI
6498                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6499                       (const_int 64))))]
6500   "TARGET_POWERPC64"
6501   "mulhd %0,%1,%2"
6502   [(set_attr "type" "lmul")])
6503
6504 (define_insn "umuldi3_highpart"
6505   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6506         (truncate:DI
6507          (lshiftrt:TI (mult:TI (zero_extend:TI
6508                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6509                                (zero_extend:TI
6510                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6511                       (const_int 64))))]
6512   "TARGET_POWERPC64"
6513   "mulhdu %0,%1,%2"
6514   [(set_attr "type" "lmul")])
6515
6516 (define_insn "rotldi3"
6517   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6518         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6519                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
6520   "TARGET_POWERPC64"
6521   "rld%I2cl %0,%1,%H2,0")
6522
6523 (define_insn "*rotldi3_internal2"
6524   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6525         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6526                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6527                     (const_int 0)))
6528    (clobber (match_scratch:DI 3 "=r,r"))]
6529   "TARGET_64BIT"
6530   "@
6531    rld%I2cl. %3,%1,%H2,0
6532    #"
6533   [(set_attr "type" "delayed_compare")
6534    (set_attr "length" "4,8")])
6535
6536 (define_split
6537   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6538         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6539                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6540                     (const_int 0)))
6541    (clobber (match_scratch:DI 3 ""))]
6542   "TARGET_POWERPC64 && reload_completed"
6543   [(set (match_dup 3)
6544         (rotate:DI (match_dup 1) (match_dup 2)))
6545    (set (match_dup 0)
6546         (compare:CC (match_dup 3)
6547                     (const_int 0)))]
6548   "")
6549
6550 (define_insn "*rotldi3_internal3"
6551   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6552         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6553                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6554                     (const_int 0)))
6555    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6556         (rotate:DI (match_dup 1) (match_dup 2)))]
6557   "TARGET_64BIT"
6558   "@
6559    rld%I2cl. %0,%1,%H2,0
6560    #"
6561   [(set_attr "type" "delayed_compare")
6562    (set_attr "length" "4,8")])
6563
6564 (define_split
6565   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6566         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6567                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6568                     (const_int 0)))
6569    (set (match_operand:DI 0 "gpc_reg_operand" "")
6570         (rotate:DI (match_dup 1) (match_dup 2)))]
6571   "TARGET_POWERPC64 && reload_completed"
6572   [(set (match_dup 0)
6573         (rotate:DI (match_dup 1) (match_dup 2)))
6574    (set (match_dup 3)
6575         (compare:CC (match_dup 0)
6576                     (const_int 0)))]
6577   "")
6578
6579 (define_insn "*rotldi3_internal4"
6580   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6581         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6582                            (match_operand:DI 2 "reg_or_cint_operand" "ri"))
6583                 (match_operand:DI 3 "mask64_operand" "n")))]
6584   "TARGET_POWERPC64"
6585   "rld%I2c%B3 %0,%1,%H2,%S3")
6586
6587 (define_insn "*rotldi3_internal5"
6588   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6589         (compare:CC (and:DI
6590                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6591                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6592                      (match_operand:DI 3 "mask64_operand" "n,n"))
6593                     (const_int 0)))
6594    (clobber (match_scratch:DI 4 "=r,r"))]
6595   "TARGET_64BIT"
6596   "@
6597    rld%I2c%B3. %4,%1,%H2,%S3
6598    #"
6599   [(set_attr "type" "delayed_compare")
6600    (set_attr "length" "4,8")])
6601
6602 (define_split
6603   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6604         (compare:CC (and:DI
6605                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6606                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6607                      (match_operand:DI 3 "mask64_operand" ""))
6608                     (const_int 0)))
6609    (clobber (match_scratch:DI 4 ""))]
6610   "TARGET_POWERPC64 && reload_completed"
6611   [(set (match_dup 4)
6612         (and:DI (rotate:DI (match_dup 1)
6613                                 (match_dup 2))
6614                      (match_dup 3)))
6615    (set (match_dup 0)
6616         (compare:CC (match_dup 4)
6617                     (const_int 0)))]
6618   "")
6619
6620 (define_insn "*rotldi3_internal6"
6621   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6622         (compare:CC (and:DI
6623                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6624                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6625                      (match_operand:DI 3 "mask64_operand" "n,n"))
6626                     (const_int 0)))
6627    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6628         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6629   "TARGET_64BIT"
6630   "@
6631    rld%I2c%B3. %0,%1,%H2,%S3
6632    #"
6633   [(set_attr "type" "delayed_compare")
6634    (set_attr "length" "4,8")])
6635
6636 (define_split
6637   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6638         (compare:CC (and:DI
6639                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6640                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6641                      (match_operand:DI 3 "mask64_operand" ""))
6642                     (const_int 0)))
6643    (set (match_operand:DI 0 "gpc_reg_operand" "")
6644         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6645   "TARGET_POWERPC64 && reload_completed"
6646   [(set (match_dup 0)
6647         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6648    (set (match_dup 4)
6649         (compare:CC (match_dup 0)
6650                     (const_int 0)))]
6651   "")
6652
6653 (define_insn "*rotldi3_internal7"
6654   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6655         (zero_extend:DI
6656          (subreg:QI
6657           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6658                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6659   "TARGET_POWERPC64"
6660   "rld%I2cl %0,%1,%H2,56")
6661
6662 (define_insn "*rotldi3_internal8"
6663   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6664         (compare:CC (zero_extend:DI
6665                      (subreg:QI
6666                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6667                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6668                     (const_int 0)))
6669    (clobber (match_scratch:DI 3 "=r,r"))]
6670   "TARGET_64BIT"
6671   "@
6672    rld%I2cl. %3,%1,%H2,56
6673    #"
6674   [(set_attr "type" "delayed_compare")
6675    (set_attr "length" "4,8")])
6676
6677 (define_split
6678   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6679         (compare:CC (zero_extend:DI
6680                      (subreg:QI
6681                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6682                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6683                     (const_int 0)))
6684    (clobber (match_scratch:DI 3 ""))]
6685   "TARGET_POWERPC64 && reload_completed"
6686   [(set (match_dup 3)
6687         (zero_extend:DI (subreg:QI
6688                       (rotate:DI (match_dup 1)
6689                                  (match_dup 2)) 0)))
6690    (set (match_dup 0)
6691         (compare:CC (match_dup 3)
6692                     (const_int 0)))]
6693   "")
6694
6695 (define_insn "*rotldi3_internal9"
6696   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6697         (compare:CC (zero_extend:DI
6698                      (subreg:QI
6699                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6700                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6701                     (const_int 0)))
6702    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6703         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6704   "TARGET_64BIT"
6705   "@
6706    rld%I2cl. %0,%1,%H2,56
6707    #"
6708   [(set_attr "type" "delayed_compare")
6709    (set_attr "length" "4,8")])
6710
6711 (define_split
6712   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6713         (compare:CC (zero_extend:DI
6714                      (subreg:QI
6715                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6716                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6717                     (const_int 0)))
6718    (set (match_operand:DI 0 "gpc_reg_operand" "")
6719         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6720   "TARGET_POWERPC64 && reload_completed"
6721   [(set (match_dup 0)
6722         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6723    (set (match_dup 3)
6724         (compare:CC (match_dup 0)
6725                     (const_int 0)))]
6726   "")
6727
6728 (define_insn "*rotldi3_internal10"
6729   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6730         (zero_extend:DI
6731          (subreg:HI
6732           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6733                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6734   "TARGET_POWERPC64"
6735   "rld%I2cl %0,%1,%H2,48")
6736
6737 (define_insn "*rotldi3_internal11"
6738   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6739         (compare:CC (zero_extend:DI
6740                      (subreg:HI
6741                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6742                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6743                     (const_int 0)))
6744    (clobber (match_scratch:DI 3 "=r,r"))]
6745   "TARGET_64BIT"
6746   "@
6747    rld%I2cl. %3,%1,%H2,48
6748    #"
6749   [(set_attr "type" "delayed_compare")
6750    (set_attr "length" "4,8")])
6751
6752 (define_split
6753   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6754         (compare:CC (zero_extend:DI
6755                      (subreg:HI
6756                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6757                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6758                     (const_int 0)))
6759    (clobber (match_scratch:DI 3 ""))]
6760   "TARGET_POWERPC64 && reload_completed"
6761   [(set (match_dup 3)
6762         (zero_extend:DI (subreg:HI
6763                       (rotate:DI (match_dup 1)
6764                                  (match_dup 2)) 0)))
6765    (set (match_dup 0)
6766         (compare:CC (match_dup 3)
6767                     (const_int 0)))]
6768   "")
6769
6770 (define_insn "*rotldi3_internal12"
6771   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6772         (compare:CC (zero_extend:DI
6773                      (subreg:HI
6774                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6775                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6776                     (const_int 0)))
6777    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6778         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6779   "TARGET_64BIT"
6780   "@
6781    rld%I2cl. %0,%1,%H2,48
6782    #"
6783   [(set_attr "type" "delayed_compare")
6784    (set_attr "length" "4,8")])
6785
6786 (define_split
6787   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6788         (compare:CC (zero_extend:DI
6789                      (subreg:HI
6790                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6791                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6792                     (const_int 0)))
6793    (set (match_operand:DI 0 "gpc_reg_operand" "")
6794         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6795   "TARGET_POWERPC64 && reload_completed"
6796   [(set (match_dup 0)
6797         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6798    (set (match_dup 3)
6799         (compare:CC (match_dup 0)
6800                     (const_int 0)))]
6801   "")
6802
6803 (define_insn "*rotldi3_internal13"
6804   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6805         (zero_extend:DI
6806          (subreg:SI
6807           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6808                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6809   "TARGET_POWERPC64"
6810   "rld%I2cl %0,%1,%H2,32")
6811
6812 (define_insn "*rotldi3_internal14"
6813   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6814         (compare:CC (zero_extend:DI
6815                      (subreg:SI
6816                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6817                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6818                     (const_int 0)))
6819    (clobber (match_scratch:DI 3 "=r,r"))]
6820   "TARGET_64BIT"
6821   "@
6822    rld%I2cl. %3,%1,%H2,32
6823    #"
6824   [(set_attr "type" "delayed_compare")
6825    (set_attr "length" "4,8")])
6826
6827 (define_split
6828   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6829         (compare:CC (zero_extend:DI
6830                      (subreg:SI
6831                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6832                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6833                     (const_int 0)))
6834    (clobber (match_scratch:DI 3 ""))]
6835   "TARGET_POWERPC64 && reload_completed"
6836   [(set (match_dup 3)
6837         (zero_extend:DI (subreg:SI
6838                       (rotate:DI (match_dup 1)
6839                                  (match_dup 2)) 0)))
6840    (set (match_dup 0)
6841         (compare:CC (match_dup 3)
6842                     (const_int 0)))]
6843   "")
6844
6845 (define_insn "*rotldi3_internal15"
6846   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6847         (compare:CC (zero_extend:DI
6848                      (subreg:SI
6849                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6850                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6851                     (const_int 0)))
6852    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6853         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6854   "TARGET_64BIT"
6855   "@
6856    rld%I2cl. %0,%1,%H2,32
6857    #"
6858   [(set_attr "type" "delayed_compare")
6859    (set_attr "length" "4,8")])
6860
6861 (define_split
6862   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6863         (compare:CC (zero_extend:DI
6864                      (subreg:SI
6865                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6866                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6867                     (const_int 0)))
6868    (set (match_operand:DI 0 "gpc_reg_operand" "")
6869         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6870   "TARGET_POWERPC64 && reload_completed"
6871   [(set (match_dup 0)
6872         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6873    (set (match_dup 3)
6874         (compare:CC (match_dup 0)
6875                     (const_int 0)))]
6876   "")
6877
6878 (define_expand "ashldi3"
6879   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6880         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6881                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
6882   "TARGET_POWERPC64 || TARGET_POWER"
6883   "
6884 {
6885   if (TARGET_POWERPC64)
6886     ;
6887   else if (TARGET_POWER)
6888     {
6889       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
6890       DONE;
6891     }
6892   else
6893     FAIL;
6894 }")
6895
6896 (define_insn "*ashldi3_internal1"
6897   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6898         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6899                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6900   "TARGET_POWERPC64"
6901   "sld%I2 %0,%1,%H2")
6902
6903 (define_insn "*ashldi3_internal2"
6904   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6905         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6906                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6907                     (const_int 0)))
6908    (clobber (match_scratch:DI 3 "=r,r"))]
6909   "TARGET_64BIT"
6910   "@
6911    sld%I2. %3,%1,%H2
6912    #"
6913   [(set_attr "type" "delayed_compare")
6914    (set_attr "length" "4,8")])
6915
6916 (define_split
6917   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6918         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6919                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6920                     (const_int 0)))
6921    (clobber (match_scratch:DI 3 ""))]
6922   "TARGET_POWERPC64 && reload_completed"
6923   [(set (match_dup 3)
6924         (ashift:DI (match_dup 1) (match_dup 2)))
6925    (set (match_dup 0)
6926         (compare:CC (match_dup 3)
6927                     (const_int 0)))]
6928   "")
6929
6930 (define_insn "*ashldi3_internal3"
6931   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6932         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6933                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6934                     (const_int 0)))
6935    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6936         (ashift:DI (match_dup 1) (match_dup 2)))]
6937   "TARGET_64BIT"
6938   "@
6939    sld%I2. %0,%1,%H2
6940    #"
6941   [(set_attr "type" "delayed_compare")
6942    (set_attr "length" "4,8")])
6943
6944 (define_split
6945   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6946         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6947                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6948                     (const_int 0)))
6949    (set (match_operand:DI 0 "gpc_reg_operand" "")
6950         (ashift:DI (match_dup 1) (match_dup 2)))]
6951   "TARGET_POWERPC64 && reload_completed"
6952   [(set (match_dup 0)
6953         (ashift:DI (match_dup 1) (match_dup 2)))
6954    (set (match_dup 3)
6955         (compare:CC (match_dup 0)
6956                     (const_int 0)))]
6957   "")
6958
6959 (define_insn "*ashldi3_internal4"
6960   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6961         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6962                            (match_operand:SI 2 "const_int_operand" "i"))
6963                 (match_operand:DI 3 "const_int_operand" "n")))]
6964   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
6965   "rldic %0,%1,%H2,%W3")
6966
6967 (define_insn "ashldi3_internal5"
6968   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6969         (compare:CC
6970          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6971                             (match_operand:SI 2 "const_int_operand" "i,i"))
6972                  (match_operand:DI 3 "const_int_operand" "n,n"))
6973          (const_int 0)))
6974    (clobber (match_scratch:DI 4 "=r,r"))]
6975   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6976   "@
6977    rldic. %4,%1,%H2,%W3
6978    #"
6979   [(set_attr "type" "compare")
6980    (set_attr "length" "4,8")])
6981
6982 (define_split
6983   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6984         (compare:CC
6985          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6986                             (match_operand:SI 2 "const_int_operand" ""))
6987                  (match_operand:DI 3 "const_int_operand" ""))
6988          (const_int 0)))
6989    (clobber (match_scratch:DI 4 ""))]
6990   "TARGET_POWERPC64 && reload_completed
6991    && includes_rldic_lshift_p (operands[2], operands[3])"
6992   [(set (match_dup 4)
6993         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6994                 (match_dup 3)))
6995    (set (match_dup 0)
6996         (compare:CC (match_dup 4)
6997                     (const_int 0)))]
6998   "")
6999
7000 (define_insn "*ashldi3_internal6"
7001   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7002         (compare:CC
7003          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7004                             (match_operand:SI 2 "const_int_operand" "i,i"))
7005                     (match_operand:DI 3 "const_int_operand" "n,n"))
7006          (const_int 0)))
7007    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7008         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7009   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
7010   "@
7011    rldic. %0,%1,%H2,%W3
7012    #"
7013   [(set_attr "type" "compare")
7014    (set_attr "length" "4,8")])
7015
7016 (define_split
7017   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
7018         (compare:CC
7019          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7020                             (match_operand:SI 2 "const_int_operand" ""))
7021                  (match_operand:DI 3 "const_int_operand" ""))
7022          (const_int 0)))
7023    (set (match_operand:DI 0 "gpc_reg_operand" "")
7024         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7025   "TARGET_POWERPC64 && reload_completed
7026    && includes_rldic_lshift_p (operands[2], operands[3])"
7027   [(set (match_dup 0)
7028         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7029                 (match_dup 3)))
7030    (set (match_dup 4)
7031         (compare:CC (match_dup 0)
7032                     (const_int 0)))]
7033   "")
7034
7035 (define_insn "*ashldi3_internal7"
7036   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7037         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7038                            (match_operand:SI 2 "const_int_operand" "i"))
7039                 (match_operand:DI 3 "mask64_operand" "n")))]
7040   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
7041   "rldicr %0,%1,%H2,%S3")
7042
7043 (define_insn "ashldi3_internal8"
7044   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7045         (compare:CC
7046          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7047                             (match_operand:SI 2 "const_int_operand" "i,i"))
7048                  (match_operand:DI 3 "mask64_operand" "n,n"))
7049          (const_int 0)))
7050    (clobber (match_scratch:DI 4 "=r,r"))]
7051   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7052   "@
7053    rldicr. %4,%1,%H2,%S3
7054    #"
7055   [(set_attr "type" "compare")
7056    (set_attr "length" "4,8")])
7057
7058 (define_split
7059   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7060         (compare:CC
7061          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7062                             (match_operand:SI 2 "const_int_operand" ""))
7063                  (match_operand:DI 3 "mask64_operand" ""))
7064          (const_int 0)))
7065    (clobber (match_scratch:DI 4 ""))]
7066   "TARGET_POWERPC64 && reload_completed
7067    && includes_rldicr_lshift_p (operands[2], operands[3])"
7068   [(set (match_dup 4)
7069         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7070                 (match_dup 3)))
7071    (set (match_dup 0)
7072         (compare:CC (match_dup 4)
7073                     (const_int 0)))]
7074   "")
7075
7076 (define_insn "*ashldi3_internal9"
7077   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7078         (compare:CC
7079          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7080                             (match_operand:SI 2 "const_int_operand" "i,i"))
7081                     (match_operand:DI 3 "mask64_operand" "n,n"))
7082          (const_int 0)))
7083    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7084         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7085   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7086   "@
7087    rldicr. %0,%1,%H2,%S3
7088    #"
7089   [(set_attr "type" "compare")
7090    (set_attr "length" "4,8")])
7091
7092 (define_split
7093   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
7094         (compare:CC
7095          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7096                             (match_operand:SI 2 "const_int_operand" ""))
7097                  (match_operand:DI 3 "mask64_operand" ""))
7098          (const_int 0)))
7099    (set (match_operand:DI 0 "gpc_reg_operand" "")
7100         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7101   "TARGET_POWERPC64 && reload_completed
7102    && includes_rldicr_lshift_p (operands[2], operands[3])"
7103   [(set (match_dup 0)
7104         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7105                 (match_dup 3)))
7106    (set (match_dup 4)
7107         (compare:CC (match_dup 0)
7108                     (const_int 0)))]
7109   "")
7110
7111 (define_expand "lshrdi3"
7112   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7113         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7114                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7115   "TARGET_POWERPC64 || TARGET_POWER"
7116   "
7117 {
7118   if (TARGET_POWERPC64)
7119     ;
7120   else if (TARGET_POWER)
7121     {
7122       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
7123       DONE;
7124     }
7125   else
7126     FAIL;
7127 }")
7128
7129 (define_insn "*lshrdi3_internal1"
7130   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7131         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7132                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
7133   "TARGET_POWERPC64"
7134   "srd%I2 %0,%1,%H2")
7135
7136 (define_insn "*lshrdi3_internal2"
7137   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7138         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7139                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7140                     (const_int 0)))
7141    (clobber (match_scratch:DI 3 "=r,r"))]
7142   "TARGET_64BIT "
7143   "@
7144    srd%I2. %3,%1,%H2
7145    #"
7146   [(set_attr "type" "delayed_compare")
7147    (set_attr "length" "4,8")])
7148
7149 (define_split
7150   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7151         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7152                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7153                     (const_int 0)))
7154    (clobber (match_scratch:DI 3 ""))]
7155   "TARGET_POWERPC64 && reload_completed"
7156   [(set (match_dup 3)
7157         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7158    (set (match_dup 0)
7159         (compare:CC (match_dup 3)
7160                     (const_int 0)))]
7161   "")
7162
7163 (define_insn "*lshrdi3_internal3"
7164   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7165         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7166                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7167                     (const_int 0)))
7168    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7169         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7170   "TARGET_64BIT"
7171   "@
7172    srd%I2. %0,%1,%H2
7173    #"
7174   [(set_attr "type" "delayed_compare")
7175    (set_attr "length" "4,8")])
7176
7177 (define_split
7178   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7179         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7180                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7181                     (const_int 0)))
7182    (set (match_operand:DI 0 "gpc_reg_operand" "")
7183         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7184   "TARGET_POWERPC64 && reload_completed"
7185   [(set (match_dup 0)
7186         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7187    (set (match_dup 3)
7188         (compare:CC (match_dup 0)
7189                     (const_int 0)))]
7190   "")
7191
7192 (define_expand "ashrdi3"
7193   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7194         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7195                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7196   "WORDS_BIG_ENDIAN"
7197   "
7198 {
7199   if (TARGET_POWERPC64)
7200     ;
7201   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
7202     {
7203       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
7204       DONE;
7205     }
7206   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
7207            && WORDS_BIG_ENDIAN)
7208     {
7209       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
7210       DONE;
7211     }
7212   else
7213     FAIL;
7214 }")
7215
7216 (define_insn "*ashrdi3_internal1"
7217   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7218         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7219                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
7220   "TARGET_POWERPC64"
7221   "srad%I2 %0,%1,%H2")
7222
7223 (define_insn "*ashrdi3_internal2"
7224   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7225         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7226                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7227                     (const_int 0)))
7228    (clobber (match_scratch:DI 3 "=r,r"))]
7229   "TARGET_64BIT"
7230   "@
7231    srad%I2. %3,%1,%H2
7232    #"
7233   [(set_attr "type" "delayed_compare")
7234    (set_attr "length" "4,8")])
7235
7236 (define_split
7237   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7238         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7239                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7240                     (const_int 0)))
7241    (clobber (match_scratch:DI 3 ""))]
7242   "TARGET_POWERPC64 && reload_completed"
7243   [(set (match_dup 3)
7244         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7245    (set (match_dup 0)
7246         (compare:CC (match_dup 3)
7247                     (const_int 0)))]
7248   "")
7249
7250 (define_insn "*ashrdi3_internal3"
7251   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7252         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7253                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7254                     (const_int 0)))
7255    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7256         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7257   "TARGET_64BIT"
7258   "@
7259    srad%I2. %0,%1,%H2
7260    #"
7261   [(set_attr "type" "delayed_compare")
7262    (set_attr "length" "4,8")])
7263
7264 (define_split
7265   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7266         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7267                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7268                     (const_int 0)))
7269    (set (match_operand:DI 0 "gpc_reg_operand" "")
7270         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7271   "TARGET_POWERPC64 && reload_completed"
7272   [(set (match_dup 0)
7273         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7274    (set (match_dup 3)
7275         (compare:CC (match_dup 0)
7276                     (const_int 0)))]
7277   "")
7278
7279 (define_insn "anddi3"
7280   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
7281         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
7282                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
7283    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
7284   "TARGET_POWERPC64"
7285   "@
7286    and %0,%1,%2
7287    rldic%B2 %0,%1,0,%S2
7288    rlwinm %0,%1,0,%m2,%M2
7289    andi. %0,%1,%b2
7290    andis. %0,%1,%u2
7291    #"
7292   [(set_attr "type" "*,*,*,compare,compare,*")
7293    (set_attr "length" "4,4,4,4,4,8")])
7294
7295 (define_split
7296   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7297         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7298                 (match_operand:DI 2 "mask64_2_operand" "")))
7299    (clobber (match_scratch:CC 3 ""))]
7300   "TARGET_POWERPC64
7301     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7302     && !mask_operand (operands[2], DImode)
7303     && !mask64_operand (operands[2], DImode)"
7304   [(set (match_dup 0)
7305         (and:DI (rotate:DI (match_dup 1)
7306                            (match_dup 4))
7307                 (match_dup 5)))
7308    (set (match_dup 0)
7309         (and:DI (rotate:DI (match_dup 0)
7310                            (match_dup 6))
7311                 (match_dup 7)))]
7312 {
7313   build_mask64_2_operands (operands[2], &operands[4]);
7314 })
7315
7316 (define_insn "*anddi3_internal2"
7317   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7318         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7319                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7320                     (const_int 0)))
7321    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r,r,r"))
7322    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7323   "TARGET_64BIT"
7324   "@
7325    and. %3,%1,%2
7326    rldic%B2. %3,%1,0,%S2
7327    rlwinm. %3,%1,0,%m2,%M2
7328    andi. %3,%1,%b2
7329    andis. %3,%1,%u2
7330    #
7331    #
7332    #
7333    #
7334    #
7335    #
7336    #"
7337   [(set_attr "type" "compare,compare,compare,compare,compare,compare,compare,compare,compare,compare,compare,compare")
7338    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7339
7340 (define_split
7341   [(set (match_operand:CC 0 "cc_reg_operand" "")
7342         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7343                             (match_operand:DI 2 "mask64_2_operand" ""))
7344                     (const_int 0)))
7345    (clobber (match_scratch:DI 3 ""))
7346    (clobber (match_scratch:CC 4 ""))]
7347   "TARGET_64BIT && reload_completed
7348     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7349     && !mask_operand (operands[2], DImode)
7350     && !mask64_operand (operands[2], DImode)"
7351   [(set (match_dup 3)
7352         (and:DI (rotate:DI (match_dup 1)
7353                            (match_dup 5))
7354                 (match_dup 6)))
7355    (parallel [(set (match_dup 0)
7356                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7357                                                   (match_dup 7))
7358                                        (match_dup 8))
7359                                (const_int 0)))
7360               (clobber (match_dup 3))])]
7361   "
7362 {
7363   build_mask64_2_operands (operands[2], &operands[5]);
7364 }")
7365
7366 (define_insn "*anddi3_internal3"
7367   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7368         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7369                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7370                     (const_int 0)))
7371    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r,r,r")
7372         (and:DI (match_dup 1) (match_dup 2)))
7373    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7374   "TARGET_64BIT"
7375   "@
7376    and. %0,%1,%2
7377    rldic%B2. %0,%1,0,%S2
7378    rlwinm. %0,%1,0,%m2,%M2
7379    andi. %0,%1,%b2
7380    andis. %0,%1,%u2
7381    #
7382    #
7383    #
7384    #
7385    #
7386    #
7387    #"
7388   [(set_attr "type" "compare,compare,compare,compare,compare,compare,compare,compare,compare,compare,compare,compare")
7389    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7390
7391 (define_split
7392   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7393         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7394                             (match_operand:DI 2 "and64_2_operand" ""))
7395                     (const_int 0)))
7396    (set (match_operand:DI 0 "gpc_reg_operand" "")
7397         (and:DI (match_dup 1) (match_dup 2)))
7398    (clobber (match_scratch:CC 4 ""))]
7399   "TARGET_64BIT && reload_completed"
7400   [(parallel [(set (match_dup 0)
7401                     (and:DI (match_dup 1) (match_dup 2)))
7402                (clobber (match_dup 4))])
7403    (set (match_dup 3)
7404         (compare:CC (match_dup 0)
7405                     (const_int 0)))]
7406   "")
7407
7408 (define_split
7409   [(set (match_operand:CC 3 "cc_reg_operand" "")
7410         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7411                             (match_operand:DI 2 "mask64_2_operand" ""))
7412                     (const_int 0)))
7413    (set (match_operand:DI 0 "gpc_reg_operand" "")
7414         (and:DI (match_dup 1) (match_dup 2)))
7415    (clobber (match_scratch:CC 4 ""))]
7416   "TARGET_64BIT && reload_completed
7417     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7418     && !mask_operand (operands[2], DImode)
7419     && !mask64_operand (operands[2], DImode)"
7420   [(set (match_dup 0)
7421         (and:DI (rotate:DI (match_dup 1)
7422                            (match_dup 5))
7423                 (match_dup 6)))
7424    (parallel [(set (match_dup 3)
7425                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7426                                                   (match_dup 7))
7427                                        (match_dup 8))
7428                                (const_int 0)))
7429               (set (match_dup 0)
7430                    (and:DI (rotate:DI (match_dup 0)
7431                                       (match_dup 7))
7432                            (match_dup 8)))])]
7433   "
7434 {
7435   build_mask64_2_operands (operands[2], &operands[5]);
7436 }")
7437
7438 (define_expand "iordi3"
7439   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7440         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7441                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7442   "TARGET_POWERPC64"
7443   "
7444 {
7445   if (non_logical_cint_operand (operands[2], DImode))
7446     {
7447       HOST_WIDE_INT value;
7448       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7449                  ? operands[0] : gen_reg_rtx (DImode));
7450
7451       if (GET_CODE (operands[2]) == CONST_INT)
7452         {
7453           value = INTVAL (operands[2]);
7454           emit_insn (gen_iordi3 (tmp, operands[1],
7455                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7456         }
7457       else
7458         {
7459           value = CONST_DOUBLE_LOW (operands[2]);
7460           emit_insn (gen_iordi3 (tmp, operands[1],
7461                                  immed_double_const (value
7462                                                      & (~ (HOST_WIDE_INT) 0xffff),
7463                                                      0, DImode)));
7464         }
7465
7466       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7467       DONE;
7468     }
7469 }")
7470
7471 (define_expand "xordi3"
7472   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7473         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7474                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7475   "TARGET_POWERPC64"
7476   "
7477 {
7478   if (non_logical_cint_operand (operands[2], DImode))
7479     {
7480       HOST_WIDE_INT value;
7481       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7482                  ? operands[0] : gen_reg_rtx (DImode));
7483
7484       if (GET_CODE (operands[2]) == CONST_INT)
7485         {
7486           value = INTVAL (operands[2]);
7487           emit_insn (gen_xordi3 (tmp, operands[1],
7488                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7489         }
7490       else
7491         {
7492           value = CONST_DOUBLE_LOW (operands[2]);
7493           emit_insn (gen_xordi3 (tmp, operands[1],
7494                                  immed_double_const (value
7495                                                      & (~ (HOST_WIDE_INT) 0xffff),
7496                                                      0, DImode)));
7497         }
7498
7499       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7500       DONE;
7501     }
7502 }")
7503
7504 (define_insn "*booldi3_internal1"
7505   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7506         (match_operator:DI 3 "boolean_or_operator"
7507          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7508           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7509   "TARGET_POWERPC64"
7510   "@
7511    %q3 %0,%1,%2
7512    %q3i %0,%1,%b2
7513    %q3is %0,%1,%u2")
7514
7515 (define_insn "*booldi3_internal2"
7516   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7517         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7518          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7519           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7520          (const_int 0)))
7521    (clobber (match_scratch:DI 3 "=r,r"))]
7522   "TARGET_64BIT"
7523   "@
7524    %q4. %3,%1,%2
7525    #"
7526   [(set_attr "type" "compare")
7527    (set_attr "length" "4,8")])
7528
7529 (define_split
7530   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7531         (compare:CC (match_operator:DI 4 "boolean_operator"
7532          [(match_operand:DI 1 "gpc_reg_operand" "")
7533           (match_operand:DI 2 "gpc_reg_operand" "")])
7534          (const_int 0)))
7535    (clobber (match_scratch:DI 3 ""))]
7536   "TARGET_POWERPC64 && reload_completed"
7537   [(set (match_dup 3) (match_dup 4))
7538    (set (match_dup 0)
7539         (compare:CC (match_dup 3)
7540                     (const_int 0)))]
7541   "")
7542
7543 (define_insn "*booldi3_internal3"
7544   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7545         (compare:CC (match_operator:DI 4 "boolean_operator"
7546          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7547           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7548          (const_int 0)))
7549    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7550         (match_dup 4))]
7551   "TARGET_64BIT"
7552   "@
7553    %q4. %0,%1,%2
7554    #"
7555   [(set_attr "type" "compare")
7556    (set_attr "length" "4,8")])
7557
7558 (define_split
7559   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7560         (compare:CC (match_operator:DI 4 "boolean_operator"
7561          [(match_operand:DI 1 "gpc_reg_operand" "")
7562           (match_operand:DI 2 "gpc_reg_operand" "")])
7563          (const_int 0)))
7564    (set (match_operand:DI 0 "gpc_reg_operand" "")
7565         (match_dup 4))]
7566   "TARGET_POWERPC64 && reload_completed"
7567   [(set (match_dup 0) (match_dup 4))
7568    (set (match_dup 3)
7569         (compare:CC (match_dup 0)
7570                     (const_int 0)))]
7571   "")
7572
7573 ;; Split a logical operation that we can't do in one insn into two insns,
7574 ;; each of which does one 16-bit part.  This is used by combine.
7575
7576 (define_split
7577   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7578         (match_operator:DI 3 "boolean_or_operator"
7579          [(match_operand:DI 1 "gpc_reg_operand" "")
7580           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7581   "TARGET_POWERPC64"
7582   [(set (match_dup 0) (match_dup 4))
7583    (set (match_dup 0) (match_dup 5))]
7584 "
7585 {
7586   rtx i3,i4;
7587
7588   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7589     {
7590       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7591       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7592                                         0, DImode);
7593       i4 = GEN_INT (value & 0xffff);
7594     }
7595   else
7596     {
7597       i3 = GEN_INT (INTVAL (operands[2])
7598                              & (~ (HOST_WIDE_INT) 0xffff));
7599       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7600     }
7601   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7602                                 operands[1], i3);
7603   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7604                                 operands[0], i4);
7605 }")
7606
7607 (define_insn "*boolcdi3_internal1"
7608   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7609         (match_operator:DI 3 "boolean_operator"
7610          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7611           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7612   "TARGET_POWERPC64"
7613   "%q3 %0,%2,%1")
7614
7615 (define_insn "*boolcdi3_internal2"
7616   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7617         (compare:CC (match_operator:DI 4 "boolean_operator"
7618          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7619           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7620          (const_int 0)))
7621    (clobber (match_scratch:DI 3 "=r,r"))]
7622   "TARGET_64BIT"
7623   "@
7624    %q4. %3,%2,%1
7625    #"
7626   [(set_attr "type" "compare")
7627    (set_attr "length" "4,8")])
7628
7629 (define_split
7630   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7631         (compare:CC (match_operator:DI 4 "boolean_operator"
7632          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7633           (match_operand:DI 2 "gpc_reg_operand" "")])
7634          (const_int 0)))
7635    (clobber (match_scratch:DI 3 ""))]
7636   "TARGET_POWERPC64 && reload_completed"
7637   [(set (match_dup 3) (match_dup 4))
7638    (set (match_dup 0)
7639         (compare:CC (match_dup 3)
7640                     (const_int 0)))]
7641   "")
7642
7643 (define_insn "*boolcdi3_internal3"
7644   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7645         (compare:CC (match_operator:DI 4 "boolean_operator"
7646          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7647           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7648          (const_int 0)))
7649    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7650         (match_dup 4))]
7651   "TARGET_64BIT"
7652   "@
7653    %q4. %0,%2,%1
7654    #"
7655   [(set_attr "type" "compare")
7656    (set_attr "length" "4,8")])
7657
7658 (define_split
7659   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7660         (compare:CC (match_operator:DI 4 "boolean_operator"
7661          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7662           (match_operand:DI 2 "gpc_reg_operand" "")])
7663          (const_int 0)))
7664    (set (match_operand:DI 0 "gpc_reg_operand" "")
7665         (match_dup 4))]
7666   "TARGET_POWERPC64 && reload_completed"
7667   [(set (match_dup 0) (match_dup 4))
7668    (set (match_dup 3)
7669         (compare:CC (match_dup 0)
7670                     (const_int 0)))]
7671   "")
7672
7673 (define_insn "*boolccdi3_internal1"
7674   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7675         (match_operator:DI 3 "boolean_operator"
7676          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7677           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7678   "TARGET_POWERPC64"
7679   "%q3 %0,%1,%2")
7680
7681 (define_insn "*boolccdi3_internal2"
7682   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7683         (compare:CC (match_operator:DI 4 "boolean_operator"
7684          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7685           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7686          (const_int 0)))
7687    (clobber (match_scratch:DI 3 "=r,r"))]
7688   "TARGET_64BIT"
7689   "@
7690    %q4. %3,%1,%2
7691    #"
7692   [(set_attr "type" "compare")
7693    (set_attr "length" "4,8")])
7694
7695 (define_split
7696   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7697         (compare:CC (match_operator:DI 4 "boolean_operator"
7698          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7699           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7700          (const_int 0)))
7701    (clobber (match_scratch:DI 3 ""))]
7702   "TARGET_POWERPC64 && reload_completed"
7703   [(set (match_dup 3) (match_dup 4))
7704    (set (match_dup 0)
7705         (compare:CC (match_dup 3)
7706                     (const_int 0)))]
7707   "")
7708
7709 (define_insn "*boolccdi3_internal3"
7710   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7711         (compare:CC (match_operator:DI 4 "boolean_operator"
7712          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7713           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7714          (const_int 0)))
7715    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7716         (match_dup 4))]
7717   "TARGET_64BIT"
7718   "@
7719    %q4. %0,%1,%2
7720    #"
7721   [(set_attr "type" "compare")
7722    (set_attr "length" "4,8")])
7723
7724 (define_split
7725   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7726         (compare:CC (match_operator:DI 4 "boolean_operator"
7727          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7728           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7729          (const_int 0)))
7730    (set (match_operand:DI 0 "gpc_reg_operand" "")
7731         (match_dup 4))]
7732   "TARGET_POWERPC64 && reload_completed"
7733   [(set (match_dup 0) (match_dup 4))
7734    (set (match_dup 3)
7735         (compare:CC (match_dup 0)
7736                     (const_int 0)))]
7737   "")
7738 \f
7739 ;; Now define ways of moving data around.
7740
7741 ;; Set up a register with a value from the GOT table
7742
7743 (define_expand "movsi_got"
7744   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7745         (unspec:SI [(match_operand:SI 1 "got_operand" "")
7746                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
7747   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7748   "
7749 {
7750   if (GET_CODE (operands[1]) == CONST)
7751     {
7752       rtx offset = const0_rtx;
7753       HOST_WIDE_INT value;
7754
7755       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
7756       value = INTVAL (offset);
7757       if (value != 0)
7758         {
7759           rtx tmp = (no_new_pseudos ? operands[0] : gen_reg_rtx (Pmode));
7760           emit_insn (gen_movsi_got (tmp, operands[1]));
7761           emit_insn (gen_addsi3 (operands[0], tmp, offset));
7762           DONE;
7763         }
7764     }
7765
7766   operands[2] = rs6000_got_register (operands[1]);
7767 }")
7768
7769 (define_insn "*movsi_got_internal"
7770   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7771         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7772                     (match_operand:SI 2 "gpc_reg_operand" "b")]
7773                    UNSPEC_MOVSI_GOT))]
7774   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7775   "{l|lwz} %0,%a1@got(%2)"
7776   [(set_attr "type" "load")])
7777
7778 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
7779 ;; didn't get allocated to a hard register.
7780 (define_split
7781   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7782         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7783                     (match_operand:SI 2 "memory_operand" "")]
7784                    UNSPEC_MOVSI_GOT))]
7785   "DEFAULT_ABI == ABI_V4
7786     && flag_pic == 1
7787     && (reload_in_progress || reload_completed)"
7788   [(set (match_dup 0) (match_dup 2))
7789    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
7790                                  UNSPEC_MOVSI_GOT))]
7791   "")
7792
7793 ;; For SI, we special-case integers that can't be loaded in one insn.  We
7794 ;; do the load 16-bits at a time.  We could do this by loading from memory,
7795 ;; and this is even supposed to be faster, but it is simpler not to get
7796 ;; integers in the TOC.
7797 (define_insn "movsi_low"
7798   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7799         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7800                            (match_operand 2 "" ""))))]
7801   "TARGET_MACHO && ! TARGET_64BIT"
7802   "{l|lwz} %0,lo16(%2)(%1)"
7803   [(set_attr "type" "load")
7804    (set_attr "length" "4")])
7805
7806 (define_insn "*movsi_internal1"
7807   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
7808         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
7809   "gpc_reg_operand (operands[0], SImode)
7810    || gpc_reg_operand (operands[1], SImode)"
7811   "@
7812    mr %0,%1
7813    {cal|la} %0,%a1
7814    {l%U1%X1|lwz%U1%X1} %0,%1
7815    {st%U0%X0|stw%U0%X0} %1,%0
7816    {lil|li} %0,%1
7817    {liu|lis} %0,%v1
7818    #
7819    {cal|la} %0,%a1
7820    mf%1 %0
7821    mt%0 %1
7822    mt%0 %1
7823    mt%0 %1
7824    {cror 0,0,0|nop}"
7825   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
7826    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
7827
7828 ;; Split a load of a large constant into the appropriate two-insn
7829 ;; sequence.
7830
7831 (define_split
7832   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7833         (match_operand:SI 1 "const_int_operand" ""))]
7834   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
7835    && (INTVAL (operands[1]) & 0xffff) != 0"
7836   [(set (match_dup 0)
7837         (match_dup 2))
7838    (set (match_dup 0)
7839         (ior:SI (match_dup 0)
7840                 (match_dup 3)))]
7841   "
7842 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
7843
7844   if (tem == operands[0])
7845     DONE;
7846   else
7847     FAIL;
7848 }")
7849
7850 (define_insn "*mov<mode>_internal2"
7851   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
7852         (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
7853                     (const_int 0)))
7854    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
7855   ""
7856   "@
7857    {cmpi|cmp<wd>i} %2,%0,0
7858    mr. %0,%1
7859    #"
7860   [(set_attr "type" "cmp,compare,cmp")
7861    (set_attr "length" "4,4,8")])
7862
7863 (define_split
7864   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
7865         (compare:CC (match_operand:P 1 "gpc_reg_operand" "")
7866                     (const_int 0)))
7867    (set (match_operand:P 0 "gpc_reg_operand" "") (match_dup 1))]
7868   "reload_completed"
7869   [(set (match_dup 0) (match_dup 1))
7870    (set (match_dup 2)
7871         (compare:CC (match_dup 0)
7872                     (const_int 0)))]
7873   "")
7874 \f
7875 (define_insn "*movhi_internal"
7876   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7877         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7878   "gpc_reg_operand (operands[0], HImode)
7879    || gpc_reg_operand (operands[1], HImode)"
7880   "@
7881    mr %0,%1
7882    lhz%U1%X1 %0,%1
7883    sth%U0%X0 %1,%0
7884    {lil|li} %0,%w1
7885    mf%1 %0
7886    mt%0 %1
7887    mt%0 %1
7888    {cror 0,0,0|nop}"
7889   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7890
7891 (define_expand "mov<mode>"
7892   [(set (match_operand:INT 0 "general_operand" "")
7893         (match_operand:INT 1 "any_operand" ""))]
7894   ""
7895   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
7896
7897 (define_insn "*movqi_internal"
7898   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7899         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7900   "gpc_reg_operand (operands[0], QImode)
7901    || gpc_reg_operand (operands[1], QImode)"
7902   "@
7903    mr %0,%1
7904    lbz%U1%X1 %0,%1
7905    stb%U0%X0 %1,%0
7906    {lil|li} %0,%1
7907    mf%1 %0
7908    mt%0 %1
7909    mt%0 %1
7910    {cror 0,0,0|nop}"
7911   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7912 \f
7913 ;; Here is how to move condition codes around.  When we store CC data in
7914 ;; an integer register or memory, we store just the high-order 4 bits.
7915 ;; This lets us not shift in the most common case of CR0.
7916 (define_expand "movcc"
7917   [(set (match_operand:CC 0 "nonimmediate_operand" "")
7918         (match_operand:CC 1 "nonimmediate_operand" ""))]
7919   ""
7920   "")
7921
7922 (define_insn "*movcc_internal1"
7923   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,y,r,r,r,r,r,q,cl,r,m")
7924         (match_operand:CC 1 "general_operand" "y,r,r,O,x,y,r,I,h,r,r,m,r"))]
7925   "register_operand (operands[0], CCmode)
7926    || register_operand (operands[1], CCmode)"
7927   "@
7928    mcrf %0,%1
7929    mtcrf 128,%1
7930    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
7931    crxor %0,%0,%0
7932    mfcr %0%Q1
7933    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
7934    mr %0,%1
7935    {lil|li} %0,%1
7936    mf%1 %0
7937    mt%0 %1
7938    mt%0 %1
7939    {l%U1%X1|lwz%U1%X1} %0,%1
7940    {st%U0%U1|stw%U0%U1} %1,%0"
7941   [(set (attr "type")
7942      (cond [(eq_attr "alternative" "0,3")
7943                 (const_string "cr_logical")
7944             (eq_attr "alternative" "1,2")
7945                 (const_string "mtcr")
7946             (eq_attr "alternative" "6,7,9")
7947                 (const_string "integer")
7948             (eq_attr "alternative" "8")
7949                 (const_string "mfjmpr")
7950             (eq_attr "alternative" "10")
7951                 (const_string "mtjmpr")
7952             (eq_attr "alternative" "11")
7953                 (const_string "load")
7954             (eq_attr "alternative" "12")
7955                 (const_string "store")
7956             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
7957                 (const_string "mfcrf")
7958            ]
7959         (const_string "mfcr")))
7960    (set_attr "length" "4,4,12,4,4,8,4,4,4,4,4,4,4")])
7961 \f
7962 ;; For floating-point, we normally deal with the floating-point registers
7963 ;; unless -msoft-float is used.  The sole exception is that parameter passing
7964 ;; can produce floating-point values in fixed-point registers.  Unless the
7965 ;; value is a simple constant or already in memory, we deal with this by
7966 ;; allocating memory and copying the value explicitly via that memory location.
7967 (define_expand "movsf"
7968   [(set (match_operand:SF 0 "nonimmediate_operand" "")
7969         (match_operand:SF 1 "any_operand" ""))]
7970   ""
7971   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
7972
7973 (define_split
7974   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7975         (match_operand:SF 1 "const_double_operand" ""))]
7976   "reload_completed
7977    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7978        || (GET_CODE (operands[0]) == SUBREG
7979            && GET_CODE (SUBREG_REG (operands[0])) == REG
7980            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7981   [(set (match_dup 2) (match_dup 3))]
7982   "
7983 {
7984   long l;
7985   REAL_VALUE_TYPE rv;
7986
7987   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7988   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
7989
7990   if (! TARGET_POWERPC64)
7991     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
7992   else
7993     operands[2] = gen_lowpart (SImode, operands[0]);
7994
7995   operands[3] = gen_int_mode (l, SImode);
7996 }")
7997
7998 (define_insn "*movsf_hardfloat"
7999   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,*c*l,*q,!r,*h,!r,!r")
8000         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,0,G,Fn"))]
8001   "(gpc_reg_operand (operands[0], SFmode)
8002    || gpc_reg_operand (operands[1], SFmode))
8003    && (TARGET_HARD_FLOAT && TARGET_FPRS)"
8004   "@
8005    mr %0,%1
8006    {l%U1%X1|lwz%U1%X1} %0,%1
8007    {st%U0%X0|stw%U0%X0} %1,%0
8008    fmr %0,%1
8009    lfs%U1%X1 %0,%1
8010    stfs%U0%X0 %1,%0
8011    mt%0 %1
8012    mt%0 %1
8013    mf%1 %0
8014    {cror 0,0,0|nop}
8015    #
8016    #"
8017   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,mfjmpr,*,*,*")
8018    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,8")])
8019
8020 (define_insn "*movsf_softfloat"
8021   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
8022         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
8023   "(gpc_reg_operand (operands[0], SFmode)
8024    || gpc_reg_operand (operands[1], SFmode))
8025    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
8026   "@
8027    mr %0,%1
8028    mt%0 %1
8029    mt%0 %1
8030    mf%1 %0
8031    {l%U1%X1|lwz%U1%X1} %0,%1
8032    {st%U0%X0|stw%U0%X0} %1,%0
8033    {lil|li} %0,%1
8034    {liu|lis} %0,%v1
8035    {cal|la} %0,%a1
8036    #
8037    #
8038    {cror 0,0,0|nop}"
8039   [(set_attr "type" "*,mtjmpr,*,mfjmpr,load,store,*,*,*,*,*,*")
8040    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
8041
8042 \f
8043 (define_expand "movdf"
8044   [(set (match_operand:DF 0 "nonimmediate_operand" "")
8045         (match_operand:DF 1 "any_operand" ""))]
8046   ""
8047   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
8048
8049 (define_split
8050   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8051         (match_operand:DF 1 "const_int_operand" ""))]
8052   "! TARGET_POWERPC64 && reload_completed
8053    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8054        || (GET_CODE (operands[0]) == SUBREG
8055            && GET_CODE (SUBREG_REG (operands[0])) == REG
8056            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8057   [(set (match_dup 2) (match_dup 4))
8058    (set (match_dup 3) (match_dup 1))]
8059   "
8060 {
8061   int endian = (WORDS_BIG_ENDIAN == 0);
8062   HOST_WIDE_INT value = INTVAL (operands[1]);
8063
8064   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8065   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8066 #if HOST_BITS_PER_WIDE_INT == 32
8067   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8068 #else
8069   operands[4] = GEN_INT (value >> 32);
8070   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8071 #endif
8072 }")
8073
8074 (define_split
8075   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8076         (match_operand:DF 1 "const_double_operand" ""))]
8077   "! TARGET_POWERPC64 && reload_completed
8078    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8079        || (GET_CODE (operands[0]) == SUBREG
8080            && GET_CODE (SUBREG_REG (operands[0])) == REG
8081            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8082   [(set (match_dup 2) (match_dup 4))
8083    (set (match_dup 3) (match_dup 5))]
8084   "
8085 {
8086   int endian = (WORDS_BIG_ENDIAN == 0);
8087   long l[2];
8088   REAL_VALUE_TYPE rv;
8089
8090   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8091   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8092
8093   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8094   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8095   operands[4] = gen_int_mode (l[endian], SImode);
8096   operands[5] = gen_int_mode (l[1 - endian], SImode);
8097 }")
8098
8099 (define_split
8100   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8101         (match_operand:DF 1 "const_double_operand" ""))]
8102   "TARGET_POWERPC64 && reload_completed
8103    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8104        || (GET_CODE (operands[0]) == SUBREG
8105            && GET_CODE (SUBREG_REG (operands[0])) == REG
8106            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8107   [(set (match_dup 2) (match_dup 3))]
8108   "
8109 {
8110   int endian = (WORDS_BIG_ENDIAN == 0);
8111   long l[2];
8112   REAL_VALUE_TYPE rv;
8113 #if HOST_BITS_PER_WIDE_INT >= 64
8114   HOST_WIDE_INT val;
8115 #endif
8116
8117   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8118   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8119
8120   operands[2] = gen_lowpart (DImode, operands[0]);
8121   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
8122 #if HOST_BITS_PER_WIDE_INT >= 64
8123   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
8124          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
8125
8126   operands[3] = gen_int_mode (val, DImode);
8127 #else
8128   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
8129 #endif
8130 }")
8131
8132 ;; Don't have reload use general registers to load a constant.  First,
8133 ;; it might not work if the output operand is the equivalent of
8134 ;; a non-offsettable memref, but also it is less efficient than loading
8135 ;; the constant into an FP register, since it will probably be used there.
8136 ;; The "??" is a kludge until we can figure out a more reasonable way
8137 ;; of handling these non-offsettable values.
8138 (define_insn "*movdf_hardfloat32"
8139   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,f,f,m,!r,!r,!r")
8140         (match_operand:DF 1 "input_operand" "r,m,r,f,m,f,G,H,F"))]
8141   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8142    && (gpc_reg_operand (operands[0], DFmode)
8143        || gpc_reg_operand (operands[1], DFmode))"
8144   "*
8145 {
8146   switch (which_alternative)
8147     {
8148     default:
8149       gcc_unreachable ();
8150     case 0:
8151       /* We normally copy the low-numbered register first.  However, if
8152          the first register operand 0 is the same as the second register
8153          of operand 1, we must copy in the opposite order.  */
8154       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8155         return \"mr %L0,%L1\;mr %0,%1\";
8156       else
8157         return \"mr %0,%1\;mr %L0,%L1\";
8158     case 1:
8159       if (rs6000_offsettable_memref_p (operands[1])
8160           || (GET_CODE (operands[1]) == MEM
8161               && (GET_CODE (XEXP (operands[1], 0)) == LO_SUM
8162                   || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
8163                   || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)))
8164         {
8165           /* If the low-address word is used in the address, we must load
8166              it last.  Otherwise, load it first.  Note that we cannot have
8167              auto-increment in that case since the address register is
8168              known to be dead.  */
8169           if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8170                                  operands[1], 0))
8171             return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8172           else
8173             return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8174         }
8175       else
8176         {
8177           rtx addreg;
8178
8179           addreg = find_addr_reg (XEXP (operands[1], 0));
8180           if (refers_to_regno_p (REGNO (operands[0]),
8181                                  REGNO (operands[0]) + 1,
8182                                  operands[1], 0))
8183             {
8184               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8185               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8186               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8187               return \"{lx|lwzx} %0,%1\";
8188             }
8189           else
8190             {
8191               output_asm_insn (\"{lx|lwzx} %0,%1\", operands);
8192               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8193               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8194               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8195               return \"\";
8196             }
8197         }
8198     case 2:
8199       if (rs6000_offsettable_memref_p (operands[0])
8200           || (GET_CODE (operands[0]) == MEM
8201               && (GET_CODE (XEXP (operands[0], 0)) == LO_SUM
8202                   || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
8203                   || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)))
8204         return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8205       else
8206         {
8207           rtx addreg;
8208
8209           addreg = find_addr_reg (XEXP (operands[0], 0));
8210           output_asm_insn (\"{stx|stwx} %1,%0\", operands);
8211           output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8212           output_asm_insn (\"{stx|stwx} %L1,%0\", operands);
8213           output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8214           return \"\";
8215         }
8216     case 3:
8217       return \"fmr %0,%1\";
8218     case 4:
8219       return \"lfd%U1%X1 %0,%1\";
8220     case 5:
8221       return \"stfd%U0%X0 %1,%0\";
8222     case 6:
8223     case 7:
8224     case 8:
8225       return \"#\";
8226     }
8227 }"
8228   [(set_attr "type" "two,load,store,fp,fpload,fpstore,*,*,*")
8229    (set_attr "length" "8,16,16,4,4,4,8,12,16")])
8230
8231 (define_insn "*movdf_softfloat32"
8232   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
8233         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
8234   "! TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
8235    && (gpc_reg_operand (operands[0], DFmode)
8236        || gpc_reg_operand (operands[1], DFmode))"
8237   "*
8238 {
8239   switch (which_alternative)
8240     {
8241     default:
8242       gcc_unreachable ();
8243     case 0:
8244       /* We normally copy the low-numbered register first.  However, if
8245          the first register operand 0 is the same as the second register of
8246          operand 1, we must copy in the opposite order.  */
8247       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8248         return \"mr %L0,%L1\;mr %0,%1\";
8249       else
8250         return \"mr %0,%1\;mr %L0,%L1\";
8251     case 1:
8252       /* If the low-address word is used in the address, we must load
8253          it last.  Otherwise, load it first.  Note that we cannot have
8254          auto-increment in that case since the address register is
8255          known to be dead.  */
8256       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8257                              operands[1], 0))
8258         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8259       else
8260         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8261     case 2:
8262       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8263     case 3:
8264     case 4:
8265     case 5:
8266       return \"#\";
8267     }
8268 }"
8269   [(set_attr "type" "two,load,store,*,*,*")
8270    (set_attr "length" "8,8,8,8,12,16")])
8271
8272 ; ld/std require word-aligned displacements -> 'Y' constraint.
8273 ; List Y->r and r->Y before r->r for reload.
8274 (define_insn "*movdf_hardfloat64"
8275   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,f,f,m,*c*l,!r,*h,!r,!r,!r")
8276         (match_operand:DF 1 "input_operand" "r,Y,r,f,m,f,r,h,0,G,H,F"))]
8277   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8278    && (gpc_reg_operand (operands[0], DFmode)
8279        || gpc_reg_operand (operands[1], DFmode))"
8280   "@
8281    std%U0%X0 %1,%0
8282    ld%U1%X1 %0,%1
8283    mr %0,%1
8284    fmr %0,%1
8285    lfd%U1%X1 %0,%1
8286    stfd%U0%X0 %1,%0
8287    mt%0 %1
8288    mf%1 %0
8289    {cror 0,0,0|nop}
8290    #
8291    #
8292    #"
8293   [(set_attr "type" "store,load,*,fp,fpload,fpstore,mtjmpr,mfjmpr,*,*,*,*")
8294    (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16")])
8295
8296 (define_insn "*movdf_softfloat64"
8297   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
8298         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
8299   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8300    && (gpc_reg_operand (operands[0], DFmode)
8301        || gpc_reg_operand (operands[1], DFmode))"
8302   "@
8303    ld%U1%X1 %0,%1
8304    std%U0%X0 %1,%0
8305    mr %0,%1
8306    mt%0 %1
8307    mf%1 %0
8308    #
8309    #
8310    #
8311    {cror 0,0,0|nop}"
8312   [(set_attr "type" "load,store,*,mtjmpr,mfjmpr,*,*,*,*")
8313    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
8314 \f
8315 (define_expand "movtf"
8316   [(set (match_operand:TF 0 "general_operand" "")
8317         (match_operand:TF 1 "any_operand" ""))]
8318   "!TARGET_IEEEQUAD
8319    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8320   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
8321
8322 ; It's important to list the o->f and f->o moves before f->f because
8323 ; otherwise reload, given m->f, will try to pick f->f and reload it,
8324 ; which doesn't make progress.  Likewise r->Y must be before r->r.
8325 (define_insn_and_split "*movtf_internal"
8326   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,f,r,Y,r")
8327         (match_operand:TF 1 "input_operand"         "f,o,f,YGHF,r,r"))]
8328   "!TARGET_IEEEQUAD
8329    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
8330    && (gpc_reg_operand (operands[0], TFmode)
8331        || gpc_reg_operand (operands[1], TFmode))"
8332   "#"
8333   "&& reload_completed"
8334   [(pc)]
8335 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8336   [(set_attr "length" "8,8,8,20,20,16")])
8337
8338 (define_expand "extenddftf2"
8339   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
8340                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
8341               (use (match_dup 2))])]
8342   "!TARGET_IEEEQUAD
8343    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8344 {
8345   operands[2] = CONST0_RTX (DFmode);
8346   /* Generate GOT reference early for SVR4 PIC.  */
8347   if (DEFAULT_ABI == ABI_V4 && flag_pic)
8348     operands[2] = validize_mem (force_const_mem (DFmode, operands[2]));
8349 })
8350
8351 (define_insn_and_split "*extenddftf2_internal"
8352   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,&f,r")
8353        (float_extend:TF (match_operand:DF 1 "input_operand" "fr,mf,mf,rmGHF")))
8354    (use (match_operand:DF 2 "zero_reg_mem_operand" "rf,m,f,n"))]
8355   "!TARGET_IEEEQUAD
8356    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8357   "#"
8358   "&& reload_completed"
8359   [(pc)]
8360 {
8361   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8362   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8363   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
8364                   operands[1]);
8365   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
8366                   operands[2]);
8367   DONE;
8368 })
8369
8370 (define_expand "extendsftf2"
8371   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8372         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
8373   "!TARGET_IEEEQUAD
8374    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8375 {
8376   rtx tmp = gen_reg_rtx (DFmode);
8377   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
8378   emit_insn (gen_extenddftf2 (operands[0], tmp));
8379   DONE;
8380 })
8381
8382 (define_expand "trunctfdf2"
8383   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8384         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
8385   "!TARGET_IEEEQUAD
8386    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8387   "")
8388
8389 (define_insn_and_split "trunctfdf2_internal1"
8390   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f")
8391         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,f")))]
8392   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
8393    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8394   "@
8395    #
8396    fmr %0,%1"
8397   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
8398   [(const_int 0)]
8399 {
8400   emit_note (NOTE_INSN_DELETED);
8401   DONE;
8402 }
8403   [(set_attr "type" "fp")])
8404
8405 (define_insn "trunctfdf2_internal2"
8406   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8407         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8408   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
8409    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8410   "fadd %0,%1,%L1"
8411   [(set_attr "type" "fp")])
8412
8413 (define_insn_and_split "trunctfsf2"
8414   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8415         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "f")))
8416    (clobber (match_scratch:DF 2 "=f"))]
8417   "!TARGET_IEEEQUAD
8418    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8419   "#"
8420   "&& reload_completed"
8421   [(set (match_dup 2)
8422         (float_truncate:DF (match_dup 1)))
8423    (set (match_dup 0)
8424         (float_truncate:SF (match_dup 2)))]
8425   "")
8426
8427 (define_expand "floatsitf2"
8428   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8429         (float:TF (match_operand:SI 1 "gpc_reg_operand" "")))]
8430   "!TARGET_IEEEQUAD
8431    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8432 {
8433   rtx tmp = gen_reg_rtx (DFmode);
8434   expand_float (tmp, operands[1], false);
8435   emit_insn (gen_extenddftf2 (operands[0], tmp));
8436   DONE;
8437 })
8438
8439 ; fadd, but rounding towards zero.
8440 ; This is probably not the optimal code sequence.
8441 (define_insn "fix_trunc_helper"
8442   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8443         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "f")]
8444                    UNSPEC_FIX_TRUNC_TF))
8445    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&f"))]
8446   "TARGET_HARD_FLOAT && TARGET_FPRS"
8447   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
8448   [(set_attr "type" "fp")
8449    (set_attr "length" "20")])
8450
8451 (define_expand "fix_trunctfsi2"
8452   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
8453                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
8454               (clobber (match_dup 2))
8455               (clobber (match_dup 3))
8456               (clobber (match_dup 4))
8457               (clobber (match_dup 5))])]
8458   "!TARGET_IEEEQUAD
8459    && (TARGET_POWER2 || TARGET_POWERPC)
8460    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8461 {
8462   operands[2] = gen_reg_rtx (DFmode);
8463   operands[3] = gen_reg_rtx (DFmode);
8464   operands[4] = gen_reg_rtx (DImode);
8465   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
8466 })
8467
8468 (define_insn_and_split "*fix_trunctfsi2_internal"
8469   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8470         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "f")))
8471    (clobber (match_operand:DF 2 "gpc_reg_operand" "=f"))
8472    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&f"))
8473    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))
8474    (clobber (match_operand:DI 5 "memory_operand" "=o"))]
8475   "!TARGET_IEEEQUAD
8476    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8477   "#"
8478   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[5]))"
8479   [(pc)]
8480 {
8481   rtx lowword;
8482   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
8483
8484   gcc_assert (MEM_P (operands[5]));
8485   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
8486
8487   emit_insn (gen_fctiwz (operands[4], operands[2]));
8488   emit_move_insn (operands[5], operands[4]);
8489   emit_move_insn (operands[0], lowword);
8490   DONE;
8491 })
8492
8493 (define_insn "negtf2"
8494   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8495         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8496   "!TARGET_IEEEQUAD
8497    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8498   "*
8499 {
8500   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8501     return \"fneg %L0,%L1\;fneg %0,%1\";
8502   else
8503     return \"fneg %0,%1\;fneg %L0,%L1\";
8504 }"
8505   [(set_attr "type" "fp")
8506    (set_attr "length" "8")])
8507
8508 (define_expand "abstf2"
8509   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8510         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8511   "!TARGET_IEEEQUAD
8512    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8513   "
8514 {
8515   rtx label = gen_label_rtx ();
8516   emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
8517   emit_label (label);
8518   DONE;
8519 }")
8520
8521 (define_expand "abstf2_internal"
8522   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8523         (match_operand:TF 1 "gpc_reg_operand" "f"))
8524    (set (match_dup 3) (match_dup 5))
8525    (set (match_dup 5) (abs:DF (match_dup 5)))
8526    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
8527    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
8528                            (label_ref (match_operand 2 "" ""))
8529                            (pc)))
8530    (set (match_dup 6) (neg:DF (match_dup 6)))]
8531   "!TARGET_IEEEQUAD
8532    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8533   "
8534 {
8535   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8536   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8537   operands[3] = gen_reg_rtx (DFmode);
8538   operands[4] = gen_reg_rtx (CCFPmode);
8539   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
8540   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
8541 }")
8542 \f
8543 ;; Next come the multi-word integer load and store and the load and store
8544 ;; multiple insns.
8545
8546 ; List r->r after r->"o<>", otherwise reload will try to reload a
8547 ; non-offsettable address by using r->r which won't make progress.
8548 (define_insn "*movdi_internal32"
8549   [(set (match_operand:DI 0 "nonimmediate_operand" "=o<>,r,r,*f,*f,m,r")
8550         (match_operand:DI 1 "input_operand" "r,r,m,f,m,f,IJKnGHF"))]
8551   "! TARGET_POWERPC64
8552    && (gpc_reg_operand (operands[0], DImode)
8553        || gpc_reg_operand (operands[1], DImode))"
8554   "@
8555    #
8556    #
8557    #
8558    fmr %0,%1
8559    lfd%U1%X1 %0,%1
8560    stfd%U0%X0 %1,%0
8561    #"
8562   [(set_attr "type" "load,*,store,fp,fpload,fpstore,*")])
8563
8564 (define_split
8565   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8566         (match_operand:DI 1 "const_int_operand" ""))]
8567   "! TARGET_POWERPC64 && reload_completed"
8568   [(set (match_dup 2) (match_dup 4))
8569    (set (match_dup 3) (match_dup 1))]
8570   "
8571 {
8572   HOST_WIDE_INT value = INTVAL (operands[1]);
8573   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8574                                        DImode);
8575   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8576                                        DImode);
8577 #if HOST_BITS_PER_WIDE_INT == 32
8578   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8579 #else
8580   operands[4] = GEN_INT (value >> 32);
8581   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8582 #endif
8583 }")
8584
8585 (define_split
8586   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8587         (match_operand:DI 1 "input_operand" ""))]
8588   "reload_completed && !TARGET_POWERPC64
8589    && gpr_or_gpr_p (operands[0], operands[1])"
8590   [(pc)]
8591 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8592
8593 (define_insn "*movdi_internal64"
8594   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*f,*f,m,r,*h,*h")
8595         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,f,m,f,*h,r,0"))]
8596   "TARGET_POWERPC64
8597    && (gpc_reg_operand (operands[0], DImode)
8598        || gpc_reg_operand (operands[1], DImode))"
8599   "@
8600    mr %0,%1
8601    ld%U1%X1 %0,%1
8602    std%U0%X0 %1,%0
8603    li %0,%1
8604    lis %0,%v1
8605    #
8606    {cal|la} %0,%a1
8607    fmr %0,%1
8608    lfd%U1%X1 %0,%1
8609    stfd%U0%X0 %1,%0
8610    mf%1 %0
8611    mt%0 %1
8612    {cror 0,0,0|nop}"
8613   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
8614    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
8615
8616 ;; immediate value valid for a single instruction hiding in a const_double
8617 (define_insn ""
8618   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8619         (match_operand:DI 1 "const_double_operand" "F"))]
8620   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
8621    && GET_CODE (operands[1]) == CONST_DOUBLE
8622    && num_insns_constant (operands[1], DImode) == 1"
8623   "*
8624 {
8625   return ((unsigned HOST_WIDE_INT)
8626           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
8627          ? \"li %0,%1\" : \"lis %0,%v1\";
8628 }")
8629
8630 ;; Generate all one-bits and clear left or right.
8631 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
8632 (define_split
8633   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8634         (match_operand:DI 1 "mask64_operand" ""))]
8635   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8636   [(set (match_dup 0) (const_int -1))
8637    (set (match_dup 0)
8638         (and:DI (rotate:DI (match_dup 0)
8639                            (const_int 0))
8640                 (match_dup 1)))]
8641   "")
8642
8643 ;; Split a load of a large constant into the appropriate five-instruction
8644 ;; sequence.  Handle anything in a constant number of insns.
8645 ;; When non-easy constants can go in the TOC, this should use
8646 ;; easy_fp_constant predicate.
8647 (define_split
8648   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8649         (match_operand:DI 1 "const_int_operand" ""))]
8650   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8651   [(set (match_dup 0) (match_dup 2))
8652    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8653   "
8654 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8655
8656   if (tem == operands[0])
8657     DONE;
8658   else
8659     FAIL;
8660 }")
8661
8662 (define_split
8663   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8664         (match_operand:DI 1 "const_double_operand" ""))]
8665   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8666   [(set (match_dup 0) (match_dup 2))
8667    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8668   "
8669 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8670
8671   if (tem == operands[0])
8672     DONE;
8673   else
8674     FAIL;
8675 }")
8676 \f
8677 ;; TImode is similar, except that we usually want to compute the address into
8678 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
8679 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
8680
8681 ;; We say that MQ is clobbered in the last alternative because the first
8682 ;; alternative would never get used otherwise since it would need a reload
8683 ;; while the 2nd alternative would not.  We put memory cases first so they
8684 ;; are preferred.  Otherwise, we'd try to reload the output instead of
8685 ;; giving the SCRATCH mq.
8686
8687 (define_insn "*movti_power"
8688   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r,r")
8689         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))
8690    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X,X"))]
8691   "TARGET_POWER && ! TARGET_POWERPC64
8692    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8693   "*
8694 {
8695   switch (which_alternative)
8696     {
8697     default:
8698       gcc_unreachable ();
8699
8700     case 0:
8701       if (TARGET_STRING)
8702         return \"{stsi|stswi} %1,%P0,16\";
8703     case 1:
8704     case 2:
8705       return \"#\";
8706     case 3:
8707       /* If the address is not used in the output, we can use lsi.  Otherwise,
8708          fall through to generating four loads.  */
8709       if (TARGET_STRING
8710           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8711         return \"{lsi|lswi} %0,%P1,16\";
8712       /* ... fall through ...  */
8713     case 4:
8714     case 5:
8715       return \"#\";
8716     }
8717 }"
8718   [(set_attr "type" "store,store,*,load,load,*")])
8719
8720 (define_insn "*movti_string"
8721   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,o<>,????r,????r,????r,r")
8722         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))]
8723   "! TARGET_POWER && ! TARGET_POWERPC64
8724    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8725   "*
8726 {
8727   switch (which_alternative)
8728     {
8729     default:
8730       gcc_unreachable ();
8731     case 0:
8732       if (TARGET_STRING)
8733         return \"{stsi|stswi} %1,%P0,16\";
8734     case 1:
8735     case 2:
8736       return \"#\";
8737     case 3:
8738       /* If the address is not used in the output, we can use lsi.  Otherwise,
8739          fall through to generating four loads.  */
8740       if (TARGET_STRING
8741           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8742         return \"{lsi|lswi} %0,%P1,16\";
8743       /* ... fall through ...  */
8744     case 4:
8745     case 5:
8746       return \"#\";
8747     }
8748 }"
8749   [(set_attr "type" "store_ux,store_ux,*,load_ux,load_ux,*")])
8750
8751 (define_insn "*movti_ppc64"
8752   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,o<>,r")
8753         (match_operand:TI 1 "input_operand" "r,r,m"))]
8754   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
8755    || gpc_reg_operand (operands[1], TImode))"
8756   "#"
8757   [(set_attr "type" "*,load,store")])
8758
8759 (define_split
8760   [(set (match_operand:TI 0 "gpc_reg_operand" "")
8761         (match_operand:TI 1 "const_double_operand" ""))]
8762   "TARGET_POWERPC64"
8763   [(set (match_dup 2) (match_dup 4))
8764    (set (match_dup 3) (match_dup 5))]
8765   "
8766 {
8767   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8768                                        TImode);
8769   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8770                                        TImode);
8771   if (GET_CODE (operands[1]) == CONST_DOUBLE)
8772     {
8773       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8774       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
8775     }
8776   else if (GET_CODE (operands[1]) == CONST_INT)
8777     {
8778       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
8779       operands[5] = operands[1];
8780     }
8781   else
8782     FAIL;
8783 }")
8784
8785 (define_split
8786   [(set (match_operand:TI 0 "nonimmediate_operand" "")
8787         (match_operand:TI 1 "input_operand" ""))]
8788   "reload_completed
8789    && gpr_or_gpr_p (operands[0], operands[1])"
8790   [(pc)]
8791 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8792 \f
8793 (define_expand "load_multiple"
8794   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8795                           (match_operand:SI 1 "" ""))
8796                      (use (match_operand:SI 2 "" ""))])]
8797   "TARGET_STRING && !TARGET_POWERPC64"
8798   "
8799 {
8800   int regno;
8801   int count;
8802   rtx op1;
8803   int i;
8804
8805   /* Support only loading a constant number of fixed-point registers from
8806      memory and only bother with this if more than two; the machine
8807      doesn't support more than eight.  */
8808   if (GET_CODE (operands[2]) != CONST_INT
8809       || INTVAL (operands[2]) <= 2
8810       || INTVAL (operands[2]) > 8
8811       || GET_CODE (operands[1]) != MEM
8812       || GET_CODE (operands[0]) != REG
8813       || REGNO (operands[0]) >= 32)
8814     FAIL;
8815
8816   count = INTVAL (operands[2]);
8817   regno = REGNO (operands[0]);
8818
8819   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
8820   op1 = replace_equiv_address (operands[1],
8821                                force_reg (SImode, XEXP (operands[1], 0)));
8822
8823   for (i = 0; i < count; i++)
8824     XVECEXP (operands[3], 0, i)
8825       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
8826                      adjust_address_nv (op1, SImode, i * 4));
8827 }")
8828
8829 (define_insn "*ldmsi8"
8830   [(match_parallel 0 "load_multiple_operation"
8831     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8832           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8833      (set (match_operand:SI 3 "gpc_reg_operand" "")
8834           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8835      (set (match_operand:SI 4 "gpc_reg_operand" "")
8836           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8837      (set (match_operand:SI 5 "gpc_reg_operand" "")
8838           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8839      (set (match_operand:SI 6 "gpc_reg_operand" "")
8840           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8841      (set (match_operand:SI 7 "gpc_reg_operand" "")
8842           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8843      (set (match_operand:SI 8 "gpc_reg_operand" "")
8844           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
8845      (set (match_operand:SI 9 "gpc_reg_operand" "")
8846           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
8847   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
8848   "*
8849 { return rs6000_output_load_multiple (operands); }"
8850   [(set_attr "type" "load_ux")
8851    (set_attr "length" "32")])
8852
8853 (define_insn "*ldmsi7"
8854   [(match_parallel 0 "load_multiple_operation"
8855     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8856           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8857      (set (match_operand:SI 3 "gpc_reg_operand" "")
8858           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8859      (set (match_operand:SI 4 "gpc_reg_operand" "")
8860           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8861      (set (match_operand:SI 5 "gpc_reg_operand" "")
8862           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8863      (set (match_operand:SI 6 "gpc_reg_operand" "")
8864           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8865      (set (match_operand:SI 7 "gpc_reg_operand" "")
8866           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8867      (set (match_operand:SI 8 "gpc_reg_operand" "")
8868           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
8869   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
8870   "*
8871 { return rs6000_output_load_multiple (operands); }"
8872   [(set_attr "type" "load_ux")
8873    (set_attr "length" "32")])
8874
8875 (define_insn "*ldmsi6"
8876   [(match_parallel 0 "load_multiple_operation"
8877     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8878           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8879      (set (match_operand:SI 3 "gpc_reg_operand" "")
8880           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8881      (set (match_operand:SI 4 "gpc_reg_operand" "")
8882           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8883      (set (match_operand:SI 5 "gpc_reg_operand" "")
8884           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8885      (set (match_operand:SI 6 "gpc_reg_operand" "")
8886           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8887      (set (match_operand:SI 7 "gpc_reg_operand" "")
8888           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
8889   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
8890   "*
8891 { return rs6000_output_load_multiple (operands); }"
8892   [(set_attr "type" "load_ux")
8893    (set_attr "length" "32")])
8894
8895 (define_insn "*ldmsi5"
8896   [(match_parallel 0 "load_multiple_operation"
8897     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8898           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8899      (set (match_operand:SI 3 "gpc_reg_operand" "")
8900           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8901      (set (match_operand:SI 4 "gpc_reg_operand" "")
8902           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8903      (set (match_operand:SI 5 "gpc_reg_operand" "")
8904           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8905      (set (match_operand:SI 6 "gpc_reg_operand" "")
8906           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
8907   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
8908   "*
8909 { return rs6000_output_load_multiple (operands); }"
8910   [(set_attr "type" "load_ux")
8911    (set_attr "length" "32")])
8912
8913 (define_insn "*ldmsi4"
8914   [(match_parallel 0 "load_multiple_operation"
8915     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8916           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8917      (set (match_operand:SI 3 "gpc_reg_operand" "")
8918           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8919      (set (match_operand:SI 4 "gpc_reg_operand" "")
8920           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8921      (set (match_operand:SI 5 "gpc_reg_operand" "")
8922           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
8923   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
8924   "*
8925 { return rs6000_output_load_multiple (operands); }"
8926   [(set_attr "type" "load_ux")
8927    (set_attr "length" "32")])
8928
8929 (define_insn "*ldmsi3"
8930   [(match_parallel 0 "load_multiple_operation"
8931     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8932           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8933      (set (match_operand:SI 3 "gpc_reg_operand" "")
8934           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8935      (set (match_operand:SI 4 "gpc_reg_operand" "")
8936           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
8937   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
8938   "*
8939 { return rs6000_output_load_multiple (operands); }"
8940   [(set_attr "type" "load_ux")
8941    (set_attr "length" "32")])
8942
8943 (define_expand "store_multiple"
8944   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8945                           (match_operand:SI 1 "" ""))
8946                      (clobber (scratch:SI))
8947                      (use (match_operand:SI 2 "" ""))])]
8948   "TARGET_STRING && !TARGET_POWERPC64"
8949   "
8950 {
8951   int regno;
8952   int count;
8953   rtx to;
8954   rtx op0;
8955   int i;
8956
8957   /* Support only storing a constant number of fixed-point registers to
8958      memory and only bother with this if more than two; the machine
8959      doesn't support more than eight.  */
8960   if (GET_CODE (operands[2]) != CONST_INT
8961       || INTVAL (operands[2]) <= 2
8962       || INTVAL (operands[2]) > 8
8963       || GET_CODE (operands[0]) != MEM
8964       || GET_CODE (operands[1]) != REG
8965       || REGNO (operands[1]) >= 32)
8966     FAIL;
8967
8968   count = INTVAL (operands[2]);
8969   regno = REGNO (operands[1]);
8970
8971   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
8972   to = force_reg (SImode, XEXP (operands[0], 0));
8973   op0 = replace_equiv_address (operands[0], to);
8974
8975   XVECEXP (operands[3], 0, 0)
8976     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
8977   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
8978                                                  gen_rtx_SCRATCH (SImode));
8979
8980   for (i = 1; i < count; i++)
8981     XVECEXP (operands[3], 0, i + 1)
8982       = gen_rtx_SET (VOIDmode,
8983                      adjust_address_nv (op0, SImode, i * 4),
8984                      gen_rtx_REG (SImode, regno + i));
8985 }")
8986
8987 (define_insn "*stmsi8"
8988   [(match_parallel 0 "store_multiple_operation"
8989     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8990           (match_operand:SI 2 "gpc_reg_operand" "r"))
8991      (clobber (match_scratch:SI 3 "=X"))
8992      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8993           (match_operand:SI 4 "gpc_reg_operand" "r"))
8994      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8995           (match_operand:SI 5 "gpc_reg_operand" "r"))
8996      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8997           (match_operand:SI 6 "gpc_reg_operand" "r"))
8998      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8999           (match_operand:SI 7 "gpc_reg_operand" "r"))
9000      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9001           (match_operand:SI 8 "gpc_reg_operand" "r"))
9002      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9003           (match_operand:SI 9 "gpc_reg_operand" "r"))
9004      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
9005           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
9006   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
9007   "{stsi|stswi} %2,%1,%O0"
9008   [(set_attr "type" "store_ux")])
9009
9010 (define_insn "*stmsi7"
9011   [(match_parallel 0 "store_multiple_operation"
9012     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9013           (match_operand:SI 2 "gpc_reg_operand" "r"))
9014      (clobber (match_scratch:SI 3 "=X"))
9015      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9016           (match_operand:SI 4 "gpc_reg_operand" "r"))
9017      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9018           (match_operand:SI 5 "gpc_reg_operand" "r"))
9019      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9020           (match_operand:SI 6 "gpc_reg_operand" "r"))
9021      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9022           (match_operand:SI 7 "gpc_reg_operand" "r"))
9023      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9024           (match_operand:SI 8 "gpc_reg_operand" "r"))
9025      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9026           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
9027   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
9028   "{stsi|stswi} %2,%1,%O0"
9029   [(set_attr "type" "store_ux")])
9030
9031 (define_insn "*stmsi6"
9032   [(match_parallel 0 "store_multiple_operation"
9033     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9034           (match_operand:SI 2 "gpc_reg_operand" "r"))
9035      (clobber (match_scratch:SI 3 "=X"))
9036      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9037           (match_operand:SI 4 "gpc_reg_operand" "r"))
9038      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9039           (match_operand:SI 5 "gpc_reg_operand" "r"))
9040      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9041           (match_operand:SI 6 "gpc_reg_operand" "r"))
9042      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9043           (match_operand:SI 7 "gpc_reg_operand" "r"))
9044      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9045           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
9046   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
9047   "{stsi|stswi} %2,%1,%O0"
9048   [(set_attr "type" "store_ux")])
9049
9050 (define_insn "*stmsi5"
9051   [(match_parallel 0 "store_multiple_operation"
9052     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9053           (match_operand:SI 2 "gpc_reg_operand" "r"))
9054      (clobber (match_scratch:SI 3 "=X"))
9055      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9056           (match_operand:SI 4 "gpc_reg_operand" "r"))
9057      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9058           (match_operand:SI 5 "gpc_reg_operand" "r"))
9059      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9060           (match_operand:SI 6 "gpc_reg_operand" "r"))
9061      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9062           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
9063   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
9064   "{stsi|stswi} %2,%1,%O0"
9065   [(set_attr "type" "store_ux")])
9066
9067 (define_insn "*stmsi4"
9068   [(match_parallel 0 "store_multiple_operation"
9069     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9070           (match_operand:SI 2 "gpc_reg_operand" "r"))
9071      (clobber (match_scratch:SI 3 "=X"))
9072      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9073           (match_operand:SI 4 "gpc_reg_operand" "r"))
9074      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9075           (match_operand:SI 5 "gpc_reg_operand" "r"))
9076      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9077           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9078   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
9079   "{stsi|stswi} %2,%1,%O0"
9080   [(set_attr "type" "store_ux")])
9081
9082 (define_insn "*stmsi3"
9083   [(match_parallel 0 "store_multiple_operation"
9084     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9085           (match_operand:SI 2 "gpc_reg_operand" "r"))
9086      (clobber (match_scratch:SI 3 "=X"))
9087      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9088           (match_operand:SI 4 "gpc_reg_operand" "r"))
9089      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9090           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9091   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
9092   "{stsi|stswi} %2,%1,%O0"
9093   [(set_attr "type" "store_ux")])
9094
9095 (define_insn "*stmsi8_power"
9096   [(match_parallel 0 "store_multiple_operation"
9097     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9098           (match_operand:SI 2 "gpc_reg_operand" "r"))
9099      (clobber (match_scratch:SI 3 "=q"))
9100      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9101           (match_operand:SI 4 "gpc_reg_operand" "r"))
9102      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9103           (match_operand:SI 5 "gpc_reg_operand" "r"))
9104      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9105           (match_operand:SI 6 "gpc_reg_operand" "r"))
9106      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9107           (match_operand:SI 7 "gpc_reg_operand" "r"))
9108      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9109           (match_operand:SI 8 "gpc_reg_operand" "r"))
9110      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9111           (match_operand:SI 9 "gpc_reg_operand" "r"))
9112      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
9113           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
9114   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 9"
9115   "{stsi|stswi} %2,%1,%O0"
9116   [(set_attr "type" "store_ux")])
9117
9118 (define_insn "*stmsi7_power"
9119   [(match_parallel 0 "store_multiple_operation"
9120     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9121           (match_operand:SI 2 "gpc_reg_operand" "r"))
9122      (clobber (match_scratch:SI 3 "=q"))
9123      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9124           (match_operand:SI 4 "gpc_reg_operand" "r"))
9125      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9126           (match_operand:SI 5 "gpc_reg_operand" "r"))
9127      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9128           (match_operand:SI 6 "gpc_reg_operand" "r"))
9129      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9130           (match_operand:SI 7 "gpc_reg_operand" "r"))
9131      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9132           (match_operand:SI 8 "gpc_reg_operand" "r"))
9133      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9134           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
9135   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 8"
9136   "{stsi|stswi} %2,%1,%O0"
9137   [(set_attr "type" "store_ux")])
9138
9139 (define_insn "*stmsi6_power"
9140   [(match_parallel 0 "store_multiple_operation"
9141     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9142           (match_operand:SI 2 "gpc_reg_operand" "r"))
9143      (clobber (match_scratch:SI 3 "=q"))
9144      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9145           (match_operand:SI 4 "gpc_reg_operand" "r"))
9146      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9147           (match_operand:SI 5 "gpc_reg_operand" "r"))
9148      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9149           (match_operand:SI 6 "gpc_reg_operand" "r"))
9150      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9151           (match_operand:SI 7 "gpc_reg_operand" "r"))
9152      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9153           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
9154   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 7"
9155   "{stsi|stswi} %2,%1,%O0"
9156   [(set_attr "type" "store_ux")])
9157
9158 (define_insn "*stmsi5_power"
9159   [(match_parallel 0 "store_multiple_operation"
9160     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9161           (match_operand:SI 2 "gpc_reg_operand" "r"))
9162      (clobber (match_scratch:SI 3 "=q"))
9163      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9164           (match_operand:SI 4 "gpc_reg_operand" "r"))
9165      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9166           (match_operand:SI 5 "gpc_reg_operand" "r"))
9167      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9168           (match_operand:SI 6 "gpc_reg_operand" "r"))
9169      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9170           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
9171   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 6"
9172   "{stsi|stswi} %2,%1,%O0"
9173   [(set_attr "type" "store_ux")])
9174
9175 (define_insn "*stmsi4_power"
9176   [(match_parallel 0 "store_multiple_operation"
9177     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9178           (match_operand:SI 2 "gpc_reg_operand" "r"))
9179      (clobber (match_scratch:SI 3 "=q"))
9180      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9181           (match_operand:SI 4 "gpc_reg_operand" "r"))
9182      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9183           (match_operand:SI 5 "gpc_reg_operand" "r"))
9184      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9185           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9186   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 5"
9187   "{stsi|stswi} %2,%1,%O0"
9188   [(set_attr "type" "store_ux")])
9189
9190 (define_insn "*stmsi3_power"
9191   [(match_parallel 0 "store_multiple_operation"
9192     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9193           (match_operand:SI 2 "gpc_reg_operand" "r"))
9194      (clobber (match_scratch:SI 3 "=q"))
9195      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9196           (match_operand:SI 4 "gpc_reg_operand" "r"))
9197      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9198           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9199   "TARGET_STRING && TARGET_POWER && XVECLEN (operands[0], 0) == 4"
9200   "{stsi|stswi} %2,%1,%O0"
9201   [(set_attr "type" "store_ux")])
9202 \f
9203 (define_expand "setmemsi"
9204   [(parallel [(set (match_operand:BLK 0 "" "")
9205                    (match_operand 2 "const_int_operand" ""))
9206               (use (match_operand:SI 1 "" ""))
9207               (use (match_operand:SI 3 "" ""))])]
9208   ""
9209   "
9210 {
9211   /* If value to set is not zero, use the library routine.  */
9212   if (operands[2] != const0_rtx)
9213     FAIL;
9214
9215   if (expand_block_clear (operands))
9216     DONE;
9217   else
9218     FAIL;
9219 }")
9220
9221 ;; String/block move insn.
9222 ;; Argument 0 is the destination
9223 ;; Argument 1 is the source
9224 ;; Argument 2 is the length
9225 ;; Argument 3 is the alignment
9226
9227 (define_expand "movmemsi"
9228   [(parallel [(set (match_operand:BLK 0 "" "")
9229                    (match_operand:BLK 1 "" ""))
9230               (use (match_operand:SI 2 "" ""))
9231               (use (match_operand:SI 3 "" ""))])]
9232   ""
9233   "
9234 {
9235   if (expand_block_move (operands))
9236     DONE;
9237   else
9238     FAIL;
9239 }")
9240
9241 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
9242 ;; register allocator doesn't have a clue about allocating 8 word registers.
9243 ;; rD/rS = r5 is preferred, efficient form.
9244 (define_expand "movmemsi_8reg"
9245   [(parallel [(set (match_operand 0 "" "")
9246                    (match_operand 1 "" ""))
9247               (use (match_operand 2 "" ""))
9248               (use (match_operand 3 "" ""))
9249               (clobber (reg:SI  5))
9250               (clobber (reg:SI  6))
9251               (clobber (reg:SI  7))
9252               (clobber (reg:SI  8))
9253               (clobber (reg:SI  9))
9254               (clobber (reg:SI 10))
9255               (clobber (reg:SI 11))
9256               (clobber (reg:SI 12))
9257               (clobber (match_scratch:SI 4 ""))])]
9258   "TARGET_STRING"
9259   "")
9260
9261 (define_insn ""
9262   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9263         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9264    (use (match_operand:SI 2 "immediate_operand" "i"))
9265    (use (match_operand:SI 3 "immediate_operand" "i"))
9266    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9267    (clobber (reg:SI  6))
9268    (clobber (reg:SI  7))
9269    (clobber (reg:SI  8))
9270    (clobber (reg:SI  9))
9271    (clobber (reg:SI 10))
9272    (clobber (reg:SI 11))
9273    (clobber (reg:SI 12))
9274    (clobber (match_scratch:SI 5 "=q"))]
9275   "TARGET_STRING && TARGET_POWER
9276    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9277        || INTVAL (operands[2]) == 0)
9278    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9279    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9280    && REGNO (operands[4]) == 5"
9281   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9282   [(set_attr "type" "store_ux")
9283    (set_attr "length" "8")])
9284
9285 (define_insn ""
9286   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9287         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9288    (use (match_operand:SI 2 "immediate_operand" "i"))
9289    (use (match_operand:SI 3 "immediate_operand" "i"))
9290    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9291    (clobber (reg:SI  6))
9292    (clobber (reg:SI  7))
9293    (clobber (reg:SI  8))
9294    (clobber (reg:SI  9))
9295    (clobber (reg:SI 10))
9296    (clobber (reg:SI 11))
9297    (clobber (reg:SI 12))
9298    (clobber (match_scratch:SI 5 "=X"))]
9299   "TARGET_STRING && ! TARGET_POWER
9300    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9301        || INTVAL (operands[2]) == 0)
9302    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9303    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9304    && REGNO (operands[4]) == 5"
9305   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9306   [(set_attr "type" "store_ux")
9307    (set_attr "length" "8")])
9308
9309 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
9310 ;; register allocator doesn't have a clue about allocating 6 word registers.
9311 ;; rD/rS = r5 is preferred, efficient form.
9312 (define_expand "movmemsi_6reg"
9313   [(parallel [(set (match_operand 0 "" "")
9314                    (match_operand 1 "" ""))
9315               (use (match_operand 2 "" ""))
9316               (use (match_operand 3 "" ""))
9317               (clobber (reg:SI  5))
9318               (clobber (reg:SI  6))
9319               (clobber (reg:SI  7))
9320               (clobber (reg:SI  8))
9321               (clobber (reg:SI  9))
9322               (clobber (reg:SI 10))
9323               (clobber (match_scratch:SI 4 ""))])]
9324   "TARGET_STRING"
9325   "")
9326
9327 (define_insn ""
9328   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9329         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9330    (use (match_operand:SI 2 "immediate_operand" "i"))
9331    (use (match_operand:SI 3 "immediate_operand" "i"))
9332    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9333    (clobber (reg:SI  6))
9334    (clobber (reg:SI  7))
9335    (clobber (reg:SI  8))
9336    (clobber (reg:SI  9))
9337    (clobber (reg:SI 10))
9338    (clobber (match_scratch:SI 5 "=q"))]
9339   "TARGET_STRING && TARGET_POWER
9340    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
9341    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9342    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9343    && REGNO (operands[4]) == 5"
9344   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9345   [(set_attr "type" "store_ux")
9346    (set_attr "length" "8")])
9347
9348 (define_insn ""
9349   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9350         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9351    (use (match_operand:SI 2 "immediate_operand" "i"))
9352    (use (match_operand:SI 3 "immediate_operand" "i"))
9353    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9354    (clobber (reg:SI  6))
9355    (clobber (reg:SI  7))
9356    (clobber (reg:SI  8))
9357    (clobber (reg:SI  9))
9358    (clobber (reg:SI 10))
9359    (clobber (match_scratch:SI 5 "=X"))]
9360   "TARGET_STRING && ! TARGET_POWER
9361    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9362    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9363    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9364    && REGNO (operands[4]) == 5"
9365   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9366   [(set_attr "type" "store_ux")
9367    (set_attr "length" "8")])
9368
9369 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
9370 ;; problems with TImode.
9371 ;; rD/rS = r5 is preferred, efficient form.
9372 (define_expand "movmemsi_4reg"
9373   [(parallel [(set (match_operand 0 "" "")
9374                    (match_operand 1 "" ""))
9375               (use (match_operand 2 "" ""))
9376               (use (match_operand 3 "" ""))
9377               (clobber (reg:SI 5))
9378               (clobber (reg:SI 6))
9379               (clobber (reg:SI 7))
9380               (clobber (reg:SI 8))
9381               (clobber (match_scratch:SI 4 ""))])]
9382   "TARGET_STRING"
9383   "")
9384
9385 (define_insn ""
9386   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9387         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9388    (use (match_operand:SI 2 "immediate_operand" "i"))
9389    (use (match_operand:SI 3 "immediate_operand" "i"))
9390    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9391    (clobber (reg:SI 6))
9392    (clobber (reg:SI 7))
9393    (clobber (reg:SI 8))
9394    (clobber (match_scratch:SI 5 "=q"))]
9395   "TARGET_STRING && TARGET_POWER
9396    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9397    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9398    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9399    && REGNO (operands[4]) == 5"
9400   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9401   [(set_attr "type" "store_ux")
9402    (set_attr "length" "8")])
9403
9404 (define_insn ""
9405   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9406         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9407    (use (match_operand:SI 2 "immediate_operand" "i"))
9408    (use (match_operand:SI 3 "immediate_operand" "i"))
9409    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9410    (clobber (reg:SI 6))
9411    (clobber (reg:SI 7))
9412    (clobber (reg:SI 8))
9413    (clobber (match_scratch:SI 5 "=X"))]
9414   "TARGET_STRING && ! TARGET_POWER
9415    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9416    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9417    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9418    && REGNO (operands[4]) == 5"
9419   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9420   [(set_attr "type" "store_ux")
9421    (set_attr "length" "8")])
9422
9423 ;; Move up to 8 bytes at a time.
9424 (define_expand "movmemsi_2reg"
9425   [(parallel [(set (match_operand 0 "" "")
9426                    (match_operand 1 "" ""))
9427               (use (match_operand 2 "" ""))
9428               (use (match_operand 3 "" ""))
9429               (clobber (match_scratch:DI 4 ""))
9430               (clobber (match_scratch:SI 5 ""))])]
9431   "TARGET_STRING && ! TARGET_POWERPC64"
9432   "")
9433
9434 (define_insn ""
9435   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9436         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9437    (use (match_operand:SI 2 "immediate_operand" "i"))
9438    (use (match_operand:SI 3 "immediate_operand" "i"))
9439    (clobber (match_scratch:DI 4 "=&r"))
9440    (clobber (match_scratch:SI 5 "=q"))]
9441   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
9442    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9443   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9444   [(set_attr "type" "store_ux")
9445    (set_attr "length" "8")])
9446
9447 (define_insn ""
9448   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9449         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9450    (use (match_operand:SI 2 "immediate_operand" "i"))
9451    (use (match_operand:SI 3 "immediate_operand" "i"))
9452    (clobber (match_scratch:DI 4 "=&r"))
9453    (clobber (match_scratch:SI 5 "=X"))]
9454   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
9455    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9456   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9457   [(set_attr "type" "store_ux")
9458    (set_attr "length" "8")])
9459
9460 ;; Move up to 4 bytes at a time.
9461 (define_expand "movmemsi_1reg"
9462   [(parallel [(set (match_operand 0 "" "")
9463                    (match_operand 1 "" ""))
9464               (use (match_operand 2 "" ""))
9465               (use (match_operand 3 "" ""))
9466               (clobber (match_scratch:SI 4 ""))
9467               (clobber (match_scratch:SI 5 ""))])]
9468   "TARGET_STRING"
9469   "")
9470
9471 (define_insn ""
9472   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9473         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9474    (use (match_operand:SI 2 "immediate_operand" "i"))
9475    (use (match_operand:SI 3 "immediate_operand" "i"))
9476    (clobber (match_scratch:SI 4 "=&r"))
9477    (clobber (match_scratch:SI 5 "=q"))]
9478   "TARGET_STRING && TARGET_POWER
9479    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9480   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9481   [(set_attr "type" "store_ux")
9482    (set_attr "length" "8")])
9483
9484 (define_insn ""
9485   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9486         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9487    (use (match_operand:SI 2 "immediate_operand" "i"))
9488    (use (match_operand:SI 3 "immediate_operand" "i"))
9489    (clobber (match_scratch:SI 4 "=&r"))
9490    (clobber (match_scratch:SI 5 "=X"))]
9491   "TARGET_STRING && ! TARGET_POWER
9492    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9493   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9494   [(set_attr "type" "store_ux")
9495    (set_attr "length" "8")])
9496 \f
9497 ;; Define insns that do load or store with update.  Some of these we can
9498 ;; get by using pre-decrement or pre-increment, but the hardware can also
9499 ;; do cases where the increment is not the size of the object.
9500 ;;
9501 ;; In all these cases, we use operands 0 and 1 for the register being
9502 ;; incremented because those are the operands that local-alloc will
9503 ;; tie and these are the pair most likely to be tieable (and the ones
9504 ;; that will benefit the most).
9505
9506 (define_insn "*movdi_update1"
9507   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9508         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9509                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
9510    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9511         (plus:DI (match_dup 1) (match_dup 2)))]
9512   "TARGET_POWERPC64 && TARGET_UPDATE"
9513   "@
9514    ldux %3,%0,%2
9515    ldu %3,%2(%0)"
9516   [(set_attr "type" "load_ux,load_u")])
9517
9518 (define_insn "movdi_<mode>_update"
9519   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
9520                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
9521         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9522    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
9523         (plus:P (match_dup 1) (match_dup 2)))]
9524   "TARGET_POWERPC64 && TARGET_UPDATE"
9525   "@
9526    stdux %3,%0,%2
9527    stdu %3,%2(%0)"
9528   [(set_attr "type" "store_ux,store_u")])
9529
9530 (define_insn "*movsi_update1"
9531   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9532         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9533                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9534    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9535         (plus:SI (match_dup 1) (match_dup 2)))]
9536   "TARGET_UPDATE"
9537   "@
9538    {lux|lwzux} %3,%0,%2
9539    {lu|lwzu} %3,%2(%0)"
9540   [(set_attr "type" "load_ux,load_u")])
9541
9542 (define_insn "*movsi_update2"
9543   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9544         (sign_extend:DI
9545          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9546                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9547    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9548         (plus:DI (match_dup 1) (match_dup 2)))]
9549   "TARGET_POWERPC64"
9550   "lwaux %3,%0,%2"
9551   [(set_attr "type" "load_ext_ux")])
9552
9553 (define_insn "movsi_update"
9554   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9555                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9556         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9557    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9558         (plus:SI (match_dup 1) (match_dup 2)))]
9559   "TARGET_UPDATE"
9560   "@
9561    {stux|stwux} %3,%0,%2
9562    {stu|stwu} %3,%2(%0)"
9563   [(set_attr "type" "store_ux,store_u")])
9564
9565 (define_insn "*movhi_update1"
9566   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9567         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9568                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9569    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9570         (plus:SI (match_dup 1) (match_dup 2)))]
9571   "TARGET_UPDATE"
9572   "@
9573    lhzux %3,%0,%2
9574    lhzu %3,%2(%0)"
9575   [(set_attr "type" "load_ux,load_u")])
9576
9577 (define_insn "*movhi_update2"
9578   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9579         (zero_extend:SI
9580          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9581                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9582    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9583         (plus:SI (match_dup 1) (match_dup 2)))]
9584   "TARGET_UPDATE"
9585   "@
9586    lhzux %3,%0,%2
9587    lhzu %3,%2(%0)"
9588   [(set_attr "type" "load_ux,load_u")])
9589
9590 (define_insn "*movhi_update3"
9591   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9592         (sign_extend:SI
9593          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9594                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9595    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9596         (plus:SI (match_dup 1) (match_dup 2)))]
9597   "TARGET_UPDATE"
9598   "@
9599    lhaux %3,%0,%2
9600    lhau %3,%2(%0)"
9601   [(set_attr "type" "load_ext_ux,load_ext_u")])
9602
9603 (define_insn "*movhi_update4"
9604   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9605                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9606         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
9607    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9608         (plus:SI (match_dup 1) (match_dup 2)))]
9609   "TARGET_UPDATE"
9610   "@
9611    sthux %3,%0,%2
9612    sthu %3,%2(%0)"
9613   [(set_attr "type" "store_ux,store_u")])
9614
9615 (define_insn "*movqi_update1"
9616   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
9617         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9618                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9619    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9620         (plus:SI (match_dup 1) (match_dup 2)))]
9621   "TARGET_UPDATE"
9622   "@
9623    lbzux %3,%0,%2
9624    lbzu %3,%2(%0)"
9625   [(set_attr "type" "load_ux,load_u")])
9626
9627 (define_insn "*movqi_update2"
9628   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9629         (zero_extend:SI
9630          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9631                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9632    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9633         (plus:SI (match_dup 1) (match_dup 2)))]
9634   "TARGET_UPDATE"
9635   "@
9636    lbzux %3,%0,%2
9637    lbzu %3,%2(%0)"
9638   [(set_attr "type" "load_ux,load_u")])
9639
9640 (define_insn "*movqi_update3"
9641   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9642                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9643         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
9644    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9645         (plus:SI (match_dup 1) (match_dup 2)))]
9646   "TARGET_UPDATE"
9647   "@
9648    stbux %3,%0,%2
9649    stbu %3,%2(%0)"
9650   [(set_attr "type" "store_ux,store_u")])
9651
9652 (define_insn "*movsf_update1"
9653   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
9654         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9655                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9656    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9657         (plus:SI (match_dup 1) (match_dup 2)))]
9658   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9659   "@
9660    lfsux %3,%0,%2
9661    lfsu %3,%2(%0)"
9662   [(set_attr "type" "fpload_ux,fpload_u")])
9663
9664 (define_insn "*movsf_update2"
9665   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9666                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9667         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
9668    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9669         (plus:SI (match_dup 1) (match_dup 2)))]
9670   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9671   "@
9672    stfsux %3,%0,%2
9673    stfsu %3,%2(%0)"
9674   [(set_attr "type" "fpstore_ux,fpstore_u")])
9675
9676 (define_insn "*movsf_update3"
9677   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
9678         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9679                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9680    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9681         (plus:SI (match_dup 1) (match_dup 2)))]
9682   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9683   "@
9684    {lux|lwzux} %3,%0,%2
9685    {lu|lwzu} %3,%2(%0)"
9686   [(set_attr "type" "load_ux,load_u")])
9687
9688 (define_insn "*movsf_update4"
9689   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9690                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9691         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
9692    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9693         (plus:SI (match_dup 1) (match_dup 2)))]
9694   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9695   "@
9696    {stux|stwux} %3,%0,%2
9697    {stu|stwu} %3,%2(%0)"
9698   [(set_attr "type" "store_ux,store_u")])
9699
9700 (define_insn "*movdf_update1"
9701   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
9702         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9703                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9704    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9705         (plus:SI (match_dup 1) (match_dup 2)))]
9706   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9707   "@
9708    lfdux %3,%0,%2
9709    lfdu %3,%2(%0)"
9710   [(set_attr "type" "fpload_ux,fpload_u")])
9711
9712 (define_insn "*movdf_update2"
9713   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9714                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9715         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
9716    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9717         (plus:SI (match_dup 1) (match_dup 2)))]
9718   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9719   "@
9720    stfdux %3,%0,%2
9721    stfdu %3,%2(%0)"
9722   [(set_attr "type" "fpstore_ux,fpstore_u")])
9723
9724 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
9725
9726 (define_insn "*lfq_power2"
9727   [(set (match_operand:V2DF 0 "gpc_reg_operand" "=f")
9728         (match_operand:V2DF 1 "memory_operand" ""))]
9729   "TARGET_POWER2
9730    && TARGET_HARD_FLOAT && TARGET_FPRS"
9731   "lfq%U1%X1 %0,%1")
9732
9733 (define_peephole2
9734   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9735         (match_operand:DF 1 "memory_operand" ""))
9736    (set (match_operand:DF 2 "gpc_reg_operand" "")
9737         (match_operand:DF 3 "memory_operand" ""))]
9738   "TARGET_POWER2
9739    && TARGET_HARD_FLOAT && TARGET_FPRS
9740    && registers_ok_for_quad_peep (operands[0], operands[2])
9741    && mems_ok_for_quad_peep (operands[1], operands[3])"
9742   [(set (match_dup 0)
9743         (match_dup 1))]
9744   "operands[1] = widen_memory_access (operands[1], V2DFmode, 0);
9745    operands[0] = gen_rtx_REG (V2DFmode, REGNO (operands[0]));")
9746
9747 (define_insn "*stfq_power2"
9748   [(set (match_operand:V2DF 0 "memory_operand" "")
9749         (match_operand:V2DF 1 "gpc_reg_operand" "f"))]
9750   "TARGET_POWER2
9751    && TARGET_HARD_FLOAT && TARGET_FPRS"
9752   "stfq%U0%X0 %1,%0")
9753
9754
9755 (define_peephole2
9756   [(set (match_operand:DF 0 "memory_operand" "")
9757         (match_operand:DF 1 "gpc_reg_operand" ""))
9758    (set (match_operand:DF 2 "memory_operand" "")
9759         (match_operand:DF 3 "gpc_reg_operand" ""))]
9760   "TARGET_POWER2
9761    && TARGET_HARD_FLOAT && TARGET_FPRS
9762    && registers_ok_for_quad_peep (operands[1], operands[3])
9763    && mems_ok_for_quad_peep (operands[0], operands[2])"
9764   [(set (match_dup 0)
9765         (match_dup 1))]
9766   "operands[0] = widen_memory_access (operands[0], V2DFmode, 0);
9767    operands[1] = gen_rtx_REG (V2DFmode, REGNO (operands[1]));")
9768
9769 ;; After inserting conditional returns we can sometimes have
9770 ;; unnecessary register moves.  Unfortunately we cannot have a
9771 ;; modeless peephole here, because some single SImode sets have early
9772 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
9773 ;; sequences, using get_attr_length here will smash the operands
9774 ;; array.  Neither is there an early_cobbler_p predicate.
9775 ;; Disallow subregs for E500 so we don't munge frob_di_df_2.
9776 (define_peephole2
9777   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9778         (match_operand:DF 1 "any_operand" ""))
9779    (set (match_operand:DF 2 "gpc_reg_operand" "")
9780         (match_dup 0))]
9781   "!(TARGET_E500_DOUBLE && GET_CODE (operands[2]) == SUBREG)
9782    && peep2_reg_dead_p (2, operands[0])"
9783   [(set (match_dup 2) (match_dup 1))])
9784
9785 (define_peephole2
9786   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9787         (match_operand:SF 1 "any_operand" ""))
9788    (set (match_operand:SF 2 "gpc_reg_operand" "")
9789         (match_dup 0))]
9790   "peep2_reg_dead_p (2, operands[0])"
9791   [(set (match_dup 2) (match_dup 1))])
9792
9793 \f
9794 ;; TLS support.
9795
9796 ;; "b" output constraint here and on tls_ld to support tls linker optimization.
9797 (define_insn "tls_gd_32"
9798   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9799         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9800                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9801                    UNSPEC_TLSGD))]
9802   "HAVE_AS_TLS && !TARGET_64BIT"
9803   "addi %0,%1,%2@got@tlsgd")
9804
9805 (define_insn "tls_gd_64"
9806   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9807         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9808                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9809                    UNSPEC_TLSGD))]
9810   "HAVE_AS_TLS && TARGET_64BIT"
9811   "addi %0,%1,%2@got@tlsgd")
9812
9813 (define_insn "tls_ld_32"
9814   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9815         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")]
9816                    UNSPEC_TLSLD))]
9817   "HAVE_AS_TLS && !TARGET_64BIT"
9818   "addi %0,%1,%&@got@tlsld")
9819
9820 (define_insn "tls_ld_64"
9821   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9822         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")]
9823                    UNSPEC_TLSLD))]
9824   "HAVE_AS_TLS && TARGET_64BIT"
9825   "addi %0,%1,%&@got@tlsld")
9826
9827 (define_insn "tls_dtprel_32"
9828   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9829         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9830                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9831                    UNSPEC_TLSDTPREL))]
9832   "HAVE_AS_TLS && !TARGET_64BIT"
9833   "addi %0,%1,%2@dtprel")
9834
9835 (define_insn "tls_dtprel_64"
9836   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9837         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9838                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9839                    UNSPEC_TLSDTPREL))]
9840   "HAVE_AS_TLS && TARGET_64BIT"
9841   "addi %0,%1,%2@dtprel")
9842
9843 (define_insn "tls_dtprel_ha_32"
9844   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9845         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9846                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9847                    UNSPEC_TLSDTPRELHA))]
9848   "HAVE_AS_TLS && !TARGET_64BIT"
9849   "addis %0,%1,%2@dtprel@ha")
9850
9851 (define_insn "tls_dtprel_ha_64"
9852   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9853         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9854                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9855                    UNSPEC_TLSDTPRELHA))]
9856   "HAVE_AS_TLS && TARGET_64BIT"
9857   "addis %0,%1,%2@dtprel@ha")
9858
9859 (define_insn "tls_dtprel_lo_32"
9860   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9861         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9862                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9863                    UNSPEC_TLSDTPRELLO))]
9864   "HAVE_AS_TLS && !TARGET_64BIT"
9865   "addi %0,%1,%2@dtprel@l")
9866
9867 (define_insn "tls_dtprel_lo_64"
9868   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9869         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9870                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9871                    UNSPEC_TLSDTPRELLO))]
9872   "HAVE_AS_TLS && TARGET_64BIT"
9873   "addi %0,%1,%2@dtprel@l")
9874
9875 (define_insn "tls_got_dtprel_32"
9876   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9877         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9878                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9879                    UNSPEC_TLSGOTDTPREL))]
9880   "HAVE_AS_TLS && !TARGET_64BIT"
9881   "lwz %0,%2@got@dtprel(%1)")
9882
9883 (define_insn "tls_got_dtprel_64"
9884   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9885         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9886                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9887                    UNSPEC_TLSGOTDTPREL))]
9888   "HAVE_AS_TLS && TARGET_64BIT"
9889   "ld %0,%2@got@dtprel(%1)")
9890
9891 (define_insn "tls_tprel_32"
9892   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9893         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9894                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9895                    UNSPEC_TLSTPREL))]
9896   "HAVE_AS_TLS && !TARGET_64BIT"
9897   "addi %0,%1,%2@tprel")
9898
9899 (define_insn "tls_tprel_64"
9900   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9901         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9902                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9903                    UNSPEC_TLSTPREL))]
9904   "HAVE_AS_TLS && TARGET_64BIT"
9905   "addi %0,%1,%2@tprel")
9906
9907 (define_insn "tls_tprel_ha_32"
9908   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9909         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9910                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9911                    UNSPEC_TLSTPRELHA))]
9912   "HAVE_AS_TLS && !TARGET_64BIT"
9913   "addis %0,%1,%2@tprel@ha")
9914
9915 (define_insn "tls_tprel_ha_64"
9916   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9917         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9918                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9919                    UNSPEC_TLSTPRELHA))]
9920   "HAVE_AS_TLS && TARGET_64BIT"
9921   "addis %0,%1,%2@tprel@ha")
9922
9923 (define_insn "tls_tprel_lo_32"
9924   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9925         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9926                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9927                    UNSPEC_TLSTPRELLO))]
9928   "HAVE_AS_TLS && !TARGET_64BIT"
9929   "addi %0,%1,%2@tprel@l")
9930
9931 (define_insn "tls_tprel_lo_64"
9932   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9933         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9934                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9935                    UNSPEC_TLSTPRELLO))]
9936   "HAVE_AS_TLS && TARGET_64BIT"
9937   "addi %0,%1,%2@tprel@l")
9938
9939 ;; "b" output constraint here and on tls_tls input to support linker tls
9940 ;; optimization.  The linker may edit the instructions emitted by a
9941 ;; tls_got_tprel/tls_tls pair to addis,addi.
9942 (define_insn "tls_got_tprel_32"
9943   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9944         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9945                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9946                    UNSPEC_TLSGOTTPREL))]
9947   "HAVE_AS_TLS && !TARGET_64BIT"
9948   "lwz %0,%2@got@tprel(%1)")
9949
9950 (define_insn "tls_got_tprel_64"
9951   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9952         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9953                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9954                    UNSPEC_TLSGOTTPREL))]
9955   "HAVE_AS_TLS && TARGET_64BIT"
9956   "ld %0,%2@got@tprel(%1)")
9957
9958 (define_insn "tls_tls_32"
9959   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9960         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9961                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9962                    UNSPEC_TLSTLS))]
9963   "HAVE_AS_TLS && !TARGET_64BIT"
9964   "add %0,%1,%2@tls")
9965
9966 (define_insn "tls_tls_64"
9967   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9968         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9969                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9970                    UNSPEC_TLSTLS))]
9971   "HAVE_AS_TLS && TARGET_64BIT"
9972   "add %0,%1,%2@tls")
9973 \f
9974 ;; Next come insns related to the calling sequence.
9975 ;;
9976 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
9977 ;; We move the back-chain and decrement the stack pointer.
9978
9979 (define_expand "allocate_stack"
9980   [(set (match_operand 0 "gpc_reg_operand" "=r")
9981         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
9982    (set (reg 1)
9983         (minus (reg 1) (match_dup 1)))]
9984   ""
9985   "
9986 { rtx chain = gen_reg_rtx (Pmode);
9987   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
9988   rtx neg_op0;
9989
9990   emit_move_insn (chain, stack_bot);
9991
9992   /* Check stack bounds if necessary.  */
9993   if (current_function_limit_stack)
9994     {
9995       rtx available;
9996       available = expand_binop (Pmode, sub_optab,
9997                                 stack_pointer_rtx, stack_limit_rtx,
9998                                 NULL_RTX, 1, OPTAB_WIDEN);
9999       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
10000     }
10001
10002   if (GET_CODE (operands[1]) != CONST_INT
10003       || INTVAL (operands[1]) < -32767
10004       || INTVAL (operands[1]) > 32768)
10005     {
10006       neg_op0 = gen_reg_rtx (Pmode);
10007       if (TARGET_32BIT)
10008         emit_insn (gen_negsi2 (neg_op0, operands[1]));
10009       else
10010         emit_insn (gen_negdi2 (neg_op0, operands[1]));
10011     }
10012   else
10013     neg_op0 = GEN_INT (- INTVAL (operands[1]));
10014
10015   if (TARGET_UPDATE)
10016     emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update : gen_movdi_di_update))
10017                 (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
10018
10019   else
10020     {
10021       emit_insn ((* ((TARGET_32BIT) ? gen_addsi3 : gen_adddi3))
10022                  (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
10023       emit_move_insn (gen_rtx_MEM (Pmode, stack_pointer_rtx), chain);
10024     }
10025
10026   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
10027   DONE;
10028 }")
10029
10030 ;; These patterns say how to save and restore the stack pointer.  We need not
10031 ;; save the stack pointer at function level since we are careful to
10032 ;; preserve the backchain.  At block level, we have to restore the backchain
10033 ;; when we restore the stack pointer.
10034 ;;
10035 ;; For nonlocal gotos, we must save both the stack pointer and its
10036 ;; backchain and restore both.  Note that in the nonlocal case, the
10037 ;; save area is a memory location.
10038
10039 (define_expand "save_stack_function"
10040   [(match_operand 0 "any_operand" "")
10041    (match_operand 1 "any_operand" "")]
10042   ""
10043   "DONE;")
10044
10045 (define_expand "restore_stack_function"
10046   [(match_operand 0 "any_operand" "")
10047    (match_operand 1 "any_operand" "")]
10048   ""
10049   "DONE;")
10050
10051 ;; Adjust stack pointer (op0) to a new value (op1).
10052 ;; First copy old stack backchain to new location, and ensure that the
10053 ;; scheduler won't reorder the sp assignment before the backchain write.
10054 (define_expand "restore_stack_block"
10055   [(set (match_dup 2) (match_dup 3))
10056    (set (match_dup 4) (match_dup 2))
10057    (set (match_dup 5) (unspec:BLK [(match_dup 5)] UNSPEC_TIE))
10058    (set (match_operand 0 "register_operand" "")
10059         (match_operand 1 "register_operand" ""))]
10060   ""
10061   "
10062 {
10063   operands[2] = gen_reg_rtx (Pmode);
10064   operands[3] = gen_frame_mem (Pmode, operands[0]);
10065   operands[4] = gen_frame_mem (Pmode, operands[1]);
10066   operands[5] = gen_frame_mem (BLKmode, operands[0]);
10067 }")
10068
10069 (define_expand "save_stack_nonlocal"
10070   [(set (match_dup 3) (match_dup 4))
10071    (set (match_operand 0 "memory_operand" "") (match_dup 3))
10072    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
10073   ""
10074   "
10075 {
10076   int units_per_word = (TARGET_32BIT) ? 4 : 8;
10077
10078   /* Copy the backchain to the first word, sp to the second.  */
10079   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
10080   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
10081   operands[3] = gen_reg_rtx (Pmode);
10082   operands[4] = gen_frame_mem (Pmode, operands[1]);
10083 }")
10084
10085 (define_expand "restore_stack_nonlocal"
10086   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
10087    (set (match_dup 3) (match_dup 4))
10088    (set (match_dup 5) (match_dup 2))
10089    (set (match_dup 6) (unspec:BLK [(match_dup 6)] UNSPEC_TIE))
10090    (set (match_operand 0 "register_operand" "") (match_dup 3))]
10091   ""
10092   "
10093 {
10094   int units_per_word = (TARGET_32BIT) ? 4 : 8;
10095
10096   /* Restore the backchain from the first word, sp from the second.  */
10097   operands[2] = gen_reg_rtx (Pmode);
10098   operands[3] = gen_reg_rtx (Pmode);
10099   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
10100   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
10101   operands[5] = gen_frame_mem (Pmode, operands[3]);
10102   operands[6] = gen_frame_mem (BLKmode, operands[0]);
10103 }")
10104 \f
10105 ;; TOC register handling.
10106
10107 ;; Code to initialize the TOC register...
10108
10109 (define_insn "load_toc_aix_si"
10110   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10111                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
10112               (use (reg:SI 2))])]
10113   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
10114   "*
10115 {
10116   char buf[30];
10117   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10118   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10119   operands[2] = gen_rtx_REG (Pmode, 2);
10120   return \"{l|lwz} %0,%1(%2)\";
10121 }"
10122   [(set_attr "type" "load")])
10123
10124 (define_insn "load_toc_aix_di"
10125   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10126                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
10127               (use (reg:DI 2))])]
10128   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
10129   "*
10130 {
10131   char buf[30];
10132 #ifdef TARGET_RELOCATABLE
10133   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
10134                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
10135 #else
10136   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10137 #endif
10138   if (TARGET_ELF)
10139     strcat (buf, \"@toc\");
10140   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10141   operands[2] = gen_rtx_REG (Pmode, 2);
10142   return \"ld %0,%1(%2)\";
10143 }"
10144   [(set_attr "type" "load")])
10145
10146 (define_insn "load_toc_v4_pic_si"
10147   [(set (match_operand:SI 0 "register_operand" "=l")
10148         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
10149   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
10150   "bl _GLOBAL_OFFSET_TABLE_@local-4"
10151   [(set_attr "type" "branch")
10152    (set_attr "length" "4")])
10153
10154 (define_insn "load_toc_v4_PIC_1"
10155   [(set (match_operand:SI 0 "register_operand" "=l")
10156         (match_operand:SI 1 "immediate_operand" "s"))
10157    (use (unspec [(match_dup 1)] UNSPEC_TOC))]
10158   "TARGET_ELF && DEFAULT_ABI != ABI_AIX
10159    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
10160   "bcl 20,31,%1\\n%1:"
10161   [(set_attr "type" "branch")
10162    (set_attr "length" "4")])
10163
10164 (define_insn "load_toc_v4_PIC_1b"
10165   [(set (match_operand:SI 0 "register_operand" "=l")
10166         (unspec:SI [(match_operand:SI 1 "immediate_operand" "s")]
10167                 UNSPEC_TOCPTR))]
10168   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10169   "bcl 20,31,$+8\\n\\t.long %1-$"
10170   [(set_attr "type" "branch")
10171    (set_attr "length" "8")])
10172
10173 (define_insn "load_toc_v4_PIC_2"
10174   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10175         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10176                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
10177                              (match_operand:SI 3 "immediate_operand" "s")))))]
10178   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10179   "{l|lwz} %0,%2-%3(%1)"
10180   [(set_attr "type" "load")])
10181
10182 (define_insn "load_toc_v4_PIC_3b"
10183   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
10184         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
10185                  (high:SI
10186                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
10187                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
10188   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
10189   "{cau|addis} %0,%1,%2-%3@ha")
10190
10191 (define_insn "load_toc_v4_PIC_3c"
10192   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10193         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10194                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
10195                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
10196   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
10197   "{cal|addi} %0,%1,%2-%3@l")
10198
10199 ;; If the TOC is shared over a translation unit, as happens with all
10200 ;; the kinds of PIC that we support, we need to restore the TOC
10201 ;; pointer only when jumping over units of translation.
10202 ;; On Darwin, we need to reload the picbase.
10203
10204 (define_expand "builtin_setjmp_receiver"
10205   [(use (label_ref (match_operand 0 "" "")))]
10206   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10207    || (TARGET_TOC && TARGET_MINIMAL_TOC)
10208    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
10209   "
10210 {
10211 #if TARGET_MACHO
10212   if (DEFAULT_ABI == ABI_DARWIN)
10213     {
10214       const char *picbase = machopic_function_base_name ();
10215       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (picbase));
10216       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
10217       rtx tmplabrtx;
10218       char tmplab[20];
10219
10220       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
10221                                   CODE_LABEL_NUMBER (operands[0]));
10222       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
10223
10224       emit_insn (gen_load_macho_picbase (picreg, tmplabrtx));
10225       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
10226     }
10227   else
10228 #endif
10229     rs6000_emit_load_toc_table (FALSE);
10230   DONE;
10231 }")
10232
10233 ;; Elf specific ways of loading addresses for non-PIC code.
10234 ;; The output of this could be r0, but we make a very strong
10235 ;; preference for a base register because it will usually
10236 ;; be needed there.
10237 (define_insn "elf_high"
10238   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
10239         (high:SI (match_operand 1 "" "")))]
10240   "TARGET_ELF && ! TARGET_64BIT"
10241   "{liu|lis} %0,%1@ha")
10242
10243 (define_insn "elf_low"
10244   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
10245         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
10246                    (match_operand 2 "" "")))]
10247    "TARGET_ELF && ! TARGET_64BIT"
10248    "@
10249     {cal|la} %0,%2@l(%1)
10250     {ai|addic} %0,%1,%K2")
10251 \f
10252 ;; A function pointer under AIX is a pointer to a data area whose first word
10253 ;; contains the actual address of the function, whose second word contains a
10254 ;; pointer to its TOC, and whose third word contains a value to place in the
10255 ;; static chain register (r11).  Note that if we load the static chain, our
10256 ;; "trampoline" need not have any executable code.
10257
10258 (define_expand "call_indirect_aix32"
10259   [(set (match_dup 2)
10260         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
10261    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10262         (reg:SI 2))
10263    (set (reg:SI 2)
10264         (mem:SI (plus:SI (match_dup 0)
10265                          (const_int 4))))
10266    (set (reg:SI 11)
10267         (mem:SI (plus:SI (match_dup 0)
10268                          (const_int 8))))
10269    (parallel [(call (mem:SI (match_dup 2))
10270                     (match_operand 1 "" ""))
10271               (use (reg:SI 2))
10272               (use (reg:SI 11))
10273               (set (reg:SI 2)
10274                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10275               (clobber (scratch:SI))])]
10276   "TARGET_32BIT"
10277   "
10278 { operands[2] = gen_reg_rtx (SImode); }")
10279
10280 (define_expand "call_indirect_aix64"
10281   [(set (match_dup 2)
10282         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
10283    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10284         (reg:DI 2))
10285    (set (reg:DI 2)
10286         (mem:DI (plus:DI (match_dup 0)
10287                          (const_int 8))))
10288    (set (reg:DI 11)
10289         (mem:DI (plus:DI (match_dup 0)
10290                          (const_int 16))))
10291    (parallel [(call (mem:SI (match_dup 2))
10292                     (match_operand 1 "" ""))
10293               (use (reg:DI 2))
10294               (use (reg:DI 11))
10295               (set (reg:DI 2)
10296                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10297               (clobber (scratch:SI))])]
10298   "TARGET_64BIT"
10299   "
10300 { operands[2] = gen_reg_rtx (DImode); }")
10301
10302 (define_expand "call_value_indirect_aix32"
10303   [(set (match_dup 3)
10304         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
10305    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10306         (reg:SI 2))
10307    (set (reg:SI 2)
10308         (mem:SI (plus:SI (match_dup 1)
10309                          (const_int 4))))
10310    (set (reg:SI 11)
10311         (mem:SI (plus:SI (match_dup 1)
10312                          (const_int 8))))
10313    (parallel [(set (match_operand 0 "" "")
10314                    (call (mem:SI (match_dup 3))
10315                          (match_operand 2 "" "")))
10316               (use (reg:SI 2))
10317               (use (reg:SI 11))
10318               (set (reg:SI 2)
10319                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10320               (clobber (scratch:SI))])]
10321   "TARGET_32BIT"
10322   "
10323 { operands[3] = gen_reg_rtx (SImode); }")
10324
10325 (define_expand "call_value_indirect_aix64"
10326   [(set (match_dup 3)
10327         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
10328    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10329         (reg:DI 2))
10330    (set (reg:DI 2)
10331         (mem:DI (plus:DI (match_dup 1)
10332                          (const_int 8))))
10333    (set (reg:DI 11)
10334         (mem:DI (plus:DI (match_dup 1)
10335                          (const_int 16))))
10336    (parallel [(set (match_operand 0 "" "")
10337                    (call (mem:SI (match_dup 3))
10338                          (match_operand 2 "" "")))
10339               (use (reg:DI 2))
10340               (use (reg:DI 11))
10341               (set (reg:DI 2)
10342                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10343               (clobber (scratch:SI))])]
10344   "TARGET_64BIT"
10345   "
10346 { operands[3] = gen_reg_rtx (DImode); }")
10347
10348 ;; Now the definitions for the call and call_value insns
10349 (define_expand "call"
10350   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10351                     (match_operand 1 "" ""))
10352               (use (match_operand 2 "" ""))
10353               (clobber (scratch:SI))])]
10354   ""
10355   "
10356 {
10357 #if TARGET_MACHO
10358   if (MACHOPIC_INDIRECT)
10359     operands[0] = machopic_indirect_call_target (operands[0]);
10360 #endif
10361
10362   gcc_assert (GET_CODE (operands[0]) == MEM);
10363   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
10364
10365   operands[0] = XEXP (operands[0], 0);
10366
10367   if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT
10368       && flag_pic
10369       && GET_CODE (operands[0]) == SYMBOL_REF
10370       && !SYMBOL_REF_LOCAL_P (operands[0]))
10371     {
10372       rtx call;
10373       rtvec tmp;
10374
10375       tmp = gen_rtvec (3,
10376                        gen_rtx_CALL (VOIDmode,
10377                                      gen_rtx_MEM (SImode, operands[0]),
10378                                      operands[1]),
10379                        gen_rtx_USE (VOIDmode, operands[2]),
10380                        gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (SImode)));
10381       call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp));
10382       use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx);
10383       DONE;
10384     }
10385
10386   if (GET_CODE (operands[0]) != SYMBOL_REF
10387       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
10388       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
10389     {
10390       if (INTVAL (operands[2]) & CALL_LONG)
10391         operands[0] = rs6000_longcall_ref (operands[0]);
10392
10393       switch (DEFAULT_ABI)
10394         {
10395         case ABI_V4:
10396         case ABI_DARWIN:
10397           operands[0] = force_reg (Pmode, operands[0]);
10398           break;
10399
10400         case ABI_AIX:
10401           /* AIX function pointers are really pointers to a three word
10402              area.  */
10403           emit_call_insn (TARGET_32BIT
10404                           ? gen_call_indirect_aix32 (force_reg (SImode,
10405                                                                 operands[0]),
10406                                                      operands[1])
10407                           : gen_call_indirect_aix64 (force_reg (DImode,
10408                                                                 operands[0]),
10409                                                      operands[1]));
10410           DONE;
10411
10412         default:
10413           gcc_unreachable ();
10414         }
10415     }
10416 }")
10417
10418 (define_expand "call_value"
10419   [(parallel [(set (match_operand 0 "" "")
10420                    (call (mem:SI (match_operand 1 "address_operand" ""))
10421                          (match_operand 2 "" "")))
10422               (use (match_operand 3 "" ""))
10423               (clobber (scratch:SI))])]
10424   ""
10425   "
10426 {
10427 #if TARGET_MACHO
10428   if (MACHOPIC_INDIRECT)
10429     operands[1] = machopic_indirect_call_target (operands[1]);
10430 #endif
10431
10432   gcc_assert (GET_CODE (operands[1]) == MEM);
10433   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
10434
10435   operands[1] = XEXP (operands[1], 0);
10436
10437   if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT
10438       && flag_pic
10439       && GET_CODE (operands[1]) == SYMBOL_REF
10440       && !SYMBOL_REF_LOCAL_P (operands[1]))
10441     {
10442       rtx call;
10443       rtvec tmp;
10444
10445       tmp = gen_rtvec (3,
10446                        gen_rtx_SET (VOIDmode,
10447                                     operands[0],
10448                                     gen_rtx_CALL (VOIDmode,
10449                                                   gen_rtx_MEM (SImode,
10450                                                                operands[1]),
10451                                                   operands[2])),
10452                        gen_rtx_USE (VOIDmode, operands[3]),
10453                        gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (SImode)));
10454       call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp));
10455       use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx);
10456       DONE;
10457     }
10458
10459   if (GET_CODE (operands[1]) != SYMBOL_REF
10460       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
10461       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
10462     {
10463       if (INTVAL (operands[3]) & CALL_LONG)
10464         operands[1] = rs6000_longcall_ref (operands[1]);
10465
10466       switch (DEFAULT_ABI)
10467         {
10468         case ABI_V4:
10469         case ABI_DARWIN:
10470           operands[1] = force_reg (Pmode, operands[1]);
10471           break;
10472
10473         case ABI_AIX:
10474           /* AIX function pointers are really pointers to a three word
10475              area.  */
10476           emit_call_insn (TARGET_32BIT
10477                           ? gen_call_value_indirect_aix32 (operands[0],
10478                                                            force_reg (SImode,
10479                                                                       operands[1]),
10480                                                            operands[2])
10481                           : gen_call_value_indirect_aix64 (operands[0],
10482                                                            force_reg (DImode,
10483                                                                       operands[1]),
10484                                                            operands[2]));
10485           DONE;
10486
10487         default:
10488           gcc_unreachable ();
10489         }
10490     }
10491 }")
10492
10493 ;; Call to function in current module.  No TOC pointer reload needed.
10494 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10495 ;; either the function was not prototyped, or it was prototyped as a
10496 ;; variable argument function.  It is > 0 if FP registers were passed
10497 ;; and < 0 if they were not.
10498
10499 (define_insn "*call_local32"
10500   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10501          (match_operand 1 "" "g,g"))
10502    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10503    (clobber (match_scratch:SI 3 "=l,l"))]
10504   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10505   "*
10506 {
10507   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10508     output_asm_insn (\"crxor 6,6,6\", operands);
10509
10510   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10511     output_asm_insn (\"creqv 6,6,6\", operands);
10512
10513   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10514 }"
10515   [(set_attr "type" "branch")
10516    (set_attr "length" "4,8")])
10517
10518 (define_insn "*call_local64"
10519   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10520          (match_operand 1 "" "g,g"))
10521    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10522    (clobber (match_scratch:SI 3 "=l,l"))]
10523   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10524   "*
10525 {
10526   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10527     output_asm_insn (\"crxor 6,6,6\", operands);
10528
10529   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10530     output_asm_insn (\"creqv 6,6,6\", operands);
10531
10532   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10533 }"
10534   [(set_attr "type" "branch")
10535    (set_attr "length" "4,8")])
10536
10537 (define_insn "*call_value_local32"
10538   [(set (match_operand 0 "" "")
10539         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10540               (match_operand 2 "" "g,g")))
10541    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10542    (clobber (match_scratch:SI 4 "=l,l"))]
10543   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10544   "*
10545 {
10546   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10547     output_asm_insn (\"crxor 6,6,6\", operands);
10548
10549   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10550     output_asm_insn (\"creqv 6,6,6\", operands);
10551
10552   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10553 }"
10554   [(set_attr "type" "branch")
10555    (set_attr "length" "4,8")])
10556
10557
10558 (define_insn "*call_value_local64"
10559   [(set (match_operand 0 "" "")
10560         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10561               (match_operand 2 "" "g,g")))
10562    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10563    (clobber (match_scratch:SI 4 "=l,l"))]
10564   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10565   "*
10566 {
10567   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10568     output_asm_insn (\"crxor 6,6,6\", operands);
10569
10570   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10571     output_asm_insn (\"creqv 6,6,6\", operands);
10572
10573   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10574 }"
10575   [(set_attr "type" "branch")
10576    (set_attr "length" "4,8")])
10577
10578 ;; Call to function which may be in another module.  Restore the TOC
10579 ;; pointer (r2) after the call unless this is System V.
10580 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10581 ;; either the function was not prototyped, or it was prototyped as a
10582 ;; variable argument function.  It is > 0 if FP registers were passed
10583 ;; and < 0 if they were not.
10584
10585 (define_insn "*call_indirect_nonlocal_aix32"
10586   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l"))
10587          (match_operand 1 "" "g,g"))
10588    (use (reg:SI 2))
10589    (use (reg:SI 11))
10590    (set (reg:SI 2)
10591         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10592    (clobber (match_scratch:SI 2 "=l,l"))]
10593   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10594   "b%T0l\;{l|lwz} 2,20(1)"
10595   [(set_attr "type" "jmpreg")
10596    (set_attr "length" "8")])
10597
10598 (define_insn "*call_nonlocal_aix32"
10599   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10600          (match_operand 1 "" "g"))
10601    (use (match_operand:SI 2 "immediate_operand" "O"))
10602    (clobber (match_scratch:SI 3 "=l"))]
10603   "TARGET_32BIT
10604    && DEFAULT_ABI == ABI_AIX
10605    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10606   "bl %z0\;%."
10607   [(set_attr "type" "branch")
10608    (set_attr "length" "8")])
10609
10610 (define_insn "*call_indirect_nonlocal_aix64"
10611   [(call (mem:SI (match_operand:DI 0 "register_operand" "c,*l"))
10612          (match_operand 1 "" "g,g"))
10613    (use (reg:DI 2))
10614    (use (reg:DI 11))
10615    (set (reg:DI 2)
10616         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10617    (clobber (match_scratch:SI 2 "=l,l"))]
10618   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10619   "b%T0l\;ld 2,40(1)"
10620   [(set_attr "type" "jmpreg")
10621    (set_attr "length" "8")])
10622
10623 (define_insn "*call_nonlocal_aix64"
10624   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10625          (match_operand 1 "" "g"))
10626    (use (match_operand:SI 2 "immediate_operand" "O"))
10627    (clobber (match_scratch:SI 3 "=l"))]
10628   "TARGET_64BIT
10629    && DEFAULT_ABI == ABI_AIX
10630    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10631   "bl %z0\;%."
10632   [(set_attr "type" "branch")
10633    (set_attr "length" "8")])
10634
10635 (define_insn "*call_value_indirect_nonlocal_aix32"
10636   [(set (match_operand 0 "" "")
10637         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l"))
10638               (match_operand 2 "" "g,g")))
10639    (use (reg:SI 2))
10640    (use (reg:SI 11))
10641    (set (reg:SI 2)
10642         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10643    (clobber (match_scratch:SI 3 "=l,l"))]
10644   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10645   "b%T1l\;{l|lwz} 2,20(1)"
10646   [(set_attr "type" "jmpreg")
10647    (set_attr "length" "8")])
10648
10649 (define_insn "*call_value_nonlocal_aix32"
10650   [(set (match_operand 0 "" "")
10651         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10652               (match_operand 2 "" "g")))
10653    (use (match_operand:SI 3 "immediate_operand" "O"))
10654    (clobber (match_scratch:SI 4 "=l"))]
10655   "TARGET_32BIT
10656    && DEFAULT_ABI == ABI_AIX
10657    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10658   "bl %z1\;%."
10659   [(set_attr "type" "branch")
10660    (set_attr "length" "8")])
10661
10662 (define_insn "*call_value_indirect_nonlocal_aix64"
10663   [(set (match_operand 0 "" "")
10664         (call (mem:SI (match_operand:DI 1 "register_operand" "c,*l"))
10665               (match_operand 2 "" "g,g")))
10666    (use (reg:DI 2))
10667    (use (reg:DI 11))
10668    (set (reg:DI 2)
10669         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10670    (clobber (match_scratch:SI 3 "=l,l"))]
10671   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10672   "b%T1l\;ld 2,40(1)"
10673   [(set_attr "type" "jmpreg")
10674    (set_attr "length" "8")])
10675
10676 (define_insn "*call_value_nonlocal_aix64"
10677   [(set (match_operand 0 "" "")
10678         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10679               (match_operand 2 "" "g")))
10680    (use (match_operand:SI 3 "immediate_operand" "O"))
10681    (clobber (match_scratch:SI 4 "=l"))]
10682   "TARGET_64BIT
10683    && DEFAULT_ABI == ABI_AIX
10684    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10685   "bl %z1\;%."
10686   [(set_attr "type" "branch")
10687    (set_attr "length" "8")])
10688
10689 ;; A function pointer under System V is just a normal pointer
10690 ;; operands[0] is the function pointer
10691 ;; operands[1] is the stack size to clean up
10692 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
10693 ;; which indicates how to set cr1
10694
10695 (define_insn "*call_indirect_nonlocal_sysv<mode>"
10696   [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l"))
10697          (match_operand 1 "" "g,g,g,g"))
10698    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
10699    (clobber (match_scratch:SI 3 "=l,l,l,l"))]
10700   "DEFAULT_ABI == ABI_V4
10701    || DEFAULT_ABI == ABI_DARWIN"
10702 {
10703   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10704     output_asm_insn ("crxor 6,6,6", operands);
10705
10706   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10707     output_asm_insn ("creqv 6,6,6", operands);
10708
10709   return "b%T0l";
10710 }
10711   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
10712    (set_attr "length" "4,4,8,8")])
10713
10714 (define_insn "*call_nonlocal_sysv<mode>"
10715   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
10716          (match_operand 1 "" "g,g"))
10717    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10718    (clobber (match_scratch:SI 3 "=l,l"))]
10719   "(DEFAULT_ABI == ABI_DARWIN
10720    || (DEFAULT_ABI == ABI_V4
10721        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
10722 {
10723   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10724     output_asm_insn ("crxor 6,6,6", operands);
10725
10726   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10727     output_asm_insn ("creqv 6,6,6", operands);
10728
10729 #if TARGET_MACHO
10730   return output_call(insn, operands, 0, 2);
10731 #else
10732   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10733     {
10734       if (TARGET_SECURE_PLT && flag_pic == 2)
10735         /* The magic 32768 offset here and in the other sysv call insns
10736            corresponds to the offset of r30 in .got2, as given by LCTOC1.
10737            See sysv4.h:toc_section.  */
10738         return "bl %z0+32768@plt";
10739       else
10740         return "bl %z0@plt";
10741     }
10742   else
10743     return "bl %z0";
10744 #endif
10745 }
10746   [(set_attr "type" "branch,branch")
10747    (set_attr "length" "4,8")])
10748
10749 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
10750   [(set (match_operand 0 "" "")
10751         (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l"))
10752               (match_operand 2 "" "g,g,g,g")))
10753    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
10754    (clobber (match_scratch:SI 4 "=l,l,l,l"))]
10755   "DEFAULT_ABI == ABI_V4
10756    || DEFAULT_ABI == ABI_DARWIN"
10757 {
10758   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10759     output_asm_insn ("crxor 6,6,6", operands);
10760
10761   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10762     output_asm_insn ("creqv 6,6,6", operands);
10763
10764   return "b%T1l";
10765 }
10766   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
10767    (set_attr "length" "4,4,8,8")])
10768
10769 (define_insn "*call_value_nonlocal_sysv<mode>"
10770   [(set (match_operand 0 "" "")
10771         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
10772               (match_operand 2 "" "g,g")))
10773    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10774    (clobber (match_scratch:SI 4 "=l,l"))]
10775   "(DEFAULT_ABI == ABI_DARWIN
10776    || (DEFAULT_ABI == ABI_V4
10777        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
10778 {
10779   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10780     output_asm_insn ("crxor 6,6,6", operands);
10781
10782   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10783     output_asm_insn ("creqv 6,6,6", operands);
10784
10785 #if TARGET_MACHO
10786   return output_call(insn, operands, 1, 3);
10787 #else
10788   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10789     {
10790       if (TARGET_SECURE_PLT && flag_pic == 2)
10791         return "bl %z1+32768@plt";
10792       else
10793         return "bl %z1@plt";
10794     }
10795   else
10796     return "bl %z1";
10797 #endif
10798 }
10799   [(set_attr "type" "branch,branch")
10800    (set_attr "length" "4,8")])
10801
10802 ;; Call subroutine returning any type.
10803 (define_expand "untyped_call"
10804   [(parallel [(call (match_operand 0 "" "")
10805                     (const_int 0))
10806               (match_operand 1 "" "")
10807               (match_operand 2 "" "")])]
10808   ""
10809   "
10810 {
10811   int i;
10812
10813   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
10814
10815   for (i = 0; i < XVECLEN (operands[2], 0); i++)
10816     {
10817       rtx set = XVECEXP (operands[2], 0, i);
10818       emit_move_insn (SET_DEST (set), SET_SRC (set));
10819     }
10820
10821   /* The optimizer does not know that the call sets the function value
10822      registers we stored in the result block.  We avoid problems by
10823      claiming that all hard registers are used and clobbered at this
10824      point.  */
10825   emit_insn (gen_blockage ());
10826
10827   DONE;
10828 }")
10829
10830 ;; sibling call patterns
10831 (define_expand "sibcall"
10832   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10833                     (match_operand 1 "" ""))
10834               (use (match_operand 2 "" ""))
10835               (use (match_operand 3 "" ""))
10836               (return)])]
10837   ""
10838   "
10839 {
10840 #if TARGET_MACHO
10841   if (MACHOPIC_INDIRECT)
10842     operands[0] = machopic_indirect_call_target (operands[0]);
10843 #endif
10844
10845   gcc_assert (GET_CODE (operands[0]) == MEM);
10846   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
10847
10848   operands[0] = XEXP (operands[0], 0);
10849   operands[3] = gen_reg_rtx (SImode);
10850
10851 }")
10852
10853 ;; this and similar patterns must be marked as using LR, otherwise
10854 ;; dataflow will try to delete the store into it.  This is true
10855 ;; even when the actual reg to jump to is in CTR, when LR was
10856 ;; saved and restored around the PIC-setting BCL.
10857 (define_insn "*sibcall_local32"
10858   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10859          (match_operand 1 "" "g,g"))
10860    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10861    (use (match_operand:SI 3 "register_operand" "l,l"))
10862    (return)]
10863   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10864   "*
10865 {
10866   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10867     output_asm_insn (\"crxor 6,6,6\", operands);
10868
10869   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10870     output_asm_insn (\"creqv 6,6,6\", operands);
10871
10872   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10873 }"
10874   [(set_attr "type" "branch")
10875    (set_attr "length" "4,8")])
10876
10877 (define_insn "*sibcall_local64"
10878   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10879          (match_operand 1 "" "g,g"))
10880    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10881    (use (match_operand:SI 3 "register_operand" "l,l"))
10882    (return)]
10883   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10884   "*
10885 {
10886   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10887     output_asm_insn (\"crxor 6,6,6\", operands);
10888
10889   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10890     output_asm_insn (\"creqv 6,6,6\", operands);
10891
10892   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10893 }"
10894   [(set_attr "type" "branch")
10895    (set_attr "length" "4,8")])
10896
10897 (define_insn "*sibcall_value_local32"
10898   [(set (match_operand 0 "" "")
10899         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10900               (match_operand 2 "" "g,g")))
10901    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10902    (use (match_operand:SI 4 "register_operand" "l,l"))
10903    (return)]
10904   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10905   "*
10906 {
10907   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10908     output_asm_insn (\"crxor 6,6,6\", operands);
10909
10910   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10911     output_asm_insn (\"creqv 6,6,6\", operands);
10912
10913   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10914 }"
10915   [(set_attr "type" "branch")
10916    (set_attr "length" "4,8")])
10917
10918
10919 (define_insn "*sibcall_value_local64"
10920   [(set (match_operand 0 "" "")
10921         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10922               (match_operand 2 "" "g,g")))
10923    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10924    (use (match_operand:SI 4 "register_operand" "l,l"))
10925    (return)]
10926   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10927   "*
10928 {
10929   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10930     output_asm_insn (\"crxor 6,6,6\", operands);
10931
10932   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10933     output_asm_insn (\"creqv 6,6,6\", operands);
10934
10935   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10936 }"
10937   [(set_attr "type" "branch")
10938    (set_attr "length" "4,8")])
10939
10940 (define_insn "*sibcall_nonlocal_aix32"
10941   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10942          (match_operand 1 "" "g"))
10943    (use (match_operand:SI 2 "immediate_operand" "O"))
10944    (use (match_operand:SI 3 "register_operand" "l"))
10945    (return)]
10946   "TARGET_32BIT
10947    && DEFAULT_ABI == ABI_AIX
10948    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10949   "b %z0"
10950   [(set_attr "type" "branch")
10951    (set_attr "length" "4")])
10952
10953 (define_insn "*sibcall_nonlocal_aix64"
10954   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10955          (match_operand 1 "" "g"))
10956    (use (match_operand:SI 2 "immediate_operand" "O"))
10957    (use (match_operand:SI 3 "register_operand" "l"))
10958    (return)]
10959   "TARGET_64BIT
10960    && DEFAULT_ABI == ABI_AIX
10961    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10962   "b %z0"
10963   [(set_attr "type" "branch")
10964    (set_attr "length" "4")])
10965
10966 (define_insn "*sibcall_value_nonlocal_aix32"
10967   [(set (match_operand 0 "" "")
10968         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10969               (match_operand 2 "" "g")))
10970    (use (match_operand:SI 3 "immediate_operand" "O"))
10971    (use (match_operand:SI 4 "register_operand" "l"))
10972    (return)]
10973   "TARGET_32BIT
10974    && DEFAULT_ABI == ABI_AIX
10975    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10976   "b %z1"
10977   [(set_attr "type" "branch")
10978    (set_attr "length" "4")])
10979
10980 (define_insn "*sibcall_value_nonlocal_aix64"
10981   [(set (match_operand 0 "" "")
10982         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10983               (match_operand 2 "" "g")))
10984    (use (match_operand:SI 3 "immediate_operand" "O"))
10985    (use (match_operand:SI 4 "register_operand" "l"))
10986    (return)]
10987   "TARGET_64BIT
10988    && DEFAULT_ABI == ABI_AIX
10989    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10990   "b %z1"
10991   [(set_attr "type" "branch")
10992    (set_attr "length" "4")])
10993
10994 (define_insn "*sibcall_nonlocal_sysv<mode>"
10995   [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
10996          (match_operand 1 "" ""))
10997    (use (match_operand 2 "immediate_operand" "O,n"))
10998    (use (match_operand:SI 3 "register_operand" "l,l"))
10999    (return)]
11000   "(DEFAULT_ABI == ABI_DARWIN
11001      || DEFAULT_ABI == ABI_V4)
11002    && (INTVAL (operands[2]) & CALL_LONG) == 0"
11003   "*
11004 {
11005   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11006     output_asm_insn (\"crxor 6,6,6\", operands);
11007
11008   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11009     output_asm_insn (\"creqv 6,6,6\", operands);
11010
11011   if (DEFAULT_ABI == ABI_V4 && flag_pic)
11012     {
11013       if (TARGET_SECURE_PLT && flag_pic == 2)
11014         return \"b %z0+32768@plt\";
11015       else
11016         return \"b %z0@plt\";
11017     }
11018   else
11019     return \"b %z0\";
11020 }"
11021   [(set_attr "type" "branch,branch")
11022    (set_attr "length" "4,8")])
11023
11024 (define_expand "sibcall_value"
11025   [(parallel [(set (match_operand 0 "register_operand" "")
11026                 (call (mem:SI (match_operand 1 "address_operand" ""))
11027                       (match_operand 2 "" "")))
11028               (use (match_operand 3 "" ""))
11029               (use (match_operand 4 "" ""))
11030               (return)])]
11031   ""
11032   "
11033 {
11034 #if TARGET_MACHO
11035   if (MACHOPIC_INDIRECT)
11036     operands[1] = machopic_indirect_call_target (operands[1]);
11037 #endif
11038
11039   gcc_assert (GET_CODE (operands[1]) == MEM);
11040   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
11041
11042   operands[1] = XEXP (operands[1], 0);
11043   operands[4] = gen_reg_rtx (SImode);
11044
11045 }")
11046
11047 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
11048   [(set (match_operand 0 "" "")
11049         (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
11050               (match_operand 2 "" "")))
11051    (use (match_operand:SI 3 "immediate_operand" "O,n"))
11052    (use (match_operand:SI 4 "register_operand" "l,l"))
11053    (return)]
11054   "(DEFAULT_ABI == ABI_DARWIN
11055        || DEFAULT_ABI == ABI_V4)
11056    && (INTVAL (operands[3]) & CALL_LONG) == 0"
11057   "*
11058 {
11059   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11060     output_asm_insn (\"crxor 6,6,6\", operands);
11061
11062   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11063     output_asm_insn (\"creqv 6,6,6\", operands);
11064
11065   if (DEFAULT_ABI == ABI_V4 && flag_pic)
11066     {
11067       if (TARGET_SECURE_PLT && flag_pic == 2)
11068         return \"b %z1+32768@plt\";
11069       else
11070         return \"b %z1@plt\";
11071     }
11072   else
11073     return \"b %z1\";
11074 }"
11075   [(set_attr "type" "branch,branch")
11076    (set_attr "length" "4,8")])
11077
11078 (define_expand "sibcall_epilogue"
11079   [(use (const_int 0))]
11080   "TARGET_SCHED_PROLOG"
11081   "
11082 {
11083       rs6000_emit_epilogue (TRUE);
11084       DONE;
11085 }")
11086
11087 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
11088 ;; all of memory.  This blocks insns from being moved across this point.
11089
11090 (define_insn "blockage"
11091   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
11092   ""
11093   "")
11094 \f
11095 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
11096 ;; signed & unsigned, and one type of branch.
11097 ;;
11098 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
11099 ;; insns, and branches.  We store the operands of compares until we see
11100 ;; how it is used.
11101 (define_expand "cmp<mode>"
11102   [(set (cc0)
11103         (compare (match_operand:GPR 0 "gpc_reg_operand" "")
11104                  (match_operand:GPR 1 "reg_or_short_operand" "")))]
11105   ""
11106   "
11107 {
11108   /* Take care of the possibility that operands[1] might be negative but
11109      this might be a logical operation.  That insn doesn't exist.  */
11110   if (GET_CODE (operands[1]) == CONST_INT
11111       && INTVAL (operands[1]) < 0)
11112     operands[1] = force_reg (<MODE>mode, operands[1]);
11113
11114   rs6000_compare_op0 = operands[0];
11115   rs6000_compare_op1 = operands[1];
11116   rs6000_compare_fp_p = 0;
11117   DONE;
11118 }")
11119
11120 (define_expand "cmp<mode>"
11121   [(set (cc0) (compare (match_operand:FP 0 "gpc_reg_operand" "")
11122                        (match_operand:FP 1 "gpc_reg_operand" "")))]
11123   ""
11124   "
11125 {
11126   rs6000_compare_op0 = operands[0];
11127   rs6000_compare_op1 = operands[1];
11128   rs6000_compare_fp_p = 1;
11129   DONE;
11130 }")
11131
11132 (define_expand "beq"
11133   [(use (match_operand 0 "" ""))]
11134   ""
11135   "{ rs6000_emit_cbranch (EQ, operands[0]); DONE; }")
11136
11137 (define_expand "bne"
11138   [(use (match_operand 0 "" ""))]
11139   ""
11140   "{ rs6000_emit_cbranch (NE, operands[0]); DONE; }")
11141
11142 (define_expand "bge"
11143   [(use (match_operand 0 "" ""))]
11144   ""
11145   "{ rs6000_emit_cbranch (GE, operands[0]); DONE; }")
11146
11147 (define_expand "bgt"
11148   [(use (match_operand 0 "" ""))]
11149   ""
11150   "{ rs6000_emit_cbranch (GT, operands[0]); DONE; }")
11151
11152 (define_expand "ble"
11153   [(use (match_operand 0 "" ""))]
11154   ""
11155   "{ rs6000_emit_cbranch (LE, operands[0]); DONE; }")
11156
11157 (define_expand "blt"
11158   [(use (match_operand 0 "" ""))]
11159   ""
11160   "{ rs6000_emit_cbranch (LT, operands[0]); DONE; }")
11161
11162 (define_expand "bgeu"
11163   [(use (match_operand 0 "" ""))]
11164   ""
11165   "{ rs6000_emit_cbranch (GEU, operands[0]); DONE; }")
11166
11167 (define_expand "bgtu"
11168   [(use (match_operand 0 "" ""))]
11169   ""
11170   "{ rs6000_emit_cbranch (GTU, operands[0]); DONE; }")
11171
11172 (define_expand "bleu"
11173   [(use (match_operand 0 "" ""))]
11174   ""
11175   "{ rs6000_emit_cbranch (LEU, operands[0]); DONE; }")
11176
11177 (define_expand "bltu"
11178   [(use (match_operand 0 "" ""))]
11179   ""
11180   "{ rs6000_emit_cbranch (LTU, operands[0]); DONE; }")
11181
11182 (define_expand "bunordered"
11183   [(use (match_operand 0 "" ""))]
11184   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11185   "{ rs6000_emit_cbranch (UNORDERED, operands[0]); DONE; }")
11186
11187 (define_expand "bordered"
11188   [(use (match_operand 0 "" ""))]
11189   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11190   "{ rs6000_emit_cbranch (ORDERED, operands[0]); DONE; }")
11191
11192 (define_expand "buneq"
11193   [(use (match_operand 0 "" ""))]
11194   ""
11195   "{ rs6000_emit_cbranch (UNEQ, operands[0]); DONE; }")
11196
11197 (define_expand "bunge"
11198   [(use (match_operand 0 "" ""))]
11199   ""
11200   "{ rs6000_emit_cbranch (UNGE, operands[0]); DONE; }")
11201
11202 (define_expand "bungt"
11203   [(use (match_operand 0 "" ""))]
11204   ""
11205   "{ rs6000_emit_cbranch (UNGT, operands[0]); DONE; }")
11206
11207 (define_expand "bunle"
11208   [(use (match_operand 0 "" ""))]
11209   ""
11210   "{ rs6000_emit_cbranch (UNLE, operands[0]); DONE; }")
11211
11212 (define_expand "bunlt"
11213   [(use (match_operand 0 "" ""))]
11214   ""
11215   "{ rs6000_emit_cbranch (UNLT, operands[0]); DONE; }")
11216
11217 (define_expand "bltgt"
11218   [(use (match_operand 0 "" ""))]
11219   ""
11220   "{ rs6000_emit_cbranch (LTGT, operands[0]); DONE; }")
11221
11222 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
11223 ;; For SEQ, likewise, except that comparisons with zero should be done
11224 ;; with an scc insns.  However, due to the order that combine see the
11225 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
11226 ;; the cases we don't want to handle.
11227 (define_expand "seq"
11228   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11229   ""
11230   "{ rs6000_emit_sCOND (EQ, operands[0]); DONE; }")
11231
11232 (define_expand "sne"
11233   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11234   ""
11235   "
11236 {
11237   if (! rs6000_compare_fp_p)
11238     FAIL;
11239
11240   rs6000_emit_sCOND (NE, operands[0]);
11241   DONE;
11242 }")
11243
11244 ;; A >= 0 is best done the portable way for A an integer.
11245 (define_expand "sge"
11246   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11247   ""
11248   "
11249 {
11250   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11251     FAIL;
11252
11253   rs6000_emit_sCOND (GE, operands[0]);
11254   DONE;
11255 }")
11256
11257 ;; A > 0 is best done using the portable sequence, so fail in that case.
11258 (define_expand "sgt"
11259   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11260   ""
11261   "
11262 {
11263   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11264     FAIL;
11265
11266   rs6000_emit_sCOND (GT, operands[0]);
11267   DONE;
11268 }")
11269
11270 ;; A <= 0 is best done the portable way for A an integer.
11271 (define_expand "sle"
11272   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11273   ""
11274   "
11275 {
11276   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11277     FAIL;
11278
11279   rs6000_emit_sCOND (LE, operands[0]);
11280   DONE;
11281 }")
11282
11283 ;; A < 0 is best done in the portable way for A an integer.
11284 (define_expand "slt"
11285   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11286   ""
11287   "
11288 {
11289   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11290     FAIL;
11291
11292   rs6000_emit_sCOND (LT, operands[0]);
11293   DONE;
11294 }")
11295
11296 (define_expand "sgeu"
11297   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11298   ""
11299   "{ rs6000_emit_sCOND (GEU, operands[0]); DONE; }")
11300
11301 (define_expand "sgtu"
11302   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11303   ""
11304   "{ rs6000_emit_sCOND (GTU, operands[0]); DONE; }")
11305
11306 (define_expand "sleu"
11307   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11308   ""
11309   "{ rs6000_emit_sCOND (LEU, operands[0]); DONE; }")
11310
11311 (define_expand "sltu"
11312   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11313   ""
11314   "{ rs6000_emit_sCOND (LTU, operands[0]); DONE; }")
11315
11316 (define_expand "sunordered"
11317   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11318   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11319   "{ rs6000_emit_sCOND (UNORDERED, operands[0]); DONE; }")
11320
11321 (define_expand "sordered"
11322   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11323   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11324   "{ rs6000_emit_sCOND (ORDERED, operands[0]); DONE; }")
11325
11326 (define_expand "suneq"
11327   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11328   ""
11329   "{ rs6000_emit_sCOND (UNEQ, operands[0]); DONE; }")
11330
11331 (define_expand "sunge"
11332   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11333   ""
11334   "{ rs6000_emit_sCOND (UNGE, operands[0]); DONE; }")
11335
11336 (define_expand "sungt"
11337   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11338   ""
11339   "{ rs6000_emit_sCOND (UNGT, operands[0]); DONE; }")
11340
11341 (define_expand "sunle"
11342   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11343   ""
11344   "{ rs6000_emit_sCOND (UNLE, operands[0]); DONE; }")
11345
11346 (define_expand "sunlt"
11347   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11348   ""
11349   "{ rs6000_emit_sCOND (UNLT, operands[0]); DONE; }")
11350
11351 (define_expand "sltgt"
11352   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11353   ""
11354   "{ rs6000_emit_sCOND (LTGT, operands[0]); DONE; }")
11355
11356 (define_expand "stack_protect_set"
11357   [(match_operand 0 "memory_operand" "")
11358    (match_operand 1 "memory_operand" "")]
11359   ""
11360 {
11361 #ifdef TARGET_THREAD_SSP_OFFSET
11362   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
11363   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
11364   operands[1] = gen_rtx_MEM (Pmode, addr);
11365 #endif
11366   if (TARGET_64BIT)
11367     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
11368   else
11369     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
11370   DONE;
11371 })
11372
11373 (define_insn "stack_protect_setsi"
11374   [(set (match_operand:SI 0 "memory_operand" "=m")
11375         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
11376    (set (match_scratch:SI 2 "=&r") (const_int 0))]
11377   "TARGET_32BIT"
11378   "{l%U1%X1|lwz%U1%X1} %2,%1\;{st%U0%X0|stw%U0%X0} %2,%0\;{lil|li} %2,0"
11379   [(set_attr "type" "three")
11380    (set_attr "length" "12")])
11381
11382 (define_insn "stack_protect_setdi"
11383   [(set (match_operand:DI 0 "memory_operand" "=m")
11384         (unspec:DI [(match_operand:DI 1 "memory_operand" "m")] UNSPEC_SP_SET))
11385    (set (match_scratch:DI 2 "=&r") (const_int 0))]
11386   "TARGET_64BIT"
11387   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;{lil|li} %2,0"
11388   [(set_attr "type" "three")
11389    (set_attr "length" "12")])
11390
11391 (define_expand "stack_protect_test"
11392   [(match_operand 0 "memory_operand" "")
11393    (match_operand 1 "memory_operand" "")
11394    (match_operand 2 "" "")]
11395   ""
11396 {
11397 #ifdef TARGET_THREAD_SSP_OFFSET
11398   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
11399   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
11400   operands[1] = gen_rtx_MEM (Pmode, addr);
11401 #endif
11402   rs6000_compare_op0 = operands[0];
11403   rs6000_compare_op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]),
11404                                        UNSPEC_SP_TEST);
11405   rs6000_compare_fp_p = 0;
11406   emit_jump_insn (gen_beq (operands[2]));
11407   DONE;
11408 })
11409
11410 (define_insn "stack_protect_testsi"
11411   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
11412         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
11413                       (match_operand:SI 2 "memory_operand" "m,m")]
11414                      UNSPEC_SP_TEST))
11415    (set (match_scratch:SI 4 "=r,r") (const_int 0))
11416    (clobber (match_scratch:SI 3 "=&r,&r"))]
11417   "TARGET_32BIT"
11418   "@
11419    {l%U1%X1|lwz%U1%X1} %3,%1\;{l%U2%X2|lwz%U2%X2} %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
11420    {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"
11421   [(set_attr "length" "16,20")])
11422
11423 (define_insn "stack_protect_testdi"
11424   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
11425         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "m,m")
11426                       (match_operand:DI 2 "memory_operand" "m,m")]
11427                      UNSPEC_SP_TEST))
11428    (set (match_scratch:DI 4 "=r,r") (const_int 0))
11429    (clobber (match_scratch:DI 3 "=&r,&r"))]
11430   "TARGET_64BIT"
11431   "@
11432    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
11433    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;{lil|li} %3,0\;{lil|li} %4,0"
11434   [(set_attr "length" "16,20")])
11435
11436 \f
11437 ;; Here are the actual compare insns.
11438 (define_insn "*cmp<mode>_internal1"
11439   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11440         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
11441                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
11442   ""
11443   "{cmp%I2|cmp<wd>%I2} %0,%1,%2"
11444   [(set_attr "type" "cmp")])
11445
11446 ;; If we are comparing a register for equality with a large constant,
11447 ;; we can do this with an XOR followed by a compare.  But this is profitable
11448 ;; only if the large constant is only used for the comparison (and in this
11449 ;; case we already have a register to reuse as scratch).
11450 ;;
11451 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
11452 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
11453
11454 (define_peephole2
11455   [(set (match_operand:SI 0 "register_operand")
11456         (match_operand:SI 1 "logical_const_operand" ""))
11457    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
11458                        [(match_dup 0)
11459                         (match_operand:SI 2 "logical_const_operand" "")]))
11460    (set (match_operand:CC 4 "cc_reg_operand" "")
11461         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
11462                     (match_dup 0)))
11463    (set (pc)
11464         (if_then_else (match_operator 6 "equality_operator"
11465                        [(match_dup 4) (const_int 0)])
11466                       (match_operand 7 "" "")
11467                       (match_operand 8 "" "")))]
11468   "peep2_reg_dead_p (3, operands[0])
11469    && peep2_reg_dead_p (4, operands[4])"
11470  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
11471   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
11472   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
11473  
11474 {
11475   /* Get the constant we are comparing against, and see what it looks like
11476      when sign-extended from 16 to 32 bits.  Then see what constant we could
11477      XOR with SEXTC to get the sign-extended value.  */
11478   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
11479                                               SImode,
11480                                               operands[1], operands[2]);
11481   HOST_WIDE_INT c = INTVAL (cnst);
11482   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
11483   HOST_WIDE_INT xorv = c ^ sextc;
11484
11485   operands[9] = GEN_INT (xorv);
11486   operands[10] = GEN_INT (sextc);
11487 })
11488
11489 (define_insn "*cmpsi_internal2"
11490   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11491         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11492                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
11493   ""
11494   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
11495   [(set_attr "type" "cmp")])
11496
11497 (define_insn "*cmpdi_internal2"
11498   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11499         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
11500                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
11501   ""
11502   "cmpld%I2 %0,%1,%b2"
11503   [(set_attr "type" "cmp")])
11504
11505 ;; The following two insns don't exist as single insns, but if we provide
11506 ;; them, we can swap an add and compare, which will enable us to overlap more
11507 ;; of the required delay between a compare and branch.  We generate code for
11508 ;; them by splitting.
11509
11510 (define_insn ""
11511   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11512         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11513                     (match_operand:SI 2 "short_cint_operand" "i")))
11514    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11515         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11516   ""
11517   "#"
11518   [(set_attr "length" "8")])
11519
11520 (define_insn ""
11521   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
11522         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11523                        (match_operand:SI 2 "u_short_cint_operand" "i")))
11524    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11525         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11526   ""
11527   "#"
11528   [(set_attr "length" "8")])
11529
11530 (define_split
11531   [(set (match_operand:CC 3 "cc_reg_operand" "")
11532         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11533                     (match_operand:SI 2 "short_cint_operand" "")))
11534    (set (match_operand:SI 0 "gpc_reg_operand" "")
11535         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11536   ""
11537   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
11538    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11539
11540 (define_split
11541   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
11542         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
11543                        (match_operand:SI 2 "u_short_cint_operand" "")))
11544    (set (match_operand:SI 0 "gpc_reg_operand" "")
11545         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11546   ""
11547   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
11548    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11549
11550 (define_insn "*cmpsf_internal1"
11551   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11552         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
11553                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
11554   "TARGET_HARD_FLOAT && TARGET_FPRS"
11555   "fcmpu %0,%1,%2"
11556   [(set_attr "type" "fpcompare")])
11557
11558 (define_insn "*cmpdf_internal1"
11559   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11560         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
11561                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
11562   "TARGET_HARD_FLOAT && TARGET_FPRS"
11563   "fcmpu %0,%1,%2"
11564   [(set_attr "type" "fpcompare")])
11565
11566 ;; Only need to compare second words if first words equal
11567 (define_insn "*cmptf_internal1"
11568   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11569         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11570                       (match_operand:TF 2 "gpc_reg_operand" "f")))]
11571   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
11572    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11573   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
11574   [(set_attr "type" "fpcompare")
11575    (set_attr "length" "12")])
11576
11577 (define_insn_and_split "*cmptf_internal2"
11578   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11579         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11580                       (match_operand:TF 2 "gpc_reg_operand" "f")))
11581     (clobber (match_scratch:DF 3 "=f"))
11582     (clobber (match_scratch:DF 4 "=f"))
11583     (clobber (match_scratch:DF 5 "=f"))
11584     (clobber (match_scratch:DF 6 "=f"))
11585     (clobber (match_scratch:DF 7 "=f"))
11586     (clobber (match_scratch:DF 8 "=f"))
11587     (clobber (match_scratch:DF 9 "=f"))
11588     (clobber (match_scratch:DF 10 "=f"))]
11589   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
11590    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11591   "#"
11592   "&& reload_completed"
11593   [(set (match_dup 3) (match_dup 13))
11594    (set (match_dup 4) (match_dup 14))
11595    (set (match_dup 9) (abs:DF (match_dup 5)))
11596    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
11597    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
11598                            (label_ref (match_dup 11))
11599                            (pc)))
11600    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
11601    (set (pc) (label_ref (match_dup 12)))
11602    (match_dup 11)
11603    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
11604    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
11605    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
11606    (set (match_dup 0) (compare:CCFP (match_dup 7) (match_dup 4)))
11607    (match_dup 12)]
11608 {
11609   REAL_VALUE_TYPE rv;
11610   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
11611   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
11612
11613   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
11614   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
11615   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
11616   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
11617   operands[11] = gen_label_rtx ();
11618   operands[12] = gen_label_rtx ();
11619   real_inf (&rv);
11620   operands[13] = force_const_mem (DFmode,
11621                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
11622   operands[14] = force_const_mem (DFmode,
11623                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
11624                                                                 DFmode));
11625   if (TARGET_TOC)
11626     {
11627       operands[13] = gen_const_mem (DFmode,
11628                                     create_TOC_reference (XEXP (operands[13], 0)));
11629       operands[14] = gen_const_mem (DFmode,
11630                                     create_TOC_reference (XEXP (operands[14], 0)));
11631       set_mem_alias_set (operands[13], get_TOC_alias_set ());
11632       set_mem_alias_set (operands[14], get_TOC_alias_set ());
11633     }
11634 })
11635 \f
11636 ;; Now we have the scc insns.  We can do some combinations because of the
11637 ;; way the machine works.
11638 ;;
11639 ;; Note that this is probably faster if we can put an insn between the
11640 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
11641 ;; cases the insns below which don't use an intermediate CR field will
11642 ;; be used instead.
11643 (define_insn ""
11644   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11645         (match_operator:SI 1 "scc_comparison_operator"
11646                            [(match_operand 2 "cc_reg_operand" "y")
11647                             (const_int 0)]))]
11648   ""
11649   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11650   [(set (attr "type")
11651      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11652                 (const_string "mfcrf")
11653            ]
11654         (const_string "mfcr")))
11655    (set_attr "length" "8")])
11656
11657 ;; Same as above, but get the GT bit.
11658 (define_insn "move_from_CR_gt_bit"
11659   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11660         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
11661   "TARGET_E500"
11662   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,31,31"
11663   [(set_attr "type" "mfcr")
11664    (set_attr "length" "8")])
11665
11666 ;; Same as above, but get the OV/ORDERED bit.
11667 (define_insn "move_from_CR_ov_bit"
11668   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11669         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
11670   "TARGET_ISEL"
11671   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
11672   [(set_attr "type" "mfcr")
11673    (set_attr "length" "8")])
11674
11675 (define_insn ""
11676   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11677         (match_operator:DI 1 "scc_comparison_operator"
11678                            [(match_operand 2 "cc_reg_operand" "y")
11679                             (const_int 0)]))]
11680   "TARGET_POWERPC64"
11681   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11682   [(set (attr "type")
11683      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11684                 (const_string "mfcrf")
11685            ]
11686         (const_string "mfcr")))
11687    (set_attr "length" "8")])
11688
11689 (define_insn ""
11690   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11691         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11692                                        [(match_operand 2 "cc_reg_operand" "y,y")
11693                                         (const_int 0)])
11694                     (const_int 0)))
11695    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11696         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11697   "TARGET_32BIT"
11698   "@
11699    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
11700    #"
11701   [(set_attr "type" "delayed_compare")
11702    (set_attr "length" "8,16")])
11703
11704 (define_split
11705   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11706         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11707                                        [(match_operand 2 "cc_reg_operand" "")
11708                                         (const_int 0)])
11709                     (const_int 0)))
11710    (set (match_operand:SI 3 "gpc_reg_operand" "")
11711         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11712   "TARGET_32BIT && reload_completed"
11713   [(set (match_dup 3)
11714         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
11715    (set (match_dup 0)
11716         (compare:CC (match_dup 3)
11717                     (const_int 0)))]
11718   "")
11719
11720 (define_insn ""
11721   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11722         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11723                                       [(match_operand 2 "cc_reg_operand" "y")
11724                                        (const_int 0)])
11725                    (match_operand:SI 3 "const_int_operand" "n")))]
11726   ""
11727   "*
11728 {
11729   int is_bit = ccr_bit (operands[1], 1);
11730   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11731   int count;
11732
11733   if (is_bit >= put_bit)
11734     count = is_bit - put_bit;
11735   else
11736     count = 32 - (put_bit - is_bit);
11737
11738   operands[4] = GEN_INT (count);
11739   operands[5] = GEN_INT (put_bit);
11740
11741   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
11742 }"
11743   [(set (attr "type")
11744      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11745                 (const_string "mfcrf")
11746            ]
11747         (const_string "mfcr")))
11748    (set_attr "length" "8")])
11749
11750 (define_insn ""
11751   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11752         (compare:CC
11753          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11754                                        [(match_operand 2 "cc_reg_operand" "y,y")
11755                                         (const_int 0)])
11756                     (match_operand:SI 3 "const_int_operand" "n,n"))
11757          (const_int 0)))
11758    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
11759         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11760                    (match_dup 3)))]
11761   ""
11762   "*
11763 {
11764   int is_bit = ccr_bit (operands[1], 1);
11765   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11766   int count;
11767
11768   /* Force split for non-cc0 compare.  */
11769   if (which_alternative == 1)
11770      return \"#\";
11771
11772   if (is_bit >= put_bit)
11773     count = is_bit - put_bit;
11774   else
11775     count = 32 - (put_bit - is_bit);
11776
11777   operands[5] = GEN_INT (count);
11778   operands[6] = GEN_INT (put_bit);
11779
11780   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
11781 }"
11782   [(set_attr "type" "delayed_compare")
11783    (set_attr "length" "8,16")])
11784
11785 (define_split
11786   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11787         (compare:CC
11788          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11789                                        [(match_operand 2 "cc_reg_operand" "")
11790                                         (const_int 0)])
11791                     (match_operand:SI 3 "const_int_operand" ""))
11792          (const_int 0)))
11793    (set (match_operand:SI 4 "gpc_reg_operand" "")
11794         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11795                    (match_dup 3)))]
11796   "reload_completed"
11797   [(set (match_dup 4)
11798         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11799                    (match_dup 3)))
11800    (set (match_dup 0)
11801         (compare:CC (match_dup 4)
11802                     (const_int 0)))]
11803   "")
11804
11805 ;; There is a 3 cycle delay between consecutive mfcr instructions
11806 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
11807
11808 (define_peephole
11809   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11810         (match_operator:SI 1 "scc_comparison_operator"
11811                            [(match_operand 2 "cc_reg_operand" "y")
11812                             (const_int 0)]))
11813    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
11814         (match_operator:SI 4 "scc_comparison_operator"
11815                            [(match_operand 5 "cc_reg_operand" "y")
11816                             (const_int 0)]))]
11817   "REGNO (operands[2]) != REGNO (operands[5])"
11818   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11819   [(set_attr "type" "mfcr")
11820    (set_attr "length" "12")])
11821
11822 (define_peephole
11823   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11824         (match_operator:DI 1 "scc_comparison_operator"
11825                            [(match_operand 2 "cc_reg_operand" "y")
11826                             (const_int 0)]))
11827    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
11828         (match_operator:DI 4 "scc_comparison_operator"
11829                            [(match_operand 5 "cc_reg_operand" "y")
11830                             (const_int 0)]))]
11831   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
11832   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11833   [(set_attr "type" "mfcr")
11834    (set_attr "length" "12")])
11835
11836 ;; There are some scc insns that can be done directly, without a compare.
11837 ;; These are faster because they don't involve the communications between
11838 ;; the FXU and branch units.   In fact, we will be replacing all of the
11839 ;; integer scc insns here or in the portable methods in emit_store_flag.
11840 ;;
11841 ;; Also support (neg (scc ..)) since that construct is used to replace
11842 ;; branches, (plus (scc ..) ..) since that construct is common and
11843 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
11844 ;; cases where it is no more expensive than (neg (scc ..)).
11845
11846 ;; Have reload force a constant into a register for the simple insns that
11847 ;; otherwise won't accept constants.  We do this because it is faster than
11848 ;; the cmp/mfcr sequence we would otherwise generate.
11849
11850 (define_mode_attr scc_eq_op2 [(SI "rKLI")
11851                               (DI "rKJI")])
11852
11853 (define_insn_and_split "*eq<mode>"
11854   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
11855         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
11856                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
11857   "!TARGET_POWER"
11858   "#"
11859   "!TARGET_POWER"
11860   [(set (match_dup 0)
11861         (clz:GPR (match_dup 3)))
11862    (set (match_dup 0)
11863         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
11864   {
11865     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
11866       {
11867         /* Use output operand as intermediate.  */
11868         operands[3] = operands[0];
11869
11870         if (logical_operand (operands[2], <MODE>mode))
11871           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
11872                                   gen_rtx_XOR (<MODE>mode,
11873                                                operands[1], operands[2])));
11874         else
11875           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
11876                                   gen_rtx_PLUS (<MODE>mode, operands[1],
11877                                                 negate_rtx (<MODE>mode,
11878                                                             operands[2]))));
11879       }
11880     else
11881       operands[3] = operands[1];
11882
11883     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
11884   })
11885
11886 (define_insn_and_split "*eq<mode>_compare"
11887   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11888         (compare:CC
11889          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
11890                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
11891          (const_int 0)))
11892    (set (match_operand:P 0 "gpc_reg_operand" "=r")
11893         (eq:P (match_dup 1) (match_dup 2)))]
11894   "!TARGET_POWER && optimize_size"
11895   "#"
11896   "!TARGET_POWER && optimize_size"
11897   [(set (match_dup 0)
11898         (clz:P (match_dup 4)))
11899    (parallel [(set (match_dup 3)
11900                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
11901                                (const_int 0)))
11902               (set (match_dup 0)
11903                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
11904   {
11905     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
11906       {
11907         /* Use output operand as intermediate.  */
11908         operands[4] = operands[0];
11909
11910         if (logical_operand (operands[2], <MODE>mode))
11911           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
11912                                   gen_rtx_XOR (<MODE>mode,
11913                                                operands[1], operands[2])));
11914         else
11915           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
11916                                   gen_rtx_PLUS (<MODE>mode, operands[1],
11917                                                 negate_rtx (<MODE>mode,
11918                                                             operands[2]))));
11919       }
11920     else
11921       operands[4] = operands[1];
11922
11923     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
11924   })
11925
11926 (define_insn "*eqsi_power"
11927   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11928         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11929                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
11930    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
11931   "TARGET_POWER"
11932   "@
11933    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11934    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
11935    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11936    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11937    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
11938   [(set_attr "type" "three,two,three,three,three")
11939    (set_attr "length" "12,8,12,12,12")])
11940
11941 ;; We have insns of the form shown by the first define_insn below.  If
11942 ;; there is something inside the comparison operation, we must split it.
11943 (define_split
11944   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11945         (plus:SI (match_operator 1 "comparison_operator"
11946                                  [(match_operand:SI 2 "" "")
11947                                   (match_operand:SI 3
11948                                                     "reg_or_cint_operand" "")])
11949                  (match_operand:SI 4 "gpc_reg_operand" "")))
11950    (clobber (match_operand:SI 5 "register_operand" ""))]
11951   "! gpc_reg_operand (operands[2], SImode)"
11952   [(set (match_dup 5) (match_dup 2))
11953    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
11954                                (match_dup 4)))])
11955
11956 (define_insn "*plus_eqsi"
11957   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
11958         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11959                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
11960                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
11961   "TARGET_32BIT"
11962   "@
11963    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11964    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
11965    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11966    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11967    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
11968   [(set_attr "type" "three,two,three,three,three")
11969    (set_attr "length" "12,8,12,12,12")])
11970
11971 (define_insn "*compare_plus_eqsi"
11972   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11973         (compare:CC
11974          (plus:SI
11975           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11976                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
11977           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11978          (const_int 0)))
11979    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
11980   "TARGET_32BIT && optimize_size"
11981   "@
11982    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11983    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
11984    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11985    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11986    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11987    #
11988    #
11989    #
11990    #
11991    #"
11992   [(set_attr "type" "compare")
11993    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11994
11995 (define_split
11996   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11997         (compare:CC
11998          (plus:SI
11999           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
12000                  (match_operand:SI 2 "scc_eq_operand" ""))
12001           (match_operand:SI 3 "gpc_reg_operand" ""))
12002          (const_int 0)))
12003    (clobber (match_scratch:SI 4 ""))]
12004   "TARGET_32BIT && optimize_size && reload_completed"
12005   [(set (match_dup 4)
12006         (plus:SI (eq:SI (match_dup 1)
12007                  (match_dup 2))
12008           (match_dup 3)))
12009    (set (match_dup 0)
12010         (compare:CC (match_dup 4)
12011                     (const_int 0)))]
12012   "")
12013
12014 (define_insn "*plus_eqsi_compare"
12015   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
12016         (compare:CC
12017          (plus:SI
12018           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
12019                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
12020           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
12021          (const_int 0)))
12022    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
12023         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12024   "TARGET_32BIT && optimize_size"
12025   "@
12026    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12027    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
12028    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12029    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12030    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12031    #
12032    #
12033    #
12034    #
12035    #"
12036   [(set_attr "type" "compare")
12037    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
12038
12039 (define_split
12040   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12041         (compare:CC
12042          (plus:SI
12043           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
12044                  (match_operand:SI 2 "scc_eq_operand" ""))
12045           (match_operand:SI 3 "gpc_reg_operand" ""))
12046          (const_int 0)))
12047    (set (match_operand:SI 0 "gpc_reg_operand" "")
12048         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12049   "TARGET_32BIT && optimize_size && reload_completed"
12050   [(set (match_dup 0)
12051         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12052    (set (match_dup 4)
12053         (compare:CC (match_dup 0)
12054                     (const_int 0)))]
12055   "")
12056
12057 (define_insn "*neg_eq0<mode>"
12058   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12059         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
12060                      (const_int 0))))]
12061   ""
12062   "{ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0"
12063   [(set_attr "type" "two")
12064    (set_attr "length" "8")])
12065
12066 (define_insn_and_split "*neg_eq<mode>"
12067   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12068         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
12069                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
12070   ""
12071   "#"
12072   ""
12073   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
12074   {
12075     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
12076       {
12077         /* Use output operand as intermediate.  */
12078         operands[3] = operands[0];
12079
12080         if (logical_operand (operands[2], <MODE>mode))
12081           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12082                                   gen_rtx_XOR (<MODE>mode,
12083                                                operands[1], operands[2])));
12084         else
12085           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
12086                                   gen_rtx_PLUS (<MODE>mode, operands[1],
12087                                                 negate_rtx (<MODE>mode,
12088                                                             operands[2]))));
12089       }
12090     else
12091       operands[3] = operands[1];
12092   })
12093
12094 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
12095 ;; since it nabs/sr is just as fast.
12096 (define_insn "*ne0si"
12097   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12098         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
12099                      (const_int 31)))
12100    (clobber (match_scratch:SI 2 "=&r"))]
12101   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
12102   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
12103   [(set_attr "type" "two")
12104    (set_attr "length" "8")])
12105
12106 (define_insn "*ne0di"
12107   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12108         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
12109                      (const_int 63)))
12110    (clobber (match_scratch:DI 2 "=&r"))]
12111   "TARGET_64BIT"
12112   "addic %2,%1,-1\;subfe %0,%2,%1"
12113   [(set_attr "type" "two")
12114    (set_attr "length" "8")])
12115
12116 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
12117 (define_insn "*plus_ne0si"
12118   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12119         (plus:SI (lshiftrt:SI
12120                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
12121                   (const_int 31))
12122                  (match_operand:SI 2 "gpc_reg_operand" "r")))
12123    (clobber (match_scratch:SI 3 "=&r"))]
12124   "TARGET_32BIT"
12125   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
12126   [(set_attr "type" "two")
12127    (set_attr "length" "8")])
12128
12129 (define_insn "*plus_ne0di"
12130   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12131         (plus:DI (lshiftrt:DI
12132                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
12133                   (const_int 63))
12134                  (match_operand:DI 2 "gpc_reg_operand" "r")))
12135    (clobber (match_scratch:DI 3 "=&r"))]
12136   "TARGET_64BIT"
12137   "addic %3,%1,-1\;addze %0,%2"
12138   [(set_attr "type" "two")
12139    (set_attr "length" "8")])
12140
12141 (define_insn "*compare_plus_ne0si"
12142   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12143         (compare:CC
12144          (plus:SI (lshiftrt:SI
12145                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
12146                    (const_int 31))
12147                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
12148          (const_int 0)))
12149    (clobber (match_scratch:SI 3 "=&r,&r"))
12150    (clobber (match_scratch:SI 4 "=X,&r"))]
12151   "TARGET_32BIT"
12152   "@
12153    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
12154    #"
12155   [(set_attr "type" "compare")
12156    (set_attr "length" "8,12")])
12157
12158 (define_split
12159   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12160         (compare:CC
12161          (plus:SI (lshiftrt:SI
12162                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
12163                    (const_int 31))
12164                   (match_operand:SI 2 "gpc_reg_operand" ""))
12165          (const_int 0)))
12166    (clobber (match_scratch:SI 3 ""))
12167    (clobber (match_scratch:SI 4 ""))]
12168   "TARGET_32BIT && reload_completed"
12169   [(parallel [(set (match_dup 3)
12170                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
12171                                          (const_int 31))
12172                             (match_dup 2)))
12173               (clobber (match_dup 4))])
12174    (set (match_dup 0)
12175         (compare:CC (match_dup 3)
12176                     (const_int 0)))]
12177   "")
12178
12179 (define_insn "*compare_plus_ne0di"
12180   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12181         (compare:CC
12182          (plus:DI (lshiftrt:DI
12183                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
12184                    (const_int 63))
12185                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12186          (const_int 0)))
12187    (clobber (match_scratch:DI 3 "=&r,&r"))]
12188   "TARGET_64BIT"
12189   "@
12190    addic %3,%1,-1\;addze. %3,%2
12191    #"
12192   [(set_attr "type" "compare")
12193    (set_attr "length" "8,12")])
12194
12195 (define_split
12196   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12197         (compare:CC
12198          (plus:DI (lshiftrt:DI
12199                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
12200                    (const_int 63))
12201                   (match_operand:DI 2 "gpc_reg_operand" ""))
12202          (const_int 0)))
12203    (clobber (match_scratch:DI 3 ""))]
12204   "TARGET_64BIT && reload_completed"
12205   [(set (match_dup 3)
12206         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
12207                    (const_int 63))
12208                   (match_dup 2)))
12209    (set (match_dup 0)
12210         (compare:CC (match_dup 3)
12211                     (const_int 0)))]
12212   "")
12213
12214 (define_insn "*plus_ne0si_compare"
12215   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12216         (compare:CC
12217          (plus:SI (lshiftrt:SI
12218                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
12219                    (const_int 31))
12220                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
12221          (const_int 0)))
12222    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12223         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
12224                  (match_dup 2)))
12225    (clobber (match_scratch:SI 3 "=&r,&r"))]
12226   "TARGET_32BIT"
12227   "@
12228    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
12229    #"
12230   [(set_attr "type" "compare")
12231    (set_attr "length" "8,12")])
12232
12233 (define_split
12234   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12235         (compare:CC
12236          (plus:SI (lshiftrt:SI
12237                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
12238                    (const_int 31))
12239                   (match_operand:SI 2 "gpc_reg_operand" ""))
12240          (const_int 0)))
12241    (set (match_operand:SI 0 "gpc_reg_operand" "")
12242         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
12243                  (match_dup 2)))
12244    (clobber (match_scratch:SI 3 ""))]
12245   "TARGET_32BIT && reload_completed"
12246   [(parallel [(set (match_dup 0)
12247         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
12248                  (match_dup 2)))
12249    (clobber (match_dup 3))])
12250    (set (match_dup 4)
12251         (compare:CC (match_dup 0)
12252                     (const_int 0)))]
12253   "")
12254
12255 (define_insn "*plus_ne0di_compare"
12256   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12257         (compare:CC
12258          (plus:DI (lshiftrt:DI
12259                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
12260                    (const_int 63))
12261                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12262          (const_int 0)))
12263    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12264         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12265                  (match_dup 2)))
12266    (clobber (match_scratch:DI 3 "=&r,&r"))]
12267   "TARGET_64BIT"
12268   "@
12269    addic %3,%1,-1\;addze. %0,%2
12270    #"
12271   [(set_attr "type" "compare")
12272    (set_attr "length" "8,12")])
12273
12274 (define_split
12275   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12276         (compare:CC
12277          (plus:DI (lshiftrt:DI
12278                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
12279                    (const_int 63))
12280                   (match_operand:DI 2 "gpc_reg_operand" ""))
12281          (const_int 0)))
12282    (set (match_operand:DI 0 "gpc_reg_operand" "")
12283         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12284                  (match_dup 2)))
12285    (clobber (match_scratch:DI 3 ""))]
12286   "TARGET_64BIT && reload_completed"
12287   [(parallel [(set (match_dup 0)
12288         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12289                  (match_dup 2)))
12290    (clobber (match_dup 3))])
12291    (set (match_dup 4)
12292         (compare:CC (match_dup 0)
12293                     (const_int 0)))]
12294   "")
12295
12296 (define_insn ""
12297   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12298         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12299                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
12300    (clobber (match_scratch:SI 3 "=r,X"))]
12301   "TARGET_POWER"
12302   "@
12303    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
12304    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
12305   [(set_attr "length" "12")])
12306
12307 (define_insn ""
12308   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12309         (compare:CC
12310          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12311                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12312          (const_int 0)))
12313    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12314         (le:SI (match_dup 1) (match_dup 2)))
12315    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
12316   "TARGET_POWER"
12317   "@
12318    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12319    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
12320    #
12321    #"
12322   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
12323    (set_attr "length" "12,12,16,16")])
12324
12325 (define_split
12326   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12327         (compare:CC
12328          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12329                 (match_operand:SI 2 "reg_or_short_operand" ""))
12330          (const_int 0)))
12331    (set (match_operand:SI 0 "gpc_reg_operand" "")
12332         (le:SI (match_dup 1) (match_dup 2)))
12333    (clobber (match_scratch:SI 3 ""))]
12334   "TARGET_POWER && reload_completed"
12335   [(parallel [(set (match_dup 0)
12336         (le:SI (match_dup 1) (match_dup 2)))
12337    (clobber (match_dup 3))])
12338    (set (match_dup 4)
12339         (compare:CC (match_dup 0)
12340                     (const_int 0)))]
12341   "")
12342
12343 (define_insn ""
12344   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12345         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12346                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
12347                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12348   "TARGET_POWER"
12349   "@
12350    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
12351    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
12352   [(set_attr "length" "12")])
12353
12354 (define_insn ""
12355   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12356         (compare:CC
12357          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12358                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12359                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12360          (const_int 0)))
12361    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12362   "TARGET_POWER"
12363   "@
12364    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12365    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
12366    #
12367    #"
12368   [(set_attr "type" "compare")
12369    (set_attr "length" "12,12,16,16")])
12370
12371 (define_split
12372   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12373         (compare:CC
12374          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12375                          (match_operand:SI 2 "reg_or_short_operand" ""))
12376                   (match_operand:SI 3 "gpc_reg_operand" ""))
12377          (const_int 0)))
12378    (clobber (match_scratch:SI 4 ""))]
12379   "TARGET_POWER && reload_completed"
12380   [(set (match_dup 4)
12381         (plus:SI (le:SI (match_dup 1) (match_dup 2))
12382                  (match_dup 3)))
12383    (set (match_dup 0)
12384         (compare:CC (match_dup 4)
12385                     (const_int 0)))]
12386   "")
12387
12388 (define_insn ""
12389   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12390         (compare:CC
12391          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12392                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12393                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12394          (const_int 0)))
12395    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12396         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12397   "TARGET_POWER"
12398   "@
12399    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12400    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
12401    #
12402    #"
12403   [(set_attr "type" "compare")
12404    (set_attr "length" "12,12,16,16")])
12405
12406 (define_split
12407   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12408         (compare:CC
12409          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12410                          (match_operand:SI 2 "reg_or_short_operand" ""))
12411                   (match_operand:SI 3 "gpc_reg_operand" ""))
12412          (const_int 0)))
12413    (set (match_operand:SI 0 "gpc_reg_operand" "")
12414         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12415   "TARGET_POWER && reload_completed"
12416   [(set (match_dup 0)
12417         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12418    (set (match_dup 4)
12419         (compare:CC (match_dup 0)
12420                     (const_int 0)))]
12421   "")
12422
12423 (define_insn ""
12424   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12425         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12426                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
12427   "TARGET_POWER"
12428   "@
12429    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
12430    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
12431   [(set_attr "length" "12")])
12432
12433 (define_insn "*leu<mode>"
12434   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12435         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12436                (match_operand:P 2 "reg_or_short_operand" "rI")))]
12437   ""
12438   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12439   [(set_attr "type" "three")
12440    (set_attr "length" "12")])
12441
12442 (define_insn "*leu<mode>_compare"
12443   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12444         (compare:CC
12445          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12446                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
12447          (const_int 0)))
12448    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12449         (leu:P (match_dup 1) (match_dup 2)))]
12450   ""
12451   "@
12452    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12453    #"
12454   [(set_attr "type" "compare")
12455    (set_attr "length" "12,16")])
12456
12457 (define_split
12458   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12459         (compare:CC
12460          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
12461                 (match_operand:P 2 "reg_or_short_operand" ""))
12462          (const_int 0)))
12463    (set (match_operand:P 0 "gpc_reg_operand" "")
12464         (leu:P (match_dup 1) (match_dup 2)))]
12465   "reload_completed"
12466   [(set (match_dup 0)
12467         (leu:P (match_dup 1) (match_dup 2)))
12468    (set (match_dup 3)
12469         (compare:CC (match_dup 0)
12470                     (const_int 0)))]
12471   "")
12472
12473 (define_insn "*plus_leu<mode>"
12474   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12475         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12476                        (match_operand:P 2 "reg_or_short_operand" "rI"))
12477                 (match_operand:P 3 "gpc_reg_operand" "r")))]
12478   ""
12479   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
12480   [(set_attr "type" "two")
12481    (set_attr "length" "8")])
12482
12483 (define_insn ""
12484   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12485         (compare:CC
12486          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12487                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12488                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12489          (const_int 0)))
12490    (clobber (match_scratch:SI 4 "=&r,&r"))]
12491   "TARGET_32BIT"
12492   "@
12493    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
12494    #"
12495   [(set_attr "type" "compare")
12496    (set_attr "length" "8,12")])
12497
12498 (define_split
12499   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12500         (compare:CC
12501          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12502                           (match_operand:SI 2 "reg_or_short_operand" ""))
12503                   (match_operand:SI 3 "gpc_reg_operand" ""))
12504          (const_int 0)))
12505    (clobber (match_scratch:SI 4 ""))]
12506   "TARGET_32BIT && reload_completed"
12507   [(set (match_dup 4)
12508         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12509                   (match_dup 3)))
12510    (set (match_dup 0)
12511         (compare:CC (match_dup 4)
12512                     (const_int 0)))]
12513   "")
12514
12515 (define_insn ""
12516   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12517         (compare:CC
12518          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12519                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12520                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12521          (const_int 0)))
12522    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12523         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12524   "TARGET_32BIT"
12525   "@
12526    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
12527    #"
12528   [(set_attr "type" "compare")
12529    (set_attr "length" "8,12")])
12530
12531 (define_split
12532   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12533         (compare:CC
12534          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12535                           (match_operand:SI 2 "reg_or_short_operand" ""))
12536                   (match_operand:SI 3 "gpc_reg_operand" ""))
12537          (const_int 0)))
12538    (set (match_operand:SI 0 "gpc_reg_operand" "")
12539         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12540   "TARGET_32BIT && reload_completed"
12541   [(set (match_dup 0)
12542         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12543    (set (match_dup 4)
12544         (compare:CC (match_dup 0)
12545                     (const_int 0)))]
12546   "")
12547
12548 (define_insn "*neg_leu<mode>"
12549   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12550         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12551                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
12552   ""
12553   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
12554    [(set_attr "type" "three")
12555     (set_attr "length" "12")])
12556
12557 (define_insn "*and_neg_leu<mode>"
12558   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12559         (and:P (neg:P
12560                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12561                         (match_operand:P 2 "reg_or_short_operand" "rI")))
12562                 (match_operand:P 3 "gpc_reg_operand" "r")))]
12563   ""
12564   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12565   [(set_attr "type" "three")
12566    (set_attr "length" "12")])
12567
12568 (define_insn ""
12569   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12570         (compare:CC
12571          (and:SI (neg:SI
12572                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12573                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12574                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12575          (const_int 0)))
12576    (clobber (match_scratch:SI 4 "=&r,&r"))]
12577   "TARGET_32BIT"
12578   "@
12579    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12580    #"
12581   [(set_attr "type" "compare")
12582    (set_attr "length" "12,16")])
12583
12584 (define_split
12585   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12586         (compare:CC
12587          (and:SI (neg:SI
12588                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12589                           (match_operand:SI 2 "reg_or_short_operand" "")))
12590                  (match_operand:SI 3 "gpc_reg_operand" ""))
12591          (const_int 0)))
12592    (clobber (match_scratch:SI 4 ""))]
12593   "TARGET_32BIT && reload_completed"
12594   [(set (match_dup 4)
12595         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12596                 (match_dup 3)))
12597    (set (match_dup 0)
12598         (compare:CC (match_dup 4)
12599                     (const_int 0)))]
12600   "")
12601
12602 (define_insn ""
12603   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12604         (compare:CC
12605          (and:SI (neg:SI
12606                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12607                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12608                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12609          (const_int 0)))
12610    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12611         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12612   "TARGET_32BIT"
12613   "@
12614    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12615    #"
12616   [(set_attr "type" "compare")
12617    (set_attr "length" "12,16")])
12618
12619 (define_split
12620   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12621         (compare:CC
12622          (and:SI (neg:SI
12623                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12624                           (match_operand:SI 2 "reg_or_short_operand" "")))
12625                  (match_operand:SI 3 "gpc_reg_operand" ""))
12626          (const_int 0)))
12627    (set (match_operand:SI 0 "gpc_reg_operand" "")
12628         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12629   "TARGET_32BIT && reload_completed"
12630   [(set (match_dup 0)
12631         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12632                 (match_dup 3)))
12633    (set (match_dup 4)
12634         (compare:CC (match_dup 0)
12635                     (const_int 0)))]
12636   "")
12637
12638 (define_insn ""
12639   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12640         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12641                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12642   "TARGET_POWER"
12643   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
12644    [(set_attr "length" "12")])
12645
12646 (define_insn ""
12647   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12648         (compare:CC
12649          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12650                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12651          (const_int 0)))
12652    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12653         (lt:SI (match_dup 1) (match_dup 2)))]
12654   "TARGET_POWER"
12655   "@
12656    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
12657    #"
12658   [(set_attr "type" "delayed_compare")
12659    (set_attr "length" "12,16")])
12660
12661 (define_split
12662   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12663         (compare:CC
12664          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12665                 (match_operand:SI 2 "reg_or_short_operand" ""))
12666          (const_int 0)))
12667    (set (match_operand:SI 0 "gpc_reg_operand" "")
12668         (lt:SI (match_dup 1) (match_dup 2)))]
12669   "TARGET_POWER && reload_completed"
12670   [(set (match_dup 0)
12671         (lt:SI (match_dup 1) (match_dup 2)))
12672    (set (match_dup 3)
12673         (compare:CC (match_dup 0)
12674                     (const_int 0)))]
12675   "")
12676
12677 (define_insn ""
12678   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12679         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12680                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12681                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12682   "TARGET_POWER"
12683   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
12684   [(set_attr "length" "12")])
12685
12686 (define_insn ""
12687   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12688         (compare:CC
12689          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12690                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12691                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12692          (const_int 0)))
12693    (clobber (match_scratch:SI 4 "=&r,&r"))]
12694   "TARGET_POWER"
12695   "@
12696    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
12697    #"
12698   [(set_attr "type" "compare")
12699    (set_attr "length" "12,16")])
12700
12701 (define_split
12702   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12703         (compare:CC
12704          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12705                          (match_operand:SI 2 "reg_or_short_operand" ""))
12706                   (match_operand:SI 3 "gpc_reg_operand" ""))
12707          (const_int 0)))
12708    (clobber (match_scratch:SI 4 ""))]
12709   "TARGET_POWER && reload_completed"
12710   [(set (match_dup 4)
12711         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
12712                  (match_dup 3)))
12713    (set (match_dup 0)
12714         (compare:CC (match_dup 4)
12715                     (const_int 0)))]
12716   "")
12717
12718 (define_insn ""
12719   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12720         (compare:CC
12721          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12722                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12723                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12724          (const_int 0)))
12725    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12726         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12727   "TARGET_POWER"
12728   "@
12729    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
12730    #"
12731   [(set_attr "type" "compare")
12732    (set_attr "length" "12,16")])
12733
12734 (define_split
12735   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12736         (compare:CC
12737          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12738                          (match_operand:SI 2 "reg_or_short_operand" ""))
12739                   (match_operand:SI 3 "gpc_reg_operand" ""))
12740          (const_int 0)))
12741    (set (match_operand:SI 0 "gpc_reg_operand" "")
12742         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12743   "TARGET_POWER && reload_completed"
12744   [(set (match_dup 0)
12745         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12746    (set (match_dup 4)
12747         (compare:CC (match_dup 0)
12748                     (const_int 0)))]
12749   "")
12750
12751 (define_insn ""
12752   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12753         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12754                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12755   "TARGET_POWER"
12756   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
12757   [(set_attr "length" "12")])
12758
12759 (define_insn_and_split "*ltu<mode>"
12760   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12761         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12762                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
12763   ""
12764   "#"
12765   ""
12766   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12767    (set (match_dup 0) (neg:P (match_dup 0)))]
12768   "")
12769
12770 (define_insn_and_split "*ltu<mode>_compare"
12771   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12772         (compare:CC
12773          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12774                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
12775          (const_int 0)))
12776    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
12777         (ltu:P (match_dup 1) (match_dup 2)))]
12778   ""
12779   "#"
12780   ""
12781   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12782    (parallel [(set (match_dup 3)
12783                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
12784               (set (match_dup 0) (neg:P (match_dup 0)))])]
12785   "")
12786
12787 (define_insn_and_split "*plus_ltu<mode>"
12788   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
12789         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12790                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
12791                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
12792   ""
12793   "#"
12794   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12795   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12796    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
12797   "")
12798
12799 (define_insn_and_split "*plus_ltu<mode>_compare"
12800   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12801         (compare:CC
12802          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12803                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
12804                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
12805          (const_int 0)))
12806    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12807         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
12808   ""
12809   "#"
12810   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12811   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12812    (parallel [(set (match_dup 4)
12813                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
12814                                (const_int 0)))
12815               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
12816   "")
12817
12818 (define_insn "*neg_ltu<mode>"
12819   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12820         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12821                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
12822   ""
12823   "@
12824    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
12825    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
12826   [(set_attr "type" "two")
12827    (set_attr "length" "8")])
12828
12829 (define_insn ""
12830   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12831         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12832                (match_operand:SI 2 "reg_or_short_operand" "rI")))
12833    (clobber (match_scratch:SI 3 "=r"))]
12834   "TARGET_POWER"
12835   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
12836    [(set_attr "length" "12")])
12837
12838 (define_insn ""
12839   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12840         (compare:CC
12841          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12842                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12843          (const_int 0)))
12844    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12845         (ge:SI (match_dup 1) (match_dup 2)))
12846    (clobber (match_scratch:SI 3 "=r,r"))]
12847   "TARGET_POWER"
12848   "@
12849    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12850    #"
12851   [(set_attr "type" "compare")
12852    (set_attr "length" "12,16")])
12853
12854 (define_split
12855   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12856         (compare:CC
12857          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12858                 (match_operand:SI 2 "reg_or_short_operand" ""))
12859          (const_int 0)))
12860    (set (match_operand:SI 0 "gpc_reg_operand" "")
12861         (ge:SI (match_dup 1) (match_dup 2)))
12862    (clobber (match_scratch:SI 3 ""))]
12863   "TARGET_POWER && reload_completed"
12864   [(parallel [(set (match_dup 0)
12865                    (ge:SI (match_dup 1) (match_dup 2)))
12866               (clobber (match_dup 3))])
12867    (set (match_dup 4)
12868         (compare:CC (match_dup 0)
12869                     (const_int 0)))]
12870   "")
12871
12872 (define_insn ""
12873   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12874         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12875                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12876                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12877   "TARGET_POWER"
12878   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
12879   [(set_attr "length" "12")])
12880
12881 (define_insn ""
12882   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12883         (compare:CC
12884          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12885                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12886                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12887          (const_int 0)))
12888    (clobber (match_scratch:SI 4 "=&r,&r"))]
12889   "TARGET_POWER"
12890   "@
12891    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12892    #"
12893   [(set_attr "type" "compare")
12894    (set_attr "length" "12,16")])
12895
12896 (define_split
12897   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12898         (compare:CC
12899          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12900                          (match_operand:SI 2 "reg_or_short_operand" ""))
12901                   (match_operand:SI 3 "gpc_reg_operand" ""))
12902          (const_int 0)))
12903    (clobber (match_scratch:SI 4 ""))]
12904   "TARGET_POWER && reload_completed"
12905   [(set (match_dup 4)
12906         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
12907                  (match_dup 3)))
12908    (set (match_dup 0)
12909         (compare:CC (match_dup 4)
12910                     (const_int 0)))]
12911   "")
12912
12913 (define_insn ""
12914   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12915         (compare:CC
12916          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12917                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12918                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12919          (const_int 0)))
12920    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12921         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12922   "TARGET_POWER"
12923   "@
12924    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12925    #"
12926   [(set_attr "type" "compare")
12927    (set_attr "length" "12,16")])
12928
12929 (define_split
12930   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12931         (compare:CC
12932          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12933                          (match_operand:SI 2 "reg_or_short_operand" ""))
12934                   (match_operand:SI 3 "gpc_reg_operand" ""))
12935          (const_int 0)))
12936    (set (match_operand:SI 0 "gpc_reg_operand" "")
12937         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12938   "TARGET_POWER && reload_completed"
12939   [(set (match_dup 0)
12940         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12941    (set (match_dup 4)
12942         (compare:CC (match_dup 0)
12943                     (const_int 0)))]
12944   "")
12945
12946 (define_insn ""
12947   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12948         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12949                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12950   "TARGET_POWER"
12951   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
12952   [(set_attr "length" "12")])
12953
12954 (define_insn "*geu<mode>"
12955   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12956         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12957                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
12958   ""
12959   "@
12960    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
12961    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12962   [(set_attr "type" "three")
12963    (set_attr "length" "12")])
12964
12965 (define_insn "*geu<mode>_compare"
12966   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12967         (compare:CC
12968          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12969                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
12970          (const_int 0)))
12971    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
12972         (geu:P (match_dup 1) (match_dup 2)))]
12973   ""
12974   "@
12975    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12976    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12977    #
12978    #"
12979   [(set_attr "type" "compare")
12980    (set_attr "length" "12,12,16,16")])
12981
12982 (define_split
12983   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12984         (compare:CC
12985          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
12986                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
12987          (const_int 0)))
12988    (set (match_operand:P 0 "gpc_reg_operand" "")
12989         (geu:P (match_dup 1) (match_dup 2)))]
12990   "reload_completed"
12991   [(set (match_dup 0)
12992         (geu:P (match_dup 1) (match_dup 2)))
12993    (set (match_dup 3)
12994         (compare:CC (match_dup 0)
12995                     (const_int 0)))]
12996   "")
12997
12998 (define_insn "*plus_geu<mode>"
12999   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
13000         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13001                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
13002                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
13003   ""
13004   "@
13005    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
13006    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
13007   [(set_attr "type" "two")
13008    (set_attr "length" "8")])
13009
13010 (define_insn ""
13011   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13012         (compare:CC
13013          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13014                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
13015                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13016          (const_int 0)))
13017    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13018   "TARGET_32BIT"
13019   "@
13020    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
13021    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
13022    #
13023    #"
13024   [(set_attr "type" "compare")
13025    (set_attr "length" "8,8,12,12")])
13026
13027 (define_split
13028   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13029         (compare:CC
13030          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13031                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
13032                   (match_operand:SI 3 "gpc_reg_operand" ""))
13033          (const_int 0)))
13034    (clobber (match_scratch:SI 4 ""))]
13035   "TARGET_32BIT && reload_completed"
13036   [(set (match_dup 4)
13037         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
13038                   (match_dup 3)))
13039    (set (match_dup 0)
13040         (compare:CC (match_dup 4)
13041                     (const_int 0)))]
13042   "")
13043
13044 (define_insn ""
13045   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13046         (compare:CC
13047          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13048                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
13049                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13050          (const_int 0)))
13051    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13052         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13053   "TARGET_32BIT"
13054   "@
13055    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
13056    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
13057    #
13058    #"
13059   [(set_attr "type" "compare")
13060    (set_attr "length" "8,8,12,12")])
13061
13062 (define_split
13063   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13064         (compare:CC
13065          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13066                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
13067                   (match_operand:SI 3 "gpc_reg_operand" ""))
13068          (const_int 0)))
13069    (set (match_operand:SI 0 "gpc_reg_operand" "")
13070         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13071   "TARGET_32BIT && reload_completed"
13072   [(set (match_dup 0)
13073         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13074    (set (match_dup 4)
13075         (compare:CC (match_dup 0)
13076                     (const_int 0)))]
13077   "")
13078
13079 (define_insn "*neg_geu<mode>"
13080   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13081         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13082                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
13083   ""
13084   "@
13085    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
13086    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
13087   [(set_attr "type" "three")
13088    (set_attr "length" "12")])
13089
13090 (define_insn "*and_neg_geu<mode>"
13091   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
13092         (and:P (neg:P
13093                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13094                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
13095                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
13096   ""
13097   "@
13098    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
13099    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
13100   [(set_attr "type" "three")
13101    (set_attr "length" "12")])
13102
13103 (define_insn ""
13104   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13105         (compare:CC
13106          (and:SI (neg:SI
13107                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13108                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
13109                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13110          (const_int 0)))
13111    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13112   "TARGET_32BIT"
13113   "@
13114    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
13115    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
13116    #
13117    #"
13118   [(set_attr "type" "compare")
13119    (set_attr "length" "12,12,16,16")])
13120
13121 (define_split
13122   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13123         (compare:CC
13124          (and:SI (neg:SI
13125                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13126                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
13127                  (match_operand:SI 3 "gpc_reg_operand" ""))
13128          (const_int 0)))
13129    (clobber (match_scratch:SI 4 ""))]
13130   "TARGET_32BIT && reload_completed"
13131   [(set (match_dup 4)
13132         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
13133                 (match_dup 3)))
13134    (set (match_dup 0)
13135         (compare:CC (match_dup 4)
13136                     (const_int 0)))]
13137   "")
13138
13139 (define_insn ""
13140   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13141         (compare:CC
13142          (and:SI (neg:SI
13143                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13144                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
13145                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13146          (const_int 0)))
13147    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13148         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13149   "TARGET_32BIT"
13150   "@
13151    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
13152    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
13153    #
13154    #"
13155   [(set_attr "type" "compare")
13156    (set_attr "length" "12,12,16,16")])
13157
13158 (define_split
13159   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13160         (compare:CC
13161          (and:SI (neg:SI
13162                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13163                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
13164                  (match_operand:SI 3 "gpc_reg_operand" ""))
13165          (const_int 0)))
13166    (set (match_operand:SI 0 "gpc_reg_operand" "")
13167         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13168   "TARGET_32BIT && reload_completed"
13169   [(set (match_dup 0)
13170         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
13171    (set (match_dup 4)
13172         (compare:CC (match_dup 0)
13173                     (const_int 0)))]
13174   "")
13175
13176 (define_insn ""
13177   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13178         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13179                (match_operand:SI 2 "reg_or_short_operand" "r")))]
13180   "TARGET_POWER"
13181   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13182   [(set_attr "length" "12")])
13183
13184 (define_insn ""
13185   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13186         (compare:CC
13187          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13188                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13189          (const_int 0)))
13190    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13191         (gt:SI (match_dup 1) (match_dup 2)))]
13192   "TARGET_POWER"
13193   "@
13194    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13195    #"
13196   [(set_attr "type" "delayed_compare")
13197    (set_attr "length" "12,16")])
13198
13199 (define_split
13200   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13201         (compare:CC
13202          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13203                 (match_operand:SI 2 "reg_or_short_operand" ""))
13204          (const_int 0)))
13205    (set (match_operand:SI 0 "gpc_reg_operand" "")
13206         (gt:SI (match_dup 1) (match_dup 2)))]
13207   "TARGET_POWER && reload_completed"
13208   [(set (match_dup 0)
13209         (gt:SI (match_dup 1) (match_dup 2)))
13210    (set (match_dup 3)
13211         (compare:CC (match_dup 0)
13212                     (const_int 0)))]
13213   "")
13214
13215 (define_insn "*plus_gt0<mode>"
13216   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13217         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
13218                       (const_int 0))
13219                  (match_operand:P 2 "gpc_reg_operand" "r")))]
13220   ""
13221   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
13222   [(set_attr "type" "three")
13223    (set_attr "length" "12")])
13224
13225 (define_insn ""
13226   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13227         (compare:CC
13228          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13229                          (const_int 0))
13230                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13231          (const_int 0)))
13232    (clobber (match_scratch:SI 3 "=&r,&r"))]
13233   "TARGET_32BIT"
13234   "@
13235    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
13236    #"
13237   [(set_attr "type" "compare")
13238    (set_attr "length" "12,16")])
13239
13240 (define_split
13241   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13242         (compare:CC
13243          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13244                          (const_int 0))
13245                   (match_operand:SI 2 "gpc_reg_operand" ""))
13246          (const_int 0)))
13247    (clobber (match_scratch:SI 3 ""))]
13248   "TARGET_32BIT && reload_completed"
13249   [(set (match_dup 3)
13250         (plus:SI (gt:SI (match_dup 1) (const_int 0))
13251                   (match_dup 2)))
13252    (set (match_dup 0)
13253         (compare:CC (match_dup 3)
13254                     (const_int 0)))]
13255   "")
13256
13257 (define_insn ""
13258   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13259         (compare:CC
13260          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13261                          (const_int 0))
13262                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13263          (const_int 0)))
13264    (clobber (match_scratch:DI 3 "=&r,&r"))]
13265   "TARGET_64BIT"
13266   "@
13267    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
13268    #"
13269   [(set_attr "type" "compare")
13270    (set_attr "length" "12,16")])
13271
13272 (define_split
13273   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13274         (compare:CC
13275          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13276                          (const_int 0))
13277                   (match_operand:DI 2 "gpc_reg_operand" ""))
13278          (const_int 0)))
13279    (clobber (match_scratch:DI 3 ""))]
13280   "TARGET_64BIT && reload_completed"
13281   [(set (match_dup 3)
13282         (plus:DI (gt:DI (match_dup 1) (const_int 0))
13283                  (match_dup 2)))
13284    (set (match_dup 0)
13285         (compare:CC (match_dup 3)
13286                     (const_int 0)))]
13287   "")
13288
13289 (define_insn ""
13290   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13291         (compare:CC
13292          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13293                          (const_int 0))
13294                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13295          (const_int 0)))
13296    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13297         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13298   "TARGET_32BIT"
13299   "@
13300    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
13301    #"
13302   [(set_attr "type" "compare")
13303    (set_attr "length" "12,16")])
13304
13305 (define_split
13306   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13307         (compare:CC
13308          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13309                          (const_int 0))
13310                   (match_operand:SI 2 "gpc_reg_operand" ""))
13311          (const_int 0)))
13312    (set (match_operand:SI 0 "gpc_reg_operand" "")
13313         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13314   "TARGET_32BIT && reload_completed"
13315   [(set (match_dup 0)
13316         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
13317    (set (match_dup 3)
13318         (compare:CC (match_dup 0)
13319                     (const_int 0)))]
13320   "")
13321
13322 (define_insn ""
13323   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13324         (compare:CC
13325          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13326                          (const_int 0))
13327                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13328          (const_int 0)))
13329    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13330         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13331   "TARGET_64BIT"
13332   "@
13333    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
13334    #"
13335   [(set_attr "type" "compare")
13336    (set_attr "length" "12,16")])
13337
13338 (define_split
13339   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13340         (compare:CC
13341          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13342                          (const_int 0))
13343                   (match_operand:DI 2 "gpc_reg_operand" ""))
13344          (const_int 0)))
13345    (set (match_operand:DI 0 "gpc_reg_operand" "")
13346         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13347   "TARGET_64BIT && reload_completed"
13348   [(set (match_dup 0)
13349         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
13350    (set (match_dup 3)
13351         (compare:CC (match_dup 0)
13352                     (const_int 0)))]
13353   "")
13354
13355 (define_insn ""
13356   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13357         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13358                         (match_operand:SI 2 "reg_or_short_operand" "r"))
13359                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13360   "TARGET_POWER"
13361   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13362   [(set_attr "length" "12")])
13363
13364 (define_insn ""
13365   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13366         (compare:CC
13367          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13368                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13369                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13370          (const_int 0)))
13371    (clobber (match_scratch:SI 4 "=&r,&r"))]
13372   "TARGET_POWER"
13373   "@
13374    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13375    #"
13376   [(set_attr "type" "compare")
13377    (set_attr "length" "12,16")])
13378
13379 (define_split
13380   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13381         (compare:CC
13382          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13383                          (match_operand:SI 2 "reg_or_short_operand" ""))
13384                   (match_operand:SI 3 "gpc_reg_operand" ""))
13385          (const_int 0)))
13386    (clobber (match_scratch:SI 4 ""))]
13387   "TARGET_POWER && reload_completed"
13388   [(set (match_dup 4)
13389         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13390    (set (match_dup 0)
13391         (compare:CC (match_dup 4)
13392                     (const_int 0)))]
13393   "")
13394
13395 (define_insn ""
13396   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13397         (compare:CC
13398          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13399                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13400                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13401          (const_int 0)))
13402    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13403         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13404   "TARGET_POWER"
13405   "@
13406    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13407    #"
13408   [(set_attr "type" "compare")
13409    (set_attr "length" "12,16")])
13410
13411 (define_split
13412   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13413         (compare:CC
13414          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13415                          (match_operand:SI 2 "reg_or_short_operand" ""))
13416                   (match_operand:SI 3 "gpc_reg_operand" ""))
13417          (const_int 0)))
13418    (set (match_operand:SI 0 "gpc_reg_operand" "")
13419         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13420   "TARGET_POWER && reload_completed"
13421   [(set (match_dup 0)
13422         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13423    (set (match_dup 4)
13424         (compare:CC (match_dup 0)
13425                     (const_int 0)))]
13426   "")
13427
13428 (define_insn ""
13429   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13430         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13431                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
13432   "TARGET_POWER"
13433   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13434   [(set_attr "length" "12")])
13435
13436 (define_insn_and_split "*gtu<mode>"
13437   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13438         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
13439                (match_operand:P 2 "reg_or_short_operand" "rI")))]
13440   ""
13441   "#"
13442   ""
13443   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13444    (set (match_dup 0) (neg:P (match_dup 0)))]
13445   "")
13446
13447 (define_insn_and_split "*gtu<mode>_compare"
13448   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13449         (compare:CC
13450          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13451                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
13452          (const_int 0)))
13453    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13454         (gtu:P (match_dup 1) (match_dup 2)))]
13455   ""
13456   "#"
13457   ""
13458   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13459    (parallel [(set (match_dup 3)
13460                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
13461               (set (match_dup 0) (neg:P (match_dup 0)))])]
13462   "")
13463
13464 (define_insn_and_split "*plus_gtu<mode>"
13465   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13466         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
13467                        (match_operand:P 2 "reg_or_short_operand" "rI"))
13468                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
13469   ""
13470   "#"
13471   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13472   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13473    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
13474   "")
13475
13476 (define_insn_and_split "*plus_gtu<mode>_compare"
13477   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13478         (compare:CC
13479          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13480                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
13481                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
13482          (const_int 0)))
13483    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13484         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
13485   ""
13486   "#"
13487   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13488   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13489    (parallel [(set (match_dup 4)
13490                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
13491                                (const_int 0)))
13492               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
13493   "")
13494
13495 (define_insn "*neg_gtu<mode>"
13496   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13497         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
13498                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
13499   ""
13500   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
13501   [(set_attr "type" "two")
13502    (set_attr "length" "8")])
13503
13504 \f
13505 ;; Define both directions of branch and return.  If we need a reload
13506 ;; register, we'd rather use CR0 since it is much easier to copy a
13507 ;; register CC value to there.
13508
13509 (define_insn ""
13510   [(set (pc)
13511         (if_then_else (match_operator 1 "branch_comparison_operator"
13512                                       [(match_operand 2
13513                                                       "cc_reg_operand" "y")
13514                                        (const_int 0)])
13515                       (label_ref (match_operand 0 "" ""))
13516                       (pc)))]
13517   ""
13518   "*
13519 {
13520   return output_cbranch (operands[1], \"%l0\", 0, insn);
13521 }"
13522   [(set_attr "type" "branch")])
13523
13524 (define_insn ""
13525   [(set (pc)
13526         (if_then_else (match_operator 0 "branch_comparison_operator"
13527                                       [(match_operand 1
13528                                                       "cc_reg_operand" "y")
13529                                        (const_int 0)])
13530                       (return)
13531                       (pc)))]
13532   "direct_return ()"
13533   "*
13534 {
13535   return output_cbranch (operands[0], NULL, 0, insn);
13536 }"
13537   [(set_attr "type" "jmpreg")
13538    (set_attr "length" "4")])
13539
13540 (define_insn ""
13541   [(set (pc)
13542         (if_then_else (match_operator 1 "branch_comparison_operator"
13543                                       [(match_operand 2
13544                                                       "cc_reg_operand" "y")
13545                                        (const_int 0)])
13546                       (pc)
13547                       (label_ref (match_operand 0 "" ""))))]
13548   ""
13549   "*
13550 {
13551   return output_cbranch (operands[1], \"%l0\", 1, insn);
13552 }"
13553   [(set_attr "type" "branch")])
13554
13555 (define_insn ""
13556   [(set (pc)
13557         (if_then_else (match_operator 0 "branch_comparison_operator"
13558                                       [(match_operand 1
13559                                                       "cc_reg_operand" "y")
13560                                        (const_int 0)])
13561                       (pc)
13562                       (return)))]
13563   "direct_return ()"
13564   "*
13565 {
13566   return output_cbranch (operands[0], NULL, 1, insn);
13567 }"
13568   [(set_attr "type" "jmpreg")
13569    (set_attr "length" "4")])
13570
13571 ;; Logic on condition register values.
13572
13573 ; This pattern matches things like
13574 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13575 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
13576 ;                                  (const_int 1)))
13577 ; which are generated by the branch logic.
13578 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
13579
13580 (define_insn "*cceq_ior_compare"
13581   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13582         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13583                         [(match_operator:SI 2
13584                                       "branch_positive_comparison_operator"
13585                                       [(match_operand 3
13586                                                       "cc_reg_operand" "y,y")
13587                                        (const_int 0)])
13588                          (match_operator:SI 4
13589                                       "branch_positive_comparison_operator"
13590                                       [(match_operand 5
13591                                                       "cc_reg_operand" "0,y")
13592                                        (const_int 0)])])
13593                       (const_int 1)))]
13594   ""
13595   "cr%q1 %E0,%j2,%j4"
13596   [(set_attr "type" "cr_logical,delayed_cr")])
13597
13598 ; Why is the constant -1 here, but 1 in the previous pattern?
13599 ; Because ~1 has all but the low bit set.
13600 (define_insn ""
13601   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13602         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
13603                         [(not:SI (match_operator:SI 2
13604                                       "branch_positive_comparison_operator"
13605                                       [(match_operand 3
13606                                                       "cc_reg_operand" "y,y")
13607                                        (const_int 0)]))
13608                          (match_operator:SI 4
13609                                 "branch_positive_comparison_operator"
13610                                 [(match_operand 5
13611                                                 "cc_reg_operand" "0,y")
13612                                  (const_int 0)])])
13613                       (const_int -1)))]
13614   ""
13615   "cr%q1 %E0,%j2,%j4"
13616   [(set_attr "type" "cr_logical,delayed_cr")])
13617
13618 (define_insn "*cceq_rev_compare"
13619   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13620         (compare:CCEQ (match_operator:SI 1
13621                                       "branch_positive_comparison_operator"
13622                                       [(match_operand 2
13623                                                       "cc_reg_operand" "0,y")
13624                                        (const_int 0)])
13625                       (const_int 0)))]
13626   ""
13627   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
13628   [(set_attr "type" "cr_logical,delayed_cr")])
13629
13630 ;; If we are comparing the result of two comparisons, this can be done
13631 ;; using creqv or crxor.
13632
13633 (define_insn_and_split ""
13634   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13635         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13636                               [(match_operand 2 "cc_reg_operand" "y")
13637                                (const_int 0)])
13638                       (match_operator 3 "branch_comparison_operator"
13639                               [(match_operand 4 "cc_reg_operand" "y")
13640                                (const_int 0)])))]
13641   ""
13642   "#"
13643   ""
13644   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13645                                     (match_dup 5)))]
13646   "
13647 {
13648   int positive_1, positive_2;
13649
13650   positive_1 = branch_positive_comparison_operator (operands[1],
13651                                                     GET_MODE (operands[1]));
13652   positive_2 = branch_positive_comparison_operator (operands[3],
13653                                                     GET_MODE (operands[3]));
13654
13655   if (! positive_1)
13656     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
13657                                                             GET_CODE (operands[1])),
13658                                   SImode,
13659                                   operands[2], const0_rtx);
13660   else if (GET_MODE (operands[1]) != SImode)
13661     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
13662                                   operands[2], const0_rtx);
13663
13664   if (! positive_2)
13665     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
13666                                                             GET_CODE (operands[3])),
13667                                   SImode,
13668                                   operands[4], const0_rtx);
13669   else if (GET_MODE (operands[3]) != SImode)
13670     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
13671                                   operands[4], const0_rtx);
13672
13673   if (positive_1 == positive_2)
13674     {
13675       operands[1] = gen_rtx_NOT (SImode, operands[1]);
13676       operands[5] = constm1_rtx;
13677     }
13678   else
13679     {
13680       operands[5] = const1_rtx;
13681     }
13682 }")
13683
13684 ;; Unconditional branch and return.
13685
13686 (define_insn "jump"
13687   [(set (pc)
13688         (label_ref (match_operand 0 "" "")))]
13689   ""
13690   "b %l0"
13691   [(set_attr "type" "branch")])
13692
13693 (define_insn "return"
13694   [(return)]
13695   "direct_return ()"
13696   "{br|blr}"
13697   [(set_attr "type" "jmpreg")])
13698
13699 (define_expand "indirect_jump"
13700   [(set (pc) (match_operand 0 "register_operand" ""))])
13701
13702 (define_insn "*indirect_jump<mode>"
13703   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
13704   ""
13705   "@
13706    bctr
13707    {br|blr}"
13708   [(set_attr "type" "jmpreg")])
13709
13710 ;; Table jump for switch statements:
13711 (define_expand "tablejump"
13712   [(use (match_operand 0 "" ""))
13713    (use (label_ref (match_operand 1 "" "")))]
13714   ""
13715   "
13716 {
13717   if (TARGET_32BIT)
13718     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
13719   else
13720     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
13721   DONE;
13722 }")
13723
13724 (define_expand "tablejumpsi"
13725   [(set (match_dup 3)
13726         (plus:SI (match_operand:SI 0 "" "")
13727                  (match_dup 2)))
13728    (parallel [(set (pc) (match_dup 3))
13729               (use (label_ref (match_operand 1 "" "")))])]
13730   "TARGET_32BIT"
13731   "
13732 { operands[0] = force_reg (SImode, operands[0]);
13733   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
13734   operands[3] = gen_reg_rtx (SImode);
13735 }")
13736
13737 (define_expand "tablejumpdi"
13738   [(set (match_dup 4)
13739         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "rm")))
13740    (set (match_dup 3)
13741         (plus:DI (match_dup 4)
13742                  (match_dup 2)))
13743    (parallel [(set (pc) (match_dup 3))
13744               (use (label_ref (match_operand 1 "" "")))])]
13745   "TARGET_64BIT"
13746   "
13747 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
13748   operands[3] = gen_reg_rtx (DImode);
13749   operands[4] = gen_reg_rtx (DImode);
13750 }")
13751
13752 (define_insn "*tablejump<mode>_internal1"
13753   [(set (pc)
13754         (match_operand:P 0 "register_operand" "c,*l"))
13755    (use (label_ref (match_operand 1 "" "")))]
13756   ""
13757   "@
13758    bctr
13759    {br|blr}"
13760   [(set_attr "type" "jmpreg")])
13761
13762 (define_insn "nop"
13763   [(const_int 0)]
13764   ""
13765   "{cror 0,0,0|nop}")
13766 \f
13767 ;; Define the subtract-one-and-jump insns, starting with the template
13768 ;; so loop.c knows what to generate.
13769
13770 (define_expand "doloop_end"
13771   [(use (match_operand 0 "" ""))        ; loop pseudo
13772    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
13773    (use (match_operand 2 "" ""))        ; max iterations
13774    (use (match_operand 3 "" ""))        ; loop level
13775    (use (match_operand 4 "" ""))]       ; label
13776   ""
13777   "
13778 {
13779   /* Only use this on innermost loops.  */
13780   if (INTVAL (operands[3]) > 1)
13781     FAIL;
13782   if (TARGET_64BIT)
13783     {
13784       if (GET_MODE (operands[0]) != DImode)
13785         FAIL;
13786       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
13787     }
13788   else
13789     {
13790       if (GET_MODE (operands[0]) != SImode)
13791         FAIL;
13792       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
13793     }
13794   DONE;
13795 }")
13796
13797 (define_expand "ctr<mode>"
13798   [(parallel [(set (pc)
13799                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
13800                                      (const_int 1))
13801                                  (label_ref (match_operand 1 "" ""))
13802                                  (pc)))
13803               (set (match_dup 0)
13804                    (plus:P (match_dup 0)
13805                             (const_int -1)))
13806               (clobber (match_scratch:CC 2 ""))
13807               (clobber (match_scratch:P 3 ""))])]
13808   ""
13809   "")
13810
13811 ;; We need to be able to do this for any operand, including MEM, or we
13812 ;; will cause reload to blow up since we don't allow output reloads on
13813 ;; JUMP_INSNs.
13814 ;; For the length attribute to be calculated correctly, the
13815 ;; label MUST be operand 0.
13816
13817 (define_insn "*ctr<mode>_internal1"
13818   [(set (pc)
13819         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13820                           (const_int 1))
13821                       (label_ref (match_operand 0 "" ""))
13822                       (pc)))
13823    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13824         (plus:P (match_dup 1)
13825                  (const_int -1)))
13826    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13827    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13828   ""
13829   "*
13830 {
13831   if (which_alternative != 0)
13832     return \"#\";
13833   else if (get_attr_length (insn) == 4)
13834     return \"{bdn|bdnz} %l0\";
13835   else
13836     return \"bdz $+8\;b %l0\";
13837 }"
13838   [(set_attr "type" "branch")
13839    (set_attr "length" "*,12,16,16")])
13840
13841 (define_insn "*ctr<mode>_internal2"
13842   [(set (pc)
13843         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13844                           (const_int 1))
13845                       (pc)
13846                       (label_ref (match_operand 0 "" ""))))
13847    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13848         (plus:P (match_dup 1)
13849                  (const_int -1)))
13850    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13851    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13852   ""
13853   "*
13854 {
13855   if (which_alternative != 0)
13856     return \"#\";
13857   else if (get_attr_length (insn) == 4)
13858     return \"bdz %l0\";
13859   else
13860     return \"{bdn|bdnz} $+8\;b %l0\";
13861 }"
13862   [(set_attr "type" "branch")
13863    (set_attr "length" "*,12,16,16")])
13864
13865 ;; Similar but use EQ
13866
13867 (define_insn "*ctr<mode>_internal5"
13868   [(set (pc)
13869         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13870                           (const_int 1))
13871                       (label_ref (match_operand 0 "" ""))
13872                       (pc)))
13873    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13874         (plus:P (match_dup 1)
13875                  (const_int -1)))
13876    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13877    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13878   ""
13879   "*
13880 {
13881   if (which_alternative != 0)
13882     return \"#\";
13883   else if (get_attr_length (insn) == 4)
13884     return \"bdz %l0\";
13885   else
13886     return \"{bdn|bdnz} $+8\;b %l0\";
13887 }"
13888   [(set_attr "type" "branch")
13889    (set_attr "length" "*,12,16,16")])
13890
13891 (define_insn "*ctr<mode>_internal6"
13892   [(set (pc)
13893         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13894                           (const_int 1))
13895                       (pc)
13896                       (label_ref (match_operand 0 "" ""))))
13897    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13898         (plus:P (match_dup 1)
13899                  (const_int -1)))
13900    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13901    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13902   ""
13903   "*
13904 {
13905   if (which_alternative != 0)
13906     return \"#\";
13907   else if (get_attr_length (insn) == 4)
13908     return \"{bdn|bdnz} %l0\";
13909   else
13910     return \"bdz $+8\;b %l0\";
13911 }"
13912   [(set_attr "type" "branch")
13913    (set_attr "length" "*,12,16,16")])
13914
13915 ;; Now the splitters if we could not allocate the CTR register
13916
13917 (define_split
13918   [(set (pc)
13919         (if_then_else (match_operator 2 "comparison_operator"
13920                                       [(match_operand:P 1 "gpc_reg_operand" "")
13921                                        (const_int 1)])
13922                       (match_operand 5 "" "")
13923                       (match_operand 6 "" "")))
13924    (set (match_operand:P 0 "gpc_reg_operand" "")
13925         (plus:P (match_dup 1) (const_int -1)))
13926    (clobber (match_scratch:CC 3 ""))
13927    (clobber (match_scratch:P 4 ""))]
13928   "reload_completed"
13929   [(parallel [(set (match_dup 3)
13930                    (compare:CC (plus:P (match_dup 1)
13931                                         (const_int -1))
13932                                (const_int 0)))
13933               (set (match_dup 0)
13934                    (plus:P (match_dup 1)
13935                             (const_int -1)))])
13936    (set (pc) (if_then_else (match_dup 7)
13937                            (match_dup 5)
13938                            (match_dup 6)))]
13939   "
13940 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
13941                                 operands[3], const0_rtx); }")
13942
13943 (define_split
13944   [(set (pc)
13945         (if_then_else (match_operator 2 "comparison_operator"
13946                                       [(match_operand:P 1 "gpc_reg_operand" "")
13947                                        (const_int 1)])
13948                       (match_operand 5 "" "")
13949                       (match_operand 6 "" "")))
13950    (set (match_operand:P 0 "nonimmediate_operand" "")
13951         (plus:P (match_dup 1) (const_int -1)))
13952    (clobber (match_scratch:CC 3 ""))
13953    (clobber (match_scratch:P 4 ""))]
13954   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
13955   [(parallel [(set (match_dup 3)
13956                    (compare:CC (plus:P (match_dup 1)
13957                                         (const_int -1))
13958                                (const_int 0)))
13959               (set (match_dup 4)
13960                    (plus:P (match_dup 1)
13961                             (const_int -1)))])
13962    (set (match_dup 0)
13963         (match_dup 4))
13964    (set (pc) (if_then_else (match_dup 7)
13965                            (match_dup 5)
13966                            (match_dup 6)))]
13967   "
13968 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
13969                                 operands[3], const0_rtx); }")
13970 \f
13971 (define_insn "trap"
13972   [(trap_if (const_int 1) (const_int 0))]
13973   ""
13974   "{t 31,0,0|trap}")
13975
13976 (define_expand "conditional_trap"
13977   [(trap_if (match_operator 0 "trap_comparison_operator"
13978                             [(match_dup 2) (match_dup 3)])
13979             (match_operand 1 "const_int_operand" ""))]
13980   ""
13981   "if (rs6000_compare_fp_p || operands[1] != const0_rtx) FAIL;
13982    operands[2] = rs6000_compare_op0;
13983    operands[3] = rs6000_compare_op1;")
13984
13985 (define_insn ""
13986   [(trap_if (match_operator 0 "trap_comparison_operator"
13987                             [(match_operand:GPR 1 "register_operand" "r")
13988                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
13989             (const_int 0))]
13990   ""
13991   "{t|t<wd>}%V0%I2 %1,%2")
13992 \f
13993 ;; Insns related to generating the function prologue and epilogue.
13994
13995 (define_expand "prologue"
13996   [(use (const_int 0))]
13997   "TARGET_SCHED_PROLOG"
13998   "
13999 {
14000       rs6000_emit_prologue ();
14001       DONE;
14002 }")
14003
14004 (define_insn "*movesi_from_cr_one"
14005   [(match_parallel 0 "mfcr_operation"
14006                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14007                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14008                                      (match_operand 3 "immediate_operand" "n")]
14009                           UNSPEC_MOVESI_FROM_CR))])]
14010   "TARGET_MFCRF"
14011   "*
14012 {
14013   int mask = 0;
14014   int i;
14015   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14016   {
14017     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14018     operands[4] = GEN_INT (mask);
14019     output_asm_insn (\"mfcr %1,%4\", operands);
14020   }
14021   return \"\";
14022 }"
14023   [(set_attr "type" "mfcrf")])
14024
14025 (define_insn "movesi_from_cr"
14026   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14027         (unspec:SI [(reg:CC 68) (reg:CC 69) (reg:CC 70) (reg:CC 71)
14028                     (reg:CC 72) (reg:CC 73) (reg:CC 74) (reg:CC 75)]
14029                    UNSPEC_MOVESI_FROM_CR))]
14030   ""
14031   "mfcr %0"
14032   [(set_attr "type" "mfcr")])
14033
14034 (define_insn "*stmw"
14035   [(match_parallel 0 "stmw_operation"
14036                    [(set (match_operand:SI 1 "memory_operand" "=m")
14037                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14038   "TARGET_MULTIPLE"
14039   "{stm|stmw} %2,%1"
14040   [(set_attr "type" "store_ux")])
14041
14042 (define_insn "*save_fpregs_<mode>"
14043   [(match_parallel 0 "any_parallel_operand"
14044                    [(clobber (match_operand:P 1 "register_operand" "=l"))
14045                     (use (match_operand:P 2 "call_operand" "s"))
14046                     (set (match_operand:DF 3 "memory_operand" "=m")
14047                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14048   ""
14049   "bl %z2"
14050   [(set_attr "type" "branch")
14051    (set_attr "length" "4")])
14052
14053 ; These are to explain that changes to the stack pointer should
14054 ; not be moved over stores to stack memory.
14055 (define_insn "stack_tie"
14056   [(set (match_operand:BLK 0 "memory_operand" "+m")
14057         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
14058   ""
14059   ""
14060   [(set_attr "length" "0")])
14061
14062
14063 (define_expand "epilogue"
14064   [(use (const_int 0))]
14065   "TARGET_SCHED_PROLOG"
14066   "
14067 {
14068       rs6000_emit_epilogue (FALSE);
14069       DONE;
14070 }")
14071
14072 ; On some processors, doing the mtcrf one CC register at a time is
14073 ; faster (like on the 604e).  On others, doing them all at once is
14074 ; faster; for instance, on the 601 and 750.
14075
14076 (define_expand "movsi_to_cr_one"
14077   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14078         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14079                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
14080   ""
14081   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
14082
14083 (define_insn "*movsi_to_cr"
14084   [(match_parallel 0 "mtcrf_operation"
14085                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14086                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14087                                      (match_operand 3 "immediate_operand" "n")]
14088                                     UNSPEC_MOVESI_TO_CR))])]
14089  ""
14090  "*
14091 {
14092   int mask = 0;
14093   int i;
14094   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14095     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14096   operands[4] = GEN_INT (mask);
14097   return \"mtcrf %4,%2\";
14098 }"
14099   [(set_attr "type" "mtcr")])
14100
14101 (define_insn "*mtcrfsi"
14102   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14103         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14104                     (match_operand 2 "immediate_operand" "n")]
14105                    UNSPEC_MOVESI_TO_CR))]
14106   "GET_CODE (operands[0]) == REG
14107    && CR_REGNO_P (REGNO (operands[0]))
14108    && GET_CODE (operands[2]) == CONST_INT
14109    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
14110   "mtcrf %R0,%1"
14111   [(set_attr "type" "mtcr")])
14112
14113 ; The load-multiple instructions have similar properties.
14114 ; Note that "load_multiple" is a name known to the machine-independent
14115 ; code that actually corresponds to the PowerPC load-string.
14116
14117 (define_insn "*lmw"
14118   [(match_parallel 0 "lmw_operation"
14119                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14120                          (match_operand:SI 2 "memory_operand" "m"))])]
14121   "TARGET_MULTIPLE"
14122   "{lm|lmw} %1,%2"
14123   [(set_attr "type" "load_ux")])
14124
14125 (define_insn "*return_internal_<mode>"
14126   [(return)
14127    (use (match_operand:P 0 "register_operand" "lc"))]
14128   ""
14129   "b%T0"
14130   [(set_attr "type" "jmpreg")])
14131
14132 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
14133 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
14134
14135 (define_insn "*return_and_restore_fpregs_<mode>"
14136  [(match_parallel 0 "any_parallel_operand"
14137                   [(return)
14138                    (use (match_operand:P 1 "register_operand" "l"))
14139                    (use (match_operand:P 2 "call_operand" "s"))
14140                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14141                         (match_operand:DF 4 "memory_operand" "m"))])]
14142  ""
14143  "b %z2")
14144
14145 ; This is used in compiling the unwind routines.
14146 (define_expand "eh_return"
14147   [(use (match_operand 0 "general_operand" ""))]
14148   ""
14149   "
14150 {
14151   if (TARGET_32BIT)
14152     emit_insn (gen_eh_set_lr_si (operands[0]));
14153   else
14154     emit_insn (gen_eh_set_lr_di (operands[0]));
14155   DONE;
14156 }")
14157
14158 ; We can't expand this before we know where the link register is stored.
14159 (define_insn "eh_set_lr_<mode>"
14160   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
14161                     UNSPECV_EH_RR)
14162    (clobber (match_scratch:P 1 "=&b"))]
14163   ""
14164   "#")
14165
14166 (define_split
14167   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
14168    (clobber (match_scratch 1 ""))]
14169   "reload_completed"
14170   [(const_int 0)]
14171   "
14172 {
14173   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
14174   DONE;
14175 }")
14176
14177 (define_insn "prefetch"
14178   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
14179              (match_operand:SI 1 "const_int_operand" "n")
14180              (match_operand:SI 2 "const_int_operand" "n"))]
14181   "TARGET_POWERPC"
14182   "*
14183 {
14184   if (GET_CODE (operands[0]) == REG)
14185     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
14186   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
14187 }"
14188   [(set_attr "type" "load")])
14189 \f
14190
14191 (include "sync.md")
14192 (include "altivec.md")
14193 (include "spe.md")