OSDN Git Service

edbccc64613aa69bbd9fcc49de8be318d386db5f
[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 Free Software Foundation, Inc.
4 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5
6 ;; This file is part of GCC.
7
8 ;; GCC is free software; you can redistribute it and/or modify it
9 ;; under the terms of the GNU General Public License as published
10 ;; by the Free Software Foundation; either version 2, or (at your
11 ;; option) any later version.
12
13 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
14 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16 ;; License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING.  If not, write to the
20 ;; Free Software Foundation, 59 Temple Place - Suite 330, Boston,
21 ;; MA 02111-1307, USA.
22
23 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
24
25 ;;
26 ;; UNSPEC usage
27 ;;
28
29 (define_constants
30   [(UNSPEC_FRSP                 0)      ; frsp for POWER machines
31    (UNSPEC_TIE                  5)      ; tie stack contents and stack pointer
32    (UNSPEC_TOCPTR               6)      ; address of a word pointing to the TOC
33    (UNSPEC_TOC                  7)      ; address of the TOC (more-or-less)
34    (UNSPEC_MOVSI_GOT            8)
35    (UNSPEC_MV_CR_OV             9)      ; move_from_CR_ov_bit
36    (UNSPEC_FCTIWZ               10)
37    (UNSPEC_LD_MPIC              15)     ; load_macho_picbase
38    (UNSPEC_MPIC_CORRECT         16)     ; macho_correct_pic
39    (UNSPEC_TLSGD                17)
40    (UNSPEC_TLSLD                18)
41    (UNSPEC_MOVESI_FROM_CR       19)
42    (UNSPEC_MOVESI_TO_CR         20)
43    (UNSPEC_TLSDTPREL            21)
44    (UNSPEC_TLSDTPRELHA          22)
45    (UNSPEC_TLSDTPRELLO          23)
46    (UNSPEC_TLSGOTDTPREL         24)
47    (UNSPEC_TLSTPREL             25)
48    (UNSPEC_TLSTPRELHA           26)
49    (UNSPEC_TLSTPRELLO           27)
50    (UNSPEC_TLSGOTTPREL          28)
51    (UNSPEC_TLSTLS               29)
52    (UNSPEC_FIX_TRUNC_TF         30)     ; fadd, rounding towards zero
53    (UNSPEC_MV_CR_EQ             31)     ; move_from_CR_eq_bit
54   ])
55
56 ;;
57 ;; UNSPEC_VOLATILE usage
58 ;;
59
60 (define_constants
61   [(UNSPECV_BLOCK               0)
62    (UNSPECV_EH_RR               9)      ; eh_reg_restore
63   ])
64 \f
65 ;; Define an insn type attribute.  This is used in function unit delay
66 ;; computations.
67 (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"
68   (const_string "integer"))
69
70 ;; Length (in bytes).
71 ; '(pc)' in the following doesn't include the instruction itself; it is
72 ; calculated as if the instruction had zero size.
73 (define_attr "length" ""
74   (if_then_else (eq_attr "type" "branch")
75                 (if_then_else (and (ge (minus (match_dup 0) (pc))
76                                        (const_int -32768))
77                                    (lt (minus (match_dup 0) (pc))
78                                        (const_int 32764)))
79                               (const_int 4)
80                               (const_int 8))
81                 (const_int 4)))
82
83 ;; Processor type -- this attribute must exactly match the processor_type
84 ;; enumeration in rs6000.h.
85
86 (define_attr "cpu" "rios1,rios2,rs64a,mpccore,ppc403,ppc405,ppc440,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,power4,power5"
87   (const (symbol_ref "rs6000_cpu_attr")))
88
89 (automata_option "ndfa")
90
91 (include "rios1.md")
92 (include "rios2.md")
93 (include "rs64.md")
94 (include "mpc.md")
95 (include "40x.md")
96 (include "440.md")
97 (include "603.md")
98 (include "6xx.md")
99 (include "7xx.md")
100 (include "7450.md")
101 (include "8540.md")
102 (include "power4.md")
103 (include "power5.md")
104 (include "darwin.md")
105
106 \f
107 ;; This mode macro allows :P to be used for patterns that operate on
108 ;; pointer-sized quantities.  Exactly one of the two alternatives will match.
109 (define_mode_macro P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
110
111 ;; Start with fixed-point load and store insns.  Here we put only the more
112 ;; complex forms.  Basic data transfer is done later.
113
114 (define_expand "zero_extendqidi2"
115   [(set (match_operand:DI 0 "gpc_reg_operand" "")
116         (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "")))]
117   "TARGET_POWERPC64"
118   "")
119
120 (define_insn ""
121   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
122         (zero_extend:DI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
123   "TARGET_POWERPC64"
124   "@
125    lbz%U1%X1 %0,%1
126    rldicl %0,%1,0,56"
127   [(set_attr "type" "load,*")])
128
129 (define_insn ""
130   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
131         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
132                     (const_int 0)))
133    (clobber (match_scratch:DI 2 "=r,r"))]
134   "TARGET_64BIT"
135   "@
136    rldicl. %2,%1,0,56
137    #"
138   [(set_attr "type" "compare")
139    (set_attr "length" "4,8")])
140
141 (define_split
142   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
143         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
144                     (const_int 0)))
145    (clobber (match_scratch:DI 2 ""))]
146   "TARGET_POWERPC64 && reload_completed"
147   [(set (match_dup 2)
148         (zero_extend:DI (match_dup 1)))
149    (set (match_dup 0)
150         (compare:CC (match_dup 2)
151                     (const_int 0)))]
152   "")
153
154 (define_insn ""
155   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
156         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
157                     (const_int 0)))
158    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
159         (zero_extend:DI (match_dup 1)))]
160   "TARGET_64BIT"
161   "@
162    rldicl. %0,%1,0,56
163    #"
164   [(set_attr "type" "compare")
165    (set_attr "length" "4,8")])
166
167 (define_split
168   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
169         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
170                     (const_int 0)))
171    (set (match_operand:DI 0 "gpc_reg_operand" "")
172         (zero_extend:DI (match_dup 1)))]
173   "TARGET_POWERPC64 && reload_completed"
174   [(set (match_dup 0)
175         (zero_extend:DI (match_dup 1)))
176    (set (match_dup 2)
177         (compare:CC (match_dup 0)
178                     (const_int 0)))]
179   "")
180
181 (define_insn "extendqidi2"
182   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
183         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
184   "TARGET_POWERPC64"
185   "extsb %0,%1")
186
187 (define_insn ""
188   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
189         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
190                     (const_int 0)))
191    (clobber (match_scratch:DI 2 "=r,r"))]
192   "TARGET_64BIT"
193   "@
194    extsb. %2,%1
195    #"
196   [(set_attr "type" "compare")
197    (set_attr "length" "4,8")])
198
199 (define_split
200   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
201         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
202                     (const_int 0)))
203    (clobber (match_scratch:DI 2 ""))]
204   "TARGET_POWERPC64 && reload_completed"
205   [(set (match_dup 2)
206         (sign_extend:DI (match_dup 1)))
207    (set (match_dup 0)
208         (compare:CC (match_dup 2)
209                     (const_int 0)))]
210   "")
211
212 (define_insn ""
213   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
214         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
215                     (const_int 0)))
216    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
217         (sign_extend:DI (match_dup 1)))]
218   "TARGET_64BIT"
219   "@
220    extsb. %0,%1
221    #"
222   [(set_attr "type" "compare")
223    (set_attr "length" "4,8")])
224
225 (define_split
226   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
227         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
228                     (const_int 0)))
229    (set (match_operand:DI 0 "gpc_reg_operand" "")
230         (sign_extend:DI (match_dup 1)))]
231   "TARGET_POWERPC64 && reload_completed"
232   [(set (match_dup 0)
233         (sign_extend:DI (match_dup 1)))
234    (set (match_dup 2)
235         (compare:CC (match_dup 0)
236                     (const_int 0)))]
237   "")
238
239 (define_expand "zero_extendhidi2"
240   [(set (match_operand:DI 0 "gpc_reg_operand" "")
241         (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
242   "TARGET_POWERPC64"
243   "")
244
245 (define_insn ""
246   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
247         (zero_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
248   "TARGET_POWERPC64"
249   "@
250    lhz%U1%X1 %0,%1
251    rldicl %0,%1,0,48"
252   [(set_attr "type" "load,*")])
253
254 (define_insn ""
255   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
256         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
257                     (const_int 0)))
258    (clobber (match_scratch:DI 2 "=r,r"))]
259   "TARGET_64BIT"
260   "@
261    rldicl. %2,%1,0,48
262    #"
263   [(set_attr "type" "compare")
264    (set_attr "length" "4,8")])
265
266 (define_split
267   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
268         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
269                     (const_int 0)))
270    (clobber (match_scratch:DI 2 ""))]
271   "TARGET_POWERPC64 && reload_completed"
272   [(set (match_dup 2)
273         (zero_extend:DI (match_dup 1)))
274    (set (match_dup 0)
275         (compare:CC (match_dup 2)
276                     (const_int 0)))]
277   "")
278
279 (define_insn ""
280   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
281         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
282                     (const_int 0)))
283    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
284         (zero_extend:DI (match_dup 1)))]
285   "TARGET_64BIT"
286   "@
287    rldicl. %0,%1,0,48
288    #"
289   [(set_attr "type" "compare")
290    (set_attr "length" "4,8")])
291
292 (define_split
293   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
294         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
295                     (const_int 0)))
296    (set (match_operand:DI 0 "gpc_reg_operand" "")
297         (zero_extend:DI (match_dup 1)))]
298   "TARGET_POWERPC64 && reload_completed"
299   [(set (match_dup 0)
300         (zero_extend:DI (match_dup 1)))
301    (set (match_dup 2)
302         (compare:CC (match_dup 0)
303                     (const_int 0)))]
304   "")
305
306 (define_expand "extendhidi2"
307   [(set (match_operand:DI 0 "gpc_reg_operand" "")
308         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
309   "TARGET_POWERPC64"
310   "")
311
312 (define_insn ""
313   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
314         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
315   "TARGET_POWERPC64"
316   "@
317    lha%U1%X1 %0,%1
318    extsh %0,%1"
319   [(set_attr "type" "load_ext,*")])
320
321 (define_insn ""
322   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
323         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
324                     (const_int 0)))
325    (clobber (match_scratch:DI 2 "=r,r"))]
326   "TARGET_64BIT"
327   "@
328    extsh. %2,%1
329    #"
330   [(set_attr "type" "compare")
331    (set_attr "length" "4,8")])
332
333 (define_split
334   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
335         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
336                     (const_int 0)))
337    (clobber (match_scratch:DI 2 ""))]
338   "TARGET_POWERPC64 && reload_completed"
339   [(set (match_dup 2)
340         (sign_extend:DI (match_dup 1)))
341    (set (match_dup 0)
342         (compare:CC (match_dup 2)
343                     (const_int 0)))]
344   "")
345
346 (define_insn ""
347   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
348         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
349                     (const_int 0)))
350    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
351         (sign_extend:DI (match_dup 1)))]
352   "TARGET_64BIT"
353   "@
354    extsh. %0,%1
355    #"
356   [(set_attr "type" "compare")
357    (set_attr "length" "4,8")])
358
359 (define_split
360   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
361         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
362                     (const_int 0)))
363    (set (match_operand:DI 0 "gpc_reg_operand" "")
364         (sign_extend:DI (match_dup 1)))]
365   "TARGET_POWERPC64 && reload_completed"
366   [(set (match_dup 0)
367         (sign_extend:DI (match_dup 1)))
368    (set (match_dup 2)
369         (compare:CC (match_dup 0)
370                     (const_int 0)))]
371   "")
372
373 (define_expand "zero_extendsidi2"
374   [(set (match_operand:DI 0 "gpc_reg_operand" "")
375         (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
376   "TARGET_POWERPC64"
377   "")
378
379 (define_insn ""
380   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
381         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r")))]
382   "TARGET_POWERPC64"
383   "@
384    lwz%U1%X1 %0,%1
385    rldicl %0,%1,0,32"
386   [(set_attr "type" "load,*")])
387
388 (define_insn ""
389   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
390         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
391                     (const_int 0)))
392    (clobber (match_scratch:DI 2 "=r,r"))]
393   "TARGET_64BIT"
394   "@
395    rldicl. %2,%1,0,32
396    #"
397   [(set_attr "type" "compare")
398    (set_attr "length" "4,8")])
399
400 (define_split
401   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
402         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
403                     (const_int 0)))
404    (clobber (match_scratch:DI 2 ""))]
405   "TARGET_POWERPC64 && reload_completed"
406   [(set (match_dup 2)
407         (zero_extend:DI (match_dup 1)))
408    (set (match_dup 0)
409         (compare:CC (match_dup 2)
410                     (const_int 0)))]
411   "")
412
413 (define_insn ""
414   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
415         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
416                     (const_int 0)))
417    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
418         (zero_extend:DI (match_dup 1)))]
419   "TARGET_64BIT"
420   "@
421    rldicl. %0,%1,0,32
422    #"
423   [(set_attr "type" "compare")
424    (set_attr "length" "4,8")])
425
426 (define_split
427   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
428         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
429                     (const_int 0)))
430    (set (match_operand:DI 0 "gpc_reg_operand" "")
431         (zero_extend:DI (match_dup 1)))]
432   "TARGET_POWERPC64 && reload_completed"
433   [(set (match_dup 0)
434         (zero_extend:DI (match_dup 1)))
435    (set (match_dup 2)
436         (compare:CC (match_dup 0)
437                     (const_int 0)))]
438   "")
439
440 (define_expand "extendsidi2"
441   [(set (match_operand:DI 0 "gpc_reg_operand" "")
442         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
443   "TARGET_POWERPC64"
444   "")
445
446 (define_insn ""
447   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
448         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
449   "TARGET_POWERPC64"
450   "@
451    lwa%U1%X1 %0,%1
452    extsw %0,%1"
453   [(set_attr "type" "load_ext,*")])
454
455 (define_insn ""
456   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
457         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
458                     (const_int 0)))
459    (clobber (match_scratch:DI 2 "=r,r"))]
460   "TARGET_64BIT"
461   "@
462    extsw. %2,%1
463    #"
464   [(set_attr "type" "compare")
465    (set_attr "length" "4,8")])
466
467 (define_split
468   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
469         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
470                     (const_int 0)))
471    (clobber (match_scratch:DI 2 ""))]
472   "TARGET_POWERPC64 && reload_completed"
473   [(set (match_dup 2)
474         (sign_extend:DI (match_dup 1)))
475    (set (match_dup 0)
476         (compare:CC (match_dup 2)
477                     (const_int 0)))]
478   "")
479
480 (define_insn ""
481   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
482         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
483                     (const_int 0)))
484    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
485         (sign_extend:DI (match_dup 1)))]
486   "TARGET_64BIT"
487   "@
488    extsw. %0,%1
489    #"
490   [(set_attr "type" "compare")
491    (set_attr "length" "4,8")])
492
493 (define_split
494   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
495         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
496                     (const_int 0)))
497    (set (match_operand:DI 0 "gpc_reg_operand" "")
498         (sign_extend:DI (match_dup 1)))]
499   "TARGET_POWERPC64 && reload_completed"
500   [(set (match_dup 0)
501         (sign_extend:DI (match_dup 1)))
502    (set (match_dup 2)
503         (compare:CC (match_dup 0)
504                     (const_int 0)))]
505   "")
506
507 (define_expand "zero_extendqisi2"
508   [(set (match_operand:SI 0 "gpc_reg_operand" "")
509         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
510   ""
511   "")
512
513 (define_insn ""
514   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
515         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
516   ""
517   "@
518    lbz%U1%X1 %0,%1
519    {rlinm|rlwinm} %0,%1,0,0xff"
520   [(set_attr "type" "load,*")])
521
522 (define_insn ""
523   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
524         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
525                     (const_int 0)))
526    (clobber (match_scratch:SI 2 "=r,r"))]
527   ""
528   "@
529    {andil.|andi.} %2,%1,0xff
530    #"
531   [(set_attr "type" "compare")
532    (set_attr "length" "4,8")])
533
534 (define_split
535   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
536         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
537                     (const_int 0)))
538    (clobber (match_scratch:SI 2 ""))]
539   "reload_completed"
540   [(set (match_dup 2)
541         (zero_extend:SI (match_dup 1)))
542    (set (match_dup 0)
543         (compare:CC (match_dup 2)
544                     (const_int 0)))]
545   "")
546
547 (define_insn ""
548   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
549         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
550                     (const_int 0)))
551    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
552         (zero_extend:SI (match_dup 1)))]
553   ""
554   "@
555    {andil.|andi.} %0,%1,0xff
556    #"
557   [(set_attr "type" "compare")
558    (set_attr "length" "4,8")])
559
560 (define_split
561   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
562         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
563                     (const_int 0)))
564    (set (match_operand:SI 0 "gpc_reg_operand" "")
565         (zero_extend:SI (match_dup 1)))]
566   "reload_completed"
567   [(set (match_dup 0)
568         (zero_extend:SI (match_dup 1)))
569    (set (match_dup 2)
570         (compare:CC (match_dup 0)
571                     (const_int 0)))]
572   "")
573
574 (define_expand "extendqisi2"
575   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
576    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
577   ""
578   "
579 {
580   if (TARGET_POWERPC)
581     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
582   else if (TARGET_POWER)
583     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
584   else
585     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
586   DONE;
587 }")
588
589 (define_insn "extendqisi2_ppc"
590   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
591         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
592   "TARGET_POWERPC"
593   "extsb %0,%1")
594
595 (define_insn ""
596   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
597         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
598                     (const_int 0)))
599    (clobber (match_scratch:SI 2 "=r,r"))]
600   "TARGET_POWERPC"
601   "@
602    extsb. %2,%1
603    #"
604   [(set_attr "type" "compare")
605    (set_attr "length" "4,8")])
606
607 (define_split
608   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
609         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
610                     (const_int 0)))
611    (clobber (match_scratch:SI 2 ""))]
612   "TARGET_POWERPC && reload_completed"
613   [(set (match_dup 2)
614         (sign_extend:SI (match_dup 1)))
615    (set (match_dup 0)
616         (compare:CC (match_dup 2)
617                     (const_int 0)))]
618   "")
619
620 (define_insn ""
621   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
622         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
623                     (const_int 0)))
624    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
625         (sign_extend:SI (match_dup 1)))]
626   "TARGET_POWERPC"
627   "@
628    extsb. %0,%1
629    #"
630   [(set_attr "type" "compare")
631    (set_attr "length" "4,8")])
632
633 (define_split
634   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
635         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
636                     (const_int 0)))
637    (set (match_operand:SI 0 "gpc_reg_operand" "")
638         (sign_extend:SI (match_dup 1)))]
639   "TARGET_POWERPC && reload_completed"
640   [(set (match_dup 0)
641         (sign_extend:SI (match_dup 1)))
642    (set (match_dup 2)
643         (compare:CC (match_dup 0)
644                     (const_int 0)))]
645   "")
646
647 (define_expand "extendqisi2_power"
648   [(parallel [(set (match_dup 2)
649                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
650                               (const_int 24)))
651               (clobber (scratch:SI))])
652    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
653                    (ashiftrt:SI (match_dup 2)
654                                 (const_int 24)))
655               (clobber (scratch:SI))])]
656   "TARGET_POWER"
657   "
658 { operands[1] = gen_lowpart (SImode, operands[1]);
659   operands[2] = gen_reg_rtx (SImode); }")
660
661 (define_expand "extendqisi2_no_power"
662   [(set (match_dup 2)
663         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
664                    (const_int 24)))
665    (set (match_operand:SI 0 "gpc_reg_operand" "")
666         (ashiftrt:SI (match_dup 2)
667                      (const_int 24)))]
668   "! TARGET_POWER && ! TARGET_POWERPC"
669   "
670 { operands[1] = gen_lowpart (SImode, operands[1]);
671   operands[2] = gen_reg_rtx (SImode); }")
672
673 (define_expand "zero_extendqihi2"
674   [(set (match_operand:HI 0 "gpc_reg_operand" "")
675         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
676   ""
677   "")
678
679 (define_insn ""
680   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
681         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
682   ""
683   "@
684    lbz%U1%X1 %0,%1
685    {rlinm|rlwinm} %0,%1,0,0xff"
686   [(set_attr "type" "load,*")])
687
688 (define_insn ""
689   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
690         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
691                     (const_int 0)))
692    (clobber (match_scratch:HI 2 "=r,r"))]
693   ""
694   "@
695    {andil.|andi.} %2,%1,0xff
696    #"
697   [(set_attr "type" "compare")
698    (set_attr "length" "4,8")])
699
700 (define_split
701   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
702         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
703                     (const_int 0)))
704    (clobber (match_scratch:HI 2 ""))]
705   "reload_completed"
706   [(set (match_dup 2)
707         (zero_extend:HI (match_dup 1)))
708    (set (match_dup 0)
709         (compare:CC (match_dup 2)
710                     (const_int 0)))]
711   "")
712
713 (define_insn ""
714   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
715         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
716                     (const_int 0)))
717    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
718         (zero_extend:HI (match_dup 1)))]
719   ""
720   "@
721    {andil.|andi.} %0,%1,0xff
722    #"
723   [(set_attr "type" "compare")
724    (set_attr "length" "4,8")])
725
726 (define_split
727   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
728         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
729                     (const_int 0)))
730    (set (match_operand:HI 0 "gpc_reg_operand" "")
731         (zero_extend:HI (match_dup 1)))]
732   "reload_completed"
733   [(set (match_dup 0)
734         (zero_extend:HI (match_dup 1)))
735    (set (match_dup 2)
736         (compare:CC (match_dup 0)
737                     (const_int 0)))]
738   "")
739
740 (define_expand "extendqihi2"
741   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
742    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
743   ""
744   "
745 {
746   if (TARGET_POWERPC)
747     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
748   else if (TARGET_POWER)
749     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
750   else
751     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
752   DONE;
753 }")
754
755 (define_insn "extendqihi2_ppc"
756   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
757         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
758   "TARGET_POWERPC"
759   "extsb %0,%1")
760
761 (define_insn ""
762   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
763         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
764                     (const_int 0)))
765    (clobber (match_scratch:HI 2 "=r,r"))]
766   "TARGET_POWERPC"
767   "@
768    extsb. %2,%1
769    #"
770   [(set_attr "type" "compare")
771    (set_attr "length" "4,8")])
772
773 (define_split
774   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
775         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
776                     (const_int 0)))
777    (clobber (match_scratch:HI 2 ""))]
778   "TARGET_POWERPC && reload_completed"
779   [(set (match_dup 2)
780         (sign_extend:HI (match_dup 1)))
781    (set (match_dup 0)
782         (compare:CC (match_dup 2)
783                     (const_int 0)))]
784   "")
785
786 (define_insn ""
787   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
788         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
789                     (const_int 0)))
790    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
791         (sign_extend:HI (match_dup 1)))]
792   "TARGET_POWERPC"
793   "@
794    extsb. %0,%1
795    #"
796   [(set_attr "type" "compare")
797    (set_attr "length" "4,8")])
798
799 (define_split
800   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
801         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
802                     (const_int 0)))
803    (set (match_operand:HI 0 "gpc_reg_operand" "")
804         (sign_extend:HI (match_dup 1)))]
805   "TARGET_POWERPC && reload_completed"
806   [(set (match_dup 0)
807         (sign_extend:HI (match_dup 1)))
808    (set (match_dup 2)
809         (compare:CC (match_dup 0)
810                     (const_int 0)))]
811   "")
812
813 (define_expand "extendqihi2_power"
814   [(parallel [(set (match_dup 2)
815                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
816                               (const_int 24)))
817               (clobber (scratch:SI))])
818    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
819                    (ashiftrt:SI (match_dup 2)
820                                 (const_int 24)))
821               (clobber (scratch:SI))])]
822   "TARGET_POWER"
823   "
824 { operands[0] = gen_lowpart (SImode, operands[0]);
825   operands[1] = gen_lowpart (SImode, operands[1]);
826   operands[2] = gen_reg_rtx (SImode); }")
827
828 (define_expand "extendqihi2_no_power"
829   [(set (match_dup 2)
830         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
831                    (const_int 24)))
832    (set (match_operand:HI 0 "gpc_reg_operand" "")
833         (ashiftrt:SI (match_dup 2)
834                      (const_int 24)))]
835   "! TARGET_POWER && ! TARGET_POWERPC"
836   "
837 { operands[0] = gen_lowpart (SImode, operands[0]);
838   operands[1] = gen_lowpart (SImode, operands[1]);
839   operands[2] = gen_reg_rtx (SImode); }")
840
841 (define_expand "zero_extendhisi2"
842   [(set (match_operand:SI 0 "gpc_reg_operand" "")
843         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
844   ""
845   "")
846
847 (define_insn ""
848   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
849         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
850   ""
851   "@
852    lhz%U1%X1 %0,%1
853    {rlinm|rlwinm} %0,%1,0,0xffff"
854   [(set_attr "type" "load,*")])
855
856 (define_insn ""
857   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
858         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
859                     (const_int 0)))
860    (clobber (match_scratch:SI 2 "=r,r"))]
861   ""
862   "@
863    {andil.|andi.} %2,%1,0xffff
864    #"
865   [(set_attr "type" "compare")
866    (set_attr "length" "4,8")])
867
868 (define_split
869   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
870         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
871                     (const_int 0)))
872    (clobber (match_scratch:SI 2 ""))]
873   "reload_completed"
874   [(set (match_dup 2)
875         (zero_extend:SI (match_dup 1)))
876    (set (match_dup 0)
877         (compare:CC (match_dup 2)
878                     (const_int 0)))]
879   "")
880
881 (define_insn ""
882   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
883         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
884                     (const_int 0)))
885    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
886         (zero_extend:SI (match_dup 1)))]
887   ""
888   "@
889    {andil.|andi.} %0,%1,0xffff
890    #"
891   [(set_attr "type" "compare")
892    (set_attr "length" "4,8")])
893
894 (define_split
895   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
896         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
897                     (const_int 0)))
898    (set (match_operand:SI 0 "gpc_reg_operand" "")
899         (zero_extend:SI (match_dup 1)))]
900   "reload_completed"
901   [(set (match_dup 0)
902         (zero_extend:SI (match_dup 1)))
903    (set (match_dup 2)
904         (compare:CC (match_dup 0)
905                     (const_int 0)))]
906   "")
907
908 (define_expand "extendhisi2"
909   [(set (match_operand:SI 0 "gpc_reg_operand" "")
910         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
911   ""
912   "")
913
914 (define_insn ""
915   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
916         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
917   ""
918   "@
919    lha%U1%X1 %0,%1
920    {exts|extsh} %0,%1"
921   [(set_attr "type" "load_ext,*")])
922
923 (define_insn ""
924   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
925         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
926                     (const_int 0)))
927    (clobber (match_scratch:SI 2 "=r,r"))]
928   ""
929   "@
930    {exts.|extsh.} %2,%1
931    #"
932   [(set_attr "type" "compare")
933    (set_attr "length" "4,8")])
934
935 (define_split
936   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
937         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
938                     (const_int 0)))
939    (clobber (match_scratch:SI 2 ""))]
940   "reload_completed"
941   [(set (match_dup 2)
942         (sign_extend:SI (match_dup 1)))
943    (set (match_dup 0)
944         (compare:CC (match_dup 2)
945                     (const_int 0)))]
946   "")
947
948 (define_insn ""
949   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
950         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
951                     (const_int 0)))
952    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
953         (sign_extend:SI (match_dup 1)))]
954   ""
955   "@
956    {exts.|extsh.} %0,%1
957    #"
958   [(set_attr "type" "compare")
959    (set_attr "length" "4,8")])
960 \f
961 (define_split
962   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
963         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
964                     (const_int 0)))
965    (set (match_operand:SI 0 "gpc_reg_operand" "")
966         (sign_extend:SI (match_dup 1)))]
967   "reload_completed"
968   [(set (match_dup 0)
969         (sign_extend:SI (match_dup 1)))
970    (set (match_dup 2)
971         (compare:CC (match_dup 0)
972                     (const_int 0)))]
973   "")
974
975 ;; Fixed-point arithmetic insns.
976
977 ;; Discourage ai/addic because of carry but provide it in an alternative
978 ;; allowing register zero as source.
979 (define_expand "addsi3"
980   [(set (match_operand:SI 0 "gpc_reg_operand" "")
981         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
982                  (match_operand:SI 2 "reg_or_arith_cint_operand" "")))]
983   ""
984   "
985 {
986   if (GET_CODE (operands[2]) == CONST_INT
987                 && ! add_operand (operands[2], SImode))
988     {
989       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
990                  ? operands[0] : gen_reg_rtx (SImode));
991
992       HOST_WIDE_INT val = INTVAL (operands[2]);
993       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
994       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, SImode);
995
996       /* The ordering here is important for the prolog expander.
997          When space is allocated from the stack, adding 'low' first may
998          produce a temporary deallocation (which would be bad).  */
999       emit_insn (gen_addsi3 (tmp, operands[1], GEN_INT (rest)));
1000       emit_insn (gen_addsi3 (operands[0], tmp, GEN_INT (low)));
1001       DONE;
1002     }
1003 }")
1004
1005 (define_insn "*addsi3_internal1"
1006   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,?r,r")
1007         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,b,r,b")
1008                  (match_operand:SI 2 "add_operand" "r,I,I,L")))]
1009   ""
1010   "@
1011    {cax|add} %0,%1,%2
1012    {cal %0,%2(%1)|addi %0,%1,%2}
1013    {ai|addic} %0,%1,%2
1014    {cau|addis} %0,%1,%v2"
1015   [(set_attr "length" "4,4,4,4")])
1016
1017 (define_insn "addsi3_high"
1018   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1019         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1020                  (high:SI (match_operand 2 "" ""))))]
1021   "TARGET_MACHO && !TARGET_64BIT"
1022   "{cau|addis} %0,%1,ha16(%2)"
1023   [(set_attr "length" "4")])
1024
1025 (define_insn "*addsi3_internal2"
1026   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1027         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1028                              (match_operand:SI 2 "reg_or_short_operand" "r,I,r,I"))
1029                     (const_int 0)))
1030    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
1031   "TARGET_32BIT"
1032   "@
1033    {cax.|add.} %3,%1,%2
1034    {ai.|addic.} %3,%1,%2
1035    #
1036    #"
1037   [(set_attr "type" "fast_compare,compare,compare,compare")
1038    (set_attr "length" "4,4,8,8")])
1039
1040 (define_split
1041   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1042         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1043                              (match_operand:SI 2 "reg_or_short_operand" ""))
1044                     (const_int 0)))
1045    (clobber (match_scratch:SI 3 ""))]
1046   "TARGET_32BIT && reload_completed"
1047   [(set (match_dup 3)
1048         (plus:SI (match_dup 1)
1049                  (match_dup 2)))
1050    (set (match_dup 0)
1051         (compare:CC (match_dup 3)
1052                     (const_int 0)))]
1053   "")
1054
1055 (define_insn "*addsi3_internal3"
1056   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1057         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1058                              (match_operand:SI 2 "reg_or_short_operand" "r,I,r,I"))
1059                     (const_int 0)))
1060    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1061         (plus:SI (match_dup 1)
1062                  (match_dup 2)))]
1063   "TARGET_32BIT"
1064   "@
1065    {cax.|add.} %0,%1,%2
1066    {ai.|addic.} %0,%1,%2
1067    #
1068    #"
1069   [(set_attr "type" "fast_compare,compare,compare,compare")
1070    (set_attr "length" "4,4,8,8")])
1071
1072 (define_split
1073   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1074         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1075                              (match_operand:SI 2 "reg_or_short_operand" ""))
1076                     (const_int 0)))
1077    (set (match_operand:SI 0 "gpc_reg_operand" "")
1078         (plus:SI (match_dup 1) (match_dup 2)))]
1079   "TARGET_32BIT && reload_completed"
1080   [(set (match_dup 0)
1081         (plus:SI (match_dup 1)
1082                  (match_dup 2)))
1083    (set (match_dup 3)
1084         (compare:CC (match_dup 0)
1085                     (const_int 0)))]
1086   "")
1087
1088 ;; Split an add that we can't do in one insn into two insns, each of which
1089 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1090 ;; add should be last in case the result gets used in an address.
1091
1092 (define_split
1093   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1094         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1095                  (match_operand:SI 2 "non_add_cint_operand" "")))]
1096   ""
1097   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
1098    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
1099 "
1100 {
1101   HOST_WIDE_INT val = INTVAL (operands[2]);
1102   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1103   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, SImode);
1104
1105   operands[3] = GEN_INT (rest);
1106   operands[4] = GEN_INT (low);
1107 }")
1108
1109 (define_insn "one_cmplsi2"
1110   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1111         (not:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1112   ""
1113   "nor %0,%1,%1")
1114
1115 (define_insn ""
1116   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1117         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1118                     (const_int 0)))
1119    (clobber (match_scratch:SI 2 "=r,r"))]
1120   "TARGET_32BIT"
1121   "@
1122    nor. %2,%1,%1
1123    #"
1124   [(set_attr "type" "compare")
1125    (set_attr "length" "4,8")])
1126
1127 (define_split
1128   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1129         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1130                     (const_int 0)))
1131    (clobber (match_scratch:SI 2 ""))]
1132   "TARGET_32BIT && reload_completed"
1133   [(set (match_dup 2)
1134         (not:SI (match_dup 1)))
1135    (set (match_dup 0)
1136         (compare:CC (match_dup 2)
1137                     (const_int 0)))]
1138   "")
1139
1140 (define_insn ""
1141   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1142         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1143                     (const_int 0)))
1144    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1145         (not:SI (match_dup 1)))]
1146   "TARGET_32BIT"
1147   "@
1148    nor. %0,%1,%1
1149    #"
1150   [(set_attr "type" "compare")
1151    (set_attr "length" "4,8")])
1152
1153 (define_split
1154   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1155         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1156                     (const_int 0)))
1157    (set (match_operand:SI 0 "gpc_reg_operand" "")
1158         (not:SI (match_dup 1)))]
1159   "TARGET_32BIT && reload_completed"
1160   [(set (match_dup 0)
1161         (not:SI (match_dup 1)))
1162    (set (match_dup 2)
1163         (compare:CC (match_dup 0)
1164                     (const_int 0)))]
1165   "")
1166
1167 (define_insn ""
1168   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1169         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1170                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1171   "! TARGET_POWERPC"
1172   "{sf%I1|subf%I1c} %0,%2,%1")
1173
1174 (define_insn ""
1175   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1176         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "r,I")
1177                   (match_operand:SI 2 "gpc_reg_operand" "r,r")))]
1178   "TARGET_POWERPC"
1179   "@
1180    subf %0,%2,%1
1181    subfic %0,%2,%1")
1182
1183 (define_insn ""
1184   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1185         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1186                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1187                     (const_int 0)))
1188    (clobber (match_scratch:SI 3 "=r,r"))]
1189   "! TARGET_POWERPC"
1190   "@
1191    {sf.|subfc.} %3,%2,%1
1192    #"
1193   [(set_attr "type" "compare")
1194    (set_attr "length" "4,8")])
1195
1196 (define_insn ""
1197   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1198         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1199                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1200                     (const_int 0)))
1201    (clobber (match_scratch:SI 3 "=r,r"))]
1202   "TARGET_POWERPC && TARGET_32BIT"
1203   "@
1204    subf. %3,%2,%1
1205    #"
1206   [(set_attr "type" "fast_compare")
1207    (set_attr "length" "4,8")])
1208
1209 (define_split
1210   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1211         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1212                               (match_operand:SI 2 "gpc_reg_operand" ""))
1213                     (const_int 0)))
1214    (clobber (match_scratch:SI 3 ""))]
1215   "TARGET_32BIT && reload_completed"
1216   [(set (match_dup 3)
1217         (minus:SI (match_dup 1)
1218                   (match_dup 2)))
1219    (set (match_dup 0)
1220         (compare:CC (match_dup 3)
1221                     (const_int 0)))]
1222   "")
1223
1224 (define_insn ""
1225   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1226         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1227                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1228                     (const_int 0)))
1229    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1230         (minus:SI (match_dup 1) (match_dup 2)))]
1231   "! TARGET_POWERPC"
1232   "@
1233    {sf.|subfc.} %0,%2,%1
1234    #"
1235   [(set_attr "type" "compare")
1236    (set_attr "length" "4,8")])
1237
1238 (define_insn ""
1239   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1240         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1241                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1242                     (const_int 0)))
1243    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1244         (minus:SI (match_dup 1)
1245                   (match_dup 2)))]
1246   "TARGET_POWERPC && TARGET_32BIT"
1247   "@
1248    subf. %0,%2,%1
1249    #"
1250   [(set_attr "type" "fast_compare")
1251    (set_attr "length" "4,8")])
1252
1253 (define_split
1254   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1255         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1256                               (match_operand:SI 2 "gpc_reg_operand" ""))
1257                     (const_int 0)))
1258    (set (match_operand:SI 0 "gpc_reg_operand" "")
1259         (minus:SI (match_dup 1)
1260                   (match_dup 2)))]
1261   "TARGET_32BIT && reload_completed"
1262   [(set (match_dup 0)
1263         (minus:SI (match_dup 1)
1264                   (match_dup 2)))
1265    (set (match_dup 3)
1266         (compare:CC (match_dup 0)
1267                     (const_int 0)))]
1268   "")
1269
1270 (define_expand "subsi3"
1271   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1272         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "")
1273                   (match_operand:SI 2 "reg_or_arith_cint_operand" "")))]
1274   ""
1275   "
1276 {
1277   if (GET_CODE (operands[2]) == CONST_INT)
1278     {
1279       emit_insn (gen_addsi3 (operands[0], operands[1],
1280                              negate_rtx (SImode, operands[2])));
1281       DONE;
1282     }
1283 }")
1284
1285 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1286 ;; instruction and some auxiliary computations.  Then we just have a single
1287 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1288 ;; combine.
1289
1290 (define_expand "sminsi3"
1291   [(set (match_dup 3)
1292         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1293                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1294                          (const_int 0)
1295                          (minus:SI (match_dup 2) (match_dup 1))))
1296    (set (match_operand:SI 0 "gpc_reg_operand" "")
1297         (minus:SI (match_dup 2) (match_dup 3)))]
1298   "TARGET_POWER || TARGET_ISEL"
1299   "
1300 {
1301   if (TARGET_ISEL)
1302     {
1303       operands[2] = force_reg (SImode, operands[2]);
1304       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1305       DONE;
1306     }
1307
1308   operands[3] = gen_reg_rtx (SImode);
1309 }")
1310
1311 (define_split
1312   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1313         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1314                  (match_operand:SI 2 "reg_or_short_operand" "")))
1315    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1316   "TARGET_POWER"
1317   [(set (match_dup 3)
1318         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1319                          (const_int 0)
1320                          (minus:SI (match_dup 2) (match_dup 1))))
1321    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1322   "")
1323
1324 (define_expand "smaxsi3"
1325   [(set (match_dup 3)
1326         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1327                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1328                          (const_int 0)
1329                          (minus:SI (match_dup 2) (match_dup 1))))
1330    (set (match_operand:SI 0 "gpc_reg_operand" "")
1331         (plus:SI (match_dup 3) (match_dup 1)))]
1332   "TARGET_POWER || TARGET_ISEL"
1333   "
1334 {
1335   if (TARGET_ISEL)
1336     {
1337       operands[2] = force_reg (SImode, operands[2]);
1338       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1339       DONE;
1340     }
1341   operands[3] = gen_reg_rtx (SImode);
1342 }")
1343
1344 (define_split
1345   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1346         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1347                  (match_operand:SI 2 "reg_or_short_operand" "")))
1348    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1349   "TARGET_POWER"
1350   [(set (match_dup 3)
1351         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1352                          (const_int 0)
1353                          (minus:SI (match_dup 2) (match_dup 1))))
1354    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1355   "")
1356
1357 (define_expand "uminsi3"
1358   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1359                               (match_dup 5)))
1360    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1361                               (match_dup 5)))
1362    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1363                                        (const_int 0)
1364                                        (minus:SI (match_dup 4) (match_dup 3))))
1365    (set (match_operand:SI 0 "gpc_reg_operand" "")
1366         (minus:SI (match_dup 2) (match_dup 3)))]
1367   "TARGET_POWER || TARGET_ISEL"
1368   "
1369 {
1370   if (TARGET_ISEL)
1371     {
1372       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1373       DONE;
1374     }
1375   operands[3] = gen_reg_rtx (SImode);
1376   operands[4] = gen_reg_rtx (SImode);
1377   operands[5] = GEN_INT (-2147483647 - 1);
1378 }")
1379
1380 (define_expand "umaxsi3"
1381   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1382                               (match_dup 5)))
1383    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1384                               (match_dup 5)))
1385    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1386                                        (const_int 0)
1387                                        (minus:SI (match_dup 4) (match_dup 3))))
1388    (set (match_operand:SI 0 "gpc_reg_operand" "")
1389         (plus:SI (match_dup 3) (match_dup 1)))]
1390   "TARGET_POWER || TARGET_ISEL"
1391   "
1392 {
1393   if (TARGET_ISEL)
1394     {
1395       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1396       DONE;
1397     }
1398   operands[3] = gen_reg_rtx (SImode);
1399   operands[4] = gen_reg_rtx (SImode);
1400   operands[5] = GEN_INT (-2147483647 - 1);
1401 }")
1402
1403 (define_insn ""
1404   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1405         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1406                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1407                          (const_int 0)
1408                          (minus:SI (match_dup 2) (match_dup 1))))]
1409   "TARGET_POWER"
1410   "doz%I2 %0,%1,%2")
1411
1412 (define_insn ""
1413   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1414         (compare:CC
1415          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1416                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1417                           (const_int 0)
1418                           (minus:SI (match_dup 2) (match_dup 1)))
1419          (const_int 0)))
1420    (clobber (match_scratch:SI 3 "=r,r"))]
1421   "TARGET_POWER"
1422   "@
1423    doz%I2. %3,%1,%2
1424    #"
1425   [(set_attr "type" "delayed_compare")
1426    (set_attr "length" "4,8")])
1427
1428 (define_split
1429   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1430         (compare:CC
1431          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1432                               (match_operand:SI 2 "reg_or_short_operand" ""))
1433                           (const_int 0)
1434                           (minus:SI (match_dup 2) (match_dup 1)))
1435          (const_int 0)))
1436    (clobber (match_scratch:SI 3 ""))]
1437   "TARGET_POWER && reload_completed"
1438   [(set (match_dup 3)
1439         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1440                           (const_int 0)
1441                           (minus:SI (match_dup 2) (match_dup 1))))
1442    (set (match_dup 0)
1443         (compare:CC (match_dup 3)
1444                     (const_int 0)))]
1445   "")
1446
1447 (define_insn ""
1448   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1449         (compare:CC
1450          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1451                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1452                           (const_int 0)
1453                           (minus:SI (match_dup 2) (match_dup 1)))
1454          (const_int 0)))
1455    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1456         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1457                          (const_int 0)
1458                          (minus:SI (match_dup 2) (match_dup 1))))]
1459   "TARGET_POWER"
1460   "@
1461    doz%I2. %0,%1,%2
1462    #"
1463   [(set_attr "type" "delayed_compare")
1464    (set_attr "length" "4,8")])
1465
1466 (define_split
1467   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1468         (compare:CC
1469          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1470                               (match_operand:SI 2 "reg_or_short_operand" ""))
1471                           (const_int 0)
1472                           (minus:SI (match_dup 2) (match_dup 1)))
1473          (const_int 0)))
1474    (set (match_operand:SI 0 "gpc_reg_operand" "")
1475         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1476                          (const_int 0)
1477                          (minus:SI (match_dup 2) (match_dup 1))))]
1478   "TARGET_POWER && reload_completed"
1479   [(set (match_dup 0)
1480         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1481                          (const_int 0)
1482                          (minus:SI (match_dup 2) (match_dup 1))))
1483    (set (match_dup 3)
1484         (compare:CC (match_dup 0)
1485                     (const_int 0)))]
1486   "")
1487
1488 ;; We don't need abs with condition code because such comparisons should
1489 ;; never be done.
1490 (define_expand "abssi2"
1491   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1492         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1493   ""
1494   "
1495 {
1496   if (TARGET_ISEL)
1497     {
1498       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
1499       DONE;
1500     }
1501   else if (! TARGET_POWER)
1502     {
1503       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1504       DONE;
1505     }
1506 }")
1507
1508 (define_insn "*abssi2_power"
1509   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1510         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1511   "TARGET_POWER"
1512   "abs %0,%1")
1513
1514 (define_insn_and_split "abssi2_isel"
1515   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1516         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
1517    (clobber (match_scratch:SI 2 "=&b"))
1518    (clobber (match_scratch:CC 3 "=y"))]
1519   "TARGET_ISEL"
1520   "#"
1521   "&& reload_completed"
1522   [(set (match_dup 2) (neg:SI (match_dup 1)))
1523    (set (match_dup 3)
1524         (compare:CC (match_dup 1)
1525                     (const_int 0)))
1526    (set (match_dup 0)
1527         (if_then_else:SI (ge (match_dup 3)
1528                              (const_int 0))
1529                          (match_dup 1)
1530                          (match_dup 2)))]
1531   "")
1532
1533 (define_insn_and_split "abssi2_nopower"
1534   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1535         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1536    (clobber (match_scratch:SI 2 "=&r,&r"))]
1537   "! TARGET_POWER && ! TARGET_ISEL"
1538   "#"
1539   "&& reload_completed"
1540   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1541    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1542    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1543   "")
1544
1545 (define_insn "*nabs_power"
1546   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1547         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
1548   "TARGET_POWER"
1549   "nabs %0,%1")
1550
1551 (define_insn_and_split "*nabs_nopower"
1552   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1553         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1554    (clobber (match_scratch:SI 2 "=&r,&r"))]
1555   "! TARGET_POWER"
1556   "#"
1557   "&& reload_completed"
1558   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1559    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1560    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
1561   "")
1562
1563 (define_insn "negsi2"
1564   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1565         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1566   ""
1567   "neg %0,%1")
1568
1569 (define_insn ""
1570   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1571         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1572                     (const_int 0)))
1573    (clobber (match_scratch:SI 2 "=r,r"))]
1574   "TARGET_32BIT"
1575   "@
1576    neg. %2,%1
1577    #"
1578   [(set_attr "type" "fast_compare")
1579    (set_attr "length" "4,8")])
1580
1581 (define_split
1582   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1583         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1584                     (const_int 0)))
1585    (clobber (match_scratch:SI 2 ""))]
1586   "TARGET_32BIT && reload_completed"
1587   [(set (match_dup 2)
1588         (neg:SI (match_dup 1)))
1589    (set (match_dup 0)
1590         (compare:CC (match_dup 2)
1591                     (const_int 0)))]
1592   "")
1593
1594 (define_insn ""
1595   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1596         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1597                     (const_int 0)))
1598    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1599         (neg:SI (match_dup 1)))]
1600   "TARGET_32BIT"
1601   "@
1602    neg. %0,%1
1603    #"
1604   [(set_attr "type" "fast_compare")
1605    (set_attr "length" "4,8")])
1606
1607 (define_split
1608   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1609         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1610                     (const_int 0)))
1611    (set (match_operand:SI 0 "gpc_reg_operand" "")
1612         (neg:SI (match_dup 1)))]
1613   "TARGET_32BIT && reload_completed"
1614   [(set (match_dup 0)
1615         (neg:SI (match_dup 1)))
1616    (set (match_dup 2)
1617         (compare:CC (match_dup 0)
1618                     (const_int 0)))]
1619   "")
1620
1621 (define_insn "clzsi2"
1622   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1623         (clz:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1624   ""
1625   "{cntlz|cntlzw} %0,%1")
1626
1627 (define_expand "ctzsi2"
1628   [(set (match_dup 2)
1629         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
1630    (parallel [(set (match_dup 3) (and:SI (match_dup 1)
1631                                          (match_dup 2)))
1632               (clobber (scratch:CC))])
1633    (set (match_dup 4) (clz:SI (match_dup 3)))
1634    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1635         (minus:SI (const_int 31) (match_dup 4)))]
1636   ""
1637   {
1638      operands[2] = gen_reg_rtx (SImode);
1639      operands[3] = gen_reg_rtx (SImode);
1640      operands[4] = gen_reg_rtx (SImode);
1641   })
1642
1643 (define_expand "ffssi2"
1644   [(set (match_dup 2)
1645         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
1646    (parallel [(set (match_dup 3) (and:SI (match_dup 1)
1647                                          (match_dup 2)))
1648               (clobber (scratch:CC))])
1649    (set (match_dup 4) (clz:SI (match_dup 3)))
1650    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1651         (minus:SI (const_int 32) (match_dup 4)))]
1652   ""
1653   {
1654      operands[2] = gen_reg_rtx (SImode);
1655      operands[3] = gen_reg_rtx (SImode);
1656      operands[4] = gen_reg_rtx (SImode);
1657   })
1658
1659 (define_expand "mulsi3"
1660   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1661    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1662    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
1663   ""
1664   "
1665 {
1666   if (TARGET_POWER)
1667     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
1668   else
1669     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
1670   DONE;
1671 }")
1672
1673 (define_insn "mulsi3_mq"
1674   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1675         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1676                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
1677    (clobber (match_scratch:SI 3 "=q,q"))]
1678   "TARGET_POWER"
1679   "@
1680    {muls|mullw} %0,%1,%2
1681    {muli|mulli} %0,%1,%2"
1682    [(set (attr "type")
1683       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
1684                 (const_string "imul3")
1685              (match_operand:SI 2 "short_cint_operand" "")
1686                 (const_string "imul2")]
1687         (const_string "imul")))])
1688
1689 (define_insn "mulsi3_no_mq"
1690   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1691         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1692                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
1693   "! TARGET_POWER"
1694   "@
1695    {muls|mullw} %0,%1,%2
1696    {muli|mulli} %0,%1,%2"
1697    [(set (attr "type")
1698       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
1699                 (const_string "imul3")
1700              (match_operand:SI 2 "short_cint_operand" "")
1701                 (const_string "imul2")]
1702         (const_string "imul")))])
1703
1704 (define_insn "*mulsi3_mq_internal1"
1705   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1706         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1707                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1708                     (const_int 0)))
1709    (clobber (match_scratch:SI 3 "=r,r"))
1710    (clobber (match_scratch:SI 4 "=q,q"))]
1711   "TARGET_POWER"
1712   "@
1713    {muls.|mullw.} %3,%1,%2
1714    #"
1715   [(set_attr "type" "imul_compare")
1716    (set_attr "length" "4,8")])
1717
1718 (define_split
1719   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1720         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1721                              (match_operand:SI 2 "gpc_reg_operand" ""))
1722                     (const_int 0)))
1723    (clobber (match_scratch:SI 3 ""))
1724    (clobber (match_scratch:SI 4 ""))]
1725   "TARGET_POWER && reload_completed"
1726   [(parallel [(set (match_dup 3)
1727         (mult:SI (match_dup 1) (match_dup 2)))
1728    (clobber (match_dup 4))])
1729    (set (match_dup 0)
1730         (compare:CC (match_dup 3)
1731                     (const_int 0)))]
1732   "")
1733
1734 (define_insn "*mulsi3_no_mq_internal1"
1735   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1736         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1737                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1738                     (const_int 0)))
1739    (clobber (match_scratch:SI 3 "=r,r"))]
1740   "! TARGET_POWER"
1741   "@
1742    {muls.|mullw.} %3,%1,%2
1743    #"
1744   [(set_attr "type" "imul_compare")
1745    (set_attr "length" "4,8")])
1746
1747 (define_split
1748   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1749         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1750                              (match_operand:SI 2 "gpc_reg_operand" ""))
1751                     (const_int 0)))
1752    (clobber (match_scratch:SI 3 ""))]
1753   "! TARGET_POWER && reload_completed"
1754   [(set (match_dup 3)
1755         (mult:SI (match_dup 1) (match_dup 2)))
1756    (set (match_dup 0)
1757         (compare:CC (match_dup 3)
1758                     (const_int 0)))]
1759   "")
1760
1761 (define_insn "*mulsi3_mq_internal2"
1762   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1763         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1764                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1765                     (const_int 0)))
1766    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1767         (mult:SI (match_dup 1) (match_dup 2)))
1768    (clobber (match_scratch:SI 4 "=q,q"))]
1769   "TARGET_POWER"
1770   "@
1771    {muls.|mullw.} %0,%1,%2
1772    #"
1773   [(set_attr "type" "imul_compare")
1774    (set_attr "length" "4,8")])
1775
1776 (define_split
1777   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1778         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1779                              (match_operand:SI 2 "gpc_reg_operand" ""))
1780                     (const_int 0)))
1781    (set (match_operand:SI 0 "gpc_reg_operand" "")
1782         (mult:SI (match_dup 1) (match_dup 2)))
1783    (clobber (match_scratch:SI 4 ""))]
1784   "TARGET_POWER && reload_completed"
1785   [(parallel [(set (match_dup 0)
1786         (mult:SI (match_dup 1) (match_dup 2)))
1787    (clobber (match_dup 4))])
1788    (set (match_dup 3)
1789         (compare:CC (match_dup 0)
1790                     (const_int 0)))]
1791   "")
1792
1793 (define_insn "*mulsi3_no_mq_internal2"
1794   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1795         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1796                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1797                     (const_int 0)))
1798    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1799         (mult:SI (match_dup 1) (match_dup 2)))]
1800   "! TARGET_POWER"
1801   "@
1802    {muls.|mullw.} %0,%1,%2
1803    #"
1804   [(set_attr "type" "imul_compare")
1805    (set_attr "length" "4,8")])
1806
1807 (define_split
1808   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1809         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
1810                              (match_operand:SI 2 "gpc_reg_operand" ""))
1811                     (const_int 0)))
1812    (set (match_operand:SI 0 "gpc_reg_operand" "")
1813         (mult:SI (match_dup 1) (match_dup 2)))]
1814   "! TARGET_POWER && reload_completed"
1815   [(set (match_dup 0)
1816         (mult:SI (match_dup 1) (match_dup 2)))
1817    (set (match_dup 3)
1818         (compare:CC (match_dup 0)
1819                     (const_int 0)))]
1820   "")
1821
1822 ;; Operand 1 is divided by operand 2; quotient goes to operand
1823 ;; 0 and remainder to operand 3.
1824 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
1825
1826 (define_expand "divmodsi4"
1827   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1828                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1829                            (match_operand:SI 2 "gpc_reg_operand" "")))
1830               (set (match_operand:SI 3 "register_operand" "")
1831                    (mod:SI (match_dup 1) (match_dup 2)))])]
1832   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
1833   "
1834 {
1835   if (! TARGET_POWER && ! TARGET_POWERPC)
1836     {
1837       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1838       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1839       emit_insn (gen_divss_call ());
1840       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1841       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
1842       DONE;
1843     }
1844 }")
1845
1846 (define_insn "*divmodsi4_internal"
1847   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1848         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1849                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1850    (set (match_operand:SI 3 "register_operand" "=q")
1851         (mod:SI (match_dup 1) (match_dup 2)))]
1852   "TARGET_POWER"
1853   "divs %0,%1,%2"
1854   [(set_attr "type" "idiv")])
1855
1856 (define_expand "udivsi3"
1857   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1858         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1859                  (match_operand:SI 2 "gpc_reg_operand" "")))]
1860   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
1861   "
1862 {
1863   if (! TARGET_POWER && ! TARGET_POWERPC)
1864     {
1865       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1866       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1867       emit_insn (gen_quous_call ());
1868       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1869       DONE;
1870     }
1871   else if (TARGET_POWER)
1872     {
1873       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
1874       DONE;
1875     }
1876 }")
1877
1878 (define_insn "udivsi3_mq"
1879   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1880         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1881                  (match_operand:SI 2 "gpc_reg_operand" "r")))
1882    (clobber (match_scratch:SI 3 "=q"))]
1883   "TARGET_POWERPC && TARGET_POWER"
1884   "divwu %0,%1,%2"
1885   [(set_attr "type" "idiv")])
1886
1887 (define_insn "*udivsi3_no_mq"
1888   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1889         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1890                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
1891   "TARGET_POWERPC && ! TARGET_POWER"
1892   "divwu %0,%1,%2"
1893   [(set_attr "type" "idiv")])
1894
1895 ;; For powers of two we can do srai/aze for divide and then adjust for
1896 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
1897 ;; used; for PowerPC, force operands into register and do a normal divide;
1898 ;; for AIX common-mode, use quoss call on register operands.
1899 (define_expand "divsi3"
1900   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1901         (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1902                 (match_operand:SI 2 "reg_or_cint_operand" "")))]
1903   ""
1904   "
1905 {
1906   if (GET_CODE (operands[2]) == CONST_INT
1907       && INTVAL (operands[2]) > 0
1908       && exact_log2 (INTVAL (operands[2])) >= 0)
1909     ;
1910   else if (TARGET_POWERPC)
1911     {
1912       operands[2] = force_reg (SImode, operands[2]);
1913       if (TARGET_POWER)
1914         {
1915           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
1916           DONE;
1917         }
1918     }
1919   else if (TARGET_POWER)
1920     FAIL;
1921   else
1922     {
1923       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
1924       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
1925       emit_insn (gen_quoss_call ());
1926       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
1927       DONE;
1928     }
1929 }")
1930
1931 (define_insn "divsi3_mq"
1932   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1933         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1934                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1935    (clobber (match_scratch:SI 3 "=q"))]
1936   "TARGET_POWERPC && TARGET_POWER"
1937   "divw %0,%1,%2"
1938   [(set_attr "type" "idiv")])
1939
1940 (define_insn "*divsi3_no_mq"
1941   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1942         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1943                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1944   "TARGET_POWERPC && ! TARGET_POWER"
1945   "divw %0,%1,%2"
1946   [(set_attr "type" "idiv")])
1947
1948 (define_expand "modsi3"
1949   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1950    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1951    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
1952   ""
1953   "
1954 {
1955   int i;
1956   rtx temp1;
1957   rtx temp2;
1958
1959   if (GET_CODE (operands[2]) != CONST_INT
1960       || INTVAL (operands[2]) <= 0
1961       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
1962     FAIL;
1963
1964   temp1 = gen_reg_rtx (SImode);
1965   temp2 = gen_reg_rtx (SImode);
1966
1967   emit_insn (gen_divsi3 (temp1, operands[1], operands[2]));
1968   emit_insn (gen_ashlsi3 (temp2, temp1, GEN_INT (i)));
1969   emit_insn (gen_subsi3 (operands[0], operands[1], temp2));
1970   DONE;
1971 }")
1972
1973 (define_insn ""
1974   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1975         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1976                 (match_operand:SI 2 "exact_log2_cint_operand" "N")))]
1977   ""
1978   "{srai|srawi} %0,%1,%p2\;{aze|addze} %0,%0"
1979   [(set_attr "type" "two")
1980    (set_attr "length" "8")])
1981
1982 (define_insn ""
1983   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1984         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1985                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
1986                     (const_int 0)))
1987    (clobber (match_scratch:SI 3 "=r,r"))]
1988   ""
1989   "@
1990    {srai|srawi} %3,%1,%p2\;{aze.|addze.} %3,%3
1991    #"
1992   [(set_attr "type" "compare")
1993    (set_attr "length" "8,12")])
1994
1995 (define_split
1996   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1997         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1998                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
1999                     (const_int 0)))
2000    (clobber (match_scratch:SI 3 ""))]
2001   "reload_completed"
2002   [(set (match_dup 3)
2003         (div:SI (match_dup 1) (match_dup 2)))
2004    (set (match_dup 0)
2005         (compare:CC (match_dup 3)
2006                     (const_int 0)))]
2007   "")
2008
2009 (define_insn ""
2010   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2011         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2012                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
2013                     (const_int 0)))
2014    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2015         (div:SI (match_dup 1) (match_dup 2)))]
2016   ""
2017   "@
2018    {srai|srawi} %0,%1,%p2\;{aze.|addze.} %0,%0
2019    #"
2020   [(set_attr "type" "compare")
2021    (set_attr "length" "8,12")])
2022
2023 (define_split
2024   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2025         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2026                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
2027                     (const_int 0)))
2028    (set (match_operand:SI 0 "gpc_reg_operand" "")
2029         (div:SI (match_dup 1) (match_dup 2)))]
2030   "reload_completed"
2031   [(set (match_dup 0)
2032         (div:SI (match_dup 1) (match_dup 2)))
2033    (set (match_dup 3)
2034         (compare:CC (match_dup 0)
2035                     (const_int 0)))]
2036   "")
2037
2038 (define_insn ""
2039   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2040         (udiv:SI
2041          (plus:DI (ashift:DI
2042                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
2043                    (const_int 32))
2044                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
2045          (match_operand:SI 3 "gpc_reg_operand" "r")))
2046    (set (match_operand:SI 2 "register_operand" "=*q")
2047         (umod:SI
2048          (plus:DI (ashift:DI
2049                    (zero_extend:DI (match_dup 1)) (const_int 32))
2050                   (zero_extend:DI (match_dup 4)))
2051          (match_dup 3)))]
2052   "TARGET_POWER"
2053   "div %0,%1,%3"
2054   [(set_attr "type" "idiv")])
2055
2056 ;; To do unsigned divide we handle the cases of the divisor looking like a
2057 ;; negative number.  If it is a constant that is less than 2**31, we don't
2058 ;; have to worry about the branches.  So make a few subroutines here.
2059 ;;
2060 ;; First comes the normal case.
2061 (define_expand "udivmodsi4_normal"
2062   [(set (match_dup 4) (const_int 0))
2063    (parallel [(set (match_operand:SI 0 "" "")
2064                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2065                                                 (const_int 32))
2066                                      (zero_extend:DI (match_operand:SI 1 "" "")))
2067                             (match_operand:SI 2 "" "")))
2068               (set (match_operand:SI 3 "" "")
2069                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2070                                                 (const_int 32))
2071                                      (zero_extend:DI (match_dup 1)))
2072                             (match_dup 2)))])]
2073   "TARGET_POWER"
2074   "
2075 { operands[4] = gen_reg_rtx (SImode); }")
2076
2077 ;; This handles the branches.
2078 (define_expand "udivmodsi4_tests"
2079   [(set (match_operand:SI 0 "" "") (const_int 0))
2080    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
2081    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
2082    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
2083                            (label_ref (match_operand:SI 4 "" "")) (pc)))
2084    (set (match_dup 0) (const_int 1))
2085    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
2086    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
2087    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
2088                            (label_ref (match_dup 4)) (pc)))]
2089   "TARGET_POWER"
2090   "
2091 { operands[5] = gen_reg_rtx (CCUNSmode);
2092   operands[6] = gen_reg_rtx (CCmode);
2093 }")
2094
2095 (define_expand "udivmodsi4"
2096   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2097                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2098                             (match_operand:SI 2 "reg_or_cint_operand" "")))
2099               (set (match_operand:SI 3 "gpc_reg_operand" "")
2100                    (umod:SI (match_dup 1) (match_dup 2)))])]
2101   ""
2102   "
2103 {
2104   rtx label = 0;
2105
2106   if (! TARGET_POWER)
2107     {
2108       if (! TARGET_POWERPC)
2109         {
2110           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2111           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2112           emit_insn (gen_divus_call ());
2113           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2114           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2115           DONE;
2116         }
2117       else
2118         FAIL;
2119     }
2120
2121   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
2122     {
2123       operands[2] = force_reg (SImode, operands[2]);
2124       label = gen_label_rtx ();
2125       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
2126                                   operands[3], label));
2127     }
2128   else
2129     operands[2] = force_reg (SImode, operands[2]);
2130
2131   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
2132                                operands[3]));
2133   if (label)
2134     emit_label (label);
2135
2136   DONE;
2137 }")
2138
2139 ;; AIX architecture-independent common-mode multiply (DImode),
2140 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
2141 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
2142 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
2143 ;; assumed unused if generating common-mode, so ignore.
2144 (define_insn "mulh_call"
2145   [(set (reg:SI 3)
2146         (truncate:SI
2147          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
2148                                (sign_extend:DI (reg:SI 4)))
2149                       (const_int 32))))
2150    (clobber (match_scratch:SI 0 "=l"))]
2151   "! TARGET_POWER && ! TARGET_POWERPC"
2152   "bla __mulh"
2153   [(set_attr "type" "imul")])
2154
2155 (define_insn "mull_call"
2156   [(set (reg:DI 3)
2157         (mult:DI (sign_extend:DI (reg:SI 3))
2158                  (sign_extend:DI (reg:SI 4))))
2159    (clobber (match_scratch:SI 0 "=l"))
2160    (clobber (reg:SI 0))]
2161   "! TARGET_POWER && ! TARGET_POWERPC"
2162   "bla __mull"
2163   [(set_attr "type" "imul")])
2164
2165 (define_insn "divss_call"
2166   [(set (reg:SI 3)
2167         (div:SI (reg:SI 3) (reg:SI 4)))
2168    (set (reg:SI 4)
2169         (mod:SI (reg:SI 3) (reg:SI 4)))
2170    (clobber (match_scratch:SI 0 "=l"))
2171    (clobber (reg:SI 0))]
2172   "! TARGET_POWER && ! TARGET_POWERPC"
2173   "bla __divss"
2174   [(set_attr "type" "idiv")])
2175
2176 (define_insn "divus_call"
2177   [(set (reg:SI 3)
2178         (udiv:SI (reg:SI 3) (reg:SI 4)))
2179    (set (reg:SI 4)
2180         (umod:SI (reg:SI 3) (reg:SI 4)))
2181    (clobber (match_scratch:SI 0 "=l"))
2182    (clobber (reg:SI 0))
2183    (clobber (match_scratch:CC 1 "=x"))
2184    (clobber (reg:CC 69))]
2185   "! TARGET_POWER && ! TARGET_POWERPC"
2186   "bla __divus"
2187   [(set_attr "type" "idiv")])
2188
2189 (define_insn "quoss_call"
2190   [(set (reg:SI 3)
2191         (div:SI (reg:SI 3) (reg:SI 4)))
2192    (clobber (match_scratch:SI 0 "=l"))]
2193   "! TARGET_POWER && ! TARGET_POWERPC"
2194   "bla __quoss"
2195   [(set_attr "type" "idiv")])
2196
2197 (define_insn "quous_call"
2198   [(set (reg:SI 3)
2199         (udiv:SI (reg:SI 3) (reg:SI 4)))
2200    (clobber (match_scratch:SI 0 "=l"))
2201    (clobber (reg:SI 0))
2202    (clobber (match_scratch:CC 1 "=x"))
2203    (clobber (reg:CC 69))]
2204   "! TARGET_POWER && ! TARGET_POWERPC"
2205   "bla __quous"
2206   [(set_attr "type" "idiv")])
2207 \f
2208 ;; Logical instructions
2209 ;; The logical instructions are mostly combined by using match_operator,
2210 ;; but the plain AND insns are somewhat different because there is no
2211 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2212 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2213
2214 (define_insn "andsi3"
2215   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2216         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2217                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2218    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2219   ""
2220   "@
2221    and %0,%1,%2
2222    {rlinm|rlwinm} %0,%1,0,%m2,%M2
2223    {andil.|andi.} %0,%1,%b2
2224    {andiu.|andis.} %0,%1,%u2"
2225   [(set_attr "type" "*,*,compare,compare")])
2226
2227 ;; Note to set cr's other than cr0 we do the and immediate and then
2228 ;; the test again -- this avoids a mfcr which on the higher end
2229 ;; machines causes an execution serialization
2230
2231 (define_insn "*andsi3_internal2"
2232   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2233         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2234                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2235                     (const_int 0)))
2236    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2237    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2238   "TARGET_32BIT"
2239   "@
2240    and. %3,%1,%2
2241    {andil.|andi.} %3,%1,%b2
2242    {andiu.|andis.} %3,%1,%u2
2243    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2244    #
2245    #
2246    #
2247    #"
2248   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2249    (set_attr "length" "4,4,4,4,8,8,8,8")])
2250
2251 (define_insn "*andsi3_internal3"
2252   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2253         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2254                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2255                     (const_int 0)))
2256    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2257    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2258   "TARGET_64BIT"
2259   "@
2260    #
2261    {andil.|andi.} %3,%1,%b2
2262    {andiu.|andis.} %3,%1,%u2
2263    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2264    #
2265    #
2266    #
2267    #"
2268   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2269    (set_attr "length" "8,4,4,4,8,8,8,8")])
2270
2271 (define_split
2272   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2273         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2274                             (match_operand:SI 2 "and_operand" ""))
2275                     (const_int 0)))
2276    (clobber (match_scratch:SI 3 ""))
2277    (clobber (match_scratch:CC 4 ""))]
2278   "reload_completed"
2279   [(parallel [(set (match_dup 3)
2280                    (and:SI (match_dup 1)
2281                            (match_dup 2)))
2282               (clobber (match_dup 4))])
2283    (set (match_dup 0)
2284         (compare:CC (match_dup 3)
2285                     (const_int 0)))]
2286   "")
2287
2288 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2289 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2290
2291 (define_split
2292   [(set (match_operand:CC 0 "cc_reg_operand" "")
2293         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2294                             (match_operand:SI 2 "gpc_reg_operand" ""))
2295                     (const_int 0)))
2296    (clobber (match_scratch:SI 3 ""))
2297    (clobber (match_scratch:CC 4 ""))]
2298   "TARGET_POWERPC64 && reload_completed"
2299   [(parallel [(set (match_dup 3)
2300                    (and:SI (match_dup 1)
2301                            (match_dup 2)))
2302               (clobber (match_dup 4))])
2303    (set (match_dup 0)
2304         (compare:CC (match_dup 3)
2305                     (const_int 0)))]
2306   "")
2307
2308 (define_insn "*andsi3_internal4"
2309   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2310         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2311                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2312                     (const_int 0)))
2313    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2314         (and:SI (match_dup 1)
2315                 (match_dup 2)))
2316    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2317   "TARGET_32BIT"
2318   "@
2319    and. %0,%1,%2
2320    {andil.|andi.} %0,%1,%b2
2321    {andiu.|andis.} %0,%1,%u2
2322    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2323    #
2324    #
2325    #
2326    #"
2327   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2328    (set_attr "length" "4,4,4,4,8,8,8,8")])
2329
2330 (define_insn "*andsi3_internal5"
2331   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2332         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2333                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2334                     (const_int 0)))
2335    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2336         (and:SI (match_dup 1)
2337                 (match_dup 2)))
2338    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2339   "TARGET_64BIT"
2340   "@
2341    #
2342    {andil.|andi.} %0,%1,%b2
2343    {andiu.|andis.} %0,%1,%u2
2344    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2345    #
2346    #
2347    #
2348    #"
2349   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2350    (set_attr "length" "8,4,4,4,8,8,8,8")])
2351
2352 (define_split
2353   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2354         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2355                             (match_operand:SI 2 "and_operand" ""))
2356                     (const_int 0)))
2357    (set (match_operand:SI 0 "gpc_reg_operand" "")
2358         (and:SI (match_dup 1)
2359                 (match_dup 2)))
2360    (clobber (match_scratch:CC 4 ""))]
2361   "reload_completed"
2362   [(parallel [(set (match_dup 0)
2363                    (and:SI (match_dup 1)
2364                            (match_dup 2)))
2365               (clobber (match_dup 4))])
2366    (set (match_dup 3)
2367         (compare:CC (match_dup 0)
2368                     (const_int 0)))]
2369   "")
2370
2371 (define_split
2372   [(set (match_operand:CC 3 "cc_reg_operand" "")
2373         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2374                             (match_operand:SI 2 "gpc_reg_operand" ""))
2375                     (const_int 0)))
2376    (set (match_operand:SI 0 "gpc_reg_operand" "")
2377         (and:SI (match_dup 1)
2378                 (match_dup 2)))
2379    (clobber (match_scratch:CC 4 ""))]
2380   "TARGET_POWERPC64 && reload_completed"
2381   [(parallel [(set (match_dup 0)
2382                    (and:SI (match_dup 1)
2383                            (match_dup 2)))
2384               (clobber (match_dup 4))])
2385    (set (match_dup 3)
2386         (compare:CC (match_dup 0)
2387                     (const_int 0)))]
2388   "")
2389
2390 ;; Handle the PowerPC64 rlwinm corner case
2391
2392 (define_insn_and_split "*andsi3_internal6"
2393   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2394         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2395                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2396   "TARGET_POWERPC64"
2397   "#"
2398   "TARGET_POWERPC64"
2399   [(set (match_dup 0)
2400         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
2401                 (match_dup 4)))
2402    (set (match_dup 0)
2403         (rotate:SI (match_dup 0) (match_dup 5)))]
2404   "
2405 {
2406   int mb = extract_MB (operands[2]);
2407   int me = extract_ME (operands[2]);
2408   operands[3] = GEN_INT (me + 1);
2409   operands[5] = GEN_INT (32 - (me + 1));
2410   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2411 }"
2412   [(set_attr "length" "8")])
2413
2414 (define_insn_and_split "*andsi3_internal7"
2415   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2416         (compare:CC (and:SI (match_operand:SI 0 "gpc_reg_operand" "r,r")
2417                             (match_operand:SI 1 "mask_operand_wrap" "i,i"))
2418                     (const_int 0)))
2419    (clobber (match_scratch:SI 3 "=r,r"))]
2420   "TARGET_POWERPC64"
2421   "#"
2422   "TARGET_POWERPC64"
2423   [(parallel [(set (match_dup 2)
2424                    (compare:CC (and:SI (rotate:SI (match_dup 0) (match_dup 4))
2425                                        (match_dup 5))
2426                                (const_int 0)))
2427               (clobber (match_dup 3))])]
2428   "
2429 {
2430   int mb = extract_MB (operands[1]);
2431   int me = extract_ME (operands[1]);
2432   operands[4] = GEN_INT (me + 1);
2433   operands[5] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2434 }"
2435   [(set_attr "type" "delayed_compare,compare")
2436    (set_attr "length" "4,8")])
2437
2438 (define_insn_and_split "*andsi3_internal8"
2439   [(set (match_operand:CC 3 "cc_reg_operand" "=x,??y")
2440         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2441                             (match_operand:SI 2 "mask_operand_wrap" "i,i"))
2442                     (const_int 0)))
2443    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2444         (and:SI (match_dup 1)
2445                 (match_dup 2)))]
2446   "TARGET_POWERPC64"
2447   "#"
2448   "TARGET_POWERPC64"
2449   [(set (match_dup 0)
2450                    (and:SI (rotate:SI (match_dup 1) (match_dup 4))
2451                            (match_dup 5)))
2452    (parallel [(set (match_dup 3)
2453                    (compare:CC (rotate:SI (match_dup 0) (match_dup 6))
2454                                (const_int 0)))
2455               (set (match_dup 0)
2456                    (rotate:SI (match_dup 0) (match_dup 6)))])]
2457   "
2458 {
2459   int mb = extract_MB (operands[2]);
2460   int me = extract_ME (operands[2]);
2461   operands[4] = GEN_INT (me + 1);
2462   operands[6] = GEN_INT (32 - (me + 1));
2463   operands[5] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2464 }"
2465   [(set_attr "type" "delayed_compare,compare")
2466    (set_attr "length" "8,12")])
2467
2468 (define_expand "iorsi3"
2469   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2470         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
2471                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2472   ""
2473   "
2474 {
2475   if (GET_CODE (operands[2]) == CONST_INT
2476       && ! logical_operand (operands[2], SImode))
2477     {
2478       HOST_WIDE_INT value = INTVAL (operands[2]);
2479       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2480                  ? operands[0] : gen_reg_rtx (SImode));
2481
2482       emit_insn (gen_iorsi3 (tmp, operands[1],
2483                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2484       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2485       DONE;
2486     }
2487 }")
2488
2489 (define_expand "xorsi3"
2490   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2491         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2492                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2493   ""
2494   "
2495 {
2496   if (GET_CODE (operands[2]) == CONST_INT
2497       && ! logical_operand (operands[2], SImode))
2498     {
2499       HOST_WIDE_INT value = INTVAL (operands[2]);
2500       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2501                  ? operands[0] : gen_reg_rtx (SImode));
2502
2503       emit_insn (gen_xorsi3 (tmp, operands[1],
2504                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2505       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2506       DONE;
2507     }
2508 }")
2509
2510 (define_insn "*boolsi3_internal1"
2511   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2512         (match_operator:SI 3 "boolean_or_operator"
2513          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
2514           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
2515   ""
2516   "@
2517    %q3 %0,%1,%2
2518    {%q3il|%q3i} %0,%1,%b2
2519    {%q3iu|%q3is} %0,%1,%u2")
2520
2521 (define_insn "*boolsi3_internal2"
2522   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2523         (compare:CC (match_operator:SI 4 "boolean_or_operator"
2524          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2525           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2526          (const_int 0)))
2527    (clobber (match_scratch:SI 3 "=r,r"))]
2528   "TARGET_32BIT"
2529   "@
2530    %q4. %3,%1,%2
2531    #"
2532   [(set_attr "type" "compare")
2533    (set_attr "length" "4,8")])
2534
2535 (define_split
2536   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2537         (compare:CC (match_operator:SI 4 "boolean_operator"
2538          [(match_operand:SI 1 "gpc_reg_operand" "")
2539           (match_operand:SI 2 "gpc_reg_operand" "")])
2540          (const_int 0)))
2541    (clobber (match_scratch:SI 3 ""))]
2542   "TARGET_32BIT && reload_completed"
2543   [(set (match_dup 3) (match_dup 4))
2544    (set (match_dup 0)
2545         (compare:CC (match_dup 3)
2546                     (const_int 0)))]
2547   "")
2548
2549 (define_insn "*boolsi3_internal3"
2550   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2551         (compare:CC (match_operator:SI 4 "boolean_operator"
2552          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2553           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2554          (const_int 0)))
2555    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2556         (match_dup 4))]
2557   "TARGET_32BIT"
2558   "@
2559    %q4. %0,%1,%2
2560    #"
2561   [(set_attr "type" "compare")
2562    (set_attr "length" "4,8")])
2563
2564 (define_split
2565   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2566         (compare:CC (match_operator:SI 4 "boolean_operator"
2567          [(match_operand:SI 1 "gpc_reg_operand" "")
2568           (match_operand:SI 2 "gpc_reg_operand" "")])
2569          (const_int 0)))
2570    (set (match_operand:SI 0 "gpc_reg_operand" "")
2571         (match_dup 4))]
2572   "TARGET_32BIT && reload_completed"
2573   [(set (match_dup 0) (match_dup 4))
2574    (set (match_dup 3)
2575         (compare:CC (match_dup 0)
2576                     (const_int 0)))]
2577   "")
2578
2579 ;; Split a logical operation that we can't do in one insn into two insns,
2580 ;; each of which does one 16-bit part.  This is used by combine.
2581
2582 (define_split
2583   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2584         (match_operator:SI 3 "boolean_or_operator"
2585          [(match_operand:SI 1 "gpc_reg_operand" "")
2586           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
2587   ""
2588   [(set (match_dup 0) (match_dup 4))
2589    (set (match_dup 0) (match_dup 5))]
2590 "
2591 {
2592   rtx i;
2593   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
2594   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2595                                 operands[1], i);
2596   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
2597   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2598                                 operands[0], i);
2599 }")
2600
2601 (define_insn "*boolcsi3_internal1"
2602   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2603         (match_operator:SI 3 "boolean_operator"
2604          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2605           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
2606   ""
2607   "%q3 %0,%2,%1")
2608
2609 (define_insn "*boolcsi3_internal2"
2610   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2611         (compare:CC (match_operator:SI 4 "boolean_operator"
2612          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2613           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2614          (const_int 0)))
2615    (clobber (match_scratch:SI 3 "=r,r"))]
2616   "TARGET_32BIT"
2617   "@
2618    %q4. %3,%2,%1
2619    #"
2620   [(set_attr "type" "compare")
2621    (set_attr "length" "4,8")])
2622
2623 (define_split
2624   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2625         (compare:CC (match_operator:SI 4 "boolean_operator"
2626          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2627           (match_operand:SI 2 "gpc_reg_operand" "")])
2628          (const_int 0)))
2629    (clobber (match_scratch:SI 3 ""))]
2630   "TARGET_32BIT && reload_completed"
2631   [(set (match_dup 3) (match_dup 4))
2632    (set (match_dup 0)
2633         (compare:CC (match_dup 3)
2634                     (const_int 0)))]
2635   "")
2636
2637 (define_insn "*boolcsi3_internal3"
2638   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2639         (compare:CC (match_operator:SI 4 "boolean_operator"
2640          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2641           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2642          (const_int 0)))
2643    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2644         (match_dup 4))]
2645   "TARGET_32BIT"
2646   "@
2647    %q4. %0,%2,%1
2648    #"
2649   [(set_attr "type" "compare")
2650    (set_attr "length" "4,8")])
2651
2652 (define_split
2653   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2654         (compare:CC (match_operator:SI 4 "boolean_operator"
2655          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2656           (match_operand:SI 2 "gpc_reg_operand" "")])
2657          (const_int 0)))
2658    (set (match_operand:SI 0 "gpc_reg_operand" "")
2659         (match_dup 4))]
2660   "TARGET_32BIT && reload_completed"
2661   [(set (match_dup 0) (match_dup 4))
2662    (set (match_dup 3)
2663         (compare:CC (match_dup 0)
2664                     (const_int 0)))]
2665   "")
2666
2667 (define_insn "*boolccsi3_internal1"
2668   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2669         (match_operator:SI 3 "boolean_operator"
2670          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2671           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
2672   ""
2673   "%q3 %0,%1,%2")
2674
2675 (define_insn "*boolccsi3_internal2"
2676   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2677         (compare:CC (match_operator:SI 4 "boolean_operator"
2678          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2679           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2680          (const_int 0)))
2681    (clobber (match_scratch:SI 3 "=r,r"))]
2682   "TARGET_32BIT"
2683   "@
2684    %q4. %3,%1,%2
2685    #"
2686   [(set_attr "type" "compare")
2687    (set_attr "length" "4,8")])
2688
2689 (define_split
2690   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2691         (compare:CC (match_operator:SI 4 "boolean_operator"
2692          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2693           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2694          (const_int 0)))
2695    (clobber (match_scratch:SI 3 ""))]
2696   "TARGET_32BIT && reload_completed"
2697   [(set (match_dup 3) (match_dup 4))
2698    (set (match_dup 0)
2699         (compare:CC (match_dup 3)
2700                     (const_int 0)))]
2701   "")
2702
2703 (define_insn "*boolccsi3_internal3"
2704   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2705         (compare:CC (match_operator:SI 4 "boolean_operator"
2706          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2707           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2708          (const_int 0)))
2709    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2710         (match_dup 4))]
2711   "TARGET_32BIT"
2712   "@
2713    %q4. %0,%1,%2
2714    #"
2715   [(set_attr "type" "compare")
2716    (set_attr "length" "4,8")])
2717
2718 (define_split
2719   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2720         (compare:CC (match_operator:SI 4 "boolean_operator"
2721          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2722           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2723          (const_int 0)))
2724    (set (match_operand:SI 0 "gpc_reg_operand" "")
2725         (match_dup 4))]
2726   "TARGET_32BIT && reload_completed"
2727   [(set (match_dup 0) (match_dup 4))
2728    (set (match_dup 3)
2729         (compare:CC (match_dup 0)
2730                     (const_int 0)))]
2731   "")
2732
2733 ;; maskir insn.  We need four forms because things might be in arbitrary
2734 ;; orders.  Don't define forms that only set CR fields because these
2735 ;; would modify an input register.
2736
2737 (define_insn "*maskir_internal1"
2738   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2739         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2740                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2741                 (and:SI (match_dup 2)
2742                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
2743   "TARGET_POWER"
2744   "maskir %0,%3,%2")
2745
2746 (define_insn "*maskir_internal2"
2747   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2748         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2749                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2750                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2751                         (match_dup 2))))]
2752   "TARGET_POWER"
2753   "maskir %0,%3,%2")
2754
2755 (define_insn "*maskir_internal3"
2756   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2757         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2758                         (match_operand:SI 3 "gpc_reg_operand" "r"))
2759                 (and:SI (not:SI (match_dup 2))
2760                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2761   "TARGET_POWER"
2762   "maskir %0,%3,%2")
2763
2764 (define_insn "*maskir_internal4"
2765   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2766         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2767                         (match_operand:SI 2 "gpc_reg_operand" "r"))
2768                 (and:SI (not:SI (match_dup 2))
2769                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2770   "TARGET_POWER"
2771   "maskir %0,%3,%2")
2772
2773 (define_insn "*maskir_internal5"
2774   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2775         (compare:CC
2776          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2777                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2778                  (and:SI (match_dup 2)
2779                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
2780          (const_int 0)))
2781    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2782         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2783                 (and:SI (match_dup 2) (match_dup 3))))]
2784   "TARGET_POWER"
2785   "@
2786    maskir. %0,%3,%2
2787    #"
2788   [(set_attr "type" "compare")
2789    (set_attr "length" "4,8")])
2790
2791 (define_split
2792   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2793         (compare:CC
2794          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2795                          (match_operand:SI 1 "gpc_reg_operand" ""))
2796                  (and:SI (match_dup 2)
2797                          (match_operand:SI 3 "gpc_reg_operand" "")))
2798          (const_int 0)))
2799    (set (match_operand:SI 0 "gpc_reg_operand" "")
2800         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2801                 (and:SI (match_dup 2) (match_dup 3))))]
2802   "TARGET_POWER && reload_completed"
2803   [(set (match_dup 0)
2804         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2805                 (and:SI (match_dup 2) (match_dup 3))))
2806    (set (match_dup 4)
2807         (compare:CC (match_dup 0)
2808                     (const_int 0)))]
2809   "")
2810
2811 (define_insn "*maskir_internal6"
2812   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2813         (compare:CC
2814          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2815                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2816                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2817                          (match_dup 2)))
2818          (const_int 0)))
2819    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2820         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2821                 (and:SI (match_dup 3) (match_dup 2))))]
2822   "TARGET_POWER"
2823   "@
2824    maskir. %0,%3,%2
2825    #"
2826   [(set_attr "type" "compare")
2827    (set_attr "length" "4,8")])
2828
2829 (define_split
2830   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2831         (compare:CC
2832          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2833                          (match_operand:SI 1 "gpc_reg_operand" ""))
2834                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2835                          (match_dup 2)))
2836          (const_int 0)))
2837    (set (match_operand:SI 0 "gpc_reg_operand" "")
2838         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2839                 (and:SI (match_dup 3) (match_dup 2))))]
2840   "TARGET_POWER && reload_completed"
2841   [(set (match_dup 0)
2842         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2843                 (and:SI (match_dup 3) (match_dup 2))))
2844    (set (match_dup 4)
2845         (compare:CC (match_dup 0)
2846                     (const_int 0)))]
2847   "")
2848
2849 (define_insn "*maskir_internal7"
2850   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2851         (compare:CC
2852          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
2853                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
2854                  (and:SI (not:SI (match_dup 2))
2855                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2856          (const_int 0)))
2857    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2858         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2859                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2860   "TARGET_POWER"
2861   "@
2862    maskir. %0,%3,%2
2863    #"
2864   [(set_attr "type" "compare")
2865    (set_attr "length" "4,8")])
2866
2867 (define_split
2868   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2869         (compare:CC
2870          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
2871                          (match_operand:SI 3 "gpc_reg_operand" ""))
2872                  (and:SI (not:SI (match_dup 2))
2873                          (match_operand:SI 1 "gpc_reg_operand" "")))
2874          (const_int 0)))
2875    (set (match_operand:SI 0 "gpc_reg_operand" "")
2876         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2877                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2878   "TARGET_POWER && reload_completed"
2879   [(set (match_dup 0)
2880         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2881                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2882    (set (match_dup 4)
2883         (compare:CC (match_dup 0)
2884                     (const_int 0)))]
2885   "")
2886
2887 (define_insn "*maskir_internal8"
2888   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2889         (compare:CC
2890          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2891                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2892                  (and:SI (not:SI (match_dup 2))
2893                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2894          (const_int 0)))
2895    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2896         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2897                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2898   "TARGET_POWER"
2899   "@
2900    maskir. %0,%3,%2
2901    #"
2902   [(set_attr "type" "compare")
2903    (set_attr "length" "4,8")])
2904
2905 (define_split
2906   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2907         (compare:CC
2908          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2909                          (match_operand:SI 2 "gpc_reg_operand" ""))
2910                  (and:SI (not:SI (match_dup 2))
2911                          (match_operand:SI 1 "gpc_reg_operand" "")))
2912          (const_int 0)))
2913    (set (match_operand:SI 0 "gpc_reg_operand" "")
2914         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2915                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2916   "TARGET_POWER && reload_completed"
2917   [(set (match_dup 0)
2918         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2919                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2920    (set (match_dup 4)
2921         (compare:CC (match_dup 0)
2922                     (const_int 0)))]
2923   "")
2924 \f
2925 ;; Rotate and shift insns, in all their variants.  These support shifts,
2926 ;; field inserts and extracts, and various combinations thereof.
2927 (define_expand "insv"
2928   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
2929                        (match_operand:SI 1 "const_int_operand" "")
2930                        (match_operand:SI 2 "const_int_operand" ""))
2931         (match_operand 3 "gpc_reg_operand" ""))]
2932   ""
2933   "
2934 {
2935   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
2936      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
2937      compiler if the address of the structure is taken later.  */
2938   if (GET_CODE (operands[0]) == SUBREG
2939       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
2940     FAIL;
2941
2942   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
2943     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
2944   else
2945     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
2946   DONE;
2947 }")
2948
2949 (define_insn "insvsi"
2950   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2951                          (match_operand:SI 1 "const_int_operand" "i")
2952                          (match_operand:SI 2 "const_int_operand" "i"))
2953         (match_operand:SI 3 "gpc_reg_operand" "r"))]
2954   ""
2955   "*
2956 {
2957   int start = INTVAL (operands[2]) & 31;
2958   int size = INTVAL (operands[1]) & 31;
2959
2960   operands[4] = GEN_INT (32 - start - size);
2961   operands[1] = GEN_INT (start + size - 1);
2962   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2963 }"
2964   [(set_attr "type" "insert_word")])
2965
2966 (define_insn "*insvsi_internal1"
2967   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2968                          (match_operand:SI 1 "const_int_operand" "i")
2969                          (match_operand:SI 2 "const_int_operand" "i"))
2970         (ashift:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2971                    (match_operand:SI 4 "const_int_operand" "i")))]
2972   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2973   "*
2974 {
2975   int shift = INTVAL (operands[4]) & 31;
2976   int start = INTVAL (operands[2]) & 31;
2977   int size = INTVAL (operands[1]) & 31;
2978
2979   operands[4] = GEN_INT (shift - start - size);
2980   operands[1] = GEN_INT (start + size - 1);
2981   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2982 }"
2983   [(set_attr "type" "insert_word")])
2984
2985 (define_insn "*insvsi_internal2"
2986   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2987                          (match_operand:SI 1 "const_int_operand" "i")
2988                          (match_operand:SI 2 "const_int_operand" "i"))
2989         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2990                      (match_operand:SI 4 "const_int_operand" "i")))]
2991   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2992   "*
2993 {
2994   int shift = INTVAL (operands[4]) & 31;
2995   int start = INTVAL (operands[2]) & 31;
2996   int size = INTVAL (operands[1]) & 31;
2997
2998   operands[4] = GEN_INT (32 - shift - start - size);
2999   operands[1] = GEN_INT (start + size - 1);
3000   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3001 }"
3002   [(set_attr "type" "insert_word")])
3003
3004 (define_insn "*insvsi_internal3"
3005   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3006                          (match_operand:SI 1 "const_int_operand" "i")
3007                          (match_operand:SI 2 "const_int_operand" "i"))
3008         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3009                      (match_operand:SI 4 "const_int_operand" "i")))]
3010   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3011   "*
3012 {
3013   int shift = INTVAL (operands[4]) & 31;
3014   int start = INTVAL (operands[2]) & 31;
3015   int size = INTVAL (operands[1]) & 31;
3016
3017   operands[4] = GEN_INT (32 - shift - start - size);
3018   operands[1] = GEN_INT (start + size - 1);
3019   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3020 }"
3021   [(set_attr "type" "insert_word")])
3022
3023 (define_insn "*insvsi_internal4"
3024   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3025                          (match_operand:SI 1 "const_int_operand" "i")
3026                          (match_operand:SI 2 "const_int_operand" "i"))
3027         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3028                          (match_operand:SI 4 "const_int_operand" "i")
3029                          (match_operand:SI 5 "const_int_operand" "i")))]
3030   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3031   "*
3032 {
3033   int extract_start = INTVAL (operands[5]) & 31;
3034   int extract_size = INTVAL (operands[4]) & 31;
3035   int insert_start = INTVAL (operands[2]) & 31;
3036   int insert_size = INTVAL (operands[1]) & 31;
3037
3038 /* Align extract field with insert field */
3039   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3040   operands[1] = GEN_INT (insert_start + insert_size - 1);
3041   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
3042 }"
3043   [(set_attr "type" "insert_word")])
3044
3045 ;; combine patterns for rlwimi
3046 (define_insn "*insvsi_internal5"
3047   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3048         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3049                         (match_operand:SI 1 "mask_operand" "i"))
3050                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3051                                      (match_operand:SI 2 "const_int_operand" "i"))
3052                         (match_operand:SI 5 "mask_operand" "i"))))]
3053   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3054   "*
3055 {
3056  int me = extract_ME(operands[5]);
3057  int mb = extract_MB(operands[5]);
3058  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3059  operands[2] = GEN_INT(mb);
3060  operands[1] = GEN_INT(me);
3061  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3062 }"
3063   [(set_attr "type" "insert_word")])
3064
3065 (define_insn "*insvsi_internal6"
3066   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3067         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3068                                      (match_operand:SI 2 "const_int_operand" "i"))
3069                         (match_operand:SI 5 "mask_operand" "i"))
3070                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3071                         (match_operand:SI 1 "mask_operand" "i"))))]
3072   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3073   "*
3074 {
3075  int me = extract_ME(operands[5]);
3076  int mb = extract_MB(operands[5]);
3077  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3078  operands[2] = GEN_INT(mb);
3079  operands[1] = GEN_INT(me);
3080  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3081 }"
3082   [(set_attr "type" "insert_word")])
3083
3084 (define_insn "insvdi"
3085   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3086                          (match_operand:SI 1 "const_int_operand" "i")
3087                          (match_operand:SI 2 "const_int_operand" "i"))
3088         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3089   "TARGET_POWERPC64"
3090   "*
3091 {
3092   int start = INTVAL (operands[2]) & 63;
3093   int size = INTVAL (operands[1]) & 63;
3094
3095   operands[1] = GEN_INT (64 - start - size);
3096   return \"rldimi %0,%3,%H1,%H2\";
3097 }")
3098
3099 (define_insn "*insvdi_internal2"
3100   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3101                          (match_operand:SI 1 "const_int_operand" "i")
3102                          (match_operand:SI 2 "const_int_operand" "i"))
3103         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3104                      (match_operand:SI 4 "const_int_operand" "i")))]
3105   "TARGET_POWERPC64
3106    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3107   "*
3108 {
3109   int shift = INTVAL (operands[4]) & 63;
3110   int start = (INTVAL (operands[2]) & 63) - 32;
3111   int size = INTVAL (operands[1]) & 63;
3112
3113   operands[4] = GEN_INT (64 - shift - start - size);
3114   operands[2] = GEN_INT (start);
3115   operands[1] = GEN_INT (start + size - 1);
3116   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3117 }")
3118
3119 (define_insn "*insvdi_internal3"
3120   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3121                          (match_operand:SI 1 "const_int_operand" "i")
3122                          (match_operand:SI 2 "const_int_operand" "i"))
3123         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3124                      (match_operand:SI 4 "const_int_operand" "i")))]
3125   "TARGET_POWERPC64
3126    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3127   "*
3128 {
3129   int shift = INTVAL (operands[4]) & 63;
3130   int start = (INTVAL (operands[2]) & 63) - 32;
3131   int size = INTVAL (operands[1]) & 63;
3132
3133   operands[4] = GEN_INT (64 - shift - start - size);
3134   operands[2] = GEN_INT (start);
3135   operands[1] = GEN_INT (start + size - 1);
3136   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3137 }")
3138
3139 (define_expand "extzv"
3140   [(set (match_operand 0 "gpc_reg_operand" "")
3141         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3142                        (match_operand:SI 2 "const_int_operand" "")
3143                        (match_operand:SI 3 "const_int_operand" "")))]
3144   ""
3145   "
3146 {
3147   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3148      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3149      compiler if the address of the structure is taken later.  */
3150   if (GET_CODE (operands[0]) == SUBREG
3151       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3152     FAIL;
3153
3154   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3155     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
3156   else
3157     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
3158   DONE;
3159 }")
3160
3161 (define_insn "extzvsi"
3162   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3163         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3164                          (match_operand:SI 2 "const_int_operand" "i")
3165                          (match_operand:SI 3 "const_int_operand" "i")))]
3166   ""
3167   "*
3168 {
3169   int start = INTVAL (operands[3]) & 31;
3170   int size = INTVAL (operands[2]) & 31;
3171
3172   if (start + size >= 32)
3173     operands[3] = const0_rtx;
3174   else
3175     operands[3] = GEN_INT (start + size);
3176   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
3177 }")
3178
3179 (define_insn "*extzvsi_internal1"
3180   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3181         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3182                          (match_operand:SI 2 "const_int_operand" "i,i")
3183                          (match_operand:SI 3 "const_int_operand" "i,i"))
3184                     (const_int 0)))
3185    (clobber (match_scratch:SI 4 "=r,r"))]
3186   ""
3187   "*
3188 {
3189   int start = INTVAL (operands[3]) & 31;
3190   int size = INTVAL (operands[2]) & 31;
3191
3192   /* Force split for non-cc0 compare.  */
3193   if (which_alternative == 1)
3194      return \"#\";
3195
3196   /* If the bit-field being tested fits in the upper or lower half of a
3197      word, it is possible to use andiu. or andil. to test it.  This is
3198      useful because the condition register set-use delay is smaller for
3199      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3200      position is 0 because the LT and GT bits may be set wrong.  */
3201
3202   if ((start > 0 && start + size <= 16) || start >= 16)
3203     {
3204       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3205                               - (1 << (16 - (start & 15) - size))));
3206       if (start < 16)
3207         return \"{andiu.|andis.} %4,%1,%3\";
3208       else
3209         return \"{andil.|andi.} %4,%1,%3\";
3210     }
3211
3212   if (start + size >= 32)
3213     operands[3] = const0_rtx;
3214   else
3215     operands[3] = GEN_INT (start + size);
3216   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
3217 }"
3218   [(set_attr "type" "compare")
3219    (set_attr "length" "4,8")])
3220
3221 (define_split
3222   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3223         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3224                          (match_operand:SI 2 "const_int_operand" "")
3225                          (match_operand:SI 3 "const_int_operand" ""))
3226                     (const_int 0)))
3227    (clobber (match_scratch:SI 4 ""))]
3228   "reload_completed"
3229   [(set (match_dup 4)
3230         (zero_extract:SI (match_dup 1) (match_dup 2)
3231                          (match_dup 3)))
3232    (set (match_dup 0)
3233         (compare:CC (match_dup 4)
3234                     (const_int 0)))]
3235   "")
3236
3237 (define_insn "*extzvsi_internal2"
3238   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3239         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3240                          (match_operand:SI 2 "const_int_operand" "i,i")
3241                          (match_operand:SI 3 "const_int_operand" "i,i"))
3242                     (const_int 0)))
3243    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3244         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3245   ""
3246   "*
3247 {
3248   int start = INTVAL (operands[3]) & 31;
3249   int size = INTVAL (operands[2]) & 31;
3250
3251   /* Force split for non-cc0 compare.  */
3252   if (which_alternative == 1)
3253      return \"#\";
3254
3255   /* Since we are using the output value, we can't ignore any need for
3256      a shift.  The bit-field must end at the LSB.  */
3257   if (start >= 16 && start + size == 32)
3258     {
3259       operands[3] = GEN_INT ((1 << size) - 1);
3260       return \"{andil.|andi.} %0,%1,%3\";
3261     }
3262
3263   if (start + size >= 32)
3264     operands[3] = const0_rtx;
3265   else
3266     operands[3] = GEN_INT (start + size);
3267   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
3268 }"
3269   [(set_attr "type" "compare")
3270    (set_attr "length" "4,8")])
3271
3272 (define_split
3273   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3274         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3275                          (match_operand:SI 2 "const_int_operand" "")
3276                          (match_operand:SI 3 "const_int_operand" ""))
3277                     (const_int 0)))
3278    (set (match_operand:SI 0 "gpc_reg_operand" "")
3279         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3280   "reload_completed"
3281   [(set (match_dup 0)
3282         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3283    (set (match_dup 4)
3284         (compare:CC (match_dup 0)
3285                     (const_int 0)))]
3286   "")
3287
3288 (define_insn "extzvdi"
3289   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3290         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3291                          (match_operand:SI 2 "const_int_operand" "i")
3292                          (match_operand:SI 3 "const_int_operand" "i")))]
3293   "TARGET_POWERPC64"
3294   "*
3295 {
3296   int start = INTVAL (operands[3]) & 63;
3297   int size = INTVAL (operands[2]) & 63;
3298
3299   if (start + size >= 64)
3300     operands[3] = const0_rtx;
3301   else
3302     operands[3] = GEN_INT (start + size);
3303   operands[2] = GEN_INT (64 - size);
3304   return \"rldicl %0,%1,%3,%2\";
3305 }")
3306
3307 (define_insn "*extzvdi_internal1"
3308   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3309         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3310                          (match_operand:SI 2 "const_int_operand" "i")
3311                          (match_operand:SI 3 "const_int_operand" "i"))
3312                     (const_int 0)))
3313    (clobber (match_scratch:DI 4 "=r"))]
3314   "TARGET_64BIT"
3315   "*
3316 {
3317   int start = INTVAL (operands[3]) & 63;
3318   int size = INTVAL (operands[2]) & 63;
3319
3320   if (start + size >= 64)
3321     operands[3] = const0_rtx;
3322   else
3323     operands[3] = GEN_INT (start + size);
3324   operands[2] = GEN_INT (64 - size);
3325   return \"rldicl. %4,%1,%3,%2\";
3326 }"
3327   [(set_attr "type" "compare")])
3328
3329 (define_insn "*extzvdi_internal2"
3330   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3331         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3332                          (match_operand:SI 2 "const_int_operand" "i")
3333                          (match_operand:SI 3 "const_int_operand" "i"))
3334                     (const_int 0)))
3335    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3336         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3337   "TARGET_64BIT"
3338   "*
3339 {
3340   int start = INTVAL (operands[3]) & 63;
3341   int size = INTVAL (operands[2]) & 63;
3342
3343   if (start + size >= 64)
3344     operands[3] = const0_rtx;
3345   else
3346     operands[3] = GEN_INT (start + size);
3347   operands[2] = GEN_INT (64 - size);
3348   return \"rldicl. %0,%1,%3,%2\";
3349 }"
3350   [(set_attr "type" "compare")])
3351
3352 (define_insn "rotlsi3"
3353   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3354         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3355                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3356   ""
3357   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
3358
3359 (define_insn "*rotlsi3_internal2"
3360   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3361         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3362                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3363                     (const_int 0)))
3364    (clobber (match_scratch:SI 3 "=r,r"))]
3365   ""
3366   "@
3367    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff
3368    #"
3369   [(set_attr "type" "delayed_compare")
3370    (set_attr "length" "4,8")])
3371
3372 (define_split
3373   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3374         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3375                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3376                     (const_int 0)))
3377    (clobber (match_scratch:SI 3 ""))]
3378   "reload_completed"
3379   [(set (match_dup 3)
3380         (rotate:SI (match_dup 1) (match_dup 2)))
3381    (set (match_dup 0)
3382         (compare:CC (match_dup 3)
3383                     (const_int 0)))]
3384   "")
3385
3386 (define_insn "*rotlsi3_internal3"
3387   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3388         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3389                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3390                     (const_int 0)))
3391    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3392         (rotate:SI (match_dup 1) (match_dup 2)))]
3393   ""
3394   "@
3395    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff
3396    #"
3397   [(set_attr "type" "delayed_compare")
3398    (set_attr "length" "4,8")])
3399
3400 (define_split
3401   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3402         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3403                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3404                     (const_int 0)))
3405    (set (match_operand:SI 0 "gpc_reg_operand" "")
3406         (rotate:SI (match_dup 1) (match_dup 2)))]
3407   "reload_completed"
3408   [(set (match_dup 0)
3409         (rotate:SI (match_dup 1) (match_dup 2)))
3410    (set (match_dup 3)
3411         (compare:CC (match_dup 0)
3412                     (const_int 0)))]
3413   "")
3414
3415 (define_insn "*rotlsi3_internal4"
3416   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3417         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3418                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
3419                 (match_operand:SI 3 "mask_operand" "n")))]
3420   ""
3421   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
3422
3423 (define_insn "*rotlsi3_internal5"
3424   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3425         (compare:CC (and:SI
3426                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3427                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3428                      (match_operand:SI 3 "mask_operand" "n,n"))
3429                     (const_int 0)))
3430    (clobber (match_scratch:SI 4 "=r,r"))]
3431   ""
3432   "@
3433    {rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3
3434    #"
3435   [(set_attr "type" "delayed_compare")
3436    (set_attr "length" "4,8")])
3437
3438 (define_split
3439   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3440         (compare:CC (and:SI
3441                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3442                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3443                      (match_operand:SI 3 "mask_operand" ""))
3444                     (const_int 0)))
3445    (clobber (match_scratch:SI 4 ""))]
3446   "reload_completed"
3447   [(set (match_dup 4)
3448         (and:SI (rotate:SI (match_dup 1)
3449                                 (match_dup 2))
3450                      (match_dup 3)))
3451    (set (match_dup 0)
3452         (compare:CC (match_dup 4)
3453                     (const_int 0)))]
3454   "")
3455
3456 (define_insn "*rotlsi3_internal6"
3457   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3458         (compare:CC (and:SI
3459                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3460                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3461                      (match_operand:SI 3 "mask_operand" "n,n"))
3462                     (const_int 0)))
3463    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3464         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3465   ""
3466   "@
3467    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3
3468    #"
3469   [(set_attr "type" "delayed_compare")
3470    (set_attr "length" "4,8")])
3471
3472 (define_split
3473   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3474         (compare:CC (and:SI
3475                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3476                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
3477                      (match_operand:SI 3 "mask_operand" ""))
3478                     (const_int 0)))
3479    (set (match_operand:SI 0 "gpc_reg_operand" "")
3480         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3481   "reload_completed"
3482   [(set (match_dup 0)
3483         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3484    (set (match_dup 4)
3485         (compare:CC (match_dup 0)
3486                     (const_int 0)))]
3487   "")
3488
3489 (define_insn "*rotlsi3_internal7"
3490   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3491         (zero_extend:SI
3492          (subreg:QI
3493           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3494                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3495   ""
3496   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
3497
3498 (define_insn "*rotlsi3_internal8"
3499   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3500         (compare:CC (zero_extend:SI
3501                      (subreg:QI
3502                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3503                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3504                     (const_int 0)))
3505    (clobber (match_scratch:SI 3 "=r,r"))]
3506   ""
3507   "@
3508    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff
3509    #"
3510   [(set_attr "type" "delayed_compare")
3511    (set_attr "length" "4,8")])
3512
3513 (define_split
3514   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3515         (compare:CC (zero_extend:SI
3516                      (subreg:QI
3517                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3518                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3519                     (const_int 0)))
3520    (clobber (match_scratch:SI 3 ""))]
3521   "reload_completed"
3522   [(set (match_dup 3)
3523         (zero_extend:SI (subreg:QI
3524                       (rotate:SI (match_dup 1)
3525                                  (match_dup 2)) 0)))
3526    (set (match_dup 0)
3527         (compare:CC (match_dup 3)
3528                     (const_int 0)))]
3529   "")
3530
3531 (define_insn "*rotlsi3_internal9"
3532   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3533         (compare:CC (zero_extend:SI
3534                      (subreg:QI
3535                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3536                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3537                     (const_int 0)))
3538    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3539         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3540   ""
3541   "@
3542    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff
3543    #"
3544   [(set_attr "type" "delayed_compare")
3545    (set_attr "length" "4,8")])
3546
3547 (define_split
3548   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3549         (compare:CC (zero_extend:SI
3550                      (subreg:QI
3551                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3552                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3553                     (const_int 0)))
3554    (set (match_operand:SI 0 "gpc_reg_operand" "")
3555         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3556   "reload_completed"
3557   [(set (match_dup 0)
3558         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3559    (set (match_dup 3)
3560         (compare:CC (match_dup 0)
3561                     (const_int 0)))]
3562   "")
3563
3564 (define_insn "*rotlsi3_internal10"
3565   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3566         (zero_extend:SI
3567          (subreg:HI
3568           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3569                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
3570   ""
3571   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
3572
3573 (define_insn "*rotlsi3_internal11"
3574   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3575         (compare:CC (zero_extend:SI
3576                      (subreg:HI
3577                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3578                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3579                     (const_int 0)))
3580    (clobber (match_scratch:SI 3 "=r,r"))]
3581   ""
3582   "@
3583    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff
3584    #"
3585   [(set_attr "type" "delayed_compare")
3586    (set_attr "length" "4,8")])
3587
3588 (define_split
3589   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3590         (compare:CC (zero_extend:SI
3591                      (subreg:HI
3592                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3593                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3594                     (const_int 0)))
3595    (clobber (match_scratch:SI 3 ""))]
3596   "reload_completed"
3597   [(set (match_dup 3)
3598         (zero_extend:SI (subreg:HI
3599                       (rotate:SI (match_dup 1)
3600                                  (match_dup 2)) 0)))
3601    (set (match_dup 0)
3602         (compare:CC (match_dup 3)
3603                     (const_int 0)))]
3604   "")
3605
3606 (define_insn "*rotlsi3_internal12"
3607   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3608         (compare:CC (zero_extend:SI
3609                      (subreg:HI
3610                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3611                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
3612                     (const_int 0)))
3613    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3614         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3615   ""
3616   "@
3617    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff
3618    #"
3619   [(set_attr "type" "delayed_compare")
3620    (set_attr "length" "4,8")])
3621
3622 (define_split
3623   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3624         (compare:CC (zero_extend:SI
3625                      (subreg:HI
3626                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3627                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
3628                     (const_int 0)))
3629    (set (match_operand:SI 0 "gpc_reg_operand" "")
3630         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
3631   "reload_completed"
3632   [(set (match_dup 0)
3633         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
3634    (set (match_dup 3)
3635         (compare:CC (match_dup 0)
3636                     (const_int 0)))]
3637   "")
3638
3639 ;; Note that we use "sle." instead of "sl." so that we can set
3640 ;; SHIFT_COUNT_TRUNCATED.
3641
3642 (define_expand "ashlsi3"
3643   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3644    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3645    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3646   ""
3647   "
3648 {
3649   if (TARGET_POWER)
3650     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
3651   else
3652     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
3653   DONE;
3654 }")
3655
3656 (define_insn "ashlsi3_power"
3657   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3658         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3659                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
3660    (clobber (match_scratch:SI 3 "=q,X"))]
3661   "TARGET_POWER"
3662   "@
3663    sle %0,%1,%2
3664    {sli|slwi} %0,%1,%h2")
3665
3666 (define_insn "ashlsi3_no_power"
3667   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3668         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3669                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3670   "! TARGET_POWER"
3671   "{sl|slw}%I2 %0,%1,%h2")
3672
3673 (define_insn ""
3674   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3675         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3676                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3677                     (const_int 0)))
3678    (clobber (match_scratch:SI 3 "=r,r,r,r"))
3679    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3680   "TARGET_POWER"
3681   "@
3682    sle. %3,%1,%2
3683    {sli.|slwi.} %3,%1,%h2
3684    #
3685    #"
3686   [(set_attr "type" "delayed_compare")
3687    (set_attr "length" "4,4,8,8")])
3688
3689 (define_split
3690   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3691         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3692                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3693                     (const_int 0)))
3694    (clobber (match_scratch:SI 3 ""))
3695    (clobber (match_scratch:SI 4 ""))]
3696   "TARGET_POWER && reload_completed"
3697   [(parallel [(set (match_dup 3)
3698         (ashift:SI (match_dup 1) (match_dup 2)))
3699    (clobber (match_dup 4))])
3700    (set (match_dup 0)
3701         (compare:CC (match_dup 3)
3702                     (const_int 0)))]
3703   "")
3704
3705 (define_insn ""
3706   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3707         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3708                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3709                     (const_int 0)))
3710    (clobber (match_scratch:SI 3 "=r,r"))]
3711   "! TARGET_POWER && TARGET_32BIT"
3712   "@
3713    {sl|slw}%I2. %3,%1,%h2
3714    #"
3715   [(set_attr "type" "delayed_compare")
3716    (set_attr "length" "4,8")])
3717
3718 (define_split
3719   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3720         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3721                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3722                     (const_int 0)))
3723    (clobber (match_scratch:SI 3 ""))]
3724   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3725   [(set (match_dup 3)
3726         (ashift:SI (match_dup 1) (match_dup 2)))
3727    (set (match_dup 0)
3728         (compare:CC (match_dup 3)
3729                     (const_int 0)))]
3730   "")
3731
3732 (define_insn ""
3733   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
3734         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3735                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
3736                     (const_int 0)))
3737    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
3738         (ashift:SI (match_dup 1) (match_dup 2)))
3739    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
3740   "TARGET_POWER"
3741   "@
3742    sle. %0,%1,%2
3743    {sli.|slwi.} %0,%1,%h2
3744    #
3745    #"
3746   [(set_attr "type" "delayed_compare")
3747    (set_attr "length" "4,4,8,8")])
3748
3749 (define_split
3750   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3751         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3752                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3753                     (const_int 0)))
3754    (set (match_operand:SI 0 "gpc_reg_operand" "")
3755         (ashift:SI (match_dup 1) (match_dup 2)))
3756    (clobber (match_scratch:SI 4 ""))]
3757   "TARGET_POWER && reload_completed"
3758   [(parallel [(set (match_dup 0)
3759         (ashift:SI (match_dup 1) (match_dup 2)))
3760    (clobber (match_dup 4))])
3761    (set (match_dup 3)
3762         (compare:CC (match_dup 0)
3763                     (const_int 0)))]
3764   "")
3765
3766 (define_insn ""
3767   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3768         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3769                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3770                     (const_int 0)))
3771    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3772         (ashift:SI (match_dup 1) (match_dup 2)))]
3773   "! TARGET_POWER && TARGET_32BIT"
3774   "@
3775    {sl|slw}%I2. %0,%1,%h2
3776    #"
3777   [(set_attr "type" "delayed_compare")
3778    (set_attr "length" "4,8")])
3779
3780 (define_split
3781   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3782         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3783                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3784                     (const_int 0)))
3785    (set (match_operand:SI 0 "gpc_reg_operand" "")
3786         (ashift:SI (match_dup 1) (match_dup 2)))]
3787   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3788   [(set (match_dup 0)
3789         (ashift:SI (match_dup 1) (match_dup 2)))
3790    (set (match_dup 3)
3791         (compare:CC (match_dup 0)
3792                     (const_int 0)))]
3793   "")
3794
3795 (define_insn ""
3796   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3797         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3798                            (match_operand:SI 2 "const_int_operand" "i"))
3799                 (match_operand:SI 3 "mask_operand" "n")))]
3800   "includes_lshift_p (operands[2], operands[3])"
3801   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
3802
3803 (define_insn ""
3804   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3805         (compare:CC
3806          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3807                             (match_operand:SI 2 "const_int_operand" "i,i"))
3808                  (match_operand:SI 3 "mask_operand" "n,n"))
3809          (const_int 0)))
3810    (clobber (match_scratch:SI 4 "=r,r"))]
3811   "includes_lshift_p (operands[2], operands[3])"
3812   "@
3813    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
3814    #"
3815   [(set_attr "type" "delayed_compare")
3816    (set_attr "length" "4,8")])
3817
3818 (define_split
3819   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3820         (compare:CC
3821          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3822                             (match_operand:SI 2 "const_int_operand" ""))
3823                  (match_operand:SI 3 "mask_operand" ""))
3824          (const_int 0)))
3825    (clobber (match_scratch:SI 4 ""))]
3826   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3827   [(set (match_dup 4)
3828         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
3829                  (match_dup 3)))
3830    (set (match_dup 0)
3831         (compare:CC (match_dup 4)
3832                     (const_int 0)))]
3833   "")
3834
3835 (define_insn ""
3836   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3837         (compare:CC
3838          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3839                             (match_operand:SI 2 "const_int_operand" "i,i"))
3840                  (match_operand:SI 3 "mask_operand" "n,n"))
3841          (const_int 0)))
3842    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3843         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3844   "includes_lshift_p (operands[2], operands[3])"
3845   "@
3846    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
3847    #"
3848   [(set_attr "type" "delayed_compare")
3849    (set_attr "length" "4,8")])
3850
3851 (define_split
3852   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3853         (compare:CC
3854          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
3855                             (match_operand:SI 2 "const_int_operand" ""))
3856                  (match_operand:SI 3 "mask_operand" ""))
3857          (const_int 0)))
3858    (set (match_operand:SI 0 "gpc_reg_operand" "")
3859         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
3860   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
3861   [(set (match_dup 0)
3862         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
3863    (set (match_dup 4)
3864         (compare:CC (match_dup 0)
3865                     (const_int 0)))]
3866   "")
3867
3868 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
3869 ;; "sli x,x,0".
3870 (define_expand "lshrsi3"
3871   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
3872    (use (match_operand:SI 1 "gpc_reg_operand" ""))
3873    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
3874   ""
3875   "
3876 {
3877   if (TARGET_POWER)
3878     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
3879   else
3880     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
3881   DONE;
3882 }")
3883
3884 (define_insn "lshrsi3_power"
3885   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3886         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
3887                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
3888    (clobber (match_scratch:SI 3 "=q,X,X"))]
3889   "TARGET_POWER"
3890   "@
3891   sre %0,%1,%2
3892   mr %0,%1
3893   {s%A2i|s%A2wi} %0,%1,%h2")
3894
3895 (define_insn "lshrsi3_no_power"
3896   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3897         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3898                      (match_operand:SI 2 "reg_or_cint_operand" "O,ri")))]
3899   "! TARGET_POWER"
3900   "@
3901   mr %0,%1
3902   {sr|srw}%I2 %0,%1,%h2")
3903
3904 (define_insn ""
3905   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
3906         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
3907                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
3908                     (const_int 0)))
3909    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
3910    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
3911   "TARGET_POWER"
3912   "@
3913   sre. %3,%1,%2
3914   mr. %1,%1
3915   {s%A2i.|s%A2wi.} %3,%1,%h2
3916   #
3917   #
3918   #"
3919   [(set_attr "type" "delayed_compare")
3920    (set_attr "length" "4,4,4,8,8,8")])
3921
3922 (define_split
3923   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3924         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3925                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3926                     (const_int 0)))
3927    (clobber (match_scratch:SI 3 ""))
3928    (clobber (match_scratch:SI 4 ""))]
3929   "TARGET_POWER && reload_completed"
3930   [(parallel [(set (match_dup 3)
3931         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3932    (clobber (match_dup 4))])
3933    (set (match_dup 0)
3934         (compare:CC (match_dup 3)
3935                     (const_int 0)))]
3936   "")
3937
3938 (define_insn ""
3939   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
3940         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
3941                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
3942                     (const_int 0)))
3943    (clobber (match_scratch:SI 3 "=X,r,X,r"))]
3944   "! TARGET_POWER && TARGET_32BIT"
3945   "@
3946    mr. %1,%1
3947    {sr|srw}%I2. %3,%1,%h2
3948    #
3949    #"
3950   [(set_attr "type" "delayed_compare")
3951    (set_attr "length" "4,4,8,8")])
3952
3953 (define_split
3954   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3955         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3956                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3957                     (const_int 0)))
3958    (clobber (match_scratch:SI 3 ""))]
3959   "! TARGET_POWER && TARGET_32BIT && reload_completed"
3960   [(set (match_dup 3)
3961         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3962    (set (match_dup 0)
3963         (compare:CC (match_dup 3)
3964                     (const_int 0)))]
3965   "")
3966
3967 (define_insn ""
3968   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
3969         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
3970                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
3971                     (const_int 0)))
3972    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
3973         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3974    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
3975   "TARGET_POWER"
3976   "@
3977   sre. %0,%1,%2
3978   mr. %0,%1
3979   {s%A2i.|s%A2wi.} %0,%1,%h2
3980   #
3981   #
3982   #"
3983   [(set_attr "type" "delayed_compare")
3984    (set_attr "length" "4,4,4,8,8,8")])
3985
3986 (define_split
3987   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3988         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
3989                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
3990                     (const_int 0)))
3991    (set (match_operand:SI 0 "gpc_reg_operand" "")
3992         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3993    (clobber (match_scratch:SI 4 ""))]
3994   "TARGET_POWER && reload_completed"
3995   [(parallel [(set (match_dup 0)
3996         (lshiftrt:SI (match_dup 1) (match_dup 2)))
3997    (clobber (match_dup 4))])
3998    (set (match_dup 3)
3999         (compare:CC (match_dup 0)
4000                     (const_int 0)))]
4001   "")
4002
4003 (define_insn ""
4004   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4005         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4006                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
4007                     (const_int 0)))
4008    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4009         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4010   "! TARGET_POWER && TARGET_32BIT"
4011   "@
4012    mr. %0,%1
4013    {sr|srw}%I2. %0,%1,%h2
4014    #
4015    #"
4016   [(set_attr "type" "delayed_compare")
4017    (set_attr "length" "4,4,8,8")])
4018
4019 (define_split
4020   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4021         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4022                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4023                     (const_int 0)))
4024    (set (match_operand:SI 0 "gpc_reg_operand" "")
4025         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4026   "! TARGET_POWER && TARGET_32BIT && reload_completed"
4027   [(set (match_dup 0)
4028         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4029    (set (match_dup 3)
4030         (compare:CC (match_dup 0)
4031                     (const_int 0)))]
4032   "")
4033
4034 (define_insn ""
4035   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4036         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4037                              (match_operand:SI 2 "const_int_operand" "i"))
4038                 (match_operand:SI 3 "mask_operand" "n")))]
4039   "includes_rshift_p (operands[2], operands[3])"
4040   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
4041
4042 (define_insn ""
4043   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4044         (compare:CC
4045          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4046                               (match_operand:SI 2 "const_int_operand" "i,i"))
4047                  (match_operand:SI 3 "mask_operand" "n,n"))
4048          (const_int 0)))
4049    (clobber (match_scratch:SI 4 "=r,r"))]
4050   "includes_rshift_p (operands[2], operands[3])"
4051   "@
4052    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
4053    #"
4054   [(set_attr "type" "delayed_compare")
4055    (set_attr "length" "4,8")])
4056
4057 (define_split
4058   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4059         (compare:CC
4060          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4061                               (match_operand:SI 2 "const_int_operand" ""))
4062                  (match_operand:SI 3 "mask_operand" ""))
4063          (const_int 0)))
4064    (clobber (match_scratch:SI 4 ""))]
4065   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4066   [(set (match_dup 4)
4067         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4068                  (match_dup 3)))
4069    (set (match_dup 0)
4070         (compare:CC (match_dup 4)
4071                     (const_int 0)))]
4072   "")
4073
4074 (define_insn ""
4075   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4076         (compare:CC
4077          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4078                               (match_operand:SI 2 "const_int_operand" "i,i"))
4079                  (match_operand:SI 3 "mask_operand" "n,n"))
4080          (const_int 0)))
4081    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4082         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4083   "includes_rshift_p (operands[2], operands[3])"
4084   "@
4085    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
4086    #"
4087   [(set_attr "type" "delayed_compare")
4088    (set_attr "length" "4,8")])
4089
4090 (define_split
4091   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4092         (compare:CC
4093          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4094                               (match_operand:SI 2 "const_int_operand" ""))
4095                  (match_operand:SI 3 "mask_operand" ""))
4096          (const_int 0)))
4097    (set (match_operand:SI 0 "gpc_reg_operand" "")
4098         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4099   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4100   [(set (match_dup 0)
4101         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4102    (set (match_dup 4)
4103         (compare:CC (match_dup 0)
4104                     (const_int 0)))]
4105   "")
4106
4107 (define_insn ""
4108   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4109         (zero_extend:SI
4110          (subreg:QI
4111           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4112                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4113   "includes_rshift_p (operands[2], GEN_INT (255))"
4114   "{rlinm|rlwinm} %0,%1,%s2,0xff")
4115
4116 (define_insn ""
4117   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4118         (compare:CC
4119          (zero_extend:SI
4120           (subreg:QI
4121            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4122                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4123          (const_int 0)))
4124    (clobber (match_scratch:SI 3 "=r,r"))]
4125   "includes_rshift_p (operands[2], GEN_INT (255))"
4126   "@
4127    {rlinm.|rlwinm.} %3,%1,%s2,0xff
4128    #"
4129   [(set_attr "type" "delayed_compare")
4130    (set_attr "length" "4,8")])
4131
4132 (define_split
4133   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4134         (compare:CC
4135          (zero_extend:SI
4136           (subreg:QI
4137            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4138                         (match_operand:SI 2 "const_int_operand" "")) 0))
4139          (const_int 0)))
4140    (clobber (match_scratch:SI 3 ""))]
4141   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4142   [(set (match_dup 3)
4143         (zero_extend:SI (subreg:QI
4144            (lshiftrt:SI (match_dup 1)
4145                         (match_dup 2)) 0)))
4146    (set (match_dup 0)
4147         (compare:CC (match_dup 3)
4148                     (const_int 0)))]
4149   "")
4150
4151 (define_insn ""
4152   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4153         (compare:CC
4154          (zero_extend:SI
4155           (subreg:QI
4156            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4157                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4158          (const_int 0)))
4159    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4160         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4161   "includes_rshift_p (operands[2], GEN_INT (255))"
4162   "@
4163    {rlinm.|rlwinm.} %0,%1,%s2,0xff
4164    #"
4165   [(set_attr "type" "delayed_compare")
4166    (set_attr "length" "4,8")])
4167
4168 (define_split
4169   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4170         (compare:CC
4171          (zero_extend:SI
4172           (subreg:QI
4173            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4174                         (match_operand:SI 2 "const_int_operand" "")) 0))
4175          (const_int 0)))
4176    (set (match_operand:SI 0 "gpc_reg_operand" "")
4177         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4178   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4179   [(set (match_dup 0)
4180         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4181    (set (match_dup 3)
4182         (compare:CC (match_dup 0)
4183                     (const_int 0)))]
4184   "")
4185
4186 (define_insn ""
4187   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4188         (zero_extend:SI
4189          (subreg:HI
4190           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4191                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4192   "includes_rshift_p (operands[2], GEN_INT (65535))"
4193   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
4194
4195 (define_insn ""
4196   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4197         (compare:CC
4198          (zero_extend:SI
4199           (subreg:HI
4200            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4201                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4202          (const_int 0)))
4203    (clobber (match_scratch:SI 3 "=r,r"))]
4204   "includes_rshift_p (operands[2], GEN_INT (65535))"
4205   "@
4206    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
4207    #"
4208   [(set_attr "type" "delayed_compare")
4209    (set_attr "length" "4,8")])
4210
4211 (define_split
4212   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4213         (compare:CC
4214          (zero_extend:SI
4215           (subreg:HI
4216            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4217                         (match_operand:SI 2 "const_int_operand" "")) 0))
4218          (const_int 0)))
4219    (clobber (match_scratch:SI 3 ""))]
4220   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4221   [(set (match_dup 3)
4222         (zero_extend:SI (subreg:HI
4223            (lshiftrt:SI (match_dup 1)
4224                         (match_dup 2)) 0)))
4225    (set (match_dup 0)
4226         (compare:CC (match_dup 3)
4227                     (const_int 0)))]
4228   "")
4229
4230 (define_insn ""
4231   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4232         (compare:CC
4233          (zero_extend:SI
4234           (subreg:HI
4235            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4236                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4237          (const_int 0)))
4238    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4239         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4240   "includes_rshift_p (operands[2], GEN_INT (65535))"
4241   "@
4242    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
4243    #"
4244   [(set_attr "type" "delayed_compare")
4245    (set_attr "length" "4,8")])
4246
4247 (define_split
4248   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4249         (compare:CC
4250          (zero_extend:SI
4251           (subreg:HI
4252            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4253                         (match_operand:SI 2 "const_int_operand" "")) 0))
4254          (const_int 0)))
4255    (set (match_operand:SI 0 "gpc_reg_operand" "")
4256         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4257   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4258   [(set (match_dup 0)
4259         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4260    (set (match_dup 3)
4261         (compare:CC (match_dup 0)
4262                     (const_int 0)))]
4263   "")
4264
4265 (define_insn ""
4266   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4267                          (const_int 1)
4268                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4269         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4270                      (const_int 31)))]
4271   "TARGET_POWER"
4272   "rrib %0,%1,%2")
4273
4274 (define_insn ""
4275   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4276                          (const_int 1)
4277                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4278         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4279                      (const_int 31)))]
4280   "TARGET_POWER"
4281   "rrib %0,%1,%2")
4282
4283 (define_insn ""
4284   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4285                          (const_int 1)
4286                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4287         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4288                          (const_int 1)
4289                          (const_int 0)))]
4290   "TARGET_POWER"
4291   "rrib %0,%1,%2")
4292
4293 (define_expand "ashrsi3"
4294   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4295         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4296                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4297   ""
4298   "
4299 {
4300   if (TARGET_POWER)
4301     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
4302   else
4303     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
4304   DONE;
4305 }")
4306
4307 (define_insn "ashrsi3_power"
4308   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4309         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4310                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4311    (clobber (match_scratch:SI 3 "=q,X"))]
4312   "TARGET_POWER"
4313   "@
4314    srea %0,%1,%2
4315    {srai|srawi} %0,%1,%h2")
4316
4317 (define_insn "ashrsi3_no_power"
4318   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4319         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4320                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4321   "! TARGET_POWER"
4322   "{sra|sraw}%I2 %0,%1,%h2")
4323
4324 (define_insn ""
4325   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4326         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4327                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4328                     (const_int 0)))
4329    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4330    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4331   "TARGET_POWER"
4332   "@
4333    srea. %3,%1,%2
4334    {srai.|srawi.} %3,%1,%h2
4335    #
4336    #"
4337   [(set_attr "type" "delayed_compare")
4338    (set_attr "length" "4,4,8,8")])
4339
4340 (define_split
4341   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4342         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4343                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4344                     (const_int 0)))
4345    (clobber (match_scratch:SI 3 ""))
4346    (clobber (match_scratch:SI 4 ""))]
4347   "TARGET_POWER && reload_completed"
4348   [(parallel [(set (match_dup 3)
4349         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4350    (clobber (match_dup 4))])
4351    (set (match_dup 0)
4352         (compare:CC (match_dup 3)
4353                     (const_int 0)))]
4354   "")
4355
4356 (define_insn ""
4357   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4358         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4359                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4360                     (const_int 0)))
4361    (clobber (match_scratch:SI 3 "=r,r"))]
4362   "! TARGET_POWER"
4363   "@
4364    {sra|sraw}%I2. %3,%1,%h2
4365    #"
4366   [(set_attr "type" "delayed_compare")
4367    (set_attr "length" "4,8")])
4368
4369 (define_split
4370   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4371         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4372                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4373                     (const_int 0)))
4374    (clobber (match_scratch:SI 3 ""))]
4375   "! TARGET_POWER && reload_completed"
4376   [(set (match_dup 3)
4377         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4378    (set (match_dup 0)
4379         (compare:CC (match_dup 3)
4380                     (const_int 0)))]
4381   "")
4382
4383 (define_insn ""
4384   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4385         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4386                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4387                     (const_int 0)))
4388    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4389         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4390    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4391   "TARGET_POWER"
4392   "@
4393    srea. %0,%1,%2
4394    {srai.|srawi.} %0,%1,%h2
4395    #
4396    #"
4397   [(set_attr "type" "delayed_compare")
4398    (set_attr "length" "4,4,8,8")])
4399
4400 (define_split
4401   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4402         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4403                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4404                     (const_int 0)))
4405    (set (match_operand:SI 0 "gpc_reg_operand" "")
4406         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4407    (clobber (match_scratch:SI 4 ""))]
4408   "TARGET_POWER && reload_completed"
4409   [(parallel [(set (match_dup 0)
4410         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4411    (clobber (match_dup 4))])
4412    (set (match_dup 3)
4413         (compare:CC (match_dup 0)
4414                     (const_int 0)))]
4415   "")
4416
4417 (define_insn ""
4418   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4419         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4420                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4421                     (const_int 0)))
4422    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4423         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4424   "! TARGET_POWER"
4425   "@
4426    {sra|sraw}%I2. %0,%1,%h2
4427    #"
4428   [(set_attr "type" "delayed_compare")
4429    (set_attr "length" "4,8")])
4430 \f
4431 (define_split
4432   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4433         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4434                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4435                     (const_int 0)))
4436    (set (match_operand:SI 0 "gpc_reg_operand" "")
4437         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
4438   "! TARGET_POWER && reload_completed"
4439   [(set (match_dup 0)
4440         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4441    (set (match_dup 3)
4442         (compare:CC (match_dup 0)
4443                     (const_int 0)))]
4444   "")
4445
4446 ;; Floating-point insns, excluding normal data motion.
4447 ;;
4448 ;; PowerPC has a full set of single-precision floating point instructions.
4449 ;;
4450 ;; For the POWER architecture, we pretend that we have both SFmode and
4451 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
4452 ;; The only conversions we will do will be when storing to memory.  In that
4453 ;; case, we will use the "frsp" instruction before storing.
4454 ;;
4455 ;; Note that when we store into a single-precision memory location, we need to
4456 ;; use the frsp insn first.  If the register being stored isn't dead, we
4457 ;; need a scratch register for the frsp.  But this is difficult when the store
4458 ;; is done by reload.  It is not incorrect to do the frsp on the register in
4459 ;; this case, we just lose precision that we would have otherwise gotten but
4460 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
4461
4462 (define_expand "extendsfdf2"
4463   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4464         (float_extend:DF (match_operand:SF 1 "gpc_reg_operand" "")))]
4465   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4466   "")
4467
4468 (define_insn_and_split "*extendsfdf2_fpr"
4469   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,?f")
4470         (float_extend:DF (match_operand:SF 1 "gpc_reg_operand" "0,f")))]
4471   "TARGET_HARD_FLOAT && TARGET_FPRS"
4472   "@
4473    #
4474    fmr %0,%1"
4475   "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
4476   [(const_int 0)]
4477 {
4478   emit_note (NOTE_INSN_DELETED);
4479   DONE;
4480 }
4481   [(set_attr "type" "fp")])
4482
4483 (define_expand "truncdfsf2"
4484   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4485         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "")))]
4486   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4487   "")
4488
4489 (define_insn "*truncdfsf2_fpr"
4490   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4491         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4492   "TARGET_HARD_FLOAT && TARGET_FPRS"
4493   "frsp %0,%1"
4494   [(set_attr "type" "fp")])
4495
4496 (define_insn "aux_truncdfsf2"
4497   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4498         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] UNSPEC_FRSP))]
4499   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4500   "frsp %0,%1"
4501   [(set_attr "type" "fp")])
4502
4503 (define_expand "negsf2"
4504   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4505         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4506   "TARGET_HARD_FLOAT"
4507   "")
4508
4509 (define_insn "*negsf2"
4510   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4511         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4512   "TARGET_HARD_FLOAT && TARGET_FPRS"
4513   "fneg %0,%1"
4514   [(set_attr "type" "fp")])
4515
4516 (define_expand "abssf2"
4517   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4518         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4519   "TARGET_HARD_FLOAT"
4520   "")
4521
4522 (define_insn "*abssf2"
4523   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4524         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4525   "TARGET_HARD_FLOAT && TARGET_FPRS"
4526   "fabs %0,%1"
4527   [(set_attr "type" "fp")])
4528
4529 (define_insn ""
4530   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4531         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
4532   "TARGET_HARD_FLOAT && TARGET_FPRS"
4533   "fnabs %0,%1"
4534   [(set_attr "type" "fp")])
4535
4536 (define_expand "addsf3"
4537   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4538         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4539                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4540   "TARGET_HARD_FLOAT"
4541   "")
4542
4543 (define_insn ""
4544   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4545         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4546                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4547   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4548   "fadds %0,%1,%2"
4549   [(set_attr "type" "fp")])
4550
4551 (define_insn ""
4552   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4553         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4554                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4555   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4556   "{fa|fadd} %0,%1,%2"
4557   [(set_attr "type" "fp")])
4558
4559 (define_expand "subsf3"
4560   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4561         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
4562                   (match_operand:SF 2 "gpc_reg_operand" "")))]
4563   "TARGET_HARD_FLOAT"
4564   "")
4565
4566 (define_insn ""
4567   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4568         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4569                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4570   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4571   "fsubs %0,%1,%2"
4572   [(set_attr "type" "fp")])
4573
4574 (define_insn ""
4575   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4576         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4577                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
4578   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4579   "{fs|fsub} %0,%1,%2"
4580   [(set_attr "type" "fp")])
4581
4582 (define_expand "mulsf3"
4583   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4584         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
4585                  (match_operand:SF 2 "gpc_reg_operand" "")))]
4586   "TARGET_HARD_FLOAT"
4587   "")
4588
4589 (define_insn ""
4590   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4591         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4592                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4593   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4594   "fmuls %0,%1,%2"
4595   [(set_attr "type" "fp")])
4596
4597 (define_insn ""
4598   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4599         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4600                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
4601   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4602   "{fm|fmul} %0,%1,%2"
4603   [(set_attr "type" "dmul")])
4604
4605 (define_expand "divsf3"
4606   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4607         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
4608                 (match_operand:SF 2 "gpc_reg_operand" "")))]
4609   "TARGET_HARD_FLOAT"
4610   "")
4611
4612 (define_insn ""
4613   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4614         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4615                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4616   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4617   "fdivs %0,%1,%2"
4618   [(set_attr "type" "sdiv")])
4619
4620 (define_insn ""
4621   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4622         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
4623                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
4624   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
4625   "{fd|fdiv} %0,%1,%2"
4626   [(set_attr "type" "ddiv")])
4627
4628 (define_insn ""
4629   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4630         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4631                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4632                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4633   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4634   "fmadds %0,%1,%2,%3"
4635   [(set_attr "type" "fp")])
4636
4637 (define_insn ""
4638   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4639         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4640                           (match_operand:SF 2 "gpc_reg_operand" "f"))
4641                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
4642   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4643   "{fma|fmadd} %0,%1,%2,%3"
4644   [(set_attr "type" "dmul")])
4645
4646 (define_insn ""
4647   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4648         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4649                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4650                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4651   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4652   "fmsubs %0,%1,%2,%3"
4653   [(set_attr "type" "fp")])
4654
4655 (define_insn ""
4656   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4657         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4658                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4659                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
4660   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4661   "{fms|fmsub} %0,%1,%2,%3"
4662   [(set_attr "type" "dmul")])
4663
4664 (define_insn ""
4665   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4666         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4667                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4668                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4669   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4670    && HONOR_SIGNED_ZEROS (SFmode)"
4671   "fnmadds %0,%1,%2,%3"
4672   [(set_attr "type" "fp")])
4673
4674 (define_insn ""
4675   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4676         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4677                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4678                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4679   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4680    && ! HONOR_SIGNED_ZEROS (SFmode)"
4681   "fnmadds %0,%1,%2,%3"
4682   [(set_attr "type" "fp")])
4683
4684 (define_insn ""
4685   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4686         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4687                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
4688                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4689   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4690   "{fnma|fnmadd} %0,%1,%2,%3"
4691   [(set_attr "type" "dmul")])
4692
4693 (define_insn ""
4694   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4695         (minus:SF (mult:SF (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f"))
4696                            (match_operand:SF 2 "gpc_reg_operand" "f"))
4697                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4698   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4699    && ! HONOR_SIGNED_ZEROS (SFmode)"
4700   "{fnma|fnmadd} %0,%1,%2,%3"
4701   [(set_attr "type" "dmul")])
4702
4703 (define_insn ""
4704   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4705         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4706                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
4707                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4708   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4709    && HONOR_SIGNED_ZEROS (SFmode)"
4710   "fnmsubs %0,%1,%2,%3"
4711   [(set_attr "type" "fp")])
4712
4713 (define_insn ""
4714   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4715         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
4716                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4717                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4718   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4719    && ! HONOR_SIGNED_ZEROS (SFmode)"
4720   "fnmsubs %0,%1,%2,%3"
4721   [(set_attr "type" "fp")])
4722
4723 (define_insn ""
4724   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4725         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4726                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
4727                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
4728   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4729   "{fnms|fnmsub} %0,%1,%2,%3"
4730   [(set_attr "type" "dmul")])
4731
4732 (define_insn ""
4733   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4734         (minus:SF (match_operand:SF 3 "gpc_reg_operand" "f")
4735                   (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
4736                            (match_operand:SF 2 "gpc_reg_operand" "f"))))]
4737   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4738    && ! HONOR_SIGNED_ZEROS (SFmode)"
4739   "{fnms|fnmsub} %0,%1,%2,%3"
4740   [(set_attr "type" "fp")])
4741
4742 (define_expand "sqrtsf2"
4743   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4744         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
4745   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
4746   "")
4747
4748 (define_insn ""
4749   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4750         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4751   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4752   "fsqrts %0,%1"
4753   [(set_attr "type" "ssqrt")])
4754
4755 (define_insn ""
4756   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4757         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
4758   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS"
4759   "fsqrt %0,%1"
4760   [(set_attr "type" "dsqrt")])
4761
4762 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
4763 ;; fsel instruction and some auxiliary computations.  Then we just have a
4764 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
4765 ;; combine.
4766 (define_expand "maxsf3"
4767   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4768         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4769                              (match_operand:SF 2 "gpc_reg_operand" ""))
4770                          (match_dup 1)
4771                          (match_dup 2)))]
4772   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
4773   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
4774
4775 (define_expand "minsf3"
4776   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4777         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
4778                              (match_operand:SF 2 "gpc_reg_operand" ""))
4779                          (match_dup 2)
4780                          (match_dup 1)))]
4781   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
4782   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
4783
4784 (define_split
4785   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4786         (match_operator:SF 3 "min_max_operator"
4787          [(match_operand:SF 1 "gpc_reg_operand" "")
4788           (match_operand:SF 2 "gpc_reg_operand" "")]))]
4789   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
4790   [(const_int 0)]
4791   "
4792 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
4793                       operands[1], operands[2]);
4794   DONE;
4795 }")
4796
4797 (define_expand "movsicc"
4798    [(set (match_operand:SI 0 "gpc_reg_operand" "")
4799          (if_then_else:SI (match_operand 1 "comparison_operator" "")
4800                           (match_operand:SI 2 "gpc_reg_operand" "")
4801                           (match_operand:SI 3 "gpc_reg_operand" "")))]
4802   "TARGET_ISEL"
4803   "
4804 {
4805   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4806     DONE;
4807   else
4808     FAIL;
4809 }")
4810
4811 ;; We use the BASE_REGS for the isel input operands because, if rA is
4812 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
4813 ;; because we may switch the operands and rB may end up being rA.
4814 ;;
4815 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
4816 ;; leave out the mode in operand 4 and use one pattern, but reload can
4817 ;; change the mode underneath our feet and then gets confused trying
4818 ;; to reload the value.
4819 (define_insn "isel_signed"
4820   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4821         (if_then_else:SI
4822          (match_operator 1 "comparison_operator"
4823                          [(match_operand:CC 4 "cc_reg_operand" "y")
4824                           (const_int 0)])
4825          (match_operand:SI 2 "gpc_reg_operand" "b")
4826          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4827   "TARGET_ISEL"
4828   "*
4829 { return output_isel (operands); }"
4830   [(set_attr "length" "4")])
4831
4832 (define_insn "isel_unsigned"
4833   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4834         (if_then_else:SI
4835          (match_operator 1 "comparison_operator"
4836                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
4837                           (const_int 0)])
4838          (match_operand:SI 2 "gpc_reg_operand" "b")
4839          (match_operand:SI 3 "gpc_reg_operand" "b")))]
4840   "TARGET_ISEL"
4841   "*
4842 { return output_isel (operands); }"
4843   [(set_attr "length" "4")])
4844
4845 (define_expand "movsfcc"
4846    [(set (match_operand:SF 0 "gpc_reg_operand" "")
4847          (if_then_else:SF (match_operand 1 "comparison_operator" "")
4848                           (match_operand:SF 2 "gpc_reg_operand" "")
4849                           (match_operand:SF 3 "gpc_reg_operand" "")))]
4850   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4851   "
4852 {
4853   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
4854     DONE;
4855   else
4856     FAIL;
4857 }")
4858
4859 (define_insn "*fselsfsf4"
4860   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4861         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
4862                              (match_operand:SF 4 "zero_fp_constant" "F"))
4863                          (match_operand:SF 2 "gpc_reg_operand" "f")
4864                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4865   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4866   "fsel %0,%1,%2,%3"
4867   [(set_attr "type" "fp")])
4868
4869 (define_insn "*fseldfsf4"
4870   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
4871         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
4872                              (match_operand:DF 4 "zero_fp_constant" "F"))
4873                          (match_operand:SF 2 "gpc_reg_operand" "f")
4874                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
4875   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
4876   "fsel %0,%1,%2,%3"
4877   [(set_attr "type" "fp")])
4878
4879 (define_expand "negdf2"
4880   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4881         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
4882   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4883   "")
4884
4885 (define_insn "*negdf2_fpr"
4886   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4887         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4888   "TARGET_HARD_FLOAT && TARGET_FPRS"
4889   "fneg %0,%1"
4890   [(set_attr "type" "fp")])
4891
4892 (define_expand "absdf2"
4893   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4894         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "")))]
4895   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4896   "")
4897
4898 (define_insn "*absdf2_fpr"
4899   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4900         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
4901   "TARGET_HARD_FLOAT && TARGET_FPRS"
4902   "fabs %0,%1"
4903   [(set_attr "type" "fp")])
4904
4905 (define_insn "*nabsdf2_fpr"
4906   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4907         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
4908   "TARGET_HARD_FLOAT && TARGET_FPRS"
4909   "fnabs %0,%1"
4910   [(set_attr "type" "fp")])
4911
4912 (define_expand "adddf3"
4913   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4914         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "")
4915                  (match_operand:DF 2 "gpc_reg_operand" "")))]
4916   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4917   "")
4918
4919 (define_insn "*adddf3_fpr"
4920   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4921         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4922                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
4923   "TARGET_HARD_FLOAT && TARGET_FPRS"
4924   "{fa|fadd} %0,%1,%2"
4925   [(set_attr "type" "fp")])
4926
4927 (define_expand "subdf3"
4928   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4929         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
4930                   (match_operand:DF 2 "gpc_reg_operand" "")))]
4931   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4932   "")
4933
4934 (define_insn "*subdf3_fpr"
4935   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4936         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
4937                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
4938   "TARGET_HARD_FLOAT && TARGET_FPRS"
4939   "{fs|fsub} %0,%1,%2"
4940   [(set_attr "type" "fp")])
4941
4942 (define_expand "muldf3"
4943   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4944         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "")
4945                  (match_operand:DF 2 "gpc_reg_operand" "")))]
4946   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4947   "")
4948
4949 (define_insn "*muldf3_fpr"
4950   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4951         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4952                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
4953   "TARGET_HARD_FLOAT && TARGET_FPRS"
4954   "{fm|fmul} %0,%1,%2"
4955   [(set_attr "type" "dmul")])
4956
4957 (define_expand "divdf3"
4958   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4959         (div:DF (match_operand:DF 1 "gpc_reg_operand" "")
4960                 (match_operand:DF 2 "gpc_reg_operand" "")))]
4961   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
4962   "")
4963
4964 (define_insn "*divdf3_fpr"
4965   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4966         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
4967                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
4968   "TARGET_HARD_FLOAT && TARGET_FPRS"
4969   "{fd|fdiv} %0,%1,%2"
4970   [(set_attr "type" "ddiv")])
4971
4972 (define_insn ""
4973   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4974         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4975                           (match_operand:DF 2 "gpc_reg_operand" "f"))
4976                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
4977   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4978   "{fma|fmadd} %0,%1,%2,%3"
4979   [(set_attr "type" "dmul")])
4980
4981 (define_insn ""
4982   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4983         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4984                            (match_operand:DF 2 "gpc_reg_operand" "f"))
4985                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
4986   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
4987   "{fms|fmsub} %0,%1,%2,%3"
4988   [(set_attr "type" "dmul")])
4989
4990 (define_insn ""
4991   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
4992         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
4993                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
4994                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
4995   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
4996    && HONOR_SIGNED_ZEROS (DFmode)"
4997   "{fnma|fnmadd} %0,%1,%2,%3"
4998   [(set_attr "type" "dmul")])
4999
5000 (define_insn ""
5001   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5002         (minus:DF (mult:DF (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f"))
5003                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5004                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5005   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5006    && ! HONOR_SIGNED_ZEROS (DFmode)"
5007   "{fnma|fnmadd} %0,%1,%2,%3"
5008   [(set_attr "type" "dmul")])
5009
5010 (define_insn ""
5011   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5012         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5013                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
5014                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5015   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5016    && HONOR_SIGNED_ZEROS (DFmode)"
5017   "{fnms|fnmsub} %0,%1,%2,%3"
5018   [(set_attr "type" "dmul")])
5019
5020 (define_insn ""
5021   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5022         (minus:DF (match_operand:DF 3 "gpc_reg_operand" "f")
5023                   (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5024                            (match_operand:DF 2 "gpc_reg_operand" "f"))))]
5025   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD
5026    && ! HONOR_SIGNED_ZEROS (DFmode)"
5027   "{fnms|fnmsub} %0,%1,%2,%3"
5028   [(set_attr "type" "dmul")])
5029
5030 (define_insn "sqrtdf2"
5031   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5032         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5033   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
5034   "fsqrt %0,%1"
5035   [(set_attr "type" "dsqrt")])
5036
5037 ;; The conditional move instructions allow us to perform max and min
5038 ;; operations even when
5039
5040 (define_expand "maxdf3"
5041   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5042         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5043                              (match_operand:DF 2 "gpc_reg_operand" ""))
5044                          (match_dup 1)
5045                          (match_dup 2)))]
5046   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5047   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5048
5049 (define_expand "mindf3"
5050   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5051         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5052                              (match_operand:DF 2 "gpc_reg_operand" ""))
5053                          (match_dup 2)
5054                          (match_dup 1)))]
5055   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5056   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5057
5058 (define_split
5059   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5060         (match_operator:DF 3 "min_max_operator"
5061          [(match_operand:DF 1 "gpc_reg_operand" "")
5062           (match_operand:DF 2 "gpc_reg_operand" "")]))]
5063   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS && !flag_trapping_math"
5064   [(const_int 0)]
5065   "
5066 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]),
5067                       operands[1], operands[2]);
5068   DONE;
5069 }")
5070
5071 (define_expand "movdfcc"
5072    [(set (match_operand:DF 0 "gpc_reg_operand" "")
5073          (if_then_else:DF (match_operand 1 "comparison_operator" "")
5074                           (match_operand:DF 2 "gpc_reg_operand" "")
5075                           (match_operand:DF 3 "gpc_reg_operand" "")))]
5076   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5077   "
5078 {
5079   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5080     DONE;
5081   else
5082     FAIL;
5083 }")
5084
5085 (define_insn "*fseldfdf4"
5086   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5087         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
5088                              (match_operand:DF 4 "zero_fp_constant" "F"))
5089                          (match_operand:DF 2 "gpc_reg_operand" "f")
5090                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5091   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5092   "fsel %0,%1,%2,%3"
5093   [(set_attr "type" "fp")])
5094
5095 (define_insn "*fselsfdf4"
5096   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5097         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5098                              (match_operand:SF 4 "zero_fp_constant" "F"))
5099                          (match_operand:DF 2 "gpc_reg_operand" "f")
5100                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5101   "TARGET_PPC_GFXOPT"
5102   "fsel %0,%1,%2,%3"
5103   [(set_attr "type" "fp")])
5104 \f
5105 ;; Conversions to and from floating-point.
5106
5107 (define_expand "fixuns_truncsfsi2"
5108   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5109         (unsigned_fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5110   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5111   "")
5112
5113 (define_expand "fix_truncsfsi2"
5114   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5115         (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5116   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5117   "")
5118
5119 ; For each of these conversions, there is a define_expand, a define_insn
5120 ; with a '#' template, and a define_split (with C code).  The idea is
5121 ; to allow constant folding with the template of the define_insn,
5122 ; then to have the insns split later (between sched1 and final).
5123
5124 (define_expand "floatsidf2"
5125   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5126                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5127               (use (match_dup 2))
5128               (use (match_dup 3))
5129               (clobber (match_dup 4))
5130               (clobber (match_dup 5))
5131               (clobber (match_dup 6))])]
5132   "TARGET_HARD_FLOAT && TARGET_FPRS"
5133   "
5134 {
5135   if (TARGET_E500_DOUBLE)
5136     {
5137       emit_insn (gen_spe_floatsidf2 (operands[0], operands[1]));
5138       DONE;
5139     }
5140   if (TARGET_POWERPC64)
5141     {
5142       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5143       rtx t1 = gen_reg_rtx (DImode);
5144       rtx t2 = gen_reg_rtx (DImode);
5145       emit_insn (gen_floatsidf_ppc64 (operands[0], operands[1], mem, t1, t2));
5146       DONE;
5147     }
5148
5149   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5150   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5151   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5152   operands[5] = gen_reg_rtx (DFmode);
5153   operands[6] = gen_reg_rtx (SImode);
5154 }")
5155
5156 (define_insn "*floatsidf2_internal"
5157   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5158         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5159    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5160    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5161    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5162    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))
5163    (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
5164   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5165   "#"
5166   [(set_attr "length" "24")])
5167
5168 (define_split
5169   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5170         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5171    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5172    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5173    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5174    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))
5175    (clobber (match_operand:SI 6 "gpc_reg_operand" ""))]
5176   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5177   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5178         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5179    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5180    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5181    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5182    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))
5183    (clobber (match_operand:SI 6 "gpc_reg_operand" ""))]
5184   "
5185 {
5186   rtx lowword, highword;
5187   if (GET_CODE (operands[4]) != MEM)
5188     abort();
5189   highword = XEXP (operands[4], 0);
5190   lowword = plus_constant (highword, 4);
5191   if (! WORDS_BIG_ENDIAN)
5192     {
5193       rtx tmp;
5194       tmp = highword; highword = lowword; lowword = tmp;
5195     }
5196
5197   emit_insn (gen_xorsi3 (operands[6], operands[1],
5198                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5199   emit_move_insn (gen_rtx_MEM (SImode, lowword), operands[6]);
5200   emit_move_insn (gen_rtx_MEM (SImode, highword), operands[2]);
5201   emit_move_insn (operands[5], operands[4]);
5202   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5203   DONE;
5204 }")
5205
5206 (define_expand "floatunssisf2"
5207   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5208         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5209   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5210   "")
5211
5212 (define_expand "floatunssidf2"
5213   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5214                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5215               (use (match_dup 2))
5216               (use (match_dup 3))
5217               (clobber (match_dup 4))
5218               (clobber (match_dup 5))])]
5219   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5220   "
5221 {
5222   if (TARGET_E500_DOUBLE)
5223     {
5224       emit_insn (gen_spe_floatunssidf2 (operands[0], operands[1]));
5225       DONE;
5226     }
5227   if (TARGET_POWERPC64)
5228     {
5229       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5230       rtx t1 = gen_reg_rtx (DImode);
5231       rtx t2 = gen_reg_rtx (DImode);
5232       emit_insn (gen_floatunssidf_ppc64 (operands[0], operands[1], mem,
5233                                          t1, t2));
5234       DONE;
5235     }
5236
5237   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5238   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5239   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5240   operands[5] = gen_reg_rtx (DFmode);
5241 }")
5242
5243 (define_insn "*floatunssidf2_internal"
5244   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5245         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5246    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5247    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5248    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5249    (clobber (match_operand:DF 5 "gpc_reg_operand" "=&f"))]
5250   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5251   "#"
5252   [(set_attr "length" "20")])
5253
5254 (define_split
5255   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5256         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5257    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5258    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5259    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5260    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))]
5261   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5262   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5263         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5264    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5265    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5266    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5267    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))]
5268   "
5269 {
5270   rtx lowword, highword;
5271   if (GET_CODE (operands[4]) != MEM)
5272     abort();
5273   highword = XEXP (operands[4], 0);
5274   lowword = plus_constant (highword, 4);
5275   if (! WORDS_BIG_ENDIAN)
5276     {
5277       rtx tmp;
5278       tmp = highword; highword = lowword; lowword = tmp;
5279     }
5280
5281   emit_move_insn (gen_rtx_MEM (SImode, lowword), operands[1]);
5282   emit_move_insn (gen_rtx_MEM (SImode, highword), operands[2]);
5283   emit_move_insn (operands[5], operands[4]);
5284   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5285   DONE;
5286 }")
5287
5288 (define_expand "fix_truncdfsi2"
5289   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
5290                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5291               (clobber (match_dup 2))
5292               (clobber (match_dup 3))])]
5293   "(TARGET_POWER2 || TARGET_POWERPC)
5294    && TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
5295   "
5296 {
5297   if (TARGET_E500_DOUBLE)
5298     {
5299      emit_insn (gen_spe_fix_truncdfsi2 (operands[0], operands[1]));
5300      DONE;
5301     }
5302   operands[2] = gen_reg_rtx (DImode);
5303   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5304 }")
5305
5306 (define_insn "*fix_truncdfsi2_internal"
5307   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5308         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5309    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
5310    (clobber (match_operand:DI 3 "memory_operand" "=o"))]
5311   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5312   "#"
5313   [(set_attr "length" "16")])
5314
5315 (define_split
5316   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5317         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5318    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
5319    (clobber (match_operand:DI 3 "offsettable_mem_operand" ""))]
5320   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5321   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5322         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5323    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
5324    (clobber (match_operand:DI 3 "offsettable_mem_operand" ""))]
5325   "
5326 {
5327   rtx lowword;
5328   if (GET_CODE (operands[3]) != MEM)
5329     abort();
5330   lowword = XEXP (operands[3], 0);
5331   if (WORDS_BIG_ENDIAN)
5332     lowword = plus_constant (lowword, 4);
5333
5334   emit_insn (gen_fctiwz (operands[2], operands[1]));
5335   emit_move_insn (operands[3], operands[2]);
5336   emit_move_insn (operands[0], gen_rtx_MEM (SImode, lowword));
5337   DONE;
5338 }")
5339
5340 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
5341 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
5342 ; because the first makes it clear that operand 0 is not live
5343 ; before the instruction.
5344 (define_insn "fctiwz"
5345   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5346         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))]
5347                    UNSPEC_FCTIWZ))]
5348   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5349   "{fcirz|fctiwz} %0,%1"
5350   [(set_attr "type" "fp")])
5351
5352 (define_expand "floatsisf2"
5353   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5354         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5355   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5356   "")
5357
5358 (define_insn "floatdidf2"
5359   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5360         (float:DF (match_operand:DI 1 "gpc_reg_operand" "*f")))]
5361   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5362   "fcfid %0,%1"
5363   [(set_attr "type" "fp")])
5364
5365 (define_insn_and_split "floatsidf_ppc64"
5366   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5367         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5368    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5369    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5370    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5371   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5372   "#"
5373   "&& 1"
5374   [(set (match_dup 3) (sign_extend:DI (match_dup 1)))
5375    (set (match_dup 2) (match_dup 3))
5376    (set (match_dup 4) (match_dup 2))
5377    (set (match_dup 0) (float:DF (match_dup 4)))]
5378   "")
5379
5380 (define_insn_and_split "floatunssidf_ppc64"
5381   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5382         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5383    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5384    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5385    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5386   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5387   "#"
5388   "&& 1"
5389   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
5390    (set (match_dup 2) (match_dup 3))
5391    (set (match_dup 4) (match_dup 2))
5392    (set (match_dup 0) (float:DF (match_dup 4)))]
5393   "")
5394
5395 (define_insn "fix_truncdfdi2"
5396   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5397         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
5398   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5399   "fctidz %0,%1"
5400   [(set_attr "type" "fp")])
5401
5402 (define_expand "floatdisf2"
5403   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5404         (float:SF (match_operand:DI 1 "gpc_reg_operand" "")))]
5405   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5406   "
5407 {
5408   rtx val = operands[1];
5409   if (!flag_unsafe_math_optimizations)
5410     {
5411       rtx label = gen_label_rtx ();
5412       val = gen_reg_rtx (DImode);
5413       emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
5414       emit_label (label);
5415     }
5416   emit_insn (gen_floatdisf2_internal1 (operands[0], val));
5417   DONE;
5418 }")
5419
5420 ;; This is not IEEE compliant if rounding mode is "round to nearest".
5421 ;; If the DI->DF conversion is inexact, then it's possible to suffer
5422 ;; from double rounding.
5423 (define_insn_and_split "floatdisf2_internal1"
5424   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5425         (float:SF (match_operand:DI 1 "gpc_reg_operand" "*f")))
5426    (clobber (match_scratch:DF 2 "=f"))]
5427   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5428   "#"
5429   "&& reload_completed"
5430   [(set (match_dup 2)
5431         (float:DF (match_dup 1)))
5432    (set (match_dup 0)
5433         (float_truncate:SF (match_dup 2)))]
5434   "")
5435
5436 ;; Twiddles bits to avoid double rounding.
5437 ;; Bits that might be truncated when converting to DFmode are replaced
5438 ;; by a bit that won't be lost at that stage, but is below the SFmode
5439 ;; rounding position.
5440 (define_expand "floatdisf2_internal2"
5441   [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "" "")
5442                                    (const_int 53)))
5443    (parallel [(set (match_operand:DI 0 "" "") (and:DI (match_dup 1)
5444                                                       (const_int 2047)))
5445               (clobber (scratch:CC))])
5446    (set (match_dup 3) (plus:DI (match_dup 3)
5447                                (const_int 1)))
5448    (set (match_dup 0) (plus:DI (match_dup 0)
5449                                (const_int 2047)))
5450    (set (match_dup 4) (compare:CCUNS (match_dup 3)
5451                                      (const_int 3)))
5452    (set (match_dup 0) (ior:DI (match_dup 0)
5453                               (match_dup 1)))
5454    (parallel [(set (match_dup 0) (and:DI (match_dup 0)
5455                                          (const_int -2048)))
5456               (clobber (scratch:CC))])
5457    (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
5458                            (label_ref (match_operand:DI 2 "" ""))
5459                            (pc)))
5460    (set (match_dup 0) (match_dup 1))]
5461   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5462   "
5463 {
5464   operands[3] = gen_reg_rtx (DImode);
5465   operands[4] = gen_reg_rtx (CCUNSmode);
5466 }")
5467 \f
5468 ;; Define the DImode operations that can be done in a small number
5469 ;; of instructions.  The & constraints are to prevent the register
5470 ;; allocator from allocating registers that overlap with the inputs
5471 ;; (for example, having an input in 7,8 and an output in 6,7).  We
5472 ;; also allow for the output being the same as one of the inputs.
5473
5474 (define_insn "*adddi3_noppc64"
5475   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
5476         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
5477                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
5478   "! TARGET_POWERPC64"
5479   "*
5480 {
5481   if (WORDS_BIG_ENDIAN)
5482     return (GET_CODE (operands[2])) != CONST_INT
5483             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
5484             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
5485   else
5486     return (GET_CODE (operands[2])) != CONST_INT
5487             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
5488             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
5489 }"
5490   [(set_attr "type" "two")
5491    (set_attr "length" "8")])
5492
5493 (define_insn "*subdi3_noppc64"
5494   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
5495         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
5496                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
5497   "! TARGET_POWERPC64"
5498   "*
5499 {
5500   if (WORDS_BIG_ENDIAN)
5501     return (GET_CODE (operands[1]) != CONST_INT)
5502             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
5503             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
5504   else
5505     return (GET_CODE (operands[1]) != CONST_INT)
5506             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
5507             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
5508 }"
5509   [(set_attr "type" "two")
5510    (set_attr "length" "8")])
5511
5512 (define_insn "*negdi2_noppc64"
5513   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5514         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
5515   "! TARGET_POWERPC64"
5516   "*
5517 {
5518   return (WORDS_BIG_ENDIAN)
5519     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
5520     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
5521 }"
5522   [(set_attr "type" "two")
5523    (set_attr "length" "8")])
5524
5525 (define_expand "mulsidi3"
5526   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5527         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5528                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5529   "! TARGET_POWERPC64"
5530   "
5531 {
5532   if (! TARGET_POWER && ! TARGET_POWERPC)
5533     {
5534       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5535       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5536       emit_insn (gen_mull_call ());
5537       if (WORDS_BIG_ENDIAN)
5538         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
5539       else
5540         {
5541           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
5542                           gen_rtx_REG (SImode, 3));
5543           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
5544                           gen_rtx_REG (SImode, 4));
5545         }
5546       DONE;
5547     }
5548   else if (TARGET_POWER)
5549     {
5550       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
5551       DONE;
5552     }
5553 }")
5554
5555 (define_insn "mulsidi3_mq"
5556   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5557         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5558                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5559    (clobber (match_scratch:SI 3 "=q"))]
5560   "TARGET_POWER"
5561   "mul %0,%1,%2\;mfmq %L0"
5562   [(set_attr "type" "imul")
5563    (set_attr "length" "8")])
5564
5565 (define_insn "*mulsidi3_no_mq"
5566   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5567         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5568                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5569   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5570   "*
5571 {
5572   return (WORDS_BIG_ENDIAN)
5573     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
5574     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
5575 }"
5576   [(set_attr "type" "imul")
5577    (set_attr "length" "8")])
5578
5579 (define_split
5580   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5581         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5582                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5583   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5584   [(set (match_dup 3)
5585         (truncate:SI
5586          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
5587                                (sign_extend:DI (match_dup 2)))
5588                       (const_int 32))))
5589    (set (match_dup 4)
5590         (mult:SI (match_dup 1)
5591                  (match_dup 2)))]
5592   "
5593 {
5594   int endian = (WORDS_BIG_ENDIAN == 0);
5595   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5596   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5597 }")
5598
5599 (define_expand "umulsidi3"
5600   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5601         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5602                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5603   "TARGET_POWERPC && ! TARGET_POWERPC64"
5604   "
5605 {
5606   if (TARGET_POWER)
5607     {
5608       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
5609       DONE;
5610     }
5611 }")
5612
5613 (define_insn "umulsidi3_mq"
5614   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5615         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5616                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5617    (clobber (match_scratch:SI 3 "=q"))]
5618   "TARGET_POWERPC && TARGET_POWER"
5619   "*
5620 {
5621   return (WORDS_BIG_ENDIAN)
5622     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5623     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5624 }"
5625   [(set_attr "type" "imul")
5626    (set_attr "length" "8")])
5627
5628 (define_insn "*umulsidi3_no_mq"
5629   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
5630         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5631                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
5632   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
5633   "*
5634 {
5635   return (WORDS_BIG_ENDIAN)
5636     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
5637     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
5638 }"
5639   [(set_attr "type" "imul")
5640    (set_attr "length" "8")])
5641
5642 (define_split
5643   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5644         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5645                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5646   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
5647   [(set (match_dup 3)
5648         (truncate:SI
5649          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
5650                                (zero_extend:DI (match_dup 2)))
5651                       (const_int 32))))
5652    (set (match_dup 4)
5653         (mult:SI (match_dup 1)
5654                  (match_dup 2)))]
5655   "
5656 {
5657   int endian = (WORDS_BIG_ENDIAN == 0);
5658   operands[3] = operand_subword (operands[0], endian, 0, DImode);
5659   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
5660 }")
5661
5662 (define_expand "smulsi3_highpart"
5663   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5664         (truncate:SI
5665          (lshiftrt:DI (mult:DI (sign_extend:DI
5666                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5667                                (sign_extend:DI
5668                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5669                       (const_int 32))))]
5670   ""
5671   "
5672 {
5673   if (! TARGET_POWER && ! TARGET_POWERPC)
5674     {
5675       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5676       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5677       emit_insn (gen_mulh_call ());
5678       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
5679       DONE;
5680     }
5681   else if (TARGET_POWER)
5682     {
5683       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5684       DONE;
5685     }
5686 }")
5687
5688 (define_insn "smulsi3_highpart_mq"
5689   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5690         (truncate:SI
5691          (lshiftrt:DI (mult:DI (sign_extend:DI
5692                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5693                                (sign_extend:DI
5694                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5695                       (const_int 32))))
5696    (clobber (match_scratch:SI 3 "=q"))]
5697   "TARGET_POWER"
5698   "mul %0,%1,%2"
5699   [(set_attr "type" "imul")])
5700
5701 (define_insn "*smulsi3_highpart_no_mq"
5702   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5703         (truncate:SI
5704          (lshiftrt:DI (mult:DI (sign_extend:DI
5705                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5706                                (sign_extend:DI
5707                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5708                       (const_int 32))))]
5709   "TARGET_POWERPC && ! TARGET_POWER"
5710   "mulhw %0,%1,%2"
5711   [(set_attr "type" "imul")])
5712
5713 (define_expand "umulsi3_highpart"
5714   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5715         (truncate:SI
5716          (lshiftrt:DI (mult:DI (zero_extend:DI
5717                                 (match_operand:SI 1 "gpc_reg_operand" ""))
5718                                (zero_extend:DI
5719                                 (match_operand:SI 2 "gpc_reg_operand" "")))
5720                       (const_int 32))))]
5721   "TARGET_POWERPC"
5722   "
5723 {
5724   if (TARGET_POWER)
5725     {
5726       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
5727       DONE;
5728     }
5729 }")
5730
5731 (define_insn "umulsi3_highpart_mq"
5732   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5733         (truncate:SI
5734          (lshiftrt:DI (mult:DI (zero_extend:DI
5735                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5736                                (zero_extend:DI
5737                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5738                       (const_int 32))))
5739    (clobber (match_scratch:SI 3 "=q"))]
5740   "TARGET_POWERPC && TARGET_POWER"
5741   "mulhwu %0,%1,%2"
5742   [(set_attr "type" "imul")])
5743
5744 (define_insn "*umulsi3_highpart_no_mq"
5745   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5746         (truncate:SI
5747          (lshiftrt:DI (mult:DI (zero_extend:DI
5748                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
5749                                (zero_extend:DI
5750                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
5751                       (const_int 32))))]
5752   "TARGET_POWERPC && ! TARGET_POWER"
5753   "mulhwu %0,%1,%2"
5754   [(set_attr "type" "imul")])
5755
5756 ;; If operands 0 and 2 are in the same register, we have a problem.  But
5757 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
5758 ;; why we have the strange constraints below.
5759 (define_insn "ashldi3_power"
5760   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5761         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5762                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5763    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5764   "TARGET_POWER"
5765   "@
5766    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
5767    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5768    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
5769    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
5770   [(set_attr "length" "8")])
5771
5772 (define_insn "lshrdi3_power"
5773   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
5774         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
5775                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
5776    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
5777   "TARGET_POWER"
5778   "@
5779    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
5780    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5781    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
5782    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
5783   [(set_attr "length" "8")])
5784
5785 ;; Shift by a variable amount is too complex to be worth open-coding.  We
5786 ;; just handle shifts by constants.
5787 (define_insn "ashrdi3_power"
5788   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5789         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5790                      (match_operand:SI 2 "const_int_operand" "M,i")))
5791    (clobber (match_scratch:SI 3 "=X,q"))]
5792   "TARGET_POWER"
5793   "@
5794    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5795    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
5796   [(set_attr "length" "8")])
5797
5798 (define_insn "ashrdi3_no_power"
5799   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
5800         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
5801                      (match_operand:SI 2 "const_int_operand" "M,i")))]
5802   "TARGET_32BIT && !TARGET_POWERPC64 && !TARGET_POWER && WORDS_BIG_ENDIAN"
5803   "@
5804    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
5805    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
5806   [(set_attr "type" "two,three")
5807    (set_attr "length" "8,12")])
5808
5809 (define_insn "*ashrdisi3_noppc64"
5810   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5811         (subreg:SI (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
5812                                 (const_int 32)) 4))]
5813   "TARGET_32BIT && !TARGET_POWERPC64"
5814   "*
5815 {
5816   if (REGNO (operands[0]) == REGNO (operands[1]))
5817     return \"\";
5818   else
5819     return \"mr %0,%1\";
5820 }"
5821    [(set_attr "length" "4")])
5822
5823 \f
5824 ;; PowerPC64 DImode operations.
5825
5826 (define_expand "adddi3"
5827   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5828         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5829                  (match_operand:DI 2 "reg_or_add_cint64_operand" "")))]
5830   ""
5831   "
5832 {
5833   if (! TARGET_POWERPC64)
5834     {
5835       if (non_short_cint_operand (operands[2], DImode))
5836         FAIL;
5837     }
5838   else
5839     if (GET_CODE (operands[2]) == CONST_INT
5840         && ! add_operand (operands[2], DImode))
5841       {
5842         rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
5843                    ? operands[0] : gen_reg_rtx (DImode));
5844
5845         HOST_WIDE_INT val = INTVAL (operands[2]);
5846         HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
5847         HOST_WIDE_INT rest = trunc_int_for_mode (val - low, DImode);
5848
5849         if (!CONST_OK_FOR_LETTER_P (rest, 'L'))
5850           FAIL;
5851
5852         /* The ordering here is important for the prolog expander.
5853            When space is allocated from the stack, adding 'low' first may
5854            produce a temporary deallocation (which would be bad).  */
5855         emit_insn (gen_adddi3 (tmp, operands[1], GEN_INT (rest)));
5856         emit_insn (gen_adddi3 (operands[0], tmp, GEN_INT (low)));
5857         DONE;
5858       }
5859 }")
5860
5861 ;; Discourage ai/addic because of carry but provide it in an alternative
5862 ;; allowing register zero as source.
5863
5864 (define_insn "*adddi3_internal1"
5865   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,?r,r")
5866         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,b,r,b")
5867                  (match_operand:DI 2 "add_operand" "r,I,I,L")))]
5868   "TARGET_POWERPC64"
5869   "@
5870    add %0,%1,%2
5871    addi %0,%1,%2
5872    addic %0,%1,%2
5873    addis %0,%1,%v2")
5874
5875 (define_insn "*adddi3_internal2"
5876   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
5877         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
5878                              (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I"))
5879                     (const_int 0)))
5880    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
5881   "TARGET_64BIT"
5882   "@
5883    add. %3,%1,%2
5884    addic. %3,%1,%2
5885    #
5886    #"
5887   [(set_attr "type" "fast_compare,compare,compare,compare")
5888    (set_attr "length" "4,4,8,8")])
5889
5890 (define_split
5891   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5892         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5893                              (match_operand:DI 2 "reg_or_short_operand" ""))
5894                     (const_int 0)))
5895    (clobber (match_scratch:DI 3 ""))]
5896   "TARGET_POWERPC64 && reload_completed"
5897   [(set (match_dup 3)
5898         (plus:DI (match_dup 1) (match_dup 2)))
5899    (set (match_dup 0)
5900         (compare:CC (match_dup 3)
5901                     (const_int 0)))]
5902   "")
5903
5904 (define_insn "*adddi3_internal3"
5905   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5906         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
5907                              (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I"))
5908                     (const_int 0)))
5909    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
5910         (plus:DI (match_dup 1) (match_dup 2)))]
5911   "TARGET_64BIT"
5912   "@
5913    add. %0,%1,%2
5914    addic. %0,%1,%2
5915    #
5916    #"
5917   [(set_attr "type" "fast_compare,compare,compare,compare")
5918    (set_attr "length" "4,4,8,8")])
5919
5920 (define_split
5921   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5922         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5923                              (match_operand:DI 2 "reg_or_short_operand" ""))
5924                     (const_int 0)))
5925    (set (match_operand:DI 0 "gpc_reg_operand" "")
5926         (plus:DI (match_dup 1) (match_dup 2)))]
5927   "TARGET_POWERPC64 && reload_completed"
5928   [(set (match_dup 0)
5929         (plus:DI (match_dup 1) (match_dup 2)))
5930    (set (match_dup 3)
5931         (compare:CC (match_dup 0)
5932                     (const_int 0)))]
5933   "")
5934
5935 ;; Split an add that we can't do in one insn into two insns, each of which
5936 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
5937 ;; add should be last in case the result gets used in an address.
5938
5939 (define_split
5940   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5941         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
5942                  (match_operand:DI 2 "non_add_cint_operand" "")))]
5943   "TARGET_POWERPC64"
5944   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 3)))
5945    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 4)))]
5946 "
5947 {
5948   HOST_WIDE_INT val = INTVAL (operands[2]);
5949   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
5950   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, DImode);
5951
5952   operands[4] = GEN_INT (low);
5953   if (CONST_OK_FOR_LETTER_P (rest, 'L'))
5954     operands[3] = GEN_INT (rest);
5955   else if (! no_new_pseudos)
5956     {
5957       operands[3] = gen_reg_rtx (DImode);
5958       emit_move_insn (operands[3], operands[2]);
5959       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
5960       DONE;
5961     }
5962   else
5963     FAIL;
5964 }")
5965
5966 (define_insn "one_cmpldi2"
5967   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5968         (not:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
5969   "TARGET_POWERPC64"
5970   "nor %0,%1,%1")
5971
5972 (define_insn ""
5973   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
5974         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
5975                     (const_int 0)))
5976    (clobber (match_scratch:DI 2 "=r,r"))]
5977   "TARGET_64BIT"
5978   "@
5979    nor. %2,%1,%1
5980    #"
5981   [(set_attr "type" "compare")
5982    (set_attr "length" "4,8")])
5983
5984 (define_split
5985   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
5986         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
5987                     (const_int 0)))
5988    (clobber (match_scratch:DI 2 ""))]
5989   "TARGET_POWERPC64 && reload_completed"
5990   [(set (match_dup 2)
5991         (not:DI (match_dup 1)))
5992    (set (match_dup 0)
5993         (compare:CC (match_dup 2)
5994                     (const_int 0)))]
5995   "")
5996
5997 (define_insn ""
5998   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
5999         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
6000                     (const_int 0)))
6001    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6002         (not:DI (match_dup 1)))]
6003   "TARGET_64BIT"
6004   "@
6005    nor. %0,%1,%1
6006    #"
6007   [(set_attr "type" "compare")
6008    (set_attr "length" "4,8")])
6009
6010 (define_split
6011   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
6012         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
6013                     (const_int 0)))
6014    (set (match_operand:DI 0 "gpc_reg_operand" "")
6015         (not:DI (match_dup 1)))]
6016   "TARGET_POWERPC64 && reload_completed"
6017   [(set (match_dup 0)
6018         (not:DI (match_dup 1)))
6019    (set (match_dup 2)
6020         (compare:CC (match_dup 0)
6021                     (const_int 0)))]
6022   "")
6023
6024 (define_insn ""
6025   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6026         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I")
6027                   (match_operand:DI 2 "gpc_reg_operand" "r,r")))]
6028   "TARGET_POWERPC64"
6029   "@
6030    subf %0,%2,%1
6031    subfic %0,%2,%1")
6032
6033 (define_insn ""
6034   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6035         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6036                               (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6037                     (const_int 0)))
6038    (clobber (match_scratch:DI 3 "=r,r"))]
6039   "TARGET_64BIT"
6040   "@
6041    subf. %3,%2,%1
6042    #"
6043   [(set_attr "type" "fast_compare")
6044    (set_attr "length" "4,8")])
6045
6046 (define_split
6047   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6048         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "")
6049                               (match_operand:DI 2 "gpc_reg_operand" ""))
6050                     (const_int 0)))
6051    (clobber (match_scratch:DI 3 ""))]
6052   "TARGET_POWERPC64 && reload_completed"
6053   [(set (match_dup 3)
6054         (minus:DI (match_dup 1) (match_dup 2)))
6055    (set (match_dup 0)
6056         (compare:CC (match_dup 3)
6057                     (const_int 0)))]
6058   "")
6059
6060 (define_insn ""
6061   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6062         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6063                               (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6064                     (const_int 0)))
6065    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6066         (minus:DI (match_dup 1) (match_dup 2)))]
6067   "TARGET_64BIT"
6068   "@
6069    subf. %0,%2,%1
6070    #"
6071   [(set_attr "type" "fast_compare")
6072    (set_attr "length" "4,8")])
6073
6074 (define_split
6075   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6076         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "")
6077                               (match_operand:DI 2 "gpc_reg_operand" ""))
6078                     (const_int 0)))
6079    (set (match_operand:DI 0 "gpc_reg_operand" "")
6080         (minus:DI (match_dup 1) (match_dup 2)))]
6081   "TARGET_POWERPC64 && reload_completed"
6082   [(set (match_dup 0)
6083         (minus:DI (match_dup 1) (match_dup 2)))
6084    (set (match_dup 3)
6085         (compare:CC (match_dup 0)
6086                     (const_int 0)))]
6087   "")
6088
6089 (define_expand "subdi3"
6090   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6091         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "")
6092                   (match_operand:DI 2 "reg_or_sub_cint64_operand" "")))]
6093   ""
6094   "
6095 {
6096   if (GET_CODE (operands[2]) == CONST_INT)
6097     {
6098       emit_insn (gen_adddi3 (operands[0], operands[1],
6099                              negate_rtx (DImode, operands[2])));
6100       DONE;
6101     }
6102 }")
6103
6104 (define_insn_and_split "absdi2"
6105   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6106         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
6107    (clobber (match_scratch:DI 2 "=&r,&r"))]
6108   "TARGET_POWERPC64"
6109   "#"
6110   "&& reload_completed"
6111   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
6112    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
6113    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
6114   "")
6115
6116 (define_insn_and_split "*nabsdi2"
6117   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6118         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
6119    (clobber (match_scratch:DI 2 "=&r,&r"))]
6120   "TARGET_POWERPC64"
6121   "#"
6122   "&& reload_completed"
6123   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
6124    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
6125    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
6126   "")
6127
6128 (define_expand "negdi2"
6129   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6130         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "")))]
6131   ""
6132   "")
6133
6134 (define_insn ""
6135   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6136         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
6137   "TARGET_POWERPC64"
6138   "neg %0,%1")
6139
6140 (define_insn ""
6141   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6142         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
6143                     (const_int 0)))
6144    (clobber (match_scratch:DI 2 "=r,r"))]
6145   "TARGET_64BIT"
6146   "@
6147    neg. %2,%1
6148    #"
6149   [(set_attr "type" "fast_compare")
6150    (set_attr "length" "4,8")])
6151
6152 (define_split
6153   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6154         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" ""))
6155                     (const_int 0)))
6156    (clobber (match_scratch:DI 2 ""))]
6157   "TARGET_POWERPC64 && reload_completed"
6158   [(set (match_dup 2)
6159         (neg:DI (match_dup 1)))
6160    (set (match_dup 0)
6161         (compare:CC (match_dup 2)
6162                     (const_int 0)))]
6163   "")
6164
6165 (define_insn ""
6166   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
6167         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
6168                     (const_int 0)))
6169    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6170         (neg:DI (match_dup 1)))]
6171   "TARGET_64BIT"
6172   "@
6173    neg. %0,%1
6174    #"
6175   [(set_attr "type" "fast_compare")
6176    (set_attr "length" "4,8")])
6177
6178 (define_split
6179   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
6180         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" ""))
6181                     (const_int 0)))
6182    (set (match_operand:DI 0 "gpc_reg_operand" "")
6183         (neg:DI (match_dup 1)))]
6184   "TARGET_POWERPC64 && reload_completed"
6185   [(set (match_dup 0)
6186         (neg:DI (match_dup 1)))
6187    (set (match_dup 2)
6188         (compare:CC (match_dup 0)
6189                     (const_int 0)))]
6190   "")
6191
6192 (define_insn "clzdi2"
6193   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6194         (clz:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
6195   "TARGET_POWERPC64"
6196   "cntlzd %0,%1")
6197
6198 (define_expand "ctzdi2"
6199   [(set (match_dup 2)
6200         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
6201    (parallel [(set (match_dup 3) (and:DI (match_dup 1)
6202                                          (match_dup 2)))
6203               (clobber (scratch:CC))])
6204    (set (match_dup 4) (clz:DI (match_dup 3)))
6205    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
6206         (minus:DI (const_int 63) (match_dup 4)))]
6207   "TARGET_POWERPC64"
6208   {
6209      operands[2] = gen_reg_rtx (DImode);
6210      operands[3] = gen_reg_rtx (DImode);
6211      operands[4] = gen_reg_rtx (DImode);
6212   })
6213
6214 (define_expand "ffsdi2"
6215   [(set (match_dup 2)
6216         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
6217    (parallel [(set (match_dup 3) (and:DI (match_dup 1)
6218                                          (match_dup 2)))
6219               (clobber (scratch:CC))])
6220    (set (match_dup 4) (clz:DI (match_dup 3)))
6221    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
6222         (minus:DI (const_int 64) (match_dup 4)))]
6223   "TARGET_POWERPC64"
6224   {
6225      operands[2] = gen_reg_rtx (DImode);
6226      operands[3] = gen_reg_rtx (DImode);
6227      operands[4] = gen_reg_rtx (DImode);
6228   })
6229
6230 (define_insn "muldi3"
6231   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6232         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
6233                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6234   "TARGET_POWERPC64"
6235   "mulld %0,%1,%2"
6236    [(set_attr "type" "lmul")])
6237
6238 (define_insn "*muldi3_internal1"
6239   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6240         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6241                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6242                     (const_int 0)))
6243    (clobber (match_scratch:DI 3 "=r,r"))]
6244   "TARGET_POWERPC64"
6245   "@
6246    mulld. %3,%1,%2
6247    #"
6248   [(set_attr "type" "lmul_compare")
6249    (set_attr "length" "4,8")])
6250
6251 (define_split
6252   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6253         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6254                              (match_operand:DI 2 "gpc_reg_operand" ""))
6255                     (const_int 0)))
6256    (clobber (match_scratch:DI 3 ""))]
6257   "TARGET_POWERPC64 && reload_completed"
6258   [(set (match_dup 3)
6259         (mult:DI (match_dup 1) (match_dup 2)))
6260    (set (match_dup 0)
6261         (compare:CC (match_dup 3)
6262                     (const_int 0)))]
6263   "")
6264
6265 (define_insn "*muldi3_internal2"
6266   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6267         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
6268                              (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6269                     (const_int 0)))
6270    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6271         (mult:DI (match_dup 1) (match_dup 2)))]
6272   "TARGET_POWERPC64"
6273   "@
6274    mulld. %0,%1,%2
6275    #"
6276   [(set_attr "type" "lmul_compare")
6277    (set_attr "length" "4,8")])
6278
6279 (define_split
6280   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6281         (compare:CC (mult:DI (match_operand:DI 1 "gpc_reg_operand" "")
6282                              (match_operand:DI 2 "gpc_reg_operand" ""))
6283                     (const_int 0)))
6284    (set (match_operand:DI 0 "gpc_reg_operand" "")
6285         (mult:DI (match_dup 1) (match_dup 2)))]
6286   "TARGET_POWERPC64 && reload_completed"
6287   [(set (match_dup 0)
6288         (mult:DI (match_dup 1) (match_dup 2)))
6289    (set (match_dup 3)
6290         (compare:CC (match_dup 0)
6291                     (const_int 0)))]
6292   "")
6293
6294 (define_insn "smuldi3_highpart"
6295   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6296         (truncate:DI
6297          (lshiftrt:TI (mult:TI (sign_extend:TI
6298                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6299                                (sign_extend:TI
6300                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6301                       (const_int 64))))]
6302   "TARGET_POWERPC64"
6303   "mulhd %0,%1,%2"
6304   [(set_attr "type" "lmul")])
6305
6306 (define_insn "umuldi3_highpart"
6307   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6308         (truncate:DI
6309          (lshiftrt:TI (mult:TI (zero_extend:TI
6310                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6311                                (zero_extend:TI
6312                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6313                       (const_int 64))))]
6314   "TARGET_POWERPC64"
6315   "mulhdu %0,%1,%2"
6316   [(set_attr "type" "lmul")])
6317
6318 (define_expand "divdi3"
6319   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6320         (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6321                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
6322   "TARGET_POWERPC64"
6323   "
6324 {
6325   if (GET_CODE (operands[2]) == CONST_INT
6326       && INTVAL (operands[2]) > 0
6327       && exact_log2 (INTVAL (operands[2])) >= 0)
6328     ;
6329   else
6330     operands[2] = force_reg (DImode, operands[2]);
6331 }")
6332
6333 (define_expand "moddi3"
6334   [(use (match_operand:DI 0 "gpc_reg_operand" ""))
6335    (use (match_operand:DI 1 "gpc_reg_operand" ""))
6336    (use (match_operand:DI 2 "reg_or_cint_operand" ""))]
6337   "TARGET_POWERPC64"
6338   "
6339 {
6340   int i;
6341   rtx temp1;
6342   rtx temp2;
6343
6344   if (GET_CODE (operands[2]) != CONST_INT
6345       || INTVAL (operands[2]) <= 0
6346       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
6347     FAIL;
6348
6349   temp1 = gen_reg_rtx (DImode);
6350   temp2 = gen_reg_rtx (DImode);
6351
6352   emit_insn (gen_divdi3 (temp1, operands[1], operands[2]));
6353   emit_insn (gen_ashldi3 (temp2, temp1, GEN_INT (i)));
6354   emit_insn (gen_subdi3 (operands[0], operands[1], temp2));
6355   DONE;
6356 }")
6357
6358 (define_insn ""
6359   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6360         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6361                 (match_operand:DI 2 "exact_log2_cint_operand" "N")))]
6362   "TARGET_POWERPC64"
6363   "sradi %0,%1,%p2\;addze %0,%0"
6364   [(set_attr "type" "two")
6365    (set_attr "length" "8")])
6366
6367 (define_insn ""
6368   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6369         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6370                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6371                     (const_int 0)))
6372    (clobber (match_scratch:DI 3 "=r,r"))]
6373   "TARGET_64BIT"
6374   "@
6375    sradi %3,%1,%p2\;addze. %3,%3
6376    #"
6377   [(set_attr "type" "compare")
6378    (set_attr "length" "8,12")])
6379
6380 (define_split
6381   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6382         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6383                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6384                     (const_int 0)))
6385    (clobber (match_scratch:DI 3 ""))]
6386   "TARGET_POWERPC64 && reload_completed"
6387   [(set (match_dup 3)
6388         (div: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 ""
6395   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6396         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6397                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6398                     (const_int 0)))
6399    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6400         (div:DI (match_dup 1) (match_dup 2)))]
6401   "TARGET_64BIT"
6402   "@
6403    sradi %0,%1,%p2\;addze. %0,%0
6404    #"
6405   [(set_attr "type" "compare")
6406    (set_attr "length" "8,12")])
6407
6408 (define_split
6409   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6410         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6411                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6412                     (const_int 0)))
6413    (set (match_operand:DI 0 "gpc_reg_operand" "")
6414         (div:DI (match_dup 1) (match_dup 2)))]
6415   "TARGET_POWERPC64 && reload_completed"
6416   [(set (match_dup 0)
6417         (div: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 ""
6424   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6425         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6426                 (match_operand:DI 2 "gpc_reg_operand" "r")))]
6427   "TARGET_POWERPC64"
6428   "divd %0,%1,%2"
6429   [(set_attr "type" "ldiv")])
6430
6431 (define_insn "udivdi3"
6432   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6433         (udiv:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6434                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6435   "TARGET_POWERPC64"
6436   "divdu %0,%1,%2"
6437   [(set_attr "type" "ldiv")])
6438
6439 (define_insn "rotldi3"
6440   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6441         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6442                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
6443   "TARGET_POWERPC64"
6444   "rld%I2cl %0,%1,%H2,0")
6445
6446 (define_insn "*rotldi3_internal2"
6447   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6448         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6449                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6450                     (const_int 0)))
6451    (clobber (match_scratch:DI 3 "=r,r"))]
6452   "TARGET_64BIT"
6453   "@
6454    rld%I2cl. %3,%1,%H2,0
6455    #"
6456   [(set_attr "type" "delayed_compare")
6457    (set_attr "length" "4,8")])
6458
6459 (define_split
6460   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6461         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6462                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6463                     (const_int 0)))
6464    (clobber (match_scratch:DI 3 ""))]
6465   "TARGET_POWERPC64 && reload_completed"
6466   [(set (match_dup 3)
6467         (rotate:DI (match_dup 1) (match_dup 2)))
6468    (set (match_dup 0)
6469         (compare:CC (match_dup 3)
6470                     (const_int 0)))]
6471   "")
6472
6473 (define_insn "*rotldi3_internal3"
6474   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6475         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6476                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6477                     (const_int 0)))
6478    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6479         (rotate:DI (match_dup 1) (match_dup 2)))]
6480   "TARGET_64BIT"
6481   "@
6482    rld%I2cl. %0,%1,%H2,0
6483    #"
6484   [(set_attr "type" "delayed_compare")
6485    (set_attr "length" "4,8")])
6486
6487 (define_split
6488   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6489         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6490                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6491                     (const_int 0)))
6492    (set (match_operand:DI 0 "gpc_reg_operand" "")
6493         (rotate:DI (match_dup 1) (match_dup 2)))]
6494   "TARGET_POWERPC64 && reload_completed"
6495   [(set (match_dup 0)
6496         (rotate:DI (match_dup 1) (match_dup 2)))
6497    (set (match_dup 3)
6498         (compare:CC (match_dup 0)
6499                     (const_int 0)))]
6500   "")
6501
6502 (define_insn "*rotldi3_internal4"
6503   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6504         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6505                            (match_operand:DI 2 "reg_or_cint_operand" "ri"))
6506                 (match_operand:DI 3 "mask64_operand" "n")))]
6507   "TARGET_POWERPC64"
6508   "rld%I2c%B3 %0,%1,%H2,%S3")
6509
6510 (define_insn "*rotldi3_internal5"
6511   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6512         (compare:CC (and:DI
6513                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6514                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6515                      (match_operand:DI 3 "mask64_operand" "n,n"))
6516                     (const_int 0)))
6517    (clobber (match_scratch:DI 4 "=r,r"))]
6518   "TARGET_64BIT"
6519   "@
6520    rld%I2c%B3. %4,%1,%H2,%S3
6521    #"
6522   [(set_attr "type" "delayed_compare")
6523    (set_attr "length" "4,8")])
6524
6525 (define_split
6526   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6527         (compare:CC (and:DI
6528                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6529                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6530                      (match_operand:DI 3 "mask64_operand" ""))
6531                     (const_int 0)))
6532    (clobber (match_scratch:DI 4 ""))]
6533   "TARGET_POWERPC64 && reload_completed"
6534   [(set (match_dup 4)
6535         (and:DI (rotate:DI (match_dup 1)
6536                                 (match_dup 2))
6537                      (match_dup 3)))
6538    (set (match_dup 0)
6539         (compare:CC (match_dup 4)
6540                     (const_int 0)))]
6541   "")
6542
6543 (define_insn "*rotldi3_internal6"
6544   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6545         (compare:CC (and:DI
6546                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6547                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6548                      (match_operand:DI 3 "mask64_operand" "n,n"))
6549                     (const_int 0)))
6550    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6551         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6552   "TARGET_64BIT"
6553   "@
6554    rld%I2c%B3. %0,%1,%H2,%S3
6555    #"
6556   [(set_attr "type" "delayed_compare")
6557    (set_attr "length" "4,8")])
6558
6559 (define_split
6560   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6561         (compare:CC (and:DI
6562                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6563                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6564                      (match_operand:DI 3 "mask64_operand" ""))
6565                     (const_int 0)))
6566    (set (match_operand:DI 0 "gpc_reg_operand" "")
6567         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6568   "TARGET_POWERPC64 && reload_completed"
6569   [(set (match_dup 0)
6570         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6571    (set (match_dup 4)
6572         (compare:CC (match_dup 0)
6573                     (const_int 0)))]
6574   "")
6575
6576 (define_insn "*rotldi3_internal7"
6577   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6578         (zero_extend:DI
6579          (subreg:QI
6580           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6581                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6582   "TARGET_POWERPC64"
6583   "rld%I2cl %0,%1,%H2,56")
6584
6585 (define_insn "*rotldi3_internal8"
6586   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6587         (compare:CC (zero_extend:DI
6588                      (subreg:QI
6589                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6590                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6591                     (const_int 0)))
6592    (clobber (match_scratch:DI 3 "=r,r"))]
6593   "TARGET_64BIT"
6594   "@
6595    rld%I2cl. %3,%1,%H2,56
6596    #"
6597   [(set_attr "type" "delayed_compare")
6598    (set_attr "length" "4,8")])
6599
6600 (define_split
6601   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6602         (compare:CC (zero_extend:DI
6603                      (subreg:QI
6604                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6605                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6606                     (const_int 0)))
6607    (clobber (match_scratch:DI 3 ""))]
6608   "TARGET_POWERPC64 && reload_completed"
6609   [(set (match_dup 3)
6610         (zero_extend:DI (subreg:QI
6611                       (rotate:DI (match_dup 1)
6612                                  (match_dup 2)) 0)))
6613    (set (match_dup 0)
6614         (compare:CC (match_dup 3)
6615                     (const_int 0)))]
6616   "")
6617
6618 (define_insn "*rotldi3_internal9"
6619   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6620         (compare:CC (zero_extend:DI
6621                      (subreg:QI
6622                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6623                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6624                     (const_int 0)))
6625    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6626         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6627   "TARGET_64BIT"
6628   "@
6629    rld%I2cl. %0,%1,%H2,56
6630    #"
6631   [(set_attr "type" "delayed_compare")
6632    (set_attr "length" "4,8")])
6633
6634 (define_split
6635   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6636         (compare:CC (zero_extend:DI
6637                      (subreg:QI
6638                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6639                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6640                     (const_int 0)))
6641    (set (match_operand:DI 0 "gpc_reg_operand" "")
6642         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6643   "TARGET_POWERPC64 && reload_completed"
6644   [(set (match_dup 0)
6645         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6646    (set (match_dup 3)
6647         (compare:CC (match_dup 0)
6648                     (const_int 0)))]
6649   "")
6650
6651 (define_insn "*rotldi3_internal10"
6652   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6653         (zero_extend:DI
6654          (subreg:HI
6655           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6656                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6657   "TARGET_POWERPC64"
6658   "rld%I2cl %0,%1,%H2,48")
6659
6660 (define_insn "*rotldi3_internal11"
6661   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6662         (compare:CC (zero_extend:DI
6663                      (subreg:HI
6664                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6665                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6666                     (const_int 0)))
6667    (clobber (match_scratch:DI 3 "=r,r"))]
6668   "TARGET_64BIT"
6669   "@
6670    rld%I2cl. %3,%1,%H2,48
6671    #"
6672   [(set_attr "type" "delayed_compare")
6673    (set_attr "length" "4,8")])
6674
6675 (define_split
6676   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6677         (compare:CC (zero_extend:DI
6678                      (subreg:HI
6679                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6680                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6681                     (const_int 0)))
6682    (clobber (match_scratch:DI 3 ""))]
6683   "TARGET_POWERPC64 && reload_completed"
6684   [(set (match_dup 3)
6685         (zero_extend:DI (subreg:HI
6686                       (rotate:DI (match_dup 1)
6687                                  (match_dup 2)) 0)))
6688    (set (match_dup 0)
6689         (compare:CC (match_dup 3)
6690                     (const_int 0)))]
6691   "")
6692
6693 (define_insn "*rotldi3_internal12"
6694   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6695         (compare:CC (zero_extend:DI
6696                      (subreg:HI
6697                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6698                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6699                     (const_int 0)))
6700    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6701         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6702   "TARGET_64BIT"
6703   "@
6704    rld%I2cl. %0,%1,%H2,48
6705    #"
6706   [(set_attr "type" "delayed_compare")
6707    (set_attr "length" "4,8")])
6708
6709 (define_split
6710   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6711         (compare:CC (zero_extend:DI
6712                      (subreg:HI
6713                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6714                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6715                     (const_int 0)))
6716    (set (match_operand:DI 0 "gpc_reg_operand" "")
6717         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6718   "TARGET_POWERPC64 && reload_completed"
6719   [(set (match_dup 0)
6720         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6721    (set (match_dup 3)
6722         (compare:CC (match_dup 0)
6723                     (const_int 0)))]
6724   "")
6725
6726 (define_insn "*rotldi3_internal13"
6727   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6728         (zero_extend:DI
6729          (subreg:SI
6730           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6731                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6732   "TARGET_POWERPC64"
6733   "rld%I2cl %0,%1,%H2,32")
6734
6735 (define_insn "*rotldi3_internal14"
6736   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6737         (compare:CC (zero_extend:DI
6738                      (subreg:SI
6739                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6740                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6741                     (const_int 0)))
6742    (clobber (match_scratch:DI 3 "=r,r"))]
6743   "TARGET_64BIT"
6744   "@
6745    rld%I2cl. %3,%1,%H2,32
6746    #"
6747   [(set_attr "type" "delayed_compare")
6748    (set_attr "length" "4,8")])
6749
6750 (define_split
6751   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6752         (compare:CC (zero_extend:DI
6753                      (subreg:SI
6754                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6755                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6756                     (const_int 0)))
6757    (clobber (match_scratch:DI 3 ""))]
6758   "TARGET_POWERPC64 && reload_completed"
6759   [(set (match_dup 3)
6760         (zero_extend:DI (subreg:SI
6761                       (rotate:DI (match_dup 1)
6762                                  (match_dup 2)) 0)))
6763    (set (match_dup 0)
6764         (compare:CC (match_dup 3)
6765                     (const_int 0)))]
6766   "")
6767
6768 (define_insn "*rotldi3_internal15"
6769   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6770         (compare:CC (zero_extend:DI
6771                      (subreg:SI
6772                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6773                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6774                     (const_int 0)))
6775    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6776         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6777   "TARGET_64BIT"
6778   "@
6779    rld%I2cl. %0,%1,%H2,32
6780    #"
6781   [(set_attr "type" "delayed_compare")
6782    (set_attr "length" "4,8")])
6783
6784 (define_split
6785   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6786         (compare:CC (zero_extend:DI
6787                      (subreg:SI
6788                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6789                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6790                     (const_int 0)))
6791    (set (match_operand:DI 0 "gpc_reg_operand" "")
6792         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6793   "TARGET_POWERPC64 && reload_completed"
6794   [(set (match_dup 0)
6795         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6796    (set (match_dup 3)
6797         (compare:CC (match_dup 0)
6798                     (const_int 0)))]
6799   "")
6800
6801 (define_expand "ashldi3"
6802   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6803         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6804                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
6805   "TARGET_POWERPC64 || TARGET_POWER"
6806   "
6807 {
6808   if (TARGET_POWERPC64)
6809     ;
6810   else if (TARGET_POWER)
6811     {
6812       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
6813       DONE;
6814     }
6815   else
6816     FAIL;
6817 }")
6818
6819 (define_insn "*ashldi3_internal1"
6820   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6821         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6822                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
6823   "TARGET_POWERPC64"
6824   "sld%I2 %0,%1,%H2")
6825
6826 (define_insn "*ashldi3_internal2"
6827   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6828         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6829                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6830                     (const_int 0)))
6831    (clobber (match_scratch:DI 3 "=r,r"))]
6832   "TARGET_64BIT"
6833   "@
6834    sld%I2. %3,%1,%H2
6835    #"
6836   [(set_attr "type" "delayed_compare")
6837    (set_attr "length" "4,8")])
6838
6839 (define_split
6840   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6841         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6842                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6843                     (const_int 0)))
6844    (clobber (match_scratch:DI 3 ""))]
6845   "TARGET_POWERPC64 && reload_completed"
6846   [(set (match_dup 3)
6847         (ashift:DI (match_dup 1) (match_dup 2)))
6848    (set (match_dup 0)
6849         (compare:CC (match_dup 3)
6850                     (const_int 0)))]
6851   "")
6852
6853 (define_insn "*ashldi3_internal3"
6854   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6855         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6856                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
6857                     (const_int 0)))
6858    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6859         (ashift:DI (match_dup 1) (match_dup 2)))]
6860   "TARGET_64BIT"
6861   "@
6862    sld%I2. %0,%1,%H2
6863    #"
6864   [(set_attr "type" "delayed_compare")
6865    (set_attr "length" "4,8")])
6866
6867 (define_split
6868   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6869         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6870                                (match_operand:SI 2 "reg_or_cint_operand" ""))
6871                     (const_int 0)))
6872    (set (match_operand:DI 0 "gpc_reg_operand" "")
6873         (ashift:DI (match_dup 1) (match_dup 2)))]
6874   "TARGET_POWERPC64 && reload_completed"
6875   [(set (match_dup 0)
6876         (ashift:DI (match_dup 1) (match_dup 2)))
6877    (set (match_dup 3)
6878         (compare:CC (match_dup 0)
6879                     (const_int 0)))]
6880   "")
6881
6882 (define_insn "*ashldi3_internal4"
6883   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6884         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6885                            (match_operand:SI 2 "const_int_operand" "i"))
6886                 (match_operand:DI 3 "const_int_operand" "n")))]
6887   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
6888   "rldic %0,%1,%H2,%W3")
6889
6890 (define_insn "ashldi3_internal5"
6891   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6892         (compare:CC
6893          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6894                             (match_operand:SI 2 "const_int_operand" "i,i"))
6895                  (match_operand:DI 3 "const_int_operand" "n,n"))
6896          (const_int 0)))
6897    (clobber (match_scratch:DI 4 "=r,r"))]
6898   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6899   "@
6900    rldic. %4,%1,%H2,%W3
6901    #"
6902   [(set_attr "type" "delayed_compare")
6903    (set_attr "length" "4,8")])
6904
6905 (define_split
6906   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6907         (compare:CC
6908          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6909                             (match_operand:SI 2 "const_int_operand" ""))
6910                  (match_operand:DI 3 "const_int_operand" ""))
6911          (const_int 0)))
6912    (clobber (match_scratch:DI 4 ""))]
6913   "TARGET_POWERPC64 && reload_completed
6914    && includes_rldic_lshift_p (operands[2], operands[3])"
6915   [(set (match_dup 4)
6916         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6917                 (match_dup 3)))
6918    (set (match_dup 0)
6919         (compare:CC (match_dup 4)
6920                     (const_int 0)))]
6921   "")
6922
6923 (define_insn "*ashldi3_internal6"
6924   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6925         (compare:CC
6926          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6927                             (match_operand:SI 2 "const_int_operand" "i,i"))
6928                     (match_operand:DI 3 "const_int_operand" "n,n"))
6929          (const_int 0)))
6930    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6931         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6932   "TARGET_64BIT && includes_rldic_lshift_p (operands[2], operands[3])"
6933   "@
6934    rldic. %0,%1,%H2,%W3
6935    #"
6936   [(set_attr "type" "delayed_compare")
6937    (set_attr "length" "4,8")])
6938
6939 (define_split
6940   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6941         (compare:CC
6942          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6943                             (match_operand:SI 2 "const_int_operand" ""))
6944                  (match_operand:DI 3 "const_int_operand" ""))
6945          (const_int 0)))
6946    (set (match_operand:DI 0 "gpc_reg_operand" "")
6947         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6948   "TARGET_POWERPC64 && reload_completed
6949    && includes_rldic_lshift_p (operands[2], operands[3])"
6950   [(set (match_dup 0)
6951         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6952                 (match_dup 3)))
6953    (set (match_dup 4)
6954         (compare:CC (match_dup 0)
6955                     (const_int 0)))]
6956   "")
6957
6958 (define_insn "*ashldi3_internal7"
6959   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6960         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6961                            (match_operand:SI 2 "const_int_operand" "i"))
6962                 (match_operand:DI 3 "mask64_operand" "n")))]
6963   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
6964   "rldicr %0,%1,%H2,%S3")
6965
6966 (define_insn "ashldi3_internal8"
6967   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6968         (compare:CC
6969          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6970                             (match_operand:SI 2 "const_int_operand" "i,i"))
6971                  (match_operand:DI 3 "mask64_operand" "n,n"))
6972          (const_int 0)))
6973    (clobber (match_scratch:DI 4 "=r,r"))]
6974   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
6975   "@
6976    rldicr. %4,%1,%H2,%S3
6977    #"
6978   [(set_attr "type" "delayed_compare")
6979    (set_attr "length" "4,8")])
6980
6981 (define_split
6982   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6983         (compare:CC
6984          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
6985                             (match_operand:SI 2 "const_int_operand" ""))
6986                  (match_operand:DI 3 "mask64_operand" ""))
6987          (const_int 0)))
6988    (clobber (match_scratch:DI 4 ""))]
6989   "TARGET_POWERPC64 && reload_completed
6990    && includes_rldicr_lshift_p (operands[2], operands[3])"
6991   [(set (match_dup 4)
6992         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
6993                 (match_dup 3)))
6994    (set (match_dup 0)
6995         (compare:CC (match_dup 4)
6996                     (const_int 0)))]
6997   "")
6998
6999 (define_insn "*ashldi3_internal9"
7000   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7001         (compare:CC
7002          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7003                             (match_operand:SI 2 "const_int_operand" "i,i"))
7004                     (match_operand:DI 3 "mask64_operand" "n,n"))
7005          (const_int 0)))
7006    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7007         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7008   "TARGET_64BIT && includes_rldicr_lshift_p (operands[2], operands[3])"
7009   "@
7010    rldicr. %0,%1,%H2,%S3
7011    #"
7012   [(set_attr "type" "delayed_compare")
7013    (set_attr "length" "4,8")])
7014
7015 (define_split
7016   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
7017         (compare:CC
7018          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7019                             (match_operand:SI 2 "const_int_operand" ""))
7020                  (match_operand:DI 3 "mask64_operand" ""))
7021          (const_int 0)))
7022    (set (match_operand:DI 0 "gpc_reg_operand" "")
7023         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7024   "TARGET_POWERPC64 && reload_completed
7025    && includes_rldicr_lshift_p (operands[2], operands[3])"
7026   [(set (match_dup 0)
7027         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7028                 (match_dup 3)))
7029    (set (match_dup 4)
7030         (compare:CC (match_dup 0)
7031                     (const_int 0)))]
7032   "")
7033
7034 (define_expand "lshrdi3"
7035   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7036         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7037                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7038   "TARGET_POWERPC64 || TARGET_POWER"
7039   "
7040 {
7041   if (TARGET_POWERPC64)
7042     ;
7043   else if (TARGET_POWER)
7044     {
7045       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
7046       DONE;
7047     }
7048   else
7049     FAIL;
7050 }")
7051
7052 (define_insn "*lshrdi3_internal1"
7053   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7054         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7055                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
7056   "TARGET_POWERPC64"
7057   "srd%I2 %0,%1,%H2")
7058
7059 (define_insn "*lshrdi3_internal2"
7060   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7061         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7062                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7063                     (const_int 0)))
7064    (clobber (match_scratch:DI 3 "=r,r"))]
7065   "TARGET_64BIT "
7066   "@
7067    srd%I2. %3,%1,%H2
7068    #"
7069   [(set_attr "type" "delayed_compare")
7070    (set_attr "length" "4,8")])
7071
7072 (define_split
7073   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7074         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7075                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7076                     (const_int 0)))
7077    (clobber (match_scratch:DI 3 ""))]
7078   "TARGET_POWERPC64 && reload_completed"
7079   [(set (match_dup 3)
7080         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7081    (set (match_dup 0)
7082         (compare:CC (match_dup 3)
7083                     (const_int 0)))]
7084   "")
7085
7086 (define_insn "*lshrdi3_internal3"
7087   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7088         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7089                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7090                     (const_int 0)))
7091    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7092         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7093   "TARGET_64BIT"
7094   "@
7095    srd%I2. %0,%1,%H2
7096    #"
7097   [(set_attr "type" "delayed_compare")
7098    (set_attr "length" "4,8")])
7099
7100 (define_split
7101   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7102         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7103                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7104                     (const_int 0)))
7105    (set (match_operand:DI 0 "gpc_reg_operand" "")
7106         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7107   "TARGET_POWERPC64 && reload_completed"
7108   [(set (match_dup 0)
7109         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7110    (set (match_dup 3)
7111         (compare:CC (match_dup 0)
7112                     (const_int 0)))]
7113   "")
7114
7115 (define_expand "ashrdi3"
7116   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7117         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7118                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7119   "WORDS_BIG_ENDIAN"
7120   "
7121 {
7122   if (TARGET_POWERPC64)
7123     ;
7124   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
7125     {
7126       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
7127       DONE;
7128     }
7129   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT
7130            && WORDS_BIG_ENDIAN)
7131     {
7132       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
7133       DONE;
7134     }
7135   else
7136     FAIL;
7137 }")
7138
7139 (define_insn "*ashrdi3_internal1"
7140   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7141         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7142                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
7143   "TARGET_POWERPC64"
7144   "srad%I2 %0,%1,%H2")
7145
7146 (define_insn "*ashrdi3_internal2"
7147   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7148         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7149                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7150                     (const_int 0)))
7151    (clobber (match_scratch:DI 3 "=r,r"))]
7152   "TARGET_64BIT"
7153   "@
7154    srad%I2. %3,%1,%H2
7155    #"
7156   [(set_attr "type" "delayed_compare")
7157    (set_attr "length" "4,8")])
7158
7159 (define_split
7160   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7161         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7162                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7163                     (const_int 0)))
7164    (clobber (match_scratch:DI 3 ""))]
7165   "TARGET_POWERPC64 && reload_completed"
7166   [(set (match_dup 3)
7167         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7168    (set (match_dup 0)
7169         (compare:CC (match_dup 3)
7170                     (const_int 0)))]
7171   "")
7172
7173 (define_insn "*ashrdi3_internal3"
7174   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7175         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7176                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7177                     (const_int 0)))
7178    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7179         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7180   "TARGET_64BIT"
7181   "@
7182    srad%I2. %0,%1,%H2
7183    #"
7184   [(set_attr "type" "delayed_compare")
7185    (set_attr "length" "4,8")])
7186
7187 (define_split
7188   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7189         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7190                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7191                     (const_int 0)))
7192    (set (match_operand:DI 0 "gpc_reg_operand" "")
7193         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7194   "TARGET_POWERPC64 && reload_completed"
7195   [(set (match_dup 0)
7196         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7197    (set (match_dup 3)
7198         (compare:CC (match_dup 0)
7199                     (const_int 0)))]
7200   "")
7201
7202 (define_insn "anddi3"
7203   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
7204         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r")
7205                 (match_operand:DI 2 "and64_2_operand" "?r,S,T,K,J,t")))
7206    (clobber (match_scratch:CC 3 "=X,X,X,x,x,X"))]
7207   "TARGET_POWERPC64"
7208   "@
7209    and %0,%1,%2
7210    rldic%B2 %0,%1,0,%S2
7211    rlwinm %0,%1,0,%m2,%M2
7212    andi. %0,%1,%b2
7213    andis. %0,%1,%u2
7214    #"
7215   [(set_attr "type" "*,*,*,compare,compare,*")
7216    (set_attr "length" "4,4,4,4,4,8")])
7217
7218 (define_split
7219   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7220         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7221                 (match_operand:DI 2 "mask64_2_operand" "")))
7222    (clobber (match_scratch:CC 3 ""))]
7223   "TARGET_POWERPC64
7224     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7225     && !mask64_operand (operands[2], DImode)"
7226   [(set (match_dup 0)
7227         (and:DI (rotate:DI (match_dup 1)
7228                            (match_dup 4))
7229                 (match_dup 5)))
7230    (set (match_dup 0)
7231         (and:DI (rotate:DI (match_dup 0)
7232                            (match_dup 6))
7233                 (match_dup 7)))]
7234 {
7235   build_mask64_2_operands (operands[2], &operands[4]);
7236 })
7237
7238 (define_insn "*anddi3_internal2"
7239   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
7240         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
7241                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
7242                     (const_int 0)))
7243    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r"))
7244    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
7245   "TARGET_64BIT"
7246   "@
7247    and. %3,%1,%2
7248    rldic%B2. %3,%1,0,%S2
7249    andi. %3,%1,%b2
7250    andis. %3,%1,%u2
7251    #
7252    #
7253    #
7254    #
7255    #
7256    #"
7257   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7258    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7259
7260 (define_split
7261   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7262         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7263                             (match_operand:DI 2 "and64_operand" ""))
7264                     (const_int 0)))
7265    (clobber (match_scratch:DI 3 ""))
7266    (clobber (match_scratch:CC 4 ""))]
7267   "TARGET_POWERPC64 && reload_completed"
7268   [(parallel [(set (match_dup 3)
7269                    (and:DI (match_dup 1)
7270                            (match_dup 2)))
7271               (clobber (match_dup 4))])
7272    (set (match_dup 0)
7273         (compare:CC (match_dup 3)
7274                     (const_int 0)))]
7275   "")
7276
7277 (define_split
7278   [(set (match_operand:CC 0 "cc_reg_operand" "")
7279         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7280                             (match_operand:DI 2 "mask64_2_operand" ""))
7281                     (const_int 0)))
7282    (clobber (match_scratch:DI 3 ""))
7283    (clobber (match_scratch:CC 4 ""))]
7284   "TARGET_POWERPC64 && reload_completed
7285     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7286     && !mask64_operand (operands[2], DImode)"
7287   [(set (match_dup 3)
7288         (and:DI (rotate:DI (match_dup 1)
7289                            (match_dup 5))
7290                 (match_dup 6)))
7291    (parallel [(set (match_dup 0)
7292                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7293                                                   (match_dup 7))
7294                                        (match_dup 8))
7295                                (const_int 0)))
7296               (clobber (match_dup 3))])]
7297   "
7298 {
7299   build_mask64_2_operands (operands[2], &operands[5]);
7300 }")
7301
7302 (define_insn "*anddi3_internal3"
7303   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
7304         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
7305                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
7306                     (const_int 0)))
7307    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
7308         (and:DI (match_dup 1) (match_dup 2)))
7309    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
7310   "TARGET_64BIT"
7311   "@
7312    and. %0,%1,%2
7313    rldic%B2. %0,%1,0,%S2
7314    andi. %0,%1,%b2
7315    andis. %0,%1,%u2
7316    #
7317    #
7318    #
7319    #
7320    #
7321    #"
7322   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7323    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7324
7325 (define_split
7326   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7327         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7328                             (match_operand:DI 2 "and64_operand" ""))
7329                     (const_int 0)))
7330    (set (match_operand:DI 0 "gpc_reg_operand" "")
7331         (and:DI (match_dup 1) (match_dup 2)))
7332    (clobber (match_scratch:CC 4 ""))]
7333   "TARGET_POWERPC64 && reload_completed"
7334   [(parallel [(set (match_dup 0)
7335                     (and:DI (match_dup 1) (match_dup 2)))
7336                (clobber (match_dup 4))])
7337    (set (match_dup 3)
7338         (compare:CC (match_dup 0)
7339                     (const_int 0)))]
7340   "")
7341
7342 (define_split
7343   [(set (match_operand:CC 3 "cc_reg_operand" "")
7344         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7345                             (match_operand:DI 2 "mask64_2_operand" ""))
7346                     (const_int 0)))
7347    (set (match_operand:DI 0 "gpc_reg_operand" "")
7348         (and:DI (match_dup 1) (match_dup 2)))
7349    (clobber (match_scratch:CC 4 ""))]
7350   "TARGET_POWERPC64 && reload_completed
7351     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7352     && !mask64_operand (operands[2], DImode)"
7353   [(set (match_dup 0)
7354         (and:DI (rotate:DI (match_dup 1)
7355                            (match_dup 5))
7356                 (match_dup 6)))
7357    (parallel [(set (match_dup 3)
7358                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7359                                                   (match_dup 7))
7360                                        (match_dup 8))
7361                                (const_int 0)))
7362               (set (match_dup 0)
7363                    (and:DI (rotate:DI (match_dup 0)
7364                                       (match_dup 7))
7365                            (match_dup 8)))])]
7366   "
7367 {
7368   build_mask64_2_operands (operands[2], &operands[5]);
7369 }")
7370
7371 (define_expand "iordi3"
7372   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7373         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7374                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7375   "TARGET_POWERPC64"
7376   "
7377 {
7378   if (non_logical_cint_operand (operands[2], DImode))
7379     {
7380       HOST_WIDE_INT value;
7381       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7382                  ? operands[0] : gen_reg_rtx (DImode));
7383
7384       if (GET_CODE (operands[2]) == CONST_INT)
7385         {
7386           value = INTVAL (operands[2]);
7387           emit_insn (gen_iordi3 (tmp, operands[1],
7388                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7389         }
7390       else
7391         {
7392           value = CONST_DOUBLE_LOW (operands[2]);
7393           emit_insn (gen_iordi3 (tmp, operands[1],
7394                                  immed_double_const (value
7395                                                      & (~ (HOST_WIDE_INT) 0xffff),
7396                                                      0, DImode)));
7397         }
7398
7399       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7400       DONE;
7401     }
7402 }")
7403
7404 (define_expand "xordi3"
7405   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7406         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7407                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7408   "TARGET_POWERPC64"
7409   "
7410 {
7411   if (non_logical_cint_operand (operands[2], DImode))
7412     {
7413       HOST_WIDE_INT value;
7414       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7415                  ? operands[0] : gen_reg_rtx (DImode));
7416
7417       if (GET_CODE (operands[2]) == CONST_INT)
7418         {
7419           value = INTVAL (operands[2]);
7420           emit_insn (gen_xordi3 (tmp, operands[1],
7421                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7422         }
7423       else
7424         {
7425           value = CONST_DOUBLE_LOW (operands[2]);
7426           emit_insn (gen_xordi3 (tmp, operands[1],
7427                                  immed_double_const (value
7428                                                      & (~ (HOST_WIDE_INT) 0xffff),
7429                                                      0, DImode)));
7430         }
7431
7432       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7433       DONE;
7434     }
7435 }")
7436
7437 (define_insn "*booldi3_internal1"
7438   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7439         (match_operator:DI 3 "boolean_or_operator"
7440          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7441           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7442   "TARGET_POWERPC64"
7443   "@
7444    %q3 %0,%1,%2
7445    %q3i %0,%1,%b2
7446    %q3is %0,%1,%u2")
7447
7448 (define_insn "*booldi3_internal2"
7449   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7450         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7451          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7452           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7453          (const_int 0)))
7454    (clobber (match_scratch:DI 3 "=r,r"))]
7455   "TARGET_64BIT"
7456   "@
7457    %q4. %3,%1,%2
7458    #"
7459   [(set_attr "type" "compare")
7460    (set_attr "length" "4,8")])
7461
7462 (define_split
7463   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7464         (compare:CC (match_operator:DI 4 "boolean_operator"
7465          [(match_operand:DI 1 "gpc_reg_operand" "")
7466           (match_operand:DI 2 "gpc_reg_operand" "")])
7467          (const_int 0)))
7468    (clobber (match_scratch:DI 3 ""))]
7469   "TARGET_POWERPC64 && reload_completed"
7470   [(set (match_dup 3) (match_dup 4))
7471    (set (match_dup 0)
7472         (compare:CC (match_dup 3)
7473                     (const_int 0)))]
7474   "")
7475
7476 (define_insn "*booldi3_internal3"
7477   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7478         (compare:CC (match_operator:DI 4 "boolean_operator"
7479          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7480           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7481          (const_int 0)))
7482    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7483         (match_dup 4))]
7484   "TARGET_64BIT"
7485   "@
7486    %q4. %0,%1,%2
7487    #"
7488   [(set_attr "type" "compare")
7489    (set_attr "length" "4,8")])
7490
7491 (define_split
7492   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7493         (compare:CC (match_operator:DI 4 "boolean_operator"
7494          [(match_operand:DI 1 "gpc_reg_operand" "")
7495           (match_operand:DI 2 "gpc_reg_operand" "")])
7496          (const_int 0)))
7497    (set (match_operand:DI 0 "gpc_reg_operand" "")
7498         (match_dup 4))]
7499   "TARGET_POWERPC64 && reload_completed"
7500   [(set (match_dup 0) (match_dup 4))
7501    (set (match_dup 3)
7502         (compare:CC (match_dup 0)
7503                     (const_int 0)))]
7504   "")
7505
7506 ;; Split a logical operation that we can't do in one insn into two insns,
7507 ;; each of which does one 16-bit part.  This is used by combine.
7508
7509 (define_split
7510   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7511         (match_operator:DI 3 "boolean_or_operator"
7512          [(match_operand:DI 1 "gpc_reg_operand" "")
7513           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7514   "TARGET_POWERPC64"
7515   [(set (match_dup 0) (match_dup 4))
7516    (set (match_dup 0) (match_dup 5))]
7517 "
7518 {
7519   rtx i3,i4;
7520
7521   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7522     {
7523       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7524       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7525                                         0, DImode);
7526       i4 = GEN_INT (value & 0xffff);
7527     }
7528   else
7529     {
7530       i3 = GEN_INT (INTVAL (operands[2])
7531                              & (~ (HOST_WIDE_INT) 0xffff));
7532       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7533     }
7534   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7535                                 operands[1], i3);
7536   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
7537                                 operands[0], i4);
7538 }")
7539
7540 (define_insn "*boolcdi3_internal1"
7541   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7542         (match_operator:DI 3 "boolean_operator"
7543          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7544           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7545   "TARGET_POWERPC64"
7546   "%q3 %0,%2,%1")
7547
7548 (define_insn "*boolcdi3_internal2"
7549   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7550         (compare:CC (match_operator:DI 4 "boolean_operator"
7551          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7552           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7553          (const_int 0)))
7554    (clobber (match_scratch:DI 3 "=r,r"))]
7555   "TARGET_64BIT"
7556   "@
7557    %q4. %3,%2,%1
7558    #"
7559   [(set_attr "type" "compare")
7560    (set_attr "length" "4,8")])
7561
7562 (define_split
7563   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7564         (compare:CC (match_operator:DI 4 "boolean_operator"
7565          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7566           (match_operand:DI 2 "gpc_reg_operand" "")])
7567          (const_int 0)))
7568    (clobber (match_scratch:DI 3 ""))]
7569   "TARGET_POWERPC64 && reload_completed"
7570   [(set (match_dup 3) (match_dup 4))
7571    (set (match_dup 0)
7572         (compare:CC (match_dup 3)
7573                     (const_int 0)))]
7574   "")
7575
7576 (define_insn "*boolcdi3_internal3"
7577   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7578         (compare:CC (match_operator:DI 4 "boolean_operator"
7579          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7580           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7581          (const_int 0)))
7582    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7583         (match_dup 4))]
7584   "TARGET_64BIT"
7585   "@
7586    %q4. %0,%2,%1
7587    #"
7588   [(set_attr "type" "compare")
7589    (set_attr "length" "4,8")])
7590
7591 (define_split
7592   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7593         (compare:CC (match_operator:DI 4 "boolean_operator"
7594          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7595           (match_operand:DI 2 "gpc_reg_operand" "")])
7596          (const_int 0)))
7597    (set (match_operand:DI 0 "gpc_reg_operand" "")
7598         (match_dup 4))]
7599   "TARGET_POWERPC64 && reload_completed"
7600   [(set (match_dup 0) (match_dup 4))
7601    (set (match_dup 3)
7602         (compare:CC (match_dup 0)
7603                     (const_int 0)))]
7604   "")
7605
7606 (define_insn "*boolccdi3_internal1"
7607   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7608         (match_operator:DI 3 "boolean_operator"
7609          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7610           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7611   "TARGET_POWERPC64"
7612   "%q3 %0,%1,%2")
7613
7614 (define_insn "*boolccdi3_internal2"
7615   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7616         (compare:CC (match_operator:DI 4 "boolean_operator"
7617          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7618           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7619          (const_int 0)))
7620    (clobber (match_scratch:DI 3 "=r,r"))]
7621   "TARGET_64BIT"
7622   "@
7623    %q4. %3,%1,%2
7624    #"
7625   [(set_attr "type" "compare")
7626    (set_attr "length" "4,8")])
7627
7628 (define_split
7629   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7630         (compare:CC (match_operator:DI 4 "boolean_operator"
7631          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7632           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7633          (const_int 0)))
7634    (clobber (match_scratch:DI 3 ""))]
7635   "TARGET_POWERPC64 && reload_completed"
7636   [(set (match_dup 3) (match_dup 4))
7637    (set (match_dup 0)
7638         (compare:CC (match_dup 3)
7639                     (const_int 0)))]
7640   "")
7641
7642 (define_insn "*boolccdi3_internal3"
7643   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7644         (compare:CC (match_operator:DI 4 "boolean_operator"
7645          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7646           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7647          (const_int 0)))
7648    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7649         (match_dup 4))]
7650   "TARGET_64BIT"
7651   "@
7652    %q4. %0,%1,%2
7653    #"
7654   [(set_attr "type" "compare")
7655    (set_attr "length" "4,8")])
7656
7657 (define_split
7658   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7659         (compare:CC (match_operator:DI 4 "boolean_operator"
7660          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7661           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7662          (const_int 0)))
7663    (set (match_operand:DI 0 "gpc_reg_operand" "")
7664         (match_dup 4))]
7665   "TARGET_POWERPC64 && reload_completed"
7666   [(set (match_dup 0) (match_dup 4))
7667    (set (match_dup 3)
7668         (compare:CC (match_dup 0)
7669                     (const_int 0)))]
7670   "")
7671 \f
7672 ;; Now define ways of moving data around.
7673
7674 ;; Elf specific ways of loading addresses for non-PIC code.
7675 ;; The output of this could be r0, but we make a very strong
7676 ;; preference for a base register because it will usually
7677 ;; be needed there.
7678 (define_insn "elf_high"
7679   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
7680         (high:SI (match_operand 1 "" "")))]
7681   "TARGET_ELF && ! TARGET_64BIT"
7682   "{liu|lis} %0,%1@ha")
7683
7684 (define_insn "elf_low"
7685   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7686         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
7687                    (match_operand 2 "" "")))]
7688    "TARGET_ELF && ! TARGET_64BIT"
7689    "@
7690     {cal|la} %0,%2@l(%1)
7691     {ai|addic} %0,%1,%K2")
7692
7693
7694 ;; Set up a register with a value from the GOT table
7695
7696 (define_expand "movsi_got"
7697   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7698         (unspec:SI [(match_operand:SI 1 "got_operand" "")
7699                     (match_dup 2)] UNSPEC_MOVSI_GOT))]
7700   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7701   "
7702 {
7703   if (GET_CODE (operands[1]) == CONST)
7704     {
7705       rtx offset = const0_rtx;
7706       HOST_WIDE_INT value;
7707
7708       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
7709       value = INTVAL (offset);
7710       if (value != 0)
7711         {
7712           rtx tmp = (no_new_pseudos ? operands[0] : gen_reg_rtx (Pmode));
7713           emit_insn (gen_movsi_got (tmp, operands[1]));
7714           emit_insn (gen_addsi3 (operands[0], tmp, offset));
7715           DONE;
7716         }
7717     }
7718
7719   operands[2] = rs6000_got_register (operands[1]);
7720 }")
7721
7722 (define_insn "*movsi_got_internal"
7723   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7724         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7725                     (match_operand:SI 2 "gpc_reg_operand" "b")]
7726                    UNSPEC_MOVSI_GOT))]
7727   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7728   "{l|lwz} %0,%a1@got(%2)"
7729   [(set_attr "type" "load")])
7730
7731 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
7732 ;; didn't get allocated to a hard register.
7733 (define_split
7734   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7735         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7736                     (match_operand:SI 2 "memory_operand" "")]
7737                    UNSPEC_MOVSI_GOT))]
7738   "DEFAULT_ABI == ABI_V4
7739     && flag_pic == 1
7740     && (reload_in_progress || reload_completed)"
7741   [(set (match_dup 0) (match_dup 2))
7742    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
7743                                  UNSPEC_MOVSI_GOT))]
7744   "")
7745
7746 ;; For SI, we special-case integers that can't be loaded in one insn.  We
7747 ;; do the load 16-bits at a time.  We could do this by loading from memory,
7748 ;; and this is even supposed to be faster, but it is simpler not to get
7749 ;; integers in the TOC.
7750 (define_expand "movsi"
7751   [(set (match_operand:SI 0 "general_operand" "")
7752         (match_operand:SI 1 "any_operand" ""))]
7753   ""
7754   "{ rs6000_emit_move (operands[0], operands[1], SImode); DONE; }")
7755
7756 (define_insn "movsi_low"
7757   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7758         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
7759                            (match_operand 2 "" ""))))]
7760   "TARGET_MACHO && ! TARGET_64BIT"
7761   "{l|lwz} %0,lo16(%2)(%1)"
7762   [(set_attr "type" "load")
7763    (set_attr "length" "4")])
7764
7765 (define_insn "*movsi_internal1"
7766   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
7767         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
7768   "gpc_reg_operand (operands[0], SImode)
7769    || gpc_reg_operand (operands[1], SImode)"
7770   "@
7771    mr %0,%1
7772    {cal|la} %0,%a1
7773    {l%U1%X1|lwz%U1%X1} %0,%1
7774    {st%U0%X0|stw%U0%X0} %1,%0
7775    {lil|li} %0,%1
7776    {liu|lis} %0,%v1
7777    #
7778    {cal|la} %0,%a1
7779    mf%1 %0
7780    mt%0 %1
7781    mt%0 %1
7782    mt%0 %1
7783    {cror 0,0,0|nop}"
7784   [(set_attr "type" "*,*,load,store,*,*,*,*,mfjmpr,*,mtjmpr,*,*")
7785    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
7786
7787 ;; Split a load of a large constant into the appropriate two-insn
7788 ;; sequence.
7789
7790 (define_split
7791   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7792         (match_operand:SI 1 "const_int_operand" ""))]
7793   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
7794    && (INTVAL (operands[1]) & 0xffff) != 0"
7795   [(set (match_dup 0)
7796         (match_dup 2))
7797    (set (match_dup 0)
7798         (ior:SI (match_dup 0)
7799                 (match_dup 3)))]
7800   "
7801 { rtx tem = rs6000_emit_set_const (operands[0], SImode, operands[1], 2);
7802
7803   if (tem == operands[0])
7804     DONE;
7805   else
7806     FAIL;
7807 }")
7808
7809 (define_insn "*movsi_internal2"
7810   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
7811         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "0,r,r")
7812                     (const_int 0)))
7813    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
7814   "TARGET_32BIT"
7815   "@
7816    {cmpi|cmpwi} %2,%0,0
7817    mr. %0,%1
7818    #"
7819   [(set_attr "type" "cmp,compare,cmp")
7820    (set_attr "length" "4,4,8")])
7821
7822 (define_split
7823   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
7824         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
7825                     (const_int 0)))
7826    (set (match_operand:SI 0 "gpc_reg_operand" "") (match_dup 1))]
7827   "TARGET_32BIT && reload_completed"
7828   [(set (match_dup 0) (match_dup 1))
7829    (set (match_dup 2)
7830         (compare:CC (match_dup 0)
7831                     (const_int 0)))]
7832   "")
7833 \f
7834 (define_expand "movhi"
7835   [(set (match_operand:HI 0 "general_operand" "")
7836         (match_operand:HI 1 "any_operand" ""))]
7837   ""
7838   "{ rs6000_emit_move (operands[0], operands[1], HImode); DONE; }")
7839
7840 (define_insn "*movhi_internal"
7841   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7842         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7843   "gpc_reg_operand (operands[0], HImode)
7844    || gpc_reg_operand (operands[1], HImode)"
7845   "@
7846    mr %0,%1
7847    lhz%U1%X1 %0,%1
7848    sth%U0%X0 %1,%0
7849    {lil|li} %0,%w1
7850    mf%1 %0
7851    mt%0 %1
7852    mt%0 %1
7853    {cror 0,0,0|nop}"
7854   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7855
7856 (define_expand "movqi"
7857   [(set (match_operand:QI 0 "general_operand" "")
7858         (match_operand:QI 1 "any_operand" ""))]
7859   ""
7860   "{ rs6000_emit_move (operands[0], operands[1], QImode); DONE; }")
7861
7862 (define_insn "*movqi_internal"
7863   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
7864         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
7865   "gpc_reg_operand (operands[0], QImode)
7866    || gpc_reg_operand (operands[1], QImode)"
7867   "@
7868    mr %0,%1
7869    lbz%U1%X1 %0,%1
7870    stb%U0%X0 %1,%0
7871    {lil|li} %0,%1
7872    mf%1 %0
7873    mt%0 %1
7874    mt%0 %1
7875    {cror 0,0,0|nop}"
7876   [(set_attr "type" "*,load,store,*,mfjmpr,*,mtjmpr,*")])
7877 \f
7878 ;; Here is how to move condition codes around.  When we store CC data in
7879 ;; an integer register or memory, we store just the high-order 4 bits.
7880 ;; This lets us not shift in the most common case of CR0.
7881 (define_expand "movcc"
7882   [(set (match_operand:CC 0 "nonimmediate_operand" "")
7883         (match_operand:CC 1 "nonimmediate_operand" ""))]
7884   ""
7885   "")
7886
7887 (define_insn "*movcc_internal1"
7888   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,?y,r,r,r,r,q,cl,r,m")
7889         (match_operand:CC 1 "nonimmediate_operand" "y,r,r,x,y,r,h,r,r,m,r"))]
7890   "register_operand (operands[0], CCmode)
7891    || register_operand (operands[1], CCmode)"
7892   "@
7893    mcrf %0,%1
7894    mtcrf 128,%1
7895    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
7896    mfcr %0%Q1
7897    mfcr %0%Q1\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
7898    mr %0,%1
7899    mf%1 %0
7900    mt%0 %1
7901    mt%0 %1
7902    {l%U1%X1|lwz%U1%X1} %0,%1
7903    {st%U0%U1|stw%U0%U1} %1,%0"
7904   [(set (attr "type")
7905      (cond [(eq_attr "alternative" "0")
7906                 (const_string "cr_logical")
7907             (eq_attr "alternative" "1,2")
7908                 (const_string "mtcr")
7909             (eq_attr "alternative" "5,7")
7910                 (const_string "integer")
7911             (eq_attr "alternative" "6")
7912                 (const_string "mfjmpr")
7913             (eq_attr "alternative" "8")
7914                 (const_string "mtjmpr")
7915             (eq_attr "alternative" "9")
7916                 (const_string "load")
7917             (eq_attr "alternative" "10")
7918                 (const_string "store")
7919             (ne (symbol_ref "TARGET_MFCRF") (const_int 0))
7920                 (const_string "mfcrf")
7921            ]
7922         (const_string "mfcr")))
7923    (set_attr "length" "4,4,12,4,8,4,4,4,4,4,4")])
7924 \f
7925 ;; For floating-point, we normally deal with the floating-point registers
7926 ;; unless -msoft-float is used.  The sole exception is that parameter passing
7927 ;; can produce floating-point values in fixed-point registers.  Unless the
7928 ;; value is a simple constant or already in memory, we deal with this by
7929 ;; allocating memory and copying the value explicitly via that memory location.
7930 (define_expand "movsf"
7931   [(set (match_operand:SF 0 "nonimmediate_operand" "")
7932         (match_operand:SF 1 "any_operand" ""))]
7933   ""
7934   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
7935
7936 (define_split
7937   [(set (match_operand:SF 0 "gpc_reg_operand" "")
7938         (match_operand:SF 1 "const_double_operand" ""))]
7939   "reload_completed
7940    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
7941        || (GET_CODE (operands[0]) == SUBREG
7942            && GET_CODE (SUBREG_REG (operands[0])) == REG
7943            && REGNO (SUBREG_REG (operands[0])) <= 31))"
7944   [(set (match_dup 2) (match_dup 3))]
7945   "
7946 {
7947   long l;
7948   REAL_VALUE_TYPE rv;
7949
7950   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
7951   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
7952
7953   if (! TARGET_POWERPC64)
7954     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
7955   else
7956     operands[2] = gen_lowpart (SImode, operands[0]);
7957
7958   operands[3] = gen_int_mode (l, SImode);
7959 }")
7960
7961 (define_insn "*movsf_hardfloat"
7962   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,!cl,!q,!r,!h,!r,!r")
7963         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,r,r,h,0,G,Fn"))]
7964   "(gpc_reg_operand (operands[0], SFmode)
7965    || gpc_reg_operand (operands[1], SFmode))
7966    && (TARGET_HARD_FLOAT && TARGET_FPRS)"
7967   "@
7968    mr %0,%1
7969    {l%U1%X1|lwz%U1%X1} %0,%1
7970    {st%U0%X0|stw%U0%X0} %1,%0
7971    fmr %0,%1
7972    lfs%U1%X1 %0,%1
7973    stfs%U0%X0 %1,%0
7974    mt%0 %1
7975    mt%0 %1
7976    mf%1 %0
7977    {cror 0,0,0|nop}
7978    #
7979    #"
7980   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,mtjmpr,*,*,*,*")
7981    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,8")])
7982
7983 (define_insn "*movsf_softfloat"
7984   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
7985         (match_operand:SF 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
7986   "(gpc_reg_operand (operands[0], SFmode)
7987    || gpc_reg_operand (operands[1], SFmode))
7988    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
7989   "@
7990    mr %0,%1
7991    mt%0 %1
7992    mt%0 %1
7993    mf%1 %0
7994    {l%U1%X1|lwz%U1%X1} %0,%1
7995    {st%U0%X0|stw%U0%X0} %1,%0
7996    {lil|li} %0,%1
7997    {liu|lis} %0,%v1
7998    {cal|la} %0,%a1
7999    #
8000    #
8001    {cror 0,0,0|nop}"
8002   [(set_attr "type" "*,mtjmpr,*,*,load,store,*,*,*,*,*,*")
8003    (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
8004
8005 \f
8006 (define_expand "movdf"
8007   [(set (match_operand:DF 0 "nonimmediate_operand" "")
8008         (match_operand:DF 1 "any_operand" ""))]
8009   ""
8010   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
8011
8012 (define_split
8013   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8014         (match_operand:DF 1 "const_int_operand" ""))]
8015   "! TARGET_POWERPC64 && reload_completed
8016    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8017        || (GET_CODE (operands[0]) == SUBREG
8018            && GET_CODE (SUBREG_REG (operands[0])) == REG
8019            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8020   [(set (match_dup 2) (match_dup 4))
8021    (set (match_dup 3) (match_dup 1))]
8022   "
8023 {
8024   int endian = (WORDS_BIG_ENDIAN == 0);
8025   HOST_WIDE_INT value = INTVAL (operands[1]);
8026
8027   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8028   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8029 #if HOST_BITS_PER_WIDE_INT == 32
8030   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8031 #else
8032   operands[4] = GEN_INT (value >> 32);
8033   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8034 #endif
8035 }")
8036
8037 (define_split
8038   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8039         (match_operand:DF 1 "const_double_operand" ""))]
8040   "! TARGET_POWERPC64 && reload_completed
8041    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8042        || (GET_CODE (operands[0]) == SUBREG
8043            && GET_CODE (SUBREG_REG (operands[0])) == REG
8044            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8045   [(set (match_dup 2) (match_dup 4))
8046    (set (match_dup 3) (match_dup 5))]
8047   "
8048 {
8049   int endian = (WORDS_BIG_ENDIAN == 0);
8050   long l[2];
8051   REAL_VALUE_TYPE rv;
8052
8053   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8054   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8055
8056   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8057   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8058   operands[4] = gen_int_mode (l[endian], SImode);
8059   operands[5] = gen_int_mode (l[1 - endian], SImode);
8060 }")
8061
8062 (define_split
8063   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8064         (match_operand:DF 1 "easy_fp_constant" ""))]
8065   "TARGET_POWERPC64 && reload_completed
8066    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8067        || (GET_CODE (operands[0]) == SUBREG
8068            && GET_CODE (SUBREG_REG (operands[0])) == REG
8069            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8070   [(set (match_dup 2) (match_dup 3))]
8071   "
8072 {
8073   int endian = (WORDS_BIG_ENDIAN == 0);
8074   long l[2];
8075   REAL_VALUE_TYPE rv;
8076 #if HOST_BITS_PER_WIDE_INT >= 64
8077   HOST_WIDE_INT val;
8078 #endif
8079
8080   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8081   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8082
8083   operands[2] = gen_lowpart (DImode, operands[0]);
8084   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
8085 #if HOST_BITS_PER_WIDE_INT >= 64
8086   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
8087          | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
8088
8089   operands[3] = gen_int_mode (val, DImode);
8090 #else
8091   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
8092 #endif
8093 }")
8094
8095 ;; Don't have reload use general registers to load a constant.  First,
8096 ;; it might not work if the output operand is the equivalent of
8097 ;; a non-offsettable memref, but also it is less efficient than loading
8098 ;; the constant into an FP register, since it will probably be used there.
8099 ;; The "??" is a kludge until we can figure out a more reasonable way
8100 ;; of handling these non-offsettable values.
8101 (define_insn "*movdf_hardfloat32"
8102   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,f,f,m,!r,!r,!r")
8103         (match_operand:DF 1 "input_operand" "r,m,r,f,m,f,G,H,F"))]
8104   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8105    && (gpc_reg_operand (operands[0], DFmode)
8106        || gpc_reg_operand (operands[1], DFmode))"
8107   "*
8108 {
8109   switch (which_alternative)
8110     {
8111     default:
8112       abort ();
8113     case 0:
8114       /* We normally copy the low-numbered register first.  However, if
8115          the first register operand 0 is the same as the second register
8116          of operand 1, we must copy in the opposite order.  */
8117       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8118         return \"mr %L0,%L1\;mr %0,%1\";
8119       else
8120         return \"mr %0,%1\;mr %L0,%L1\";
8121     case 1:
8122       if (GET_CODE (operands[1]) == MEM
8123           && (rs6000_legitimate_offset_address_p (DFmode, XEXP (operands[1], 0),
8124                         reload_completed || reload_in_progress)
8125               || GET_CODE (XEXP (operands[1], 0)) == REG
8126               || GET_CODE (XEXP (operands[1], 0)) == LO_SUM
8127                   || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
8128               || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC))
8129         {
8130           /* If the low-address word is used in the address, we must load
8131              it last.  Otherwise, load it first.  Note that we cannot have
8132              auto-increment in that case since the address register is
8133              known to be dead.  */
8134           if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8135                                  operands[1], 0))
8136             return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8137           else
8138             return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8139         }
8140       else
8141         {
8142           rtx addreg;
8143
8144           addreg = find_addr_reg (XEXP (operands[1], 0));
8145           if (refers_to_regno_p (REGNO (operands[0]),
8146                                  REGNO (operands[0]) + 1,
8147                                  operands[1], 0))
8148             {
8149               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8150               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8151               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8152               return \"{lx|lwzx} %0,%1\";
8153             }
8154           else
8155             {
8156               output_asm_insn (\"{lx|lwzx} %0,%1\", operands);
8157               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8158               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8159               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8160               return \"\";
8161             }
8162         }
8163     case 2:
8164       if (GET_CODE (operands[0]) == MEM
8165           && (rs6000_legitimate_offset_address_p (DFmode, XEXP (operands[0], 0),
8166                     reload_completed || reload_in_progress)
8167               || GET_CODE (XEXP (operands[0], 0)) == REG
8168               || GET_CODE (XEXP (operands[0], 0)) == LO_SUM
8169                   || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
8170               || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC))
8171         return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8172       else
8173         {
8174           rtx addreg;
8175
8176           addreg = find_addr_reg (XEXP (operands[0], 0));
8177           output_asm_insn (\"{stx|stwx} %1,%0\", operands);
8178           output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8179           output_asm_insn (\"{stx|stwx} %L1,%0\", operands);
8180           output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8181           return \"\";
8182         }
8183     case 3:
8184       return \"fmr %0,%1\";
8185     case 4:
8186       return \"lfd%U1%X1 %0,%1\";
8187     case 5:
8188       return \"stfd%U0%X0 %1,%0\";
8189     case 6:
8190     case 7:
8191     case 8:
8192       return \"#\";
8193     }
8194 }"
8195   [(set_attr "type" "two,load,store,fp,fpload,fpstore,*,*,*")
8196    (set_attr "length" "8,16,16,4,4,4,8,12,16")])
8197
8198 (define_insn "*movdf_softfloat32"
8199   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
8200         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
8201   "! TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
8202    && (gpc_reg_operand (operands[0], DFmode)
8203        || gpc_reg_operand (operands[1], DFmode))"
8204   "*
8205 {
8206   switch (which_alternative)
8207     {
8208     default:
8209       abort ();
8210     case 0:
8211       /* We normally copy the low-numbered register first.  However, if
8212          the first register operand 0 is the same as the second register of
8213          operand 1, we must copy in the opposite order.  */
8214       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8215         return \"mr %L0,%L1\;mr %0,%1\";
8216       else
8217         return \"mr %0,%1\;mr %L0,%L1\";
8218     case 1:
8219       /* If the low-address word is used in the address, we must load
8220          it last.  Otherwise, load it first.  Note that we cannot have
8221          auto-increment in that case since the address register is
8222          known to be dead.  */
8223       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8224                              operands[1], 0))
8225         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8226       else
8227         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8228     case 2:
8229       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8230     case 3:
8231     case 4:
8232     case 5:
8233       return \"#\";
8234     }
8235 }"
8236   [(set_attr "type" "two,load,store,*,*,*")
8237    (set_attr "length" "8,8,8,8,12,16")])
8238
8239 ; ld/std require word-aligned displacements -> 'Y' constraint.
8240 ; List Y->r and r->Y before r->r for reload.
8241 (define_insn "*movdf_hardfloat64"
8242   [(set (match_operand:DF 0 "nonimmediate_operand" "=Y,r,!r,f,f,m,!cl,!r,!h,!r,!r,!r")
8243         (match_operand:DF 1 "input_operand" "r,Y,r,f,m,f,r,h,0,G,H,F"))]
8244   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8245    && (gpc_reg_operand (operands[0], DFmode)
8246        || gpc_reg_operand (operands[1], DFmode))"
8247   "@
8248    std%U0%X0 %1,%0
8249    ld%U1%X1 %0,%1
8250    mr %0,%1
8251    fmr %0,%1
8252    lfd%U1%X1 %0,%1
8253    stfd%U0%X0 %1,%0
8254    mt%0 %1
8255    mf%1 %0
8256    {cror 0,0,0|nop}
8257    #
8258    #
8259    #"
8260   [(set_attr "type" "*,load,store,fp,fpload,fpstore,mtjmpr,*,*,*,*,*")
8261    (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16")])
8262
8263 (define_insn "*movdf_softfloat64"
8264   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
8265         (match_operand:DF 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
8266   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8267    && (gpc_reg_operand (operands[0], DFmode)
8268        || gpc_reg_operand (operands[1], DFmode))"
8269   "@
8270    ld%U1%X1 %0,%1
8271    std%U0%X0 %1,%0
8272    mr %0,%1
8273    mt%0 %1
8274    mf%1 %0
8275    #
8276    #
8277    #
8278    {cror 0,0,0|nop}"
8279   [(set_attr "type" "load,store,*,*,*,*,*,*,*")
8280    (set_attr "length" "4,4,4,4,4,8,12,16,4")])
8281 \f
8282 (define_expand "movtf"
8283   [(set (match_operand:TF 0 "general_operand" "")
8284         (match_operand:TF 1 "any_operand" ""))]
8285   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8286    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8287   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
8288
8289 ; It's important to list the o->f and f->o moves before f->f because
8290 ; otherwise reload, given m->f, will try to pick f->f and reload it,
8291 ; which doesn't make progress.  Likewise r->o<> must be before r->r.
8292 (define_insn_and_split "*movtf_internal"
8293   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,f,r,o<>,r")
8294         (match_operand:TF 1 "input_operand"         "f,o,f,mGHF,r,r"))]
8295   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8296    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
8297    && (gpc_reg_operand (operands[0], TFmode)
8298        || gpc_reg_operand (operands[1], TFmode))"
8299   "#"
8300   "&& reload_completed"
8301   [(pc)]
8302 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
8303   [(set_attr "length" "8,8,8,20,20,16")])
8304
8305 (define_expand "extenddftf2"
8306   [(parallel [(set (match_operand:TF 0 "nonimmediate_operand" "")
8307                    (float_extend:TF (match_operand:DF 1 "input_operand" "")))
8308               (use (match_dup 2))])]
8309   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8310    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8311 {
8312   operands[2] = CONST0_RTX (DFmode);
8313 })
8314
8315 (define_insn_and_split "*extenddftf2_internal"
8316   [(set (match_operand:TF 0 "nonimmediate_operand" "=o,f,&f,r")
8317        (float_extend:TF (match_operand:DF 1 "input_operand" "fr,mf,mf,rmGHF")))
8318    (use (match_operand:DF 2 "input_operand" "rf,m,f,n"))]
8319   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8320    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8321   "#"
8322   "&& reload_completed"
8323   [(pc)]
8324 {
8325   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8326   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8327   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word),
8328                   operands[1]);
8329   emit_move_insn (simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word),
8330                   operands[2]);
8331   DONE;
8332 })
8333
8334 (define_expand "extendsftf2"
8335   [(set (match_operand:TF 0 "nonimmediate_operand" "")
8336         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "")))]
8337   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8338    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8339 {
8340   rtx tmp = gen_reg_rtx (DFmode);
8341   emit_insn (gen_extendsfdf2 (tmp, operands[1]));
8342   emit_insn (gen_extenddftf2 (operands[0], tmp));
8343   DONE;
8344 })
8345
8346 (define_insn "trunctfdf2"
8347   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8348         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8349   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8350    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8351   "fadd %0,%1,%L1"
8352   [(set_attr "type" "fp")
8353    (set_attr "length" "4")])
8354
8355 (define_insn_and_split "trunctfsf2"
8356   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8357         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "f")))
8358    (clobber (match_scratch:DF 2 "=f"))]
8359   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8360    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8361   "#"
8362   "&& reload_completed"
8363   [(set (match_dup 2)
8364         (float_truncate:DF (match_dup 1)))
8365    (set (match_dup 0)
8366         (float_truncate:SF (match_dup 2)))]
8367   "")
8368
8369 (define_expand "floatsitf2"
8370   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8371         (float:TF (match_operand:SI 1 "gpc_reg_operand" "r")))]
8372   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8373    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8374 {
8375   rtx tmp = gen_reg_rtx (DFmode);
8376   expand_float (tmp, operands[1], false);
8377   emit_insn (gen_extenddftf2 (operands[0], tmp));
8378   DONE;
8379 })
8380
8381 ; fadd, but rounding towards zero.
8382 ; This is probably not the optimal code sequence.
8383 (define_insn "fix_trunc_helper"
8384   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8385         (unspec:DF [(match_operand:TF 1 "gpc_reg_operand" "f")]
8386                    UNSPEC_FIX_TRUNC_TF))
8387    (clobber (match_operand:DF 2 "gpc_reg_operand" "=&f"))]
8388   "TARGET_HARD_FLOAT && TARGET_FPRS"
8389   "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
8390   [(set_attr "type" "fp")
8391    (set_attr "length" "20")])
8392
8393 (define_expand "fix_trunctfsi2"
8394   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
8395                    (fix:SI (match_operand:TF 1 "gpc_reg_operand" "")))
8396               (clobber (match_dup 2))
8397               (clobber (match_dup 3))
8398               (clobber (match_dup 4))
8399               (clobber (match_dup 5))])]
8400   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8401    && (TARGET_POWER2 || TARGET_POWERPC)
8402    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8403 {
8404   operands[2] = gen_reg_rtx (DFmode);
8405   operands[3] = gen_reg_rtx (DFmode);
8406   operands[4] = gen_reg_rtx (DImode);
8407   operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
8408 })
8409
8410 (define_insn_and_split "*fix_trunctfsi2_internal"
8411   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8412         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "f")))
8413    (clobber (match_operand:DF 2 "gpc_reg_operand" "=f"))
8414    (clobber (match_operand:DF 3 "gpc_reg_operand" "=&f"))
8415    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))
8416    (clobber (match_operand:DI 5 "memory_operand" "=o"))]
8417   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8418    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8419   "#"
8420   "&& reload_completed"
8421   [(pc)]
8422 {
8423   rtx lowword;
8424   emit_insn (gen_fix_trunc_helper (operands[2], operands[1], operands[3]));
8425
8426   if (GET_CODE (operands[5]) != MEM)
8427     abort();
8428   lowword = XEXP (operands[5], 0);
8429   if (WORDS_BIG_ENDIAN)
8430     lowword = plus_constant (lowword, 4);
8431
8432   emit_insn (gen_fctiwz (operands[4], operands[2]));
8433   emit_move_insn (operands[5], operands[4]);
8434   emit_move_insn (operands[0], gen_rtx_MEM (SImode, lowword));
8435   DONE;
8436 })
8437
8438 (define_insn "negtf2"
8439   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8440         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8441   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8442    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8443   "*
8444 {
8445   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8446     return \"fneg %L0,%L1\;fneg %0,%1\";
8447   else
8448     return \"fneg %0,%1\;fneg %L0,%L1\";
8449 }"
8450   [(set_attr "type" "fp")
8451    (set_attr "length" "8")])
8452
8453 (define_expand "abstf2"
8454   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8455         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8456   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8457    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8458   "
8459 {
8460   rtx label = gen_label_rtx ();
8461   emit_insn (gen_abstf2_internal (operands[0], operands[1], label));
8462   emit_label (label);
8463   DONE;
8464 }")
8465
8466 (define_expand "abstf2_internal"
8467   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8468         (match_operand:TF 1 "gpc_reg_operand" "f"))
8469    (set (match_dup 3) (match_dup 5))
8470    (set (match_dup 5) (abs:DF (match_dup 5)))
8471    (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
8472    (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
8473                            (label_ref (match_operand 2 "" ""))
8474                            (pc)))
8475    (set (match_dup 6) (neg:DF (match_dup 6)))]
8476   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
8477    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8478   "
8479 {
8480   const int hi_word = FLOAT_WORDS_BIG_ENDIAN ? 0 : GET_MODE_SIZE (DFmode);
8481   const int lo_word = FLOAT_WORDS_BIG_ENDIAN ? GET_MODE_SIZE (DFmode) : 0;
8482   operands[3] = gen_reg_rtx (DFmode);
8483   operands[4] = gen_reg_rtx (CCFPmode);
8484   operands[5] = simplify_gen_subreg (DFmode, operands[0], TFmode, hi_word);
8485   operands[6] = simplify_gen_subreg (DFmode, operands[0], TFmode, lo_word);
8486 }")
8487 \f
8488 ;; Next come the multi-word integer load and store and the load and store
8489 ;; multiple insns.
8490 (define_expand "movdi"
8491   [(set (match_operand:DI 0 "general_operand" "")
8492         (match_operand:DI 1 "any_operand" ""))]
8493   ""
8494   "{ rs6000_emit_move (operands[0], operands[1], DImode); DONE; }")
8495
8496 ; List r->r after r->"o<>", otherwise reload will try to reload a
8497 ; non-offsettable address by using r->r which won't make progress.
8498 (define_insn "*movdi_internal32"
8499   [(set (match_operand:DI 0 "nonimmediate_operand" "=o<>,r,r,f,f,m,r")
8500         (match_operand:DI 1 "input_operand" "r,r,m,f,m,f,IJKnGHF"))]
8501   "! TARGET_POWERPC64
8502    && (gpc_reg_operand (operands[0], DImode)
8503        || gpc_reg_operand (operands[1], DImode))"
8504   "@
8505    #
8506    #
8507    #
8508    fmr %0,%1
8509    lfd%U1%X1 %0,%1
8510    stfd%U0%X0 %1,%0
8511    #"
8512   [(set_attr "type" "load,*,store,fp,fpload,fpstore,*")])
8513
8514 (define_split
8515   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8516         (match_operand:DI 1 "const_int_operand" ""))]
8517   "! TARGET_POWERPC64 && reload_completed"
8518   [(set (match_dup 2) (match_dup 4))
8519    (set (match_dup 3) (match_dup 1))]
8520   "
8521 {
8522   HOST_WIDE_INT value = INTVAL (operands[1]);
8523   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8524                                        DImode);
8525   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8526                                        DImode);
8527 #if HOST_BITS_PER_WIDE_INT == 32
8528   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8529 #else
8530   operands[4] = GEN_INT (value >> 32);
8531   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8532 #endif
8533 }")
8534
8535 (define_split
8536   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8537         (match_operand:DI 1 "input_operand" ""))]
8538   "reload_completed && !TARGET_POWERPC64
8539    && gpr_or_gpr_p (operands[0], operands[1])"
8540   [(pc)]
8541 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8542
8543 (define_split
8544   [(set (match_operand:TI 0 "gpc_reg_operand" "")
8545         (match_operand:TI 1 "const_double_operand" ""))]
8546   "TARGET_POWERPC64"
8547   [(set (match_dup 2) (match_dup 4))
8548    (set (match_dup 3) (match_dup 5))]
8549   "
8550 {
8551   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8552                                        TImode);
8553   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8554                                        TImode);
8555   if (GET_CODE (operands[1]) == CONST_DOUBLE)
8556     {
8557       operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8558       operands[5] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
8559     }
8560   else if (GET_CODE (operands[1]) == CONST_INT)
8561     {
8562       operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
8563       operands[5] = operands[1];
8564     }
8565   else
8566     FAIL;
8567 }")
8568
8569 (define_insn "*movdi_internal64"
8570   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,??f,f,m,r,*h,*h")
8571         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,f,m,f,*h,r,0"))]
8572   "TARGET_POWERPC64
8573    && (gpc_reg_operand (operands[0], DImode)
8574        || gpc_reg_operand (operands[1], DImode))"
8575   "@
8576    mr %0,%1
8577    ld%U1%X1 %0,%1
8578    std%U0%X0 %1,%0
8579    li %0,%1
8580    lis %0,%v1
8581    #
8582    {cal|la} %0,%a1
8583    fmr %0,%1
8584    lfd%U1%X1 %0,%1
8585    stfd%U0%X0 %1,%0
8586    mf%1 %0
8587    mt%0 %1
8588    {cror 0,0,0|nop}"
8589   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,mfjmpr,mtjmpr,*")
8590    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
8591
8592 ;; immediate value valid for a single instruction hiding in a const_double
8593 (define_insn ""
8594   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8595         (match_operand:DI 1 "const_double_operand" "F"))]
8596   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
8597    && GET_CODE (operands[1]) == CONST_DOUBLE
8598    && num_insns_constant (operands[1], DImode) == 1"
8599   "*
8600 {
8601   return ((unsigned HOST_WIDE_INT)
8602           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
8603          ? \"li %0,%1\" : \"lis %0,%v1\";
8604 }")
8605
8606 ;; Generate all one-bits and clear left or right.
8607 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
8608 (define_split
8609   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8610         (match_operand:DI 1 "mask64_operand" ""))]
8611   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8612   [(set (match_dup 0) (const_int -1))
8613    (set (match_dup 0)
8614         (and:DI (rotate:DI (match_dup 0)
8615                            (const_int 0))
8616                 (match_dup 1)))]
8617   "")
8618
8619 ;; Split a load of a large constant into the appropriate five-instruction
8620 ;; sequence.  Handle anything in a constant number of insns.
8621 ;; When non-easy constants can go in the TOC, this should use
8622 ;; easy_fp_constant predicate.
8623 (define_split
8624   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8625         (match_operand:DI 1 "const_int_operand" ""))]
8626   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8627   [(set (match_dup 0) (match_dup 2))
8628    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8629   "
8630 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8631
8632   if (tem == operands[0])
8633     DONE;
8634   else
8635     FAIL;
8636 }")
8637
8638 (define_split
8639   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8640         (match_operand:DI 1 "const_double_operand" ""))]
8641   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8642   [(set (match_dup 0) (match_dup 2))
8643    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
8644   "
8645 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
8646
8647   if (tem == operands[0])
8648     DONE;
8649   else
8650     FAIL;
8651 }")
8652
8653 (define_insn "*movdi_internal2"
8654   [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
8655         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "0,r,r")
8656                     (const_int 0)))
8657    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
8658   "TARGET_64BIT"
8659   "@
8660    cmpdi %2,%0,0
8661    mr. %0,%1
8662    #"
8663   [(set_attr "type" "cmp,compare,cmp")
8664    (set_attr "length" "4,4,8")])
8665
8666 (define_split
8667   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
8668         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "")
8669                     (const_int 0)))
8670    (set (match_operand:DI 0 "gpc_reg_operand" "") (match_dup 1))]
8671   "TARGET_POWERPC64 && reload_completed"
8672   [(set (match_dup 0) (match_dup 1))
8673    (set (match_dup 2)
8674         (compare:CC (match_dup 0)
8675                     (const_int 0)))]
8676   "")
8677 \f
8678 ;; TImode is similar, except that we usually want to compute the address into
8679 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
8680 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
8681 (define_expand "movti"
8682   [(parallel [(set (match_operand:TI 0 "general_operand" "")
8683                    (match_operand:TI 1 "general_operand" ""))
8684               (clobber (scratch:SI))])]
8685   ""
8686   "{ rs6000_emit_move (operands[0], operands[1], TImode); DONE; }")
8687
8688 ;; We say that MQ is clobbered in the last alternative because the first
8689 ;; alternative would never get used otherwise since it would need a reload
8690 ;; while the 2nd alternative would not.  We put memory cases first so they
8691 ;; are preferred.  Otherwise, we'd try to reload the output instead of
8692 ;; giving the SCRATCH mq.
8693
8694 (define_insn "*movti_power"
8695   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
8696         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))
8697    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X"))]
8698   "TARGET_POWER && ! TARGET_POWERPC64
8699    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8700   "*
8701 {
8702   switch (which_alternative)
8703     {
8704     default:
8705       abort ();
8706
8707     case 0:
8708       if (TARGET_STRING)
8709         return \"{stsi|stswi} %1,%P0,16\";
8710     case 1:
8711     case 2:
8712       return \"#\";
8713     case 3:
8714       /* If the address is not used in the output, we can use lsi.  Otherwise,
8715          fall through to generating four loads.  */
8716       if (TARGET_STRING
8717           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8718         return \"{lsi|lswi} %0,%P1,16\";
8719       /* ... fall through ...  */
8720     case 4:
8721       return \"#\";
8722     }
8723 }"
8724   [(set_attr "type" "store,store,*,load,load")])
8725
8726 (define_insn "*movti_string"
8727   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,o<>,????r,????r,????r")
8728         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))]
8729   "! TARGET_POWER && ! TARGET_POWERPC64
8730    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
8731   "*
8732 {
8733   switch (which_alternative)
8734     {
8735     default:
8736       abort ();
8737     case 0:
8738       if (TARGET_STRING)
8739         return \"{stsi|stswi} %1,%P0,16\";
8740     case 1:
8741     case 2:
8742       return \"#\";
8743     case 3:
8744       /* If the address is not used in the output, we can use lsi.  Otherwise,
8745          fall through to generating four loads.  */
8746       if (TARGET_STRING
8747           && ! reg_overlap_mentioned_p (operands[0], operands[1]))
8748         return \"{lsi|lswi} %0,%P1,16\";
8749       /* ... fall through ...  */
8750     case 4:
8751       return \"#\";
8752     }
8753 }"
8754   [(set_attr "type" "store,store,*,load,load")])
8755
8756 (define_insn "*movti_ppc64"
8757   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,o<>,r")
8758         (match_operand:TI 1 "input_operand" "r,r,m"))]
8759   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
8760    || gpc_reg_operand (operands[1], TImode))"
8761   "#"
8762   [(set_attr "type" "*,load,store")])
8763
8764 (define_split
8765   [(set (match_operand:TI 0 "nonimmediate_operand" "")
8766         (match_operand:TI 1 "input_operand" ""))]
8767   "reload_completed
8768    && gpr_or_gpr_p (operands[0], operands[1])"
8769   [(pc)]
8770 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; })
8771 \f
8772 (define_expand "load_multiple"
8773   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8774                           (match_operand:SI 1 "" ""))
8775                      (use (match_operand:SI 2 "" ""))])]
8776   "TARGET_STRING && !TARGET_POWERPC64"
8777   "
8778 {
8779   int regno;
8780   int count;
8781   rtx op1;
8782   int i;
8783
8784   /* Support only loading a constant number of fixed-point registers from
8785      memory and only bother with this if more than two; the machine
8786      doesn't support more than eight.  */
8787   if (GET_CODE (operands[2]) != CONST_INT
8788       || INTVAL (operands[2]) <= 2
8789       || INTVAL (operands[2]) > 8
8790       || GET_CODE (operands[1]) != MEM
8791       || GET_CODE (operands[0]) != REG
8792       || REGNO (operands[0]) >= 32)
8793     FAIL;
8794
8795   count = INTVAL (operands[2]);
8796   regno = REGNO (operands[0]);
8797
8798   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
8799   op1 = replace_equiv_address (operands[1],
8800                                force_reg (SImode, XEXP (operands[1], 0)));
8801
8802   for (i = 0; i < count; i++)
8803     XVECEXP (operands[3], 0, i)
8804       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
8805                      adjust_address_nv (op1, SImode, i * 4));
8806 }")
8807
8808 (define_insn "*ldmsi8"
8809   [(match_parallel 0 "load_multiple_operation"
8810     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8811           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8812      (set (match_operand:SI 3 "gpc_reg_operand" "")
8813           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8814      (set (match_operand:SI 4 "gpc_reg_operand" "")
8815           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8816      (set (match_operand:SI 5 "gpc_reg_operand" "")
8817           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8818      (set (match_operand:SI 6 "gpc_reg_operand" "")
8819           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8820      (set (match_operand:SI 7 "gpc_reg_operand" "")
8821           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8822      (set (match_operand:SI 8 "gpc_reg_operand" "")
8823           (mem:SI (plus:SI (match_dup 1) (const_int 24))))
8824      (set (match_operand:SI 9 "gpc_reg_operand" "")
8825           (mem:SI (plus:SI (match_dup 1) (const_int 28))))])]
8826   "TARGET_STRING && XVECLEN (operands[0], 0) == 8"
8827   "*
8828 { return rs6000_output_load_multiple (operands); }"
8829   [(set_attr "type" "load")
8830    (set_attr "length" "32")])
8831
8832 (define_insn "*ldmsi7"
8833   [(match_parallel 0 "load_multiple_operation"
8834     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8835           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8836      (set (match_operand:SI 3 "gpc_reg_operand" "")
8837           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8838      (set (match_operand:SI 4 "gpc_reg_operand" "")
8839           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8840      (set (match_operand:SI 5 "gpc_reg_operand" "")
8841           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8842      (set (match_operand:SI 6 "gpc_reg_operand" "")
8843           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8844      (set (match_operand:SI 7 "gpc_reg_operand" "")
8845           (mem:SI (plus:SI (match_dup 1) (const_int 20))))
8846      (set (match_operand:SI 8 "gpc_reg_operand" "")
8847           (mem:SI (plus:SI (match_dup 1) (const_int 24))))])]
8848   "TARGET_STRING && XVECLEN (operands[0], 0) == 7"
8849   "*
8850 { return rs6000_output_load_multiple (operands); }"
8851   [(set_attr "type" "load")
8852    (set_attr "length" "32")])
8853
8854 (define_insn "*ldmsi6"
8855   [(match_parallel 0 "load_multiple_operation"
8856     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8857           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8858      (set (match_operand:SI 3 "gpc_reg_operand" "")
8859           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8860      (set (match_operand:SI 4 "gpc_reg_operand" "")
8861           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8862      (set (match_operand:SI 5 "gpc_reg_operand" "")
8863           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8864      (set (match_operand:SI 6 "gpc_reg_operand" "")
8865           (mem:SI (plus:SI (match_dup 1) (const_int 16))))
8866      (set (match_operand:SI 7 "gpc_reg_operand" "")
8867           (mem:SI (plus:SI (match_dup 1) (const_int 20))))])]
8868   "TARGET_STRING && XVECLEN (operands[0], 0) == 6"
8869   "*
8870 { return rs6000_output_load_multiple (operands); }"
8871   [(set_attr "type" "load")
8872    (set_attr "length" "32")])
8873
8874 (define_insn "*ldmsi5"
8875   [(match_parallel 0 "load_multiple_operation"
8876     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8877           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8878      (set (match_operand:SI 3 "gpc_reg_operand" "")
8879           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8880      (set (match_operand:SI 4 "gpc_reg_operand" "")
8881           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8882      (set (match_operand:SI 5 "gpc_reg_operand" "")
8883           (mem:SI (plus:SI (match_dup 1) (const_int 12))))
8884      (set (match_operand:SI 6 "gpc_reg_operand" "")
8885           (mem:SI (plus:SI (match_dup 1) (const_int 16))))])]
8886   "TARGET_STRING && XVECLEN (operands[0], 0) == 5"
8887   "*
8888 { return rs6000_output_load_multiple (operands); }"
8889   [(set_attr "type" "load")
8890    (set_attr "length" "32")])
8891
8892 (define_insn "*ldmsi4"
8893   [(match_parallel 0 "load_multiple_operation"
8894     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8895           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8896      (set (match_operand:SI 3 "gpc_reg_operand" "")
8897           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8898      (set (match_operand:SI 4 "gpc_reg_operand" "")
8899           (mem:SI (plus:SI (match_dup 1) (const_int 8))))
8900      (set (match_operand:SI 5 "gpc_reg_operand" "")
8901           (mem:SI (plus:SI (match_dup 1) (const_int 12))))])]
8902   "TARGET_STRING && XVECLEN (operands[0], 0) == 4"
8903   "*
8904 { return rs6000_output_load_multiple (operands); }"
8905   [(set_attr "type" "load")
8906    (set_attr "length" "32")])
8907
8908 (define_insn "*ldmsi3"
8909   [(match_parallel 0 "load_multiple_operation"
8910     [(set (match_operand:SI 2 "gpc_reg_operand" "")
8911           (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
8912      (set (match_operand:SI 3 "gpc_reg_operand" "")
8913           (mem:SI (plus:SI (match_dup 1) (const_int 4))))
8914      (set (match_operand:SI 4 "gpc_reg_operand" "")
8915           (mem:SI (plus:SI (match_dup 1) (const_int 8))))])]
8916   "TARGET_STRING && XVECLEN (operands[0], 0) == 3"
8917   "*
8918 { return rs6000_output_load_multiple (operands); }"
8919   [(set_attr "type" "load")
8920    (set_attr "length" "32")])
8921
8922 (define_expand "store_multiple"
8923   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
8924                           (match_operand:SI 1 "" ""))
8925                      (clobber (scratch:SI))
8926                      (use (match_operand:SI 2 "" ""))])]
8927   "TARGET_STRING && !TARGET_POWERPC64"
8928   "
8929 {
8930   int regno;
8931   int count;
8932   rtx to;
8933   rtx op0;
8934   int i;
8935
8936   /* Support only storing a constant number of fixed-point registers to
8937      memory and only bother with this if more than two; the machine
8938      doesn't support more than eight.  */
8939   if (GET_CODE (operands[2]) != CONST_INT
8940       || INTVAL (operands[2]) <= 2
8941       || INTVAL (operands[2]) > 8
8942       || GET_CODE (operands[0]) != MEM
8943       || GET_CODE (operands[1]) != REG
8944       || REGNO (operands[1]) >= 32)
8945     FAIL;
8946
8947   count = INTVAL (operands[2]);
8948   regno = REGNO (operands[1]);
8949
8950   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
8951   to = force_reg (SImode, XEXP (operands[0], 0));
8952   op0 = replace_equiv_address (operands[0], to);
8953
8954   XVECEXP (operands[3], 0, 0)
8955     = gen_rtx_SET (VOIDmode, adjust_address_nv (op0, SImode, 0), operands[1]);
8956   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
8957                                                  gen_rtx_SCRATCH (SImode));
8958
8959   for (i = 1; i < count; i++)
8960     XVECEXP (operands[3], 0, i + 1)
8961       = gen_rtx_SET (VOIDmode,
8962                      adjust_address_nv (op0, SImode, i * 4),
8963                      gen_rtx_REG (SImode, regno + i));
8964 }")
8965
8966 (define_insn "*store_multiple_power"
8967   [(match_parallel 0 "store_multiple_operation"
8968                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
8969                          (match_operand:SI 2 "gpc_reg_operand" "r"))
8970                     (clobber (match_scratch:SI 3 "=q"))])]
8971   "TARGET_STRING && TARGET_POWER"
8972   "{stsi|stswi} %2,%P1,%O0"
8973   [(set_attr "type" "store")])
8974
8975 (define_insn "*stmsi8"
8976   [(match_parallel 0 "store_multiple_operation"
8977     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
8978           (match_operand:SI 2 "gpc_reg_operand" "r"))
8979      (clobber (match_scratch:SI 3 "X"))
8980      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
8981           (match_operand:SI 4 "gpc_reg_operand" "r"))
8982      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
8983           (match_operand:SI 5 "gpc_reg_operand" "r"))
8984      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
8985           (match_operand:SI 6 "gpc_reg_operand" "r"))
8986      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
8987           (match_operand:SI 7 "gpc_reg_operand" "r"))
8988      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
8989           (match_operand:SI 8 "gpc_reg_operand" "r"))
8990      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
8991           (match_operand:SI 9 "gpc_reg_operand" "r"))
8992      (set (mem:SI (plus:SI (match_dup 1) (const_int 28)))
8993           (match_operand:SI 10 "gpc_reg_operand" "r"))])]
8994   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 9"
8995   "{stsi|stswi} %2,%1,%O0"
8996   [(set_attr "type" "store")])
8997
8998 (define_insn "*stmsi7"
8999   [(match_parallel 0 "store_multiple_operation"
9000     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9001           (match_operand:SI 2 "gpc_reg_operand" "r"))
9002      (clobber (match_scratch:SI 3 "X"))
9003      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9004           (match_operand:SI 4 "gpc_reg_operand" "r"))
9005      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9006           (match_operand:SI 5 "gpc_reg_operand" "r"))
9007      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9008           (match_operand:SI 6 "gpc_reg_operand" "r"))
9009      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9010           (match_operand:SI 7 "gpc_reg_operand" "r"))
9011      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9012           (match_operand:SI 8 "gpc_reg_operand" "r"))
9013      (set (mem:SI (plus:SI (match_dup 1) (const_int 24)))
9014           (match_operand:SI 9 "gpc_reg_operand" "r"))])]
9015   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 8"
9016   "{stsi|stswi} %2,%1,%O0"
9017   [(set_attr "type" "store")])
9018
9019 (define_insn "*stmsi6"
9020   [(match_parallel 0 "store_multiple_operation"
9021     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9022           (match_operand:SI 2 "gpc_reg_operand" "r"))
9023      (clobber (match_scratch:SI 3 "X"))
9024      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9025           (match_operand:SI 4 "gpc_reg_operand" "r"))
9026      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9027           (match_operand:SI 5 "gpc_reg_operand" "r"))
9028      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9029           (match_operand:SI 6 "gpc_reg_operand" "r"))
9030      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9031           (match_operand:SI 7 "gpc_reg_operand" "r"))
9032      (set (mem:SI (plus:SI (match_dup 1) (const_int 20)))
9033           (match_operand:SI 8 "gpc_reg_operand" "r"))])]
9034   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 7"
9035   "{stsi|stswi} %2,%1,%O0"
9036   [(set_attr "type" "store")])
9037
9038 (define_insn "*stmsi5"
9039   [(match_parallel 0 "store_multiple_operation"
9040     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9041           (match_operand:SI 2 "gpc_reg_operand" "r"))
9042      (clobber (match_scratch:SI 3 "X"))
9043      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9044           (match_operand:SI 4 "gpc_reg_operand" "r"))
9045      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9046           (match_operand:SI 5 "gpc_reg_operand" "r"))
9047      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9048           (match_operand:SI 6 "gpc_reg_operand" "r"))
9049      (set (mem:SI (plus:SI (match_dup 1) (const_int 16)))
9050           (match_operand:SI 7 "gpc_reg_operand" "r"))])]
9051   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 6"
9052   "{stsi|stswi} %2,%1,%O0"
9053   [(set_attr "type" "store")])
9054
9055 (define_insn "*stmsi4"
9056   [(match_parallel 0 "store_multiple_operation"
9057     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9058           (match_operand:SI 2 "gpc_reg_operand" "r"))
9059      (clobber (match_scratch:SI 3 "X"))
9060      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9061           (match_operand:SI 4 "gpc_reg_operand" "r"))
9062      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9063           (match_operand:SI 5 "gpc_reg_operand" "r"))
9064      (set (mem:SI (plus:SI (match_dup 1) (const_int 12)))
9065           (match_operand:SI 6 "gpc_reg_operand" "r"))])]
9066   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 5"
9067   "{stsi|stswi} %2,%1,%O0"
9068   [(set_attr "type" "store")])
9069
9070 (define_insn "*stmsi3"
9071   [(match_parallel 0 "store_multiple_operation"
9072     [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9073           (match_operand:SI 2 "gpc_reg_operand" "r"))
9074      (clobber (match_scratch:SI 3 "X"))
9075      (set (mem:SI (plus:SI (match_dup 1) (const_int 4)))
9076           (match_operand:SI 4 "gpc_reg_operand" "r"))
9077      (set (mem:SI (plus:SI (match_dup 1) (const_int 8)))
9078           (match_operand:SI 5 "gpc_reg_operand" "r"))])]
9079   "TARGET_STRING && !TARGET_POWER && XVECLEN (operands[0], 0) == 4"
9080   "{stsi|stswi} %2,%1,%O0"
9081   [(set_attr "type" "store")])
9082 \f
9083 (define_expand "clrmemsi"
9084   [(parallel [(set (match_operand:BLK 0 "" "")
9085                    (const_int 0))
9086               (use (match_operand:SI 1 "" ""))
9087               (use (match_operand:SI 2 "" ""))])]
9088   ""
9089   "
9090 {
9091   if (expand_block_clear (operands))
9092     DONE;
9093   else
9094     FAIL;
9095 }")
9096
9097 ;; String/block move insn.
9098 ;; Argument 0 is the destination
9099 ;; Argument 1 is the source
9100 ;; Argument 2 is the length
9101 ;; Argument 3 is the alignment
9102
9103 (define_expand "movmemsi"
9104   [(parallel [(set (match_operand:BLK 0 "" "")
9105                    (match_operand:BLK 1 "" ""))
9106               (use (match_operand:SI 2 "" ""))
9107               (use (match_operand:SI 3 "" ""))])]
9108   ""
9109   "
9110 {
9111   if (expand_block_move (operands))
9112     DONE;
9113   else
9114     FAIL;
9115 }")
9116
9117 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
9118 ;; register allocator doesn't have a clue about allocating 8 word registers.
9119 ;; rD/rS = r5 is preferred, efficient form.
9120 (define_expand "movmemsi_8reg"
9121   [(parallel [(set (match_operand 0 "" "")
9122                    (match_operand 1 "" ""))
9123               (use (match_operand 2 "" ""))
9124               (use (match_operand 3 "" ""))
9125               (clobber (reg:SI  5))
9126               (clobber (reg:SI  6))
9127               (clobber (reg:SI  7))
9128               (clobber (reg:SI  8))
9129               (clobber (reg:SI  9))
9130               (clobber (reg:SI 10))
9131               (clobber (reg:SI 11))
9132               (clobber (reg:SI 12))
9133               (clobber (match_scratch:SI 4 ""))])]
9134   "TARGET_STRING"
9135   "")
9136
9137 (define_insn ""
9138   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9139         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9140    (use (match_operand:SI 2 "immediate_operand" "i"))
9141    (use (match_operand:SI 3 "immediate_operand" "i"))
9142    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9143    (clobber (reg:SI  6))
9144    (clobber (reg:SI  7))
9145    (clobber (reg:SI  8))
9146    (clobber (reg:SI  9))
9147    (clobber (reg:SI 10))
9148    (clobber (reg:SI 11))
9149    (clobber (reg:SI 12))
9150    (clobber (match_scratch:SI 5 "=q"))]
9151   "TARGET_STRING && TARGET_POWER
9152    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9153        || INTVAL (operands[2]) == 0)
9154    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9155    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9156    && REGNO (operands[4]) == 5"
9157   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9158   [(set_attr "type" "load")
9159    (set_attr "length" "8")])
9160
9161 (define_insn ""
9162   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9163         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9164    (use (match_operand:SI 2 "immediate_operand" "i"))
9165    (use (match_operand:SI 3 "immediate_operand" "i"))
9166    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9167    (clobber (reg:SI  6))
9168    (clobber (reg:SI  7))
9169    (clobber (reg:SI  8))
9170    (clobber (reg:SI  9))
9171    (clobber (reg:SI 10))
9172    (clobber (reg:SI 11))
9173    (clobber (reg:SI 12))
9174    (clobber (match_scratch:SI 5 "X"))]
9175   "TARGET_STRING && ! TARGET_POWER
9176    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9177        || INTVAL (operands[2]) == 0)
9178    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9179    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9180    && REGNO (operands[4]) == 5"
9181   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9182   [(set_attr "type" "load")
9183    (set_attr "length" "8")])
9184
9185 (define_insn ""
9186   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9187         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9188    (use (match_operand:SI 2 "immediate_operand" "i"))
9189    (use (match_operand:SI 3 "immediate_operand" "i"))
9190    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9191    (clobber (reg:SI  6))
9192    (clobber (reg:SI  7))
9193    (clobber (reg:SI  8))
9194    (clobber (reg:SI  9))
9195    (clobber (reg:SI 10))
9196    (clobber (reg:SI 11))
9197    (clobber (reg:SI 12))
9198    (clobber (match_scratch:SI 5 "X"))]
9199   "TARGET_STRING && TARGET_POWERPC64
9200    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9201        || INTVAL (operands[2]) == 0)
9202    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9203    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9204    && REGNO (operands[4]) == 5"
9205   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9206   [(set_attr "type" "load")
9207    (set_attr "length" "8")])
9208
9209 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
9210 ;; register allocator doesn't have a clue about allocating 6 word registers.
9211 ;; rD/rS = r5 is preferred, efficient form.
9212 (define_expand "movmemsi_6reg"
9213   [(parallel [(set (match_operand 0 "" "")
9214                    (match_operand 1 "" ""))
9215               (use (match_operand 2 "" ""))
9216               (use (match_operand 3 "" ""))
9217               (clobber (reg:SI  5))
9218               (clobber (reg:SI  6))
9219               (clobber (reg:SI  7))
9220               (clobber (reg:SI  8))
9221               (clobber (reg:SI  9))
9222               (clobber (reg:SI 10))
9223               (clobber (match_scratch:SI 4 ""))])]
9224   "TARGET_STRING"
9225   "")
9226
9227 (define_insn ""
9228   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9229         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9230    (use (match_operand:SI 2 "immediate_operand" "i"))
9231    (use (match_operand:SI 3 "immediate_operand" "i"))
9232    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9233    (clobber (reg:SI  6))
9234    (clobber (reg:SI  7))
9235    (clobber (reg:SI  8))
9236    (clobber (reg:SI  9))
9237    (clobber (reg:SI 10))
9238    (clobber (match_scratch:SI 5 "=q"))]
9239   "TARGET_STRING && TARGET_POWER
9240    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
9241    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9242    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9243    && REGNO (operands[4]) == 5"
9244   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9245   [(set_attr "type" "load")
9246    (set_attr "length" "8")])
9247
9248 (define_insn ""
9249   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9250         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9251    (use (match_operand:SI 2 "immediate_operand" "i"))
9252    (use (match_operand:SI 3 "immediate_operand" "i"))
9253    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9254    (clobber (reg:SI  6))
9255    (clobber (reg:SI  7))
9256    (clobber (reg:SI  8))
9257    (clobber (reg:SI  9))
9258    (clobber (reg:SI 10))
9259    (clobber (match_scratch:SI 5 "X"))]
9260   "TARGET_STRING && ! TARGET_POWER
9261    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9262    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9263    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9264    && REGNO (operands[4]) == 5"
9265   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9266   [(set_attr "type" "load")
9267    (set_attr "length" "8")])
9268
9269 (define_insn ""
9270   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9271         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9272    (use (match_operand:SI 2 "immediate_operand" "i"))
9273    (use (match_operand:SI 3 "immediate_operand" "i"))
9274    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9275    (clobber (reg:SI  6))
9276    (clobber (reg:SI  7))
9277    (clobber (reg:SI  8))
9278    (clobber (reg:SI  9))
9279    (clobber (reg:SI 10))
9280    (clobber (match_scratch:SI 5 "X"))]
9281   "TARGET_STRING && TARGET_POWERPC64
9282    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9283    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9284    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9285    && REGNO (operands[4]) == 5"
9286   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9287   [(set_attr "type" "load")
9288    (set_attr "length" "8")])
9289
9290 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
9291 ;; problems with TImode.
9292 ;; rD/rS = r5 is preferred, efficient form.
9293 (define_expand "movmemsi_4reg"
9294   [(parallel [(set (match_operand 0 "" "")
9295                    (match_operand 1 "" ""))
9296               (use (match_operand 2 "" ""))
9297               (use (match_operand 3 "" ""))
9298               (clobber (reg:SI 5))
9299               (clobber (reg:SI 6))
9300               (clobber (reg:SI 7))
9301               (clobber (reg:SI 8))
9302               (clobber (match_scratch:SI 4 ""))])]
9303   "TARGET_STRING"
9304   "")
9305
9306 (define_insn ""
9307   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9308         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9309    (use (match_operand:SI 2 "immediate_operand" "i"))
9310    (use (match_operand:SI 3 "immediate_operand" "i"))
9311    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9312    (clobber (reg:SI 6))
9313    (clobber (reg:SI 7))
9314    (clobber (reg:SI 8))
9315    (clobber (match_scratch:SI 5 "=q"))]
9316   "TARGET_STRING && TARGET_POWER
9317    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9318    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9319    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9320    && REGNO (operands[4]) == 5"
9321   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9322   [(set_attr "type" "load")
9323    (set_attr "length" "8")])
9324
9325 (define_insn ""
9326   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9327         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9328    (use (match_operand:SI 2 "immediate_operand" "i"))
9329    (use (match_operand:SI 3 "immediate_operand" "i"))
9330    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9331    (clobber (reg:SI 6))
9332    (clobber (reg:SI 7))
9333    (clobber (reg:SI 8))
9334    (clobber (match_scratch:SI 5 "X"))]
9335   "TARGET_STRING && ! TARGET_POWER
9336    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9337    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9338    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9339    && REGNO (operands[4]) == 5"
9340   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9341   [(set_attr "type" "load")
9342    (set_attr "length" "8")])
9343
9344 (define_insn ""
9345   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9346         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9347    (use (match_operand:SI 2 "immediate_operand" "i"))
9348    (use (match_operand:SI 3 "immediate_operand" "i"))
9349    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9350    (clobber (reg:SI 6))
9351    (clobber (reg:SI 7))
9352    (clobber (reg:SI 8))
9353    (clobber (match_scratch:SI 5 "X"))]
9354   "TARGET_STRING && TARGET_POWERPC64
9355    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9356    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9357    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9358    && REGNO (operands[4]) == 5"
9359   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9360   [(set_attr "type" "load")
9361    (set_attr "length" "8")])
9362
9363 ;; Move up to 8 bytes at a time.
9364 (define_expand "movmemsi_2reg"
9365   [(parallel [(set (match_operand 0 "" "")
9366                    (match_operand 1 "" ""))
9367               (use (match_operand 2 "" ""))
9368               (use (match_operand 3 "" ""))
9369               (clobber (match_scratch:DI 4 ""))
9370               (clobber (match_scratch:SI 5 ""))])]
9371   "TARGET_STRING && ! TARGET_POWERPC64"
9372   "")
9373
9374 (define_insn ""
9375   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9376         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9377    (use (match_operand:SI 2 "immediate_operand" "i"))
9378    (use (match_operand:SI 3 "immediate_operand" "i"))
9379    (clobber (match_scratch:DI 4 "=&r"))
9380    (clobber (match_scratch:SI 5 "=q"))]
9381   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
9382    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9383   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9384   [(set_attr "type" "load")
9385    (set_attr "length" "8")])
9386
9387 (define_insn ""
9388   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9389         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9390    (use (match_operand:SI 2 "immediate_operand" "i"))
9391    (use (match_operand:SI 3 "immediate_operand" "i"))
9392    (clobber (match_scratch:DI 4 "=&r"))
9393    (clobber (match_scratch:SI 5 "X"))]
9394   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
9395    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9396   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9397   [(set_attr "type" "load")
9398    (set_attr "length" "8")])
9399
9400 ;; Move up to 4 bytes at a time.
9401 (define_expand "movmemsi_1reg"
9402   [(parallel [(set (match_operand 0 "" "")
9403                    (match_operand 1 "" ""))
9404               (use (match_operand 2 "" ""))
9405               (use (match_operand 3 "" ""))
9406               (clobber (match_scratch:SI 4 ""))
9407               (clobber (match_scratch:SI 5 ""))])]
9408   "TARGET_STRING"
9409   "")
9410
9411 (define_insn ""
9412   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9413         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9414    (use (match_operand:SI 2 "immediate_operand" "i"))
9415    (use (match_operand:SI 3 "immediate_operand" "i"))
9416    (clobber (match_scratch:SI 4 "=&r"))
9417    (clobber (match_scratch:SI 5 "=q"))]
9418   "TARGET_STRING && TARGET_POWER
9419    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9420   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9421   [(set_attr "type" "load")
9422    (set_attr "length" "8")])
9423
9424 (define_insn ""
9425   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9426         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9427    (use (match_operand:SI 2 "immediate_operand" "i"))
9428    (use (match_operand:SI 3 "immediate_operand" "i"))
9429    (clobber (match_scratch:SI 4 "=&r"))
9430    (clobber (match_scratch:SI 5 "X"))]
9431   "TARGET_STRING && ! TARGET_POWER
9432    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9433   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9434   [(set_attr "type" "load")
9435    (set_attr "length" "8")])
9436
9437 (define_insn ""
9438   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9439         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9440    (use (match_operand:SI 2 "immediate_operand" "i"))
9441    (use (match_operand:SI 3 "immediate_operand" "i"))
9442    (clobber (match_scratch:SI 4 "=&r"))
9443    (clobber (match_scratch:SI 5 "X"))]
9444   "TARGET_STRING && TARGET_POWERPC64
9445    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9446   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9447   [(set_attr "type" "load")
9448    (set_attr "length" "8")])
9449
9450 \f
9451 ;; Define insns that do load or store with update.  Some of these we can
9452 ;; get by using pre-decrement or pre-increment, but the hardware can also
9453 ;; do cases where the increment is not the size of the object.
9454 ;;
9455 ;; In all these cases, we use operands 0 and 1 for the register being
9456 ;; incremented because those are the operands that local-alloc will
9457 ;; tie and these are the pair most likely to be tieable (and the ones
9458 ;; that will benefit the most).
9459
9460 (define_insn "*movdi_update1"
9461   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9462         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9463                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
9464    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9465         (plus:DI (match_dup 1) (match_dup 2)))]
9466   "TARGET_POWERPC64 && TARGET_UPDATE"
9467   "@
9468    ldux %3,%0,%2
9469    ldu %3,%2(%0)"
9470   [(set_attr "type" "load_ux,load_u")])
9471
9472 (define_insn "movdi_<mode>_update"
9473   [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
9474                          (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
9475         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9476    (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
9477         (plus:P (match_dup 1) (match_dup 2)))]
9478   "TARGET_POWERPC64 && TARGET_UPDATE"
9479   "@
9480    stdux %3,%0,%2
9481    stdu %3,%2(%0)"
9482   [(set_attr "type" "store_ux,store_u")])
9483
9484 (define_insn "*movsi_update1"
9485   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9486         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9487                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9488    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9489         (plus:SI (match_dup 1) (match_dup 2)))]
9490   "TARGET_UPDATE"
9491   "@
9492    {lux|lwzux} %3,%0,%2
9493    {lu|lwzu} %3,%2(%0)"
9494   [(set_attr "type" "load_ux,load_u")])
9495
9496 (define_insn "*movsi_update2"
9497   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9498         (sign_extend:DI
9499          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9500                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9501    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9502         (plus:DI (match_dup 1) (match_dup 2)))]
9503   "TARGET_POWERPC64"
9504   "lwaux %3,%0,%2"
9505   [(set_attr "type" "load_ext_ux")])
9506
9507 (define_insn "movsi_update"
9508   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9509                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9510         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9511    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9512         (plus:SI (match_dup 1) (match_dup 2)))]
9513   "TARGET_UPDATE"
9514   "@
9515    {stux|stwux} %3,%0,%2
9516    {stu|stwu} %3,%2(%0)"
9517   [(set_attr "type" "store_ux,store_u")])
9518
9519 (define_insn "*movhi_update1"
9520   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9521         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9522                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9523    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9524         (plus:SI (match_dup 1) (match_dup 2)))]
9525   "TARGET_UPDATE"
9526   "@
9527    lhzux %3,%0,%2
9528    lhzu %3,%2(%0)"
9529   [(set_attr "type" "load_ux,load_u")])
9530
9531 (define_insn "*movhi_update2"
9532   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9533         (zero_extend:SI
9534          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9535                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9536    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9537         (plus:SI (match_dup 1) (match_dup 2)))]
9538   "TARGET_UPDATE"
9539   "@
9540    lhzux %3,%0,%2
9541    lhzu %3,%2(%0)"
9542   [(set_attr "type" "load_ux,load_u")])
9543
9544 (define_insn "*movhi_update3"
9545   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9546         (sign_extend:SI
9547          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9548                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9549    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9550         (plus:SI (match_dup 1) (match_dup 2)))]
9551   "TARGET_UPDATE"
9552   "@
9553    lhaux %3,%0,%2
9554    lhau %3,%2(%0)"
9555   [(set_attr "type" "load_ext_ux,load_ext_u")])
9556
9557 (define_insn "*movhi_update4"
9558   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9559                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9560         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
9561    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9562         (plus:SI (match_dup 1) (match_dup 2)))]
9563   "TARGET_UPDATE"
9564   "@
9565    sthux %3,%0,%2
9566    sthu %3,%2(%0)"
9567   [(set_attr "type" "store_ux,store_u")])
9568
9569 (define_insn "*movqi_update1"
9570   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
9571         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9572                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9573    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9574         (plus:SI (match_dup 1) (match_dup 2)))]
9575   "TARGET_UPDATE"
9576   "@
9577    lbzux %3,%0,%2
9578    lbzu %3,%2(%0)"
9579   [(set_attr "type" "load_ux,load_u")])
9580
9581 (define_insn "*movqi_update2"
9582   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9583         (zero_extend:SI
9584          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9585                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9586    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9587         (plus:SI (match_dup 1) (match_dup 2)))]
9588   "TARGET_UPDATE"
9589   "@
9590    lbzux %3,%0,%2
9591    lbzu %3,%2(%0)"
9592   [(set_attr "type" "load_ux,load_u")])
9593
9594 (define_insn "*movqi_update3"
9595   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9596                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9597         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
9598    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9599         (plus:SI (match_dup 1) (match_dup 2)))]
9600   "TARGET_UPDATE"
9601   "@
9602    stbux %3,%0,%2
9603    stbu %3,%2(%0)"
9604   [(set_attr "type" "store_ux,store_u")])
9605
9606 (define_insn "*movsf_update1"
9607   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
9608         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9609                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9610    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9611         (plus:SI (match_dup 1) (match_dup 2)))]
9612   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9613   "@
9614    lfsux %3,%0,%2
9615    lfsu %3,%2(%0)"
9616   [(set_attr "type" "fpload_ux,fpload_u")])
9617
9618 (define_insn "*movsf_update2"
9619   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9620                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9621         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
9622    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9623         (plus:SI (match_dup 1) (match_dup 2)))]
9624   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9625   "@
9626    stfsux %3,%0,%2
9627    stfsu %3,%2(%0)"
9628   [(set_attr "type" "fpstore_ux,fpstore_u")])
9629
9630 (define_insn "*movsf_update3"
9631   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
9632         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9633                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9634    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9635         (plus:SI (match_dup 1) (match_dup 2)))]
9636   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9637   "@
9638    {lux|lwzux} %3,%0,%2
9639    {lu|lwzu} %3,%2(%0)"
9640   [(set_attr "type" "load_ux,load_u")])
9641
9642 (define_insn "*movsf_update4"
9643   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9644                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9645         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
9646    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9647         (plus:SI (match_dup 1) (match_dup 2)))]
9648   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9649   "@
9650    {stux|stwux} %3,%0,%2
9651    {stu|stwu} %3,%2(%0)"
9652   [(set_attr "type" "store_ux,store_u")])
9653
9654 (define_insn "*movdf_update1"
9655   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
9656         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9657                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9658    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9659         (plus:SI (match_dup 1) (match_dup 2)))]
9660   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9661   "@
9662    lfdux %3,%0,%2
9663    lfdu %3,%2(%0)"
9664   [(set_attr "type" "fpload_ux,fpload_u")])
9665
9666 (define_insn "*movdf_update2"
9667   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9668                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9669         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
9670    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9671         (plus:SI (match_dup 1) (match_dup 2)))]
9672   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9673   "@
9674    stfdux %3,%0,%2
9675    stfdu %3,%2(%0)"
9676   [(set_attr "type" "fpstore_ux,fpstore_u")])
9677
9678 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
9679
9680 (define_insn "*lfq_power2"
9681   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
9682         (match_operand:TF 1 "memory_operand" ""))]
9683   "TARGET_POWER2
9684    && TARGET_HARD_FLOAT && TARGET_FPRS"
9685    "lfq%U1%X1 %0,%1")
9686
9687 (define_peephole2
9688   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9689         (match_operand:DF 1 "memory_operand" ""))
9690    (set (match_operand:DF 2 "gpc_reg_operand" "")
9691         (match_operand:DF 3 "memory_operand" ""))]
9692   "TARGET_POWER2
9693    && TARGET_HARD_FLOAT && TARGET_FPRS
9694    && registers_ok_for_quad_peep (operands[0], operands[2])
9695    && mems_ok_for_quad_peep (operands[1], operands[3])"
9696   [(set (match_dup 0)
9697         (match_dup 1))]
9698   "operands[1] = widen_memory_access (operands[1], TFmode, 0);
9699    operands[0] = gen_rtx_REG (TFmode, REGNO (operands[0]));")
9700
9701 (define_insn "*stfq_power2"
9702   [(set (match_operand:TF 0 "memory_operand" "")
9703         (match_operand:TF 1 "gpc_reg_operand" "f"))]
9704   "TARGET_POWER2
9705    && TARGET_HARD_FLOAT && TARGET_FPRS"
9706   "stfq%U0%X0 %1,%0")
9707
9708
9709 (define_peephole2
9710   [(set (match_operand:DF 0 "memory_operand" "")
9711         (match_operand:DF 1 "gpc_reg_operand" ""))
9712    (set (match_operand:DF 2 "memory_operand" "")
9713         (match_operand:DF 3 "gpc_reg_operand" ""))]
9714   "TARGET_POWER2
9715    && TARGET_HARD_FLOAT && TARGET_FPRS
9716    && registers_ok_for_quad_peep (operands[1], operands[3])
9717    && mems_ok_for_quad_peep (operands[0], operands[2])"
9718   [(set (match_dup 0)
9719         (match_dup 1))]
9720   "operands[0] = widen_memory_access (operands[0], TFmode, 0);
9721    operands[1] = gen_rtx_REG (TFmode, REGNO (operands[1]));")
9722
9723 ;; after inserting conditional returns we can sometimes have
9724 ;; unnecessary register moves.  Unfortunately we cannot have a
9725 ;; modeless peephole here, because some single SImode sets have early
9726 ;; clobber outputs.  Although those sets expand to multi-ppc-insn
9727 ;; sequences, using get_attr_length here will smash the operands
9728 ;; array.  Neither is there an early_cobbler_p predicate.
9729 (define_peephole2
9730   [(set (match_operand:DF 0 "gpc_reg_operand" "")
9731         (match_operand:DF 1 "any_operand" ""))
9732    (set (match_operand:DF 2 "gpc_reg_operand" "")
9733         (match_dup 0))]
9734   "peep2_reg_dead_p (2, operands[0])"
9735   [(set (match_dup 2) (match_dup 1))])
9736
9737 (define_peephole2
9738   [(set (match_operand:SF 0 "gpc_reg_operand" "")
9739         (match_operand:SF 1 "any_operand" ""))
9740    (set (match_operand:SF 2 "gpc_reg_operand" "")
9741         (match_dup 0))]
9742   "peep2_reg_dead_p (2, operands[0])"
9743   [(set (match_dup 2) (match_dup 1))])
9744
9745 \f
9746 ;; TLS support.
9747
9748 ;; "b" output constraint here and on tls_ld to support tls linker optimization.
9749 (define_insn "tls_gd_32"
9750   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9751         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9752                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9753                    UNSPEC_TLSGD))]
9754   "HAVE_AS_TLS && !TARGET_64BIT"
9755   "addi %0,%1,%2@got@tlsgd")
9756
9757 (define_insn "tls_gd_64"
9758   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9759         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9760                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9761                    UNSPEC_TLSGD))]
9762   "HAVE_AS_TLS && TARGET_64BIT"
9763   "addi %0,%1,%2@got@tlsgd")
9764
9765 (define_insn "tls_ld_32"
9766   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9767         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")]
9768                    UNSPEC_TLSLD))]
9769   "HAVE_AS_TLS && !TARGET_64BIT"
9770   "addi %0,%1,%&@got@tlsld")
9771
9772 (define_insn "tls_ld_64"
9773   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9774         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")]
9775                    UNSPEC_TLSLD))]
9776   "HAVE_AS_TLS && TARGET_64BIT"
9777   "addi %0,%1,%&@got@tlsld")
9778
9779 (define_insn "tls_dtprel_32"
9780   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9781         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9782                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9783                    UNSPEC_TLSDTPREL))]
9784   "HAVE_AS_TLS && !TARGET_64BIT"
9785   "addi %0,%1,%2@dtprel")
9786
9787 (define_insn "tls_dtprel_64"
9788   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9789         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9790                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9791                    UNSPEC_TLSDTPREL))]
9792   "HAVE_AS_TLS && TARGET_64BIT"
9793   "addi %0,%1,%2@dtprel")
9794
9795 (define_insn "tls_dtprel_ha_32"
9796   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9797         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9798                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9799                    UNSPEC_TLSDTPRELHA))]
9800   "HAVE_AS_TLS && !TARGET_64BIT"
9801   "addis %0,%1,%2@dtprel@ha")
9802
9803 (define_insn "tls_dtprel_ha_64"
9804   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9805         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9806                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9807                    UNSPEC_TLSDTPRELHA))]
9808   "HAVE_AS_TLS && TARGET_64BIT"
9809   "addis %0,%1,%2@dtprel@ha")
9810
9811 (define_insn "tls_dtprel_lo_32"
9812   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9813         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9814                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9815                    UNSPEC_TLSDTPRELLO))]
9816   "HAVE_AS_TLS && !TARGET_64BIT"
9817   "addi %0,%1,%2@dtprel@l")
9818
9819 (define_insn "tls_dtprel_lo_64"
9820   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9821         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9822                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9823                    UNSPEC_TLSDTPRELLO))]
9824   "HAVE_AS_TLS && TARGET_64BIT"
9825   "addi %0,%1,%2@dtprel@l")
9826
9827 (define_insn "tls_got_dtprel_32"
9828   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9829         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9830                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9831                    UNSPEC_TLSGOTDTPREL))]
9832   "HAVE_AS_TLS && !TARGET_64BIT"
9833   "lwz %0,%2@got@dtprel(%1)")
9834
9835 (define_insn "tls_got_dtprel_64"
9836   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9837         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9838                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9839                    UNSPEC_TLSGOTDTPREL))]
9840   "HAVE_AS_TLS && TARGET_64BIT"
9841   "ld %0,%2@got@dtprel(%1)")
9842
9843 (define_insn "tls_tprel_32"
9844   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9845         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9846                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9847                    UNSPEC_TLSTPREL))]
9848   "HAVE_AS_TLS && !TARGET_64BIT"
9849   "addi %0,%1,%2@tprel")
9850
9851 (define_insn "tls_tprel_64"
9852   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9853         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9854                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9855                    UNSPEC_TLSTPREL))]
9856   "HAVE_AS_TLS && TARGET_64BIT"
9857   "addi %0,%1,%2@tprel")
9858
9859 (define_insn "tls_tprel_ha_32"
9860   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9861         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9862                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9863                    UNSPEC_TLSTPRELHA))]
9864   "HAVE_AS_TLS && !TARGET_64BIT"
9865   "addis %0,%1,%2@tprel@ha")
9866
9867 (define_insn "tls_tprel_ha_64"
9868   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9869         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9870                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9871                    UNSPEC_TLSTPRELHA))]
9872   "HAVE_AS_TLS && TARGET_64BIT"
9873   "addis %0,%1,%2@tprel@ha")
9874
9875 (define_insn "tls_tprel_lo_32"
9876   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9877         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9878                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9879                    UNSPEC_TLSTPRELLO))]
9880   "HAVE_AS_TLS && !TARGET_64BIT"
9881   "addi %0,%1,%2@tprel@l")
9882
9883 (define_insn "tls_tprel_lo_64"
9884   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9885         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9886                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9887                    UNSPEC_TLSTPRELLO))]
9888   "HAVE_AS_TLS && TARGET_64BIT"
9889   "addi %0,%1,%2@tprel@l")
9890
9891 ;; "b" output constraint here and on tls_tls input to support linker tls
9892 ;; optimization.  The linker may edit the instructions emitted by a
9893 ;; tls_got_tprel/tls_tls pair to addis,addi.
9894 (define_insn "tls_got_tprel_32"
9895   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
9896         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9897                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9898                    UNSPEC_TLSGOTTPREL))]
9899   "HAVE_AS_TLS && !TARGET_64BIT"
9900   "lwz %0,%2@got@tprel(%1)")
9901
9902 (define_insn "tls_got_tprel_64"
9903   [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
9904         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9905                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9906                    UNSPEC_TLSGOTTPREL))]
9907   "HAVE_AS_TLS && TARGET_64BIT"
9908   "ld %0,%2@got@tprel(%1)")
9909
9910 (define_insn "tls_tls_32"
9911   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9912         (unspec:SI [(match_operand:SI 1 "gpc_reg_operand" "b")
9913                     (match_operand:SI 2 "rs6000_tls_symbol_ref" "")]
9914                    UNSPEC_TLSTLS))]
9915   "HAVE_AS_TLS && !TARGET_64BIT"
9916   "add %0,%1,%2@tls")
9917
9918 (define_insn "tls_tls_64"
9919   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
9920         (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "b")
9921                     (match_operand:DI 2 "rs6000_tls_symbol_ref" "")]
9922                    UNSPEC_TLSTLS))]
9923   "HAVE_AS_TLS && TARGET_64BIT"
9924   "add %0,%1,%2@tls")
9925 \f
9926 ;; Next come insns related to the calling sequence.
9927 ;;
9928 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
9929 ;; We move the back-chain and decrement the stack pointer.
9930
9931 (define_expand "allocate_stack"
9932   [(set (match_operand 0 "gpc_reg_operand" "=r")
9933         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
9934    (set (reg 1)
9935         (minus (reg 1) (match_dup 1)))]
9936   ""
9937   "
9938 { rtx chain = gen_reg_rtx (Pmode);
9939   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
9940   rtx neg_op0;
9941
9942   emit_move_insn (chain, stack_bot);
9943
9944   /* Check stack bounds if necessary.  */
9945   if (current_function_limit_stack)
9946     {
9947       rtx available;
9948       available = expand_binop (Pmode, sub_optab,
9949                                 stack_pointer_rtx, stack_limit_rtx,
9950                                 NULL_RTX, 1, OPTAB_WIDEN);
9951       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
9952     }
9953
9954   if (GET_CODE (operands[1]) != CONST_INT
9955       || INTVAL (operands[1]) < -32767
9956       || INTVAL (operands[1]) > 32768)
9957     {
9958       neg_op0 = gen_reg_rtx (Pmode);
9959       if (TARGET_32BIT)
9960         emit_insn (gen_negsi2 (neg_op0, operands[1]));
9961       else
9962         emit_insn (gen_negdi2 (neg_op0, operands[1]));
9963     }
9964   else
9965     neg_op0 = GEN_INT (- INTVAL (operands[1]));
9966
9967   if (TARGET_UPDATE)
9968     emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update : gen_movdi_di_update))
9969                 (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
9970
9971   else
9972     {
9973       emit_insn ((* ((TARGET_32BIT) ? gen_addsi3 : gen_adddi3))
9974                  (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
9975       emit_move_insn (gen_rtx_MEM (Pmode, stack_pointer_rtx), chain);
9976     }
9977
9978   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
9979   DONE;
9980 }")
9981
9982 ;; These patterns say how to save and restore the stack pointer.  We need not
9983 ;; save the stack pointer at function level since we are careful to
9984 ;; preserve the backchain.  At block level, we have to restore the backchain
9985 ;; when we restore the stack pointer.
9986 ;;
9987 ;; For nonlocal gotos, we must save both the stack pointer and its
9988 ;; backchain and restore both.  Note that in the nonlocal case, the
9989 ;; save area is a memory location.
9990
9991 (define_expand "save_stack_function"
9992   [(match_operand 0 "any_operand" "")
9993    (match_operand 1 "any_operand" "")]
9994   ""
9995   "DONE;")
9996
9997 (define_expand "restore_stack_function"
9998   [(match_operand 0 "any_operand" "")
9999    (match_operand 1 "any_operand" "")]
10000   ""
10001   "DONE;")
10002
10003 (define_expand "restore_stack_block"
10004   [(use (match_operand 0 "register_operand" ""))
10005    (set (match_dup 2) (match_dup 3))
10006    (set (match_dup 0) (match_operand 1 "register_operand" ""))
10007    (set (match_dup 3) (match_dup 2))]
10008   ""
10009   "
10010 {
10011   operands[2] = gen_reg_rtx (Pmode);
10012   operands[3] = gen_rtx_MEM (Pmode, operands[0]);
10013 }")
10014
10015 (define_expand "save_stack_nonlocal"
10016   [(match_operand 0 "memory_operand" "")
10017    (match_operand 1 "register_operand" "")]
10018   ""
10019   "
10020 {
10021   rtx temp = gen_reg_rtx (Pmode);
10022   int units_per_word = (TARGET_32BIT) ? 4 : 8;
10023
10024   /* Copy the backchain to the first word, sp to the second.  */
10025   emit_move_insn (temp, gen_rtx_MEM (Pmode, operands[1]));
10026   emit_move_insn (adjust_address_nv (operands[0], Pmode, 0), temp);
10027   emit_move_insn (adjust_address_nv (operands[0], Pmode, units_per_word),
10028                   operands[1]);
10029   DONE;
10030 }")
10031
10032 (define_expand "restore_stack_nonlocal"
10033   [(match_operand 0 "register_operand" "")
10034    (match_operand 1 "memory_operand" "")]
10035   ""
10036   "
10037 {
10038   rtx temp = gen_reg_rtx (Pmode);
10039   int units_per_word = (TARGET_32BIT) ? 4 : 8;
10040
10041   /* Restore the backchain from the first word, sp from the second.  */
10042   emit_move_insn (temp,
10043                   adjust_address_nv (operands[1], Pmode, 0));
10044   emit_move_insn (operands[0],
10045                   adjust_address_nv (operands[1], Pmode, units_per_word));
10046   emit_move_insn (gen_rtx_MEM (Pmode, operands[0]), temp);
10047   DONE;
10048 }")
10049 \f
10050 ;; TOC register handling.
10051
10052 ;; Code to initialize the TOC register...
10053
10054 (define_insn "load_toc_aix_si"
10055   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10056                    (unspec:SI [(const_int 0)] UNSPEC_TOC))
10057               (use (reg:SI 2))])]
10058   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
10059   "*
10060 {
10061   char buf[30];
10062   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10063   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10064   operands[2] = gen_rtx_REG (Pmode, 2);
10065   return \"{l|lwz} %0,%1(%2)\";
10066 }"
10067   [(set_attr "type" "load")])
10068
10069 (define_insn "load_toc_aix_di"
10070   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10071                    (unspec:DI [(const_int 0)] UNSPEC_TOC))
10072               (use (reg:DI 2))])]
10073   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
10074   "*
10075 {
10076   char buf[30];
10077 #ifdef TARGET_RELOCATABLE
10078   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
10079                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
10080 #else
10081   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10082 #endif
10083   if (TARGET_ELF)
10084     strcat (buf, \"@toc\");
10085   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10086   operands[2] = gen_rtx_REG (Pmode, 2);
10087   return \"ld %0,%1(%2)\";
10088 }"
10089   [(set_attr "type" "load")])
10090
10091 (define_insn "load_toc_v4_pic_si"
10092   [(set (match_operand:SI 0 "register_operand" "=l")
10093         (unspec:SI [(const_int 0)] UNSPEC_TOC))]
10094   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
10095   "bl _GLOBAL_OFFSET_TABLE_@local-4"
10096   [(set_attr "type" "branch")
10097    (set_attr "length" "4")])
10098
10099 (define_insn "load_toc_v4_PIC_1"
10100   [(set (match_operand:SI 0 "register_operand" "=l")
10101         (match_operand:SI 1 "immediate_operand" "s"))
10102    (use (unspec [(match_dup 1)] UNSPEC_TOC))]
10103   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10104   "bcl 20,31,%1\\n%1:"
10105   [(set_attr "type" "branch")
10106    (set_attr "length" "4")])
10107
10108 (define_insn "load_toc_v4_PIC_1b"
10109   [(set (match_operand:SI 0 "register_operand" "=l")
10110         (match_operand:SI 1 "immediate_operand" "s"))
10111    (use (unspec [(match_dup 1) (match_operand 2 "immediate_operand" "s")]
10112                 UNSPEC_TOCPTR))]
10113   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10114   "bcl 20,31,%1+4\\n%1:\\n\\t.long %2-%1"
10115   [(set_attr "type" "branch")
10116    (set_attr "length" "8")])
10117
10118 (define_insn "load_toc_v4_PIC_2"
10119   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10120         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
10121                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
10122                              (match_operand:SI 3 "immediate_operand" "s")))))]
10123   "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
10124   "{l|lwz} %0,%2-%3(%1)"
10125   [(set_attr "type" "load")])
10126
10127
10128 ;; If the TOC is shared over a translation unit, as happens with all
10129 ;; the kinds of PIC that we support, we need to restore the TOC
10130 ;; pointer only when jumping over units of translation.
10131 ;; On Darwin, we need to reload the picbase.
10132
10133 (define_expand "builtin_setjmp_receiver"
10134   [(use (label_ref (match_operand 0 "" "")))]
10135   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10136    || (TARGET_TOC && TARGET_MINIMAL_TOC)
10137    || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
10138   "
10139 {
10140 #if TARGET_MACHO
10141   if (DEFAULT_ABI == ABI_DARWIN)
10142     {
10143       const char *picbase = machopic_function_base_name ();
10144       rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (picbase));
10145       rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
10146       rtx tmplabrtx;
10147       char tmplab[20];
10148
10149       ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
10150                                   CODE_LABEL_NUMBER (operands[0]));
10151       tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
10152
10153       emit_insn (gen_load_macho_picbase (picreg, tmplabrtx));
10154       emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
10155     }
10156   else
10157 #endif
10158     rs6000_emit_load_toc_table (FALSE);
10159   DONE;
10160 }")
10161 \f
10162 ;; A function pointer under AIX is a pointer to a data area whose first word
10163 ;; contains the actual address of the function, whose second word contains a
10164 ;; pointer to its TOC, and whose third word contains a value to place in the
10165 ;; static chain register (r11).  Note that if we load the static chain, our
10166 ;; "trampoline" need not have any executable code.
10167
10168 (define_expand "call_indirect_aix32"
10169   [(set (match_dup 2)
10170         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
10171    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10172         (reg:SI 2))
10173    (set (reg:SI 2)
10174         (mem:SI (plus:SI (match_dup 0)
10175                          (const_int 4))))
10176    (set (reg:SI 11)
10177         (mem:SI (plus:SI (match_dup 0)
10178                          (const_int 8))))
10179    (parallel [(call (mem:SI (match_dup 2))
10180                     (match_operand 1 "" ""))
10181               (use (reg:SI 2))
10182               (use (reg:SI 11))
10183               (set (reg:SI 2)
10184                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10185               (clobber (scratch:SI))])]
10186   "TARGET_32BIT"
10187   "
10188 { operands[2] = gen_reg_rtx (SImode); }")
10189
10190 (define_expand "call_indirect_aix64"
10191   [(set (match_dup 2)
10192         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
10193    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10194         (reg:DI 2))
10195    (set (reg:DI 2)
10196         (mem:DI (plus:DI (match_dup 0)
10197                          (const_int 8))))
10198    (set (reg:DI 11)
10199         (mem:DI (plus:DI (match_dup 0)
10200                          (const_int 16))))
10201    (parallel [(call (mem:SI (match_dup 2))
10202                     (match_operand 1 "" ""))
10203               (use (reg:DI 2))
10204               (use (reg:DI 11))
10205               (set (reg:DI 2)
10206                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10207               (clobber (scratch:SI))])]
10208   "TARGET_64BIT"
10209   "
10210 { operands[2] = gen_reg_rtx (DImode); }")
10211
10212 (define_expand "call_value_indirect_aix32"
10213   [(set (match_dup 3)
10214         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
10215    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10216         (reg:SI 2))
10217    (set (reg:SI 2)
10218         (mem:SI (plus:SI (match_dup 1)
10219                          (const_int 4))))
10220    (set (reg:SI 11)
10221         (mem:SI (plus:SI (match_dup 1)
10222                          (const_int 8))))
10223    (parallel [(set (match_operand 0 "" "")
10224                    (call (mem:SI (match_dup 3))
10225                          (match_operand 2 "" "")))
10226               (use (reg:SI 2))
10227               (use (reg:SI 11))
10228               (set (reg:SI 2)
10229                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10230               (clobber (scratch:SI))])]
10231   "TARGET_32BIT"
10232   "
10233 { operands[3] = gen_reg_rtx (SImode); }")
10234
10235 (define_expand "call_value_indirect_aix64"
10236   [(set (match_dup 3)
10237         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
10238    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10239         (reg:DI 2))
10240    (set (reg:DI 2)
10241         (mem:DI (plus:DI (match_dup 1)
10242                          (const_int 8))))
10243    (set (reg:DI 11)
10244         (mem:DI (plus:DI (match_dup 1)
10245                          (const_int 16))))
10246    (parallel [(set (match_operand 0 "" "")
10247                    (call (mem:SI (match_dup 3))
10248                          (match_operand 2 "" "")))
10249               (use (reg:DI 2))
10250               (use (reg:DI 11))
10251               (set (reg:DI 2)
10252                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10253               (clobber (scratch:SI))])]
10254   "TARGET_64BIT"
10255   "
10256 { operands[3] = gen_reg_rtx (DImode); }")
10257
10258 ;; Now the definitions for the call and call_value insns
10259 (define_expand "call"
10260   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10261                     (match_operand 1 "" ""))
10262               (use (match_operand 2 "" ""))
10263               (clobber (scratch:SI))])]
10264   ""
10265   "
10266 {
10267 #if TARGET_MACHO
10268   if (MACHOPIC_INDIRECT)
10269     operands[0] = machopic_indirect_call_target (operands[0]);
10270 #endif
10271
10272   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
10273     abort ();
10274
10275   operands[0] = XEXP (operands[0], 0);
10276
10277   if (GET_CODE (operands[0]) != SYMBOL_REF
10278       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0]))
10279       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0))
10280     {
10281       if (INTVAL (operands[2]) & CALL_LONG)
10282         operands[0] = rs6000_longcall_ref (operands[0]);
10283
10284       if (DEFAULT_ABI == ABI_V4
10285           || DEFAULT_ABI == ABI_DARWIN)
10286         operands[0] = force_reg (Pmode, operands[0]);
10287
10288       else if (DEFAULT_ABI == ABI_AIX)
10289         {
10290           /* AIX function pointers are really pointers to a three word
10291              area.  */
10292           emit_call_insn (TARGET_32BIT
10293                           ? gen_call_indirect_aix32 (force_reg (SImode,
10294                                                                 operands[0]),
10295                                                      operands[1])
10296                           : gen_call_indirect_aix64 (force_reg (DImode,
10297                                                                 operands[0]),
10298                                                      operands[1]));
10299           DONE;
10300         }
10301       else
10302         abort ();
10303     }
10304 }")
10305
10306 (define_expand "call_value"
10307   [(parallel [(set (match_operand 0 "" "")
10308                    (call (mem:SI (match_operand 1 "address_operand" ""))
10309                          (match_operand 2 "" "")))
10310               (use (match_operand 3 "" ""))
10311               (clobber (scratch:SI))])]
10312   ""
10313   "
10314 {
10315 #if TARGET_MACHO
10316   if (MACHOPIC_INDIRECT)
10317     operands[1] = machopic_indirect_call_target (operands[1]);
10318 #endif
10319
10320   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
10321     abort ();
10322
10323   operands[1] = XEXP (operands[1], 0);
10324
10325   if (GET_CODE (operands[1]) != SYMBOL_REF
10326       || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1]))
10327       || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0))
10328     {
10329       if (INTVAL (operands[3]) & CALL_LONG)
10330         operands[1] = rs6000_longcall_ref (operands[1]);
10331
10332       if (DEFAULT_ABI == ABI_V4
10333           || DEFAULT_ABI == ABI_DARWIN)
10334         operands[1] = force_reg (Pmode, operands[1]);
10335
10336       else if (DEFAULT_ABI == ABI_AIX)
10337         {
10338           /* AIX function pointers are really pointers to a three word
10339              area.  */
10340           emit_call_insn (TARGET_32BIT
10341                           ? gen_call_value_indirect_aix32 (operands[0],
10342                                                            force_reg (SImode,
10343                                                                       operands[1]),
10344                                                            operands[2])
10345                           : gen_call_value_indirect_aix64 (operands[0],
10346                                                            force_reg (DImode,
10347                                                                       operands[1]),
10348                                                            operands[2]));
10349           DONE;
10350         }
10351       else
10352         abort ();
10353     }
10354 }")
10355
10356 ;; Call to function in current module.  No TOC pointer reload needed.
10357 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10358 ;; either the function was not prototyped, or it was prototyped as a
10359 ;; variable argument function.  It is > 0 if FP registers were passed
10360 ;; and < 0 if they were not.
10361
10362 (define_insn "*call_local32"
10363   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10364          (match_operand 1 "" "g,g"))
10365    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10366    (clobber (match_scratch:SI 3 "=l,l"))]
10367   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10368   "*
10369 {
10370   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10371     output_asm_insn (\"crxor 6,6,6\", operands);
10372
10373   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10374     output_asm_insn (\"creqv 6,6,6\", operands);
10375
10376   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10377 }"
10378   [(set_attr "type" "branch")
10379    (set_attr "length" "4,8")])
10380
10381 (define_insn "*call_local64"
10382   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10383          (match_operand 1 "" "g,g"))
10384    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10385    (clobber (match_scratch:SI 3 "=l,l"))]
10386   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10387   "*
10388 {
10389   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10390     output_asm_insn (\"crxor 6,6,6\", operands);
10391
10392   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10393     output_asm_insn (\"creqv 6,6,6\", operands);
10394
10395   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10396 }"
10397   [(set_attr "type" "branch")
10398    (set_attr "length" "4,8")])
10399
10400 (define_insn "*call_value_local32"
10401   [(set (match_operand 0 "" "")
10402         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10403               (match_operand 2 "" "g,g")))
10404    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10405    (clobber (match_scratch:SI 4 "=l,l"))]
10406   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10407   "*
10408 {
10409   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10410     output_asm_insn (\"crxor 6,6,6\", operands);
10411
10412   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10413     output_asm_insn (\"creqv 6,6,6\", operands);
10414
10415   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10416 }"
10417   [(set_attr "type" "branch")
10418    (set_attr "length" "4,8")])
10419
10420
10421 (define_insn "*call_value_local64"
10422   [(set (match_operand 0 "" "")
10423         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10424               (match_operand 2 "" "g,g")))
10425    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10426    (clobber (match_scratch:SI 4 "=l,l"))]
10427   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10428   "*
10429 {
10430   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10431     output_asm_insn (\"crxor 6,6,6\", operands);
10432
10433   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10434     output_asm_insn (\"creqv 6,6,6\", operands);
10435
10436   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10437 }"
10438   [(set_attr "type" "branch")
10439    (set_attr "length" "4,8")])
10440
10441 ;; Call to function which may be in another module.  Restore the TOC
10442 ;; pointer (r2) after the call unless this is System V.
10443 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
10444 ;; either the function was not prototyped, or it was prototyped as a
10445 ;; variable argument function.  It is > 0 if FP registers were passed
10446 ;; and < 0 if they were not.
10447
10448 (define_insn "*call_indirect_nonlocal_aix32"
10449   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl"))
10450          (match_operand 1 "" "g"))
10451    (use (reg:SI 2))
10452    (use (reg:SI 11))
10453    (set (reg:SI 2)
10454         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10455    (clobber (match_scratch:SI 2 "=l"))]
10456   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10457   "b%T0l\;{l|lwz} 2,20(1)"
10458   [(set_attr "type" "jmpreg")
10459    (set_attr "length" "8")])
10460
10461 (define_insn "*call_nonlocal_aix32"
10462   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10463          (match_operand 1 "" "g"))
10464    (use (match_operand:SI 2 "immediate_operand" "O"))
10465    (clobber (match_scratch:SI 3 "=l"))]
10466   "TARGET_32BIT
10467    && DEFAULT_ABI == ABI_AIX
10468    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10469   "bl %z0\;%."
10470   [(set_attr "type" "branch")
10471    (set_attr "length" "8")])
10472
10473 (define_insn "*call_indirect_nonlocal_aix64"
10474   [(call (mem:SI (match_operand:DI 0 "register_operand" "cl"))
10475          (match_operand 1 "" "g"))
10476    (use (reg:DI 2))
10477    (use (reg:DI 11))
10478    (set (reg:DI 2)
10479         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10480    (clobber (match_scratch:SI 2 "=l"))]
10481   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10482   "b%T0l\;ld 2,40(1)"
10483   [(set_attr "type" "jmpreg")
10484    (set_attr "length" "8")])
10485
10486 (define_insn "*call_nonlocal_aix64"
10487   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10488          (match_operand 1 "" "g"))
10489    (use (match_operand:SI 2 "immediate_operand" "O"))
10490    (clobber (match_scratch:SI 3 "=l"))]
10491   "TARGET_64BIT
10492    && DEFAULT_ABI == ABI_AIX
10493    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10494   "bl %z0\;%."
10495   [(set_attr "type" "branch")
10496    (set_attr "length" "8")])
10497
10498 (define_insn "*call_value_indirect_nonlocal_aix32"
10499   [(set (match_operand 0 "" "")
10500         (call (mem:SI (match_operand:SI 1 "register_operand" "cl"))
10501               (match_operand 2 "" "g")))
10502    (use (reg:SI 2))
10503    (use (reg:SI 11))
10504    (set (reg:SI 2)
10505         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10506    (clobber (match_scratch:SI 3 "=l"))]
10507   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10508   "b%T1l\;{l|lwz} 2,20(1)"
10509   [(set_attr "type" "jmpreg")
10510    (set_attr "length" "8")])
10511
10512 (define_insn "*call_value_nonlocal_aix32"
10513   [(set (match_operand 0 "" "")
10514         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10515               (match_operand 2 "" "g")))
10516    (use (match_operand:SI 3 "immediate_operand" "O"))
10517    (clobber (match_scratch:SI 4 "=l"))]
10518   "TARGET_32BIT
10519    && DEFAULT_ABI == ABI_AIX
10520    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10521   "bl %z1\;%."
10522   [(set_attr "type" "branch")
10523    (set_attr "length" "8")])
10524
10525 (define_insn "*call_value_indirect_nonlocal_aix64"
10526   [(set (match_operand 0 "" "")
10527         (call (mem:SI (match_operand:DI 1 "register_operand" "cl"))
10528               (match_operand 2 "" "g")))
10529    (use (reg:DI 2))
10530    (use (reg:DI 11))
10531    (set (reg:DI 2)
10532         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10533    (clobber (match_scratch:SI 3 "=l"))]
10534   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10535   "b%T1l\;ld 2,40(1)"
10536   [(set_attr "type" "jmpreg")
10537    (set_attr "length" "8")])
10538
10539 (define_insn "*call_value_nonlocal_aix64"
10540   [(set (match_operand 0 "" "")
10541         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10542               (match_operand 2 "" "g")))
10543    (use (match_operand:SI 3 "immediate_operand" "O"))
10544    (clobber (match_scratch:SI 4 "=l"))]
10545   "TARGET_64BIT
10546    && DEFAULT_ABI == ABI_AIX
10547    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10548   "bl %z1\;%."
10549   [(set_attr "type" "branch")
10550    (set_attr "length" "8")])
10551
10552 ;; A function pointer under System V is just a normal pointer
10553 ;; operands[0] is the function pointer
10554 ;; operands[1] is the stack size to clean up
10555 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
10556 ;; which indicates how to set cr1
10557
10558 (define_insn "*call_indirect_nonlocal_sysv"
10559   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl,cl"))
10560          (match_operand 1 "" "g,g"))
10561    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10562    (clobber (match_scratch:SI 3 "=l,l"))]
10563   "DEFAULT_ABI == ABI_V4
10564    || DEFAULT_ABI == ABI_DARWIN"
10565 {
10566   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10567     output_asm_insn ("crxor 6,6,6", operands);
10568
10569   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10570     output_asm_insn ("creqv 6,6,6", operands);
10571
10572   return "b%T0l";
10573 }
10574   [(set_attr "type" "jmpreg,jmpreg")
10575    (set_attr "length" "4,8")])
10576
10577 (define_insn "*call_nonlocal_sysv"
10578   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10579          (match_operand 1 "" "g,g"))
10580    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10581    (clobber (match_scratch:SI 3 "=l,l"))]
10582   "(DEFAULT_ABI == ABI_DARWIN
10583    || (DEFAULT_ABI == ABI_V4
10584        && (INTVAL (operands[2]) & CALL_LONG) == 0))"
10585 {
10586   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10587     output_asm_insn ("crxor 6,6,6", operands);
10588
10589   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10590     output_asm_insn ("creqv 6,6,6", operands);
10591
10592 #if TARGET_MACHO
10593   return output_call(insn, operands, 0, 2);
10594 #else
10595   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z0@plt" : "bl %z0";
10596 #endif
10597 }
10598   [(set_attr "type" "branch,branch")
10599    (set_attr "length" "4,8")])
10600
10601 (define_insn "*call_value_indirect_nonlocal_sysv"
10602   [(set (match_operand 0 "" "")
10603         (call (mem:SI (match_operand:SI 1 "register_operand" "cl,cl"))
10604               (match_operand 2 "" "g,g")))
10605    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10606    (clobber (match_scratch:SI 4 "=l,l"))]
10607   "DEFAULT_ABI == ABI_V4
10608    || DEFAULT_ABI == ABI_DARWIN"
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   return "b%T1l";
10617 }
10618   [(set_attr "type" "jmpreg,jmpreg")
10619    (set_attr "length" "4,8")])
10620
10621 (define_insn "*call_value_nonlocal_sysv"
10622   [(set (match_operand 0 "" "")
10623         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10624               (match_operand 2 "" "g,g")))
10625    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10626    (clobber (match_scratch:SI 4 "=l,l"))]
10627   "(DEFAULT_ABI == ABI_DARWIN
10628    || (DEFAULT_ABI == ABI_V4
10629        && (INTVAL (operands[3]) & CALL_LONG) == 0))"
10630 {
10631   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10632     output_asm_insn ("crxor 6,6,6", operands);
10633
10634   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10635     output_asm_insn ("creqv 6,6,6", operands);
10636
10637 #if TARGET_MACHO
10638   return output_call(insn, operands, 1, 3);
10639 #else
10640   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z1@plt" : "bl %z1";
10641 #endif
10642 }
10643   [(set_attr "type" "branch,branch")
10644    (set_attr "length" "4,8")])
10645
10646 ;; Call subroutine returning any type.
10647 (define_expand "untyped_call"
10648   [(parallel [(call (match_operand 0 "" "")
10649                     (const_int 0))
10650               (match_operand 1 "" "")
10651               (match_operand 2 "" "")])]
10652   ""
10653   "
10654 {
10655   int i;
10656
10657   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
10658
10659   for (i = 0; i < XVECLEN (operands[2], 0); i++)
10660     {
10661       rtx set = XVECEXP (operands[2], 0, i);
10662       emit_move_insn (SET_DEST (set), SET_SRC (set));
10663     }
10664
10665   /* The optimizer does not know that the call sets the function value
10666      registers we stored in the result block.  We avoid problems by
10667      claiming that all hard registers are used and clobbered at this
10668      point.  */
10669   emit_insn (gen_blockage ());
10670
10671   DONE;
10672 }")
10673
10674 ;; sibling call patterns
10675 (define_expand "sibcall"
10676   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10677                     (match_operand 1 "" ""))
10678               (use (match_operand 2 "" ""))
10679               (use (match_operand 3 "" ""))
10680               (return)])]
10681   ""
10682   "
10683 {
10684 #if TARGET_MACHO
10685   if (MACHOPIC_INDIRECT)
10686     operands[0] = machopic_indirect_call_target (operands[0]);
10687 #endif
10688
10689   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
10690     abort ();
10691
10692   operands[0] = XEXP (operands[0], 0);
10693   operands[3] = gen_reg_rtx (SImode);
10694
10695 }")
10696
10697 ;; this and similar patterns must be marked as using LR, otherwise
10698 ;; dataflow will try to delete the store into it.  This is true
10699 ;; even when the actual reg to jump to is in CTR, when LR was
10700 ;; saved and restored around the PIC-setting BCL.
10701 (define_insn "*sibcall_local32"
10702   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10703          (match_operand 1 "" "g,g"))
10704    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10705    (use (match_operand:SI 3 "register_operand" "l,l"))
10706    (return)]
10707   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10708   "*
10709 {
10710   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10711     output_asm_insn (\"crxor 6,6,6\", operands);
10712
10713   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10714     output_asm_insn (\"creqv 6,6,6\", operands);
10715
10716   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10717 }"
10718   [(set_attr "type" "branch")
10719    (set_attr "length" "4,8")])
10720
10721 (define_insn "*sibcall_local64"
10722   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10723          (match_operand 1 "" "g,g"))
10724    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10725    (use (match_operand:SI 3 "register_operand" "l,l"))
10726    (return)]
10727   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10728   "*
10729 {
10730   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10731     output_asm_insn (\"crxor 6,6,6\", operands);
10732
10733   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10734     output_asm_insn (\"creqv 6,6,6\", operands);
10735
10736   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@local\" : \"b %z0\";
10737 }"
10738   [(set_attr "type" "branch")
10739    (set_attr "length" "4,8")])
10740
10741 (define_insn "*sibcall_value_local32"
10742   [(set (match_operand 0 "" "")
10743         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10744               (match_operand 2 "" "g,g")))
10745    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10746    (use (match_operand:SI 4 "register_operand" "l,l"))
10747    (return)]
10748   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10749   "*
10750 {
10751   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10752     output_asm_insn (\"crxor 6,6,6\", operands);
10753
10754   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10755     output_asm_insn (\"creqv 6,6,6\", operands);
10756
10757   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10758 }"
10759   [(set_attr "type" "branch")
10760    (set_attr "length" "4,8")])
10761
10762
10763 (define_insn "*sibcall_value_local64"
10764   [(set (match_operand 0 "" "")
10765         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10766               (match_operand 2 "" "g,g")))
10767    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10768    (use (match_operand:SI 4 "register_operand" "l,l"))
10769    (return)]
10770   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10771   "*
10772 {
10773   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10774     output_asm_insn (\"crxor 6,6,6\", operands);
10775
10776   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10777     output_asm_insn (\"creqv 6,6,6\", operands);
10778
10779   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@local\" : \"b %z1\";
10780 }"
10781   [(set_attr "type" "branch")
10782    (set_attr "length" "4,8")])
10783
10784 (define_insn "*sibcall_nonlocal_aix32"
10785   [(call (mem:SI (match_operand:SI 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_32BIT
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_nonlocal_aix64"
10798   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10799          (match_operand 1 "" "g"))
10800    (use (match_operand:SI 2 "immediate_operand" "O"))
10801    (use (match_operand:SI 3 "register_operand" "l"))
10802    (return)]
10803   "TARGET_64BIT
10804    && DEFAULT_ABI == ABI_AIX
10805    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10806   "b %z0"
10807   [(set_attr "type" "branch")
10808    (set_attr "length" "4")])
10809
10810 (define_insn "*sibcall_value_nonlocal_aix32"
10811   [(set (match_operand 0 "" "")
10812         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10813               (match_operand 2 "" "g")))
10814    (use (match_operand:SI 3 "immediate_operand" "O"))
10815    (use (match_operand:SI 4 "register_operand" "l"))
10816    (return)]
10817   "TARGET_32BIT
10818    && DEFAULT_ABI == ABI_AIX
10819    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10820   "b %z1"
10821   [(set_attr "type" "branch")
10822    (set_attr "length" "4")])
10823
10824 (define_insn "*sibcall_value_nonlocal_aix64"
10825   [(set (match_operand 0 "" "")
10826         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10827               (match_operand 2 "" "g")))
10828    (use (match_operand:SI 3 "immediate_operand" "O"))
10829    (use (match_operand:SI 4 "register_operand" "l"))
10830    (return)]
10831   "TARGET_64BIT
10832    && DEFAULT_ABI == ABI_AIX
10833    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10834   "b %z1"
10835   [(set_attr "type" "branch")
10836    (set_attr "length" "4")])
10837
10838 (define_insn "*sibcall_nonlocal_sysv"
10839   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10840          (match_operand 1 "" ""))
10841    (use (match_operand 2 "immediate_operand" "O,n"))
10842    (use (match_operand:SI 3 "register_operand" "l,l"))
10843    (return)]
10844   "(DEFAULT_ABI == ABI_DARWIN
10845      || DEFAULT_ABI == ABI_V4)
10846    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10847   "*
10848 {
10849   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10850     output_asm_insn (\"crxor 6,6,6\", operands);
10851
10852   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10853     output_asm_insn (\"creqv 6,6,6\", operands);
10854
10855   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@plt\" : \"b %z0\";
10856 }"
10857   [(set_attr "type" "branch,branch")
10858    (set_attr "length" "4,8")])
10859
10860 (define_expand "sibcall_value"
10861   [(parallel [(set (match_operand 0 "register_operand" "")
10862                 (call (mem:SI (match_operand 1 "address_operand" ""))
10863                       (match_operand 2 "" "")))
10864               (use (match_operand 3 "" ""))
10865               (use (match_operand 4 "" ""))
10866               (return)])]
10867   ""
10868   "
10869 {
10870 #if TARGET_MACHO
10871   if (MACHOPIC_INDIRECT)
10872     operands[1] = machopic_indirect_call_target (operands[1]);
10873 #endif
10874
10875   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
10876     abort ();
10877
10878   operands[1] = XEXP (operands[1], 0);
10879   operands[4] = gen_reg_rtx (SImode);
10880
10881 }")
10882
10883 (define_insn "*sibcall_value_nonlocal_sysv"
10884   [(set (match_operand 0 "" "")
10885         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10886               (match_operand 2 "" "")))
10887    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10888    (use (match_operand:SI 4 "register_operand" "l,l"))
10889    (return)]
10890   "(DEFAULT_ABI == ABI_DARWIN
10891        || DEFAULT_ABI == ABI_V4)
10892    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10893   "*
10894 {
10895   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10896     output_asm_insn (\"crxor 6,6,6\", operands);
10897
10898   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10899     output_asm_insn (\"creqv 6,6,6\", operands);
10900
10901   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@plt\" : \"b %z1\";
10902 }"
10903   [(set_attr "type" "branch,branch")
10904    (set_attr "length" "4,8")])
10905
10906 (define_expand "sibcall_epilogue"
10907   [(use (const_int 0))]
10908   "TARGET_SCHED_PROLOG"
10909   "
10910 {
10911       rs6000_emit_epilogue (TRUE);
10912       DONE;
10913 }")
10914
10915 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
10916 ;; all of memory.  This blocks insns from being moved across this point.
10917
10918 (define_insn "blockage"
10919   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
10920   ""
10921   "")
10922 \f
10923 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
10924 ;; signed & unsigned, and one type of branch.
10925 ;;
10926 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
10927 ;; insns, and branches.  We store the operands of compares until we see
10928 ;; how it is used.
10929 (define_expand "cmpsi"
10930   [(set (cc0)
10931         (compare (match_operand:SI 0 "gpc_reg_operand" "")
10932                  (match_operand:SI 1 "reg_or_short_operand" "")))]
10933   ""
10934   "
10935 {
10936   /* Take care of the possibility that operands[1] might be negative but
10937      this might be a logical operation.  That insn doesn't exist.  */
10938   if (GET_CODE (operands[1]) == CONST_INT
10939       && INTVAL (operands[1]) < 0)
10940     operands[1] = force_reg (SImode, operands[1]);
10941
10942   rs6000_compare_op0 = operands[0];
10943   rs6000_compare_op1 = operands[1];
10944   rs6000_compare_fp_p = 0;
10945   DONE;
10946 }")
10947
10948 (define_expand "cmpdi"
10949   [(set (cc0)
10950         (compare (match_operand:DI 0 "gpc_reg_operand" "")
10951                  (match_operand:DI 1 "reg_or_short_operand" "")))]
10952   "TARGET_POWERPC64"
10953   "
10954 {
10955   /* Take care of the possibility that operands[1] might be negative but
10956      this might be a logical operation.  That insn doesn't exist.  */
10957   if (GET_CODE (operands[1]) == CONST_INT
10958       && INTVAL (operands[1]) < 0)
10959     operands[1] = force_reg (DImode, operands[1]);
10960
10961   rs6000_compare_op0 = operands[0];
10962   rs6000_compare_op1 = operands[1];
10963   rs6000_compare_fp_p = 0;
10964   DONE;
10965 }")
10966
10967 (define_expand "cmpsf"
10968   [(set (cc0) (compare (match_operand:SF 0 "gpc_reg_operand" "")
10969                        (match_operand:SF 1 "gpc_reg_operand" "")))]
10970   "TARGET_HARD_FLOAT"
10971   "
10972 {
10973   rs6000_compare_op0 = operands[0];
10974   rs6000_compare_op1 = operands[1];
10975   rs6000_compare_fp_p = 1;
10976   DONE;
10977 }")
10978
10979 (define_expand "cmpdf"
10980   [(set (cc0) (compare (match_operand:DF 0 "gpc_reg_operand" "")
10981                        (match_operand:DF 1 "gpc_reg_operand" "")))]
10982   "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
10983   "
10984 {
10985   rs6000_compare_op0 = operands[0];
10986   rs6000_compare_op1 = operands[1];
10987   rs6000_compare_fp_p = 1;
10988   DONE;
10989 }")
10990
10991 (define_expand "cmptf"
10992   [(set (cc0) (compare (match_operand:TF 0 "gpc_reg_operand" "")
10993                        (match_operand:TF 1 "gpc_reg_operand" "")))]
10994   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
10995    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
10996   "
10997 {
10998   rs6000_compare_op0 = operands[0];
10999   rs6000_compare_op1 = operands[1];
11000   rs6000_compare_fp_p = 1;
11001   DONE;
11002 }")
11003
11004 (define_expand "beq"
11005   [(use (match_operand 0 "" ""))]
11006   ""
11007   "{ rs6000_emit_cbranch (EQ, operands[0]); DONE; }")
11008
11009 (define_expand "bne"
11010   [(use (match_operand 0 "" ""))]
11011   ""
11012   "{ rs6000_emit_cbranch (NE, operands[0]); DONE; }")
11013
11014 (define_expand "bge"
11015   [(use (match_operand 0 "" ""))]
11016   ""
11017   "{ rs6000_emit_cbranch (GE, operands[0]); DONE; }")
11018
11019 (define_expand "bgt"
11020   [(use (match_operand 0 "" ""))]
11021   ""
11022   "{ rs6000_emit_cbranch (GT, operands[0]); DONE; }")
11023
11024 (define_expand "ble"
11025   [(use (match_operand 0 "" ""))]
11026   ""
11027   "{ rs6000_emit_cbranch (LE, operands[0]); DONE; }")
11028
11029 (define_expand "blt"
11030   [(use (match_operand 0 "" ""))]
11031   ""
11032   "{ rs6000_emit_cbranch (LT, operands[0]); DONE; }")
11033
11034 (define_expand "bgeu"
11035   [(use (match_operand 0 "" ""))]
11036   ""
11037   "{ rs6000_emit_cbranch (GEU, operands[0]); DONE; }")
11038
11039 (define_expand "bgtu"
11040   [(use (match_operand 0 "" ""))]
11041   ""
11042   "{ rs6000_emit_cbranch (GTU, operands[0]); DONE; }")
11043
11044 (define_expand "bleu"
11045   [(use (match_operand 0 "" ""))]
11046   ""
11047   "{ rs6000_emit_cbranch (LEU, operands[0]); DONE; }")
11048
11049 (define_expand "bltu"
11050   [(use (match_operand 0 "" ""))]
11051   ""
11052   "{ rs6000_emit_cbranch (LTU, operands[0]); DONE; }")
11053
11054 (define_expand "bunordered"
11055   [(use (match_operand 0 "" ""))]
11056   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11057   "{ rs6000_emit_cbranch (UNORDERED, operands[0]); DONE; }")
11058
11059 (define_expand "bordered"
11060   [(use (match_operand 0 "" ""))]
11061   "! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)"
11062   "{ rs6000_emit_cbranch (ORDERED, operands[0]); DONE; }")
11063
11064 (define_expand "buneq"
11065   [(use (match_operand 0 "" ""))]
11066   ""
11067   "{ rs6000_emit_cbranch (UNEQ, operands[0]); DONE; }")
11068
11069 (define_expand "bunge"
11070   [(use (match_operand 0 "" ""))]
11071   ""
11072   "{ rs6000_emit_cbranch (UNGE, operands[0]); DONE; }")
11073
11074 (define_expand "bungt"
11075   [(use (match_operand 0 "" ""))]
11076   ""
11077   "{ rs6000_emit_cbranch (UNGT, operands[0]); DONE; }")
11078
11079 (define_expand "bunle"
11080   [(use (match_operand 0 "" ""))]
11081   ""
11082   "{ rs6000_emit_cbranch (UNLE, operands[0]); DONE; }")
11083
11084 (define_expand "bunlt"
11085   [(use (match_operand 0 "" ""))]
11086   ""
11087   "{ rs6000_emit_cbranch (UNLT, operands[0]); DONE; }")
11088
11089 (define_expand "bltgt"
11090   [(use (match_operand 0 "" ""))]
11091   ""
11092   "{ rs6000_emit_cbranch (LTGT, operands[0]); DONE; }")
11093
11094 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
11095 ;; For SEQ, likewise, except that comparisons with zero should be done
11096 ;; with an scc insns.  However, due to the order that combine see the
11097 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
11098 ;; the cases we don't want to handle.
11099 (define_expand "seq"
11100   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11101   ""
11102   "{ rs6000_emit_sCOND (EQ, operands[0]); DONE; }")
11103
11104 (define_expand "sne"
11105   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11106   ""
11107   "
11108 {
11109   if (! rs6000_compare_fp_p)
11110     FAIL;
11111
11112   rs6000_emit_sCOND (NE, operands[0]);
11113   DONE;
11114 }")
11115
11116 ;; A >= 0 is best done the portable way for A an integer.
11117 (define_expand "sge"
11118   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11119   ""
11120   "
11121 {
11122   if (! rs6000_compare_fp_p
11123       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11124     FAIL;
11125
11126   rs6000_emit_sCOND (GE, operands[0]);
11127   DONE;
11128 }")
11129
11130 ;; A > 0 is best done using the portable sequence, so fail in that case.
11131 (define_expand "sgt"
11132   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11133   ""
11134   "
11135 {
11136   if (! rs6000_compare_fp_p
11137       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11138     FAIL;
11139
11140   rs6000_emit_sCOND (GT, operands[0]);
11141   DONE;
11142 }")
11143
11144 ;; A <= 0 is best done the portable way for A an integer.
11145 (define_expand "sle"
11146   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11147   ""
11148   "
11149 {
11150   if (! rs6000_compare_fp_p
11151       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11152     FAIL;
11153
11154   rs6000_emit_sCOND (LE, operands[0]);
11155   DONE;
11156 }")
11157
11158 ;; A < 0 is best done in the portable way for A an integer.
11159 (define_expand "slt"
11160   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11161   ""
11162   "
11163 {
11164   if (! rs6000_compare_fp_p
11165       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
11166     FAIL;
11167
11168   rs6000_emit_sCOND (LT, operands[0]);
11169   DONE;
11170 }")
11171
11172 (define_expand "sgeu"
11173   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11174   ""
11175   "{ rs6000_emit_sCOND (GEU, operands[0]); DONE; }")
11176
11177 (define_expand "sgtu"
11178   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11179   ""
11180   "{ rs6000_emit_sCOND (GTU, operands[0]); DONE; }")
11181
11182 (define_expand "sleu"
11183   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11184   ""
11185   "{ rs6000_emit_sCOND (LEU, operands[0]); DONE; }")
11186
11187 (define_expand "sltu"
11188   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11189   ""
11190   "{ rs6000_emit_sCOND (LTU, operands[0]); DONE; }")
11191
11192 (define_expand "sunordered"
11193   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11194   ""
11195   "{ rs6000_emit_sCOND (UNORDERED, operands[0]); DONE; }")
11196
11197 (define_expand "sordered"
11198   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11199   ""
11200   "{ rs6000_emit_sCOND (ORDERED, operands[0]); DONE; }")
11201
11202 (define_expand "suneq"
11203   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11204   ""
11205   "{ rs6000_emit_sCOND (UNEQ, operands[0]); DONE; }")
11206
11207 (define_expand "sunge"
11208   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11209   ""
11210   "{ rs6000_emit_sCOND (UNGE, operands[0]); DONE; }")
11211
11212 (define_expand "sungt"
11213   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11214   ""
11215   "{ rs6000_emit_sCOND (UNGT, operands[0]); DONE; }")
11216
11217 (define_expand "sunle"
11218   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11219   ""
11220   "{ rs6000_emit_sCOND (UNLE, operands[0]); DONE; }")
11221
11222 (define_expand "sunlt"
11223   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11224   ""
11225   "{ rs6000_emit_sCOND (UNLT, operands[0]); DONE; }")
11226
11227 (define_expand "sltgt"
11228   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
11229   ""
11230   "{ rs6000_emit_sCOND (LTGT, operands[0]); DONE; }")
11231
11232 \f
11233 ;; Here are the actual compare insns.
11234 (define_insn "*cmpsi_internal1"
11235   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11236         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11237                     (match_operand:SI 2 "reg_or_short_operand" "rI")))]
11238   ""
11239   "{cmp%I2|cmpw%I2} %0,%1,%2"
11240   [(set_attr "type" "cmp")])
11241
11242 (define_insn "*cmpdi_internal1"
11243   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11244         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "r")
11245                     (match_operand:DI 2 "reg_or_short_operand" "rI")))]
11246   "TARGET_POWERPC64"
11247   "cmpd%I2 %0,%1,%2"
11248   [(set_attr "type" "cmp")])
11249
11250 ;; If we are comparing a register for equality with a large constant,
11251 ;; we can do this with an XOR followed by a compare.  But we need a scratch
11252 ;; register for the result of the XOR.
11253
11254 (define_split
11255   [(set (match_operand:CC 0 "cc_reg_operand" "")
11256         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11257                     (match_operand:SI 2 "non_short_cint_operand" "")))
11258    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
11259   "find_single_use (operands[0], insn, 0)
11260    && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
11261        || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
11262   [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
11263    (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
11264   "
11265 {
11266   /* Get the constant we are comparing against, C,  and see what it looks like
11267      sign-extended to 16 bits.  Then see what constant could be XOR'ed
11268      with C to get the sign-extended value.  */
11269
11270   HOST_WIDE_INT c = INTVAL (operands[2]);
11271   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
11272   HOST_WIDE_INT xorv = c ^ sextc;
11273
11274   operands[4] = GEN_INT (xorv);
11275   operands[5] = GEN_INT (sextc);
11276 }")
11277
11278 (define_insn "*cmpsi_internal2"
11279   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11280         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11281                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
11282   ""
11283   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
11284   [(set_attr "type" "cmp")])
11285
11286 (define_insn "*cmpdi_internal2"
11287   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11288         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
11289                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
11290   ""
11291   "cmpld%I2 %0,%1,%b2"
11292   [(set_attr "type" "cmp")])
11293
11294 ;; The following two insns don't exist as single insns, but if we provide
11295 ;; them, we can swap an add and compare, which will enable us to overlap more
11296 ;; of the required delay between a compare and branch.  We generate code for
11297 ;; them by splitting.
11298
11299 (define_insn ""
11300   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11301         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11302                     (match_operand:SI 2 "short_cint_operand" "i")))
11303    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11304         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11305   ""
11306   "#"
11307   [(set_attr "length" "8")])
11308
11309 (define_insn ""
11310   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
11311         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11312                        (match_operand:SI 2 "u_short_cint_operand" "i")))
11313    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11314         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11315   ""
11316   "#"
11317   [(set_attr "length" "8")])
11318
11319 (define_split
11320   [(set (match_operand:CC 3 "cc_reg_operand" "")
11321         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11322                     (match_operand:SI 2 "short_cint_operand" "")))
11323    (set (match_operand:SI 0 "gpc_reg_operand" "")
11324         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11325   ""
11326   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
11327    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11328
11329 (define_split
11330   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
11331         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
11332                        (match_operand:SI 2 "u_short_cint_operand" "")))
11333    (set (match_operand:SI 0 "gpc_reg_operand" "")
11334         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11335   ""
11336   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
11337    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11338
11339 (define_insn "*cmpsf_internal1"
11340   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11341         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
11342                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
11343   "TARGET_HARD_FLOAT && TARGET_FPRS"
11344   "fcmpu %0,%1,%2"
11345   [(set_attr "type" "fpcompare")])
11346
11347 (define_insn "*cmpdf_internal1"
11348   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11349         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
11350                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
11351   "TARGET_HARD_FLOAT && TARGET_FPRS"
11352   "fcmpu %0,%1,%2"
11353   [(set_attr "type" "fpcompare")])
11354
11355 ;; Only need to compare second words if first words equal
11356 (define_insn "*cmptf_internal1"
11357   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11358         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11359                       (match_operand:TF 2 "gpc_reg_operand" "f")))]
11360   "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
11361    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
11362   "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
11363   [(set_attr "type" "fpcompare")
11364    (set_attr "length" "12")])
11365 \f
11366 ;; Now we have the scc insns.  We can do some combinations because of the
11367 ;; way the machine works.
11368 ;;
11369 ;; Note that this is probably faster if we can put an insn between the
11370 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
11371 ;; cases the insns below which don't use an intermediate CR field will
11372 ;; be used instead.
11373 (define_insn ""
11374   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11375         (match_operator:SI 1 "scc_comparison_operator"
11376                            [(match_operand 2 "cc_reg_operand" "y")
11377                             (const_int 0)]))]
11378   ""
11379   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11380   [(set (attr "type")
11381      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11382                 (const_string "mfcrf")
11383            ]
11384         (const_string "mfcr")))
11385    (set_attr "length" "8")])
11386
11387 ;; Same as above, but get the GT bit.
11388 (define_insn "move_from_CR_eq_bit"
11389   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11390         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_EQ))]
11391   "TARGET_E500"
11392   "mfcr %0\;{rlinm|rlwinm} %0,%0,%D1,1"
11393   [(set_attr "type" "mfcr")
11394    (set_attr "length" "8")])
11395
11396 ;; Same as above, but get the OV/ORDERED bit.
11397 (define_insn "move_from_CR_ov_bit"
11398   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11399         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] UNSPEC_MV_CR_OV))]
11400   "TARGET_ISEL"
11401   "mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
11402   [(set_attr "type" "mfcr")
11403    (set_attr "length" "8")])
11404
11405 (define_insn ""
11406   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11407         (match_operator:DI 1 "scc_comparison_operator"
11408                            [(match_operand 2 "cc_reg_operand" "y")
11409                             (const_int 0)]))]
11410   "TARGET_POWERPC64"
11411   "mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%J1,1"
11412   [(set (attr "type")
11413      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11414                 (const_string "mfcrf")
11415            ]
11416         (const_string "mfcr")))
11417    (set_attr "length" "8")])
11418
11419 (define_insn ""
11420   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11421         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11422                                        [(match_operand 2 "cc_reg_operand" "y,y")
11423                                         (const_int 0)])
11424                     (const_int 0)))
11425    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11426         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11427   "TARGET_32BIT"
11428   "@
11429    mfcr %3%Q2\;{rlinm.|rlwinm.} %3,%3,%J1,1
11430    #"
11431   [(set_attr "type" "delayed_compare")
11432    (set_attr "length" "8,16")])
11433
11434 (define_split
11435   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11436         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11437                                        [(match_operand 2 "cc_reg_operand" "")
11438                                         (const_int 0)])
11439                     (const_int 0)))
11440    (set (match_operand:SI 3 "gpc_reg_operand" "")
11441         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11442   "TARGET_32BIT && reload_completed"
11443   [(set (match_dup 3)
11444         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
11445    (set (match_dup 0)
11446         (compare:CC (match_dup 3)
11447                     (const_int 0)))]
11448   "")
11449
11450 (define_insn ""
11451   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11452         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11453                                       [(match_operand 2 "cc_reg_operand" "y")
11454                                        (const_int 0)])
11455                    (match_operand:SI 3 "const_int_operand" "n")))]
11456   ""
11457   "*
11458 {
11459   int is_bit = ccr_bit (operands[1], 1);
11460   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11461   int count;
11462
11463   if (is_bit >= put_bit)
11464     count = is_bit - put_bit;
11465   else
11466     count = 32 - (put_bit - is_bit);
11467
11468   operands[4] = GEN_INT (count);
11469   operands[5] = GEN_INT (put_bit);
11470
11471   return \"mfcr %0%Q2\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
11472 }"
11473   [(set (attr "type")
11474      (cond [(ne (symbol_ref "TARGET_MFCRF") (const_int 0))
11475                 (const_string "mfcrf")
11476            ]
11477         (const_string "mfcr")))
11478    (set_attr "length" "8")])
11479
11480 (define_insn ""
11481   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11482         (compare:CC
11483          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11484                                        [(match_operand 2 "cc_reg_operand" "y,y")
11485                                         (const_int 0)])
11486                     (match_operand:SI 3 "const_int_operand" "n,n"))
11487          (const_int 0)))
11488    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
11489         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11490                    (match_dup 3)))]
11491   ""
11492   "*
11493 {
11494   int is_bit = ccr_bit (operands[1], 1);
11495   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11496   int count;
11497
11498   /* Force split for non-cc0 compare.  */
11499   if (which_alternative == 1)
11500      return \"#\";
11501
11502   if (is_bit >= put_bit)
11503     count = is_bit - put_bit;
11504   else
11505     count = 32 - (put_bit - is_bit);
11506
11507   operands[5] = GEN_INT (count);
11508   operands[6] = GEN_INT (put_bit);
11509
11510   return \"mfcr %4%Q2\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
11511 }"
11512   [(set_attr "type" "delayed_compare")
11513    (set_attr "length" "8,16")])
11514
11515 (define_split
11516   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11517         (compare:CC
11518          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11519                                        [(match_operand 2 "cc_reg_operand" "")
11520                                         (const_int 0)])
11521                     (match_operand:SI 3 "const_int_operand" ""))
11522          (const_int 0)))
11523    (set (match_operand:SI 4 "gpc_reg_operand" "")
11524         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11525                    (match_dup 3)))]
11526   "reload_completed"
11527   [(set (match_dup 4)
11528         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11529                    (match_dup 3)))
11530    (set (match_dup 0)
11531         (compare:CC (match_dup 4)
11532                     (const_int 0)))]
11533   "")
11534
11535 ;; There is a 3 cycle delay between consecutive mfcr instructions
11536 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
11537
11538 (define_peephole
11539   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11540         (match_operator:SI 1 "scc_comparison_operator"
11541                            [(match_operand 2 "cc_reg_operand" "y")
11542                             (const_int 0)]))
11543    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
11544         (match_operator:SI 4 "scc_comparison_operator"
11545                            [(match_operand 5 "cc_reg_operand" "y")
11546                             (const_int 0)]))]
11547   "REGNO (operands[2]) != REGNO (operands[5])"
11548   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11549   [(set_attr "type" "mfcr")
11550    (set_attr "length" "12")])
11551
11552 (define_peephole
11553   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11554         (match_operator:DI 1 "scc_comparison_operator"
11555                            [(match_operand 2 "cc_reg_operand" "y")
11556                             (const_int 0)]))
11557    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
11558         (match_operator:DI 4 "scc_comparison_operator"
11559                            [(match_operand 5 "cc_reg_operand" "y")
11560                             (const_int 0)]))]
11561   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
11562   "mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11563   [(set_attr "type" "mfcr")
11564    (set_attr "length" "12")])
11565
11566 ;; There are some scc insns that can be done directly, without a compare.
11567 ;; These are faster because they don't involve the communications between
11568 ;; the FXU and branch units.   In fact, we will be replacing all of the
11569 ;; integer scc insns here or in the portable methods in emit_store_flag.
11570 ;;
11571 ;; Also support (neg (scc ..)) since that construct is used to replace
11572 ;; branches, (plus (scc ..) ..) since that construct is common and
11573 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
11574 ;; cases where it is no more expensive than (neg (scc ..)).
11575
11576 ;; Have reload force a constant into a register for the simple insns that
11577 ;; otherwise won't accept constants.  We do this because it is faster than
11578 ;; the cmp/mfcr sequence we would otherwise generate.
11579
11580 (define_insn ""
11581   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11582         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11583                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
11584    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
11585   "TARGET_32BIT"
11586   "@
11587    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11588    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
11589    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11590    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11591    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
11592   [(set_attr "type" "three,two,three,three,three")
11593    (set_attr "length" "12,8,12,12,12")])
11594
11595 (define_insn ""
11596   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r")
11597         (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r")
11598                (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I")))
11599    (clobber (match_scratch:DI 3 "=r,&r,r,r,r"))]
11600   "TARGET_64BIT"
11601   "@
11602    xor %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0
11603    subfic %3,%1,0\;adde %0,%3,%1
11604    xori %0,%1,%b2\;subfic %3,%0,0\;adde %0,%3,%0
11605    xoris %0,%1,%u2\;subfic %3,%0,0\;adde %0,%3,%0
11606    subfic %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0"
11607   [(set_attr "type" "three,two,three,three,three")
11608    (set_attr "length" "12,8,12,12,12")])
11609
11610 (define_insn ""
11611   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11612         (compare:CC
11613          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11614                 (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11615          (const_int 0)))
11616    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11617         (eq:SI (match_dup 1) (match_dup 2)))
11618    (clobber (match_scratch:SI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11619   "TARGET_32BIT"
11620   "@
11621    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11622    {sfi|subfic} %3,%1,0\;{ae.|adde.} %0,%3,%1
11623    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11624    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11625    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11626    #
11627    #
11628    #
11629    #
11630    #"
11631   [(set_attr "type" "compare")
11632    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11633
11634 (define_split
11635   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11636         (compare:CC
11637          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11638                 (match_operand:SI 2 "reg_or_cint_operand" ""))
11639          (const_int 0)))
11640    (set (match_operand:SI 0 "gpc_reg_operand" "")
11641         (eq:SI (match_dup 1) (match_dup 2)))
11642    (clobber (match_scratch:SI 3 ""))]
11643   "TARGET_32BIT && reload_completed"
11644   [(parallel [(set (match_dup 0)
11645         (eq:SI (match_dup 1) (match_dup 2)))
11646    (clobber (match_dup 3))])
11647    (set (match_dup 4)
11648         (compare:CC (match_dup 0)
11649                     (const_int 0)))]
11650   "")
11651
11652 (define_insn ""
11653   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11654         (compare:CC
11655          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11656                 (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I,r,O,K,J,I"))
11657          (const_int 0)))
11658    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11659         (eq:DI (match_dup 1) (match_dup 2)))
11660    (clobber (match_scratch:DI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11661   "TARGET_64BIT"
11662   "@
11663    xor %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11664    subfic %3,%1,0\;adde. %0,%3,%1
11665    xori %0,%1,%b2\;subfic %3,%0,0\;adde. %0,%3,%0
11666    xoris %0,%1,%u2\;subfic %3,%0,0\;adde. %0,%3,%0
11667    subfic %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11668    #
11669    #
11670    #
11671    #
11672    #"
11673   [(set_attr "type" "compare")
11674    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11675
11676 (define_split
11677   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11678         (compare:CC
11679          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "")
11680                 (match_operand:DI 2 "reg_or_cint_operand" ""))
11681          (const_int 0)))
11682    (set (match_operand:DI 0 "gpc_reg_operand" "")
11683         (eq:DI (match_dup 1) (match_dup 2)))
11684    (clobber (match_scratch:DI 3 ""))]
11685   "TARGET_64BIT && reload_completed"
11686   [(parallel [(set (match_dup 0)
11687         (eq:DI (match_dup 1) (match_dup 2)))
11688    (clobber (match_dup 3))])
11689    (set (match_dup 4)
11690         (compare:CC (match_dup 0)
11691                     (const_int 0)))]
11692   "")
11693
11694 ;; We have insns of the form shown by the first define_insn below.  If
11695 ;; there is something inside the comparison operation, we must split it.
11696 (define_split
11697   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11698         (plus:SI (match_operator 1 "comparison_operator"
11699                                  [(match_operand:SI 2 "" "")
11700                                   (match_operand:SI 3
11701                                                     "reg_or_cint_operand" "")])
11702                  (match_operand:SI 4 "gpc_reg_operand" "")))
11703    (clobber (match_operand:SI 5 "register_operand" ""))]
11704   "! gpc_reg_operand (operands[2], SImode)"
11705   [(set (match_dup 5) (match_dup 2))
11706    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
11707                                (match_dup 4)))])
11708
11709 (define_insn ""
11710   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
11711         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11712                         (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))
11713                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
11714   "TARGET_32BIT"
11715   "@
11716    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11717    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
11718    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11719    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11720    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
11721   [(set_attr "type" "three,two,three,three,three")
11722    (set_attr "length" "12,8,12,12,12")])
11723
11724 (define_insn ""
11725   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11726         (compare:CC
11727          (plus:SI
11728           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11729                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11730           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11731          (const_int 0)))
11732    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
11733   "TARGET_32BIT"
11734   "@
11735    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11736    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
11737    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11738    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11739    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11740    #
11741    #
11742    #
11743    #
11744    #"
11745   [(set_attr "type" "compare")
11746    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11747
11748 (define_split
11749   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11750         (compare:CC
11751          (plus:SI
11752           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11753                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11754           (match_operand:SI 3 "gpc_reg_operand" ""))
11755          (const_int 0)))
11756    (clobber (match_scratch:SI 4 ""))]
11757   "TARGET_32BIT && reload_completed"
11758   [(set (match_dup 4)
11759         (plus:SI (eq:SI (match_dup 1)
11760                  (match_dup 2))
11761           (match_dup 3)))
11762    (set (match_dup 0)
11763         (compare:CC (match_dup 4)
11764                     (const_int 0)))]
11765   "")
11766
11767 (define_insn ""
11768   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11769         (compare:CC
11770          (plus:SI
11771           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11772                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11773           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11774          (const_int 0)))
11775    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
11776         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11777   "TARGET_32BIT"
11778   "@
11779    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11780    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
11781    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11782    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11783    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11784    #
11785    #
11786    #
11787    #
11788    #"
11789   [(set_attr "type" "compare")
11790    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11791
11792 (define_split
11793   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11794         (compare:CC
11795          (plus:SI
11796           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11797                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11798           (match_operand:SI 3 "gpc_reg_operand" ""))
11799          (const_int 0)))
11800    (set (match_operand:SI 0 "gpc_reg_operand" "")
11801         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11802   "TARGET_32BIT && reload_completed"
11803   [(set (match_dup 0)
11804         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
11805    (set (match_dup 4)
11806         (compare:CC (match_dup 0)
11807                     (const_int 0)))]
11808   "")
11809
11810 (define_insn ""
11811   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11812         (neg:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11813                        (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))))]
11814   "TARGET_32BIT"
11815   "@
11816    xor %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11817    {ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0
11818    {xoril|xori} %0,%1,%b2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11819    {xoriu|xoris} %0,%1,%u2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11820    {sfi|subfic} %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
11821    [(set_attr "type" "three,two,three,three,three")
11822     (set_attr "length" "12,8,12,12,12")])
11823
11824 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
11825 ;; since it nabs/sr is just as fast.
11826 (define_insn "*ne0"
11827   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
11828         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11829                      (const_int 31)))
11830    (clobber (match_scratch:SI 2 "=&r"))]
11831   "! TARGET_POWER && TARGET_32BIT && !TARGET_ISEL"
11832   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
11833   [(set_attr "type" "two")
11834    (set_attr "length" "8")])
11835
11836 (define_insn ""
11837   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11838         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11839                      (const_int 63)))
11840    (clobber (match_scratch:DI 2 "=&r"))]
11841   "TARGET_64BIT"
11842   "addic %2,%1,-1\;subfe %0,%2,%1"
11843   [(set_attr "type" "two")
11844    (set_attr "length" "8")])
11845
11846 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
11847 (define_insn ""
11848   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11849         (plus:SI (lshiftrt:SI
11850                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11851                   (const_int 31))
11852                  (match_operand:SI 2 "gpc_reg_operand" "r")))
11853    (clobber (match_scratch:SI 3 "=&r"))]
11854   "TARGET_32BIT"
11855   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
11856   [(set_attr "type" "two")
11857    (set_attr "length" "8")])
11858
11859 (define_insn ""
11860   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11861         (plus:DI (lshiftrt:DI
11862                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11863                   (const_int 63))
11864                  (match_operand:DI 2 "gpc_reg_operand" "r")))
11865    (clobber (match_scratch:DI 3 "=&r"))]
11866   "TARGET_64BIT"
11867   "addic %3,%1,-1\;addze %0,%2"
11868   [(set_attr "type" "two")
11869    (set_attr "length" "8")])
11870
11871 (define_insn ""
11872   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11873         (compare:CC
11874          (plus:SI (lshiftrt:SI
11875                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11876                    (const_int 31))
11877                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11878          (const_int 0)))
11879    (clobber (match_scratch:SI 3 "=&r,&r"))
11880    (clobber (match_scratch:SI 4 "=X,&r"))]
11881   "TARGET_32BIT"
11882   "@
11883    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
11884    #"
11885   [(set_attr "type" "compare")
11886    (set_attr "length" "8,12")])
11887
11888 (define_split
11889   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11890         (compare:CC
11891          (plus:SI (lshiftrt:SI
11892                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11893                    (const_int 31))
11894                   (match_operand:SI 2 "gpc_reg_operand" ""))
11895          (const_int 0)))
11896    (clobber (match_scratch:SI 3 ""))
11897    (clobber (match_scratch:SI 4 ""))]
11898   "TARGET_32BIT && reload_completed"
11899   [(parallel [(set (match_dup 3)
11900                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
11901                                          (const_int 31))
11902                             (match_dup 2)))
11903               (clobber (match_dup 4))])
11904    (set (match_dup 0)
11905         (compare:CC (match_dup 3)
11906                     (const_int 0)))]
11907   "")
11908
11909 (define_insn ""
11910   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11911         (compare:CC
11912          (plus:DI (lshiftrt:DI
11913                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11914                    (const_int 63))
11915                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11916          (const_int 0)))
11917    (clobber (match_scratch:DI 3 "=&r,&r"))]
11918   "TARGET_64BIT"
11919   "@
11920    addic %3,%1,-1\;addze. %3,%2
11921    #"
11922   [(set_attr "type" "compare")
11923    (set_attr "length" "8,12")])
11924
11925 (define_split
11926   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11927         (compare:CC
11928          (plus:DI (lshiftrt:DI
11929                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11930                    (const_int 63))
11931                   (match_operand:DI 2 "gpc_reg_operand" ""))
11932          (const_int 0)))
11933    (clobber (match_scratch:DI 3 ""))]
11934   "TARGET_64BIT && reload_completed"
11935   [(set (match_dup 3)
11936         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
11937                    (const_int 63))
11938                   (match_dup 2)))
11939    (set (match_dup 0)
11940         (compare:CC (match_dup 3)
11941                     (const_int 0)))]
11942   "")
11943
11944 (define_insn ""
11945   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11946         (compare:CC
11947          (plus:SI (lshiftrt:SI
11948                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11949                    (const_int 31))
11950                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11951          (const_int 0)))
11952    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11953         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11954                  (match_dup 2)))
11955    (clobber (match_scratch:SI 3 "=&r,&r"))]
11956   "TARGET_32BIT"
11957   "@
11958    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
11959    #"
11960   [(set_attr "type" "compare")
11961    (set_attr "length" "8,12")])
11962
11963 (define_split
11964   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11965         (compare:CC
11966          (plus:SI (lshiftrt:SI
11967                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11968                    (const_int 31))
11969                   (match_operand:SI 2 "gpc_reg_operand" ""))
11970          (const_int 0)))
11971    (set (match_operand:SI 0 "gpc_reg_operand" "")
11972         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11973                  (match_dup 2)))
11974    (clobber (match_scratch:SI 3 ""))]
11975   "TARGET_32BIT && reload_completed"
11976   [(parallel [(set (match_dup 0)
11977         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11978                  (match_dup 2)))
11979    (clobber (match_dup 3))])
11980    (set (match_dup 4)
11981         (compare:CC (match_dup 0)
11982                     (const_int 0)))]
11983   "")
11984
11985 (define_insn ""
11986   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11987         (compare:CC
11988          (plus:DI (lshiftrt:DI
11989                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11990                    (const_int 63))
11991                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11992          (const_int 0)))
11993    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
11994         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11995                  (match_dup 2)))
11996    (clobber (match_scratch:DI 3 "=&r,&r"))]
11997   "TARGET_64BIT"
11998   "@
11999    addic %3,%1,-1\;addze. %0,%2
12000    #"
12001   [(set_attr "type" "compare")
12002    (set_attr "length" "8,12")])
12003
12004 (define_split
12005   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12006         (compare:CC
12007          (plus:DI (lshiftrt:DI
12008                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
12009                    (const_int 63))
12010                   (match_operand:DI 2 "gpc_reg_operand" ""))
12011          (const_int 0)))
12012    (set (match_operand:DI 0 "gpc_reg_operand" "")
12013         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12014                  (match_dup 2)))
12015    (clobber (match_scratch:DI 3 ""))]
12016   "TARGET_64BIT && reload_completed"
12017   [(parallel [(set (match_dup 0)
12018         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
12019                  (match_dup 2)))
12020    (clobber (match_dup 3))])
12021    (set (match_dup 4)
12022         (compare:CC (match_dup 0)
12023                     (const_int 0)))]
12024   "")
12025
12026 (define_insn ""
12027   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12028         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12029                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
12030    (clobber (match_scratch:SI 3 "=r,X"))]
12031   "TARGET_POWER"
12032   "@
12033    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
12034    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
12035   [(set_attr "length" "12")])
12036
12037 (define_insn ""
12038   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12039         (compare:CC
12040          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12041                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12042          (const_int 0)))
12043    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12044         (le:SI (match_dup 1) (match_dup 2)))
12045    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
12046   "TARGET_POWER"
12047   "@
12048    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12049    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
12050    #
12051    #"
12052   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
12053    (set_attr "length" "12,12,16,16")])
12054
12055 (define_split
12056   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12057         (compare:CC
12058          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12059                 (match_operand:SI 2 "reg_or_short_operand" ""))
12060          (const_int 0)))
12061    (set (match_operand:SI 0 "gpc_reg_operand" "")
12062         (le:SI (match_dup 1) (match_dup 2)))
12063    (clobber (match_scratch:SI 3 ""))]
12064   "TARGET_POWER && reload_completed"
12065   [(parallel [(set (match_dup 0)
12066         (le:SI (match_dup 1) (match_dup 2)))
12067    (clobber (match_dup 3))])
12068    (set (match_dup 4)
12069         (compare:CC (match_dup 0)
12070                     (const_int 0)))]
12071   "")
12072
12073 (define_insn ""
12074   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12075         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12076                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
12077                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12078   "TARGET_POWER"
12079   "@
12080    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
12081    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
12082   [(set_attr "length" "12")])
12083
12084 (define_insn ""
12085   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12086         (compare:CC
12087          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12088                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12089                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12090          (const_int 0)))
12091    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12092   "TARGET_POWER"
12093   "@
12094    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12095    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
12096    #
12097    #"
12098   [(set_attr "type" "compare")
12099    (set_attr "length" "12,12,16,16")])
12100
12101 (define_split
12102   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12103         (compare:CC
12104          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12105                          (match_operand:SI 2 "reg_or_short_operand" ""))
12106                   (match_operand:SI 3 "gpc_reg_operand" ""))
12107          (const_int 0)))
12108    (clobber (match_scratch:SI 4 ""))]
12109   "TARGET_POWER && reload_completed"
12110   [(set (match_dup 4)
12111         (plus:SI (le:SI (match_dup 1) (match_dup 2))
12112                  (match_dup 3)))
12113    (set (match_dup 0)
12114         (compare:CC (match_dup 4)
12115                     (const_int 0)))]
12116   "")
12117
12118 (define_insn ""
12119   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12120         (compare:CC
12121          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12122                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
12123                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12124          (const_int 0)))
12125    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12126         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12127   "TARGET_POWER"
12128   "@
12129    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12130    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
12131    #
12132    #"
12133   [(set_attr "type" "compare")
12134    (set_attr "length" "12,12,16,16")])
12135
12136 (define_split
12137   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12138         (compare:CC
12139          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
12140                          (match_operand:SI 2 "reg_or_short_operand" ""))
12141                   (match_operand:SI 3 "gpc_reg_operand" ""))
12142          (const_int 0)))
12143    (set (match_operand:SI 0 "gpc_reg_operand" "")
12144         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12145   "TARGET_POWER && reload_completed"
12146   [(set (match_dup 0)
12147         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12148    (set (match_dup 4)
12149         (compare:CC (match_dup 0)
12150                     (const_int 0)))]
12151   "")
12152
12153 (define_insn ""
12154   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12155         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12156                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
12157   "TARGET_POWER"
12158   "@
12159    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
12160    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
12161   [(set_attr "length" "12")])
12162
12163 (define_insn ""
12164   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12165         (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12166                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12167   "TARGET_32BIT"
12168   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12169   [(set_attr "type" "three")
12170    (set_attr "length" "12")])
12171
12172 (define_insn ""
12173   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12174         (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
12175                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
12176   "TARGET_64BIT"
12177   "subf%I2c %0,%1,%2\;li %0,0\;adde %0,%0,%0"
12178   [(set_attr "type" "three")
12179    (set_attr "length" "12")])
12180
12181 (define_insn ""
12182   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12183         (compare:CC
12184          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12185                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
12186          (const_int 0)))
12187    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12188         (leu:DI (match_dup 1) (match_dup 2)))]
12189   "TARGET_64BIT"
12190   "@
12191    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
12192    #"
12193   [(set_attr "type" "compare")
12194    (set_attr "length" "12,16")])
12195
12196 (define_split
12197   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12198         (compare:CC
12199          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12200                  (match_operand:DI 2 "reg_or_short_operand" ""))
12201          (const_int 0)))
12202    (set (match_operand:DI 0 "gpc_reg_operand" "")
12203         (leu:DI (match_dup 1) (match_dup 2)))]
12204   "TARGET_64BIT && reload_completed"
12205   [(set (match_dup 0)
12206         (leu:DI (match_dup 1) (match_dup 2)))
12207    (set (match_dup 3)
12208         (compare:CC (match_dup 0)
12209                     (const_int 0)))]
12210   "")
12211
12212 (define_insn ""
12213   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12214         (compare:CC
12215          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12216                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12217          (const_int 0)))
12218    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12219         (leu:SI (match_dup 1) (match_dup 2)))]
12220   "TARGET_32BIT"
12221   "@
12222    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12223    #"
12224   [(set_attr "type" "compare")
12225    (set_attr "length" "12,16")])
12226
12227 (define_split
12228   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12229         (compare:CC
12230          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12231                  (match_operand:SI 2 "reg_or_short_operand" ""))
12232          (const_int 0)))
12233    (set (match_operand:SI 0 "gpc_reg_operand" "")
12234         (leu:SI (match_dup 1) (match_dup 2)))]
12235   "TARGET_32BIT && reload_completed"
12236   [(set (match_dup 0)
12237         (leu:SI (match_dup 1) (match_dup 2)))
12238    (set (match_dup 3)
12239         (compare:CC (match_dup 0)
12240                     (const_int 0)))]
12241   "")
12242
12243 (define_insn ""
12244   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12245         (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12246                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
12247                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12248   "TARGET_32BIT"
12249   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
12250   [(set_attr "type" "two")
12251    (set_attr "length" "8")])
12252
12253 (define_insn ""
12254   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12255         (compare:CC
12256          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12257                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12258                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12259          (const_int 0)))
12260    (clobber (match_scratch:SI 4 "=&r,&r"))]
12261   "TARGET_32BIT"
12262   "@
12263    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
12264    #"
12265   [(set_attr "type" "compare")
12266    (set_attr "length" "8,12")])
12267
12268 (define_split
12269   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12270         (compare:CC
12271          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12272                           (match_operand:SI 2 "reg_or_short_operand" ""))
12273                   (match_operand:SI 3 "gpc_reg_operand" ""))
12274          (const_int 0)))
12275    (clobber (match_scratch:SI 4 ""))]
12276   "TARGET_32BIT && reload_completed"
12277   [(set (match_dup 4)
12278         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12279                   (match_dup 3)))
12280    (set (match_dup 0)
12281         (compare:CC (match_dup 4)
12282                     (const_int 0)))]
12283   "")
12284
12285 (define_insn ""
12286   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12287         (compare:CC
12288          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12289                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12290                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12291          (const_int 0)))
12292    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12293         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12294   "TARGET_32BIT"
12295   "@
12296    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
12297    #"
12298   [(set_attr "type" "compare")
12299    (set_attr "length" "8,12")])
12300
12301 (define_split
12302   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12303         (compare:CC
12304          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12305                           (match_operand:SI 2 "reg_or_short_operand" ""))
12306                   (match_operand:SI 3 "gpc_reg_operand" ""))
12307          (const_int 0)))
12308    (set (match_operand:SI 0 "gpc_reg_operand" "")
12309         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12310   "TARGET_32BIT && reload_completed"
12311   [(set (match_dup 0)
12312         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12313    (set (match_dup 4)
12314         (compare:CC (match_dup 0)
12315                     (const_int 0)))]
12316   "")
12317
12318 (define_insn ""
12319   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12320         (neg:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12321                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12322   "TARGET_32BIT"
12323   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
12324    [(set_attr "type" "three")
12325     (set_attr "length" "12")])
12326
12327 (define_insn ""
12328   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12329         (and:SI (neg:SI
12330                  (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12331                          (match_operand:SI 2 "reg_or_short_operand" "rI")))
12332                 (match_operand:SI 3 "gpc_reg_operand" "r")))]
12333   "TARGET_32BIT"
12334   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12335   [(set_attr "type" "three")
12336    (set_attr "length" "12")])
12337
12338 (define_insn ""
12339   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12340         (compare:CC
12341          (and:SI (neg:SI
12342                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12343                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12344                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12345          (const_int 0)))
12346    (clobber (match_scratch:SI 4 "=&r,&r"))]
12347   "TARGET_32BIT"
12348   "@
12349    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12350    #"
12351   [(set_attr "type" "compare")
12352    (set_attr "length" "12,16")])
12353
12354 (define_split
12355   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12356         (compare:CC
12357          (and:SI (neg:SI
12358                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12359                           (match_operand:SI 2 "reg_or_short_operand" "")))
12360                  (match_operand:SI 3 "gpc_reg_operand" ""))
12361          (const_int 0)))
12362    (clobber (match_scratch:SI 4 ""))]
12363   "TARGET_32BIT && reload_completed"
12364   [(set (match_dup 4)
12365         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12366                 (match_dup 3)))
12367    (set (match_dup 0)
12368         (compare:CC (match_dup 4)
12369                     (const_int 0)))]
12370   "")
12371
12372 (define_insn ""
12373   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12374         (compare:CC
12375          (and:SI (neg:SI
12376                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12377                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12378                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12379          (const_int 0)))
12380    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12381         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12382   "TARGET_32BIT"
12383   "@
12384    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12385    #"
12386   [(set_attr "type" "compare")
12387    (set_attr "length" "12,16")])
12388
12389 (define_split
12390   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12391         (compare:CC
12392          (and:SI (neg:SI
12393                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12394                           (match_operand:SI 2 "reg_or_short_operand" "")))
12395                  (match_operand:SI 3 "gpc_reg_operand" ""))
12396          (const_int 0)))
12397    (set (match_operand:SI 0 "gpc_reg_operand" "")
12398         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12399   "TARGET_32BIT && reload_completed"
12400   [(set (match_dup 0)
12401         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12402                 (match_dup 3)))
12403    (set (match_dup 4)
12404         (compare:CC (match_dup 0)
12405                     (const_int 0)))]
12406   "")
12407
12408 (define_insn ""
12409   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12410         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12411                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12412   "TARGET_POWER"
12413   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
12414    [(set_attr "length" "12")])
12415
12416 (define_insn ""
12417   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12418         (compare:CC
12419          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12420                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12421          (const_int 0)))
12422    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12423         (lt:SI (match_dup 1) (match_dup 2)))]
12424   "TARGET_POWER"
12425   "@
12426    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
12427    #"
12428   [(set_attr "type" "delayed_compare")
12429    (set_attr "length" "12,16")])
12430
12431 (define_split
12432   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12433         (compare:CC
12434          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12435                 (match_operand:SI 2 "reg_or_short_operand" ""))
12436          (const_int 0)))
12437    (set (match_operand:SI 0 "gpc_reg_operand" "")
12438         (lt:SI (match_dup 1) (match_dup 2)))]
12439   "TARGET_POWER && reload_completed"
12440   [(set (match_dup 0)
12441         (lt:SI (match_dup 1) (match_dup 2)))
12442    (set (match_dup 3)
12443         (compare:CC (match_dup 0)
12444                     (const_int 0)))]
12445   "")
12446
12447 (define_insn ""
12448   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12449         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12450                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12451                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12452   "TARGET_POWER"
12453   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
12454   [(set_attr "length" "12")])
12455
12456 (define_insn ""
12457   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12458         (compare:CC
12459          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12460                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12461                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12462          (const_int 0)))
12463    (clobber (match_scratch:SI 4 "=&r,&r"))]
12464   "TARGET_POWER"
12465   "@
12466    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
12467    #"
12468   [(set_attr "type" "compare")
12469    (set_attr "length" "12,16")])
12470
12471 (define_split
12472   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12473         (compare:CC
12474          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12475                          (match_operand:SI 2 "reg_or_short_operand" ""))
12476                   (match_operand:SI 3 "gpc_reg_operand" ""))
12477          (const_int 0)))
12478    (clobber (match_scratch:SI 4 ""))]
12479   "TARGET_POWER && reload_completed"
12480   [(set (match_dup 4)
12481         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
12482                  (match_dup 3)))
12483    (set (match_dup 0)
12484         (compare:CC (match_dup 4)
12485                     (const_int 0)))]
12486   "")
12487
12488 (define_insn ""
12489   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12490         (compare:CC
12491          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12492                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12493                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12494          (const_int 0)))
12495    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12496         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12497   "TARGET_POWER"
12498   "@
12499    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
12500    #"
12501   [(set_attr "type" "compare")
12502    (set_attr "length" "12,16")])
12503
12504 (define_split
12505   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12506         (compare:CC
12507          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12508                          (match_operand:SI 2 "reg_or_short_operand" ""))
12509                   (match_operand:SI 3 "gpc_reg_operand" ""))
12510          (const_int 0)))
12511    (set (match_operand:SI 0 "gpc_reg_operand" "")
12512         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12513   "TARGET_POWER && reload_completed"
12514   [(set (match_dup 0)
12515         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12516    (set (match_dup 4)
12517         (compare:CC (match_dup 0)
12518                     (const_int 0)))]
12519   "")
12520
12521 (define_insn ""
12522   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12523         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12524                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12525   "TARGET_POWER"
12526   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
12527   [(set_attr "length" "12")])
12528
12529 (define_insn_and_split ""
12530   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12531         (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12532                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12533   "TARGET_32BIT"
12534   "#"
12535   "TARGET_32BIT"
12536   [(set (match_dup 0) (neg:SI (ltu:SI (match_dup 1) (match_dup 2))))
12537    (set (match_dup 0) (neg:SI (match_dup 0)))]
12538   "")
12539
12540 (define_insn_and_split ""
12541   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12542         (ltu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12543                 (match_operand:DI 2 "reg_or_neg_short_operand" "r,P")))]
12544   "TARGET_64BIT"
12545   "#"
12546   "TARGET_64BIT"
12547   [(set (match_dup 0) (neg:DI (ltu:DI (match_dup 1) (match_dup 2))))
12548    (set (match_dup 0) (neg:DI (match_dup 0)))]
12549   "")
12550
12551 (define_insn ""
12552   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12553         (compare:CC
12554          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12555                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12556          (const_int 0)))
12557    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12558         (ltu:SI (match_dup 1) (match_dup 2)))]
12559   "TARGET_32BIT"
12560   "@
12561    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12562    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12563    #
12564    #"
12565   [(set_attr "type" "compare")
12566    (set_attr "length" "12,12,16,16")])
12567
12568 (define_split
12569   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12570         (compare:CC
12571          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12572                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12573          (const_int 0)))
12574    (set (match_operand:SI 0 "gpc_reg_operand" "")
12575         (ltu:SI (match_dup 1) (match_dup 2)))]
12576   "TARGET_32BIT && reload_completed"
12577   [(set (match_dup 0)
12578         (ltu:SI (match_dup 1) (match_dup 2)))
12579    (set (match_dup 3)
12580         (compare:CC (match_dup 0)
12581                     (const_int 0)))]
12582   "")
12583
12584 (define_insn_and_split ""
12585   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12586         (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12587                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12588                  (match_operand:SI 3 "reg_or_short_operand" "rI,rI")))]
12589   "TARGET_32BIT"
12590   "#"
12591   "TARGET_32BIT"
12592   [(set (match_dup 0) (neg:SI (ltu:SI (match_dup 1) (match_dup 2))))
12593    (set (match_dup 0) (minus:SI (match_dup 3) (match_dup 0)))]
12594   "")
12595
12596 (define_insn_and_split ""
12597   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12598         (plus:DI (ltu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12599                          (match_operand:DI 2 "reg_or_neg_short_operand" "r,P"))
12600                  (match_operand:DI 3 "reg_or_short_operand" "rI,rI")))]
12601   "TARGET_64BIT"
12602   "#"
12603   "TARGET_64BIT"
12604   [(set (match_dup 0) (neg:DI (ltu:DI (match_dup 1) (match_dup 2))))
12605    (set (match_dup 0) (minus:DI (match_dup 3) (match_dup 0)))]
12606   "")
12607
12608 (define_insn ""
12609   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12610         (compare:CC
12611          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12612                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12613                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12614          (const_int 0)))
12615    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12616   "TARGET_32BIT"
12617   "@
12618    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subf.} %4,%4,%3
12619    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subf.} %4,%4,%3
12620    #
12621    #"
12622   [(set_attr "type" "compare")
12623    (set_attr "length" "12,12,16,16")])
12624
12625 (define_split
12626   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12627         (compare:CC
12628          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12629                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12630                   (match_operand:SI 3 "gpc_reg_operand" ""))
12631          (const_int 0)))
12632    (clobber (match_scratch:SI 4 ""))]
12633   "TARGET_32BIT && reload_completed"
12634   [(set (match_dup 4)
12635         (plus:SI (ltu:SI (match_dup 1) (match_dup 2))
12636                  (match_dup 3)))
12637    (set (match_dup 0)
12638         (compare:CC (match_dup 4)
12639                     (const_int 0)))]
12640   "")
12641
12642 (define_insn ""
12643   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12644         (compare:CC
12645          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12646                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12647                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12648          (const_int 0)))
12649    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12650         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12651   "TARGET_32BIT"
12652   "@
12653    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;{sf.|subf.} %0,%0,%3
12654    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;{sf.|subf.} %0,%0,%3
12655    #
12656    #"
12657   [(set_attr "type" "compare")
12658    (set_attr "length" "12,12,16,16")])
12659
12660 (define_split
12661   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12662         (compare:CC
12663          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12664                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12665                   (match_operand:SI 3 "gpc_reg_operand" ""))
12666          (const_int 0)))
12667    (set (match_operand:SI 0 "gpc_reg_operand" "")
12668         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12669   "TARGET_32BIT && reload_completed"
12670   [(set (match_dup 0)
12671         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12672    (set (match_dup 4)
12673         (compare:CC (match_dup 0)
12674                     (const_int 0)))]
12675   "")
12676
12677 (define_insn ""
12678   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12679         (neg:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12680                         (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))))]
12681   "TARGET_32BIT"
12682   "@
12683    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
12684    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
12685   [(set_attr "type" "two")
12686    (set_attr "length" "8")])
12687
12688 (define_insn ""
12689   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12690         (neg:DI (ltu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12691                         (match_operand:DI 2 "reg_or_neg_short_operand" "r,P"))))]
12692   "TARGET_64BIT"
12693   "@
12694    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
12695    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
12696   [(set_attr "type" "two")
12697    (set_attr "length" "8")])
12698
12699 (define_insn ""
12700   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12701         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12702                (match_operand:SI 2 "reg_or_short_operand" "rI")))
12703    (clobber (match_scratch:SI 3 "=r"))]
12704   "TARGET_POWER"
12705   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
12706    [(set_attr "length" "12")])
12707
12708 (define_insn ""
12709   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12710         (compare:CC
12711          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12712                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12713          (const_int 0)))
12714    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12715         (ge:SI (match_dup 1) (match_dup 2)))
12716    (clobber (match_scratch:SI 3 "=r,r"))]
12717   "TARGET_POWER"
12718   "@
12719    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12720    #"
12721   [(set_attr "type" "compare")
12722    (set_attr "length" "12,16")])
12723
12724 (define_split
12725   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12726         (compare:CC
12727          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12728                 (match_operand:SI 2 "reg_or_short_operand" ""))
12729          (const_int 0)))
12730    (set (match_operand:SI 0 "gpc_reg_operand" "")
12731         (ge:SI (match_dup 1) (match_dup 2)))
12732    (clobber (match_scratch:SI 3 ""))]
12733   "TARGET_POWER && reload_completed"
12734   [(parallel [(set (match_dup 0)
12735                    (ge:SI (match_dup 1) (match_dup 2)))
12736               (clobber (match_dup 3))])
12737    (set (match_dup 4)
12738         (compare:CC (match_dup 0)
12739                     (const_int 0)))]
12740   "")
12741
12742 (define_insn ""
12743   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12744         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12745                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12746                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12747   "TARGET_POWER"
12748   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
12749   [(set_attr "length" "12")])
12750
12751 (define_insn ""
12752   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12753         (compare:CC
12754          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12755                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12756                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12757          (const_int 0)))
12758    (clobber (match_scratch:SI 4 "=&r,&r"))]
12759   "TARGET_POWER"
12760   "@
12761    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12762    #"
12763   [(set_attr "type" "compare")
12764    (set_attr "length" "12,16")])
12765
12766 (define_split
12767   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12768         (compare:CC
12769          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12770                          (match_operand:SI 2 "reg_or_short_operand" ""))
12771                   (match_operand:SI 3 "gpc_reg_operand" ""))
12772          (const_int 0)))
12773    (clobber (match_scratch:SI 4 ""))]
12774   "TARGET_POWER && reload_completed"
12775   [(set (match_dup 4)
12776         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
12777                  (match_dup 3)))
12778    (set (match_dup 0)
12779         (compare:CC (match_dup 4)
12780                     (const_int 0)))]
12781   "")
12782
12783 (define_insn ""
12784   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12785         (compare:CC
12786          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12787                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12788                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12789          (const_int 0)))
12790    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12791         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12792   "TARGET_POWER"
12793   "@
12794    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12795    #"
12796   [(set_attr "type" "compare")
12797    (set_attr "length" "12,16")])
12798
12799 (define_split
12800   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12801         (compare:CC
12802          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12803                          (match_operand:SI 2 "reg_or_short_operand" ""))
12804                   (match_operand:SI 3 "gpc_reg_operand" ""))
12805          (const_int 0)))
12806    (set (match_operand:SI 0 "gpc_reg_operand" "")
12807         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12808   "TARGET_POWER && reload_completed"
12809   [(set (match_dup 0)
12810         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12811    (set (match_dup 4)
12812         (compare:CC (match_dup 0)
12813                     (const_int 0)))]
12814   "")
12815
12816 (define_insn ""
12817   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12818         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12819                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12820   "TARGET_POWER"
12821   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
12822   [(set_attr "length" "12")])
12823
12824 (define_insn ""
12825   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12826         (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12827                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12828   "TARGET_32BIT"
12829   "@
12830    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
12831    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12832   [(set_attr "type" "three")
12833    (set_attr "length" "12")])
12834
12835 (define_insn ""
12836   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12837         (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12838                 (match_operand:DI 2 "reg_or_neg_short_operand" "r,P")))]
12839   "TARGET_64BIT"
12840   "@
12841    subfc %0,%2,%1\;li %0,0\;adde %0,%0,%0
12842    addic %0,%1,%n2\;li %0,0\;adde %0,%0,%0"
12843   [(set_attr "type" "three")
12844    (set_attr "length" "12")])
12845
12846 (define_insn ""
12847   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12848         (compare:CC
12849          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12850                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12851          (const_int 0)))
12852    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12853         (geu:SI (match_dup 1) (match_dup 2)))]
12854   "TARGET_32BIT"
12855   "@
12856    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12857    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12858    #
12859    #"
12860   [(set_attr "type" "compare")
12861    (set_attr "length" "12,12,16,16")])
12862
12863 (define_split
12864   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12865         (compare:CC
12866          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12867                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12868          (const_int 0)))
12869    (set (match_operand:SI 0 "gpc_reg_operand" "")
12870         (geu:SI (match_dup 1) (match_dup 2)))]
12871   "TARGET_32BIT && reload_completed"
12872   [(set (match_dup 0)
12873         (geu:SI (match_dup 1) (match_dup 2)))
12874    (set (match_dup 3)
12875         (compare:CC (match_dup 0)
12876                     (const_int 0)))]
12877   "")
12878
12879 (define_insn ""
12880   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12881         (compare:CC
12882          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
12883                  (match_operand:DI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12884          (const_int 0)))
12885    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
12886         (geu:DI (match_dup 1) (match_dup 2)))]
12887   "TARGET_64BIT"
12888   "@
12889    subfc %0,%2,%1\;li %0,0\;adde. %0,%0,%0
12890    addic %0,%1,%n2\;li %0,0\;adde. %0,%0,%0
12891    #
12892    #"
12893   [(set_attr "type" "compare")
12894    (set_attr "length" "12,12,16,16")])
12895
12896 (define_split
12897   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12898         (compare:CC
12899          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12900                  (match_operand:DI 2 "reg_or_neg_short_operand" ""))
12901          (const_int 0)))
12902    (set (match_operand:DI 0 "gpc_reg_operand" "")
12903         (geu:DI (match_dup 1) (match_dup 2)))]
12904   "TARGET_64BIT && reload_completed"
12905   [(set (match_dup 0)
12906         (geu:DI (match_dup 1) (match_dup 2)))
12907    (set (match_dup 3)
12908         (compare:CC (match_dup 0)
12909                     (const_int 0)))]
12910   "")
12911
12912 (define_insn ""
12913   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12914         (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12915                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12916                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12917   "TARGET_32BIT"
12918   "@
12919    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
12920    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
12921   [(set_attr "type" "two")
12922    (set_attr "length" "8")])
12923
12924 (define_insn ""
12925   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12926         (compare:CC
12927          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12928                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12929                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12930          (const_int 0)))
12931    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12932   "TARGET_32BIT"
12933   "@
12934    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
12935    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
12936    #
12937    #"
12938   [(set_attr "type" "compare")
12939    (set_attr "length" "8,8,12,12")])
12940
12941 (define_split
12942   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12943         (compare:CC
12944          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12945                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12946                   (match_operand:SI 3 "gpc_reg_operand" ""))
12947          (const_int 0)))
12948    (clobber (match_scratch:SI 4 ""))]
12949   "TARGET_32BIT && reload_completed"
12950   [(set (match_dup 4)
12951         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
12952                   (match_dup 3)))
12953    (set (match_dup 0)
12954         (compare:CC (match_dup 4)
12955                     (const_int 0)))]
12956   "")
12957
12958 (define_insn ""
12959   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12960         (compare:CC
12961          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12962                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12963                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12964          (const_int 0)))
12965    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12966         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12967   "TARGET_32BIT"
12968   "@
12969    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
12970    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
12971    #
12972    #"
12973   [(set_attr "type" "compare")
12974    (set_attr "length" "8,8,12,12")])
12975
12976 (define_split
12977   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12978         (compare:CC
12979          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12980                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12981                   (match_operand:SI 3 "gpc_reg_operand" ""))
12982          (const_int 0)))
12983    (set (match_operand:SI 0 "gpc_reg_operand" "")
12984         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12985   "TARGET_32BIT && reload_completed"
12986   [(set (match_dup 0)
12987         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12988    (set (match_dup 4)
12989         (compare:CC (match_dup 0)
12990                     (const_int 0)))]
12991   "")
12992
12993 (define_insn ""
12994   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12995         (neg:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12996                         (match_operand:SI 2 "reg_or_short_operand" "r,I"))))]
12997   "TARGET_32BIT"
12998   "@
12999    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
13000    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
13001   [(set_attr "type" "three")
13002    (set_attr "length" "12")])
13003
13004 (define_insn ""
13005   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13006         (and:SI (neg:SI
13007                  (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13008                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
13009                 (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
13010   "TARGET_32BIT"
13011   "@
13012    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
13013    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
13014   [(set_attr "type" "three")
13015    (set_attr "length" "12")])
13016
13017 (define_insn ""
13018   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13019         (compare:CC
13020          (and:SI (neg:SI
13021                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13022                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
13023                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13024          (const_int 0)))
13025    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13026   "TARGET_32BIT"
13027   "@
13028    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
13029    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
13030    #
13031    #"
13032   [(set_attr "type" "compare")
13033    (set_attr "length" "12,12,16,16")])
13034
13035 (define_split
13036   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13037         (compare:CC
13038          (and:SI (neg:SI
13039                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13040                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
13041                  (match_operand:SI 3 "gpc_reg_operand" ""))
13042          (const_int 0)))
13043    (clobber (match_scratch:SI 4 ""))]
13044   "TARGET_32BIT && reload_completed"
13045   [(set (match_dup 4)
13046         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
13047                 (match_dup 3)))
13048    (set (match_dup 0)
13049         (compare:CC (match_dup 4)
13050                     (const_int 0)))]
13051   "")
13052
13053 (define_insn ""
13054   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13055         (compare:CC
13056          (and:SI (neg:SI
13057                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13058                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
13059                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13060          (const_int 0)))
13061    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13062         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13063   "TARGET_32BIT"
13064   "@
13065    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
13066    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
13067    #
13068    #"
13069   [(set_attr "type" "compare")
13070    (set_attr "length" "12,12,16,16")])
13071
13072 (define_split
13073   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13074         (compare:CC
13075          (and:SI (neg:SI
13076                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13077                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
13078                  (match_operand:SI 3 "gpc_reg_operand" ""))
13079          (const_int 0)))
13080    (set (match_operand:SI 0 "gpc_reg_operand" "")
13081         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
13082   "TARGET_32BIT && reload_completed"
13083   [(set (match_dup 0)
13084         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
13085    (set (match_dup 4)
13086         (compare:CC (match_dup 0)
13087                     (const_int 0)))]
13088   "")
13089
13090 (define_insn ""
13091   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13092         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13093                (const_int 0)))]
13094   "TARGET_32BIT"
13095   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri|srwi} %0,%0,31"
13096   [(set_attr "type" "three")
13097    (set_attr "length" "12")])
13098
13099 (define_insn ""
13100   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13101         (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13102                (const_int 0)))]
13103   "TARGET_64BIT"
13104   "subfic %0,%1,0\;addme %0,%0\;srdi %0,%0,63"
13105   [(set_attr "type" "three")
13106    (set_attr "length" "12")])
13107
13108 (define_insn ""
13109   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
13110         (compare:CC
13111          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13112                 (const_int 0))
13113          (const_int 0)))
13114    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13115         (gt:SI (match_dup 1) (const_int 0)))]
13116   "TARGET_32BIT"
13117   "@
13118    {sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri.|srwi.} %0,%0,31
13119    #"
13120   [(set_attr "type" "delayed_compare")
13121    (set_attr "length" "12,16")])
13122
13123 (define_split
13124   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
13125         (compare:CC
13126          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13127                 (const_int 0))
13128          (const_int 0)))
13129    (set (match_operand:SI 0 "gpc_reg_operand" "")
13130         (gt:SI (match_dup 1) (const_int 0)))]
13131   "TARGET_32BIT && reload_completed"
13132   [(set (match_dup 0)
13133         (gt:SI (match_dup 1) (const_int 0)))
13134    (set (match_dup 2)
13135         (compare:CC (match_dup 0)
13136                     (const_int 0)))]
13137   "")
13138
13139 (define_insn ""
13140   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
13141         (compare:CC
13142          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13143                 (const_int 0))
13144          (const_int 0)))
13145    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13146         (gt:DI (match_dup 1) (const_int 0)))]
13147   "TARGET_64BIT"
13148   "@
13149    subfic %0,%1,0\;addme %0,%0\;srdi. %0,%0,63
13150    #"
13151   [(set_attr "type" "delayed_compare")
13152    (set_attr "length" "12,16")])
13153
13154 (define_split
13155   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
13156         (compare:CC
13157          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13158                 (const_int 0))
13159          (const_int 0)))
13160    (set (match_operand:DI 0 "gpc_reg_operand" "")
13161         (gt:DI (match_dup 1) (const_int 0)))]
13162   "TARGET_64BIT && reload_completed"
13163   [(set (match_dup 0)
13164         (gt:DI (match_dup 1) (const_int 0)))
13165    (set (match_dup 2)
13166         (compare:CC (match_dup 0)
13167                     (const_int 0)))]
13168   "")
13169
13170 (define_insn ""
13171   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13172         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13173                (match_operand:SI 2 "reg_or_short_operand" "r")))]
13174   "TARGET_POWER"
13175   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
13176   [(set_attr "length" "12")])
13177
13178 (define_insn ""
13179   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13180         (compare:CC
13181          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13182                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13183          (const_int 0)))
13184    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13185         (gt:SI (match_dup 1) (match_dup 2)))]
13186   "TARGET_POWER"
13187   "@
13188    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
13189    #"
13190   [(set_attr "type" "delayed_compare")
13191    (set_attr "length" "12,16")])
13192
13193 (define_split
13194   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13195         (compare:CC
13196          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13197                 (match_operand:SI 2 "reg_or_short_operand" ""))
13198          (const_int 0)))
13199    (set (match_operand:SI 0 "gpc_reg_operand" "")
13200         (gt:SI (match_dup 1) (match_dup 2)))]
13201   "TARGET_POWER && reload_completed"
13202   [(set (match_dup 0)
13203         (gt:SI (match_dup 1) (match_dup 2)))
13204    (set (match_dup 3)
13205         (compare:CC (match_dup 0)
13206                     (const_int 0)))]
13207   "")
13208
13209 (define_insn ""
13210   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13211         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13212                         (const_int 0))
13213                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
13214   "TARGET_32BIT"
13215   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
13216   [(set_attr "type" "three")
13217    (set_attr "length" "12")])
13218
13219 (define_insn ""
13220   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
13221         (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13222                         (const_int 0))
13223                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
13224   "TARGET_64BIT"
13225   "addc %0,%1,%1\;subfe %0,%1,%0\;addze %0,%2"
13226   [(set_attr "type" "three")
13227    (set_attr "length" "12")])
13228
13229 (define_insn ""
13230   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13231         (compare:CC
13232          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13233                          (const_int 0))
13234                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13235          (const_int 0)))
13236    (clobber (match_scratch:SI 3 "=&r,&r"))]
13237   "TARGET_32BIT"
13238   "@
13239    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
13240    #"
13241   [(set_attr "type" "compare")
13242    (set_attr "length" "12,16")])
13243
13244 (define_split
13245   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13246         (compare:CC
13247          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13248                          (const_int 0))
13249                   (match_operand:SI 2 "gpc_reg_operand" ""))
13250          (const_int 0)))
13251    (clobber (match_scratch:SI 3 ""))]
13252   "TARGET_32BIT && reload_completed"
13253   [(set (match_dup 3)
13254         (plus:SI (gt:SI (match_dup 1) (const_int 0))
13255                   (match_dup 2)))
13256    (set (match_dup 0)
13257         (compare:CC (match_dup 3)
13258                     (const_int 0)))]
13259   "")
13260
13261 (define_insn ""
13262   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13263         (compare:CC
13264          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13265                          (const_int 0))
13266                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13267          (const_int 0)))
13268    (clobber (match_scratch:DI 3 "=&r,&r"))]
13269   "TARGET_64BIT"
13270   "@
13271    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
13272    #"
13273   [(set_attr "type" "compare")
13274    (set_attr "length" "12,16")])
13275
13276 (define_split
13277   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13278         (compare:CC
13279          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13280                          (const_int 0))
13281                   (match_operand:DI 2 "gpc_reg_operand" ""))
13282          (const_int 0)))
13283    (clobber (match_scratch:DI 3 ""))]
13284   "TARGET_64BIT && reload_completed"
13285   [(set (match_dup 3)
13286         (plus:DI (gt:DI (match_dup 1) (const_int 0))
13287                  (match_dup 2)))
13288    (set (match_dup 0)
13289         (compare:CC (match_dup 3)
13290                     (const_int 0)))]
13291   "")
13292
13293 (define_insn ""
13294   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13295         (compare:CC
13296          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13297                          (const_int 0))
13298                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
13299          (const_int 0)))
13300    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13301         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13302   "TARGET_32BIT"
13303   "@
13304    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
13305    #"
13306   [(set_attr "type" "compare")
13307    (set_attr "length" "12,16")])
13308
13309 (define_split
13310   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13311         (compare:CC
13312          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13313                          (const_int 0))
13314                   (match_operand:SI 2 "gpc_reg_operand" ""))
13315          (const_int 0)))
13316    (set (match_operand:SI 0 "gpc_reg_operand" "")
13317         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13318   "TARGET_32BIT && reload_completed"
13319   [(set (match_dup 0)
13320         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
13321    (set (match_dup 3)
13322         (compare:CC (match_dup 0)
13323                     (const_int 0)))]
13324   "")
13325
13326 (define_insn ""
13327   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13328         (compare:CC
13329          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13330                          (const_int 0))
13331                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13332          (const_int 0)))
13333    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13334         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13335   "TARGET_64BIT"
13336   "@
13337    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
13338    #"
13339   [(set_attr "type" "compare")
13340    (set_attr "length" "12,16")])
13341
13342 (define_split
13343   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13344         (compare:CC
13345          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13346                          (const_int 0))
13347                   (match_operand:DI 2 "gpc_reg_operand" ""))
13348          (const_int 0)))
13349    (set (match_operand:DI 0 "gpc_reg_operand" "")
13350         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13351   "TARGET_64BIT && reload_completed"
13352   [(set (match_dup 0)
13353         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
13354    (set (match_dup 3)
13355         (compare:CC (match_dup 0)
13356                     (const_int 0)))]
13357   "")
13358
13359 (define_insn ""
13360   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13361         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13362                         (match_operand:SI 2 "reg_or_short_operand" "r"))
13363                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13364   "TARGET_POWER"
13365   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13366   [(set_attr "length" "12")])
13367
13368 (define_insn ""
13369   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13370         (compare:CC
13371          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13372                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13373                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13374          (const_int 0)))
13375    (clobber (match_scratch:SI 4 "=&r,&r"))]
13376   "TARGET_POWER"
13377   "@
13378    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13379    #"
13380   [(set_attr "type" "compare")
13381    (set_attr "length" "12,16")])
13382
13383 (define_split
13384   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13385         (compare:CC
13386          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13387                          (match_operand:SI 2 "reg_or_short_operand" ""))
13388                   (match_operand:SI 3 "gpc_reg_operand" ""))
13389          (const_int 0)))
13390    (clobber (match_scratch:SI 4 ""))]
13391   "TARGET_POWER && reload_completed"
13392   [(set (match_dup 4)
13393         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13394    (set (match_dup 0)
13395         (compare:CC (match_dup 4)
13396                     (const_int 0)))]
13397   "")
13398
13399 (define_insn ""
13400   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13401         (compare:CC
13402          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13403                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13404                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13405          (const_int 0)))
13406    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13407         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13408   "TARGET_POWER"
13409   "@
13410    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13411    #"
13412   [(set_attr "type" "compare")
13413    (set_attr "length" "12,16")])
13414
13415 (define_split
13416   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13417         (compare:CC
13418          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13419                          (match_operand:SI 2 "reg_or_short_operand" ""))
13420                   (match_operand:SI 3 "gpc_reg_operand" ""))
13421          (const_int 0)))
13422    (set (match_operand:SI 0 "gpc_reg_operand" "")
13423         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13424   "TARGET_POWER && reload_completed"
13425   [(set (match_dup 0)
13426         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13427    (set (match_dup 4)
13428         (compare:CC (match_dup 0)
13429                     (const_int 0)))]
13430   "")
13431
13432 (define_insn ""
13433   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13434         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13435                        (const_int 0))))]
13436   "TARGET_32BIT"
13437   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{srai|srawi} %0,%0,31"
13438   [(set_attr "type" "three")
13439    (set_attr "length" "12")])
13440
13441 (define_insn ""
13442   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13443         (neg:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13444                        (const_int 0))))]
13445   "TARGET_64BIT"
13446   "subfic %0,%1,0\;addme %0,%0\;sradi %0,%0,63"
13447   [(set_attr "type" "three")
13448    (set_attr "length" "12")])
13449
13450 (define_insn ""
13451   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13452         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13453                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
13454   "TARGET_POWER"
13455   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13456   [(set_attr "length" "12")])
13457
13458 (define_insn_and_split ""
13459   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13460         (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13461                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
13462   "TARGET_32BIT"
13463   "#"
13464   "TARGET_32BIT"
13465   [(set (match_dup 0) (neg:SI (gtu:SI (match_dup 1) (match_dup 2))))
13466    (set (match_dup 0) (neg:SI (match_dup 0)))]
13467   "")
13468
13469 (define_insn_and_split ""
13470   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13471         (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13472                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
13473   "TARGET_64BIT"
13474   "#"
13475   "TARGET_64BIT"
13476   [(set (match_dup 0) (neg:DI (gtu:DI (match_dup 1) (match_dup 2))))
13477    (set (match_dup 0) (neg:DI (match_dup 0)))]
13478   "")
13479
13480 (define_insn ""
13481   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13482         (compare:CC
13483          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13484                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13485          (const_int 0)))
13486    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13487         (gtu:SI (match_dup 1) (match_dup 2)))]
13488   "TARGET_32BIT"
13489   "@
13490    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
13491    #"
13492   [(set_attr "type" "compare")
13493    (set_attr "length" "12,16")])
13494
13495 (define_split
13496   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13497         (compare:CC
13498          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13499                  (match_operand:SI 2 "reg_or_short_operand" ""))
13500          (const_int 0)))
13501    (set (match_operand:SI 0 "gpc_reg_operand" "")
13502         (gtu:SI (match_dup 1) (match_dup 2)))]
13503   "TARGET_32BIT && reload_completed"
13504   [(set (match_dup 0)
13505         (gtu:SI (match_dup 1) (match_dup 2)))
13506    (set (match_dup 3)
13507         (compare:CC (match_dup 0)
13508                     (const_int 0)))]
13509   "")
13510
13511 (define_insn ""
13512   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13513         (compare:CC
13514          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13515                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
13516          (const_int 0)))
13517    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13518         (gtu:DI (match_dup 1) (match_dup 2)))]
13519   "TARGET_64BIT"
13520   "@
13521    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;neg. %0,%0
13522    #"
13523   [(set_attr "type" "compare")
13524    (set_attr "length" "12,16")])
13525
13526 (define_split
13527   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13528         (compare:CC
13529          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13530                  (match_operand:DI 2 "reg_or_short_operand" ""))
13531          (const_int 0)))
13532    (set (match_operand:DI 0 "gpc_reg_operand" "")
13533         (gtu:DI (match_dup 1) (match_dup 2)))]
13534   "TARGET_64BIT && reload_completed"
13535   [(set (match_dup 0)
13536         (gtu:DI (match_dup 1) (match_dup 2)))
13537    (set (match_dup 3)
13538         (compare:CC (match_dup 0)
13539                     (const_int 0)))]
13540   "")
13541
13542 (define_insn_and_split ""
13543   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13544         (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13545                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
13546                  (match_operand:SI 3 "reg_or_short_operand" "rI")))]
13547   "TARGET_32BIT"
13548   "#"
13549   "TARGET_32BIT"
13550   [(set (match_dup 0) (neg:SI (gtu:SI (match_dup 1) (match_dup 2))))
13551    (set (match_dup 0) (minus:SI (match_dup 3) (match_dup 0)))]
13552   "")
13553
13554 (define_insn_and_split ""
13555   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13556         (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13557                          (match_operand:DI 2 "reg_or_short_operand" "rI"))
13558                  (match_operand:DI 3 "reg_or_short_operand" "rI")))]
13559   "TARGET_64BIT"
13560   "#"
13561   "TARGET_64BIT"
13562   [(set (match_dup 0) (neg:DI (gtu:DI (match_dup 1) (match_dup 2))))
13563    (set (match_dup 0) (minus:DI (match_dup 3) (match_dup 0)))]
13564   "")
13565
13566 (define_insn ""
13567   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13568         (compare:CC
13569          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13570                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13571                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13572          (const_int 0)))
13573    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13574   "TARGET_32BIT"
13575   "@
13576    {ai|addic} %4,%1,%k2\;{aze.|addze.} %4,%3
13577    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subf.} %4,%4,%3
13578    #
13579    #"
13580   [(set_attr "type" "compare")
13581    (set_attr "length" "8,12,12,16")])
13582
13583 (define_split
13584   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13585         (compare:CC
13586          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13587                           (match_operand:SI 2 "reg_or_short_operand" ""))
13588                   (match_operand:SI 3 "gpc_reg_operand" ""))
13589          (const_int 0)))
13590    (clobber (match_scratch:SI 4 ""))]
13591   "TARGET_32BIT && reload_completed"
13592   [(set (match_dup 4)
13593         (plus:SI (gtu:SI (match_dup 1) (match_dup 2))
13594                  (match_dup 3)))
13595    (set (match_dup 0)
13596         (compare:CC (match_dup 4)
13597                     (const_int 0)))]
13598   "")
13599
13600 (define_insn ""
13601   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13602         (compare:CC
13603          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13604                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13605                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13606          (const_int 0)))
13607    (clobber (match_scratch:DI 4 "=&r,&r,&r,&r"))]
13608   "TARGET_64BIT"
13609   "@
13610    addic %4,%1,%k2\;addze. %4,%3
13611    subf%I2c %4,%1,%2\;subfe %4,%4,%4\;subf. %4,%4,%3
13612    #
13613    #"
13614   [(set_attr "type" "compare")
13615    (set_attr "length" "8,12,12,16")])
13616
13617 (define_split
13618   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13619         (compare:CC
13620          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13621                           (match_operand:DI 2 "reg_or_short_operand" ""))
13622                   (match_operand:DI 3 "gpc_reg_operand" ""))
13623          (const_int 0)))
13624    (clobber (match_scratch:DI 4 ""))]
13625   "TARGET_64BIT && reload_completed"
13626   [(set (match_dup 4)
13627         (plus:DI (gtu:DI (match_dup 1) (match_dup 2))
13628                   (match_dup 3)))
13629    (set (match_dup 0)
13630         (compare:CC (match_dup 4)
13631                     (const_int 0)))]
13632   "")
13633
13634 (define_insn ""
13635   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13636         (compare:CC
13637          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13638                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13639                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13640          (const_int 0)))
13641    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13642         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13643   "TARGET_32BIT"
13644   "@
13645    {ai|addic} %0,%1,%k2\;{aze.|addze.} %0,%3
13646    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;{sf.|subf.} %0,%0,%3
13647    #
13648    #"
13649   [(set_attr "type" "compare")
13650    (set_attr "length" "8,12,12,16")])
13651
13652 (define_split
13653   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13654         (compare:CC
13655          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13656                           (match_operand:SI 2 "reg_or_short_operand" ""))
13657                   (match_operand:SI 3 "gpc_reg_operand" ""))
13658          (const_int 0)))
13659    (set (match_operand:SI 0 "gpc_reg_operand" "")
13660         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13661   "TARGET_32BIT && reload_completed"
13662   [(set (match_dup 0)
13663         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13664    (set (match_dup 4)
13665         (compare:CC (match_dup 0)
13666                     (const_int 0)))]
13667   "")
13668
13669 (define_insn ""
13670   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13671         (compare:CC
13672          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13673                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13674                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13675          (const_int 0)))
13676    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13677         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13678   "TARGET_64BIT"
13679   "@
13680    addic %0,%1,%k2\;addze. %0,%3
13681    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;subf. %0,%0,%3
13682    #
13683    #"
13684   [(set_attr "type" "compare")
13685    (set_attr "length" "8,12,12,16")])
13686
13687 (define_split
13688   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13689         (compare:CC
13690          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13691                           (match_operand:DI 2 "reg_or_short_operand" ""))
13692                   (match_operand:DI 3 "gpc_reg_operand" ""))
13693          (const_int 0)))
13694    (set (match_operand:DI 0 "gpc_reg_operand" "")
13695         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13696   "TARGET_64BIT && reload_completed"
13697   [(set (match_dup 0)
13698         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
13699    (set (match_dup 4)
13700         (compare:CC (match_dup 0)
13701                     (const_int 0)))]
13702   "")
13703
13704 (define_insn ""
13705   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13706         (neg:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13707                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
13708   "TARGET_32BIT"
13709   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
13710   [(set_attr "type" "two")
13711    (set_attr "length" "8")])
13712
13713 (define_insn ""
13714   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13715         (neg:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13716                         (match_operand:DI 2 "reg_or_short_operand" "rI"))))]
13717   "TARGET_64BIT"
13718   "subf%I2c %0,%1,%2\;subfe %0,%0,%0"
13719   [(set_attr "type" "two")
13720    (set_attr "length" "8")])
13721 \f
13722 ;; Define both directions of branch and return.  If we need a reload
13723 ;; register, we'd rather use CR0 since it is much easier to copy a
13724 ;; register CC value to there.
13725
13726 (define_insn ""
13727   [(set (pc)
13728         (if_then_else (match_operator 1 "branch_comparison_operator"
13729                                       [(match_operand 2
13730                                                       "cc_reg_operand" "y")
13731                                        (const_int 0)])
13732                       (label_ref (match_operand 0 "" ""))
13733                       (pc)))]
13734   ""
13735   "*
13736 {
13737   return output_cbranch (operands[1], \"%l0\", 0, insn);
13738 }"
13739   [(set_attr "type" "branch")])
13740
13741 (define_insn ""
13742   [(set (pc)
13743         (if_then_else (match_operator 0 "branch_comparison_operator"
13744                                       [(match_operand 1
13745                                                       "cc_reg_operand" "y")
13746                                        (const_int 0)])
13747                       (return)
13748                       (pc)))]
13749   "direct_return ()"
13750   "*
13751 {
13752   return output_cbranch (operands[0], NULL, 0, insn);
13753 }"
13754   [(set_attr "type" "branch")
13755    (set_attr "length" "4")])
13756
13757 (define_insn ""
13758   [(set (pc)
13759         (if_then_else (match_operator 1 "branch_comparison_operator"
13760                                       [(match_operand 2
13761                                                       "cc_reg_operand" "y")
13762                                        (const_int 0)])
13763                       (pc)
13764                       (label_ref (match_operand 0 "" ""))))]
13765   ""
13766   "*
13767 {
13768   return output_cbranch (operands[1], \"%l0\", 1, insn);
13769 }"
13770   [(set_attr "type" "branch")])
13771
13772 (define_insn ""
13773   [(set (pc)
13774         (if_then_else (match_operator 0 "branch_comparison_operator"
13775                                       [(match_operand 1
13776                                                       "cc_reg_operand" "y")
13777                                        (const_int 0)])
13778                       (pc)
13779                       (return)))]
13780   "direct_return ()"
13781   "*
13782 {
13783   return output_cbranch (operands[0], NULL, 1, insn);
13784 }"
13785   [(set_attr "type" "branch")
13786    (set_attr "length" "4")])
13787
13788 ;; Logic on condition register values.
13789
13790 ; This pattern matches things like
13791 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13792 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
13793 ;                                  (const_int 1)))
13794 ; which are generated by the branch logic.
13795 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
13796
13797 (define_insn "*cceq_ior_compare"
13798   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13799         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13800                         [(match_operator:SI 2
13801                                       "branch_positive_comparison_operator"
13802                                       [(match_operand 3
13803                                                       "cc_reg_operand" "y,y")
13804                                        (const_int 0)])
13805                          (match_operator:SI 4
13806                                       "branch_positive_comparison_operator"
13807                                       [(match_operand 5
13808                                                       "cc_reg_operand" "0,y")
13809                                        (const_int 0)])])
13810                       (const_int 1)))]
13811   ""
13812   "cr%q1 %E0,%j2,%j4"
13813   [(set_attr "type" "cr_logical,delayed_cr")])
13814
13815 ; Why is the constant -1 here, but 1 in the previous pattern?
13816 ; Because ~1 has all but the low bit set.
13817 (define_insn ""
13818   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13819         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
13820                         [(not:SI (match_operator:SI 2
13821                                       "branch_positive_comparison_operator"
13822                                       [(match_operand 3
13823                                                       "cc_reg_operand" "y,y")
13824                                        (const_int 0)]))
13825                          (match_operator:SI 4
13826                                 "branch_positive_comparison_operator"
13827                                 [(match_operand 5
13828                                                 "cc_reg_operand" "0,y")
13829                                  (const_int 0)])])
13830                       (const_int -1)))]
13831   ""
13832   "cr%q1 %E0,%j2,%j4"
13833   [(set_attr "type" "cr_logical,delayed_cr")])
13834
13835 (define_insn "*cceq_rev_compare"
13836   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13837         (compare:CCEQ (match_operator:SI 1
13838                                       "branch_positive_comparison_operator"
13839                                       [(match_operand 2
13840                                                       "cc_reg_operand" "0,y")
13841                                        (const_int 0)])
13842                       (const_int 0)))]
13843   ""
13844   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
13845   [(set_attr "type" "cr_logical,delayed_cr")])
13846
13847 ;; If we are comparing the result of two comparisons, this can be done
13848 ;; using creqv or crxor.
13849
13850 (define_insn_and_split ""
13851   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13852         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13853                               [(match_operand 2 "cc_reg_operand" "y")
13854                                (const_int 0)])
13855                       (match_operator 3 "branch_comparison_operator"
13856                               [(match_operand 4 "cc_reg_operand" "y")
13857                                (const_int 0)])))]
13858   ""
13859   "#"
13860   ""
13861   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13862                                     (match_dup 5)))]
13863   "
13864 {
13865   int positive_1, positive_2;
13866
13867   positive_1 = branch_positive_comparison_operator (operands[1], CCEQmode);
13868   positive_2 = branch_positive_comparison_operator (operands[3], CCEQmode);
13869
13870   if (! positive_1)
13871     operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
13872                                                             GET_CODE (operands[1])),
13873                                   SImode,
13874                                   operands[2], const0_rtx);
13875   else if (GET_MODE (operands[1]) != SImode)
13876     operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
13877                                   operands[2], const0_rtx);
13878
13879   if (! positive_2)
13880     operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
13881                                                             GET_CODE (operands[3])),
13882                                   SImode,
13883                                   operands[4], const0_rtx);
13884   else if (GET_MODE (operands[3]) != SImode)
13885     operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
13886                                   operands[4], const0_rtx);
13887
13888   if (positive_1 == positive_2)
13889     {
13890       operands[1] = gen_rtx_NOT (SImode, operands[1]);
13891       operands[5] = constm1_rtx;
13892     }
13893   else
13894     {
13895       operands[5] = const1_rtx;
13896     }
13897 }")
13898
13899 ;; Unconditional branch and return.
13900
13901 (define_insn "jump"
13902   [(set (pc)
13903         (label_ref (match_operand 0 "" "")))]
13904   ""
13905   "b %l0"
13906   [(set_attr "type" "branch")])
13907
13908 (define_insn "return"
13909   [(return)]
13910   "direct_return ()"
13911   "{br|blr}"
13912   [(set_attr "type" "jmpreg")])
13913
13914 (define_expand "indirect_jump"
13915   [(set (pc) (match_operand 0 "register_operand" ""))]
13916   ""
13917   "
13918 {
13919   if (TARGET_32BIT)
13920     emit_jump_insn (gen_indirect_jumpsi (operands[0]));
13921   else
13922     emit_jump_insn (gen_indirect_jumpdi (operands[0]));
13923   DONE;
13924 }")
13925
13926 (define_insn "indirect_jumpsi"
13927   [(set (pc) (match_operand:SI 0 "register_operand" "c,*l"))]
13928   "TARGET_32BIT"
13929   "@
13930    bctr
13931    {br|blr}"
13932   [(set_attr "type" "jmpreg")])
13933
13934 (define_insn "indirect_jumpdi"
13935   [(set (pc) (match_operand:DI 0 "register_operand" "c,*l"))]
13936   "TARGET_64BIT"
13937   "@
13938    bctr
13939    blr"
13940   [(set_attr "type" "jmpreg")])
13941
13942 ;; Table jump for switch statements:
13943 (define_expand "tablejump"
13944   [(use (match_operand 0 "" ""))
13945    (use (label_ref (match_operand 1 "" "")))]
13946   ""
13947   "
13948 {
13949   if (TARGET_32BIT)
13950     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
13951   else
13952     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
13953   DONE;
13954 }")
13955
13956 (define_expand "tablejumpsi"
13957   [(set (match_dup 3)
13958         (plus:SI (match_operand:SI 0 "" "")
13959                  (match_dup 2)))
13960    (parallel [(set (pc) (match_dup 3))
13961               (use (label_ref (match_operand 1 "" "")))])]
13962   "TARGET_32BIT"
13963   "
13964 { operands[0] = force_reg (SImode, operands[0]);
13965   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
13966   operands[3] = gen_reg_rtx (SImode);
13967 }")
13968
13969 (define_expand "tablejumpdi"
13970   [(set (match_dup 4)
13971         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "rm")))
13972    (set (match_dup 3)
13973         (plus:DI (match_dup 4)
13974                  (match_dup 2)))
13975    (parallel [(set (pc) (match_dup 3))
13976               (use (label_ref (match_operand 1 "" "")))])]
13977   "TARGET_64BIT"
13978   "
13979 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
13980   operands[3] = gen_reg_rtx (DImode);
13981   operands[4] = gen_reg_rtx (DImode);
13982 }")
13983
13984 (define_insn ""
13985   [(set (pc)
13986         (match_operand:SI 0 "register_operand" "c,*l"))
13987    (use (label_ref (match_operand 1 "" "")))]
13988   "TARGET_32BIT"
13989   "@
13990    bctr
13991    {br|blr}"
13992   [(set_attr "type" "jmpreg")])
13993
13994 (define_insn ""
13995   [(set (pc)
13996         (match_operand:DI 0 "register_operand" "c,*l"))
13997    (use (label_ref (match_operand 1 "" "")))]
13998   "TARGET_64BIT"
13999   "@
14000    bctr
14001    blr"
14002   [(set_attr "type" "jmpreg")])
14003
14004 (define_insn "nop"
14005   [(const_int 0)]
14006   ""
14007   "{cror 0,0,0|nop}")
14008 \f
14009 ;; Define the subtract-one-and-jump insns, starting with the template
14010 ;; so loop.c knows what to generate.
14011
14012 (define_expand "doloop_end"
14013   [(use (match_operand 0 "" ""))        ; loop pseudo
14014    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
14015    (use (match_operand 2 "" ""))        ; max iterations
14016    (use (match_operand 3 "" ""))        ; loop level
14017    (use (match_operand 4 "" ""))]       ; label
14018   ""
14019   "
14020 {
14021   /* Only use this on innermost loops.  */
14022   if (INTVAL (operands[3]) > 1)
14023     FAIL;
14024   if (TARGET_64BIT)
14025     {
14026       if (GET_MODE (operands[0]) != DImode)
14027         FAIL;
14028       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
14029     }
14030   else
14031     {
14032       if (GET_MODE (operands[0]) != SImode)
14033         FAIL;
14034       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
14035     }
14036   DONE;
14037 }")
14038
14039 (define_expand "ctrsi"
14040   [(parallel [(set (pc)
14041                    (if_then_else (ne (match_operand:SI 0 "register_operand" "")
14042                                      (const_int 1))
14043                                  (label_ref (match_operand 1 "" ""))
14044                                  (pc)))
14045               (set (match_dup 0)
14046                    (plus:SI (match_dup 0)
14047                             (const_int -1)))
14048               (clobber (match_scratch:CC 2 ""))
14049               (clobber (match_scratch:SI 3 ""))])]
14050   "TARGET_32BIT"
14051   "")
14052
14053 (define_expand "ctrdi"
14054   [(parallel [(set (pc)
14055                    (if_then_else (ne (match_operand:DI 0 "register_operand" "")
14056                                      (const_int 1))
14057                                  (label_ref (match_operand 1 "" ""))
14058                                  (pc)))
14059               (set (match_dup 0)
14060                    (plus:DI (match_dup 0)
14061                             (const_int -1)))
14062               (clobber (match_scratch:CC 2 ""))
14063               (clobber (match_scratch:DI 3 ""))])]
14064   "TARGET_64BIT"
14065   "")
14066
14067 ;; We need to be able to do this for any operand, including MEM, or we
14068 ;; will cause reload to blow up since we don't allow output reloads on
14069 ;; JUMP_INSNs.
14070 ;; For the length attribute to be calculated correctly, the
14071 ;; label MUST be operand 0.
14072
14073 (define_insn "*ctrsi_internal1"
14074   [(set (pc)
14075         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14076                           (const_int 1))
14077                       (label_ref (match_operand 0 "" ""))
14078                       (pc)))
14079    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14080         (plus:SI (match_dup 1)
14081                  (const_int -1)))
14082    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14083    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14084   "TARGET_32BIT"
14085   "*
14086 {
14087   if (which_alternative != 0)
14088     return \"#\";
14089   else if (get_attr_length (insn) == 4)
14090     return \"{bdn|bdnz} %l0\";
14091   else
14092     return \"bdz $+8\;b %l0\";
14093 }"
14094   [(set_attr "type" "branch")
14095    (set_attr "length" "*,12,16,16")])
14096
14097 (define_insn "*ctrsi_internal2"
14098   [(set (pc)
14099         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14100                           (const_int 1))
14101                       (pc)
14102                       (label_ref (match_operand 0 "" ""))))
14103    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14104         (plus:SI (match_dup 1)
14105                  (const_int -1)))
14106    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14107    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14108   "TARGET_32BIT"
14109   "*
14110 {
14111   if (which_alternative != 0)
14112     return \"#\";
14113   else if (get_attr_length (insn) == 4)
14114     return \"bdz %l0\";
14115   else
14116     return \"{bdn|bdnz} $+8\;b %l0\";
14117 }"
14118   [(set_attr "type" "branch")
14119    (set_attr "length" "*,12,16,16")])
14120
14121 (define_insn "*ctrdi_internal1"
14122   [(set (pc)
14123         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14124                           (const_int 1))
14125                       (label_ref (match_operand 0 "" ""))
14126                       (pc)))
14127    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14128         (plus:DI (match_dup 1)
14129                  (const_int -1)))
14130    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14131    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14132   "TARGET_64BIT"
14133   "*
14134 {
14135   if (which_alternative != 0)
14136     return \"#\";
14137   else if (get_attr_length (insn) == 4)
14138     return \"{bdn|bdnz} %l0\";
14139   else
14140     return \"bdz $+8\;b %l0\";
14141 }"
14142   [(set_attr "type" "branch")
14143    (set_attr "length" "*,12,16,16")])
14144
14145 (define_insn "*ctrdi_internal2"
14146   [(set (pc)
14147         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14148                           (const_int 1))
14149                       (pc)
14150                       (label_ref (match_operand 0 "" ""))))
14151    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14152         (plus:DI (match_dup 1)
14153                  (const_int -1)))
14154    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14155    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14156   "TARGET_64BIT"
14157   "*
14158 {
14159   if (which_alternative != 0)
14160     return \"#\";
14161   else if (get_attr_length (insn) == 4)
14162     return \"bdz %l0\";
14163   else
14164     return \"{bdn|bdnz} $+8\;b %l0\";
14165 }"
14166   [(set_attr "type" "branch")
14167    (set_attr "length" "*,12,16,16")])
14168
14169 ;; Similar but use EQ
14170
14171 (define_insn "*ctrsi_internal5"
14172   [(set (pc)
14173         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14174                           (const_int 1))
14175                       (label_ref (match_operand 0 "" ""))
14176                       (pc)))
14177    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14178         (plus:SI (match_dup 1)
14179                  (const_int -1)))
14180    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14181    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14182   "TARGET_32BIT"
14183   "*
14184 {
14185   if (which_alternative != 0)
14186     return \"#\";
14187   else if (get_attr_length (insn) == 4)
14188     return \"bdz %l0\";
14189   else
14190     return \"{bdn|bdnz} $+8\;b %l0\";
14191 }"
14192   [(set_attr "type" "branch")
14193    (set_attr "length" "*,12,16,16")])
14194
14195 (define_insn "*ctrsi_internal6"
14196   [(set (pc)
14197         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r,*r")
14198                           (const_int 1))
14199                       (pc)
14200                       (label_ref (match_operand 0 "" ""))))
14201    (set (match_operand:SI 2 "nonimmediate_operand" "=1,*r,m,*q*c*l")
14202         (plus:SI (match_dup 1)
14203                  (const_int -1)))
14204    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14205    (clobber (match_scratch:SI 4 "=X,X,&r,r"))]
14206   "TARGET_32BIT"
14207   "*
14208 {
14209   if (which_alternative != 0)
14210     return \"#\";
14211   else if (get_attr_length (insn) == 4)
14212     return \"{bdn|bdnz} %l0\";
14213   else
14214     return \"bdz $+8\;b %l0\";
14215 }"
14216   [(set_attr "type" "branch")
14217    (set_attr "length" "*,12,16,16")])
14218
14219 (define_insn "*ctrdi_internal5"
14220   [(set (pc)
14221         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14222                           (const_int 1))
14223                       (label_ref (match_operand 0 "" ""))
14224                       (pc)))
14225    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14226         (plus:DI (match_dup 1)
14227                  (const_int -1)))
14228    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14229    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14230   "TARGET_64BIT"
14231   "*
14232 {
14233   if (which_alternative != 0)
14234     return \"#\";
14235   else if (get_attr_length (insn) == 4)
14236     return \"bdz %l0\";
14237   else
14238     return \"{bdn|bdnz} $+8\;b %l0\";
14239 }"
14240   [(set_attr "type" "branch")
14241    (set_attr "length" "*,12,16,16")])
14242
14243 (define_insn "*ctrdi_internal6"
14244   [(set (pc)
14245         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r,*r")
14246                           (const_int 1))
14247                       (pc)
14248                       (label_ref (match_operand 0 "" ""))))
14249    (set (match_operand:DI 2 "nonimmediate_operand" "=1,*r,m,*c*l")
14250         (plus:DI (match_dup 1)
14251                  (const_int -1)))
14252    (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
14253    (clobber (match_scratch:DI 4 "=X,X,&r,r"))]
14254   "TARGET_64BIT"
14255   "*
14256 {
14257   if (which_alternative != 0)
14258     return \"#\";
14259   else if (get_attr_length (insn) == 4)
14260     return \"{bdn|bdnz} %l0\";
14261   else
14262     return \"bdz $+8\;b %l0\";
14263 }"
14264   [(set_attr "type" "branch")
14265    (set_attr "length" "*,12,16,16")])
14266
14267 ;; Now the splitters if we could not allocate the CTR register
14268
14269 (define_split
14270   [(set (pc)
14271         (if_then_else (match_operator 2 "comparison_operator"
14272                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14273                                        (const_int 1)])
14274                       (match_operand 5 "" "")
14275                       (match_operand 6 "" "")))
14276    (set (match_operand:SI 0 "gpc_reg_operand" "")
14277         (plus:SI (match_dup 1)
14278                  (const_int -1)))
14279    (clobber (match_scratch:CC 3 ""))
14280    (clobber (match_scratch:SI 4 ""))]
14281   "TARGET_32BIT && reload_completed"
14282   [(parallel [(set (match_dup 3)
14283                    (compare:CC (plus:SI (match_dup 1)
14284                                         (const_int -1))
14285                                (const_int 0)))
14286               (set (match_dup 0)
14287                    (plus:SI (match_dup 1)
14288                             (const_int -1)))])
14289    (set (pc) (if_then_else (match_dup 7)
14290                            (match_dup 5)
14291                            (match_dup 6)))]
14292   "
14293 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14294                                 operands[3], const0_rtx); }")
14295
14296 (define_split
14297   [(set (pc)
14298         (if_then_else (match_operator 2 "comparison_operator"
14299                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14300                                        (const_int 1)])
14301                       (match_operand 5 "" "")
14302                       (match_operand 6 "" "")))
14303    (set (match_operand:SI 0 "nonimmediate_operand" "")
14304         (plus:SI (match_dup 1) (const_int -1)))
14305    (clobber (match_scratch:CC 3 ""))
14306    (clobber (match_scratch:SI 4 ""))]
14307   "TARGET_32BIT && reload_completed
14308    && ! gpc_reg_operand (operands[0], SImode)"
14309   [(parallel [(set (match_dup 3)
14310                    (compare:CC (plus:SI (match_dup 1)
14311                                         (const_int -1))
14312                                (const_int 0)))
14313               (set (match_dup 4)
14314                    (plus:SI (match_dup 1)
14315                             (const_int -1)))])
14316    (set (match_dup 0)
14317         (match_dup 4))
14318    (set (pc) (if_then_else (match_dup 7)
14319                            (match_dup 5)
14320                            (match_dup 6)))]
14321   "
14322 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14323                                 operands[3], const0_rtx); }")
14324 (define_split
14325   [(set (pc)
14326         (if_then_else (match_operator 2 "comparison_operator"
14327                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14328                                        (const_int 1)])
14329                       (match_operand 5 "" "")
14330                       (match_operand 6 "" "")))
14331    (set (match_operand:DI 0 "gpc_reg_operand" "")
14332         (plus:DI (match_dup 1)
14333                  (const_int -1)))
14334    (clobber (match_scratch:CC 3 ""))
14335    (clobber (match_scratch:DI 4 ""))]
14336   "TARGET_64BIT && reload_completed"
14337   [(parallel [(set (match_dup 3)
14338                    (compare:CC (plus:DI (match_dup 1)
14339                                         (const_int -1))
14340                                (const_int 0)))
14341               (set (match_dup 0)
14342                    (plus:DI (match_dup 1)
14343                             (const_int -1)))])
14344    (set (pc) (if_then_else (match_dup 7)
14345                            (match_dup 5)
14346                            (match_dup 6)))]
14347   "
14348 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14349                                 operands[3], const0_rtx); }")
14350
14351 (define_split
14352   [(set (pc)
14353         (if_then_else (match_operator 2 "comparison_operator"
14354                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14355                                        (const_int 1)])
14356                       (match_operand 5 "" "")
14357                       (match_operand 6 "" "")))
14358    (set (match_operand:DI 0 "nonimmediate_operand" "")
14359         (plus:DI (match_dup 1) (const_int -1)))
14360    (clobber (match_scratch:CC 3 ""))
14361    (clobber (match_scratch:DI 4 ""))]
14362   "TARGET_64BIT && reload_completed
14363    && ! gpc_reg_operand (operands[0], DImode)"
14364   [(parallel [(set (match_dup 3)
14365                    (compare:CC (plus:DI (match_dup 1)
14366                                         (const_int -1))
14367                                (const_int 0)))
14368               (set (match_dup 4)
14369                    (plus:DI (match_dup 1)
14370                             (const_int -1)))])
14371    (set (match_dup 0)
14372         (match_dup 4))
14373    (set (pc) (if_then_else (match_dup 7)
14374                            (match_dup 5)
14375                            (match_dup 6)))]
14376   "
14377 { operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode,
14378                                 operands[3], const0_rtx); }")
14379 \f
14380 (define_insn "trap"
14381   [(trap_if (const_int 1) (const_int 0))]
14382   ""
14383   "{t 31,0,0|trap}")
14384
14385 (define_expand "conditional_trap"
14386   [(trap_if (match_operator 0 "trap_comparison_operator"
14387                             [(match_dup 2) (match_dup 3)])
14388             (match_operand 1 "const_int_operand" ""))]
14389   ""
14390   "if (rs6000_compare_fp_p || operands[1] != const0_rtx) FAIL;
14391    operands[2] = rs6000_compare_op0;
14392    operands[3] = rs6000_compare_op1;")
14393
14394 (define_insn ""
14395   [(trap_if (match_operator 0 "trap_comparison_operator"
14396                             [(match_operand:SI 1 "register_operand" "r")
14397                              (match_operand:SI 2 "reg_or_short_operand" "rI")])
14398             (const_int 0))]
14399   ""
14400   "{t|tw}%V0%I2 %1,%2")
14401
14402 (define_insn ""
14403   [(trap_if (match_operator 0 "trap_comparison_operator"
14404                             [(match_operand:DI 1 "register_operand" "r")
14405                              (match_operand:DI 2 "reg_or_short_operand" "rI")])
14406             (const_int 0))]
14407   "TARGET_POWERPC64"
14408   "td%V0%I2 %1,%2")
14409 \f
14410 ;; Insns related to generating the function prologue and epilogue.
14411
14412 (define_expand "prologue"
14413   [(use (const_int 0))]
14414   "TARGET_SCHED_PROLOG"
14415   "
14416 {
14417       rs6000_emit_prologue ();
14418       DONE;
14419 }")
14420
14421 (define_insn "*movesi_from_cr_one"
14422   [(match_parallel 0 "mfcr_operation"
14423                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14424                          (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
14425                                      (match_operand 3 "immediate_operand" "n")]
14426                           UNSPEC_MOVESI_FROM_CR))])]
14427   "TARGET_MFCRF"
14428   "*
14429 {
14430   int mask = 0;
14431   int i;
14432   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14433   {
14434     mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14435     operands[4] = GEN_INT (mask);
14436     output_asm_insn (\"mfcr %1,%4\", operands);
14437   }
14438   return \"\";
14439 }"
14440   [(set_attr "type" "mfcrf")])
14441
14442 (define_insn "movesi_from_cr"
14443   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14444         (unspec:SI [(reg:CC 68) (reg:CC 69) (reg:CC 70) (reg:CC 71)
14445                     (reg:CC 72) (reg:CC 73) (reg:CC 74) (reg:CC 75)]
14446                    UNSPEC_MOVESI_FROM_CR))]
14447   ""
14448   "mfcr %0"
14449   [(set_attr "type" "mfcr")])
14450
14451 (define_insn "*stmw"
14452   [(match_parallel 0 "stmw_operation"
14453                    [(set (match_operand:SI 1 "memory_operand" "=m")
14454                          (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14455   "TARGET_MULTIPLE"
14456   "{stm|stmw} %2,%1")
14457
14458 (define_insn "*save_fpregs_si"
14459   [(match_parallel 0 "any_parallel_operand"
14460                    [(clobber (match_operand:SI 1 "register_operand" "=l"))
14461                     (use (match_operand:SI 2 "call_operand" "s"))
14462                     (set (match_operand:DF 3 "memory_operand" "=m")
14463                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14464   "TARGET_32BIT"
14465   "bl %z2"
14466   [(set_attr "type" "branch")
14467    (set_attr "length" "4")])
14468
14469 (define_insn "*save_fpregs_di"
14470   [(match_parallel 0 "any_parallel_operand"
14471                    [(clobber (match_operand:DI 1 "register_operand" "=l"))
14472                     (use (match_operand:DI 2 "call_operand" "s"))
14473                     (set (match_operand:DF 3 "memory_operand" "=m")
14474                          (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14475   "TARGET_64BIT"
14476   "bl %z2"
14477   [(set_attr "type" "branch")
14478    (set_attr "length" "4")])
14479
14480 ; These are to explain that changes to the stack pointer should
14481 ; not be moved over stores to stack memory.
14482 (define_insn "stack_tie"
14483   [(set (match_operand:BLK 0 "memory_operand" "+m")
14484         (unspec:BLK [(match_dup 0)] UNSPEC_TIE))]
14485   ""
14486   ""
14487   [(set_attr "length" "0")])
14488
14489
14490 (define_expand "epilogue"
14491   [(use (const_int 0))]
14492   "TARGET_SCHED_PROLOG"
14493   "
14494 {
14495       rs6000_emit_epilogue (FALSE);
14496       DONE;
14497 }")
14498
14499 ; On some processors, doing the mtcrf one CC register at a time is
14500 ; faster (like on the 604e).  On others, doing them all at once is
14501 ; faster; for instance, on the 601 and 750.
14502
14503 (define_expand "movsi_to_cr_one"
14504   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14505         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14506                     (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
14507   ""
14508   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
14509
14510 (define_insn "*movsi_to_cr"
14511   [(match_parallel 0 "mtcrf_operation"
14512                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14513                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14514                                      (match_operand 3 "immediate_operand" "n")]
14515                                     UNSPEC_MOVESI_TO_CR))])]
14516  ""
14517  "*
14518 {
14519   int mask = 0;
14520   int i;
14521   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14522     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14523   operands[4] = GEN_INT (mask);
14524   return \"mtcrf %4,%2\";
14525 }"
14526   [(set_attr "type" "mtcr")])
14527
14528 (define_insn "*mtcrfsi"
14529   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14530         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14531                     (match_operand 2 "immediate_operand" "n")]
14532                    UNSPEC_MOVESI_TO_CR))]
14533   "GET_CODE (operands[0]) == REG
14534    && CR_REGNO_P (REGNO (operands[0]))
14535    && GET_CODE (operands[2]) == CONST_INT
14536    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
14537   "mtcrf %R0,%1"
14538   [(set_attr "type" "mtcr")])
14539
14540 ; The load-multiple instructions have similar properties.
14541 ; Note that "load_multiple" is a name known to the machine-independent
14542 ; code that actually corresponds to the powerpc load-string.
14543
14544 (define_insn "*lmw"
14545   [(match_parallel 0 "lmw_operation"
14546                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14547                          (match_operand:SI 2 "memory_operand" "m"))])]
14548   "TARGET_MULTIPLE"
14549   "{lm|lmw} %1,%2")
14550
14551 (define_insn "*return_internal_si"
14552   [(return)
14553    (use (match_operand:SI 0 "register_operand" "lc"))]
14554   "TARGET_32BIT"
14555   "b%T0"
14556   [(set_attr "type" "jmpreg")])
14557
14558 (define_insn "*return_internal_di"
14559   [(return)
14560    (use (match_operand:DI 0 "register_operand" "lc"))]
14561   "TARGET_64BIT"
14562   "b%T0"
14563   [(set_attr "type" "jmpreg")])
14564
14565 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
14566 ; stuff was in GCC.  Oh, and "any_parallel_operand" is a bit flexible...
14567
14568 (define_insn "*return_and_restore_fpregs_si"
14569  [(match_parallel 0 "any_parallel_operand"
14570                   [(return)
14571                    (use (match_operand:SI 1 "register_operand" "l"))
14572                    (use (match_operand:SI 2 "call_operand" "s"))
14573                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14574                         (match_operand:DF 4 "memory_operand" "m"))])]
14575  "TARGET_32BIT"
14576  "b %z2")
14577
14578 (define_insn "*return_and_restore_fpregs_di"
14579  [(match_parallel 0 "any_parallel_operand"
14580                   [(return)
14581                    (use (match_operand:DI 1 "register_operand" "l"))
14582                    (use (match_operand:DI 2 "call_operand" "s"))
14583                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14584                         (match_operand:DF 4 "memory_operand" "m"))])]
14585  "TARGET_64BIT"
14586  "b %z2")
14587
14588 ; This is used in compiling the unwind routines.
14589 (define_expand "eh_return"
14590   [(use (match_operand 0 "general_operand" ""))]
14591   ""
14592   "
14593 {
14594   if (TARGET_32BIT)
14595     emit_insn (gen_eh_set_lr_si (operands[0]));
14596   else
14597     emit_insn (gen_eh_set_lr_di (operands[0]));
14598   DONE;
14599 }")
14600
14601 ; We can't expand this before we know where the link register is stored.
14602 (define_insn "eh_set_lr_si"
14603   [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
14604                     UNSPECV_EH_RR)
14605    (clobber (match_scratch:SI 1 "=&b"))]
14606   "TARGET_32BIT"
14607   "#")
14608
14609 (define_insn "eh_set_lr_di"
14610   [(unspec_volatile [(match_operand:DI 0 "register_operand" "r")]
14611                     UNSPECV_EH_RR)
14612    (clobber (match_scratch:DI 1 "=&b"))]
14613   "TARGET_64BIT"
14614   "#")
14615
14616 (define_split
14617   [(unspec_volatile [(match_operand 0 "register_operand" "")] UNSPECV_EH_RR)
14618    (clobber (match_scratch 1 ""))]
14619   "reload_completed"
14620   [(const_int 0)]
14621   "
14622 {
14623   rs6000_emit_eh_reg_restore (operands[0], operands[1]);
14624   DONE;
14625 }")
14626
14627 (define_insn "prefetch"
14628   [(prefetch (match_operand:V4SI 0 "address_operand" "p")
14629              (match_operand:SI 1 "const_int_operand" "n")
14630              (match_operand:SI 2 "const_int_operand" "n"))]
14631   "TARGET_POWERPC"
14632   "*
14633 {
14634   if (GET_CODE (operands[0]) == REG)
14635     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
14636   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
14637 }"
14638   [(set_attr "type" "load")])
14639
14640 (include "altivec.md")
14641 (include "spe.md")