OSDN Git Service

2006-01-27 Jakub Jelinek <jakub@redhat.com>
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / rs6000.md
1 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
2 ;; Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
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_eq_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   ])
73
74 ;;
75 ;; UNSPEC_VOLATILE usage
76 ;;
77
78 (define_constants
79   [(UNSPECV_BLOCK               0)
80    (UNSPECV_LL                  1)      ; load-locked
81    (UNSPECV_SC                  2)      ; store-conditional
82    (UNSPECV_EH_RR               9)      ; eh_reg_restore
83   ])
84 \f
85 ;; Define an insn type attribute.  This is used in function unit delay
86 ;; computations.
87 (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"
88   (const_string "integer"))
89
90 ;; Length (in bytes).
91 ; '(pc)' in the following doesn't include the instruction itself; it is
92 ; calculated as if the instruction had zero size.
93 (define_attr "length" ""
94   (if_then_else (eq_attr "type" "branch")
95                 (if_then_else (and (ge (minus (match_dup 0) (pc))
96                                        (const_int -32768))
97                                    (lt (minus (match_dup 0) (pc))
98                                        (const_int 32764)))
99                               (const_int 4)
100                               (const_int 8))
101                 (const_int 4)))
102
103 ;; Processor type -- this attribute must exactly match the processor_type
104 ;; enumeration in rs6000.h.
105
106 (define_attr "cpu" "rios1,rios2,rs64a,mpccore,ppc403,ppc405,ppc440,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,power4,power5"
107   (const (symbol_ref "rs6000_cpu_attr")))
108
109 (automata_option "ndfa")
110
111 (include "rios1.md")
112 (include "rios2.md")
113 (include "rs64.md")
114 (include "mpc.md")
115 (include "40x.md")
116 (include "440.md")
117 (include "603.md")
118 (include "6xx.md")
119 (include "7xx.md")
120 (include "7450.md")
121 (include "8540.md")
122 (include "power4.md")
123 (include "power5.md")
124
125 (include "predicates.md")
126
127 (include "darwin.md")
128
129 \f
130 ;; Mode macros
131
132 ; This mode macro allows :GPR to be used to indicate the allowable size
133 ; of whole values in GPRs.
134 (define_mode_macro GPR [SI (DI "TARGET_POWERPC64")])
135
136 ; Any supported integer mode.
137 (define_mode_macro INT [QI HI SI DI TI])
138
139 ; Any supported integer mode that fits in one register.
140 (define_mode_macro INT1 [QI HI SI (DI "TARGET_POWERPC64")])
141
142 ; extend modes for DImode
143 (define_mode_macro QHSI [QI HI SI])
144
145 ; SImode or DImode, even if DImode doesn't fit in GPRs.
146 (define_mode_macro SDI [SI DI])
147
148 ; The size of a pointer.  Also, the size of the value that a record-condition
149 ; (one with a '.') will compare.
150 (define_mode_macro P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
151
152 ; Any hardware-supported floating-point mode
153 (define_mode_macro FP [(SF "TARGET_HARD_FLOAT")
154   (DF "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)")
155   (TF "!TARGET_IEEEQUAD
156    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128")])
157
158 ; Various instructions that come in SI and DI forms.
159 ; A generic w/d attribute, for things like cmpw/cmpd.
160 (define_mode_attr wd [(QI "b") (HI "h") (SI "w") (DI "d")])
161
162 ; DImode bits
163 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
164
165 \f
166 ;; Start with fixed-point load and store insns.  Here we put only the more
167 ;; complex forms.  Basic data transfer is done later.
168
169 (define_expand "zero_extend<mode>di2"
170   [(set (match_operand:DI 0 "gpc_reg_operand" "")
171         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
172   "TARGET_POWERPC64"
173   "")
174
175 (define_insn "*zero_extend<mode>di2_internal1"
176   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
177         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
178   "TARGET_POWERPC64"
179   "@
180    l<wd>z%U1%X1 %0,%1
181    rldicl %0,%1,0,<dbits>"
182   [(set_attr "type" "load,*")])
183
184 (define_insn "*zero_extend<mode>di2_internal2"
185   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
186         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
187                     (const_int 0)))
188    (clobber (match_scratch:DI 2 "=r,r"))]
189   "TARGET_64BIT"
190   "@
191    rldicl. %2,%1,0,<dbits>
192    #"
193   [(set_attr "type" "compare")
194    (set_attr "length" "4,8")])
195
196 (define_split
197   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
198         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
199                     (const_int 0)))
200    (clobber (match_scratch:DI 2 ""))]
201   "TARGET_POWERPC64 && reload_completed"
202   [(set (match_dup 2)
203         (zero_extend:DI (match_dup 1)))
204    (set (match_dup 0)
205         (compare:CC (match_dup 2)
206                     (const_int 0)))]
207   "")
208
209 (define_insn "*zero_extend<mode>di2_internal3"
210   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
211         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
212                     (const_int 0)))
213    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
214         (zero_extend:DI (match_dup 1)))]
215   "TARGET_64BIT"
216   "@
217    rldicl. %0,%1,0,<dbits>
218    #"
219   [(set_attr "type" "compare")
220    (set_attr "length" "4,8")])
221
222 (define_split
223   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
224         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
225                     (const_int 0)))
226    (set (match_operand:DI 0 "gpc_reg_operand" "")
227         (zero_extend:DI (match_dup 1)))]
228   "TARGET_POWERPC64 && reload_completed"
229   [(set (match_dup 0)
230         (zero_extend:DI (match_dup 1)))
231    (set (match_dup 2)
232         (compare:CC (match_dup 0)
233                     (const_int 0)))]
234   "")
235
236 (define_insn "extendqidi2"
237   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
238         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
239   "TARGET_POWERPC64"
240   "extsb %0,%1")
241
242 (define_insn ""
243   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
244         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
245                     (const_int 0)))
246    (clobber (match_scratch:DI 2 "=r,r"))]
247   "TARGET_64BIT"
248   "@
249    extsb. %2,%1
250    #"
251   [(set_attr "type" "compare")
252    (set_attr "length" "4,8")])
253
254 (define_split
255   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
256         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
257                     (const_int 0)))
258    (clobber (match_scratch:DI 2 ""))]
259   "TARGET_POWERPC64 && reload_completed"
260   [(set (match_dup 2)
261         (sign_extend:DI (match_dup 1)))
262    (set (match_dup 0)
263         (compare:CC (match_dup 2)
264                     (const_int 0)))]
265   "")
266
267 (define_insn ""
268   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
269         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
270                     (const_int 0)))
271    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
272         (sign_extend:DI (match_dup 1)))]
273   "TARGET_64BIT"
274   "@
275    extsb. %0,%1
276    #"
277   [(set_attr "type" "compare")
278    (set_attr "length" "4,8")])
279
280 (define_split
281   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
282         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
283                     (const_int 0)))
284    (set (match_operand:DI 0 "gpc_reg_operand" "")
285         (sign_extend:DI (match_dup 1)))]
286   "TARGET_POWERPC64 && reload_completed"
287   [(set (match_dup 0)
288         (sign_extend:DI (match_dup 1)))
289    (set (match_dup 2)
290         (compare:CC (match_dup 0)
291                     (const_int 0)))]
292   "")
293
294 (define_expand "extendhidi2"
295   [(set (match_operand:DI 0 "gpc_reg_operand" "")
296         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
297   "TARGET_POWERPC64"
298   "")
299
300 (define_insn ""
301   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
302         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
303   "TARGET_POWERPC64"
304   "@
305    lha%U1%X1 %0,%1
306    extsh %0,%1"
307   [(set_attr "type" "load_ext,*")])
308
309 (define_insn ""
310   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
311         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
312                     (const_int 0)))
313    (clobber (match_scratch:DI 2 "=r,r"))]
314   "TARGET_64BIT"
315   "@
316    extsh. %2,%1
317    #"
318   [(set_attr "type" "compare")
319    (set_attr "length" "4,8")])
320
321 (define_split
322   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
323         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
324                     (const_int 0)))
325    (clobber (match_scratch:DI 2 ""))]
326   "TARGET_POWERPC64 && reload_completed"
327   [(set (match_dup 2)
328         (sign_extend:DI (match_dup 1)))
329    (set (match_dup 0)
330         (compare:CC (match_dup 2)
331                     (const_int 0)))]
332   "")
333
334 (define_insn ""
335   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
336         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
337                     (const_int 0)))
338    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
339         (sign_extend:DI (match_dup 1)))]
340   "TARGET_64BIT"
341   "@
342    extsh. %0,%1
343    #"
344   [(set_attr "type" "compare")
345    (set_attr "length" "4,8")])
346
347 (define_split
348   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
349         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
350                     (const_int 0)))
351    (set (match_operand:DI 0 "gpc_reg_operand" "")
352         (sign_extend:DI (match_dup 1)))]
353   "TARGET_POWERPC64 && reload_completed"
354   [(set (match_dup 0)
355         (sign_extend:DI (match_dup 1)))
356    (set (match_dup 2)
357         (compare:CC (match_dup 0)
358                     (const_int 0)))]
359   "")
360
361 (define_expand "extendsidi2"
362   [(set (match_operand:DI 0 "gpc_reg_operand" "")
363         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
364   "TARGET_POWERPC64"
365   "")
366
367 (define_insn ""
368   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
369         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
370   "TARGET_POWERPC64"
371   "@
372    lwa%U1%X1 %0,%1
373    extsw %0,%1"
374   [(set_attr "type" "load_ext,*")])
375
376 (define_insn ""
377   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
378         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
379                     (const_int 0)))
380    (clobber (match_scratch:DI 2 "=r,r"))]
381   "TARGET_64BIT"
382   "@
383    extsw. %2,%1
384    #"
385   [(set_attr "type" "compare")
386    (set_attr "length" "4,8")])
387
388 (define_split
389   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
390         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
391                     (const_int 0)))
392    (clobber (match_scratch:DI 2 ""))]
393   "TARGET_POWERPC64 && reload_completed"
394   [(set (match_dup 2)
395         (sign_extend:DI (match_dup 1)))
396    (set (match_dup 0)
397         (compare:CC (match_dup 2)
398                     (const_int 0)))]
399   "")
400
401 (define_insn ""
402   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
403         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
404                     (const_int 0)))
405    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
406         (sign_extend:DI (match_dup 1)))]
407   "TARGET_64BIT"
408   "@
409    extsw. %0,%1
410    #"
411   [(set_attr "type" "compare")
412    (set_attr "length" "4,8")])
413
414 (define_split
415   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
416         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
417                     (const_int 0)))
418    (set (match_operand:DI 0 "gpc_reg_operand" "")
419         (sign_extend:DI (match_dup 1)))]
420   "TARGET_POWERPC64 && reload_completed"
421   [(set (match_dup 0)
422         (sign_extend:DI (match_dup 1)))
423    (set (match_dup 2)
424         (compare:CC (match_dup 0)
425                     (const_int 0)))]
426   "")
427
428 (define_expand "zero_extendqisi2"
429   [(set (match_operand:SI 0 "gpc_reg_operand" "")
430         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
431   ""
432   "")
433
434 (define_insn ""
435   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
436         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
437   ""
438   "@
439    lbz%U1%X1 %0,%1
440    {rlinm|rlwinm} %0,%1,0,0xff"
441   [(set_attr "type" "load,*")])
442
443 (define_insn ""
444   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
445         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
446                     (const_int 0)))
447    (clobber (match_scratch:SI 2 "=r,r"))]
448   ""
449   "@
450    {andil.|andi.} %2,%1,0xff
451    #"
452   [(set_attr "type" "compare")
453    (set_attr "length" "4,8")])
454
455 (define_split
456   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
457         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
458                     (const_int 0)))
459    (clobber (match_scratch:SI 2 ""))]
460   "reload_completed"
461   [(set (match_dup 2)
462         (zero_extend:SI (match_dup 1)))
463    (set (match_dup 0)
464         (compare:CC (match_dup 2)
465                     (const_int 0)))]
466   "")
467
468 (define_insn ""
469   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
470         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
471                     (const_int 0)))
472    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
473         (zero_extend:SI (match_dup 1)))]
474   ""
475   "@
476    {andil.|andi.} %0,%1,0xff
477    #"
478   [(set_attr "type" "compare")
479    (set_attr "length" "4,8")])
480
481 (define_split
482   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
483         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
484                     (const_int 0)))
485    (set (match_operand:SI 0 "gpc_reg_operand" "")
486         (zero_extend:SI (match_dup 1)))]
487   "reload_completed"
488   [(set (match_dup 0)
489         (zero_extend:SI (match_dup 1)))
490    (set (match_dup 2)
491         (compare:CC (match_dup 0)
492                     (const_int 0)))]
493   "")
494
495 (define_expand "extendqisi2"
496   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
497    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
498   ""
499   "
500 {
501   if (TARGET_POWERPC)
502     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
503   else if (TARGET_POWER)
504     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
505   else
506     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
507   DONE;
508 }")
509
510 (define_insn "extendqisi2_ppc"
511   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
512         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
513   "TARGET_POWERPC"
514   "extsb %0,%1")
515
516 (define_insn ""
517   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
518         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
519                     (const_int 0)))
520    (clobber (match_scratch:SI 2 "=r,r"))]
521   "TARGET_POWERPC"
522   "@
523    extsb. %2,%1
524    #"
525   [(set_attr "type" "compare")
526    (set_attr "length" "4,8")])
527
528 (define_split
529   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
530         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
531                     (const_int 0)))
532    (clobber (match_scratch:SI 2 ""))]
533   "TARGET_POWERPC && reload_completed"
534   [(set (match_dup 2)
535         (sign_extend:SI (match_dup 1)))
536    (set (match_dup 0)
537         (compare:CC (match_dup 2)
538                     (const_int 0)))]
539   "")
540
541 (define_insn ""
542   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
543         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
544                     (const_int 0)))
545    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
546         (sign_extend:SI (match_dup 1)))]
547   "TARGET_POWERPC"
548   "@
549    extsb. %0,%1
550    #"
551   [(set_attr "type" "compare")
552    (set_attr "length" "4,8")])
553
554 (define_split
555   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
556         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
557                     (const_int 0)))
558    (set (match_operand:SI 0 "gpc_reg_operand" "")
559         (sign_extend:SI (match_dup 1)))]
560   "TARGET_POWERPC && reload_completed"
561   [(set (match_dup 0)
562         (sign_extend:SI (match_dup 1)))
563    (set (match_dup 2)
564         (compare:CC (match_dup 0)
565                     (const_int 0)))]
566   "")
567
568 (define_expand "extendqisi2_power"
569   [(parallel [(set (match_dup 2)
570                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
571                               (const_int 24)))
572               (clobber (scratch:SI))])
573    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
574                    (ashiftrt:SI (match_dup 2)
575                                 (const_int 24)))
576               (clobber (scratch:SI))])]
577   "TARGET_POWER"
578   "
579 { operands[1] = gen_lowpart (SImode, operands[1]);
580   operands[2] = gen_reg_rtx (SImode); }")
581
582 (define_expand "extendqisi2_no_power"
583   [(set (match_dup 2)
584         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
585                    (const_int 24)))
586    (set (match_operand:SI 0 "gpc_reg_operand" "")
587         (ashiftrt:SI (match_dup 2)
588                      (const_int 24)))]
589   "! TARGET_POWER && ! TARGET_POWERPC"
590   "
591 { operands[1] = gen_lowpart (SImode, operands[1]);
592   operands[2] = gen_reg_rtx (SImode); }")
593
594 (define_expand "zero_extendqihi2"
595   [(set (match_operand:HI 0 "gpc_reg_operand" "")
596         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
597   ""
598   "")
599
600 (define_insn ""
601   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
602         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
603   ""
604   "@
605    lbz%U1%X1 %0,%1
606    {rlinm|rlwinm} %0,%1,0,0xff"
607   [(set_attr "type" "load,*")])
608
609 (define_insn ""
610   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
611         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
612                     (const_int 0)))
613    (clobber (match_scratch:HI 2 "=r,r"))]
614   ""
615   "@
616    {andil.|andi.} %2,%1,0xff
617    #"
618   [(set_attr "type" "compare")
619    (set_attr "length" "4,8")])
620
621 (define_split
622   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
623         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
624                     (const_int 0)))
625    (clobber (match_scratch:HI 2 ""))]
626   "reload_completed"
627   [(set (match_dup 2)
628         (zero_extend:HI (match_dup 1)))
629    (set (match_dup 0)
630         (compare:CC (match_dup 2)
631                     (const_int 0)))]
632   "")
633
634 (define_insn ""
635   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
636         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
637                     (const_int 0)))
638    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
639         (zero_extend:HI (match_dup 1)))]
640   ""
641   "@
642    {andil.|andi.} %0,%1,0xff
643    #"
644   [(set_attr "type" "compare")
645    (set_attr "length" "4,8")])
646
647 (define_split
648   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
649         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
650                     (const_int 0)))
651    (set (match_operand:HI 0 "gpc_reg_operand" "")
652         (zero_extend:HI (match_dup 1)))]
653   "reload_completed"
654   [(set (match_dup 0)
655         (zero_extend:HI (match_dup 1)))
656    (set (match_dup 2)
657         (compare:CC (match_dup 0)
658                     (const_int 0)))]
659   "")
660
661 (define_expand "extendqihi2"
662   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
663    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
664   ""
665   "
666 {
667   if (TARGET_POWERPC)
668     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
669   else if (TARGET_POWER)
670     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
671   else
672     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
673   DONE;
674 }")
675
676 (define_insn "extendqihi2_ppc"
677   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
678         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
679   "TARGET_POWERPC"
680   "extsb %0,%1")
681
682 (define_insn ""
683   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
684         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
685                     (const_int 0)))
686    (clobber (match_scratch:HI 2 "=r,r"))]
687   "TARGET_POWERPC"
688   "@
689    extsb. %2,%1
690    #"
691   [(set_attr "type" "compare")
692    (set_attr "length" "4,8")])
693
694 (define_split
695   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
696         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
697                     (const_int 0)))
698    (clobber (match_scratch:HI 2 ""))]
699   "TARGET_POWERPC && reload_completed"
700   [(set (match_dup 2)
701         (sign_extend:HI (match_dup 1)))
702    (set (match_dup 0)
703         (compare:CC (match_dup 2)
704                     (const_int 0)))]
705   "")
706
707 (define_insn ""
708   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
709         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
710                     (const_int 0)))
711    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
712         (sign_extend:HI (match_dup 1)))]
713   "TARGET_POWERPC"
714   "@
715    extsb. %0,%1
716    #"
717   [(set_attr "type" "compare")
718    (set_attr "length" "4,8")])
719
720 (define_split
721   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
722         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
723                     (const_int 0)))
724    (set (match_operand:HI 0 "gpc_reg_operand" "")
725         (sign_extend:HI (match_dup 1)))]
726   "TARGET_POWERPC && reload_completed"
727   [(set (match_dup 0)
728         (sign_extend:HI (match_dup 1)))
729    (set (match_dup 2)
730         (compare:CC (match_dup 0)
731                     (const_int 0)))]
732   "")
733
734 (define_expand "extendqihi2_power"
735   [(parallel [(set (match_dup 2)
736                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
737                               (const_int 24)))
738               (clobber (scratch:SI))])
739    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
740                    (ashiftrt:SI (match_dup 2)
741                                 (const_int 24)))
742               (clobber (scratch:SI))])]
743   "TARGET_POWER"
744   "
745 { operands[0] = gen_lowpart (SImode, operands[0]);
746   operands[1] = gen_lowpart (SImode, operands[1]);
747   operands[2] = gen_reg_rtx (SImode); }")
748
749 (define_expand "extendqihi2_no_power"
750   [(set (match_dup 2)
751         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
752                    (const_int 24)))
753    (set (match_operand:HI 0 "gpc_reg_operand" "")
754         (ashiftrt:SI (match_dup 2)
755                      (const_int 24)))]
756   "! TARGET_POWER && ! TARGET_POWERPC"
757   "
758 { operands[0] = gen_lowpart (SImode, operands[0]);
759   operands[1] = gen_lowpart (SImode, operands[1]);
760   operands[2] = gen_reg_rtx (SImode); }")
761
762 (define_expand "zero_extendhisi2"
763   [(set (match_operand:SI 0 "gpc_reg_operand" "")
764         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
765   ""
766   "")
767
768 (define_insn ""
769   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
770         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
771   ""
772   "@
773    lhz%U1%X1 %0,%1
774    {rlinm|rlwinm} %0,%1,0,0xffff"
775   [(set_attr "type" "load,*")])
776
777 (define_insn ""
778   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
779         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
780                     (const_int 0)))
781    (clobber (match_scratch:SI 2 "=r,r"))]
782   ""
783   "@
784    {andil.|andi.} %2,%1,0xffff
785    #"
786   [(set_attr "type" "compare")
787    (set_attr "length" "4,8")])
788
789 (define_split
790   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
791         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
792                     (const_int 0)))
793    (clobber (match_scratch:SI 2 ""))]
794   "reload_completed"
795   [(set (match_dup 2)
796         (zero_extend:SI (match_dup 1)))
797    (set (match_dup 0)
798         (compare:CC (match_dup 2)
799                     (const_int 0)))]
800   "")
801
802 (define_insn ""
803   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
804         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
805                     (const_int 0)))
806    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
807         (zero_extend:SI (match_dup 1)))]
808   ""
809   "@
810    {andil.|andi.} %0,%1,0xffff
811    #"
812   [(set_attr "type" "compare")
813    (set_attr "length" "4,8")])
814
815 (define_split
816   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
817         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
818                     (const_int 0)))
819    (set (match_operand:SI 0 "gpc_reg_operand" "")
820         (zero_extend:SI (match_dup 1)))]
821   "reload_completed"
822   [(set (match_dup 0)
823         (zero_extend:SI (match_dup 1)))
824    (set (match_dup 2)
825         (compare:CC (match_dup 0)
826                     (const_int 0)))]
827   "")
828
829 (define_expand "extendhisi2"
830   [(set (match_operand:SI 0 "gpc_reg_operand" "")
831         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
832   ""
833   "")
834
835 (define_insn ""
836   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
837         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
838   ""
839   "@
840    lha%U1%X1 %0,%1
841    {exts|extsh} %0,%1"
842   [(set_attr "type" "load_ext,*")])
843
844 (define_insn ""
845   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
846         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
847                     (const_int 0)))
848    (clobber (match_scratch:SI 2 "=r,r"))]
849   ""
850   "@
851    {exts.|extsh.} %2,%1
852    #"
853   [(set_attr "type" "compare")
854    (set_attr "length" "4,8")])
855
856 (define_split
857   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
858         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
859                     (const_int 0)))
860    (clobber (match_scratch:SI 2 ""))]
861   "reload_completed"
862   [(set (match_dup 2)
863         (sign_extend:SI (match_dup 1)))
864    (set (match_dup 0)
865         (compare:CC (match_dup 2)
866                     (const_int 0)))]
867   "")
868
869 (define_insn ""
870   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
871         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
872                     (const_int 0)))
873    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
874         (sign_extend:SI (match_dup 1)))]
875   ""
876   "@
877    {exts.|extsh.} %0,%1
878    #"
879   [(set_attr "type" "compare")
880    (set_attr "length" "4,8")])
881 \f
882 ;; IBM 405 and 440 half-word multiplication operations.
883
884 (define_insn "*macchwc"
885   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
886         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
887                                        (match_operand:SI 2 "gpc_reg_operand" "r")
888                                        (const_int 16))
889                                       (sign_extend:SI
890                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
891                              (match_operand:SI 4 "gpc_reg_operand" "0"))
892                     (const_int 0)))
893    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
894         (plus:SI (mult:SI (ashiftrt:SI
895                            (match_dup 2)
896                            (const_int 16))
897                           (sign_extend:SI
898                            (match_dup 1)))
899                  (match_dup 4)))]
900   "TARGET_MULHW"
901   "macchw. %0, %1, %2"
902   [(set_attr "type" "imul3")])
903
904 (define_insn "*macchw"
905   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
906         (plus:SI (mult:SI (ashiftrt:SI
907                            (match_operand:SI 2 "gpc_reg_operand" "r")
908                            (const_int 16))
909                           (sign_extend:SI
910                            (match_operand:HI 1 "gpc_reg_operand" "r")))
911                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
912   "TARGET_MULHW"
913   "macchw %0, %1, %2"
914   [(set_attr "type" "imul3")])
915
916 (define_insn "*macchwuc"
917   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
918         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
919                                        (match_operand:SI 2 "gpc_reg_operand" "r")
920                                        (const_int 16))
921                                       (zero_extend:SI
922                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
923                              (match_operand:SI 4 "gpc_reg_operand" "0"))
924                     (const_int 0)))
925    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
926         (plus:SI (mult:SI (lshiftrt:SI
927                            (match_dup 2)
928                            (const_int 16))
929                           (zero_extend:SI
930                            (match_dup 1)))
931                  (match_dup 4)))]
932   "TARGET_MULHW"
933   "macchwu. %0, %1, %2"
934   [(set_attr "type" "imul3")])
935
936 (define_insn "*macchwu"
937   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
938         (plus:SI (mult:SI (lshiftrt:SI
939                            (match_operand:SI 2 "gpc_reg_operand" "r")
940                            (const_int 16))
941                           (zero_extend:SI
942                            (match_operand:HI 1 "gpc_reg_operand" "r")))
943                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
944   "TARGET_MULHW"
945   "macchwu %0, %1, %2"
946   [(set_attr "type" "imul3")])
947
948 (define_insn "*machhwc"
949   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
950         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
951                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
952                                        (const_int 16))
953                                       (ashiftrt:SI
954                                        (match_operand:SI 2 "gpc_reg_operand" "r")
955                                        (const_int 16)))
956                              (match_operand:SI 4 "gpc_reg_operand" "0"))
957                     (const_int 0)))
958    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
959         (plus:SI (mult:SI (ashiftrt:SI
960                            (match_dup 1)
961                            (const_int 16))
962                           (ashiftrt:SI
963                            (match_dup 2)
964                            (const_int 16)))
965                  (match_dup 4)))]
966   "TARGET_MULHW"
967   "machhw. %0, %1, %2"
968   [(set_attr "type" "imul3")])
969
970 (define_insn "*machhw"
971   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
972         (plus:SI (mult:SI (ashiftrt:SI
973                            (match_operand:SI 1 "gpc_reg_operand" "%r")
974                            (const_int 16))
975                           (ashiftrt:SI
976                            (match_operand:SI 2 "gpc_reg_operand" "r")
977                            (const_int 16)))
978                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
979   "TARGET_MULHW"
980   "machhw %0, %1, %2"
981   [(set_attr "type" "imul3")])
982
983 (define_insn "*machhwuc"
984   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
985         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
986                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
987                                        (const_int 16))
988                                       (lshiftrt:SI
989                                        (match_operand:SI 2 "gpc_reg_operand" "r")
990                                        (const_int 16)))
991                              (match_operand:SI 4 "gpc_reg_operand" "0"))
992                     (const_int 0)))
993    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
994         (plus:SI (mult:SI (lshiftrt:SI
995                            (match_dup 1)
996                            (const_int 16))
997                           (lshiftrt:SI
998                            (match_dup 2)
999                            (const_int 16)))
1000                  (match_dup 4)))]
1001   "TARGET_MULHW"
1002   "machhwu. %0, %1, %2"
1003   [(set_attr "type" "imul3")])
1004
1005 (define_insn "*machhwu"
1006   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1007         (plus:SI (mult:SI (lshiftrt:SI
1008                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1009                            (const_int 16))
1010                           (lshiftrt:SI
1011                            (match_operand:SI 2 "gpc_reg_operand" "r")
1012                            (const_int 16)))
1013                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1014   "TARGET_MULHW"
1015   "machhwu %0, %1, %2"
1016   [(set_attr "type" "imul3")])
1017
1018 (define_insn "*maclhwc"
1019   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1020         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1021                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1022                                       (sign_extend:SI
1023                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1024                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1025                     (const_int 0)))
1026    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1027         (plus:SI (mult:SI (sign_extend:SI
1028                            (match_dup 1))
1029                           (sign_extend:SI
1030                            (match_dup 2)))
1031                  (match_dup 4)))]
1032   "TARGET_MULHW"
1033   "maclhw. %0, %1, %2"
1034   [(set_attr "type" "imul3")])
1035
1036 (define_insn "*maclhw"
1037   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1038         (plus:SI (mult:SI (sign_extend:SI
1039                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1040                           (sign_extend:SI
1041                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1042                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1043   "TARGET_MULHW"
1044   "maclhw %0, %1, %2"
1045   [(set_attr "type" "imul3")])
1046
1047 (define_insn "*maclhwuc"
1048   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1049         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1050                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1051                                       (zero_extend:SI
1052                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1053                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1054                     (const_int 0)))
1055    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1056         (plus:SI (mult:SI (zero_extend:SI
1057                            (match_dup 1))
1058                           (zero_extend:SI
1059                            (match_dup 2)))
1060                  (match_dup 4)))]
1061   "TARGET_MULHW"
1062   "maclhwu. %0, %1, %2"
1063   [(set_attr "type" "imul3")])
1064
1065 (define_insn "*maclhwu"
1066   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1067         (plus:SI (mult:SI (zero_extend:SI
1068                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1069                           (zero_extend:SI
1070                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1071                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1072   "TARGET_MULHW"
1073   "maclhwu %0, %1, %2"
1074   [(set_attr "type" "imul3")])
1075
1076 (define_insn "*nmacchwc"
1077   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1078         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1079                               (mult:SI (ashiftrt:SI
1080                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1081                                         (const_int 16))
1082                                        (sign_extend:SI
1083                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1084                     (const_int 0)))
1085    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1086         (minus:SI (match_dup 4)
1087                   (mult:SI (ashiftrt:SI
1088                             (match_dup 2)
1089                             (const_int 16))
1090                            (sign_extend:SI
1091                             (match_dup 1)))))]
1092   "TARGET_MULHW"
1093   "nmacchw. %0, %1, %2"
1094   [(set_attr "type" "imul3")])
1095
1096 (define_insn "*nmacchw"
1097   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1098         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1099                   (mult:SI (ashiftrt:SI
1100                             (match_operand:SI 2 "gpc_reg_operand" "r")
1101                             (const_int 16))
1102                            (sign_extend:SI
1103                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1104   "TARGET_MULHW"
1105   "nmacchw %0, %1, %2"
1106   [(set_attr "type" "imul3")])
1107
1108 (define_insn "*nmachhwc"
1109   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1110         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1111                               (mult:SI (ashiftrt:SI
1112                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1113                                         (const_int 16))
1114                                        (ashiftrt:SI
1115                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1116                                         (const_int 16))))
1117                     (const_int 0)))
1118    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1119         (minus:SI (match_dup 4)
1120                   (mult:SI (ashiftrt:SI
1121                             (match_dup 1)
1122                             (const_int 16))
1123                            (ashiftrt:SI
1124                             (match_dup 2)
1125                             (const_int 16)))))]
1126   "TARGET_MULHW"
1127   "nmachhw. %0, %1, %2"
1128   [(set_attr "type" "imul3")])
1129
1130 (define_insn "*nmachhw"
1131   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1132         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1133                   (mult:SI (ashiftrt:SI
1134                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1135                             (const_int 16))
1136                            (ashiftrt:SI
1137                             (match_operand:SI 2 "gpc_reg_operand" "r")
1138                             (const_int 16)))))]
1139   "TARGET_MULHW"
1140   "nmachhw %0, %1, %2"
1141   [(set_attr "type" "imul3")])
1142
1143 (define_insn "*nmaclhwc"
1144   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1145         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1146                               (mult:SI (sign_extend:SI
1147                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1148                                        (sign_extend:SI
1149                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1150                     (const_int 0)))
1151    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1152         (minus:SI (match_dup 4)
1153                   (mult:SI (sign_extend:SI
1154                             (match_dup 1))
1155                            (sign_extend:SI
1156                             (match_dup 2)))))]
1157   "TARGET_MULHW"
1158   "nmaclhw. %0, %1, %2"
1159   [(set_attr "type" "imul3")])
1160
1161 (define_insn "*nmaclhw"
1162   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1163         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1164                   (mult:SI (sign_extend:SI
1165                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1166                            (sign_extend:SI
1167                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1168   "TARGET_MULHW"
1169   "nmaclhw %0, %1, %2"
1170   [(set_attr "type" "imul3")])
1171
1172 (define_insn "*mulchwc"
1173   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1174         (compare:CC (mult:SI (ashiftrt:SI
1175                               (match_operand:SI 2 "gpc_reg_operand" "r")
1176                               (const_int 16))
1177                              (sign_extend:SI
1178                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1179                     (const_int 0)))
1180    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1181         (mult:SI (ashiftrt:SI
1182                   (match_dup 2)
1183                   (const_int 16))
1184                  (sign_extend:SI
1185                   (match_dup 1))))]
1186   "TARGET_MULHW"
1187   "mulchw. %0, %1, %2"
1188   [(set_attr "type" "imul3")])
1189
1190 (define_insn "*mulchw"
1191   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1192         (mult:SI (ashiftrt:SI
1193                   (match_operand:SI 2 "gpc_reg_operand" "r")
1194                   (const_int 16))
1195                  (sign_extend:SI
1196                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1197   "TARGET_MULHW"
1198   "mulchw %0, %1, %2"
1199   [(set_attr "type" "imul3")])
1200
1201 (define_insn "*mulchwuc"
1202   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1203         (compare:CC (mult:SI (lshiftrt:SI
1204                               (match_operand:SI 2 "gpc_reg_operand" "r")
1205                               (const_int 16))
1206                              (zero_extend:SI
1207                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1208                     (const_int 0)))
1209    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1210         (mult:SI (lshiftrt:SI
1211                   (match_dup 2)
1212                   (const_int 16))
1213                  (zero_extend:SI
1214                   (match_dup 1))))]
1215   "TARGET_MULHW"
1216   "mulchwu. %0, %1, %2"
1217   [(set_attr "type" "imul3")])
1218
1219 (define_insn "*mulchwu"
1220   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1221         (mult:SI (lshiftrt:SI
1222                   (match_operand:SI 2 "gpc_reg_operand" "r")
1223                   (const_int 16))
1224                  (zero_extend:SI
1225                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1226   "TARGET_MULHW"
1227   "mulchwu %0, %1, %2"
1228   [(set_attr "type" "imul3")])
1229
1230 (define_insn "*mulhhwc"
1231   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1232         (compare:CC (mult:SI (ashiftrt:SI
1233                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1234                               (const_int 16))
1235                              (ashiftrt:SI
1236                               (match_operand:SI 2 "gpc_reg_operand" "r")
1237                               (const_int 16)))
1238                     (const_int 0)))
1239    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1240         (mult:SI (ashiftrt:SI
1241                   (match_dup 1)
1242                   (const_int 16))
1243                  (ashiftrt:SI
1244                   (match_dup 2)
1245                   (const_int 16))))]
1246   "TARGET_MULHW"
1247   "mulhhw. %0, %1, %2"
1248   [(set_attr "type" "imul3")])
1249
1250 (define_insn "*mulhhw"
1251   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1252         (mult:SI (ashiftrt:SI
1253                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1254                   (const_int 16))
1255                  (ashiftrt:SI
1256                   (match_operand:SI 2 "gpc_reg_operand" "r")
1257                   (const_int 16))))]
1258   "TARGET_MULHW"
1259   "mulhhw %0, %1, %2"
1260   [(set_attr "type" "imul3")])
1261
1262 (define_insn "*mulhhwuc"
1263   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1264         (compare:CC (mult:SI (lshiftrt:SI
1265                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1266                               (const_int 16))
1267                              (lshiftrt:SI
1268                               (match_operand:SI 2 "gpc_reg_operand" "r")
1269                               (const_int 16)))
1270                     (const_int 0)))
1271    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1272         (mult:SI (lshiftrt:SI
1273                   (match_dup 1)
1274                   (const_int 16))
1275                  (lshiftrt:SI
1276                   (match_dup 2)
1277                   (const_int 16))))]
1278   "TARGET_MULHW"
1279   "mulhhwu. %0, %1, %2"
1280   [(set_attr "type" "imul3")])
1281
1282 (define_insn "*mulhhwu"
1283   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1284         (mult:SI (lshiftrt:SI
1285                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1286                   (const_int 16))
1287                  (lshiftrt:SI
1288                   (match_operand:SI 2 "gpc_reg_operand" "r")
1289                   (const_int 16))))]
1290   "TARGET_MULHW"
1291   "mulhhwu %0, %1, %2"
1292   [(set_attr "type" "imul3")])
1293
1294 (define_insn "*mullhwc"
1295   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1296         (compare:CC (mult:SI (sign_extend:SI
1297                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1298                              (sign_extend:SI
1299                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1300                     (const_int 0)))
1301    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1302         (mult:SI (sign_extend:SI
1303                   (match_dup 1))
1304                  (sign_extend:SI
1305                   (match_dup 2))))]
1306   "TARGET_MULHW"
1307   "mullhw. %0, %1, %2"
1308   [(set_attr "type" "imul3")])
1309
1310 (define_insn "*mullhw"
1311   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1312         (mult:SI (sign_extend:SI
1313                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1314                  (sign_extend:SI
1315                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1316   "TARGET_MULHW"
1317   "mullhw %0, %1, %2"
1318   [(set_attr "type" "imul3")])
1319
1320 (define_insn "*mullhwuc"
1321   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1322         (compare:CC (mult:SI (zero_extend:SI
1323                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1324                              (zero_extend:SI
1325                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1326                     (const_int 0)))
1327    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1328         (mult:SI (zero_extend:SI
1329                   (match_dup 1))
1330                  (zero_extend:SI
1331                   (match_dup 2))))]
1332   "TARGET_MULHW"
1333   "mullhwu. %0, %1, %2"
1334   [(set_attr "type" "imul3")])
1335
1336 (define_insn "*mullhwu"
1337   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1338         (mult:SI (zero_extend:SI
1339                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1340                  (zero_extend:SI
1341                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1342   "TARGET_MULHW"
1343   "mullhwu %0, %1, %2"
1344   [(set_attr "type" "imul3")])
1345 \f
1346 (define_split
1347   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1348         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1349                     (const_int 0)))
1350    (set (match_operand:SI 0 "gpc_reg_operand" "")
1351         (sign_extend:SI (match_dup 1)))]
1352   "reload_completed"
1353   [(set (match_dup 0)
1354         (sign_extend:SI (match_dup 1)))
1355    (set (match_dup 2)
1356         (compare:CC (match_dup 0)
1357                     (const_int 0)))]
1358   "")
1359
1360 ;; Fixed-point arithmetic insns.
1361
1362 (define_expand "add<mode>3"
1363   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1364         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1365                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1366   ""
1367   "
1368 {
1369   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1370     {
1371       if (non_short_cint_operand (operands[2], DImode))
1372         FAIL;
1373     }
1374   else if (GET_CODE (operands[2]) == CONST_INT
1375            && ! add_operand (operands[2], <MODE>mode))
1376     {
1377       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
1378                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1379
1380       HOST_WIDE_INT val = INTVAL (operands[2]);
1381       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1382       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1383
1384       if (<MODE>mode == DImode && !CONST_OK_FOR_LETTER_P (rest, 'L'))
1385         FAIL;
1386
1387       /* The ordering here is important for the prolog expander.
1388          When space is allocated from the stack, adding 'low' first may
1389          produce a temporary deallocation (which would be bad).  */
1390       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1391       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1392       DONE;
1393     }
1394 }")
1395
1396 ;; Discourage ai/addic because of carry but provide it in an alternative
1397 ;; allowing register zero as source.
1398 (define_insn "*add<mode>3_internal1"
1399   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1400         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1401                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1402   ""
1403   "@
1404    {cax|add} %0,%1,%2
1405    {cal %0,%2(%1)|addi %0,%1,%2}
1406    {ai|addic} %0,%1,%2
1407    {cau|addis} %0,%1,%v2"
1408   [(set_attr "length" "4,4,4,4")])
1409
1410 (define_insn "addsi3_high"
1411   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1412         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1413                  (high:SI (match_operand 2 "" ""))))]
1414   "TARGET_MACHO && !TARGET_64BIT"
1415   "{cau|addis} %0,%1,ha16(%2)"
1416   [(set_attr "length" "4")])
1417
1418 (define_insn "*add<mode>3_internal2"
1419   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1420         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1421                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1422                     (const_int 0)))
1423    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1424   ""
1425   "@
1426    {cax.|add.} %3,%1,%2
1427    {ai.|addic.} %3,%1,%2
1428    #
1429    #"
1430   [(set_attr "type" "fast_compare,compare,compare,compare")
1431    (set_attr "length" "4,4,8,8")])
1432
1433 (define_split
1434   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1435         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1436                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1437                     (const_int 0)))
1438    (clobber (match_scratch:GPR 3 ""))]
1439   "reload_completed"
1440   [(set (match_dup 3)
1441         (plus:GPR (match_dup 1)
1442                  (match_dup 2)))
1443    (set (match_dup 0)
1444         (compare:CC (match_dup 3)
1445                     (const_int 0)))]
1446   "")
1447
1448 (define_insn "*add<mode>3_internal3"
1449   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1450         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1451                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1452                     (const_int 0)))
1453    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1454         (plus:P (match_dup 1)
1455                 (match_dup 2)))]
1456   ""
1457   "@
1458    {cax.|add.} %0,%1,%2
1459    {ai.|addic.} %0,%1,%2
1460    #
1461    #"
1462   [(set_attr "type" "fast_compare,compare,compare,compare")
1463    (set_attr "length" "4,4,8,8")])
1464
1465 (define_split
1466   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1467         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1468                             (match_operand:P 2 "reg_or_short_operand" ""))
1469                     (const_int 0)))
1470    (set (match_operand:P 0 "gpc_reg_operand" "")
1471         (plus:P (match_dup 1) (match_dup 2)))]
1472   "reload_completed"
1473   [(set (match_dup 0)
1474         (plus:P (match_dup 1)
1475                 (match_dup 2)))
1476    (set (match_dup 3)
1477         (compare:CC (match_dup 0)
1478                     (const_int 0)))]
1479   "")
1480
1481 ;; Split an add that we can't do in one insn into two insns, each of which
1482 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1483 ;; add should be last in case the result gets used in an address.
1484
1485 (define_split
1486   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1487         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1488                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1489   ""
1490   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1491    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1492 "
1493 {
1494   HOST_WIDE_INT val = INTVAL (operands[2]);
1495   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1496   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1497
1498   operands[4] = GEN_INT (low);
1499   if (<MODE>mode == SImode || CONST_OK_FOR_LETTER_P (rest, 'L'))
1500     operands[3] = GEN_INT (rest);
1501   else if (! no_new_pseudos)
1502     {
1503       operands[3] = gen_reg_rtx (DImode);
1504       emit_move_insn (operands[3], operands[2]);
1505       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1506       DONE;
1507     }
1508   else
1509     FAIL;
1510 }")
1511
1512 (define_insn "one_cmpl<mode>2"
1513   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1514         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1515   ""
1516   "nor %0,%1,%1")
1517
1518 (define_insn ""
1519   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1520         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1521                     (const_int 0)))
1522    (clobber (match_scratch:P 2 "=r,r"))]
1523   ""
1524   "@
1525    nor. %2,%1,%1
1526    #"
1527   [(set_attr "type" "compare")
1528    (set_attr "length" "4,8")])
1529
1530 (define_split
1531   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1532         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1533                     (const_int 0)))
1534    (clobber (match_scratch:P 2 ""))]
1535   "reload_completed"
1536   [(set (match_dup 2)
1537         (not:P (match_dup 1)))
1538    (set (match_dup 0)
1539         (compare:CC (match_dup 2)
1540                     (const_int 0)))]
1541   "")
1542
1543 (define_insn ""
1544   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1545         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1546                     (const_int 0)))
1547    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1548         (not:P (match_dup 1)))]
1549   ""
1550   "@
1551    nor. %0,%1,%1
1552    #"
1553   [(set_attr "type" "compare")
1554    (set_attr "length" "4,8")])
1555
1556 (define_split
1557   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1558         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1559                     (const_int 0)))
1560    (set (match_operand:P 0 "gpc_reg_operand" "")
1561         (not:P (match_dup 1)))]
1562   "reload_completed"
1563   [(set (match_dup 0)
1564         (not:P (match_dup 1)))
1565    (set (match_dup 2)
1566         (compare:CC (match_dup 0)
1567                     (const_int 0)))]
1568   "")
1569
1570 (define_insn ""
1571   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1572         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1573                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1574   "! TARGET_POWERPC"
1575   "{sf%I1|subf%I1c} %0,%2,%1")
1576
1577 (define_insn ""
1578   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1579         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1580                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1581   "TARGET_POWERPC"
1582   "@
1583    subf %0,%2,%1
1584    subfic %0,%2,%1")
1585
1586 (define_insn ""
1587   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1588         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1589                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1590                     (const_int 0)))
1591    (clobber (match_scratch:SI 3 "=r,r"))]
1592   "! TARGET_POWERPC"
1593   "@
1594    {sf.|subfc.} %3,%2,%1
1595    #"
1596   [(set_attr "type" "compare")
1597    (set_attr "length" "4,8")])
1598
1599 (define_insn ""
1600   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1601         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1602                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1603                     (const_int 0)))
1604    (clobber (match_scratch:P 3 "=r,r"))]
1605   "TARGET_POWERPC"
1606   "@
1607    subf. %3,%2,%1
1608    #"
1609   [(set_attr "type" "fast_compare")
1610    (set_attr "length" "4,8")])
1611
1612 (define_split
1613   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1614         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1615                              (match_operand:P 2 "gpc_reg_operand" ""))
1616                     (const_int 0)))
1617    (clobber (match_scratch:P 3 ""))]
1618   "reload_completed"
1619   [(set (match_dup 3)
1620         (minus:P (match_dup 1)
1621                   (match_dup 2)))
1622    (set (match_dup 0)
1623         (compare:CC (match_dup 3)
1624                     (const_int 0)))]
1625   "")
1626
1627 (define_insn ""
1628   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1629         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1630                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1631                     (const_int 0)))
1632    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1633         (minus:SI (match_dup 1) (match_dup 2)))]
1634   "! TARGET_POWERPC"
1635   "@
1636    {sf.|subfc.} %0,%2,%1
1637    #"
1638   [(set_attr "type" "compare")
1639    (set_attr "length" "4,8")])
1640
1641 (define_insn ""
1642   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1643         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1644                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1645                     (const_int 0)))
1646    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1647         (minus:P (match_dup 1)
1648                   (match_dup 2)))]
1649   "TARGET_POWERPC"
1650   "@
1651    subf. %0,%2,%1
1652    #"
1653   [(set_attr "type" "fast_compare")
1654    (set_attr "length" "4,8")])
1655
1656 (define_split
1657   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1658         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1659                              (match_operand:P 2 "gpc_reg_operand" ""))
1660                     (const_int 0)))
1661    (set (match_operand:P 0 "gpc_reg_operand" "")
1662         (minus:P (match_dup 1)
1663                   (match_dup 2)))]
1664   "reload_completed"
1665   [(set (match_dup 0)
1666         (minus:P (match_dup 1)
1667                   (match_dup 2)))
1668    (set (match_dup 3)
1669         (compare:CC (match_dup 0)
1670                     (const_int 0)))]
1671   "")
1672
1673 (define_expand "sub<mode>3"
1674   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1675         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1676                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
1677   ""
1678   "
1679 {
1680   if (GET_CODE (operands[2]) == CONST_INT)
1681     {
1682       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1683                                  negate_rtx (<MODE>mode, operands[2])));
1684       DONE;
1685     }
1686 }")
1687
1688 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1689 ;; instruction and some auxiliary computations.  Then we just have a single
1690 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1691 ;; combine.
1692
1693 (define_expand "sminsi3"
1694   [(set (match_dup 3)
1695         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1696                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1697                          (const_int 0)
1698                          (minus:SI (match_dup 2) (match_dup 1))))
1699    (set (match_operand:SI 0 "gpc_reg_operand" "")
1700         (minus:SI (match_dup 2) (match_dup 3)))]
1701   "TARGET_POWER || TARGET_ISEL"
1702   "
1703 {
1704   if (TARGET_ISEL)
1705     {
1706       operands[2] = force_reg (SImode, operands[2]);
1707       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1708       DONE;
1709     }
1710
1711   operands[3] = gen_reg_rtx (SImode);
1712 }")
1713
1714 (define_split
1715   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1716         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1717                  (match_operand:SI 2 "reg_or_short_operand" "")))
1718    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1719   "TARGET_POWER"
1720   [(set (match_dup 3)
1721         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1722                          (const_int 0)
1723                          (minus:SI (match_dup 2) (match_dup 1))))
1724    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1725   "")
1726
1727 (define_expand "smaxsi3"
1728   [(set (match_dup 3)
1729         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1730                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1731                          (const_int 0)
1732                          (minus:SI (match_dup 2) (match_dup 1))))
1733    (set (match_operand:SI 0 "gpc_reg_operand" "")
1734         (plus:SI (match_dup 3) (match_dup 1)))]
1735   "TARGET_POWER || TARGET_ISEL"
1736   "
1737 {
1738   if (TARGET_ISEL)
1739     {
1740       operands[2] = force_reg (SImode, operands[2]);
1741       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1742       DONE;
1743     }
1744   operands[3] = gen_reg_rtx (SImode);
1745 }")
1746
1747 (define_split
1748   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1749         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1750                  (match_operand:SI 2 "reg_or_short_operand" "")))
1751    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1752   "TARGET_POWER"
1753   [(set (match_dup 3)
1754         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1755                          (const_int 0)
1756                          (minus:SI (match_dup 2) (match_dup 1))))
1757    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1758   "")
1759
1760 (define_expand "uminsi3"
1761   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1762                               (match_dup 5)))
1763    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1764                               (match_dup 5)))
1765    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1766                                        (const_int 0)
1767                                        (minus:SI (match_dup 4) (match_dup 3))))
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       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1776       DONE;
1777     }
1778   operands[3] = gen_reg_rtx (SImode);
1779   operands[4] = gen_reg_rtx (SImode);
1780   operands[5] = GEN_INT (-2147483647 - 1);
1781 }")
1782
1783 (define_expand "umaxsi3"
1784   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1785                               (match_dup 5)))
1786    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1787                               (match_dup 5)))
1788    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1789                                        (const_int 0)
1790                                        (minus:SI (match_dup 4) (match_dup 3))))
1791    (set (match_operand:SI 0 "gpc_reg_operand" "")
1792         (plus:SI (match_dup 3) (match_dup 1)))]
1793   "TARGET_POWER || TARGET_ISEL"
1794   "
1795 {
1796   if (TARGET_ISEL)
1797     {
1798       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1799       DONE;
1800     }
1801   operands[3] = gen_reg_rtx (SImode);
1802   operands[4] = gen_reg_rtx (SImode);
1803   operands[5] = GEN_INT (-2147483647 - 1);
1804 }")
1805
1806 (define_insn ""
1807   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1808         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1809                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1810                          (const_int 0)
1811                          (minus:SI (match_dup 2) (match_dup 1))))]
1812   "TARGET_POWER"
1813   "doz%I2 %0,%1,%2")
1814
1815 (define_insn ""
1816   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1817         (compare:CC
1818          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1819                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1820                           (const_int 0)
1821                           (minus:SI (match_dup 2) (match_dup 1)))
1822          (const_int 0)))
1823    (clobber (match_scratch:SI 3 "=r,r"))]
1824   "TARGET_POWER"
1825   "@
1826    doz%I2. %3,%1,%2
1827    #"
1828   [(set_attr "type" "delayed_compare")
1829    (set_attr "length" "4,8")])
1830
1831 (define_split
1832   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1833         (compare:CC
1834          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1835                               (match_operand:SI 2 "reg_or_short_operand" ""))
1836                           (const_int 0)
1837                           (minus:SI (match_dup 2) (match_dup 1)))
1838          (const_int 0)))
1839    (clobber (match_scratch:SI 3 ""))]
1840   "TARGET_POWER && reload_completed"
1841   [(set (match_dup 3)
1842         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1843                           (const_int 0)
1844                           (minus:SI (match_dup 2) (match_dup 1))))
1845    (set (match_dup 0)
1846         (compare:CC (match_dup 3)
1847                     (const_int 0)))]
1848   "")
1849
1850 (define_insn ""
1851   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1852         (compare:CC
1853          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1854                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1855                           (const_int 0)
1856                           (minus:SI (match_dup 2) (match_dup 1)))
1857          (const_int 0)))
1858    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1859         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1860                          (const_int 0)
1861                          (minus:SI (match_dup 2) (match_dup 1))))]
1862   "TARGET_POWER"
1863   "@
1864    doz%I2. %0,%1,%2
1865    #"
1866   [(set_attr "type" "delayed_compare")
1867    (set_attr "length" "4,8")])
1868
1869 (define_split
1870   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1871         (compare:CC
1872          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1873                               (match_operand:SI 2 "reg_or_short_operand" ""))
1874                           (const_int 0)
1875                           (minus:SI (match_dup 2) (match_dup 1)))
1876          (const_int 0)))
1877    (set (match_operand:SI 0 "gpc_reg_operand" "")
1878         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1879                          (const_int 0)
1880                          (minus:SI (match_dup 2) (match_dup 1))))]
1881   "TARGET_POWER && reload_completed"
1882   [(set (match_dup 0)
1883         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1884                          (const_int 0)
1885                          (minus:SI (match_dup 2) (match_dup 1))))
1886    (set (match_dup 3)
1887         (compare:CC (match_dup 0)
1888                     (const_int 0)))]
1889   "")
1890
1891 ;; We don't need abs with condition code because such comparisons should
1892 ;; never be done.
1893 (define_expand "abssi2"
1894   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1895         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1896   ""
1897   "
1898 {
1899   if (TARGET_ISEL)
1900     {
1901       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
1902       DONE;
1903     }
1904   else if (! TARGET_POWER)
1905     {
1906       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1907       DONE;
1908     }
1909 }")
1910
1911 (define_insn "*abssi2_power"
1912   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1913         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1914   "TARGET_POWER"
1915   "abs %0,%1")
1916
1917 (define_insn_and_split "abssi2_isel"
1918   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1919         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
1920    (clobber (match_scratch:SI 2 "=&b"))
1921    (clobber (match_scratch:CC 3 "=y"))]
1922   "TARGET_ISEL"
1923   "#"
1924   "&& reload_completed"
1925   [(set (match_dup 2) (neg:SI (match_dup 1)))
1926    (set (match_dup 3)
1927         (compare:CC (match_dup 1)
1928                     (const_int 0)))
1929    (set (match_dup 0)
1930         (if_then_else:SI (ge (match_dup 3)
1931                              (const_int 0))
1932                          (match_dup 1)
1933                          (match_dup 2)))]
1934   "")
1935
1936 (define_insn_and_split "abssi2_nopower"
1937   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1938         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1939    (clobber (match_scratch:SI 2 "=&r,&r"))]
1940   "! TARGET_POWER && ! TARGET_ISEL"
1941   "#"
1942   "&& reload_completed"
1943   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1944    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1945    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1946   "")
1947
1948 (define_insn "*nabs_power"
1949   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1950         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
1951   "TARGET_POWER"
1952   "nabs %0,%1")
1953
1954 (define_insn_and_split "*nabs_nopower"
1955   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1956         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1957    (clobber (match_scratch:SI 2 "=&r,&r"))]
1958   "! TARGET_POWER"
1959   "#"
1960   "&& reload_completed"
1961   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1962    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1963    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
1964   "")
1965
1966 (define_expand "neg<mode>2"
1967   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1968         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
1969   ""
1970   "")
1971
1972 (define_insn "*neg<mode>2_internal"
1973   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1974         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1975   ""
1976   "neg %0,%1")
1977
1978 (define_insn ""
1979   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1980         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1981                     (const_int 0)))
1982    (clobber (match_scratch:P 2 "=r,r"))]
1983   ""
1984   "@
1985    neg. %2,%1
1986    #"
1987   [(set_attr "type" "fast_compare")
1988    (set_attr "length" "4,8")])
1989
1990 (define_split
1991   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1992         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
1993                     (const_int 0)))
1994    (clobber (match_scratch:P 2 ""))]
1995   "reload_completed"
1996   [(set (match_dup 2)
1997         (neg:P (match_dup 1)))
1998    (set (match_dup 0)
1999         (compare:CC (match_dup 2)
2000                     (const_int 0)))]
2001   "")
2002
2003 (define_insn ""
2004   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2005         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2006                     (const_int 0)))
2007    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2008         (neg:P (match_dup 1)))]
2009   ""
2010   "@
2011    neg. %0,%1
2012    #"
2013   [(set_attr "type" "fast_compare")
2014    (set_attr "length" "4,8")])
2015
2016 (define_split
2017   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2018         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2019                     (const_int 0)))
2020    (set (match_operand:P 0 "gpc_reg_operand" "")
2021         (neg:P (match_dup 1)))]
2022   "reload_completed"
2023   [(set (match_dup 0)
2024         (neg:P (match_dup 1)))
2025    (set (match_dup 2)
2026         (compare:CC (match_dup 0)
2027                     (const_int 0)))]
2028   "")
2029
2030 (define_insn "clz<mode>2"
2031   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2032         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2033   ""
2034   "{cntlz|cntlz<wd>} %0,%1")
2035
2036 (define_expand "ctz<mode>2"
2037   [(set (match_dup 2)
2038         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))
2039    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2040                                           (match_dup 2)))
2041               (clobber (scratch:CC))])
2042    (set (match_dup 4) (clz:GPR (match_dup 3)))
2043    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2044         (minus:GPR (match_dup 5) (match_dup 4)))]
2045   ""
2046   {
2047      operands[2] = gen_reg_rtx (<MODE>mode);
2048      operands[3] = gen_reg_rtx (<MODE>mode);
2049      operands[4] = gen_reg_rtx (<MODE>mode);
2050      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
2051   })
2052
2053 (define_expand "ffs<mode>2"
2054   [(set (match_dup 2)
2055         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))
2056    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2057                                           (match_dup 2)))
2058               (clobber (scratch:CC))])
2059    (set (match_dup 4) (clz:GPR (match_dup 3)))
2060    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2061         (minus:GPR (match_dup 5) (match_dup 4)))]
2062   ""
2063   {
2064      operands[2] = gen_reg_rtx (<MODE>mode);
2065      operands[3] = gen_reg_rtx (<MODE>mode);
2066      operands[4] = gen_reg_rtx (<MODE>mode);
2067      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
2068   })
2069
2070 (define_expand "popcount<mode>2"
2071   [(set (match_dup 2)
2072         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2073                      UNSPEC_POPCNTB))
2074    (set (match_dup 3)
2075         (mult:GPR (match_dup 2) (match_dup 4)))
2076    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2077         (lshiftrt:GPR (match_dup 3) (match_dup 5)))]
2078   "TARGET_POPCNTB"
2079   {
2080     operands[2] = gen_reg_rtx (<MODE>mode);
2081     operands[3] = gen_reg_rtx (<MODE>mode);
2082     operands[4] = force_reg (<MODE>mode,
2083                              <MODE>mode == SImode
2084                              ? GEN_INT (0x01010101)
2085                              : GEN_INT ((HOST_WIDE_INT)
2086                                         0x01010101 << 32 | 0x01010101));
2087     operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 8);
2088   })
2089
2090 (define_insn "popcntb<mode>2"
2091   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2092         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2093                      UNSPEC_POPCNTB))]
2094   "TARGET_POPCNTB"
2095   "popcntb %0,%1")
2096
2097 (define_expand "mulsi3"
2098   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2099    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2100    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
2101   ""
2102   "
2103 {
2104   if (TARGET_POWER)
2105     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
2106   else
2107     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
2108   DONE;
2109 }")
2110
2111 (define_insn "mulsi3_mq"
2112   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2113         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2114                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
2115    (clobber (match_scratch:SI 3 "=q,q"))]
2116   "TARGET_POWER"
2117   "@
2118    {muls|mullw} %0,%1,%2
2119    {muli|mulli} %0,%1,%2"
2120    [(set (attr "type")
2121       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2122                 (const_string "imul3")
2123              (match_operand:SI 2 "short_cint_operand" "")
2124                 (const_string "imul2")]
2125         (const_string "imul")))])
2126
2127 (define_insn "mulsi3_no_mq"
2128   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2129         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2130                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2131   "! TARGET_POWER"
2132   "@
2133    {muls|mullw} %0,%1,%2
2134    {muli|mulli} %0,%1,%2"
2135    [(set (attr "type")
2136       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2137                 (const_string "imul3")
2138              (match_operand:SI 2 "short_cint_operand" "")
2139                 (const_string "imul2")]
2140         (const_string "imul")))])
2141
2142 (define_insn "*mulsi3_mq_internal1"
2143   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2144         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2145                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2146                     (const_int 0)))
2147    (clobber (match_scratch:SI 3 "=r,r"))
2148    (clobber (match_scratch:SI 4 "=q,q"))]
2149   "TARGET_POWER"
2150   "@
2151    {muls.|mullw.} %3,%1,%2
2152    #"
2153   [(set_attr "type" "imul_compare")
2154    (set_attr "length" "4,8")])
2155
2156 (define_split
2157   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2158         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2159                              (match_operand:SI 2 "gpc_reg_operand" ""))
2160                     (const_int 0)))
2161    (clobber (match_scratch:SI 3 ""))
2162    (clobber (match_scratch:SI 4 ""))]
2163   "TARGET_POWER && reload_completed"
2164   [(parallel [(set (match_dup 3)
2165         (mult:SI (match_dup 1) (match_dup 2)))
2166    (clobber (match_dup 4))])
2167    (set (match_dup 0)
2168         (compare:CC (match_dup 3)
2169                     (const_int 0)))]
2170   "")
2171
2172 (define_insn "*mulsi3_no_mq_internal1"
2173   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2174         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2175                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2176                     (const_int 0)))
2177    (clobber (match_scratch:SI 3 "=r,r"))]
2178   "! TARGET_POWER"
2179   "@
2180    {muls.|mullw.} %3,%1,%2
2181    #"
2182   [(set_attr "type" "imul_compare")
2183    (set_attr "length" "4,8")])
2184
2185 (define_split
2186   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2187         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2188                              (match_operand:SI 2 "gpc_reg_operand" ""))
2189                     (const_int 0)))
2190    (clobber (match_scratch:SI 3 ""))]
2191   "! TARGET_POWER && reload_completed"
2192   [(set (match_dup 3)
2193         (mult:SI (match_dup 1) (match_dup 2)))
2194    (set (match_dup 0)
2195         (compare:CC (match_dup 3)
2196                     (const_int 0)))]
2197   "")
2198
2199 (define_insn "*mulsi3_mq_internal2"
2200   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2201         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2202                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2203                     (const_int 0)))
2204    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2205         (mult:SI (match_dup 1) (match_dup 2)))
2206    (clobber (match_scratch:SI 4 "=q,q"))]
2207   "TARGET_POWER"
2208   "@
2209    {muls.|mullw.} %0,%1,%2
2210    #"
2211   [(set_attr "type" "imul_compare")
2212    (set_attr "length" "4,8")])
2213
2214 (define_split
2215   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2216         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2217                              (match_operand:SI 2 "gpc_reg_operand" ""))
2218                     (const_int 0)))
2219    (set (match_operand:SI 0 "gpc_reg_operand" "")
2220         (mult:SI (match_dup 1) (match_dup 2)))
2221    (clobber (match_scratch:SI 4 ""))]
2222   "TARGET_POWER && reload_completed"
2223   [(parallel [(set (match_dup 0)
2224         (mult:SI (match_dup 1) (match_dup 2)))
2225    (clobber (match_dup 4))])
2226    (set (match_dup 3)
2227         (compare:CC (match_dup 0)
2228                     (const_int 0)))]
2229   "")
2230
2231 (define_insn "*mulsi3_no_mq_internal2"
2232   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2233         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2234                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2235                     (const_int 0)))
2236    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2237         (mult:SI (match_dup 1) (match_dup 2)))]
2238   "! TARGET_POWER"
2239   "@
2240    {muls.|mullw.} %0,%1,%2
2241    #"
2242   [(set_attr "type" "imul_compare")
2243    (set_attr "length" "4,8")])
2244
2245 (define_split
2246   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2247         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2248                              (match_operand:SI 2 "gpc_reg_operand" ""))
2249                     (const_int 0)))
2250    (set (match_operand:SI 0 "gpc_reg_operand" "")
2251         (mult:SI (match_dup 1) (match_dup 2)))]
2252   "! TARGET_POWER && reload_completed"
2253   [(set (match_dup 0)
2254         (mult:SI (match_dup 1) (match_dup 2)))
2255    (set (match_dup 3)
2256         (compare:CC (match_dup 0)
2257                     (const_int 0)))]
2258   "")
2259
2260 ;; Operand 1 is divided by operand 2; quotient goes to operand
2261 ;; 0 and remainder to operand 3.
2262 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
2263
2264 (define_expand "divmodsi4"
2265   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2266                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2267                            (match_operand:SI 2 "gpc_reg_operand" "")))
2268               (set (match_operand:SI 3 "register_operand" "")
2269                    (mod:SI (match_dup 1) (match_dup 2)))])]
2270   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
2271   "
2272 {
2273   if (! TARGET_POWER && ! TARGET_POWERPC)
2274     {
2275       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2276       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2277       emit_insn (gen_divss_call ());
2278       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2279       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2280       DONE;
2281     }
2282 }")
2283
2284 (define_insn "*divmodsi4_internal"
2285   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2286         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2287                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2288    (set (match_operand:SI 3 "register_operand" "=q")
2289         (mod:SI (match_dup 1) (match_dup 2)))]
2290   "TARGET_POWER"
2291   "divs %0,%1,%2"
2292   [(set_attr "type" "idiv")])
2293
2294 (define_expand "udiv<mode>3"
2295   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2296         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2297                   (match_operand:GPR 2 "gpc_reg_operand" "")))]
2298   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
2299   "
2300 {
2301   if (! TARGET_POWER && ! TARGET_POWERPC)
2302     {
2303       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2304       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2305       emit_insn (gen_quous_call ());
2306       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2307       DONE;
2308     }
2309   else if (TARGET_POWER)
2310     {
2311       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
2312       DONE;
2313     }
2314 }")
2315
2316 (define_insn "udivsi3_mq"
2317   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2318         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2319                  (match_operand:SI 2 "gpc_reg_operand" "r")))
2320    (clobber (match_scratch:SI 3 "=q"))]
2321   "TARGET_POWERPC && TARGET_POWER"
2322   "divwu %0,%1,%2"
2323   [(set_attr "type" "idiv")])
2324
2325 (define_insn "*udivsi3_no_mq"
2326   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2327         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2328                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2329   "TARGET_POWERPC && ! TARGET_POWER"
2330   "div<wd>u %0,%1,%2"
2331   [(set_attr "type" "idiv")])
2332
2333 ;; For powers of two we can do srai/aze for divide and then adjust for
2334 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
2335 ;; used; for PowerPC, force operands into register and do a normal divide;
2336 ;; for AIX common-mode, use quoss call on register operands.
2337 (define_expand "div<mode>3"
2338   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2339         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2340                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2341   ""
2342   "
2343 {
2344   if (GET_CODE (operands[2]) == CONST_INT
2345       && INTVAL (operands[2]) > 0
2346       && exact_log2 (INTVAL (operands[2])) >= 0)
2347     ;
2348   else if (TARGET_POWERPC)
2349     {
2350       operands[2] = force_reg (SImode, operands[2]);
2351       if (TARGET_POWER)
2352         {
2353           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
2354           DONE;
2355         }
2356     }
2357   else if (TARGET_POWER)
2358     FAIL;
2359   else
2360     {
2361       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2362       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2363       emit_insn (gen_quoss_call ());
2364       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2365       DONE;
2366     }
2367 }")
2368
2369 (define_insn "divsi3_mq"
2370   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2371         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2372                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2373    (clobber (match_scratch:SI 3 "=q"))]
2374   "TARGET_POWERPC && TARGET_POWER"
2375   "divw %0,%1,%2"
2376   [(set_attr "type" "idiv")])
2377
2378 (define_insn "*div<mode>3_no_mq"
2379   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2380         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2381                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2382   "TARGET_POWERPC && ! TARGET_POWER"
2383   "div<wd> %0,%1,%2"
2384   [(set_attr "type" "idiv")])
2385
2386 (define_expand "mod<mode>3"
2387   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
2388    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
2389    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
2390   ""
2391   "
2392 {
2393   int i;
2394   rtx temp1;
2395   rtx temp2;
2396
2397   if (GET_CODE (operands[2]) != CONST_INT
2398       || INTVAL (operands[2]) <= 0
2399       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2400     FAIL;
2401
2402   temp1 = gen_reg_rtx (<MODE>mode);
2403   temp2 = gen_reg_rtx (<MODE>mode);
2404
2405   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
2406   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
2407   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
2408   DONE;
2409 }")
2410
2411 (define_insn ""
2412   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2413         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2414                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
2415   ""
2416   "{srai|sra<wd>i} %0,%1,%p2\;{aze|addze} %0,%0"
2417   [(set_attr "type" "two")
2418    (set_attr "length" "8")])
2419
2420 (define_insn ""
2421   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2422         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2423                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2424                     (const_int 0)))
2425    (clobber (match_scratch:P 3 "=r,r"))]
2426   ""
2427   "@
2428    {srai|sra<wd>i} %3,%1,%p2\;{aze.|addze.} %3,%3
2429    #"
2430   [(set_attr "type" "compare")
2431    (set_attr "length" "8,12")])
2432
2433 (define_split
2434   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2435         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2436                              (match_operand:GPR 2 "exact_log2_cint_operand"
2437                               ""))
2438                     (const_int 0)))
2439    (clobber (match_scratch:GPR 3 ""))]
2440   "reload_completed"
2441   [(set (match_dup 3)
2442         (div:<MODE> (match_dup 1) (match_dup 2)))
2443    (set (match_dup 0)
2444         (compare:CC (match_dup 3)
2445                     (const_int 0)))]
2446   "")
2447
2448 (define_insn ""
2449   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2450         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2451                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2452                     (const_int 0)))
2453    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2454         (div:P (match_dup 1) (match_dup 2)))]
2455   ""
2456   "@
2457    {srai|sra<wd>i} %0,%1,%p2\;{aze.|addze.} %0,%0
2458    #"
2459   [(set_attr "type" "compare")
2460    (set_attr "length" "8,12")])
2461
2462 (define_split
2463   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2464         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2465                              (match_operand:GPR 2 "exact_log2_cint_operand"
2466                               ""))
2467                     (const_int 0)))
2468    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2469         (div:GPR (match_dup 1) (match_dup 2)))]
2470   "reload_completed"
2471   [(set (match_dup 0)
2472         (div:<MODE> (match_dup 1) (match_dup 2)))
2473    (set (match_dup 3)
2474         (compare:CC (match_dup 0)
2475                     (const_int 0)))]
2476   "")
2477
2478 (define_insn ""
2479   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2480         (udiv:SI
2481          (plus:DI (ashift:DI
2482                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
2483                    (const_int 32))
2484                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
2485          (match_operand:SI 3 "gpc_reg_operand" "r")))
2486    (set (match_operand:SI 2 "register_operand" "=*q")
2487         (umod:SI
2488          (plus:DI (ashift:DI
2489                    (zero_extend:DI (match_dup 1)) (const_int 32))
2490                   (zero_extend:DI (match_dup 4)))
2491          (match_dup 3)))]
2492   "TARGET_POWER"
2493   "div %0,%1,%3"
2494   [(set_attr "type" "idiv")])
2495
2496 ;; To do unsigned divide we handle the cases of the divisor looking like a
2497 ;; negative number.  If it is a constant that is less than 2**31, we don't
2498 ;; have to worry about the branches.  So make a few subroutines here.
2499 ;;
2500 ;; First comes the normal case.
2501 (define_expand "udivmodsi4_normal"
2502   [(set (match_dup 4) (const_int 0))
2503    (parallel [(set (match_operand:SI 0 "" "")
2504                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2505                                                 (const_int 32))
2506                                      (zero_extend:DI (match_operand:SI 1 "" "")))
2507                             (match_operand:SI 2 "" "")))
2508               (set (match_operand:SI 3 "" "")
2509                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2510                                                 (const_int 32))
2511                                      (zero_extend:DI (match_dup 1)))
2512                             (match_dup 2)))])]
2513   "TARGET_POWER"
2514   "
2515 { operands[4] = gen_reg_rtx (SImode); }")
2516
2517 ;; This handles the branches.
2518 (define_expand "udivmodsi4_tests"
2519   [(set (match_operand:SI 0 "" "") (const_int 0))
2520    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
2521    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
2522    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
2523                            (label_ref (match_operand:SI 4 "" "")) (pc)))
2524    (set (match_dup 0) (const_int 1))
2525    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
2526    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
2527    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
2528                            (label_ref (match_dup 4)) (pc)))]
2529   "TARGET_POWER"
2530   "
2531 { operands[5] = gen_reg_rtx (CCUNSmode);
2532   operands[6] = gen_reg_rtx (CCmode);
2533 }")
2534
2535 (define_expand "udivmodsi4"
2536   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2537                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2538                             (match_operand:SI 2 "reg_or_cint_operand" "")))
2539               (set (match_operand:SI 3 "gpc_reg_operand" "")
2540                    (umod:SI (match_dup 1) (match_dup 2)))])]
2541   ""
2542   "
2543 {
2544   rtx label = 0;
2545
2546   if (! TARGET_POWER)
2547     {
2548       if (! TARGET_POWERPC)
2549         {
2550           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2551           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2552           emit_insn (gen_divus_call ());
2553           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2554           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2555           DONE;
2556         }
2557       else
2558         FAIL;
2559     }
2560
2561   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
2562     {
2563       operands[2] = force_reg (SImode, operands[2]);
2564       label = gen_label_rtx ();
2565       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
2566                                   operands[3], label));
2567     }
2568   else
2569     operands[2] = force_reg (SImode, operands[2]);
2570
2571   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
2572                                operands[3]));
2573   if (label)
2574     emit_label (label);
2575
2576   DONE;
2577 }")
2578
2579 ;; AIX architecture-independent common-mode multiply (DImode),
2580 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
2581 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
2582 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
2583 ;; assumed unused if generating common-mode, so ignore.
2584 (define_insn "mulh_call"
2585   [(set (reg:SI 3)
2586         (truncate:SI
2587          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
2588                                (sign_extend:DI (reg:SI 4)))
2589                       (const_int 32))))
2590    (clobber (match_scratch:SI 0 "=l"))]
2591   "! TARGET_POWER && ! TARGET_POWERPC"
2592   "bla __mulh"
2593   [(set_attr "type" "imul")])
2594
2595 (define_insn "mull_call"
2596   [(set (reg:DI 3)
2597         (mult:DI (sign_extend:DI (reg:SI 3))
2598                  (sign_extend:DI (reg:SI 4))))
2599    (clobber (match_scratch:SI 0 "=l"))
2600    (clobber (reg:SI 0))]
2601   "! TARGET_POWER && ! TARGET_POWERPC"
2602   "bla __mull"
2603   [(set_attr "type" "imul")])
2604
2605 (define_insn "divss_call"
2606   [(set (reg:SI 3)
2607         (div:SI (reg:SI 3) (reg:SI 4)))
2608    (set (reg:SI 4)
2609         (mod:SI (reg:SI 3) (reg:SI 4)))
2610    (clobber (match_scratch:SI 0 "=l"))
2611    (clobber (reg:SI 0))]
2612   "! TARGET_POWER && ! TARGET_POWERPC"
2613   "bla __divss"
2614   [(set_attr "type" "idiv")])
2615
2616 (define_insn "divus_call"
2617   [(set (reg:SI 3)
2618         (udiv:SI (reg:SI 3) (reg:SI 4)))
2619    (set (reg:SI 4)
2620         (umod:SI (reg:SI 3) (reg:SI 4)))
2621    (clobber (match_scratch:SI 0 "=l"))
2622    (clobber (reg:SI 0))
2623    (clobber (match_scratch:CC 1 "=x"))
2624    (clobber (reg:CC 69))]
2625   "! TARGET_POWER && ! TARGET_POWERPC"
2626   "bla __divus"
2627   [(set_attr "type" "idiv")])
2628
2629 (define_insn "quoss_call"
2630   [(set (reg:SI 3)
2631         (div:SI (reg:SI 3) (reg:SI 4)))
2632    (clobber (match_scratch:SI 0 "=l"))]
2633   "! TARGET_POWER && ! TARGET_POWERPC"
2634   "bla __quoss"
2635   [(set_attr "type" "idiv")])
2636
2637 (define_insn "quous_call"
2638   [(set (reg:SI 3)
2639         (udiv:SI (reg:SI 3) (reg:SI 4)))
2640    (clobber (match_scratch:SI 0 "=l"))
2641    (clobber (reg:SI 0))
2642    (clobber (match_scratch:CC 1 "=x"))
2643    (clobber (reg:CC 69))]
2644   "! TARGET_POWER && ! TARGET_POWERPC"
2645   "bla __quous"
2646   [(set_attr "type" "idiv")])
2647 \f
2648 ;; Logical instructions
2649 ;; The logical instructions are mostly combined by using match_operator,
2650 ;; but the plain AND insns are somewhat different because there is no
2651 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2652 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2653
2654 (define_insn "andsi3"
2655   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2656         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2657                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2658    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2659   ""
2660   "@
2661    and %0,%1,%2
2662    {rlinm|rlwinm} %0,%1,0,%m2,%M2
2663    {andil.|andi.} %0,%1,%b2
2664    {andiu.|andis.} %0,%1,%u2"
2665   [(set_attr "type" "*,*,compare,compare")])
2666
2667 ;; Note to set cr's other than cr0 we do the and immediate and then
2668 ;; the test again -- this avoids a mfcr which on the higher end
2669 ;; machines causes an execution serialization
2670
2671 (define_insn "*andsi3_internal2"
2672   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2673         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2674                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2675                     (const_int 0)))
2676    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2677    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2678   "TARGET_32BIT"
2679   "@
2680    and. %3,%1,%2
2681    {andil.|andi.} %3,%1,%b2
2682    {andiu.|andis.} %3,%1,%u2
2683    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2684    #
2685    #
2686    #
2687    #"
2688   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2689    (set_attr "length" "4,4,4,4,8,8,8,8")])
2690
2691 (define_insn "*andsi3_internal3"
2692   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2693         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2694                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2695                     (const_int 0)))
2696    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2697    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2698   "TARGET_64BIT"
2699   "@
2700    #
2701    {andil.|andi.} %3,%1,%b2
2702    {andiu.|andis.} %3,%1,%u2
2703    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2704    #
2705    #
2706    #
2707    #"
2708   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2709    (set_attr "length" "8,4,4,4,8,8,8,8")])
2710
2711 (define_split
2712   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2713         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2714                              (match_operand:GPR 2 "and_operand" ""))
2715                     (const_int 0)))
2716    (clobber (match_scratch:GPR 3 ""))
2717    (clobber (match_scratch:CC 4 ""))]
2718   "reload_completed"
2719   [(parallel [(set (match_dup 3)
2720                    (and:<MODE> (match_dup 1)
2721                                (match_dup 2)))
2722               (clobber (match_dup 4))])
2723    (set (match_dup 0)
2724         (compare:CC (match_dup 3)
2725                     (const_int 0)))]
2726   "")
2727
2728 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2729 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2730
2731 (define_split
2732   [(set (match_operand:CC 0 "cc_reg_operand" "")
2733         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2734                             (match_operand:SI 2 "gpc_reg_operand" ""))
2735                     (const_int 0)))
2736    (clobber (match_scratch:SI 3 ""))
2737    (clobber (match_scratch:CC 4 ""))]
2738   "TARGET_POWERPC64 && reload_completed"
2739   [(parallel [(set (match_dup 3)
2740                    (and:SI (match_dup 1)
2741                            (match_dup 2)))
2742               (clobber (match_dup 4))])
2743    (set (match_dup 0)
2744         (compare:CC (match_dup 3)
2745                     (const_int 0)))]
2746   "")
2747
2748 (define_insn "*andsi3_internal4"
2749   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2750         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2751                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2752                     (const_int 0)))
2753    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2754         (and:SI (match_dup 1)
2755                 (match_dup 2)))
2756    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2757   "TARGET_32BIT"
2758   "@
2759    and. %0,%1,%2
2760    {andil.|andi.} %0,%1,%b2
2761    {andiu.|andis.} %0,%1,%u2
2762    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2763    #
2764    #
2765    #
2766    #"
2767   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2768    (set_attr "length" "4,4,4,4,8,8,8,8")])
2769
2770 (define_insn "*andsi3_internal5"
2771   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2772         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2773                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2774                     (const_int 0)))
2775    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2776         (and:SI (match_dup 1)
2777                 (match_dup 2)))
2778    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2779   "TARGET_64BIT"
2780   "@
2781    #
2782    {andil.|andi.} %0,%1,%b2
2783    {andiu.|andis.} %0,%1,%u2
2784    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2785    #
2786    #
2787    #
2788    #"
2789   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2790    (set_attr "length" "8,4,4,4,8,8,8,8")])
2791
2792 (define_split
2793   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2794         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2795                             (match_operand:SI 2 "and_operand" ""))
2796                     (const_int 0)))
2797    (set (match_operand:SI 0 "gpc_reg_operand" "")
2798         (and:SI (match_dup 1)
2799                 (match_dup 2)))
2800    (clobber (match_scratch:CC 4 ""))]
2801   "reload_completed"
2802   [(parallel [(set (match_dup 0)
2803                    (and:SI (match_dup 1)
2804                            (match_dup 2)))
2805               (clobber (match_dup 4))])
2806    (set (match_dup 3)
2807         (compare:CC (match_dup 0)
2808                     (const_int 0)))]
2809   "")
2810
2811 (define_split
2812   [(set (match_operand:CC 3 "cc_reg_operand" "")
2813         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2814                             (match_operand:SI 2 "gpc_reg_operand" ""))
2815                     (const_int 0)))
2816    (set (match_operand:SI 0 "gpc_reg_operand" "")
2817         (and:SI (match_dup 1)
2818                 (match_dup 2)))
2819    (clobber (match_scratch:CC 4 ""))]
2820   "TARGET_POWERPC64 && reload_completed"
2821   [(parallel [(set (match_dup 0)
2822                    (and:SI (match_dup 1)
2823                            (match_dup 2)))
2824               (clobber (match_dup 4))])
2825    (set (match_dup 3)
2826         (compare:CC (match_dup 0)
2827                     (const_int 0)))]
2828   "")
2829
2830 ;; Handle the PowerPC64 rlwinm corner case
2831
2832 (define_insn_and_split "*andsi3_internal6"
2833   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2834         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2835                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2836   "TARGET_POWERPC64"
2837   "#"
2838   "TARGET_POWERPC64"
2839   [(set (match_dup 0)
2840         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
2841                 (match_dup 4)))
2842    (set (match_dup 0)
2843         (rotate:SI (match_dup 0) (match_dup 5)))]
2844   "
2845 {
2846   int mb = extract_MB (operands[2]);
2847   int me = extract_ME (operands[2]);
2848   operands[3] = GEN_INT (me + 1);
2849   operands[5] = GEN_INT (32 - (me + 1));
2850   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2851 }"
2852   [(set_attr "length" "8")])
2853
2854 (define_expand "iorsi3"
2855   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2856         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
2857                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2858   ""
2859   "
2860 {
2861   if (GET_CODE (operands[2]) == CONST_INT
2862       && ! logical_operand (operands[2], SImode))
2863     {
2864       HOST_WIDE_INT value = INTVAL (operands[2]);
2865       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2866                  ? operands[0] : gen_reg_rtx (SImode));
2867
2868       emit_insn (gen_iorsi3 (tmp, operands[1],
2869                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2870       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2871       DONE;
2872     }
2873 }")
2874
2875 (define_expand "xorsi3"
2876   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2877         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2878                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2879   ""
2880   "
2881 {
2882   if (GET_CODE (operands[2]) == CONST_INT
2883       && ! logical_operand (operands[2], SImode))
2884     {
2885       HOST_WIDE_INT value = INTVAL (operands[2]);
2886       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2887                  ? operands[0] : gen_reg_rtx (SImode));
2888
2889       emit_insn (gen_xorsi3 (tmp, operands[1],
2890                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2891       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2892       DONE;
2893     }
2894 }")
2895
2896 (define_insn "*boolsi3_internal1"
2897   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2898         (match_operator:SI 3 "boolean_or_operator"
2899          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
2900           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
2901   ""
2902   "@
2903    %q3 %0,%1,%2
2904    {%q3il|%q3i} %0,%1,%b2
2905    {%q3iu|%q3is} %0,%1,%u2")
2906
2907 (define_insn "*boolsi3_internal2"
2908   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2909         (compare:CC (match_operator:SI 4 "boolean_or_operator"
2910          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2911           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2912          (const_int 0)))
2913    (clobber (match_scratch:SI 3 "=r,r"))]
2914   "TARGET_32BIT"
2915   "@
2916    %q4. %3,%1,%2
2917    #"
2918   [(set_attr "type" "compare")
2919    (set_attr "length" "4,8")])
2920
2921 (define_split
2922   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2923         (compare:CC (match_operator:SI 4 "boolean_operator"
2924          [(match_operand:SI 1 "gpc_reg_operand" "")
2925           (match_operand:SI 2 "gpc_reg_operand" "")])
2926          (const_int 0)))
2927    (clobber (match_scratch:SI 3 ""))]
2928   "TARGET_32BIT && reload_completed"
2929   [(set (match_dup 3) (match_dup 4))
2930    (set (match_dup 0)
2931         (compare:CC (match_dup 3)
2932                     (const_int 0)))]
2933   "")
2934
2935 (define_insn "*boolsi3_internal3"
2936   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2937         (compare:CC (match_operator:SI 4 "boolean_operator"
2938          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2939           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2940          (const_int 0)))
2941    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2942         (match_dup 4))]
2943   "TARGET_32BIT"
2944   "@
2945    %q4. %0,%1,%2
2946    #"
2947   [(set_attr "type" "compare")
2948    (set_attr "length" "4,8")])
2949
2950 (define_split
2951   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2952         (compare:CC (match_operator:SI 4 "boolean_operator"
2953          [(match_operand:SI 1 "gpc_reg_operand" "")
2954           (match_operand:SI 2 "gpc_reg_operand" "")])
2955          (const_int 0)))
2956    (set (match_operand:SI 0 "gpc_reg_operand" "")
2957         (match_dup 4))]
2958   "TARGET_32BIT && reload_completed"
2959   [(set (match_dup 0) (match_dup 4))
2960    (set (match_dup 3)
2961         (compare:CC (match_dup 0)
2962                     (const_int 0)))]
2963   "")
2964
2965 ;; Split a logical operation that we can't do in one insn into two insns,
2966 ;; each of which does one 16-bit part.  This is used by combine.
2967
2968 (define_split
2969   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2970         (match_operator:SI 3 "boolean_or_operator"
2971          [(match_operand:SI 1 "gpc_reg_operand" "")
2972           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
2973   ""
2974   [(set (match_dup 0) (match_dup 4))
2975    (set (match_dup 0) (match_dup 5))]
2976 "
2977 {
2978   rtx i;
2979   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
2980   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2981                                 operands[1], i);
2982   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
2983   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2984                                 operands[0], i);
2985 }")
2986
2987 (define_insn "*boolcsi3_internal1"
2988   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2989         (match_operator:SI 3 "boolean_operator"
2990          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2991           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
2992   ""
2993   "%q3 %0,%2,%1")
2994
2995 (define_insn "*boolcsi3_internal2"
2996   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2997         (compare:CC (match_operator:SI 4 "boolean_operator"
2998          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2999           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3000          (const_int 0)))
3001    (clobber (match_scratch:SI 3 "=r,r"))]
3002   "TARGET_32BIT"
3003   "@
3004    %q4. %3,%2,%1
3005    #"
3006   [(set_attr "type" "compare")
3007    (set_attr "length" "4,8")])
3008
3009 (define_split
3010   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3011         (compare:CC (match_operator:SI 4 "boolean_operator"
3012          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3013           (match_operand:SI 2 "gpc_reg_operand" "")])
3014          (const_int 0)))
3015    (clobber (match_scratch:SI 3 ""))]
3016   "TARGET_32BIT && reload_completed"
3017   [(set (match_dup 3) (match_dup 4))
3018    (set (match_dup 0)
3019         (compare:CC (match_dup 3)
3020                     (const_int 0)))]
3021   "")
3022
3023 (define_insn "*boolcsi3_internal3"
3024   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3025         (compare:CC (match_operator:SI 4 "boolean_operator"
3026          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3027           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3028          (const_int 0)))
3029    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3030         (match_dup 4))]
3031   "TARGET_32BIT"
3032   "@
3033    %q4. %0,%2,%1
3034    #"
3035   [(set_attr "type" "compare")
3036    (set_attr "length" "4,8")])
3037
3038 (define_split
3039   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3040         (compare:CC (match_operator:SI 4 "boolean_operator"
3041          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3042           (match_operand:SI 2 "gpc_reg_operand" "")])
3043          (const_int 0)))
3044    (set (match_operand:SI 0 "gpc_reg_operand" "")
3045         (match_dup 4))]
3046   "TARGET_32BIT && reload_completed"
3047   [(set (match_dup 0) (match_dup 4))
3048    (set (match_dup 3)
3049         (compare:CC (match_dup 0)
3050                     (const_int 0)))]
3051   "")
3052
3053 (define_insn "*boolccsi3_internal1"
3054   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3055         (match_operator:SI 3 "boolean_operator"
3056          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3057           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3058   ""
3059   "%q3 %0,%1,%2")
3060
3061 (define_insn "*boolccsi3_internal2"
3062   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3063         (compare:CC (match_operator:SI 4 "boolean_operator"
3064          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3065           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3066          (const_int 0)))
3067    (clobber (match_scratch:SI 3 "=r,r"))]
3068   "TARGET_32BIT"
3069   "@
3070    %q4. %3,%1,%2
3071    #"
3072   [(set_attr "type" "compare")
3073    (set_attr "length" "4,8")])
3074
3075 (define_split
3076   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3077         (compare:CC (match_operator:SI 4 "boolean_operator"
3078          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3079           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3080          (const_int 0)))
3081    (clobber (match_scratch:SI 3 ""))]
3082   "TARGET_32BIT && reload_completed"
3083   [(set (match_dup 3) (match_dup 4))
3084    (set (match_dup 0)
3085         (compare:CC (match_dup 3)
3086                     (const_int 0)))]
3087   "")
3088
3089 (define_insn "*boolccsi3_internal3"
3090   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3091         (compare:CC (match_operator:SI 4 "boolean_operator"
3092          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3093           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3094          (const_int 0)))
3095    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3096         (match_dup 4))]
3097   "TARGET_32BIT"
3098   "@
3099    %q4. %0,%1,%2
3100    #"
3101   [(set_attr "type" "compare")
3102    (set_attr "length" "4,8")])
3103
3104 (define_split
3105   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3106         (compare:CC (match_operator:SI 4 "boolean_operator"
3107          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3108           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3109          (const_int 0)))
3110    (set (match_operand:SI 0 "gpc_reg_operand" "")
3111         (match_dup 4))]
3112   "TARGET_32BIT && reload_completed"
3113   [(set (match_dup 0) (match_dup 4))
3114    (set (match_dup 3)
3115         (compare:CC (match_dup 0)
3116                     (const_int 0)))]
3117   "")
3118
3119 ;; maskir insn.  We need four forms because things might be in arbitrary
3120 ;; orders.  Don't define forms that only set CR fields because these
3121 ;; would modify an input register.
3122
3123 (define_insn "*maskir_internal1"
3124   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3125         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3126                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3127                 (and:SI (match_dup 2)
3128                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
3129   "TARGET_POWER"
3130   "maskir %0,%3,%2")
3131
3132 (define_insn "*maskir_internal2"
3133   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3134         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3135                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3136                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3137                         (match_dup 2))))]
3138   "TARGET_POWER"
3139   "maskir %0,%3,%2")
3140
3141 (define_insn "*maskir_internal3"
3142   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3143         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
3144                         (match_operand:SI 3 "gpc_reg_operand" "r"))
3145                 (and:SI (not:SI (match_dup 2))
3146                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3147   "TARGET_POWER"
3148   "maskir %0,%3,%2")
3149
3150 (define_insn "*maskir_internal4"
3151   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3152         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3153                         (match_operand:SI 2 "gpc_reg_operand" "r"))
3154                 (and:SI (not:SI (match_dup 2))
3155                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3156   "TARGET_POWER"
3157   "maskir %0,%3,%2")
3158
3159 (define_insn "*maskir_internal5"
3160   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3161         (compare:CC
3162          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3163                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3164                  (and:SI (match_dup 2)
3165                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
3166          (const_int 0)))
3167    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3168         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3169                 (and:SI (match_dup 2) (match_dup 3))))]
3170   "TARGET_POWER"
3171   "@
3172    maskir. %0,%3,%2
3173    #"
3174   [(set_attr "type" "compare")
3175    (set_attr "length" "4,8")])
3176
3177 (define_split
3178   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3179         (compare:CC
3180          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3181                          (match_operand:SI 1 "gpc_reg_operand" ""))
3182                  (and:SI (match_dup 2)
3183                          (match_operand:SI 3 "gpc_reg_operand" "")))
3184          (const_int 0)))
3185    (set (match_operand:SI 0 "gpc_reg_operand" "")
3186         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3187                 (and:SI (match_dup 2) (match_dup 3))))]
3188   "TARGET_POWER && reload_completed"
3189   [(set (match_dup 0)
3190         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3191                 (and:SI (match_dup 2) (match_dup 3))))
3192    (set (match_dup 4)
3193         (compare:CC (match_dup 0)
3194                     (const_int 0)))]
3195   "")
3196
3197 (define_insn "*maskir_internal6"
3198   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3199         (compare:CC
3200          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3201                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3202                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3203                          (match_dup 2)))
3204          (const_int 0)))
3205    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3206         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3207                 (and:SI (match_dup 3) (match_dup 2))))]
3208   "TARGET_POWER"
3209   "@
3210    maskir. %0,%3,%2
3211    #"
3212   [(set_attr "type" "compare")
3213    (set_attr "length" "4,8")])
3214
3215 (define_split
3216   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3217         (compare:CC
3218          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3219                          (match_operand:SI 1 "gpc_reg_operand" ""))
3220                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3221                          (match_dup 2)))
3222          (const_int 0)))
3223    (set (match_operand:SI 0 "gpc_reg_operand" "")
3224         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3225                 (and:SI (match_dup 3) (match_dup 2))))]
3226   "TARGET_POWER && reload_completed"
3227   [(set (match_dup 0)
3228         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3229                 (and:SI (match_dup 3) (match_dup 2))))
3230    (set (match_dup 4)
3231         (compare:CC (match_dup 0)
3232                     (const_int 0)))]
3233   "")
3234
3235 (define_insn "*maskir_internal7"
3236   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3237         (compare:CC
3238          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
3239                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
3240                  (and:SI (not:SI (match_dup 2))
3241                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3242          (const_int 0)))
3243    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3244         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3245                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3246   "TARGET_POWER"
3247   "@
3248    maskir. %0,%3,%2
3249    #"
3250   [(set_attr "type" "compare")
3251    (set_attr "length" "4,8")])
3252
3253 (define_split
3254   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3255         (compare:CC
3256          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
3257                          (match_operand:SI 3 "gpc_reg_operand" ""))
3258                  (and:SI (not:SI (match_dup 2))
3259                          (match_operand:SI 1 "gpc_reg_operand" "")))
3260          (const_int 0)))
3261    (set (match_operand:SI 0 "gpc_reg_operand" "")
3262         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3263                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3264   "TARGET_POWER && reload_completed"
3265   [(set (match_dup 0)
3266         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3267                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3268    (set (match_dup 4)
3269         (compare:CC (match_dup 0)
3270                     (const_int 0)))]
3271   "")
3272
3273 (define_insn "*maskir_internal8"
3274   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3275         (compare:CC
3276          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3277                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3278                  (and:SI (not:SI (match_dup 2))
3279                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3280          (const_int 0)))
3281    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3282         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3283                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3284   "TARGET_POWER"
3285   "@
3286    maskir. %0,%3,%2
3287    #"
3288   [(set_attr "type" "compare")
3289    (set_attr "length" "4,8")])
3290
3291 (define_split
3292   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3293         (compare:CC
3294          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3295                          (match_operand:SI 2 "gpc_reg_operand" ""))
3296                  (and:SI (not:SI (match_dup 2))
3297                          (match_operand:SI 1 "gpc_reg_operand" "")))
3298          (const_int 0)))
3299    (set (match_operand:SI 0 "gpc_reg_operand" "")
3300         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3301                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3302   "TARGET_POWER && reload_completed"
3303   [(set (match_dup 0)
3304         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3305                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3306    (set (match_dup 4)
3307         (compare:CC (match_dup 0)
3308                     (const_int 0)))]
3309   "")
3310 \f
3311 ;; Rotate and shift insns, in all their variants.  These support shifts,
3312 ;; field inserts and extracts, and various combinations thereof.
3313 (define_expand "insv"
3314   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
3315                        (match_operand:SI 1 "const_int_operand" "")
3316                        (match_operand:SI 2 "const_int_operand" ""))
3317         (match_operand 3 "gpc_reg_operand" ""))]
3318   ""
3319   "
3320 {
3321   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3322      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3323      compiler if the address of the structure is taken later.  */
3324   if (GET_CODE (operands[0]) == SUBREG
3325       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3326     FAIL;
3327
3328   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
3329     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
3330   else
3331     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
3332   DONE;
3333 }")
3334
3335 (define_insn "insvsi"
3336   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3337                          (match_operand:SI 1 "const_int_operand" "i")
3338                          (match_operand:SI 2 "const_int_operand" "i"))
3339         (match_operand:SI 3 "gpc_reg_operand" "r"))]
3340   ""
3341   "*
3342 {
3343   int start = INTVAL (operands[2]) & 31;
3344   int size = INTVAL (operands[1]) & 31;
3345
3346   operands[4] = GEN_INT (32 - start - size);
3347   operands[1] = GEN_INT (start + size - 1);
3348   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3349 }"
3350   [(set_attr "type" "insert_word")])
3351
3352 (define_insn "*insvsi_internal1"
3353   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3354                          (match_operand:SI 1 "const_int_operand" "i")
3355                          (match_operand:SI 2 "const_int_operand" "i"))
3356         (rotate:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3357                    (match_operand:SI 4 "const_int_operand" "i")))]
3358   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3359   "*
3360 {
3361   int shift = INTVAL (operands[4]) & 31;
3362   int start = INTVAL (operands[2]) & 31;
3363   int size = INTVAL (operands[1]) & 31;
3364
3365   operands[4] = GEN_INT (shift - start - size);
3366   operands[1] = GEN_INT (start + size - 1);
3367   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3368 }"
3369   [(set_attr "type" "insert_word")])
3370
3371 (define_insn "*insvsi_internal2"
3372   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3373                          (match_operand:SI 1 "const_int_operand" "i")
3374                          (match_operand:SI 2 "const_int_operand" "i"))
3375         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3376                      (match_operand:SI 4 "const_int_operand" "i")))]
3377   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3378   "*
3379 {
3380   int shift = INTVAL (operands[4]) & 31;
3381   int start = INTVAL (operands[2]) & 31;
3382   int size = INTVAL (operands[1]) & 31;
3383
3384   operands[4] = GEN_INT (32 - shift - start - size);
3385   operands[1] = GEN_INT (start + size - 1);
3386   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3387 }"
3388   [(set_attr "type" "insert_word")])
3389
3390 (define_insn "*insvsi_internal3"
3391   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3392                          (match_operand:SI 1 "const_int_operand" "i")
3393                          (match_operand:SI 2 "const_int_operand" "i"))
3394         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3395                      (match_operand:SI 4 "const_int_operand" "i")))]
3396   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3397   "*
3398 {
3399   int shift = INTVAL (operands[4]) & 31;
3400   int start = INTVAL (operands[2]) & 31;
3401   int size = INTVAL (operands[1]) & 31;
3402
3403   operands[4] = GEN_INT (32 - shift - start - size);
3404   operands[1] = GEN_INT (start + size - 1);
3405   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3406 }"
3407   [(set_attr "type" "insert_word")])
3408
3409 (define_insn "*insvsi_internal4"
3410   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3411                          (match_operand:SI 1 "const_int_operand" "i")
3412                          (match_operand:SI 2 "const_int_operand" "i"))
3413         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3414                          (match_operand:SI 4 "const_int_operand" "i")
3415                          (match_operand:SI 5 "const_int_operand" "i")))]
3416   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3417   "*
3418 {
3419   int extract_start = INTVAL (operands[5]) & 31;
3420   int extract_size = INTVAL (operands[4]) & 31;
3421   int insert_start = INTVAL (operands[2]) & 31;
3422   int insert_size = INTVAL (operands[1]) & 31;
3423
3424 /* Align extract field with insert field */
3425   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3426   operands[1] = GEN_INT (insert_start + insert_size - 1);
3427   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
3428 }"
3429   [(set_attr "type" "insert_word")])
3430
3431 ;; combine patterns for rlwimi
3432 (define_insn "*insvsi_internal5"
3433   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3434         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3435                         (match_operand:SI 1 "mask_operand" "i"))
3436                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3437                                      (match_operand:SI 2 "const_int_operand" "i"))
3438                         (match_operand:SI 5 "mask_operand" "i"))))]
3439   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3440   "*
3441 {
3442  int me = extract_ME(operands[5]);
3443  int mb = extract_MB(operands[5]);
3444  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3445  operands[2] = GEN_INT(mb);
3446  operands[1] = GEN_INT(me);
3447  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3448 }"
3449   [(set_attr "type" "insert_word")])
3450
3451 (define_insn "*insvsi_internal6"
3452   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3453         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3454                                      (match_operand:SI 2 "const_int_operand" "i"))
3455                         (match_operand:SI 5 "mask_operand" "i"))
3456                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3457                         (match_operand:SI 1 "mask_operand" "i"))))]
3458   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3459   "*
3460 {
3461  int me = extract_ME(operands[5]);
3462  int mb = extract_MB(operands[5]);
3463  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3464  operands[2] = GEN_INT(mb);
3465  operands[1] = GEN_INT(me);
3466  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3467 }"
3468   [(set_attr "type" "insert_word")])
3469
3470 (define_insn "insvdi"
3471   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3472                          (match_operand:SI 1 "const_int_operand" "i")
3473                          (match_operand:SI 2 "const_int_operand" "i"))
3474         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3475   "TARGET_POWERPC64"
3476   "*
3477 {
3478   int start = INTVAL (operands[2]) & 63;
3479   int size = INTVAL (operands[1]) & 63;
3480
3481   operands[1] = GEN_INT (64 - start - size);
3482   return \"rldimi %0,%3,%H1,%H2\";
3483 }")
3484
3485 (define_insn "*insvdi_internal2"
3486   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3487                          (match_operand:SI 1 "const_int_operand" "i")
3488                          (match_operand:SI 2 "const_int_operand" "i"))
3489         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3490                      (match_operand:SI 4 "const_int_operand" "i")))]
3491   "TARGET_POWERPC64
3492    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3493   "*
3494 {
3495   int shift = INTVAL (operands[4]) & 63;
3496   int start = (INTVAL (operands[2]) & 63) - 32;
3497   int size = INTVAL (operands[1]) & 63;
3498
3499   operands[4] = GEN_INT (64 - shift - start - size);
3500   operands[2] = GEN_INT (start);
3501   operands[1] = GEN_INT (start + size - 1);
3502   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3503 }")
3504
3505 (define_insn "*insvdi_internal3"
3506   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3507                          (match_operand:SI 1 "const_int_operand" "i")
3508                          (match_operand:SI 2 "const_int_operand" "i"))
3509         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3510                      (match_operand:SI 4 "const_int_operand" "i")))]
3511   "TARGET_POWERPC64
3512    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3513   "*
3514 {
3515   int shift = INTVAL (operands[4]) & 63;
3516   int start = (INTVAL (operands[2]) & 63) - 32;
3517   int size = INTVAL (operands[1]) & 63;
3518
3519   operands[4] = GEN_INT (64 - shift - start - size);
3520   operands[2] = GEN_INT (start);
3521   operands[1] = GEN_INT (start + size - 1);
3522   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3523 }")
3524
3525 (define_expand "extzv"
3526   [(set (match_operand 0 "gpc_reg_operand" "")
3527         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3528                        (match_operand:SI 2 "const_int_operand" "")
3529                        (match_operand:SI 3 "const_int_operand" "")))]
3530   ""
3531   "
3532 {
3533   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3534      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3535      compiler if the address of the structure is taken later.  */
3536   if (GET_CODE (operands[0]) == SUBREG
3537       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3538     FAIL;
3539
3540   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3541     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
3542   else
3543     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
3544   DONE;
3545 }")
3546
3547 (define_insn "extzvsi"
3548   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3549         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3550                          (match_operand:SI 2 "const_int_operand" "i")
3551                          (match_operand:SI 3 "const_int_operand" "i")))]
3552   ""
3553   "*
3554 {
3555   int start = INTVAL (operands[3]) & 31;
3556   int size = INTVAL (operands[2]) & 31;
3557
3558   if (start + size >= 32)
3559     operands[3] = const0_rtx;
3560   else
3561     operands[3] = GEN_INT (start + size);
3562   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
3563 }")
3564
3565 (define_insn "*extzvsi_internal1"
3566   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3567         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3568                          (match_operand:SI 2 "const_int_operand" "i,i")
3569                          (match_operand:SI 3 "const_int_operand" "i,i"))
3570                     (const_int 0)))
3571    (clobber (match_scratch:SI 4 "=r,r"))]
3572   ""
3573   "*
3574 {
3575   int start = INTVAL (operands[3]) & 31;
3576   int size = INTVAL (operands[2]) & 31;
3577
3578   /* Force split for non-cc0 compare.  */
3579   if (which_alternative == 1)
3580      return \"#\";
3581
3582   /* If the bit-field being tested fits in the upper or lower half of a
3583      word, it is possible to use andiu. or andil. to test it.  This is
3584      useful because the condition register set-use delay is smaller for
3585      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3586      position is 0 because the LT and GT bits may be set wrong.  */
3587
3588   if ((start > 0 && start + size <= 16) || start >= 16)
3589     {
3590       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3591                               - (1 << (16 - (start & 15) - size))));
3592       if (start < 16)
3593         return \"{andiu.|andis.} %4,%1,%3\";
3594       else
3595         return \"{andil.|andi.} %4,%1,%3\";
3596     }
3597
3598   if (start + size >= 32)
3599     operands[3] = const0_rtx;
3600   else
3601     operands[3] = GEN_INT (start + size);
3602   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
3603 }"
3604   [(set_attr "type" "compare")
3605    (set_attr "length" "4,8")])
3606
3607 (define_split
3608   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3609         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3610                          (match_operand:SI 2 "const_int_operand" "")
3611                          (match_operand:SI 3 "const_int_operand" ""))
3612                     (const_int 0)))
3613    (clobber (match_scratch:SI 4 ""))]
3614   "reload_completed"
3615   [(set (match_dup 4)
3616         (zero_extract:SI (match_dup 1) (match_dup 2)
3617                          (match_dup 3)))
3618    (set (match_dup 0)
3619         (compare:CC (match_dup 4)
3620                     (const_int 0)))]
3621   "")
3622
3623 (define_insn "*extzvsi_internal2"
3624   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3625         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3626                          (match_operand:SI 2 "const_int_operand" "i,i")
3627                          (match_operand:SI 3 "const_int_operand" "i,i"))
3628                     (const_int 0)))
3629    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3630         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3631   ""
3632   "*
3633 {
3634   int start = INTVAL (operands[3]) & 31;
3635   int size = INTVAL (operands[2]) & 31;
3636
3637   /* Force split for non-cc0 compare.  */
3638   if (which_alternative == 1)
3639      return \"#\";
3640
3641   /* Since we are using the output value, we can't ignore any need for
3642      a shift.  The bit-field must end at the LSB.  */
3643   if (start >= 16 && start + size == 32)
3644     {
3645       operands[3] = GEN_INT ((1 << size) - 1);
3646       return \"{andil.|andi.} %0,%1,%3\";
3647     }
3648
3649   if (start + size >= 32)
3650     operands[3] = const0_rtx;
3651   else
3652     operands[3] = GEN_INT (start + size);
3653   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
3654 }"
3655   [(set_attr "type" "compare")
3656    (set_attr "length" "4,8")])
3657
3658 (define_split
3659   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3660         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3661                          (match_operand:SI 2 "const_int_operand" "")
3662                          (match_operand:SI 3 "const_int_operand" ""))
3663                     (const_int 0)))
3664    (set (match_operand:SI 0 "gpc_reg_operand" "")
3665         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3666   "reload_completed"
3667   [(set (match_dup 0)
3668         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3669    (set (match_dup 4)
3670         (compare:CC (match_dup 0)
3671                     (const_int 0)))]
3672   "")
3673
3674 (define_insn "extzvdi"
3675   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3676         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3677                          (match_operand:SI 2 "const_int_operand" "i")
3678                          (match_operand:SI 3 "const_int_operand" "i")))]
3679   "TARGET_POWERPC64"
3680   "*
3681 {
3682   int start = INTVAL (operands[3]) & 63;
3683   int size = INTVAL (operands[2]) & 63;
3684
3685   if (start + size >= 64)
3686     operands[3] = const0_rtx;
3687   else
3688     operands[3] = GEN_INT (start + size);
3689   operands[2] = GEN_INT (64 - size);
3690   return \"rldicl %0,%1,%3,%2\";
3691 }")
3692
3693 (define_insn "*extzvdi_internal1"
3694   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3695         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3696                          (match_operand:SI 2 "const_int_operand" "i")
3697                          (match_operand:SI 3 "const_int_operand" "i"))
3698                     (const_int 0)))
3699    (clobber (match_scratch:DI 4 "=r"))]
3700   "TARGET_64BIT"
3701   "*
3702 {
3703   int start = INTVAL (operands[3]) & 63;
3704   int size = INTVAL (operands[2]) & 63;
3705
3706   if (start + size >= 64)
3707     operands[3] = const0_rtx;
3708   else
3709     operands[3] = GEN_INT (start + size);
3710   operands[2] = GEN_INT (64 - size);
3711   return \"rldicl. %4,%1,%3,%2\";
3712 }"
3713   [(set_attr "type" "compare")])
3714
3715 (define_insn "*extzvdi_internal2"
3716   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3717         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3718                          (match_operand:SI 2 "const_int_operand" "i")
3719                          (match_operand:SI 3 "const_int_operand" "i"))
3720                     (const_int 0)))
3721    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3722         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3723   "TARGET_64BIT"
3724   "*
3725 {
3726   int start = INTVAL (operands[3]) & 63;
3727   int size = INTVAL (operands[2]) & 63;
3728
3729   if (start + size >= 64)
3730     operands[3] = const0_rtx;
3731   else
3732     operands[3] = GEN_INT (start + size);
3733   operands[2] = GEN_INT (64 - size);
3734   return \"rldicl. %0,%1,%3,%2\";
3735 }"
3736   [(set_attr "type" "compare")])
3737
3738 (define_insn "rotlsi3"
3739   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3740         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3741                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3742   ""
3743   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
3744
3745 (define_insn "*rotlsi3_internal2"
3746   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3747         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3748                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3749                     (const_int 0)))
3750    (clobber (match_scratch:SI 3 "=r,r"))]
3751   ""
3752   "@
3753    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff
3754    #"
3755   [(set_attr "type" "delayed_compare")
3756    (set_attr "length" "4,8")])
3757
3758 (define_split
3759   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3760         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3761                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3762                     (const_int 0)))
3763    (clobber (match_scratch:SI 3 ""))]
3764   "reload_completed"
3765   [(set (match_dup 3)
3766         (rotate:SI (match_dup 1) (match_dup 2)))
3767    (set (match_dup 0)
3768         (compare:CC (match_dup 3)
3769                     (const_int 0)))]
3770   "")
3771
3772 (define_insn "*rotlsi3_internal3"
3773   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3774         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3775                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3776                     (const_int 0)))
3777    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3778         (rotate:SI (match_dup 1) (match_dup 2)))]
3779   ""
3780   "@
3781    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff
3782    #"
3783   [(set_attr "type" "delayed_compare")
3784    (set_attr "length" "4,8")])
3785
3786 (define_split
3787   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3788         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3789                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3790                     (const_int 0)))
3791    (set (match_operand:SI 0 "gpc_reg_operand" "")
3792         (rotate:SI (match_dup 1) (match_dup 2)))]
3793   "reload_completed"
3794   [(set (match_dup 0)
3795         (rotate:SI (match_dup 1) (match_dup 2)))
3796    (set (match_dup 3)
3797         (compare:CC (match_dup 0)
3798                     (const_int 0)))]
3799   "")
3800
3801 (define_insn "*rotlsi3_internal4"
3802   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3803         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3804                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
3805                 (match_operand:SI 3 "mask_operand" "n")))]
3806   ""
3807   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
3808
3809 (define_insn "*rotlsi3_internal5"
3810   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3811         (compare:CC (and:SI
3812                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3813                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3814                      (match_operand:SI 3 "mask_operand" "n,n"))
3815                     (const_int 0)))
3816    (clobber (match_scratch:SI 4 "=r,r"))]
3817   ""
3818   "@
3819    {rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3
3820    #"
3821   [(set_attr "type" "delayed_compare")
3822    (set_attr "length" "4,8")])
3823
3824 (define_split
3825   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3826         (compare:CC (and:SI
3827                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3828                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3829                      (match_operand:SI 3 "mask_operand" ""))
3830                     (const_int 0)))
3831    (clobber (match_scratch:SI 4 ""))]
3832   "reload_completed"
3833   [(set (match_dup 4)
3834         (and:SI (rotate:SI (match_dup 1)
3835                                 (match_dup 2))
3836                      (match_dup 3)))
3837    (set (match_dup 0)
3838         (compare:CC (match_dup 4)
3839                     (const_int 0)))]
3840   "")
3841
3842 (define_insn "*rotlsi3_internal6"
3843   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3844         (compare:CC (and:SI
3845                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3846                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3847                      (match_operand:SI 3 "mask_operand" "n,n"))
3848                     (const_int 0)))
3849    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3850         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3851   ""
3852   "@
3853    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3
3854    #"
3855   [(set_attr "type" "delayed_compare")
3856    (set_attr "length" "4,8")])
3857
3858 (define_split
3859   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3860         (compare:CC (and:SI
3861                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3862                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3863                      (match_operand:SI 3 "mask_operand" ""))
3864                     (const_int 0)))
3865    (set (match_operand:SI 0 "gpc_reg_operand" "")
3866         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3867   "reload_completed"
3868   [(set (match_dup 0)
3869         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3870    (set (match_dup 4)
3871         (compare:CC (match_dup 0)
3872                     (const_int 0)))]
3873   "")
3874
3875 (define_insn "*rotlsi3_internal7"
3876   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3877         (zero_extend:SI
3878          (subreg:QI
3879           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3880                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3881   ""
3882   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
3883
3884 (define_insn "*rotlsi3_internal8"
3885   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3886         (compare:CC (zero_extend:SI
3887                      (subreg:QI
3888                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3889                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3890                     (const_int 0)))
3891    (clobber (match_scratch:SI 3 "=r,r"))]
3892   ""
3893   "@
3894    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff
3895    #"
3896   [(set_attr "type" "delayed_compare")
3897    (set_attr "length" "4,8")])
3898
3899 (define_split
3900   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3901         (compare:CC (zero_extend:SI
3902                      (subreg:QI
3903                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3904                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3905                     (const_int 0)))
3906    (clobber (match_scratch:SI 3 ""))]
3907   "reload_completed"
3908   [(set (match_dup 3)
3909         (zero_extend:SI (subreg:QI
3910                       (rotate:SI (match_dup 1)
3911                                  (match_dup 2)) 0)))
3912    (set (match_dup 0)
3913         (compare:CC (match_dup 3)
3914                     (const_int 0)))]
3915   "")
3916
3917 (define_insn "*rotlsi3_internal9"
3918   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3919         (compare:CC (zero_extend:SI
3920                      (subreg:QI
3921                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3922                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3923                     (const_int 0)))
3924    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3925         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3926   ""
3927   "@
3928    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff
3929    #"
3930   [(set_attr "type" "delayed_compare")
3931    (set_attr "length" "4,8")])
3932
3933 (define_split
3934   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3935         (compare:CC (zero_extend:SI
3936                      (subreg:QI
3937                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3938                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3939                     (const_int 0)))
3940    (set (match_operand:SI 0 "gpc_reg_operand" "")
3941         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3942   "reload_completed"
3943   [(set (match_dup 0)
3944         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3945    (set (match_dup 3)
3946         (compare:CC (match_dup 0)
3947                     (const_int 0)))]
3948   "")
3949
3950 (define_insn "*rotlsi3_internal10"
3951   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3952         (zero_extend:SI
3953          (subreg:HI
3954           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3955                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3956   ""
3957   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
3958
3959 (define_insn "*rotlsi3_internal11"
3960   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3961         (compare:CC (zero_extend:SI
3962                      (subreg:HI
3963                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3964                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3965                     (const_int 0)))
3966    (clobber (match_scratch:SI 3 "=r,r"))]
3967   ""
3968   "@
3969    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff
3970    #"
3971   [(set_attr "type" "delayed_compare")
3972    (set_attr "length" "4,8")])
3973
3974 (define_split
3975   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3976         (compare:CC (zero_extend:SI
3977                      (subreg:HI
3978                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3979                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3980                     (const_int 0)))
3981    (clobber (match_scratch:SI 3 ""))]
3982   "reload_completed"
3983   [(set (match_dup 3)
3984         (zero_extend:SI (subreg:HI
3985                       (rotate:SI (match_dup 1)
3986                                  (match_dup 2)) 0)))
3987    (set (match_dup 0)
3988         (compare:CC (match_dup 3)
3989                     (const_int 0)))]
3990   "")
3991
3992 (define_insn "*rotlsi3_internal12"
3993   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3994         (compare:CC (zero_extend:SI
3995                      (subreg:HI
3996                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3997                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3998                     (const_int 0)))
3999    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4000         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4001   ""
4002   "@
4003    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff
4004    #"
4005   [(set_attr "type" "delayed_compare")
4006    (set_attr "length" "4,8")])
4007
4008 (define_split
4009   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4010         (compare:CC (zero_extend:SI
4011                      (subreg:HI
4012                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4013                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4014                     (const_int 0)))
4015    (set (match_operand:SI 0 "gpc_reg_operand" "")
4016         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4017   "reload_completed"
4018   [(set (match_dup 0)
4019         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4020    (set (match_dup 3)
4021         (compare:CC (match_dup 0)
4022                     (const_int 0)))]
4023   "")
4024
4025 ;; Note that we use "sle." instead of "sl." so that we can set
4026 ;; SHIFT_COUNT_TRUNCATED.
4027
4028 (define_expand "ashlsi3"
4029   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4030    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4031    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4032   ""
4033   "
4034 {
4035   if (TARGET_POWER)
4036     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
4037   else
4038     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
4039   DONE;
4040 }")
4041
4042 (define_insn "ashlsi3_power"
4043   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4044         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4045                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4046    (clobber (match_scratch:SI 3 "=q,X"))]
4047   "TARGET_POWER"
4048   "@
4049    sle %0,%1,%2
4050    {sli|slwi} %0,%1,%h2")
4051
4052 (define_insn "ashlsi3_no_power"
4053   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4054         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4055                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4056   "! TARGET_POWER"
4057   "{sl|slw}%I2 %0,%1,%h2")
4058
4059 (define_insn ""
4060   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4061         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4062                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4063                     (const_int 0)))
4064    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4065    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4066   "TARGET_POWER"
4067   "@
4068    sle. %3,%1,%2
4069    {sli.|slwi.} %3,%1,%h2
4070    #
4071    #"
4072   [(set_attr "type" "delayed_compare")
4073    (set_attr "length" "4,4,8,8")])
4074
4075 (define_split
4076   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4077         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4078                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4079                     (const_int 0)))
4080    (clobber (match_scratch:SI 3 ""))
4081    (clobber (match_scratch:SI 4 ""))]
4082   "TARGET_POWER && reload_completed"
4083   [(parallel [(set (match_dup 3)
4084         (ashift:SI (match_dup 1) (match_dup 2)))
4085    (clobber (match_dup 4))])
4086    (set (match_dup 0)
4087         (compare:CC (match_dup 3)
4088                     (const_int 0)))]
4089   "")
4090
4091 (define_insn ""
4092   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4093         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4094                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4095                     (const_int 0)))
4096    (clobber (match_scratch:SI 3 "=r,r"))]
4097   "! TARGET_POWER && TARGET_32BIT"
4098   "@
4099    {sl|slw}%I2. %3,%1,%h2
4100    #"
4101   [(set_attr "type" "delayed_compare")
4102    (set_attr "length" "4,8")])
4103
4104 (define_split
4105   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4106         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4107                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4108                     (const_int 0)))
4109    (clobber (match_scratch:SI 3 ""))]
4110   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4111   [(set (match_dup 3)
4112         (ashift:SI (match_dup 1) (match_dup 2)))
4113    (set (match_dup 0)
4114         (compare:CC (match_dup 3)
4115                     (const_int 0)))]
4116   "")
4117
4118 (define_insn ""
4119   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4120         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4121                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4122                     (const_int 0)))
4123    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4124         (ashift:SI (match_dup 1) (match_dup 2)))
4125    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4126   "TARGET_POWER"
4127   "@
4128    sle. %0,%1,%2
4129    {sli.|slwi.} %0,%1,%h2
4130    #
4131    #"
4132   [(set_attr "type" "delayed_compare")
4133    (set_attr "length" "4,4,8,8")])
4134
4135 (define_split
4136   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4137         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4138                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4139                     (const_int 0)))
4140    (set (match_operand:SI 0 "gpc_reg_operand" "")
4141         (ashift:SI (match_dup 1) (match_dup 2)))
4142    (clobber (match_scratch:SI 4 ""))]
4143   "TARGET_POWER && reload_completed"
4144   [(parallel [(set (match_dup 0)
4145         (ashift:SI (match_dup 1) (match_dup 2)))
4146    (clobber (match_dup 4))])
4147    (set (match_dup 3)
4148         (compare:CC (match_dup 0)
4149                     (const_int 0)))]
4150   "")
4151
4152 (define_insn ""
4153   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4154         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4155                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4156                     (const_int 0)))
4157    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4158         (ashift:SI (match_dup 1) (match_dup 2)))]
4159   "! TARGET_POWER && TARGET_32BIT"
4160   "@
4161    {sl|slw}%I2. %0,%1,%h2
4162    #"
4163   [(set_attr "type" "delayed_compare")
4164    (set_attr "length" "4,8")])
4165
4166 (define_split
4167   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4168         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4169                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4170                     (const_int 0)))
4171    (set (match_operand:SI 0 "gpc_reg_operand" "")
4172         (ashift:SI (match_dup 1) (match_dup 2)))]
4173   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4174   [(set (match_dup 0)
4175         (ashift:SI (match_dup 1) (match_dup 2)))
4176    (set (match_dup 3)
4177         (compare:CC (match_dup 0)
4178                     (const_int 0)))]
4179   "")
4180
4181 (define_insn "rlwinm"
4182   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4183         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4184                            (match_operand:SI 2 "const_int_operand" "i"))
4185                 (match_operand:SI 3 "mask_operand" "n")))]
4186   "includes_lshift_p (operands[2], operands[3])"
4187   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
4188
4189 (define_insn ""
4190   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4191         (compare:CC
4192          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4193                             (match_operand:SI 2 "const_int_operand" "i,i"))
4194                  (match_operand:SI 3 "mask_operand" "n,n"))
4195          (const_int 0)))
4196    (clobber (match_scratch:SI 4 "=r,r"))]
4197   "includes_lshift_p (operands[2], operands[3])"
4198   "@
4199    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
4200    #"
4201   [(set_attr "type" "delayed_compare")
4202    (set_attr "length" "4,8")])
4203
4204 (define_split
4205   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4206         (compare:CC
4207          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4208                             (match_operand:SI 2 "const_int_operand" ""))
4209                  (match_operand:SI 3 "mask_operand" ""))
4210          (const_int 0)))
4211    (clobber (match_scratch:SI 4 ""))]
4212   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4213   [(set (match_dup 4)
4214         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
4215                  (match_dup 3)))
4216    (set (match_dup 0)
4217         (compare:CC (match_dup 4)
4218                     (const_int 0)))]
4219   "")
4220
4221 (define_insn ""
4222   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4223         (compare:CC
4224          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4225                             (match_operand:SI 2 "const_int_operand" "i,i"))
4226                  (match_operand:SI 3 "mask_operand" "n,n"))
4227          (const_int 0)))
4228    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4229         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4230   "includes_lshift_p (operands[2], operands[3])"
4231   "@
4232    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
4233    #"
4234   [(set_attr "type" "delayed_compare")
4235    (set_attr "length" "4,8")])
4236
4237 (define_split
4238   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4239         (compare:CC
4240          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4241                             (match_operand:SI 2 "const_int_operand" ""))
4242                  (match_operand:SI 3 "mask_operand" ""))
4243          (const_int 0)))
4244    (set (match_operand:SI 0 "gpc_reg_operand" "")
4245         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4246   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4247   [(set (match_dup 0)
4248         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4249    (set (match_dup 4)
4250         (compare:CC (match_dup 0)
4251                     (const_int 0)))]
4252   "")
4253
4254 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
4255 ;; "sli x,x,0".
4256 (define_expand "lshrsi3"
4257   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4258    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4259    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4260   ""
4261   "
4262 {
4263   if (TARGET_POWER)
4264     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
4265   else
4266     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
4267   DONE;
4268 }")
4269
4270 (define_insn "lshrsi3_power"
4271   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4272         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4273                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
4274    (clobber (match_scratch:SI 3 "=q,X,X"))]
4275   "TARGET_POWER"
4276   "@
4277   sre %0,%1,%2
4278   mr %0,%1
4279   {s%A2i|s%A2wi} %0,%1,%h2")
4280
4281 (define_insn "lshrsi3_no_power"
4282   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4283         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4284                      (match_operand:SI 2 "reg_or_cint_operand" "O,ri")))]
4285   "! TARGET_POWER"
4286   "@
4287   mr %0,%1
4288   {sr|srw}%I2 %0,%1,%h2")
4289
4290 (define_insn ""
4291   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4292         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4293                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
4294                     (const_int 0)))
4295    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
4296    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
4297   "TARGET_POWER"
4298   "@
4299   sre. %3,%1,%2
4300   mr. %1,%1
4301   {s%A2i.|s%A2wi.} %3,%1,%h2
4302   #
4303   #
4304   #"
4305   [(set_attr "type" "delayed_compare")
4306    (set_attr "length" "4,4,4,8,8,8")])
4307
4308 (define_split
4309   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4310         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4311                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4312                     (const_int 0)))
4313    (clobber (match_scratch:SI 3 ""))
4314    (clobber (match_scratch:SI 4 ""))]
4315   "TARGET_POWER && reload_completed"
4316   [(parallel [(set (match_dup 3)
4317         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4318    (clobber (match_dup 4))])
4319    (set (match_dup 0)
4320         (compare:CC (match_dup 3)
4321                     (const_int 0)))]
4322   "")
4323
4324 (define_insn ""
4325   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4326         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4327                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
4328                     (const_int 0)))
4329    (clobber (match_scratch:SI 3 "=X,r,X,r"))]
4330   "! TARGET_POWER && TARGET_32BIT"
4331   "@
4332    mr. %1,%1
4333    {sr|srw}%I2. %3,%1,%h2
4334    #
4335    #"
4336   [(set_attr "type" "delayed_compare")
4337    (set_attr "length" "4,4,8,8")])
4338
4339 (define_split
4340   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4341         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4342                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4343                     (const_int 0)))
4344    (clobber (match_scratch:SI 3 ""))]
4345   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4346   [(set (match_dup 3)
4347         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4348    (set (match_dup 0)
4349         (compare:CC (match_dup 3)
4350                     (const_int 0)))]
4351   "")
4352
4353 (define_insn ""
4354   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4355         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4356                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
4357                     (const_int 0)))
4358    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
4359         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4360    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
4361   "TARGET_POWER"
4362   "@
4363   sre. %0,%1,%2
4364   mr. %0,%1
4365   {s%A2i.|s%A2wi.} %0,%1,%h2
4366   #
4367   #
4368   #"
4369   [(set_attr "type" "delayed_compare")
4370    (set_attr "length" "4,4,4,8,8,8")])
4371
4372 (define_split
4373   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4374         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4375                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4376                     (const_int 0)))
4377    (set (match_operand:SI 0 "gpc_reg_operand" "")
4378         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4379    (clobber (match_scratch:SI 4 ""))]
4380   "TARGET_POWER && reload_completed"
4381   [(parallel [(set (match_dup 0)
4382         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4383    (clobber (match_dup 4))])
4384    (set (match_dup 3)
4385         (compare:CC (match_dup 0)
4386                     (const_int 0)))]
4387   "")
4388
4389 (define_insn ""
4390   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4391         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4392                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
4393                     (const_int 0)))
4394    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4395         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4396   "! TARGET_POWER && TARGET_32BIT"
4397   "@
4398    mr. %0,%1
4399    {sr|srw}%I2. %0,%1,%h2
4400    #
4401    #"
4402   [(set_attr "type" "delayed_compare")
4403    (set_attr "length" "4,4,8,8")])
4404
4405 (define_split
4406   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4407         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4408                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4409                     (const_int 0)))
4410    (set (match_operand:SI 0 "gpc_reg_operand" "")
4411         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4412   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4413   [(set (match_dup 0)
4414         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4415    (set (match_dup 3)
4416         (compare:CC (match_dup 0)
4417                     (const_int 0)))]
4418   "")
4419
4420 (define_insn ""
4421   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4422         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4423                              (match_operand:SI 2 "const_int_operand" "i"))
4424                 (match_operand:SI 3 "mask_operand" "n")))]
4425   "includes_rshift_p (operands[2], operands[3])"
4426   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
4427
4428 (define_insn ""
4429   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4430         (compare:CC
4431          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4432                               (match_operand:SI 2 "const_int_operand" "i,i"))
4433                  (match_operand:SI 3 "mask_operand" "n,n"))
4434          (const_int 0)))
4435    (clobber (match_scratch:SI 4 "=r,r"))]
4436   "includes_rshift_p (operands[2], operands[3])"
4437   "@
4438    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
4439    #"
4440   [(set_attr "type" "delayed_compare")
4441    (set_attr "length" "4,8")])
4442
4443 (define_split
4444   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4445         (compare:CC
4446          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4447                               (match_operand:SI 2 "const_int_operand" ""))
4448                  (match_operand:SI 3 "mask_operand" ""))
4449          (const_int 0)))
4450    (clobber (match_scratch:SI 4 ""))]
4451   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4452   [(set (match_dup 4)
4453         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4454                  (match_dup 3)))
4455    (set (match_dup 0)
4456         (compare:CC (match_dup 4)
4457                     (const_int 0)))]
4458   "")
4459
4460 (define_insn ""
4461   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4462         (compare:CC
4463          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4464                               (match_operand:SI 2 "const_int_operand" "i,i"))
4465                  (match_operand:SI 3 "mask_operand" "n,n"))
4466          (const_int 0)))
4467    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4468         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4469   "includes_rshift_p (operands[2], operands[3])"
4470   "@
4471    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
4472    #"
4473   [(set_attr "type" "delayed_compare")
4474    (set_attr "length" "4,8")])
4475
4476 (define_split
4477   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4478         (compare:CC
4479          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4480                               (match_operand:SI 2 "const_int_operand" ""))
4481                  (match_operand:SI 3 "mask_operand" ""))
4482          (const_int 0)))
4483    (set (match_operand:SI 0 "gpc_reg_operand" "")
4484         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4485   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4486   [(set (match_dup 0)
4487         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4488    (set (match_dup 4)
4489         (compare:CC (match_dup 0)
4490                     (const_int 0)))]
4491   "")
4492
4493 (define_insn ""
4494   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4495         (zero_extend:SI
4496          (subreg:QI
4497           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4498                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4499   "includes_rshift_p (operands[2], GEN_INT (255))"
4500   "{rlinm|rlwinm} %0,%1,%s2,0xff")
4501
4502 (define_insn ""
4503   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4504         (compare:CC
4505          (zero_extend:SI
4506           (subreg:QI
4507            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4508                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4509          (const_int 0)))
4510    (clobber (match_scratch:SI 3 "=r,r"))]
4511   "includes_rshift_p (operands[2], GEN_INT (255))"
4512   "@
4513    {rlinm.|rlwinm.} %3,%1,%s2,0xff
4514    #"
4515   [(set_attr "type" "delayed_compare")
4516    (set_attr "length" "4,8")])
4517
4518 (define_split
4519   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4520         (compare:CC
4521          (zero_extend:SI
4522           (subreg:QI
4523            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4524                         (match_operand:SI 2 "const_int_operand" "")) 0))
4525          (const_int 0)))
4526    (clobber (match_scratch:SI 3 ""))]
4527   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4528   [(set (match_dup 3)
4529         (zero_extend:SI (subreg:QI
4530            (lshiftrt:SI (match_dup 1)
4531                         (match_dup 2)) 0)))
4532    (set (match_dup 0)
4533         (compare:CC (match_dup 3)
4534                     (const_int 0)))]
4535   "")
4536
4537 (define_insn ""
4538   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4539         (compare:CC
4540          (zero_extend:SI
4541           (subreg:QI
4542            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4543                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4544          (const_int 0)))
4545    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4546         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4547   "includes_rshift_p (operands[2], GEN_INT (255))"
4548   "@
4549    {rlinm.|rlwinm.} %0,%1,%s2,0xff
4550    #"
4551   [(set_attr "type" "delayed_compare")
4552    (set_attr "length" "4,8")])
4553
4554 (define_split
4555   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4556         (compare:CC
4557          (zero_extend:SI
4558           (subreg:QI
4559            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4560                         (match_operand:SI 2 "const_int_operand" "")) 0))
4561          (const_int 0)))
4562    (set (match_operand:SI 0 "gpc_reg_operand" "")
4563         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4564   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4565   [(set (match_dup 0)
4566         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4567    (set (match_dup 3)
4568         (compare:CC (match_dup 0)
4569                     (const_int 0)))]
4570   "")
4571
4572 (define_insn ""
4573   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4574         (zero_extend:SI
4575          (subreg:HI
4576           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4577                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4578   "includes_rshift_p (operands[2], GEN_INT (65535))"
4579   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
4580
4581 (define_insn ""
4582   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4583         (compare:CC
4584          (zero_extend:SI
4585           (subreg:HI
4586            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4587                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4588          (const_int 0)))
4589    (clobber (match_scratch:SI 3 "=r,r"))]
4590   "includes_rshift_p (operands[2], GEN_INT (65535))"
4591   "@
4592    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
4593    #"
4594   [(set_attr "type" "delayed_compare")
4595    (set_attr "length" "4,8")])
4596
4597 (define_split
4598   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4599         (compare:CC
4600          (zero_extend:SI
4601           (subreg:HI
4602            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4603                         (match_operand:SI 2 "const_int_operand" "")) 0))
4604          (const_int 0)))
4605    (clobber (match_scratch:SI 3 ""))]
4606   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4607   [(set (match_dup 3)
4608         (zero_extend:SI (subreg:HI
4609            (lshiftrt:SI (match_dup 1)
4610                         (match_dup 2)) 0)))
4611    (set (match_dup 0)
4612         (compare:CC (match_dup 3)
4613                     (const_int 0)))]
4614   "")
4615
4616 (define_insn ""
4617   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4618         (compare:CC
4619          (zero_extend:SI
4620           (subreg:HI
4621            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4622                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4623          (const_int 0)))
4624    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4625         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4626   "includes_rshift_p (operands[2], GEN_INT (65535))"
4627   "@
4628    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
4629    #"
4630   [(set_attr "type" "delayed_compare")
4631    (set_attr "length" "4,8")])
4632
4633 (define_split
4634   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4635         (compare:CC
4636          (zero_extend:SI
4637           (subreg:HI
4638            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4639                         (match_operand:SI 2 "const_int_operand" "")) 0))
4640          (const_int 0)))
4641    (set (match_operand:SI 0 "gpc_reg_operand" "")
4642         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4643   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4644   [(set (match_dup 0)
4645         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4646    (set (match_dup 3)
4647         (compare:CC (match_dup 0)
4648                     (const_int 0)))]
4649   "")
4650
4651 (define_insn ""
4652   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4653                          (const_int 1)
4654                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4655         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4656                      (const_int 31)))]
4657   "TARGET_POWER"
4658   "rrib %0,%1,%2")
4659
4660 (define_insn ""
4661   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4662                          (const_int 1)
4663                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4664         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4665                      (const_int 31)))]
4666   "TARGET_POWER"
4667   "rrib %0,%1,%2")
4668
4669 (define_insn ""
4670   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4671                          (const_int 1)
4672                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4673         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4674                          (const_int 1)
4675                          (const_int 0)))]
4676   "TARGET_POWER"
4677   "rrib %0,%1,%2")
4678
4679 (define_expand "ashrsi3"
4680   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4681         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4682                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4683   ""
4684   "
4685 {
4686   if (TARGET_POWER)
4687     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
4688   else
4689     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
4690   DONE;
4691 }")
4692
4693 (define_insn "ashrsi3_power"
4694   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4695         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4696                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4697    (clobber (match_scratch:SI 3 "=q,X"))]
4698   "TARGET_POWER"
4699   "@
4700    srea %0,%1,%2
4701    {srai|srawi} %0,%1,%h2")
4702
4703 (define_insn "ashrsi3_no_power"
4704   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4705         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4706                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4707   "! TARGET_POWER"
4708   "{sra|sraw}%I2 %0,%1,%h2")
4709
4710 (define_insn ""
4711   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4712         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4713                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4714                     (const_int 0)))
4715    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4716    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4717   "TARGET_POWER"
4718   "@
4719    srea. %3,%1,%2
4720    {srai.|srawi.} %3,%1,%h2
4721    #
4722    #"
4723   [(set_attr "type" "delayed_compare")
4724    (set_attr "length" "4,4,8,8")])
4725
4726 (define_split
4727   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4728         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4729                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4730                     (const_int 0)))
4731    (clobber (match_scratch:SI 3 ""))
4732    (clobber (match_scratch:SI 4 ""))]
4733   "TARGET_POWER && reload_completed"
4734   [(parallel [(set (match_dup 3)
4735         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4736    (clobber (match_dup 4))])
4737    (set (match_dup 0)
4738         (compare:CC (match_dup 3)
4739                     (const_int 0)))]
4740   "")
4741
4742 (define_insn ""
4743   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4744         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4745                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4746                     (const_int 0)))
4747    (clobber (match_scratch:SI 3 "=r,r"))]
4748   "! TARGET_POWER"
4749   "@
4750    {sra|sraw}%I2. %3,%1,%h2
4751    #"
4752   [(set_attr "type" "delayed_compare")
4753    (set_attr "length" "4,8")])
4754
4755 (define_split
4756   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4757         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4758                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4759                     (const_int 0)))
4760    (clobber (match_scratch:SI 3 ""))]
4761   "! TARGET_POWER && reload_completed"
4762   [(set (match_dup 3)
4763         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4764    (set (match_dup 0)
4765         (compare:CC (match_dup 3)
4766                     (const_int 0)))]
4767   "")
4768
4769 (define_insn ""
4770   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4771         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4772                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4773                     (const_int 0)))
4774    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4775         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4776    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4777   "TARGET_POWER"
4778   "@
4779    srea. %0,%1,%2
4780    {srai.|srawi.} %0,%1,%h2
4781    #
4782    #"
4783   [(set_attr "type" "delayed_compare")
4784    (set_attr "length" "4,4,8,8")])
4785
4786 (define_split
4787   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4788         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4789                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4790                     (const_int 0)))
4791    (set (match_operand:SI 0 "gpc_reg_operand" "")
4792         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4793    (clobber (match_scratch:SI 4 ""))]
4794   "TARGET_POWER && reload_completed"
4795   [(parallel [(set (match_dup 0)
4796         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4797    (clobber (match_dup 4))])
4798    (set (match_dup 3)
4799         (compare:CC (match_dup 0)
4800                     (const_int 0)))]
4801   "")
4802
4803 (define_insn ""
4804   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4805         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4806                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4807                     (const_int 0)))
4808    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4809         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4810   "! TARGET_POWER"
4811   "@
4812    {sra|sraw}%I2. %0,%1,%h2
4813    #"
4814   [(set_attr "type" "delayed_compare")
4815    (set_attr "length" "4,8")])
4816 \f
4817 (define_split
4818   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4819         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4820                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4821                     (const_int 0)))
4822    (set (match_operand:SI 0 "gpc_reg_operand" "")
4823         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4824   "! TARGET_POWER && reload_completed"
4825   [(set (match_dup 0)
4826         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4827    (set (match_dup 3)
4828         (compare:CC (match_dup 0)
4829                     (const_int 0)))]
4830   "")
4831
4832 ;; Floating-point insns, excluding normal data motion.
4833 ;;
4834 ;; PowerPC has a full set of single-precision floating point instructions.
4835 ;;
4836 ;; For the POWER architecture, we pretend that we have both SFmode and
4837 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
4838 ;; The only conversions we will do will be when storing to memory.  In that
4839 ;; case, we will use the "frsp" instruction before storing.
4840 ;;
4841 ;; Note that when we store into a single-precision memory location, we need to
4842 ;; use the frsp insn first.  If the register being stored isn't dead, we
4843 ;; need a scratch register for the frsp.  But this is difficult when the store
4844 ;; is done by reload.  It is not incorrect to do the frsp on the register in
4845 ;; this case, we just lose precision that we would have otherwise gotten but
4846 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
4847
4848 (define_expand "extendsfdf2"
4849   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4850         (float_extend:DF (match_operand:SF 1 "reg_or_none500mem_operand" "")))]
4851   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4852   "")
4853
4854 (define_insn_and_split "*extendsfdf2_fpr"
4855   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f,f")
4856         (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m")))]
4857   "TARGET_HARD_FLOAT && TARGET_FPRS"
4858   "@
4859    #
4860    fmr %0,%1
4861    lfs%U1%X1 %0,%1"
4862   "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
4863   [(const_int 0)]
4864 {
4865   emit_note (NOTE_INSN_DELETED);
4866   DONE;
4867 }
4868   [(set_attr "type" "fp,fp,fpload")])
4869
4870 (define_expand "truncdfsf2"
4871   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4872         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
4873   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4874   "")
4875
4876 (define_insn "*truncdfsf2_fpr"
4877   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4878         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4879   "TARGET_HARD_FLOAT && TARGET_FPRS"
4880   "frsp %0,%1"
4881   [(set_attr "type" "fp")])
4882
4883 (define_insn "aux_truncdfsf2"
4884   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4885         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
4886   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4887   "frsp %0,%1"
4888   [(set_attr "type" "fp")])
4889
4890 (define_expand "negsf2"
4891   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4892         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4893   "TARGET_HARD_FLOAT"
4894   "")
4895
4896 (define_insn "*negsf2"
4897   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4898         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4899   "TARGET_HARD_FLOAT && TARGET_FPRS"
4900   "fneg %0,%1"
4901   [(set_attr "type" "fp")])
4902
4903 (define_expand "abssf2"
4904   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4905         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4906   "TARGET_HARD_FLOAT"
4907   "")
4908
4909 (define_insn "*abssf2"
4910   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4911         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4912   "TARGET_HARD_FLOAT && TARGET_FPRS"
4913   "fabs %0,%1"
4914   [(set_attr "type" "fp")])
4915
4916 (define_insn ""
4917   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4918         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
4919   "TARGET_HARD_FLOAT && TARGET_FPRS"
4920   "fnabs %0,%1"
4921   [(set_attr "type" "fp")])
4922
4923 (define_expand "addsf3"
4924   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4925         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4926                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4927   "TARGET_HARD_FLOAT"
4928   "")
4929
4930 (define_insn ""
4931   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4932         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4933                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4934   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4935   "fadds %0,%1,%2"
4936   [(set_attr "type" "fp")])
4937
4938 (define_insn ""
4939   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4940         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4941                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4942   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4943   "{fa|fadd} %0,%1,%2"
4944   [(set_attr "type" "fp")])
4945
4946 (define_expand "subsf3"
4947   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4948         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4949                   (match_operand:SF 2 "gpc_reg_operand" "")))]
4950   "TARGET_HARD_FLOAT"
4951   "")
4952
4953 (define_insn ""
4954   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4955         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4956                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4957   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4958   "fsubs %0,%1,%2"
4959   [(set_attr "type" "fp")])
4960
4961 (define_insn ""
4962   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4963         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4964                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4965   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4966   "{fs|fsub} %0,%1,%2"
4967   [(set_attr "type" "fp")])
4968
4969 (define_expand "mulsf3"
4970   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4971         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
4972                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4973   "TARGET_HARD_FLOAT"
4974   "")
4975
4976 (define_insn ""
4977   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4978         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4979                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4980   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4981   "fmuls %0,%1,%2"
4982   [(set_attr "type" "fp")])
4983
4984 (define_insn ""
4985   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4986         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4987                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4988   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4989   "{fm|fmul} %0,%1,%2"
4990   [(set_attr "type" "dmul")])
4991
4992 (define_insn "fres"
4993   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4994         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
4995   "TARGET_PPC_GFXOPT && flag_finite_math_only"
4996   "fres %0,%1"
4997   [(set_attr "type" "fp")])
4998
4999 (define_expand "divsf3"
5000   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5001         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
5002                 (match_operand:SF 2 "gpc_reg_operand" "")))]
5003   "TARGET_HARD_FLOAT"
5004 {
5005   if (swdiv && !optimize_size && TARGET_PPC_GFXOPT
5006   && flag_finite_math_only && !flag_trapping_math)
5007     {
5008       rs6000_emit_swdivsf (operands[0], operands[1], operands[2]);
5009       DONE;
5010     }
5011 })
5012
5013 (define_insn ""
5014   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5015         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5016                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5017   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5018   "fdivs %0,%1,%2"
5019   [(set_attr "type" "sdiv")])
5020
5021 (define_insn ""
5022   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5023         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5024                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5025   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5026   "{fd|fdiv} %0,%1,%2"
5027   [(set_attr "type" "ddiv")])
5028
5029 (define_insn ""
5030   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5031         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5032                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5033                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5034   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5035   "fmadds %0,%1,%2,%3"
5036   [(set_attr "type" "fp")])
5037
5038 (define_insn ""
5039   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5040         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5041                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5042                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5043   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5044   "{fma|fmadd} %0,%1,%2,%3"
5045   [(set_attr "type" "dmul")])
5046
5047 (define_insn ""
5048   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5049         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5050                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5051                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5052   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5053   "fmsubs %0,%1,%2,%3"
5054   [(set_attr "type" "fp")])
5055
5056 (define_insn ""
5057   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5058         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5059                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5060                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5061   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5062   "{fms|fmsub} %0,%1,%2,%3"
5063   [(set_attr "type" "dmul")])
5064
5065 (define_insn ""
5066   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5067         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5068                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5069                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5070   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5071    && HONOR_SIGNED_ZEROS (SFmode)"
5072   "fnmadds %0,%1,%2,%3"
5073   [(set_attr "type" "fp")])
5074
5075 (define_insn ""
5076   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5077         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5078                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5079                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5080   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5081    && ! HONOR_SIGNED_ZEROS (SFmode)"
5082   "fnmadds %0,%1,%2,%3"
5083   [(set_attr "type" "fp")])
5084
5085 (define_insn ""
5086   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5087         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5088                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5089                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5090   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5091   "{fnma|fnmadd} %0,%1,%2,%3"
5092   [(set_attr "type" "dmul")])
5093
5094 (define_insn ""
5095   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5096         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
5097                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5098                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5099   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5100    && ! HONOR_SIGNED_ZEROS (SFmode)"
5101   "{fnma|fnmadd} %0,%1,%2,%3"
5102   [(set_attr "type" "dmul")])
5103
5104 (define_insn ""
5105   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5106         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5107                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5108                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5109   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5110    && HONOR_SIGNED_ZEROS (SFmode)"
5111   "fnmsubs %0,%1,%2,%3"
5112   [(set_attr "type" "fp")])
5113
5114 (define_insn ""
5115   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5116         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
5117                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5118                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
5119   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5120    && ! HONOR_SIGNED_ZEROS (SFmode)"
5121   "fnmsubs %0,%1,%2,%3"
5122   [(set_attr "type" "fp")])
5123
5124 (define_insn ""
5125   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5126         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5127                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5128                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5129   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5130   "{fnms|fnmsub} %0,%1,%2,%3"
5131   [(set_attr "type" "dmul")])
5132
5133 (define_insn ""
5134   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5135         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
5136                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5137                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
5138   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5139    && ! HONOR_SIGNED_ZEROS (SFmode)"
5140   "{fnms|fnmsub} %0,%1,%2,%3"
5141   [(set_attr "type" "dmul")])
5142
5143 (define_expand "sqrtsf2"
5144   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5145         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5146   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
5147   "")
5148
5149 (define_insn ""
5150   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5151         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5152   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5153   "fsqrts %0,%1"
5154   [(set_attr "type" "ssqrt")])
5155
5156 (define_insn ""
5157   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5158         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5159   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS"
5160   "fsqrt %0,%1"
5161   [(set_attr "type" "dsqrt")])
5162
5163 (define_expand "copysignsf3"
5164   [(set (match_dup 3)
5165         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))
5166    (set (match_dup 4)
5167         (neg:SF (abs:SF (match_dup 1))))
5168    (set (match_operand:SF 0 "gpc_reg_operand" "")
5169         (if_then_else:SF (ge (match_operand:SF 2 "gpc_reg_operand" "")
5170                              (match_dup 5))
5171                          (match_dup 3)
5172                          (match_dup 4)))]
5173   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS
5174    && !HONOR_NANS (SFmode) && !HONOR_SIGNED_ZEROS (SFmode)"
5175   {
5176      operands[3] = gen_reg_rtx (SFmode);
5177      operands[4] = gen_reg_rtx (SFmode);
5178      operands[5] = CONST0_RTX (SFmode);
5179   })
5180
5181 (define_expand "copysigndf3"
5182   [(set (match_dup 3)
5183         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))
5184    (set (match_dup 4)
5185         (neg:DF (abs:DF (match_dup 1))))
5186    (set (match_operand:DF 0 "gpc_reg_operand" "")
5187         (if_then_else:DF (ge (match_operand:DF 2 "gpc_reg_operand" "")
5188                              (match_dup 5))
5189                          (match_dup 3)
5190                          (match_dup 4)))]
5191   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS
5192    && !HONOR_NANS (DFmode) && !HONOR_SIGNED_ZEROS (DFmode)"
5193   {
5194      operands[3] = gen_reg_rtx (DFmode);
5195      operands[4] = gen_reg_rtx (DFmode);
5196      operands[5] = CONST0_RTX (DFmode);
5197   })
5198
5199 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
5200 ;; fsel instruction and some auxiliary computations.  Then we just have a
5201 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
5202 ;; combine.
5203 (define_expand "smaxsf3"
5204   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5205         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
5206                              (match_operand:SF 2 "gpc_reg_operand" ""))
5207                          (match_dup 1)
5208                          (match_dup 2)))]
5209   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5210   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5211
5212 (define_expand "sminsf3"
5213   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5214         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
5215                              (match_operand:SF 2 "gpc_reg_operand" ""))
5216                          (match_dup 2)
5217                          (match_dup 1)))]
5218   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5219   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5220
5221 (define_split
5222   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5223         (match_operator:SF 3 "min_max_operator"
5224          [(match_operand:SF 1 "gpc_reg_operand" "")
5225           (match_operand:SF 2 "gpc_reg_operand" "")]))]
5226   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5227   [(const_int 0)]
5228   "
5229 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5230                       operands[1], operands[2]);
5231   DONE;
5232 }")
5233
5234 (define_expand "movsicc"
5235    [(set (match_operand:SI 0 "gpc_reg_operand" "")
5236          (if_then_else:SI (match_operand 1 "comparison_operator" "")
5237                           (match_operand:SI 2 "gpc_reg_operand" "")
5238                           (match_operand:SI 3 "gpc_reg_operand" "")))]
5239   "TARGET_ISEL"
5240   "
5241 {
5242   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5243     DONE;
5244   else
5245     FAIL;
5246 }")
5247
5248 ;; We use the BASE_REGS for the isel input operands because, if rA is
5249 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
5250 ;; because we may switch the operands and rB may end up being rA.
5251 ;;
5252 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
5253 ;; leave out the mode in operand 4 and use one pattern, but reload can
5254 ;; change the mode underneath our feet and then gets confused trying
5255 ;; to reload the value.
5256 (define_insn "isel_signed"
5257   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5258         (if_then_else:SI
5259          (match_operator 1 "comparison_operator"
5260                          [(match_operand:CC 4 "cc_reg_operand" "y")
5261                           (const_int 0)])
5262          (match_operand:SI 2 "gpc_reg_operand" "b")
5263          (match_operand:SI 3 "gpc_reg_operand" "b")))]
5264   "TARGET_ISEL"
5265   "*
5266 { return output_isel (operands); }"
5267   [(set_attr "length" "4")])
5268
5269 (define_insn "isel_unsigned"
5270   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5271         (if_then_else:SI
5272          (match_operator 1 "comparison_operator"
5273                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
5274                           (const_int 0)])
5275          (match_operand:SI 2 "gpc_reg_operand" "b")
5276          (match_operand:SI 3 "gpc_reg_operand" "b")))]
5277   "TARGET_ISEL"
5278   "*
5279 { return output_isel (operands); }"
5280   [(set_attr "length" "4")])
5281
5282 (define_expand "movsfcc"
5283    [(set (match_operand:SF 0 "gpc_reg_operand" "")
5284          (if_then_else:SF (match_operand 1 "comparison_operator" "")
5285                           (match_operand:SF 2 "gpc_reg_operand" "")
5286                           (match_operand:SF 3 "gpc_reg_operand" "")))]
5287   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5288   "
5289 {
5290   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5291     DONE;
5292   else
5293     FAIL;
5294 }")
5295
5296 (define_insn "*fselsfsf4"
5297   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5298         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5299                              (match_operand:SF 4 "zero_fp_constant" "F"))
5300                          (match_operand:SF 2 "gpc_reg_operand" "f")
5301                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5302   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5303   "fsel %0,%1,%2,%3"
5304   [(set_attr "type" "fp")])
5305
5306 (define_insn "*fseldfsf4"
5307   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5308         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
5309                              (match_operand:DF 4 "zero_fp_constant" "F"))
5310                          (match_operand:SF 2 "gpc_reg_operand" "f")
5311                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5312   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5313   "fsel %0,%1,%2,%3"
5314   [(set_attr "type" "fp")])
5315
5316 (define_expand "negdf2"
5317   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5318         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
5319   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5320   "")
5321
5322 (define_insn "*negdf2_fpr"
5323   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5324         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5325   "TARGET_HARD_FLOAT && TARGET_FPRS"
5326   "fneg %0,%1"
5327   [(set_attr "type" "fp")])
5328
5329 (define_expand "absdf2"
5330   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5331         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
5332   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5333   "")
5334
5335 (define_insn "*absdf2_fpr"
5336   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5337         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5338   "TARGET_HARD_FLOAT && TARGET_FPRS"
5339   "fabs %0,%1"
5340   [(set_attr "type" "fp")])
5341
5342 (define_insn "*nabsdf2_fpr"
5343   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5344         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
5345   "TARGET_HARD_FLOAT && TARGET_FPRS"
5346   "fnabs %0,%1"
5347   [(set_attr "type" "fp")])
5348
5349 (define_expand "adddf3"
5350   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5351         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "")
5352                  (match_operand:DF 2 "gpc_reg_operand" "")))]
5353   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5354   "")
5355
5356 (define_insn "*adddf3_fpr"
5357   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5358         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5359                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
5360   "TARGET_HARD_FLOAT && TARGET_FPRS"
5361   "{fa|fadd} %0,%1,%2"
5362   [(set_attr "type" "fp")])
5363
5364 (define_expand "subdf3"
5365   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5366         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
5367                   (match_operand:DF 2 "gpc_reg_operand" "")))]
5368   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5369   "")
5370
5371 (define_insn "*subdf3_fpr"
5372   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5373         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5374                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
5375   "TARGET_HARD_FLOAT && TARGET_FPRS"
5376   "{fs|fsub} %0,%1,%2"
5377   [(set_attr "type" "fp")])
5378
5379 (define_expand "muldf3"
5380   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5381         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "")
5382                  (match_operand:DF 2 "gpc_reg_operand" "")))]
5383   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5384   "")
5385
5386 (define_insn "*muldf3_fpr"
5387   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5388         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5389                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
5390   "TARGET_HARD_FLOAT && TARGET_FPRS"
5391   "{fm|fmul} %0,%1,%2"
5392   [(set_attr "type" "dmul")])
5393
5394 (define_insn "fred"
5395   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5396         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRES))]
5397   "TARGET_POPCNTB && flag_finite_math_only"
5398   "fre %0,%1"
5399   [(set_attr "type" "fp")])
5400
5401 (define_expand "divdf3"
5402   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5403         (div:DF (match_operand:DF 1 "gpc_reg_operand" "")
5404                 (match_operand:DF 2 "gpc_reg_operand" "")))]
5405   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5406 {
5407   if (swdiv && !optimize_size && TARGET_POPCNTB
5408   && flag_finite_math_only && !flag_trapping_math)
5409     {
5410       rs6000_emit_swdivdf (operands[0], operands[1], operands[2]);
5411       DONE;
5412     }
5413 })
5414
5415 (define_insn "*divdf3_fpr"
5416   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5417         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5418                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
5419   "TARGET_HARD_FLOAT && TARGET_FPRS"
5420   "{fd|fdiv} %0,%1,%2"
5421   [(set_attr "type" "ddiv")])
5422
5423 (define_insn ""
5424   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5425         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5426                           (match_operand:DF 2 "gpc_reg_operand" "f"))
5427                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
5428   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5429   "{fma|fmadd} %0,%1,%2,%3"
5430   [(set_attr "type" "dmul")])
5431
5432 (define_insn ""
5433   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5434         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5435                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5436                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5437   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5438   "{fms|fmsub} %0,%1,%2,%3"
5439   [(set_attr "type" "dmul")])
5440
5441 (define_insn ""
5442   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5443         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5444                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
5445                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5446   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5447    && HONOR_SIGNED_ZEROS (DFmode)"
5448   "{fnma|fnmadd} %0,%1,%2,%3"
5449   [(set_attr "type" "dmul")])
5450
5451 (define_insn ""
5452   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5453         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f"))
5454                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5455                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5456   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5457    && ! HONOR_SIGNED_ZEROS (DFmode)"
5458   "{fnma|fnmadd} %0,%1,%2,%3"
5459   [(set_attr "type" "dmul")])
5460
5461 (define_insn ""
5462   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5463         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5464                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
5465                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5466   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5467    && HONOR_SIGNED_ZEROS (DFmode)"
5468   "{fnms|fnmsub} %0,%1,%2,%3"
5469   [(set_attr "type" "dmul")])
5470
5471 (define_insn ""
5472   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5473         (minus:DF (match_operand:DF 3 "gpc_reg_operand" "f")
5474                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5475                            (match_operand:DF 2 "gpc_reg_operand" "f"))))]
5476   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5477    && ! HONOR_SIGNED_ZEROS (DFmode)"
5478   "{fnms|fnmsub} %0,%1,%2,%3"
5479   [(set_attr "type" "dmul")])
5480
5481 (define_insn "sqrtdf2"
5482   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5483         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5484   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
5485   "fsqrt %0,%1"
5486   [(set_attr "type" "dsqrt")])
5487
5488 ;; The conditional move instructions allow us to perform max and min
5489 ;; operations even when
5490
5491 (define_expand "smaxdf3"
5492   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5493         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5494                              (match_operand:DF 2 "gpc_reg_operand" ""))
5495                          (match_dup 1)
5496                          (match_dup 2)))]
5497   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5498   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5499
5500 (define_expand "smindf3"
5501   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5502         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5503                              (match_operand:DF 2 "gpc_reg_operand" ""))
5504                          (match_dup 2)
5505                          (match_dup 1)))]
5506   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5507   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5508
5509 (define_split
5510   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5511         (match_operator:DF 3 "min_max_operator"
5512          [(match_operand:DF 1 "gpc_reg_operand" "")
5513           (match_operand:DF 2 "gpc_reg_operand" "")]))]
5514   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5515   [(const_int 0)]
5516   "
5517 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5518                       operands[1], operands[2]);
5519   DONE;
5520 }")
5521
5522 (define_expand "movdfcc"
5523    [(set (match_operand:DF 0 "gpc_reg_operand" "")
5524          (if_then_else:DF (match_operand 1 "comparison_operator" "")
5525                           (match_operand:DF 2 "gpc_reg_operand" "")
5526                           (match_operand:DF 3 "gpc_reg_operand" "")))]
5527   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5528   "
5529 {
5530   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5531     DONE;
5532   else
5533     FAIL;
5534 }")
5535
5536 (define_insn "*fseldfdf4"
5537   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5538         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
5539                              (match_operand:DF 4 "zero_fp_constant" "F"))
5540                          (match_operand:DF 2 "gpc_reg_operand" "f")
5541                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5542   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5543   "fsel %0,%1,%2,%3"
5544   [(set_attr "type" "fp")])
5545
5546 (define_insn "*fselsfdf4"
5547   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5548         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5549                              (match_operand:SF 4 "zero_fp_constant" "F"))
5550                          (match_operand:DF 2 "gpc_reg_operand" "f")
5551                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5552   "TARGET_PPC_GFXOPT"
5553   "fsel %0,%1,%2,%3"
5554   [(set_attr "type" "fp")])
5555 \f
5556 ;; Conversions to and from floating-point.
5557
5558 (define_expand "fixuns_truncsfsi2"
5559   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5560         (unsigned_fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5561   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5562   "")
5563
5564 (define_expand "fix_truncsfsi2"
5565   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5566         (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5567   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5568   "")
5569
5570 ; For each of these conversions, there is a define_expand, a define_insn
5571 ; with a '#' template, and a define_split (with C code).  The idea is
5572 ; to allow constant folding with the template of the define_insn,
5573 ; then to have the insns split later (between sched1 and final).
5574
5575 (define_expand "floatsidf2"
5576   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5577                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5578               (use (match_dup 2))
5579               (use (match_dup 3))
5580               (clobber (match_dup 4))
5581               (clobber (match_dup 5))
5582               (clobber (match_dup 6))])]
5583   "TARGET_HARD_FLOAT && TARGET_FPRS"
5584   "
5585 {
5586   if (TARGET_E500_DOUBLE)
5587     {
5588       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
5589       DONE;
5590     }
5591   if (TARGET_POWERPC64)
5592     {
5593       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5594       rtx t1 = gen_reg_rtx (DImode);
5595       rtx t2 = gen_reg_rtx (DImode);
5596       emit_insn (gen_floatsidf_ppc64 (operands[0], operands[1], mem, t1, t2));
5597       DONE;
5598     }
5599
5600   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5601   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5602   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5603   operands[5] = gen_reg_rtx (DFmode);
5604   operands[6] = gen_reg_rtx (SImode);
5605 }")
5606
5607 (define_insn_and_split "*floatsidf2_internal"
5608   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5609         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5610    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5611    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5612    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5613    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))
5614    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5615   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5616   "#"
5617   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[4]))"
5618   [(pc)]
5619   "
5620 {
5621   rtx lowword, highword;
5622   gcc_assert (MEM_P (operands[4]));
5623   highword = adjust_address (operands[4], SImode, 0);
5624   lowword = adjust_address (operands[4], SImode, 4);
5625   if (! WORDS_BIG_ENDIAN)
5626     {
5627       rtx tmp;
5628       tmp = highword; highword = lowword; lowword = tmp;
5629     }
5630
5631   emit_insn (gen_xorsi3 (operands[6], operands[1],
5632                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5633   emit_move_insn (lowword, operands[6]);
5634   emit_move_insn (highword, operands[2]);
5635   emit_move_insn (operands[5], operands[4]);
5636   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5637   DONE;
5638 }"
5639   [(set_attr "length" "24")])
5640
5641 (define_expand "floatunssisf2"
5642   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5643         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5644   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5645   "")
5646
5647 (define_expand "floatunssidf2"
5648   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5649                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5650               (use (match_dup 2))
5651               (use (match_dup 3))
5652               (clobber (match_dup 4))
5653               (clobber (match_dup 5))])]
5654   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5655   "
5656 {
5657   if (TARGET_E500_DOUBLE)
5658     {
5659       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
5660       DONE;
5661     }
5662   if (TARGET_POWERPC64)
5663     {
5664       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5665       rtx t1 = gen_reg_rtx (DImode);
5666       rtx t2 = gen_reg_rtx (DImode);
5667       emit_insn (gen_floatunssidf_ppc64 (operands[0], operands[1], mem,
5668                                          t1, t2));
5669       DONE;
5670     }
5671
5672   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5673   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5674   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5675   operands[5] = gen_reg_rtx (DFmode);
5676 }")
5677
5678 (define_insn_and_split "*floatunssidf2_internal"
5679   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5680         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5681    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5682    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5683    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5684    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))]
5685   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5686   "#"
5687   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[4]))"
5688   [(pc)]
5689   "
5690 {
5691   rtx lowword, highword;
5692   gcc_assert (MEM_P (operands[4]));
5693   highword = adjust_address (operands[4], SImode, 0);
5694   lowword = adjust_address (operands[4], SImode, 4);
5695   if (! WORDS_BIG_ENDIAN)
5696     {
5697       rtx tmp;
5698       tmp = highword; highword = lowword; lowword = tmp;
5699     }
5700
5701   emit_move_insn (lowword, operands[1]);
5702   emit_move_insn (highword, operands[2]);
5703   emit_move_insn (operands[5], operands[4]);
5704   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5705   DONE;
5706 }"
5707   [(set_attr "length" "20")])
5708
5709 (define_expand "fix_truncdfsi2"
5710   [(parallel [(set (match_operand:SI 0 "fix_trunc_dest_operand" "")
5711                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5712               (clobber (match_dup 2))
5713               (clobber (match_dup 3))])]
5714   "(TARGET_POWER2 || TARGET_POWERPC)
5715    && TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5716   "
5717 {
5718   if (TARGET_E500_DOUBLE)
5719     {
5720      emit_insn (gen_spe_fix_truncdfsi2 (operands[0], operands[1]));
5721      DONE;
5722     }
5723   operands[2] = gen_reg_rtx (DImode);
5724   if (TARGET_PPC_GFXOPT)
5725     {
5726       rtx orig_dest = operands[0];
5727       if (! memory_operand (orig_dest, GET_MODE (orig_dest)))
5728         operands[0] = assign_stack_temp (SImode, GET_MODE_SIZE (SImode), 0);
5729       emit_insn (gen_fix_truncdfsi2_internal_gfxopt (operands[0], operands[1],
5730                                                      operands[2]));
5731       if (operands[0] != orig_dest)
5732         emit_move_insn (orig_dest, operands[0]);
5733       DONE;
5734     }
5735   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5736 }")
5737
5738 (define_insn_and_split "*fix_truncdfsi2_internal"
5739   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5740         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5741    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
5742    (clobber (match_operand:DI 3 "memory_operand" "=o"))]
5743   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5744   "#"
5745   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[3]))"
5746   [(pc)]
5747   "
5748 {
5749   rtx lowword;
5750   gcc_assert (MEM_P (operands[3]));
5751   lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
5752
5753   emit_insn (gen_fctiwz (operands[2], operands[1]));
5754   emit_move_insn (operands[3], operands[2]);
5755   emit_move_insn (operands[0], lowword);
5756   DONE;
5757 }"
5758   [(set_attr "length" "16")])
5759
5760 (define_insn_and_split "fix_truncdfsi2_internal_gfxopt"
5761   [(set (match_operand:SI 0 "memory_operand" "=Z")
5762         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5763    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))]
5764   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS
5765    && TARGET_PPC_GFXOPT"
5766   "#"
5767   "&& 1"
5768   [(pc)]
5769   "
5770 {
5771   emit_insn (gen_fctiwz (operands[2], operands[1]));
5772   emit_insn (gen_stfiwx (operands[0], operands[2]));
5773   DONE;
5774 }"
5775   [(set_attr "length" "16")])
5776
5777 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
5778 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
5779 ; because the first makes it clear that operand 0 is not live
5780 ; before the instruction.
5781 (define_insn "fctiwz"
5782   [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
5783         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))]
5784                    UNSPEC_FCTIWZ))]
5785   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5786   "{fcirz|fctiwz} %0,%1"
5787   [(set_attr "type" "fp")])
5788
5789 (define_insn "btruncdf2"
5790   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5791         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIZ))]
5792   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5793   "friz %0,%1"
5794   [(set_attr "type" "fp")])
5795
5796 (define_insn "btruncsf2"
5797   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5798         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIZ))]
5799   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5800   "friz %0,%1"
5801   [(set_attr "type" "fp")])
5802
5803 (define_insn "ceildf2"
5804   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5805         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIP))]
5806   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5807   "frip %0,%1"
5808   [(set_attr "type" "fp")])
5809
5810 (define_insn "ceilsf2"
5811  [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5812         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIP))]
5813   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5814   "frip %0,%1"
5815   [(set_attr "type" "fp")])
5816
5817 (define_insn "floordf2"
5818   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5819         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIM))]
5820   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5821   "frim %0,%1"
5822   [(set_attr "type" "fp")])
5823
5824 (define_insn "floorsf2"
5825   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5826         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIM))]
5827   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5828   "frim %0,%1"
5829   [(set_attr "type" "fp")])
5830
5831 (define_insn "rounddf2"
5832   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5833         (unspec:DF [(match_operand:DF 1 "gpc_reg_operand" "f")] UNSPEC_FRIN))]
5834   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5835   "frin %0,%1"
5836   [(set_attr "type" "fp")])
5837
5838 (define_insn "roundsf2"
5839   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5840         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRIN))]
5841   "TARGET_FPRND && TARGET_HARD_FLOAT && TARGET_FPRS"
5842   "frin %0,%1"
5843   [(set_attr "type" "fp")])
5844
5845 ; An UNSPEC is used so we don't have to support SImode in FP registers.
5846 (define_insn "stfiwx"
5847   [(set (match_operand:SI 0 "memory_operand" "=Z")
5848         (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "f")]
5849                    UNSPEC_STFIWX))]
5850   "TARGET_PPC_GFXOPT"
5851   "stfiwx %1,%y0"
5852   [(set_attr "type" "fpstore")])
5853
5854 (define_expand "floatsisf2"
5855   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5856         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5857   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5858   "")
5859
5860 (define_insn "floatdidf2"
5861   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5862         (float:DF (match_operand:DI 1 "gpc_reg_operand" "*f")))]
5863   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5864   "fcfid %0,%1"
5865   [(set_attr "type" "fp")])
5866
5867 (define_insn_and_split "floatsidf_ppc64"
5868   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5869         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5870    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5871    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5872    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5873   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5874   "#"
5875   "&& 1"
5876   [(set (match_dup 3) (sign_extend:DI (match_dup 1)))
5877    (set (match_dup 2) (match_dup 3))
5878    (set (match_dup 4) (match_dup 2))
5879    (set (match_dup 0) (float:DF (match_dup 4)))]
5880   "")
5881
5882 (define_insn_and_split "floatunssidf_ppc64"
5883   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5884         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5885    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5886    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5887    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5888   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5889   "#"
5890   "&& 1"
5891   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
5892    (set (match_dup 2) (match_dup 3))
5893    (set (match_dup 4) (match_dup 2))
5894    (set (match_dup 0) (float:DF (match_dup 4)))]
5895   "")
5896
5897 (define_insn "fix_truncdfdi2"
5898   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5899         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
5900   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5901   "fctidz %0,%1"
5902   [(set_attr "type" "fp")])
5903
5904 (define_expand "floatdisf2"
5905   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5906         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
5907   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5908   "
5909 {
5910   rtx val = operands[1];
5911   if (!flag_unsafe_math_optimizations)
5912     {
5913       rtx label = gen_label_rtx ();
5914       val = gen_reg_rtx (DImode);
5915       emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
5916       emit_label (label);
5917     }
5918   emit_insn (gen_floatdisf2_internal1 (operands[0], val));
5919   DONE;
5920 }")
5921
5922 ;; This is not IEEE compliant if rounding mode is "round to nearest".
5923 ;; If the DI->DF conversion is inexact, then it's possible to suffer
5924 ;; from double rounding.
5925 (define_insn_and_split "floatdisf2_internal1"
5926   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5927         (float:SF (match_operand:DI 1 "gpc_reg_operand" "*f")))
5928    (clobber (match_scratch:DF 2 "=f"))]
5929   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5930   "#"
5931   "&& reload_completed"
5932   [(set (match_dup 2)
5933         (float:DF (match_dup 1)))
5934    (set (match_dup 0)
5935         (float_truncate:SF (match_dup 2)))]
5936   "")
5937
5938 ;; Twiddles bits to avoid double rounding.
5939 ;; Bits that might be truncated when converting to DFmode are replaced
5940 ;; by a bit that won't be lost at that stage, but is below the SFmode
5941 ;; rounding position.
5942 (define_expand "floatdisf2_internal2"
5943   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
5944                                    (const_int 53)))
5945    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
5946                                                       (const_int 2047)))
5947               (clobber (scratch:CC))])
5948    (set (match_dup 3) (plus:DI (match_dup 3)
5949                                (const_int 1)))
5950    (set (match_dup 0) (plus:DI (match_dup 0)
5951                                (const_int 2047)))
5952    (set (match_dup 4) (compare:CCUNS (match_dup 3)
5953                                      (const_int 2)))
5954    (set (match_dup 0) (ior:DI (match_dup 0)
5955                               (match_dup 1)))
5956    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
5957                                          (const_int -2048)))
5958               (clobber (scratch:CC))])
5959    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
5960                            (label_ref (match_operand:DI 2 "" ""))
5961                            (pc)))
5962    (set (match_dup 0) (match_dup 1))]
5963   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5964   "
5965 {
5966   operands[3] = gen_reg_rtx (DImode);
5967   operands[4] = gen_reg_rtx (CCUNSmode);
5968 }")
5969 \f
5970 ;; Define the DImode operations that can be done in a small number
5971 ;; of instructions.  The & constraints are to prevent the register
5972 ;; allocator from allocating registers that overlap with the inputs
5973 ;; (for example, having an input in 7,8 and an output in 6,7).  We
5974 ;; also allow for the output being the same as one of the inputs.
5975
5976 (define_insn "*adddi3_noppc64"
5977   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
5978         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
5979                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
5980   "! TARGET_POWERPC64"
5981   "*
5982 {
5983   if (WORDS_BIG_ENDIAN)
5984     return (GET_CODE (operands[2])) != CONST_INT
5985             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
5986             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
5987   else
5988     return (GET_CODE (operands[2])) != CONST_INT
5989             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
5990             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
5991 }"
5992   [(set_attr "type" "two")
5993    (set_attr "length" "8")])
5994
5995 (define_insn "*subdi3_noppc64"
5996   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
5997         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
5998                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
5999   "! TARGET_POWERPC64"
6000   "*
6001 {
6002   if (WORDS_BIG_ENDIAN)
6003     return (GET_CODE (operands[1]) != CONST_INT)
6004             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
6005             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
6006   else
6007     return (GET_CODE (operands[1]) != CONST_INT)
6008             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
6009             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
6010 }"
6011   [(set_attr "type" "two")
6012    (set_attr "length" "8")])
6013
6014 (define_insn "*negdi2_noppc64"
6015   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6016         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
6017   "! TARGET_POWERPC64"
6018   "*
6019 {
6020   return (WORDS_BIG_ENDIAN)
6021     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
6022     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
6023 }"
6024   [(set_attr "type" "two")
6025    (set_attr "length" "8")])
6026
6027 (define_expand "mulsidi3"
6028   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6029         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6030                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6031   "! TARGET_POWERPC64"
6032   "
6033 {
6034   if (! TARGET_POWER && ! TARGET_POWERPC)
6035     {
6036       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
6037       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
6038       emit_insn (gen_mull_call ());
6039       if (WORDS_BIG_ENDIAN)
6040         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
6041       else
6042         {
6043           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
6044                           gen_rtx_REG (SImode, 3));
6045           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
6046                           gen_rtx_REG (SImode, 4));
6047         }
6048       DONE;
6049     }
6050   else if (TARGET_POWER)
6051     {
6052       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
6053       DONE;
6054     }
6055 }")
6056
6057 (define_insn "mulsidi3_mq"
6058   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6059         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6060                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
6061    (clobber (match_scratch:SI 3 "=q"))]
6062   "TARGET_POWER"
6063   "mul %0,%1,%2\;mfmq %L0"
6064   [(set_attr "type" "imul")
6065    (set_attr "length" "8")])
6066
6067 (define_insn "*mulsidi3_no_mq"
6068   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6069         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6070                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6071   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
6072   "*
6073 {
6074   return (WORDS_BIG_ENDIAN)
6075     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
6076     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
6077 }"
6078   [(set_attr "type" "imul")
6079    (set_attr "length" "8")])
6080
6081 (define_split
6082   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6083         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6084                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6085   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
6086   [(set (match_dup 3)
6087         (truncate:SI
6088          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
6089                                (sign_extend:DI (match_dup 2)))
6090                       (const_int 32))))
6091    (set (match_dup 4)
6092         (mult:SI (match_dup 1)
6093                  (match_dup 2)))]
6094   "
6095 {
6096   int endian = (WORDS_BIG_ENDIAN == 0);
6097   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6098   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6099 }")
6100
6101 (define_expand "umulsidi3"
6102   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6103         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6104                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6105   "TARGET_POWERPC && ! TARGET_POWERPC64"
6106   "
6107 {
6108   if (TARGET_POWER)
6109     {
6110       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
6111       DONE;
6112     }
6113 }")
6114
6115 (define_insn "umulsidi3_mq"
6116   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6117         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6118                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
6119    (clobber (match_scratch:SI 3 "=q"))]
6120   "TARGET_POWERPC && TARGET_POWER"
6121   "*
6122 {
6123   return (WORDS_BIG_ENDIAN)
6124     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6125     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6126 }"
6127   [(set_attr "type" "imul")
6128    (set_attr "length" "8")])
6129
6130 (define_insn "*umulsidi3_no_mq"
6131   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6132         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6133                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6134   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
6135   "*
6136 {
6137   return (WORDS_BIG_ENDIAN)
6138     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6139     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6140 }"
6141   [(set_attr "type" "imul")
6142    (set_attr "length" "8")])
6143
6144 (define_split
6145   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6146         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6147                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6148   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
6149   [(set (match_dup 3)
6150         (truncate:SI
6151          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
6152                                (zero_extend:DI (match_dup 2)))
6153                       (const_int 32))))
6154    (set (match_dup 4)
6155         (mult:SI (match_dup 1)
6156                  (match_dup 2)))]
6157   "
6158 {
6159   int endian = (WORDS_BIG_ENDIAN == 0);
6160   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6161   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6162 }")
6163
6164 (define_expand "smulsi3_highpart"
6165   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6166         (truncate:SI
6167          (lshiftrt:DI (mult:DI (sign_extend:DI
6168                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6169                                (sign_extend:DI
6170                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6171                       (const_int 32))))]
6172   ""
6173   "
6174 {
6175   if (! TARGET_POWER && ! TARGET_POWERPC)
6176     {
6177       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
6178       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
6179       emit_insn (gen_mulh_call ());
6180       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
6181       DONE;
6182     }
6183   else if (TARGET_POWER)
6184     {
6185       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
6186       DONE;
6187     }
6188 }")
6189
6190 (define_insn "smulsi3_highpart_mq"
6191   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6192         (truncate:SI
6193          (lshiftrt:DI (mult:DI (sign_extend:DI
6194                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6195                                (sign_extend:DI
6196                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6197                       (const_int 32))))
6198    (clobber (match_scratch:SI 3 "=q"))]
6199   "TARGET_POWER"
6200   "mul %0,%1,%2"
6201   [(set_attr "type" "imul")])
6202
6203 (define_insn "*smulsi3_highpart_no_mq"
6204   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6205         (truncate:SI
6206          (lshiftrt:DI (mult:DI (sign_extend:DI
6207                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6208                                (sign_extend:DI
6209                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6210                       (const_int 32))))]
6211   "TARGET_POWERPC && ! TARGET_POWER"
6212   "mulhw %0,%1,%2"
6213   [(set_attr "type" "imul")])
6214
6215 (define_expand "umulsi3_highpart"
6216   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6217         (truncate:SI
6218          (lshiftrt:DI (mult:DI (zero_extend:DI
6219                                 (match_operand:SI 1 "gpc_reg_operand" ""))
6220                                (zero_extend:DI
6221                                 (match_operand:SI 2 "gpc_reg_operand" "")))
6222                       (const_int 32))))]
6223   "TARGET_POWERPC"
6224   "
6225 {
6226   if (TARGET_POWER)
6227     {
6228       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
6229       DONE;
6230     }
6231 }")
6232
6233 (define_insn "umulsi3_highpart_mq"
6234   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6235         (truncate:SI
6236          (lshiftrt:DI (mult:DI (zero_extend:DI
6237                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6238                                (zero_extend:DI
6239                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6240                       (const_int 32))))
6241    (clobber (match_scratch:SI 3 "=q"))]
6242   "TARGET_POWERPC && TARGET_POWER"
6243   "mulhwu %0,%1,%2"
6244   [(set_attr "type" "imul")])
6245
6246 (define_insn "*umulsi3_highpart_no_mq"
6247   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6248         (truncate:SI
6249          (lshiftrt:DI (mult:DI (zero_extend:DI
6250                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6251                                (zero_extend:DI
6252                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6253                       (const_int 32))))]
6254   "TARGET_POWERPC && ! TARGET_POWER"
6255   "mulhwu %0,%1,%2"
6256   [(set_attr "type" "imul")])
6257
6258 ;; If operands 0 and 2 are in the same register, we have a problem.  But
6259 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
6260 ;; why we have the strange constraints below.
6261 (define_insn "ashldi3_power"
6262   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
6263         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
6264                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
6265    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
6266   "TARGET_POWER"
6267   "@
6268    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
6269    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
6270    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
6271    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
6272   [(set_attr "length" "8")])
6273
6274 (define_insn "lshrdi3_power"
6275   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
6276         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
6277                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
6278    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
6279   "TARGET_POWER"
6280   "@
6281    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
6282    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
6283    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
6284    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
6285   [(set_attr "length" "8")])
6286
6287 ;; Shift by a variable amount is too complex to be worth open-coding.  We
6288 ;; just handle shifts by constants.
6289 (define_insn "ashrdi3_power"
6290   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6291         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6292                      (match_operand:SI 2 "const_int_operand" "M,i")))
6293    (clobber (match_scratch:SI 3 "=X,q"))]
6294   "TARGET_POWER"
6295   "@
6296    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
6297    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
6298   [(set_attr "length" "8")])
6299
6300 (define_insn "ashrdi3_no_power"
6301   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
6302         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6303                      (match_operand:SI 2 "const_int_operand" "M,i")))]
6304   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER && WORDS_BIG_ENDIAN"
6305   "@
6306    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
6307    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
6308   [(set_attr "type" "two,three")
6309    (set_attr "length" "8,12")])
6310
6311 (define_insn "*ashrdisi3_noppc64"
6312   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6313         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6314                                 (const_int 32)) 4))]
6315   "TARGET_32BIT && !TARGET_POWERPC64"
6316   "*
6317 {
6318   if (REGNO (operands[0]) == REGNO (operands[1]))
6319     return \"\";
6320   else
6321     return \"mr %0,%1\";
6322 }"
6323    [(set_attr "length" "4")])
6324
6325 \f
6326 ;; PowerPC64 DImode operations.
6327
6328 (define_insn_and_split "absdi2"
6329   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6330         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
6331    (clobber (match_scratch:DI 2 "=&r,&r"))]
6332   "TARGET_POWERPC64"
6333   "#"
6334   "&& reload_completed"
6335   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
6336    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
6337    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
6338   "")
6339
6340 (define_insn_and_split "*nabsdi2"
6341   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6342         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
6343    (clobber (match_scratch:DI 2 "=&r,&r"))]
6344   "TARGET_POWERPC64"
6345   "#"
6346   "&& reload_completed"
6347   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
6348    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
6349    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
6350   "")
6351
6352 (define_insn "muldi3"
6353   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6354         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6355                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
6356   "TARGET_POWERPC64"
6357   "@
6358    mulld %0,%1,%2
6359    mulli %0,%1,%2"
6360    [(set (attr "type")
6361       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
6362                 (const_string "imul3")
6363              (match_operand:SI 2 "short_cint_operand" "")
6364                 (const_string "imul2")]
6365         (const_string "lmul")))])
6366
6367 (define_insn "*muldi3_internal1"
6368   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6369         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6370                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6371                     (const_int 0)))
6372    (clobber (match_scratch:DI 3 "=r,r"))]
6373   "TARGET_POWERPC64"
6374   "@
6375    mulld. %3,%1,%2
6376    #"
6377   [(set_attr "type" "lmul_compare")
6378    (set_attr "length" "4,8")])
6379
6380 (define_split
6381   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6382         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6383                              (match_operand:DI 2 "gpc_reg_operand" ""))
6384                     (const_int 0)))
6385    (clobber (match_scratch:DI 3 ""))]
6386   "TARGET_POWERPC64 && reload_completed"
6387   [(set (match_dup 3)
6388         (mult:DI (match_dup 1) (match_dup 2)))
6389    (set (match_dup 0)
6390         (compare:CC (match_dup 3)
6391                     (const_int 0)))]
6392   "")
6393
6394 (define_insn "*muldi3_internal2"
6395   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6396         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6397                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6398                     (const_int 0)))
6399    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6400         (mult:DI (match_dup 1) (match_dup 2)))]
6401   "TARGET_POWERPC64"
6402   "@
6403    mulld. %0,%1,%2
6404    #"
6405   [(set_attr "type" "lmul_compare")
6406    (set_attr "length" "4,8")])
6407
6408 (define_split
6409   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6410         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6411                              (match_operand:DI 2 "gpc_reg_operand" ""))
6412                     (const_int 0)))
6413    (set (match_operand:DI 0 "gpc_reg_operand" "")
6414         (mult:DI (match_dup 1) (match_dup 2)))]
6415   "TARGET_POWERPC64 && reload_completed"
6416   [(set (match_dup 0)
6417         (mult:DI (match_dup 1) (match_dup 2)))
6418    (set (match_dup 3)
6419         (compare:CC (match_dup 0)
6420                     (const_int 0)))]
6421   "")
6422
6423 (define_insn "smuldi3_highpart"
6424   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6425         (truncate:DI
6426          (lshiftrt:TI (mult:TI (sign_extend:TI
6427                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6428                                (sign_extend:TI
6429                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6430                       (const_int 64))))]
6431   "TARGET_POWERPC64"
6432   "mulhd %0,%1,%2"
6433   [(set_attr "type" "lmul")])
6434
6435 (define_insn "umuldi3_highpart"
6436   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6437         (truncate:DI
6438          (lshiftrt:TI (mult:TI (zero_extend:TI
6439                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6440                                (zero_extend:TI
6441                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6442                       (const_int 64))))]
6443   "TARGET_POWERPC64"
6444   "mulhdu %0,%1,%2"
6445   [(set_attr "type" "lmul")])
6446
6447 (define_insn "rotldi3"
6448   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6449         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6450                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
6451   "TARGET_POWERPC64"
6452   "rld%I2cl %0,%1,%H2,0")
6453
6454 (define_insn "*rotldi3_internal2"
6455   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6456         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6457                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6458                     (const_int 0)))
6459    (clobber (match_scratch:DI 3 "=r,r"))]
6460   "TARGET_64BIT"
6461   "@
6462    rld%I2cl. %3,%1,%H2,0
6463    #"
6464   [(set_attr "type" "delayed_compare")
6465    (set_attr "length" "4,8")])
6466
6467 (define_split
6468   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6469         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6470                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6471                     (const_int 0)))
6472    (clobber (match_scratch:DI 3 ""))]
6473   "TARGET_POWERPC64 && reload_completed"
6474   [(set (match_dup 3)
6475         (rotate:DI (match_dup 1) (match_dup 2)))
6476    (set (match_dup 0)
6477         (compare:CC (match_dup 3)
6478                     (const_int 0)))]
6479   "")
6480
6481 (define_insn "*rotldi3_internal3"
6482   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6483         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6484                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6485                     (const_int 0)))
6486    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6487         (rotate:DI (match_dup 1) (match_dup 2)))]
6488   "TARGET_64BIT"
6489   "@
6490    rld%I2cl. %0,%1,%H2,0
6491    #"
6492   [(set_attr "type" "delayed_compare")
6493    (set_attr "length" "4,8")])
6494
6495 (define_split
6496   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6497         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6498                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6499                     (const_int 0)))
6500    (set (match_operand:DI 0 "gpc_reg_operand" "")
6501         (rotate:DI (match_dup 1) (match_dup 2)))]
6502   "TARGET_POWERPC64 && reload_completed"
6503   [(set (match_dup 0)
6504         (rotate:DI (match_dup 1) (match_dup 2)))
6505    (set (match_dup 3)
6506         (compare:CC (match_dup 0)
6507                     (const_int 0)))]
6508   "")
6509
6510 (define_insn "*rotldi3_internal4"
6511   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6512         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6513                            (match_operand:DI 2 "reg_or_cint_operand" "ri"))
6514                 (match_operand:DI 3 "mask64_operand" "n")))]
6515   "TARGET_POWERPC64"
6516   "rld%I2c%B3 %0,%1,%H2,%S3")
6517
6518 (define_insn "*rotldi3_internal5"
6519   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6520         (compare:CC (and:DI
6521                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6522                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6523                      (match_operand:DI 3 "mask64_operand" "n,n"))
6524                     (const_int 0)))
6525    (clobber (match_scratch:DI 4 "=r,r"))]
6526   "TARGET_64BIT"
6527   "@
6528    rld%I2c%B3. %4,%1,%H2,%S3
6529    #"
6530   [(set_attr "type" "delayed_compare")
6531    (set_attr "length" "4,8")])
6532
6533 (define_split
6534   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6535         (compare:CC (and:DI
6536                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6537                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6538                      (match_operand:DI 3 "mask64_operand" ""))
6539                     (const_int 0)))
6540    (clobber (match_scratch:DI 4 ""))]
6541   "TARGET_POWERPC64 && reload_completed"
6542   [(set (match_dup 4)
6543         (and:DI (rotate:DI (match_dup 1)
6544                                 (match_dup 2))
6545                      (match_dup 3)))
6546    (set (match_dup 0)
6547         (compare:CC (match_dup 4)
6548                     (const_int 0)))]
6549   "")
6550
6551 (define_insn "*rotldi3_internal6"
6552   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6553         (compare:CC (and:DI
6554                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6555                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6556                      (match_operand:DI 3 "mask64_operand" "n,n"))
6557                     (const_int 0)))
6558    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6559         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6560   "TARGET_64BIT"
6561   "@
6562    rld%I2c%B3. %0,%1,%H2,%S3
6563    #"
6564   [(set_attr "type" "delayed_compare")
6565    (set_attr "length" "4,8")])
6566
6567 (define_split
6568   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6569         (compare:CC (and:DI
6570                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6571                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6572                      (match_operand:DI 3 "mask64_operand" ""))
6573                     (const_int 0)))
6574    (set (match_operand:DI 0 "gpc_reg_operand" "")
6575         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6576   "TARGET_POWERPC64 && reload_completed"
6577   [(set (match_dup 0)
6578         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6579    (set (match_dup 4)
6580         (compare:CC (match_dup 0)
6581                     (const_int 0)))]
6582   "")
6583
6584 (define_insn "*rotldi3_internal7"
6585   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6586         (zero_extend:DI
6587          (subreg:QI
6588           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6589                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6590   "TARGET_POWERPC64"
6591   "rld%I2cl %0,%1,%H2,56")
6592
6593 (define_insn "*rotldi3_internal8"
6594   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6595         (compare:CC (zero_extend:DI
6596                      (subreg:QI
6597                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6598                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6599                     (const_int 0)))
6600    (clobber (match_scratch:DI 3 "=r,r"))]
6601   "TARGET_64BIT"
6602   "@
6603    rld%I2cl. %3,%1,%H2,56
6604    #"
6605   [(set_attr "type" "delayed_compare")
6606    (set_attr "length" "4,8")])
6607
6608 (define_split
6609   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6610         (compare:CC (zero_extend:DI
6611                      (subreg:QI
6612                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6613                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6614                     (const_int 0)))
6615    (clobber (match_scratch:DI 3 ""))]
6616   "TARGET_POWERPC64 && reload_completed"
6617   [(set (match_dup 3)
6618         (zero_extend:DI (subreg:QI
6619                       (rotate:DI (match_dup 1)
6620                                  (match_dup 2)) 0)))
6621    (set (match_dup 0)
6622         (compare:CC (match_dup 3)
6623                     (const_int 0)))]
6624   "")
6625
6626 (define_insn "*rotldi3_internal9"
6627   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6628         (compare:CC (zero_extend:DI
6629                      (subreg:QI
6630                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6631                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6632                     (const_int 0)))
6633    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6634         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6635   "TARGET_64BIT"
6636   "@
6637    rld%I2cl. %0,%1,%H2,56
6638    #"
6639   [(set_attr "type" "delayed_compare")
6640    (set_attr "length" "4,8")])
6641
6642 (define_split
6643   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6644         (compare:CC (zero_extend:DI
6645                      (subreg:QI
6646                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6647                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6648                     (const_int 0)))
6649    (set (match_operand:DI 0 "gpc_reg_operand" "")
6650         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6651   "TARGET_POWERPC64 && reload_completed"
6652   [(set (match_dup 0)
6653         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6654    (set (match_dup 3)
6655         (compare:CC (match_dup 0)
6656                     (const_int 0)))]
6657   "")
6658
6659 (define_insn "*rotldi3_internal10"
6660   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6661         (zero_extend:DI
6662          (subreg:HI
6663           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6664                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6665   "TARGET_POWERPC64"
6666   "rld%I2cl %0,%1,%H2,48")
6667
6668 (define_insn "*rotldi3_internal11"
6669   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6670         (compare:CC (zero_extend:DI
6671                      (subreg:HI
6672                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6673                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6674                     (const_int 0)))
6675    (clobber (match_scratch:DI 3 "=r,r"))]
6676   "TARGET_64BIT"
6677   "@
6678    rld%I2cl. %3,%1,%H2,48
6679    #"
6680   [(set_attr "type" "delayed_compare")
6681    (set_attr "length" "4,8")])
6682
6683 (define_split
6684   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6685         (compare:CC (zero_extend:DI
6686                      (subreg:HI
6687                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6688                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6689                     (const_int 0)))
6690    (clobber (match_scratch:DI 3 ""))]
6691   "TARGET_POWERPC64 && reload_completed"
6692   [(set (match_dup 3)
6693         (zero_extend:DI (subreg:HI
6694                       (rotate:DI (match_dup 1)
6695                                  (match_dup 2)) 0)))
6696    (set (match_dup 0)
6697         (compare:CC (match_dup 3)
6698                     (const_int 0)))]
6699   "")
6700
6701 (define_insn "*rotldi3_internal12"
6702   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6703         (compare:CC (zero_extend:DI
6704                      (subreg:HI
6705                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6706                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6707                     (const_int 0)))
6708    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6709         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6710   "TARGET_64BIT"
6711   "@
6712    rld%I2cl. %0,%1,%H2,48
6713    #"
6714   [(set_attr "type" "delayed_compare")
6715    (set_attr "length" "4,8")])
6716
6717 (define_split
6718   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6719         (compare:CC (zero_extend:DI
6720                      (subreg:HI
6721                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6722                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6723                     (const_int 0)))
6724    (set (match_operand:DI 0 "gpc_reg_operand" "")
6725         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6726   "TARGET_POWERPC64 && reload_completed"
6727   [(set (match_dup 0)
6728         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6729    (set (match_dup 3)
6730         (compare:CC (match_dup 0)
6731                     (const_int 0)))]
6732   "")
6733
6734 (define_insn "*rotldi3_internal13"
6735   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6736         (zero_extend:DI
6737          (subreg:SI
6738           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6739                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6740   "TARGET_POWERPC64"
6741   "rld%I2cl %0,%1,%H2,32")
6742
6743 (define_insn "*rotldi3_internal14"
6744   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6745         (compare:CC (zero_extend:DI
6746                      (subreg:SI
6747                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6748                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6749                     (const_int 0)))
6750    (clobber (match_scratch:DI 3 "=r,r"))]
6751   "TARGET_64BIT"
6752   "@
6753    rld%I2cl. %3,%1,%H2,32
6754    #"
6755   [(set_attr "type" "delayed_compare")
6756    (set_attr "length" "4,8")])
6757
6758 (define_split
6759   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6760         (compare:CC (zero_extend:DI
6761                      (subreg:SI
6762                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6763                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6764                     (const_int 0)))
6765    (clobber (match_scratch:DI 3 ""))]
6766   "TARGET_POWERPC64 && reload_completed"
6767   [(set (match_dup 3)
6768         (zero_extend:DI (subreg:SI
6769                       (rotate:DI (match_dup 1)
6770                                  (match_dup 2)) 0)))
6771    (set (match_dup 0)
6772         (compare:CC (match_dup 3)
6773                     (const_int 0)))]
6774   "")
6775
6776 (define_insn "*rotldi3_internal15"
6777   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6778         (compare:CC (zero_extend:DI
6779                      (subreg:SI
6780                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6781                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6782                     (const_int 0)))
6783    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6784         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6785   "TARGET_64BIT"
6786   "@
6787    rld%I2cl. %0,%1,%H2,32
6788    #"
6789   [(set_attr "type" "delayed_compare")
6790    (set_attr "length" "4,8")])
6791
6792 (define_split
6793   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6794         (compare:CC (zero_extend:DI
6795                      (subreg:SI
6796                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6797                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6798                     (const_int 0)))
6799    (set (match_operand:DI 0 "gpc_reg_operand" "")
6800         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6801   "TARGET_POWERPC64 && reload_completed"
6802   [(set (match_dup 0)
6803         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6804    (set (match_dup 3)
6805         (compare:CC (match_dup 0)
6806                     (const_int 0)))]
6807   "")
6808
6809 (define_expand "ashldi3"
6810   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6811         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6812                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
6813   "TARGET_POWERPC64 || TARGET_POWER"
6814   "
6815 {
6816   if (TARGET_POWERPC64)
6817     ;
6818   else if (TARGET_POWER)
6819     {
6820       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
6821       DONE;
6822     }
6823   else
6824     FAIL;
6825 }")
6826
6827 (define_insn "*ashldi3_internal1"
6828   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6829         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6830                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6831   "TARGET_POWERPC64"
6832   "sld%I2 %0,%1,%H2")
6833
6834 (define_insn "*ashldi3_internal2"
6835   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6836         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6837                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6838                     (const_int 0)))
6839    (clobber (match_scratch:DI 3 "=r,r"))]
6840   "TARGET_64BIT"
6841   "@
6842    sld%I2. %3,%1,%H2
6843    #"
6844   [(set_attr "type" "delayed_compare")
6845    (set_attr "length" "4,8")])
6846
6847 (define_split
6848   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6849         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6850                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6851                     (const_int 0)))
6852    (clobber (match_scratch:DI 3 ""))]
6853   "TARGET_POWERPC64 && reload_completed"
6854   [(set (match_dup 3)
6855         (ashift:DI (match_dup 1) (match_dup 2)))
6856    (set (match_dup 0)
6857         (compare:CC (match_dup 3)
6858                     (const_int 0)))]
6859   "")
6860
6861 (define_insn "*ashldi3_internal3"
6862   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6863         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6864                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6865                     (const_int 0)))
6866    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6867         (ashift:DI (match_dup 1) (match_dup 2)))]
6868   "TARGET_64BIT"
6869   "@
6870    sld%I2. %0,%1,%H2
6871    #"
6872   [(set_attr "type" "delayed_compare")
6873    (set_attr "length" "4,8")])
6874
6875 (define_split
6876   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6877         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6878                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6879                     (const_int 0)))
6880    (set (match_operand:DI 0 "gpc_reg_operand" "")
6881         (ashift:DI (match_dup 1) (match_dup 2)))]
6882   "TARGET_POWERPC64 && reload_completed"
6883   [(set (match_dup 0)
6884         (ashift:DI (match_dup 1) (match_dup 2)))
6885    (set (match_dup 3)
6886         (compare:CC (match_dup 0)
6887                     (const_int 0)))]
6888   "")
6889
6890 (define_insn "*ashldi3_internal4"
6891   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6892         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6893                            (match_operand:SI 2 "const_int_operand" "i"))
6894                 (match_operand:DI 3 "const_int_operand" "n")))]
6895   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
6896   "rldic %0,%1,%H2,%W3")
6897
6898 (define_insn "ashldi3_internal5"
6899   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6900         (compare:CC
6901          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6902                             (match_operand:SI 2 "const_int_operand" "i,i"))
6903                  (match_operand:DI 3 "const_int_operand" "n,n"))
6904          (const_int 0)))
6905    (clobber (match_scratch:DI 4 "=r,r"))]
6906   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6907   "@
6908    rldic. %4,%1,%H2,%W3
6909    #"
6910   [(set_attr "type" "compare")
6911    (set_attr "length" "4,8")])
6912
6913 (define_split
6914   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6915         (compare:CC
6916          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6917                             (match_operand:SI 2 "const_int_operand" ""))
6918                  (match_operand:DI 3 "const_int_operand" ""))
6919          (const_int 0)))
6920    (clobber (match_scratch:DI 4 ""))]
6921   "TARGET_POWERPC64 && reload_completed
6922    && includes_rldic_lshift_p (operands[2], operands[3])"
6923   [(set (match_dup 4)
6924         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6925                 (match_dup 3)))
6926    (set (match_dup 0)
6927         (compare:CC (match_dup 4)
6928                     (const_int 0)))]
6929   "")
6930
6931 (define_insn "*ashldi3_internal6"
6932   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6933         (compare:CC
6934          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6935                             (match_operand:SI 2 "const_int_operand" "i,i"))
6936                     (match_operand:DI 3 "const_int_operand" "n,n"))
6937          (const_int 0)))
6938    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6939         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6940   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6941   "@
6942    rldic. %0,%1,%H2,%W3
6943    #"
6944   [(set_attr "type" "compare")
6945    (set_attr "length" "4,8")])
6946
6947 (define_split
6948   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6949         (compare:CC
6950          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6951                             (match_operand:SI 2 "const_int_operand" ""))
6952                  (match_operand:DI 3 "const_int_operand" ""))
6953          (const_int 0)))
6954    (set (match_operand:DI 0 "gpc_reg_operand" "")
6955         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6956   "TARGET_POWERPC64 && reload_completed
6957    && includes_rldic_lshift_p (operands[2], operands[3])"
6958   [(set (match_dup 0)
6959         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6960                 (match_dup 3)))
6961    (set (match_dup 4)
6962         (compare:CC (match_dup 0)
6963                     (const_int 0)))]
6964   "")
6965
6966 (define_insn "*ashldi3_internal7"
6967   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6968         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6969                            (match_operand:SI 2 "const_int_operand" "i"))
6970                 (match_operand:DI 3 "mask64_operand" "n")))]
6971   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
6972   "rldicr %0,%1,%H2,%S3")
6973
6974 (define_insn "ashldi3_internal8"
6975   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6976         (compare:CC
6977          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6978                             (match_operand:SI 2 "const_int_operand" "i,i"))
6979                  (match_operand:DI 3 "mask64_operand" "n,n"))
6980          (const_int 0)))
6981    (clobber (match_scratch:DI 4 "=r,r"))]
6982   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6983   "@
6984    rldicr. %4,%1,%H2,%S3
6985    #"
6986   [(set_attr "type" "compare")
6987    (set_attr "length" "4,8")])
6988
6989 (define_split
6990   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6991         (compare:CC
6992          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6993                             (match_operand:SI 2 "const_int_operand" ""))
6994                  (match_operand:DI 3 "mask64_operand" ""))
6995          (const_int 0)))
6996    (clobber (match_scratch:DI 4 ""))]
6997   "TARGET_POWERPC64 && reload_completed
6998    && includes_rldicr_lshift_p (operands[2], operands[3])"
6999   [(set (match_dup 4)
7000         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7001                 (match_dup 3)))
7002    (set (match_dup 0)
7003         (compare:CC (match_dup 4)
7004                     (const_int 0)))]
7005   "")
7006
7007 (define_insn "*ashldi3_internal9"
7008   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7009         (compare:CC
7010          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7011                             (match_operand:SI 2 "const_int_operand" "i,i"))
7012                     (match_operand:DI 3 "mask64_operand" "n,n"))
7013          (const_int 0)))
7014    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7015         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7016   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7017   "@
7018    rldicr. %0,%1,%H2,%S3
7019    #"
7020   [(set_attr "type" "compare")
7021    (set_attr "length" "4,8")])
7022
7023 (define_split
7024   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
7025         (compare:CC
7026          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7027                             (match_operand:SI 2 "const_int_operand" ""))
7028                  (match_operand:DI 3 "mask64_operand" ""))
7029          (const_int 0)))
7030    (set (match_operand:DI 0 "gpc_reg_operand" "")
7031         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7032   "TARGET_POWERPC64 && reload_completed
7033    && includes_rldicr_lshift_p (operands[2], operands[3])"
7034   [(set (match_dup 0)
7035         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7036                 (match_dup 3)))
7037    (set (match_dup 4)
7038         (compare:CC (match_dup 0)
7039                     (const_int 0)))]
7040   "")
7041
7042 (define_expand "lshrdi3"
7043   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7044         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7045                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7046   "TARGET_POWERPC64 || TARGET_POWER"
7047   "
7048 {
7049   if (TARGET_POWERPC64)
7050     ;
7051   else if (TARGET_POWER)
7052     {
7053       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
7054       DONE;
7055     }
7056   else
7057     FAIL;
7058 }")
7059
7060 (define_insn "*lshrdi3_internal1"
7061   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7062         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7063                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
7064   "TARGET_POWERPC64"
7065   "srd%I2 %0,%1,%H2")
7066
7067 (define_insn "*lshrdi3_internal2"
7068   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7069         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7070                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7071                     (const_int 0)))
7072    (clobber (match_scratch:DI 3 "=r,r"))]
7073   "TARGET_64BIT "
7074   "@
7075    srd%I2. %3,%1,%H2
7076    #"
7077   [(set_attr "type" "delayed_compare")
7078    (set_attr "length" "4,8")])
7079
7080 (define_split
7081   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7082         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7083                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7084                     (const_int 0)))
7085    (clobber (match_scratch:DI 3 ""))]
7086   "TARGET_POWERPC64 && reload_completed"
7087   [(set (match_dup 3)
7088         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7089    (set (match_dup 0)
7090         (compare:CC (match_dup 3)
7091                     (const_int 0)))]
7092   "")
7093
7094 (define_insn "*lshrdi3_internal3"
7095   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7096         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7097                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7098                     (const_int 0)))
7099    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7100         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7101   "TARGET_64BIT"
7102   "@
7103    srd%I2. %0,%1,%H2
7104    #"
7105   [(set_attr "type" "delayed_compare")
7106    (set_attr "length" "4,8")])
7107
7108 (define_split
7109   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7110         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7111                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7112                     (const_int 0)))
7113    (set (match_operand:DI 0 "gpc_reg_operand" "")
7114         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7115   "TARGET_POWERPC64 && reload_completed"
7116   [(set (match_dup 0)
7117         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7118    (set (match_dup 3)
7119         (compare:CC (match_dup 0)
7120                     (const_int 0)))]
7121   "")
7122
7123 (define_expand "ashrdi3"
7124   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7125         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7126                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7127   "WORDS_BIG_ENDIAN"
7128   "
7129 {
7130   if (TARGET_POWERPC64)
7131     ;
7132   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
7133     {
7134       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
7135       DONE;
7136     }
7137   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
7138            && WORDS_BIG_ENDIAN)
7139     {
7140       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
7141       DONE;
7142     }
7143   else
7144     FAIL;
7145 }")
7146
7147 (define_insn "*ashrdi3_internal1"
7148   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7149         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7150                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
7151   "TARGET_POWERPC64"
7152   "srad%I2 %0,%1,%H2")
7153
7154 (define_insn "*ashrdi3_internal2"
7155   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7156         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7157                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7158                     (const_int 0)))
7159    (clobber (match_scratch:DI 3 "=r,r"))]
7160   "TARGET_64BIT"
7161   "@
7162    srad%I2. %3,%1,%H2
7163    #"
7164   [(set_attr "type" "delayed_compare")
7165    (set_attr "length" "4,8")])
7166
7167 (define_split
7168   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7169         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7170                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7171                     (const_int 0)))
7172    (clobber (match_scratch:DI 3 ""))]
7173   "TARGET_POWERPC64 && reload_completed"
7174   [(set (match_dup 3)
7175         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7176    (set (match_dup 0)
7177         (compare:CC (match_dup 3)
7178                     (const_int 0)))]
7179   "")
7180
7181 (define_insn "*ashrdi3_internal3"
7182   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7183         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7184                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7185                     (const_int 0)))
7186    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7187         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7188   "TARGET_64BIT"
7189   "@
7190    srad%I2. %0,%1,%H2
7191    #"
7192   [(set_attr "type" "delayed_compare")
7193    (set_attr "length" "4,8")])
7194
7195 (define_split
7196   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7197         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7198                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7199                     (const_int 0)))
7200    (set (match_operand:DI 0 "gpc_reg_operand" "")
7201         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7202   "TARGET_POWERPC64 && reload_completed"
7203   [(set (match_dup 0)
7204         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7205    (set (match_dup 3)
7206         (compare:CC (match_dup 0)
7207                     (const_int 0)))]
7208   "")
7209
7210 (define_insn "anddi3"
7211   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
7212         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
7213                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
7214    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
7215   "TARGET_POWERPC64"
7216   "@
7217    and %0,%1,%2
7218    rldic%B2 %0,%1,0,%S2
7219    rlwinm %0,%1,0,%m2,%M2
7220    andi. %0,%1,%b2
7221    andis. %0,%1,%u2
7222    #"
7223   [(set_attr "type" "*,*,*,compare,compare,*")
7224    (set_attr "length" "4,4,4,4,4,8")])
7225
7226 (define_split
7227   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7228         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7229                 (match_operand:DI 2 "mask64_2_operand" "")))
7230    (clobber (match_scratch:CC 3 ""))]
7231   "TARGET_POWERPC64
7232     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7233     && !mask_operand (operands[2], DImode)
7234     && !mask64_operand (operands[2], DImode)"
7235   [(set (match_dup 0)
7236         (and:DI (rotate:DI (match_dup 1)
7237                            (match_dup 4))
7238                 (match_dup 5)))
7239    (set (match_dup 0)
7240         (and:DI (rotate:DI (match_dup 0)
7241                            (match_dup 6))
7242                 (match_dup 7)))]
7243 {
7244   build_mask64_2_operands (operands[2], &operands[4]);
7245 })
7246
7247 (define_insn "*anddi3_internal2"
7248   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7249         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7250                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7251                     (const_int 0)))
7252    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r,r,r"))
7253    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7254   "TARGET_64BIT"
7255   "@
7256    and. %3,%1,%2
7257    rldic%B2. %3,%1,0,%S2
7258    rlwinm. %3,%1,0,%m2,%M2
7259    andi. %3,%1,%b2
7260    andis. %3,%1,%u2
7261    #
7262    #
7263    #
7264    #
7265    #
7266    #
7267    #"
7268   [(set_attr "type" "compare,compare,compare,compare,compare,compare,compare,compare,compare,compare,compare,compare")
7269    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7270
7271 (define_split
7272   [(set (match_operand:CC 0 "cc_reg_operand" "")
7273         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7274                             (match_operand:DI 2 "mask64_2_operand" ""))
7275                     (const_int 0)))
7276    (clobber (match_scratch:DI 3 ""))
7277    (clobber (match_scratch:CC 4 ""))]
7278   "TARGET_64BIT && reload_completed
7279     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7280     && !mask_operand (operands[2], DImode)
7281     && !mask64_operand (operands[2], DImode)"
7282   [(set (match_dup 3)
7283         (and:DI (rotate:DI (match_dup 1)
7284                            (match_dup 5))
7285                 (match_dup 6)))
7286    (parallel [(set (match_dup 0)
7287                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7288                                                   (match_dup 7))
7289                                        (match_dup 8))
7290                                (const_int 0)))
7291               (clobber (match_dup 3))])]
7292   "
7293 {
7294   build_mask64_2_operands (operands[2], &operands[5]);
7295 }")
7296
7297 (define_insn "*anddi3_internal3"
7298   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,x,?y,?y,?y,??y,??y,?y")
7299         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r,r,r")
7300                             (match_operand:DI 2 "and64_2_operand" "r,S,T,K,J,t,r,S,T,K,J,t"))
7301                     (const_int 0)))
7302    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r,r,r")
7303         (and:DI (match_dup 1) (match_dup 2)))
7304    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,X,X,x,x,X"))]
7305   "TARGET_64BIT"
7306   "@
7307    and. %0,%1,%2
7308    rldic%B2. %0,%1,0,%S2
7309    rlwinm. %0,%1,0,%m2,%M2
7310    andi. %0,%1,%b2
7311    andis. %0,%1,%u2
7312    #
7313    #
7314    #
7315    #
7316    #
7317    #
7318    #"
7319   [(set_attr "type" "compare,compare,compare,compare,compare,compare,compare,compare,compare,compare,compare,compare")
7320    (set_attr "length" "4,4,4,4,4,8,8,8,8,8,8,12")])
7321
7322 (define_split
7323   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7324         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7325                             (match_operand:DI 2 "and64_2_operand" ""))
7326                     (const_int 0)))
7327    (set (match_operand:DI 0 "gpc_reg_operand" "")
7328         (and:DI (match_dup 1) (match_dup 2)))
7329    (clobber (match_scratch:CC 4 ""))]
7330   "TARGET_64BIT && reload_completed"
7331   [(parallel [(set (match_dup 0)
7332                     (and:DI (match_dup 1) (match_dup 2)))
7333                (clobber (match_dup 4))])
7334    (set (match_dup 3)
7335         (compare:CC (match_dup 0)
7336                     (const_int 0)))]
7337   "")
7338
7339 (define_split
7340   [(set (match_operand:CC 3 "cc_reg_operand" "")
7341         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7342                             (match_operand:DI 2 "mask64_2_operand" ""))
7343                     (const_int 0)))
7344    (set (match_operand:DI 0 "gpc_reg_operand" "")
7345         (and:DI (match_dup 1) (match_dup 2)))
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 0)
7352         (and:DI (rotate:DI (match_dup 1)
7353                            (match_dup 5))
7354                 (match_dup 6)))
7355    (parallel [(set (match_dup 3)
7356                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7357                                                   (match_dup 7))
7358                                        (match_dup 8))
7359                                (const_int 0)))
7360               (set (match_dup 0)
7361                    (and:DI (rotate:DI (match_dup 0)
7362                                       (match_dup 7))
7363                            (match_dup 8)))])]
7364   "
7365 {
7366   build_mask64_2_operands (operands[2], &operands[5]);
7367 }")
7368
7369 (define_expand "iordi3"
7370   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7371         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7372                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7373   "TARGET_POWERPC64"
7374   "
7375 {
7376   if (non_logical_cint_operand (operands[2], DImode))
7377     {
7378       HOST_WIDE_INT value;
7379       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7380                  ? operands[0] : gen_reg_rtx (DImode));
7381
7382       if (GET_CODE (operands[2]) == CONST_INT)
7383         {
7384           value = INTVAL (operands[2]);
7385           emit_insn (gen_iordi3 (tmp, operands[1],
7386                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7387         }
7388       else
7389         {
7390           value = CONST_DOUBLE_LOW (operands[2]);
7391           emit_insn (gen_iordi3 (tmp, operands[1],
7392                                  immed_double_const (value
7393                                                      & (~ (HOST_WIDE_INT) 0xffff),
7394                                                      0, DImode)));
7395         }
7396
7397       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7398       DONE;
7399     }
7400 }")
7401
7402 (define_expand "xordi3"
7403   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7404         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7405                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7406   "TARGET_POWERPC64"
7407   "
7408 {
7409   if (non_logical_cint_operand (operands[2], DImode))
7410     {
7411       HOST_WIDE_INT value;
7412       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7413                  ? operands[0] : gen_reg_rtx (DImode));
7414
7415       if (GET_CODE (operands[2]) == CONST_INT)
7416         {
7417           value = INTVAL (operands[2]);
7418           emit_insn (gen_xordi3 (tmp, operands[1],
7419                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7420         }
7421       else
7422         {
7423           value = CONST_DOUBLE_LOW (operands[2]);
7424           emit_insn (gen_xordi3 (tmp, operands[1],
7425                                  immed_double_const (value
7426                                                      & (~ (HOST_WIDE_INT) 0xffff),
7427                                                      0, DImode)));
7428         }
7429
7430       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7431       DONE;
7432     }
7433 }")
7434
7435 (define_insn "*booldi3_internal1"
7436   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7437         (match_operator:DI 3 "boolean_or_operator"
7438          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7439           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7440   "TARGET_POWERPC64"
7441   "@
7442    %q3 %0,%1,%2
7443    %q3i %0,%1,%b2
7444    %q3is %0,%1,%u2")
7445
7446 (define_insn "*booldi3_internal2"
7447   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7448         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7449          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7450           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7451          (const_int 0)))
7452    (clobber (match_scratch:DI 3 "=r,r"))]
7453   "TARGET_64BIT"
7454   "@
7455    %q4. %3,%1,%2
7456    #"
7457   [(set_attr "type" "compare")
7458    (set_attr "length" "4,8")])
7459
7460 (define_split
7461   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7462         (compare:CC (match_operator:DI 4 "boolean_operator"
7463          [(match_operand:DI 1 "gpc_reg_operand" "")
7464           (match_operand:DI 2 "gpc_reg_operand" "")])
7465          (const_int 0)))
7466    (clobber (match_scratch:DI 3 ""))]
7467   "TARGET_POWERPC64 && reload_completed"
7468   [(set (match_dup 3) (match_dup 4))
7469    (set (match_dup 0)
7470         (compare:CC (match_dup 3)
7471                     (const_int 0)))]
7472   "")
7473
7474 (define_insn "*booldi3_internal3"
7475   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7476         (compare:CC (match_operator:DI 4 "boolean_operator"
7477          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7478           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7479          (const_int 0)))
7480    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7481         (match_dup 4))]
7482   "TARGET_64BIT"
7483   "@
7484    %q4. %0,%1,%2
7485    #"
7486   [(set_attr "type" "compare")
7487    (set_attr "length" "4,8")])
7488
7489 (define_split
7490   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7491         (compare:CC (match_operator:DI 4 "boolean_operator"
7492          [(match_operand:DI 1 "gpc_reg_operand" "")
7493           (match_operand:DI 2 "gpc_reg_operand" "")])
7494          (const_int 0)))
7495    (set (match_operand:DI 0 "gpc_reg_operand" "")
7496         (match_dup 4))]
7497   "TARGET_POWERPC64 && reload_completed"
7498   [(set (match_dup 0) (match_dup 4))
7499    (set (match_dup 3)
7500         (compare:CC (match_dup 0)
7501                     (const_int 0)))]
7502   "")
7503
7504 ;; Split a logical operation that we can't do in one insn into two insns,
7505 ;; each of which does one 16-bit part.  This is used by combine.
7506
7507 (define_split
7508   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7509         (match_operator:DI 3 "boolean_or_operator"
7510          [(match_operand:DI 1 "gpc_reg_operand" "")
7511           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7512   "TARGET_POWERPC64"
7513   [(set (match_dup 0) (match_dup 4))
7514    (set (match_dup 0) (match_dup 5))]
7515 "
7516 {
7517   rtx i3,i4;
7518
7519   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7520     {
7521       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7522       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7523                                         0, DImode);
7524       i4 = GEN_INT (value & 0xffff);
7525     }
7526   else
7527     {
7528       i3 = GEN_INT (INTVAL (operands[2])
7529                              & (~ (HOST_WIDE_INT) 0xffff));
7530       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7531     }
7532   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7533                                 operands[1], i3);
7534   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7535                                 operands[0], i4);
7536 }")
7537
7538 (define_insn "*boolcdi3_internal1"
7539   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7540         (match_operator:DI 3 "boolean_operator"
7541          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7542           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7543   "TARGET_POWERPC64"
7544   "%q3 %0,%2,%1")
7545
7546 (define_insn "*boolcdi3_internal2"
7547   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7548         (compare:CC (match_operator:DI 4 "boolean_operator"
7549          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7550           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7551          (const_int 0)))
7552    (clobber (match_scratch:DI 3 "=r,r"))]
7553   "TARGET_64BIT"
7554   "@
7555    %q4. %3,%2,%1
7556    #"
7557   [(set_attr "type" "compare")
7558    (set_attr "length" "4,8")])
7559
7560 (define_split
7561   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7562         (compare:CC (match_operator:DI 4 "boolean_operator"
7563          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7564           (match_operand:DI 2 "gpc_reg_operand" "")])
7565          (const_int 0)))
7566    (clobber (match_scratch:DI 3 ""))]
7567   "TARGET_POWERPC64 && reload_completed"
7568   [(set (match_dup 3) (match_dup 4))
7569    (set (match_dup 0)
7570         (compare:CC (match_dup 3)
7571                     (const_int 0)))]
7572   "")
7573
7574 (define_insn "*boolcdi3_internal3"
7575   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7576         (compare:CC (match_operator:DI 4 "boolean_operator"
7577          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7578           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7579          (const_int 0)))
7580    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7581         (match_dup 4))]
7582   "TARGET_64BIT"
7583   "@
7584    %q4. %0,%2,%1
7585    #"
7586   [(set_attr "type" "compare")
7587    (set_attr "length" "4,8")])
7588
7589 (define_split
7590   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7591         (compare:CC (match_operator:DI 4 "boolean_operator"
7592          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7593           (match_operand:DI 2 "gpc_reg_operand" "")])
7594          (const_int 0)))
7595    (set (match_operand:DI 0 "gpc_reg_operand" "")
7596         (match_dup 4))]
7597   "TARGET_POWERPC64 && reload_completed"
7598   [(set (match_dup 0) (match_dup 4))
7599    (set (match_dup 3)
7600         (compare:CC (match_dup 0)
7601                     (const_int 0)))]
7602   "")
7603
7604 (define_insn "*boolccdi3_internal1"
7605   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7606         (match_operator:DI 3 "boolean_operator"
7607          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7608           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7609   "TARGET_POWERPC64"
7610   "%q3 %0,%1,%2")
7611
7612 (define_insn "*boolccdi3_internal2"
7613   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7614         (compare:CC (match_operator:DI 4 "boolean_operator"
7615          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7616           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7617          (const_int 0)))
7618    (clobber (match_scratch:DI 3 "=r,r"))]
7619   "TARGET_64BIT"
7620   "@
7621    %q4. %3,%1,%2
7622    #"
7623   [(set_attr "type" "compare")
7624    (set_attr "length" "4,8")])
7625
7626 (define_split
7627   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7628         (compare:CC (match_operator:DI 4 "boolean_operator"
7629          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7630           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7631          (const_int 0)))
7632    (clobber (match_scratch:DI 3 ""))]
7633   "TARGET_POWERPC64 && reload_completed"
7634   [(set (match_dup 3) (match_dup 4))
7635    (set (match_dup 0)
7636         (compare:CC (match_dup 3)
7637                     (const_int 0)))]
7638   "")
7639
7640 (define_insn "*boolccdi3_internal3"
7641   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7642         (compare:CC (match_operator:DI 4 "boolean_operator"
7643          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7644           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7645          (const_int 0)))
7646    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7647         (match_dup 4))]
7648   "TARGET_64BIT"
7649   "@
7650    %q4. %0,%1,%2
7651    #"
7652   [(set_attr "type" "compare")
7653    (set_attr "length" "4,8")])
7654
7655 (define_split
7656   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7657         (compare:CC (match_operator:DI 4 "boolean_operator"
7658          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7659           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7660          (const_int 0)))
7661    (set (match_operand:DI 0 "gpc_reg_operand" "")
7662         (match_dup 4))]
7663   "TARGET_POWERPC64 && reload_completed"
7664   [(set (match_dup 0) (match_dup 4))
7665    (set (match_dup 3)
7666         (compare:CC (match_dup 0)
7667                     (const_int 0)))]
7668   "")
7669 \f
7670 ;; Now define ways of moving data around.
7671
7672 ;; Set up a register with a value from the GOT table
7673
7674 (define_expand "movsi_got"
7675   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7676         (unspec:SI [(match_operand:SI 1 "got_operand" "")
7677                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
7678   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7679   "
7680 {
7681   if (GET_CODE (operands[1]) == CONST)
7682     {
7683       rtx offset = const0_rtx;
7684       HOST_WIDE_INT value;
7685
7686       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
7687       value = INTVAL (offset);
7688       if (value != 0)
7689         {
7690           rtx tmp = (no_new_pseudos ? operands[0] : gen_reg_rtx (Pmode));
7691           emit_insn (gen_movsi_got (tmp, operands[1]));
7692           emit_insn (gen_addsi3 (operands[0], tmp, offset));
7693           DONE;
7694         }
7695     }
7696
7697   operands[2] = rs6000_got_register (operands[1]);
7698 }")
7699
7700 (define_insn "*movsi_got_internal"
7701   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7702         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7703                     (match_operand:SI 2 "gpc_reg_operand" "b")]
7704                    UNSPEC_MOVSI_GOT))]
7705   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7706   "{l|lwz} %0,%a1@got(%2)"
7707   [(set_attr "type" "load")])
7708
7709 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
7710 ;; didn't get allocated to a hard register.
7711 (define_split
7712   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7713         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7714                     (match_operand:SI 2 "memory_operand" "")]
7715                    UNSPEC_MOVSI_GOT))]
7716   "DEFAULT_ABI == ABI_V4
7717     && flag_pic == 1
7718     && (reload_in_progress || reload_completed)"
7719   [(set (match_dup 0) (match_dup 2))
7720    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
7721                                  UNSPEC_MOVSI_GOT))]
7722   "")
7723
7724 ;; For SI, we special-case integers that can't be loaded in one insn.  We
7725 ;; do the load 16-bits at a time.  We could do this by loading from memory,
7726 ;; and this is even supposed to be faster, but it is simpler not to get
7727 ;; integers in the TOC.
7728 (define_insn "movsi_low"
7729   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7730         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7731                            (match_operand 2 "" ""))))]
7732   "TARGET_MACHO && ! TARGET_64BIT"
7733   "{l|lwz} %0,lo16(%2)(%1)"
7734   [(set_attr "type" "load")
7735    (set_attr "length" "4")])
7736
7737 (define_insn "*movsi_internal1"
7738   [(set (match_operand:SI 0 "rs6000_nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
7739         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
7740   "gpc_reg_operand (operands[0], SImode)
7741    || gpc_reg_operand (operands[1], SImode)"
7742   "@
7743    mr %0,%1
7744    {cal|la} %0,%a1
7745    {l%U1%X1|lwz%U1%X1} %0,%1
7746    {st%U0%X0|stw%U0%X0} %1,%0
7747    {lil|li} %0,%1
7748    {liu|lis} %0,%v1
7749    #
7750    {cal|la} %0,%a1
7751    mf%1 %0
7752    mt%0 %1
7753    mt%0 %1
7754    mt%0 %1
7755    {cror 0,0,0|nop}"
7756   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
7757    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
7758
7759 ;; Split a load of a large constant into the appropriate two-insn
7760 ;; sequence.
7761
7762 (define_split
7763   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7764         (match_operand:SI 1 "const_int_operand" ""))]
7765   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
7766    && (INTVAL (operands[1]) & 0xffff) != 0"
7767   [(set (match_dup 0)
7768         (match_dup 2))
7769    (set (match_dup 0)
7770         (ior:SI (match_dup 0)
7771                 (match_dup 3)))]
7772   "
7773 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
7774
7775   if (tem == operands[0])
7776     DONE;
7777   else
7778     FAIL;
7779 }")
7780
7781 (define_insn "*mov<mode>_internal2"
7782   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
7783         (compare:CC (match_operand:P 1 "gpc_reg_operand" "0,r,r")
7784                     (const_int 0)))
7785    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
7786   ""
7787   "@
7788    {cmpi|cmp<wd>i} %2,%0,0
7789    mr. %0,%1
7790    #"
7791   [(set_attr "type" "cmp,compare,cmp")
7792    (set_attr "length" "4,4,8")])
7793
7794 (define_split
7795   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
7796         (compare:CC (match_operand:P 1 "gpc_reg_operand" "")
7797                     (const_int 0)))
7798    (set (match_operand:P 0 "gpc_reg_operand" "") (match_dup 1))]
7799   "reload_completed"
7800   [(set (match_dup 0) (match_dup 1))
7801    (set (match_dup 2)
7802         (compare:CC (match_dup 0)
7803                     (const_int 0)))]
7804   "")
7805 \f
7806 (define_insn "*movhi_internal"
7807   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7808         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7809   "gpc_reg_operand (operands[0], HImode)
7810    || gpc_reg_operand (operands[1], HImode)"
7811   "@
7812    mr %0,%1
7813    lhz%U1%X1 %0,%1
7814    sth%U0%X0 %1,%0
7815    {lil|li} %0,%w1
7816    mf%1 %0
7817    mt%0 %1
7818    mt%0 %1
7819    {cror 0,0,0|nop}"
7820   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7821
7822 (define_expand "mov<mode>"
7823   [(set (match_operand:INT 0 "general_operand" "")
7824         (match_operand:INT 1 "any_operand" ""))]
7825   ""
7826   "{ rs6000_emit_move (operands[0], operands[1], <MODE>mode); DONE; }")
7827
7828 (define_insn "*movqi_internal"
7829   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7830         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7831   "gpc_reg_operand (operands[0], QImode)
7832    || gpc_reg_operand (operands[1], QImode)"
7833   "@
7834    mr %0,%1
7835    lbz%U1%X1 %0,%1
7836    stb%U0%X0 %1,%0
7837    {lil|li} %0,%1
7838    mf%1 %0
7839    mt%0 %1
7840    mt%0 %1
7841    {cror 0,0,0|nop}"
7842   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7843 \f
7844 ;; Here is how to move condition codes around.  When we store CC data in
7845 ;; an integer register or memory, we store just the high-order 4 bits.
7846 ;; This lets us not shift in the most common case of CR0.
7847 (define_expand "movcc"
7848   [(set (match_operand:CC 0 "nonimmediate_operand" "")
7849         (match_operand:CC 1 "nonimmediate_operand" ""))]
7850   ""
7851   "")
7852
7853 (define_insn "*movcc_internal1"
7854   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,r,r,r,r,q,cl,r,m")
7855         (match_operand:CC 1 "nonimmediate_operand" "y,r,r,x,y,r,h,r,r,m,r"))]
7856   "register_operand (operands[0], CCmode)
7857    || register_operand (operands[1], CCmode)"
7858   "@
7859    mcrf %0,%1
7860    mtcrf 128,%1
7861    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
7862    mfcr %0%Q1
7863    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
7864    mr %0,%1
7865    mf%1 %0
7866    mt%0 %1
7867    mt%0 %1
7868    {l%U1%X1|lwz%U1%X1} %0,%1
7869    {st%U0%U1|stw%U0%U1} %1,%0"
7870   [(set (attr "type")
7871      (cond [(eq_attr "alternative" "0")
7872                 (const_string "cr_logical")
7873             (eq_attr "alternative" "1,2")
7874                 (const_string "mtcr")
7875             (eq_attr "alternative" "5,7")
7876                 (const_string "integer")
7877             (eq_attr "alternative" "6")
7878                 (const_string "mfjmpr")
7879             (eq_attr "alternative" "8")
7880                 (const_string "mtjmpr")
7881             (eq_attr "alternative" "9")
7882                 (const_string "load")
7883             (eq_attr "alternative" "10")
7884                 (const_string "store")
7885             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
7886                 (const_string "mfcrf")
7887            ]
7888         (const_string "mfcr")))
7889    (set_attr "length" "4,4,12,4,8,4,4,4,4,4,4")])
7890 \f
7891 ;; For floating-point, we normally deal with the floating-point registers
7892 ;; unless -msoft-float is used.  The sole exception is that parameter passing
7893 ;; can produce floating-point values in fixed-point registers.  Unless the
7894 ;; value is a simple constant or already in memory, we deal with this by
7895 ;; allocating memory and copying the value explicitly via that memory location.
7896 (define_expand "movsf"
7897   [(set (match_operand:SF 0 "nonimmediate_operand" "")
7898         (match_operand:SF 1 "any_operand" ""))]
7899   ""
7900   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
7901
7902 (define_split
7903   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7904         (match_operand:SF 1 "const_double_operand" ""))]
7905   "reload_completed
7906    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7907        || (GET_CODE (operands[0]) == SUBREG
7908            && GET_CODE (SUBREG_REG (operands[0])) == REG
7909            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7910   [(set (match_dup 2) (match_dup 3))]
7911   "
7912 {
7913   long l;
7914   REAL_VALUE_TYPE rv;
7915
7916   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7917   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
7918
7919   if (! TARGET_POWERPC64)
7920     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
7921   else
7922     operands[2] = gen_lowpart (SImode, operands[0]);
7923
7924   operands[3] = gen_int_mode (l, SImode);
7925 }")
7926
7927 (define_insn "*movsf_hardfloat"
7928   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,*c*l,*q,!r,*h,!r,!r")
7929         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,0,G,Fn"))]
7930   "(gpc_reg_operand (operands[0], SFmode)
7931    || gpc_reg_operand (operands[1], SFmode))
7932    && (TARGET_HARD_FLOAT && TARGET_FPRS)"
7933   "@
7934    mr %0,%1
7935    {l%U1%X1|lwz%U1%X1} %0,%1
7936    {st%U0%X0|stw%U0%X0} %1,%0
7937    fmr %0,%1
7938    lfs%U1%X1 %0,%1
7939    stfs%U0%X0 %1,%0
7940    mt%0 %1
7941    mt%0 %1
7942    mf%1 %0
7943    {cror 0,0,0|nop}
7944    #
7945    #"
7946   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,mfjmpr,*,*,*")
7947    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,8")])
7948
7949 (define_insn "*movsf_softfloat"
7950   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
7951         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
7952   "(gpc_reg_operand (operands[0], SFmode)
7953    || gpc_reg_operand (operands[1], SFmode))
7954    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
7955   "@
7956    mr %0,%1
7957    mt%0 %1
7958    mt%0 %1
7959    mf%1 %0
7960    {l%U1%X1|lwz%U1%X1} %0,%1
7961    {st%U0%X0|stw%U0%X0} %1,%0
7962    {lil|li} %0,%1
7963    {liu|lis} %0,%v1
7964    {cal|la} %0,%a1
7965    #
7966    #
7967    {cror 0,0,0|nop}"
7968   [(set_attr "type" "*,mtjmpr,*,mfjmpr,load,store,*,*,*,*,*,*")
7969    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
7970
7971 \f
7972 (define_expand "movdf"
7973   [(set (match_operand:DF 0 "nonimmediate_operand" "")
7974         (match_operand:DF 1 "any_operand" ""))]
7975   ""
7976   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
7977
7978 (define_split
7979   [(set (match_operand:DF 0 "gpc_reg_operand" "")
7980         (match_operand:DF 1 "const_int_operand" ""))]
7981   "! TARGET_POWERPC64 && reload_completed
7982    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7983        || (GET_CODE (operands[0]) == SUBREG
7984            && GET_CODE (SUBREG_REG (operands[0])) == REG
7985            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7986   [(set (match_dup 2) (match_dup 4))
7987    (set (match_dup 3) (match_dup 1))]
7988   "
7989 {
7990   int endian = (WORDS_BIG_ENDIAN == 0);
7991   HOST_WIDE_INT value = INTVAL (operands[1]);
7992
7993   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
7994   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
7995 #if HOST_BITS_PER_WIDE_INT == 32
7996   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
7997 #else
7998   operands[4] = GEN_INT (value >> 32);
7999   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8000 #endif
8001 }")
8002
8003 (define_split
8004   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8005         (match_operand:DF 1 "const_double_operand" ""))]
8006   "! TARGET_POWERPC64 && reload_completed
8007    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8008        || (GET_CODE (operands[0]) == SUBREG
8009            && GET_CODE (SUBREG_REG (operands[0])) == REG
8010            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8011   [(set (match_dup 2) (match_dup 4))
8012    (set (match_dup 3) (match_dup 5))]
8013   "
8014 {
8015   int endian = (WORDS_BIG_ENDIAN == 0);
8016   long l[2];
8017   REAL_VALUE_TYPE rv;
8018
8019   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8020   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8021
8022   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8023   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8024   operands[4] = gen_int_mode (l[endian], SImode);
8025   operands[5] = gen_int_mode (l[1 - endian], SImode);
8026 }")
8027
8028 (define_split
8029   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8030         (match_operand:DF 1 "const_double_operand" ""))]
8031   "TARGET_POWERPC64 && reload_completed
8032    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8033        || (GET_CODE (operands[0]) == SUBREG
8034            && GET_CODE (SUBREG_REG (operands[0])) == REG
8035            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8036   [(set (match_dup 2) (match_dup 3))]
8037   "
8038 {
8039   int endian = (WORDS_BIG_ENDIAN == 0);
8040   long l[2];
8041   REAL_VALUE_TYPE rv;
8042 #if HOST_BITS_PER_WIDE_INT >= 64
8043   HOST_WIDE_INT val;
8044 #endif
8045
8046   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8047   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8048
8049   operands[2] = gen_lowpart (DImode, operands[0]);
8050   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
8051 #if HOST_BITS_PER_WIDE_INT >= 64
8052   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
8053          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
8054
8055   operands[3] = gen_int_mode (val, DImode);
8056 #else
8057   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
8058 #endif
8059 }")
8060
8061 ;; Don't have reload use general registers to load a constant.  First,
8062 ;; it might not work if the output operand is the equivalent of
8063 ;; a non-offsettable memref, but also it is less efficient than loading
8064 ;; the constant into an FP register, since it will probably be used there.
8065 ;; The "??" is a kludge until we can figure out a more reasonable way
8066 ;; of handling these non-offsettable values.
8067 (define_insn "*movdf_hardfloat32"
8068   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,f,f,m,!r,!r,!r")
8069         (match_operand:DF 1 "input_operand" "r,m,r,f,m,f,G,H,F"))]
8070   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8071    && (gpc_reg_operand (operands[0], DFmode)
8072        || gpc_reg_operand (operands[1], DFmode))"
8073   "*
8074 {
8075   switch (which_alternative)
8076     {
8077     default:
8078       gcc_unreachable ();
8079     case 0:
8080       /* We normally copy the low-numbered register first.  However, if
8081          the first register operand 0 is the same as the second register
8082          of operand 1, we must copy in the opposite order.  */
8083       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8084         return \"mr %L0,%L1\;mr %0,%1\";
8085       else
8086         return \"mr %0,%1\;mr %L0,%L1\";
8087     case 1:
8088       if (GET_CODE (operands[1]) == MEM
8089           && (rs6000_legitimate_offset_address_p (DFmode, XEXP (operands[1], 0),
8090                         reload_completed || reload_in_progress)
8091               || rs6000_legitimate_small_data_p (DFmode, XEXP (operands[1], 0))
8092               || GET_CODE (XEXP (operands[1], 0)) == REG
8093               || GET_CODE (XEXP (operands[1], 0)) == LO_SUM
8094               || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
8095               || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC))
8096         {
8097           /* If the low-address word is used in the address, we must load
8098              it last.  Otherwise, load it first.  Note that we cannot have
8099              auto-increment in that case since the address register is
8100              known to be dead.  */
8101           if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8102                                  operands[1], 0))
8103             return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8104           else
8105             return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8106         }
8107       else
8108         {
8109           rtx addreg;
8110
8111           addreg = find_addr_reg (XEXP (operands[1], 0));
8112           if (refers_to_regno_p (REGNO (operands[0]),
8113                                  REGNO (operands[0]) + 1,
8114                                  operands[1], 0))
8115             {
8116               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8117               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8118               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8119               return \"{lx|lwzx} %0,%1\";
8120             }
8121           else
8122             {
8123               output_asm_insn (\"{lx|lwzx} %0,%1\", operands);
8124               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8125               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8126               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8127               return \"\";
8128             }
8129         }
8130     case 2:
8131       if (GET_CODE (operands[0]) == MEM
8132           && (rs6000_legitimate_offset_address_p (DFmode, XEXP (operands[0], 0),
8133                     reload_completed || reload_in_progress)
8134               || rs6000_legitimate_small_data_p (DFmode, XEXP (operands[0], 0))
8135               || GET_CODE (XEXP (operands[0], 0)) == REG
8136               || GET_CODE (XEXP (operands[0], 0)) == LO_SUM
8137               || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
8138               || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC))
8139         return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8140       else
8141         {
8142           rtx addreg;
8143
8144           addreg = find_addr_reg (XEXP (operands[0], 0));
8145           output_asm_insn (\"{stx|stwx} %1,%0\", operands);
8146           output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8147           output_asm_insn (\"{stx|stwx} %L1,%0\", operands);
8148           output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8149           return \"\";
8150         }
8151     case 3:
8152       return \"fmr %0,%1\";
8153     case 4:
8154       return \"lfd%U1%X1 %0,%1\";
8155     case 5:
8156       return \"stfd%U0%X0 %1,%0\";
8157     case 6:
8158     case 7:
8159     case 8:
8160       return \"#\";
8161     }
8162 }"
8163   [(set_attr "type" "two,load,store,fp,fpload,fpstore,*,*,*")
8164    (set_attr "length" "8,16,16,4,4,4,8,12,16")])
8165
8166 (define_insn "*movdf_softfloat32"
8167   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
8168         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
8169   "! TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
8170    && (gpc_reg_operand (operands[0], DFmode)
8171        || gpc_reg_operand (operands[1], DFmode))"
8172   "*
8173 {
8174   switch (which_alternative)
8175     {
8176     default:
8177       gcc_unreachable ();
8178     case 0:
8179       /* We normally copy the low-numbered register first.  However, if
8180          the first register operand 0 is the same as the second register of
8181          operand 1, we must copy in the opposite order.  */
8182       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8183         return \"mr %L0,%L1\;mr %0,%1\";
8184       else
8185         return \"mr %0,%1\;mr %L0,%L1\";
8186     case 1:
8187       /* If the low-address word is used in the address, we must load
8188          it last.  Otherwise, load it first.  Note that we cannot have
8189          auto-increment in that case since the address register is
8190          known to be dead.  */
8191       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8192                              operands[1], 0))
8193         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8194       else
8195         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8196     case 2:
8197       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8198     case 3:
8199     case 4:
8200     case 5:
8201       return \"#\";
8202     }
8203 }"
8204   [(set_attr "type" "two,load,store,*,*,*")
8205    (set_attr "length" "8,8,8,8,12,16")])
8206
8207 ; ld/std require word-aligned displacements -> 'Y' constraint.
8208 ; List Y->r and r->Y before r->r for reload.
8209 (define_insn "*movdf_hardfloat64"
8210   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,f,f,m,*c*l,!r,*h,!r,!r,!r")
8211         (match_operand:DF 1 "input_operand" "r,Y,r,f,m,f,r,h,0,G,H,F"))]
8212   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8213    && (gpc_reg_operand (operands[0], DFmode)
8214        || gpc_reg_operand (operands[1], DFmode))"
8215   "@
8216    std%U0%X0 %1,%0
8217    ld%U1%X1 %0,%1
8218    mr %0,%1
8219    fmr %0,%1
8220    lfd%U1%X1 %0,%1
8221    stfd%U0%X0 %1,%0
8222    mt%0 %1
8223    mf%1 %0
8224    {cror 0,0,0|nop}
8225    #
8226    #
8227    #"
8228   [(set_attr "type" "store,load,*,fp,fpload,fpstore,mtjmpr,mfjmpr,*,*,*,*")
8229    (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16")])
8230
8231 (define_insn "*movdf_softfloat64"
8232   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
8233         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
8234   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8235    && (gpc_reg_operand (operands[0], DFmode)
8236        || gpc_reg_operand (operands[1], DFmode))"
8237   "@
8238    ld%U1%X1 %0,%1
8239    std%U0%X0 %1,%0
8240    mr %0,%1
8241    mt%0 %1
8242    mf%1 %0
8243    #
8244    #
8245    #
8246    {cror 0,0,0|nop}"
8247   [(set_attr "type" "load,store,*,mtjmpr,mfjmpr,*,*,*,*")
8248    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
8249 \f
8250 (define_expand "movtf"
8251   [(set (match_operand:TF 0 "general_operand" "")
8252         (match_operand:TF 1 "any_operand" ""))]
8253   "!TARGET_IEEEQUAD
8254    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8255   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
8256
8257 ; It's important to list the o->f and f->o moves before f->f because
8258 ; otherwise reload, given m->f, will try to pick f->f and reload it,
8259 ; which doesn't make progress.  Likewise r->Y must be before r->r.
8260 (define_insn_and_split "*movtf_internal"
8261   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,f,r,Y,r")
8262         (match_operand:TF 1 "input_operand"         "f,o,f,YGHF,r,r"))]
8263   "!TARGET_IEEEQUAD
8264    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
8265    && (gpc_reg_operand (operands[0], TFmode)
8266        || gpc_reg_operand (operands[1], TFmode))"
8267   "#"
8268   "&& reload_completed"
8269   [(pc)]
8270 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8271   [(set_attr "length" "8,8,8,20,20,16")])
8272
8273 (define_expand "extenddftf2"
8274   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
8275                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
8276               (use (match_dup 2))])]
8277   "!TARGET_IEEEQUAD
8278    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8279 {
8280   operands[2] = CONST0_RTX (DFmode);
8281 })
8282
8283 (define_insn_and_split "*extenddftf2_internal"
8284   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,&f,r")
8285        (float_extend:TF (match_operand:DF 1 "input_operand" "fr,mf,mf,rmGHF")))
8286    (use (match_operand:DF 2 "zero_reg_mem_operand" "rf,m,f,n"))]
8287   "!TARGET_IEEEQUAD
8288    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8289   "#"
8290   "&& reload_completed"
8291   [(pc)]
8292 {
8293   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8294   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8295   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
8296                   operands[1]);
8297   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
8298                   operands[2]);
8299   DONE;
8300 })
8301
8302 (define_expand "extendsftf2"
8303   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8304         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
8305   "!TARGET_IEEEQUAD
8306    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8307 {
8308   rtx tmp = gen_reg_rtx (DFmode);
8309   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
8310   emit_insn (gen_extenddftf2 (operands[0], tmp));
8311   DONE;
8312 })
8313
8314 (define_expand "trunctfdf2"
8315   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8316         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))]
8317   "!TARGET_IEEEQUAD
8318    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8319   "")
8320
8321 (define_insn_and_split "trunctfdf2_internal1"
8322   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f")
8323         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "0,f")))]
8324   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
8325    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8326   "@
8327    #
8328    fmr %0,%1"
8329   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
8330   [(const_int 0)]
8331 {
8332   emit_note (NOTE_INSN_DELETED);
8333   DONE;
8334 }
8335   [(set_attr "type" "fp")])
8336
8337 (define_insn "trunctfdf2_internal2"
8338   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8339         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8340   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
8341    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8342   "fadd %0,%1,%L1"
8343   [(set_attr "type" "fp")])
8344
8345 (define_insn_and_split "trunctfsf2"
8346   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8347         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "f")))
8348    (clobber (match_scratch:DF 2 "=f"))]
8349   "!TARGET_IEEEQUAD
8350    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8351   "#"
8352   "&& reload_completed"
8353   [(set (match_dup 2)
8354         (float_truncate:DF (match_dup 1)))
8355    (set (match_dup 0)
8356         (float_truncate:SF (match_dup 2)))]
8357   "")
8358
8359 (define_expand "floatsitf2"
8360   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8361         (float:TF (match_operand:SI 1 "gpc_reg_operand" "r")))]
8362   "!TARGET_IEEEQUAD
8363    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8364 {
8365   rtx tmp = gen_reg_rtx (DFmode);
8366   expand_float (tmp, operands[1], false);
8367   emit_insn (gen_extenddftf2 (operands[0], tmp));
8368   DONE;
8369 })
8370
8371 ; fadd, but rounding towards zero.
8372 ; This is probably not the optimal code sequence.
8373 (define_insn "fix_trunc_helper"
8374   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8375         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "f")]
8376                    UNSPEC_FIX_TRUNC_TF))
8377    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&f"))]
8378   "TARGET_HARD_FLOAT && TARGET_FPRS"
8379   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
8380   [(set_attr "type" "fp")
8381    (set_attr "length" "20")])
8382
8383 (define_expand "fix_trunctfsi2"
8384   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
8385                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
8386               (clobber (match_dup 2))
8387               (clobber (match_dup 3))
8388               (clobber (match_dup 4))
8389               (clobber (match_dup 5))])]
8390   "!TARGET_IEEEQUAD
8391    && (TARGET_POWER2 || TARGET_POWERPC)
8392    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8393 {
8394   operands[2] = gen_reg_rtx (DFmode);
8395   operands[3] = gen_reg_rtx (DFmode);
8396   operands[4] = gen_reg_rtx (DImode);
8397   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
8398 })
8399
8400 (define_insn_and_split "*fix_trunctfsi2_internal"
8401   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8402         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "f")))
8403    (clobber (match_operand:DF 2 "gpc_reg_operand" "=f"))
8404    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&f"))
8405    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))
8406    (clobber (match_operand:DI 5 "memory_operand" "=o"))]
8407   "!TARGET_IEEEQUAD
8408    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8409   "#"
8410   "&& (!no_new_pseudos || offsettable_nonstrict_memref_p (operands[5]))"
8411   [(pc)]
8412 {
8413   rtx lowword;
8414   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
8415
8416   gcc_assert (MEM_P (operands[5]));
8417   lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
8418
8419   emit_insn (gen_fctiwz (operands[4], operands[2]));
8420   emit_move_insn (operands[5], operands[4]);
8421   emit_move_insn (operands[0], lowword);
8422   DONE;
8423 })
8424
8425 (define_insn "negtf2"
8426   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8427         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8428   "!TARGET_IEEEQUAD
8429    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8430   "*
8431 {
8432   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8433     return \"fneg %L0,%L1\;fneg %0,%1\";
8434   else
8435     return \"fneg %0,%1\;fneg %L0,%L1\";
8436 }"
8437   [(set_attr "type" "fp")
8438    (set_attr "length" "8")])
8439
8440 (define_expand "abstf2"
8441   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8442         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8443   "!TARGET_IEEEQUAD
8444    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8445   "
8446 {
8447   rtx label = gen_label_rtx ();
8448   emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
8449   emit_label (label);
8450   DONE;
8451 }")
8452
8453 (define_expand "abstf2_internal"
8454   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8455         (match_operand:TF 1 "gpc_reg_operand" "f"))
8456    (set (match_dup 3) (match_dup 5))
8457    (set (match_dup 5) (abs:DF (match_dup 5)))
8458    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
8459    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
8460                            (label_ref (match_operand 2 "" ""))
8461                            (pc)))
8462    (set (match_dup 6) (neg:DF (match_dup 6)))]
8463   "!TARGET_IEEEQUAD
8464    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8465   "
8466 {
8467   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8468   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8469   operands[3] = gen_reg_rtx (DFmode);
8470   operands[4] = gen_reg_rtx (CCFPmode);
8471   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
8472   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
8473 }")
8474 \f
8475 ;; Next come the multi-word integer load and store and the load and store
8476 ;; multiple insns.
8477
8478 ; List r->r after r->"o<>", otherwise reload will try to reload a
8479 ; non-offsettable address by using r->r which won't make progress.
8480 (define_insn "*movdi_internal32"
8481   [(set (match_operand:DI 0 "nonimmediate_operand" "=o<>,r,r,*f,*f,m,r")
8482         (match_operand:DI 1 "input_operand" "r,r,m,f,m,f,IJKnGHF"))]
8483   "! TARGET_POWERPC64
8484    && (gpc_reg_operand (operands[0], DImode)
8485        || gpc_reg_operand (operands[1], DImode))"
8486   "@
8487    #
8488    #
8489    #
8490    fmr %0,%1
8491    lfd%U1%X1 %0,%1
8492    stfd%U0%X0 %1,%0
8493    #"
8494   [(set_attr "type" "load,*,store,fp,fpload,fpstore,*")])
8495
8496 (define_split
8497   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8498         (match_operand:DI 1 "const_int_operand" ""))]
8499   "! TARGET_POWERPC64 && reload_completed"
8500   [(set (match_dup 2) (match_dup 4))
8501    (set (match_dup 3) (match_dup 1))]
8502   "
8503 {
8504   HOST_WIDE_INT value = INTVAL (operands[1]);
8505   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8506                                        DImode);
8507   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8508                                        DImode);
8509 #if HOST_BITS_PER_WIDE_INT == 32
8510   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8511 #else
8512   operands[4] = GEN_INT (value >> 32);
8513   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8514 #endif
8515 }")
8516
8517 (define_split
8518   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8519         (match_operand:DI 1 "input_operand" ""))]
8520   "reload_completed && !TARGET_POWERPC64
8521    && gpr_or_gpr_p (operands[0], operands[1])"
8522   [(pc)]
8523 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8524
8525 (define_insn "*movdi_internal64"
8526   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*f,*f,m,r,*h,*h")
8527         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,f,m,f,*h,r,0"))]
8528   "TARGET_POWERPC64
8529    && (gpc_reg_operand (operands[0], DImode)
8530        || gpc_reg_operand (operands[1], DImode))"
8531   "@
8532    mr %0,%1
8533    ld%U1%X1 %0,%1
8534    std%U0%X0 %1,%0
8535    li %0,%1
8536    lis %0,%v1
8537    #
8538    {cal|la} %0,%a1
8539    fmr %0,%1
8540    lfd%U1%X1 %0,%1
8541    stfd%U0%X0 %1,%0
8542    mf%1 %0
8543    mt%0 %1
8544    {cror 0,0,0|nop}"
8545   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
8546    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
8547
8548 ;; immediate value valid for a single instruction hiding in a const_double
8549 (define_insn ""
8550   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8551         (match_operand:DI 1 "const_double_operand" "F"))]
8552   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
8553    && GET_CODE (operands[1]) == CONST_DOUBLE
8554    && num_insns_constant (operands[1], DImode) == 1"
8555   "*
8556 {
8557   return ((unsigned HOST_WIDE_INT)
8558           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
8559          ? \"li %0,%1\" : \"lis %0,%v1\";
8560 }")
8561
8562 ;; Generate all one-bits and clear left or right.
8563 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
8564 (define_split
8565   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8566         (match_operand:DI 1 "mask64_operand" ""))]
8567   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8568   [(set (match_dup 0) (const_int -1))
8569    (set (match_dup 0)
8570         (and:DI (rotate:DI (match_dup 0)
8571                            (const_int 0))
8572                 (match_dup 1)))]
8573   "")
8574
8575 ;; Split a load of a large constant into the appropriate five-instruction
8576 ;; sequence.  Handle anything in a constant number of insns.
8577 ;; When non-easy constants can go in the TOC, this should use
8578 ;; easy_fp_constant predicate.
8579 (define_split
8580   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8581         (match_operand:DI 1 "const_int_operand" ""))]
8582   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8583   [(set (match_dup 0) (match_dup 2))
8584    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8585   "
8586 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8587
8588   if (tem == operands[0])
8589     DONE;
8590   else
8591     FAIL;
8592 }")
8593
8594 (define_split
8595   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8596         (match_operand:DI 1 "const_double_operand" ""))]
8597   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8598   [(set (match_dup 0) (match_dup 2))
8599    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8600   "
8601 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8602
8603   if (tem == operands[0])
8604     DONE;
8605   else
8606     FAIL;
8607 }")
8608 \f
8609 ;; TImode is similar, except that we usually want to compute the address into
8610 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
8611 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
8612
8613 ;; We say that MQ is clobbered in the last alternative because the first
8614 ;; alternative would never get used otherwise since it would need a reload
8615 ;; while the 2nd alternative would not.  We put memory cases first so they
8616 ;; are preferred.  Otherwise, we'd try to reload the output instead of
8617 ;; giving the SCRATCH mq.
8618
8619 (define_insn "*movti_power"
8620   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r,r")
8621         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))
8622    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X,X"))]
8623   "TARGET_POWER && ! TARGET_POWERPC64
8624    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8625   "*
8626 {
8627   switch (which_alternative)
8628     {
8629     default:
8630       gcc_unreachable ();
8631
8632     case 0:
8633       if (TARGET_STRING)
8634         return \"{stsi|stswi} %1,%P0,16\";
8635     case 1:
8636     case 2:
8637       return \"#\";
8638     case 3:
8639       /* If the address is not used in the output, we can use lsi.  Otherwise,
8640          fall through to generating four loads.  */
8641       if (TARGET_STRING
8642           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8643         return \"{lsi|lswi} %0,%P1,16\";
8644       /* ... fall through ...  */
8645     case 4:
8646     case 5:
8647       return \"#\";
8648     }
8649 }"
8650   [(set_attr "type" "store,store,*,load,load,*")])
8651
8652 (define_insn "*movti_string"
8653   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,o<>,????r,????r,????r,r")
8654         (match_operand:TI 1 "input_operand" "r,r,r,Q,m,n"))]
8655   "! TARGET_POWER && ! TARGET_POWERPC64
8656    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8657   "*
8658 {
8659   switch (which_alternative)
8660     {
8661     default:
8662       gcc_unreachable ();
8663     case 0:
8664       if (TARGET_STRING)
8665         return \"{stsi|stswi} %1,%P0,16\";
8666     case 1:
8667     case 2:
8668       return \"#\";
8669     case 3:
8670       /* If the address is not used in the output, we can use lsi.  Otherwise,
8671          fall through to generating four loads.  */
8672       if (TARGET_STRING
8673           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8674         return \"{lsi|lswi} %0,%P1,16\";
8675       /* ... fall through ...  */
8676     case 4:
8677     case 5:
8678       return \"#\";
8679     }
8680 }"
8681   [(set_attr "type" "store_ux,store_ux,*,load_ux,load_ux,*")])
8682
8683 (define_insn "*movti_ppc64"
8684   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,o<>,r")
8685         (match_operand:TI 1 "input_operand" "r,r,m"))]
8686   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
8687    || gpc_reg_operand (operands[1], TImode))"
8688   "#"
8689   [(set_attr "type" "*,load,store")])
8690
8691 (define_split
8692   [(set (match_operand:TI 0 "gpc_reg_operand" "")
8693         (match_operand:TI 1 "const_double_operand" ""))]
8694   "TARGET_POWERPC64"
8695   [(set (match_dup 2) (match_dup 4))
8696    (set (match_dup 3) (match_dup 5))]
8697   "
8698 {
8699   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8700                                        TImode);
8701   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8702                                        TImode);
8703   if (GET_CODE (operands[1]) == CONST_DOUBLE)
8704     {
8705       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8706       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
8707     }
8708   else if (GET_CODE (operands[1]) == CONST_INT)
8709     {
8710       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
8711       operands[5] = operands[1];
8712     }
8713   else
8714     FAIL;
8715 }")
8716
8717 (define_split
8718   [(set (match_operand:TI 0 "nonimmediate_operand" "")
8719         (match_operand:TI 1 "input_operand" ""))]
8720   "reload_completed
8721    && gpr_or_gpr_p (operands[0], operands[1])"
8722   [(pc)]
8723 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8724 \f
8725 (define_expand "load_multiple"
8726   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8727                           (match_operand:SI 1 "" ""))
8728                      (use (match_operand:SI 2 "" ""))])]
8729   "TARGET_STRING && !TARGET_POWERPC64"
8730   "
8731 {
8732   int regno;
8733   int count;
8734   rtx op1;
8735   int i;
8736
8737   /* Support only loading a constant number of fixed-point registers from
8738      memory and only bother with this if more than two; the machine
8739      doesn't support more than eight.  */
8740   if (GET_CODE (operands[2]) != CONST_INT
8741       || INTVAL (operands[2]) <= 2
8742       || INTVAL (operands[2]) > 8
8743       || GET_CODE (operands[1]) != MEM
8744       || GET_CODE (operands[0]) != REG
8745       || REGNO (operands[0]) >= 32)
8746     FAIL;
8747
8748   count = INTVAL (operands[2]);
8749   regno = REGNO (operands[0]);
8750
8751   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
8752   op1 = replace_equiv_address (operands[1],
8753                                force_reg (SImode, XEXP (operands[1], 0)));
8754
8755   for (i = 0; i < count; i++)
8756     XVECEXP (operands[3], 0, i)
8757       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
8758                      adjust_address_nv (op1, SImode, i * 4));
8759 }")
8760
8761 (define_insn "*ldmsi8"
8762   [(match_parallel 0 "load_multiple_operation"
8763     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8764           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8765      (set (match_operand:SI 3 "gpc_reg_operand" "")
8766           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8767      (set (match_operand:SI 4 "gpc_reg_operand" "")
8768           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8769      (set (match_operand:SI 5 "gpc_reg_operand" "")
8770           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8771      (set (match_operand:SI 6 "gpc_reg_operand" "")
8772           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8773      (set (match_operand:SI 7 "gpc_reg_operand" "")
8774           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8775      (set (match_operand:SI 8 "gpc_reg_operand" "")
8776           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
8777      (set (match_operand:SI 9 "gpc_reg_operand" "")
8778           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
8779   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
8780   "*
8781 { return rs6000_output_load_multiple (operands); }"
8782   [(set_attr "type" "load_ux")
8783    (set_attr "length" "32")])
8784
8785 (define_insn "*ldmsi7"
8786   [(match_parallel 0 "load_multiple_operation"
8787     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8788           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8789      (set (match_operand:SI 3 "gpc_reg_operand" "")
8790           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8791      (set (match_operand:SI 4 "gpc_reg_operand" "")
8792           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8793      (set (match_operand:SI 5 "gpc_reg_operand" "")
8794           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8795      (set (match_operand:SI 6 "gpc_reg_operand" "")
8796           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8797      (set (match_operand:SI 7 "gpc_reg_operand" "")
8798           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8799      (set (match_operand:SI 8 "gpc_reg_operand" "")
8800           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
8801   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
8802   "*
8803 { return rs6000_output_load_multiple (operands); }"
8804   [(set_attr "type" "load_ux")
8805    (set_attr "length" "32")])
8806
8807 (define_insn "*ldmsi6"
8808   [(match_parallel 0 "load_multiple_operation"
8809     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8810           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8811      (set (match_operand:SI 3 "gpc_reg_operand" "")
8812           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8813      (set (match_operand:SI 4 "gpc_reg_operand" "")
8814           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8815      (set (match_operand:SI 5 "gpc_reg_operand" "")
8816           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8817      (set (match_operand:SI 6 "gpc_reg_operand" "")
8818           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8819      (set (match_operand:SI 7 "gpc_reg_operand" "")
8820           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
8821   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
8822   "*
8823 { return rs6000_output_load_multiple (operands); }"
8824   [(set_attr "type" "load_ux")
8825    (set_attr "length" "32")])
8826
8827 (define_insn "*ldmsi5"
8828   [(match_parallel 0 "load_multiple_operation"
8829     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8830           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8831      (set (match_operand:SI 3 "gpc_reg_operand" "")
8832           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8833      (set (match_operand:SI 4 "gpc_reg_operand" "")
8834           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8835      (set (match_operand:SI 5 "gpc_reg_operand" "")
8836           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8837      (set (match_operand:SI 6 "gpc_reg_operand" "")
8838           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
8839   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
8840   "*
8841 { return rs6000_output_load_multiple (operands); }"
8842   [(set_attr "type" "load_ux")
8843    (set_attr "length" "32")])
8844
8845 (define_insn "*ldmsi4"
8846   [(match_parallel 0 "load_multiple_operation"
8847     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8848           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8849      (set (match_operand:SI 3 "gpc_reg_operand" "")
8850           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8851      (set (match_operand:SI 4 "gpc_reg_operand" "")
8852           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8853      (set (match_operand:SI 5 "gpc_reg_operand" "")
8854           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
8855   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
8856   "*
8857 { return rs6000_output_load_multiple (operands); }"
8858   [(set_attr "type" "load_ux")
8859    (set_attr "length" "32")])
8860
8861 (define_insn "*ldmsi3"
8862   [(match_parallel 0 "load_multiple_operation"
8863     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8864           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8865      (set (match_operand:SI 3 "gpc_reg_operand" "")
8866           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8867      (set (match_operand:SI 4 "gpc_reg_operand" "")
8868           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
8869   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
8870   "*
8871 { return rs6000_output_load_multiple (operands); }"
8872   [(set_attr "type" "load_ux")
8873    (set_attr "length" "32")])
8874
8875 (define_expand "store_multiple"
8876   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8877                           (match_operand:SI 1 "" ""))
8878                      (clobber (scratch:SI))
8879                      (use (match_operand:SI 2 "" ""))])]
8880   "TARGET_STRING && !TARGET_POWERPC64"
8881   "
8882 {
8883   int regno;
8884   int count;
8885   rtx to;
8886   rtx op0;
8887   int i;
8888
8889   /* Support only storing a constant number of fixed-point registers to
8890      memory and only bother with this if more than two; the machine
8891      doesn't support more than eight.  */
8892   if (GET_CODE (operands[2]) != CONST_INT
8893       || INTVAL (operands[2]) <= 2
8894       || INTVAL (operands[2]) > 8
8895       || GET_CODE (operands[0]) != MEM
8896       || GET_CODE (operands[1]) != REG
8897       || REGNO (operands[1]) >= 32)
8898     FAIL;
8899
8900   count = INTVAL (operands[2]);
8901   regno = REGNO (operands[1]);
8902
8903   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
8904   to = force_reg (SImode, XEXP (operands[0], 0));
8905   op0 = replace_equiv_address (operands[0], to);
8906
8907   XVECEXP (operands[3], 0, 0)
8908     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
8909   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
8910                                                  gen_rtx_SCRATCH (SImode));
8911
8912   for (i = 1; i < count; i++)
8913     XVECEXP (operands[3], 0, i + 1)
8914       = gen_rtx_SET (VOIDmode,
8915                      adjust_address_nv (op0, SImode, i * 4),
8916                      gen_rtx_REG (SImode, regno + i));
8917 }")
8918
8919 (define_insn "*store_multiple_power"
8920   [(match_parallel 0 "store_multiple_operation"
8921                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
8922                          (match_operand:SI 2 "gpc_reg_operand" "r"))
8923                     (clobber (match_scratch:SI 3 "=q"))])]
8924   "TARGET_STRING && TARGET_POWER"
8925   "{stsi|stswi} %2,%P1,%O0"
8926   [(set_attr "type" "store")])
8927
8928 (define_insn "*stmsi8"
8929   [(match_parallel 0 "store_multiple_operation"
8930     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8931           (match_operand:SI 2 "gpc_reg_operand" "r"))
8932      (clobber (match_scratch:SI 3 "X"))
8933      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8934           (match_operand:SI 4 "gpc_reg_operand" "r"))
8935      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8936           (match_operand:SI 5 "gpc_reg_operand" "r"))
8937      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8938           (match_operand:SI 6 "gpc_reg_operand" "r"))
8939      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8940           (match_operand:SI 7 "gpc_reg_operand" "r"))
8941      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8942           (match_operand:SI 8 "gpc_reg_operand" "r"))
8943      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8944           (match_operand:SI 9 "gpc_reg_operand" "r"))
8945      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
8946           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
8947   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
8948   "{stsi|stswi} %2,%1,%O0"
8949   [(set_attr "type" "store_ux")])
8950
8951 (define_insn "*stmsi7"
8952   [(match_parallel 0 "store_multiple_operation"
8953     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8954           (match_operand:SI 2 "gpc_reg_operand" "r"))
8955      (clobber (match_scratch:SI 3 "X"))
8956      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8957           (match_operand:SI 4 "gpc_reg_operand" "r"))
8958      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8959           (match_operand:SI 5 "gpc_reg_operand" "r"))
8960      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8961           (match_operand:SI 6 "gpc_reg_operand" "r"))
8962      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8963           (match_operand:SI 7 "gpc_reg_operand" "r"))
8964      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8965           (match_operand:SI 8 "gpc_reg_operand" "r"))
8966      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8967           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
8968   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
8969   "{stsi|stswi} %2,%1,%O0"
8970   [(set_attr "type" "store_ux")])
8971
8972 (define_insn "*stmsi6"
8973   [(match_parallel 0 "store_multiple_operation"
8974     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8975           (match_operand:SI 2 "gpc_reg_operand" "r"))
8976      (clobber (match_scratch:SI 3 "X"))
8977      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8978           (match_operand:SI 4 "gpc_reg_operand" "r"))
8979      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8980           (match_operand:SI 5 "gpc_reg_operand" "r"))
8981      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8982           (match_operand:SI 6 "gpc_reg_operand" "r"))
8983      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8984           (match_operand:SI 7 "gpc_reg_operand" "r"))
8985      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8986           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
8987   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
8988   "{stsi|stswi} %2,%1,%O0"
8989   [(set_attr "type" "store_ux")])
8990
8991 (define_insn "*stmsi5"
8992   [(match_parallel 0 "store_multiple_operation"
8993     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8994           (match_operand:SI 2 "gpc_reg_operand" "r"))
8995      (clobber (match_scratch:SI 3 "X"))
8996      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8997           (match_operand:SI 4 "gpc_reg_operand" "r"))
8998      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8999           (match_operand:SI 5 "gpc_reg_operand" "r"))
9000      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9001           (match_operand:SI 6 "gpc_reg_operand" "r"))
9002      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9003           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
9004   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
9005   "{stsi|stswi} %2,%1,%O0"
9006   [(set_attr "type" "store_ux")])
9007
9008 (define_insn "*stmsi4"
9009   [(match_parallel 0 "store_multiple_operation"
9010     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9011           (match_operand:SI 2 "gpc_reg_operand" "r"))
9012      (clobber (match_scratch:SI 3 "X"))
9013      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9014           (match_operand:SI 4 "gpc_reg_operand" "r"))
9015      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9016           (match_operand:SI 5 "gpc_reg_operand" "r"))
9017      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9018           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9019   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
9020   "{stsi|stswi} %2,%1,%O0"
9021   [(set_attr "type" "store_ux")])
9022
9023 (define_insn "*stmsi3"
9024   [(match_parallel 0 "store_multiple_operation"
9025     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9026           (match_operand:SI 2 "gpc_reg_operand" "r"))
9027      (clobber (match_scratch:SI 3 "X"))
9028      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9029           (match_operand:SI 4 "gpc_reg_operand" "r"))
9030      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9031           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9032   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
9033   "{stsi|stswi} %2,%1,%O0"
9034   [(set_attr "type" "store_ux")])
9035 \f
9036 (define_expand "setmemsi"
9037   [(parallel [(set (match_operand:BLK 0 "" "")
9038                    (match_operand 2 "const_int_operand" ""))
9039               (use (match_operand:SI 1 "" ""))
9040               (use (match_operand:SI 3 "" ""))])]
9041   ""
9042   "
9043 {
9044   /* If value to set is not zero, use the library routine.  */
9045   if (operands[2] != const0_rtx)
9046     FAIL;
9047
9048   if (expand_block_clear (operands))
9049     DONE;
9050   else
9051     FAIL;
9052 }")
9053
9054 ;; String/block move insn.
9055 ;; Argument 0 is the destination
9056 ;; Argument 1 is the source
9057 ;; Argument 2 is the length
9058 ;; Argument 3 is the alignment
9059
9060 (define_expand "movmemsi"
9061   [(parallel [(set (match_operand:BLK 0 "" "")
9062                    (match_operand:BLK 1 "" ""))
9063               (use (match_operand:SI 2 "" ""))
9064               (use (match_operand:SI 3 "" ""))])]
9065   ""
9066   "
9067 {
9068   if (expand_block_move (operands))
9069     DONE;
9070   else
9071     FAIL;
9072 }")
9073
9074 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
9075 ;; register allocator doesn't have a clue about allocating 8 word registers.
9076 ;; rD/rS = r5 is preferred, efficient form.
9077 (define_expand "movmemsi_8reg"
9078   [(parallel [(set (match_operand 0 "" "")
9079                    (match_operand 1 "" ""))
9080               (use (match_operand 2 "" ""))
9081               (use (match_operand 3 "" ""))
9082               (clobber (reg:SI  5))
9083               (clobber (reg:SI  6))
9084               (clobber (reg:SI  7))
9085               (clobber (reg:SI  8))
9086               (clobber (reg:SI  9))
9087               (clobber (reg:SI 10))
9088               (clobber (reg:SI 11))
9089               (clobber (reg:SI 12))
9090               (clobber (match_scratch:SI 4 ""))])]
9091   "TARGET_STRING"
9092   "")
9093
9094 (define_insn ""
9095   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9096         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9097    (use (match_operand:SI 2 "immediate_operand" "i"))
9098    (use (match_operand:SI 3 "immediate_operand" "i"))
9099    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9100    (clobber (reg:SI  6))
9101    (clobber (reg:SI  7))
9102    (clobber (reg:SI  8))
9103    (clobber (reg:SI  9))
9104    (clobber (reg:SI 10))
9105    (clobber (reg:SI 11))
9106    (clobber (reg:SI 12))
9107    (clobber (match_scratch:SI 5 "=q"))]
9108   "TARGET_STRING && TARGET_POWER
9109    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9110        || INTVAL (operands[2]) == 0)
9111    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9112    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9113    && REGNO (operands[4]) == 5"
9114   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9115   [(set_attr "type" "store_ux")
9116    (set_attr "length" "8")])
9117
9118 (define_insn ""
9119   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9120         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9121    (use (match_operand:SI 2 "immediate_operand" "i"))
9122    (use (match_operand:SI 3 "immediate_operand" "i"))
9123    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9124    (clobber (reg:SI  6))
9125    (clobber (reg:SI  7))
9126    (clobber (reg:SI  8))
9127    (clobber (reg:SI  9))
9128    (clobber (reg:SI 10))
9129    (clobber (reg:SI 11))
9130    (clobber (reg:SI 12))
9131    (clobber (match_scratch:SI 5 "X"))]
9132   "TARGET_STRING && ! TARGET_POWER
9133    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9134        || INTVAL (operands[2]) == 0)
9135    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9136    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9137    && REGNO (operands[4]) == 5"
9138   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9139   [(set_attr "type" "store_ux")
9140    (set_attr "length" "8")])
9141
9142 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
9143 ;; register allocator doesn't have a clue about allocating 6 word registers.
9144 ;; rD/rS = r5 is preferred, efficient form.
9145 (define_expand "movmemsi_6reg"
9146   [(parallel [(set (match_operand 0 "" "")
9147                    (match_operand 1 "" ""))
9148               (use (match_operand 2 "" ""))
9149               (use (match_operand 3 "" ""))
9150               (clobber (reg:SI  5))
9151               (clobber (reg:SI  6))
9152               (clobber (reg:SI  7))
9153               (clobber (reg:SI  8))
9154               (clobber (reg:SI  9))
9155               (clobber (reg:SI 10))
9156               (clobber (match_scratch:SI 4 ""))])]
9157   "TARGET_STRING"
9158   "")
9159
9160 (define_insn ""
9161   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9162         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9163    (use (match_operand:SI 2 "immediate_operand" "i"))
9164    (use (match_operand:SI 3 "immediate_operand" "i"))
9165    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9166    (clobber (reg:SI  6))
9167    (clobber (reg:SI  7))
9168    (clobber (reg:SI  8))
9169    (clobber (reg:SI  9))
9170    (clobber (reg:SI 10))
9171    (clobber (match_scratch:SI 5 "=q"))]
9172   "TARGET_STRING && TARGET_POWER
9173    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
9174    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9175    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9176    && REGNO (operands[4]) == 5"
9177   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9178   [(set_attr "type" "store_ux")
9179    (set_attr "length" "8")])
9180
9181 (define_insn ""
9182   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9183         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9184    (use (match_operand:SI 2 "immediate_operand" "i"))
9185    (use (match_operand:SI 3 "immediate_operand" "i"))
9186    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9187    (clobber (reg:SI  6))
9188    (clobber (reg:SI  7))
9189    (clobber (reg:SI  8))
9190    (clobber (reg:SI  9))
9191    (clobber (reg:SI 10))
9192    (clobber (match_scratch:SI 5 "X"))]
9193   "TARGET_STRING && ! TARGET_POWER
9194    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9195    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9196    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9197    && REGNO (operands[4]) == 5"
9198   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9199   [(set_attr "type" "store_ux")
9200    (set_attr "length" "8")])
9201
9202 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
9203 ;; problems with TImode.
9204 ;; rD/rS = r5 is preferred, efficient form.
9205 (define_expand "movmemsi_4reg"
9206   [(parallel [(set (match_operand 0 "" "")
9207                    (match_operand 1 "" ""))
9208               (use (match_operand 2 "" ""))
9209               (use (match_operand 3 "" ""))
9210               (clobber (reg:SI 5))
9211               (clobber (reg:SI 6))
9212               (clobber (reg:SI 7))
9213               (clobber (reg:SI 8))
9214               (clobber (match_scratch:SI 4 ""))])]
9215   "TARGET_STRING"
9216   "")
9217
9218 (define_insn ""
9219   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9220         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9221    (use (match_operand:SI 2 "immediate_operand" "i"))
9222    (use (match_operand:SI 3 "immediate_operand" "i"))
9223    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9224    (clobber (reg:SI 6))
9225    (clobber (reg:SI 7))
9226    (clobber (reg:SI 8))
9227    (clobber (match_scratch:SI 5 "=q"))]
9228   "TARGET_STRING && TARGET_POWER
9229    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9230    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9231    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9232    && REGNO (operands[4]) == 5"
9233   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9234   [(set_attr "type" "store_ux")
9235    (set_attr "length" "8")])
9236
9237 (define_insn ""
9238   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9239         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9240    (use (match_operand:SI 2 "immediate_operand" "i"))
9241    (use (match_operand:SI 3 "immediate_operand" "i"))
9242    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9243    (clobber (reg:SI 6))
9244    (clobber (reg:SI 7))
9245    (clobber (reg:SI 8))
9246    (clobber (match_scratch:SI 5 "X"))]
9247   "TARGET_STRING && ! TARGET_POWER
9248    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9249    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9250    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9251    && REGNO (operands[4]) == 5"
9252   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9253   [(set_attr "type" "store_ux")
9254    (set_attr "length" "8")])
9255
9256 ;; Move up to 8 bytes at a time.
9257 (define_expand "movmemsi_2reg"
9258   [(parallel [(set (match_operand 0 "" "")
9259                    (match_operand 1 "" ""))
9260               (use (match_operand 2 "" ""))
9261               (use (match_operand 3 "" ""))
9262               (clobber (match_scratch:DI 4 ""))
9263               (clobber (match_scratch:SI 5 ""))])]
9264   "TARGET_STRING && ! TARGET_POWERPC64"
9265   "")
9266
9267 (define_insn ""
9268   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9269         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9270    (use (match_operand:SI 2 "immediate_operand" "i"))
9271    (use (match_operand:SI 3 "immediate_operand" "i"))
9272    (clobber (match_scratch:DI 4 "=&r"))
9273    (clobber (match_scratch:SI 5 "=q"))]
9274   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
9275    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9276   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9277   [(set_attr "type" "store_ux")
9278    (set_attr "length" "8")])
9279
9280 (define_insn ""
9281   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9282         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9283    (use (match_operand:SI 2 "immediate_operand" "i"))
9284    (use (match_operand:SI 3 "immediate_operand" "i"))
9285    (clobber (match_scratch:DI 4 "=&r"))
9286    (clobber (match_scratch:SI 5 "X"))]
9287   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
9288    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9289   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9290   [(set_attr "type" "store_ux")
9291    (set_attr "length" "8")])
9292
9293 ;; Move up to 4 bytes at a time.
9294 (define_expand "movmemsi_1reg"
9295   [(parallel [(set (match_operand 0 "" "")
9296                    (match_operand 1 "" ""))
9297               (use (match_operand 2 "" ""))
9298               (use (match_operand 3 "" ""))
9299               (clobber (match_scratch:SI 4 ""))
9300               (clobber (match_scratch:SI 5 ""))])]
9301   "TARGET_STRING"
9302   "")
9303
9304 (define_insn ""
9305   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9306         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9307    (use (match_operand:SI 2 "immediate_operand" "i"))
9308    (use (match_operand:SI 3 "immediate_operand" "i"))
9309    (clobber (match_scratch:SI 4 "=&r"))
9310    (clobber (match_scratch:SI 5 "=q"))]
9311   "TARGET_STRING && TARGET_POWER
9312    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9313   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9314   [(set_attr "type" "store_ux")
9315    (set_attr "length" "8")])
9316
9317 (define_insn ""
9318   [(set (mem:BLK (match_operand:P 0 "gpc_reg_operand" "b"))
9319         (mem:BLK (match_operand:P 1 "gpc_reg_operand" "b")))
9320    (use (match_operand:SI 2 "immediate_operand" "i"))
9321    (use (match_operand:SI 3 "immediate_operand" "i"))
9322    (clobber (match_scratch:SI 4 "=&r"))
9323    (clobber (match_scratch:SI 5 "X"))]
9324   "TARGET_STRING && ! TARGET_POWER
9325    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9326   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9327   [(set_attr "type" "store_ux")
9328    (set_attr "length" "8")])
9329 \f
9330 ;; Define insns that do load or store with update.  Some of these we can
9331 ;; get by using pre-decrement or pre-increment, but the hardware can also
9332 ;; do cases where the increment is not the size of the object.
9333 ;;
9334 ;; In all these cases, we use operands 0 and 1 for the register being
9335 ;; incremented because those are the operands that local-alloc will
9336 ;; tie and these are the pair most likely to be tieable (and the ones
9337 ;; that will benefit the most).
9338
9339 (define_insn "*movdi_update1"
9340   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9341         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9342                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
9343    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9344         (plus:DI (match_dup 1) (match_dup 2)))]
9345   "TARGET_POWERPC64 && TARGET_UPDATE"
9346   "@
9347    ldux %3,%0,%2
9348    ldu %3,%2(%0)"
9349   [(set_attr "type" "load_ux,load_u")])
9350
9351 (define_insn "movdi_<mode>_update"
9352   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
9353                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
9354         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9355    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
9356         (plus:P (match_dup 1) (match_dup 2)))]
9357   "TARGET_POWERPC64 && TARGET_UPDATE"
9358   "@
9359    stdux %3,%0,%2
9360    stdu %3,%2(%0)"
9361   [(set_attr "type" "store_ux,store_u")])
9362
9363 (define_insn "*movsi_update1"
9364   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9365         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9366                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9367    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9368         (plus:SI (match_dup 1) (match_dup 2)))]
9369   "TARGET_UPDATE"
9370   "@
9371    {lux|lwzux} %3,%0,%2
9372    {lu|lwzu} %3,%2(%0)"
9373   [(set_attr "type" "load_ux,load_u")])
9374
9375 (define_insn "*movsi_update2"
9376   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9377         (sign_extend:DI
9378          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9379                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9380    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9381         (plus:DI (match_dup 1) (match_dup 2)))]
9382   "TARGET_POWERPC64"
9383   "lwaux %3,%0,%2"
9384   [(set_attr "type" "load_ext_ux")])
9385
9386 (define_insn "movsi_update"
9387   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9388                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9389         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9390    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9391         (plus:SI (match_dup 1) (match_dup 2)))]
9392   "TARGET_UPDATE"
9393   "@
9394    {stux|stwux} %3,%0,%2
9395    {stu|stwu} %3,%2(%0)"
9396   [(set_attr "type" "store_ux,store_u")])
9397
9398 (define_insn "*movhi_update1"
9399   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9400         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9401                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9402    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9403         (plus:SI (match_dup 1) (match_dup 2)))]
9404   "TARGET_UPDATE"
9405   "@
9406    lhzux %3,%0,%2
9407    lhzu %3,%2(%0)"
9408   [(set_attr "type" "load_ux,load_u")])
9409
9410 (define_insn "*movhi_update2"
9411   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9412         (zero_extend:SI
9413          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9414                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9415    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9416         (plus:SI (match_dup 1) (match_dup 2)))]
9417   "TARGET_UPDATE"
9418   "@
9419    lhzux %3,%0,%2
9420    lhzu %3,%2(%0)"
9421   [(set_attr "type" "load_ux,load_u")])
9422
9423 (define_insn "*movhi_update3"
9424   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9425         (sign_extend:SI
9426          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9427                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9428    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9429         (plus:SI (match_dup 1) (match_dup 2)))]
9430   "TARGET_UPDATE"
9431   "@
9432    lhaux %3,%0,%2
9433    lhau %3,%2(%0)"
9434   [(set_attr "type" "load_ext_ux,load_ext_u")])
9435
9436 (define_insn "*movhi_update4"
9437   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9438                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9439         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
9440    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9441         (plus:SI (match_dup 1) (match_dup 2)))]
9442   "TARGET_UPDATE"
9443   "@
9444    sthux %3,%0,%2
9445    sthu %3,%2(%0)"
9446   [(set_attr "type" "store_ux,store_u")])
9447
9448 (define_insn "*movqi_update1"
9449   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
9450         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9451                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9452    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9453         (plus:SI (match_dup 1) (match_dup 2)))]
9454   "TARGET_UPDATE"
9455   "@
9456    lbzux %3,%0,%2
9457    lbzu %3,%2(%0)"
9458   [(set_attr "type" "load_ux,load_u")])
9459
9460 (define_insn "*movqi_update2"
9461   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9462         (zero_extend:SI
9463          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9464                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9465    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9466         (plus:SI (match_dup 1) (match_dup 2)))]
9467   "TARGET_UPDATE"
9468   "@
9469    lbzux %3,%0,%2
9470    lbzu %3,%2(%0)"
9471   [(set_attr "type" "load_ux,load_u")])
9472
9473 (define_insn "*movqi_update3"
9474   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9475                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9476         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
9477    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9478         (plus:SI (match_dup 1) (match_dup 2)))]
9479   "TARGET_UPDATE"
9480   "@
9481    stbux %3,%0,%2
9482    stbu %3,%2(%0)"
9483   [(set_attr "type" "store_ux,store_u")])
9484
9485 (define_insn "*movsf_update1"
9486   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
9487         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9488                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9489    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9490         (plus:SI (match_dup 1) (match_dup 2)))]
9491   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9492   "@
9493    lfsux %3,%0,%2
9494    lfsu %3,%2(%0)"
9495   [(set_attr "type" "fpload_ux,fpload_u")])
9496
9497 (define_insn "*movsf_update2"
9498   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9499                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9500         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
9501    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9502         (plus:SI (match_dup 1) (match_dup 2)))]
9503   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9504   "@
9505    stfsux %3,%0,%2
9506    stfsu %3,%2(%0)"
9507   [(set_attr "type" "fpstore_ux,fpstore_u")])
9508
9509 (define_insn "*movsf_update3"
9510   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
9511         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9512                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9513    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9514         (plus:SI (match_dup 1) (match_dup 2)))]
9515   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9516   "@
9517    {lux|lwzux} %3,%0,%2
9518    {lu|lwzu} %3,%2(%0)"
9519   [(set_attr "type" "load_ux,load_u")])
9520
9521 (define_insn "*movsf_update4"
9522   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9523                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9524         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
9525    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9526         (plus:SI (match_dup 1) (match_dup 2)))]
9527   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9528   "@
9529    {stux|stwux} %3,%0,%2
9530    {stu|stwu} %3,%2(%0)"
9531   [(set_attr "type" "store_ux,store_u")])
9532
9533 (define_insn "*movdf_update1"
9534   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
9535         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9536                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9537    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9538         (plus:SI (match_dup 1) (match_dup 2)))]
9539   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9540   "@
9541    lfdux %3,%0,%2
9542    lfdu %3,%2(%0)"
9543   [(set_attr "type" "fpload_ux,fpload_u")])
9544
9545 (define_insn "*movdf_update2"
9546   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9547                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9548         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
9549    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9550         (plus:SI (match_dup 1) (match_dup 2)))]
9551   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9552   "@
9553    stfdux %3,%0,%2
9554    stfdu %3,%2(%0)"
9555   [(set_attr "type" "fpstore_ux,fpstore_u")])
9556
9557 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
9558
9559 (define_insn "*lfq_power2"
9560   [(set (match_operand:V2DF 0 "gpc_reg_operand" "=f")
9561         (match_operand:V2DF 1 "memory_operand" ""))]
9562   "TARGET_POWER2
9563    && TARGET_HARD_FLOAT && TARGET_FPRS"
9564   "lfq%U1%X1 %0,%1")
9565
9566 (define_peephole2
9567   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9568         (match_operand:DF 1 "memory_operand" ""))
9569    (set (match_operand:DF 2 "gpc_reg_operand" "")
9570         (match_operand:DF 3 "memory_operand" ""))]
9571   "TARGET_POWER2
9572    && TARGET_HARD_FLOAT && TARGET_FPRS
9573    && registers_ok_for_quad_peep (operands[0], operands[2])
9574    && mems_ok_for_quad_peep (operands[1], operands[3])"
9575   [(set (match_dup 0)
9576         (match_dup 1))]
9577   "operands[1] = widen_memory_access (operands[1], V2DFmode, 0);
9578    operands[0] = gen_rtx_REG (V2DFmode, REGNO (operands[0]));")
9579
9580 (define_insn "*stfq_power2"
9581   [(set (match_operand:V2DF 0 "memory_operand" "")
9582         (match_operand:V2DF 1 "gpc_reg_operand" "f"))]
9583   "TARGET_POWER2
9584    && TARGET_HARD_FLOAT && TARGET_FPRS"
9585   "stfq%U0%X0 %1,%0")
9586
9587
9588 (define_peephole2
9589   [(set (match_operand:DF 0 "memory_operand" "")
9590         (match_operand:DF 1 "gpc_reg_operand" ""))
9591    (set (match_operand:DF 2 "memory_operand" "")
9592         (match_operand:DF 3 "gpc_reg_operand" ""))]
9593   "TARGET_POWER2
9594    && TARGET_HARD_FLOAT && TARGET_FPRS
9595    && registers_ok_for_quad_peep (operands[1], operands[3])
9596    && mems_ok_for_quad_peep (operands[0], operands[2])"
9597   [(set (match_dup 0)
9598         (match_dup 1))]
9599   "operands[0] = widen_memory_access (operands[0], V2DFmode, 0);
9600    operands[1] = gen_rtx_REG (V2DFmode, REGNO (operands[1]));")
9601
9602 ;; after inserting conditional returns we can sometimes have
9603 ;; unnecessary register moves.  Unfortunately we cannot have a
9604 ;; modeless peephole here, because some single SImode sets have early
9605 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
9606 ;; sequences, using get_attr_length here will smash the operands
9607 ;; array.  Neither is there an early_cobbler_p predicate.
9608 (define_peephole2
9609   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9610         (match_operand:DF 1 "any_operand" ""))
9611    (set (match_operand:DF 2 "gpc_reg_operand" "")
9612         (match_dup 0))]
9613   "peep2_reg_dead_p (2, operands[0])"
9614   [(set (match_dup 2) (match_dup 1))])
9615
9616 (define_peephole2
9617   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9618         (match_operand:SF 1 "any_operand" ""))
9619    (set (match_operand:SF 2 "gpc_reg_operand" "")
9620         (match_dup 0))]
9621   "peep2_reg_dead_p (2, operands[0])"
9622   [(set (match_dup 2) (match_dup 1))])
9623
9624 \f
9625 ;; TLS support.
9626
9627 ;; "b" output constraint here and on tls_ld to support tls linker optimization.
9628 (define_insn "tls_gd_32"
9629   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9630         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9631                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9632                    UNSPEC_TLSGD))]
9633   "HAVE_AS_TLS && !TARGET_64BIT"
9634   "addi %0,%1,%2@got@tlsgd")
9635
9636 (define_insn "tls_gd_64"
9637   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9638         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9639                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9640                    UNSPEC_TLSGD))]
9641   "HAVE_AS_TLS && TARGET_64BIT"
9642   "addi %0,%1,%2@got@tlsgd")
9643
9644 (define_insn "tls_ld_32"
9645   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9646         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")]
9647                    UNSPEC_TLSLD))]
9648   "HAVE_AS_TLS && !TARGET_64BIT"
9649   "addi %0,%1,%&@got@tlsld")
9650
9651 (define_insn "tls_ld_64"
9652   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9653         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")]
9654                    UNSPEC_TLSLD))]
9655   "HAVE_AS_TLS && TARGET_64BIT"
9656   "addi %0,%1,%&@got@tlsld")
9657
9658 (define_insn "tls_dtprel_32"
9659   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9660         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9661                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9662                    UNSPEC_TLSDTPREL))]
9663   "HAVE_AS_TLS && !TARGET_64BIT"
9664   "addi %0,%1,%2@dtprel")
9665
9666 (define_insn "tls_dtprel_64"
9667   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9668         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9669                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9670                    UNSPEC_TLSDTPREL))]
9671   "HAVE_AS_TLS && TARGET_64BIT"
9672   "addi %0,%1,%2@dtprel")
9673
9674 (define_insn "tls_dtprel_ha_32"
9675   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9676         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9677                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9678                    UNSPEC_TLSDTPRELHA))]
9679   "HAVE_AS_TLS && !TARGET_64BIT"
9680   "addis %0,%1,%2@dtprel@ha")
9681
9682 (define_insn "tls_dtprel_ha_64"
9683   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9684         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9685                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9686                    UNSPEC_TLSDTPRELHA))]
9687   "HAVE_AS_TLS && TARGET_64BIT"
9688   "addis %0,%1,%2@dtprel@ha")
9689
9690 (define_insn "tls_dtprel_lo_32"
9691   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9692         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9693                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9694                    UNSPEC_TLSDTPRELLO))]
9695   "HAVE_AS_TLS && !TARGET_64BIT"
9696   "addi %0,%1,%2@dtprel@l")
9697
9698 (define_insn "tls_dtprel_lo_64"
9699   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9700         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9701                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9702                    UNSPEC_TLSDTPRELLO))]
9703   "HAVE_AS_TLS && TARGET_64BIT"
9704   "addi %0,%1,%2@dtprel@l")
9705
9706 (define_insn "tls_got_dtprel_32"
9707   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9708         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9709                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9710                    UNSPEC_TLSGOTDTPREL))]
9711   "HAVE_AS_TLS && !TARGET_64BIT"
9712   "lwz %0,%2@got@dtprel(%1)")
9713
9714 (define_insn "tls_got_dtprel_64"
9715   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9716         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9717                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9718                    UNSPEC_TLSGOTDTPREL))]
9719   "HAVE_AS_TLS && TARGET_64BIT"
9720   "ld %0,%2@got@dtprel(%1)")
9721
9722 (define_insn "tls_tprel_32"
9723   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9724         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9725                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9726                    UNSPEC_TLSTPREL))]
9727   "HAVE_AS_TLS && !TARGET_64BIT"
9728   "addi %0,%1,%2@tprel")
9729
9730 (define_insn "tls_tprel_64"
9731   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9732         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9733                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9734                    UNSPEC_TLSTPREL))]
9735   "HAVE_AS_TLS && TARGET_64BIT"
9736   "addi %0,%1,%2@tprel")
9737
9738 (define_insn "tls_tprel_ha_32"
9739   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9740         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9741                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9742                    UNSPEC_TLSTPRELHA))]
9743   "HAVE_AS_TLS && !TARGET_64BIT"
9744   "addis %0,%1,%2@tprel@ha")
9745
9746 (define_insn "tls_tprel_ha_64"
9747   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9748         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9749                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9750                    UNSPEC_TLSTPRELHA))]
9751   "HAVE_AS_TLS && TARGET_64BIT"
9752   "addis %0,%1,%2@tprel@ha")
9753
9754 (define_insn "tls_tprel_lo_32"
9755   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9756         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9757                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9758                    UNSPEC_TLSTPRELLO))]
9759   "HAVE_AS_TLS && !TARGET_64BIT"
9760   "addi %0,%1,%2@tprel@l")
9761
9762 (define_insn "tls_tprel_lo_64"
9763   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9764         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9765                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9766                    UNSPEC_TLSTPRELLO))]
9767   "HAVE_AS_TLS && TARGET_64BIT"
9768   "addi %0,%1,%2@tprel@l")
9769
9770 ;; "b" output constraint here and on tls_tls input to support linker tls
9771 ;; optimization.  The linker may edit the instructions emitted by a
9772 ;; tls_got_tprel/tls_tls pair to addis,addi.
9773 (define_insn "tls_got_tprel_32"
9774   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9775         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9776                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9777                    UNSPEC_TLSGOTTPREL))]
9778   "HAVE_AS_TLS && !TARGET_64BIT"
9779   "lwz %0,%2@got@tprel(%1)")
9780
9781 (define_insn "tls_got_tprel_64"
9782   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9783         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9784                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9785                    UNSPEC_TLSGOTTPREL))]
9786   "HAVE_AS_TLS && TARGET_64BIT"
9787   "ld %0,%2@got@tprel(%1)")
9788
9789 (define_insn "tls_tls_32"
9790   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9791         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9792                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9793                    UNSPEC_TLSTLS))]
9794   "HAVE_AS_TLS && !TARGET_64BIT"
9795   "add %0,%1,%2@tls")
9796
9797 (define_insn "tls_tls_64"
9798   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9799         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9800                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9801                    UNSPEC_TLSTLS))]
9802   "HAVE_AS_TLS && TARGET_64BIT"
9803   "add %0,%1,%2@tls")
9804 \f
9805 ;; Next come insns related to the calling sequence.
9806 ;;
9807 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
9808 ;; We move the back-chain and decrement the stack pointer.
9809
9810 (define_expand "allocate_stack"
9811   [(set (match_operand 0 "gpc_reg_operand" "=r")
9812         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
9813    (set (reg 1)
9814         (minus (reg 1) (match_dup 1)))]
9815   ""
9816   "
9817 { rtx chain = gen_reg_rtx (Pmode);
9818   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
9819   rtx neg_op0;
9820
9821   emit_move_insn (chain, stack_bot);
9822
9823   /* Check stack bounds if necessary.  */
9824   if (current_function_limit_stack)
9825     {
9826       rtx available;
9827       available = expand_binop (Pmode, sub_optab,
9828                                 stack_pointer_rtx, stack_limit_rtx,
9829                                 NULL_RTX, 1, OPTAB_WIDEN);
9830       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
9831     }
9832
9833   if (GET_CODE (operands[1]) != CONST_INT
9834       || INTVAL (operands[1]) < -32767
9835       || INTVAL (operands[1]) > 32768)
9836     {
9837       neg_op0 = gen_reg_rtx (Pmode);
9838       if (TARGET_32BIT)
9839         emit_insn (gen_negsi2 (neg_op0, operands[1]));
9840       else
9841         emit_insn (gen_negdi2 (neg_op0, operands[1]));
9842     }
9843   else
9844     neg_op0 = GEN_INT (- INTVAL (operands[1]));
9845
9846   if (TARGET_UPDATE)
9847     emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update : gen_movdi_di_update))
9848                 (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
9849
9850   else
9851     {
9852       emit_insn ((* ((TARGET_32BIT) ? gen_addsi3 : gen_adddi3))
9853                  (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
9854       emit_move_insn (gen_rtx_MEM (Pmode, stack_pointer_rtx), chain);
9855     }
9856
9857   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
9858   DONE;
9859 }")
9860
9861 ;; These patterns say how to save and restore the stack pointer.  We need not
9862 ;; save the stack pointer at function level since we are careful to
9863 ;; preserve the backchain.  At block level, we have to restore the backchain
9864 ;; when we restore the stack pointer.
9865 ;;
9866 ;; For nonlocal gotos, we must save both the stack pointer and its
9867 ;; backchain and restore both.  Note that in the nonlocal case, the
9868 ;; save area is a memory location.
9869
9870 (define_expand "save_stack_function"
9871   [(match_operand 0 "any_operand" "")
9872    (match_operand 1 "any_operand" "")]
9873   ""
9874   "DONE;")
9875
9876 (define_expand "restore_stack_function"
9877   [(match_operand 0 "any_operand" "")
9878    (match_operand 1 "any_operand" "")]
9879   ""
9880   "DONE;")
9881
9882 ;; Adjust stack pointer (op0) to a new value (op1).
9883 ;; First copy old stack backchain to new location, and ensure that the
9884 ;; scheduler won't reorder the sp assignment before the backchain write.
9885 (define_expand "restore_stack_block"
9886   [(set (match_dup 2) (match_dup 3))
9887    (set (match_dup 4) (match_dup 2))
9888    (set (match_dup 5) (unspec:BLK [(match_dup 5)] UNSPEC_TIE))
9889    (set (match_operand 0 "register_operand" "")
9890         (match_operand 1 "register_operand" ""))]
9891   ""
9892   "
9893 {
9894   operands[2] = gen_reg_rtx (Pmode);
9895   operands[3] = gen_frame_mem (Pmode, operands[0]);
9896   operands[4] = gen_frame_mem (Pmode, operands[1]);
9897   operands[5] = gen_frame_mem (BLKmode, operands[0]);
9898 }")
9899
9900 (define_expand "save_stack_nonlocal"
9901   [(set (match_dup 3) (match_dup 4))
9902    (set (match_operand 0 "memory_operand" "") (match_dup 3))
9903    (set (match_dup 2) (match_operand 1 "register_operand" ""))]
9904   ""
9905   "
9906 {
9907   int units_per_word = (TARGET_32BIT) ? 4 : 8;
9908
9909   /* Copy the backchain to the first word, sp to the second.  */
9910   operands[0] = adjust_address_nv (operands[0], Pmode, 0);
9911   operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
9912   operands[3] = gen_reg_rtx (Pmode);
9913   operands[4] = gen_frame_mem (Pmode, operands[1]);
9914 }")
9915
9916 (define_expand "restore_stack_nonlocal"
9917   [(set (match_dup 2) (match_operand 1 "memory_operand" ""))
9918    (set (match_dup 3) (match_dup 4))
9919    (set (match_dup 5) (match_dup 2))
9920    (set (match_dup 6) (unspec:BLK [(match_dup 6)] UNSPEC_TIE))
9921    (set (match_operand 0 "register_operand" "") (match_dup 3))]
9922   ""
9923   "
9924 {
9925   int units_per_word = (TARGET_32BIT) ? 4 : 8;
9926
9927   /* Restore the backchain from the first word, sp from the second.  */
9928   operands[2] = gen_reg_rtx (Pmode);
9929   operands[3] = gen_reg_rtx (Pmode);
9930   operands[1] = adjust_address_nv (operands[1], Pmode, 0);
9931   operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
9932   operands[5] = gen_frame_mem (Pmode, operands[3]);
9933   operands[6] = gen_frame_mem (BLKmode, operands[0]);
9934 }")
9935 \f
9936 ;; TOC register handling.
9937
9938 ;; Code to initialize the TOC register...
9939
9940 (define_insn "load_toc_aix_si"
9941   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9942                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
9943               (use (reg:SI 2))])]
9944   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
9945   "*
9946 {
9947   char buf[30];
9948   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
9949   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9950   operands[2] = gen_rtx_REG (Pmode, 2);
9951   return \"{l|lwz} %0,%1(%2)\";
9952 }"
9953   [(set_attr "type" "load")])
9954
9955 (define_insn "load_toc_aix_di"
9956   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9957                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
9958               (use (reg:DI 2))])]
9959   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
9960   "*
9961 {
9962   char buf[30];
9963 #ifdef TARGET_RELOCATABLE
9964   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
9965                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
9966 #else
9967   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
9968 #endif
9969   if (TARGET_ELF)
9970     strcat (buf, \"@toc\");
9971   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9972   operands[2] = gen_rtx_REG (Pmode, 2);
9973   return \"ld %0,%1(%2)\";
9974 }"
9975   [(set_attr "type" "load")])
9976
9977 (define_insn "load_toc_v4_pic_si"
9978   [(set (match_operand:SI 0 "register_operand" "=l")
9979         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
9980   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
9981   "bl _GLOBAL_OFFSET_TABLE_@local-4"
9982   [(set_attr "type" "branch")
9983    (set_attr "length" "4")])
9984
9985 (define_insn "load_toc_v4_PIC_1"
9986   [(set (match_operand:SI 0 "register_operand" "=l")
9987         (match_operand:SI 1 "immediate_operand" "s"))
9988    (use (unspec [(match_dup 1)] UNSPEC_TOC))]
9989   "TARGET_ELF && DEFAULT_ABI != ABI_AIX
9990    && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
9991   "bcl 20,31,%1\\n%1:"
9992   [(set_attr "type" "branch")
9993    (set_attr "length" "4")])
9994
9995 (define_insn "load_toc_v4_PIC_1b"
9996   [(set (match_operand:SI 0 "register_operand" "=l")
9997         (unspec:SI [(match_operand:SI 1 "immediate_operand" "s")]
9998                 UNSPEC_TOCPTR))]
9999   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10000   "bcl 20,31,$+8\\n\\t.long %1-$"
10001   [(set_attr "type" "branch")
10002    (set_attr "length" "8")])
10003
10004 (define_insn "load_toc_v4_PIC_2"
10005   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10006         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10007                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
10008                              (match_operand:SI 3 "immediate_operand" "s")))))]
10009   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10010   "{l|lwz} %0,%2-%3(%1)"
10011   [(set_attr "type" "load")])
10012
10013 (define_insn "load_toc_v4_PIC_3b"
10014   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
10015         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
10016                  (high:SI
10017                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
10018                              (match_operand:SI 3 "symbol_ref_operand" "s")))))]
10019   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
10020   "{cau|addis} %0,%1,%2-%3@ha")
10021
10022 (define_insn "load_toc_v4_PIC_3c"
10023   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10024         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10025                    (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
10026                              (match_operand:SI 3 "symbol_ref_operand" "s"))))]
10027   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI != ABI_AIX && flag_pic"
10028   "{cal|addi} %0,%1,%2-%3@l")
10029
10030 ;; If the TOC is shared over a translation unit, as happens with all
10031 ;; the kinds of PIC that we support, we need to restore the TOC
10032 ;; pointer only when jumping over units of translation.
10033 ;; On Darwin, we need to reload the picbase.
10034
10035 (define_expand "builtin_setjmp_receiver"
10036   [(use (label_ref (match_operand 0 "" "")))]
10037   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10038    || (TARGET_TOC && TARGET_MINIMAL_TOC)
10039    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
10040   "
10041 {
10042 #if TARGET_MACHO
10043   if (DEFAULT_ABI == ABI_DARWIN)
10044     {
10045       const char *picbase = machopic_function_base_name ();
10046       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (picbase));
10047       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
10048       rtx tmplabrtx;
10049       char tmplab[20];
10050
10051       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
10052                                   CODE_LABEL_NUMBER (operands[0]));
10053       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
10054
10055       emit_insn (gen_load_macho_picbase (picreg, tmplabrtx));
10056       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
10057     }
10058   else
10059 #endif
10060     rs6000_emit_load_toc_table (FALSE);
10061   DONE;
10062 }")
10063
10064 ;; Elf specific ways of loading addresses for non-PIC code.
10065 ;; The output of this could be r0, but we make a very strong
10066 ;; preference for a base register because it will usually
10067 ;; be needed there.
10068 (define_insn "elf_high"
10069   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
10070         (high:SI (match_operand 1 "" "")))]
10071   "TARGET_ELF && ! TARGET_64BIT"
10072   "{liu|lis} %0,%1@ha")
10073
10074 (define_insn "elf_low"
10075   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
10076         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
10077                    (match_operand 2 "" "")))]
10078    "TARGET_ELF && ! TARGET_64BIT"
10079    "@
10080     {cal|la} %0,%2@l(%1)
10081     {ai|addic} %0,%1,%K2")
10082 \f
10083 ;; A function pointer under AIX is a pointer to a data area whose first word
10084 ;; contains the actual address of the function, whose second word contains a
10085 ;; pointer to its TOC, and whose third word contains a value to place in the
10086 ;; static chain register (r11).  Note that if we load the static chain, our
10087 ;; "trampoline" need not have any executable code.
10088
10089 (define_expand "call_indirect_aix32"
10090   [(set (match_dup 2)
10091         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
10092    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10093         (reg:SI 2))
10094    (set (reg:SI 2)
10095         (mem:SI (plus:SI (match_dup 0)
10096                          (const_int 4))))
10097    (set (reg:SI 11)
10098         (mem:SI (plus:SI (match_dup 0)
10099                          (const_int 8))))
10100    (parallel [(call (mem:SI (match_dup 2))
10101                     (match_operand 1 "" ""))
10102               (use (reg:SI 2))
10103               (use (reg:SI 11))
10104               (set (reg:SI 2)
10105                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10106               (clobber (scratch:SI))])]
10107   "TARGET_32BIT"
10108   "
10109 { operands[2] = gen_reg_rtx (SImode); }")
10110
10111 (define_expand "call_indirect_aix64"
10112   [(set (match_dup 2)
10113         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
10114    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10115         (reg:DI 2))
10116    (set (reg:DI 2)
10117         (mem:DI (plus:DI (match_dup 0)
10118                          (const_int 8))))
10119    (set (reg:DI 11)
10120         (mem:DI (plus:DI (match_dup 0)
10121                          (const_int 16))))
10122    (parallel [(call (mem:SI (match_dup 2))
10123                     (match_operand 1 "" ""))
10124               (use (reg:DI 2))
10125               (use (reg:DI 11))
10126               (set (reg:DI 2)
10127                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10128               (clobber (scratch:SI))])]
10129   "TARGET_64BIT"
10130   "
10131 { operands[2] = gen_reg_rtx (DImode); }")
10132
10133 (define_expand "call_value_indirect_aix32"
10134   [(set (match_dup 3)
10135         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
10136    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10137         (reg:SI 2))
10138    (set (reg:SI 2)
10139         (mem:SI (plus:SI (match_dup 1)
10140                          (const_int 4))))
10141    (set (reg:SI 11)
10142         (mem:SI (plus:SI (match_dup 1)
10143                          (const_int 8))))
10144    (parallel [(set (match_operand 0 "" "")
10145                    (call (mem:SI (match_dup 3))
10146                          (match_operand 2 "" "")))
10147               (use (reg:SI 2))
10148               (use (reg:SI 11))
10149               (set (reg:SI 2)
10150                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10151               (clobber (scratch:SI))])]
10152   "TARGET_32BIT"
10153   "
10154 { operands[3] = gen_reg_rtx (SImode); }")
10155
10156 (define_expand "call_value_indirect_aix64"
10157   [(set (match_dup 3)
10158         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
10159    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10160         (reg:DI 2))
10161    (set (reg:DI 2)
10162         (mem:DI (plus:DI (match_dup 1)
10163                          (const_int 8))))
10164    (set (reg:DI 11)
10165         (mem:DI (plus:DI (match_dup 1)
10166                          (const_int 16))))
10167    (parallel [(set (match_operand 0 "" "")
10168                    (call (mem:SI (match_dup 3))
10169                          (match_operand 2 "" "")))
10170               (use (reg:DI 2))
10171               (use (reg:DI 11))
10172               (set (reg:DI 2)
10173                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10174               (clobber (scratch:SI))])]
10175   "TARGET_64BIT"
10176   "
10177 { operands[3] = gen_reg_rtx (DImode); }")
10178
10179 ;; Now the definitions for the call and call_value insns
10180 (define_expand "call"
10181   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10182                     (match_operand 1 "" ""))
10183               (use (match_operand 2 "" ""))
10184               (clobber (scratch:SI))])]
10185   ""
10186   "
10187 {
10188 #if TARGET_MACHO
10189   if (MACHOPIC_INDIRECT)
10190     operands[0] = machopic_indirect_call_target (operands[0]);
10191 #endif
10192
10193   gcc_assert (GET_CODE (operands[0]) == MEM);
10194   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
10195
10196   operands[0] = XEXP (operands[0], 0);
10197
10198   if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT
10199       && flag_pic
10200       && GET_CODE (operands[0]) == SYMBOL_REF
10201       && !SYMBOL_REF_LOCAL_P (operands[0]))
10202     {
10203       rtx call;
10204       rtvec tmp;
10205
10206       tmp = gen_rtvec (3,
10207                        gen_rtx_CALL (VOIDmode,
10208                                      gen_rtx_MEM (SImode, operands[0]),
10209                                      operands[1]),
10210                        gen_rtx_USE (VOIDmode, operands[2]),
10211                        gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (SImode)));
10212       call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp));
10213       use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx);
10214       DONE;
10215     }
10216
10217   if (GET_CODE (operands[0]) != SYMBOL_REF
10218       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
10219       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
10220     {
10221       if (INTVAL (operands[2]) & CALL_LONG)
10222         operands[0] = rs6000_longcall_ref (operands[0]);
10223
10224       switch (DEFAULT_ABI)
10225         {
10226         case ABI_V4:
10227         case ABI_DARWIN:
10228           operands[0] = force_reg (Pmode, operands[0]);
10229           break;
10230
10231         case ABI_AIX:
10232           /* AIX function pointers are really pointers to a three word
10233              area.  */
10234           emit_call_insn (TARGET_32BIT
10235                           ? gen_call_indirect_aix32 (force_reg (SImode,
10236                                                                 operands[0]),
10237                                                      operands[1])
10238                           : gen_call_indirect_aix64 (force_reg (DImode,
10239                                                                 operands[0]),
10240                                                      operands[1]));
10241           DONE;
10242
10243         default:
10244           gcc_unreachable ();
10245         }
10246     }
10247 }")
10248
10249 (define_expand "call_value"
10250   [(parallel [(set (match_operand 0 "" "")
10251                    (call (mem:SI (match_operand 1 "address_operand" ""))
10252                          (match_operand 2 "" "")))
10253               (use (match_operand 3 "" ""))
10254               (clobber (scratch:SI))])]
10255   ""
10256   "
10257 {
10258 #if TARGET_MACHO
10259   if (MACHOPIC_INDIRECT)
10260     operands[1] = machopic_indirect_call_target (operands[1]);
10261 #endif
10262
10263   gcc_assert (GET_CODE (operands[1]) == MEM);
10264   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
10265
10266   operands[1] = XEXP (operands[1], 0);
10267
10268   if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT
10269       && flag_pic
10270       && GET_CODE (operands[1]) == SYMBOL_REF
10271       && !SYMBOL_REF_LOCAL_P (operands[1]))
10272     {
10273       rtx call;
10274       rtvec tmp;
10275
10276       tmp = gen_rtvec (3,
10277                        gen_rtx_SET (VOIDmode,
10278                                     operands[0],
10279                                     gen_rtx_CALL (VOIDmode,
10280                                                   gen_rtx_MEM (SImode,
10281                                                                operands[1]),
10282                                                   operands[2])),
10283                        gen_rtx_USE (VOIDmode, operands[3]),
10284                        gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (SImode)));
10285       call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp));
10286       use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx);
10287       DONE;
10288     }
10289
10290   if (GET_CODE (operands[1]) != SYMBOL_REF
10291       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
10292       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
10293     {
10294       if (INTVAL (operands[3]) & CALL_LONG)
10295         operands[1] = rs6000_longcall_ref (operands[1]);
10296
10297       switch (DEFAULT_ABI)
10298         {
10299         case ABI_V4:
10300         case ABI_DARWIN:
10301           operands[1] = force_reg (Pmode, operands[1]);
10302           break;
10303
10304         case ABI_AIX:
10305           /* AIX function pointers are really pointers to a three word
10306              area.  */
10307           emit_call_insn (TARGET_32BIT
10308                           ? gen_call_value_indirect_aix32 (operands[0],
10309                                                            force_reg (SImode,
10310                                                                       operands[1]),
10311                                                            operands[2])
10312                           : gen_call_value_indirect_aix64 (operands[0],
10313                                                            force_reg (DImode,
10314                                                                       operands[1]),
10315                                                            operands[2]));
10316           DONE;
10317
10318         default:
10319           gcc_unreachable ();
10320         }
10321     }
10322 }")
10323
10324 ;; Call to function in current module.  No TOC pointer reload needed.
10325 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10326 ;; either the function was not prototyped, or it was prototyped as a
10327 ;; variable argument function.  It is > 0 if FP registers were passed
10328 ;; and < 0 if they were not.
10329
10330 (define_insn "*call_local32"
10331   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10332          (match_operand 1 "" "g,g"))
10333    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10334    (clobber (match_scratch:SI 3 "=l,l"))]
10335   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10336   "*
10337 {
10338   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10339     output_asm_insn (\"crxor 6,6,6\", operands);
10340
10341   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10342     output_asm_insn (\"creqv 6,6,6\", operands);
10343
10344   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10345 }"
10346   [(set_attr "type" "branch")
10347    (set_attr "length" "4,8")])
10348
10349 (define_insn "*call_local64"
10350   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10351          (match_operand 1 "" "g,g"))
10352    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10353    (clobber (match_scratch:SI 3 "=l,l"))]
10354   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10355   "*
10356 {
10357   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10358     output_asm_insn (\"crxor 6,6,6\", operands);
10359
10360   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10361     output_asm_insn (\"creqv 6,6,6\", operands);
10362
10363   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10364 }"
10365   [(set_attr "type" "branch")
10366    (set_attr "length" "4,8")])
10367
10368 (define_insn "*call_value_local32"
10369   [(set (match_operand 0 "" "")
10370         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10371               (match_operand 2 "" "g,g")))
10372    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10373    (clobber (match_scratch:SI 4 "=l,l"))]
10374   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10375   "*
10376 {
10377   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10378     output_asm_insn (\"crxor 6,6,6\", operands);
10379
10380   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10381     output_asm_insn (\"creqv 6,6,6\", operands);
10382
10383   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10384 }"
10385   [(set_attr "type" "branch")
10386    (set_attr "length" "4,8")])
10387
10388
10389 (define_insn "*call_value_local64"
10390   [(set (match_operand 0 "" "")
10391         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10392               (match_operand 2 "" "g,g")))
10393    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10394    (clobber (match_scratch:SI 4 "=l,l"))]
10395   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10396   "*
10397 {
10398   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10399     output_asm_insn (\"crxor 6,6,6\", operands);
10400
10401   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10402     output_asm_insn (\"creqv 6,6,6\", operands);
10403
10404   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10405 }"
10406   [(set_attr "type" "branch")
10407    (set_attr "length" "4,8")])
10408
10409 ;; Call to function which may be in another module.  Restore the TOC
10410 ;; pointer (r2) after the call unless this is System V.
10411 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10412 ;; either the function was not prototyped, or it was prototyped as a
10413 ;; variable argument function.  It is > 0 if FP registers were passed
10414 ;; and < 0 if they were not.
10415
10416 (define_insn "*call_indirect_nonlocal_aix32"
10417   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l"))
10418          (match_operand 1 "" "g,g"))
10419    (use (reg:SI 2))
10420    (use (reg:SI 11))
10421    (set (reg:SI 2)
10422         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10423    (clobber (match_scratch:SI 2 "=l,l"))]
10424   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10425   "b%T0l\;{l|lwz} 2,20(1)"
10426   [(set_attr "type" "jmpreg")
10427    (set_attr "length" "8")])
10428
10429 (define_insn "*call_nonlocal_aix32"
10430   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10431          (match_operand 1 "" "g"))
10432    (use (match_operand:SI 2 "immediate_operand" "O"))
10433    (clobber (match_scratch:SI 3 "=l"))]
10434   "TARGET_32BIT
10435    && DEFAULT_ABI == ABI_AIX
10436    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10437   "bl %z0\;%."
10438   [(set_attr "type" "branch")
10439    (set_attr "length" "8")])
10440
10441 (define_insn "*call_indirect_nonlocal_aix64"
10442   [(call (mem:SI (match_operand:DI 0 "register_operand" "c,*l"))
10443          (match_operand 1 "" "g,g"))
10444    (use (reg:DI 2))
10445    (use (reg:DI 11))
10446    (set (reg:DI 2)
10447         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10448    (clobber (match_scratch:SI 2 "=l,l"))]
10449   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10450   "b%T0l\;ld 2,40(1)"
10451   [(set_attr "type" "jmpreg")
10452    (set_attr "length" "8")])
10453
10454 (define_insn "*call_nonlocal_aix64"
10455   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10456          (match_operand 1 "" "g"))
10457    (use (match_operand:SI 2 "immediate_operand" "O"))
10458    (clobber (match_scratch:SI 3 "=l"))]
10459   "TARGET_64BIT
10460    && DEFAULT_ABI == ABI_AIX
10461    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10462   "bl %z0\;%."
10463   [(set_attr "type" "branch")
10464    (set_attr "length" "8")])
10465
10466 (define_insn "*call_value_indirect_nonlocal_aix32"
10467   [(set (match_operand 0 "" "")
10468         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l"))
10469               (match_operand 2 "" "g,g")))
10470    (use (reg:SI 2))
10471    (use (reg:SI 11))
10472    (set (reg:SI 2)
10473         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10474    (clobber (match_scratch:SI 3 "=l,l"))]
10475   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10476   "b%T1l\;{l|lwz} 2,20(1)"
10477   [(set_attr "type" "jmpreg")
10478    (set_attr "length" "8")])
10479
10480 (define_insn "*call_value_nonlocal_aix32"
10481   [(set (match_operand 0 "" "")
10482         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10483               (match_operand 2 "" "g")))
10484    (use (match_operand:SI 3 "immediate_operand" "O"))
10485    (clobber (match_scratch:SI 4 "=l"))]
10486   "TARGET_32BIT
10487    && DEFAULT_ABI == ABI_AIX
10488    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10489   "bl %z1\;%."
10490   [(set_attr "type" "branch")
10491    (set_attr "length" "8")])
10492
10493 (define_insn "*call_value_indirect_nonlocal_aix64"
10494   [(set (match_operand 0 "" "")
10495         (call (mem:SI (match_operand:DI 1 "register_operand" "c,*l"))
10496               (match_operand 2 "" "g,g")))
10497    (use (reg:DI 2))
10498    (use (reg:DI 11))
10499    (set (reg:DI 2)
10500         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10501    (clobber (match_scratch:SI 3 "=l,l"))]
10502   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10503   "b%T1l\;ld 2,40(1)"
10504   [(set_attr "type" "jmpreg")
10505    (set_attr "length" "8")])
10506
10507 (define_insn "*call_value_nonlocal_aix64"
10508   [(set (match_operand 0 "" "")
10509         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10510               (match_operand 2 "" "g")))
10511    (use (match_operand:SI 3 "immediate_operand" "O"))
10512    (clobber (match_scratch:SI 4 "=l"))]
10513   "TARGET_64BIT
10514    && DEFAULT_ABI == ABI_AIX
10515    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10516   "bl %z1\;%."
10517   [(set_attr "type" "branch")
10518    (set_attr "length" "8")])
10519
10520 ;; A function pointer under System V is just a normal pointer
10521 ;; operands[0] is the function pointer
10522 ;; operands[1] is the stack size to clean up
10523 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
10524 ;; which indicates how to set cr1
10525
10526 (define_insn "*call_indirect_nonlocal_sysv"
10527   [(call (mem:SI (match_operand:SI 0 "register_operand" "c,*l,c,*l"))
10528          (match_operand 1 "" "g,g,g,g"))
10529    (use (match_operand:SI 2 "immediate_operand" "O,O,n,n"))
10530    (clobber (match_scratch:SI 3 "=l,l,l,l"))]
10531   "DEFAULT_ABI == ABI_V4
10532    || DEFAULT_ABI == ABI_DARWIN"
10533 {
10534   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10535     output_asm_insn ("crxor 6,6,6", operands);
10536
10537   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10538     output_asm_insn ("creqv 6,6,6", operands);
10539
10540   return "b%T0l";
10541 }
10542   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
10543    (set_attr "length" "4,4,8,8")])
10544
10545 (define_insn "*call_nonlocal_sysv"
10546   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10547          (match_operand 1 "" "g,g"))
10548    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10549    (clobber (match_scratch:SI 3 "=l,l"))]
10550   "(DEFAULT_ABI == ABI_DARWIN
10551    || (DEFAULT_ABI == ABI_V4
10552        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
10553 {
10554   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10555     output_asm_insn ("crxor 6,6,6", operands);
10556
10557   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10558     output_asm_insn ("creqv 6,6,6", operands);
10559
10560 #if TARGET_MACHO
10561   return output_call(insn, operands, 0, 2);
10562 #else
10563   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10564     {
10565       if (TARGET_SECURE_PLT && flag_pic == 2)
10566         /* The magic 32768 offset here and in the other sysv call insns
10567            corresponds to the offset of r30 in .got2, as given by LCTOC1.
10568            See sysv4.h:toc_section.  */
10569         return "bl %z0+32768@plt";
10570       else
10571         return "bl %z0@plt";
10572     }
10573   else
10574     return "bl %z0";
10575 #endif
10576 }
10577   [(set_attr "type" "branch,branch")
10578    (set_attr "length" "4,8")])
10579
10580 (define_insn "*call_value_indirect_nonlocal_sysv"
10581   [(set (match_operand 0 "" "")
10582         (call (mem:SI (match_operand:SI 1 "register_operand" "c,*l,c,*l"))
10583               (match_operand 2 "" "g,g,g,g")))
10584    (use (match_operand:SI 3 "immediate_operand" "O,O,n,n"))
10585    (clobber (match_scratch:SI 4 "=l,l,l,l"))]
10586   "DEFAULT_ABI == ABI_V4
10587    || DEFAULT_ABI == ABI_DARWIN"
10588 {
10589   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10590     output_asm_insn ("crxor 6,6,6", operands);
10591
10592   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10593     output_asm_insn ("creqv 6,6,6", operands);
10594
10595   return "b%T1l";
10596 }
10597   [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
10598    (set_attr "length" "4,4,8,8")])
10599
10600 (define_insn "*call_value_nonlocal_sysv"
10601   [(set (match_operand 0 "" "")
10602         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10603               (match_operand 2 "" "g,g")))
10604    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10605    (clobber (match_scratch:SI 4 "=l,l"))]
10606   "(DEFAULT_ABI == ABI_DARWIN
10607    || (DEFAULT_ABI == ABI_V4
10608        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
10609 {
10610   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10611     output_asm_insn ("crxor 6,6,6", operands);
10612
10613   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10614     output_asm_insn ("creqv 6,6,6", operands);
10615
10616 #if TARGET_MACHO
10617   return output_call(insn, operands, 1, 3);
10618 #else
10619   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10620     {
10621       if (TARGET_SECURE_PLT && flag_pic == 2)
10622         return "bl %z1+32768@plt";
10623       else
10624         return "bl %z1@plt";
10625     }
10626   else
10627     return "bl %z1";
10628 #endif
10629 }
10630   [(set_attr "type" "branch,branch")
10631    (set_attr "length" "4,8")])
10632
10633 ;; Call subroutine returning any type.
10634 (define_expand "untyped_call"
10635   [(parallel [(call (match_operand 0 "" "")
10636                     (const_int 0))
10637               (match_operand 1 "" "")
10638               (match_operand 2 "" "")])]
10639   ""
10640   "
10641 {
10642   int i;
10643
10644   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
10645
10646   for (i = 0; i < XVECLEN (operands[2], 0); i++)
10647     {
10648       rtx set = XVECEXP (operands[2], 0, i);
10649       emit_move_insn (SET_DEST (set), SET_SRC (set));
10650     }
10651
10652   /* The optimizer does not know that the call sets the function value
10653      registers we stored in the result block.  We avoid problems by
10654      claiming that all hard registers are used and clobbered at this
10655      point.  */
10656   emit_insn (gen_blockage ());
10657
10658   DONE;
10659 }")
10660
10661 ;; sibling call patterns
10662 (define_expand "sibcall"
10663   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10664                     (match_operand 1 "" ""))
10665               (use (match_operand 2 "" ""))
10666               (use (match_operand 3 "" ""))
10667               (return)])]
10668   ""
10669   "
10670 {
10671 #if TARGET_MACHO
10672   if (MACHOPIC_INDIRECT)
10673     operands[0] = machopic_indirect_call_target (operands[0]);
10674 #endif
10675
10676   gcc_assert (GET_CODE (operands[0]) == MEM);
10677   gcc_assert (GET_CODE (operands[1]) == CONST_INT);
10678
10679   operands[0] = XEXP (operands[0], 0);
10680   operands[3] = gen_reg_rtx (SImode);
10681
10682 }")
10683
10684 ;; this and similar patterns must be marked as using LR, otherwise
10685 ;; dataflow will try to delete the store into it.  This is true
10686 ;; even when the actual reg to jump to is in CTR, when LR was
10687 ;; saved and restored around the PIC-setting BCL.
10688 (define_insn "*sibcall_local32"
10689   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10690          (match_operand 1 "" "g,g"))
10691    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10692    (use (match_operand:SI 3 "register_operand" "l,l"))
10693    (return)]
10694   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10695   "*
10696 {
10697   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10698     output_asm_insn (\"crxor 6,6,6\", operands);
10699
10700   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10701     output_asm_insn (\"creqv 6,6,6\", operands);
10702
10703   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10704 }"
10705   [(set_attr "type" "branch")
10706    (set_attr "length" "4,8")])
10707
10708 (define_insn "*sibcall_local64"
10709   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10710          (match_operand 1 "" "g,g"))
10711    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10712    (use (match_operand:SI 3 "register_operand" "l,l"))
10713    (return)]
10714   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10715   "*
10716 {
10717   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10718     output_asm_insn (\"crxor 6,6,6\", operands);
10719
10720   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10721     output_asm_insn (\"creqv 6,6,6\", operands);
10722
10723   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10724 }"
10725   [(set_attr "type" "branch")
10726    (set_attr "length" "4,8")])
10727
10728 (define_insn "*sibcall_value_local32"
10729   [(set (match_operand 0 "" "")
10730         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10731               (match_operand 2 "" "g,g")))
10732    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10733    (use (match_operand:SI 4 "register_operand" "l,l"))
10734    (return)]
10735   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10736   "*
10737 {
10738   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10739     output_asm_insn (\"crxor 6,6,6\", operands);
10740
10741   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10742     output_asm_insn (\"creqv 6,6,6\", operands);
10743
10744   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10745 }"
10746   [(set_attr "type" "branch")
10747    (set_attr "length" "4,8")])
10748
10749
10750 (define_insn "*sibcall_value_local64"
10751   [(set (match_operand 0 "" "")
10752         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10753               (match_operand 2 "" "g,g")))
10754    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10755    (use (match_operand:SI 4 "register_operand" "l,l"))
10756    (return)]
10757   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10758   "*
10759 {
10760   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10761     output_asm_insn (\"crxor 6,6,6\", operands);
10762
10763   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10764     output_asm_insn (\"creqv 6,6,6\", operands);
10765
10766   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10767 }"
10768   [(set_attr "type" "branch")
10769    (set_attr "length" "4,8")])
10770
10771 (define_insn "*sibcall_nonlocal_aix32"
10772   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10773          (match_operand 1 "" "g"))
10774    (use (match_operand:SI 2 "immediate_operand" "O"))
10775    (use (match_operand:SI 3 "register_operand" "l"))
10776    (return)]
10777   "TARGET_32BIT
10778    && DEFAULT_ABI == ABI_AIX
10779    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10780   "b %z0"
10781   [(set_attr "type" "branch")
10782    (set_attr "length" "4")])
10783
10784 (define_insn "*sibcall_nonlocal_aix64"
10785   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10786          (match_operand 1 "" "g"))
10787    (use (match_operand:SI 2 "immediate_operand" "O"))
10788    (use (match_operand:SI 3 "register_operand" "l"))
10789    (return)]
10790   "TARGET_64BIT
10791    && DEFAULT_ABI == ABI_AIX
10792    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10793   "b %z0"
10794   [(set_attr "type" "branch")
10795    (set_attr "length" "4")])
10796
10797 (define_insn "*sibcall_value_nonlocal_aix32"
10798   [(set (match_operand 0 "" "")
10799         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10800               (match_operand 2 "" "g")))
10801    (use (match_operand:SI 3 "immediate_operand" "O"))
10802    (use (match_operand:SI 4 "register_operand" "l"))
10803    (return)]
10804   "TARGET_32BIT
10805    && DEFAULT_ABI == ABI_AIX
10806    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10807   "b %z1"
10808   [(set_attr "type" "branch")
10809    (set_attr "length" "4")])
10810
10811 (define_insn "*sibcall_value_nonlocal_aix64"
10812   [(set (match_operand 0 "" "")
10813         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10814               (match_operand 2 "" "g")))
10815    (use (match_operand:SI 3 "immediate_operand" "O"))
10816    (use (match_operand:SI 4 "register_operand" "l"))
10817    (return)]
10818   "TARGET_64BIT
10819    && DEFAULT_ABI == ABI_AIX
10820    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10821   "b %z1"
10822   [(set_attr "type" "branch")
10823    (set_attr "length" "4")])
10824
10825 (define_insn "*sibcall_nonlocal_sysv"
10826   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10827          (match_operand 1 "" ""))
10828    (use (match_operand 2 "immediate_operand" "O,n"))
10829    (use (match_operand:SI 3 "register_operand" "l,l"))
10830    (return)]
10831   "(DEFAULT_ABI == ABI_DARWIN
10832      || DEFAULT_ABI == ABI_V4)
10833    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10834   "*
10835 {
10836   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10837     output_asm_insn (\"crxor 6,6,6\", operands);
10838
10839   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10840     output_asm_insn (\"creqv 6,6,6\", operands);
10841
10842   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10843     {
10844       if (TARGET_SECURE_PLT && flag_pic == 2)
10845         return \"b %z0+32768@plt\";
10846       else
10847         return \"b %z0@plt\";
10848     }
10849   else
10850     return \"b %z0\";
10851 }"
10852   [(set_attr "type" "branch,branch")
10853    (set_attr "length" "4,8")])
10854
10855 (define_expand "sibcall_value"
10856   [(parallel [(set (match_operand 0 "register_operand" "")
10857                 (call (mem:SI (match_operand 1 "address_operand" ""))
10858                       (match_operand 2 "" "")))
10859               (use (match_operand 3 "" ""))
10860               (use (match_operand 4 "" ""))
10861               (return)])]
10862   ""
10863   "
10864 {
10865 #if TARGET_MACHO
10866   if (MACHOPIC_INDIRECT)
10867     operands[1] = machopic_indirect_call_target (operands[1]);
10868 #endif
10869
10870   gcc_assert (GET_CODE (operands[1]) == MEM);
10871   gcc_assert (GET_CODE (operands[2]) == CONST_INT);
10872
10873   operands[1] = XEXP (operands[1], 0);
10874   operands[4] = gen_reg_rtx (SImode);
10875
10876 }")
10877
10878 (define_insn "*sibcall_value_nonlocal_sysv"
10879   [(set (match_operand 0 "" "")
10880         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10881               (match_operand 2 "" "")))
10882    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10883    (use (match_operand:SI 4 "register_operand" "l,l"))
10884    (return)]
10885   "(DEFAULT_ABI == ABI_DARWIN
10886        || DEFAULT_ABI == ABI_V4)
10887    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10888   "*
10889 {
10890   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10891     output_asm_insn (\"crxor 6,6,6\", operands);
10892
10893   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10894     output_asm_insn (\"creqv 6,6,6\", operands);
10895
10896   if (DEFAULT_ABI == ABI_V4 && flag_pic)
10897     {
10898       if (TARGET_SECURE_PLT && flag_pic == 2)
10899         return \"b %z1+32768@plt\";
10900       else
10901         return \"b %z1@plt\";
10902     }
10903   else
10904     return \"b %z1\";
10905 }"
10906   [(set_attr "type" "branch,branch")
10907    (set_attr "length" "4,8")])
10908
10909 (define_expand "sibcall_epilogue"
10910   [(use (const_int 0))]
10911   "TARGET_SCHED_PROLOG"
10912   "
10913 {
10914       rs6000_emit_epilogue (TRUE);
10915       DONE;
10916 }")
10917
10918 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
10919 ;; all of memory.  This blocks insns from being moved across this point.
10920
10921 (define_insn "blockage"
10922   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
10923   ""
10924   "")
10925 \f
10926 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
10927 ;; signed & unsigned, and one type of branch.
10928 ;;
10929 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
10930 ;; insns, and branches.  We store the operands of compares until we see
10931 ;; how it is used.
10932 (define_expand "cmp<mode>"
10933   [(set (cc0)
10934         (compare (match_operand:GPR 0 "gpc_reg_operand" "")
10935                  (match_operand:GPR 1 "reg_or_short_operand" "")))]
10936   ""
10937   "
10938 {
10939   /* Take care of the possibility that operands[1] might be negative but
10940      this might be a logical operation.  That insn doesn't exist.  */
10941   if (GET_CODE (operands[1]) == CONST_INT
10942       && INTVAL (operands[1]) < 0)
10943     operands[1] = force_reg (<MODE>mode, operands[1]);
10944
10945   rs6000_compare_op0 = operands[0];
10946   rs6000_compare_op1 = operands[1];
10947   rs6000_compare_fp_p = 0;
10948   DONE;
10949 }")
10950
10951 (define_expand "cmp<mode>"
10952   [(set (cc0) (compare (match_operand:FP 0 "gpc_reg_operand" "")
10953                        (match_operand:FP 1 "gpc_reg_operand" "")))]
10954   ""
10955   "
10956 {
10957   rs6000_compare_op0 = operands[0];
10958   rs6000_compare_op1 = operands[1];
10959   rs6000_compare_fp_p = 1;
10960   DONE;
10961 }")
10962
10963 (define_expand "beq"
10964   [(use (match_operand 0 "" ""))]
10965   ""
10966   "{ rs6000_emit_cbranch (EQ, operands[0]); DONE; }")
10967
10968 (define_expand "bne"
10969   [(use (match_operand 0 "" ""))]
10970   ""
10971   "{ rs6000_emit_cbranch (NE, operands[0]); DONE; }")
10972
10973 (define_expand "bge"
10974   [(use (match_operand 0 "" ""))]
10975   ""
10976   "{ rs6000_emit_cbranch (GE, operands[0]); DONE; }")
10977
10978 (define_expand "bgt"
10979   [(use (match_operand 0 "" ""))]
10980   ""
10981   "{ rs6000_emit_cbranch (GT, operands[0]); DONE; }")
10982
10983 (define_expand "ble"
10984   [(use (match_operand 0 "" ""))]
10985   ""
10986   "{ rs6000_emit_cbranch (LE, operands[0]); DONE; }")
10987
10988 (define_expand "blt"
10989   [(use (match_operand 0 "" ""))]
10990   ""
10991   "{ rs6000_emit_cbranch (LT, operands[0]); DONE; }")
10992
10993 (define_expand "bgeu"
10994   [(use (match_operand 0 "" ""))]
10995   ""
10996   "{ rs6000_emit_cbranch (GEU, operands[0]); DONE; }")
10997
10998 (define_expand "bgtu"
10999   [(use (match_operand 0 "" ""))]
11000   ""
11001   "{ rs6000_emit_cbranch (GTU, operands[0]); DONE; }")
11002
11003 (define_expand "bleu"
11004   [(use (match_operand 0 "" ""))]
11005   ""
11006   "{ rs6000_emit_cbranch (LEU, operands[0]); DONE; }")
11007
11008 (define_expand "bltu"
11009   [(use (match_operand 0 "" ""))]
11010   ""
11011   "{ rs6000_emit_cbranch (LTU, operands[0]); DONE; }")
11012
11013 (define_expand "bunordered"
11014   [(use (match_operand 0 "" ""))]
11015   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11016   "{ rs6000_emit_cbranch (UNORDERED, operands[0]); DONE; }")
11017
11018 (define_expand "bordered"
11019   [(use (match_operand 0 "" ""))]
11020   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11021   "{ rs6000_emit_cbranch (ORDERED, operands[0]); DONE; }")
11022
11023 (define_expand "buneq"
11024   [(use (match_operand 0 "" ""))]
11025   ""
11026   "{ rs6000_emit_cbranch (UNEQ, operands[0]); DONE; }")
11027
11028 (define_expand "bunge"
11029   [(use (match_operand 0 "" ""))]
11030   ""
11031   "{ rs6000_emit_cbranch (UNGE, operands[0]); DONE; }")
11032
11033 (define_expand "bungt"
11034   [(use (match_operand 0 "" ""))]
11035   ""
11036   "{ rs6000_emit_cbranch (UNGT, operands[0]); DONE; }")
11037
11038 (define_expand "bunle"
11039   [(use (match_operand 0 "" ""))]
11040   ""
11041   "{ rs6000_emit_cbranch (UNLE, operands[0]); DONE; }")
11042
11043 (define_expand "bunlt"
11044   [(use (match_operand 0 "" ""))]
11045   ""
11046   "{ rs6000_emit_cbranch (UNLT, operands[0]); DONE; }")
11047
11048 (define_expand "bltgt"
11049   [(use (match_operand 0 "" ""))]
11050   ""
11051   "{ rs6000_emit_cbranch (LTGT, operands[0]); DONE; }")
11052
11053 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
11054 ;; For SEQ, likewise, except that comparisons with zero should be done
11055 ;; with an scc insns.  However, due to the order that combine see the
11056 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
11057 ;; the cases we don't want to handle.
11058 (define_expand "seq"
11059   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11060   ""
11061   "{ rs6000_emit_sCOND (EQ, operands[0]); DONE; }")
11062
11063 (define_expand "sne"
11064   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11065   ""
11066   "
11067 {
11068   if (! rs6000_compare_fp_p)
11069     FAIL;
11070
11071   rs6000_emit_sCOND (NE, operands[0]);
11072   DONE;
11073 }")
11074
11075 ;; A >= 0 is best done the portable way for A an integer.
11076 (define_expand "sge"
11077   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11078   ""
11079   "
11080 {
11081   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11082     FAIL;
11083
11084   rs6000_emit_sCOND (GE, operands[0]);
11085   DONE;
11086 }")
11087
11088 ;; A > 0 is best done using the portable sequence, so fail in that case.
11089 (define_expand "sgt"
11090   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11091   ""
11092   "
11093 {
11094   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11095     FAIL;
11096
11097   rs6000_emit_sCOND (GT, operands[0]);
11098   DONE;
11099 }")
11100
11101 ;; A <= 0 is best done the portable way for A an integer.
11102 (define_expand "sle"
11103   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11104   ""
11105   "
11106 {
11107   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11108     FAIL;
11109
11110   rs6000_emit_sCOND (LE, operands[0]);
11111   DONE;
11112 }")
11113
11114 ;; A < 0 is best done in the portable way for A an integer.
11115 (define_expand "slt"
11116   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11117   ""
11118   "
11119 {
11120   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
11121     FAIL;
11122
11123   rs6000_emit_sCOND (LT, operands[0]);
11124   DONE;
11125 }")
11126
11127 (define_expand "sgeu"
11128   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11129   ""
11130   "{ rs6000_emit_sCOND (GEU, operands[0]); DONE; }")
11131
11132 (define_expand "sgtu"
11133   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11134   ""
11135   "{ rs6000_emit_sCOND (GTU, operands[0]); DONE; }")
11136
11137 (define_expand "sleu"
11138   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11139   ""
11140   "{ rs6000_emit_sCOND (LEU, operands[0]); DONE; }")
11141
11142 (define_expand "sltu"
11143   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11144   ""
11145   "{ rs6000_emit_sCOND (LTU, operands[0]); DONE; }")
11146
11147 (define_expand "sunordered"
11148   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11149   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11150   "{ rs6000_emit_sCOND (UNORDERED, operands[0]); DONE; }")
11151
11152 (define_expand "sordered"
11153   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11154   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11155   "{ rs6000_emit_sCOND (ORDERED, operands[0]); DONE; }")
11156
11157 (define_expand "suneq"
11158   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11159   ""
11160   "{ rs6000_emit_sCOND (UNEQ, operands[0]); DONE; }")
11161
11162 (define_expand "sunge"
11163   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11164   ""
11165   "{ rs6000_emit_sCOND (UNGE, operands[0]); DONE; }")
11166
11167 (define_expand "sungt"
11168   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11169   ""
11170   "{ rs6000_emit_sCOND (UNGT, operands[0]); DONE; }")
11171
11172 (define_expand "sunle"
11173   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11174   ""
11175   "{ rs6000_emit_sCOND (UNLE, operands[0]); DONE; }")
11176
11177 (define_expand "sunlt"
11178   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11179   ""
11180   "{ rs6000_emit_sCOND (UNLT, operands[0]); DONE; }")
11181
11182 (define_expand "sltgt"
11183   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11184   ""
11185   "{ rs6000_emit_sCOND (LTGT, operands[0]); DONE; }")
11186
11187 (define_expand "stack_protect_set"
11188   [(match_operand 0 "memory_operand" "")
11189    (match_operand 1 "memory_operand" "")]
11190   ""
11191 {
11192 #ifdef TARGET_THREAD_SSP_OFFSET
11193   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
11194   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
11195   operands[1] = gen_rtx_MEM (Pmode, addr);
11196 #endif
11197   if (TARGET_64BIT)
11198     emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
11199   else
11200     emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
11201   DONE;
11202 })
11203
11204 (define_insn "stack_protect_setsi"
11205   [(set (match_operand:SI 0 "memory_operand" "=m")
11206         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
11207    (set (match_scratch:SI 2 "=&r") (const_int 0))]
11208   "TARGET_32BIT"
11209   "{l%U1%X1|lwz%U1%X1} %2,%1\;{st%U0%X0|stw%U0%X0} %2,%0\;{lil|li} %2,0"
11210   [(set_attr "type" "three")
11211    (set_attr "length" "12")])
11212
11213 (define_insn "stack_protect_setdi"
11214   [(set (match_operand:DI 0 "memory_operand" "=m")
11215         (unspec:DI [(match_operand:DI 1 "memory_operand" "m")] UNSPEC_SP_SET))
11216    (set (match_scratch:DI 2 "=&r") (const_int 0))]
11217   "TARGET_64BIT"
11218   "ld%U1%X1 %2,%1\;std%U0%X0 %2,%0\;{lil|li} %2,0"
11219   [(set_attr "type" "three")
11220    (set_attr "length" "12")])
11221
11222 (define_expand "stack_protect_test"
11223   [(match_operand 0 "memory_operand" "")
11224    (match_operand 1 "memory_operand" "")
11225    (match_operand 2 "" "")]
11226   ""
11227 {
11228 #ifdef TARGET_THREAD_SSP_OFFSET
11229   rtx tlsreg = gen_rtx_REG (Pmode, TARGET_64BIT ? 13 : 2);
11230   rtx addr = gen_rtx_PLUS (Pmode, tlsreg, GEN_INT (TARGET_THREAD_SSP_OFFSET));
11231   operands[1] = gen_rtx_MEM (Pmode, addr);
11232 #endif
11233   rs6000_compare_op0 = operands[0];
11234   rs6000_compare_op1 = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, operands[1]),
11235                                        UNSPEC_SP_TEST);
11236   rs6000_compare_fp_p = 0;
11237   emit_jump_insn (gen_beq (operands[2]));
11238   DONE;
11239 })
11240
11241 (define_insn "stack_protect_testsi"
11242   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
11243         (unspec:CCEQ [(match_operand:SI 1 "memory_operand" "m,m")
11244                       (match_operand:SI 2 "memory_operand" "m,m")]
11245                      UNSPEC_SP_TEST))
11246    (set (match_scratch:SI 4 "=r,r") (const_int 0))
11247    (clobber (match_scratch:SI 3 "=&r,&r"))]
11248   "TARGET_32BIT"
11249   "@
11250    {l%U1%X1|lwz%U1%X1} %3,%1\;{l%U2%X2|lwz%U2%X2} %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
11251    {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"
11252   [(set_attr "length" "16,20")])
11253
11254 (define_insn "stack_protect_testdi"
11255   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
11256         (unspec:CCEQ [(match_operand:DI 1 "memory_operand" "m,m")
11257                       (match_operand:DI 2 "memory_operand" "m,m")]
11258                      UNSPEC_SP_TEST))
11259    (set (match_scratch:DI 4 "=r,r") (const_int 0))
11260    (clobber (match_scratch:DI 3 "=&r,&r"))]
11261   "TARGET_64BIT"
11262   "@
11263    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;xor. %3,%3,%4\;{lil|li} %4,0
11264    ld%U1%X1 %3,%1\;ld%U2%X2 %4,%2\;cmpld %0,%3,%4\;{lil|li} %3,0\;{lil|li} %4,0"
11265   [(set_attr "length" "16,20")])
11266
11267 \f
11268 ;; Here are the actual compare insns.
11269 (define_insn "*cmp<mode>_internal1"
11270   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11271         (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
11272                     (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
11273   ""
11274   "{cmp%I2|cmp<wd>%I2} %0,%1,%2"
11275   [(set_attr "type" "cmp")])
11276
11277 ;; If we are comparing a register for equality with a large constant,
11278 ;; we can do this with an XOR followed by a compare.  But this is profitable
11279 ;; only if the large constant is only used for the comparison (and in this
11280 ;; case we already have a register to reuse as scratch).
11281 ;;
11282 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
11283 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
11284
11285 (define_peephole2
11286   [(set (match_operand:SI 0 "register_operand")
11287         (match_operand:SI 1 "logical_const_operand" ""))
11288    (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
11289                        [(match_dup 0)
11290                         (match_operand:SI 2 "logical_const_operand" "")]))
11291    (set (match_operand:CC 4 "cc_reg_operand" "")
11292         (compare:CC (match_operand:SI 5 "gpc_reg_operand" "")
11293                     (match_dup 0)))
11294    (set (pc)
11295         (if_then_else (match_operator 6 "equality_operator"
11296                        [(match_dup 4) (const_int 0)])
11297                       (match_operand 7 "" "")
11298                       (match_operand 8 "" "")))]
11299   "peep2_reg_dead_p (3, operands[0])
11300    && peep2_reg_dead_p (4, operands[4])"
11301  [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
11302   (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
11303   (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
11304  
11305 {
11306   /* Get the constant we are comparing against, and see what it looks like
11307      when sign-extended from 16 to 32 bits.  Then see what constant we could
11308      XOR with SEXTC to get the sign-extended value.  */
11309   rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
11310                                               SImode,
11311                                               operands[1], operands[2]);
11312   HOST_WIDE_INT c = INTVAL (cnst);
11313   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
11314   HOST_WIDE_INT xorv = c ^ sextc;
11315
11316   operands[9] = GEN_INT (xorv);
11317   operands[10] = GEN_INT (sextc);
11318 })
11319
11320 (define_insn "*cmpsi_internal2"
11321   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11322         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11323                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
11324   ""
11325   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
11326   [(set_attr "type" "cmp")])
11327
11328 (define_insn "*cmpdi_internal2"
11329   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11330         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
11331                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
11332   ""
11333   "cmpld%I2 %0,%1,%b2"
11334   [(set_attr "type" "cmp")])
11335
11336 ;; The following two insns don't exist as single insns, but if we provide
11337 ;; them, we can swap an add and compare, which will enable us to overlap more
11338 ;; of the required delay between a compare and branch.  We generate code for
11339 ;; them by splitting.
11340
11341 (define_insn ""
11342   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11343         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11344                     (match_operand:SI 2 "short_cint_operand" "i")))
11345    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11346         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11347   ""
11348   "#"
11349   [(set_attr "length" "8")])
11350
11351 (define_insn ""
11352   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
11353         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11354                        (match_operand:SI 2 "u_short_cint_operand" "i")))
11355    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11356         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11357   ""
11358   "#"
11359   [(set_attr "length" "8")])
11360
11361 (define_split
11362   [(set (match_operand:CC 3 "cc_reg_operand" "")
11363         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11364                     (match_operand:SI 2 "short_cint_operand" "")))
11365    (set (match_operand:SI 0 "gpc_reg_operand" "")
11366         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11367   ""
11368   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
11369    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11370
11371 (define_split
11372   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
11373         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
11374                        (match_operand:SI 2 "u_short_cint_operand" "")))
11375    (set (match_operand:SI 0 "gpc_reg_operand" "")
11376         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11377   ""
11378   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
11379    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11380
11381 (define_insn "*cmpsf_internal1"
11382   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11383         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
11384                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
11385   "TARGET_HARD_FLOAT && TARGET_FPRS"
11386   "fcmpu %0,%1,%2"
11387   [(set_attr "type" "fpcompare")])
11388
11389 (define_insn "*cmpdf_internal1"
11390   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11391         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
11392                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
11393   "TARGET_HARD_FLOAT && TARGET_FPRS"
11394   "fcmpu %0,%1,%2"
11395   [(set_attr "type" "fpcompare")])
11396
11397 ;; Only need to compare second words if first words equal
11398 (define_insn "*cmptf_internal1"
11399   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11400         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11401                       (match_operand:TF 2 "gpc_reg_operand" "f")))]
11402   "!TARGET_IEEEQUAD && !TARGET_XL_COMPAT
11403    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11404   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
11405   [(set_attr "type" "fpcompare")
11406    (set_attr "length" "12")])
11407
11408 (define_insn_and_split "*cmptf_internal2"
11409   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11410         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11411                       (match_operand:TF 2 "gpc_reg_operand" "f")))
11412     (clobber (match_scratch:DF 3 "=f"))
11413     (clobber (match_scratch:DF 4 "=f"))
11414     (clobber (match_scratch:DF 5 "=f"))
11415     (clobber (match_scratch:DF 6 "=f"))
11416     (clobber (match_scratch:DF 7 "=f"))
11417     (clobber (match_scratch:DF 8 "=f"))
11418     (clobber (match_scratch:DF 9 "=f"))
11419     (clobber (match_scratch:DF 10 "=f"))]
11420   "!TARGET_IEEEQUAD && TARGET_XL_COMPAT
11421    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11422   "#"
11423   "&& reload_completed"
11424   [(set (match_dup 3) (match_dup 13))
11425    (set (match_dup 4) (match_dup 14))
11426    (set (match_dup 9) (abs:DF (match_dup 5)))
11427    (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
11428    (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
11429                            (label_ref (match_dup 11))
11430                            (pc)))
11431    (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
11432    (set (pc) (label_ref (match_dup 12)))
11433    (match_dup 11)
11434    (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
11435    (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
11436    (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
11437    (set (match_dup 0) (compare:CCFP (match_dup 7) (match_dup 4)))
11438    (match_dup 12)]
11439 {
11440   REAL_VALUE_TYPE rv;
11441   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
11442   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
11443
11444   operands[5] = simplify_gen_subreg (DFmode, operands[1], TFmode, hi_word);
11445   operands[6] = simplify_gen_subreg (DFmode, operands[1], TFmode, lo_word);
11446   operands[7] = simplify_gen_subreg (DFmode, operands[2], TFmode, hi_word);
11447   operands[8] = simplify_gen_subreg (DFmode, operands[2], TFmode, lo_word);
11448   operands[11] = gen_label_rtx ();
11449   operands[12] = gen_label_rtx ();
11450   real_inf (&rv);
11451   operands[13] = force_const_mem (DFmode,
11452                                   CONST_DOUBLE_FROM_REAL_VALUE (rv, DFmode));
11453   operands[14] = force_const_mem (DFmode,
11454                                   CONST_DOUBLE_FROM_REAL_VALUE (dconst0,
11455                                                                 DFmode));
11456   if (TARGET_TOC)
11457     {
11458       operands[13] = gen_const_mem (DFmode,
11459                                     create_TOC_reference (XEXP (operands[13], 0)));
11460       operands[14] = gen_const_mem (DFmode,
11461                                     create_TOC_reference (XEXP (operands[14], 0)));
11462       set_mem_alias_set (operands[13], get_TOC_alias_set ());
11463       set_mem_alias_set (operands[14], get_TOC_alias_set ());
11464     }
11465 })
11466 \f
11467 ;; Now we have the scc insns.  We can do some combinations because of the
11468 ;; way the machine works.
11469 ;;
11470 ;; Note that this is probably faster if we can put an insn between the
11471 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
11472 ;; cases the insns below which don't use an intermediate CR field will
11473 ;; be used instead.
11474 (define_insn ""
11475   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11476         (match_operator:SI 1 "scc_comparison_operator"
11477                            [(match_operand 2 "cc_reg_operand" "y")
11478                             (const_int 0)]))]
11479   ""
11480   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11481   [(set (attr "type")
11482      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11483                 (const_string "mfcrf")
11484            ]
11485         (const_string "mfcr")))
11486    (set_attr "length" "8")])
11487
11488 ;; Same as above, but get the GT bit.
11489 (define_insn "move_from_CR_gt_bit"
11490   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11491         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_GT))]
11492   "TARGET_E500"
11493   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,31,31"
11494   [(set_attr "type" "mfcr")
11495    (set_attr "length" "8")])
11496
11497 ;; Same as above, but get the OV/ORDERED bit.
11498 (define_insn "move_from_CR_ov_bit"
11499   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11500         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
11501   "TARGET_ISEL"
11502   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
11503   [(set_attr "type" "mfcr")
11504    (set_attr "length" "8")])
11505
11506 (define_insn ""
11507   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11508         (match_operator:DI 1 "scc_comparison_operator"
11509                            [(match_operand 2 "cc_reg_operand" "y")
11510                             (const_int 0)]))]
11511   "TARGET_POWERPC64"
11512   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11513   [(set (attr "type")
11514      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11515                 (const_string "mfcrf")
11516            ]
11517         (const_string "mfcr")))
11518    (set_attr "length" "8")])
11519
11520 (define_insn ""
11521   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11522         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11523                                        [(match_operand 2 "cc_reg_operand" "y,y")
11524                                         (const_int 0)])
11525                     (const_int 0)))
11526    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11527         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11528   "TARGET_32BIT"
11529   "@
11530    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
11531    #"
11532   [(set_attr "type" "delayed_compare")
11533    (set_attr "length" "8,16")])
11534
11535 (define_split
11536   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11537         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11538                                        [(match_operand 2 "cc_reg_operand" "")
11539                                         (const_int 0)])
11540                     (const_int 0)))
11541    (set (match_operand:SI 3 "gpc_reg_operand" "")
11542         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11543   "TARGET_32BIT && reload_completed"
11544   [(set (match_dup 3)
11545         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
11546    (set (match_dup 0)
11547         (compare:CC (match_dup 3)
11548                     (const_int 0)))]
11549   "")
11550
11551 (define_insn ""
11552   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11553         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11554                                       [(match_operand 2 "cc_reg_operand" "y")
11555                                        (const_int 0)])
11556                    (match_operand:SI 3 "const_int_operand" "n")))]
11557   ""
11558   "*
11559 {
11560   int is_bit = ccr_bit (operands[1], 1);
11561   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11562   int count;
11563
11564   if (is_bit >= put_bit)
11565     count = is_bit - put_bit;
11566   else
11567     count = 32 - (put_bit - is_bit);
11568
11569   operands[4] = GEN_INT (count);
11570   operands[5] = GEN_INT (put_bit);
11571
11572   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
11573 }"
11574   [(set (attr "type")
11575      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11576                 (const_string "mfcrf")
11577            ]
11578         (const_string "mfcr")))
11579    (set_attr "length" "8")])
11580
11581 (define_insn ""
11582   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11583         (compare:CC
11584          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11585                                        [(match_operand 2 "cc_reg_operand" "y,y")
11586                                         (const_int 0)])
11587                     (match_operand:SI 3 "const_int_operand" "n,n"))
11588          (const_int 0)))
11589    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
11590         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11591                    (match_dup 3)))]
11592   ""
11593   "*
11594 {
11595   int is_bit = ccr_bit (operands[1], 1);
11596   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11597   int count;
11598
11599   /* Force split for non-cc0 compare.  */
11600   if (which_alternative == 1)
11601      return \"#\";
11602
11603   if (is_bit >= put_bit)
11604     count = is_bit - put_bit;
11605   else
11606     count = 32 - (put_bit - is_bit);
11607
11608   operands[5] = GEN_INT (count);
11609   operands[6] = GEN_INT (put_bit);
11610
11611   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
11612 }"
11613   [(set_attr "type" "delayed_compare")
11614    (set_attr "length" "8,16")])
11615
11616 (define_split
11617   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11618         (compare:CC
11619          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11620                                        [(match_operand 2 "cc_reg_operand" "")
11621                                         (const_int 0)])
11622                     (match_operand:SI 3 "const_int_operand" ""))
11623          (const_int 0)))
11624    (set (match_operand:SI 4 "gpc_reg_operand" "")
11625         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11626                    (match_dup 3)))]
11627   "reload_completed"
11628   [(set (match_dup 4)
11629         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11630                    (match_dup 3)))
11631    (set (match_dup 0)
11632         (compare:CC (match_dup 4)
11633                     (const_int 0)))]
11634   "")
11635
11636 ;; There is a 3 cycle delay between consecutive mfcr instructions
11637 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
11638
11639 (define_peephole
11640   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11641         (match_operator:SI 1 "scc_comparison_operator"
11642                            [(match_operand 2 "cc_reg_operand" "y")
11643                             (const_int 0)]))
11644    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
11645         (match_operator:SI 4 "scc_comparison_operator"
11646                            [(match_operand 5 "cc_reg_operand" "y")
11647                             (const_int 0)]))]
11648   "REGNO (operands[2]) != REGNO (operands[5])"
11649   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11650   [(set_attr "type" "mfcr")
11651    (set_attr "length" "12")])
11652
11653 (define_peephole
11654   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11655         (match_operator:DI 1 "scc_comparison_operator"
11656                            [(match_operand 2 "cc_reg_operand" "y")
11657                             (const_int 0)]))
11658    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
11659         (match_operator:DI 4 "scc_comparison_operator"
11660                            [(match_operand 5 "cc_reg_operand" "y")
11661                             (const_int 0)]))]
11662   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
11663   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11664   [(set_attr "type" "mfcr")
11665    (set_attr "length" "12")])
11666
11667 ;; There are some scc insns that can be done directly, without a compare.
11668 ;; These are faster because they don't involve the communications between
11669 ;; the FXU and branch units.   In fact, we will be replacing all of the
11670 ;; integer scc insns here or in the portable methods in emit_store_flag.
11671 ;;
11672 ;; Also support (neg (scc ..)) since that construct is used to replace
11673 ;; branches, (plus (scc ..) ..) since that construct is common and
11674 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
11675 ;; cases where it is no more expensive than (neg (scc ..)).
11676
11677 ;; Have reload force a constant into a register for the simple insns that
11678 ;; otherwise won't accept constants.  We do this because it is faster than
11679 ;; the cmp/mfcr sequence we would otherwise generate.
11680
11681 (define_mode_attr scc_eq_op2 [(SI "rKLI")
11682                               (DI "rKJI")])
11683
11684 (define_insn_and_split "*eq<mode>"
11685   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
11686         (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
11687                 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))]
11688   "!TARGET_POWER"
11689   "#"
11690   "!TARGET_POWER"
11691   [(set (match_dup 0)
11692         (clz:GPR (match_dup 3)))
11693    (set (match_dup 0)
11694         (lshiftrt:GPR (match_dup 0) (match_dup 4)))]
11695   {
11696     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
11697       {
11698         /* Use output operand as intermediate.  */
11699         operands[3] = operands[0];
11700
11701         if (logical_operand (operands[2], <MODE>mode))
11702           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
11703                                   gen_rtx_XOR (<MODE>mode,
11704                                                operands[1], operands[2])));
11705         else
11706           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
11707                                   gen_rtx_PLUS (<MODE>mode, operands[1],
11708                                                 negate_rtx (<MODE>mode,
11709                                                             operands[2]))));
11710       }
11711     else
11712       operands[3] = operands[1];
11713
11714     operands[4] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
11715   })
11716
11717 (define_insn_and_split "*eq<mode>_compare"
11718   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11719         (compare:CC
11720          (eq:P (match_operand:P 1 "gpc_reg_operand" "=r")
11721                (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
11722          (const_int 0)))
11723    (set (match_operand:P 0 "gpc_reg_operand" "=r")
11724         (eq:P (match_dup 1) (match_dup 2)))]
11725   "!TARGET_POWER && optimize_size"
11726   "#"
11727   "!TARGET_POWER && optimize_size"
11728   [(set (match_dup 0)
11729         (clz:P (match_dup 4)))
11730    (parallel [(set (match_dup 3)
11731                    (compare:CC (lshiftrt:P (match_dup 0) (match_dup 5))
11732                                (const_int 0)))
11733               (set (match_dup 0)
11734                    (lshiftrt:P (match_dup 0) (match_dup 5)))])]
11735   {
11736     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
11737       {
11738         /* Use output operand as intermediate.  */
11739         operands[4] = operands[0];
11740
11741         if (logical_operand (operands[2], <MODE>mode))
11742           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
11743                                   gen_rtx_XOR (<MODE>mode,
11744                                                operands[1], operands[2])));
11745         else
11746           emit_insn (gen_rtx_SET (VOIDmode, operands[4],
11747                                   gen_rtx_PLUS (<MODE>mode, operands[1],
11748                                                 negate_rtx (<MODE>mode,
11749                                                             operands[2]))));
11750       }
11751     else
11752       operands[4] = operands[1];
11753
11754     operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
11755   })
11756
11757 (define_insn "*eqsi_power"
11758   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11759         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11760                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
11761    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
11762   "TARGET_POWER"
11763   "@
11764    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11765    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
11766    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11767    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11768    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
11769   [(set_attr "type" "three,two,three,three,three")
11770    (set_attr "length" "12,8,12,12,12")])
11771
11772 ;; We have insns of the form shown by the first define_insn below.  If
11773 ;; there is something inside the comparison operation, we must split it.
11774 (define_split
11775   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11776         (plus:SI (match_operator 1 "comparison_operator"
11777                                  [(match_operand:SI 2 "" "")
11778                                   (match_operand:SI 3
11779                                                     "reg_or_cint_operand" "")])
11780                  (match_operand:SI 4 "gpc_reg_operand" "")))
11781    (clobber (match_operand:SI 5 "register_operand" ""))]
11782   "! gpc_reg_operand (operands[2], SImode)"
11783   [(set (match_dup 5) (match_dup 2))
11784    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
11785                                (match_dup 4)))])
11786
11787 (define_insn "*plus_eqsi"
11788   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
11789         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11790                         (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I"))
11791                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
11792   "TARGET_32BIT"
11793   "@
11794    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11795    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
11796    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11797    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11798    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
11799   [(set_attr "type" "three,two,three,three,three")
11800    (set_attr "length" "12,8,12,12,12")])
11801
11802 (define_insn "*compare_plus_eqsi"
11803   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11804         (compare:CC
11805          (plus:SI
11806           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11807                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
11808           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11809          (const_int 0)))
11810    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
11811   "TARGET_32BIT && optimize_size"
11812   "@
11813    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11814    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
11815    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11816    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11817    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11818    #
11819    #
11820    #
11821    #
11822    #"
11823   [(set_attr "type" "compare")
11824    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11825
11826 (define_split
11827   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11828         (compare:CC
11829          (plus:SI
11830           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11831                  (match_operand:SI 2 "scc_eq_operand" ""))
11832           (match_operand:SI 3 "gpc_reg_operand" ""))
11833          (const_int 0)))
11834    (clobber (match_scratch:SI 4 ""))]
11835   "TARGET_32BIT && optimize_size && reload_completed"
11836   [(set (match_dup 4)
11837         (plus:SI (eq:SI (match_dup 1)
11838                  (match_dup 2))
11839           (match_dup 3)))
11840    (set (match_dup 0)
11841         (compare:CC (match_dup 4)
11842                     (const_int 0)))]
11843   "")
11844
11845 (define_insn "*plus_eqsi_compare"
11846   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11847         (compare:CC
11848          (plus:SI
11849           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11850                  (match_operand:SI 2 "scc_eq_operand" "r,O,K,L,I,r,O,K,L,I"))
11851           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11852          (const_int 0)))
11853    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
11854         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11855   "TARGET_32BIT && optimize_size"
11856   "@
11857    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11858    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
11859    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11860    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11861    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11862    #
11863    #
11864    #
11865    #
11866    #"
11867   [(set_attr "type" "compare")
11868    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11869
11870 (define_split
11871   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11872         (compare:CC
11873          (plus:SI
11874           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11875                  (match_operand:SI 2 "scc_eq_operand" ""))
11876           (match_operand:SI 3 "gpc_reg_operand" ""))
11877          (const_int 0)))
11878    (set (match_operand:SI 0 "gpc_reg_operand" "")
11879         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11880   "TARGET_32BIT && optimize_size && reload_completed"
11881   [(set (match_dup 0)
11882         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
11883    (set (match_dup 4)
11884         (compare:CC (match_dup 0)
11885                     (const_int 0)))]
11886   "")
11887
11888 (define_insn "*neg_eq0<mode>"
11889   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
11890         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
11891                      (const_int 0))))]
11892   ""
11893   "{ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0"
11894   [(set_attr "type" "two")
11895    (set_attr "length" "8")])
11896
11897 (define_insn_and_split "*neg_eq<mode>"
11898   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
11899         (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "%r")
11900                      (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))]
11901   ""
11902   "#"
11903   ""
11904   [(set (match_dup 0) (neg:P (eq:P (match_dup 3) (const_int 0))))]
11905   {
11906     if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)
11907       {
11908         /* Use output operand as intermediate.  */
11909         operands[3] = operands[0];
11910
11911         if (logical_operand (operands[2], <MODE>mode))
11912           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
11913                                   gen_rtx_XOR (<MODE>mode,
11914                                                operands[1], operands[2])));
11915         else
11916           emit_insn (gen_rtx_SET (VOIDmode, operands[3],
11917                                   gen_rtx_PLUS (<MODE>mode, operands[1],
11918                                                 negate_rtx (<MODE>mode,
11919                                                             operands[2]))));
11920       }
11921     else
11922       operands[3] = operands[1];
11923   })
11924
11925 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
11926 ;; since it nabs/sr is just as fast.
11927 (define_insn "*ne0si"
11928   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
11929         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11930                      (const_int 31)))
11931    (clobber (match_scratch:SI 2 "=&r"))]
11932   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
11933   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
11934   [(set_attr "type" "two")
11935    (set_attr "length" "8")])
11936
11937 (define_insn "*ne0di"
11938   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11939         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11940                      (const_int 63)))
11941    (clobber (match_scratch:DI 2 "=&r"))]
11942   "TARGET_64BIT"
11943   "addic %2,%1,-1\;subfe %0,%2,%1"
11944   [(set_attr "type" "two")
11945    (set_attr "length" "8")])
11946
11947 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
11948 (define_insn "*plus_ne0si"
11949   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11950         (plus:SI (lshiftrt:SI
11951                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11952                   (const_int 31))
11953                  (match_operand:SI 2 "gpc_reg_operand" "r")))
11954    (clobber (match_scratch:SI 3 "=&r"))]
11955   "TARGET_32BIT"
11956   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
11957   [(set_attr "type" "two")
11958    (set_attr "length" "8")])
11959
11960 (define_insn "*plus_ne0di"
11961   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11962         (plus:DI (lshiftrt:DI
11963                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11964                   (const_int 63))
11965                  (match_operand:DI 2 "gpc_reg_operand" "r")))
11966    (clobber (match_scratch:DI 3 "=&r"))]
11967   "TARGET_64BIT"
11968   "addic %3,%1,-1\;addze %0,%2"
11969   [(set_attr "type" "two")
11970    (set_attr "length" "8")])
11971
11972 (define_insn "*compare_plus_ne0si"
11973   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11974         (compare:CC
11975          (plus:SI (lshiftrt:SI
11976                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11977                    (const_int 31))
11978                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11979          (const_int 0)))
11980    (clobber (match_scratch:SI 3 "=&r,&r"))
11981    (clobber (match_scratch:SI 4 "=X,&r"))]
11982   "TARGET_32BIT"
11983   "@
11984    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
11985    #"
11986   [(set_attr "type" "compare")
11987    (set_attr "length" "8,12")])
11988
11989 (define_split
11990   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11991         (compare:CC
11992          (plus:SI (lshiftrt:SI
11993                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11994                    (const_int 31))
11995                   (match_operand:SI 2 "gpc_reg_operand" ""))
11996          (const_int 0)))
11997    (clobber (match_scratch:SI 3 ""))
11998    (clobber (match_scratch:SI 4 ""))]
11999   "TARGET_32BIT && reload_completed"
12000   [(parallel [(set (match_dup 3)
12001                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
12002                                          (const_int 31))
12003                             (match_dup 2)))
12004               (clobber (match_dup 4))])
12005    (set (match_dup 0)
12006         (compare:CC (match_dup 3)
12007                     (const_int 0)))]
12008   "")
12009
12010 (define_insn "*compare_plus_ne0di"
12011   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12012         (compare:CC
12013          (plus:DI (lshiftrt:DI
12014                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
12015                    (const_int 63))
12016                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12017          (const_int 0)))
12018    (clobber (match_scratch:DI 3 "=&r,&r"))]
12019   "TARGET_64BIT"
12020   "@
12021    addic %3,%1,-1\;addze. %3,%2
12022    #"
12023   [(set_attr "type" "compare")
12024    (set_attr "length" "8,12")])
12025
12026 (define_split
12027   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12028         (compare:CC
12029          (plus:DI (lshiftrt:DI
12030                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
12031                    (const_int 63))
12032                   (match_operand:DI 2 "gpc_reg_operand" ""))
12033          (const_int 0)))
12034    (clobber (match_scratch:DI 3 ""))]
12035   "TARGET_64BIT && reload_completed"
12036   [(set (match_dup 3)
12037         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
12038                    (const_int 63))
12039                   (match_dup 2)))
12040    (set (match_dup 0)
12041         (compare:CC (match_dup 3)
12042                     (const_int 0)))]
12043   "")
12044
12045 (define_insn "*plus_ne0si_compare"
12046   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12047         (compare:CC
12048          (plus:SI (lshiftrt:SI
12049                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
12050                    (const_int 31))
12051                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
12052          (const_int 0)))
12053    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12054         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
12055                  (match_dup 2)))
12056    (clobber (match_scratch:SI 3 "=&r,&r"))]
12057   "TARGET_32BIT"
12058   "@
12059    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
12060    #"
12061   [(set_attr "type" "compare")
12062    (set_attr "length" "8,12")])
12063
12064 (define_split
12065   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12066         (compare:CC
12067          (plus:SI (lshiftrt:SI
12068                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
12069                    (const_int 31))
12070                   (match_operand:SI 2 "gpc_reg_operand" ""))
12071          (const_int 0)))
12072    (set (match_operand:SI 0 "gpc_reg_operand" "")
12073         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
12074                  (match_dup 2)))
12075    (clobber (match_scratch:SI 3 ""))]
12076   "TARGET_32BIT && reload_completed"
12077   [(parallel [(set (match_dup 0)
12078         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
12079                  (match_dup 2)))
12080    (clobber (match_dup 3))])
12081    (set (match_dup 4)
12082         (compare:CC (match_dup 0)
12083                     (const_int 0)))]
12084   "")
12085
12086 (define_insn "*plus_ne0di_compare"
12087   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12088         (compare:CC
12089          (plus:DI (lshiftrt:DI
12090                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
12091                    (const_int 63))
12092                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12093          (const_int 0)))
12094    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12095         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12096                  (match_dup 2)))
12097    (clobber (match_scratch:DI 3 "=&r,&r"))]
12098   "TARGET_64BIT"
12099   "@
12100    addic %3,%1,-1\;addze. %0,%2
12101    #"
12102   [(set_attr "type" "compare")
12103    (set_attr "length" "8,12")])
12104
12105 (define_split
12106   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12107         (compare:CC
12108          (plus:DI (lshiftrt:DI
12109                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
12110                    (const_int 63))
12111                   (match_operand:DI 2 "gpc_reg_operand" ""))
12112          (const_int 0)))
12113    (set (match_operand:DI 0 "gpc_reg_operand" "")
12114         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12115                  (match_dup 2)))
12116    (clobber (match_scratch:DI 3 ""))]
12117   "TARGET_64BIT && reload_completed"
12118   [(parallel [(set (match_dup 0)
12119         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12120                  (match_dup 2)))
12121    (clobber (match_dup 3))])
12122    (set (match_dup 4)
12123         (compare:CC (match_dup 0)
12124                     (const_int 0)))]
12125   "")
12126
12127 (define_insn ""
12128   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12129         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12130                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
12131    (clobber (match_scratch:SI 3 "=r,X"))]
12132   "TARGET_POWER"
12133   "@
12134    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
12135    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
12136   [(set_attr "length" "12")])
12137
12138 (define_insn ""
12139   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12140         (compare:CC
12141          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12142                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12143          (const_int 0)))
12144    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12145         (le:SI (match_dup 1) (match_dup 2)))
12146    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
12147   "TARGET_POWER"
12148   "@
12149    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12150    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
12151    #
12152    #"
12153   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
12154    (set_attr "length" "12,12,16,16")])
12155
12156 (define_split
12157   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12158         (compare:CC
12159          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12160                 (match_operand:SI 2 "reg_or_short_operand" ""))
12161          (const_int 0)))
12162    (set (match_operand:SI 0 "gpc_reg_operand" "")
12163         (le:SI (match_dup 1) (match_dup 2)))
12164    (clobber (match_scratch:SI 3 ""))]
12165   "TARGET_POWER && reload_completed"
12166   [(parallel [(set (match_dup 0)
12167         (le:SI (match_dup 1) (match_dup 2)))
12168    (clobber (match_dup 3))])
12169    (set (match_dup 4)
12170         (compare:CC (match_dup 0)
12171                     (const_int 0)))]
12172   "")
12173
12174 (define_insn ""
12175   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12176         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12177                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
12178                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12179   "TARGET_POWER"
12180   "@
12181    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
12182    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
12183   [(set_attr "length" "12")])
12184
12185 (define_insn ""
12186   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12187         (compare:CC
12188          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12189                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12190                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12191          (const_int 0)))
12192    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12193   "TARGET_POWER"
12194   "@
12195    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12196    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
12197    #
12198    #"
12199   [(set_attr "type" "compare")
12200    (set_attr "length" "12,12,16,16")])
12201
12202 (define_split
12203   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12204         (compare:CC
12205          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12206                          (match_operand:SI 2 "reg_or_short_operand" ""))
12207                   (match_operand:SI 3 "gpc_reg_operand" ""))
12208          (const_int 0)))
12209    (clobber (match_scratch:SI 4 ""))]
12210   "TARGET_POWER && reload_completed"
12211   [(set (match_dup 4)
12212         (plus:SI (le:SI (match_dup 1) (match_dup 2))
12213                  (match_dup 3)))
12214    (set (match_dup 0)
12215         (compare:CC (match_dup 4)
12216                     (const_int 0)))]
12217   "")
12218
12219 (define_insn ""
12220   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12221         (compare:CC
12222          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12223                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12224                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12225          (const_int 0)))
12226    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12227         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12228   "TARGET_POWER"
12229   "@
12230    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12231    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
12232    #
12233    #"
12234   [(set_attr "type" "compare")
12235    (set_attr "length" "12,12,16,16")])
12236
12237 (define_split
12238   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12239         (compare:CC
12240          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12241                          (match_operand:SI 2 "reg_or_short_operand" ""))
12242                   (match_operand:SI 3 "gpc_reg_operand" ""))
12243          (const_int 0)))
12244    (set (match_operand:SI 0 "gpc_reg_operand" "")
12245         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12246   "TARGET_POWER && reload_completed"
12247   [(set (match_dup 0)
12248         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12249    (set (match_dup 4)
12250         (compare:CC (match_dup 0)
12251                     (const_int 0)))]
12252   "")
12253
12254 (define_insn ""
12255   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12256         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12257                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
12258   "TARGET_POWER"
12259   "@
12260    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
12261    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
12262   [(set_attr "length" "12")])
12263
12264 (define_insn "*leu<mode>"
12265   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12266         (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12267                (match_operand:P 2 "reg_or_short_operand" "rI")))]
12268   ""
12269   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12270   [(set_attr "type" "three")
12271    (set_attr "length" "12")])
12272
12273 (define_insn "*leu<mode>_compare"
12274   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12275         (compare:CC
12276          (leu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12277                 (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
12278          (const_int 0)))
12279    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12280         (leu:P (match_dup 1) (match_dup 2)))]
12281   ""
12282   "@
12283    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12284    #"
12285   [(set_attr "type" "compare")
12286    (set_attr "length" "12,16")])
12287
12288 (define_split
12289   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12290         (compare:CC
12291          (leu:P (match_operand:P 1 "gpc_reg_operand" "")
12292                 (match_operand:P 2 "reg_or_short_operand" ""))
12293          (const_int 0)))
12294    (set (match_operand:P 0 "gpc_reg_operand" "")
12295         (leu:P (match_dup 1) (match_dup 2)))]
12296   "reload_completed"
12297   [(set (match_dup 0)
12298         (leu:P (match_dup 1) (match_dup 2)))
12299    (set (match_dup 3)
12300         (compare:CC (match_dup 0)
12301                     (const_int 0)))]
12302   "")
12303
12304 (define_insn "*plus_leu<mode>"
12305   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12306         (plus:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12307                        (match_operand:P 2 "reg_or_short_operand" "rI"))
12308                 (match_operand:P 3 "gpc_reg_operand" "r")))]
12309   ""
12310   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
12311   [(set_attr "type" "two")
12312    (set_attr "length" "8")])
12313
12314 (define_insn ""
12315   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12316         (compare:CC
12317          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12318                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12319                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12320          (const_int 0)))
12321    (clobber (match_scratch:SI 4 "=&r,&r"))]
12322   "TARGET_32BIT"
12323   "@
12324    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
12325    #"
12326   [(set_attr "type" "compare")
12327    (set_attr "length" "8,12")])
12328
12329 (define_split
12330   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12331         (compare:CC
12332          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12333                           (match_operand:SI 2 "reg_or_short_operand" ""))
12334                   (match_operand:SI 3 "gpc_reg_operand" ""))
12335          (const_int 0)))
12336    (clobber (match_scratch:SI 4 ""))]
12337   "TARGET_32BIT && reload_completed"
12338   [(set (match_dup 4)
12339         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12340                   (match_dup 3)))
12341    (set (match_dup 0)
12342         (compare:CC (match_dup 4)
12343                     (const_int 0)))]
12344   "")
12345
12346 (define_insn ""
12347   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12348         (compare:CC
12349          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12350                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12351                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12352          (const_int 0)))
12353    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12354         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12355   "TARGET_32BIT"
12356   "@
12357    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
12358    #"
12359   [(set_attr "type" "compare")
12360    (set_attr "length" "8,12")])
12361
12362 (define_split
12363   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12364         (compare:CC
12365          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12366                           (match_operand:SI 2 "reg_or_short_operand" ""))
12367                   (match_operand:SI 3 "gpc_reg_operand" ""))
12368          (const_int 0)))
12369    (set (match_operand:SI 0 "gpc_reg_operand" "")
12370         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12371   "TARGET_32BIT && reload_completed"
12372   [(set (match_dup 0)
12373         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12374    (set (match_dup 4)
12375         (compare:CC (match_dup 0)
12376                     (const_int 0)))]
12377   "")
12378
12379 (define_insn "*neg_leu<mode>"
12380   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12381         (neg:P (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12382                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
12383   ""
12384   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
12385    [(set_attr "type" "three")
12386     (set_attr "length" "12")])
12387
12388 (define_insn "*and_neg_leu<mode>"
12389   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
12390         (and:P (neg:P
12391                  (leu:P (match_operand:P 1 "gpc_reg_operand" "r")
12392                         (match_operand:P 2 "reg_or_short_operand" "rI")))
12393                 (match_operand:P 3 "gpc_reg_operand" "r")))]
12394   ""
12395   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12396   [(set_attr "type" "three")
12397    (set_attr "length" "12")])
12398
12399 (define_insn ""
12400   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12401         (compare:CC
12402          (and:SI (neg:SI
12403                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12404                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12405                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12406          (const_int 0)))
12407    (clobber (match_scratch:SI 4 "=&r,&r"))]
12408   "TARGET_32BIT"
12409   "@
12410    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12411    #"
12412   [(set_attr "type" "compare")
12413    (set_attr "length" "12,16")])
12414
12415 (define_split
12416   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12417         (compare:CC
12418          (and:SI (neg:SI
12419                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12420                           (match_operand:SI 2 "reg_or_short_operand" "")))
12421                  (match_operand:SI 3 "gpc_reg_operand" ""))
12422          (const_int 0)))
12423    (clobber (match_scratch:SI 4 ""))]
12424   "TARGET_32BIT && reload_completed"
12425   [(set (match_dup 4)
12426         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12427                 (match_dup 3)))
12428    (set (match_dup 0)
12429         (compare:CC (match_dup 4)
12430                     (const_int 0)))]
12431   "")
12432
12433 (define_insn ""
12434   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12435         (compare:CC
12436          (and:SI (neg:SI
12437                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12438                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12439                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12440          (const_int 0)))
12441    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12442         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12443   "TARGET_32BIT"
12444   "@
12445    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12446    #"
12447   [(set_attr "type" "compare")
12448    (set_attr "length" "12,16")])
12449
12450 (define_split
12451   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12452         (compare:CC
12453          (and:SI (neg:SI
12454                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12455                           (match_operand:SI 2 "reg_or_short_operand" "")))
12456                  (match_operand:SI 3 "gpc_reg_operand" ""))
12457          (const_int 0)))
12458    (set (match_operand:SI 0 "gpc_reg_operand" "")
12459         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12460   "TARGET_32BIT && reload_completed"
12461   [(set (match_dup 0)
12462         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12463                 (match_dup 3)))
12464    (set (match_dup 4)
12465         (compare:CC (match_dup 0)
12466                     (const_int 0)))]
12467   "")
12468
12469 (define_insn ""
12470   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12471         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12472                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12473   "TARGET_POWER"
12474   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
12475    [(set_attr "length" "12")])
12476
12477 (define_insn ""
12478   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12479         (compare:CC
12480          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12481                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12482          (const_int 0)))
12483    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12484         (lt:SI (match_dup 1) (match_dup 2)))]
12485   "TARGET_POWER"
12486   "@
12487    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
12488    #"
12489   [(set_attr "type" "delayed_compare")
12490    (set_attr "length" "12,16")])
12491
12492 (define_split
12493   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12494         (compare:CC
12495          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12496                 (match_operand:SI 2 "reg_or_short_operand" ""))
12497          (const_int 0)))
12498    (set (match_operand:SI 0 "gpc_reg_operand" "")
12499         (lt:SI (match_dup 1) (match_dup 2)))]
12500   "TARGET_POWER && reload_completed"
12501   [(set (match_dup 0)
12502         (lt:SI (match_dup 1) (match_dup 2)))
12503    (set (match_dup 3)
12504         (compare:CC (match_dup 0)
12505                     (const_int 0)))]
12506   "")
12507
12508 (define_insn ""
12509   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12510         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12511                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12512                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12513   "TARGET_POWER"
12514   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
12515   [(set_attr "length" "12")])
12516
12517 (define_insn ""
12518   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12519         (compare:CC
12520          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12521                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12522                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12523          (const_int 0)))
12524    (clobber (match_scratch:SI 4 "=&r,&r"))]
12525   "TARGET_POWER"
12526   "@
12527    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
12528    #"
12529   [(set_attr "type" "compare")
12530    (set_attr "length" "12,16")])
12531
12532 (define_split
12533   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12534         (compare:CC
12535          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12536                          (match_operand:SI 2 "reg_or_short_operand" ""))
12537                   (match_operand:SI 3 "gpc_reg_operand" ""))
12538          (const_int 0)))
12539    (clobber (match_scratch:SI 4 ""))]
12540   "TARGET_POWER && reload_completed"
12541   [(set (match_dup 4)
12542         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
12543                  (match_dup 3)))
12544    (set (match_dup 0)
12545         (compare:CC (match_dup 4)
12546                     (const_int 0)))]
12547   "")
12548
12549 (define_insn ""
12550   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12551         (compare:CC
12552          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12553                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12554                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12555          (const_int 0)))
12556    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12557         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12558   "TARGET_POWER"
12559   "@
12560    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
12561    #"
12562   [(set_attr "type" "compare")
12563    (set_attr "length" "12,16")])
12564
12565 (define_split
12566   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12567         (compare:CC
12568          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12569                          (match_operand:SI 2 "reg_or_short_operand" ""))
12570                   (match_operand:SI 3 "gpc_reg_operand" ""))
12571          (const_int 0)))
12572    (set (match_operand:SI 0 "gpc_reg_operand" "")
12573         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12574   "TARGET_POWER && reload_completed"
12575   [(set (match_dup 0)
12576         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12577    (set (match_dup 4)
12578         (compare:CC (match_dup 0)
12579                     (const_int 0)))]
12580   "")
12581
12582 (define_insn ""
12583   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12584         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12585                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12586   "TARGET_POWER"
12587   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
12588   [(set_attr "length" "12")])
12589
12590 (define_insn_and_split "*ltu<mode>"
12591   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12592         (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12593                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
12594   ""
12595   "#"
12596   ""
12597   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12598    (set (match_dup 0) (neg:P (match_dup 0)))]
12599   "")
12600
12601 (define_insn_and_split "*ltu<mode>_compare"
12602   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12603         (compare:CC
12604          (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12605                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
12606          (const_int 0)))
12607    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
12608         (ltu:P (match_dup 1) (match_dup 2)))]
12609   ""
12610   "#"
12611   ""
12612   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12613    (parallel [(set (match_dup 3)
12614                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
12615               (set (match_dup 0) (neg:P (match_dup 0)))])]
12616   "")
12617
12618 (define_insn_and_split "*plus_ltu<mode>"
12619   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,r")
12620         (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12621                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
12622                 (match_operand:P 3 "reg_or_short_operand" "rI,rI")))]
12623   ""
12624   "#"
12625   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12626   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12627    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
12628   "")
12629
12630 (define_insn_and_split "*plus_ltu<mode>_compare"
12631   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12632         (compare:CC
12633          (plus:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12634                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
12635                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
12636          (const_int 0)))
12637    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12638         (plus:P (ltu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
12639   ""
12640   "#"
12641   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
12642   [(set (match_dup 0) (neg:P (ltu:P (match_dup 1) (match_dup 2))))
12643    (parallel [(set (match_dup 4)
12644                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
12645                                (const_int 0)))
12646               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
12647   "")
12648
12649 (define_insn "*neg_ltu<mode>"
12650   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12651         (neg:P (ltu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12652                       (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))))]
12653   ""
12654   "@
12655    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
12656    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
12657   [(set_attr "type" "two")
12658    (set_attr "length" "8")])
12659
12660 (define_insn ""
12661   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12662         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12663                (match_operand:SI 2 "reg_or_short_operand" "rI")))
12664    (clobber (match_scratch:SI 3 "=r"))]
12665   "TARGET_POWER"
12666   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
12667    [(set_attr "length" "12")])
12668
12669 (define_insn ""
12670   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12671         (compare:CC
12672          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12673                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12674          (const_int 0)))
12675    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12676         (ge:SI (match_dup 1) (match_dup 2)))
12677    (clobber (match_scratch:SI 3 "=r,r"))]
12678   "TARGET_POWER"
12679   "@
12680    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12681    #"
12682   [(set_attr "type" "compare")
12683    (set_attr "length" "12,16")])
12684
12685 (define_split
12686   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12687         (compare:CC
12688          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12689                 (match_operand:SI 2 "reg_or_short_operand" ""))
12690          (const_int 0)))
12691    (set (match_operand:SI 0 "gpc_reg_operand" "")
12692         (ge:SI (match_dup 1) (match_dup 2)))
12693    (clobber (match_scratch:SI 3 ""))]
12694   "TARGET_POWER && reload_completed"
12695   [(parallel [(set (match_dup 0)
12696                    (ge:SI (match_dup 1) (match_dup 2)))
12697               (clobber (match_dup 3))])
12698    (set (match_dup 4)
12699         (compare:CC (match_dup 0)
12700                     (const_int 0)))]
12701   "")
12702
12703 (define_insn ""
12704   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12705         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12706                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12707                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12708   "TARGET_POWER"
12709   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
12710   [(set_attr "length" "12")])
12711
12712 (define_insn ""
12713   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12714         (compare:CC
12715          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12716                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12717                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12718          (const_int 0)))
12719    (clobber (match_scratch:SI 4 "=&r,&r"))]
12720   "TARGET_POWER"
12721   "@
12722    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12723    #"
12724   [(set_attr "type" "compare")
12725    (set_attr "length" "12,16")])
12726
12727 (define_split
12728   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12729         (compare:CC
12730          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12731                          (match_operand:SI 2 "reg_or_short_operand" ""))
12732                   (match_operand:SI 3 "gpc_reg_operand" ""))
12733          (const_int 0)))
12734    (clobber (match_scratch:SI 4 ""))]
12735   "TARGET_POWER && reload_completed"
12736   [(set (match_dup 4)
12737         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
12738                  (match_dup 3)))
12739    (set (match_dup 0)
12740         (compare:CC (match_dup 4)
12741                     (const_int 0)))]
12742   "")
12743
12744 (define_insn ""
12745   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12746         (compare:CC
12747          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12748                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12749                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12750          (const_int 0)))
12751    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12752         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12753   "TARGET_POWER"
12754   "@
12755    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12756    #"
12757   [(set_attr "type" "compare")
12758    (set_attr "length" "12,16")])
12759
12760 (define_split
12761   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12762         (compare:CC
12763          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12764                          (match_operand:SI 2 "reg_or_short_operand" ""))
12765                   (match_operand:SI 3 "gpc_reg_operand" ""))
12766          (const_int 0)))
12767    (set (match_operand:SI 0 "gpc_reg_operand" "")
12768         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12769   "TARGET_POWER && reload_completed"
12770   [(set (match_dup 0)
12771         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12772    (set (match_dup 4)
12773         (compare:CC (match_dup 0)
12774                     (const_int 0)))]
12775   "")
12776
12777 (define_insn ""
12778   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12779         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12780                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12781   "TARGET_POWER"
12782   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
12783   [(set_attr "length" "12")])
12784
12785 (define_insn "*geu<mode>"
12786   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12787         (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12788                (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))]
12789   ""
12790   "@
12791    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
12792    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12793   [(set_attr "type" "three")
12794    (set_attr "length" "12")])
12795
12796 (define_insn "*geu<mode>_compare"
12797   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12798         (compare:CC
12799          (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
12800                 (match_operand:P 2 "reg_or_neg_short_operand" "r,P,r,P"))
12801          (const_int 0)))
12802    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
12803         (geu:P (match_dup 1) (match_dup 2)))]
12804   ""
12805   "@
12806    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12807    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12808    #
12809    #"
12810   [(set_attr "type" "compare")
12811    (set_attr "length" "12,12,16,16")])
12812
12813 (define_split
12814   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12815         (compare:CC
12816          (geu:P (match_operand:P 1 "gpc_reg_operand" "")
12817                 (match_operand:P 2 "reg_or_neg_short_operand" ""))
12818          (const_int 0)))
12819    (set (match_operand:P 0 "gpc_reg_operand" "")
12820         (geu:P (match_dup 1) (match_dup 2)))]
12821   "reload_completed"
12822   [(set (match_dup 0)
12823         (geu:P (match_dup 1) (match_dup 2)))
12824    (set (match_dup 3)
12825         (compare:CC (match_dup 0)
12826                     (const_int 0)))]
12827   "")
12828
12829 (define_insn "*plus_geu<mode>"
12830   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
12831         (plus:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12832                        (match_operand:P 2 "reg_or_neg_short_operand" "r,P"))
12833                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
12834   ""
12835   "@
12836    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
12837    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
12838   [(set_attr "type" "two")
12839    (set_attr "length" "8")])
12840
12841 (define_insn ""
12842   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12843         (compare:CC
12844          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12845                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12846                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12847          (const_int 0)))
12848    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12849   "TARGET_32BIT"
12850   "@
12851    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
12852    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
12853    #
12854    #"
12855   [(set_attr "type" "compare")
12856    (set_attr "length" "8,8,12,12")])
12857
12858 (define_split
12859   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12860         (compare:CC
12861          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12862                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12863                   (match_operand:SI 3 "gpc_reg_operand" ""))
12864          (const_int 0)))
12865    (clobber (match_scratch:SI 4 ""))]
12866   "TARGET_32BIT && reload_completed"
12867   [(set (match_dup 4)
12868         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
12869                   (match_dup 3)))
12870    (set (match_dup 0)
12871         (compare:CC (match_dup 4)
12872                     (const_int 0)))]
12873   "")
12874
12875 (define_insn ""
12876   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12877         (compare:CC
12878          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12879                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12880                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12881          (const_int 0)))
12882    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12883         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12884   "TARGET_32BIT"
12885   "@
12886    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
12887    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
12888    #
12889    #"
12890   [(set_attr "type" "compare")
12891    (set_attr "length" "8,8,12,12")])
12892
12893 (define_split
12894   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12895         (compare:CC
12896          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12897                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12898                   (match_operand:SI 3 "gpc_reg_operand" ""))
12899          (const_int 0)))
12900    (set (match_operand:SI 0 "gpc_reg_operand" "")
12901         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12902   "TARGET_32BIT && reload_completed"
12903   [(set (match_dup 0)
12904         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12905    (set (match_dup 4)
12906         (compare:CC (match_dup 0)
12907                     (const_int 0)))]
12908   "")
12909
12910 (define_insn "*neg_geu<mode>"
12911   [(set (match_operand:P 0 "gpc_reg_operand" "=r,r")
12912         (neg:P (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12913                       (match_operand:P 2 "reg_or_short_operand" "r,I"))))]
12914   ""
12915   "@
12916    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
12917    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
12918   [(set_attr "type" "three")
12919    (set_attr "length" "12")])
12920
12921 (define_insn "*and_neg_geu<mode>"
12922   [(set (match_operand:P 0 "gpc_reg_operand" "=&r,&r")
12923         (and:P (neg:P
12924                  (geu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
12925                         (match_operand:P 2 "reg_or_neg_short_operand" "r,P")))
12926                 (match_operand:P 3 "gpc_reg_operand" "r,r")))]
12927   ""
12928   "@
12929    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
12930    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12931   [(set_attr "type" "three")
12932    (set_attr "length" "12")])
12933
12934 (define_insn ""
12935   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12936         (compare:CC
12937          (and:SI (neg:SI
12938                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12939                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12940                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12941          (const_int 0)))
12942    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12943   "TARGET_32BIT"
12944   "@
12945    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12946    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12947    #
12948    #"
12949   [(set_attr "type" "compare")
12950    (set_attr "length" "12,12,16,16")])
12951
12952 (define_split
12953   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12954         (compare:CC
12955          (and:SI (neg:SI
12956                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12957                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12958                  (match_operand:SI 3 "gpc_reg_operand" ""))
12959          (const_int 0)))
12960    (clobber (match_scratch:SI 4 ""))]
12961   "TARGET_32BIT && reload_completed"
12962   [(set (match_dup 4)
12963         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
12964                 (match_dup 3)))
12965    (set (match_dup 0)
12966         (compare:CC (match_dup 4)
12967                     (const_int 0)))]
12968   "")
12969
12970 (define_insn ""
12971   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12972         (compare:CC
12973          (and:SI (neg:SI
12974                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12975                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12976                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12977          (const_int 0)))
12978    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12979         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12980   "TARGET_32BIT"
12981   "@
12982    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12983    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12984    #
12985    #"
12986   [(set_attr "type" "compare")
12987    (set_attr "length" "12,12,16,16")])
12988
12989 (define_split
12990   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12991         (compare:CC
12992          (and:SI (neg:SI
12993                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12994                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12995                  (match_operand:SI 3 "gpc_reg_operand" ""))
12996          (const_int 0)))
12997    (set (match_operand:SI 0 "gpc_reg_operand" "")
12998         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12999   "TARGET_32BIT && reload_completed"
13000   [(set (match_dup 0)
13001         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
13002    (set (match_dup 4)
13003         (compare:CC (match_dup 0)
13004                     (const_int 0)))]
13005   "")
13006
13007 (define_insn ""
13008   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13009         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13010                (match_operand:SI 2 "reg_or_short_operand" "r")))]
13011   "TARGET_POWER"
13012   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13013   [(set_attr "length" "12")])
13014
13015 (define_insn ""
13016   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13017         (compare:CC
13018          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13019                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13020          (const_int 0)))
13021    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13022         (gt:SI (match_dup 1) (match_dup 2)))]
13023   "TARGET_POWER"
13024   "@
13025    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13026    #"
13027   [(set_attr "type" "delayed_compare")
13028    (set_attr "length" "12,16")])
13029
13030 (define_split
13031   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13032         (compare:CC
13033          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13034                 (match_operand:SI 2 "reg_or_short_operand" ""))
13035          (const_int 0)))
13036    (set (match_operand:SI 0 "gpc_reg_operand" "")
13037         (gt:SI (match_dup 1) (match_dup 2)))]
13038   "TARGET_POWER && reload_completed"
13039   [(set (match_dup 0)
13040         (gt:SI (match_dup 1) (match_dup 2)))
13041    (set (match_dup 3)
13042         (compare:CC (match_dup 0)
13043                     (const_int 0)))]
13044   "")
13045
13046 (define_insn "*plus_gt0<mode>"
13047   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13048         (plus:P (gt:P (match_operand:P 1 "gpc_reg_operand" "r")
13049                       (const_int 0))
13050                  (match_operand:P 2 "gpc_reg_operand" "r")))]
13051   ""
13052   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
13053   [(set_attr "type" "three")
13054    (set_attr "length" "12")])
13055
13056 (define_insn ""
13057   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13058         (compare:CC
13059          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13060                          (const_int 0))
13061                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13062          (const_int 0)))
13063    (clobber (match_scratch:SI 3 "=&r,&r"))]
13064   "TARGET_32BIT"
13065   "@
13066    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
13067    #"
13068   [(set_attr "type" "compare")
13069    (set_attr "length" "12,16")])
13070
13071 (define_split
13072   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13073         (compare:CC
13074          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13075                          (const_int 0))
13076                   (match_operand:SI 2 "gpc_reg_operand" ""))
13077          (const_int 0)))
13078    (clobber (match_scratch:SI 3 ""))]
13079   "TARGET_32BIT && reload_completed"
13080   [(set (match_dup 3)
13081         (plus:SI (gt:SI (match_dup 1) (const_int 0))
13082                   (match_dup 2)))
13083    (set (match_dup 0)
13084         (compare:CC (match_dup 3)
13085                     (const_int 0)))]
13086   "")
13087
13088 (define_insn ""
13089   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13090         (compare:CC
13091          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13092                          (const_int 0))
13093                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13094          (const_int 0)))
13095    (clobber (match_scratch:DI 3 "=&r,&r"))]
13096   "TARGET_64BIT"
13097   "@
13098    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
13099    #"
13100   [(set_attr "type" "compare")
13101    (set_attr "length" "12,16")])
13102
13103 (define_split
13104   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13105         (compare:CC
13106          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13107                          (const_int 0))
13108                   (match_operand:DI 2 "gpc_reg_operand" ""))
13109          (const_int 0)))
13110    (clobber (match_scratch:DI 3 ""))]
13111   "TARGET_64BIT && reload_completed"
13112   [(set (match_dup 3)
13113         (plus:DI (gt:DI (match_dup 1) (const_int 0))
13114                  (match_dup 2)))
13115    (set (match_dup 0)
13116         (compare:CC (match_dup 3)
13117                     (const_int 0)))]
13118   "")
13119
13120 (define_insn ""
13121   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13122         (compare:CC
13123          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13124                          (const_int 0))
13125                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13126          (const_int 0)))
13127    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13128         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13129   "TARGET_32BIT"
13130   "@
13131    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
13132    #"
13133   [(set_attr "type" "compare")
13134    (set_attr "length" "12,16")])
13135
13136 (define_split
13137   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13138         (compare:CC
13139          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13140                          (const_int 0))
13141                   (match_operand:SI 2 "gpc_reg_operand" ""))
13142          (const_int 0)))
13143    (set (match_operand:SI 0 "gpc_reg_operand" "")
13144         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13145   "TARGET_32BIT && reload_completed"
13146   [(set (match_dup 0)
13147         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
13148    (set (match_dup 3)
13149         (compare:CC (match_dup 0)
13150                     (const_int 0)))]
13151   "")
13152
13153 (define_insn ""
13154   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13155         (compare:CC
13156          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13157                          (const_int 0))
13158                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13159          (const_int 0)))
13160    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13161         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13162   "TARGET_64BIT"
13163   "@
13164    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
13165    #"
13166   [(set_attr "type" "compare")
13167    (set_attr "length" "12,16")])
13168
13169 (define_split
13170   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13171         (compare:CC
13172          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13173                          (const_int 0))
13174                   (match_operand:DI 2 "gpc_reg_operand" ""))
13175          (const_int 0)))
13176    (set (match_operand:DI 0 "gpc_reg_operand" "")
13177         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13178   "TARGET_64BIT && reload_completed"
13179   [(set (match_dup 0)
13180         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
13181    (set (match_dup 3)
13182         (compare:CC (match_dup 0)
13183                     (const_int 0)))]
13184   "")
13185
13186 (define_insn ""
13187   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13188         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13189                         (match_operand:SI 2 "reg_or_short_operand" "r"))
13190                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13191   "TARGET_POWER"
13192   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13193   [(set_attr "length" "12")])
13194
13195 (define_insn ""
13196   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13197         (compare:CC
13198          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13199                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13200                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13201          (const_int 0)))
13202    (clobber (match_scratch:SI 4 "=&r,&r"))]
13203   "TARGET_POWER"
13204   "@
13205    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13206    #"
13207   [(set_attr "type" "compare")
13208    (set_attr "length" "12,16")])
13209
13210 (define_split
13211   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13212         (compare:CC
13213          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13214                          (match_operand:SI 2 "reg_or_short_operand" ""))
13215                   (match_operand:SI 3 "gpc_reg_operand" ""))
13216          (const_int 0)))
13217    (clobber (match_scratch:SI 4 ""))]
13218   "TARGET_POWER && reload_completed"
13219   [(set (match_dup 4)
13220         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13221    (set (match_dup 0)
13222         (compare:CC (match_dup 4)
13223                     (const_int 0)))]
13224   "")
13225
13226 (define_insn ""
13227   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13228         (compare:CC
13229          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13230                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13231                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13232          (const_int 0)))
13233    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13234         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13235   "TARGET_POWER"
13236   "@
13237    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13238    #"
13239   [(set_attr "type" "compare")
13240    (set_attr "length" "12,16")])
13241
13242 (define_split
13243   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13244         (compare:CC
13245          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13246                          (match_operand:SI 2 "reg_or_short_operand" ""))
13247                   (match_operand:SI 3 "gpc_reg_operand" ""))
13248          (const_int 0)))
13249    (set (match_operand:SI 0 "gpc_reg_operand" "")
13250         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13251   "TARGET_POWER && reload_completed"
13252   [(set (match_dup 0)
13253         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13254    (set (match_dup 4)
13255         (compare:CC (match_dup 0)
13256                     (const_int 0)))]
13257   "")
13258
13259 (define_insn ""
13260   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13261         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13262                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
13263   "TARGET_POWER"
13264   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13265   [(set_attr "length" "12")])
13266
13267 (define_insn_and_split "*gtu<mode>"
13268   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13269         (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
13270                (match_operand:P 2 "reg_or_short_operand" "rI")))]
13271   ""
13272   "#"
13273   ""
13274   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13275    (set (match_dup 0) (neg:P (match_dup 0)))]
13276   "")
13277
13278 (define_insn_and_split "*gtu<mode>_compare"
13279   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13280         (compare:CC
13281          (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r")
13282                  (match_operand:P 2 "reg_or_short_operand" "rI,rI"))
13283          (const_int 0)))
13284    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
13285         (gtu:P (match_dup 1) (match_dup 2)))]
13286   ""
13287   "#"
13288   ""
13289   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13290    (parallel [(set (match_dup 3)
13291                    (compare:CC (neg:P (match_dup 0)) (const_int 0)))
13292               (set (match_dup 0) (neg:P (match_dup 0)))])]
13293   "")
13294
13295 (define_insn_and_split "*plus_gtu<mode>"
13296   [(set (match_operand:P 0 "gpc_reg_operand" "=&r")
13297         (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
13298                        (match_operand:P 2 "reg_or_short_operand" "rI"))
13299                 (match_operand:P 3 "reg_or_short_operand" "rI")))]
13300   ""
13301   "#"
13302   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13303   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13304    (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))]
13305   "")
13306
13307 (define_insn_and_split "*plus_gtu<mode>_compare"
13308   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13309         (compare:CC
13310          (plus:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r,r,r,r")
13311                         (match_operand:P 2 "reg_or_short_operand" "I,r,I,r"))
13312                  (match_operand:P 3 "gpc_reg_operand" "r,r,r,r"))
13313          (const_int 0)))
13314    (set (match_operand:P 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13315         (plus:P (gtu:P (match_dup 1) (match_dup 2)) (match_dup 3)))]
13316   ""
13317   "#"
13318   "&& !reg_overlap_mentioned_p (operands[0], operands[3])"
13319   [(set (match_dup 0) (neg:P (gtu:P (match_dup 1) (match_dup 2))))
13320    (parallel [(set (match_dup 4)
13321                    (compare:CC (minus:P (match_dup 3) (match_dup 0))
13322                                (const_int 0)))
13323               (set (match_dup 0) (minus:P (match_dup 3) (match_dup 0)))])]
13324   "")
13325
13326 (define_insn "*neg_gtu<mode>"
13327   [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13328         (neg:P (gtu:P (match_operand:P 1 "gpc_reg_operand" "r")
13329                       (match_operand:P 2 "reg_or_short_operand" "rI"))))]
13330   ""
13331   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
13332   [(set_attr "type" "two")
13333    (set_attr "length" "8")])
13334
13335 \f
13336 ;; Define both directions of branch and return.  If we need a reload
13337 ;; register, we'd rather use CR0 since it is much easier to copy a
13338 ;; register CC value to there.
13339
13340 (define_insn ""
13341   [(set (pc)
13342         (if_then_else (match_operator 1 "branch_comparison_operator"
13343                                       [(match_operand 2
13344                                                       "cc_reg_operand" "y")
13345                                        (const_int 0)])
13346                       (label_ref (match_operand 0 "" ""))
13347                       (pc)))]
13348   ""
13349   "*
13350 {
13351   return output_cbranch (operands[1], \"%l0\", 0, insn);
13352 }"
13353   [(set_attr "type" "branch")])
13354
13355 (define_insn ""
13356   [(set (pc)
13357         (if_then_else (match_operator 0 "branch_comparison_operator"
13358                                       [(match_operand 1
13359                                                       "cc_reg_operand" "y")
13360                                        (const_int 0)])
13361                       (return)
13362                       (pc)))]
13363   "direct_return ()"
13364   "*
13365 {
13366   return output_cbranch (operands[0], NULL, 0, insn);
13367 }"
13368   [(set_attr "type" "jmpreg")
13369    (set_attr "length" "4")])
13370
13371 (define_insn ""
13372   [(set (pc)
13373         (if_then_else (match_operator 1 "branch_comparison_operator"
13374                                       [(match_operand 2
13375                                                       "cc_reg_operand" "y")
13376                                        (const_int 0)])
13377                       (pc)
13378                       (label_ref (match_operand 0 "" ""))))]
13379   ""
13380   "*
13381 {
13382   return output_cbranch (operands[1], \"%l0\", 1, insn);
13383 }"
13384   [(set_attr "type" "branch")])
13385
13386 (define_insn ""
13387   [(set (pc)
13388         (if_then_else (match_operator 0 "branch_comparison_operator"
13389                                       [(match_operand 1
13390                                                       "cc_reg_operand" "y")
13391                                        (const_int 0)])
13392                       (pc)
13393                       (return)))]
13394   "direct_return ()"
13395   "*
13396 {
13397   return output_cbranch (operands[0], NULL, 1, insn);
13398 }"
13399   [(set_attr "type" "jmpreg")
13400    (set_attr "length" "4")])
13401
13402 ;; Logic on condition register values.
13403
13404 ; This pattern matches things like
13405 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13406 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
13407 ;                                  (const_int 1)))
13408 ; which are generated by the branch logic.
13409 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
13410
13411 (define_insn "*cceq_ior_compare"
13412   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13413         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13414                         [(match_operator:SI 2
13415                                       "branch_positive_comparison_operator"
13416                                       [(match_operand 3
13417                                                       "cc_reg_operand" "y,y")
13418                                        (const_int 0)])
13419                          (match_operator:SI 4
13420                                       "branch_positive_comparison_operator"
13421                                       [(match_operand 5
13422                                                       "cc_reg_operand" "0,y")
13423                                        (const_int 0)])])
13424                       (const_int 1)))]
13425   ""
13426   "cr%q1 %E0,%j2,%j4"
13427   [(set_attr "type" "cr_logical,delayed_cr")])
13428
13429 ; Why is the constant -1 here, but 1 in the previous pattern?
13430 ; Because ~1 has all but the low bit set.
13431 (define_insn ""
13432   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13433         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
13434                         [(not:SI (match_operator:SI 2
13435                                       "branch_positive_comparison_operator"
13436                                       [(match_operand 3
13437                                                       "cc_reg_operand" "y,y")
13438                                        (const_int 0)]))
13439                          (match_operator:SI 4
13440                                 "branch_positive_comparison_operator"
13441                                 [(match_operand 5
13442                                                 "cc_reg_operand" "0,y")
13443                                  (const_int 0)])])
13444                       (const_int -1)))]
13445   ""
13446   "cr%q1 %E0,%j2,%j4"
13447   [(set_attr "type" "cr_logical,delayed_cr")])
13448
13449 (define_insn "*cceq_rev_compare"
13450   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13451         (compare:CCEQ (match_operator:SI 1
13452                                       "branch_positive_comparison_operator"
13453                                       [(match_operand 2
13454                                                       "cc_reg_operand" "0,y")
13455                                        (const_int 0)])
13456                       (const_int 0)))]
13457   ""
13458   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
13459   [(set_attr "type" "cr_logical,delayed_cr")])
13460
13461 ;; If we are comparing the result of two comparisons, this can be done
13462 ;; using creqv or crxor.
13463
13464 (define_insn_and_split ""
13465   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13466         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13467                               [(match_operand 2 "cc_reg_operand" "y")
13468                                (const_int 0)])
13469                       (match_operator 3 "branch_comparison_operator"
13470                               [(match_operand 4 "cc_reg_operand" "y")
13471                                (const_int 0)])))]
13472   ""
13473   "#"
13474   ""
13475   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13476                                     (match_dup 5)))]
13477   "
13478 {
13479   int positive_1, positive_2;
13480
13481   positive_1 = branch_positive_comparison_operator (operands[1],
13482                                                     GET_MODE (operands[1]));
13483   positive_2 = branch_positive_comparison_operator (operands[3],
13484                                                     GET_MODE (operands[3]));
13485
13486   if (! positive_1)
13487     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
13488                                                             GET_CODE (operands[1])),
13489                                   SImode,
13490                                   operands[2], const0_rtx);
13491   else if (GET_MODE (operands[1]) != SImode)
13492     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
13493                                   operands[2], const0_rtx);
13494
13495   if (! positive_2)
13496     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
13497                                                             GET_CODE (operands[3])),
13498                                   SImode,
13499                                   operands[4], const0_rtx);
13500   else if (GET_MODE (operands[3]) != SImode)
13501     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
13502                                   operands[4], const0_rtx);
13503
13504   if (positive_1 == positive_2)
13505     {
13506       operands[1] = gen_rtx_NOT (SImode, operands[1]);
13507       operands[5] = constm1_rtx;
13508     }
13509   else
13510     {
13511       operands[5] = const1_rtx;
13512     }
13513 }")
13514
13515 ;; Unconditional branch and return.
13516
13517 (define_insn "jump"
13518   [(set (pc)
13519         (label_ref (match_operand 0 "" "")))]
13520   ""
13521   "b %l0"
13522   [(set_attr "type" "branch")])
13523
13524 (define_insn "return"
13525   [(return)]
13526   "direct_return ()"
13527   "{br|blr}"
13528   [(set_attr "type" "jmpreg")])
13529
13530 (define_expand "indirect_jump"
13531   [(set (pc) (match_operand 0 "register_operand" ""))])
13532
13533 (define_insn "*indirect_jump<mode>"
13534   [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
13535   ""
13536   "@
13537    bctr
13538    {br|blr}"
13539   [(set_attr "type" "jmpreg")])
13540
13541 ;; Table jump for switch statements:
13542 (define_expand "tablejump"
13543   [(use (match_operand 0 "" ""))
13544    (use (label_ref (match_operand 1 "" "")))]
13545   ""
13546   "
13547 {
13548   if (TARGET_32BIT)
13549     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
13550   else
13551     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
13552   DONE;
13553 }")
13554
13555 (define_expand "tablejumpsi"
13556   [(set (match_dup 3)
13557         (plus:SI (match_operand:SI 0 "" "")
13558                  (match_dup 2)))
13559    (parallel [(set (pc) (match_dup 3))
13560               (use (label_ref (match_operand 1 "" "")))])]
13561   "TARGET_32BIT"
13562   "
13563 { operands[0] = force_reg (SImode, operands[0]);
13564   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
13565   operands[3] = gen_reg_rtx (SImode);
13566 }")
13567
13568 (define_expand "tablejumpdi"
13569   [(set (match_dup 4)
13570         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "rm")))
13571    (set (match_dup 3)
13572         (plus:DI (match_dup 4)
13573                  (match_dup 2)))
13574    (parallel [(set (pc) (match_dup 3))
13575               (use (label_ref (match_operand 1 "" "")))])]
13576   "TARGET_64BIT"
13577   "
13578 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
13579   operands[3] = gen_reg_rtx (DImode);
13580   operands[4] = gen_reg_rtx (DImode);
13581 }")
13582
13583 (define_insn "*tablejump<mode>_internal1"
13584   [(set (pc)
13585         (match_operand:P 0 "register_operand" "c,*l"))
13586    (use (label_ref (match_operand 1 "" "")))]
13587   ""
13588   "@
13589    bctr
13590    {br|blr}"
13591   [(set_attr "type" "jmpreg")])
13592
13593 (define_insn "nop"
13594   [(const_int 0)]
13595   ""
13596   "{cror 0,0,0|nop}")
13597 \f
13598 ;; Define the subtract-one-and-jump insns, starting with the template
13599 ;; so loop.c knows what to generate.
13600
13601 (define_expand "doloop_end"
13602   [(use (match_operand 0 "" ""))        ; loop pseudo
13603    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
13604    (use (match_operand 2 "" ""))        ; max iterations
13605    (use (match_operand 3 "" ""))        ; loop level
13606    (use (match_operand 4 "" ""))]       ; label
13607   ""
13608   "
13609 {
13610   /* Only use this on innermost loops.  */
13611   if (INTVAL (operands[3]) > 1)
13612     FAIL;
13613   if (TARGET_64BIT)
13614     {
13615       if (GET_MODE (operands[0]) != DImode)
13616         FAIL;
13617       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
13618     }
13619   else
13620     {
13621       if (GET_MODE (operands[0]) != SImode)
13622         FAIL;
13623       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
13624     }
13625   DONE;
13626 }")
13627
13628 (define_expand "ctr<mode>"
13629   [(parallel [(set (pc)
13630                    (if_then_else (ne (match_operand:P 0 "register_operand" "")
13631                                      (const_int 1))
13632                                  (label_ref (match_operand 1 "" ""))
13633                                  (pc)))
13634               (set (match_dup 0)
13635                    (plus:P (match_dup 0)
13636                             (const_int -1)))
13637               (clobber (match_scratch:CC 2 ""))
13638               (clobber (match_scratch:P 3 ""))])]
13639   ""
13640   "")
13641
13642 ;; We need to be able to do this for any operand, including MEM, or we
13643 ;; will cause reload to blow up since we don't allow output reloads on
13644 ;; JUMP_INSNs.
13645 ;; For the length attribute to be calculated correctly, the
13646 ;; label MUST be operand 0.
13647
13648 (define_insn "*ctr<mode>_internal1"
13649   [(set (pc)
13650         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13651                           (const_int 1))
13652                       (label_ref (match_operand 0 "" ""))
13653                       (pc)))
13654    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13655         (plus:P (match_dup 1)
13656                  (const_int -1)))
13657    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13658    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13659   ""
13660   "*
13661 {
13662   if (which_alternative != 0)
13663     return \"#\";
13664   else if (get_attr_length (insn) == 4)
13665     return \"{bdn|bdnz} %l0\";
13666   else
13667     return \"bdz $+8\;b %l0\";
13668 }"
13669   [(set_attr "type" "branch")
13670    (set_attr "length" "*,12,16,16")])
13671
13672 (define_insn "*ctr<mode>_internal2"
13673   [(set (pc)
13674         (if_then_else (ne (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13675                           (const_int 1))
13676                       (pc)
13677                       (label_ref (match_operand 0 "" ""))))
13678    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13679         (plus:P (match_dup 1)
13680                  (const_int -1)))
13681    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13682    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13683   ""
13684   "*
13685 {
13686   if (which_alternative != 0)
13687     return \"#\";
13688   else if (get_attr_length (insn) == 4)
13689     return \"bdz %l0\";
13690   else
13691     return \"{bdn|bdnz} $+8\;b %l0\";
13692 }"
13693   [(set_attr "type" "branch")
13694    (set_attr "length" "*,12,16,16")])
13695
13696 ;; Similar but use EQ
13697
13698 (define_insn "*ctr<mode>_internal5"
13699   [(set (pc)
13700         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13701                           (const_int 1))
13702                       (label_ref (match_operand 0 "" ""))
13703                       (pc)))
13704    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13705         (plus:P (match_dup 1)
13706                  (const_int -1)))
13707    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13708    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13709   ""
13710   "*
13711 {
13712   if (which_alternative != 0)
13713     return \"#\";
13714   else if (get_attr_length (insn) == 4)
13715     return \"bdz %l0\";
13716   else
13717     return \"{bdn|bdnz} $+8\;b %l0\";
13718 }"
13719   [(set_attr "type" "branch")
13720    (set_attr "length" "*,12,16,16")])
13721
13722 (define_insn "*ctr<mode>_internal6"
13723   [(set (pc)
13724         (if_then_else (eq (match_operand:P 1 "register_operand" "c,*r,*r,*r")
13725                           (const_int 1))
13726                       (pc)
13727                       (label_ref (match_operand 0 "" ""))))
13728    (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
13729         (plus:P (match_dup 1)
13730                  (const_int -1)))
13731    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13732    (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13733   ""
13734   "*
13735 {
13736   if (which_alternative != 0)
13737     return \"#\";
13738   else if (get_attr_length (insn) == 4)
13739     return \"{bdn|bdnz} %l0\";
13740   else
13741     return \"bdz $+8\;b %l0\";
13742 }"
13743   [(set_attr "type" "branch")
13744    (set_attr "length" "*,12,16,16")])
13745
13746 ;; Now the splitters if we could not allocate the CTR register
13747
13748 (define_split
13749   [(set (pc)
13750         (if_then_else (match_operator 2 "comparison_operator"
13751                                       [(match_operand:P 1 "gpc_reg_operand" "")
13752                                        (const_int 1)])
13753                       (match_operand 5 "" "")
13754                       (match_operand 6 "" "")))
13755    (set (match_operand:P 0 "gpc_reg_operand" "")
13756         (plus:P (match_dup 1) (const_int -1)))
13757    (clobber (match_scratch:CC 3 ""))
13758    (clobber (match_scratch:P 4 ""))]
13759   "reload_completed"
13760   [(parallel [(set (match_dup 3)
13761                    (compare:CC (plus:P (match_dup 1)
13762                                         (const_int -1))
13763                                (const_int 0)))
13764               (set (match_dup 0)
13765                    (plus:P (match_dup 1)
13766                             (const_int -1)))])
13767    (set (pc) (if_then_else (match_dup 7)
13768                            (match_dup 5)
13769                            (match_dup 6)))]
13770   "
13771 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
13772                                 operands[3], const0_rtx); }")
13773
13774 (define_split
13775   [(set (pc)
13776         (if_then_else (match_operator 2 "comparison_operator"
13777                                       [(match_operand:P 1 "gpc_reg_operand" "")
13778                                        (const_int 1)])
13779                       (match_operand 5 "" "")
13780                       (match_operand 6 "" "")))
13781    (set (match_operand:P 0 "nonimmediate_operand" "")
13782         (plus:P (match_dup 1) (const_int -1)))
13783    (clobber (match_scratch:CC 3 ""))
13784    (clobber (match_scratch:P 4 ""))]
13785   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
13786   [(parallel [(set (match_dup 3)
13787                    (compare:CC (plus:P (match_dup 1)
13788                                         (const_int -1))
13789                                (const_int 0)))
13790               (set (match_dup 4)
13791                    (plus:P (match_dup 1)
13792                             (const_int -1)))])
13793    (set (match_dup 0)
13794         (match_dup 4))
13795    (set (pc) (if_then_else (match_dup 7)
13796                            (match_dup 5)
13797                            (match_dup 6)))]
13798   "
13799 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
13800                                 operands[3], const0_rtx); }")
13801 \f
13802 (define_insn "trap"
13803   [(trap_if (const_int 1) (const_int 0))]
13804   ""
13805   "{t 31,0,0|trap}")
13806
13807 (define_expand "conditional_trap"
13808   [(trap_if (match_operator 0 "trap_comparison_operator"
13809                             [(match_dup 2) (match_dup 3)])
13810             (match_operand 1 "const_int_operand" ""))]
13811   ""
13812   "if (rs6000_compare_fp_p || operands[1] != const0_rtx) FAIL;
13813    operands[2] = rs6000_compare_op0;
13814    operands[3] = rs6000_compare_op1;")
13815
13816 (define_insn ""
13817   [(trap_if (match_operator 0 "trap_comparison_operator"
13818                             [(match_operand:GPR 1 "register_operand" "r")
13819                              (match_operand:GPR 2 "reg_or_short_operand" "rI")])
13820             (const_int 0))]
13821   ""
13822   "{t|t<wd>}%V0%I2 %1,%2")
13823 \f
13824 ;; Insns related to generating the function prologue and epilogue.
13825
13826 (define_expand "prologue"
13827   [(use (const_int 0))]
13828   "TARGET_SCHED_PROLOG"
13829   "
13830 {
13831       rs6000_emit_prologue ();
13832       DONE;
13833 }")
13834
13835 (define_insn "*movesi_from_cr_one"
13836   [(match_parallel 0 "mfcr_operation"
13837                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
13838                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
13839                                      (match_operand 3 "immediate_operand" "n")]
13840                           UNSPEC_MOVESI_FROM_CR))])]
13841   "TARGET_MFCRF"
13842   "*
13843 {
13844   int mask = 0;
13845   int i;
13846   for (i = 0; i < XVECLEN (operands[0], 0); i++)
13847   {
13848     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
13849     operands[4] = GEN_INT (mask);
13850     output_asm_insn (\"mfcr %1,%4\", operands);
13851   }
13852   return \"\";
13853 }"
13854   [(set_attr "type" "mfcrf")])
13855
13856 (define_insn "movesi_from_cr"
13857   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13858         (unspec:SI [(reg:CC 68) (reg:CC 69) (reg:CC 70) (reg:CC 71)
13859                     (reg:CC 72) (reg:CC 73) (reg:CC 74) (reg:CC 75)]
13860                    UNSPEC_MOVESI_FROM_CR))]
13861   ""
13862   "mfcr %0"
13863   [(set_attr "type" "mfcr")])
13864
13865 (define_insn "*stmw"
13866   [(match_parallel 0 "stmw_operation"
13867                    [(set (match_operand:SI 1 "memory_operand" "=m")
13868                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
13869   "TARGET_MULTIPLE"
13870   "{stm|stmw} %2,%1"
13871   [(set_attr "type" "store_ux")])
13872
13873 (define_insn "*save_fpregs_<mode>"
13874   [(match_parallel 0 "any_parallel_operand"
13875                    [(clobber (match_operand:P 1 "register_operand" "=l"))
13876                     (use (match_operand:P 2 "call_operand" "s"))
13877                     (set (match_operand:DF 3 "memory_operand" "=m")
13878                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
13879   ""
13880   "bl %z2"
13881   [(set_attr "type" "branch")
13882    (set_attr "length" "4")])
13883
13884 ; These are to explain that changes to the stack pointer should
13885 ; not be moved over stores to stack memory.
13886 (define_insn "stack_tie"
13887   [(set (match_operand:BLK 0 "memory_operand" "+m")
13888         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
13889   ""
13890   ""
13891   [(set_attr "length" "0")])
13892
13893
13894 (define_expand "epilogue"
13895   [(use (const_int 0))]
13896   "TARGET_SCHED_PROLOG"
13897   "
13898 {
13899       rs6000_emit_epilogue (FALSE);
13900       DONE;
13901 }")
13902
13903 ; On some processors, doing the mtcrf one CC register at a time is
13904 ; faster (like on the 604e).  On others, doing them all at once is
13905 ; faster; for instance, on the 601 and 750.
13906
13907 (define_expand "movsi_to_cr_one"
13908   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
13909         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
13910                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
13911   ""
13912   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
13913
13914 (define_insn "*movsi_to_cr"
13915   [(match_parallel 0 "mtcrf_operation"
13916                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
13917                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
13918                                      (match_operand 3 "immediate_operand" "n")]
13919                                     UNSPEC_MOVESI_TO_CR))])]
13920  ""
13921  "*
13922 {
13923   int mask = 0;
13924   int i;
13925   for (i = 0; i < XVECLEN (operands[0], 0); i++)
13926     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
13927   operands[4] = GEN_INT (mask);
13928   return \"mtcrf %4,%2\";
13929 }"
13930   [(set_attr "type" "mtcr")])
13931
13932 (define_insn "*mtcrfsi"
13933   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
13934         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
13935                     (match_operand 2 "immediate_operand" "n")]
13936                    UNSPEC_MOVESI_TO_CR))]
13937   "GET_CODE (operands[0]) == REG
13938    && CR_REGNO_P (REGNO (operands[0]))
13939    && GET_CODE (operands[2]) == CONST_INT
13940    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
13941   "mtcrf %R0,%1"
13942   [(set_attr "type" "mtcr")])
13943
13944 ; The load-multiple instructions have similar properties.
13945 ; Note that "load_multiple" is a name known to the machine-independent
13946 ; code that actually corresponds to the PowerPC load-string.
13947
13948 (define_insn "*lmw"
13949   [(match_parallel 0 "lmw_operation"
13950                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
13951                          (match_operand:SI 2 "memory_operand" "m"))])]
13952   "TARGET_MULTIPLE"
13953   "{lm|lmw} %1,%2"
13954   [(set_attr "type" "load_ux")])
13955
13956 (define_insn "*return_internal_<mode>"
13957   [(return)
13958    (use (match_operand:P 0 "register_operand" "lc"))]
13959   ""
13960   "b%T0"
13961   [(set_attr "type" "jmpreg")])
13962
13963 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
13964 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
13965
13966 (define_insn "*return_and_restore_fpregs_<mode>"
13967  [(match_parallel 0 "any_parallel_operand"
13968                   [(return)
13969                    (use (match_operand:P 1 "register_operand" "l"))
13970                    (use (match_operand:P 2 "call_operand" "s"))
13971                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
13972                         (match_operand:DF 4 "memory_operand" "m"))])]
13973  ""
13974  "b %z2")
13975
13976 ; This is used in compiling the unwind routines.
13977 (define_expand "eh_return"
13978   [(use (match_operand 0 "general_operand" ""))]
13979   ""
13980   "
13981 {
13982   if (TARGET_32BIT)
13983     emit_insn (gen_eh_set_lr_si (operands[0]));
13984   else
13985     emit_insn (gen_eh_set_lr_di (operands[0]));
13986   DONE;
13987 }")
13988
13989 ; We can't expand this before we know where the link register is stored.
13990 (define_insn "eh_set_lr_<mode>"
13991   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
13992                     UNSPECV_EH_RR)
13993    (clobber (match_scratch:P 1 "=&b"))]
13994   ""
13995   "#")
13996
13997 (define_split
13998   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
13999    (clobber (match_scratch 1 ""))]
14000   "reload_completed"
14001   [(const_int 0)]
14002   "
14003 {
14004   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
14005   DONE;
14006 }")
14007
14008 (define_insn "prefetch"
14009   [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
14010              (match_operand:SI 1 "const_int_operand" "n")
14011              (match_operand:SI 2 "const_int_operand" "n"))]
14012   "TARGET_POWERPC"
14013   "*
14014 {
14015   if (GET_CODE (operands[0]) == REG)
14016     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
14017   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
14018 }"
14019   [(set_attr "type" "load")])
14020 \f
14021
14022 (include "sync.md")
14023 (include "altivec.md")
14024 (include "spe.md")