OSDN Git Service

PR target/19389
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / rs6000.md
1 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
2 ;; Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005 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_expand "iorsi3"
2415   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2416         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
2417                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2418   ""
2419   "
2420 {
2421   if (GET_CODE (operands[2]) == CONST_INT
2422       && ! logical_operand (operands[2], SImode))
2423     {
2424       HOST_WIDE_INT value = INTVAL (operands[2]);
2425       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2426                  ? operands[0] : gen_reg_rtx (SImode));
2427
2428       emit_insn (gen_iorsi3 (tmp, operands[1],
2429                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2430       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2431       DONE;
2432     }
2433 }")
2434
2435 (define_expand "xorsi3"
2436   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2437         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2438                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2439   ""
2440   "
2441 {
2442   if (GET_CODE (operands[2]) == CONST_INT
2443       && ! logical_operand (operands[2], SImode))
2444     {
2445       HOST_WIDE_INT value = INTVAL (operands[2]);
2446       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2447                  ? operands[0] : gen_reg_rtx (SImode));
2448
2449       emit_insn (gen_xorsi3 (tmp, operands[1],
2450                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2451       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2452       DONE;
2453     }
2454 }")
2455
2456 (define_insn "*boolsi3_internal1"
2457   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2458         (match_operator:SI 3 "boolean_or_operator"
2459          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
2460           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
2461   ""
2462   "@
2463    %q3 %0,%1,%2
2464    {%q3il|%q3i} %0,%1,%b2
2465    {%q3iu|%q3is} %0,%1,%u2")
2466
2467 (define_insn "*boolsi3_internal2"
2468   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2469         (compare:CC (match_operator:SI 4 "boolean_or_operator"
2470          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2471           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2472          (const_int 0)))
2473    (clobber (match_scratch:SI 3 "=r,r"))]
2474   "TARGET_32BIT"
2475   "@
2476    %q4. %3,%1,%2
2477    #"
2478   [(set_attr "type" "compare")
2479    (set_attr "length" "4,8")])
2480
2481 (define_split
2482   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2483         (compare:CC (match_operator:SI 4 "boolean_operator"
2484          [(match_operand:SI 1 "gpc_reg_operand" "")
2485           (match_operand:SI 2 "gpc_reg_operand" "")])
2486          (const_int 0)))
2487    (clobber (match_scratch:SI 3 ""))]
2488   "TARGET_32BIT && reload_completed"
2489   [(set (match_dup 3) (match_dup 4))
2490    (set (match_dup 0)
2491         (compare:CC (match_dup 3)
2492                     (const_int 0)))]
2493   "")
2494
2495 (define_insn "*boolsi3_internal3"
2496   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2497         (compare:CC (match_operator:SI 4 "boolean_operator"
2498          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2499           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2500          (const_int 0)))
2501    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2502         (match_dup 4))]
2503   "TARGET_32BIT"
2504   "@
2505    %q4. %0,%1,%2
2506    #"
2507   [(set_attr "type" "compare")
2508    (set_attr "length" "4,8")])
2509
2510 (define_split
2511   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2512         (compare:CC (match_operator:SI 4 "boolean_operator"
2513          [(match_operand:SI 1 "gpc_reg_operand" "")
2514           (match_operand:SI 2 "gpc_reg_operand" "")])
2515          (const_int 0)))
2516    (set (match_operand:SI 0 "gpc_reg_operand" "")
2517         (match_dup 4))]
2518   "TARGET_32BIT && reload_completed"
2519   [(set (match_dup 0) (match_dup 4))
2520    (set (match_dup 3)
2521         (compare:CC (match_dup 0)
2522                     (const_int 0)))]
2523   "")
2524
2525 ;; Split a logical operation that we can't do in one insn into two insns,
2526 ;; each of which does one 16-bit part.  This is used by combine.
2527
2528 (define_split
2529   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2530         (match_operator:SI 3 "boolean_or_operator"
2531          [(match_operand:SI 1 "gpc_reg_operand" "")
2532           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
2533   ""
2534   [(set (match_dup 0) (match_dup 4))
2535    (set (match_dup 0) (match_dup 5))]
2536 "
2537 {
2538   rtx i;
2539   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
2540   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2541                                 operands[1], i);
2542   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
2543   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2544                                 operands[0], i);
2545 }")
2546
2547 (define_insn "*boolcsi3_internal1"
2548   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2549         (match_operator:SI 3 "boolean_operator"
2550          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2551           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
2552   ""
2553   "%q3 %0,%2,%1")
2554
2555 (define_insn "*boolcsi3_internal2"
2556   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2557         (compare:CC (match_operator:SI 4 "boolean_operator"
2558          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2559           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2560          (const_int 0)))
2561    (clobber (match_scratch:SI 3 "=r,r"))]
2562   "TARGET_32BIT"
2563   "@
2564    %q4. %3,%2,%1
2565    #"
2566   [(set_attr "type" "compare")
2567    (set_attr "length" "4,8")])
2568
2569 (define_split
2570   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2571         (compare:CC (match_operator:SI 4 "boolean_operator"
2572          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2573           (match_operand:SI 2 "gpc_reg_operand" "")])
2574          (const_int 0)))
2575    (clobber (match_scratch:SI 3 ""))]
2576   "TARGET_32BIT && reload_completed"
2577   [(set (match_dup 3) (match_dup 4))
2578    (set (match_dup 0)
2579         (compare:CC (match_dup 3)
2580                     (const_int 0)))]
2581   "")
2582
2583 (define_insn "*boolcsi3_internal3"
2584   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2585         (compare:CC (match_operator:SI 4 "boolean_operator"
2586          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2587           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2588          (const_int 0)))
2589    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2590         (match_dup 4))]
2591   "TARGET_32BIT"
2592   "@
2593    %q4. %0,%2,%1
2594    #"
2595   [(set_attr "type" "compare")
2596    (set_attr "length" "4,8")])
2597
2598 (define_split
2599   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2600         (compare:CC (match_operator:SI 4 "boolean_operator"
2601          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2602           (match_operand:SI 2 "gpc_reg_operand" "")])
2603          (const_int 0)))
2604    (set (match_operand:SI 0 "gpc_reg_operand" "")
2605         (match_dup 4))]
2606   "TARGET_32BIT && reload_completed"
2607   [(set (match_dup 0) (match_dup 4))
2608    (set (match_dup 3)
2609         (compare:CC (match_dup 0)
2610                     (const_int 0)))]
2611   "")
2612
2613 (define_insn "*boolccsi3_internal1"
2614   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2615         (match_operator:SI 3 "boolean_operator"
2616          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2617           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
2618   ""
2619   "%q3 %0,%1,%2")
2620
2621 (define_insn "*boolccsi3_internal2"
2622   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2623         (compare:CC (match_operator:SI 4 "boolean_operator"
2624          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2625           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2626          (const_int 0)))
2627    (clobber (match_scratch:SI 3 "=r,r"))]
2628   "TARGET_32BIT"
2629   "@
2630    %q4. %3,%1,%2
2631    #"
2632   [(set_attr "type" "compare")
2633    (set_attr "length" "4,8")])
2634
2635 (define_split
2636   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2637         (compare:CC (match_operator:SI 4 "boolean_operator"
2638          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2639           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2640          (const_int 0)))
2641    (clobber (match_scratch:SI 3 ""))]
2642   "TARGET_32BIT && reload_completed"
2643   [(set (match_dup 3) (match_dup 4))
2644    (set (match_dup 0)
2645         (compare:CC (match_dup 3)
2646                     (const_int 0)))]
2647   "")
2648
2649 (define_insn "*boolccsi3_internal3"
2650   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2651         (compare:CC (match_operator:SI 4 "boolean_operator"
2652          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
2653           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
2654          (const_int 0)))
2655    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2656         (match_dup 4))]
2657   "TARGET_32BIT"
2658   "@
2659    %q4. %0,%1,%2
2660    #"
2661   [(set_attr "type" "compare")
2662    (set_attr "length" "4,8")])
2663
2664 (define_split
2665   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2666         (compare:CC (match_operator:SI 4 "boolean_operator"
2667          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2668           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
2669          (const_int 0)))
2670    (set (match_operand:SI 0 "gpc_reg_operand" "")
2671         (match_dup 4))]
2672   "TARGET_32BIT && reload_completed"
2673   [(set (match_dup 0) (match_dup 4))
2674    (set (match_dup 3)
2675         (compare:CC (match_dup 0)
2676                     (const_int 0)))]
2677   "")
2678
2679 ;; maskir insn.  We need four forms because things might be in arbitrary
2680 ;; orders.  Don't define forms that only set CR fields because these
2681 ;; would modify an input register.
2682
2683 (define_insn "*maskir_internal1"
2684   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2685         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2686                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2687                 (and:SI (match_dup 2)
2688                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
2689   "TARGET_POWER"
2690   "maskir %0,%3,%2")
2691
2692 (define_insn "*maskir_internal2"
2693   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2694         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
2695                         (match_operand:SI 1 "gpc_reg_operand" "0"))
2696                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2697                         (match_dup 2))))]
2698   "TARGET_POWER"
2699   "maskir %0,%3,%2")
2700
2701 (define_insn "*maskir_internal3"
2702   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2703         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2704                         (match_operand:SI 3 "gpc_reg_operand" "r"))
2705                 (and:SI (not:SI (match_dup 2))
2706                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2707   "TARGET_POWER"
2708   "maskir %0,%3,%2")
2709
2710 (define_insn "*maskir_internal4"
2711   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2712         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2713                         (match_operand:SI 2 "gpc_reg_operand" "r"))
2714                 (and:SI (not:SI (match_dup 2))
2715                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
2716   "TARGET_POWER"
2717   "maskir %0,%3,%2")
2718
2719 (define_insn "*maskir_internal5"
2720   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2721         (compare:CC
2722          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2723                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2724                  (and:SI (match_dup 2)
2725                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
2726          (const_int 0)))
2727    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2728         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2729                 (and:SI (match_dup 2) (match_dup 3))))]
2730   "TARGET_POWER"
2731   "@
2732    maskir. %0,%3,%2
2733    #"
2734   [(set_attr "type" "compare")
2735    (set_attr "length" "4,8")])
2736
2737 (define_split
2738   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2739         (compare:CC
2740          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2741                          (match_operand:SI 1 "gpc_reg_operand" ""))
2742                  (and:SI (match_dup 2)
2743                          (match_operand:SI 3 "gpc_reg_operand" "")))
2744          (const_int 0)))
2745    (set (match_operand:SI 0 "gpc_reg_operand" "")
2746         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2747                 (and:SI (match_dup 2) (match_dup 3))))]
2748   "TARGET_POWER && reload_completed"
2749   [(set (match_dup 0)
2750         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2751                 (and:SI (match_dup 2) (match_dup 3))))
2752    (set (match_dup 4)
2753         (compare:CC (match_dup 0)
2754                     (const_int 0)))]
2755   "")
2756
2757 (define_insn "*maskir_internal6"
2758   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2759         (compare:CC
2760          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2761                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
2762                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2763                          (match_dup 2)))
2764          (const_int 0)))
2765    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2766         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2767                 (and:SI (match_dup 3) (match_dup 2))))]
2768   "TARGET_POWER"
2769   "@
2770    maskir. %0,%3,%2
2771    #"
2772   [(set_attr "type" "compare")
2773    (set_attr "length" "4,8")])
2774
2775 (define_split
2776   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2777         (compare:CC
2778          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
2779                          (match_operand:SI 1 "gpc_reg_operand" ""))
2780                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2781                          (match_dup 2)))
2782          (const_int 0)))
2783    (set (match_operand:SI 0 "gpc_reg_operand" "")
2784         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2785                 (and:SI (match_dup 3) (match_dup 2))))]
2786   "TARGET_POWER && reload_completed"
2787   [(set (match_dup 0)
2788         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2789                 (and:SI (match_dup 3) (match_dup 2))))
2790    (set (match_dup 4)
2791         (compare:CC (match_dup 0)
2792                     (const_int 0)))]
2793   "")
2794
2795 (define_insn "*maskir_internal7"
2796   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2797         (compare:CC
2798          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
2799                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
2800                  (and:SI (not:SI (match_dup 2))
2801                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2802          (const_int 0)))
2803    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2804         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2805                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2806   "TARGET_POWER"
2807   "@
2808    maskir. %0,%3,%2
2809    #"
2810   [(set_attr "type" "compare")
2811    (set_attr "length" "4,8")])
2812
2813 (define_split
2814   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2815         (compare:CC
2816          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
2817                          (match_operand:SI 3 "gpc_reg_operand" ""))
2818                  (and:SI (not:SI (match_dup 2))
2819                          (match_operand:SI 1 "gpc_reg_operand" "")))
2820          (const_int 0)))
2821    (set (match_operand:SI 0 "gpc_reg_operand" "")
2822         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2823                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2824   "TARGET_POWER && reload_completed"
2825   [(set (match_dup 0)
2826         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2827                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2828    (set (match_dup 4)
2829         (compare:CC (match_dup 0)
2830                     (const_int 0)))]
2831   "")
2832
2833 (define_insn "*maskir_internal8"
2834   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
2835         (compare:CC
2836          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
2837                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2838                  (and:SI (not:SI (match_dup 2))
2839                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
2840          (const_int 0)))
2841    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2842         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2843                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2844   "TARGET_POWER"
2845   "@
2846    maskir. %0,%3,%2
2847    #"
2848   [(set_attr "type" "compare")
2849    (set_attr "length" "4,8")])
2850
2851 (define_split
2852   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
2853         (compare:CC
2854          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
2855                          (match_operand:SI 2 "gpc_reg_operand" ""))
2856                  (and:SI (not:SI (match_dup 2))
2857                          (match_operand:SI 1 "gpc_reg_operand" "")))
2858          (const_int 0)))
2859    (set (match_operand:SI 0 "gpc_reg_operand" "")
2860         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2861                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2862   "TARGET_POWER && reload_completed"
2863   [(set (match_dup 0)
2864         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2865                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
2866    (set (match_dup 4)
2867         (compare:CC (match_dup 0)
2868                     (const_int 0)))]
2869   "")
2870 \f
2871 ;; Rotate and shift insns, in all their variants.  These support shifts,
2872 ;; field inserts and extracts, and various combinations thereof.
2873 (define_expand "insv"
2874   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
2875                        (match_operand:SI 1 "const_int_operand" "")
2876                        (match_operand:SI 2 "const_int_operand" ""))
2877         (match_operand 3 "gpc_reg_operand" ""))]
2878   ""
2879   "
2880 {
2881   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
2882      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
2883      compiler if the address of the structure is taken later.  */
2884   if (GET_CODE (operands[0]) == SUBREG
2885       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
2886     FAIL;
2887
2888   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
2889     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
2890   else
2891     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
2892   DONE;
2893 }")
2894
2895 (define_insn "insvsi"
2896   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2897                          (match_operand:SI 1 "const_int_operand" "i")
2898                          (match_operand:SI 2 "const_int_operand" "i"))
2899         (match_operand:SI 3 "gpc_reg_operand" "r"))]
2900   ""
2901   "*
2902 {
2903   int start = INTVAL (operands[2]) & 31;
2904   int size = INTVAL (operands[1]) & 31;
2905
2906   operands[4] = GEN_INT (32 - start - size);
2907   operands[1] = GEN_INT (start + size - 1);
2908   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2909 }"
2910   [(set_attr "type" "insert_word")])
2911
2912 (define_insn "*insvsi_internal1"
2913   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2914                          (match_operand:SI 1 "const_int_operand" "i")
2915                          (match_operand:SI 2 "const_int_operand" "i"))
2916         (ashift:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2917                    (match_operand:SI 4 "const_int_operand" "i")))]
2918   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2919   "*
2920 {
2921   int shift = INTVAL (operands[4]) & 31;
2922   int start = INTVAL (operands[2]) & 31;
2923   int size = INTVAL (operands[1]) & 31;
2924
2925   operands[4] = GEN_INT (shift - start - size);
2926   operands[1] = GEN_INT (start + size - 1);
2927   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2928 }"
2929   [(set_attr "type" "insert_word")])
2930
2931 (define_insn "*insvsi_internal2"
2932   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2933                          (match_operand:SI 1 "const_int_operand" "i")
2934                          (match_operand:SI 2 "const_int_operand" "i"))
2935         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2936                      (match_operand:SI 4 "const_int_operand" "i")))]
2937   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2938   "*
2939 {
2940   int shift = INTVAL (operands[4]) & 31;
2941   int start = INTVAL (operands[2]) & 31;
2942   int size = INTVAL (operands[1]) & 31;
2943
2944   operands[4] = GEN_INT (32 - shift - start - size);
2945   operands[1] = GEN_INT (start + size - 1);
2946   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2947 }"
2948   [(set_attr "type" "insert_word")])
2949
2950 (define_insn "*insvsi_internal3"
2951   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2952                          (match_operand:SI 1 "const_int_operand" "i")
2953                          (match_operand:SI 2 "const_int_operand" "i"))
2954         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2955                      (match_operand:SI 4 "const_int_operand" "i")))]
2956   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
2957   "*
2958 {
2959   int shift = INTVAL (operands[4]) & 31;
2960   int start = INTVAL (operands[2]) & 31;
2961   int size = INTVAL (operands[1]) & 31;
2962
2963   operands[4] = GEN_INT (32 - shift - start - size);
2964   operands[1] = GEN_INT (start + size - 1);
2965   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
2966 }"
2967   [(set_attr "type" "insert_word")])
2968
2969 (define_insn "*insvsi_internal4"
2970   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2971                          (match_operand:SI 1 "const_int_operand" "i")
2972                          (match_operand:SI 2 "const_int_operand" "i"))
2973         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2974                          (match_operand:SI 4 "const_int_operand" "i")
2975                          (match_operand:SI 5 "const_int_operand" "i")))]
2976   "INTVAL (operands[4]) >= INTVAL (operands[1])"
2977   "*
2978 {
2979   int extract_start = INTVAL (operands[5]) & 31;
2980   int extract_size = INTVAL (operands[4]) & 31;
2981   int insert_start = INTVAL (operands[2]) & 31;
2982   int insert_size = INTVAL (operands[1]) & 31;
2983
2984 /* Align extract field with insert field */
2985   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
2986   operands[1] = GEN_INT (insert_start + insert_size - 1);
2987   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
2988 }"
2989   [(set_attr "type" "insert_word")])
2990
2991 ;; combine patterns for rlwimi
2992 (define_insn "*insvsi_internal5"
2993   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2994         (ior:SI (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
2995                         (match_operand:SI 1 "mask_operand" "i"))
2996                 (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2997                                      (match_operand:SI 2 "const_int_operand" "i"))
2998                         (match_operand:SI 5 "mask_operand" "i"))))]
2999   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3000   "*
3001 {
3002  int me = extract_ME(operands[5]);
3003  int mb = extract_MB(operands[5]);
3004  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3005  operands[2] = GEN_INT(mb);
3006  operands[1] = GEN_INT(me);
3007  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3008 }"
3009   [(set_attr "type" "insert_word")])
3010
3011 (define_insn "*insvsi_internal6"
3012   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3013         (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3014                                      (match_operand:SI 2 "const_int_operand" "i"))
3015                         (match_operand:SI 5 "mask_operand" "i"))
3016                 (and:SI (match_operand:SI 4 "gpc_reg_operand" "0")
3017                         (match_operand:SI 1 "mask_operand" "i"))))]
3018   "TARGET_POWERPC && INTVAL(operands[1]) == ~INTVAL(operands[5])"
3019   "*
3020 {
3021  int me = extract_ME(operands[5]);
3022  int mb = extract_MB(operands[5]);
3023  operands[4] = GEN_INT(32 - INTVAL(operands[2]));
3024  operands[2] = GEN_INT(mb);
3025  operands[1] = GEN_INT(me);
3026  return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3027 }"
3028   [(set_attr "type" "insert_word")])
3029
3030 (define_insn "insvdi"
3031   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3032                          (match_operand:SI 1 "const_int_operand" "i")
3033                          (match_operand:SI 2 "const_int_operand" "i"))
3034         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3035   "TARGET_POWERPC64"
3036   "*
3037 {
3038   int start = INTVAL (operands[2]) & 63;
3039   int size = INTVAL (operands[1]) & 63;
3040
3041   operands[1] = GEN_INT (64 - start - size);
3042   return \"rldimi %0,%3,%H1,%H2\";
3043 }")
3044
3045 (define_insn "*insvdi_internal2"
3046   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3047                          (match_operand:SI 1 "const_int_operand" "i")
3048                          (match_operand:SI 2 "const_int_operand" "i"))
3049         (ashiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3050                      (match_operand:SI 4 "const_int_operand" "i")))]
3051   "TARGET_POWERPC64
3052    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3053   "*
3054 {
3055   int shift = INTVAL (operands[4]) & 63;
3056   int start = (INTVAL (operands[2]) & 63) - 32;
3057   int size = INTVAL (operands[1]) & 63;
3058
3059   operands[4] = GEN_INT (64 - shift - start - size);
3060   operands[2] = GEN_INT (start);
3061   operands[1] = GEN_INT (start + size - 1);
3062   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3063 }")
3064
3065 (define_insn "*insvdi_internal3"
3066   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3067                          (match_operand:SI 1 "const_int_operand" "i")
3068                          (match_operand:SI 2 "const_int_operand" "i"))
3069         (lshiftrt:DI (match_operand:DI 3 "gpc_reg_operand" "r")
3070                      (match_operand:SI 4 "const_int_operand" "i")))]
3071   "TARGET_POWERPC64
3072    && insvdi_rshift_rlwimi_p (operands[1], operands[2], operands[4])"
3073   "*
3074 {
3075   int shift = INTVAL (operands[4]) & 63;
3076   int start = (INTVAL (operands[2]) & 63) - 32;
3077   int size = INTVAL (operands[1]) & 63;
3078
3079   operands[4] = GEN_INT (64 - shift - start - size);
3080   operands[2] = GEN_INT (start);
3081   operands[1] = GEN_INT (start + size - 1);
3082   return \"rlwimi %0,%3,%h4,%h2,%h1\";
3083 }")
3084
3085 (define_expand "extzv"
3086   [(set (match_operand 0 "gpc_reg_operand" "")
3087         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3088                        (match_operand:SI 2 "const_int_operand" "")
3089                        (match_operand:SI 3 "const_int_operand" "")))]
3090   ""
3091   "
3092 {
3093   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3094      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3095      compiler if the address of the structure is taken later.  */
3096   if (GET_CODE (operands[0]) == SUBREG
3097       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3098     FAIL;
3099
3100   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3101     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
3102   else
3103     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
3104   DONE;
3105 }")
3106
3107 (define_insn "extzvsi"
3108   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3109         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3110                          (match_operand:SI 2 "const_int_operand" "i")
3111                          (match_operand:SI 3 "const_int_operand" "i")))]
3112   ""
3113   "*
3114 {
3115   int start = INTVAL (operands[3]) & 31;
3116   int size = INTVAL (operands[2]) & 31;
3117
3118   if (start + size >= 32)
3119     operands[3] = const0_rtx;
3120   else
3121     operands[3] = GEN_INT (start + size);
3122   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
3123 }")
3124
3125 (define_insn "*extzvsi_internal1"
3126   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3127         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3128                          (match_operand:SI 2 "const_int_operand" "i,i")
3129                          (match_operand:SI 3 "const_int_operand" "i,i"))
3130                     (const_int 0)))
3131    (clobber (match_scratch:SI 4 "=r,r"))]
3132   ""
3133   "*
3134 {
3135   int start = INTVAL (operands[3]) & 31;
3136   int size = INTVAL (operands[2]) & 31;
3137
3138   /* Force split for non-cc0 compare.  */
3139   if (which_alternative == 1)
3140      return \"#\";
3141
3142   /* If the bit-field being tested fits in the upper or lower half of a
3143      word, it is possible to use andiu. or andil. to test it.  This is
3144      useful because the condition register set-use delay is smaller for
3145      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3146      position is 0 because the LT and GT bits may be set wrong.  */
3147
3148   if ((start > 0 && start + size <= 16) || start >= 16)
3149     {
3150       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3151                               - (1 << (16 - (start & 15) - size))));
3152       if (start < 16)
3153         return \"{andiu.|andis.} %4,%1,%3\";
3154       else
3155         return \"{andil.|andi.} %4,%1,%3\";
3156     }
3157
3158   if (start + size >= 32)
3159     operands[3] = const0_rtx;
3160   else
3161     operands[3] = GEN_INT (start + size);
3162   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
3163 }"
3164   [(set_attr "type" "compare")
3165    (set_attr "length" "4,8")])
3166
3167 (define_split
3168   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3169         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3170                          (match_operand:SI 2 "const_int_operand" "")
3171                          (match_operand:SI 3 "const_int_operand" ""))
3172                     (const_int 0)))
3173    (clobber (match_scratch:SI 4 ""))]
3174   "reload_completed"
3175   [(set (match_dup 4)
3176         (zero_extract:SI (match_dup 1) (match_dup 2)
3177                          (match_dup 3)))
3178    (set (match_dup 0)
3179         (compare:CC (match_dup 4)
3180                     (const_int 0)))]
3181   "")
3182
3183 (define_insn "*extzvsi_internal2"
3184   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3185         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3186                          (match_operand:SI 2 "const_int_operand" "i,i")
3187                          (match_operand:SI 3 "const_int_operand" "i,i"))
3188                     (const_int 0)))
3189    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3190         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3191   ""
3192   "*
3193 {
3194   int start = INTVAL (operands[3]) & 31;
3195   int size = INTVAL (operands[2]) & 31;
3196
3197   /* Force split for non-cc0 compare.  */
3198   if (which_alternative == 1)
3199      return \"#\";
3200
3201   /* Since we are using the output value, we can't ignore any need for
3202      a shift.  The bit-field must end at the LSB.  */
3203   if (start >= 16 && start + size == 32)
3204     {
3205       operands[3] = GEN_INT ((1 << size) - 1);
3206       return \"{andil.|andi.} %0,%1,%3\";
3207     }
3208
3209   if (start + size >= 32)
3210     operands[3] = const0_rtx;
3211   else
3212     operands[3] = GEN_INT (start + size);
3213   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
3214 }"
3215   [(set_attr "type" "compare")
3216    (set_attr "length" "4,8")])
3217
3218 (define_split
3219   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3220         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3221                          (match_operand:SI 2 "const_int_operand" "")
3222                          (match_operand:SI 3 "const_int_operand" ""))
3223                     (const_int 0)))
3224    (set (match_operand:SI 0 "gpc_reg_operand" "")
3225         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3226   "reload_completed"
3227   [(set (match_dup 0)
3228         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3229    (set (match_dup 4)
3230         (compare:CC (match_dup 0)
3231                     (const_int 0)))]
3232   "")
3233
3234 (define_insn "extzvdi"
3235   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3236         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3237                          (match_operand:SI 2 "const_int_operand" "i")
3238                          (match_operand:SI 3 "const_int_operand" "i")))]
3239   "TARGET_POWERPC64"
3240   "*
3241 {
3242   int start = INTVAL (operands[3]) & 63;
3243   int size = INTVAL (operands[2]) & 63;
3244
3245   if (start + size >= 64)
3246     operands[3] = const0_rtx;
3247   else
3248     operands[3] = GEN_INT (start + size);
3249   operands[2] = GEN_INT (64 - size);
3250   return \"rldicl %0,%1,%3,%2\";
3251 }")
3252
3253 (define_insn "*extzvdi_internal1"
3254   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3255         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3256                          (match_operand:SI 2 "const_int_operand" "i")
3257                          (match_operand:SI 3 "const_int_operand" "i"))
3258                     (const_int 0)))
3259    (clobber (match_scratch:DI 4 "=r"))]
3260   "TARGET_64BIT"
3261   "*
3262 {
3263   int start = INTVAL (operands[3]) & 63;
3264   int size = INTVAL (operands[2]) & 63;
3265
3266   if (start + size >= 64)
3267     operands[3] = const0_rtx;
3268   else
3269     operands[3] = GEN_INT (start + size);
3270   operands[2] = GEN_INT (64 - size);
3271   return \"rldicl. %4,%1,%3,%2\";
3272 }"
3273   [(set_attr "type" "compare")])
3274
3275 (define_insn "*extzvdi_internal2"
3276   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3277         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3278                          (match_operand:SI 2 "const_int_operand" "i")
3279                          (match_operand:SI 3 "const_int_operand" "i"))
3280                     (const_int 0)))
3281    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3282         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3283   "TARGET_64BIT"
3284   "*
3285 {
3286   int start = INTVAL (operands[3]) & 63;
3287   int size = INTVAL (operands[2]) & 63;
3288
3289   if (start + size >= 64)
3290     operands[3] = const0_rtx;
3291   else
3292     operands[3] = GEN_INT (start + size);
3293   operands[2] = GEN_INT (64 - size);
3294   return \"rldicl. %0,%1,%3,%2\";
3295 }"
3296   [(set_attr "type" "compare")])
3297
3298 (define_insn "rotlsi3"
3299   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3300         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3301                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3302   ""
3303   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
3304
3305 (define_insn "*rotlsi3_internal2"
3306   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3307         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3308                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3309                     (const_int 0)))
3310    (clobber (match_scratch:SI 3 "=r,r"))]
3311   ""
3312   "@
3313    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff
3314    #"
3315   [(set_attr "type" "delayed_compare")
3316    (set_attr "length" "4,8")])
3317
3318 (define_split
3319   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3320         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
3321                                (match_operand:SI 2 "reg_or_cint_operand" ""))
3322                     (const_int 0)))
3323    (clobber (match_scratch:SI 3 ""))]
3324   "reload_completed"
3325   [(set (match_dup 3)
3326         (rotate:SI (match_dup 1) (match_dup 2)))
3327    (set (match_dup 0)
3328         (compare:CC (match_dup 3)
3329                     (const_int 0)))]
3330   "")
3331
3332 (define_insn "*rotlsi3_internal3"
3333   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3334         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3335                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3336                     (const_int 0)))
3337    (set (match_operand:SI 0 "gpc_reg_op