OSDN Git Service

(decrement_and_branch): Finish last fix; update matching constraint.
[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, 91, 92, 93, 94, 1995 Free Software Foundation, Inc.
3 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
4
5 ;; This file is part of GNU CC.
6
7 ;; GNU CC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; any later version.
11
12 ;; GNU CC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU CC; see the file COPYING.  If not, write to
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
22 \f
23 ;; Define an insn type attribute.  This is used in function unit delay
24 ;; computations.
25 (define_attr "type" "integer,load,fpload,imul,idiv,branch,compare,delayed_compare,fpcompare,mtjmpr,fp,dmul,sdiv,ddiv,ssqrt,dsqrt,jmpreg"
26   (const_string "integer"))
27
28 ;; Length (in bytes).
29 (define_attr "length" ""
30   (if_then_else (eq_attr "type" "branch")
31                 (if_then_else (and (ge (minus (pc) (match_dup 0))
32                                        (const_int -32768))
33                                    (lt (minus (pc) (match_dup 0))
34                                        (const_int 32767)))
35                               (const_int 8)
36                               (const_int 12))
37                 (const_int 4)))
38
39 ;; Processor type -- this attribute must exactly match the processor_type
40 ;; enumeration in rs6000.h.
41
42 (define_attr "cpu" "rios1,rios2,ppc403,ppc601,ppc603,ppc604,ppc620"
43   (const (symbol_ref "rs6000_cpu_attr")))
44
45 ; (define_function_unit NAME MULTIPLICITY SIMULTANEITY
46 ;                       TEST READY-DELAY ISSUE-DELAY [CONFLICT-LIST])
47
48 ; Load/Store Unit -- POWER/2 and pure PowerPC only
49 ; (POWER and 601 use Integer Unit)
50 (define_function_unit "lsu" 1 0
51   (and (eq_attr "type" "load")
52        (eq_attr "cpu" "rios2,ppc603,ppc604,ppc620"))
53   2 0)
54
55 (define_function_unit "lsu" 1 0
56   (and (eq_attr "type" "fpload")
57        (eq_attr "cpu" "rios2,ppc603,ppc604,ppc620"))
58   2 0)
59
60 (define_function_unit "iu" 1 0
61   (and (eq_attr "type" "load")
62        (eq_attr "cpu" "rios1,ppc403,ppc601"))
63   2 0)
64
65 (define_function_unit "iu" 1 0
66   (and (eq_attr "type" "fpload")
67        (eq_attr "cpu" "rios1,ppc601"))
68   3 0)
69
70 ; Integer Unit (RIOS1, PPC601, PPC603)
71 ; Trivial operations take one cycle which need not be listed here.
72 (define_function_unit "iu" 1 0
73   (and (eq_attr "type" "imul")
74        (eq_attr "cpu" "rios1"))
75   3 3)
76
77 (define_function_unit "iu" 1 0
78   (and (eq_attr "type" "imul")
79        (eq_attr "cpu" "ppc403"))
80   4 4)
81
82 (define_function_unit "iu" 1 0
83   (and (eq_attr "type" "imul")
84        (eq_attr "cpu" "ppc601,ppc603"))
85   5 5)
86
87 (define_function_unit "iu" 1 0
88   (and (eq_attr "type" "idiv")
89        (eq_attr "cpu" "rios1"))
90   19 19)
91
92 (define_function_unit "iu" 1 0
93   (and (eq_attr "type" "idiv")
94        (eq_attr "cpu" "ppc403"))
95   33 33)
96
97 (define_function_unit "iu" 1 0
98   (and (eq_attr "type" "idiv")
99        (eq_attr "cpu" "ppc601"))
100   36 36)
101
102 (define_function_unit "iu" 1 0
103   (and (eq_attr "type" "idiv")
104        (eq_attr "cpu" "ppc603"))
105   37 36)
106
107 ; RIOS2 has two integer units: a primary one which can perform all
108 ; operations and a secondary one which is fed in lock step with the first
109 ; and can perform "simple" integer operations.
110 (define_function_unit "iu2" 2 0
111   (and (eq_attr "type" "integer")
112        (eq_attr "cpu" "rios2"))
113   1 0
114   [(eq_attr "type" "imul,idiv")])
115
116 (define_function_unit "imuldiv" 1 0
117   (and (eq_attr "type" "imul")
118        (eq_attr "cpu" "rios2"))
119   2 2
120   [(eq_attr "type" "integer")])
121
122 (define_function_unit "imuldiv" 1 0
123   (and (eq_attr "type" "idiv")
124        (eq_attr "cpu" "rios2"))
125   13 13
126   [(eq_attr "type" "integer")])
127
128 ; PPC604 has three integer units: one primary and two secondary.
129 (define_function_unit "iu3" 3 0
130   (and (eq_attr "type" "integer")
131        (eq_attr "cpu" "ppc604,ppc620"))
132   1 0
133   [(eq_attr "type" "imul,idiv")])
134
135 (define_function_unit "imuldiv" 1 0
136   (and (eq_attr "type" "imul")
137        (eq_attr "cpu" "ppc604,ppc620"))
138   4 2
139   [(eq_attr "type" "integer")])
140
141 (define_function_unit "imuldiv" 1 0
142   (and (eq_attr "type" "idiv")
143        (eq_attr "cpu" "ppc604,ppc620"))
144   20 19
145   [(eq_attr "type" "integer")])
146
147 ; Branch Processing Unit
148 (define_function_unit "bpu" 1 0
149   (eq_attr "type" "compare")
150   4 0)
151
152 (define_function_unit "bpu" 1 0
153   (eq_attr "type" "delayed_compare")
154   5 0)
155
156 (define_function_unit "bpu" 1 0
157   (and (eq_attr "type" "fpcompare")
158        (eq_attr "cpu" "rios1,rios2"))
159   8 0)
160
161 (define_function_unit "bpu" 1 0
162   (and (eq_attr "type" "fpcompare")
163        (eq_attr "cpu" "ppc601,ppc603,ppc604,ppc620"))
164   4 0)
165
166 (define_function_unit "bpu" 1 0
167   (and (eq_attr "type" "mtjmpr")
168        (eq_attr "cpu" "rios1,rios2"))
169   5 0)
170
171 (define_function_unit "bpu" 1 0
172   (and (eq_attr "type" "mtjmpr")
173        (eq_attr "cpu" "ppc403,ppc601,ppc603,ppc604,ppc620"))
174   4 0)
175
176 ; Floating Point Unit (RIOS1, PPC601, PPC603, PPC604).
177 (define_function_unit "fpu" 1 0
178   (and (eq_attr "type" "fp,dmul")
179        (eq_attr "cpu" "rios1"))
180   2 0)
181
182 (define_function_unit "fpu" 1 0
183   (and (eq_attr "type" "fp")
184        (eq_attr "cpu" "ppc601"))
185   4 0)
186
187 (define_function_unit "fpu" 1 0
188   (and (eq_attr "type" "fp")
189        (eq_attr "cpu" "ppc603,ppc604,ppc620"))
190   3 0)
191
192 (define_function_unit "fpu" 1 0
193   (and (eq_attr "type" "dmul")
194        (eq_attr "cpu" "ppc601"))
195   5 5)
196
197 (define_function_unit "fpu" 1 0
198   (and (eq_attr "type" "dmul")
199        (eq_attr "cpu" "ppc603"))
200   4 2)
201
202 (define_function_unit "fpu" 1 0
203   (and (eq_attr "type" "dmul")
204        (eq_attr "cpu" "ppc604,ppc620"))
205   3 0)
206
207 (define_function_unit "fpu" 1 0
208   (and (eq_attr "type" "sdiv,ddiv")
209        (eq_attr "cpu" "rios1"))
210   19 19)
211
212 (define_function_unit "fpu" 1 0
213   (and (eq_attr "type" "sdiv")
214        (eq_attr "cpu" "ppc601"))
215   17 17)
216
217 (define_function_unit "fpu" 1 0
218   (and (eq_attr "type" "sdiv")
219        (eq_attr "cpu" "ppc603,ppc604,ppc620"))
220   18 18)
221
222 (define_function_unit "fpu" 1 0
223   (and (eq_attr "type" "ddiv")
224        (eq_attr "cpu" "ppc601,ppc604,ppc620"))
225   31 31)
226
227 (define_function_unit "fpu" 1 0
228   (and (eq_attr "type" "ddiv")
229        (eq_attr "cpu" "ppc603"))
230   33 33)
231
232 (define_function_unit "fpu" 1 0
233   (and (eq_attr "type" "ssqrt")
234        (eq_attr "cpu" "ppc620"))
235   31 31)
236
237 (define_function_unit "fpu" 1 0
238   (and (eq_attr "type" "dsqrt")
239        (eq_attr "cpu" "ppc620"))
240   31 31)
241
242 ; RIOS2 has two symmetric FPUs.
243 (define_function_unit "fpu2" 2 0
244   (and (eq_attr "type" "fp")
245        (eq_attr "cpu" "rios2"))
246   2 0)
247
248 (define_function_unit "fpu2" 2 0
249   (and (eq_attr "type" "dmul")
250        (eq_attr "cpu" "rios2"))
251   2 0)
252
253 (define_function_unit "fpu2" 2 0
254   (and (eq_attr "type" "sdiv,ddiv")
255        (eq_attr "cpu" "rios2"))
256   17 17)
257
258 (define_function_unit "fpu2" 2 0
259   (and (eq_attr "type" "ssqrt,dsqrt")
260        (eq_attr "cpu" "rios2"))
261   26 26)
262 \f
263 ;; Start with fixed-point load and store insns.  Here we put only the more
264 ;; complex forms.  Basic data transfer is done later.
265
266 (define_expand "zero_extendqidi2"
267   [(set (match_operand:DI 0 "gpc_reg_operand" "")
268         (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "")))]
269   "TARGET_POWERPC64"
270   "")
271
272 (define_insn ""
273   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
274         (zero_extend:DI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
275   "TARGET_POWERPC64"
276   "@
277    lbz%U1%X1 %0,%1
278    rldicl %0,%1,0,56"
279   [(set_attr "type" "load,*")])
280
281 (define_insn ""
282   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
283         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
284                     (const_int 0)))
285    (clobber (match_scratch:DI 2 "=r"))]
286   "TARGET_POWERPC64"
287   "rldicl. %2,%1,0,56"
288   [(set_attr "type" "compare")])
289
290 (define_insn ""
291   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
292         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
293                     (const_int 0)))
294    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
295         (zero_extend:DI (match_dup 1)))]
296   "TARGET_POWERPC64"
297   "rldicl. %0,%1,0,56"
298   [(set_attr "type" "compare")])
299
300 (define_insn "extendqidi2"
301   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
302         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
303   "TARGET_POWERPC64"
304   "extsb %0,%1")
305
306 (define_insn ""
307   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
308         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
309                     (const_int 0)))
310    (clobber (match_scratch:DI 2 "=r"))]
311   "TARGET_POWERPC64"
312   "extsb. %2,%1"
313   [(set_attr "type" "compare")])
314
315 (define_insn ""
316   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
317         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
318                     (const_int 0)))
319    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
320         (sign_extend:DI (match_dup 1)))]
321   "TARGET_POWERPC64"
322   "extsb. %0,%1"
323   [(set_attr "type" "compare")])
324
325 (define_expand "zero_extendhidi2"
326   [(set (match_operand:DI 0 "gpc_reg_operand" "")
327         (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
328   "TARGET_POWERPC64"
329   "")
330
331 (define_insn ""
332   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
333         (zero_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
334   "TARGET_POWERPC64"
335   "@
336    lhz%U1%X1 %0,%1
337    rldicl %0,%1,0,48"
338   [(set_attr "type" "load,*")])
339
340 (define_insn ""
341   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
342         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
343                     (const_int 0)))
344    (clobber (match_scratch:DI 2 "=r"))]
345   "TARGET_POWERPC64"
346   "rldicl. %2,%1,0,48"
347   [(set_attr "type" "compare")])
348
349 (define_insn ""
350   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
351         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
352                     (const_int 0)))
353    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
354         (zero_extend:DI (match_dup 1)))]
355   "TARGET_POWERPC64"
356   "rldicl. %0,%1,0,48"
357   [(set_attr "type" "compare")])
358
359 (define_expand "extendhidi2"
360   [(set (match_operand:DI 0 "gpc_reg_operand" "")
361         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
362   "TARGET_POWERPC64"
363   "")
364
365 (define_insn ""
366   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
367         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
368   "TARGET_POWERPC64"
369   "@
370    lha%U1%X1 %0,%1
371    extsh %0,%1"
372   [(set_attr "type" "load,*")])
373
374 (define_insn ""
375   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
376         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
377                     (const_int 0)))
378    (clobber (match_scratch:DI 2 "=r"))]
379   "TARGET_POWERPC64"
380   "extsh. %2,%1"
381   [(set_attr "type" "compare")])
382
383 (define_insn ""
384   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
385         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
386                     (const_int 0)))
387    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
388         (sign_extend:DI (match_dup 1)))]
389   "TARGET_POWERPC64"
390   "extsh. %0,%1"
391   [(set_attr "type" "compare")])
392
393 (define_expand "zero_extendsidi2"
394   [(set (match_operand:DI 0 "gpc_reg_operand" "")
395         (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
396   "TARGET_POWERPC64"
397   "")
398
399 (define_insn ""
400   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
401         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r")))]
402   "TARGET_POWERPC64"
403   "@
404    lwz%U1%X1 %0,%1
405    rldicl %0,%1,0,32"
406   [(set_attr "type" "load,*")])
407
408 (define_insn ""
409   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
410         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
411                     (const_int 0)))
412    (clobber (match_scratch:DI 2 "=r"))]
413   "TARGET_POWERPC64"
414   "rldicl. %2,%1,0,32"
415   [(set_attr "type" "compare")])
416
417 (define_insn ""
418   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
419         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
420                     (const_int 0)))
421    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
422         (zero_extend:DI (match_dup 1)))]
423   "TARGET_POWERPC64"
424   "rldicl. %0,%1,0,32"
425   [(set_attr "type" "compare")])
426
427 (define_expand "extendsidi2"
428   [(set (match_operand:DI 0 "gpc_reg_operand" "")
429         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
430   "TARGET_POWERPC64"
431   "")
432
433 (define_insn ""
434   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
435         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
436   "TARGET_POWERPC64"
437   "@
438    lwa%U1%X1 %0,%1
439    extsw %0,%1"
440   [(set_attr "type" "load,*")])
441
442 (define_insn ""
443   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
444         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
445                     (const_int 0)))
446    (clobber (match_scratch:DI 2 "=r"))]
447   "TARGET_POWERPC64"
448   "extsw. %2,%1"
449   [(set_attr "type" "compare")])
450
451 (define_insn ""
452   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
453         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
454                     (const_int 0)))
455    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
456         (sign_extend:DI (match_dup 1)))]
457   "TARGET_POWERPC64"
458   "extsw. %0,%1"
459   [(set_attr "type" "compare")])
460
461 (define_expand "zero_extendqisi2"
462   [(set (match_operand:SI 0 "gpc_reg_operand" "")
463         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
464   ""
465   "")
466
467 (define_insn ""
468   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
469         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
470   ""
471   "@
472    lbz%U1%X1 %0,%1
473    {rlinm|rlwinm} %0,%1,0,0xff"
474   [(set_attr "type" "load,*")])
475
476 (define_insn ""
477   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
478         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
479                     (const_int 0)))
480    (clobber (match_scratch:SI 2 "=r"))]
481   ""
482   "{andil.|andi.} %2,%1,0xff"
483   [(set_attr "type" "compare")])
484
485 (define_insn ""
486   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
487         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
488                     (const_int 0)))
489    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
490         (zero_extend:SI (match_dup 1)))]
491   ""
492   "{andil.|andi.} %0,%1,0xff"
493   [(set_attr "type" "compare")])
494
495 (define_expand "extendqisi2"
496   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
497    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
498   ""
499   "
500 {
501   if (TARGET_POWERPC)
502     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
503   else if (TARGET_POWER)
504     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
505   else
506     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
507   DONE;
508 }")
509
510 (define_insn "extendqisi2_ppc"
511   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
512         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
513   "TARGET_POWERPC"
514   "extsb %0,%1")
515
516 (define_insn ""
517   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
518         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
519                     (const_int 0)))
520    (clobber (match_scratch:SI 2 "=r"))]
521   "TARGET_POWERPC"
522   "extsb. %2,%1"
523   [(set_attr "type" "compare")])
524
525 (define_insn ""
526   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
527         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
528                     (const_int 0)))
529    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
530         (sign_extend:SI (match_dup 1)))]
531   "TARGET_POWERPC"
532   "extsb. %0,%1"
533   [(set_attr "type" "compare")])
534
535 (define_expand "extendqisi2_power"
536   [(parallel [(set (match_dup 2)
537                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
538                               (const_int 24)))
539               (clobber (scratch:SI))])
540    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
541                    (ashiftrt:SI (match_dup 2)
542                                 (const_int 24)))
543               (clobber (scratch:SI))])]
544   "TARGET_POWER"
545   "
546 { operands[1] = gen_lowpart (SImode, operands[1]);
547   operands[2] = gen_reg_rtx (SImode); }")
548
549 (define_expand "extendqisi2_no_power"
550   [(set (match_dup 2)
551         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
552                    (const_int 24)))
553    (set (match_operand:SI 0 "gpc_reg_operand" "")
554         (ashiftrt:SI (match_dup 2)
555                      (const_int 24)))]
556   "! TARGET_POWER && ! TARGET_POWERPC"
557   "
558 { operands[1] = gen_lowpart (SImode, operands[1]);
559   operands[2] = gen_reg_rtx (SImode); }")
560
561 (define_expand "zero_extendqihi2"
562   [(set (match_operand:HI 0 "gpc_reg_operand" "")
563         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
564   ""
565   "")
566
567 (define_insn ""
568   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
569         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
570   ""
571   "@
572    lbz%U1%X1 %0,%1
573    {rlinm|rlwinm} %0,%1,0,0xff"
574   [(set_attr "type" "load,*")])
575
576 (define_insn ""
577   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
578         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
579                     (const_int 0)))
580    (clobber (match_scratch:HI 2 "=r"))]
581   ""
582   "{andil.|andi.} %2,%1,0xff"
583   [(set_attr "type" "compare")])
584
585 (define_insn ""
586   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
587         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
588                     (const_int 0)))
589    (set (match_operand:HI 0 "gpc_reg_operand" "=r")
590         (zero_extend:HI (match_dup 1)))]
591   ""
592   "{andil.|andi.} %0,%1,0xff"
593   [(set_attr "type" "compare")])
594
595 (define_expand "extendqihi2"
596   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
597    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
598   ""
599   "
600 {
601   if (TARGET_POWERPC)
602     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
603   else if (TARGET_POWER)
604     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
605   else
606     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
607   DONE;
608 }")
609
610 (define_insn "extendqihi2_ppc"
611   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
612         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
613   "TARGET_POWERPC"
614   "extsb %0,%1")
615
616 (define_insn ""
617   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
618         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
619                     (const_int 0)))
620    (clobber (match_scratch:HI 2 "=r"))]
621   "TARGET_POWERPC"
622   "extsb. %2,%1"
623   [(set_attr "type" "compare")])
624
625 (define_insn ""
626   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
627         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
628                     (const_int 0)))
629    (set (match_operand:HI 0 "gpc_reg_operand" "=r")
630         (sign_extend:HI (match_dup 1)))]
631   "TARGET_POWERPC"
632   "extsb. %0,%1"
633   [(set_attr "type" "compare")])
634
635 (define_expand "extendqihi2_power"
636   [(parallel [(set (match_dup 2)
637                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
638                               (const_int 24)))
639               (clobber (scratch:SI))])
640    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
641                    (ashiftrt:SI (match_dup 2)
642                                 (const_int 24)))
643               (clobber (scratch:SI))])]
644   "TARGET_POWER"
645   "
646 { operands[0] = gen_lowpart (SImode, operands[0]);
647   operands[1] = gen_lowpart (SImode, operands[1]);
648   operands[2] = gen_reg_rtx (SImode); }")
649
650 (define_expand "extendqihi2_no_power"
651   [(set (match_dup 2)
652         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
653                    (const_int 24)))
654    (set (match_operand:HI 0 "gpc_reg_operand" "")
655         (ashiftrt:SI (match_dup 2)
656                      (const_int 24)))]
657   "! TARGET_POWER && ! TARGET_POWERPC"
658   "
659 { operands[0] = gen_lowpart (SImode, operands[0]);
660   operands[1] = gen_lowpart (SImode, operands[1]);
661   operands[2] = gen_reg_rtx (SImode); }")
662
663 (define_expand "zero_extendhisi2"
664   [(set (match_operand:SI 0 "gpc_reg_operand" "")
665         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
666   ""
667   "")
668
669 (define_insn ""
670   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
671         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
672   ""
673   "@
674    lhz%U1%X1 %0,%1
675    {rlinm|rlwinm} %0,%1,0,0xffff"
676   [(set_attr "type" "load,*")])
677
678 (define_insn ""
679   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
680         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
681                     (const_int 0)))
682    (clobber (match_scratch:SI 2 "=r"))]
683   ""
684   "{andil.|andi.} %2,%1,0xffff"
685   [(set_attr "type" "compare")])
686
687 (define_insn ""
688   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
689         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
690                     (const_int 0)))
691    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
692         (zero_extend:SI (match_dup 1)))]
693   ""
694   "{andil.|andi.} %0,%1,0xffff"
695   [(set_attr "type" "compare")])
696
697 (define_expand "extendhisi2"
698   [(set (match_operand:SI 0 "gpc_reg_operand" "")
699         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
700   ""
701   "")
702
703 (define_insn ""
704   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
705         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
706   ""
707   "@
708    lha%U1%X1 %0,%1
709    {exts|extsh} %0,%1"
710   [(set_attr "type" "load,*")])
711
712 (define_insn ""
713   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
714         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
715                     (const_int 0)))
716    (clobber (match_scratch:SI 2 "=r"))]
717   ""
718   "{exts.|extsh.} %2,%1"
719   [(set_attr "type" "compare")])
720
721 (define_insn ""
722   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
723         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
724                     (const_int 0)))
725    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
726         (sign_extend:SI (match_dup 1)))]
727   ""
728   "{exts.|extsh.} %0,%1"
729   [(set_attr "type" "compare")])
730 \f
731 ;; Fixed-point arithmetic insns.
732
733 ;; Discourage ai/addic because of carry but provide it in an alternative
734 ;; allowing register zero as source.
735 (define_insn "addsi3"
736   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,?r,r")
737         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,b,r,b")
738                  (match_operand:SI 2 "add_operand" "r,I,I,J")))]
739   ""
740   "@
741    {cax|add} %0,%1,%2
742    {cal %0,%2(%1)|addi %0,%1,%2}
743    {ai|addic} %0,%1,%2
744    {cau|addis} %0,%1,%u2")
745
746 (define_insn ""
747   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
748         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
749                              (match_operand:SI 2 "reg_or_short_operand" "r,I"))
750                     (const_int 0)))
751    (clobber (match_scratch:SI 3 "=r,r"))]
752   ""
753   "@
754    {cax.|add.} %3,%1,%2
755    {ai.|addic.} %3,%1,%2"
756   [(set_attr "type" "compare")])
757
758 (define_insn ""
759   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
760         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
761                              (match_operand:SI 2 "reg_or_short_operand" "r,I"))
762                     (const_int 0)))
763    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
764         (plus:SI (match_dup 1) (match_dup 2)))]
765   ""
766   "@
767    {cax.|add.} %0,%1,%2
768    {ai.|addic.} %0,%1,%2"
769   [(set_attr "type" "compare")])
770
771 ;; Split an add that we can't do in one insn into two insns, each of which
772 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
773 ;; add should be last in case the result gets used in an address.
774
775 (define_split
776   [(set (match_operand:SI 0 "gpc_reg_operand" "")
777         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
778                  (match_operand:SI 2 "non_add_cint_operand" "")))]
779   ""
780   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
781    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
782 "
783 {
784   int low = INTVAL (operands[2]) & 0xffff;
785   int high = (unsigned) INTVAL (operands[2]) >> 16;
786
787   if (low & 0x8000)
788     high++, low |= 0xffff0000;
789
790   operands[3] = gen_rtx (CONST_INT, VOIDmode, high << 16);
791   operands[4] = gen_rtx (CONST_INT, VOIDmode, low);
792 }")
793
794 (define_insn "one_cmplsi2"
795   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
796         (not:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
797   ""
798   "nor %0,%1,%1")
799
800 (define_insn ""
801   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
802         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
803                     (const_int 0)))
804    (clobber (match_scratch:SI 2 "=r"))]
805   ""
806   "nor. %2,%1,%1"
807   [(set_attr "type" "compare")])
808
809 (define_insn ""
810   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
811         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
812                     (const_int 0)))
813    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
814         (not:SI (match_dup 1)))]
815   ""
816   "nor. %0,%2,%1"
817   [(set_attr "type" "compare")])
818
819 (define_insn ""
820   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
821         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
822                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
823   "! TARGET_POWERPC"
824   "{sf%I1|subf%I1c} %0,%2,%1")
825
826 (define_insn ""
827   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
828         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "r,I")
829                   (match_operand:SI 2 "gpc_reg_operand" "r,r")))]
830   "TARGET_POWERPC"
831   "@
832    subf %0,%2,%1
833    subfic %0,%2,%1")
834
835 (define_insn ""
836   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
837         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
838                               (match_operand:SI 2 "gpc_reg_operand" "r"))
839                     (const_int 0)))
840    (clobber (match_scratch:SI 3 "=r"))]
841   "! TARGET_POWERPC"
842   "{sf.|subfc.} %3,%2,%1"
843   [(set_attr "type" "compare")])
844
845 (define_insn ""
846   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
847         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
848                               (match_operand:SI 2 "gpc_reg_operand" "r"))
849                     (const_int 0)))
850    (clobber (match_scratch:SI 3 "=r"))]
851   "TARGET_POWERPC"
852   "subf. %3,%2,%1"
853   [(set_attr "type" "compare")])
854
855 (define_insn ""
856   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
857         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
858                               (match_operand:SI 2 "gpc_reg_operand" "r"))
859                     (const_int 0)))
860    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
861         (minus:SI (match_dup 1) (match_dup 2)))]
862   "! TARGET_POWERPC"
863   "{sf.|subfc.} %0,%2,%1"
864   [(set_attr "type" "compare")])
865
866 (define_insn ""
867   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
868         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
869                               (match_operand:SI 2 "gpc_reg_operand" "r"))
870                     (const_int 0)))
871    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
872         (minus:SI (match_dup 1) (match_dup 2)))]
873   "TARGET_POWERPC"
874   "subf. %0,%2,%1"
875   [(set_attr "type" "compare")])
876
877 (define_expand "subsi3"
878   [(set (match_operand:SI 0 "gpc_reg_operand" "")
879         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "")
880                   (match_operand:SI 2 "reg_or_cint_operand" "")))]
881   ""
882   "
883 {
884   if (GET_CODE (operands[2]) == CONST_INT)
885     {
886       emit_insn (gen_addsi3 (operands[0], operands[1],
887                              negate_rtx (SImode, operands[2])));
888       DONE;
889     }
890 }")
891
892 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
893 ;; instruction and some auxiliary computations.  Then we just have a single
894 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
895 ;; combine.
896
897 (define_expand "sminsi3"
898   [(set (match_dup 3)
899         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
900                                 (match_operand:SI 2 "reg_or_short_operand" ""))
901                          (const_int 0)
902                          (minus:SI (match_dup 2) (match_dup 1))))
903    (set (match_operand:SI 0 "gpc_reg_operand" "")
904         (minus:SI (match_dup 2) (match_dup 3)))]
905   "TARGET_POWER"
906   "
907 { operands[3] = gen_reg_rtx (SImode); }")
908
909 (define_split
910   [(set (match_operand:SI 0 "gpc_reg_operand" "")
911         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
912                  (match_operand:SI 2 "reg_or_short_operand" "")))
913    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
914   "TARGET_POWER"
915   [(set (match_dup 3)
916         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
917                          (const_int 0)
918                          (minus:SI (match_dup 2) (match_dup 1))))
919    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
920   "")
921
922 (define_expand "smaxsi3"
923   [(set (match_dup 3)
924         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
925                                 (match_operand:SI 2 "reg_or_short_operand" ""))
926                          (const_int 0)
927                          (minus:SI (match_dup 2) (match_dup 1))))
928    (set (match_operand:SI 0 "gpc_reg_operand" "")
929         (plus:SI (match_dup 3) (match_dup 1)))]
930   "TARGET_POWER"
931   "
932 { operands[3] = gen_reg_rtx (SImode); }")
933
934 (define_split
935   [(set (match_operand:SI 0 "gpc_reg_operand" "")
936         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
937                  (match_operand:SI 2 "reg_or_short_operand" "")))
938    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
939   "TARGET_POWER"
940   [(set (match_dup 3)
941         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
942                          (const_int 0)
943                          (minus:SI (match_dup 2) (match_dup 1))))
944    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
945   "")
946
947 (define_expand "uminsi3"
948   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
949                               (match_dup 5)))
950    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
951                               (match_dup 5)))
952    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
953                                        (const_int 0)
954                                        (minus:SI (match_dup 4) (match_dup 3))))
955    (set (match_operand:SI 0 "gpc_reg_operand" "")
956         (minus:SI (match_dup 2) (match_dup 3)))]
957   "TARGET_POWER"
958   "
959 {
960   operands[3] = gen_reg_rtx (SImode);
961   operands[4] = gen_reg_rtx (SImode);
962   operands[5] = GEN_INT (-2147483647 - 1);
963 }")
964
965 (define_expand "umaxsi3"
966   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
967                               (match_dup 5)))
968    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
969                               (match_dup 5)))
970    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
971                                        (const_int 0)
972                                        (minus:SI (match_dup 4) (match_dup 3))))
973    (set (match_operand:SI 0 "gpc_reg_operand" "")
974         (plus:SI (match_dup 3) (match_dup 1)))]
975   "TARGET_POWER"
976   "
977 {
978   operands[3] = gen_reg_rtx (SImode);
979   operands[4] = gen_reg_rtx (SImode);
980   operands[5] = GEN_INT (-2147483647 - 1);
981 }")
982
983 (define_insn ""
984   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
985         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
986                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
987                          (const_int 0)
988                          (minus:SI (match_dup 2) (match_dup 1))))]
989   "TARGET_POWER"
990   "doz%I2 %0,%1,%2")
991
992 (define_insn ""
993   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
994         (compare:CC
995          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
996                               (match_operand:SI 2 "reg_or_short_operand" "rI"))
997                           (const_int 0)
998                           (minus:SI (match_dup 2) (match_dup 1)))
999          (const_int 0)))
1000    (clobber (match_scratch:SI 3 "=r"))]
1001   "TARGET_POWER"
1002   "doz%I2. %3,%1,%2"
1003   [(set_attr "type" "delayed_compare")])
1004
1005 (define_insn ""
1006   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1007         (compare:CC
1008          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1009                               (match_operand:SI 2 "reg_or_short_operand" "rI"))
1010                           (const_int 0)
1011                           (minus:SI (match_dup 2) (match_dup 1)))
1012          (const_int 0)))
1013    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1014         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1015                          (const_int 0)
1016                          (minus:SI (match_dup 2) (match_dup 1))))]
1017   "TARGET_POWER"
1018   "doz%I2. %0,%1,%2"
1019   [(set_attr "type" "delayed_compare")])
1020
1021 ;; We don't need abs with condition code because such comparisons should
1022 ;; never be done.
1023 (define_expand "abssi2"
1024   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1025         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1026   ""
1027   "
1028 {
1029   if (!TARGET_POWER)
1030     {
1031       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1032       DONE;
1033     }
1034 }")
1035
1036 (define_insn "abssi2_power"
1037   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1038         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1039   "TARGET_POWER"
1040   "abs %0,%1")
1041
1042 (define_insn "abssi2_nopower"
1043   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1044         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1045    (clobber (match_scratch:SI 2 "=&r,&r"))]
1046   "!TARGET_POWER"
1047   "*
1048 {
1049   return (TARGET_POWERPC)
1050     ? \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;subf %0,%2,%0\"
1051     : \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;{sf|subfc} %0,%2,%0\";
1052 }"
1053   [(set_attr "length" "12")])
1054
1055 (define_split
1056   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1057         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1058    (clobber (match_scratch:SI 2 "=&r,&r"))]
1059   "!TARGET_POWER && reload_completed"
1060   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1061    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1062    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
1063   "")
1064
1065 (define_insn ""
1066   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1067         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
1068   "TARGET_POWER"
1069   "nabs %0,%1")
1070
1071 (define_insn ""
1072   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1073         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1074    (clobber (match_scratch:SI 2 "=&r,&r"))]
1075   "!TARGET_POWER"
1076   "*
1077 {
1078   return (TARGET_POWERPC)
1079     ? \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;subf %0,%0,%2\"
1080     : \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;{sf|subfc} %0,%0,%2\";
1081 }"
1082   [(set_attr "length" "12")])
1083
1084 (define_split
1085   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1086         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1087    (clobber (match_scratch:SI 2 "=&r,&r"))]
1088   "!TARGET_POWER && reload_completed"
1089   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1090    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1091    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1092   "")
1093
1094 (define_insn "negsi2"
1095   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1096         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1097   ""
1098   "neg %0,%1")
1099
1100 (define_insn ""
1101   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1102         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1103                     (const_int 0)))
1104    (clobber (match_scratch:SI 2 "=r"))]
1105   ""
1106   "neg. %2,%1"
1107   [(set_attr "type" "compare")])
1108
1109 (define_insn ""
1110   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
1111         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1112                     (const_int 0)))
1113    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1114         (neg:SI (match_dup 1)))]
1115   ""
1116   "neg. %0,%1"
1117   [(set_attr "type" "compare")])
1118
1119 (define_insn "ffssi2"
1120   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
1121         (ffs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1122   ""
1123   "neg %0,%1\;and %0,%0,%1\;{cntlz|cntlzw} %0,%0\;{sfi|subfic} %0,%0,32"
1124   [(set_attr "length" "16")])
1125
1126 (define_expand "mulsi3"
1127   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1128    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1129    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
1130   ""
1131   "
1132 {
1133   if (TARGET_POWER)
1134     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
1135   else
1136     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
1137   DONE;
1138 }")
1139
1140 (define_insn "mulsi3_mq"
1141   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1142         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1143                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
1144    (clobber (match_scratch:SI 3 "=q,q"))]
1145   "TARGET_POWER"
1146   "@
1147    {muls|mullw} %0,%1,%2
1148    {muli|mulli} %0,%1,%2"
1149    [(set_attr "type" "imul")])
1150
1151 (define_insn "mulsi3_no_mq"
1152   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1153         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1154                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
1155   "! TARGET_POWER"
1156   "@
1157    mullw %0,%1,%2
1158    mulli %0,%1,%2"
1159    [(set_attr "type" "imul")])
1160
1161 (define_insn ""
1162   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1163         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1164                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1165                     (const_int 0)))
1166    (clobber (match_scratch:SI 3 "=r"))
1167    (clobber (match_scratch:SI 4 "=q"))]
1168   "TARGET_POWER"
1169   "{muls.|mullw.} %3,%1,%2"
1170   [(set_attr "type" "delayed_compare")])
1171
1172 (define_insn ""
1173   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1174         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1175                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1176                     (const_int 0)))
1177    (clobber (match_scratch:SI 3 "=r"))]
1178   "! TARGET_POWER"
1179   "mullw. %3,%1,%2"
1180   [(set_attr "type" "delayed_compare")])
1181
1182 (define_insn ""
1183   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1184         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1185                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1186                     (const_int 0)))
1187    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1188         (mult:SI (match_dup 1) (match_dup 2)))
1189    (clobber (match_scratch:SI 4 "=q"))]
1190   "TARGET_POWER"
1191   "{muls.|mullw.} %0,%1,%2"
1192   [(set_attr "type" "delayed_compare")])
1193
1194 (define_insn ""
1195   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1196         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1197                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1198                     (const_int 0)))
1199    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1200         (mult:SI (match_dup 1) (match_dup 2)))]
1201   "! TARGET_POWER"
1202   "mullw. %0,%1,%2"
1203   [(set_attr "type" "delayed_compare")])
1204
1205 ;; Operand 1 is divided by operand 2; quotient goes to operand
1206 ;; 0 and remainder to operand 3.
1207 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
1208
1209 (define_expand "divmodsi4"
1210   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1211                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1212                            (match_operand:SI 2 "gpc_reg_operand" "")))
1213               (set (match_operand:SI 3 "gpc_reg_operand" "")
1214                    (mod:SI (match_dup 1) (match_dup 2)))])]
1215   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
1216   "
1217 {
1218   if (! TARGET_POWER && ! TARGET_POWERPC)
1219     {
1220       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1221       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1222       emit_insn (gen_divss_call ());
1223       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1224       emit_move_insn (operands[3], gen_rtx (REG, SImode, 4));
1225       DONE;
1226     }
1227 }")
1228
1229 (define_insn ""
1230   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1231         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1232                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1233    (set (match_operand:SI 3 "gpc_reg_operand" "=q")
1234         (mod:SI (match_dup 1) (match_dup 2)))]
1235   "TARGET_POWER"
1236   "divs %0,%1,%2"
1237   [(set_attr "type" "idiv")])
1238
1239 (define_insn ""
1240   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1241         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1242                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1243   "TARGET_POWERPC"
1244   "divw %0,%1,%2"
1245   [(set_attr "type" "idiv")])
1246
1247 (define_expand "udivsi3"
1248   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1249         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1250                  (match_operand:SI 2 "gpc_reg_operand" "")))]
1251   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
1252   "
1253 {
1254   if (! TARGET_POWER && ! TARGET_POWERPC)
1255     {
1256       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1257       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1258       emit_insn (gen_quous_call ());
1259       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1260       DONE;
1261     }
1262 }")
1263
1264 (define_insn ""
1265   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1266         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1267                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
1268   "TARGET_POWERPC"
1269   "divwu %0,%1,%2"
1270   [(set_attr "type" "idiv")])
1271
1272 ;; For powers of two we can do srai/aze for divide and then adjust for
1273 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
1274 ;; used; for PowerPC, force operands into register and do a normal divide;
1275 ;; for AIX common-mode, use quoss call on register operands.
1276 (define_expand "divsi3"
1277   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1278         (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1279                 (match_operand:SI 2 "reg_or_cint_operand" "")))]
1280   ""
1281   "
1282 {
1283   if (GET_CODE (operands[2]) == CONST_INT
1284       && exact_log2 (INTVAL (operands[2])) >= 0)
1285     ;
1286   else if (TARGET_POWER && ! TARGET_POWERPC)
1287     FAIL;
1288   else
1289     operands[2] = force_reg (SImode, operands[2]);
1290
1291   if (! TARGET_POWER && ! TARGET_POWERPC)
1292     {
1293       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1294       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1295       emit_insn (gen_quoss_call ());
1296       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1297       DONE;
1298     }
1299 }")
1300
1301 (define_expand "modsi3"
1302   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1303    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1304    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
1305   ""
1306   "
1307 {
1308   int i = exact_log2 (INTVAL (operands[2]));
1309   rtx temp1;
1310   rtx temp2;
1311
1312   if (GET_CODE (operands[2]) != CONST_INT || i < 0)
1313     FAIL;
1314
1315   temp1 = gen_reg_rtx (SImode);
1316   temp2 = gen_reg_rtx (SImode);
1317
1318   emit_insn (gen_divsi3 (temp1, operands[1], operands[2]));
1319   emit_insn (gen_ashlsi3 (temp2, temp1, GEN_INT (i)));
1320   emit_insn (gen_subsi3 (operands[0], operands[1], temp2));
1321   DONE;
1322 }")
1323
1324 (define_insn ""
1325   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1326         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1327                 (match_operand:SI 2 "const_int_operand" "N")))]
1328   "exact_log2 (INTVAL (operands[2])) >= 0"
1329   "{srai|srawi} %0,%1,%p2\;{aze|addze} %0,%0"
1330   [(set_attr "length" "8")])
1331
1332 (define_insn ""
1333   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1334         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1335                             (match_operand:SI 2 "const_int_operand" "N"))
1336                     (const_int 0)))
1337    (clobber (match_scratch:SI 3 "=r"))]
1338   "exact_log2 (INTVAL (operands[2])) >= 0"
1339   "{srai|srawi} %3,%1,%p2\;{aze.|addze.} %3,%3"
1340   [(set_attr "type" "compare")
1341    (set_attr "length" "8")])
1342
1343 (define_insn ""
1344   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1345         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1346                             (match_operand:SI 2 "const_int_operand" "N"))
1347                     (const_int 0)))
1348    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1349         (div:SI (match_dup 1) (match_dup 2)))]
1350   "exact_log2 (INTVAL (operands[2])) >= 0"
1351   "{srai|srawi} %0,%1,%p2\;{aze.|addze.} %0,%0"
1352   [(set_attr "type" "compare")
1353    (set_attr "length" "8")])
1354
1355 (define_insn ""
1356   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1357         (udiv:SI
1358          (plus:DI (ashift:DI
1359                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
1360                    (const_int 32))
1361                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
1362          (match_operand:SI 3 "gpc_reg_operand" "r")))
1363    (set (match_operand:SI 2 "register_operand" "=*q")
1364         (umod:SI
1365          (plus:DI (ashift:DI
1366                    (zero_extend:DI (match_dup 1)) (const_int 32))
1367                   (zero_extend:DI (match_dup 4)))
1368          (match_dup 3)))]
1369   "TARGET_POWER"
1370   "div %0,%1,%3"
1371   [(set_attr "type" "idiv")])
1372
1373 ;; To do unsigned divide we handle the cases of the divisor looking like a
1374 ;; negative number.  If it is a constant that is less than 2**31, we don't
1375 ;; have to worry about the branches.  So make a few subroutines here.
1376 ;;
1377 ;; First comes the normal case.
1378 (define_expand "udivmodsi4_normal"
1379   [(set (match_dup 4) (const_int 0))
1380    (parallel [(set (match_operand:SI 0 "" "")
1381                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
1382                                                 (const_int 32))
1383                                      (zero_extend:DI (match_operand:SI 1 "" "")))
1384                             (match_operand:SI 2 "" "")))
1385               (set (match_operand:SI 3 "" "")
1386                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
1387                                                 (const_int 32))
1388                                      (zero_extend:DI (match_dup 1)))
1389                             (match_dup 2)))])]
1390   "TARGET_POWER"
1391   "
1392 { operands[4] = gen_reg_rtx (SImode); }")
1393
1394 ;; This handles the branches.
1395 (define_expand "udivmodsi4_tests"
1396   [(set (match_operand:SI 0 "" "") (const_int 0))
1397    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
1398    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
1399    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
1400                            (label_ref (match_operand:SI 4 "" "")) (pc)))
1401    (set (match_dup 0) (const_int 1))
1402    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
1403    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
1404    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
1405                            (label_ref (match_dup 4)) (pc)))]
1406   "TARGET_POWER"
1407   "
1408 { operands[5] = gen_reg_rtx (CCUNSmode);
1409   operands[6] = gen_reg_rtx (CCmode);
1410 }")
1411
1412 (define_expand "udivmodsi4"
1413   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1414                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1415                             (match_operand:SI 2 "reg_or_cint_operand" "")))
1416               (set (match_operand:SI 3 "gpc_reg_operand" "")
1417                    (umod:SI (match_dup 1) (match_dup 2)))])]
1418   ""
1419   "
1420 {
1421   rtx label = 0;
1422
1423   if (! TARGET_POWER)
1424     if (! TARGET_POWERPC)
1425       {
1426         emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1427         emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1428         emit_insn (gen_divus_call ());
1429         emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1430         emit_move_insn (operands[3], gen_rtx (REG, SImode, 4));
1431         DONE;
1432       }
1433     else
1434       FAIL;
1435
1436   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
1437     {
1438       operands[2] = force_reg (SImode, operands[2]);
1439       label = gen_label_rtx ();
1440       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
1441                                   operands[3], label));
1442     }
1443   else
1444     operands[2] = force_reg (SImode, operands[2]);
1445
1446   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
1447                                operands[3]));
1448   if (label)
1449     emit_label (label);
1450
1451   DONE;
1452 }")
1453
1454 ;; AIX architecture-independent common-mode multiply (DImode),
1455 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
1456 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
1457 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
1458 ;; assumed unused if generating common-mode, so ignore.
1459 (define_insn "mulh_call"
1460   [(set (reg:SI 3)
1461         (truncate:SI
1462          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
1463                                (sign_extend:DI (reg:SI 4)))
1464                       (const_int 32))))
1465    (clobber (match_scratch:SI 0 "=l"))]
1466   "! TARGET_POWER && ! TARGET_POWERPC"
1467   "bla __mulh")
1468
1469 (define_insn "mull_call"
1470   [(set (reg:DI 3)
1471         (mult:DI (sign_extend:DI (reg:SI 3))
1472                  (sign_extend:DI (reg:SI 4))))
1473    (clobber (match_scratch:SI 0 "=l"))
1474    (clobber (reg:SI 0))]
1475   "! TARGET_POWER && ! TARGET_POWERPC"
1476   "bla __mull")
1477
1478 (define_insn "divss_call"
1479   [(set (reg:SI 3)
1480         (div:SI (reg:SI 3) (reg:SI 4)))
1481    (set (reg:SI 4)
1482         (mod:SI (reg:SI 3) (reg:SI 4)))
1483    (clobber (match_scratch:SI 0 "=l"))
1484    (clobber (reg:SI 0))]
1485   "! TARGET_POWER && ! TARGET_POWERPC"
1486   "bla __divss")
1487
1488 (define_insn "divus_call"
1489   [(set (reg:SI 3)
1490         (udiv:SI (reg:SI 3) (reg:SI 4)))
1491    (set (reg:SI 4)
1492         (umod:SI (reg:SI 3) (reg:SI 4)))
1493    (clobber (match_scratch:SI 0 "=l"))
1494    (clobber (reg:SI 0))]
1495   "! TARGET_POWER && ! TARGET_POWERPC"
1496   "bla __divus")
1497
1498 (define_insn "quoss_call"
1499   [(set (reg:SI 3)
1500         (div:SI (reg:SI 3) (reg:SI 4)))
1501    (clobber (match_scratch:SI 0 "=l"))]
1502   "! TARGET_POWER && ! TARGET_POWERPC"
1503   "bla __quoss")
1504
1505 (define_insn "quous_call"
1506   [(set (reg:SI 3)
1507         (udiv:SI (reg:SI 3) (reg:SI 4)))
1508    (clobber (match_scratch:SI 0 "=l"))
1509    (clobber (reg:SI 0))]
1510   "! TARGET_POWER && ! TARGET_POWERPC"
1511   "bla __quous")
1512 \f
1513 (define_insn "andsi3"
1514   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1515         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1516                 (match_operand:SI 2 "and_operand" "?r,L,K,J")))
1517    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
1518   ""
1519   "@
1520    and %0,%1,%2
1521    {rlinm|rlwinm} %0,%1,0,%m2,%M2
1522    {andil.|andi.} %0,%1,%b2
1523    {andiu.|andis.} %0,%1,%u2")
1524
1525 (define_insn ""
1526   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x")
1527         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1528                             (match_operand:SI 2 "and_operand" "r,K,J,L"))
1529                     (const_int 0)))
1530    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
1531   ""
1532   "@
1533    and. %3,%1,%2
1534    {andil.|andi.} %3,%1,%b2
1535    {andiu.|andis.} %3,%1,%u2
1536    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2"
1537   [(set_attr "type" "compare,compare,compare,delayed_compare")])
1538
1539 (define_insn ""
1540   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x")
1541         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1542                             (match_operand:SI 2 "and_operand" "r,K,J,L"))
1543                     (const_int 0)))
1544    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1545         (and:SI (match_dup 1) (match_dup 2)))]
1546   ""
1547   "@
1548    and. %0,%1,%2
1549    {andil.|andi.} %0,%1,%b2
1550    {andiu.|andis.} %0,%1,%u2
1551    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2"
1552   [(set_attr "type" "compare,compare,compare,delayed_compare")])
1553
1554 ;; Take a AND with a constant that cannot be done in a single insn and try to
1555 ;; split it into two insns.  This does not verify that the insns are valid
1556 ;; since this need not be done as combine will do it.
1557
1558 (define_split
1559   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1560         (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
1561                 (match_operand:SI 2 "non_and_cint_operand" "")))]
1562   ""
1563   [(set (match_dup 0) (and:SI (match_dup 1) (match_dup 3)))
1564    (set (match_dup 0) (and:SI (match_dup 0) (match_dup 4)))]
1565   "
1566 {
1567   int maskval = INTVAL (operands[2]);
1568   int i, transitions, last_bit_value;
1569   int orig = maskval, first_c = maskval, second_c;
1570
1571   /* We know that MASKVAL must have more than 2 bit-transitions.  Start at
1572      the low-order bit and count for the third transition.  When we get there,
1573      make a first mask that has everything to the left of that position
1574      a one.  Then make the second mask to turn off whatever else is needed.  */
1575
1576   for (i = 1, transitions = 0, last_bit_value = maskval & 1; i < 32; i++)
1577     {
1578       if (((maskval >>= 1) & 1) != last_bit_value)
1579         last_bit_value ^= 1, transitions++;
1580
1581       if (transitions > 2)
1582         {
1583           first_c |= (~0) << i;
1584           break;
1585         }
1586     }
1587
1588   second_c = orig | ~ first_c;
1589
1590   operands[3] = gen_rtx (CONST_INT, VOIDmode, first_c);
1591   operands[4] = gen_rtx (CONST_INT, VOIDmode, second_c);
1592 }")
1593
1594 (define_insn "iorsi3"
1595   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
1596         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
1597                 (match_operand:SI 2 "logical_operand" "r,K,J")))]
1598   ""
1599   "@
1600    or %0,%1,%2
1601    {oril|ori} %0,%1,%b2
1602    {oriu|oris} %0,%1,%u2")
1603
1604 (define_insn ""
1605   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1606         (compare:CC (ior:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1607                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1608                     (const_int 0)))
1609    (clobber (match_scratch:SI 3 "=r"))]
1610   ""
1611   "or. %3,%1,%2"
1612   [(set_attr "type" "compare")])
1613
1614 (define_insn ""
1615   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1616         (compare:CC (ior:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1617                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1618                     (const_int 0)))
1619    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1620         (ior:SI (match_dup 1) (match_dup 2)))]
1621   ""
1622   "or. %0,%1,%2"
1623   [(set_attr "type" "compare")])
1624
1625 ;; Split an IOR that we can't do in one insn into two insns, each of which
1626 ;; does one 16-bit part.  This is used by combine.
1627
1628 (define_split
1629   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1630         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
1631                 (match_operand:SI 2 "non_logical_cint_operand" "")))]
1632   ""
1633   [(set (match_dup 0) (ior:SI (match_dup 1) (match_dup 3)))
1634    (set (match_dup 0) (ior:SI (match_dup 0) (match_dup 4)))]
1635 "
1636 {
1637   operands[3] = gen_rtx (CONST_INT, VOIDmode,
1638                          INTVAL (operands[2]) & 0xffff0000);
1639   operands[4] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[2]) & 0xffff);
1640 }")
1641
1642 (define_insn "xorsi3"
1643   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
1644         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
1645                 (match_operand:SI 2 "logical_operand" "r,K,J")))]
1646   ""
1647   "@
1648    xor %0,%1,%2
1649    {xoril|xori} %0,%1,%b2
1650    {xoriu|xoris} %0,%1,%u2")
1651
1652 (define_insn ""
1653   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1654         (compare:CC (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1655                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1656                     (const_int 0)))
1657    (clobber (match_scratch:SI 3 "=r"))]
1658   ""
1659   "xor. %3,%1,%2"
1660   [(set_attr "type" "compare")])
1661
1662 (define_insn ""
1663   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1664         (compare:CC (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1665                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1666                     (const_int 0)))
1667    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1668         (xor:SI (match_dup 1) (match_dup 2)))]
1669   ""
1670   "xor. %0,%1,%2"
1671   [(set_attr "type" "compare")])
1672
1673 ;; Split an XOR that we can't do in one insn into two insns, each of which
1674 ;; does one 16-bit part.  This is used by combine.
1675
1676 (define_split
1677   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1678         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1679                 (match_operand:SI 2 "non_logical_cint_operand" "")))]
1680   ""
1681   [(set (match_dup 0) (xor:SI (match_dup 1) (match_dup 3)))
1682    (set (match_dup 0) (xor:SI (match_dup 0) (match_dup 4)))]
1683 "
1684 {
1685   operands[3] = gen_rtx (CONST_INT, VOIDmode,
1686                          INTVAL (operands[2]) & 0xffff0000);
1687   operands[4] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[2]) & 0xffff);
1688 }")
1689
1690 (define_insn ""
1691   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1692         (not:SI (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1693                         (match_operand:SI 2 "gpc_reg_operand" "r"))))]
1694    ""
1695    "eqv %0,%1,%2")
1696
1697 (define_insn ""
1698   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1699         (compare:CC (not:SI (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1700                                     (match_operand:SI 2 "gpc_reg_operand" "r")))
1701                     (const_int 0)))
1702    (clobber (match_scratch:SI 3 "=r"))]
1703    ""
1704    "eqv. %3,%1,%2"
1705    [(set_attr "type" "compare")])
1706
1707 (define_insn ""
1708   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1709         (compare:CC (not:SI (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1710                                     (match_operand:SI 2 "gpc_reg_operand" "r")))
1711                     (const_int 0)))
1712    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1713         (not:SI (xor:SI (match_dup 1) (match_dup 2))))]
1714    ""
1715    "eqv. %0,%1,%2"
1716    [(set_attr "type" "compare")])
1717
1718 (define_insn ""
1719   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1720         (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1721                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1722   ""
1723   "andc %0,%2,%1")
1724
1725 (define_insn ""
1726   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1727         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1728                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1729                     (const_int 0)))
1730    (clobber (match_scratch:SI 3 "=r"))]
1731   ""
1732   "andc. %3,%2,%1"
1733   [(set_attr "type" "compare")])
1734
1735 (define_insn ""
1736   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1737         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1738                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1739                     (const_int 0)))
1740    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1741         (and:SI (not:SI (match_dup 1)) (match_dup 2)))]
1742   ""
1743   "andc. %0,%2,%1"
1744   [(set_attr "type" "compare")])
1745
1746 (define_insn ""
1747   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1748         (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1749                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1750   ""
1751   "orc %0,%2,%1")
1752
1753 (define_insn ""
1754   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1755         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1756                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1757                     (const_int 0)))
1758    (clobber (match_scratch:SI 3 "=r"))]
1759   ""
1760   "orc. %3,%2,%1"
1761   [(set_attr "type" "compare")])
1762
1763 (define_insn ""
1764   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1765         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1766                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1767                     (const_int 0)))
1768    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1769         (ior:SI (not:SI (match_dup 1)) (match_dup 2)))]
1770   ""
1771   "orc. %0,%2,%1"
1772   [(set_attr "type" "compare")])
1773
1774 (define_insn ""
1775   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1776         (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1777                 (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
1778   ""
1779   "nand %0,%1,%2")
1780
1781 (define_insn ""
1782   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1783         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1784                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1785                     (const_int 0)))
1786    (clobber (match_scratch:SI 3 "=r"))]
1787   ""
1788   "nand. %3,%1,%2"
1789   [(set_attr "type" "compare")])
1790
1791 (define_insn ""
1792   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1793         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1794                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1795                     (const_int 0)))
1796    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1797         (ior:SI (not:SI (match_dup 1)) (not:SI (match_dup 2))))]
1798   ""
1799   "nand. %0,%1,%2"
1800   [(set_attr "type" "compare")])
1801
1802 (define_insn ""
1803   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1804         (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1805                 (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
1806   ""
1807   "nor %0,%1,%2")
1808
1809 (define_insn ""
1810   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1811         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1812                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1813                     (const_int 0)))
1814    (clobber (match_scratch:SI 3 "=r"))]
1815   ""
1816   "nor. %3,%1,%2"
1817   [(set_attr "type" "compare")])
1818
1819 (define_insn ""
1820   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1821         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1822                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1823                     (const_int 0)))
1824    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1825         (and:SI (not:SI (match_dup 1)) (not:SI (match_dup 2))))]
1826   ""
1827   "nor. %0,%1,%2"
1828   [(set_attr "type" "compare")])
1829
1830 ;; maskir insn.  We need four forms because things might be in arbitrary
1831 ;; orders.  Don't define forms that only set CR fields because these
1832 ;; would modify an input register.
1833
1834 (define_insn ""
1835   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1836         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1837                         (match_operand:SI 1 "gpc_reg_operand" "0"))
1838                 (and:SI (match_dup 2)
1839                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
1840   "TARGET_POWER"
1841   "maskir %0,%3,%2")
1842
1843 (define_insn ""
1844   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1845         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1846                         (match_operand:SI 1 "gpc_reg_operand" "0"))
1847                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1848                         (match_dup 2))))]
1849   "TARGET_POWER"
1850   "maskir %0,%3,%2")
1851
1852 (define_insn ""
1853   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1854         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
1855                         (match_operand:SI 3 "gpc_reg_operand" "r"))
1856                 (and:SI (not:SI (match_dup 2))
1857                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
1858   "TARGET_POWER"
1859   "maskir %0,%3,%2")
1860
1861 (define_insn ""
1862   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1863         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1864                         (match_operand:SI 2 "gpc_reg_operand" "r"))
1865                 (and:SI (not:SI (match_dup 2))
1866                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
1867   "TARGET_POWER"
1868   "maskir %0,%3,%2")
1869
1870 (define_insn ""
1871   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
1872         (compare:CC
1873          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1874                          (match_operand:SI 1 "gpc_reg_operand" "0"))
1875                  (and:SI (match_dup 2)
1876                          (match_operand:SI 3 "gpc_reg_operand" "r")))
1877          (const_int 0)))
1878    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1879         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
1880                 (and:SI (match_dup 2) (match_dup 3))))]
1881   "TARGET_POWER"
1882   "maskir. %0,%3,%2"
1883   [(set_attr "type" "compare")])
1884
1885 (define_insn ""
1886   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
1887         (compare:CC
1888          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1889                          (match_operand:SI 1 "gpc_reg_operand" "0"))
1890                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1891                          (match_dup 2)))
1892          (const_int 0)))
1893    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1894         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
1895                 (and:SI (match_dup 3) (match_dup 2))))]
1896   "TARGET_POWER"
1897   "maskir. %0,%3,%2"
1898   [(set_attr "type" "compare")])
1899
1900 (define_insn ""
1901   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
1902         (compare:CC
1903          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
1904                          (match_operand:SI 3 "gpc_reg_operand" "r"))
1905                  (and:SI (not:SI (match_dup 2))
1906                          (match_operand:SI 1 "gpc_reg_operand" "0")))
1907          (const_int 0)))
1908    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1909         (ior:SI (and:SI (match_dup 2) (match_dup 3))
1910                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
1911   "TARGET_POWER"
1912   "maskir. %0,%3,%2"
1913   [(set_attr "type" "compare")])
1914
1915 (define_insn ""
1916   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
1917         (compare:CC
1918          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1919                          (match_operand:SI 2 "gpc_reg_operand" "r"))
1920                  (and:SI (not:SI (match_dup 2))
1921                          (match_operand:SI 1 "gpc_reg_operand" "0")))
1922          (const_int 0)))
1923    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1924         (ior:SI (and:SI (match_dup 3) (match_dup 2))
1925                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
1926   "TARGET_POWER"
1927   "maskir. %0,%3,%2"
1928   [(set_attr "type" "compare")])
1929 \f
1930 ;; Rotate and shift insns, in all their variants.  These support shifts,
1931 ;; field inserts and extracts, and various combinations thereof.
1932 (define_expand "insv"
1933   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
1934                          (match_operand:SI 1 "const_int_operand" "i")
1935                          (match_operand:SI 2 "const_int_operand" "i"))
1936         (match_operand:SI 3 "gpc_reg_operand" "r"))]
1937   ""
1938   "
1939 {
1940   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
1941      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
1942      compiler if the address of the structure is taken later.  */
1943   if (GET_CODE (operands[0]) == SUBREG
1944       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
1945     FAIL;
1946 }")
1947
1948 (define_insn ""
1949   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
1950                          (match_operand:SI 1 "const_int_operand" "i")
1951                          (match_operand:SI 2 "const_int_operand" "i"))
1952         (match_operand:SI 3 "gpc_reg_operand" "r"))]
1953   ""
1954   "*
1955 {
1956   int start = INTVAL (operands[2]) & 31;
1957   int size = INTVAL (operands[1]) & 31;
1958
1959   operands[4] = gen_rtx (CONST_INT, VOIDmode, 32 - start - size);
1960   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
1961   return \"{rlimi|rlwimi} %0,%3,%4,%h2,%h1\";
1962 }")
1963
1964 (define_insn ""
1965   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
1966                          (match_operand:SI 1 "const_int_operand" "i")
1967                          (match_operand:SI 2 "const_int_operand" "i"))
1968         (ashift:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1969                    (match_operand:SI 4 "const_int_operand" "i")))]
1970   ""
1971   "*
1972 {
1973   int shift = INTVAL (operands[4]) & 31;
1974   int start = INTVAL (operands[2]) & 31;
1975   int size = INTVAL (operands[1]) & 31;
1976
1977   operands[4] = gen_rtx (CONST_INT, VOIDmode, (shift - start - size) & 31);
1978   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
1979   return \"{rlimi|rlwimi} %0,%3,%4,%h2,%h1\";
1980 }")
1981
1982 (define_insn ""
1983   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
1984                          (match_operand:SI 1 "const_int_operand" "i")
1985                          (match_operand:SI 2 "const_int_operand" "i"))
1986         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1987                      (match_operand:SI 4 "const_int_operand" "i")))]
1988   ""
1989   "*
1990 {
1991   int shift = INTVAL (operands[4]) & 31;
1992   int start = INTVAL (operands[2]) & 31;
1993   int size = INTVAL (operands[1]) & 31;
1994
1995   operands[4] = gen_rtx (CONST_INT, VOIDmode, (32 - shift - start - size) & 31);
1996   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
1997   return \"{rlimi|rlwimi} %0,%3,%4,%h2,%h1\";
1998 }")
1999
2000 (define_insn ""
2001   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2002                          (match_operand:SI 1 "const_int_operand" "i")
2003                          (match_operand:SI 2 "const_int_operand" "i"))
2004         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2005                      (match_operand:SI 4 "const_int_operand" "i")))]
2006   ""
2007   "*
2008 {
2009   int shift = INTVAL (operands[4]) & 31;
2010   int start = INTVAL (operands[2]) & 31;
2011   int size = INTVAL (operands[1]) & 31;
2012
2013   operands[4] = gen_rtx (CONST_INT, VOIDmode, (32 - shift - start - size) & 31);
2014   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
2015   return \"{rlimi|rlwimi} %0,%3,%4,%h2,%h1\";
2016 }")
2017
2018 (define_insn ""
2019   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2020                          (match_operand:SI 1 "const_int_operand" "i")
2021                          (match_operand:SI 2 "const_int_operand" "i"))
2022         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2023                          (match_operand:SI 4 "const_int_operand" "i")
2024                          (match_operand:SI 5 "const_int_operand" "i")))]
2025   "INTVAL (operands[4]) >= INTVAL (operands[1])"
2026   "*
2027 {
2028   int extract_start = INTVAL (operands[5]) & 31;
2029   int extract_size = INTVAL (operands[4]) & 31;
2030   int insert_start = INTVAL (operands[2]) & 31;
2031   int insert_size = INTVAL (operands[1]) & 31;
2032
2033 /* Align extract field with insert field */
2034   operands[5] = gen_rtx (CONST_INT, VOIDmode,
2035                          (extract_start + extract_size - insert_start - insert_size) & 31);
2036   operands[1] = gen_rtx (CONST_INT, VOIDmode, insert_start + insert_size - 1);
2037   return \"{rlimi|rlwimi} %0,%3,%5,%h2,%h1\";
2038 }")
2039
2040 (define_expand "extzv"
2041   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2042         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2043                          (match_operand:SI 2 "const_int_operand" "i")
2044                          (match_operand:SI 3 "const_int_operand" "i")))]
2045   ""
2046   "
2047 {
2048   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
2049      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
2050      compiler if the address of the structure is taken later.  */
2051   if (GET_CODE (operands[0]) == SUBREG
2052       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
2053     FAIL;
2054 }")
2055
2056 (define_insn ""
2057   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2058         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2059                          (match_operand:SI 2 "const_int_operand" "i")
2060                          (match_operand:SI 3 "const_int_operand" "i")))]
2061   ""
2062   "*
2063 {
2064   int start = INTVAL (operands[3]) & 31;
2065   int size = INTVAL (operands[2]) & 31;
2066
2067   if (start + size >= 32)
2068     operands[3] = const0_rtx;
2069   else
2070     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2071   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
2072 }")
2073
2074 (define_insn ""
2075   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2076         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2077                          (match_operand:SI 2 "const_int_operand" "i")
2078                          (match_operand:SI 3 "const_int_operand" "i"))
2079                     (const_int 0)))
2080    (clobber (match_scratch:SI 4 "=r"))]
2081   ""
2082   "*
2083 {
2084   int start = INTVAL (operands[3]) & 31;
2085   int size = INTVAL (operands[2]) & 31;
2086
2087   /* If the bitfield being tested fits in the upper or lower half of a
2088      word, it is possible to use andiu. or andil. to test it.  This is
2089      useful because the condition register set-use delay is smaller for
2090      andi[ul]. than for rlinm.  This doesn't work when the starting bit
2091      position is 0 because the LT and GT bits may be set wrong.  */
2092
2093   if ((start > 0 && start + size <= 16) || start >= 16)
2094     {
2095       operands[3] = gen_rtx (CONST_INT, VOIDmode,
2096                              ((1 << (16 - (start & 15)))
2097                               - (1 << (16 - (start & 15) - size))));
2098       if (start < 16)
2099         return \"{andiu.|andis.} %4,%1,%3\";
2100       else
2101         return \"{andil.|andi.} %4,%1,%3\";
2102     }
2103
2104   if (start + size >= 32)
2105     operands[3] = const0_rtx;
2106   else
2107     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2108   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
2109 }"
2110   [(set_attr "type" "compare")])
2111
2112 (define_insn ""
2113   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2114         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2115                          (match_operand:SI 2 "const_int_operand" "i")
2116                          (match_operand:SI 3 "const_int_operand" "i"))
2117                     (const_int 0)))
2118    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2119         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
2120   ""
2121   "*
2122 {
2123   int start = INTVAL (operands[3]) & 31;
2124   int size = INTVAL (operands[2]) & 31;
2125
2126   if (start >= 16 && start + size == 32)
2127     {
2128       operands[3] = gen_rtx (CONST_INT, VOIDmode, (1 << (32 - start)) - 1);
2129       return \"{andil.|andi.} %0,%1,%3\";
2130     }
2131
2132   if (start + size >= 32)
2133     operands[3] = const0_rtx;
2134   else
2135     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2136   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
2137 }"
2138   [(set_attr "type" "delayed_compare")])
2139
2140 (define_insn "rotlsi3"
2141   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2142         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2143                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2144   ""
2145   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
2146
2147 (define_insn ""
2148   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2149         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2150                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2151                     (const_int 0)))
2152    (clobber (match_scratch:SI 3 "=r"))]
2153   ""
2154   "{rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff"
2155   [(set_attr "type" "delayed_compare")])
2156
2157 (define_insn ""
2158   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2159         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2160                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2161                     (const_int 0)))
2162    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2163         (rotate:SI (match_dup 1) (match_dup 2)))]
2164   ""
2165   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff"
2166   [(set_attr "type" "delayed_compare")])
2167
2168 (define_insn ""
2169   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2170         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2171                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2172                 (match_operand:SI 3 "mask_operand" "L")))]
2173   ""
2174   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
2175
2176 (define_insn ""
2177   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2178         (compare:CC (and:SI
2179                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2180                                 (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2181                      (match_operand:SI 3 "mask_operand" "L"))
2182                     (const_int 0)))
2183    (clobber (match_scratch:SI 4 "=r"))]
2184   ""
2185   "{rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3"
2186   [(set_attr "type" "delayed_compare")])
2187
2188 (define_insn ""
2189   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2190         (compare:CC (and:SI
2191                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2192                                 (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2193                      (match_operand:SI 3 "mask_operand" "L"))
2194                     (const_int 0)))
2195    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2196         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
2197   ""
2198   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3"
2199   [(set_attr "type" "delayed_compare")])
2200
2201 (define_insn ""
2202   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2203         (zero_extend:SI
2204          (subreg:QI
2205           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2206                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
2207   ""
2208   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
2209
2210 (define_insn ""
2211   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2212         (compare:CC (zero_extend:SI
2213                      (subreg:QI
2214                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2215                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2216                     (const_int 0)))
2217    (clobber (match_scratch:SI 3 "=r"))]
2218   ""
2219   "{rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff"
2220   [(set_attr "type" "delayed_compare")])
2221
2222 (define_insn ""
2223   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2224         (compare:CC (zero_extend:SI
2225                      (subreg:QI
2226                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2227                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2228                     (const_int 0)))
2229    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2230         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
2231   ""
2232   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff"
2233   [(set_attr "type" "delayed_compare")])
2234
2235 (define_insn ""
2236   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2237         (zero_extend:SI
2238          (subreg:HI
2239           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2240                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
2241   ""
2242   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
2243
2244 (define_insn ""
2245   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2246         (compare:CC (zero_extend:SI
2247                      (subreg:HI
2248                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2249                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2250                     (const_int 0)))
2251    (clobber (match_scratch:SI 3 "=r"))]
2252   ""
2253   "{rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff"
2254   [(set_attr "type" "delayed_compare")])
2255
2256 (define_insn ""
2257   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2258         (compare:CC (zero_extend:SI
2259                      (subreg:HI
2260                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2261                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2262                     (const_int 0)))
2263    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2264         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
2265   ""
2266   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff"
2267   [(set_attr "type" "delayed_compare")])
2268
2269 ;; Note that we use "sle." instead of "sl." so that we can set
2270 ;; SHIFT_COUNT_TRUNCATED.
2271
2272 (define_expand "ashlsi3"
2273   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2274    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2275    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
2276   ""
2277   "
2278 {
2279   if (TARGET_POWER)
2280     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
2281   else
2282     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
2283   DONE;
2284 }")
2285
2286 (define_insn "ashlsi3_power"
2287   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2288         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2289                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
2290    (clobber (match_scratch:SI 3 "=q,X"))]
2291   "TARGET_POWER"
2292   "@
2293    sle %0,%1,%2
2294    {sli|slwi} %0,%1,%h2"
2295   [(set_attr "length" "8")])
2296
2297 (define_insn "ashlsi3_no_power"
2298   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2299         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2300                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2301   "! TARGET_POWER"
2302   "slw%I2 %0,%1,%h2"
2303   [(set_attr "length" "8")])
2304
2305 (define_insn ""
2306   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
2307         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2308                                (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2309                     (const_int 0)))
2310    (clobber (match_scratch:SI 3 "=r,r"))
2311    (clobber (match_scratch:SI 4 "=q,X"))]
2312   "TARGET_POWER"
2313   "@
2314    sle. %3,%1,%2
2315    {sli.|slwi.} %3,%1,%h2"
2316   [(set_attr "type" "delayed_compare")])
2317
2318 (define_insn ""
2319   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2320         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2321                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2322                     (const_int 0)))
2323    (clobber (match_scratch:SI 3 "=r"))]
2324   "! TARGET_POWER"
2325   "slw%I2. %3,%1,%h2"
2326   [(set_attr "type" "delayed_compare")])
2327
2328 (define_insn ""
2329   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
2330         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2331                                (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2332                     (const_int 0)))
2333    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2334         (ashift:SI (match_dup 1) (match_dup 2)))
2335    (clobber (match_scratch:SI 4 "=q,X"))]
2336   "TARGET_POWER"
2337   "@
2338    sle. %0,%1,%2
2339    {sli.|slwi.} %0,%1,%h2"
2340   [(set_attr "type" "delayed_compare")])
2341
2342 (define_insn ""
2343   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2344         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2345                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2346                     (const_int 0)))
2347    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2348         (ashift:SI (match_dup 1) (match_dup 2)))]
2349   "! TARGET_POWER"
2350   "slw%I2. %0,%1,%h2"
2351   [(set_attr "type" "delayed_compare")])
2352
2353 (define_insn ""
2354   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2355         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2356                            (match_operand:SI 2 "const_int_operand" "i"))
2357                 (match_operand:SI 3 "mask_operand" "L")))]
2358   "includes_lshift_p (operands[2], operands[3])"
2359   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
2360
2361 (define_insn ""
2362   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2363         (compare:CC
2364          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2365                             (match_operand:SI 2 "const_int_operand" "i"))
2366                  (match_operand:SI 3 "mask_operand" "L"))
2367          (const_int 0)))
2368    (clobber (match_scratch:SI 4 "=r"))]
2369   "includes_lshift_p (operands[2], operands[3])"
2370   "{rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3"
2371   [(set_attr "type" "delayed_compare")])
2372
2373 (define_insn ""
2374   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2375         (compare:CC
2376          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2377                             (match_operand:SI 2 "const_int_operand" "i"))
2378                  (match_operand:SI 3 "mask_operand" "L"))
2379          (const_int 0)))
2380    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2381         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
2382   "includes_lshift_p (operands[2], operands[3])"
2383   "{rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3"
2384   [(set_attr "type" "delayed_compare")])
2385
2386 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
2387 ;; "sli x,x,0".
2388 (define_expand "lshrsi3"
2389   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2390    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2391    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
2392   ""
2393   "
2394 {
2395   if (TARGET_POWER)
2396     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
2397   else
2398     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
2399   DONE;
2400 }")
2401
2402 (define_insn "lshrsi3_power"
2403   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2404         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2405                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
2406    (clobber (match_scratch:SI 3 "=q,X"))]
2407   "TARGET_POWER"
2408   "@
2409   sre %0,%1,%2
2410   {s%A2i|s%A2wi} %0,%1,%h2")
2411
2412 (define_insn "lshrsi3_no_power"
2413   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2414         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2415                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2416   "! TARGET_POWER"
2417   "srw%I2 %0,%1,%h2")
2418
2419 (define_insn ""
2420   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
2421         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2422                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2423                     (const_int 0)))
2424    (clobber (match_scratch:SI 3 "=r,r"))
2425    (clobber (match_scratch:SI 4 "=q,X"))]
2426   "TARGET_POWER"
2427   "@
2428   sre. %3,%1,%2
2429   {s%A2i.|s%A2wi.} %3,%1,%h2"
2430   [(set_attr "type" "delayed_compare")])
2431
2432 (define_insn ""
2433   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2434         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2435                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2436                     (const_int 0)))
2437    (clobber (match_scratch:SI 3 "=r"))]
2438   "! TARGET_POWER"
2439   "srw%I2. %3,%1,%h2"
2440   [(set_attr "type" "delayed_compare")])
2441
2442 (define_insn ""
2443   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
2444         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2445                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2446                     (const_int 0)))
2447    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2448         (lshiftrt:SI (match_dup 1) (match_dup 2)))
2449    (clobber (match_scratch:SI 4 "=q,X"))]
2450   "TARGET_POWER"
2451   "@
2452   sre. %0,%1,%2
2453   {s%A2i.|s%A2wi.} %0,%1,%h2"
2454   [(set_attr "type" "delayed_compare")])
2455
2456 (define_insn ""
2457   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2458         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2459                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2460                     (const_int 0)))
2461    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2462         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
2463   "! TARGET_POWER"
2464   "srw%I2. %0,%1,%h2"
2465   [(set_attr "type" "delayed_compare")])
2466
2467 (define_insn ""
2468   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2469         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2470                              (match_operand:SI 2 "const_int_operand" "i"))
2471                 (match_operand:SI 3 "mask_operand" "L")))]
2472   "includes_rshift_p (operands[2], operands[3])"
2473   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
2474
2475 (define_insn ""
2476   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2477         (compare:CC
2478          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2479                               (match_operand:SI 2 "const_int_operand" "i"))
2480                  (match_operand:SI 3 "mask_operand" "L"))
2481          (const_int 0)))
2482    (clobber (match_scratch:SI 4 "=r"))]
2483   "includes_rshift_p (operands[2], operands[3])"
2484   "{rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3"
2485   [(set_attr "type" "delayed_compare")])
2486
2487 (define_insn ""
2488   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2489         (compare:CC
2490          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2491                               (match_operand:SI 2 "const_int_operand" "i"))
2492                  (match_operand:SI 3 "mask_operand" "L"))
2493          (const_int 0)))
2494    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2495         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
2496   "includes_rshift_p (operands[2], operands[3])"
2497   "{rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3"
2498   [(set_attr "type" "delayed_compare")])
2499
2500 (define_insn ""
2501   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2502         (zero_extend:SI
2503          (subreg:QI
2504           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2505                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
2506   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 255))"
2507   "{rlinm|rlwinm} %0,%1,%s2,0xff")
2508
2509 (define_insn ""
2510   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2511         (compare:CC
2512          (zero_extend:SI
2513           (subreg:QI
2514            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2515                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2516          (const_int 0)))
2517    (clobber (match_scratch:SI 3 "=r"))]
2518   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 255))"
2519   "{rlinm.|rlwinm.} %3,%1,%s2,0xff"
2520   [(set_attr "type" "delayed_compare")])
2521
2522 (define_insn ""
2523   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2524         (compare:CC
2525          (zero_extend:SI
2526           (subreg:QI
2527            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2528                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2529          (const_int 0)))
2530    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2531         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
2532   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 255))"
2533   "{rlinm.|rlwinm.} %0,%1,%s2,0xff"
2534   [(set_attr "type" "delayed_compare")])
2535
2536 (define_insn ""
2537   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2538         (zero_extend:SI
2539          (subreg:HI
2540           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2541                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
2542   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 65535))"
2543   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
2544
2545 (define_insn ""
2546   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2547         (compare:CC
2548          (zero_extend:SI
2549           (subreg:HI
2550            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2551                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2552          (const_int 0)))
2553    (clobber (match_scratch:SI 3 "=r"))]
2554   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 65535))"
2555   "{rlinm.|rlwinm.} %3,%1,%s2,0xffff"
2556   [(set_attr "type" "delayed_compare")])
2557
2558 (define_insn ""
2559   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2560         (compare:CC
2561          (zero_extend:SI
2562           (subreg:HI
2563            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2564                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2565          (const_int 0)))
2566    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2567         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
2568   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 65535))"
2569   "{rlinm.|rlwinm.} %0,%1,%s2,0xffff"
2570   [(set_attr "type" "delayed_compare")])
2571
2572 (define_insn ""
2573   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2574                          (const_int 1)
2575                          (match_operand:SI 1 "gpc_reg_operand" "r"))
2576         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2577                      (const_int 31)))]
2578   "TARGET_POWER"
2579   "rrib %0,%1,%2")
2580
2581 (define_insn ""
2582   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2583                          (const_int 1)
2584                          (match_operand:SI 1 "gpc_reg_operand" "r"))
2585         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2586                      (const_int 31)))]
2587   "TARGET_POWER"
2588   "rrib %0,%1,%2")
2589
2590 (define_insn ""
2591   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2592                          (const_int 1)
2593                          (match_operand:SI 1 "gpc_reg_operand" "r"))
2594         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2595                          (const_int 1)
2596                          (const_int 0)))]
2597   "TARGET_POWER"
2598   "rrib %0,%1,%2")
2599
2600 (define_expand "ashrsi3"
2601   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2602         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
2603                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
2604   ""
2605   "
2606 {
2607   if (TARGET_POWER)
2608     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
2609   else
2610     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
2611   DONE;
2612 }")
2613
2614 (define_insn "ashrsi3_power"
2615   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2616         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2617                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
2618    (clobber (match_scratch:SI 3 "=q,X"))]
2619   "TARGET_POWER"
2620   "@
2621    srea %0,%1,%2
2622    {srai|srawi} %0,%1,%h2")
2623
2624 (define_insn "ashrsi3_no_power"
2625   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2626         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2627                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2628   "! TARGET_POWER"
2629   "sraw%I2 %0,%1,%h2")
2630
2631 (define_insn ""
2632   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
2633         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2634                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2635                     (const_int 0)))
2636    (clobber (match_scratch:SI 3 "=r,r"))
2637    (clobber (match_scratch:SI 4 "=q,X"))]
2638   "TARGET_POWER"
2639   "@
2640    srea. %3,%1,%2
2641    {srai.|srawi.} %3,%1,%h2"
2642   [(set_attr "type" "delayed_compare")])
2643
2644 (define_insn ""
2645   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2646         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2647                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2648                     (const_int 0)))
2649    (clobber (match_scratch:SI 3 "=r"))]
2650   "! TARGET_POWER"
2651   "sraw%I2. %3,%1,%h2"
2652   [(set_attr "type" "delayed_compare")])
2653
2654 (define_insn ""
2655   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
2656         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2657                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2658                     (const_int 0)))
2659    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2660         (ashiftrt:SI (match_dup 1) (match_dup 2)))
2661    (clobber (match_scratch:SI 4 "=q,X"))]
2662   "TARGET_POWER"
2663   "@
2664    srea. %0,%1,%2
2665    {srai.|srawi.} %0,%1,%h2"
2666   [(set_attr "type" "delayed_compare")])
2667
2668 (define_insn ""
2669   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2670         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2671                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2672                     (const_int 0)))
2673    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2674         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
2675   "! TARGET_POWER"
2676   "sraw%I2. %0,%1,%h2"
2677   [(set_attr "type" "delayed_compare")])
2678 \f
2679 ;; Floating-point insns, excluding normal data motion.
2680 ;;
2681 ;; PowerPC has a full set of single-precision floating point instructions.
2682 ;;
2683 ;; For the POWER architecture, we pretend that we have both SFmode and
2684 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
2685 ;; The only conversions we will do will be when storing to memory.  In that
2686 ;; case, we will use the "frsp" instruction before storing.
2687 ;;
2688 ;; Note that when we store into a single-precision memory location, we need to
2689 ;; use the frsp insn first.  If the register being stored isn't dead, we
2690 ;; need a scratch register for the frsp.  But this is difficult when the store
2691 ;; is done by reload.  It is not incorrect to do the frsp on the register in
2692 ;; this case, we just lose precision that we would have otherwise gotten but
2693 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
2694
2695 (define_insn "extendsfdf2"
2696   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
2697         (float_extend:DF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2698   "TARGET_HARD_FLOAT"
2699   "*
2700 {
2701   if (REGNO (operands[0]) == REGNO (operands[1]))
2702     return \"\";
2703   else
2704     return \"fmr %0,%1\";
2705 }"
2706   [(set_attr "type" "fp")])
2707
2708 (define_insn "truncdfsf2"
2709   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2710         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
2711   "TARGET_HARD_FLOAT"
2712   "frsp %0,%1"
2713   [(set_attr "type" "fp")])
2714
2715 (define_insn "aux_truncdfsf2"
2716   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2717         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] 0))]
2718   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2719   "frsp %0,%1"
2720   [(set_attr "type" "fp")])
2721
2722 (define_insn "negsf2"
2723   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2724         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2725   "TARGET_HARD_FLOAT"
2726   "fneg %0,%1"
2727   [(set_attr "type" "fp")])
2728
2729 (define_insn "abssf2"
2730   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2731         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2732   "TARGET_HARD_FLOAT"
2733   "fabs %0,%1"
2734   [(set_attr "type" "fp")])
2735
2736 (define_insn ""
2737   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2738         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
2739   "TARGET_HARD_FLOAT"
2740   "fnabs %0,%1"
2741   [(set_attr "type" "fp")])
2742
2743 (define_expand "addsf3"
2744   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2745         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
2746                  (match_operand:SF 2 "gpc_reg_operand" "")))]
2747   "TARGET_HARD_FLOAT"
2748   "")
2749
2750 (define_insn ""
2751   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2752         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2753                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2754   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2755   "fadds %0,%1,%2"
2756   [(set_attr "type" "fp")])
2757
2758 (define_insn ""
2759   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2760         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2761                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2762   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2763   "{fa|fadd} %0,%1,%2"
2764   [(set_attr "type" "fp")])
2765
2766 (define_expand "subsf3"
2767   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2768         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
2769                   (match_operand:SF 2 "gpc_reg_operand" "")))]
2770   "TARGET_HARD_FLOAT"
2771   "")
2772
2773 (define_insn ""
2774   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2775         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
2776                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
2777   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2778   "fsubs %0,%1,%2"
2779   [(set_attr "type" "fp")])
2780
2781 (define_insn ""
2782   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2783         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
2784                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
2785   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2786   "{fs|fsub} %0,%1,%2"
2787   [(set_attr "type" "fp")])
2788
2789 (define_expand "mulsf3"
2790   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2791         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
2792                  (match_operand:SF 2 "gpc_reg_operand" "")))]
2793   "TARGET_HARD_FLOAT"
2794   "")
2795
2796 (define_insn ""
2797   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2798         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2799                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2800   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2801   "fmuls %0,%1,%2"
2802   [(set_attr "type" "fp")])
2803
2804 (define_insn ""
2805   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2806         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2807                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2808   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2809   "{fm|fmul} %0,%1,%2"
2810   [(set_attr "type" "fp")])
2811
2812 (define_expand "divsf3"
2813   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2814         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
2815                 (match_operand:SF 2 "gpc_reg_operand" "")))]
2816   "TARGET_HARD_FLOAT"
2817   "")
2818
2819 (define_insn ""
2820   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2821         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
2822                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
2823   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2824   "fdivs %0,%1,%2"
2825   [(set_attr "type" "sdiv")])
2826
2827 (define_insn ""
2828   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2829         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
2830                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
2831   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2832   "{fd|fdiv} %0,%1,%2"
2833   [(set_attr "type" "sdiv")])
2834
2835 (define_insn ""
2836   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2837         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2838                           (match_operand:SF 2 "gpc_reg_operand" "f"))
2839                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
2840   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2841   "fmadds %0,%1,%2,%3"
2842   [(set_attr "type" "fp")])
2843
2844 (define_insn ""
2845   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2846         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2847                           (match_operand:SF 2 "gpc_reg_operand" "f"))
2848                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
2849   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2850   "{fma|fmadd} %0,%1,%2,%3"
2851   [(set_attr "type" "fp")])
2852
2853 (define_insn ""
2854   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2855         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2856                            (match_operand:SF 2 "gpc_reg_operand" "f"))
2857                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
2858   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2859   "fmsubs %0,%1,%2,%3"
2860   [(set_attr "type" "fp")])
2861
2862 (define_insn ""
2863   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2864         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2865                            (match_operand:SF 2 "gpc_reg_operand" "f"))
2866                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
2867   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2868   "{fms|fmsub} %0,%1,%2,%3"
2869   [(set_attr "type" "fp")])
2870
2871 (define_insn ""
2872   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2873         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2874                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
2875                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
2876   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2877   "fnmadds %0,%1,%2,%3"
2878   [(set_attr "type" "fp")])
2879
2880 (define_insn ""
2881   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2882         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2883                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
2884                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
2885   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2886   "{fnma|fnmadd} %0,%1,%2,%3"
2887   [(set_attr "type" "fp")])
2888
2889 (define_insn ""
2890   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2891         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2892                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
2893                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
2894   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2895   "fnmsubs %0,%1,%2,%3"
2896   [(set_attr "type" "fp")])
2897
2898 (define_insn ""
2899   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2900         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2901                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
2902                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
2903   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2904   "{fnms|fnmsub} %0,%1,%2,%3"
2905   [(set_attr "type" "fp")])
2906
2907 (define_expand "sqrtsf2"
2908   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2909         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
2910   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT"
2911   "")
2912
2913 (define_insn ""
2914   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2915         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2916   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT"
2917   "fsqrts %0,%1"
2918   [(set_attr "type" "ssqrt")])
2919
2920 (define_insn ""
2921   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2922         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2923   "TARGET_POWER2 && TARGET_HARD_FLOAT"
2924   "fsqrt %0,%1"
2925   [(set_attr "type" "dsqrt")])
2926
2927 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
2928 ;; fsel instruction and some auxiliary computations.  Then we just have a
2929 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
2930 ;; combine.
2931 (define_expand "maxsf3"
2932   [(set (match_dup 3)
2933         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
2934                   (match_operand:SF 2 "gpc_reg_operand" "")))
2935    (set (match_operand:SF 0 "gpc_reg_operand" "")
2936         (if_then_else:SF (ge (match_dup 3)
2937                              (const_int 0))
2938                          (match_dup 1)
2939                          (match_dup 2)))]
2940   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
2941   "
2942 { operands[3] = gen_reg_rtx (SFmode); }")
2943
2944 (define_split
2945   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2946         (smax:SF (match_operand:SF 1 "gpc_reg_operand" "")
2947                  (match_operand:SF 2 "gpc_reg_operand" "")))
2948    (clobber (match_operand:SF 3 "gpc_reg_operand" ""))]
2949   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
2950   [(set (match_dup 3)
2951         (minus:SF (match_dup 1) (match_dup 2)))
2952    (set (match_dup 0)
2953         (if_then_else:SF (ge (match_dup 3)
2954                              (const_int 0))
2955                          (match_dup 1)
2956                          (match_dup 2)))]
2957   "")
2958
2959 (define_expand "minsf3"
2960   [(set (match_dup 3)
2961         (minus:SF (match_operand:SF 2 "gpc_reg_operand" "")
2962                   (match_operand:SF 1 "gpc_reg_operand" "")))
2963    (set (match_operand:SF 0 "gpc_reg_operand" "")
2964         (if_then_else:SF (ge (match_dup 3)
2965                              (const_int 0))
2966                          (match_dup 1)
2967                          (match_dup 2)))]
2968   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
2969   "
2970 { operands[3] = gen_reg_rtx (SFmode); }")
2971
2972 (define_split
2973   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2974         (smin:SF (match_operand:SF 1 "gpc_reg_operand" "")
2975                  (match_operand:SF 2 "gpc_reg_operand" "")))
2976    (clobber (match_operand:SF 3 "gpc_reg_operand" ""))]
2977   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
2978   [(set (match_dup 3)
2979         (minus:SF (match_dup 2) (match_dup 1)))
2980    (set (match_dup 0)
2981         (if_then_else:SF (ge (match_dup 3)
2982                              (const_int 0))
2983                          (match_dup 1)
2984                          (match_dup 2)))]
2985   "")
2986
2987 (define_expand "movsfcc"
2988    [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2989          (if_then_else:SF (match_operand 1 "comparison_operator" "")
2990                           (match_operand:SF 2 "gpc_reg_operand" "f")
2991                           (match_operand:SF 3 "gpc_reg_operand" "f")))]
2992   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
2993   "
2994 {
2995   rtx temp, op0, op1;
2996   enum rtx_code code = GET_CODE (operands[1]);
2997   if (! rs6000_compare_fp_p)
2998     FAIL;
2999   switch (code)
3000     {
3001     case GE: case EQ: case NE:
3002       op0 = rs6000_compare_op0;
3003       op1 = rs6000_compare_op1;
3004       break;
3005     case GT:
3006       op0 = rs6000_compare_op1;
3007       op1 = rs6000_compare_op0;
3008       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3009       break;
3010     case LE:
3011       op0 = rs6000_compare_op1;
3012       op1 = rs6000_compare_op0;
3013       break;
3014     case LT:
3015       op0 = rs6000_compare_op0;
3016       op1 = rs6000_compare_op1;
3017       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3018       break;
3019     default:
3020       FAIL;
3021     }
3022   if (GET_MODE (rs6000_compare_op0) == DFmode)
3023     {
3024       temp = gen_reg_rtx (DFmode);
3025       emit_insn (gen_subdf3 (temp, op0, op1));
3026       emit_insn (gen_fseldfsf4 (operands[0], temp, operands[2], operands[3]));
3027       if (code == EQ)
3028         {
3029           emit_insn (gen_negdf2 (temp, temp));
3030           emit_insn (gen_fseldfsf4 (operands[0], temp, operands[0], operands[3]));
3031         }
3032       if (code == NE)
3033         {
3034           emit_insn (gen_negdf2 (temp, temp));
3035           emit_insn (gen_fseldfsf4 (operands[0], temp, operands[3], operands[0]));
3036         }
3037     }
3038   else
3039     {
3040       temp = gen_reg_rtx (SFmode);
3041       emit_insn (gen_subsf3 (temp, op0, op1));
3042       emit_insn (gen_fselsfsf4 (operands[0], temp, operands[2], operands[3]));
3043       if (code == EQ)
3044         {
3045           emit_insn (gen_negsf2 (temp, temp));
3046           emit_insn (gen_fselsfsf4 (operands[0], temp, operands[0], operands[3]));
3047         }
3048       if (code == NE)
3049         {
3050           emit_insn (gen_negsf2 (temp, temp));
3051           emit_insn (gen_fselsfsf4 (operands[0], temp, operands[3], operands[0]));
3052         }
3053     }
3054   DONE;
3055 }")
3056
3057 (define_insn "fselsfsf4"
3058   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3059         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
3060                              (const_int 0))
3061                          (match_operand:SF 2 "gpc_reg_operand" "f")
3062                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
3063   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3064   "fsel %0,%1,%2,%3"
3065   [(set_attr "type" "fp")])
3066
3067 (define_insn "fseldfsf4"
3068   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3069         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
3070                              (const_int 0))
3071                          (match_operand:SF 2 "gpc_reg_operand" "f")
3072                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
3073   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3074   "fsel %0,%1,%2,%3"
3075   [(set_attr "type" "fp")])
3076
3077 (define_insn "negdf2"
3078   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3079         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
3080   "TARGET_HARD_FLOAT"
3081   "fneg %0,%1"
3082   [(set_attr "type" "fp")])
3083
3084 (define_insn "absdf2"
3085   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3086         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
3087   "TARGET_HARD_FLOAT"
3088   "fabs %0,%1"
3089   [(set_attr "type" "fp")])
3090
3091 (define_insn ""
3092   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3093         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
3094   "TARGET_HARD_FLOAT"
3095   "fnabs %0,%1"
3096   [(set_attr "type" "fp")])
3097
3098 (define_insn "adddf3"
3099   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3100         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3101                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
3102   "TARGET_HARD_FLOAT"
3103   "{fa|fadd} %0,%1,%2"
3104   [(set_attr "type" "fp")])
3105
3106 (define_insn "subdf3"
3107   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3108         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
3109                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
3110   "TARGET_HARD_FLOAT"
3111   "{fs|fsub} %0,%1,%2"
3112   [(set_attr "type" "fp")])
3113
3114 (define_insn "muldf3"
3115   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3116         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3117                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
3118   "TARGET_HARD_FLOAT"
3119   "{fm|fmul} %0,%1,%2"
3120   [(set_attr "type" "dmul")])
3121
3122 (define_insn "divdf3"
3123   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3124         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
3125                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
3126   "TARGET_HARD_FLOAT"
3127   "{fd|fdiv} %0,%1,%2"
3128   [(set_attr "type" "ddiv")])
3129
3130 (define_insn ""
3131   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3132         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3133                           (match_operand:DF 2 "gpc_reg_operand" "f"))
3134                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
3135   "TARGET_HARD_FLOAT"
3136   "{fma|fmadd} %0,%1,%2,%3"
3137   [(set_attr "type" "dmul")])
3138
3139 (define_insn ""
3140   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3141         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3142                            (match_operand:DF 2 "gpc_reg_operand" "f"))
3143                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
3144   "TARGET_HARD_FLOAT"
3145   "{fms|fmsub} %0,%1,%2,%3"
3146   [(set_attr "type" "dmul")])
3147
3148 (define_insn ""
3149   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3150         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3151                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
3152                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
3153   "TARGET_HARD_FLOAT"
3154   "{fnma|fnmadd} %0,%1,%2,%3"
3155   [(set_attr "type" "dmul")])
3156
3157 (define_insn ""
3158   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3159         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3160                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
3161                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
3162   "TARGET_HARD_FLOAT"
3163   "{fnms|fnmsub} %0,%1,%2,%3"
3164   [(set_attr "type" "dmul")])
3165
3166 (define_insn "sqrtdf2"
3167   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3168         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
3169   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT"
3170   "fsqrt %0,%1"
3171   [(set_attr "type" "dsqrt")])
3172
3173 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
3174 ;; fsel instruction and some auxiliary computations.  Then we just have a
3175 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
3176 ;; combine.
3177
3178 (define_expand "maxdf3"
3179   [(set (match_dup 3)
3180         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
3181                   (match_operand:DF 2 "gpc_reg_operand" "")))
3182    (set (match_operand:DF 0 "gpc_reg_operand" "")
3183         (if_then_else:DF (ge (match_dup 3)
3184                              (const_int 0))
3185                          (match_dup 1)
3186                          (match_dup 2)))]
3187   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3188   "
3189 { operands[3] = gen_reg_rtx (DFmode); }")
3190
3191 (define_split
3192   [(set (match_operand:DF 0 "gpc_reg_operand" "")
3193         (smax:DF (match_operand:DF 1 "gpc_reg_operand" "")
3194                  (match_operand:DF 2 "gpc_reg_operand" "")))
3195    (clobber (match_operand:DF 3 "gpc_reg_operand" ""))]
3196   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3197   [(set (match_dup 3)
3198         (minus:DF (match_dup 1) (match_dup 2)))
3199    (set (match_dup 0)
3200         (if_then_else:DF (ge (match_dup 3)
3201                              (const_int 0))
3202                          (match_dup 1)
3203                          (match_dup 2)))]
3204   "")
3205
3206 (define_expand "mindf3"
3207   [(set (match_dup 3)
3208         (minus:DF (match_operand:DF 2 "gpc_reg_operand" "")
3209                   (match_operand:DF 1 "gpc_reg_operand" "")))
3210    (set (match_operand:DF 0 "gpc_reg_operand" "")
3211         (if_then_else:DF (ge (match_dup 3)
3212                              (const_int 0))
3213                          (match_dup 1)
3214                          (match_dup 2)))]
3215   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3216   "
3217 { operands[3] = gen_reg_rtx (DFmode); }")
3218
3219 (define_split
3220   [(set (match_operand:DF 0 "gpc_reg_operand" "")
3221         (smin:DF (match_operand:DF 1 "gpc_reg_operand" "")
3222                  (match_operand:DF 2 "gpc_reg_operand" "")))
3223    (clobber (match_operand:DF 3 "gpc_reg_operand" ""))]
3224   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3225   [(set (match_dup 3)
3226         (minus:DF (match_dup 2) (match_dup 1)))
3227    (set (match_dup 0)
3228         (if_then_else:DF (ge (match_dup 3)
3229                              (const_int 0))
3230                          (match_dup 1)
3231                          (match_dup 2)))]
3232   "")
3233
3234 (define_expand "movdfcc"
3235    [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3236          (if_then_else:DF (match_operand 1 "comparison_operator" "")
3237                           (match_operand:DF 2 "gpc_reg_operand" "f")
3238                           (match_operand:DF 3 "gpc_reg_operand" "f")))]
3239   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3240   "
3241 {
3242   rtx temp, op0, op1;
3243   enum rtx_code code = GET_CODE (operands[1]);
3244   if (! rs6000_compare_fp_p)
3245     FAIL;
3246   switch (code)
3247     {
3248     case GE: case EQ: case NE:
3249       op0 = rs6000_compare_op0;
3250       op1 = rs6000_compare_op1;
3251       break;
3252     case GT:
3253       op0 = rs6000_compare_op1;
3254       op1 = rs6000_compare_op0;
3255       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3256       break;
3257     case LE:
3258       op0 = rs6000_compare_op1;
3259       op1 = rs6000_compare_op0;
3260       break;
3261     case LT:
3262       op0 = rs6000_compare_op0;
3263       op1 = rs6000_compare_op1;
3264       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3265       break;
3266     default:
3267       FAIL;
3268     }
3269   if (GET_MODE (rs6000_compare_op0) == DFmode)
3270     {
3271       temp = gen_reg_rtx (DFmode);
3272       emit_insn (gen_subdf3 (temp, op0, op1));
3273       emit_insn (gen_fseldfdf4 (operands[0], temp, operands[2], operands[3]));
3274       if (code == EQ)
3275         {
3276           emit_insn (gen_negdf2 (temp, temp));
3277           emit_insn (gen_fseldfdf4 (operands[0], temp, operands[0], operands[3]));
3278         }
3279       if (code == NE)
3280         {
3281           emit_insn (gen_negdf2 (temp, temp));
3282           emit_insn (gen_fseldfdf4 (operands[0], temp, operands[3], operands[0]));
3283         }
3284     }
3285   else
3286     {
3287       temp = gen_reg_rtx (SFmode);
3288       emit_insn (gen_subsf3 (temp, op0, op1));
3289       emit_insn (gen_fselsfdf4 (operands[0], temp, operands[2], operands[3]));
3290       if (code == EQ)
3291         {
3292           emit_insn (gen_negsf2 (temp, temp));
3293           emit_insn (gen_fselsfdf4 (operands[0], temp, operands[0], operands[3]));
3294         }
3295       if (code == NE)
3296         {
3297           emit_insn (gen_negsf2 (temp, temp));
3298           emit_insn (gen_fselsfdf4 (operands[0], temp, operands[3], operands[0]));
3299         }
3300     }
3301   DONE;
3302 }")
3303
3304 (define_insn "fseldfdf4"
3305   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3306         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
3307                              (const_int 0))
3308                          (match_operand:DF 2 "gpc_reg_operand" "f")
3309                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
3310   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3311   "fsel %0,%1,%2,%3"
3312   [(set_attr "type" "fp")])
3313
3314 (define_insn "fselsfdf4"
3315   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3316         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
3317                              (const_int 0))
3318                          (match_operand:DF 2 "gpc_reg_operand" "f")
3319                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
3320   "TARGET_PPC_GFXOPT"
3321   "fsel %0,%1,%2,%3"
3322   [(set_attr "type" "fp")])
3323 \f
3324 ;; Conversions to and from floating-point.
3325 (define_expand "floatsidf2"
3326   [(set (match_dup 2)
3327         (plus:DI (zero_extend:DI
3328                   (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3329                           (match_dup 3)))
3330                  (match_dup 4)))
3331    (set (match_operand:DF 0 "gpc_reg_operand" "")
3332         (minus:DF (subreg:DF (match_dup 2) 0)
3333                   (match_dup 5)))]
3334   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3335   "
3336 {
3337   operands[2] = gen_reg_rtx (DImode);
3338   operands[3] = gen_rtx (CONST_INT, VOIDmode, 0x80000000);
3339   operands[4] = rs6000_immed_double_const (0, 0x43300000, DImode);
3340   operands[5] = force_reg (DFmode, rs6000_immed_double_const (0x43300000,
3341                                                               0x80000000,
3342                                                               DFmode));
3343 }")
3344
3345 (define_expand "floatunssidf2"
3346   [(set (match_dup 2)
3347         (plus:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
3348                  (match_dup 3)))
3349    (set (match_operand:DF 0 "gpc_reg_operand" "")
3350         (minus:DF (subreg:DF (match_dup 2) 0)
3351                   (match_dup 4)))]
3352   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3353   "
3354 {
3355   operands[2] = gen_reg_rtx (DImode);
3356   operands[3] = rs6000_immed_double_const (0, 0x43300000, DImode);
3357   operands[4] = force_reg (DFmode, rs6000_immed_double_const (0x43300000, 0, DFmode));
3358 }")
3359
3360 ;; For the above two cases, we always split.
3361 (define_split
3362   [(set (match_operand:DI 0 "gpc_reg_operand" "")
3363         (plus:DI (zero_extend:DI
3364                   (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3365                           (match_operand:SI 2 "logical_operand" "")))
3366                  (match_operand:DI 3 "low_32_bit_operand" "")))]
3367   "reload_completed"
3368   [(set (match_dup 6) (xor:SI (match_dup 1) (match_dup 2)))
3369    (set (match_dup 4) (match_dup 5))]
3370   "
3371 { operands[4] = operand_subword (operands[0], 0, 0, DImode);
3372   operands[5] = operand_subword (operands[3], 0, 0, DImode);
3373   operands[6] = operand_subword (operands[0], 1, 0, DImode);
3374 }")
3375
3376 (define_insn ""
3377   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3378         (plus:DI (zero_extend:DI
3379                   (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
3380                           (match_operand:SI 2 "logical_operand" "rKJ")))
3381                  (match_operand:DI 3 "low_32_bit_operand" "n")))]
3382   ""
3383   "#"
3384   [(set_attr "length" "8")])
3385
3386 (define_split
3387   [(set (match_operand:DI 0 "gpc_reg_operand" "=")
3388         (plus:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
3389                  (match_operand:DI 2 "low_32_bit_operand" "")))]
3390   "reload_completed"
3391   [(set (match_dup 3) (match_dup 4))
3392    (set (match_dup 5) (match_dup 1))]
3393   "
3394 { operands[3] = operand_subword (operands[0], 0, 0, DImode);
3395   operands[4] = operand_subword (operands[2], 0, 0, DImode);
3396   operands[5] = operand_subword (operands[0], 1, 0, DImode);
3397
3398   if (rtx_equal_p (operands[1], operands[5]))
3399     {
3400       emit_move_insn (operands[3], operands[4]);
3401       DONE;
3402     }
3403
3404   if (rtx_equal_p (operands[1], operands[3]))
3405     {
3406       rtx temp;
3407
3408       temp = operands[3]; operands[3] = operands[5]; operands[5] = temp;
3409       temp = operands[4]; operands[4] = operands[1]; operands[1] = temp;
3410     }
3411 }")
3412
3413 (define_insn ""
3414   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3415         (plus:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
3416                  (match_operand:DI 2 "low_32_bit_operand" "n")))]
3417   ""
3418   "#"
3419   [(set_attr "length" "8")])
3420
3421 (define_expand "fix_truncdfsi2"
3422   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3423         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))]
3424   "TARGET_HARD_FLOAT"
3425   "
3426 {
3427   if (TARGET_POWER2 || TARGET_POWERPC)
3428     {
3429       rtx stack_slot = assign_stack_temp (DImode, 8, 0),
3430         temp = gen_reg_rtx (DImode);
3431
3432       emit_insn (gen_fpcvtsi (temp, operands[1]));
3433       emit_move_insn (stack_slot, temp);
3434       emit_move_insn (operands[0],
3435                       operand_subword (stack_slot, 1, 0, DImode));
3436       DONE;
3437     }
3438   else
3439     {
3440       emit_insn (gen_trunc_call (operands[0], operands[1],
3441                                  gen_rtx (SYMBOL_REF, Pmode, RS6000_ITRUNC)));
3442       DONE;
3443     }
3444 }")
3445
3446 (define_insn "fpcvtsi"
3447   [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
3448         (sign_extend:DI
3449          (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))))]
3450   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT"
3451   "{fcirz|fctiwz} %0,%1"
3452   [(set_attr "type" "fp")])
3453
3454 (define_expand "fixuns_truncdfsi2"
3455   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3456         (unsigned_fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))]
3457   "! TARGET_POWER2 && ! TARGET_POWERPC && TARGET_HARD_FLOAT"
3458   "
3459 {
3460   emit_insn (gen_trunc_call (operands[0], operands[1],
3461                              gen_rtx (SYMBOL_REF, Pmode, RS6000_UITRUNC)));
3462   DONE;
3463 }")
3464
3465 (define_expand "trunc_call"
3466   [(parallel [(set (match_operand:SI 0 "" "")
3467                    (fix:SI (match_operand:DF 1 "" "")))
3468               (use (match_operand:SI 2 "" ""))])]
3469   "TARGET_HARD_FLOAT"
3470   "
3471 {
3472   rtx insns = gen_trunc_call_rtl (operands[0], operands[1], operands[2]);
3473   rtx first = XVECEXP (insns, 0, 0);
3474   rtx last = XVECEXP (insns, 0, XVECLEN (insns, 0) - 1);
3475
3476   REG_NOTES (first) = gen_rtx (INSN_LIST, REG_LIBCALL, last,
3477                                REG_NOTES (first));
3478   REG_NOTES (last) = gen_rtx (INSN_LIST, REG_RETVAL, first, REG_NOTES (last));
3479
3480   emit_insn (insns);
3481   DONE;
3482 }")
3483
3484 (define_expand "trunc_call_rtl"
3485   [(set (reg:DF 33) (match_operand:DF 1 "gpc_reg_operand" ""))
3486    (use (reg:DF 33))
3487    (parallel [(set (reg:SI 3)
3488                    (call (mem:SI (match_operand 2 "" "")) (const_int 0)))
3489               (clobber (scratch:SI))])
3490    (set (match_operand:SI 0 "gpc_reg_operand" "")
3491         (reg:SI 3))]
3492   "TARGET_HARD_FLOAT"
3493   "
3494 {
3495   rs6000_trunc_used = 1;
3496 }")
3497
3498 (define_insn "floatdidf2"
3499   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3500         (float:DF (match_operand:DI 1 "gpc_reg_operand" "f")))]
3501   "TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3502   "fcfid %0,%1"
3503   [(set_attr "type" "fp")])
3504
3505 (define_insn "fix_truncdfdi2"
3506   [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
3507         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
3508   "TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3509   "fctidz %0,%1"
3510   [(set_attr "type" "fp")])
3511 \f
3512 ;; Define the DImode operations that can be done in a small number
3513 ;; of instructions.
3514 (define_expand "adddi3"
3515   [(set (match_operand:DI 0 "gpc_reg_operand" "")
3516         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
3517                  (match_operand:DI 2 "reg_or_short_operand" "")))]
3518   ""
3519   "
3520 {
3521   if (! TARGET_POWER && ! TARGET_POWERPC64
3522       && short_cint_operand (operands[2], DImode))
3523     FAIL;
3524 }")
3525
3526 (define_insn ""
3527   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3528         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
3529                  (match_operand:DI 2 "reg_or_short_operand" "r,I")))]
3530   "TARGET_POWER && ! TARGET_POWERPC64"
3531   "@
3532    {a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2
3533    {ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1"
3534   [(set_attr "length" "8")])
3535
3536 (define_insn ""
3537   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3538         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
3539                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
3540   "! TARGET_POWER && ! TARGET_POWERPC64"
3541   "addc %L0,%L1,%L2\;adde %0,%1,%2"
3542   [(set_attr "length" "8")])
3543
3544 (define_expand "subdi3"
3545   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3546         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I")
3547                   (match_operand:DI 2 "gpc_reg_operand" "r,r")))]
3548   ""
3549   "
3550 {
3551   if (! TARGET_POWER && ! TARGET_POWERPC64
3552       && short_cint_operand (operands[1], DImode))
3553     FAIL;
3554 }")
3555
3556 (define_insn ""
3557   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3558         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I")
3559                   (match_operand:DI 2 "gpc_reg_operand" "r,r")))]
3560   "TARGET_POWER && ! TARGET_POWERPC64"
3561   "@
3562    {sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1
3563    {sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2"
3564   [(set_attr "length" "8")])
3565
3566 (define_insn ""
3567   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3568         (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3569                   (match_operand:DI 2 "gpc_reg_operand" "r")))]
3570   "! TARGET_POWER && ! TARGET_POWERPC64"
3571   "subfc %L0,%L2,%L1\;subfe %0,%2,%1"
3572   [(set_attr "length" "8")])
3573
3574 (define_expand "negdi2"
3575   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3576         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
3577   ""
3578   "")
3579
3580 (define_insn ""
3581   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3582         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
3583   "! TARGET_POWERPC64"
3584   "{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1"
3585   [(set_attr "length" "8")])
3586
3587 (define_expand "mulsidi3"
3588   [(set (match_operand:DI 0 "gpc_reg_operand" "")
3589         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
3590                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
3591   ""
3592   "
3593 {
3594   if (! TARGET_POWER && ! TARGET_POWERPC)
3595     {
3596       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
3597       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
3598       emit_insn (gen_mull_call ());
3599       emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
3600                       gen_rtx (REG, SImode, 3));
3601       emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
3602                       gen_rtx (REG, SImode, 4));
3603       DONE;
3604     }
3605   else if (TARGET_POWER)
3606     {
3607       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
3608       DONE;
3609     }
3610 }")
3611
3612 (define_insn "mulsidi3_mq"
3613   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3614         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
3615                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
3616    (clobber (match_scratch:SI 3 "=q"))]
3617   "TARGET_POWER"
3618   "mul %0,%1,%2\;mfmq %L0"
3619   [(set_attr "type" "imul")
3620    (set_attr "length" "8")])
3621
3622 (define_insn ""
3623   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
3624         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
3625                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
3626   "TARGET_POWERPC && ! TARGET_POWERPC64"
3627   "mulhw %0,%1,%2\;mullw %L0,%1,%2"
3628   [(set_attr "type" "imul")
3629    (set_attr "length" "8")])
3630
3631 (define_expand "smulsi3_highpart"
3632   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3633         (truncate:SI
3634          (lshiftrt:DI (mult:DI (sign_extend:DI
3635                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
3636                                (sign_extend:DI
3637                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
3638                       (const_int 32))))]
3639   ""
3640   "
3641 {
3642   if (! TARGET_POWER && ! TARGET_POWERPC)
3643     {
3644       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
3645       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
3646       emit_insn (gen_mulh_call ());
3647       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
3648       DONE;
3649     }
3650   else if (TARGET_POWER)
3651     {
3652       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
3653       DONE;
3654     }
3655 }")
3656
3657 (define_insn "smulsi3_highpart_mq"
3658   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3659         (truncate:SI
3660          (lshiftrt:DI (mult:DI (sign_extend:DI
3661                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
3662                                (sign_extend:DI
3663                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
3664                       (const_int 32))))
3665    (clobber (match_scratch:SI 3 "=q"))]
3666   "TARGET_POWER"
3667   "mul %0,%1,%2"
3668   [(set_attr "type" "imul")])
3669
3670 (define_insn ""
3671   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3672         (truncate:SI
3673          (lshiftrt:DI (mult:DI (sign_extend:DI
3674                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
3675                                (sign_extend:DI
3676                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
3677                       (const_int 32))))]
3678   "TARGET_POWERPC"
3679   "mulhw %0,%1,%2"
3680   [(set_attr "type" "imul")])
3681
3682 (define_insn "umulsi3_highpart"
3683   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3684         (truncate:SI
3685          (lshiftrt:DI (mult:DI (zero_extend:DI
3686                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
3687                                (zero_extend:DI
3688                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
3689                       (const_int 32))))]
3690   "TARGET_POWERPC"
3691   "mulhwu %0,%1,%2"
3692   [(set_attr "type" "imul")])
3693
3694 ;; If operands 0 and 2 are in the same register, we have a problem.  But
3695 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
3696 ;; why we have the strange constraints below.
3697 (define_insn "ashldi3"
3698   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
3699         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
3700                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
3701    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
3702   "TARGET_POWER"
3703   "@
3704    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
3705    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
3706    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
3707    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
3708   [(set_attr "length" "8")])
3709
3710 (define_insn "lshrdi3"
3711   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r,r,&r")
3712         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
3713                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
3714    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
3715   "TARGET_POWER"
3716   "@
3717    {cal %0,0(0)|li %0,0}\;{s%A2i|s%A2wi} %L0,%1,%h2
3718    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
3719    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
3720    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
3721   [(set_attr "length" "8")])
3722
3723 ;; Shift by a variable amount is too complex to be worth open-coding.  We
3724 ;; just handle shifts by constants.
3725
3726 (define_expand "ashrdi3"
3727   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "")
3728                    (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
3729                                 (match_operand:SI 2 "general_operand" "")))
3730               (clobber (match_scratch:SI 3 ""))])]
3731   "TARGET_POWER"
3732   "
3733 { if (GET_CODE (operands[2]) != CONST_INT)
3734     FAIL;
3735 }")
3736
3737 (define_insn ""
3738   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3739         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
3740                      (match_operand:SI 2 "const_int_operand" "M,i")))
3741    (clobber (match_scratch:SI 3 "=X,q"))]
3742   "TARGET_POWER"
3743   "@
3744    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
3745    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
3746   [(set_attr "length" "8")])
3747 \f
3748 ;; PowerPC64 DImode operations.
3749
3750 (define_insn "ffsdi2"
3751   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
3752         (ffs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
3753   "TARGET_POWERPC64"
3754   "neg %0,%1\;and %0,%0,%1\;cntlzd %0,%0\;subfic %0,%0,64"
3755   [(set_attr "length" "16")])
3756
3757 (define_insn "muldi3"
3758   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3759         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
3760                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
3761   "TARGET_POWERPC64"
3762   "mulld %0,%1,%2"
3763    [(set_attr "type" "imul")])
3764
3765 (define_insn "smuldi3_highpart"
3766   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3767         (truncate:DI
3768          (lshiftrt:TI (mult:TI (sign_extend:TI
3769                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
3770                                (sign_extend:TI
3771                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
3772                       (const_int 64))))]
3773   "TARGET_POWERPC64"
3774   "mulhd %0,%1,%2"
3775   [(set_attr "type" "imul")])
3776
3777 (define_insn "umuldi3_highpart"
3778   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3779         (truncate:DI
3780          (lshiftrt:TI (mult:TI (zero_extend:TI
3781                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
3782                                (zero_extend:TI
3783                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
3784                       (const_int 64))))]
3785   "TARGET_POWERPC64"
3786   "mulhdu %0,%1,%2"
3787   [(set_attr "type" "imul")])
3788
3789 (define_insn "divdi3"
3790   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3791         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3792                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
3793   "TARGET_POWERPC64"
3794   "divd %0,%1,%2"
3795   [(set_attr "type" "idiv")])
3796
3797 (define_insn "udivdi3"
3798   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3799         (udiv:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3800                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
3801   "TARGET_POWERPC64"
3802   "divdu %0,%1,%2"
3803   [(set_attr "type" "idiv")])
3804
3805 (define_insn "rotldi3"
3806   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3807         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3808                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
3809   "TARGET_POWERPC64"
3810   "rld%I2cl %0,%1,%h2,0")
3811
3812 (define_insn ""
3813   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
3814         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3815                                (match_operand:DI 2 "reg_or_cint_operand" "ri"))
3816                     (const_int 0)))
3817    (clobber (match_scratch:DI 3 "=r"))]
3818   "TARGET_POWERPC64"
3819   "rld%I2cl. %3,%1,%h2,0"
3820   [(set_attr "type" "delayed_compare")])
3821
3822 (define_insn ""
3823   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
3824         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3825                                (match_operand:DI 2 "reg_or_cint_operand" "ri"))
3826                     (const_int 0)))
3827    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3828         (rotate:DI (match_dup 1) (match_dup 2)))]
3829   "TARGET_POWERPC64"
3830   "rld%I2cl. %0,%1,%h2,0"
3831   [(set_attr "type" "delayed_compare")])
3832 \f
3833 ;; Now define ways of moving data around.
3834 ;;
3835 ;; For SI, we special-case integers that can't be loaded in one insn.  We
3836 ;; do the load 16-bits at a time.  We could do this by loading from memory,
3837 ;; and this is even supposed to be faster, but it is simpler not to get
3838 ;; integers in the TOC.
3839 (define_expand "movsi"
3840   [(set (match_operand:SI 0 "general_operand" "")
3841         (match_operand:SI 1 "any_operand" ""))]
3842   ""
3843   "
3844 {
3845   if (GET_CODE (operands[0]) != REG)
3846     operands[1] = force_reg (SImode, operands[1]);
3847
3848   if (CONSTANT_P (operands[1]) && GET_CODE (operands[1]) != CONST_INT
3849       && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1]))
3850     {
3851       /* If we are to limit the number of things we put in the TOC and
3852          this is a symbol plus a constant we can add in one insn,
3853          just put the sumbol in the TOC and add the constant.  Don't do
3854          this if reload is in progress.  */
3855       if (GET_CODE (operands[1]) == CONST
3856           && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
3857           && GET_CODE (XEXP (operands[1], 0)) == PLUS
3858           && add_operand (XEXP (XEXP (operands[1], 0), 1), SImode)
3859           && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
3860               || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
3861           && ! side_effects_p (operands[0]))
3862         {
3863           rtx sym = force_const_mem (SImode, XEXP (XEXP (operands[1], 0), 0));
3864           rtx other = XEXP (XEXP (operands[1], 0), 1);
3865
3866           emit_insn (gen_addsi3 (operands[0], force_reg (SImode, sym), other));
3867           DONE;
3868         }
3869
3870       operands[1] = force_const_mem (SImode, operands[1]);
3871       if (! memory_address_p (SImode, XEXP (operands[1], 0))
3872           && ! reload_in_progress)
3873         operands[1] = change_address (operands[1], SImode,
3874                                       XEXP (operands[1], 0));
3875     }
3876
3877   if (GET_CODE (operands[1]) == CONST_INT
3878       && (unsigned) (INTVAL (operands[1]) + 0x8000) >= 0x10000
3879       && (INTVAL (operands[1]) & 0xffff) != 0)
3880     {
3881       emit_move_insn (operands[0],
3882                       gen_rtx (CONST_INT, VOIDmode,
3883                                INTVAL (operands[1]) & 0xffff0000));
3884       emit_insn (gen_iorsi3 (operands[0], operands[0],
3885                              gen_rtx (CONST_INT, VOIDmode,
3886                                       INTVAL (operands[1]) & 0xffff)));
3887       DONE;
3888     }
3889 }")
3890
3891 (define_insn ""
3892   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,*q,*c*l,*h")
3893         (match_operand:SI 1 "input_operand" "r,m,r,I,J,R,*h,r,r,0"))]
3894   "gpc_reg_operand (operands[0], SImode)
3895    || gpc_reg_operand (operands[1], SImode)"
3896   "@
3897    mr %0,%1
3898    {l%U1%X1|lwz%U1%X1} %0,%1
3899    {st%U0%X0|stw%U0%X0} %1,%0
3900    {lil|li} %0,%1
3901    {liu|lis} %0,%u1
3902    {cal|la} %0,%1(%*)
3903    mf%1 %0
3904    mt%0 %1
3905    mt%0 %1
3906    cror 0,0,0"
3907   [(set_attr "type" "*,load,*,*,*,*,*,*,mtjmpr,*")])
3908
3909 ;; Split a load of a large constant into the appropriate two-insn
3910 ;; sequence.
3911
3912 (define_split
3913   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3914         (match_operand:SI 1 "const_int_operand" ""))]
3915   "(unsigned) (INTVAL (operands[1]) + 0x8000) >= 0x10000
3916    && (INTVAL (operands[1]) & 0xffff) != 0"
3917   [(set (match_dup 0)
3918         (match_dup 2))
3919    (set (match_dup 0)
3920         (ior:SI (match_dup 0)
3921                 (match_dup 3)))]
3922   "
3923 {
3924   operands[2] = gen_rtx (CONST_INT, VOIDmode,
3925                          INTVAL (operands[1]) & 0xffff0000);
3926   operands[3] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[1]) & 0xffff);
3927 }")
3928
3929 (define_insn ""
3930   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
3931         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
3932                     (const_int 0)))
3933    (set (match_operand:SI 0 "gpc_reg_operand" "=r") (match_dup 1))]
3934   ""
3935   "mr. %0,%1"
3936   [(set_attr "type" "compare")])
3937 \f
3938 (define_expand "movhi"
3939   [(set (match_operand:HI 0 "general_operand" "")
3940         (match_operand:HI 1 "any_operand" ""))]
3941   ""
3942   "
3943 {
3944   if (GET_CODE (operands[0]) != REG)
3945     operands[1] = force_reg (HImode, operands[1]);
3946
3947   if (CONSTANT_P (operands[1]) && GET_CODE (operands[1]) != CONST_INT)
3948     {
3949       operands[1] = force_const_mem (HImode, operands[1]);
3950       if (! memory_address_p (HImode, XEXP (operands[1], 0))
3951           && ! reload_in_progress)
3952         operands[1] = change_address (operands[1], HImode,
3953                                       XEXP (operands[1], 0));
3954     }
3955 }")
3956
3957 (define_insn ""
3958   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
3959         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
3960   "gpc_reg_operand (operands[0], HImode)
3961    || gpc_reg_operand (operands[1], HImode)"
3962   "@
3963    mr %0,%1
3964    lhz%U1%X1 %0,%1
3965    sth%U0%X0 %1,%0
3966    {lil|li} %0,%w1
3967    mf%1 %0
3968    mt%0 %1
3969    mt%0 %1
3970    cror 0,0,0"
3971   [(set_attr "type" "*,load,*,*,*,*,mtjmpr,*")])
3972
3973 (define_expand "movqi"
3974   [(set (match_operand:QI 0 "general_operand" "")
3975         (match_operand:QI 1 "any_operand" ""))]
3976   ""
3977   "
3978 {
3979   if (GET_CODE (operands[0]) != REG)
3980     operands[1] = force_reg (QImode, operands[1]);
3981
3982   if (CONSTANT_P (operands[1]) && GET_CODE (operands[1]) != CONST_INT)
3983     {
3984       operands[1] = force_const_mem (QImode, operands[1]);
3985       if (! memory_address_p (QImode, XEXP (operands[1], 0))
3986           && ! reload_in_progress)
3987         operands[1] = change_address (operands[1], QImode,
3988                                       XEXP (operands[1], 0));
3989     }
3990 }")
3991
3992 (define_insn ""
3993   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
3994         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
3995   "gpc_reg_operand (operands[0], QImode)
3996    || gpc_reg_operand (operands[1], QImode)"
3997   "@
3998    mr %0,%1
3999    lbz%U1%X1 %0,%1
4000    stb%U0%X0 %1,%0
4001    {lil|li} %0,%1
4002    mf%1 %0
4003    mt%0 %1
4004    mt%0 %1
4005    cror 0,0,0"
4006   [(set_attr "type" "*,load,*,*,*,*,mtjmpr,*")])
4007 \f
4008 ;; Here is how to move condition codes around.  When we store CC data in
4009 ;; an integer register or memory, we store just the high-order 4 bits.
4010 ;; This lets us not shift in the most common case of CR0.
4011 (define_expand "movcc"
4012   [(set (match_operand:CC 0 "nonimmediate_operand" "")
4013         (match_operand:CC 1 "nonimmediate_operand" ""))]
4014   ""
4015   "")
4016
4017 (define_insn ""
4018   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,y,r,r,r,r,m")
4019         (match_operand:CC 1 "nonimmediate_operand" "y,r,r,x,y,r,m,r"))]
4020   "register_operand (operands[0], CCmode)
4021    || register_operand (operands[1], CCmode)"
4022   "@
4023    mcrf %0,%1
4024    mtcrf 128,%1
4025    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
4026    mfcr %0
4027    mfcr %0\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
4028    mr %0,%1
4029    {l%U1%X1|lwz%U1%X1} %0,%1
4030    {st%U0%U1|stw%U0%U1} %1,%0"
4031   [(set_attr "type" "*,*,*,compare,*,*,load,*")
4032    (set_attr "length" "*,*,12,*,8,*,*,*")])
4033 \f
4034 ;; For floating-point, we normally deal with the floating-point registers
4035 ;; unless -msoft-float is used.  The sole exception is that parameter passing
4036 ;; can produce floating-point values in fixed-point registers.  Unless the
4037 ;; value is a simple constant or already in memory, we deal with this by
4038 ;; allocating memory and copying the value explicitly via that memory location.
4039 (define_expand "movsf"
4040   [(set (match_operand:SF 0 "nonimmediate_operand" "")
4041         (match_operand:SF 1 "any_operand" ""))]
4042   ""
4043   "
4044 {
4045   /* If we are called from reload, we might be getting a SUBREG of a hard
4046      reg.  So expand it.  */
4047   if (GET_CODE (operands[0]) == SUBREG
4048       && GET_CODE (SUBREG_REG (operands[0])) == REG
4049       && REGNO (SUBREG_REG (operands[0])) < FIRST_PSEUDO_REGISTER)
4050     operands[0] = alter_subreg (operands[0]);
4051   if (GET_CODE (operands[1]) == SUBREG
4052       && GET_CODE (SUBREG_REG (operands[1])) == REG
4053       && REGNO (SUBREG_REG (operands[1])) < FIRST_PSEUDO_REGISTER)
4054     operands[1] = alter_subreg (operands[1]);
4055
4056   if (TARGET_SOFT_FLOAT && GET_CODE (operands[0]) == MEM)
4057     operands[1] = force_reg (SFmode, operands[1]);
4058
4059   else if (TARGET_HARD_FLOAT)
4060     {
4061       if (GET_CODE (operands[1]) == REG && REGNO (operands[1]) < 32)
4062         {
4063           /* If this is a store to memory or another integer register do the
4064              move directly.  Otherwise store to a temporary stack slot and
4065              load from there into a floating point register.  */
4066
4067           if (GET_CODE (operands[0]) == MEM
4068               || (GET_CODE (operands[0]) == REG
4069                   && (REGNO (operands[0]) < 32
4070                       || (reload_in_progress
4071                           && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER))))
4072             {
4073               emit_move_insn (operand_subword (operands[0], 0, 0, SFmode),
4074                               operand_subword (operands[1], 0, 0, SFmode));
4075               DONE;
4076             }
4077           else
4078             {
4079               rtx stack_slot = assign_stack_temp (SFmode, 4, 0);
4080
4081               emit_move_insn (stack_slot, operands[1]);
4082               emit_move_insn (operands[0], stack_slot);
4083               DONE;
4084             }
4085         }
4086
4087       if (GET_CODE (operands[0]) == MEM)
4088         {
4089           /* If operands[1] is a register, it may have double-precision data
4090              in it, so truncate it to single precision.  We need not do
4091              this for POWERPC.  */
4092           if (! TARGET_POWERPC && TARGET_HARD_FLOAT
4093               && GET_CODE (operands[1]) == REG)
4094             {
4095               rtx newreg
4096                 = reload_in_progress ? operands[1] : gen_reg_rtx (SFmode);
4097               emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
4098               operands[1] = newreg;
4099             }
4100
4101           operands[1] = force_reg (SFmode, operands[1]);
4102         }
4103
4104       if (GET_CODE (operands[0]) == REG && REGNO (operands[0]) < 32)
4105         {
4106           if (GET_CODE (operands[1]) == MEM
4107 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && ! defined(REAL_IS_NOT_DOUBLE)
4108               || GET_CODE (operands[1]) == CONST_DOUBLE
4109 #endif
4110               || (GET_CODE (operands[1]) == REG
4111                   && (REGNO (operands[1]) < 32
4112                       || (reload_in_progress
4113                           && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER))))
4114             {
4115               emit_move_insn (operand_subword (operands[0], 0, 0, SFmode),
4116                               operand_subword (operands[1], 0, 0, SFmode));
4117               DONE;
4118             }
4119           else
4120             {
4121               rtx stack_slot = assign_stack_temp (SFmode, 4, 0);
4122
4123               emit_move_insn (stack_slot, operands[1]);
4124               emit_move_insn (operands[0], stack_slot);
4125               DONE;
4126             }
4127         }
4128     }
4129
4130   if (CONSTANT_P (operands[1]))
4131     {
4132       operands[1] = force_const_mem (SFmode, operands[1]);
4133       if (! memory_address_p (SFmode, XEXP (operands[1], 0))
4134           && ! reload_in_progress)
4135         operands[1] = change_address (operands[1], SFmode,
4136                                       XEXP (operands[1], 0));
4137     }
4138 }")
4139
4140 (define_split
4141   [(set (match_operand:SF 0 "gpc_reg_operand" "")
4142         (match_operand:SF 1 "easy_fp_constant" ""))]
4143   "reload_completed && REGNO (operands[0]) <= 31"
4144   [(set (match_dup 2) (match_dup 3))]
4145   "
4146 { operands[2] = operand_subword (operands[0], 0, 0, SFmode);
4147   operands[3] = operand_subword (operands[1], 0, 0, SFmode); }")
4148
4149 (define_insn ""
4150   [(set (match_operand:SF 0 "fp_reg_or_mem_operand" "=f,f,m")
4151         (match_operand:SF 1 "input_operand" "f,m,f"))]
4152   "(gpc_reg_operand (operands[0], SFmode)
4153    || gpc_reg_operand (operands[1], SFmode)) && TARGET_HARD_FLOAT"
4154   "@
4155    fmr %0,%1
4156    lfs%U1%X1 %0,%1
4157    stfs%U0%X0 %1,%0"
4158   [(set_attr "type" "fp,fpload,*")])
4159
4160 (define_insn ""
4161   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
4162         (match_operand:SF 1 "input_operand" "r,m,r,I,J,R"))]
4163   "(gpc_reg_operand (operands[0], SFmode)
4164    || gpc_reg_operand (operands[1], SFmode)) && TARGET_SOFT_FLOAT"
4165   "@
4166    mr %0,%1
4167    {l%U1%X1|lwz%U1%X1} %0,%1
4168    {st%U0%X0|stw%U0%X0} %1,%0
4169    {lil|li} %0,%1
4170    {liu|lis} %0,%u1
4171    {cal|la} %0,%1(%*)"
4172   [(set_attr "type" "*,load,*,*,*,*")])
4173
4174 \f
4175 (define_expand "movdf"
4176   [(set (match_operand:DF 0 "nonimmediate_operand" "")
4177         (match_operand:DF 1 "any_operand" ""))]
4178   ""
4179   "
4180 {
4181   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
4182     {
4183       emit_move_insn (operand_subword (operands[0], 1, 1, DFmode),
4184                       operand_subword_force (operands[1], 1, DFmode));
4185       emit_move_insn (operand_subword (operands[0], 0, 1, DFmode),
4186                       operand_subword_force (operands[1], 0, DFmode));
4187       DONE;
4188     }
4189
4190   if (GET_CODE (operands[0]) != REG)
4191     operands[1] = force_reg (DFmode, operands[1]);
4192
4193   if (CONSTANT_P (operands[1]) && ! easy_fp_constant (operands[1], DFmode))
4194     {
4195       operands[1] = force_const_mem (DFmode, operands[1]);
4196       if (! memory_address_p (DFmode, XEXP (operands[1], 0))
4197           && ! reload_in_progress)
4198         operands[1] = change_address (operands[1], DFmode,
4199                                       XEXP (operands[1], 0));
4200     }
4201 }")
4202
4203 (define_split
4204   [(set (match_operand:DF 0 "gpc_reg_operand" "")
4205         (match_operand:DF 1 "easy_fp_constant" ""))]
4206   "reload_completed && REGNO (operands[0]) <= 31"
4207   [(set (match_dup 2) (match_dup 3))
4208    (set (match_dup 4) (match_dup 5))]
4209   "
4210 { operands[2] = operand_subword (operands[0], 0, 0, DFmode);
4211   operands[3] = operand_subword (operands[1], 0, 0, DFmode);
4212   operands[4] = operand_subword (operands[0], 1, 0, DFmode);
4213   operands[5] = operand_subword (operands[1], 1, 0, DFmode); }")
4214
4215 ;; Don't have reload use general registers to load a constant.  First,
4216 ;; it might not work if the output operand has is the equivalent of
4217 ;; a non-offsettable memref, but also it is less efficient than loading
4218 ;; the constant into an FP register, since it will probably be used there.
4219 ;; The "??" is a kludge until we can figure out a more reasonable way
4220 ;; of handling these non-offsettable values.
4221 (define_insn ""
4222   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,o,!r,f,f,m")
4223         (match_operand:DF 1 "input_operand" "r,o,r,G,f,m,f"))]
4224   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT
4225    && (register_operand (operands[0], DFmode)
4226        || register_operand (operands[1], DFmode))"
4227   "*
4228 {
4229   switch (which_alternative)
4230     {
4231     case 0:
4232       /* We normally copy the low-numbered register first.  However, if
4233          the first register operand 0 is the same as the second register of
4234          operand 1, we must copy in the opposite order.  */
4235       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
4236         return \"mr %L0,%L1\;mr %0,%1\";
4237       else
4238         return \"mr %0,%1\;mr %L0,%L1\";
4239     case 1:
4240       /* If the low-address word is used in the address, we must load it
4241          last.  Otherwise, load it first.  Note that we cannot have
4242          auto-increment in that case since the address register is known to be
4243          dead.  */
4244       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
4245                              operands [1], 0))
4246         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
4247       else
4248         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
4249     case 2:
4250       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
4251     case 3:
4252       return \"#\";
4253     case 4:
4254       return \"fmr %0,%1\";
4255     case 5:
4256       return \"lfd%U1%X1 %0,%1\";
4257     case 6:
4258       return \"stfd%U0%X0 %1,%0\";
4259     }
4260 }"
4261   [(set_attr "type" "*,load,*,*,fp,fpload,*")
4262    (set_attr "length" "8,8,8,8,*,*,*")])
4263
4264 (define_insn ""
4265   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,o,r")
4266         (match_operand:DF 1 "input_operand" "r,o,r,G"))]
4267   "! TARGET_POWERPC64 && TARGET_SOFT_FLOAT
4268    && (register_operand (operands[0], DFmode)
4269        || register_operand (operands[1], DFmode))"
4270   "*
4271 {
4272   switch (which_alternative)
4273     {
4274     case 0:
4275       /* We normally copy the low-numbered register first.  However, if
4276          the first register operand 0 is the same as the second register of
4277          operand 1, we must copy in the opposite order.  */
4278       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
4279         return \"mr %L0,%L1\;mr %0,%1\";
4280       else
4281         return \"mr %0,%1\;mr %L0,%L1\";
4282     case 1:
4283       /* If the low-address word is used in the address, we must load it
4284          last.  Otherwise, load it first.  Note that we cannot have
4285          auto-increment in that case since the address register is known to be
4286          dead.  */
4287       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
4288                              operands [1], 0))
4289         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
4290       else
4291         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
4292     case 2:
4293       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
4294     case 3:
4295       return \"#\";
4296     }
4297 }"
4298   [(set_attr "type" "*,load,*,*")
4299    (set_attr "length" "8,8,8,8")])
4300
4301 (define_insn ""
4302   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,o,!r,f,f,m")
4303         (match_operand:DF 1 "input_operand" "r,o,r,G,f,m,f"))]
4304   "TARGET_POWERPC64 && TARGET_HARD_FLOAT
4305    && (register_operand (operands[0], DFmode)
4306        || register_operand (operands[1], DFmode))"
4307   "@
4308    mr %0,%1
4309    ld%U1%X1 %0,%1
4310    sd%U0%X0 %1,%0
4311    #
4312    fmr %0,%1
4313    lfd%U1%X1 %0,%1
4314    stfd%U0%X0 %1,%0"
4315   [(set_attr "type" "*,load,*,*,fp,fpload,*")])
4316
4317 (define_insn ""
4318   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,o,r")
4319         (match_operand:DF 1 "input_operand" "r,o,r,G"))]
4320   "TARGET_POWERPC64 && TARGET_SOFT_FLOAT
4321    && (register_operand (operands[0], DFmode)
4322        || register_operand (operands[1], DFmode))"
4323   "@
4324    mr %0,%1
4325    ld%U1%X1 %0,%1
4326    sd%U0%X0 %1,%0
4327    #"
4328   [(set_attr "type" "*,load,*,*")])
4329 \f
4330 ;; Next come the multi-word integer load and store and the load and store
4331 ;; multiple insns.
4332 (define_expand "movdi"
4333   [(set (match_operand:DI 0 "general_operand" "")
4334         (match_operand:DI 1 "general_operand" ""))]
4335   ""
4336   "
4337 {
4338   if (GET_CODE (operands[1]) == CONST_DOUBLE
4339       || GET_CODE (operands[1]) == CONST_INT)
4340     {
4341       emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
4342                       operand_subword (operands[1], 0, 0, DImode));
4343       emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
4344                       operand_subword (operands[1], 1, 0, DImode));
4345       DONE;
4346     }
4347
4348   if (GET_CODE (operands[0]) == MEM)
4349     operands[1] = force_reg (DImode, operands[1]);
4350
4351       /* Stores between FPR and any non-FPR registers must go through a
4352          temporary stack slot.  */
4353
4354   if (GET_CODE (operands[0]) == REG && GET_CODE (operands[1]) == REG
4355       && ((FP_REGNO_P (REGNO (operands[0]))
4356            && ! FP_REGNO_P (REGNO (operands[1])))
4357           || (FP_REGNO_P (REGNO (operands[1]))
4358               && ! FP_REGNO_P (REGNO (operands[0])))))
4359     {
4360       rtx stack_slot = assign_stack_temp (DImode, 8, 0);
4361
4362       emit_move_insn (stack_slot, operands[1]);
4363       emit_move_insn (operands[0], stack_slot);
4364       DONE;
4365     }
4366 }")
4367
4368 (define_insn ""
4369   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,f,f,m")
4370         (match_operand:DI 1 "input_operand" "r,m,r,f,m,f"))]
4371   "! TARGET_POWERPC64 && (gpc_reg_operand (operands[0], DImode)
4372    || gpc_reg_operand (operands[1], DImode))"
4373   "*
4374 {
4375   switch (which_alternative)
4376     {
4377     case 0:
4378       /* We normally copy the low-numbered register first.  However, if
4379          the first register operand 0 is the same as the second register of
4380          operand 1, we must copy in the opposite order.  */
4381       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
4382         return \"mr %L0,%L1\;mr %0,%1\";
4383       else
4384         return \"mr %0,%1\;mr %L0,%L1\";
4385     case 1:
4386       /* If the low-address word is used in the address, we must load it
4387          last.  Otherwise, load it first.  Note that we cannot have
4388          auto-increment in that case since the address register is known to be
4389          dead.  */
4390       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
4391                              operands [1], 0))
4392         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
4393       else
4394         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
4395     case 2:
4396       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
4397     case 3:
4398       return \"fmr %0,%1\";
4399     case 4:
4400       return \"lfd%U1%X1 %0,%1\";
4401     case 5:
4402       return \"stfd%U0%X0 %1,%0\";
4403     }
4404 }"
4405   [(set_attr "type" "*,load,*,fp,fpload,*")
4406    (set_attr "length" "8,8,8,*,*,*")])
4407
4408 (define_insn ""
4409   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,f,f,m,r,*h")
4410         (match_operand:DI 1 "input_operand" "r,m,r,I,J,R,f,m,f,*h,r"))]
4411   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], DImode)
4412    || gpc_reg_operand (operands[1], DImode))"
4413   "@
4414    mr %0,%1
4415    ld%U1%X1 %0,%1
4416    sd%U0%X0 %1,%0
4417    li %0,%1
4418    lis %0,%u1
4419    {cal|la} %0,%1(%*)
4420    fmr %0,%1
4421    lfd%U1%X1 %0,%1
4422    stfd%U0%X0 %1,%0
4423    mf%1 %0
4424    mt%0 %1"
4425   [(set_attr "type" "*,load,*,*,*,*,fp,fpload,*,*,mtjmpr")])
4426 \f
4427 ;; TImode is similar, except that we usually want to compute the address into
4428 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
4429 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
4430 (define_expand "movti"
4431   [(parallel [(set (match_operand:TI 0 "general_operand" "")
4432                    (match_operand:TI 1 "general_operand" ""))
4433               (clobber (scratch:SI))])]
4434   "TARGET_STRING || TARGET_POWERPC64"
4435   "
4436 {
4437   if (GET_CODE (operands[0]) == MEM)
4438     operands[1] = force_reg (TImode, operands[1]);
4439
4440   if (GET_CODE (operands[0]) == MEM
4441       && GET_CODE (XEXP (operands[0], 0)) != REG
4442       && ! reload_in_progress)
4443     operands[0] = change_address (operands[0], TImode,
4444                                   copy_addr_to_reg (XEXP (operands[0], 0)));
4445
4446   if (GET_CODE (operands[1]) == MEM
4447       && GET_CODE (XEXP (operands[1], 0)) != REG
4448       && ! reload_in_progress)
4449     operands[1] = change_address (operands[1], TImode,
4450                                   copy_addr_to_reg (XEXP (operands[1], 0)));
4451 }")
4452
4453 ;; We say that MQ is clobbered in the last alternative because the first
4454 ;; alternative would never get used otherwise since it would need a reload
4455 ;; while the 2nd alternative would not.  We put memory cases first so they
4456 ;; are preferred.  Otherwise, we'd try to reload the output instead of
4457 ;; giving the SCRATCH mq.
4458 (define_insn ""
4459   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
4460         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))
4461    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X"))]
4462   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
4463    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
4464   "*
4465 {
4466   switch (which_alternative)
4467     {
4468     default:
4469       abort ();
4470
4471     case 0:
4472       return \"{stsi|stswi} %1,%P0,16\";
4473
4474     case 1:
4475       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\;{st|stw} %Y1,%Y0\;{st|stw} %Z1,%Z0\";
4476
4477     case 2:
4478       /* Normally copy registers with lowest numbered register copied first.
4479          But copy in the other order if the first register of the output
4480          is the second, third, or fourth register in the input.  */
4481       if (REGNO (operands[0]) >= REGNO (operands[1]) + 1
4482           && REGNO (operands[0]) <= REGNO (operands[1]) + 3)
4483         return \"mr %Z0,%Z1\;mr %Y0,%Y1\;mr %L0,%L1\;mr %0,%1\";
4484       else
4485         return \"mr %0,%1\;mr %L0,%L1\;mr %Y0,%Y1\;mr %Z0,%Z1\";
4486     case 3:
4487       /* If the address is not used in the output, we can use lsi.  Otherwise,
4488          fall through to generating four loads.  */
4489       if (! reg_overlap_mentioned_p (operands[0], operands[1]))
4490         return \"{lsi|lswi} %0,%P1,16\";
4491       /* ... fall through ... */
4492     case 4:
4493       /* If the address register is the same as the register for the lowest-
4494          addressed word, load it last.  Similarly for the next two words.
4495          Otherwise load lowest address to highest.  */
4496       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
4497                              operands[1], 0))
4498         return \"{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %0,%1\";
4499       else if (refers_to_regno_p (REGNO (operands[0]) + 1,
4500                                   REGNO (operands[0]) + 2, operands[1], 0))
4501         return \"{l|lwz} %0,%1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %L0,%L1\";
4502       else if (refers_to_regno_p (REGNO (operands[0]) + 2,
4503                                   REGNO (operands[0]) + 3, operands[1], 0))
4504         return \"{l|lwz} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Z0,%Z1\;{l|lwz} %Y0,%Y1\";
4505       else
4506         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\";
4507     }
4508 }"
4509   [(set_attr "type" "*,load,load,*,*")
4510    (set_attr "length" "*,16,16,*,16")])
4511
4512 (define_insn ""
4513   [(set (match_operand:TI 0 "reg_or_mem_operand" "=m,????r,????r")
4514         (match_operand:TI 1 "reg_or_mem_operand" "r,r,m"))
4515    (clobber (match_scratch:SI 2 "=X,X,X"))]
4516   "TARGET_STRING && !TARGET_POWER && ! TARGET_POWERPC64
4517    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
4518   "*
4519 {
4520   switch (which_alternative)
4521     {
4522     default:
4523       abort ();
4524
4525     case 0:
4526       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\;{st|stw} %Y1,%Y0\;{st|stw} %Z1,%Z0\";
4527
4528     case 1:
4529       /* Normally copy registers with lowest numbered register copied first.
4530          But copy in the other order if the first register of the output
4531          is the second, third, or fourth register in the input.  */
4532       if (REGNO (operands[0]) >= REGNO (operands[1]) + 1
4533           && REGNO (operands[0]) <= REGNO (operands[1]) + 3)
4534         return \"mr %Z0,%Z1\;mr %Y0,%Y1\;mr %L0,%L1\;mr %0,%1\";
4535       else
4536         return \"mr %0,%1\;mr %L0,%L1\;mr %Y0,%Y1\;mr %Z0,%Z1\";
4537     case 2:
4538       /* If the address register is the same as the register for the lowest-
4539          addressed word, load it last.  Similarly for the next two words.
4540          Otherwise load lowest address to highest.  */
4541       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
4542                              operands[1], 0))
4543         return \"{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %0,%1\";
4544       else if (refers_to_regno_p (REGNO (operands[0]) + 1,
4545                                   REGNO (operands[0]) + 2, operands[1], 0))
4546         return \"{l|lwz} %0,%1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %L0,%L1\";
4547       else if (refers_to_regno_p (REGNO (operands[0]) + 2,
4548                                   REGNO (operands[0]) + 3, operands[1], 0))
4549         return \"{l|lwz} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Z0,%Z1\;{l|lwz} %Y0,%Y1\";
4550       else
4551         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\";
4552     }
4553 }"
4554   [(set_attr "type" "load,*,*")
4555    (set_attr "length" "16,16,16")])
4556
4557 (define_insn ""
4558   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,r,m")
4559         (match_operand:TI 1 "input_operand" "r,m,r"))]
4560   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
4561    || gpc_reg_operand (operands[1], TImode))"
4562   "*
4563 {
4564   switch (which_alternative)
4565     {
4566     case 0:
4567       /* We normally copy the low-numbered register first.  However, if
4568          the first register operand 0 is the same as the second register of
4569          operand 1, we must copy in the opposite order.  */
4570       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
4571         return \"mr %L0,%L1\;mr %0,%1\";
4572       else
4573         return \"mr %0,%1\;mr %L0,%L1\";
4574     case 1:
4575       /* If the low-address word is used in the address, we must load it
4576          last.  Otherwise, load it first.  Note that we cannot have
4577          auto-increment in that case since the address register is known to be
4578          dead.  */
4579       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
4580                              operands [1], 0))
4581         return \"ld %L0,%L1\;ld %0,%1\";
4582       else
4583         return \"ld%U1 %0,%1\;ld %L0,%L1\";
4584     case 2:
4585       return \"std%U0 %1,%0\;std %L1,%L0\";
4586     }
4587 }"
4588   [(set_attr "type" "*,load,*")
4589    (set_attr "length" "8,8,8")])
4590 \f
4591 (define_expand "load_multiple"
4592   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
4593                           (match_operand:SI 1 "" ""))
4594                      (use (match_operand:SI 2 "" ""))])]
4595   "TARGET_STRING"
4596   "
4597 {
4598   int regno;
4599   int count;
4600   rtx from;
4601   int i;
4602
4603   /* Support only loading a constant number of fixed-point registers from
4604      memory and only bother with this if more than two; the machine
4605      doesn't support more than eight.  */
4606   if (GET_CODE (operands[2]) != CONST_INT
4607       || INTVAL (operands[2]) <= 2
4608       || INTVAL (operands[2]) > 8
4609       || GET_CODE (operands[1]) != MEM
4610       || GET_CODE (operands[0]) != REG
4611       || REGNO (operands[0]) >= 32)
4612     FAIL;
4613
4614   count = INTVAL (operands[2]);
4615   regno = REGNO (operands[0]);
4616
4617   operands[3] = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (count));
4618   from = force_reg (SImode, XEXP (operands[1], 0));
4619
4620   for (i = 0; i < count; i++)
4621     XVECEXP (operands[3], 0, i)
4622       = gen_rtx (SET, VOIDmode, gen_rtx (REG, SImode, regno + i),
4623                  gen_rtx (MEM, SImode, plus_constant (from, i * 4)));
4624 }")
4625
4626 (define_insn ""
4627   [(match_parallel 0 "load_multiple_operation"
4628                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
4629                          (match_operand:SI 2 "indirect_operand" "Q"))])]
4630   "TARGET_STRING"
4631   "*
4632 {
4633   /* We have to handle the case where the pseudo used to contain the address
4634      is assigned to one of the output registers.  In that case, do the
4635      lsi, but then load the correct value.  This is a bit of a mess, but is
4636      the best we can do.
4637      We set the length attribute to the maximum possible size (8 bytes).  */
4638   static char result[100];
4639   char newload[40];
4640   int i;
4641
4642   strcpy (result, \"{lsi|lswi} %1,%P2,%N0\");
4643   for (i = 0; i < XVECLEN (operands[0], 0); i++)
4644     if (refers_to_regno_p (REGNO (operands[1]) + i,
4645                            REGNO (operands[1]) + i + 1, operands[2], 0))
4646       {
4647         sprintf (newload, \"\;{l|lwz} %d,%d(%d)\",
4648                  REGNO (operands[1]) + i,
4649                  i * 4, REGNO (XEXP (operands[2], 0)));
4650         strcat (result, newload);
4651       }
4652
4653   return result;
4654 }"
4655   [(set_attr "type" "load")
4656    (set_attr "length" "8")])
4657 \f
4658
4659 (define_expand "store_multiple"
4660   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
4661                           (match_operand:SI 1 "" ""))
4662                      (clobber (scratch:SI))
4663                      (use (match_operand:SI 2 "" ""))])]
4664   "TARGET_STRING"
4665   "
4666 {
4667   int regno;
4668   int count;
4669   rtx to;
4670   int i;
4671
4672   /* Support only storing a constant number of fixed-point registers to
4673      memory and only bother with this if more than two; the machine
4674      doesn't support more than eight.  */
4675   if (GET_CODE (operands[2]) != CONST_INT
4676       || INTVAL (operands[2]) <= 2
4677       || INTVAL (operands[2]) > 8
4678       || GET_CODE (operands[0]) != MEM
4679       || GET_CODE (operands[1]) != REG
4680       || REGNO (operands[1]) >= 32)
4681     FAIL;
4682
4683   count = INTVAL (operands[2]);
4684   regno = REGNO (operands[1]);
4685
4686   operands[3] = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (count + 1));
4687   to = force_reg (SImode, XEXP (operands[0], 0));
4688
4689   XVECEXP (operands[3], 0, 0)
4690     = gen_rtx (SET, VOIDmode, gen_rtx (MEM, SImode, to), operands[1]);
4691   XVECEXP (operands[3], 0, 1) = gen_rtx (CLOBBER, VOIDmode,
4692                                                   gen_rtx (SCRATCH, SImode));
4693
4694   for (i = 1; i < count; i++)
4695     XVECEXP (operands[3], 0, i + 1)
4696       = gen_rtx (SET, VOIDmode,
4697                  gen_rtx (MEM, SImode, plus_constant (to, i * 4)),
4698                  gen_rtx (REG, SImode, regno + i));
4699 }")
4700
4701 (define_insn ""
4702   [(match_parallel 0 "store_multiple_operation"
4703                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
4704                          (match_operand:SI 2 "gpc_reg_operand" "r"))
4705                     (clobber (match_scratch:SI 3 "=q"))])]
4706   "TARGET_STRING && TARGET_POWER"
4707   "{stsi|stswi} %2,%P1,%O0")
4708
4709 (define_insn ""
4710   [(match_parallel 0 "store_multiple_operation"
4711                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
4712                          (match_operand:SI 2 "gpc_reg_operand" "r"))
4713                     (clobber (match_scratch:SI 3 "X"))])]
4714   "TARGET_STRING && !TARGET_POWER"
4715   "{stsi|stswi} %2,%P1,%O0")
4716
4717 \f
4718 ;; String/block move insn.
4719 ;; Argument 0 is the destination
4720 ;; Argument 1 is the source
4721 ;; Argument 2 is the length
4722 ;; Argument 3 is the alignment
4723
4724 (define_expand "movstrsi"
4725   [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
4726                    (match_operand:BLK 1 "memory_operand" ""))
4727               (use (match_operand:SI 2 "general_operand" ""))
4728               (use (match_operand:SI 3 "immediate_operand" ""))])]
4729   ""
4730   "
4731 {
4732   if (expand_block_move (operands))
4733     DONE;
4734   else
4735     FAIL;
4736 }")
4737
4738 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
4739 ;; register allocator doesn't have a clue about allocating 8 word registers
4740 (define_expand "movstrsi_8reg"
4741   [(parallel [(set (mem:BLK (match_operand:SI 0 "register_operand" ""))
4742                    (mem:BLK (match_operand:SI 1 "register_operand" "")))
4743               (use (match_operand:SI 2 "immediate_operand" ""))
4744               (use (match_operand:SI 3 "immediate_operand" ""))
4745               (clobber (reg:SI  5))
4746               (clobber (reg:SI  6))
4747               (clobber (reg:SI  7))
4748               (clobber (reg:SI  8))
4749               (clobber (reg:SI  9))
4750               (clobber (reg:SI 10))
4751               (clobber (reg:SI 11))
4752               (clobber (reg:SI 12))
4753               (clobber (match_scratch:SI 4 ""))])]
4754   "TARGET_STRING"
4755   "")
4756
4757 (define_insn ""
4758   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
4759         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
4760    (use (match_operand:SI 2 "immediate_operand" "i"))
4761    (use (match_operand:SI 3 "immediate_operand" "i"))
4762    (clobber (match_operand:SI 4 "register_operand" "=r"))
4763    (clobber (reg:SI  6))
4764    (clobber (reg:SI  7))
4765    (clobber (reg:SI  8))
4766    (clobber (reg:SI  9))
4767    (clobber (reg:SI 10))
4768    (clobber (reg:SI 11))
4769    (clobber (reg:SI 12))
4770    (clobber (match_scratch:SI 5 "=q"))]
4771   "TARGET_STRING && TARGET_POWER
4772    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32) || INTVAL (operands[2]) == 0)
4773    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
4774    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
4775    && REGNO (operands[4]) == 5"
4776   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
4777   [(set_attr "length" "8")])
4778
4779 (define_insn ""
4780   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
4781         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
4782    (use (match_operand:SI 2 "immediate_operand" "i"))
4783    (use (match_operand:SI 3 "immediate_operand" "i"))
4784    (clobber (match_operand:SI 4 "register_operand" "=r"))
4785    (clobber (reg:SI  6))
4786    (clobber (reg:SI  7))
4787    (clobber (reg:SI  8))
4788    (clobber (reg:SI  9))
4789    (clobber (reg:SI 10))
4790    (clobber (reg:SI 11))
4791    (clobber (reg:SI 12))
4792    (clobber (match_scratch:SI 5 "X"))]
4793   "TARGET_STRING && !TARGET_POWER
4794    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32) || INTVAL (operands[2]) == 0)
4795    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
4796    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
4797    && REGNO (operands[4]) == 5"
4798   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
4799   [(set_attr "length" "8")])
4800
4801 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
4802 ;; register allocator doesn't have a clue about allocating 6 word registers
4803 (define_expand "movstrsi_6reg"
4804   [(parallel [(set (mem:BLK (match_operand:SI 0 "register_operand" ""))
4805                    (mem:BLK (match_operand:SI 1 "register_operand" "")))
4806               (use (match_operand:SI 2 "immediate_operand" ""))
4807               (use (match_operand:SI 3 "immediate_operand" ""))
4808               (clobber (reg:SI  7))
4809               (clobber (reg:SI  8))
4810               (clobber (reg:SI  9))
4811               (clobber (reg:SI 10))
4812               (clobber (reg:SI 11))
4813               (clobber (reg:SI 12))
4814               (clobber (match_scratch:SI 4 ""))])]
4815   "TARGET_STRING"
4816   "")
4817
4818 (define_insn ""
4819   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
4820         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
4821    (use (match_operand:SI 2 "immediate_operand" "i"))
4822    (use (match_operand:SI 3 "immediate_operand" "i"))
4823    (clobber (match_operand:SI 4 "register_operand" "=r"))
4824    (clobber (reg:SI  8))
4825    (clobber (reg:SI  9))
4826    (clobber (reg:SI 10))
4827    (clobber (reg:SI 11))
4828    (clobber (reg:SI 12))
4829    (clobber (match_scratch:SI 5 "=q"))]
4830   "TARGET_STRING && TARGET_POWER
4831    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
4832    && (REGNO (operands[0]) < 7 || REGNO (operands[0]) > 12)
4833    && (REGNO (operands[1]) < 7 || REGNO (operands[1]) > 12)
4834    && REGNO (operands[4]) == 7"
4835   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
4836   [(set_attr "length" "8")])
4837
4838 (define_insn ""
4839   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
4840         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
4841    (use (match_operand:SI 2 "immediate_operand" "i"))
4842    (use (match_operand:SI 3 "immediate_operand" "i"))
4843    (clobber (match_operand:SI 4 "register_operand" "=r"))
4844    (clobber (reg:SI  8))
4845    (clobber (reg:SI  9))
4846    (clobber (reg:SI 10))
4847    (clobber (reg:SI 11))
4848    (clobber (reg:SI 12))
4849    (clobber (match_scratch:SI 5 "X"))]
4850   "TARGET_STRING && !TARGET_POWER
4851    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
4852    && (REGNO (operands[0]) < 7 || REGNO (operands[0]) > 12)
4853    && (REGNO (operands[1]) < 7 || REGNO (operands[1]) > 12)
4854    && REGNO (operands[4]) == 7"
4855   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
4856   [(set_attr "length" "8")])
4857
4858 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill problems
4859 ;; with TImode
4860 (define_expand "movstrsi_4reg"
4861   [(parallel [(set (mem:BLK (match_operand:SI 0 "register_operand" ""))
4862                    (mem:BLK (match_operand:SI 1 "register_operand" "")))
4863               (use (match_operand:SI 2 "immediate_operand" ""))
4864               (use (match_operand:SI 3 "immediate_operand" ""))
4865               (clobber (reg:SI  9))
4866               (clobber (reg:SI 10))
4867               (clobber (reg:SI 11))
4868               (clobber (reg:SI 12))
4869               (clobber (match_scratch:SI 4 ""))])]
4870   "TARGET_STRING"
4871   "")
4872
4873 (define_insn ""
4874   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
4875         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
4876    (use (match_operand:SI 2 "immediate_operand" "i"))
4877    (use (match_operand:SI 3 "immediate_operand" "i"))
4878    (clobber (match_operand:SI 4 "register_operand" "=r"))
4879    (clobber (reg:SI 10))
4880    (clobber (reg:SI 11))
4881    (clobber (reg:SI 12))
4882    (clobber (match_scratch:SI 5 "=q"))]
4883   "TARGET_STRING && TARGET_POWER
4884    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
4885    && (REGNO (operands[0]) < 9 || REGNO (operands[0]) > 12)
4886    && (REGNO (operands[1]) < 9 || REGNO (operands[1]) > 12)
4887    && REGNO (operands[4]) == 9"
4888   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
4889   [(set_attr "length" "8")])
4890
4891 (define_insn ""
4892   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
4893         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
4894    (use (match_operand:SI 2 "immediate_operand" "i"))
4895    (use (match_operand:SI 3 "immediate_operand" "i"))
4896    (clobber (match_operand:SI 4 "register_operand" "=r"))
4897    (clobber (reg:SI 10))
4898    (clobber (reg:SI 11))
4899    (clobber (reg:SI 12))
4900    (clobber (match_scratch:SI 5 "X"))]
4901   "TARGET_STRING && !TARGET_POWER
4902    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
4903    && (REGNO (operands[0]) < 9 || REGNO (operands[0]) > 12)
4904    && (REGNO (operands[1]) < 9 || REGNO (operands[1]) > 12)
4905    && REGNO (operands[4]) == 9"
4906   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
4907   [(set_attr "length" "8")])
4908
4909 ;; Move up to 8 bytes at a time.
4910 (define_expand "movstrsi_2reg"
4911   [(parallel [(set (mem:BLK (match_operand:SI 0 "register_operand" ""))
4912                    (mem:BLK (match_operand:SI 1 "register_operand" "")))
4913               (use (match_operand:SI 2 "immediate_operand" ""))
4914               (use (match_operand:SI 3 "immediate_operand" ""))
4915               (clobber (match_scratch:DI 4 ""))
4916               (clobber (match_scratch:SI 5 ""))])]
4917   "TARGET_STRING && !TARGET_64BIT"
4918   "")
4919
4920 (define_insn ""
4921   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
4922         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
4923    (use (match_operand:SI 2 "immediate_operand" "i"))
4924    (use (match_operand:SI 3 "immediate_operand" "i"))
4925    (clobber (match_scratch:DI 4 "=&r"))
4926    (clobber (match_scratch:SI 5 "=q"))]
4927   "TARGET_STRING && TARGET_POWER && !TARGET_64BIT
4928    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
4929   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
4930   [(set_attr "length" "8")])
4931
4932 (define_insn ""
4933   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
4934         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
4935    (use (match_operand:SI 2 "immediate_operand" "i"))
4936    (use (match_operand:SI 3 "immediate_operand" "i"))
4937    (clobber (match_scratch:DI 4 "=&r"))
4938    (clobber (match_scratch:SI 5 "X"))]
4939   "TARGET_STRING && !TARGET_POWER && !TARGET_64BIT
4940    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
4941   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
4942   [(set_attr "length" "8")])
4943
4944 ;; Move up to 4 bytes at a time.
4945 (define_expand "movstrsi_1reg"
4946   [(parallel [(set (mem:BLK (match_operand:SI 0 "register_operand" ""))
4947                    (mem:BLK (match_operand:SI 1 "register_operand" "")))
4948               (use (match_operand:SI 2 "immediate_operand" ""))
4949               (use (match_operand:SI 3 "immediate_operand" ""))
4950               (clobber (match_scratch:SI 4 ""))
4951               (clobber (match_scratch:SI 5 ""))])]
4952   "TARGET_STRING"
4953   "")
4954
4955 (define_insn ""
4956   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
4957         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
4958    (use (match_operand:SI 2 "immediate_operand" "i"))
4959    (use (match_operand:SI 3 "immediate_operand" "i"))
4960    (clobber (match_scratch:SI 4 "=&r"))
4961    (clobber (match_scratch:SI 5 "=q"))]
4962   "TARGET_STRING && TARGET_POWER
4963    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
4964   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
4965   [(set_attr "length" "8")])
4966
4967 (define_insn ""
4968   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
4969         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
4970    (use (match_operand:SI 2 "immediate_operand" "i"))
4971    (use (match_operand:SI 3 "immediate_operand" "i"))
4972    (clobber (match_scratch:SI 4 "=&r"))
4973    (clobber (match_scratch:SI 5 "X"))]
4974   "TARGET_STRING && !TARGET_POWER
4975    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
4976   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
4977   [(set_attr "length" "8")])
4978
4979 \f
4980 ;; Define insns that do load or store with update.  Some of these we can
4981 ;; get by using pre-decrement or pre-increment, but the hardware can also
4982 ;; do cases where the increment is not the size of the object.
4983 ;;
4984 ;; In all these cases, we use operands 0 and 1 for the register being
4985 ;; incremented because those are the operands that local-alloc will
4986 ;; tie and these are the pair most likely to be tieable (and the ones
4987 ;; that will benefit the most).
4988
4989 (define_insn ""
4990   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
4991         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
4992                          (match_operand:DI 2 "reg_or_short_operand" "r,I"))))
4993    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
4994         (plus:DI (match_dup 1) (match_dup 2)))]
4995   "TARGET_POWERPC64"
4996   "@
4997    ldux %3,%0,%2
4998    ldu %3,%2(%0)"
4999   [(set_attr "type" "load")])
5000
5001 (define_insn ""
5002   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
5003         (sign_extend:DI
5004          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
5005                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
5006    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
5007         (plus:DI (match_dup 1) (match_dup 2)))]
5008   "TARGET_POWERPC64"
5009   "lwaux %3,%0,%2"
5010   [(set_attr "type" "load")])
5011
5012 (define_insn ""
5013   [(set (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
5014                          (match_operand:DI 2 "reg_or_short_operand" "r,I")))
5015         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
5016    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
5017         (plus:DI (match_dup 1) (match_dup 2)))]
5018   "TARGET_POWERPC64"
5019   "@
5020    stdux %3,%0,%2
5021    stdu %3,%2(%0)")
5022
5023 (define_insn ""
5024   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
5025         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
5026                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
5027    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
5028         (plus:SI (match_dup 1) (match_dup 2)))]
5029   ""
5030   "@
5031    {lux|lwzux} %3,%0,%2
5032    {lu|lwzu} %3,%2(%0)"
5033   [(set_attr "type" "load")])
5034
5035 (define_insn ""
5036   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
5037                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
5038         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
5039    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
5040         (plus:SI (match_dup 1) (match_dup 2)))]
5041   ""
5042   "@
5043    {stux|stwux} %3,%0,%2
5044    {stu|stwu} %3,%2(%0)")
5045
5046 (define_insn ""
5047   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
5048         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
5049                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
5050    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
5051         (plus:SI (match_dup 1) (match_dup 2)))]
5052   ""
5053   "@
5054    lhzux %3,%0,%2
5055    lhzu %3,%2(%0)"
5056   [(set_attr "type" "load")])
5057
5058 (define_insn ""
5059   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
5060         (zero_extend:SI
5061          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
5062                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
5063    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
5064         (plus:SI (match_dup 1) (match_dup 2)))]
5065   ""
5066   "@
5067    lhzux %3,%0,%2
5068    lhzu %3,%2(%0)"
5069   [(set_attr "type" "load")])
5070
5071 (define_insn ""
5072   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
5073         (sign_extend:SI
5074          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
5075                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
5076    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
5077         (plus:SI (match_dup 1) (match_dup 2)))]
5078   ""
5079   "@
5080    lhaux %3,%0,%2
5081    lhau %3,%2(%0)"
5082   [(set_attr "type" "load")])
5083
5084 (define_insn ""
5085   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
5086                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
5087         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
5088    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
5089         (plus:SI (match_dup 1) (match_dup 2)))]
5090   ""
5091   "@
5092    sthux %3,%0,%2
5093    sthu %3,%2(%0)")
5094
5095 (define_insn ""
5096   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
5097         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
5098                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
5099    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
5100         (plus:SI (match_dup 1) (match_dup 2)))]
5101   ""
5102   "@
5103    lbzux %3,%0,%2
5104    lbzu %3,%2(%0)"
5105   [(set_attr "type" "load")])
5106
5107 (define_insn ""
5108   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
5109         (zero_extend:SI
5110          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
5111                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
5112    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
5113         (plus:SI (match_dup 1) (match_dup 2)))]
5114   ""
5115   "@
5116    lbzux %3,%0,%2
5117    lbzu %3,%2(%0)"
5118   [(set_attr "type" "load")])
5119
5120 (define_insn ""
5121   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
5122                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
5123         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
5124    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
5125         (plus:SI (match_dup 1) (match_dup 2)))]
5126   ""
5127   "@
5128    stbux %3,%0,%2
5129    stbu %3,%2(%0)")
5130
5131 (define_insn ""
5132   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
5133         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
5134                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
5135    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
5136         (plus:SI (match_dup 1) (match_dup 2)))]
5137   "TARGET_HARD_FLOAT"
5138   "@
5139    lfsux %3,%0,%2
5140    lfsu %3,%2(%0)"
5141   [(set_attr "type" "fpload")])
5142
5143 (define_insn ""
5144   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
5145                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
5146         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
5147    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
5148         (plus:SI (match_dup 1) (match_dup 2)))]
5149   "TARGET_HARD_FLOAT"
5150   "@
5151    stfsux %3,%0,%2
5152    stfsu %3,%2(%0)")
5153
5154 (define_insn ""
5155   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
5156         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
5157                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
5158    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
5159         (plus:SI (match_dup 1) (match_dup 2)))]
5160   "TARGET_HARD_FLOAT"
5161   "@
5162    lfdux %3,%0,%2
5163    lfdu %3,%2(%0)"
5164   [(set_attr "type" "fpload")])
5165
5166 (define_insn ""
5167   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
5168                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
5169         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
5170    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
5171         (plus:SI (match_dup 1) (match_dup 2)))]
5172   "TARGET_HARD_FLOAT"
5173   "@
5174    stfdux %3,%0,%2
5175    stfdu %3,%2(%0)")
5176
5177 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
5178
5179 (define_peephole
5180   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5181         (match_operand:DF 1 "memory_operand" ""))
5182    (set (match_operand:DF 2 "gpc_reg_operand" "=f")
5183         (match_operand:DF 3 "memory_operand" ""))]
5184   "TARGET_POWER2
5185    && TARGET_HARD_FLOAT
5186    && registers_ok_for_quad_peep (operands[0], operands[2])
5187    && ! MEM_VOLATILE_P (operands[1]) && ! MEM_VOLATILE_P (operands[3])
5188    && addrs_ok_for_quad_peep (XEXP (operands[1], 0), XEXP (operands[3], 0))"
5189   "lfq%U1%X1 %0,%1")
5190
5191 (define_peephole
5192   [(set (match_operand:DF 0 "memory_operand" "")
5193         (match_operand:DF 1 "gpc_reg_operand" "f"))
5194    (set (match_operand:DF 2 "memory_operand" "")
5195         (match_operand:DF 3 "gpc_reg_operand" "f"))]
5196   "TARGET_POWER2
5197    && TARGET_HARD_FLOAT
5198    && registers_ok_for_quad_peep (operands[1], operands[3])
5199    && ! MEM_VOLATILE_P (operands[0]) && ! MEM_VOLATILE_P (operands[2])
5200    && addrs_ok_for_quad_peep (XEXP (operands[0], 0), XEXP (operands[2], 0))"
5201   "stfq%U0%X0 %1,%0")
5202 \f
5203 ;; Next come insns related to the calling sequence.
5204 ;;
5205 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
5206 ;; We move the back-chain and decrement the stack pointer.
5207
5208 (define_expand "allocate_stack"
5209   [(set (reg:SI 1)
5210         (minus:SI (reg:SI 1) (match_operand:SI 0 "reg_or_short_operand" "")))]
5211   ""
5212   "
5213 { rtx chain = gen_reg_rtx (SImode);
5214   rtx stack_bot = gen_rtx (MEM, Pmode, stack_pointer_rtx);
5215
5216   emit_move_insn (chain, stack_bot);
5217   emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, operands[0]));
5218   emit_move_insn (stack_bot, chain);
5219   DONE;
5220 }")
5221
5222 ;; These patterns say how to save and restore the stack pointer.  We need not
5223 ;; save the stack pointer at function level since we are careful to
5224 ;; preserve the backchain.  At block level, we have to restore the backchain
5225 ;; when we restore the stack pointer.
5226 ;;
5227 ;; For nonlocal gotos, we must save both the stack pointer and its
5228 ;; backchain and restore both.  Note that in the nonlocal case, the
5229 ;; save area is a memory location.
5230
5231 (define_expand "save_stack_function"
5232   [(use (const_int 0))]
5233   ""
5234   "")
5235
5236 (define_expand "restore_stack_function"
5237   [(use (const_int 0))]
5238   ""
5239   "")
5240
5241 (define_expand "restore_stack_block"
5242   [(set (match_dup 2) (mem:SI (match_operand:SI 0 "register_operand" "")))
5243    (set (match_dup 0) (match_operand:SI 1 "register_operand" ""))
5244    (set (mem:SI (match_dup 0)) (match_dup 2))]
5245   ""
5246   "
5247 { operands[2] = gen_reg_rtx (SImode); }")
5248
5249 (define_expand "save_stack_nonlocal"
5250   [(match_operand:DI 0 "memory_operand" "")
5251    (match_operand:SI 1 "register_operand" "")]
5252   ""
5253   "
5254 {
5255   rtx temp = gen_reg_rtx (SImode);
5256
5257   /* Copy the backchain to the first word, sp to the second.  */
5258   emit_move_insn (temp, gen_rtx (MEM, SImode, operands[1]));
5259   emit_move_insn (operand_subword (operands[0], 0, 0, DImode), temp);
5260   emit_move_insn (operand_subword (operands[0], 1, 0, DImode), operands[1]);
5261   DONE;
5262 }")
5263
5264 (define_expand "restore_stack_nonlocal"
5265   [(match_operand:SI 0 "register_operand" "")
5266    (match_operand:DI 1 "memory_operand" "")]
5267   ""
5268   "
5269 {
5270   rtx temp = gen_reg_rtx (SImode);
5271
5272   /* Restore the backchain from the first word, sp from the second.  */
5273   emit_move_insn (temp, operand_subword (operands[1], 0, 0, DImode));
5274   emit_move_insn (operands[0], operand_subword (operands[1], 1, 0, DImode));
5275   emit_move_insn (gen_rtx (MEM, SImode, operands[0]), temp);
5276   DONE;
5277 }")
5278 \f
5279 ;; A function pointer is a pointer to a data area whose first word contains
5280 ;; the actual address of the function, whose second word contains a pointer
5281 ;; to its TOC, and whose third word contains a value to place in the static
5282 ;; chain register (r11).  Note that if we load the static chain, our
5283 ;; "trampoline" need not have any executable code.
5284 ;;
5285 ;; operands[0] is an SImode pseudo in which we place the address of the
5286 ;;             function.
5287 ;; operands[1] is the address of data area of the function to call
5288
5289 (define_expand "call_via_ptr"
5290   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5291         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
5292    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
5293         (reg:SI 2))
5294    (set (reg:SI 2)
5295         (mem:SI (plus:SI (match_dup 1)
5296                          (const_int 4))))
5297    (set (reg:SI 11)
5298         (mem:SI (plus:SI (match_dup 1)
5299                          (const_int 8))))
5300    (use (reg:SI 2))
5301    (use (reg:SI 11))]
5302   ""
5303   "")
5304
5305 (define_expand "call"
5306   [(parallel [(call (mem:SI (match_operand:SI 0 "address_operand" ""))
5307                     (match_operand 1 "" ""))
5308               (clobber (scratch:SI))])]
5309   ""
5310   "
5311 {
5312   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
5313     abort ();
5314
5315   operands[0] = XEXP (operands[0], 0);
5316   if (GET_CODE (operands[0]) != SYMBOL_REF)
5317     {
5318 #ifndef USING_SVR4_H
5319       /* AIX function pointers are really pointers to a three word area */
5320       rtx temp = gen_reg_rtx (SImode);
5321
5322       emit_insn (gen_call_via_ptr (temp, force_reg (SImode, operands[0])));
5323       operands[0] = temp;
5324 #endif  /* !USING_SVR4_H */
5325     }
5326 }")
5327
5328 (define_expand "call_value"
5329   [(parallel [(set (match_operand 0 "" "")
5330                    (call (mem:SI (match_operand:SI 1 "address_operand" ""))
5331                          (match_operand 2 "" "")))
5332               (clobber (scratch:SI))])]
5333   ""
5334   "
5335 {
5336   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
5337     abort ();
5338
5339   operands[1] = XEXP (operands[1], 0);
5340   if (GET_CODE (operands[1]) != SYMBOL_REF)
5341     {
5342 #ifndef USING_SVR4_H
5343       /* AIX function pointers are really pointers to a three word area */
5344       rtx temp = gen_reg_rtx (SImode);
5345
5346       emit_insn (gen_call_via_ptr (temp, force_reg (SImode, operands[1])));
5347       operands[1] = temp;
5348 #endif  /* !USING_SVR4_H */
5349     }
5350 }")
5351
5352 ;; Call to function in current module.  No TOC pointer reload needed.
5353
5354 (define_insn ""
5355   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s"))
5356          (match_operand 1 "" "g"))
5357    (clobber (match_scratch:SI 2 "=l"))]
5358   ""
5359   "bl %z0")
5360
5361 ;; Call to function which may be in another module.  Restore the TOC
5362 ;; pointer (r2) after the call unless this is System V.
5363
5364 (define_insn ""
5365   [(call (mem:SI (match_operand:SI 0 "call_operand" "l,s"))
5366          (match_operand 1 "" "fg,fg"))
5367    (clobber (match_scratch:SI 2 "=l,l"))]
5368   ""
5369   "*
5370 {
5371 #ifndef USING_SVR4_H
5372   if (GET_CODE (operands[0]) == REG)
5373     return \"{brl|blrl}\;{l|lwz} 2,20(1)\";
5374
5375   return \"bl %z0\;%.\";
5376
5377 #else
5378   if (GET_CODE (operands[0]) == REG)
5379     return \"{brl|blrl}\";
5380
5381   return \"bl %z0\";
5382 #endif
5383 }"
5384   [(set_attr "length" "8")])
5385
5386 (define_insn ""
5387   [(set (match_operand 0 "" "=fg")
5388         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s"))
5389               (match_operand 2 "" "g")))
5390    (clobber (match_scratch:SI 3 "=l"))]
5391   ""
5392   "bl %z1")
5393
5394 (define_insn ""
5395   [(set (match_operand 0 "" "=fg,fg")
5396         (call (mem:SI (match_operand:SI 1 "call_operand" "l,s"))
5397               (match_operand 2 "" "fg,fg")))
5398    (clobber (match_scratch:SI 3 "=l,l"))]
5399   ""
5400   "*
5401 {
5402 #ifndef USING_SVR4_H
5403   if (GET_CODE (operands[1]) == REG)
5404     return \"{brl|blrl}\;{l|lwz} 2,20(1)\";
5405
5406   return \"bl %z1\;%.\";
5407
5408 #else
5409   if (GET_CODE (operands[1]) == REG)
5410     return \"{brl|blrl}\";
5411
5412   return \"bl %z1\";
5413 #endif
5414 }"
5415   [(set_attr "length" "8")])
5416
5417 ;; Call subroutine returning any type.
5418
5419 (define_expand "untyped_call"
5420   [(parallel [(call (match_operand 0 "" "")
5421                     (const_int 0))
5422               (match_operand 1 "" "")
5423               (match_operand 2 "" "")])]
5424   ""
5425   "
5426 {
5427   int i;
5428
5429   emit_call_insn (gen_call (operands[0], const0_rtx, NULL, const0_rtx));
5430
5431   for (i = 0; i < XVECLEN (operands[2], 0); i++)
5432     {
5433       rtx set = XVECEXP (operands[2], 0, i);
5434       emit_move_insn (SET_DEST (set), SET_SRC (set));
5435     }
5436
5437   /* The optimizer does not know that the call sets the function value
5438      registers we stored in the result block.  We avoid problems by
5439      claiming that all hard registers are used and clobbered at this
5440      point.  */
5441   emit_insn (gen_blockage ());
5442
5443   DONE;
5444 }")
5445
5446 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
5447 ;; all of memory.  This blocks insns from being moved across this point.
5448
5449 (define_insn "blockage"
5450   [(unspec_volatile [(const_int 0)] 0)]
5451   ""
5452   "")
5453 \f
5454 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
5455 ;; signed & unsigned, and one type of branch.
5456 ;;
5457 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
5458 ;; insns, and branches.  We store the operands of compares until we see
5459 ;; how it is used.
5460 (define_expand "cmpsi"
5461   [(set (cc0)
5462         (compare (match_operand:SI 0 "gpc_reg_operand" "")
5463                  (match_operand:SI 1 "reg_or_short_operand" "")))]
5464   ""
5465   "
5466 {
5467   /* Take care of the possibility that operands[1] might be negative but
5468      this might be a logical operation.  That insn doesn't exist.  */
5469   if (GET_CODE (operands[1]) == CONST_INT
5470       && INTVAL (operands[1]) < 0)
5471     operands[1] = force_reg (SImode, operands[1]);
5472
5473   rs6000_compare_op0 = operands[0];
5474   rs6000_compare_op1 = operands[1];
5475   rs6000_compare_fp_p = 0;
5476   DONE;
5477 }")
5478
5479 (define_expand "cmpsf"
5480   [(set (cc0) (compare (match_operand:SF 0 "gpc_reg_operand" "")
5481                        (match_operand:SF 1 "gpc_reg_operand" "")))]
5482   "TARGET_HARD_FLOAT"
5483   "
5484 {
5485   rs6000_compare_op0 = operands[0];
5486   rs6000_compare_op1 = operands[1];
5487   rs6000_compare_fp_p = 1;
5488   DONE;
5489 }")
5490
5491 (define_expand "cmpdf"
5492   [(set (cc0) (compare (match_operand:DF 0 "gpc_reg_operand" "")
5493                        (match_operand:DF 1 "gpc_reg_operand" "")))]
5494   "TARGET_HARD_FLOAT"
5495   "
5496 {
5497   rs6000_compare_op0 = operands[0];
5498   rs6000_compare_op1 = operands[1];
5499   rs6000_compare_fp_p = 1;
5500   DONE;
5501 }")
5502
5503 (define_expand "beq"
5504   [(set (match_dup 2) (match_dup 1))
5505    (set (pc)
5506         (if_then_else (eq (match_dup 2)
5507                           (const_int 0))
5508                       (label_ref (match_operand 0 "" ""))
5509                       (pc)))]
5510   ""
5511   "
5512 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5513   operands[1] = gen_rtx (COMPARE, mode,
5514                          rs6000_compare_op0, rs6000_compare_op1);
5515   operands[2] = gen_reg_rtx (mode);
5516 }")
5517
5518 (define_expand "bne"
5519   [(set (match_dup 2) (match_dup 1))
5520    (set (pc)
5521         (if_then_else (ne (match_dup 2)
5522                           (const_int 0))
5523                       (label_ref (match_operand 0 "" ""))
5524                       (pc)))]
5525   ""
5526   "
5527 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5528   operands[1] = gen_rtx (COMPARE, mode,
5529                          rs6000_compare_op0, rs6000_compare_op1);
5530   operands[2] = gen_reg_rtx (mode);
5531 }")
5532
5533 (define_expand "blt"
5534   [(set (match_dup 2) (match_dup 1))
5535    (set (pc)
5536         (if_then_else (lt (match_dup 2)
5537                           (const_int 0))
5538                       (label_ref (match_operand 0 "" ""))
5539                       (pc)))]
5540   ""
5541   "
5542 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5543   operands[1] = gen_rtx (COMPARE, mode,
5544                          rs6000_compare_op0, rs6000_compare_op1);
5545   operands[2] = gen_reg_rtx (mode);
5546 }")
5547
5548 (define_expand "bgt"
5549   [(set (match_dup 2) (match_dup 1))
5550    (set (pc)
5551         (if_then_else (gt (match_dup 2)
5552                           (const_int 0))
5553                       (label_ref (match_operand 0 "" ""))
5554                       (pc)))]
5555   ""
5556   "
5557 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5558   operands[1] = gen_rtx (COMPARE, mode,
5559                          rs6000_compare_op0, rs6000_compare_op1);
5560   operands[2] = gen_reg_rtx (mode);
5561 }")
5562
5563 (define_expand "ble"
5564   [(set (match_dup 2) (match_dup 1))
5565    (set (pc)
5566         (if_then_else (le (match_dup 2)
5567                           (const_int 0))
5568                       (label_ref (match_operand 0 "" ""))
5569                       (pc)))]
5570   ""
5571   "
5572 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5573   operands[1] = gen_rtx (COMPARE, mode,
5574                          rs6000_compare_op0, rs6000_compare_op1);
5575   operands[2] = gen_reg_rtx (mode);
5576 }")
5577
5578 (define_expand "bge"
5579   [(set (match_dup 2) (match_dup 1))
5580    (set (pc)
5581         (if_then_else (ge (match_dup 2)
5582                           (const_int 0))
5583                       (label_ref (match_operand 0 "" ""))
5584                       (pc)))]
5585   ""
5586   "
5587 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5588   operands[1] = gen_rtx (COMPARE, mode,
5589                          rs6000_compare_op0, rs6000_compare_op1);
5590   operands[2] = gen_reg_rtx (mode);
5591 }")
5592
5593 (define_expand "bgtu"
5594   [(set (match_dup 2) (match_dup 1))
5595    (set (pc)
5596         (if_then_else (gtu (match_dup 2)
5597                            (const_int 0))
5598                       (label_ref (match_operand 0 "" ""))
5599                       (pc)))]
5600   ""
5601   "
5602 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5603                          rs6000_compare_op0, rs6000_compare_op1);
5604   operands[2] = gen_reg_rtx (CCUNSmode);
5605 }")
5606
5607 (define_expand "bltu"
5608   [(set (match_dup 2) (match_dup 1))
5609    (set (pc)
5610         (if_then_else (ltu (match_dup 2)
5611                            (const_int 0))
5612                       (label_ref (match_operand 0 "" ""))
5613                       (pc)))]
5614   ""
5615   "
5616 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5617                          rs6000_compare_op0, rs6000_compare_op1);
5618   operands[2] = gen_reg_rtx (CCUNSmode);
5619 }")
5620
5621 (define_expand "bgeu"
5622   [(set (match_dup 2) (match_dup 1))
5623    (set (pc)
5624         (if_then_else (geu (match_dup 2)
5625                            (const_int 0))
5626                       (label_ref (match_operand 0 "" ""))
5627                       (pc)))]
5628   ""
5629   "
5630 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5631                          rs6000_compare_op0, rs6000_compare_op1);
5632   operands[2] = gen_reg_rtx (CCUNSmode);
5633 }")
5634
5635 (define_expand "bleu"
5636   [(set (match_dup 2) (match_dup 1))
5637    (set (pc)
5638         (if_then_else (leu (match_dup 2)
5639                            (const_int 0))
5640                       (label_ref (match_operand 0 "" ""))
5641                       (pc)))]
5642   ""
5643   "
5644 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5645                          rs6000_compare_op0, rs6000_compare_op1);
5646   operands[2] = gen_reg_rtx (CCUNSmode);
5647 }")
5648
5649 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
5650 ;; For SEQ, likewise, except that comparisons with zero should be done
5651 ;; with an scc insns.  However, due to the order that combine see the
5652 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
5653 ;; the cases we don't want to handle.
5654 (define_expand "seq"
5655   [(set (match_dup 2) (match_dup 1))
5656    (set (match_operand:SI 0 "gpc_reg_operand" "")
5657         (eq:SI (match_dup 2) (const_int 0)))]
5658   ""
5659   "
5660 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5661   operands[1] = gen_rtx (COMPARE, mode,
5662                          rs6000_compare_op0, rs6000_compare_op1);
5663   operands[2] = gen_reg_rtx (mode);
5664 }")
5665
5666 (define_expand "sne"
5667   [(set (match_dup 2) (match_dup 1))
5668    (set (match_operand:SI 0 "gpc_reg_operand" "")
5669         (ne:SI (match_dup 2) (const_int 0)))]
5670   ""
5671   "
5672 { if (! rs6000_compare_fp_p)
5673     FAIL;
5674
5675   operands[1] = gen_rtx (COMPARE, CCFPmode,
5676                          rs6000_compare_op0, rs6000_compare_op1);
5677   operands[2] = gen_reg_rtx (CCFPmode);
5678 }")
5679
5680 ;; A > 0 is best done using the portable sequence, so fail in that case.
5681 (define_expand "sgt"
5682   [(set (match_dup 2) (match_dup 1))
5683    (set (match_operand:SI 0 "gpc_reg_operand" "")
5684         (gt:SI (match_dup 2) (const_int 0)))]
5685   ""
5686   "
5687 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5688
5689   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
5690     FAIL;
5691
5692   operands[1] = gen_rtx (COMPARE, mode,
5693                          rs6000_compare_op0, rs6000_compare_op1);
5694   operands[2] = gen_reg_rtx (mode);
5695 }")
5696
5697 ;; A < 0 is best done in the portable way for A an integer.
5698 (define_expand "slt"
5699   [(set (match_dup 2) (match_dup 1))
5700    (set (match_operand:SI 0 "gpc_reg_operand" "")
5701         (lt:SI (match_dup 2) (const_int 0)))]
5702   ""
5703   "
5704 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5705
5706   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
5707     FAIL;
5708
5709   operands[1] = gen_rtx (COMPARE, mode,
5710                          rs6000_compare_op0, rs6000_compare_op1);
5711   operands[2] = gen_reg_rtx (mode);
5712 }")
5713
5714 (define_expand "sge"
5715   [(set (match_dup 2) (match_dup 1))
5716    (set (match_operand:SI 0 "gpc_reg_operand" "")
5717         (ge:SI (match_dup 2) (const_int 0)))]
5718   ""
5719   "
5720 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5721   operands[1] = gen_rtx (COMPARE, mode,
5722                          rs6000_compare_op0, rs6000_compare_op1);
5723   operands[2] = gen_reg_rtx (mode);
5724 }")
5725
5726 ;; A <= 0 is best done the portable way for A an integer.
5727 (define_expand "sle"
5728   [(set (match_dup 2) (match_dup 1))
5729    (set (match_operand:SI 0 "gpc_reg_operand" "")
5730         (le:SI (match_dup 2) (const_int 0)))]
5731   ""
5732   "
5733 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
5734
5735   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
5736     FAIL;
5737
5738   operands[1] = gen_rtx (COMPARE, mode,
5739                          rs6000_compare_op0, rs6000_compare_op1);
5740   operands[2] = gen_reg_rtx (mode);
5741 }")
5742
5743 (define_expand "sgtu"
5744   [(set (match_dup 2) (match_dup 1))
5745    (set (match_operand:SI 0 "gpc_reg_operand" "")
5746         (gtu:SI (match_dup 2) (const_int 0)))]
5747   ""
5748   "
5749 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5750                          rs6000_compare_op0, rs6000_compare_op1);
5751   operands[2] = gen_reg_rtx (CCUNSmode);
5752 }")
5753
5754 (define_expand "sltu"
5755   [(set (match_dup 2) (match_dup 1))
5756    (set (match_operand:SI 0 "gpc_reg_operand" "")
5757         (ltu:SI (match_dup 2) (const_int 0)))]
5758   ""
5759   "
5760 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5761                          rs6000_compare_op0, rs6000_compare_op1);
5762   operands[2] = gen_reg_rtx (CCUNSmode);
5763 }")
5764
5765 (define_expand "sgeu"
5766   [(set (match_dup 2) (match_dup 1))
5767    (set (match_operand:SI 0 "gpc_reg_operand" "")
5768         (geu:SI (match_dup 2) (const_int 0)))]
5769   ""
5770   "
5771 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5772                          rs6000_compare_op0, rs6000_compare_op1);
5773   operands[2] = gen_reg_rtx (CCUNSmode);
5774 }")
5775
5776 (define_expand "sleu"
5777   [(set (match_dup 2) (match_dup 1))
5778    (set (match_operand:SI 0 "gpc_reg_operand" "")
5779         (leu:SI (match_dup 2) (const_int 0)))]
5780   ""
5781   "
5782 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
5783                          rs6000_compare_op0, rs6000_compare_op1);
5784   operands[2] = gen_reg_rtx (CCUNSmode);
5785 }")
5786 \f
5787 ;; Here are the actual compare insns.
5788 (define_insn ""
5789   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
5790         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
5791                     (match_operand:SI 2 "reg_or_short_operand" "rI")))]
5792   ""
5793   "{cmp%I2|cmpw%I2} %0,%1,%2"
5794   [(set_attr "type" "compare")])
5795
5796 ;; If we are comparing a register for equality with a large constant,
5797 ;; we can do this with an XOR followed by a compare.  But we need a scratch
5798 ;; register for the result of the XOR.
5799
5800 (define_split
5801   [(set (match_operand:CC 0 "cc_reg_operand" "")
5802         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
5803                     (match_operand:SI 2 "non_short_cint_operand" "")))
5804    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
5805   "find_single_use (operands[0], insn, 0)
5806    && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
5807        || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
5808   [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
5809    (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
5810   "
5811 {
5812   /* Get the constant we are comparing against, C,  and see what it looks like
5813      sign-extended to 16 bits.  Then see what constant could be XOR'ed
5814      with C to get the sign-extended value.  */
5815
5816   int c = INTVAL (operands[2]);
5817   int sextc = (c << 16) >> 16;
5818   int xorv = c ^ sextc;
5819
5820   operands[4] = gen_rtx (CONST_INT, VOIDmode, xorv);
5821   operands[5] = gen_rtx (CONST_INT, VOIDmode, sextc);
5822 }")
5823
5824 (define_insn ""
5825   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
5826         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
5827                        (match_operand:SI 2 "reg_or_u_short_operand" "rI")))]
5828   ""
5829   "{cmpl%I2|cmplw%I2} %0,%1,%W2"
5830   [(set_attr "type" "compare")])
5831
5832 ;; The following two insns don't exist as single insns, but if we provide
5833 ;; them, we can swap an add and compare, which will enable us to overlap more
5834 ;; of the required delay between a compare and branch.  We generate code for
5835 ;; them by splitting.
5836
5837 (define_insn ""
5838   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
5839         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
5840                     (match_operand:SI 2 "short_cint_operand" "i")))
5841    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
5842         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
5843   ""
5844   "#"
5845   [(set_attr "length" "8")])
5846
5847 (define_insn ""
5848   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
5849         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
5850                        (match_operand:SI 2 "u_short_cint_operand" "i")))
5851    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
5852         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
5853   ""
5854   "#"
5855   [(set_attr "length" "8")])
5856
5857 (define_split
5858   [(set (match_operand:CC 3 "cc_reg_operand" "")
5859         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
5860                     (match_operand:SI 2 "short_cint_operand" "")))
5861    (set (match_operand:SI 0 "gpc_reg_operand" "")
5862         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
5863   ""
5864   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
5865    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
5866
5867 (define_split
5868   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
5869         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
5870                        (match_operand:SI 2 "u_short_cint_operand" "")))
5871    (set (match_operand:SI 0 "gpc_reg_operand" "")
5872         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
5873   ""
5874   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
5875    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
5876
5877 (define_insn ""
5878   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
5879         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
5880                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
5881   "TARGET_HARD_FLOAT"
5882   "fcmpu %0,%1,%2"
5883   [(set_attr "type" "fpcompare")])
5884
5885 (define_insn ""
5886   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
5887         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
5888                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
5889   "TARGET_HARD_FLOAT"
5890   "fcmpu %0,%1,%2"
5891   [(set_attr "type" "fpcompare")])
5892 \f
5893 ;; Now we have the scc insns.  We can do some combinations because of the
5894 ;; way the machine works.
5895 ;;
5896 ;; Note that this is probably faster if we can put an insn between the
5897 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
5898 ;; cases the insns below which don't use an intermediate CR field will
5899 ;; be used instead.
5900 (define_insn ""
5901   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5902         (match_operator:SI 1 "scc_comparison_operator"
5903                            [(match_operand 2 "cc_reg_operand" "y")
5904                             (const_int 0)]))]
5905   ""
5906   "%D1mfcr %0\;{rlinm|rlwinm} %0,%0,%J1,1"
5907   [(set_attr "length" "12")])
5908
5909 (define_insn ""
5910   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
5911         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
5912                                        [(match_operand 2 "cc_reg_operand" "y")
5913                                         (const_int 0)])
5914                     (const_int 0)))
5915    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
5916         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
5917   ""
5918   "%D1mfcr %3\;{rlinm.|rlwinm.} %3,%3,%J1,1"
5919   [(set_attr "type" "delayed_compare")
5920    (set_attr "length" "12")])
5921
5922 (define_insn ""
5923   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5924         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
5925                                       [(match_operand 2 "cc_reg_operand" "y")
5926                                        (const_int 0)])
5927                    (match_operand:SI 3 "const_int_operand" "n")))]
5928   ""
5929   "*
5930 {
5931   int is_bit = ccr_bit (operands[1], 1);
5932   int put_bit = 31 - (INTVAL (operands[3]) & 31);
5933   int count;
5934
5935   if (is_bit >= put_bit)
5936     count = is_bit - put_bit;
5937   else
5938     count = 32 - (put_bit - is_bit);
5939
5940   operands[4] = gen_rtx (CONST_INT, VOIDmode, count);
5941   operands[5] = gen_rtx (CONST_INT, VOIDmode, put_bit);
5942
5943   return \"%D1mfcr %0\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
5944 }"
5945  [(set_attr "length" "12")])
5946
5947 (define_insn ""
5948   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
5949         (compare:CC
5950          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
5951                                        [(match_operand 2 "cc_reg_operand" "y")
5952                                         (const_int 0)])
5953                     (match_operand:SI 3 "const_int_operand" "n"))
5954          (const_int 0)))
5955    (set (match_operand:SI 4 "gpc_reg_operand" "=r")
5956         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
5957                    (match_dup 3)))]
5958   ""
5959   "*
5960 {
5961   int is_bit = ccr_bit (operands[1], 1);
5962   int put_bit = 31 - (INTVAL (operands[3]) & 31);
5963   int count;
5964
5965   if (is_bit >= put_bit)
5966     count = is_bit - put_bit;
5967   else
5968     count = 32 - (put_bit - is_bit);
5969
5970   operands[5] = gen_rtx (CONST_INT, VOIDmode, count);
5971   operands[6] = gen_rtx (CONST_INT, VOIDmode, put_bit);
5972
5973   return \"%D1mfcr %4\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
5974 }"
5975   [(set_attr "type" "delayed_compare")
5976    (set_attr "length" "12")])
5977
5978 ;; If we are comparing the result of two comparisons, this can be done
5979 ;; using creqv or crxor.
5980
5981 (define_insn ""
5982   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
5983         (compare:CCEQ (match_operator 1 "scc_comparison_operator"
5984                               [(match_operand 2 "cc_reg_operand" "y")
5985                                (const_int 0)])
5986                       (match_operator 3 "scc_comparison_operator"
5987                               [(match_operand 4 "cc_reg_operand" "y")
5988                                (const_int 0)])))]
5989   "REGNO (operands[2]) != REGNO (operands[4])"
5990   "*
5991 {
5992   enum rtx_code code1, code2;
5993
5994   code1 = GET_CODE (operands[1]);
5995   code2 = GET_CODE (operands[3]);
5996
5997   if ((code1 == EQ || code1 == LT || code1 == GT
5998        || code1 == LTU || code1 == GTU
5999        || (code1 != NE && GET_MODE (operands[2]) == CCFPmode))
6000       !=
6001       (code2 == EQ || code2 == LT || code2 == GT
6002        || code2 == LTU || code2 == GTU
6003        || (code2 != NE && GET_MODE (operands[4]) == CCFPmode)))
6004     return \"%C1%C3crxor %E0,%j1,%j3\";
6005   else
6006     return \"%C1%C3creqv %E0,%j1,%j3\";
6007 }"
6008   [(set_attr "length" "12")])
6009
6010 ;; There is a 3 cycle delay between consecutive mfcr instructions
6011 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
6012
6013 (define_peephole
6014   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6015         (match_operator:SI 1 "scc_comparison_operator"
6016                            [(match_operand 2 "cc_reg_operand" "y")
6017                             (const_int 0)]))
6018    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
6019         (match_operator:SI 4 "scc_comparison_operator"
6020                            [(match_operand 5 "cc_reg_operand" "y")
6021                             (const_int 0)]))]
6022    "REGNO (operands[2]) != REGNO (operands[5])"
6023    "%D1%D4mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
6024    [(set_attr "length" "20")])
6025
6026 ;; There are some scc insns that can be done directly, without a compare.
6027 ;; These are faster because they don't involve the communications between
6028 ;; the FXU and branch units.   In fact, we will be replacing all of the
6029 ;; integer scc insns here or in the portable methods in emit_store_flag.
6030 ;;
6031 ;; Also support (neg (scc ..)) since that construct is used to replace
6032 ;; branches, (plus (scc ..) ..) since that construct is common and
6033 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
6034 ;; cases where it is no more expensive than (neg (scc ..)).
6035
6036 ;; Have reload force a constant into a register for the simple insns that
6037 ;; otherwise won't accept constants.  We do this because it is faster than
6038 ;; the cmp/mfcr sequence we would otherwise generate.
6039
6040 (define_insn ""
6041   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
6042         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
6043                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I")))
6044    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
6045   ""
6046   "@
6047    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
6048    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
6049    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
6050    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
6051    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
6052   [(set_attr "length" "12,8,12,12,12")])
6053
6054 (define_insn ""
6055   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x")
6056         (compare:CC
6057          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
6058                 (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
6059          (const_int 0)))
6060    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
6061         (eq:SI (match_dup 1) (match_dup 2)))
6062    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
6063   ""
6064   "@
6065    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
6066    {sfi|subfic} %3,%1,0\;{ae.|adde.} %0,%3,%1
6067    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
6068    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
6069    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0"
6070   [(set_attr "type" "compare")
6071    (set_attr "length" "12,8,12,12,12")])
6072
6073 ;; We have insns of the form shown by the first define_insn below.  If
6074 ;; there is something inside the comparison operation, we must split it.
6075 (define_split
6076   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6077         (plus:SI (match_operator 1 "comparison_operator"
6078                                  [(match_operand:SI 2 "" "")
6079                                   (match_operand:SI 3
6080                                                     "reg_or_cint_operand" "")])
6081                  (match_operand:SI 4 "gpc_reg_operand" "")))
6082    (clobber (match_operand:SI 5 "register_operand" ""))]
6083   "! gpc_reg_operand (operands[2], SImode)"
6084   [(set (match_dup 5) (match_dup 2))
6085    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
6086                                (match_dup 4)))])
6087
6088 (define_insn ""
6089   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
6090         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
6091                         (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
6092                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))
6093    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r"))]
6094   ""
6095   "@
6096    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
6097    {sfi|subfic} %4,%1,0\;{aze|addze} %0,%3
6098    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
6099    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
6100    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3"
6101   [(set_attr "length" "12,8,12,12,12")])
6102
6103 (define_insn ""
6104   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x")
6105         (compare:CC
6106          (plus:SI
6107           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
6108                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
6109           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r"))
6110          (const_int 0)))
6111    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r"))]
6112   ""
6113   "@
6114    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
6115    {sfi|subfic} %4,%1,0\;{aze.|addze.} %0,%3
6116    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
6117    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
6118    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3"
6119   [(set_attr "type" "compare")
6120    (set_attr "length" "12,8,12,12,12")])
6121
6122 (define_insn ""
6123   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x,x,x,x")
6124         (compare:CC
6125          (plus:SI
6126           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
6127                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
6128           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r"))
6129          (const_int 0)))
6130    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
6131         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6132    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r"))]
6133   ""
6134   "@
6135    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
6136    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
6137    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
6138    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
6139    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3"
6140   [(set_attr "type" "compare")
6141    (set_attr "length" "12,8,12,12,12")])
6142
6143 (define_insn ""
6144   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
6145         (neg:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
6146                        (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))))]
6147   ""
6148   "@
6149    xor %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
6150    {ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0
6151    {xoril|xori} %0,%1,%b2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
6152    {xoriu|xoris} %0,%1,%u2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
6153    {sfi|subfic} %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
6154    [(set_attr "length" "12,8,12,12,12")])
6155
6156 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
6157 ;; since it nabs/sr is just as fast.
6158 (define_insn ""
6159   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6160         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
6161                      (const_int 31)))
6162    (clobber (match_scratch:SI 2 "=&r"))]
6163   "!TARGET_POWER"
6164   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
6165   [(set_attr "length" "8")])
6166
6167 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
6168 (define_insn ""
6169   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6170         (plus:SI (lshiftrt:SI
6171                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
6172                   (const_int 31))
6173                  (match_operand:SI 2 "gpc_reg_operand" "r")))
6174    (clobber (match_scratch:SI 3 "=&r"))]
6175   ""
6176   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
6177   [(set_attr "length" "8")])
6178
6179 (define_insn ""
6180   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
6181         (compare:CC
6182          (plus:SI (lshiftrt:SI
6183                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
6184                    (const_int 31))
6185                   (match_operand:SI 2 "gpc_reg_operand" "r"))
6186          (const_int 0)))
6187    (clobber (match_scratch:SI 3 "=&r"))]
6188   ""
6189   "{ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2"
6190   [(set_attr "type" "compare")
6191    (set_attr "length" "8")])
6192
6193 (define_insn ""
6194   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
6195         (compare:CC
6196          (plus:SI (lshiftrt:SI
6197                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
6198                    (const_int 31))
6199                   (match_operand:SI 2 "gpc_reg_operand" "r"))
6200          (const_int 0)))
6201    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6202         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
6203                  (match_dup 2)))
6204    (clobber (match_scratch:SI 3 "=&r"))]
6205   ""
6206   "{ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2"
6207   [(set_attr "type" "compare")
6208    (set_attr "length" "8")])
6209
6210 (define_insn ""
6211   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6212         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6213                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
6214    (clobber (match_scratch:SI 3 "=r,X"))]
6215   "TARGET_POWER"
6216   "@
6217    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
6218    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
6219   [(set_attr "length" "12")])
6220
6221 (define_insn ""
6222   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x")
6223         (compare:CC
6224          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6225                 (match_operand:SI 2 "reg_or_short_operand" "r,O"))
6226          (const_int 0)))
6227    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6228         (le:SI (match_dup 1) (match_dup 2)))
6229    (clobber (match_scratch:SI 3 "=r,X"))]
6230   "TARGET_POWER"
6231   "@
6232    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
6233    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31"
6234   [(set_attr "type" "compare,delayed_compare")
6235    (set_attr "length" "12")])
6236
6237 (define_insn ""
6238   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6239         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6240                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
6241                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))
6242    (clobber (match_scratch:SI 4 "=&r,&r"))]
6243   "TARGET_POWER"
6244   "@
6245    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
6246    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze|addze} %0,%3"
6247   [(set_attr "length" "12")])
6248
6249 (define_insn ""
6250   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
6251         (compare:CC
6252          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6253                          (match_operand:SI 2 "reg_or_short_operand" "r,O"))
6254                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6255          (const_int 0)))
6256    (clobber (match_scratch:SI 4 "=&r,&r"))]
6257   "TARGET_POWER"
6258   "@
6259    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
6260    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3"
6261   [(set_attr "type" "compare")
6262    (set_attr "length" "12")])
6263
6264 (define_insn ""
6265   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
6266         (compare:CC
6267          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6268                          (match_operand:SI 2 "reg_or_short_operand" "r,O"))
6269                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6270          (const_int 0)))
6271    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6272         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6273    (clobber (match_scratch:SI 4 "=&r,&r"))]
6274   "TARGET_POWER"
6275   "@
6276    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
6277    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %0,%3"
6278   [(set_attr "type" "compare")
6279    (set_attr "length" "12")])
6280
6281 (define_insn ""
6282   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6283         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6284                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
6285   "TARGET_POWER"
6286   "@
6287    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
6288    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
6289   [(set_attr "length" "12")])
6290
6291 (define_insn ""
6292   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6293         (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6294                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
6295   ""
6296   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
6297   [(set_attr "length" "12")])
6298
6299 (define_insn ""
6300   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
6301         (compare:CC
6302          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6303                  (match_operand:SI 2 "reg_or_short_operand" "rI"))
6304          (const_int 0)))
6305    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6306         (leu:SI (match_dup 1) (match_dup 2)))]
6307    ""
6308   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0"
6309   [(set_attr "type" "compare")
6310    (set_attr "length" "12")])
6311
6312 (define_insn ""
6313   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6314         (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6315                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
6316                  (match_operand:SI 3 "gpc_reg_operand" "r")))
6317    (clobber (match_scratch:SI 4 "=&r"))]
6318   ""
6319   "{sf%I2|subf%I2c} %4,%1,%2\;{aze|addze} %0,%3"
6320   [(set_attr "length" "8")])
6321
6322 (define_insn ""
6323   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
6324         (compare:CC
6325          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6326                           (match_operand:SI 2 "reg_or_short_operand" "rI"))
6327                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6328          (const_int 0)))
6329    (clobber (match_scratch:SI 4 "=&r"))]
6330   ""
6331   "{sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3"
6332   [(set_attr "type" "compare")
6333    (set_attr "length" "8")])
6334
6335 (define_insn ""
6336   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
6337         (compare:CC
6338          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6339                           (match_operand:SI 2 "reg_or_short_operand" "rI"))
6340                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6341          (const_int 0)))
6342    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6343         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6344    (clobber (match_scratch:SI 4 "=&r"))]
6345   ""
6346   "{sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %0,%3"
6347   [(set_attr "type" "compare")
6348    (set_attr "length" "8")])
6349
6350 (define_insn ""
6351   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6352         (neg:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6353                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
6354   ""
6355   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
6356    [(set_attr "length" "12")])
6357
6358 (define_insn ""
6359   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6360         (and:SI (neg:SI
6361                  (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6362                          (match_operand:SI 2 "reg_or_short_operand" "rI")))
6363                 (match_operand:SI 3 "gpc_reg_operand" "r")))
6364    (clobber (match_scratch:SI 4 "=&r"))]
6365   ""
6366   "{sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc %0,%3,%4"
6367   [(set_attr "length" "12")])
6368
6369 (define_insn ""
6370   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
6371         (compare:CC
6372          (and:SI (neg:SI
6373                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6374                           (match_operand:SI 2 "reg_or_short_operand" "rI")))
6375                  (match_operand:SI 3 "gpc_reg_operand" "r"))
6376          (const_int 0)))
6377    (clobber (match_scratch:SI 4 "=&r"))]
6378   ""
6379   "{sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4"
6380   [(set_attr "type" "compare")
6381    (set_attr "length" "12")])
6382
6383 (define_insn ""
6384   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
6385         (compare:CC
6386          (and:SI (neg:SI
6387                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6388                           (match_operand:SI 2 "reg_or_short_operand" "rI")))
6389                  (match_operand:SI 3 "gpc_reg_operand" "r"))
6390          (const_int 0)))
6391    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6392         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
6393    (clobber (match_scratch:SI 4 "=&r"))]
6394   ""
6395   "{sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %0,%3,%4"
6396   [(set_attr "type" "compare")
6397    (set_attr "length" "12")])
6398
6399 (define_insn ""
6400   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6401         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6402                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
6403   "TARGET_POWER"
6404   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
6405    [(set_attr "length" "12")])
6406
6407 (define_insn ""
6408   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
6409         (compare:CC
6410          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6411                 (match_operand:SI 2 "reg_or_short_operand" "rI"))
6412          (const_int 0)))
6413    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6414         (lt:SI (match_dup 1) (match_dup 2)))]
6415   "TARGET_POWER"
6416   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31"
6417   [(set_attr "type" "delayed_compare")
6418    (set_attr "length" "12")])
6419
6420 (define_insn ""
6421   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6422         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6423                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
6424                  (match_operand:SI 3 "gpc_reg_operand" "r")))
6425    (clobber (match_scratch:SI 4 "=&r"))]
6426   "TARGET_POWER"
6427   "doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze|addze} %0,%3"
6428   [(set_attr "length" "12")])
6429
6430 (define_insn ""
6431   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
6432         (compare:CC
6433          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6434                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
6435                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6436          (const_int 0)))
6437    (clobber (match_scratch:SI 4 "=&r"))]
6438   "TARGET_POWER"
6439   "doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3"
6440   [(set_attr "type" "compare")
6441    (set_attr "length" "12")])
6442
6443 (define_insn ""
6444   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
6445         (compare:CC
6446          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6447                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
6448                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6449          (const_int 0)))
6450    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6451         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6452    (clobber (match_scratch:SI 4 "=&r"))]
6453   "TARGET_POWER"
6454   "doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %0,%3"
6455   [(set_attr "type" "compare")
6456    (set_attr "length" "12")])
6457
6458 (define_insn ""
6459   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6460         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6461                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
6462   "TARGET_POWER"
6463   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
6464   [(set_attr "length" "12")])
6465
6466 (define_insn ""
6467   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6468         (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6469                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
6470   ""
6471   "@
6472    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg %0,%0
6473    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
6474   [(set_attr "length" "12")])
6475
6476 (define_insn ""
6477   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
6478         (compare:CC
6479          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6480                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
6481          (const_int 0)))
6482    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6483         (ltu:SI (match_dup 1) (match_dup 2)))]
6484   ""
6485   "@
6486    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
6487    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0"
6488   [(set_attr "type" "compare")
6489    (set_attr "length" "12")])
6490
6491 (define_insn ""
6492   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
6493         (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
6494                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,r,P,P"))
6495                  (match_operand:SI 3 "reg_or_short_operand" "r,I,r,I")))
6496    (clobber (match_scratch:SI 4 "=&r,r,&r,r"))]
6497   ""
6498   "@
6499   {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
6500   {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
6501   {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
6502   {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3"
6503  [(set_attr "length" "12")])
6504
6505 (define_insn ""
6506   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
6507         (compare:CC
6508          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6509                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
6510                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6511          (const_int 0)))
6512    (clobber (match_scratch:SI 4 "=&r,&r"))]
6513   ""
6514   "@
6515    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
6516    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3"
6517   [(set_attr "type" "compare")
6518    (set_attr "length" "12")])
6519
6520 (define_insn ""
6521   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
6522         (compare:CC
6523          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6524                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
6525                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6526          (const_int 0)))
6527    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6528         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6529    (clobber (match_scratch:SI 4 "=&r,&r"))]
6530   ""
6531   "@
6532    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3
6533    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3"
6534   [(set_attr "type" "compare")
6535    (set_attr "length" "12")])
6536
6537 (define_insn ""
6538   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6539         (neg:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6540                         (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))))]
6541   ""
6542   "@
6543    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
6544    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
6545   [(set_attr "length" "8")])
6546
6547 (define_insn ""
6548   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6549         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6550                (match_operand:SI 2 "reg_or_short_operand" "rI")))
6551    (clobber (match_scratch:SI 3 "=r"))]
6552   "TARGET_POWER"
6553   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
6554    [(set_attr "length" "12")])
6555
6556 (define_insn ""
6557   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
6558         (compare:CC
6559          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6560                 (match_operand:SI 2 "reg_or_short_operand" "rI"))
6561          (const_int 0)))
6562    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6563         (ge:SI (match_dup 1) (match_dup 2)))
6564    (clobber (match_scratch:SI 3 "=r"))]
6565   "TARGET_POWER"
6566   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3"
6567   [(set_attr "type" "compare")
6568    (set_attr "length" "12")])
6569
6570 (define_insn ""
6571   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6572         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6573                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
6574                  (match_operand:SI 3 "gpc_reg_operand" "r")))
6575    (clobber (match_scratch:SI 4 "=&r"))]
6576   "TARGET_POWER"
6577   "doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3"
6578   [(set_attr "length" "12")])
6579
6580 (define_insn ""
6581   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
6582         (compare:CC
6583          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6584                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
6585                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6586          (const_int 0)))
6587    (clobber (match_scratch:SI 4 "=&r"))]
6588   "TARGET_POWER"
6589   "doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3"
6590   [(set_attr "type" "compare")
6591    (set_attr "length" "12")])
6592
6593 (define_insn ""
6594   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
6595         (compare:CC
6596          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6597                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
6598                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6599          (const_int 0)))
6600    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6601         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6602    (clobber (match_scratch:SI 4 "=&r"))]
6603   "TARGET_POWER"
6604   "doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3"
6605   [(set_attr "type" "compare")
6606    (set_attr "length" "12")])
6607
6608 (define_insn ""
6609   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6610         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6611                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
6612   "TARGET_POWER"
6613   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
6614   [(set_attr "length" "12")])
6615
6616 ;; This is (and (neg (ge X (const_int 0))) Y).
6617 (define_insn ""
6618   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6619         (and:SI (neg:SI
6620                  (lshiftrt:SI
6621                   (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
6622                   (const_int 31)))
6623                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6624    (clobber (match_scratch:SI 3 "=&r"))]
6625   ""
6626   "{srai|srawi} %3,%1,31\;andc %0,%2,%3"
6627   [(set_attr "length" "8")])
6628
6629 (define_insn ""
6630   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
6631         (compare:CC
6632          (and:SI (neg:SI
6633                   (lshiftrt:SI
6634                    (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
6635                    (const_int 31)))
6636                  (match_operand:SI 2 "gpc_reg_operand" "r"))
6637          (const_int 0)))
6638    (clobber (match_scratch:SI 3 "=&r"))]
6639   ""
6640   "{srai|srawi} %3,%1,31\;andc. %3,%2,%3"
6641   [(set_attr "type" "compare")
6642    (set_attr "length" "8")])
6643
6644 (define_insn ""
6645   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
6646         (compare:CC
6647          (and:SI (neg:SI
6648                   (lshiftrt:SI
6649                    (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
6650                    (const_int 31)))
6651                  (match_operand:SI 2 "gpc_reg_operand" "r"))
6652          (const_int 0)))
6653    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6654         (and:SI (neg:SI (lshiftrt:SI (not:SI (match_dup 1))
6655                                      (const_int 31)))
6656                 (match_dup 2)))
6657    (clobber (match_scratch:SI 3 "=&r"))]
6658   ""
6659   "{srai|srawi} %3,%1,31\;andc. %0,%2,%3"
6660   [(set_attr "type" "compare")
6661    (set_attr "length" "8")])
6662
6663 (define_insn ""
6664   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6665         (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6666                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
6667   ""
6668   "@
6669    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
6670    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
6671   [(set_attr "length" "12")])
6672
6673 (define_insn ""
6674   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
6675         (compare:CC
6676          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6677                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
6678          (const_int 0)))
6679    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6680         (geu:SI (match_dup 1) (match_dup 2)))]
6681   ""
6682   "@
6683    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
6684    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0"
6685   [(set_attr "type" "compare")
6686    (set_attr "length" "12")])
6687
6688 (define_insn ""
6689   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6690         (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6691                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
6692                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))
6693    (clobber (match_scratch:SI 4 "=&r,&r"))]
6694   ""
6695   "@
6696    {sf|subfc} %4,%2,%1\;{aze|addze} %0,%3
6697    {ai|addic} %4,%1,%n2\;{aze|addze} %0,%3"
6698   [(set_attr "length" "8")])
6699
6700 (define_insn ""
6701   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
6702         (compare:CC
6703          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6704                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
6705                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6706          (const_int 0)))
6707    (clobber (match_scratch:SI 4 "=&r,&r"))]
6708   ""
6709   "@
6710    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
6711    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3"
6712   [(set_attr "type" "compare")
6713    (set_attr "length" "8")])
6714
6715 (define_insn ""
6716   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
6717         (compare:CC
6718          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6719                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
6720                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6721          (const_int 0)))
6722    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6723         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6724    (clobber (match_scratch:SI 4 "=&r,&r"))]
6725   ""
6726   "@
6727    {sf|subfc} %4,%2,%1\;{aze.|addze.} %0,%3
6728    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3"
6729   [(set_attr "type" "compare")
6730    (set_attr "length" "8")])
6731
6732 (define_insn ""
6733   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6734         (neg:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6735                         (match_operand:SI 2 "reg_or_short_operand" "r,I"))))]
6736   ""
6737   "@
6738    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
6739    {sfi|subfic} %0,%1,-1\;a%I2 %0,%0,%2\;{sfe|subfe} %0,%0,%0"
6740   [(set_attr "length" "12")])
6741
6742 (define_insn ""
6743   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6744         (and:SI (neg:SI
6745                  (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6746                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
6747                 (match_operand:SI 3 "gpc_reg_operand" "r,r")))
6748    (clobber (match_scratch:SI 4 "=&r,&r"))]
6749   ""
6750   "@
6751    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc %0,%3,%4
6752    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc %0,%3,%4"
6753   [(set_attr "length" "12")])
6754
6755 (define_insn ""
6756   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
6757         (compare:CC
6758          (and:SI (neg:SI
6759                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6760                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
6761                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6762          (const_int 0)))
6763    (clobber (match_scratch:SI 4 "=&r,&r"))]
6764   ""
6765   "@
6766    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
6767    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4"
6768   [(set_attr "type" "compare")
6769    (set_attr "length" "12")])
6770
6771 (define_insn ""
6772   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
6773         (compare:CC
6774          (and:SI (neg:SI
6775                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6776                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
6777                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6778          (const_int 0)))
6779    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6780         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
6781    (clobber (match_scratch:SI 4 "=&r,&r"))]
6782   ""
6783   "@
6784    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %0,%3,%4
6785    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %0,%3,%4"
6786   [(set_attr "type" "compare")
6787    (set_attr "length" "12")])
6788
6789 (define_insn ""
6790   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6791         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6792                (const_int 0)))]
6793   ""
6794   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri|srwi} %0,%0,31"
6795   [(set_attr "length" "12")])
6796
6797 (define_insn ""
6798   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
6799         (compare:CC
6800          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6801                 (const_int 0))
6802          (const_int 0)))
6803    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6804         (gt:SI (match_dup 1) (const_int 0)))]
6805   ""
6806   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri.|srwi.} %0,%0,31"
6807   [(set_attr "type" "delayed_compare")
6808    (set_attr "length" "12")])
6809
6810 (define_insn ""
6811   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6812         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6813                (match_operand:SI 2 "reg_or_short_operand" "r")))]
6814   "TARGET_POWER"
6815   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
6816   [(set_attr "length" "12")])
6817
6818 (define_insn ""
6819   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
6820         (compare:CC
6821          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6822                 (match_operand:SI 2 "reg_or_short_operand" "r"))
6823          (const_int 0)))
6824    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6825         (gt:SI (match_dup 1) (match_dup 2)))]
6826   "TARGET_POWER"
6827   "doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31"
6828   [(set_attr "type" "delayed_compare")
6829    (set_attr "length" "12")])
6830
6831 (define_insn ""
6832   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6833         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6834                         (const_int 0))
6835                  (match_operand:SI 2 "gpc_reg_operand" "r")))
6836    (clobber (match_scratch:SI 3 "=&r"))]
6837   ""
6838   "{a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze|addze} %0,%2"
6839   [(set_attr "length" "12")])
6840
6841 (define_insn ""
6842   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
6843         (compare:CC
6844          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6845                          (const_int 0))
6846                   (match_operand:SI 2 "gpc_reg_operand" "r"))
6847          (const_int 0)))
6848    (clobber (match_scratch:SI 3 "=&r"))]
6849   ""
6850   "{a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %0,%2"
6851   [(set_attr "type" "compare")
6852    (set_attr "length" "12")])
6853
6854 (define_insn ""
6855   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
6856         (compare:CC
6857          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6858                          (const_int 0))
6859                   (match_operand:SI 2 "gpc_reg_operand" "r"))
6860          (const_int 0)))
6861    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6862         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
6863    (clobber (match_scratch:SI 3 "=&r"))]
6864   ""
6865   "{a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2"
6866   [(set_attr "type" "compare")
6867    (set_attr "length" "12")])
6868
6869 (define_insn ""
6870   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6871         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6872                         (match_operand:SI 2 "reg_or_short_operand" "r"))
6873                  (match_operand:SI 3 "gpc_reg_operand" "r")))
6874    (clobber (match_scratch:SI 4 "=&r"))]
6875   "TARGET_POWER"
6876   "doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze|addze} %0,%3"
6877   [(set_attr "length" "12")])
6878
6879 (define_insn ""
6880   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
6881         (compare:CC
6882          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6883                          (match_operand:SI 2 "reg_or_short_operand" "r"))
6884                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6885          (const_int 0)))
6886    (clobber (match_scratch:SI 4 "=&r"))]
6887   "TARGET_POWER"
6888   "doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3"
6889   [(set_attr "type" "compare")
6890    (set_attr "length" "12")])
6891
6892 (define_insn ""
6893   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
6894         (compare:CC
6895          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6896                          (match_operand:SI 2 "reg_or_short_operand" "r"))
6897                   (match_operand:SI 3 "gpc_reg_operand" "r"))
6898          (const_int 0)))
6899    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6900         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6901    (clobber (match_scratch:SI 4 "=&r"))]
6902   "TARGET_POWER"
6903   "doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %0,%3"
6904   [(set_attr "type" "compare")
6905    (set_attr "length" "12")])
6906
6907 (define_insn ""
6908   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6909         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6910                        (const_int 0))))]
6911   ""
6912   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{srai|srawi} %0,%0,31"
6913   [(set_attr "length" "12")])
6914
6915 (define_insn ""
6916   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6917         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6918                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
6919   "TARGET_POWER"
6920   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
6921   [(set_attr "length" "12")])
6922
6923 (define_insn ""
6924   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6925         (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6926                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
6927   ""
6928   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
6929   [(set_attr "length" "12")])
6930
6931 (define_insn ""
6932   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
6933         (compare:CC
6934          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6935                  (match_operand:SI 2 "reg_or_short_operand" "rI"))
6936          (const_int 0)))
6937    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
6938         (gtu:SI (match_dup 1) (match_dup 2)))]
6939   ""
6940   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0"
6941   [(set_attr "type" "compare")
6942    (set_attr "length" "12")])
6943
6944 (define_insn ""
6945   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
6946         (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
6947                          (match_operand:SI 2 "reg_or_short_operand" "I,r,rI"))
6948                  (match_operand:SI 3 "reg_or_short_operand" "r,r,I")))
6949    (clobber (match_scratch:SI 4 "=&r,&r,&r"))]
6950   ""
6951   "@
6952    {ai|addic} %4,%1,%k2\;{aze|addze} %0,%3
6953    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
6954    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3"
6955   [(set_attr "length" "8,12,12")])
6956
6957 (define_insn ""
6958   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
6959         (compare:CC
6960          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6961                           (match_operand:SI 2 "reg_or_short_operand" "I,r"))
6962                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6963          (const_int 0)))
6964    (clobber (match_scratch:SI 4 "=&r,&r"))]
6965   ""
6966   "@
6967    {ai|addic} %4,%1,%k2\;{aze.|addze.} %0,%3
6968    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3"
6969   [(set_attr "type" "compare")
6970    (set_attr "length" "8,12")])
6971
6972 (define_insn ""
6973   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
6974         (compare:CC
6975          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
6976                           (match_operand:SI 2 "reg_or_short_operand" "I,r"))
6977                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6978          (const_int 0)))
6979    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
6980         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
6981    (clobber (match_scratch:SI 4 "=&r,&r"))]
6982   ""
6983   "@
6984    {ai|addic} %4,%1,%k2\;{aze.|addze.} %0,%3
6985    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3"
6986   [(set_attr "type" "compare")
6987    (set_attr "length" "8,12")])
6988
6989 (define_insn ""
6990   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6991         (neg:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
6992                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
6993   ""
6994   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
6995   [(set_attr "length" "8")])
6996 \f
6997 ;; Define both directions of branch and return.  If we need a reload
6998 ;; register, we'd rather use CR0 since it is much easier to copy a
6999 ;; register CC value to there.
7000
7001 (define_insn ""
7002   [(set (pc)
7003         (if_then_else (match_operator 1 "branch_comparison_operator"
7004                                       [(match_operand 2
7005                                                       "cc_reg_operand" "x,?y")
7006                                        (const_int 0)])
7007                       (label_ref (match_operand 0 "" ""))
7008                       (pc)))]
7009   ""
7010   "*
7011 {
7012   if (get_attr_length (insn) == 8)
7013     return \"%C1bc %t1,%j1,%l0\";
7014   else
7015     return \"%C1bc %T1,%j1,$+8\;b %l0\";
7016 }"
7017   [(set_attr "type" "branch")])
7018
7019 (define_insn ""
7020   [(set (pc)
7021         (if_then_else (match_operator 0 "branch_comparison_operator"
7022                                       [(match_operand 1
7023                                                       "cc_reg_operand" "x,?y")
7024                                        (const_int 0)])
7025                       (return)
7026                       (pc)))]
7027   "direct_return ()"
7028   "{%C0bcr|%C0bclr} %t0,%j0"
7029   [(set_attr "length" "8")])
7030
7031 (define_insn ""
7032   [(set (pc)
7033         (if_then_else (match_operator 1 "branch_comparison_operator"
7034                                       [(match_operand 2
7035                                                       "cc_reg_operand" "x,?y")
7036                                        (const_int 0)])
7037                       (pc)
7038                       (label_ref (match_operand 0 "" ""))))]
7039   ""
7040   "*
7041 {
7042   if (get_attr_length (insn) == 8)
7043     return \"%C1bc %T1,%j1,%l0\";
7044   else
7045     return \"%C1bc %t1,%j1,$+8\;b %l0\";
7046 }"
7047   [(set_attr "type" "branch")])
7048
7049 (define_insn ""
7050   [(set (pc)
7051         (if_then_else (match_operator 0 "branch_comparison_operator"
7052                                       [(match_operand 1
7053                                                       "cc_reg_operand" "x,?y")
7054                                        (const_int 0)])
7055                       (pc)
7056                       (return)))]
7057   "direct_return ()"
7058   "{%C0bcr|%C0bclr} %T0,%j0"
7059   [(set_attr "length" "8")])
7060
7061 ;; Unconditional branch and return.
7062
7063 (define_insn "jump"
7064   [(set (pc)
7065         (label_ref (match_operand 0 "" "")))]
7066   ""
7067   "b %l0")
7068
7069 (define_insn "return"
7070   [(return)]
7071   "direct_return ()"
7072   "{br|blr}"
7073   [(set_attr "type" "jmpreg")])
7074
7075 (define_insn "indirect_jump"
7076   [(set (pc) (match_operand:SI 0 "register_operand" "c,l"))]
7077   ""
7078   "@
7079    bctr
7080    {br|blr}"
7081   [(set_attr "type" "jmpreg")])
7082
7083 ;; Table jump for switch statements:
7084 (define_expand "tablejump"
7085   [(set (match_dup 3)
7086         (plus:SI (match_operand:SI 0 "" "")
7087                  (match_dup 2)))
7088    (parallel [(set (pc) (match_dup 3))
7089               (use (label_ref (match_operand 1 "" "")))])]
7090   ""
7091   "
7092 { operands[0] = force_reg (SImode, operands[0]);
7093   operands[2] = force_reg (SImode, gen_rtx (LABEL_REF, VOIDmode, operands[1]));
7094   operands[3] = gen_reg_rtx (SImode);
7095 }")
7096
7097 (define_insn ""
7098   [(set (pc)
7099         (match_operand:SI 0 "register_operand" "c,l"))
7100    (use (label_ref (match_operand 1 "" "")))]
7101   ""
7102   "@
7103    bctr
7104    {br|blr}"
7105   [(set_attr "type" "jmpreg")])
7106
7107 (define_insn "nop"
7108   [(const_int 0)]
7109   ""
7110   "{cror 0,0,0|nop}")
7111 \f
7112 ;; Define the subtract-one-and-jump insns, starting with the template
7113 ;; so loop.c knows what to generate.
7114
7115 (define_expand "decrement_and_branchsi"
7116   [(parallel [(set (pc) (if_then_else (ne (match_operand:SI 0 "register_operand" "c")
7117                                           (const_int 1))
7118                                       (label_ref (match_operand 1 "" ""))
7119                                       (pc)))
7120               (set (match_dup 0) (plus:SI (match_dup 0) (const_int -1)))])]
7121   ""
7122   "")
7123
7124 ;; We need to be able to do this for any operand, including MEM, or we
7125 ;; will cause reload to blow up since we don't allow output reloads on
7126 ;; JUMP_INSNs.
7127 (define_insn ""
7128   [(set (pc)
7129         (if_then_else (ne (match_operand:SI 1 "register_operand" "2,*r,*r")
7130                           (const_int 1))
7131                       (label_ref (match_operand 0 "" ""))
7132                       (pc)))
7133    (set (match_operand:SI 2 "register_operand" "=c,*r,m*q*c*l")
7134         (plus:SI (match_dup 1) (const_int -1)))
7135    (clobber (match_scratch:CC 3 "=X,&x,&x"))
7136    (clobber (match_scratch:SI 4 "=X,X,r"))]
7137   ""
7138   "*
7139 {
7140   if (which_alternative != 0)
7141     return \"#\";
7142   else if (get_attr_length (insn) == 8)
7143     return \"{bdn|bdnz} %l0\";
7144   else
7145     return \"bdz $+8\;b %l0\";
7146 }"
7147   [(set_attr "type" "branch")
7148    (set_attr "length" "*,12,16")])
7149
7150 ;; Similar, but we can use GE since we have a REG_NONNEG.
7151 (define_insn ""
7152   [(set (pc)
7153         (if_then_else (ge (match_operand:SI 1 "register_operand" "2,*r,*r")
7154                           (const_int 0))
7155                       (label_ref (match_operand 0 "" ""))
7156                       (pc)))
7157    (set (match_operand:SI 2 "register_operand" "=c,*r,m*q*c*l")
7158         (plus:SI (match_dup 1) (const_int -1)))
7159    (clobber (match_scratch:CC 3 "=X,&x,&X"))
7160    (clobber (match_scratch:SI 4 "=X,X,r"))]
7161   "find_reg_note (insn, REG_NONNEG, 0)"
7162   "*
7163 {
7164   if (which_alternative != 0)
7165     return \"#\";
7166   else if (get_attr_length (insn) == 8)
7167     return \"{bdn|bdnz} %l0\";
7168   else
7169     return \"bdz $+8\;b %l0\";
7170 }"
7171   [(set_attr "type" "branch")
7172    (set_attr "length" "*,12,16")])
7173
7174 (define_insn ""
7175   [(set (pc)
7176         (if_then_else (eq (match_operand:SI 1 "register_operand" "2,*r,*r")
7177                           (const_int 1))
7178                       (label_ref (match_operand 0 "" ""))
7179                       (pc)))
7180    (set (match_operand:SI 2 "register_operand" "=c,*r,m*q*c*l")
7181         (plus:SI (match_dup 1) (const_int -1)))
7182    (clobber (match_scratch:CC 3 "=X,&x,&x"))
7183    (clobber (match_scratch:SI 4 "=X,X,r"))]
7184   ""
7185   "*
7186 {
7187   if (which_alternative != 0)
7188     return \"#\";
7189   else if (get_attr_length (insn) == 8)
7190     return \"bdz %l0\";
7191   else
7192     return \"{bdn|bdnz} $+8\;b %l0\";
7193 }"
7194   [(set_attr "type" "branch")
7195    (set_attr "length" "*,12,16")])
7196
7197 (define_split
7198   [(set (pc)
7199         (if_then_else (match_operator 2 "comparison_operator"
7200                                       [(match_operand:SI 1 "gpc_reg_operand" "")
7201                                        (const_int 1)])
7202                       (match_operand 5 "" "")
7203                       (match_operand 6 "" "")))
7204    (set (match_operand:SI 0 "gpc_reg_operand" "")
7205         (plus:SI (match_dup 1) (const_int -1)))
7206    (clobber (match_scratch:CC 3 ""))
7207    (clobber (match_scratch:SI 4 ""))]
7208   "reload_completed"
7209   [(parallel [(set (match_dup 3)
7210                    (compare:CC (plus:SI (match_dup 1) (const_int -1))
7211                                (const_int 0)))
7212               (set (match_dup 0) (plus:SI (match_dup 1) (const_int -1)))])
7213    (set (pc) (if_then_else (match_dup 7) (match_dup 5) (match_dup 6)))]
7214   "
7215 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
7216                          const0_rtx); }")
7217
7218 (define_split
7219   [(set (pc)
7220         (if_then_else (match_operator 2 "comparison_operator"
7221                                       [(match_operand:SI 1 "gpc_reg_operand" "")
7222                                        (const_int 1)])
7223                       (match_operand 5 "" "")
7224                       (match_operand 6 "" "")))
7225    (set (match_operand:SI 0 "general_operand" "")
7226         (plus:SI (match_dup 1) (const_int -1)))
7227    (clobber (match_scratch:CC 3 ""))
7228    (clobber (match_scratch:SI 4 ""))]
7229   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
7230   [(parallel [(set (match_dup 3)
7231                    (compare:CC (plus:SI (match_dup 1) (const_int -1))
7232                                (const_int 0)))
7233               (set (match_dup 4) (plus:SI (match_dup 1) (const_int -1)))])
7234    (set (match_dup 0) (match_dup 4))
7235    (set (pc) (if_then_else (match_dup 7) (match_dup 5) (match_dup 6)))]
7236   "
7237 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
7238                          const0_rtx); }")