OSDN Git Service

d076d0bb698ea6b388b479cff4621b2ef743b054
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / rs6000.md
1 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
2 ;; Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 
3 ;; 1999, 2000, 2001 Free Software Foundation, Inc.
4 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5
6 ;; This file is part of GNU CC.
7
8 ;; GNU CC is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
12
13 ;; GNU CC is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU CC; see the file COPYING.  If not, write to
20 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
22
23 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
24
25 ;; `unspec' values used in rs6000.md:
26 ;; Number       Use
27 ;; 0            frsp for POWER machines
28 ;; 0/v          blockage
29 ;; 5            used to tie the stack contents and the stack pointer
30 ;; 6            address of a word pointing to the TOC
31 ;; 7            address of the TOC (more-or-less)
32 ;; 8            movsi_got
33 ;; 9/v          eh_reg_restore
34 ;; 10           fctiwz
35 ;; 19           movesi_from_cr
36 ;; 20           movesi_to_cr
37 \f
38 ;; Define an insn type attribute.  This is used in function unit delay
39 ;; computations.
40 (define_attr "type" "integer,load,store,fpload,fpstore,vecload,vecstore,imul,imul2,imul3,lmul,idiv,ldiv,branch,compare,cr_logical,delayed_compare,fpcompare,mtjmpr,fp,dmul,sdiv,ddiv,ssqrt,dsqrt,jmpreg,vecsimple,veccomplex,veccmp,vecperm,vecfloat,altivec"
41   (const_string "integer"))
42
43 ;; Length (in bytes).
44 ; '(pc)' in the following doesn't include the instruction itself; it is 
45 ; calculated as if the instruction had zero size.
46 (define_attr "length" ""
47   (if_then_else (eq_attr "type" "branch")
48                 (if_then_else (and (ge (minus (match_dup 0) (pc))
49                                        (const_int -32768))
50                                    (lt (minus (match_dup 0) (pc))
51                                        (const_int 32764)))
52                               (const_int 4)
53                               (const_int 8))
54                 (const_int 4)))
55
56 ;; Processor type -- this attribute must exactly match the processor_type
57 ;; enumeration in rs6000.h.
58
59 (define_attr "cpu" "rios1,rios2,rs64a,mpccore,ppc403,ppc405,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,power4"
60   (const (symbol_ref "rs6000_cpu_attr")))
61
62 ; (define_function_unit NAME MULTIPLICITY SIMULTANEITY
63 ;                       TEST READY-DELAY ISSUE-DELAY [CONFLICT-LIST])
64
65 ; Load/Store Unit -- pure PowerPC only
66 ; (POWER and 601 use Integer Unit)
67 (define_function_unit "lsu" 1 0
68   (and (eq_attr "type" "load")
69        (eq_attr "cpu" "rs64a,mpccore,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400"))
70   2 1)
71
72 (define_function_unit "lsu" 1 0
73   (and (eq_attr "type" "load,vecload")
74        (eq_attr "cpu" "ppc7450"))
75   3 1)
76
77 (define_function_unit "lsu" 1 0
78   (and (eq_attr "type" "store,fpstore")
79        (eq_attr "cpu" "rs64a,mpccore,ppc603,ppc604,ppc604e,ppc620,ppc630"))
80   1 1)
81
82 (define_function_unit "lsu" 1 0
83   (and (eq_attr "type" "store,fpstore")
84        (eq_attr "cpu" "ppc750,ppc7400"))
85   2 1)
86
87 (define_function_unit "lsu" 1 0
88   (and (eq_attr "type" "store,vecstore")
89        (eq_attr "cpu" "ppc7450"))
90   3 1)
91
92 (define_function_unit "lsu" 1 0
93   (and (eq_attr "type" "fpstore")
94        (eq_attr "cpu" "ppc7450"))
95   3 3)
96
97 (define_function_unit "lsu" 1 0
98   (and (eq_attr "type" "fpload")
99        (eq_attr "cpu" "mpccore,ppc603,ppc750,ppc7400"))
100   2 1)
101
102 (define_function_unit "lsu" 1 0
103   (and (eq_attr "type" "fpload")
104        (eq_attr "cpu" "ppc7450"))
105   4 1)
106
107 (define_function_unit "lsu" 1 0
108   (and (eq_attr "type" "fpload")
109        (eq_attr "cpu" "rs64a,ppc604,ppc604e,ppc620,ppc630"))
110   3 1)
111
112 (define_function_unit "iu" 1 0
113   (and (eq_attr "type" "load")
114        (eq_attr "cpu" "rios1,ppc403,ppc405,ppc601"))
115   2 1)
116
117 (define_function_unit "iu" 1 0
118   (and (eq_attr "type" "store,fpstore")
119        (eq_attr "cpu" "rios1,ppc403,ppc405,ppc601"))
120   1 1)
121
122 (define_function_unit "fpu" 1 0
123   (and (eq_attr "type" "fpstore")
124        (eq_attr "cpu" "rios1,ppc601"))
125   0 1)
126
127 (define_function_unit "iu" 1 0
128   (and (eq_attr "type" "fpload")
129        (eq_attr "cpu" "rios1"))
130   2 1)
131
132 (define_function_unit "iu" 1 0
133   (and (eq_attr "type" "fpload")
134        (eq_attr "cpu" "ppc601"))
135   3 1)
136
137 (define_function_unit "iu2" 2 0
138   (and (eq_attr "type" "load,fpload")
139        (eq_attr "cpu" "rios2"))
140   2 1)
141
142 (define_function_unit "iu2" 2 0
143   (and (eq_attr "type" "store,fpstore")
144        (eq_attr "cpu" "rios2"))
145   1 1)
146
147 ; Integer Unit (RIOS1, PPC601, PPC603, RS64a)
148 (define_function_unit "iu" 1 0
149   (and (eq_attr "type" "integer")
150        (eq_attr "cpu" "rios1,rs64a,mpccore,ppc403,ppc405,ppc601,ppc603"))
151   1 1)
152
153 (define_function_unit "iu" 1 0
154   (and (eq_attr "type" "cr_logical")
155        (eq_attr "cpu" "mpccore,ppc403,ppc405,ppc601"))
156   1 1)
157
158 (define_function_unit "iu" 1 0
159   (and (eq_attr "type" "imul,imul2,imul3")
160        (eq_attr "cpu" "ppc403"))
161   4 4)
162
163 (define_function_unit "iu" 1 0
164   (and (eq_attr "type" "imul")
165        (eq_attr "cpu" "ppc405"))
166   4 3)
167
168 (define_function_unit "iu" 1 0
169   (and (eq_attr "type" "imul2,imul3")
170        (eq_attr "cpu" "ppc405"))
171   3 2)
172
173 (define_function_unit "iu" 1 0
174   (and (eq_attr "type" "imul")
175        (eq_attr "cpu" "rios1"))
176   5 5)
177
178 (define_function_unit "iu" 1 0
179   (and (eq_attr "type" "imul2")
180        (eq_attr "cpu" "rios1"))
181   4 4)
182
183 (define_function_unit "iu" 1 0
184   (and (eq_attr "type" "imul3")
185        (eq_attr "cpu" "rios1"))
186   3 3)
187
188 (define_function_unit "iu" 1 0
189   (and (eq_attr "type" "imul,imul2,imul3")
190        (eq_attr "cpu" "ppc601,ppc603"))
191   5 5)
192
193 (define_function_unit "iu" 1 0
194   (and (eq_attr "type" "imul")
195        (eq_attr "cpu" "rs64a"))
196   20 20)
197
198 (define_function_unit "iu" 1 0
199   (and (eq_attr "type" "imul2")
200        (eq_attr "cpu" "rs64a"))
201   12 12)
202
203 (define_function_unit "iu" 1 0
204   (and (eq_attr "type" "imul3")
205        (eq_attr "cpu" "rs64a"))
206   8 8)
207
208 (define_function_unit "iu" 1 0
209   (and (eq_attr "type" "lmul")
210        (eq_attr "cpu" "rs64a"))
211   34 34)
212
213 (define_function_unit "iu" 1 0
214   (and (eq_attr "type" "idiv")
215        (eq_attr "cpu" "rios1"))
216   19 19)
217
218 (define_function_unit "iu" 1 0
219   (and (eq_attr "type" "idiv")
220        (eq_attr "cpu" "rs64a"))
221   66 66)
222
223 (define_function_unit "iu" 1 0
224   (and (eq_attr "type" "ldiv")
225        (eq_attr "cpu" "rs64a"))
226   66 66)
227
228 (define_function_unit "iu" 1 0
229   (and (eq_attr "type" "idiv")
230        (eq_attr "cpu" "ppc403"))
231   33 33)
232
233 (define_function_unit "iu" 1 0
234   (and (eq_attr "type" "idiv")
235        (eq_attr "cpu" "ppc405"))
236   35 35)
237
238 (define_function_unit "iu" 1 0
239   (and (eq_attr "type" "idiv")
240        (eq_attr "cpu" "ppc601"))
241   36 36)
242
243 (define_function_unit "iu" 1 0
244   (and (eq_attr "type" "idiv")
245        (eq_attr "cpu" "ppc603"))
246   37 36)
247
248 ; RIOS2 has two integer units: a primary one which can perform all
249 ; operations and a secondary one which is fed in lock step with the first
250 ; and can perform "simple" integer operations.  
251 ; To catch this we define a 'dummy' imuldiv-unit that is also needed
252 ; for the complex insns. 
253 (define_function_unit "iu2" 2 0
254   (and (eq_attr "type" "integer")
255        (eq_attr "cpu" "rios2"))
256   1 1)
257
258 (define_function_unit "iu2" 2 0
259   (and (eq_attr "type" "imul,imul2,imul3")
260        (eq_attr "cpu" "rios2"))
261   2 2)
262
263 (define_function_unit "iu2" 2 0
264   (and (eq_attr "type" "idiv")
265        (eq_attr "cpu" "rios2"))
266   13 13)
267
268 (define_function_unit "imuldiv" 1 0
269   (and (eq_attr "type" "imul,imul2,imul3")
270        (eq_attr "cpu" "rios2"))
271   2 2)
272
273 (define_function_unit "imuldiv" 1 0
274   (and (eq_attr "type" "idiv")
275        (eq_attr "cpu" "rios2"))
276   13 13)
277
278 ; MPCCORE has separate IMUL/IDIV unit for multicycle instructions
279 ; Divide latency varies greatly from 2-11, use 6 as average
280 (define_function_unit "imuldiv" 1 0
281   (and (eq_attr "type" "imul,imul2,imul3")
282        (eq_attr "cpu" "mpccore"))
283   2 1)
284
285 (define_function_unit "imuldiv" 1 0
286   (and (eq_attr "type" "idiv")
287        (eq_attr "cpu" "mpccore"))
288   6 6)
289
290 ; PPC604{,e} has two units that perform integer operations
291 ; and one unit for divide/multiply operations (and move
292 ; from/to spr).
293 (define_function_unit "iu2" 2 0
294   (and (eq_attr "type" "integer")
295        (eq_attr "cpu" "ppc604,ppc604e,ppc620,ppc630"))
296   1 1)
297
298 (define_function_unit "imuldiv" 1 0
299   (and (eq_attr "type" "imul,imul2,imul3")
300        (eq_attr "cpu" "ppc604"))
301   4 2)
302
303 (define_function_unit "imuldiv" 1 0
304   (and (eq_attr "type" "imul,imul2,imul3")
305        (eq_attr "cpu" "ppc604e"))
306   2 1)
307
308 (define_function_unit "imuldiv" 1 0
309   (and (eq_attr "type" "imul")
310        (eq_attr "cpu" "ppc620,ppc630"))
311   5 3)
312
313 (define_function_unit "imuldiv" 1 0
314   (and (eq_attr "type" "imul2")
315        (eq_attr "cpu" "ppc620,ppc630"))
316   4 3)
317
318 (define_function_unit "imuldiv" 1 0
319   (and (eq_attr "type" "imul3")
320        (eq_attr "cpu" "ppc620,ppc630"))
321   3 3)
322
323 (define_function_unit "imuldiv" 1 0
324   (and (eq_attr "type" "lmul")
325        (eq_attr "cpu" "ppc620,ppc630"))
326   7 5)
327
328 (define_function_unit "imuldiv" 1 0
329   (and (eq_attr "type" "idiv")
330        (eq_attr "cpu" "ppc604,ppc604e"))
331   20 19)
332
333 (define_function_unit "imuldiv" 1 0
334   (and (eq_attr "type" "idiv")
335        (eq_attr "cpu" "ppc620"))
336   37 36)
337
338 (define_function_unit "imuldiv" 1 0
339   (and (eq_attr "type" "idiv")
340        (eq_attr "cpu" "ppc630"))
341   21 20)
342
343 (define_function_unit "imuldiv" 1 0
344   (and (eq_attr "type" "ldiv")
345        (eq_attr "cpu" "ppc620,ppc630"))
346   37 36)
347
348 ; PPC7450 has 3 integer units (for most integer insns) and one mul/div
349 ; unit, which also does CR-logical insns and move to/from SPR.
350 ; It also has 4 vector units, one for each type of vector instruction.
351 ; However, we can only dispatch 2 instructions per cycle. 
352 ; We model this as saying that dispatching two of the same type of instruction
353 ; in a row incurs a single cycle delay.
354 (define_function_unit "iu3" 3 0
355   (and (eq_attr "type" "integer")
356        (eq_attr "cpu" "ppc7450"))
357   1 1)
358
359 (define_function_unit "imuldiv" 1 0
360   (and (eq_attr "type" "imul")
361        (eq_attr "cpu" "ppc7450"))
362   4 2)
363
364 (define_function_unit "imuldiv" 1 0
365   (and (eq_attr "type" "imul2,imul3")
366        (eq_attr "cpu" "ppc7450"))
367   3 1)
368
369 (define_function_unit "imuldiv" 1 0
370   (and (eq_attr "type" "idiv")
371        (eq_attr "cpu" "ppc7450"))
372   23 23)
373
374 (define_function_unit "imuldiv" 1 0
375   (and (eq_attr "type" "cr_logical")
376        (eq_attr "cpu" "ppc7450"))
377   1 1)
378
379 (define_function_unit "vec_alu2" 2 0
380   (and (eq_attr "type" "vecsimple")
381        (eq_attr "cpu" "ppc7450"))
382   1 2 [(eq_attr "type" "vecsimple")])
383
384 (define_function_unit "vec_alu2" 2 0
385   (and (eq_attr "type" "vecsimple")
386        (eq_attr "cpu" "ppc7450"))
387   1 1 [(eq_attr "type" "!vecsimple")])
388
389 (define_function_unit "vec_alu2" 2 0
390   (and (eq_attr "type" "veccomplex")
391        (eq_attr "cpu" "ppc7450"))
392   4 2 [(eq_attr "type" "veccomplex")])
393
394 (define_function_unit "vec_alu2" 2 0
395   (and (eq_attr "type" "veccomplex")
396        (eq_attr "cpu" "ppc7450"))
397   4 1 [(eq_attr "type" "!veccomplex")])
398
399 (define_function_unit "vec_alu2" 2 0
400   (and (eq_attr "type" "veccmp")
401        (eq_attr "cpu" "ppc7450"))
402   2 2 [(eq_attr "type" "veccmp")])
403
404 (define_function_unit "vec_alu2" 2 0
405   (and (eq_attr "type" "veccmp")
406        (eq_attr "cpu" "ppc7450"))
407   2 1 [(eq_attr "type" "!veccmp")])
408
409 (define_function_unit "vec_alu2" 2 0
410   (and (eq_attr "type" "vecfloat")
411        (eq_attr "cpu" "ppc7450"))
412   4 2 [(eq_attr "type" "vecfloat")])
413
414 (define_function_unit "vec_alu2" 2 0
415   (and (eq_attr "type" "vecfloat")
416        (eq_attr "cpu" "ppc7450"))
417   4 1 [(eq_attr "type" "!vecfloat")])
418
419 (define_function_unit "vec_alu2" 2 0
420   (and (eq_attr "type" "vecperm")
421        (eq_attr "cpu" "ppc7450"))
422   2 2 [(eq_attr "type" "vecperm")])
423
424 (define_function_unit "vec_alu2" 2 0
425   (and (eq_attr "type" "vecperm")
426        (eq_attr "cpu" "ppc7450"))
427   2 1 [(eq_attr "type" "!vecperm")])
428
429 ; PPC750 has two integer units: a primary one which can perform all
430 ; operations and a secondary one which is fed in lock step with the first
431 ; and can perform "simple" integer operations.  
432 ; To catch this we define a 'dummy' imuldiv-unit that is also needed
433 ; for the complex insns. 
434 (define_function_unit "iu2" 2 0
435   (and (eq_attr "type" "integer")
436        (eq_attr "cpu" "ppc750,ppc7400"))
437   1 1)
438
439 (define_function_unit "iu2" 2 0
440   (and (eq_attr "type" "imul")
441        (eq_attr "cpu" "ppc750,ppc7400"))
442   4 4)
443
444 (define_function_unit "iu2" 2 0
445   (and (eq_attr "type" "imul2")
446        (eq_attr "cpu" "ppc750,ppc7400"))
447   3 2)
448
449 (define_function_unit "iu2" 2 0
450   (and (eq_attr "type" "imul3")
451        (eq_attr "cpu" "ppc750,ppc7400"))
452   2 1)
453
454 (define_function_unit "iu2" 2 0
455   (and (eq_attr "type" "idiv")
456        (eq_attr "cpu" "ppc750,ppc7400"))
457   19 19)
458
459 (define_function_unit "imuldiv" 1 0
460   (and (eq_attr "type" "imul")
461        (eq_attr "cpu" "ppc750,ppc7400"))
462   4 4)
463
464 (define_function_unit "imuldiv" 1 0
465   (and (eq_attr "type" "imul2")
466        (eq_attr "cpu" "ppc750,ppc7400"))
467   3 2)
468
469 (define_function_unit "imuldiv" 1 0
470   (and (eq_attr "type" "imul3")
471        (eq_attr "cpu" "ppc750,ppc7400"))
472   2 1)
473
474 (define_function_unit "imuldiv" 1 0
475   (and (eq_attr "type" "idiv")
476        (eq_attr "cpu" "ppc750,ppc7400"))
477   19 19)
478
479 ; CR-logical operations are execute-serialized, that is they don't
480 ; start (and block the function unit) until all preceding operations
481 ; have finished.  They don't block dispatch of other insns, though.
482 ; I've imitated this by giving them longer latency.
483 (define_function_unit "sru" 1 0 
484   (and (eq_attr "type" "cr_logical")
485        (eq_attr "cpu" "ppc603,ppc750,ppc7400"))
486   3 2)
487
488 ; compare is done on integer unit, but feeds insns which
489 ; execute on the branch unit.
490 (define_function_unit "iu" 1 0   
491   (and (eq_attr "type" "compare")
492        (eq_attr "cpu" "rios1"))
493   4 1)
494
495 (define_function_unit "iu" 1 0   
496   (and (eq_attr "type" "delayed_compare")
497        (eq_attr "cpu" "rios1"))
498   5 1)
499
500 (define_function_unit "iu" 1 0
501   (and (eq_attr "type" "compare,delayed_compare")
502        (eq_attr "cpu" "rs64a,mpccore,ppc403,ppc405,ppc601,ppc603"))
503   3 1)
504
505 ; some extra cycles added by TARGET_SCHED_ADJUST_COST between compare
506 ; and a following branch, to reduce mispredicts
507 (define_function_unit "iu3" 3 0
508   (and (eq_attr "type" "compare,delayed_compare")
509        (eq_attr "cpu" "ppc7450"))
510   1 1)
511
512 (define_function_unit "iu2" 2 0   
513   (and (eq_attr "type" "compare,delayed_compare")
514        (eq_attr "cpu" "rios2"))
515   3 1)
516
517 (define_function_unit "iu2" 2 0
518   (and (eq_attr "type" "compare,delayed_compare")
519        (eq_attr "cpu" "ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400"))
520   1 1)
521
522 ; fp compare uses fp unit
523 (define_function_unit "fpu" 1 0
524   (and (eq_attr "type" "fpcompare")
525        (eq_attr "cpu" "rios1"))
526   9 1)
527
528 ; rios1 and rios2 have different fpcompare delays
529 (define_function_unit "fpu2" 2 0
530   (and (eq_attr "type" "fpcompare")
531        (eq_attr "cpu" "rios2,ppc630"))
532   5 1)
533
534 ; on ppc601 and ppc603, fpcompare takes also 2 cycles from
535 ; the integer unit
536 ; here we do not define delays, just occupy the unit. The dependencies
537 ; will be assigned by the fpcompare definition in the fpu.
538 (define_function_unit "iu" 1 0
539   (and (eq_attr "type" "fpcompare")
540        (eq_attr "cpu" "ppc601,ppc603"))
541   0 2)
542
543 ; fp compare uses fp unit
544 (define_function_unit "fpu" 1 0
545   (and (eq_attr "type" "fpcompare")
546        (eq_attr "cpu" "rs64a,ppc601,ppc603,ppc604,ppc604e,ppc620"))
547   5 1)
548
549 (define_function_unit "fpu" 1 0
550   (and (eq_attr "type" "fpcompare")
551        (eq_attr "cpu"  "ppc750,ppc7400,ppc7450"))
552   3 1)
553
554 (define_function_unit "fpu" 1 0
555   (and (eq_attr "type" "fpcompare")
556        (eq_attr "cpu" "mpccore"))
557   1 1)
558
559 (define_function_unit "bpu" 1 0
560   (and (eq_attr "type" "mtjmpr")
561        (eq_attr "cpu" "rios1,rios2,rs64a"))
562   5 1)
563
564 (define_function_unit "bpu" 1 0
565   (and (eq_attr "type" "mtjmpr")
566        (eq_attr "cpu" "mpccore,ppc403,ppc405,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630"))
567   4 1)
568
569 (define_function_unit "sru" 1 0
570   (and (eq_attr "type" "mtjmpr")
571        (eq_attr "cpu" "ppc750,ppc7400"))
572   2 2)
573
574 (define_function_unit "imuldiv" 1 0
575   (and (eq_attr "type" "mtjmpr")
576        (eq_attr "cpu" "ppc7450"))
577   2 2)
578
579 (define_function_unit "bpu" 1 0
580   (and (eq_attr "type" "cr_logical")
581        (eq_attr "cpu" "rios1,rios2,ppc604"))
582   4 1)
583   
584 (define_function_unit "cru" 1 0
585   (and (eq_attr "type" "cr_logical")
586        (eq_attr "cpu" "ppc604e,ppc620,ppc630,rs64a"))
587   1 1)
588
589 ; all jumps/branches are executing on the bpu, in 1 cycle, for all machines.
590 (define_function_unit "bpu" 1 0
591   (eq_attr "type" "jmpreg")
592   1 1)
593
594 (define_function_unit "bpu" 1 0
595   (eq_attr "type" "branch")
596   1 1)
597
598 ; Floating Point Unit
599 (define_function_unit "fpu" 1 0
600   (and (eq_attr "type" "fp,dmul")
601        (eq_attr "cpu" "rios1"))
602   2 1)
603
604 (define_function_unit "fpu" 1 0
605   (and (eq_attr "type" "fp")
606        (eq_attr "cpu" "rs64a,mpccore"))
607   4 2)
608
609 (define_function_unit "fpu" 1 0
610   (and (eq_attr "type" "fp")
611        (eq_attr "cpu" "ppc601"))
612   4 1)
613
614 (define_function_unit "fpu" 1 0
615   (and (eq_attr "type" "fp")
616        (eq_attr "cpu" "ppc603,ppc604,ppc604e,ppc620,ppc750,ppc7400"))
617   3 1)
618
619 (define_function_unit "fpu" 1 0
620   (and (eq_attr "type" "fp,dmul")
621        (eq_attr "cpu" "ppc7450"))
622   5 1)
623
624 (define_function_unit "fpu" 1 0
625   (and (eq_attr "type" "dmul")
626        (eq_attr "cpu" "rs64a"))
627   7 2)
628
629 (define_function_unit "fpu" 1 0
630   (and (eq_attr "type" "dmul")
631        (eq_attr "cpu" "mpccore"))
632   5 5)
633
634 (define_function_unit "fpu" 1 0
635   (and (eq_attr "type" "dmul")
636        (eq_attr "cpu" "ppc601"))
637   5 2)
638
639 ; is this true?
640 (define_function_unit "fpu" 1 0
641   (and (eq_attr "type" "dmul")
642        (eq_attr "cpu" "ppc603,ppc750"))
643   4 2)
644
645 (define_function_unit "fpu" 1 0
646   (and (eq_attr "type" "dmul")
647        (eq_attr "cpu" "ppc604,ppc604e,ppc620,ppc7400"))
648   3 1)
649
650 (define_function_unit "fpu" 1 0
651   (and (eq_attr "type" "sdiv,ddiv")
652        (eq_attr "cpu" "rios1"))
653   19 19)
654
655 (define_function_unit "fpu" 1 0
656   (and (eq_attr "type" "sdiv")
657        (eq_attr "cpu" "rs64a"))
658   31 31)
659
660 (define_function_unit "fpu" 1 0
661   (and (eq_attr "type" "sdiv")
662        (eq_attr "cpu" "ppc601,ppc750,ppc7400"))
663   17 17)
664
665 (define_function_unit "fpu" 1 0
666   (and (eq_attr "type" "sdiv")
667        (eq_attr "cpu" "ppc7450"))
668   21 21)
669
670 (define_function_unit "fpu" 1 0
671   (and (eq_attr "type" "sdiv")
672        (eq_attr "cpu" "mpccore"))
673   10 10)
674
675 (define_function_unit "fpu" 1 0
676   (and (eq_attr "type" "sdiv")
677        (eq_attr "cpu" "ppc603,ppc604,ppc604e,ppc620"))
678   18 18)
679
680 (define_function_unit "fpu" 1 0
681   (and (eq_attr "type" "ddiv")
682        (eq_attr "cpu" "mpccore"))
683   17 17)
684
685 (define_function_unit "fpu" 1 0
686   (and (eq_attr "type" "ddiv")
687        (eq_attr "cpu" "rs64a,ppc601,ppc750,ppc604,ppc604e,ppc620,ppc7400"))
688   31 31)
689
690 (define_function_unit "fpu" 1 0
691   (and (eq_attr "type" "ddiv")
692        (eq_attr "cpu" "ppc7450"))
693   35 35)
694
695 (define_function_unit "fpu" 1 0
696   (and (eq_attr "type" "ddiv")
697        (eq_attr "cpu" "ppc603"))
698   33 33)
699
700 (define_function_unit "fpu" 1 0
701   (and (eq_attr "type" "ssqrt")
702        (eq_attr "cpu" "ppc620"))
703   31 31)
704
705 (define_function_unit "fpu" 1 0
706   (and (eq_attr "type" "dsqrt")
707        (eq_attr "cpu" "ppc620"))
708   31 31)
709
710 ; RIOS2 has two symmetric FPUs.
711 (define_function_unit "fpu2" 2 0
712   (and (eq_attr "type" "fp,dmul")
713        (eq_attr "cpu" "rios2"))
714   2 1)
715
716 (define_function_unit "fpu2" 2 0
717   (and (eq_attr "type" "fp,dmul")
718        (eq_attr "cpu" "ppc630"))
719   3 1)
720
721 (define_function_unit "fpu2" 2 0
722   (and (eq_attr "type" "sdiv,ddiv")
723        (eq_attr "cpu" "rios2"))
724   17 17)
725
726 (define_function_unit "fpu2" 2 0
727   (and (eq_attr "type" "sdiv")
728        (eq_attr "cpu" "ppc630"))
729   17 17)
730
731 (define_function_unit "fpu2" 2 0
732   (and (eq_attr "type" "ddiv")
733        (eq_attr "cpu" "ppc630"))
734   21 21)
735
736 (define_function_unit "fpu2" 2 0
737   (and (eq_attr "type" "ssqrt,dsqrt")
738        (eq_attr "cpu" "rios2"))
739   26 26)
740
741 (define_function_unit "fpu2" 2 0
742   (and (eq_attr "type" "ssqrt")
743        (eq_attr "cpu" "ppc630"))
744   18 18)
745
746 (define_function_unit "fpu2" 2 0
747   (and (eq_attr "type" "dsqrt")
748        (eq_attr "cpu" "ppc630"))
749   26 26)
750
751 ;; Power4
752 (define_function_unit "lsu2" 2 0
753   (and (eq_attr "type" "load")
754        (eq_attr "cpu" "power4"))
755   3 1)
756
757 (define_function_unit "lsu2" 2 0
758   (and (eq_attr "type" "fpload")
759        (eq_attr "cpu" "power4"))
760   5 1)
761
762 (define_function_unit "lsu2" 2 0
763   (and (eq_attr "type" "store,fpstore")
764        (eq_attr "cpu" "power4"))
765   1 1)
766
767 (define_function_unit "iu2" 2 0
768   (and (eq_attr "type" "integer")
769        (eq_attr "cpu" "power4"))
770   2 1)
771
772 (define_function_unit "iu2" 2 0
773   (and (eq_attr "type" "imul,lmul")
774        (eq_attr "cpu" "power4"))
775   7 6)
776
777 (define_function_unit "iu2" 2 0
778   (and (eq_attr "type" "imul2")
779        (eq_attr "cpu" "power4"))
780   5 4)
781
782 (define_function_unit "iu2" 2 0
783   (and (eq_attr "type" "imul3")
784        (eq_attr "cpu" "power4"))
785   4 3)
786
787 (define_function_unit "iu2" 2 0
788   (and (eq_attr "type" "idiv")
789        (eq_attr "cpu" "power4"))
790   36 35)
791
792 (define_function_unit "iu2" 2 0
793   (and (eq_attr "type" "ldiv")
794        (eq_attr "cpu" "power4"))
795   68 67)
796
797 (define_function_unit "imuldiv" 1 0
798   (and (eq_attr "type" "idiv")
799        (eq_attr "cpu" "power4"))
800   36 35)
801
802 (define_function_unit "imuldiv" 1 0
803   (and (eq_attr "type" "ldiv")
804        (eq_attr "cpu" "power4"))
805   68 67)
806
807 (define_function_unit "iu2" 2 0
808   (and (eq_attr "type" "compare")
809        (eq_attr "cpu" "power4"))
810   3 1)
811
812 (define_function_unit "iu2" 2 0
813   (and (eq_attr "type" "delayed_compare")
814        (eq_attr "cpu" "power4"))
815   4 1)
816
817 (define_function_unit "bpu" 1 0
818   (and (eq_attr "type" "mtjmpr")
819        (eq_attr "cpu" "power4"))
820   3 1)
821
822 (define_function_unit "bpu" 1 0
823   (and (eq_attr "type" "jmpreg,branch")
824        (eq_attr "cpu" "power4"))
825   2 1)
826
827 (define_function_unit "cru" 1 0
828   (and (eq_attr "type" "cr_logical")
829        (eq_attr "cpu" "power4"))
830   4 1)
831
832 (define_function_unit "fpu2" 2 0
833   (and (eq_attr "type" "fp,dmul")
834        (eq_attr "cpu" "power4"))
835   6 1)
836
837 ; adjust_cost increases the cost of dependent branches,
838 ; so shave a few cycles off for fpcompare.
839 (define_function_unit "fpu2" 2 0
840   (and (eq_attr "type" "fpcompare")
841        (eq_attr "cpu" "power4"))
842   5 1)
843
844 (define_function_unit "fpu2" 2 0
845   (and (eq_attr "type" "sdiv,ddiv")
846        (eq_attr "cpu" "power4"))
847   33 28)
848
849 (define_function_unit "fpu2" 2 0
850   (and (eq_attr "type" "ssqrt,dsqrt")
851        (eq_attr "cpu" "power4"))
852   40 35)
853
854 \f
855 ;; Start with fixed-point load and store insns.  Here we put only the more
856 ;; complex forms.  Basic data transfer is done later.
857
858 (define_expand "zero_extendqidi2"
859   [(set (match_operand:DI 0 "gpc_reg_operand" "")
860         (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "")))]
861   "TARGET_POWERPC64"
862   "")
863
864 (define_insn ""
865   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
866         (zero_extend:DI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
867   "TARGET_POWERPC64"
868   "@
869    lbz%U1%X1 %0,%1
870    rldicl %0,%1,0,56"
871   [(set_attr "type" "load,*")])
872
873 (define_insn ""
874   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
875         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
876                     (const_int 0)))
877    (clobber (match_scratch:DI 2 "=r,r"))]
878   "TARGET_POWERPC64"
879   "@
880    rldicl. %2,%1,0,56
881    #"
882   [(set_attr "type" "compare")
883    (set_attr "length" "4,8")])
884
885 (define_split
886   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
887         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
888                     (const_int 0)))
889    (clobber (match_scratch:DI 2 ""))]
890   "TARGET_POWERPC64 && reload_completed"
891   [(set (match_dup 2)
892         (zero_extend:DI (match_dup 1)))
893    (set (match_dup 0)
894         (compare:CC (match_dup 2)
895                     (const_int 0)))]
896   "")
897
898 (define_insn ""
899   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
900         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
901                     (const_int 0)))
902    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
903         (zero_extend:DI (match_dup 1)))]
904   "TARGET_POWERPC64"
905   "@
906    rldicl. %0,%1,0,56
907    #"
908   [(set_attr "type" "compare")
909    (set_attr "length" "4,8")])
910
911 (define_split
912   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
913         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
914                     (const_int 0)))
915    (set (match_operand:DI 0 "gpc_reg_operand" "")
916         (zero_extend:DI (match_dup 1)))]
917   "TARGET_POWERPC64 && reload_completed"
918   [(set (match_dup 0)
919         (zero_extend:DI (match_dup 1)))
920    (set (match_dup 2)
921         (compare:CC (match_dup 0)
922                     (const_int 0)))]
923   "")
924
925 (define_insn "extendqidi2"
926   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
927         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
928   "TARGET_POWERPC64"
929   "extsb %0,%1")
930
931 (define_insn ""
932   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
933         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
934                     (const_int 0)))
935    (clobber (match_scratch:DI 2 "=r,r"))]
936   "TARGET_POWERPC64"
937   "@
938    extsb. %2,%1
939    #"
940   [(set_attr "type" "compare")
941    (set_attr "length" "4,8")])
942
943 (define_split
944   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
945         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
946                     (const_int 0)))
947    (clobber (match_scratch:DI 2 ""))]
948   "TARGET_POWERPC64 && reload_completed"
949   [(set (match_dup 2)
950         (sign_extend:DI (match_dup 1)))
951    (set (match_dup 0)
952         (compare:CC (match_dup 2)
953                     (const_int 0)))]
954   "")
955
956 (define_insn ""
957   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
958         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
959                     (const_int 0)))
960    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
961         (sign_extend:DI (match_dup 1)))]
962   "TARGET_POWERPC64"
963   "@
964    extsb. %0,%1
965    #"
966   [(set_attr "type" "compare")
967    (set_attr "length" "4,8")])
968
969 (define_split
970   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
971         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
972                     (const_int 0)))
973    (set (match_operand:DI 0 "gpc_reg_operand" "")
974         (sign_extend:DI (match_dup 1)))]
975   "TARGET_POWERPC64 && reload_completed"
976   [(set (match_dup 0)
977         (sign_extend:DI (match_dup 1)))
978    (set (match_dup 2)
979         (compare:CC (match_dup 0)
980                     (const_int 0)))]
981   "")
982
983 (define_expand "zero_extendhidi2"
984   [(set (match_operand:DI 0 "gpc_reg_operand" "")
985         (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
986   "TARGET_POWERPC64"
987   "")
988
989 (define_insn ""
990   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
991         (zero_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
992   "TARGET_POWERPC64"
993   "@
994    lhz%U1%X1 %0,%1
995    rldicl %0,%1,0,48"
996   [(set_attr "type" "load,*")])
997
998 (define_insn ""
999   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1000         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1001                     (const_int 0)))
1002    (clobber (match_scratch:DI 2 "=r,r"))]
1003   "TARGET_POWERPC64"
1004   "@
1005    rldicl. %2,%1,0,48
1006    #"
1007   [(set_attr "type" "compare")
1008    (set_attr "length" "4,8")])
1009
1010 (define_split
1011   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1012         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
1013                     (const_int 0)))
1014    (clobber (match_scratch:DI 2 ""))]
1015   "TARGET_POWERPC64 && reload_completed"
1016   [(set (match_dup 2)
1017         (zero_extend:DI (match_dup 1)))
1018    (set (match_dup 0)
1019         (compare:CC (match_dup 2)
1020                     (const_int 0)))]
1021   "")
1022
1023 (define_insn ""
1024   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1025         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1026                     (const_int 0)))
1027    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
1028         (zero_extend:DI (match_dup 1)))]
1029   "TARGET_POWERPC64"
1030   "@
1031    rldicl. %0,%1,0,48
1032    #"
1033   [(set_attr "type" "compare")
1034    (set_attr "length" "4,8")])
1035
1036 (define_split
1037   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1038         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
1039                     (const_int 0)))
1040    (set (match_operand:DI 0 "gpc_reg_operand" "")
1041         (zero_extend:DI (match_dup 1)))]
1042   "TARGET_POWERPC64 && reload_completed"
1043   [(set (match_dup 0)
1044         (zero_extend:DI (match_dup 1)))
1045    (set (match_dup 2)
1046         (compare:CC (match_dup 0)
1047                     (const_int 0)))]
1048   "")
1049
1050 (define_expand "extendhidi2"
1051   [(set (match_operand:DI 0 "gpc_reg_operand" "")
1052         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
1053   "TARGET_POWERPC64"
1054   "")
1055
1056 (define_insn ""
1057   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
1058         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
1059   "TARGET_POWERPC64"
1060   "@
1061    lha%U1%X1 %0,%1
1062    extsh %0,%1"
1063   [(set_attr "type" "load,*")])
1064
1065 (define_insn ""
1066   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1067         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1068                     (const_int 0)))
1069    (clobber (match_scratch:DI 2 "=r,r"))]
1070   "TARGET_POWERPC64"
1071   "@
1072    extsh. %2,%1
1073    #"
1074   [(set_attr "type" "compare")
1075    (set_attr "length" "4,8")])
1076
1077 (define_split
1078   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1079         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
1080                     (const_int 0)))
1081    (clobber (match_scratch:DI 2 ""))]
1082   "TARGET_POWERPC64 && reload_completed"
1083   [(set (match_dup 2)
1084         (sign_extend:DI (match_dup 1)))
1085    (set (match_dup 0)
1086         (compare:CC (match_dup 2)
1087                     (const_int 0)))]
1088   "")
1089
1090 (define_insn ""
1091   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1092         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1093                     (const_int 0)))
1094    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
1095         (sign_extend:DI (match_dup 1)))]
1096   "TARGET_POWERPC64"
1097   "@
1098    extsh. %0,%1
1099    #"
1100   [(set_attr "type" "compare")
1101    (set_attr "length" "4,8")])
1102
1103 (define_split
1104   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1105         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
1106                     (const_int 0)))
1107    (set (match_operand:DI 0 "gpc_reg_operand" "")
1108         (sign_extend:DI (match_dup 1)))]
1109   "TARGET_POWERPC64 && reload_completed"
1110   [(set (match_dup 0)
1111         (sign_extend:DI (match_dup 1)))
1112    (set (match_dup 2)
1113         (compare:CC (match_dup 0)
1114                     (const_int 0)))]
1115   "")
1116
1117 (define_expand "zero_extendsidi2"
1118   [(set (match_operand:DI 0 "gpc_reg_operand" "")
1119         (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
1120   "TARGET_POWERPC64"
1121   "")
1122
1123 (define_insn ""
1124   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
1125         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r")))]
1126   "TARGET_POWERPC64"
1127   "@
1128    lwz%U1%X1 %0,%1
1129    rldicl %0,%1,0,32"
1130   [(set_attr "type" "load,*")])
1131
1132 (define_insn ""
1133   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1134         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1135                     (const_int 0)))
1136    (clobber (match_scratch:DI 2 "=r,r"))]
1137   "TARGET_POWERPC64"
1138   "@
1139    rldicl. %2,%1,0,32
1140    #"
1141   [(set_attr "type" "compare")
1142    (set_attr "length" "4,8")])
1143
1144 (define_split
1145   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1146         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
1147                     (const_int 0)))
1148    (clobber (match_scratch:DI 2 ""))]
1149   "TARGET_POWERPC64 && reload_completed"
1150   [(set (match_dup 2)
1151         (zero_extend:DI (match_dup 1)))
1152    (set (match_dup 0)
1153         (compare:CC (match_dup 2)
1154                     (const_int 0)))]
1155   "")
1156
1157 (define_insn ""
1158   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1159         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1160                     (const_int 0)))
1161    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
1162         (zero_extend:DI (match_dup 1)))]
1163   "TARGET_POWERPC64"
1164   "@
1165    rldicl. %0,%1,0,32
1166    #"
1167   [(set_attr "type" "compare")
1168    (set_attr "length" "4,8")])
1169
1170 (define_split
1171   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1172         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
1173                     (const_int 0)))
1174    (set (match_operand:DI 0 "gpc_reg_operand" "")
1175         (zero_extend:DI (match_dup 1)))]
1176   "TARGET_POWERPC64 && reload_completed"
1177   [(set (match_dup 0)
1178         (zero_extend:DI (match_dup 1)))
1179    (set (match_dup 2)
1180         (compare:CC (match_dup 0)
1181                     (const_int 0)))]
1182   "")
1183
1184 (define_expand "extendsidi2"
1185   [(set (match_operand:DI 0 "gpc_reg_operand" "")
1186         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
1187   "TARGET_POWERPC64"
1188   "")
1189
1190 (define_insn ""
1191   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
1192         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
1193   "TARGET_POWERPC64"
1194   "@
1195    lwa%U1%X1 %0,%1
1196    extsw %0,%1"
1197   [(set_attr "type" "load,*")])
1198
1199 (define_insn ""
1200   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1201         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1202                     (const_int 0)))
1203    (clobber (match_scratch:DI 2 "=r,r"))]
1204   "TARGET_POWERPC64"
1205   "@
1206    extsw. %2,%1
1207    #"
1208   [(set_attr "type" "compare")
1209    (set_attr "length" "4,8")])
1210
1211 (define_split
1212   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1213         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
1214                     (const_int 0)))
1215    (clobber (match_scratch:DI 2 ""))]
1216   "TARGET_POWERPC64 && reload_completed"
1217   [(set (match_dup 2)
1218         (sign_extend:DI (match_dup 1)))
1219    (set (match_dup 0)
1220         (compare:CC (match_dup 2)
1221                     (const_int 0)))]
1222   "")
1223
1224 (define_insn ""
1225   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1226         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1227                     (const_int 0)))
1228    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
1229         (sign_extend:DI (match_dup 1)))]
1230   "TARGET_POWERPC64"
1231   "@
1232    extsw. %0,%1
1233    #"
1234   [(set_attr "type" "compare")
1235    (set_attr "length" "4,8")])
1236
1237 (define_split
1238   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1239         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
1240                     (const_int 0)))
1241    (set (match_operand:DI 0 "gpc_reg_operand" "")
1242         (sign_extend:DI (match_dup 1)))]
1243   "TARGET_POWERPC64 && reload_completed"
1244   [(set (match_dup 0)
1245         (sign_extend:DI (match_dup 1)))
1246    (set (match_dup 2)
1247         (compare:CC (match_dup 0)
1248                     (const_int 0)))]
1249   "")
1250
1251 (define_expand "zero_extendqisi2"
1252   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1253         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
1254   ""
1255   "")
1256
1257 (define_insn ""
1258   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1259         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
1260   ""
1261   "@
1262    lbz%U1%X1 %0,%1
1263    {rlinm|rlwinm} %0,%1,0,0xff"
1264   [(set_attr "type" "load,*")])
1265
1266 (define_insn ""
1267   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1268         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1269                     (const_int 0)))
1270    (clobber (match_scratch:SI 2 "=r,r"))]
1271   ""
1272   "@
1273    {andil.|andi.} %2,%1,0xff
1274    #"
1275   [(set_attr "type" "compare")
1276    (set_attr "length" "4,8")])
1277
1278 (define_split
1279   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1280         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
1281                     (const_int 0)))
1282    (clobber (match_scratch:SI 2 ""))]
1283   "reload_completed"
1284   [(set (match_dup 2)
1285         (zero_extend:SI (match_dup 1)))
1286    (set (match_dup 0)
1287         (compare:CC (match_dup 2)
1288                     (const_int 0)))]
1289   "")
1290
1291 (define_insn ""
1292   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1293         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1294                     (const_int 0)))
1295    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1296         (zero_extend:SI (match_dup 1)))]
1297   ""
1298   "@
1299    {andil.|andi.} %0,%1,0xff
1300    #"
1301   [(set_attr "type" "compare")
1302    (set_attr "length" "4,8")])
1303
1304 (define_split
1305   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1306         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
1307                     (const_int 0)))
1308    (set (match_operand:SI 0 "gpc_reg_operand" "")
1309         (zero_extend:SI (match_dup 1)))]
1310   "reload_completed"
1311   [(set (match_dup 0)
1312         (zero_extend:SI (match_dup 1)))
1313    (set (match_dup 2)
1314         (compare:CC (match_dup 0)
1315                     (const_int 0)))]
1316   "")
1317
1318 (define_expand "extendqisi2"
1319   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1320    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
1321   ""
1322   "
1323 {
1324   if (TARGET_POWERPC)
1325     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
1326   else if (TARGET_POWER)
1327     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
1328   else
1329     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
1330   DONE;
1331 }")
1332
1333 (define_insn "extendqisi2_ppc"
1334   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1335         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
1336   "TARGET_POWERPC"
1337   "extsb %0,%1")
1338
1339 (define_insn ""
1340   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1341         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1342                     (const_int 0)))
1343    (clobber (match_scratch:SI 2 "=r,r"))]
1344   "TARGET_POWERPC"
1345   "@
1346    extsb. %2,%1
1347    #"
1348   [(set_attr "type" "compare")
1349    (set_attr "length" "4,8")])
1350
1351 (define_split
1352   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1353         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
1354                     (const_int 0)))
1355    (clobber (match_scratch:SI 2 ""))]
1356   "TARGET_POWERPC && reload_completed"
1357   [(set (match_dup 2)
1358         (sign_extend:SI (match_dup 1)))
1359    (set (match_dup 0)
1360         (compare:CC (match_dup 2)
1361                     (const_int 0)))]
1362   "")
1363
1364 (define_insn ""
1365   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1366         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1367                     (const_int 0)))
1368    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1369         (sign_extend:SI (match_dup 1)))]
1370   "TARGET_POWERPC"
1371   "@
1372    extsb. %0,%1
1373    #"
1374   [(set_attr "type" "compare")
1375    (set_attr "length" "4,8")])
1376
1377 (define_split
1378   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1379         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
1380                     (const_int 0)))
1381    (set (match_operand:SI 0 "gpc_reg_operand" "")
1382         (sign_extend:SI (match_dup 1)))]
1383   "TARGET_POWERPC && reload_completed"
1384   [(set (match_dup 0)
1385         (sign_extend:SI (match_dup 1)))
1386    (set (match_dup 2)
1387         (compare:CC (match_dup 0)
1388                     (const_int 0)))]
1389   "")
1390
1391 (define_expand "extendqisi2_power"
1392   [(parallel [(set (match_dup 2)
1393                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
1394                               (const_int 24)))
1395               (clobber (scratch:SI))])
1396    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1397                    (ashiftrt:SI (match_dup 2)
1398                                 (const_int 24)))
1399               (clobber (scratch:SI))])]
1400   "TARGET_POWER"
1401   "
1402 { operands[1] = gen_lowpart (SImode, operands[1]);
1403   operands[2] = gen_reg_rtx (SImode); }")
1404
1405 (define_expand "extendqisi2_no_power"
1406   [(set (match_dup 2)
1407         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
1408                    (const_int 24)))
1409    (set (match_operand:SI 0 "gpc_reg_operand" "")
1410         (ashiftrt:SI (match_dup 2)
1411                      (const_int 24)))]
1412   "! TARGET_POWER && ! TARGET_POWERPC"
1413   "
1414 { operands[1] = gen_lowpart (SImode, operands[1]);
1415   operands[2] = gen_reg_rtx (SImode); }")
1416
1417 (define_expand "zero_extendqihi2"
1418   [(set (match_operand:HI 0 "gpc_reg_operand" "")
1419         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
1420   ""
1421   "")
1422
1423 (define_insn ""
1424   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
1425         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
1426   ""
1427   "@
1428    lbz%U1%X1 %0,%1
1429    {rlinm|rlwinm} %0,%1,0,0xff"
1430   [(set_attr "type" "load,*")])
1431
1432 (define_insn ""
1433   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1434         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1435                     (const_int 0)))
1436    (clobber (match_scratch:HI 2 "=r,r"))]
1437   ""
1438   "@
1439    {andil.|andi.} %2,%1,0xff
1440    #"
1441   [(set_attr "type" "compare")
1442    (set_attr "length" "4,8")])
1443
1444 (define_split
1445   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1446         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1447                     (const_int 0)))
1448    (clobber (match_scratch:HI 2 ""))]
1449   "reload_completed"
1450   [(set (match_dup 2)
1451         (zero_extend:HI (match_dup 1)))
1452    (set (match_dup 0)
1453         (compare:CC (match_dup 2)
1454                     (const_int 0)))]
1455   "")
1456
1457 (define_insn ""
1458   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1459         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1460                     (const_int 0)))
1461    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
1462         (zero_extend:HI (match_dup 1)))]
1463   ""
1464   "@
1465    {andil.|andi.} %0,%1,0xff
1466    #"
1467   [(set_attr "type" "compare")
1468    (set_attr "length" "4,8")])
1469
1470 (define_split
1471   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1472         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1473                     (const_int 0)))
1474    (set (match_operand:HI 0 "gpc_reg_operand" "")
1475         (zero_extend:HI (match_dup 1)))]
1476   "reload_completed"
1477   [(set (match_dup 0)
1478         (zero_extend:HI (match_dup 1)))
1479    (set (match_dup 2)
1480         (compare:CC (match_dup 0)
1481                     (const_int 0)))]
1482   "")
1483
1484 (define_expand "extendqihi2"
1485   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
1486    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
1487   ""
1488   "
1489 {
1490   if (TARGET_POWERPC)
1491     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
1492   else if (TARGET_POWER)
1493     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
1494   else
1495     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
1496   DONE;
1497 }")
1498
1499 (define_insn "extendqihi2_ppc"
1500   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
1501         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
1502   "TARGET_POWERPC"
1503   "extsb %0,%1")
1504
1505 (define_insn ""
1506   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1507         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1508                     (const_int 0)))
1509    (clobber (match_scratch:HI 2 "=r,r"))]
1510   "TARGET_POWERPC"
1511   "@
1512    extsb. %2,%1
1513    #"
1514   [(set_attr "type" "compare")
1515    (set_attr "length" "4,8")])
1516
1517 (define_split
1518   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1519         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1520                     (const_int 0)))
1521    (clobber (match_scratch:HI 2 ""))]
1522   "TARGET_POWERPC && reload_completed"
1523   [(set (match_dup 2)
1524         (sign_extend:HI (match_dup 1)))
1525    (set (match_dup 0)
1526         (compare:CC (match_dup 2)
1527                     (const_int 0)))]
1528   "")
1529
1530 (define_insn ""
1531   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1532         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1533                     (const_int 0)))
1534    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
1535         (sign_extend:HI (match_dup 1)))]
1536   "TARGET_POWERPC"
1537   "@
1538    extsb. %0,%1
1539    #"
1540   [(set_attr "type" "compare")
1541    (set_attr "length" "4,8")])
1542
1543 (define_split
1544   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1545         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
1546                     (const_int 0)))
1547    (set (match_operand:HI 0 "gpc_reg_operand" "")
1548         (sign_extend:HI (match_dup 1)))]
1549   "TARGET_POWERPC && reload_completed"
1550   [(set (match_dup 0)
1551         (sign_extend:HI (match_dup 1)))
1552    (set (match_dup 2)
1553         (compare:CC (match_dup 0)
1554                     (const_int 0)))]
1555   "")
1556
1557 (define_expand "extendqihi2_power"
1558   [(parallel [(set (match_dup 2)
1559                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
1560                               (const_int 24)))
1561               (clobber (scratch:SI))])
1562    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
1563                    (ashiftrt:SI (match_dup 2)
1564                                 (const_int 24)))
1565               (clobber (scratch:SI))])]
1566   "TARGET_POWER"
1567   "
1568 { operands[0] = gen_lowpart (SImode, operands[0]);
1569   operands[1] = gen_lowpart (SImode, operands[1]);
1570   operands[2] = gen_reg_rtx (SImode); }")
1571
1572 (define_expand "extendqihi2_no_power"
1573   [(set (match_dup 2)
1574         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
1575                    (const_int 24)))
1576    (set (match_operand:HI 0 "gpc_reg_operand" "")
1577         (ashiftrt:SI (match_dup 2)
1578                      (const_int 24)))]
1579   "! TARGET_POWER && ! TARGET_POWERPC"
1580   "
1581 { operands[0] = gen_lowpart (SImode, operands[0]);
1582   operands[1] = gen_lowpart (SImode, operands[1]);
1583   operands[2] = gen_reg_rtx (SImode); }")
1584
1585 (define_expand "zero_extendhisi2"
1586   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1587         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
1588   ""
1589   "")
1590
1591 (define_insn ""
1592   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1593         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
1594   ""
1595   "@
1596    lhz%U1%X1 %0,%1
1597    {rlinm|rlwinm} %0,%1,0,0xffff"
1598   [(set_attr "type" "load,*")])
1599
1600 (define_insn ""
1601   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1602         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1603                     (const_int 0)))
1604    (clobber (match_scratch:SI 2 "=r,r"))]
1605   ""
1606   "@
1607    {andil.|andi.} %2,%1,0xffff
1608    #"
1609   [(set_attr "type" "compare")
1610    (set_attr "length" "4,8")])
1611
1612 (define_split
1613   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1614         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1615                     (const_int 0)))
1616    (clobber (match_scratch:SI 2 ""))]
1617   "reload_completed"
1618   [(set (match_dup 2)
1619         (zero_extend:SI (match_dup 1)))
1620    (set (match_dup 0)
1621         (compare:CC (match_dup 2)
1622                     (const_int 0)))]
1623   "")
1624
1625 (define_insn ""
1626   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1627         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1628                     (const_int 0)))
1629    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1630         (zero_extend:SI (match_dup 1)))]
1631   ""
1632   "@
1633    {andil.|andi.} %0,%1,0xffff
1634    #"
1635   [(set_attr "type" "compare")
1636    (set_attr "length" "4,8")])
1637
1638 (define_split
1639   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1640         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1641                     (const_int 0)))
1642    (set (match_operand:SI 0 "gpc_reg_operand" "")
1643         (zero_extend:SI (match_dup 1)))]
1644   "reload_completed"
1645   [(set (match_dup 0)
1646         (zero_extend:SI (match_dup 1)))
1647    (set (match_dup 2)
1648         (compare:CC (match_dup 0)
1649                     (const_int 0)))]
1650   "")
1651
1652 (define_expand "extendhisi2"
1653   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1654         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
1655   ""
1656   "")
1657
1658 (define_insn ""
1659   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1660         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
1661   ""
1662   "@
1663    lha%U1%X1 %0,%1
1664    {exts|extsh} %0,%1"
1665   [(set_attr "type" "load,*")])
1666
1667 (define_insn ""
1668   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1669         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1670                     (const_int 0)))
1671    (clobber (match_scratch:SI 2 "=r,r"))]
1672   ""
1673   "@
1674    {exts.|extsh.} %2,%1
1675    #"
1676   [(set_attr "type" "compare")
1677    (set_attr "length" "4,8")])
1678
1679 (define_split
1680   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1681         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1682                     (const_int 0)))
1683    (clobber (match_scratch:SI 2 ""))]
1684   "reload_completed"
1685   [(set (match_dup 2)
1686         (sign_extend:SI (match_dup 1)))
1687    (set (match_dup 0)
1688         (compare:CC (match_dup 2)
1689                     (const_int 0)))]
1690   "")
1691
1692 (define_insn ""
1693   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1694         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1695                     (const_int 0)))
1696    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1697         (sign_extend:SI (match_dup 1)))]
1698   ""
1699   "@
1700    {exts.|extsh.} %0,%1
1701    #"
1702   [(set_attr "type" "compare")
1703    (set_attr "length" "4,8")])
1704 \f
1705 (define_split
1706   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1707         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1708                     (const_int 0)))
1709    (set (match_operand:SI 0 "gpc_reg_operand" "")
1710         (sign_extend:SI (match_dup 1)))]
1711   "reload_completed"
1712   [(set (match_dup 0)
1713         (sign_extend:SI (match_dup 1)))
1714    (set (match_dup 2)
1715         (compare:CC (match_dup 0)
1716                     (const_int 0)))]
1717   "")
1718
1719 ;; Fixed-point arithmetic insns.
1720
1721 ;; Discourage ai/addic because of carry but provide it in an alternative
1722 ;; allowing register zero as source.
1723 (define_expand "addsi3"
1724   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1725         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1726                  (match_operand:SI 2 "reg_or_arith_cint_operand" "")))]
1727   ""
1728   "
1729 {
1730   if (GET_CODE (operands[2]) == CONST_INT
1731                 && ! add_operand (operands[2], SImode))
1732     {
1733       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
1734                  ? operands[0] : gen_reg_rtx (SImode));
1735
1736       HOST_WIDE_INT val = INTVAL (operands[2]);
1737       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1738       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, SImode);
1739
1740       /* The ordering here is important for the prolog expander.
1741          When space is allocated from the stack, adding 'low' first may
1742          produce a temporary deallocation (which would be bad).  */
1743       emit_insn (gen_addsi3 (tmp, operands[1], GEN_INT (rest)));
1744       emit_insn (gen_addsi3 (operands[0], tmp, GEN_INT (low)));
1745       DONE;
1746     }
1747 }")
1748
1749 (define_insn "*addsi3_internal1"
1750   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,?r,r")
1751         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,b,r,b")
1752                  (match_operand:SI 2 "add_operand" "r,I,I,L")))]
1753   ""
1754   "@
1755    {cax|add} %0,%1,%2
1756    {cal %0,%2(%1)|addi %0,%1,%2}
1757    {ai|addic} %0,%1,%2
1758    {cau|addis} %0,%1,%v2"
1759   [(set_attr "length" "4,4,4,4")])
1760
1761 (define_insn "addsi3_high"
1762   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1763         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1764                  (high:SI (match_operand 2 "" ""))))]
1765   "TARGET_MACHO && !TARGET_64BIT"
1766   "{cau|addis} %0,%1,ha16(%2)"
1767   [(set_attr "length" "4")])
1768
1769 (define_insn "*addsi3_internal2"
1770   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1771         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1772                              (match_operand:SI 2 "reg_or_short_operand" "r,I,r,I"))
1773                     (const_int 0)))
1774    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
1775   "! TARGET_POWERPC64"
1776   "@
1777    {cax.|add.} %3,%1,%2
1778    {ai.|addic.} %3,%1,%2
1779    #
1780    #"
1781   [(set_attr "type" "compare")
1782    (set_attr "length" "4,4,8,8")])
1783
1784 (define_split
1785   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1786         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1787                              (match_operand:SI 2 "reg_or_short_operand" ""))
1788                     (const_int 0)))
1789    (clobber (match_scratch:SI 3 ""))]
1790   "! TARGET_POWERPC64 && reload_completed"
1791   [(set (match_dup 3)
1792         (plus:SI (match_dup 1)
1793                  (match_dup 2)))
1794    (set (match_dup 0)
1795         (compare:CC (match_dup 3)
1796                     (const_int 0)))]
1797   "")
1798
1799 (define_insn "*addsi3_internal3"
1800   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1801         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1802                              (match_operand:SI 2 "reg_or_short_operand" "r,I,r,I"))
1803                     (const_int 0)))
1804    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1805         (plus:SI (match_dup 1)
1806                  (match_dup 2)))]
1807   "! TARGET_POWERPC64"
1808   "@
1809    {cax.|add.} %0,%1,%2
1810    {ai.|addic.} %0,%1,%2
1811    #
1812    #"
1813   [(set_attr "type" "compare")
1814    (set_attr "length" "4,4,8,8")])
1815
1816 (define_split
1817   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1818         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1819                              (match_operand:SI 2 "reg_or_short_operand" ""))
1820                     (const_int 0)))
1821    (set (match_operand:SI 0 "gpc_reg_operand" "")
1822         (plus:SI (match_dup 1) (match_dup 2)))]
1823   "! TARGET_POWERPC64 && reload_completed"
1824   [(set (match_dup 0)
1825         (plus:SI (match_dup 1)
1826                  (match_dup 2)))
1827    (set (match_dup 3)
1828         (compare:CC (match_dup 0)
1829                     (const_int 0)))]
1830   "")
1831
1832 ;; Split an add that we can't do in one insn into two insns, each of which
1833 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1834 ;; add should be last in case the result gets used in an address.
1835
1836 (define_split
1837   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1838         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1839                  (match_operand:SI 2 "non_add_cint_operand" "")))]
1840   ""
1841   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
1842    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
1843 "
1844 {
1845   HOST_WIDE_INT val = INTVAL (operands[2]);
1846   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1847   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, SImode);
1848
1849   operands[3] = GEN_INT (rest);
1850   operands[4] = GEN_INT (low);
1851 }")
1852
1853 (define_insn "one_cmplsi2"
1854   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1855         (not:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1856   ""
1857   "nor %0,%1,%1")
1858
1859 (define_insn ""
1860   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1861         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1862                     (const_int 0)))
1863    (clobber (match_scratch:SI 2 "=r,r"))]
1864   "! TARGET_POWERPC64"
1865   "@
1866    nor. %2,%1,%1
1867    #"
1868   [(set_attr "type" "compare")
1869    (set_attr "length" "4,8")])
1870
1871 (define_split
1872   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1873         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1874                     (const_int 0)))
1875    (clobber (match_scratch:SI 2 ""))]
1876   "! TARGET_POWERPC64 && reload_completed"
1877   [(set (match_dup 2)
1878         (not:SI (match_dup 1)))
1879    (set (match_dup 0)
1880         (compare:CC (match_dup 2)
1881                     (const_int 0)))]
1882   "")
1883
1884 (define_insn ""
1885   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1886         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1887                     (const_int 0)))
1888    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1889         (not:SI (match_dup 1)))]
1890   "! TARGET_POWERPC64"
1891   "@
1892    nor. %0,%1,%1
1893    #"
1894   [(set_attr "type" "compare")
1895    (set_attr "length" "4,8")])
1896
1897 (define_split
1898   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1899         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
1900                     (const_int 0)))
1901    (set (match_operand:SI 0 "gpc_reg_operand" "")
1902         (not:SI (match_dup 1)))]
1903   "! TARGET_POWERPC64 && reload_completed"
1904   [(set (match_dup 0)
1905         (not:SI (match_dup 1)))
1906    (set (match_dup 2)
1907         (compare:CC (match_dup 0)
1908                     (const_int 0)))]
1909   "")
1910
1911 (define_insn ""
1912   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1913         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1914                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1915   "! TARGET_POWERPC"
1916   "{sf%I1|subf%I1c} %0,%2,%1")
1917
1918 (define_insn ""
1919   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1920         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "r,I")
1921                   (match_operand:SI 2 "gpc_reg_operand" "r,r")))]
1922   "TARGET_POWERPC"
1923   "@
1924    subf %0,%2,%1
1925    subfic %0,%2,%1")
1926
1927 (define_insn ""
1928   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1929         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1930                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1931                     (const_int 0)))
1932    (clobber (match_scratch:SI 3 "=r,r"))]
1933   "! TARGET_POWERPC"
1934   "@
1935    {sf.|subfc.} %3,%2,%1
1936    #"
1937   [(set_attr "type" "compare")
1938    (set_attr "length" "4,8")])
1939
1940 (define_insn ""
1941   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1942         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1943                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1944                     (const_int 0)))
1945    (clobber (match_scratch:SI 3 "=r,r"))]
1946   "TARGET_POWERPC && ! TARGET_POWERPC64"
1947   "@
1948    subf. %3,%2,%1
1949    #"
1950   [(set_attr "type" "compare")
1951    (set_attr "length" "4,8")])
1952
1953 (define_split
1954   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1955         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "")
1956                               (match_operand:SI 2 "gpc_reg_operand" ""))
1957                     (const_int 0)))
1958    (clobber (match_scratch:SI 3 ""))]
1959   "! TARGET_POWERPC64 && reload_completed"
1960   [(set (match_dup 3)
1961         (minus:SI (match_dup 1)
1962                   (match_dup 2)))
1963    (set (match_dup 0)
1964         (compare:CC (match_dup 3)
1965                     (const_int 0)))]
1966   "")
1967
1968 (define_insn ""
1969   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1970         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1971                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1972                     (const_int 0)))
1973    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1974         (minus:SI (match_dup 1) (match_dup 2)))]
1975   "! TARGET_POWERPC"
1976   "@
1977    {sf.|subfc.} %0,%2,%1
1978    #"
1979   [(set_attr "type" "compare")
1980    (set_attr "length" "4,8")])
1981
1982 (define_insn ""
1983   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1984         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1985                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1986                     (const_int 0)))
1987    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1988         (minus:SI (match_dup 1)
1989                   (match_dup 2)))]
1990   "TARGET_POWERPC && ! TARGET_POWERPC64"
1991   "@
1992    subf. %0,%2,%1
1993    #"
1994   [(set_attr "type" "compare")
1995    (set_attr "length" "4,8")])
1996
1997 (define_split
1998   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1999         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "")
2000                               (match_operand:SI 2 "gpc_reg_operand" ""))
2001                     (const_int 0)))
2002    (set (match_operand:SI 0 "gpc_reg_operand" "")
2003         (minus:SI (match_dup 1)
2004                   (match_dup 2)))]
2005   "! TARGET_POWERPC64 && reload_completed"
2006   [(set (match_dup 0)
2007         (minus:SI (match_dup 1)
2008                   (match_dup 2)))
2009    (set (match_dup 3)
2010         (compare:CC (match_dup 0)
2011                     (const_int 0)))]
2012   "")
2013
2014 (define_expand "subsi3"
2015   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2016         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "")
2017                   (match_operand:SI 2 "reg_or_arith_cint_operand" "")))]
2018   ""
2019   "
2020 {
2021   if (GET_CODE (operands[2]) == CONST_INT)
2022     {
2023       emit_insn (gen_addsi3 (operands[0], operands[1],
2024                              negate_rtx (SImode, operands[2])));
2025       DONE;
2026     }
2027 }")
2028
2029 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
2030 ;; instruction and some auxiliary computations.  Then we just have a single
2031 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
2032 ;; combine.
2033
2034 (define_expand "sminsi3"
2035   [(set (match_dup 3)
2036         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
2037                                 (match_operand:SI 2 "reg_or_short_operand" ""))
2038                          (const_int 0)
2039                          (minus:SI (match_dup 2) (match_dup 1))))
2040    (set (match_operand:SI 0 "gpc_reg_operand" "")
2041         (minus:SI (match_dup 2) (match_dup 3)))]
2042   "TARGET_POWER || TARGET_ISEL"
2043   "
2044 {
2045   if (TARGET_ISEL)
2046     {
2047       operands[2] = force_reg (SImode, operands[2]);
2048       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
2049       DONE;
2050     }
2051
2052   operands[3] = gen_reg_rtx (SImode);
2053 }")
2054
2055 (define_split
2056   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2057         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
2058                  (match_operand:SI 2 "reg_or_short_operand" "")))
2059    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
2060   "TARGET_POWER"
2061   [(set (match_dup 3)
2062         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
2063                          (const_int 0)
2064                          (minus:SI (match_dup 2) (match_dup 1))))
2065    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
2066   "")
2067
2068 (define_expand "smaxsi3"
2069   [(set (match_dup 3)
2070         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
2071                                 (match_operand:SI 2 "reg_or_short_operand" ""))
2072                          (const_int 0)
2073                          (minus:SI (match_dup 2) (match_dup 1))))
2074    (set (match_operand:SI 0 "gpc_reg_operand" "")
2075         (plus:SI (match_dup 3) (match_dup 1)))]
2076   "TARGET_POWER || TARGET_ISEL"
2077   "
2078 {
2079   if (TARGET_ISEL)
2080     {
2081       operands[2] = force_reg (SImode, operands[2]);
2082       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
2083       DONE;
2084     }
2085   operands[3] = gen_reg_rtx (SImode);
2086 }")
2087
2088 (define_split
2089   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2090         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
2091                  (match_operand:SI 2 "reg_or_short_operand" "")))
2092    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
2093   "TARGET_POWER"
2094   [(set (match_dup 3)
2095         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
2096                          (const_int 0)
2097                          (minus:SI (match_dup 2) (match_dup 1))))
2098    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
2099   "")
2100
2101 (define_expand "uminsi3"
2102   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2103                               (match_dup 5)))
2104    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
2105                               (match_dup 5)))
2106    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
2107                                        (const_int 0)
2108                                        (minus:SI (match_dup 4) (match_dup 3))))
2109    (set (match_operand:SI 0 "gpc_reg_operand" "")
2110         (minus:SI (match_dup 2) (match_dup 3)))]
2111   "TARGET_POWER || TARGET_ISEL"
2112   "
2113 {
2114   if (TARGET_ISEL)
2115     {
2116       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
2117       DONE;
2118     }
2119   operands[3] = gen_reg_rtx (SImode);
2120   operands[4] = gen_reg_rtx (SImode);
2121   operands[5] = GEN_INT (-2147483647 - 1);
2122 }")
2123
2124 (define_expand "umaxsi3"
2125   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2126                               (match_dup 5)))
2127    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
2128                               (match_dup 5)))
2129    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
2130                                        (const_int 0)
2131                                        (minus:SI (match_dup 4) (match_dup 3))))
2132    (set (match_operand:SI 0 "gpc_reg_operand" "")
2133         (plus:SI (match_dup 3) (match_dup 1)))]
2134   "TARGET_POWER || TARGET_ISEL"
2135   "
2136 {
2137   if (TARGET_ISEL)
2138     {
2139       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
2140       DONE;
2141     }
2142   operands[3] = gen_reg_rtx (SImode);
2143   operands[4] = gen_reg_rtx (SImode);
2144   operands[5] = GEN_INT (-2147483647 - 1);
2145 }")
2146
2147 (define_insn ""
2148   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2149         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
2150                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
2151                          (const_int 0)
2152                          (minus:SI (match_dup 2) (match_dup 1))))]
2153   "TARGET_POWER"
2154   "doz%I2 %0,%1,%2")
2155
2156 (define_insn ""
2157   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2158         (compare:CC
2159          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
2160                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
2161                           (const_int 0)
2162                           (minus:SI (match_dup 2) (match_dup 1)))
2163          (const_int 0)))
2164    (clobber (match_scratch:SI 3 "=r,r"))]
2165   "TARGET_POWER"
2166   "@
2167    doz%I2. %3,%1,%2
2168    #"
2169   [(set_attr "type" "delayed_compare")
2170    (set_attr "length" "4,8")])
2171
2172 (define_split
2173   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2174         (compare:CC
2175          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
2176                               (match_operand:SI 2 "reg_or_short_operand" ""))
2177                           (const_int 0)
2178                           (minus:SI (match_dup 2) (match_dup 1)))
2179          (const_int 0)))
2180    (clobber (match_scratch:SI 3 ""))]
2181   "TARGET_POWER && reload_completed"
2182   [(set (match_dup 3)
2183         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2184                           (const_int 0)
2185                           (minus:SI (match_dup 2) (match_dup 1))))
2186    (set (match_dup 0)
2187         (compare:CC (match_dup 3)
2188                     (const_int 0)))]
2189   "")
2190
2191 (define_insn ""
2192   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2193         (compare:CC
2194          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
2195                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
2196                           (const_int 0)
2197                           (minus:SI (match_dup 2) (match_dup 1)))
2198          (const_int 0)))
2199    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2200         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2201                          (const_int 0)
2202                          (minus:SI (match_dup 2) (match_dup 1))))]
2203   "TARGET_POWER"
2204   "@
2205    doz%I2. %0,%1,%2
2206    #"
2207   [(set_attr "type" "delayed_compare")
2208    (set_attr "length" "4,8")])
2209
2210 (define_split
2211   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2212         (compare:CC
2213          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
2214                               (match_operand:SI 2 "reg_or_short_operand" ""))
2215                           (const_int 0)
2216                           (minus:SI (match_dup 2) (match_dup 1)))
2217          (const_int 0)))
2218    (set (match_operand:SI 0 "gpc_reg_operand" "")
2219         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2220                          (const_int 0)
2221                          (minus:SI (match_dup 2) (match_dup 1))))]
2222   "TARGET_POWER && reload_completed"
2223   [(set (match_dup 0)
2224         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
2225                          (const_int 0)
2226                          (minus:SI (match_dup 2) (match_dup 1))))
2227    (set (match_dup 3)
2228         (compare:CC (match_dup 0)
2229                     (const_int 0)))]
2230   "")
2231
2232 ;; We don't need abs with condition code because such comparisons should
2233 ;; never be done.
2234 (define_expand "abssi2"
2235   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2236         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
2237   ""
2238   "
2239 {
2240   if (TARGET_ISEL)
2241     {
2242       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
2243       DONE;
2244     }
2245   else if (! TARGET_POWER)
2246     {
2247       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
2248       DONE;
2249     }
2250 }")
2251
2252 (define_insn "*abssi2_power"
2253   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2254         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
2255   "TARGET_POWER"
2256   "abs %0,%1")
2257
2258 (define_insn_and_split "abssi2_isel"
2259   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2260         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
2261    (clobber (match_scratch:SI 2 "=b"))
2262    (clobber (match_scratch:CC 3 "=y"))]
2263   "TARGET_ISEL"
2264   "#"
2265   "&& reload_completed"
2266   [(set (match_dup 2) (neg:SI (match_dup 1)))
2267    (set (match_dup 3)
2268         (compare:CC (match_dup 1)
2269                     (const_int 0)))
2270    (set (match_dup 0)
2271         (if_then_else:SI (ge (match_dup 3)
2272                              (const_int 0))
2273                          (match_dup 1)
2274                          (match_dup 2)))]
2275   "")
2276
2277 (define_insn_and_split "abssi2_nopower"
2278   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2279         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
2280    (clobber (match_scratch:SI 2 "=&r,&r"))]
2281   "! TARGET_POWER && ! TARGET_ISEL"
2282   "#"
2283   "&& reload_completed"
2284   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2285    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2286    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
2287   "")
2288
2289 (define_insn "*nabs_power"
2290   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2291         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
2292   "TARGET_POWER"
2293   "nabs %0,%1")
2294
2295 (define_insn_and_split "*nabs_nopower"
2296   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
2297         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
2298    (clobber (match_scratch:SI 2 "=&r,&r"))]
2299   "! TARGET_POWER"
2300   "#"
2301   "&& reload_completed"
2302   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
2303    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
2304    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
2305   "")
2306
2307 (define_insn "negsi2"
2308   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2309         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
2310   ""
2311   "neg %0,%1")
2312
2313 (define_insn ""
2314   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2315         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2316                     (const_int 0)))
2317    (clobber (match_scratch:SI 2 "=r,r"))]
2318   "! TARGET_POWERPC64"
2319   "@
2320    neg. %2,%1
2321    #"
2322   [(set_attr "type" "compare")
2323    (set_attr "length" "4,8")])
2324
2325 (define_split
2326   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2327         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2328                     (const_int 0)))
2329    (clobber (match_scratch:SI 2 ""))]
2330   "! TARGET_POWERPC64 && reload_completed"
2331   [(set (match_dup 2)
2332         (neg:SI (match_dup 1)))
2333    (set (match_dup 0)
2334         (compare:CC (match_dup 2)
2335                     (const_int 0)))]
2336   "")
2337
2338 (define_insn ""
2339   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2340         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2341                     (const_int 0)))
2342    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2343         (neg:SI (match_dup 1)))]
2344   "! TARGET_POWERPC64"
2345   "@
2346    neg. %0,%1
2347    #"
2348   [(set_attr "type" "compare")
2349    (set_attr "length" "4,8")])
2350
2351 (define_split
2352   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2353         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" ""))
2354                     (const_int 0)))
2355    (set (match_operand:SI 0 "gpc_reg_operand" "")
2356         (neg:SI (match_dup 1)))]
2357   "! TARGET_POWERPC64 && reload_completed"
2358   [(set (match_dup 0)
2359         (neg:SI (match_dup 1)))
2360    (set (match_dup 2)
2361         (compare:CC (match_dup 0)
2362                     (const_int 0)))]
2363   "")
2364
2365 (define_insn "ffssi2"
2366   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
2367         (ffs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
2368   ""
2369   "neg %0,%1\;and %0,%0,%1\;{cntlz|cntlzw} %0,%0\;{sfi|subfic} %0,%0,32"
2370   [(set_attr "length" "16")])
2371
2372 (define_expand "mulsi3"
2373   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2374    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2375    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
2376   ""
2377   "
2378 {
2379   if (TARGET_POWER)
2380     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
2381   else
2382     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
2383   DONE;
2384 }")
2385
2386 (define_insn "mulsi3_mq"
2387   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2388         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2389                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
2390    (clobber (match_scratch:SI 3 "=q,q"))]
2391   "TARGET_POWER"
2392   "@
2393    {muls|mullw} %0,%1,%2
2394    {muli|mulli} %0,%1,%2"
2395    [(set (attr "type") 
2396       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2397                 (const_string "imul3")
2398              (match_operand:SI 2 "short_cint_operand" "") 
2399                 (const_string "imul2")]
2400         (const_string "imul")))])
2401
2402 (define_insn "mulsi3_no_mq"
2403   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2404         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2405                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2406   "! TARGET_POWER"
2407   "@
2408    {muls|mullw} %0,%1,%2
2409    {muli|mulli} %0,%1,%2"
2410    [(set (attr "type") 
2411       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2412                 (const_string "imul3")
2413              (match_operand:SI 2 "short_cint_operand" "") 
2414                 (const_string "imul2")]
2415         (const_string "imul")))])
2416
2417 (define_insn ""
2418   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2419         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2420                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2421                     (const_int 0)))
2422    (clobber (match_scratch:SI 3 "=r,r"))
2423    (clobber (match_scratch:SI 4 "=q,q"))]
2424   "TARGET_POWER"
2425   "@
2426    {muls.|mullw.} %3,%1,%2
2427    #"
2428   [(set_attr "type" "delayed_compare")
2429    (set_attr "length" "4,8")])
2430
2431 (define_split
2432   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2433         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2434                              (match_operand:SI 2 "gpc_reg_operand" ""))
2435                     (const_int 0)))
2436    (clobber (match_scratch:SI 3 ""))
2437    (clobber (match_scratch:SI 4 ""))]
2438   "TARGET_POWER && reload_completed"
2439   [(parallel [(set (match_dup 3)
2440         (mult:SI (match_dup 1) (match_dup 2)))
2441    (clobber (match_dup 4))])
2442    (set (match_dup 0)
2443         (compare:CC (match_dup 3)
2444                     (const_int 0)))]
2445   "")
2446
2447 (define_insn ""
2448   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2449         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2450                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2451                     (const_int 0)))
2452    (clobber (match_scratch:SI 3 "=r,r"))]
2453   "! TARGET_POWER"
2454   "@
2455    {muls.|mullw.} %3,%1,%2
2456    #"
2457   [(set_attr "type" "delayed_compare")
2458    (set_attr "length" "4,8")])
2459
2460 (define_split
2461   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2462         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2463                              (match_operand:SI 2 "gpc_reg_operand" ""))
2464                     (const_int 0)))
2465    (clobber (match_scratch:SI 3 ""))]
2466   "! TARGET_POWER && reload_completed"
2467   [(set (match_dup 3)
2468         (mult:SI (match_dup 1) (match_dup 2)))
2469    (set (match_dup 0)
2470         (compare:CC (match_dup 3)
2471                     (const_int 0)))]
2472   "")
2473
2474 (define_insn ""
2475   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2476         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2477                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2478                     (const_int 0)))
2479    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2480         (mult:SI (match_dup 1) (match_dup 2)))
2481    (clobber (match_scratch:SI 4 "=q,q"))]
2482   "TARGET_POWER"
2483   "@
2484    {muls.|mullw.} %0,%1,%2
2485    #"
2486   [(set_attr "type" "delayed_compare")
2487    (set_attr "length" "4,8")])
2488
2489 (define_split
2490   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2491         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2492                              (match_operand:SI 2 "gpc_reg_operand" ""))
2493                     (const_int 0)))
2494    (set (match_operand:SI 0 "gpc_reg_operand" "")
2495         (mult:SI (match_dup 1) (match_dup 2)))
2496    (clobber (match_scratch:SI 4 ""))]
2497   "TARGET_POWER && reload_completed"
2498   [(parallel [(set (match_dup 0)
2499         (mult:SI (match_dup 1) (match_dup 2)))
2500    (clobber (match_dup 4))])
2501    (set (match_dup 3)
2502         (compare:CC (match_dup 0)
2503                     (const_int 0)))]
2504   "")
2505
2506 (define_insn ""
2507   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2508         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2509                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2510                     (const_int 0)))
2511    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2512         (mult:SI (match_dup 1) (match_dup 2)))]
2513   "! TARGET_POWER"
2514   "@
2515    {muls.|mullw.} %0,%1,%2
2516    #"
2517   [(set_attr "type" "delayed_compare")
2518    (set_attr "length" "4,8")])
2519
2520 (define_split
2521   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2522         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2523                              (match_operand:SI 2 "gpc_reg_operand" ""))
2524                     (const_int 0)))
2525    (set (match_operand:SI 0 "gpc_reg_operand" "")
2526         (mult:SI (match_dup 1) (match_dup 2)))]
2527   "! TARGET_POWER && reload_completed"
2528   [(set (match_dup 0)
2529         (mult:SI (match_dup 1) (match_dup 2)))
2530    (set (match_dup 3)
2531         (compare:CC (match_dup 0)
2532                     (const_int 0)))]
2533   "")
2534
2535 ;; Operand 1 is divided by operand 2; quotient goes to operand
2536 ;; 0 and remainder to operand 3.
2537 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
2538
2539 (define_expand "divmodsi4"
2540   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2541                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2542                            (match_operand:SI 2 "gpc_reg_operand" "")))
2543               (set (match_operand:SI 3 "gpc_reg_operand" "")
2544                    (mod:SI (match_dup 1) (match_dup 2)))])]
2545   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
2546   "
2547 {
2548   if (! TARGET_POWER && ! TARGET_POWERPC)
2549     {
2550       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2551       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2552       emit_insn (gen_divss_call ());
2553       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2554       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2555       DONE;
2556     }
2557 }")
2558
2559 (define_insn ""
2560   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2561         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2562                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2563    (set (match_operand:SI 3 "gpc_reg_operand" "=q")
2564         (mod:SI (match_dup 1) (match_dup 2)))]
2565   "TARGET_POWER"
2566   "divs %0,%1,%2"
2567   [(set_attr "type" "idiv")])
2568
2569 (define_expand "udivsi3"
2570   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2571         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2572                  (match_operand:SI 2 "gpc_reg_operand" "")))]
2573   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
2574   "
2575 {
2576   if (! TARGET_POWER && ! TARGET_POWERPC)
2577     {
2578       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2579       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2580       emit_insn (gen_quous_call ());
2581       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2582       DONE;
2583     }
2584   else if (TARGET_POWER)
2585     {
2586       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
2587       DONE;
2588     }
2589 }")
2590
2591 (define_insn "udivsi3_mq"
2592   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2593         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2594                  (match_operand:SI 2 "gpc_reg_operand" "r")))
2595    (clobber (match_scratch:SI 3 "=q"))]
2596   "TARGET_POWERPC && TARGET_POWER"
2597   "divwu %0,%1,%2"
2598   [(set_attr "type" "idiv")])
2599
2600 (define_insn "*udivsi3_no_mq"
2601   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2602         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2603                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
2604   "TARGET_POWERPC && ! TARGET_POWER"
2605   "divwu %0,%1,%2"
2606   [(set_attr "type" "idiv")])
2607
2608 ;; For powers of two we can do srai/aze for divide and then adjust for
2609 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
2610 ;; used; for PowerPC, force operands into register and do a normal divide;
2611 ;; for AIX common-mode, use quoss call on register operands.
2612 (define_expand "divsi3"
2613   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2614         (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2615                 (match_operand:SI 2 "reg_or_cint_operand" "")))]
2616   ""
2617   "
2618 {
2619   if (GET_CODE (operands[2]) == CONST_INT
2620       && INTVAL (operands[2]) > 0
2621       && exact_log2 (INTVAL (operands[2])) >= 0)
2622     ;
2623   else if (TARGET_POWERPC)
2624     {
2625       operands[2] = force_reg (SImode, operands[2]);
2626       if (TARGET_POWER)
2627         {
2628           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
2629           DONE;
2630         }
2631     }
2632   else if (TARGET_POWER)
2633     FAIL;
2634   else
2635     {
2636       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2637       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2638       emit_insn (gen_quoss_call ());
2639       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2640       DONE;
2641     }
2642 }")
2643
2644 (define_insn "divsi3_mq"
2645   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2646         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2647                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2648    (clobber (match_scratch:SI 3 "=q"))]
2649   "TARGET_POWERPC && TARGET_POWER"
2650   "divw %0,%1,%2"
2651   [(set_attr "type" "idiv")])
2652
2653 (define_insn "*divsi3_no_mq"
2654   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2655         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2656                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
2657   "TARGET_POWERPC && ! TARGET_POWER"
2658   "divw %0,%1,%2"
2659   [(set_attr "type" "idiv")])
2660
2661 (define_expand "modsi3"
2662   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2663    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2664    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
2665   ""
2666   "
2667 {
2668   int i;
2669   rtx temp1;
2670   rtx temp2;
2671
2672   if (GET_CODE (operands[2]) != CONST_INT
2673       || INTVAL (operands[2]) <= 0
2674       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2675     FAIL;
2676
2677   temp1 = gen_reg_rtx (SImode);
2678   temp2 = gen_reg_rtx (SImode);
2679
2680   emit_insn (gen_divsi3 (temp1, operands[1], operands[2]));
2681   emit_insn (gen_ashlsi3 (temp2, temp1, GEN_INT (i)));
2682   emit_insn (gen_subsi3 (operands[0], operands[1], temp2));
2683   DONE;
2684 }")
2685
2686 (define_insn ""
2687   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2688         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2689                 (match_operand:SI 2 "exact_log2_cint_operand" "N")))]
2690   ""
2691   "{srai|srawi} %0,%1,%p2\;{aze|addze} %0,%0"
2692   [(set_attr "length" "8")])
2693
2694 (define_insn ""
2695   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2696         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2697                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
2698                     (const_int 0)))
2699    (clobber (match_scratch:SI 3 "=r,r"))]
2700   ""
2701   "@
2702    {srai|srawi} %3,%1,%p2\;{aze.|addze.} %3,%3
2703    #"
2704   [(set_attr "type" "compare")
2705    (set_attr "length" "8,12")])
2706
2707 (define_split
2708   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2709         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2710                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
2711                     (const_int 0)))
2712    (clobber (match_scratch:SI 3 ""))]
2713   "reload_completed"
2714   [(set (match_dup 3)
2715         (div:SI (match_dup 1) (match_dup 2)))
2716    (set (match_dup 0)
2717         (compare:CC (match_dup 3)
2718                     (const_int 0)))]
2719   "")
2720
2721 (define_insn ""
2722   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2723         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2724                             (match_operand:SI 2 "exact_log2_cint_operand" "N,N"))
2725                     (const_int 0)))
2726    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2727         (div:SI (match_dup 1) (match_dup 2)))]
2728   ""
2729   "@
2730    {srai|srawi} %0,%1,%p2\;{aze.|addze.} %0,%0
2731    #"
2732   [(set_attr "type" "compare")
2733    (set_attr "length" "8,12")])
2734
2735 (define_split
2736   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2737         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2738                             (match_operand:SI 2 "exact_log2_cint_operand" ""))
2739                     (const_int 0)))
2740    (set (match_operand:SI 0 "gpc_reg_operand" "")
2741         (div:SI (match_dup 1) (match_dup 2)))]
2742   "reload_completed"
2743   [(set (match_dup 0)
2744         (div:SI (match_dup 1) (match_dup 2)))
2745    (set (match_dup 3)
2746         (compare:CC (match_dup 0)
2747                     (const_int 0)))]
2748   "")
2749
2750 (define_insn ""
2751   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2752         (udiv:SI
2753          (plus:DI (ashift:DI
2754                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
2755                    (const_int 32))
2756                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
2757          (match_operand:SI 3 "gpc_reg_operand" "r")))
2758    (set (match_operand:SI 2 "register_operand" "=*q")
2759         (umod:SI
2760          (plus:DI (ashift:DI
2761                    (zero_extend:DI (match_dup 1)) (const_int 32))
2762                   (zero_extend:DI (match_dup 4)))
2763          (match_dup 3)))]
2764   "TARGET_POWER"
2765   "div %0,%1,%3"
2766   [(set_attr "type" "idiv")])
2767
2768 ;; To do unsigned divide we handle the cases of the divisor looking like a
2769 ;; negative number.  If it is a constant that is less than 2**31, we don't
2770 ;; have to worry about the branches.  So make a few subroutines here.
2771 ;;
2772 ;; First comes the normal case.
2773 (define_expand "udivmodsi4_normal"
2774   [(set (match_dup 4) (const_int 0))
2775    (parallel [(set (match_operand:SI 0 "" "")
2776                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2777                                                 (const_int 32))
2778                                      (zero_extend:DI (match_operand:SI 1 "" "")))
2779                             (match_operand:SI 2 "" "")))
2780               (set (match_operand:SI 3 "" "")
2781                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2782                                                 (const_int 32))
2783                                      (zero_extend:DI (match_dup 1)))
2784                             (match_dup 2)))])]
2785   "TARGET_POWER"
2786   "
2787 { operands[4] = gen_reg_rtx (SImode); }")
2788
2789 ;; This handles the branches.
2790 (define_expand "udivmodsi4_tests"
2791   [(set (match_operand:SI 0 "" "") (const_int 0))
2792    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
2793    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
2794    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
2795                            (label_ref (match_operand:SI 4 "" "")) (pc)))
2796    (set (match_dup 0) (const_int 1))
2797    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
2798    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
2799    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
2800                            (label_ref (match_dup 4)) (pc)))]
2801   "TARGET_POWER"
2802   "
2803 { operands[5] = gen_reg_rtx (CCUNSmode);
2804   operands[6] = gen_reg_rtx (CCmode);
2805 }")
2806
2807 (define_expand "udivmodsi4"
2808   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2809                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2810                             (match_operand:SI 2 "reg_or_cint_operand" "")))
2811               (set (match_operand:SI 3 "gpc_reg_operand" "")
2812                    (umod:SI (match_dup 1) (match_dup 2)))])]
2813   ""
2814   "
2815 {
2816   rtx label = 0;
2817
2818   if (! TARGET_POWER)
2819     {
2820       if (! TARGET_POWERPC)
2821         {
2822           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2823           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2824           emit_insn (gen_divus_call ());
2825           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2826           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2827           DONE;
2828         }
2829       else
2830         FAIL;
2831     }
2832
2833   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
2834     {
2835       operands[2] = force_reg (SImode, operands[2]);
2836       label = gen_label_rtx ();
2837       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
2838                                   operands[3], label));
2839     }
2840   else
2841     operands[2] = force_reg (SImode, operands[2]);
2842
2843   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
2844                                operands[3]));
2845   if (label)
2846     emit_label (label);
2847
2848   DONE;
2849 }")
2850
2851 ;; AIX architecture-independent common-mode multiply (DImode),
2852 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
2853 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
2854 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
2855 ;; assumed unused if generating common-mode, so ignore.
2856 (define_insn "mulh_call"
2857   [(set (reg:SI 3)
2858         (truncate:SI
2859          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
2860                                (sign_extend:DI (reg:SI 4)))
2861                       (const_int 32))))
2862    (clobber (match_scratch:SI 0 "=l"))]
2863   "! TARGET_POWER && ! TARGET_POWERPC"
2864   "bla __mulh"
2865   [(set_attr "type" "imul")])
2866
2867 (define_insn "mull_call"
2868   [(set (reg:DI 3)
2869         (mult:DI (sign_extend:DI (reg:SI 3))
2870                  (sign_extend:DI (reg:SI 4))))
2871    (clobber (match_scratch:SI 0 "=l"))
2872    (clobber (reg:SI 0))]
2873   "! TARGET_POWER && ! TARGET_POWERPC"
2874   "bla __mull"
2875   [(set_attr "type" "imul")])
2876
2877 (define_insn "divss_call"
2878   [(set (reg:SI 3)
2879         (div:SI (reg:SI 3) (reg:SI 4)))
2880    (set (reg:SI 4)
2881         (mod:SI (reg:SI 3) (reg:SI 4)))
2882    (clobber (match_scratch:SI 0 "=l"))
2883    (clobber (reg:SI 0))]
2884   "! TARGET_POWER && ! TARGET_POWERPC"
2885   "bla __divss"
2886   [(set_attr "type" "idiv")])
2887
2888 (define_insn "divus_call"
2889   [(set (reg:SI 3)
2890         (udiv:SI (reg:SI 3) (reg:SI 4)))
2891    (set (reg:SI 4)
2892         (umod:SI (reg:SI 3) (reg:SI 4)))
2893    (clobber (match_scratch:SI 0 "=l"))
2894    (clobber (reg:SI 0))
2895    (clobber (match_scratch:CC 1 "=x"))
2896    (clobber (reg:CC 69))]
2897   "! TARGET_POWER && ! TARGET_POWERPC"
2898   "bla __divus"
2899   [(set_attr "type" "idiv")])
2900
2901 (define_insn "quoss_call"
2902   [(set (reg:SI 3)
2903         (div:SI (reg:SI 3) (reg:SI 4)))
2904    (clobber (match_scratch:SI 0 "=l"))]
2905   "! TARGET_POWER && ! TARGET_POWERPC"
2906   "bla __quoss"
2907   [(set_attr "type" "idiv")])
2908
2909 (define_insn "quous_call"
2910   [(set (reg:SI 3)
2911         (udiv:SI (reg:SI 3) (reg:SI 4)))
2912    (clobber (match_scratch:SI 0 "=l"))
2913    (clobber (reg:SI 0))
2914    (clobber (match_scratch:CC 1 "=x"))
2915    (clobber (reg:CC 69))]
2916   "! TARGET_POWER && ! TARGET_POWERPC"
2917   "bla __quous"
2918   [(set_attr "type" "idiv")])
2919 \f
2920 ;; Logical instructions
2921 ;; The logical instructions are mostly combined by using match_operator,
2922 ;; but the plain AND insns are somewhat different because there is no
2923 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2924 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2925
2926 (define_insn "andsi3"
2927   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2928         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2929                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2930    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2931   ""
2932   "@
2933    and %0,%1,%2
2934    {rlinm|rlwinm} %0,%1,0,%m2,%M2
2935    {andil.|andi.} %0,%1,%b2
2936    {andiu.|andis.} %0,%1,%u2")
2937
2938 ;; Note to set cr's other than cr0 we do the and immediate and then
2939 ;; the test again -- this avoids a mfcr which on the higher end
2940 ;; machines causes an execution serialization
2941
2942 (define_insn "*andsi3_internal2"
2943   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2944         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2945                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2946                     (const_int 0)))
2947    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2948    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2949   "! TARGET_POWERPC64"
2950   "@
2951    and. %3,%1,%2
2952    {andil.|andi.} %3,%1,%b2
2953    {andiu.|andis.} %3,%1,%u2
2954    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2955    #
2956    #
2957    #
2958    #"
2959   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2960    (set_attr "length" "4,4,4,4,8,8,8,8")])
2961
2962 (define_insn "*andsi3_internal3"
2963   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2964         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2965                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2966                     (const_int 0)))
2967    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2968    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2969   "TARGET_POWERPC64"
2970   "@
2971    #
2972    {andil.|andi.} %3,%1,%b2
2973    {andiu.|andis.} %3,%1,%u2
2974    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2975    #
2976    #
2977    #
2978    #"
2979   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2980    (set_attr "length" "8,4,4,4,8,8,8,8")])
2981
2982 (define_split
2983   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2984         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2985                             (match_operand:SI 2 "and_operand" ""))
2986                     (const_int 0)))
2987    (clobber (match_scratch:SI 3 ""))
2988    (clobber (match_scratch:CC 4 ""))]
2989   "reload_completed"
2990   [(parallel [(set (match_dup 3)
2991                    (and:SI (match_dup 1)
2992                            (match_dup 2)))
2993               (clobber (match_dup 4))])
2994    (set (match_dup 0)
2995         (compare:CC (match_dup 3)
2996                     (const_int 0)))]
2997   "")
2998
2999 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
3000 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
3001
3002 (define_split
3003   [(set (match_operand:CC 0 "cc_reg_operand" "")
3004         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3005                             (match_operand:SI 2 "gpc_reg_operand" ""))
3006                     (const_int 0)))
3007    (clobber (match_scratch:SI 3 ""))
3008    (clobber (match_scratch:CC 4 ""))]
3009   "TARGET_POWERPC64 && reload_completed"
3010   [(parallel [(set (match_dup 3)
3011                    (and:SI (match_dup 1)
3012                            (match_dup 2)))
3013               (clobber (match_dup 4))])
3014    (set (match_dup 0)
3015         (compare:CC (match_dup 3)
3016                     (const_int 0)))]
3017   "")
3018
3019 (define_insn "*andsi3_internal4"
3020   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3021         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3022                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3023                     (const_int 0)))
3024    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
3025         (and:SI (match_dup 1)
3026                 (match_dup 2)))
3027    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3028   "! TARGET_POWERPC64"
3029   "@
3030    and. %0,%1,%2
3031    {andil.|andi.} %0,%1,%b2
3032    {andiu.|andis.} %0,%1,%u2
3033    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
3034    #
3035    #
3036    #
3037    #"
3038   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
3039    (set_attr "length" "4,4,4,4,8,8,8,8")])
3040
3041 (define_insn "*andsi3_internal5"
3042   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
3043         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
3044                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
3045                     (const_int 0)))
3046    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
3047         (and:SI (match_dup 1)
3048                 (match_dup 2)))
3049    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
3050   "TARGET_POWERPC64"
3051   "@
3052    #
3053    {andil.|andi.} %0,%1,%b2
3054    {andiu.|andis.} %0,%1,%u2
3055    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
3056    #
3057    #
3058    #
3059    #"
3060   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
3061    (set_attr "length" "8,4,4,4,8,8,8,8")])
3062
3063 (define_split
3064   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3065         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3066                             (match_operand:SI 2 "and_operand" ""))
3067                     (const_int 0)))
3068    (set (match_operand:SI 0 "gpc_reg_operand" "")
3069         (and:SI (match_dup 1)
3070                 (match_dup 2)))
3071    (clobber (match_scratch:CC 4 ""))]
3072   "reload_completed"
3073   [(parallel [(set (match_dup 0)
3074                    (and:SI (match_dup 1)
3075                            (match_dup 2)))
3076               (clobber (match_dup 4))])
3077    (set (match_dup 3)
3078         (compare:CC (match_dup 0)
3079                     (const_int 0)))]
3080   "")
3081
3082 (define_split
3083   [(set (match_operand:CC 3 "cc_reg_operand" "")
3084         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
3085                             (match_operand:SI 2 "gpc_reg_operand" ""))
3086                     (const_int 0)))
3087    (set (match_operand:SI 0 "gpc_reg_operand" "")
3088         (and:SI (match_dup 1)
3089                 (match_dup 2)))
3090    (clobber (match_scratch:CC 4 ""))]
3091   "TARGET_POWERPC64 && reload_completed"
3092   [(parallel [(set (match_dup 0)
3093                    (and:SI (match_dup 1)
3094                            (match_dup 2)))
3095               (clobber (match_dup 4))])
3096    (set (match_dup 3)
3097         (compare:CC (match_dup 0)
3098                     (const_int 0)))]
3099   "")
3100
3101 ;; Handle the PowerPC64 rlwinm corner case
3102
3103 (define_insn_and_split "*andsi3_internal6"
3104   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3105         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3106                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
3107   "TARGET_POWERPC64"
3108   "#"
3109   "TARGET_POWERPC64"
3110   [(set (match_dup 0)
3111         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
3112                 (match_dup 4)))
3113    (set (match_dup 0)
3114         (rotate:SI (match_dup 0) (match_dup 5)))]
3115   "
3116 {
3117   int mb = extract_MB (operands[2]);
3118   int me = extract_ME (operands[2]);
3119   operands[3] = GEN_INT (me + 1);
3120   operands[5] = GEN_INT (32 - (me + 1));
3121   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
3122 }"
3123   [(set_attr "length" "8")])
3124
3125 (define_insn_and_split "*andsi3_internal7"
3126   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
3127         (compare:CC (and:SI (match_operand:SI 0 "gpc_reg_operand" "r,r")
3128                             (match_operand:SI 1 "mask_operand_wrap" "i,i"))
3129                     (const_int 0)))
3130    (clobber (match_scratch:SI 3 "=r,r"))]
3131   "TARGET_POWERPC64"
3132   "#"
3133   "TARGET_POWERPC64"
3134   [(parallel [(set (match_dup 2)
3135                    (compare:CC (and:SI (rotate:SI (match_dup 0) (match_dup 4))
3136                                        (match_dup 5))
3137                                (const_int 0)))
3138               (clobber (match_dup 3))])]
3139   "
3140 {
3141   int mb = extract_MB (operands[1]);
3142   int me = extract_ME (operands[1]);
3143   operands[4] = GEN_INT (me + 1);
3144   operands[5] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
3145 }"
3146   [(set_attr "type" "delayed_compare,compare")
3147    (set_attr "length" "4,8")])
3148
3149 (define_insn_and_split "*andsi3_internal8"
3150   [(set (match_operand:CC 3 "cc_reg_operand" "=x,??y")
3151         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3152                             (match_operand:SI 2 "mask_operand_wrap" "i,i"))
3153                     (const_int 0)))
3154    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3155         (and:SI (match_dup 1)
3156                 (match_dup 2)))]
3157   "TARGET_POWERPC64"
3158   "#"
3159   "TARGET_POWERPC64"
3160   [(parallel [(set (match_dup 3)
3161                    (compare:CC (and:SI (rotate:SI (match_dup 1) (match_dup 4))
3162                                        (match_dup 5))
3163                                (const_int 0)))
3164               (set (match_dup 0)
3165                    (and:SI (rotate:SI (match_dup 1) (match_dup 4))
3166                            (match_dup 5)))])
3167    (set (match_dup 0)
3168         (rotate:SI (match_dup 0) (match_dup 6)))]
3169   "
3170 {
3171   int mb = extract_MB (operands[2]);
3172   int me = extract_ME (operands[2]);
3173   operands[4] = GEN_INT (me + 1);
3174   operands[6] = GEN_INT (32 - (me + 1));
3175   operands[5] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
3176 }"
3177   [(set_attr "type" "delayed_compare,compare")
3178    (set_attr "length" "8,12")])
3179
3180 (define_expand "iorsi3"
3181   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3182         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
3183                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3184   ""
3185   "
3186 {
3187   if (GET_CODE (operands[2]) == CONST_INT
3188       && ! logical_operand (operands[2], SImode))
3189     {
3190       HOST_WIDE_INT value = INTVAL (operands[2]);
3191       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
3192                  ? operands[0] : gen_reg_rtx (SImode));
3193
3194       emit_insn (gen_iorsi3 (tmp, operands[1],
3195                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3196       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3197       DONE;
3198     }
3199 }")
3200
3201 (define_expand "xorsi3"
3202   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3203         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
3204                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
3205   ""
3206   "
3207 {
3208   if (GET_CODE (operands[2]) == CONST_INT
3209       && ! logical_operand (operands[2], SImode))
3210     {
3211       HOST_WIDE_INT value = INTVAL (operands[2]);
3212       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
3213                  ? operands[0] : gen_reg_rtx (SImode));
3214
3215       emit_insn (gen_xorsi3 (tmp, operands[1],
3216                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
3217       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
3218       DONE;
3219     }
3220 }")
3221
3222 (define_insn "*boolsi3_internal1"
3223   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
3224         (match_operator:SI 3 "boolean_or_operator"
3225          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
3226           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
3227   ""
3228   "@
3229    %q3 %0,%1,%2
3230    {%q3il|%q3i} %0,%1,%b2
3231    {%q3iu|%q3is} %0,%1,%u2")
3232
3233 (define_insn "*boolsi3_internal2"
3234   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3235         (compare:CC (match_operator:SI 4 "boolean_or_operator"
3236          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3237           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3238          (const_int 0)))
3239    (clobber (match_scratch:SI 3 "=r,r"))]
3240   "! TARGET_POWERPC64"
3241   "@
3242    %q4. %3,%1,%2
3243    #"
3244   [(set_attr "type" "compare")
3245    (set_attr "length" "4,8")])
3246
3247 (define_split
3248   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3249         (compare:CC (match_operator:SI 4 "boolean_operator"
3250          [(match_operand:SI 1 "gpc_reg_operand" "")
3251           (match_operand:SI 2 "gpc_reg_operand" "")])
3252          (const_int 0)))
3253    (clobber (match_scratch:SI 3 ""))]
3254   "! TARGET_POWERPC64 && reload_completed"
3255   [(set (match_dup 3) (match_dup 4))
3256    (set (match_dup 0)
3257         (compare:CC (match_dup 3)
3258                     (const_int 0)))]
3259   "")
3260
3261 (define_insn "*boolsi3_internal3"
3262   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3263         (compare:CC (match_operator:SI 4 "boolean_operator"
3264          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
3265           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3266          (const_int 0)))
3267    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3268         (match_dup 4))]
3269   "! TARGET_POWERPC64"
3270   "@
3271    %q4. %0,%1,%2
3272    #"
3273   [(set_attr "type" "compare")
3274    (set_attr "length" "4,8")])
3275
3276 (define_split
3277   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3278         (compare:CC (match_operator:SI 4 "boolean_operator"
3279          [(match_operand:SI 1 "gpc_reg_operand" "")
3280           (match_operand:SI 2 "gpc_reg_operand" "")])
3281          (const_int 0)))
3282    (set (match_operand:SI 0 "gpc_reg_operand" "")
3283         (match_dup 4))]
3284   "! TARGET_POWERPC64 && reload_completed"
3285   [(set (match_dup 0) (match_dup 4))
3286    (set (match_dup 3)
3287         (compare:CC (match_dup 0)
3288                     (const_int 0)))]
3289   "")
3290
3291 ;; Split an logical operation that we can't do in one insn into two insns, 
3292 ;; each of which does one 16-bit part.  This is used by combine.
3293
3294 (define_split
3295   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3296         (match_operator:SI 3 "boolean_or_operator"
3297          [(match_operand:SI 1 "gpc_reg_operand" "")
3298           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
3299   ""
3300   [(set (match_dup 0) (match_dup 4))
3301    (set (match_dup 0) (match_dup 5))]
3302 "
3303 {
3304   rtx i;
3305   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
3306   operands[4] = gen_rtx (GET_CODE (operands[3]), SImode,
3307                          operands[1], i);
3308   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
3309   operands[5] = gen_rtx (GET_CODE (operands[3]), SImode,
3310                          operands[0], i);
3311 }")
3312
3313 (define_insn "*boolcsi3_internal1"
3314   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3315         (match_operator:SI 3 "boolean_operator"
3316          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3317           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
3318   ""
3319   "%q3 %0,%2,%1")
3320
3321 (define_insn "*boolcsi3_internal2"
3322   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3323         (compare:CC (match_operator:SI 4 "boolean_operator"
3324          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3325           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3326          (const_int 0)))
3327    (clobber (match_scratch:SI 3 "=r,r"))]
3328   "! TARGET_POWERPC64"
3329   "@
3330    %q4. %3,%2,%1
3331    #"
3332   [(set_attr "type" "compare")
3333    (set_attr "length" "4,8")])
3334
3335 (define_split
3336   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3337         (compare:CC (match_operator:SI 4 "boolean_operator"
3338          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3339           (match_operand:SI 2 "gpc_reg_operand" "")])
3340          (const_int 0)))
3341    (clobber (match_scratch:SI 3 ""))]
3342   "! TARGET_POWERPC64 && reload_completed"
3343   [(set (match_dup 3) (match_dup 4))
3344    (set (match_dup 0)
3345         (compare:CC (match_dup 3)
3346                     (const_int 0)))]
3347   "")
3348
3349 (define_insn "*boolcsi3_internal3"
3350   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3351         (compare:CC (match_operator:SI 4 "boolean_operator"
3352          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3353           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3354          (const_int 0)))
3355    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3356         (match_dup 4))]
3357   "! TARGET_POWERPC64"
3358   "@
3359    %q4. %0,%2,%1
3360    #"
3361   [(set_attr "type" "compare")
3362    (set_attr "length" "4,8")])
3363
3364 (define_split
3365   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3366         (compare:CC (match_operator:SI 4 "boolean_operator"
3367          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3368           (match_operand:SI 2 "gpc_reg_operand" "")])
3369          (const_int 0)))
3370    (set (match_operand:SI 0 "gpc_reg_operand" "")
3371         (match_dup 4))]
3372   "! TARGET_POWERPC64 && reload_completed"
3373   [(set (match_dup 0) (match_dup 4))
3374    (set (match_dup 3)
3375         (compare:CC (match_dup 0)
3376                     (const_int 0)))]
3377   "")
3378
3379 (define_insn "*boolccsi3_internal1"
3380   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3381         (match_operator:SI 3 "boolean_operator"
3382          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3383           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3384   ""
3385   "%q3 %0,%1,%2")
3386
3387 (define_insn "*boolccsi3_internal2"
3388   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3389         (compare:CC (match_operator:SI 4 "boolean_operator"
3390          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3391           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3392          (const_int 0)))
3393    (clobber (match_scratch:SI 3 "=r,r"))]
3394   "! TARGET_POWERPC64"
3395   "@
3396    %q4. %3,%1,%2
3397    #"
3398   [(set_attr "type" "compare")
3399    (set_attr "length" "4,8")])
3400
3401 (define_split
3402   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3403         (compare:CC (match_operator:SI 4 "boolean_operator"
3404          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3405           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3406          (const_int 0)))
3407    (clobber (match_scratch:SI 3 ""))]
3408   "! TARGET_POWERPC64 && reload_completed"
3409   [(set (match_dup 3) (match_dup 4))
3410    (set (match_dup 0)
3411         (compare:CC (match_dup 3)
3412                     (const_int 0)))]
3413   "")
3414
3415 (define_insn "*boolccsi3_internal3"
3416   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3417         (compare:CC (match_operator:SI 4 "boolean_operator"
3418          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3419           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3420          (const_int 0)))
3421    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3422         (match_dup 4))]
3423   "! TARGET_POWERPC64"
3424   "@
3425    %q4. %0,%1,%2
3426    #"
3427   [(set_attr "type" "compare")
3428    (set_attr "length" "4,8")])
3429
3430 (define_split
3431   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3432         (compare:CC (match_operator:SI 4 "boolean_operator"
3433          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3434           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3435          (const_int 0)))
3436    (set (match_operand:SI 0 "gpc_reg_operand" "")
3437         (match_dup 4))]
3438   "! TARGET_POWERPC64 && reload_completed"
3439   [(set (match_dup 0) (match_dup 4))
3440    (set (match_dup 3)
3441         (compare:CC (match_dup 0)
3442                     (const_int 0)))]
3443   "")
3444
3445 ;; maskir insn.  We need four forms because things might be in arbitrary
3446 ;; orders.  Don't define forms that only set CR fields because these
3447 ;; would modify an input register.
3448
3449 (define_insn "*maskir_internal1"
3450   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3451         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3452                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3453                 (and:SI (match_dup 2)
3454                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
3455   "TARGET_POWER"
3456   "maskir %0,%3,%2")
3457
3458 (define_insn "*maskir_internal2"
3459   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3460         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3461                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3462                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3463                         (match_dup 2))))]
3464   "TARGET_POWER"
3465   "maskir %0,%3,%2")
3466
3467 (define_insn "*maskir_internal3"
3468   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3469         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
3470                         (match_operand:SI 3 "gpc_reg_operand" "r"))
3471                 (and:SI (not:SI (match_dup 2))
3472                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3473   "TARGET_POWER"
3474   "maskir %0,%3,%2")
3475
3476 (define_insn "*maskir_internal4"
3477   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3478         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3479                         (match_operand:SI 2 "gpc_reg_operand" "r"))
3480                 (and:SI (not:SI (match_dup 2))
3481                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3482   "TARGET_POWER"
3483   "maskir %0,%3,%2")
3484
3485 (define_insn "*maskir_internal5"
3486   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3487         (compare:CC
3488          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3489                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3490                  (and:SI (match_dup 2)
3491                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
3492          (const_int 0)))
3493    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3494         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3495                 (and:SI (match_dup 2) (match_dup 3))))]
3496   "TARGET_POWER"
3497   "@
3498    maskir. %0,%3,%2
3499    #"
3500   [(set_attr "type" "compare")
3501    (set_attr "length" "4,8")])
3502
3503 (define_split
3504   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3505         (compare:CC
3506          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3507                          (match_operand:SI 1 "gpc_reg_operand" ""))
3508                  (and:SI (match_dup 2)
3509                          (match_operand:SI 3 "gpc_reg_operand" "")))
3510          (const_int 0)))
3511    (set (match_operand:SI 0 "gpc_reg_operand" "")
3512         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3513                 (and:SI (match_dup 2) (match_dup 3))))]
3514   "TARGET_POWER && reload_completed"
3515   [(set (match_dup 0)
3516         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3517                 (and:SI (match_dup 2) (match_dup 3))))
3518    (set (match_dup 4)
3519         (compare:CC (match_dup 0)
3520                     (const_int 0)))]
3521   "")
3522
3523 (define_insn "*maskir_internal6"
3524   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3525         (compare:CC
3526          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3527                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3528                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3529                          (match_dup 2)))
3530          (const_int 0)))
3531    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3532         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3533                 (and:SI (match_dup 3) (match_dup 2))))]
3534   "TARGET_POWER"
3535   "@
3536    maskir. %0,%3,%2
3537    #"
3538   [(set_attr "type" "compare")
3539    (set_attr "length" "4,8")])
3540
3541 (define_split
3542   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3543         (compare:CC
3544          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3545                          (match_operand:SI 1 "gpc_reg_operand" ""))
3546                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3547                          (match_dup 2)))
3548          (const_int 0)))
3549    (set (match_operand:SI 0 "gpc_reg_operand" "")
3550         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3551                 (and:SI (match_dup 3) (match_dup 2))))]
3552   "TARGET_POWER && reload_completed"
3553   [(set (match_dup 0)
3554         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3555                 (and:SI (match_dup 3) (match_dup 2))))
3556    (set (match_dup 4)
3557         (compare:CC (match_dup 0)
3558                     (const_int 0)))]
3559   "")
3560
3561 (define_insn "*maskir_internal7"
3562   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3563         (compare:CC
3564          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
3565                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
3566                  (and:SI (not:SI (match_dup 2))
3567                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3568          (const_int 0)))
3569    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3570         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3571                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3572   "TARGET_POWER"
3573   "@
3574    maskir. %0,%3,%2
3575    #"
3576   [(set_attr "type" "compare")
3577    (set_attr "length" "4,8")])
3578
3579 (define_split
3580   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3581         (compare:CC
3582          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
3583                          (match_operand:SI 3 "gpc_reg_operand" ""))
3584                  (and:SI (not:SI (match_dup 2))
3585                          (match_operand:SI 1 "gpc_reg_operand" "")))
3586          (const_int 0)))
3587    (set (match_operand:SI 0 "gpc_reg_operand" "")
3588         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3589                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3590   "TARGET_POWER && reload_completed"
3591   [(set (match_dup 0)
3592         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3593                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3594    (set (match_dup 4)
3595         (compare:CC (match_dup 0)
3596                     (const_int 0)))]
3597   "")
3598
3599 (define_insn "*maskir_internal8"
3600   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3601         (compare:CC
3602          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3603                          (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3604                  (and:SI (not:SI (match_dup 2))
3605                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3606          (const_int 0)))
3607    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3608         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3609                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3610   "TARGET_POWER"
3611   "@
3612    maskir. %0,%3,%2
3613    #"
3614   [(set_attr "type" "compare")
3615    (set_attr "length" "4,8")])
3616 \f
3617 (define_split
3618   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3619         (compare:CC
3620          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3621                          (match_operand:SI 2 "gpc_reg_operand" ""))
3622                  (and:SI (not:SI (match_dup 2))
3623                          (match_operand:SI 1 "gpc_reg_operand" "")))
3624          (const_int 0)))
3625    (set (match_operand:SI 0 "gpc_reg_operand" "")
3626         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3627                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3628   "TARGET_POWER && reload_completed"
3629   [(set (match_dup 0)
3630         (ior:SI (and:SI (match_dup 3) (match_dup 2))
3631                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3632    (set (match_dup 4)
3633         (compare:CC (match_dup 0)
3634                     (const_int 0)))]
3635   "")
3636
3637 ;; Rotate and shift insns, in all their variants.  These support shifts,
3638 ;; field inserts and extracts, and various combinations thereof.
3639 (define_expand "insv"
3640   [(set (zero_extract (match_operand 0 "gpc_reg_operand" "")
3641                        (match_operand:SI 1 "const_int_operand" "")
3642                        (match_operand:SI 2 "const_int_operand" ""))
3643         (match_operand 3 "gpc_reg_operand" ""))]
3644   ""
3645   "
3646 {
3647   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3648      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3649      compiler if the address of the structure is taken later.  */
3650   if (GET_CODE (operands[0]) == SUBREG
3651       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3652     FAIL;
3653
3654   if (TARGET_POWERPC64 && GET_MODE (operands[0]) == DImode)
3655     emit_insn (gen_insvdi (operands[0], operands[1], operands[2], operands[3]));
3656   else
3657     emit_insn (gen_insvsi (operands[0], operands[1], operands[2], operands[3]));
3658   DONE;
3659 }")
3660
3661 (define_insn "insvsi"
3662   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3663                          (match_operand:SI 1 "const_int_operand" "i")
3664                          (match_operand:SI 2 "const_int_operand" "i"))
3665         (match_operand:SI 3 "gpc_reg_operand" "r"))]
3666   ""
3667   "*
3668 {
3669   int start = INTVAL (operands[2]) & 31;
3670   int size = INTVAL (operands[1]) & 31;
3671
3672   operands[4] = GEN_INT (32 - start - size);
3673   operands[1] = GEN_INT (start + size - 1);
3674   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3675 }")
3676
3677 (define_insn "*insvsi_internal1"
3678   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3679                          (match_operand:SI 1 "const_int_operand" "i")
3680                          (match_operand:SI 2 "const_int_operand" "i"))
3681         (ashift:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3682                    (match_operand:SI 4 "const_int_operand" "i")))]
3683   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3684   "*
3685 {
3686   int shift = INTVAL (operands[4]) & 31;
3687   int start = INTVAL (operands[2]) & 31;
3688   int size = INTVAL (operands[1]) & 31;
3689
3690   operands[4] = GEN_INT (shift - start - size);
3691   operands[1] = GEN_INT (start + size - 1);
3692   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3693 }")
3694
3695 (define_insn "*insvsi_internal2"
3696   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3697                          (match_operand:SI 1 "const_int_operand" "i")
3698                          (match_operand:SI 2 "const_int_operand" "i"))
3699         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3700                      (match_operand:SI 4 "const_int_operand" "i")))]
3701   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3702   "*
3703 {
3704   int shift = INTVAL (operands[4]) & 31;
3705   int start = INTVAL (operands[2]) & 31;
3706   int size = INTVAL (operands[1]) & 31;
3707
3708   operands[4] = GEN_INT (32 - shift - start - size);
3709   operands[1] = GEN_INT (start + size - 1);
3710   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3711 }")
3712
3713 (define_insn "*insvsi_internal3"
3714   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3715                          (match_operand:SI 1 "const_int_operand" "i")
3716                          (match_operand:SI 2 "const_int_operand" "i"))
3717         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3718                      (match_operand:SI 4 "const_int_operand" "i")))]
3719   "(32 - (INTVAL (operands[4]) & 31)) >= INTVAL (operands[1])"
3720   "*
3721 {
3722   int shift = INTVAL (operands[4]) & 31;
3723   int start = INTVAL (operands[2]) & 31;
3724   int size = INTVAL (operands[1]) & 31;
3725
3726   operands[4] = GEN_INT (32 - shift - start - size);
3727   operands[1] = GEN_INT (start + size - 1);
3728   return \"{rlimi|rlwimi} %0,%3,%h4,%h2,%h1\";
3729 }")
3730
3731 (define_insn "*insvsi_internal4"
3732   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
3733                          (match_operand:SI 1 "const_int_operand" "i")
3734                          (match_operand:SI 2 "const_int_operand" "i"))
3735         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3736                          (match_operand:SI 4 "const_int_operand" "i")
3737                          (match_operand:SI 5 "const_int_operand" "i")))]
3738   "INTVAL (operands[4]) >= INTVAL (operands[1])"
3739   "*
3740 {
3741   int extract_start = INTVAL (operands[5]) & 31;
3742   int extract_size = INTVAL (operands[4]) & 31;
3743   int insert_start = INTVAL (operands[2]) & 31;
3744   int insert_size = INTVAL (operands[1]) & 31;
3745
3746 /* Align extract field with insert field */
3747   operands[5] = GEN_INT (extract_start + extract_size - insert_start - insert_size);
3748   operands[1] = GEN_INT (insert_start + insert_size - 1);
3749   return \"{rlimi|rlwimi} %0,%3,%h5,%h2,%h1\";
3750 }")
3751
3752 (define_insn "insvdi"
3753   [(set (zero_extract:DI (match_operand:DI 0 "gpc_reg_operand" "+r")
3754                          (match_operand:SI 1 "const_int_operand" "i")
3755                          (match_operand:SI 2 "const_int_operand" "i"))
3756         (match_operand:DI 3 "gpc_reg_operand" "r"))]
3757   "TARGET_POWERPC64"
3758   "*
3759 {
3760   int start = INTVAL (operands[2]) & 63;
3761   int size = INTVAL (operands[1]) & 63;
3762
3763   operands[1] = GEN_INT (64 - start - size);
3764   return \"rldimi %0,%3,%H1,%H2\";
3765 }")
3766
3767 (define_expand "extzv"
3768   [(set (match_operand 0 "gpc_reg_operand" "")
3769         (zero_extract (match_operand 1 "gpc_reg_operand" "")
3770                        (match_operand:SI 2 "const_int_operand" "")
3771                        (match_operand:SI 3 "const_int_operand" "")))]
3772   ""
3773   "
3774 {
3775   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
3776      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
3777      compiler if the address of the structure is taken later.  */
3778   if (GET_CODE (operands[0]) == SUBREG
3779       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
3780     FAIL;
3781
3782   if (TARGET_POWERPC64 && GET_MODE (operands[1]) == DImode)
3783     emit_insn (gen_extzvdi (operands[0], operands[1], operands[2], operands[3]));
3784   else
3785     emit_insn (gen_extzvsi (operands[0], operands[1], operands[2], operands[3]));
3786   DONE;
3787 }")
3788
3789 (define_insn "extzvsi"
3790   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3791         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3792                          (match_operand:SI 2 "const_int_operand" "i")
3793                          (match_operand:SI 3 "const_int_operand" "i")))]
3794   ""
3795   "*
3796 {
3797   int start = INTVAL (operands[3]) & 31;
3798   int size = INTVAL (operands[2]) & 31;
3799
3800   if (start + size >= 32)
3801     operands[3] = const0_rtx;
3802   else
3803     operands[3] = GEN_INT (start + size);
3804   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
3805 }")
3806
3807 (define_insn "*extzvsi_internal1"
3808   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3809         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3810                          (match_operand:SI 2 "const_int_operand" "i,i")
3811                          (match_operand:SI 3 "const_int_operand" "i,i"))
3812                     (const_int 0)))
3813    (clobber (match_scratch:SI 4 "=r,r"))]
3814   ""
3815   "*
3816 {
3817   int start = INTVAL (operands[3]) & 31;
3818   int size = INTVAL (operands[2]) & 31;
3819
3820   /* Force split for non-cc0 compare.  */
3821   if (which_alternative == 1)
3822      return \"#\";
3823
3824   /* If the bitfield being tested fits in the upper or lower half of a
3825      word, it is possible to use andiu. or andil. to test it.  This is
3826      useful because the condition register set-use delay is smaller for
3827      andi[ul]. than for rlinm.  This doesn't work when the starting bit
3828      position is 0 because the LT and GT bits may be set wrong.  */
3829
3830   if ((start > 0 && start + size <= 16) || start >= 16)
3831     {
3832       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3833                               - (1 << (16 - (start & 15) - size))));
3834       if (start < 16)
3835         return \"{andiu.|andis.} %4,%1,%3\";
3836       else
3837         return \"{andil.|andi.} %4,%1,%3\";
3838     }
3839
3840   if (start + size >= 32)
3841     operands[3] = const0_rtx;
3842   else
3843     operands[3] = GEN_INT (start + size);
3844   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
3845 }"
3846   [(set_attr "type" "compare")
3847    (set_attr "length" "4,8")])
3848
3849 (define_split
3850   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3851         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3852                          (match_operand:SI 2 "const_int_operand" "")
3853                          (match_operand:SI 3 "const_int_operand" ""))
3854                     (const_int 0)))
3855    (clobber (match_scratch:SI 4 ""))]
3856   "reload_completed"
3857   [(set (match_dup 4)
3858         (zero_extract:SI (match_dup 1) (match_dup 2)
3859                          (match_dup 3)))
3860    (set (match_dup 0)
3861         (compare:CC (match_dup 4)
3862                     (const_int 0)))]
3863   "")
3864
3865 (define_insn "*extzvsi_internal2"
3866   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3867         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3868                          (match_operand:SI 2 "const_int_operand" "i,i")
3869                          (match_operand:SI 3 "const_int_operand" "i,i"))
3870                     (const_int 0)))
3871    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3872         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3873   ""
3874   "*
3875 {
3876   int start = INTVAL (operands[3]) & 31;
3877   int size = INTVAL (operands[2]) & 31;
3878
3879   /* Force split for non-cc0 compare.  */
3880   if (which_alternative == 1)
3881      return \"#\";
3882
3883   if ((start > 0 && start + size <= 16) || start >= 16)
3884     {
3885       operands[3] = GEN_INT (((1 << (16 - (start & 15)))
3886                               - (1 << (16 - (start & 15) - size))));
3887       if (start < 16)
3888         return \"{andiu.|andis.} %0,%1,%3\";
3889       else
3890         return \"{andil.|andi.} %0,%1,%3\";
3891     }
3892
3893   if (start + size >= 32)
3894     operands[3] = const0_rtx;
3895   else
3896     operands[3] = GEN_INT (start + size);
3897   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
3898 }"
3899   [(set_attr "type" "compare")
3900    (set_attr "length" "4,8")])
3901
3902 (define_split
3903   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3904         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "")
3905                          (match_operand:SI 2 "const_int_operand" "")
3906                          (match_operand:SI 3 "const_int_operand" ""))
3907                     (const_int 0)))
3908    (set (match_operand:SI 0 "gpc_reg_operand" "")
3909         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
3910   "reload_completed"
3911   [(set (match_dup 0)
3912         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))
3913    (set (match_dup 4)
3914         (compare:CC (match_dup 0)
3915                     (const_int 0)))]
3916   "")
3917
3918 (define_insn "extzvdi"
3919   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3920         (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3921                          (match_operand:SI 2 "const_int_operand" "i")
3922                          (match_operand:SI 3 "const_int_operand" "i")))]
3923   "TARGET_POWERPC64"
3924   "*
3925 {
3926   int start = INTVAL (operands[3]) & 63;
3927   int size = INTVAL (operands[2]) & 63;
3928
3929   if (start + size >= 64)
3930     operands[3] = const0_rtx;
3931   else
3932     operands[3] = GEN_INT (start + size);
3933   operands[2] = GEN_INT (64 - size);
3934   return \"rldicl %0,%1,%3,%2\";
3935 }")
3936
3937 (define_insn "*extzvdi_internal1"
3938   [(set (match_operand:CC 0 "gpc_reg_operand" "=x")
3939         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3940                          (match_operand:SI 2 "const_int_operand" "i")
3941                          (match_operand:SI 3 "const_int_operand" "i"))
3942                     (const_int 0)))
3943    (clobber (match_scratch:DI 4 "=r"))]
3944   "TARGET_POWERPC64"
3945   "*
3946 {
3947   int start = INTVAL (operands[3]) & 63;
3948   int size = INTVAL (operands[2]) & 63;
3949
3950   if (start + size >= 64)
3951     operands[3] = const0_rtx;
3952   else
3953     operands[3] = GEN_INT (start + size);
3954   operands[2] = GEN_INT (64 - size);
3955   return \"rldicl. %4,%1,%3,%2\";
3956 }")
3957
3958 (define_insn "*extzvdi_internal2"
3959   [(set (match_operand:CC 4 "gpc_reg_operand" "=x")
3960         (compare:CC (zero_extract:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3961                          (match_operand:SI 2 "const_int_operand" "i")
3962                          (match_operand:SI 3 "const_int_operand" "i"))
3963                     (const_int 0)))
3964    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3965         (zero_extract:DI (match_dup 1) (match_dup 2) (match_dup 3)))]
3966   "TARGET_POWERPC64"
3967   "*
3968 {
3969   int start = INTVAL (operands[3]) & 63;
3970   int size = INTVAL (operands[2]) & 63;
3971
3972   if (start + size >= 64)
3973     operands[3] = const0_rtx;
3974   else
3975     operands[3] = GEN_INT (start + size);
3976   operands[2] = GEN_INT (64 - size);
3977   return \"rldicl. %0,%1,%3,%2\";
3978 }")
3979
3980 (define_insn "rotlsi3"
3981   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3982         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
3983                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
3984   ""
3985   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
3986
3987 (define_insn "*rotlsi3_internal2"
3988   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3989         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
3990                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
3991                     (const_int 0)))
3992    (clobber (match_scratch:SI 3 "=r,r"))]
3993   ""
3994   "@
3995    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff
3996    #"
3997   [(set_attr "type" "delayed_compare")
3998    (set_attr "length" "4,8")])
3999
4000 (define_split
4001   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4002         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4003                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4004                     (const_int 0)))
4005    (clobber (match_scratch:SI 3 ""))]
4006   "reload_completed"
4007   [(set (match_dup 3)
4008         (rotate:SI (match_dup 1) (match_dup 2)))
4009    (set (match_dup 0)
4010         (compare:CC (match_dup 3)
4011                     (const_int 0)))]
4012   "")
4013
4014 (define_insn "*rotlsi3_internal3"
4015   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4016         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4017                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4018                     (const_int 0)))
4019    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4020         (rotate:SI (match_dup 1) (match_dup 2)))]
4021   ""
4022   "@
4023    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff
4024    #"
4025   [(set_attr "type" "delayed_compare")
4026    (set_attr "length" "4,8")])
4027
4028 (define_split
4029   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4030         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4031                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4032                     (const_int 0)))
4033    (set (match_operand:SI 0 "gpc_reg_operand" "")
4034         (rotate:SI (match_dup 1) (match_dup 2)))]
4035   "reload_completed"
4036   [(set (match_dup 0)
4037         (rotate:SI (match_dup 1) (match_dup 2)))
4038    (set (match_dup 3)
4039         (compare:CC (match_dup 0)
4040                     (const_int 0)))]
4041   "")
4042
4043 (define_insn "*rotlsi3_internal4"
4044   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4045         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4046                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
4047                 (match_operand:SI 3 "mask_operand" "n")))]
4048   ""
4049   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
4050
4051 (define_insn "*rotlsi3_internal5"
4052   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4053         (compare:CC (and:SI
4054                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4055                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4056                      (match_operand:SI 3 "mask_operand" "n,n"))
4057                     (const_int 0)))
4058    (clobber (match_scratch:SI 4 "=r,r"))]
4059   ""
4060   "@
4061    {rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3
4062    #"
4063   [(set_attr "type" "delayed_compare")
4064    (set_attr "length" "4,8")])
4065
4066 (define_split
4067   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4068         (compare:CC (and:SI
4069                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4070                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
4071                      (match_operand:SI 3 "mask_operand" ""))
4072                     (const_int 0)))
4073    (clobber (match_scratch:SI 4 ""))]
4074   "reload_completed"
4075   [(set (match_dup 4)
4076         (and:SI (rotate:SI (match_dup 1)
4077                                 (match_dup 2))
4078                      (match_dup 3)))
4079    (set (match_dup 0)
4080         (compare:CC (match_dup 4)
4081                     (const_int 0)))]
4082   "")
4083
4084 (define_insn "*rotlsi3_internal6"
4085   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4086         (compare:CC (and:SI
4087                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4088                                 (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4089                      (match_operand:SI 3 "mask_operand" "n,n"))
4090                     (const_int 0)))
4091    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4092         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4093   ""
4094   "@
4095    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3
4096    #"
4097   [(set_attr "type" "delayed_compare")
4098    (set_attr "length" "4,8")])
4099
4100 (define_split
4101   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4102         (compare:CC (and:SI
4103                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4104                                 (match_operand:SI 2 "reg_or_cint_operand" ""))
4105                      (match_operand:SI 3 "mask_operand" ""))
4106                     (const_int 0)))
4107    (set (match_operand:SI 0 "gpc_reg_operand" "")
4108         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4109   "reload_completed"
4110   [(set (match_dup 0)
4111         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4112    (set (match_dup 4)
4113         (compare:CC (match_dup 0)
4114                     (const_int 0)))]
4115   "")
4116
4117 (define_insn "*rotlsi3_internal7"
4118   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4119         (zero_extend:SI
4120          (subreg:QI
4121           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4122                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
4123   ""
4124   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
4125
4126 (define_insn "*rotlsi3_internal8"
4127   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4128         (compare:CC (zero_extend:SI
4129                      (subreg:QI
4130                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4131                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
4132                     (const_int 0)))
4133    (clobber (match_scratch:SI 3 "=r,r"))]
4134   ""
4135   "@
4136    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff
4137    #"
4138   [(set_attr "type" "delayed_compare")
4139    (set_attr "length" "4,8")])
4140
4141 (define_split
4142   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4143         (compare:CC (zero_extend:SI
4144                      (subreg:QI
4145                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4146                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4147                     (const_int 0)))
4148    (clobber (match_scratch:SI 3 ""))]
4149   "reload_completed"
4150   [(set (match_dup 3)
4151         (zero_extend:SI (subreg:QI
4152                       (rotate:SI (match_dup 1)
4153                                  (match_dup 2)) 0)))
4154    (set (match_dup 0)
4155         (compare:CC (match_dup 3)
4156                     (const_int 0)))]
4157   "")
4158
4159 (define_insn "*rotlsi3_internal9"
4160   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4161         (compare:CC (zero_extend:SI
4162                      (subreg:QI
4163                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4164                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
4165                     (const_int 0)))
4166    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4167         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4168   ""
4169   "@
4170    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff
4171    #"
4172   [(set_attr "type" "delayed_compare")
4173    (set_attr "length" "4,8")])
4174
4175 (define_split
4176   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4177         (compare:CC (zero_extend:SI
4178                      (subreg:QI
4179                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4180                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4181                     (const_int 0)))
4182    (set (match_operand:SI 0 "gpc_reg_operand" "")
4183         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4184   "reload_completed"
4185   [(set (match_dup 0)
4186         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4187    (set (match_dup 3)
4188         (compare:CC (match_dup 0)
4189                     (const_int 0)))]
4190   "")
4191
4192 (define_insn "*rotlsi3_internal10"
4193   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4194         (zero_extend:SI
4195          (subreg:HI
4196           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4197                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
4198   ""
4199   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
4200
4201 (define_insn "*rotlsi3_internal11"
4202   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4203         (compare:CC (zero_extend:SI
4204                      (subreg:HI
4205                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4206                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
4207                     (const_int 0)))
4208    (clobber (match_scratch:SI 3 "=r,r"))]
4209   ""
4210   "@
4211    {rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff
4212    #"
4213   [(set_attr "type" "delayed_compare")
4214    (set_attr "length" "4,8")])
4215
4216 (define_split
4217   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4218         (compare:CC (zero_extend:SI
4219                      (subreg:HI
4220                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4221                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4222                     (const_int 0)))
4223    (clobber (match_scratch:SI 3 ""))]
4224   "reload_completed"
4225   [(set (match_dup 3)
4226         (zero_extend:SI (subreg:HI
4227                       (rotate:SI (match_dup 1)
4228                                  (match_dup 2)) 0)))
4229    (set (match_dup 0)
4230         (compare:CC (match_dup 3)
4231                     (const_int 0)))]
4232   "")
4233
4234 (define_insn "*rotlsi3_internal12"
4235   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4236         (compare:CC (zero_extend:SI
4237                      (subreg:HI
4238                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4239                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri")) 0))
4240                     (const_int 0)))
4241    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4242         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4243   ""
4244   "@
4245    {rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff
4246    #"
4247   [(set_attr "type" "delayed_compare")
4248    (set_attr "length" "4,8")])
4249
4250 (define_split
4251   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4252         (compare:CC (zero_extend:SI
4253                      (subreg:HI
4254                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "")
4255                                  (match_operand:SI 2 "reg_or_cint_operand" "")) 0))
4256                     (const_int 0)))
4257    (set (match_operand:SI 0 "gpc_reg_operand" "")
4258         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
4259   "reload_completed"
4260   [(set (match_dup 0)
4261         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))
4262    (set (match_dup 3)
4263         (compare:CC (match_dup 0)
4264                     (const_int 0)))]
4265   "")
4266
4267 ;; Note that we use "sle." instead of "sl." so that we can set
4268 ;; SHIFT_COUNT_TRUNCATED.
4269
4270 (define_expand "ashlsi3"
4271   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4272    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4273    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4274   ""
4275   "
4276 {
4277   if (TARGET_POWER)
4278     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
4279   else
4280     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
4281   DONE;
4282 }")
4283
4284 (define_insn "ashlsi3_power"
4285   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4286         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4287                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4288    (clobber (match_scratch:SI 3 "=q,X"))]
4289   "TARGET_POWER"
4290   "@
4291    sle %0,%1,%2
4292    {sli|slwi} %0,%1,%h2")
4293
4294 (define_insn "ashlsi3_no_power"
4295   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4296         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4297                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4298   "! TARGET_POWER"
4299   "{sl|slw}%I2 %0,%1,%h2")
4300
4301 (define_insn ""
4302   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4303         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4304                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4305                     (const_int 0)))
4306    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4307    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4308   "TARGET_POWER"
4309   "@
4310    sle. %3,%1,%2
4311    {sli.|slwi.} %3,%1,%h2
4312    #
4313    #"
4314   [(set_attr "type" "delayed_compare")
4315    (set_attr "length" "4,4,8,8")])
4316
4317 (define_split
4318   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4319         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4320                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4321                     (const_int 0)))
4322    (clobber (match_scratch:SI 3 ""))
4323    (clobber (match_scratch:SI 4 ""))]
4324   "TARGET_POWER && reload_completed"
4325   [(parallel [(set (match_dup 3)
4326         (ashift:SI (match_dup 1) (match_dup 2)))
4327    (clobber (match_dup 4))])
4328    (set (match_dup 0)
4329         (compare:CC (match_dup 3)
4330                     (const_int 0)))]
4331   "")
4332
4333 (define_insn ""
4334   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4335         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4336                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4337                     (const_int 0)))
4338    (clobber (match_scratch:SI 3 "=r,r"))]
4339   "! TARGET_POWER && ! TARGET_POWERPC64"
4340   "@
4341    {sl|slw}%I2. %3,%1,%h2
4342    #"
4343   [(set_attr "type" "delayed_compare")
4344    (set_attr "length" "4,8")])
4345
4346 (define_split
4347   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4348         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4349                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4350                     (const_int 0)))
4351    (clobber (match_scratch:SI 3 ""))]
4352   "! TARGET_POWER && ! TARGET_POWERPC64 && reload_completed"
4353   [(set (match_dup 3)
4354         (ashift:SI (match_dup 1) (match_dup 2)))
4355    (set (match_dup 0)
4356         (compare:CC (match_dup 3)
4357                     (const_int 0)))]
4358   "")
4359
4360 (define_insn ""
4361   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4362         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4363                                (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4364                     (const_int 0)))
4365    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4366         (ashift:SI (match_dup 1) (match_dup 2)))
4367    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4368   "TARGET_POWER"
4369   "@
4370    sle. %0,%1,%2
4371    {sli.|slwi.} %0,%1,%h2
4372    #
4373    #"
4374   [(set_attr "type" "delayed_compare")
4375    (set_attr "length" "4,4,8,8")])
4376
4377 (define_split
4378   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4379         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4380                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4381                     (const_int 0)))
4382    (set (match_operand:SI 0 "gpc_reg_operand" "")
4383         (ashift:SI (match_dup 1) (match_dup 2)))
4384    (clobber (match_scratch:SI 4 ""))]
4385   "TARGET_POWER && reload_completed"
4386   [(parallel [(set (match_dup 0)
4387         (ashift:SI (match_dup 1) (match_dup 2)))
4388    (clobber (match_dup 4))])
4389    (set (match_dup 3)
4390         (compare:CC (match_dup 0)
4391                     (const_int 0)))]
4392   "")
4393
4394 (define_insn ""
4395   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4396         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4397                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4398                     (const_int 0)))
4399    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4400         (ashift:SI (match_dup 1) (match_dup 2)))]
4401   "! TARGET_POWER && ! TARGET_POWERPC64"
4402   "@
4403    {sl|slw}%I2. %0,%1,%h2
4404    #"
4405   [(set_attr "type" "delayed_compare")
4406    (set_attr "length" "4,8")])
4407
4408 (define_split
4409   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4410         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4411                                (match_operand:SI 2 "reg_or_cint_operand" ""))
4412                     (const_int 0)))
4413    (set (match_operand:SI 0 "gpc_reg_operand" "")
4414         (ashift:SI (match_dup 1) (match_dup 2)))]
4415   "! TARGET_POWER && ! TARGET_POWERPC64 && reload_completed"
4416   [(set (match_dup 0)
4417         (ashift:SI (match_dup 1) (match_dup 2)))
4418    (set (match_dup 3)
4419         (compare:CC (match_dup 0)
4420                     (const_int 0)))]
4421   "")
4422
4423 (define_insn ""
4424   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4425         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4426                            (match_operand:SI 2 "const_int_operand" "i"))
4427                 (match_operand:SI 3 "mask_operand" "n")))]
4428   "includes_lshift_p (operands[2], operands[3])"
4429   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
4430
4431 (define_insn ""
4432   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4433         (compare:CC
4434          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4435                             (match_operand:SI 2 "const_int_operand" "i,i"))
4436                  (match_operand:SI 3 "mask_operand" "n,n"))
4437          (const_int 0)))
4438    (clobber (match_scratch:SI 4 "=r,r"))]
4439   "includes_lshift_p (operands[2], operands[3])"
4440   "@
4441    {rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3
4442    #"
4443   [(set_attr "type" "delayed_compare")
4444    (set_attr "length" "4,8")])
4445
4446 (define_split
4447   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4448         (compare:CC
4449          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4450                             (match_operand:SI 2 "const_int_operand" ""))
4451                  (match_operand:SI 3 "mask_operand" ""))
4452          (const_int 0)))
4453    (clobber (match_scratch:SI 4 ""))]
4454   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4455   [(set (match_dup 4)
4456         (and:SI (ashift:SI (match_dup 1) (match_dup 2))
4457                  (match_dup 3)))
4458    (set (match_dup 0)
4459         (compare:CC (match_dup 4)
4460                     (const_int 0)))]
4461   "")
4462
4463 (define_insn ""
4464   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4465         (compare:CC
4466          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4467                             (match_operand:SI 2 "const_int_operand" "i,i"))
4468                  (match_operand:SI 3 "mask_operand" "n,n"))
4469          (const_int 0)))
4470    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4471         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4472   "includes_lshift_p (operands[2], operands[3])"
4473   "@
4474    {rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3
4475    #"
4476   [(set_attr "type" "delayed_compare")
4477    (set_attr "length" "4,8")])
4478
4479 (define_split
4480   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4481         (compare:CC
4482          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "")
4483                             (match_operand:SI 2 "const_int_operand" ""))
4484                  (match_operand:SI 3 "mask_operand" ""))
4485          (const_int 0)))
4486    (set (match_operand:SI 0 "gpc_reg_operand" "")
4487         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4488   "includes_lshift_p (operands[2], operands[3]) && reload_completed"
4489   [(set (match_dup 0)
4490         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4491    (set (match_dup 4)
4492         (compare:CC (match_dup 0)
4493                     (const_int 0)))]
4494   "")
4495
4496 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
4497 ;; "sli x,x,0".
4498 (define_expand "lshrsi3"
4499   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
4500    (use (match_operand:SI 1 "gpc_reg_operand" ""))
4501    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
4502   ""
4503   "
4504 {
4505   if (TARGET_POWER)
4506     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
4507   else
4508     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
4509   DONE;
4510 }")
4511
4512 (define_insn "lshrsi3_power"
4513   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
4514         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
4515                      (match_operand:SI 2 "reg_or_cint_operand" "r,O,i")))
4516    (clobber (match_scratch:SI 3 "=q,X,X"))]
4517   "TARGET_POWER"
4518   "@
4519   sre %0,%1,%2
4520   mr %0,%1
4521   {s%A2i|s%A2wi} %0,%1,%h2")
4522
4523 (define_insn "lshrsi3_no_power"
4524   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4525         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4526                      (match_operand:SI 2 "reg_or_cint_operand" "O,ri")))]
4527   "! TARGET_POWER"
4528   "@
4529   mr %0,%1
4530   {sr|srw}%I2 %0,%1,%h2")
4531
4532 (define_insn ""
4533   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4534         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4535                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
4536                     (const_int 0)))
4537    (clobber (match_scratch:SI 3 "=r,X,r,r,X,r"))
4538    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
4539   "TARGET_POWER"
4540   "@
4541   sre. %3,%1,%2
4542   mr. %1,%1
4543   {s%A2i.|s%A2wi.} %3,%1,%h2
4544   #
4545   #
4546   #"
4547   [(set_attr "type" "delayed_compare")
4548    (set_attr "length" "4,4,4,8,8,8")])
4549
4550 (define_split
4551   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4552         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4553                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4554                     (const_int 0)))
4555    (clobber (match_scratch:SI 3 ""))
4556    (clobber (match_scratch:SI 4 ""))]
4557   "TARGET_POWER && reload_completed"
4558   [(parallel [(set (match_dup 3)
4559         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4560    (clobber (match_dup 4))])
4561    (set (match_dup 0)
4562         (compare:CC (match_dup 3)
4563                     (const_int 0)))]
4564   "")
4565
4566 (define_insn ""
4567   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4568         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4569                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
4570                     (const_int 0)))
4571    (clobber (match_scratch:SI 3 "=X,r,X,r"))]
4572   "! TARGET_POWER && ! TARGET_POWERPC64"
4573   "@
4574    mr. %1,%1
4575    {sr|srw}%I2. %3,%1,%h2
4576    #
4577    #"
4578   [(set_attr "type" "delayed_compare")
4579    (set_attr "length" "4,4,8,8")])
4580
4581 (define_split
4582   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4583         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4584                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4585                     (const_int 0)))
4586    (clobber (match_scratch:SI 3 ""))]
4587   "! TARGET_POWER && ! TARGET_POWERPC64 && reload_completed"
4588   [(set (match_dup 3)
4589         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4590    (set (match_dup 0)
4591         (compare:CC (match_dup 3)
4592                     (const_int 0)))]
4593   "")
4594
4595 (define_insn ""
4596   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,?y,?y,?y")
4597         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r,r,r")
4598                                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,i,r,O,i"))
4599                     (const_int 0)))
4600    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r")
4601         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4602    (clobber (match_scratch:SI 4 "=q,X,X,q,X,X"))]
4603   "TARGET_POWER"
4604   "@
4605   sre. %0,%1,%2
4606   mr. %0,%1
4607   {s%A2i.|s%A2wi.} %0,%1,%h2
4608   #
4609   #
4610   #"
4611   [(set_attr "type" "delayed_compare")
4612    (set_attr "length" "4,4,4,8,8,8")])
4613
4614 (define_split
4615   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4616         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4617                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4618                     (const_int 0)))
4619    (set (match_operand:SI 0 "gpc_reg_operand" "")
4620         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4621    (clobber (match_scratch:SI 4 ""))]
4622   "TARGET_POWER && reload_completed"
4623   [(parallel [(set (match_dup 0)
4624         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4625    (clobber (match_dup 4))])
4626    (set (match_dup 3)
4627         (compare:CC (match_dup 0)
4628                     (const_int 0)))]
4629   "")
4630
4631 (define_insn ""
4632   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
4633         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4634                                  (match_operand:SI 2 "reg_or_cint_operand" "O,ri,O,ri"))
4635                     (const_int 0)))
4636    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
4637         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4638   "! TARGET_POWER && ! TARGET_POWERPC64"
4639   "@
4640    mr. %0,%1
4641    {sr|srw}%I2. %0,%1,%h2
4642    #
4643    #"
4644   [(set_attr "type" "delayed_compare")
4645    (set_attr "length" "4,4,8,8")])
4646
4647 (define_split
4648   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4649         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4650                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4651                     (const_int 0)))
4652    (set (match_operand:SI 0 "gpc_reg_operand" "")
4653         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
4654   "! TARGET_POWER && ! TARGET_POWERPC64 && reload_completed"
4655   [(set (match_dup 0)
4656         (lshiftrt:SI (match_dup 1) (match_dup 2)))
4657    (set (match_dup 3)
4658         (compare:CC (match_dup 0)
4659                     (const_int 0)))]
4660   "")
4661
4662 (define_insn ""
4663   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4664         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4665                              (match_operand:SI 2 "const_int_operand" "i"))
4666                 (match_operand:SI 3 "mask_operand" "n")))]
4667   "includes_rshift_p (operands[2], operands[3])"
4668   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
4669
4670 (define_insn ""
4671   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4672         (compare:CC
4673          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4674                               (match_operand:SI 2 "const_int_operand" "i,i"))
4675                  (match_operand:SI 3 "mask_operand" "n,n"))
4676          (const_int 0)))
4677    (clobber (match_scratch:SI 4 "=r,r"))]
4678   "includes_rshift_p (operands[2], operands[3])"
4679   "@
4680    {rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3
4681    #"
4682   [(set_attr "type" "delayed_compare")
4683    (set_attr "length" "4,8")])
4684
4685 (define_split
4686   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4687         (compare:CC
4688          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4689                               (match_operand:SI 2 "const_int_operand" ""))
4690                  (match_operand:SI 3 "mask_operand" ""))
4691          (const_int 0)))
4692    (clobber (match_scratch:SI 4 ""))]
4693   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4694   [(set (match_dup 4)
4695         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4696                  (match_dup 3)))
4697    (set (match_dup 0)
4698         (compare:CC (match_dup 4)
4699                     (const_int 0)))]
4700   "")
4701
4702 (define_insn ""
4703   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4704         (compare:CC
4705          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4706                               (match_operand:SI 2 "const_int_operand" "i,i"))
4707                  (match_operand:SI 3 "mask_operand" "n,n"))
4708          (const_int 0)))
4709    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4710         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4711   "includes_rshift_p (operands[2], operands[3])"
4712   "@
4713    {rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3
4714    #"
4715   [(set_attr "type" "delayed_compare")
4716    (set_attr "length" "4,8")])
4717
4718 (define_split
4719   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
4720         (compare:CC
4721          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4722                               (match_operand:SI 2 "const_int_operand" ""))
4723                  (match_operand:SI 3 "mask_operand" ""))
4724          (const_int 0)))
4725    (set (match_operand:SI 0 "gpc_reg_operand" "")
4726         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
4727   "includes_rshift_p (operands[2], operands[3]) && reload_completed"
4728   [(set (match_dup 0)
4729         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
4730    (set (match_dup 4)
4731         (compare:CC (match_dup 0)
4732                     (const_int 0)))]
4733   "")
4734
4735 (define_insn ""
4736   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4737         (zero_extend:SI
4738          (subreg:QI
4739           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4740                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4741   "includes_rshift_p (operands[2], GEN_INT (255))"
4742   "{rlinm|rlwinm} %0,%1,%s2,0xff")
4743
4744 (define_insn ""
4745   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4746         (compare:CC
4747          (zero_extend:SI
4748           (subreg:QI
4749            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4750                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4751          (const_int 0)))
4752    (clobber (match_scratch:SI 3 "=r,r"))]
4753   "includes_rshift_p (operands[2], GEN_INT (255))"
4754   "@
4755    {rlinm.|rlwinm.} %3,%1,%s2,0xff
4756    #"
4757   [(set_attr "type" "delayed_compare")
4758    (set_attr "length" "4,8")])
4759
4760 (define_split
4761   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4762         (compare:CC
4763          (zero_extend:SI
4764           (subreg:QI
4765            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4766                         (match_operand:SI 2 "const_int_operand" "")) 0))
4767          (const_int 0)))
4768    (clobber (match_scratch:SI 3 ""))]
4769   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4770   [(set (match_dup 3)
4771         (zero_extend:SI (subreg:QI
4772            (lshiftrt:SI (match_dup 1)
4773                         (match_dup 2)) 0)))
4774    (set (match_dup 0)
4775         (compare:CC (match_dup 3)
4776                     (const_int 0)))]
4777   "")
4778
4779 (define_insn ""
4780   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4781         (compare:CC
4782          (zero_extend:SI
4783           (subreg:QI
4784            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4785                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4786          (const_int 0)))
4787    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4788         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4789   "includes_rshift_p (operands[2], GEN_INT (255))"
4790   "@
4791    {rlinm.|rlwinm.} %0,%1,%s2,0xff
4792    #"
4793   [(set_attr "type" "delayed_compare")
4794    (set_attr "length" "4,8")])
4795
4796 (define_split
4797   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4798         (compare:CC
4799          (zero_extend:SI
4800           (subreg:QI
4801            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4802                         (match_operand:SI 2 "const_int_operand" "")) 0))
4803          (const_int 0)))
4804    (set (match_operand:SI 0 "gpc_reg_operand" "")
4805         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4806   "includes_rshift_p (operands[2], GEN_INT (255)) && reload_completed"
4807   [(set (match_dup 0)
4808         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4809    (set (match_dup 3)
4810         (compare:CC (match_dup 0)
4811                     (const_int 0)))]
4812   "")
4813
4814 (define_insn ""
4815   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4816         (zero_extend:SI
4817          (subreg:HI
4818           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4819                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
4820   "includes_rshift_p (operands[2], GEN_INT (65535))"
4821   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
4822
4823 (define_insn ""
4824   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4825         (compare:CC
4826          (zero_extend:SI
4827           (subreg:HI
4828            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4829                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4830          (const_int 0)))
4831    (clobber (match_scratch:SI 3 "=r,r"))]
4832   "includes_rshift_p (operands[2], GEN_INT (65535))"
4833   "@
4834    {rlinm.|rlwinm.} %3,%1,%s2,0xffff
4835    #"
4836   [(set_attr "type" "delayed_compare")
4837    (set_attr "length" "4,8")])
4838
4839 (define_split
4840   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4841         (compare:CC
4842          (zero_extend:SI
4843           (subreg:HI
4844            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4845                         (match_operand:SI 2 "const_int_operand" "")) 0))
4846          (const_int 0)))
4847    (clobber (match_scratch:SI 3 ""))]
4848   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4849   [(set (match_dup 3)
4850         (zero_extend:SI (subreg:HI
4851            (lshiftrt:SI (match_dup 1)
4852                         (match_dup 2)) 0)))
4853    (set (match_dup 0)
4854         (compare:CC (match_dup 3)
4855                     (const_int 0)))]
4856   "")
4857
4858 (define_insn ""
4859   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4860         (compare:CC
4861          (zero_extend:SI
4862           (subreg:HI
4863            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4864                         (match_operand:SI 2 "const_int_operand" "i,i")) 0))
4865          (const_int 0)))
4866    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4867         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4868   "includes_rshift_p (operands[2], GEN_INT (65535))"
4869   "@
4870    {rlinm.|rlwinm.} %0,%1,%s2,0xffff
4871    #"
4872   [(set_attr "type" "delayed_compare")
4873    (set_attr "length" "4,8")])
4874
4875 (define_split
4876   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
4877         (compare:CC
4878          (zero_extend:SI
4879           (subreg:HI
4880            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4881                         (match_operand:SI 2 "const_int_operand" "")) 0))
4882          (const_int 0)))
4883    (set (match_operand:SI 0 "gpc_reg_operand" "")
4884         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
4885   "includes_rshift_p (operands[2], GEN_INT (65535)) && reload_completed"
4886   [(set (match_dup 0)
4887         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))
4888    (set (match_dup 3)
4889         (compare:CC (match_dup 0)
4890                     (const_int 0)))]
4891   "")
4892
4893 (define_insn ""
4894   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4895                          (const_int 1)
4896                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4897         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4898                      (const_int 31)))]
4899   "TARGET_POWER"
4900   "rrib %0,%1,%2")
4901
4902 (define_insn ""
4903   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4904                          (const_int 1)
4905                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4906         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4907                      (const_int 31)))]
4908   "TARGET_POWER"
4909   "rrib %0,%1,%2")
4910
4911 (define_insn ""
4912   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
4913                          (const_int 1)
4914                          (match_operand:SI 1 "gpc_reg_operand" "r"))
4915         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
4916                          (const_int 1)
4917                          (const_int 0)))]
4918   "TARGET_POWER"
4919   "rrib %0,%1,%2")
4920
4921 (define_expand "ashrsi3"
4922   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4923         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4924                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4925   ""
4926   "
4927 {
4928   if (TARGET_POWER)
4929     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
4930   else
4931     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
4932   DONE;
4933 }")
4934
4935 (define_insn "ashrsi3_power"
4936   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4937         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4938                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
4939    (clobber (match_scratch:SI 3 "=q,X"))]
4940   "TARGET_POWER"
4941   "@
4942    srea %0,%1,%2
4943    {srai|srawi} %0,%1,%h2")
4944
4945 (define_insn "ashrsi3_no_power"
4946   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4947         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4948                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4949   "! TARGET_POWER"
4950   "{sra|sraw}%I2 %0,%1,%h2")
4951
4952 (define_insn ""
4953   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
4954         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
4955                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
4956                     (const_int 0)))
4957    (clobber (match_scratch:SI 3 "=r,r,r,r"))
4958    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
4959   "TARGET_POWER"
4960   "@
4961    srea. %3,%1,%2
4962    {srai.|srawi.} %3,%1,%h2
4963    #
4964    #"
4965   [(set_attr "type" "delayed_compare")
4966    (set_attr "length" "4,4,8,8")])
4967
4968 (define_split
4969   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4970         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
4971                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
4972                     (const_int 0)))
4973    (clobber (match_scratch:SI 3 ""))
4974    (clobber (match_scratch:SI 4 ""))]
4975   "TARGET_POWER && reload_completed"
4976   [(parallel [(set (match_dup 3)
4977         (ashiftrt:SI (match_dup 1) (match_dup 2)))
4978    (clobber (match_dup 4))])
4979    (set (match_dup 0)
4980         (compare:CC (match_dup 3)
4981                     (const_int 0)))]
4982   "")
4983
4984 (define_insn ""
4985   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
4986         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
4987                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
4988                     (const_int 0)))
4989    (clobber (match_scratch:SI 3 "=r,r"))]
4990   "! TARGET_POWER"
4991   "@
4992    {sra|sraw}%I2. %3,%1,%h2
4993    #"
4994   [(set_attr "type" "delayed_compare")
4995    (set_attr "length" "4,8")])
4996
4997 (define_split
4998   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
4999         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5000                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5001                     (const_int 0)))
5002    (clobber (match_scratch:SI 3 ""))]
5003   "! TARGET_POWER && reload_completed"
5004   [(set (match_dup 3)
5005         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5006    (set (match_dup 0)
5007         (compare:CC (match_dup 3)
5008                     (const_int 0)))]
5009   "")
5010
5011 (define_insn ""
5012   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
5013         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
5014                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i,r,i"))
5015                     (const_int 0)))
5016    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
5017         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5018    (clobber (match_scratch:SI 4 "=q,X,q,X"))]
5019   "TARGET_POWER"
5020   "@
5021    srea. %0,%1,%2
5022    {srai.|srawi.} %0,%1,%h2
5023    #
5024    #"
5025   [(set_attr "type" "delayed_compare")
5026    (set_attr "length" "4,4,8,8")])
5027
5028 (define_split
5029   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5030         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5031                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5032                     (const_int 0)))
5033    (set (match_operand:SI 0 "gpc_reg_operand" "")
5034         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5035    (clobber (match_scratch:SI 4 ""))]
5036   "TARGET_POWER && reload_completed"
5037   [(parallel [(set (match_dup 0)
5038         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5039    (clobber (match_dup 4))])
5040    (set (match_dup 3)
5041         (compare:CC (match_dup 0)
5042                     (const_int 0)))]
5043   "")
5044
5045 (define_insn ""
5046   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
5047         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
5048                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
5049                     (const_int 0)))
5050    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
5051         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5052   "! TARGET_POWER"
5053   "@
5054    {sra|sraw}%I2. %0,%1,%h2
5055    #"
5056   [(set_attr "type" "delayed_compare")
5057    (set_attr "length" "4,8")])
5058 \f
5059 (define_split
5060   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
5061         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
5062                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
5063                     (const_int 0)))
5064    (set (match_operand:SI 0 "gpc_reg_operand" "")
5065         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
5066   "! TARGET_POWER && reload_completed"
5067   [(set (match_dup 0)
5068         (ashiftrt:SI (match_dup 1) (match_dup 2)))
5069    (set (match_dup 3)
5070         (compare:CC (match_dup 0)
5071                     (const_int 0)))]
5072   "")
5073
5074 ;; Floating-point insns, excluding normal data motion.
5075 ;;
5076 ;; PowerPC has a full set of single-precision floating point instructions.
5077 ;;
5078 ;; For the POWER architecture, we pretend that we have both SFmode and
5079 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
5080 ;; The only conversions we will do will be when storing to memory.  In that
5081 ;; case, we will use the "frsp" instruction before storing.
5082 ;;
5083 ;; Note that when we store into a single-precision memory location, we need to
5084 ;; use the frsp insn first.  If the register being stored isn't dead, we
5085 ;; need a scratch register for the frsp.  But this is difficult when the store
5086 ;; is done by reload.  It is not incorrect to do the frsp on the register in
5087 ;; this case, we just lose precision that we would have otherwise gotten but
5088 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
5089
5090 (define_insn "extendsfdf2"
5091   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5092         (float_extend:DF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5093   "TARGET_HARD_FLOAT && TARGET_FPRS"
5094   "*
5095 {
5096   if (REGNO (operands[0]) == REGNO (operands[1]))
5097     return \"\";
5098   else
5099     return \"fmr %0,%1\";
5100 }"
5101   [(set_attr "type" "fp")])
5102
5103 (define_insn "truncdfsf2"
5104   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5105         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5106   "TARGET_HARD_FLOAT && TARGET_FPRS"
5107   "frsp %0,%1"
5108   [(set_attr "type" "fp")])
5109
5110 (define_insn "aux_truncdfsf2"
5111   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5112         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] 0))]
5113   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5114   "frsp %0,%1"
5115   [(set_attr "type" "fp")])
5116
5117 (define_expand "negsf2"
5118   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5119         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5120   "TARGET_HARD_FLOAT"
5121   "")
5122
5123 (define_insn "*negsf2"
5124   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5125         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5126   "TARGET_HARD_FLOAT && TARGET_FPRS"
5127   "fneg %0,%1"
5128   [(set_attr "type" "fp")])
5129
5130 (define_expand "abssf2"
5131   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5132         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5133   "TARGET_HARD_FLOAT"
5134   "")
5135
5136 (define_insn "*abssf2"
5137   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5138         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5139   "TARGET_HARD_FLOAT && TARGET_FPRS"
5140   "fabs %0,%1"
5141   [(set_attr "type" "fp")])
5142
5143 (define_insn ""
5144   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5145         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
5146   "TARGET_HARD_FLOAT && TARGET_FPRS"
5147   "fnabs %0,%1"
5148   [(set_attr "type" "fp")])
5149
5150 (define_expand "addsf3"
5151   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5152         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5153                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5154   "TARGET_HARD_FLOAT"
5155   "")
5156
5157 (define_insn ""
5158   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5159         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5160                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5161   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5162   "fadds %0,%1,%2"
5163   [(set_attr "type" "fp")])
5164
5165 (define_insn ""
5166   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5167         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5168                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5169   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5170   "{fa|fadd} %0,%1,%2"
5171   [(set_attr "type" "fp")])
5172
5173 (define_expand "subsf3"
5174   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5175         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
5176                   (match_operand:SF 2 "gpc_reg_operand" "")))]
5177   "TARGET_HARD_FLOAT"
5178   "")
5179
5180 (define_insn ""
5181   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5182         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5183                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5184   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5185   "fsubs %0,%1,%2"
5186   [(set_attr "type" "fp")])
5187
5188 (define_insn ""
5189   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5190         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5191                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
5192   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5193   "{fs|fsub} %0,%1,%2"
5194   [(set_attr "type" "fp")])
5195
5196 (define_expand "mulsf3"
5197   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5198         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
5199                  (match_operand:SF 2 "gpc_reg_operand" "")))]
5200   "TARGET_HARD_FLOAT"
5201   "")
5202
5203 (define_insn ""
5204   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5205         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5206                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5207   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5208   "fmuls %0,%1,%2"
5209   [(set_attr "type" "fp")])
5210
5211 (define_insn ""
5212   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5213         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5214                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
5215   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5216   "{fm|fmul} %0,%1,%2"
5217   [(set_attr "type" "dmul")])
5218
5219 (define_expand "divsf3"
5220   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5221         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
5222                 (match_operand:SF 2 "gpc_reg_operand" "")))]
5223   "TARGET_HARD_FLOAT"
5224   "")
5225
5226 (define_insn ""
5227   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5228         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5229                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5230   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5231   "fdivs %0,%1,%2"
5232   [(set_attr "type" "sdiv")])
5233
5234 (define_insn ""
5235   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5236         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
5237                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
5238   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS"
5239   "{fd|fdiv} %0,%1,%2"
5240   [(set_attr "type" "ddiv")])
5241
5242 (define_insn ""
5243   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5244         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5245                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5246                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5247   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5248   "fmadds %0,%1,%2,%3"
5249   [(set_attr "type" "fp")])
5250
5251 (define_insn ""
5252   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5253         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5254                           (match_operand:SF 2 "gpc_reg_operand" "f"))
5255                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
5256   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5257   "{fma|fmadd} %0,%1,%2,%3"
5258   [(set_attr "type" "dmul")])
5259
5260 (define_insn ""
5261   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5262         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5263                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5264                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5265   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5266   "fmsubs %0,%1,%2,%3"
5267   [(set_attr "type" "fp")])
5268
5269 (define_insn ""
5270   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5271         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5272                            (match_operand:SF 2 "gpc_reg_operand" "f"))
5273                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
5274   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5275   "{fms|fmsub} %0,%1,%2,%3"
5276   [(set_attr "type" "dmul")])
5277
5278 (define_insn ""
5279   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5280         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5281                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5282                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5283   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5284   "fnmadds %0,%1,%2,%3"
5285   [(set_attr "type" "fp")])
5286
5287 (define_insn ""
5288   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5289         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5290                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
5291                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5292   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5293   "{fnma|fnmadd} %0,%1,%2,%3"
5294   [(set_attr "type" "dmul")])
5295
5296 (define_insn ""
5297   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5298         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5299                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5300                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5301   "TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5302   "fnmsubs %0,%1,%2,%3"
5303   [(set_attr "type" "fp")])
5304
5305 (define_insn ""
5306   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5307         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
5308                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
5309                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
5310   "! TARGET_POWERPC && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5311   "{fnms|fnmsub} %0,%1,%2,%3"
5312   [(set_attr "type" "dmul")])
5313
5314 (define_expand "sqrtsf2"
5315   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5316         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
5317   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
5318   "")
5319
5320 (define_insn ""
5321   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5322         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5323   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5324   "fsqrts %0,%1"
5325   [(set_attr "type" "ssqrt")])
5326
5327 (define_insn ""
5328   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5329         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
5330   "TARGET_POWER2 && TARGET_HARD_FLOAT && TARGET_FPRS"
5331   "fsqrt %0,%1"
5332   [(set_attr "type" "dsqrt")])
5333
5334 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
5335 ;; fsel instruction and some auxiliary computations.  Then we just have a
5336 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
5337 ;; combine.
5338 (define_expand "maxsf3"
5339   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5340         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
5341                              (match_operand:SF 2 "gpc_reg_operand" ""))
5342                          (match_dup 1)
5343                          (match_dup 2)))]
5344   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5345   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5346
5347 (define_expand "minsf3"
5348   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5349         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "")
5350                              (match_operand:SF 2 "gpc_reg_operand" ""))
5351                          (match_dup 2)
5352                          (match_dup 1)))]
5353   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5354   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5355
5356 (define_split
5357   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5358         (match_operator:SF 3 "min_max_operator"
5359          [(match_operand:SF 1 "gpc_reg_operand" "")
5360           (match_operand:SF 2 "gpc_reg_operand" "")]))]
5361   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5362   [(const_int 0)]
5363   "
5364 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]), 
5365                       operands[1], operands[2]);
5366   DONE;
5367 }")
5368
5369 (define_expand "movsicc"
5370    [(set (match_operand:SI 0 "gpc_reg_operand" "")
5371          (if_then_else:SI (match_operand 1 "comparison_operator" "")
5372                           (match_operand:SI 2 "gpc_reg_operand" "")
5373                           (match_operand:SI 3 "gpc_reg_operand" "")))]
5374   "TARGET_ISEL"
5375   "
5376 {
5377   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5378     DONE;
5379   else
5380     FAIL;
5381 }")
5382
5383 ;; We use the BASE_REGS for the isel input operands because, if rA is
5384 ;; 0, the value of 0 is placed in rD upon truth.  Similarly for rB
5385 ;; because we may switch the operands and rB may end up being rA.
5386 ;;
5387 ;; We need 2 patterns: an unsigned and a signed pattern.  We could
5388 ;; leave out the mode in operand 4 and use one pattern, but reload can
5389 ;; change the mode underneath our feet and then gets confused trying
5390 ;; to reload the value.
5391 (define_insn "isel_signed"
5392   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5393         (if_then_else:SI
5394          (match_operator 1 "comparison_operator"
5395                          [(match_operand:CC 4 "cc_reg_operand" "y")
5396                           (const_int 0)])
5397          (match_operand:SI 2 "gpc_reg_operand" "b")
5398          (match_operand:SI 3 "gpc_reg_operand" "b")))]
5399   "TARGET_ISEL"
5400   "*
5401 { return output_isel (operands); }"
5402   [(set_attr "length" "4")])
5403
5404 (define_insn "isel_unsigned"
5405   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5406         (if_then_else:SI
5407          (match_operator 1 "comparison_operator"
5408                          [(match_operand:CCUNS 4 "cc_reg_operand" "y")
5409                           (const_int 0)])
5410          (match_operand:SI 2 "gpc_reg_operand" "b")
5411          (match_operand:SI 3 "gpc_reg_operand" "b")))]
5412   "TARGET_ISEL"
5413   "*
5414 { return output_isel (operands); }"
5415   [(set_attr "length" "4")])
5416
5417 (define_expand "movsfcc"
5418    [(set (match_operand:SF 0 "gpc_reg_operand" "")
5419          (if_then_else:SF (match_operand 1 "comparison_operator" "")
5420                           (match_operand:SF 2 "gpc_reg_operand" "")
5421                           (match_operand:SF 3 "gpc_reg_operand" "")))]
5422   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5423   "
5424 {
5425   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5426     DONE;
5427   else
5428     FAIL;
5429 }")
5430
5431 (define_insn "*fselsfsf4"
5432   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5433         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5434                              (match_operand:SF 4 "zero_fp_constant" "F"))
5435                          (match_operand:SF 2 "gpc_reg_operand" "f")
5436                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5437   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5438   "fsel %0,%1,%2,%3"
5439   [(set_attr "type" "fp")])
5440
5441 (define_insn "*fseldfsf4"
5442   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5443         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
5444                              (match_operand:DF 4 "zero_fp_constant" "F"))
5445                          (match_operand:SF 2 "gpc_reg_operand" "f")
5446                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
5447   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5448   "fsel %0,%1,%2,%3"
5449   [(set_attr "type" "fp")])
5450
5451 (define_insn "negdf2"
5452   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5453         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5454   "TARGET_HARD_FLOAT && TARGET_FPRS"
5455   "fneg %0,%1"
5456   [(set_attr "type" "fp")])
5457
5458 (define_insn "absdf2"
5459   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5460         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5461   "TARGET_HARD_FLOAT && TARGET_FPRS"
5462   "fabs %0,%1"
5463   [(set_attr "type" "fp")])
5464
5465 (define_insn ""
5466   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5467         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
5468   "TARGET_HARD_FLOAT && TARGET_FPRS"
5469   "fnabs %0,%1"
5470   [(set_attr "type" "fp")])
5471
5472 (define_insn "adddf3"
5473   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5474         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5475                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
5476   "TARGET_HARD_FLOAT && TARGET_FPRS"
5477   "{fa|fadd} %0,%1,%2"
5478   [(set_attr "type" "fp")])
5479
5480 (define_insn "subdf3"
5481   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5482         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5483                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
5484   "TARGET_HARD_FLOAT && TARGET_FPRS"
5485   "{fs|fsub} %0,%1,%2"
5486   [(set_attr "type" "fp")])
5487
5488 (define_insn "muldf3"
5489   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5490         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5491                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
5492   "TARGET_HARD_FLOAT && TARGET_FPRS"
5493   "{fm|fmul} %0,%1,%2"
5494   [(set_attr "type" "dmul")])
5495
5496 (define_insn "divdf3"
5497   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5498         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
5499                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
5500   "TARGET_HARD_FLOAT && TARGET_FPRS"
5501   "{fd|fdiv} %0,%1,%2"
5502   [(set_attr "type" "ddiv")])
5503
5504 (define_insn ""
5505   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5506         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5507                           (match_operand:DF 2 "gpc_reg_operand" "f"))
5508                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
5509   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5510   "{fma|fmadd} %0,%1,%2,%3"
5511   [(set_attr "type" "dmul")])
5512
5513 (define_insn ""
5514   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5515         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5516                            (match_operand:DF 2 "gpc_reg_operand" "f"))
5517                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
5518   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5519   "{fms|fmsub} %0,%1,%2,%3"
5520   [(set_attr "type" "dmul")])
5521
5522 (define_insn ""
5523   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5524         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5525                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
5526                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5527   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5528   "{fnma|fnmadd} %0,%1,%2,%3"
5529   [(set_attr "type" "dmul")])
5530
5531 (define_insn ""
5532   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5533         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
5534                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
5535                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
5536   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_FUSED_MADD"
5537   "{fnms|fnmsub} %0,%1,%2,%3"
5538   [(set_attr "type" "dmul")])
5539
5540 (define_insn "sqrtdf2"
5541   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5542         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
5543   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT && TARGET_FPRS"
5544   "fsqrt %0,%1"
5545   [(set_attr "type" "dsqrt")])
5546
5547 ;; The conditional move instructions allow us to perform max and min
5548 ;; operations even when 
5549
5550 (define_expand "maxdf3"
5551   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5552         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5553                              (match_operand:DF 2 "gpc_reg_operand" ""))
5554                          (match_dup 1)
5555                          (match_dup 2)))]
5556   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5557   "{ rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]); DONE;}")
5558
5559 (define_expand "mindf3"
5560   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5561         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "")
5562                              (match_operand:DF 2 "gpc_reg_operand" ""))
5563                          (match_dup 2)
5564                          (match_dup 1)))]
5565   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5566   "{ rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]); DONE;}")
5567
5568 (define_split
5569   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5570         (match_operator:DF 3 "min_max_operator"
5571          [(match_operand:DF 1 "gpc_reg_operand" "")
5572           (match_operand:DF 2 "gpc_reg_operand" "")]))]
5573   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5574   [(const_int 0)]
5575   "
5576 { rs6000_emit_minmax (operands[0], GET_CODE (operands[3]), 
5577                       operands[1], operands[2]);
5578   DONE;
5579 }")
5580
5581 (define_expand "movdfcc"
5582    [(set (match_operand:DF 0 "gpc_reg_operand" "")
5583          (if_then_else:DF (match_operand 1 "comparison_operator" "")
5584                           (match_operand:DF 2 "gpc_reg_operand" "")
5585                           (match_operand:DF 3 "gpc_reg_operand" "")))]
5586   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5587   "
5588 {
5589   if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5590     DONE;
5591   else
5592     FAIL;
5593 }")
5594
5595 (define_insn "*fseldfdf4"
5596   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5597         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
5598                              (match_operand:DF 4 "zero_fp_constant" "F"))
5599                          (match_operand:DF 2 "gpc_reg_operand" "f")
5600                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5601   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS"
5602   "fsel %0,%1,%2,%3"
5603   [(set_attr "type" "fp")])
5604
5605 (define_insn "*fselsfdf4"
5606   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5607         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
5608                              (match_operand:SF 4 "zero_fp_constant" "F"))
5609                          (match_operand:DF 2 "gpc_reg_operand" "f")
5610                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
5611   "TARGET_PPC_GFXOPT"
5612   "fsel %0,%1,%2,%3"
5613   [(set_attr "type" "fp")])
5614 \f
5615 ;; Conversions to and from floating-point.
5616
5617 (define_expand "fixunssfsi2"
5618   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5619         (unsigned_fix:SI (fix:SF (match_operand:SF 1 "gpc_reg_operand" ""))))]
5620   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5621   "")
5622
5623 (define_expand "fix_truncsfsi2"
5624   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5625         (fix:SI (match_operand:SF 1 "gpc_reg_operand" "")))]
5626   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5627   "")
5628
5629 ; For each of these conversions, there is a define_expand, a define_insn
5630 ; with a '#' template, and a define_split (with C code).  The idea is
5631 ; to allow constant folding with the template of the define_insn,
5632 ; then to have the insns split later (between sched1 and final).
5633
5634 (define_expand "floatsidf2"
5635   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5636                    (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5637               (use (match_dup 2))
5638               (use (match_dup 3))
5639               (clobber (match_dup 4))
5640               (clobber (match_dup 5))
5641               (clobber (match_dup 6))])]
5642   "TARGET_HARD_FLOAT && TARGET_FPRS"
5643   "
5644 {
5645   if (TARGET_POWERPC64)
5646     {
5647       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5648       rtx t1 = gen_reg_rtx (DImode);
5649       rtx t2 = gen_reg_rtx (DImode);
5650       emit_insn (gen_floatsidf_ppc64 (operands[0], operands[1], mem, t1, t2));
5651       DONE;
5652     }
5653
5654   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5655   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
5656   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5657   operands[5] = gen_reg_rtx (DFmode);
5658   operands[6] = gen_reg_rtx (SImode);
5659 }")
5660
5661 (define_insn "*floatsidf2_internal"
5662   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5663         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5664    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5665    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5666    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5667    (clobber (match_operand:DF 5 "gpc_reg_operand" "=f"))
5668    (clobber (match_operand:SI 6 "gpc_reg_operand" "=r"))]
5669   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5670   "#"
5671   [(set_attr "length" "24")])
5672
5673 (define_split
5674   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5675         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5676    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5677    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5678    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5679    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))
5680    (clobber (match_operand:SI 6 "gpc_reg_operand" ""))]
5681   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5682   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5683         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5684    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5685    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5686    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5687    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))
5688    (clobber (match_operand:SI 6 "gpc_reg_operand" ""))]
5689   "
5690 {
5691   rtx lowword, highword;
5692   if (GET_CODE (operands[4]) != MEM)
5693     abort();
5694   highword = XEXP (operands[4], 0);
5695   lowword = plus_constant (highword, 4);
5696   if (! WORDS_BIG_ENDIAN)
5697     {
5698       rtx tmp;
5699       tmp = highword; highword = lowword; lowword = tmp;
5700     }
5701
5702   emit_insn (gen_xorsi3 (operands[6], operands[1], 
5703                          GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
5704   emit_move_insn (gen_rtx_MEM (SImode, lowword), operands[6]);
5705   emit_move_insn (gen_rtx_MEM (SImode, highword), operands[2]);
5706   emit_move_insn (operands[5], operands[4]);
5707   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5708   DONE;
5709 }")
5710
5711 (define_expand "floatunssisf2"
5712   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5713         (unsigned_float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5714   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5715   "")
5716
5717 (define_expand "floatunssidf2"
5718   [(parallel [(set (match_operand:DF 0 "gpc_reg_operand" "")
5719                    (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5720               (use (match_dup 2))
5721               (use (match_dup 3))
5722               (clobber (match_dup 4))
5723               (clobber (match_dup 5))])]
5724   "TARGET_HARD_FLOAT && TARGET_FPRS"
5725   "
5726 {
5727   if (TARGET_POWERPC64)
5728     {
5729       rtx mem = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5730       rtx t1 = gen_reg_rtx (DImode);
5731       rtx t2 = gen_reg_rtx (DImode);
5732       emit_insn (gen_floatunssidf_ppc64 (operands[0], operands[1], mem,
5733                                          t1, t2));
5734       DONE;
5735     }
5736
5737   operands[2] = force_reg (SImode, GEN_INT (0x43300000));
5738   operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
5739   operands[4] = assign_stack_temp (DFmode, GET_MODE_SIZE (DFmode), 0);
5740   operands[5] = gen_reg_rtx (DFmode);
5741 }")
5742
5743 (define_insn "*floatunssidf2_internal"
5744   [(set (match_operand:DF 0 "gpc_reg_operand" "=&f")
5745         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5746    (use (match_operand:SI 2 "gpc_reg_operand" "r"))
5747    (use (match_operand:DF 3 "gpc_reg_operand" "f"))
5748    (clobber (match_operand:DF 4 "memory_operand" "=o"))
5749    (clobber (match_operand:DF 5 "gpc_reg_operand" "=f"))]
5750   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5751   "#"
5752   [(set_attr "length" "20")])
5753
5754 (define_split
5755   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5756         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5757    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5758    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5759    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5760    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))]
5761   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5762   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5763         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
5764    (use (match_operand:SI 2 "gpc_reg_operand" ""))
5765    (use (match_operand:DF 3 "gpc_reg_operand" ""))
5766    (clobber (match_operand:DF 4 "offsettable_mem_operand" ""))
5767    (clobber (match_operand:DF 5 "gpc_reg_operand" ""))]
5768   "
5769 {
5770   rtx lowword, highword;
5771   if (GET_CODE (operands[4]) != MEM)
5772     abort();
5773   highword = XEXP (operands[4], 0);
5774   lowword = plus_constant (highword, 4);
5775   if (! WORDS_BIG_ENDIAN)
5776     {
5777       rtx tmp;
5778       tmp = highword; highword = lowword; lowword = tmp;
5779     }
5780
5781   emit_move_insn (gen_rtx_MEM (SImode, lowword), operands[1]);
5782   emit_move_insn (gen_rtx_MEM (SImode, highword), operands[2]);
5783   emit_move_insn (operands[5], operands[4]);
5784   emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
5785   DONE;
5786 }")
5787
5788 (define_expand "fix_truncdfsi2"
5789   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
5790                    (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5791               (clobber (match_dup 2))
5792               (clobber (match_dup 3))])]
5793   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5794   "
5795 {
5796   operands[2] = gen_reg_rtx (DImode);
5797   operands[3] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode), 0);
5798 }")
5799
5800 (define_insn "*fix_truncdfsi2_internal"
5801   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
5802         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f")))
5803    (clobber (match_operand:DI 2 "gpc_reg_operand" "=f"))
5804    (clobber (match_operand:DI 3 "memory_operand" "=o"))]
5805   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5806   "#"
5807   [(set_attr "length" "16")])
5808
5809 (define_split
5810   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5811         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5812    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
5813    (clobber (match_operand:DI 3 "offsettable_mem_operand" ""))]
5814   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5815   [(set (match_operand:SI 0 "gpc_reg_operand" "")
5816         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))
5817    (clobber (match_operand:DI 2 "gpc_reg_operand" ""))
5818    (clobber (match_operand:DI 3 "offsettable_mem_operand" ""))]
5819   "
5820 {
5821   rtx lowword;
5822   if (GET_CODE (operands[3]) != MEM)
5823     abort();
5824   lowword = XEXP (operands[3], 0);
5825   if (WORDS_BIG_ENDIAN)
5826     lowword = plus_constant (lowword, 4);
5827
5828   emit_insn (gen_fctiwz (operands[2], operands[1]));
5829   emit_move_insn (operands[3], operands[2]);
5830   emit_move_insn (operands[0], gen_rtx_MEM (SImode, lowword));
5831   DONE;
5832 }")
5833
5834 ; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] 10))
5835 ; rather than (set (subreg:SI (reg)) (fix:SI ...))
5836 ; because the first makes it clear that operand 0 is not live
5837 ; before the instruction.
5838 (define_insn "fctiwz"
5839   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5840         (unspec:DI [(fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))] 10))]
5841   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT && TARGET_FPRS"
5842   "{fcirz|fctiwz} %0,%1"
5843   [(set_attr "type" "fp")])
5844
5845 (define_expand "floatsisf2"
5846   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5847         (float:SF (match_operand:SI 1 "gpc_reg_operand" "")))]
5848   "TARGET_HARD_FLOAT && !TARGET_FPRS"
5849   "")
5850
5851 (define_insn "floatdidf2"
5852   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5853         (float:DF (match_operand:DI 1 "gpc_reg_operand" "*f")))]
5854   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5855   "fcfid %0,%1"
5856   [(set_attr "type" "fp")])
5857
5858 (define_insn_and_split "floatsidf_ppc64"
5859   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5860         (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5861    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5862    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5863    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5864   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5865   "#"
5866   ""
5867   [(set (match_dup 3) (sign_extend:DI (match_dup 1)))
5868    (set (match_dup 2) (match_dup 3))
5869    (set (match_dup 4) (match_dup 2))
5870    (set (match_dup 0) (float:DF (match_dup 4)))]
5871   "")
5872
5873 (define_insn_and_split "floatunssidf_ppc64"
5874   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
5875         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
5876    (clobber (match_operand:DI 2 "memory_operand" "=o"))
5877    (clobber (match_operand:DI 3 "gpc_reg_operand" "=r"))
5878    (clobber (match_operand:DI 4 "gpc_reg_operand" "=f"))]
5879   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5880   "#"
5881   ""
5882   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
5883    (set (match_dup 2) (match_dup 3))
5884    (set (match_dup 4) (match_dup 2))
5885    (set (match_dup 0) (float:DF (match_dup 4)))]
5886   "")
5887
5888 (define_insn "fix_truncdfdi2"
5889   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
5890         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
5891   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS"
5892   "fctidz %0,%1"
5893   [(set_attr "type" "fp")])
5894
5895 ;; This only is safe if rounding mode set appropriately.
5896 (define_insn_and_split "floatdisf2"
5897   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
5898         (float:SF (match_operand:DI 1 "gpc_reg_operand" "*f")))
5899    (clobber (match_scratch:DF 2 "=f"))]
5900   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
5901    && flag_unsafe_math_optimizations"
5902   "#"
5903   "&& reload_completed"
5904   [(set (match_dup 2)
5905         (float:DF (match_dup 1)))
5906    (set (match_dup 0)
5907         (float_truncate:SF (match_dup 2)))]
5908   "")
5909 \f
5910 ;; Define the DImode operations that can be done in a small number
5911 ;; of instructions.  The & constraints are to prevent the register
5912 ;; allocator from allocating registers that overlap with the inputs
5913 ;; (for example, having an input in 7,8 and an output in 6,7).  We
5914 ;; also allow for the output being the same as one of the inputs.
5915
5916 (define_insn "*adddi3_noppc64"
5917   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
5918         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
5919                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
5920   "! TARGET_POWERPC64"
5921   "*
5922 {
5923   if (WORDS_BIG_ENDIAN)
5924     return (GET_CODE (operands[2])) != CONST_INT
5925             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
5926             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
5927   else
5928     return (GET_CODE (operands[2])) != CONST_INT
5929             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
5930             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
5931 }"
5932   [(set_attr "length" "8")])
5933
5934 (define_insn "*subdi3_noppc64"
5935   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
5936         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
5937                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
5938   "! TARGET_POWERPC64"
5939   "*
5940 {
5941   if (WORDS_BIG_ENDIAN)
5942     return (GET_CODE (operands[1]) != CONST_INT)
5943             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
5944             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
5945   else
5946     return (GET_CODE (operands[1]) != CONST_INT)
5947             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
5948             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
5949 }"
5950   [(set_attr "length" "8")])
5951
5952 (define_insn "*negdi2_noppc64"
5953   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
5954         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
5955   "! TARGET_POWERPC64"
5956   "*
5957 {
5958   return (WORDS_BIG_ENDIAN)
5959     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
5960     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
5961 }"
5962   [(set_attr "length" "8")])
5963
5964 (define_expand "mulsidi3"
5965   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5966         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
5967                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
5968   "! TARGET_POWERPC64"
5969   "
5970 {
5971   if (! TARGET_POWER && ! TARGET_POWERPC)
5972     {
5973       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
5974       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
5975       emit_insn (gen_mull_call ());
5976       if (WORDS_BIG_ENDIAN)
5977         emit_move_insn (operands[0], gen_rtx_REG (DImode, 3));
5978       else
5979         {
5980           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
5981                           gen_rtx_REG (SImode, 3));
5982           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
5983                           gen_rtx_REG (SImode, 4));
5984         }
5985       DONE;
5986     }
5987   else if (TARGET_POWER)
5988     {
5989       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
5990       DONE;
5991     }
5992 }")
5993
5994 (define_insn "mulsidi3_mq"
5995   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
5996         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
5997                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
5998    (clobber (match_scratch:SI 3 "=q"))]
5999   "TARGET_POWER"
6000   "mul %0,%1,%2\;mfmq %L0"
6001   [(set_attr "type" "imul")
6002    (set_attr "length" "8")])
6003
6004 (define_insn "*mulsidi3_no_mq"
6005   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6006         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6007                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6008   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
6009   "*
6010 {
6011   return (WORDS_BIG_ENDIAN)
6012     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
6013     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
6014 }"
6015   [(set_attr "type" "imul")
6016    (set_attr "length" "8")])
6017
6018 (define_split
6019   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6020         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6021                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6022   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
6023   [(set (match_dup 3)
6024         (truncate:SI
6025          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
6026                                (sign_extend:DI (match_dup 2)))
6027                       (const_int 32))))
6028    (set (match_dup 4)
6029         (mult:SI (match_dup 1)
6030                  (match_dup 2)))]
6031   "
6032 {
6033   int endian = (WORDS_BIG_ENDIAN == 0);
6034   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6035   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6036 }")
6037
6038 (define_expand "umulsidi3"
6039   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6040         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6041                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6042   "TARGET_POWERPC && ! TARGET_POWERPC64"
6043   "
6044 {
6045   if (TARGET_POWER)
6046     {
6047       emit_insn (gen_umulsidi3_mq (operands[0], operands[1], operands[2]));
6048       DONE;
6049     }
6050 }")
6051
6052 (define_insn "umulsidi3_mq"
6053   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6054         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6055                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
6056    (clobber (match_scratch:SI 3 "=q"))]
6057   "TARGET_POWERPC && TARGET_POWER"
6058   "*
6059 {
6060   return (WORDS_BIG_ENDIAN)
6061     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6062     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6063 }"
6064   [(set_attr "type" "imul")
6065    (set_attr "length" "8")])
6066
6067 (define_insn "*umulsidi3_no_mq"
6068   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6069         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
6070                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
6071   "TARGET_POWERPC && ! TARGET_POWER && ! TARGET_POWERPC64"
6072   "*
6073 {
6074   return (WORDS_BIG_ENDIAN)
6075     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
6076     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
6077 }"
6078   [(set_attr "type" "imul")
6079    (set_attr "length" "8")])
6080
6081 (define_split
6082   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6083         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
6084                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
6085   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
6086   [(set (match_dup 3)
6087         (truncate:SI
6088          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
6089                                (zero_extend:DI (match_dup 2)))
6090                       (const_int 32))))
6091    (set (match_dup 4)
6092         (mult:SI (match_dup 1)
6093                  (match_dup 2)))]
6094   "
6095 {
6096   int endian = (WORDS_BIG_ENDIAN == 0);
6097   operands[3] = operand_subword (operands[0], endian, 0, DImode);
6098   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
6099 }")
6100
6101 (define_expand "smulsi3_highpart"
6102   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6103         (truncate:SI
6104          (lshiftrt:DI (mult:DI (sign_extend:DI
6105                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6106                                (sign_extend:DI
6107                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6108                       (const_int 32))))]
6109   ""
6110   "
6111 {
6112   if (! TARGET_POWER && ! TARGET_POWERPC)
6113     {
6114       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
6115       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
6116       emit_insn (gen_mulh_call ());
6117       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
6118       DONE;
6119     }
6120   else if (TARGET_POWER)
6121     {
6122       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
6123       DONE;
6124     }
6125 }")
6126
6127 (define_insn "smulsi3_highpart_mq"
6128   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6129         (truncate:SI
6130          (lshiftrt:DI (mult:DI (sign_extend:DI
6131                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6132                                (sign_extend:DI
6133                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6134                       (const_int 32))))
6135    (clobber (match_scratch:SI 3 "=q"))]
6136   "TARGET_POWER"
6137   "mul %0,%1,%2"
6138   [(set_attr "type" "imul")])
6139
6140 (define_insn "*smulsi3_highpart_no_mq"
6141   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6142         (truncate:SI
6143          (lshiftrt:DI (mult:DI (sign_extend:DI
6144                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6145                                (sign_extend:DI
6146                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6147                       (const_int 32))))]
6148   "TARGET_POWERPC && ! TARGET_POWER"
6149   "mulhw %0,%1,%2"
6150   [(set_attr "type" "imul")])
6151
6152 (define_expand "umulsi3_highpart"
6153   [(set (match_operand:SI 0 "gpc_reg_operand" "")
6154         (truncate:SI
6155          (lshiftrt:DI (mult:DI (zero_extend:DI
6156                                 (match_operand:SI 1 "gpc_reg_operand" ""))
6157                                (zero_extend:DI
6158                                 (match_operand:SI 2 "gpc_reg_operand" "")))
6159                       (const_int 32))))]
6160   "TARGET_POWERPC"
6161   "
6162 {
6163   if (TARGET_POWER)
6164     {
6165       emit_insn (gen_umulsi3_highpart_mq (operands[0], operands[1], operands[2]));
6166       DONE;
6167     }
6168 }")
6169
6170 (define_insn "umulsi3_highpart_mq"
6171   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6172         (truncate:SI
6173          (lshiftrt:DI (mult:DI (zero_extend:DI
6174                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6175                                (zero_extend:DI
6176                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6177                       (const_int 32))))
6178    (clobber (match_scratch:SI 3 "=q"))]
6179   "TARGET_POWERPC && TARGET_POWER"
6180   "mulhwu %0,%1,%2"
6181   [(set_attr "type" "imul")])
6182
6183 (define_insn "*umulsi3_highpart_no_mq"
6184   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
6185         (truncate:SI
6186          (lshiftrt:DI (mult:DI (zero_extend:DI
6187                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
6188                                (zero_extend:DI
6189                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
6190                       (const_int 32))))]
6191   "TARGET_POWERPC && ! TARGET_POWER"
6192   "mulhwu %0,%1,%2"
6193   [(set_attr "type" "imul")])
6194
6195 ;; If operands 0 and 2 are in the same register, we have a problem.  But
6196 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
6197 ;; why we have the strange constraints below.
6198 (define_insn "ashldi3_power"
6199   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
6200         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
6201                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
6202    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
6203   "TARGET_POWER"
6204   "@
6205    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
6206    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
6207    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
6208    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
6209   [(set_attr "length" "8")])
6210
6211 (define_insn "lshrdi3_power"
6212   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
6213         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
6214                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
6215    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
6216   "TARGET_POWER"
6217   "@
6218    {s%A2i|s%A2wi} %L0,%1,%h2\;{cal %0,0(0)|li %0,0}
6219    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
6220    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
6221    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
6222   [(set_attr "length" "8")])
6223
6224 ;; Shift by a variable amount is too complex to be worth open-coding.  We
6225 ;; just handle shifts by constants.
6226 (define_insn "ashrdi3_power"
6227   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6228         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6229                      (match_operand:SI 2 "const_int_operand" "M,i")))
6230    (clobber (match_scratch:SI 3 "=X,q"))]
6231   "TARGET_POWER"
6232   "@
6233    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
6234    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
6235   [(set_attr "length" "8")])
6236
6237 (define_insn "ashrdi3_no_power"
6238   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
6239         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6240                      (match_operand:SI 2 "const_int_operand" "M,i")))]
6241   "TARGET_32BIT && !TARGET_POWER"
6242   "@
6243    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
6244    {sri|srwi} %L0,%L1,%h2\;insrwi %L0,%1,%h2,0\;{srai|srawi} %0,%1,%h2"
6245   [(set_attr "length" "8,12")])
6246 \f
6247 ;; PowerPC64 DImode operations.
6248
6249 (define_expand "adddi3"
6250   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6251         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
6252                  (match_operand:DI 2 "reg_or_add_cint64_operand" "")))]
6253   ""
6254   "
6255 {
6256   if (! TARGET_POWERPC64)
6257     {
6258       if (non_short_cint_operand (operands[2], DImode))
6259         FAIL;
6260     }
6261   else
6262     if (GET_CODE (operands[2]) == CONST_INT
6263         && ! add_operand (operands[2], DImode))
6264       {
6265         rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
6266                    ? operands[0] : gen_reg_rtx (DImode));
6267
6268         HOST_WIDE_INT val = INTVAL (operands[2]);
6269         HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
6270         HOST_WIDE_INT rest = trunc_int_for_mode (val - low, DImode);
6271
6272         if (!CONST_OK_FOR_LETTER_P (rest, 'L'))
6273           FAIL;
6274
6275         /* The ordering here is important for the prolog expander.
6276            When space is allocated from the stack, adding 'low' first may
6277            produce a temporary deallocation (which would be bad).  */
6278         emit_insn (gen_adddi3 (tmp, operands[1], GEN_INT (rest)));
6279         emit_insn (gen_adddi3 (operands[0], tmp, GEN_INT (low)));
6280         DONE;
6281       }
6282 }")
6283
6284 ;; Discourage ai/addic because of carry but provide it in an alternative
6285 ;; allowing register zero as source.
6286
6287 (define_insn "*adddi3_internal1"
6288   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,?r,r")
6289         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,b,r,b")
6290                  (match_operand:DI 2 "add_operand" "r,I,I,L")))]
6291   "TARGET_POWERPC64"
6292   "@
6293    add %0,%1,%2
6294    addi %0,%1,%2
6295    addic %0,%1,%2
6296    addis %0,%1,%v2")
6297
6298 (define_insn "*adddi3_internal2"
6299   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
6300         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
6301                              (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I"))
6302                     (const_int 0)))
6303    (clobber (match_scratch:DI 3 "=r,r,r,r"))]
6304   "TARGET_POWERPC64"
6305   "@
6306    add. %3,%1,%2
6307    addic. %3,%1,%2
6308    #
6309    #"
6310   [(set_attr "type" "compare")
6311    (set_attr "length" "4,4,8,8")])
6312
6313 (define_split
6314   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6315         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
6316                              (match_operand:DI 2 "reg_or_short_operand" ""))
6317                     (const_int 0)))
6318    (clobber (match_scratch:DI 3 ""))]
6319   "TARGET_POWERPC64 && reload_completed"
6320   [(set (match_dup 3)
6321         (plus:DI (match_dup 1) (match_dup 2)))
6322    (set (match_dup 0)
6323         (compare:CC (match_dup 3)
6324                     (const_int 0)))]
6325   "")
6326
6327 (define_insn "*adddi3_internal3"
6328   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
6329         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r")
6330                              (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I"))
6331                     (const_int 0)))
6332    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
6333         (plus:DI (match_dup 1) (match_dup 2)))]
6334   "TARGET_POWERPC64"
6335   "@
6336    add. %0,%1,%2
6337    addic. %0,%1,%2
6338    #
6339    #"
6340   [(set_attr "type" "compare")
6341    (set_attr "length" "4,4,8,8")])
6342
6343 (define_split
6344   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6345         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
6346                              (match_operand:DI 2 "reg_or_short_operand" ""))
6347                     (const_int 0)))
6348    (set (match_operand:DI 0 "gpc_reg_operand" "")
6349         (plus:DI (match_dup 1) (match_dup 2)))]
6350   "TARGET_POWERPC64 && reload_completed"
6351   [(set (match_dup 0)
6352         (plus:DI (match_dup 1) (match_dup 2)))
6353    (set (match_dup 3)
6354         (compare:CC (match_dup 0)
6355                     (const_int 0)))]
6356   "")
6357
6358 ;; Split an add that we can't do in one insn into two insns, each of which
6359 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
6360 ;; add should be last in case the result gets used in an address.
6361
6362 (define_split
6363   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6364         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
6365                  (match_operand:DI 2 "non_add_cint_operand" "")))]
6366   "TARGET_POWERPC64"
6367   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 3)))
6368    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 4)))]
6369 "
6370 {
6371   HOST_WIDE_INT val = INTVAL (operands[2]);
6372   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
6373   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, DImode);
6374
6375   operands[4] = GEN_INT (low);
6376   if (CONST_OK_FOR_LETTER_P (rest, 'L'))
6377     operands[3] = GEN_INT (rest);
6378   else if (! no_new_pseudos)
6379     {
6380       operands[3] = gen_reg_rtx (DImode);
6381       emit_move_insn (operands[3], operands[2]);
6382       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
6383       DONE;
6384     }
6385   else
6386     FAIL;
6387 }")
6388
6389 (define_insn "one_cmpldi2"
6390   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6391         (not:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
6392   "TARGET_POWERPC64"
6393   "nor %0,%1,%1")
6394
6395 (define_insn ""
6396   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6397         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
6398                     (const_int 0)))
6399    (clobber (match_scratch:DI 2 "=r,r"))]
6400   "TARGET_POWERPC64"
6401   "@
6402    nor. %2,%1,%1
6403    #"
6404   [(set_attr "type" "compare")
6405    (set_attr "length" "4,8")])
6406
6407 (define_split
6408   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6409         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
6410                     (const_int 0)))
6411    (clobber (match_scratch:DI 2 ""))]
6412   "TARGET_POWERPC64 && reload_completed"
6413   [(set (match_dup 2)
6414         (not:DI (match_dup 1)))
6415    (set (match_dup 0)
6416         (compare:CC (match_dup 2)
6417                     (const_int 0)))]
6418   "")
6419
6420 (define_insn ""
6421   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
6422         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
6423                     (const_int 0)))
6424    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6425         (not:DI (match_dup 1)))]
6426   "TARGET_POWERPC64"
6427   "@
6428    nor. %0,%1,%1
6429    #"
6430   [(set_attr "type" "compare")
6431    (set_attr "length" "4,8")])
6432
6433 (define_split
6434   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
6435         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
6436                     (const_int 0)))
6437    (set (match_operand:DI 0 "gpc_reg_operand" "")
6438         (not:DI (match_dup 1)))]
6439   "TARGET_POWERPC64 && reload_completed"
6440   [(set (match_dup 0)
6441         (not:DI (match_dup 1)))
6442    (set (match_dup 2)
6443         (compare:CC (match_dup 0)
6444                     (const_int 0)))]
6445   "")
6446
6447 (define_insn ""
6448   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6449         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I")
6450                   (match_operand:DI 2 "gpc_reg_operand" "r,r")))]
6451   "TARGET_POWERPC64"
6452   "@
6453    subf %0,%2,%1
6454    subfic %0,%2,%1")
6455
6456 (define_insn ""
6457   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6458         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6459                               (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6460                     (const_int 0)))
6461    (clobber (match_scratch:DI 3 "=r,r"))]
6462   "TARGET_POWERPC64"
6463   "@
6464    subf. %3,%2,%1
6465    #"
6466   [(set_attr "type" "compare")
6467    (set_attr "length" "4,8")])
6468
6469 (define_split
6470   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6471         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "")
6472                               (match_operand:DI 2 "gpc_reg_operand" ""))
6473                     (const_int 0)))
6474    (clobber (match_scratch:DI 3 ""))]
6475   "TARGET_POWERPC64 && reload_completed"
6476   [(set (match_dup 3)
6477         (minus:DI (match_dup 1) (match_dup 2)))
6478    (set (match_dup 0)
6479         (compare:CC (match_dup 3)
6480                     (const_int 0)))]
6481   "")
6482
6483 (define_insn ""
6484   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6485         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6486                               (match_operand:DI 2 "gpc_reg_operand" "r,r"))
6487                     (const_int 0)))
6488    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6489         (minus:DI (match_dup 1) (match_dup 2)))]
6490   "TARGET_POWERPC64"
6491   "@
6492    subf. %0,%2,%1
6493    #"
6494   [(set_attr "type" "compare")
6495    (set_attr "length" "4,8")])
6496
6497 (define_split
6498   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6499         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "")
6500                               (match_operand:DI 2 "gpc_reg_operand" ""))
6501                     (const_int 0)))
6502    (set (match_operand:DI 0 "gpc_reg_operand" "")
6503         (minus:DI (match_dup 1) (match_dup 2)))]
6504   "TARGET_POWERPC64 && reload_completed"
6505   [(set (match_dup 0)
6506         (minus:DI (match_dup 1) (match_dup 2)))
6507    (set (match_dup 3)
6508         (compare:CC (match_dup 0)
6509                     (const_int 0)))]
6510   "")
6511
6512 (define_expand "subdi3"
6513   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6514         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "")
6515                   (match_operand:DI 2 "reg_or_sub_cint64_operand" "")))]
6516   ""
6517   "
6518 {
6519   if (GET_CODE (operands[2]) == CONST_INT)
6520     {
6521       emit_insn (gen_adddi3 (operands[0], operands[1],
6522                              negate_rtx (DImode, operands[2])));
6523       DONE;
6524     }
6525 }")
6526
6527 (define_insn_and_split "absdi2"
6528   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6529         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
6530    (clobber (match_scratch:DI 2 "=&r,&r"))]
6531   "TARGET_POWERPC64"
6532   "#"
6533   "&& reload_completed"
6534   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
6535    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
6536    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
6537   "")
6538
6539 (define_insn_and_split "*nabsdi2"
6540   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
6541         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
6542    (clobber (match_scratch:DI 2 "=&r,&r"))]
6543   "TARGET_POWERPC64"
6544   "#"
6545   "&& reload_completed"
6546   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 63)))
6547    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
6548    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
6549   "")
6550
6551 (define_expand "negdi2"
6552   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6553         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "")))]
6554   ""
6555   "")
6556
6557 (define_insn ""
6558   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6559         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
6560   "TARGET_POWERPC64"
6561   "neg %0,%1")
6562
6563 (define_insn ""
6564   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6565         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
6566                     (const_int 0)))
6567    (clobber (match_scratch:DI 2 "=r,r"))]
6568   "TARGET_POWERPC64"
6569   "@
6570    neg. %2,%1
6571    #"
6572   [(set_attr "type" "compare")
6573    (set_attr "length" "4,8")])
6574
6575 (define_split
6576   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6577         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" ""))
6578                     (const_int 0)))
6579    (clobber (match_scratch:DI 2 ""))]
6580   "TARGET_POWERPC64 && reload_completed"
6581   [(set (match_dup 2)
6582         (neg:DI (match_dup 1)))
6583    (set (match_dup 0)
6584         (compare:CC (match_dup 2)
6585                     (const_int 0)))]
6586   "")
6587
6588 (define_insn ""
6589   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
6590         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
6591                     (const_int 0)))
6592    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6593         (neg:DI (match_dup 1)))]
6594   "TARGET_POWERPC64"
6595   "@
6596    neg. %0,%1
6597    #"
6598   [(set_attr "type" "compare")
6599    (set_attr "length" "4,8")])
6600
6601 (define_split
6602   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
6603         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" ""))
6604                     (const_int 0)))
6605    (set (match_operand:DI 0 "gpc_reg_operand" "")
6606         (neg:DI (match_dup 1)))]
6607   "TARGET_POWERPC64 && reload_completed"
6608   [(set (match_dup 0)
6609         (neg:DI (match_dup 1)))
6610    (set (match_dup 2)
6611         (compare:CC (match_dup 0)
6612                     (const_int 0)))]
6613   "")
6614
6615 (define_insn "ffsdi2"
6616   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
6617         (ffs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
6618   "TARGET_POWERPC64"
6619   "neg %0,%1\;and %0,%0,%1\;cntlzd %0,%0\;subfic %0,%0,64"
6620   [(set_attr "length" "16")])
6621
6622 (define_insn "muldi3"
6623   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6624         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
6625                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6626   "TARGET_POWERPC64"
6627   "mulld %0,%1,%2"
6628    [(set_attr "type" "lmul")])
6629
6630 (define_insn "smuldi3_highpart"
6631   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6632         (truncate:DI
6633          (lshiftrt:TI (mult:TI (sign_extend:TI
6634                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6635                                (sign_extend:TI
6636                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6637                       (const_int 64))))]
6638   "TARGET_POWERPC64"
6639   "mulhd %0,%1,%2"
6640   [(set_attr "type" "lmul")])
6641
6642 (define_insn "umuldi3_highpart"
6643   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6644         (truncate:DI
6645          (lshiftrt:TI (mult:TI (zero_extend:TI
6646                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
6647                                (zero_extend:TI
6648                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
6649                       (const_int 64))))]
6650   "TARGET_POWERPC64"
6651   "mulhdu %0,%1,%2"
6652   [(set_attr "type" "lmul")])
6653
6654 (define_expand "divdi3"
6655   [(set (match_operand:DI 0 "gpc_reg_operand" "")
6656         (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6657                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
6658   "TARGET_POWERPC64"
6659   "
6660 {
6661   if (GET_CODE (operands[2]) == CONST_INT
6662       && INTVAL (operands[2]) > 0
6663       && exact_log2 (INTVAL (operands[2])) >= 0)
6664     ;
6665   else
6666     operands[2] = force_reg (DImode, operands[2]);
6667 }")
6668
6669 (define_expand "moddi3"
6670   [(use (match_operand:DI 0 "gpc_reg_operand" ""))
6671    (use (match_operand:DI 1 "gpc_reg_operand" ""))
6672    (use (match_operand:DI 2 "reg_or_cint_operand" ""))]
6673   "TARGET_POWERPC64"
6674   "
6675 {
6676   int i;
6677   rtx temp1;
6678   rtx temp2;
6679
6680   if (GET_CODE (operands[2]) != CONST_INT
6681       || INTVAL (operands[2]) <= 0
6682       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
6683     FAIL;
6684
6685   temp1 = gen_reg_rtx (DImode);
6686   temp2 = gen_reg_rtx (DImode);
6687
6688   emit_insn (gen_divdi3 (temp1, operands[1], operands[2]));
6689   emit_insn (gen_ashldi3 (temp2, temp1, GEN_INT (i)));
6690   emit_insn (gen_subdi3 (operands[0], operands[1], temp2));
6691   DONE;
6692 }")
6693
6694 (define_insn ""
6695   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6696         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6697                 (match_operand:DI 2 "exact_log2_cint_operand" "N")))]
6698   "TARGET_POWERPC64"
6699   "sradi %0,%1,%p2\;addze %0,%0"
6700   [(set_attr "length" "8")])
6701
6702 (define_insn ""
6703   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6704         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6705                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6706                     (const_int 0)))
6707    (clobber (match_scratch:DI 3 "=r,r"))]
6708   "TARGET_POWERPC64"
6709   "@
6710    sradi %3,%1,%p2\;addze. %3,%3
6711    #"
6712   [(set_attr "type" "compare")
6713    (set_attr "length" "8,12")])
6714
6715 (define_split
6716   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6717         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6718                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6719                     (const_int 0)))
6720    (clobber (match_scratch:DI 3 ""))]
6721   "TARGET_POWERPC64 && reload_completed"
6722   [(set (match_dup 3)
6723         (div:DI (match_dup 1) (match_dup 2)))
6724    (set (match_dup 0)
6725         (compare:CC (match_dup 3)
6726                     (const_int 0)))]
6727   "")
6728
6729 (define_insn ""
6730   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6731         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6732                             (match_operand:DI 2 "exact_log2_cint_operand" "N,N"))
6733                     (const_int 0)))
6734    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6735         (div:DI (match_dup 1) (match_dup 2)))]
6736   "TARGET_POWERPC64"
6737   "@
6738    sradi %0,%1,%p2\;addze. %0,%0
6739    #"
6740   [(set_attr "type" "compare")
6741    (set_attr "length" "8,12")])
6742
6743 (define_split
6744   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6745         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
6746                             (match_operand:DI 2 "exact_log2_cint_operand" ""))
6747                     (const_int 0)))
6748    (set (match_operand:DI 0 "gpc_reg_operand" "")
6749         (div:DI (match_dup 1) (match_dup 2)))]
6750   "TARGET_POWERPC64 && reload_completed"
6751   [(set (match_dup 0)
6752         (div:DI (match_dup 1) (match_dup 2)))
6753    (set (match_dup 3)
6754         (compare:CC (match_dup 0)
6755                     (const_int 0)))]
6756   "")
6757
6758 (define_insn ""
6759   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6760         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6761                 (match_operand:DI 2 "gpc_reg_operand" "r")))]
6762   "TARGET_POWERPC64"
6763   "divd %0,%1,%2"
6764   [(set_attr "type" "ldiv")])
6765
6766 (define_insn "udivdi3"
6767   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6768         (udiv:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6769                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
6770   "TARGET_POWERPC64"
6771   "divdu %0,%1,%2"
6772   [(set_attr "type" "ldiv")])
6773
6774 (define_insn "rotldi3"
6775   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6776         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6777                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
6778   "TARGET_POWERPC64"
6779   "rld%I2cl %0,%1,%H2,0")
6780
6781 (define_insn "*rotldi3_internal2"
6782   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6783         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6784                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6785                     (const_int 0)))
6786    (clobber (match_scratch:DI 3 "=r,r"))]
6787   "TARGET_POWERPC64"
6788   "@
6789    rld%I2cl. %3,%1,%H2,0
6790    #"
6791   [(set_attr "type" "delayed_compare")
6792    (set_attr "length" "4,8")])
6793
6794 (define_split
6795   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6796         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6797                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6798                     (const_int 0)))
6799    (clobber (match_scratch:DI 3 ""))]
6800   "TARGET_POWERPC64 && reload_completed"
6801   [(set (match_dup 3)
6802         (rotate:DI (match_dup 1) (match_dup 2)))
6803    (set (match_dup 0)
6804         (compare:CC (match_dup 3)
6805                     (const_int 0)))]
6806   "")
6807
6808 (define_insn "*rotldi3_internal3"
6809   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6810         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6811                                (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6812                     (const_int 0)))
6813    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6814         (rotate:DI (match_dup 1) (match_dup 2)))]
6815   "TARGET_POWERPC64"
6816   "@
6817    rld%I2cl. %0,%1,%H2,0
6818    #"
6819   [(set_attr "type" "delayed_compare")
6820    (set_attr "length" "4,8")])
6821
6822 (define_split
6823   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6824         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6825                                (match_operand:DI 2 "reg_or_cint_operand" ""))
6826                     (const_int 0)))
6827    (set (match_operand:DI 0 "gpc_reg_operand" "")
6828         (rotate:DI (match_dup 1) (match_dup 2)))]
6829   "TARGET_POWERPC64 && reload_completed"
6830   [(set (match_dup 0)
6831         (rotate:DI (match_dup 1) (match_dup 2)))
6832    (set (match_dup 3)
6833         (compare:CC (match_dup 0)
6834                     (const_int 0)))]
6835   "")
6836
6837 (define_insn "*rotldi3_internal4"
6838   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6839         (and:DI (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6840                            (match_operand:DI 2 "reg_or_cint_operand" "ri"))
6841                 (match_operand:DI 3 "mask64_operand" "n")))]
6842   "TARGET_POWERPC64"
6843   "rld%I2c%B3 %0,%1,%H2,%S3")
6844
6845 (define_insn "*rotldi3_internal5"
6846   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6847         (compare:CC (and:DI
6848                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6849                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6850                      (match_operand:DI 3 "mask64_operand" "n,n"))
6851                     (const_int 0)))
6852    (clobber (match_scratch:DI 4 "=r,r"))]
6853   "TARGET_POWERPC64"
6854   "@
6855    rld%I2c%B3. %4,%1,%H2,%S3
6856    #"
6857   [(set_attr "type" "delayed_compare")
6858    (set_attr "length" "4,8")])
6859
6860 (define_split
6861   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6862         (compare:CC (and:DI
6863                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6864                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6865                      (match_operand:DI 3 "mask64_operand" ""))
6866                     (const_int 0)))
6867    (clobber (match_scratch:DI 4 ""))]
6868   "TARGET_POWERPC64 && reload_completed"
6869   [(set (match_dup 4)
6870         (and:DI (rotate:DI (match_dup 1)
6871                                 (match_dup 2))
6872                      (match_dup 3)))
6873    (set (match_dup 0)
6874         (compare:CC (match_dup 4)
6875                     (const_int 0)))]
6876   "")
6877
6878 (define_insn "*rotldi3_internal6"
6879   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
6880         (compare:CC (and:DI
6881                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6882                                 (match_operand:DI 2 "reg_or_cint_operand" "ri,ri"))
6883                      (match_operand:DI 3 "mask64_operand" "n,n"))
6884                     (const_int 0)))
6885    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6886         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6887   "TARGET_POWERPC64"
6888   "@
6889    rld%I2c%B3. %0,%1,%H2,%S3
6890    #"
6891   [(set_attr "type" "delayed_compare")
6892    (set_attr "length" "4,8")])
6893
6894 (define_split
6895   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
6896         (compare:CC (and:DI
6897                      (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6898                                 (match_operand:DI 2 "reg_or_cint_operand" ""))
6899                      (match_operand:DI 3 "mask64_operand" ""))
6900                     (const_int 0)))
6901    (set (match_operand:DI 0 "gpc_reg_operand" "")
6902         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
6903   "TARGET_POWERPC64 && reload_completed"
6904   [(set (match_dup 0)
6905         (and:DI (rotate:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
6906    (set (match_dup 4)
6907         (compare:CC (match_dup 0)
6908                     (const_int 0)))]
6909   "")
6910
6911 (define_insn "*rotldi3_internal7"
6912   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6913         (zero_extend:DI
6914          (subreg:QI
6915           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6916                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6917   "TARGET_POWERPC64"
6918   "rld%I2cl %0,%1,%H2,56")
6919
6920 (define_insn "*rotldi3_internal8"
6921   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6922         (compare:CC (zero_extend:DI
6923                      (subreg:QI
6924                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6925                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6926                     (const_int 0)))
6927    (clobber (match_scratch:DI 3 "=r,r"))]
6928   "TARGET_POWERPC64"
6929   "@
6930    rld%I2cl. %3,%1,%H2,56
6931    #"
6932   [(set_attr "type" "delayed_compare")
6933    (set_attr "length" "4,8")])
6934
6935 (define_split
6936   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
6937         (compare:CC (zero_extend:DI
6938                      (subreg:QI
6939                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6940                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6941                     (const_int 0)))
6942    (clobber (match_scratch:DI 3 ""))]
6943   "TARGET_POWERPC64 && reload_completed"
6944   [(set (match_dup 3)
6945         (zero_extend:DI (subreg:QI
6946                       (rotate:DI (match_dup 1)
6947                                  (match_dup 2)) 0)))
6948    (set (match_dup 0)
6949         (compare:CC (match_dup 3)
6950                     (const_int 0)))]
6951   "")
6952
6953 (define_insn "*rotldi3_internal9"
6954   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
6955         (compare:CC (zero_extend:DI
6956                      (subreg:QI
6957                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
6958                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
6959                     (const_int 0)))
6960    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
6961         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6962   "TARGET_POWERPC64"
6963   "@
6964    rld%I2cl. %0,%1,%H2,56
6965    #"
6966   [(set_attr "type" "delayed_compare")
6967    (set_attr "length" "4,8")])
6968
6969 (define_split
6970   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
6971         (compare:CC (zero_extend:DI
6972                      (subreg:QI
6973                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
6974                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
6975                     (const_int 0)))
6976    (set (match_operand:DI 0 "gpc_reg_operand" "")
6977         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
6978   "TARGET_POWERPC64 && reload_completed"
6979   [(set (match_dup 0)
6980         (zero_extend:DI (subreg:QI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
6981    (set (match_dup 3)
6982         (compare:CC (match_dup 0)
6983                     (const_int 0)))]
6984   "")
6985
6986 (define_insn "*rotldi3_internal10"
6987   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6988         (zero_extend:DI
6989          (subreg:HI
6990           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
6991                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
6992   "TARGET_POWERPC64"
6993   "rld%I2cl %0,%1,%H2,48")
6994
6995 (define_insn "*rotldi3_internal11"
6996   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
6997         (compare:CC (zero_extend:DI
6998                      (subreg:HI
6999                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7000                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
7001                     (const_int 0)))
7002    (clobber (match_scratch:DI 3 "=r,r"))]
7003   "TARGET_POWERPC64"
7004   "@
7005    rld%I2cl. %3,%1,%H2,48
7006    #"
7007   [(set_attr "type" "delayed_compare")
7008    (set_attr "length" "4,8")])
7009
7010 (define_split
7011   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7012         (compare:CC (zero_extend:DI
7013                      (subreg:HI
7014                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7015                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7016                     (const_int 0)))
7017    (clobber (match_scratch:DI 3 ""))]
7018   "TARGET_POWERPC64 && reload_completed"
7019   [(set (match_dup 3)
7020         (zero_extend:DI (subreg:HI
7021                       (rotate:DI (match_dup 1)
7022                                  (match_dup 2)) 0)))
7023    (set (match_dup 0)
7024         (compare:CC (match_dup 3)
7025                     (const_int 0)))]
7026   "")
7027
7028 (define_insn "*rotldi3_internal12"
7029   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7030         (compare:CC (zero_extend:DI
7031                      (subreg:HI
7032                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7033                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
7034                     (const_int 0)))
7035    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7036         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7037   "TARGET_POWERPC64"
7038   "@
7039    rld%I2cl. %0,%1,%H2,48
7040    #"
7041   [(set_attr "type" "delayed_compare")
7042    (set_attr "length" "4,8")])
7043
7044 (define_split
7045   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7046         (compare:CC (zero_extend:DI
7047                      (subreg:HI
7048                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7049                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7050                     (const_int 0)))
7051    (set (match_operand:DI 0 "gpc_reg_operand" "")
7052         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7053   "TARGET_POWERPC64 && reload_completed"
7054   [(set (match_dup 0)
7055         (zero_extend:DI (subreg:HI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7056    (set (match_dup 3)
7057         (compare:CC (match_dup 0)
7058                     (const_int 0)))]
7059   "")
7060
7061 (define_insn "*rotldi3_internal13"
7062   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7063         (zero_extend:DI
7064          (subreg:SI
7065           (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7066                      (match_operand:DI 2 "reg_or_cint_operand" "ri")) 0)))]
7067   "TARGET_POWERPC64"
7068   "rld%I2cl %0,%1,%H2,32")
7069
7070 (define_insn "*rotldi3_internal14"
7071   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7072         (compare:CC (zero_extend:DI
7073                      (subreg:SI
7074                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7075                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
7076                     (const_int 0)))
7077    (clobber (match_scratch:DI 3 "=r,r"))]
7078   "TARGET_POWERPC64"
7079   "@
7080    rld%I2cl. %3,%1,%H2,32
7081    #"
7082   [(set_attr "type" "delayed_compare")
7083    (set_attr "length" "4,8")])
7084
7085 (define_split
7086   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7087         (compare:CC (zero_extend:DI
7088                      (subreg:SI
7089                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7090                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7091                     (const_int 0)))
7092    (clobber (match_scratch:DI 3 ""))]
7093   "TARGET_POWERPC64 && reload_completed"
7094   [(set (match_dup 3)
7095         (zero_extend:DI (subreg:SI
7096                       (rotate:DI (match_dup 1)
7097                                  (match_dup 2)) 0)))
7098    (set (match_dup 0)
7099         (compare:CC (match_dup 3)
7100                     (const_int 0)))]
7101   "")
7102
7103 (define_insn "*rotldi3_internal15"
7104   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7105         (compare:CC (zero_extend:DI
7106                      (subreg:SI
7107                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7108                                  (match_operand:DI 2 "reg_or_cint_operand" "ri,ri")) 0))
7109                     (const_int 0)))
7110    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7111         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7112   "TARGET_POWERPC64"
7113   "@
7114    rld%I2cl. %0,%1,%H2,32
7115    #"
7116   [(set_attr "type" "delayed_compare")
7117    (set_attr "length" "4,8")])
7118
7119 (define_split
7120   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7121         (compare:CC (zero_extend:DI
7122                      (subreg:SI
7123                       (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "")
7124                                  (match_operand:DI 2 "reg_or_cint_operand" "")) 0))
7125                     (const_int 0)))
7126    (set (match_operand:DI 0 "gpc_reg_operand" "")
7127         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))]
7128   "TARGET_POWERPC64 && reload_completed"
7129   [(set (match_dup 0)
7130         (zero_extend:DI (subreg:SI (rotate:DI (match_dup 1) (match_dup 2)) 0)))
7131    (set (match_dup 3)
7132         (compare:CC (match_dup 0)
7133                     (const_int 0)))]
7134   "")
7135
7136 (define_expand "ashldi3"
7137   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7138         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7139                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
7140   "TARGET_POWERPC64 || TARGET_POWER"
7141   "
7142 {
7143   if (TARGET_POWERPC64)
7144     ;
7145   else if (TARGET_POWER)
7146     {
7147       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
7148       DONE;
7149     }
7150   else
7151     FAIL;
7152 }")
7153
7154 (define_insn "*ashldi3_internal1"
7155   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7156         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7157                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
7158   "TARGET_POWERPC64"
7159   "sld%I2 %0,%1,%H2"
7160   [(set_attr "length" "8")])
7161   
7162 (define_insn "*ashldi3_internal2"
7163   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7164         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7165                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7166                     (const_int 0)))
7167    (clobber (match_scratch:DI 3 "=r,r"))]
7168   "TARGET_POWERPC64"
7169   "@
7170    sld%I2. %3,%1,%H2
7171    #"
7172   [(set_attr "type" "delayed_compare")
7173    (set_attr "length" "4,8")])
7174   
7175 (define_split
7176   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7177         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7178                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7179                     (const_int 0)))
7180    (clobber (match_scratch:DI 3 ""))]
7181   "TARGET_POWERPC64 && reload_completed"
7182   [(set (match_dup 3)
7183         (ashift:DI (match_dup 1) (match_dup 2)))
7184    (set (match_dup 0)
7185         (compare:CC (match_dup 3)
7186                     (const_int 0)))]
7187   "")
7188
7189 (define_insn "*ashldi3_internal3"
7190   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7191         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7192                                (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7193                     (const_int 0)))
7194    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7195         (ashift:DI (match_dup 1) (match_dup 2)))]
7196   "TARGET_POWERPC64"
7197   "@
7198    sld%I2. %0,%1,%H2
7199    #"
7200   [(set_attr "type" "delayed_compare")
7201    (set_attr "length" "4,8")])
7202
7203 (define_split
7204   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7205         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7206                                (match_operand:SI 2 "reg_or_cint_operand" ""))
7207                     (const_int 0)))
7208    (set (match_operand:DI 0 "gpc_reg_operand" "")
7209         (ashift:DI (match_dup 1) (match_dup 2)))]
7210   "TARGET_POWERPC64 && reload_completed"
7211   [(set (match_dup 0)
7212         (ashift:DI (match_dup 1) (match_dup 2)))
7213    (set (match_dup 3)
7214         (compare:CC (match_dup 0)
7215                     (const_int 0)))]
7216   "")
7217
7218 (define_insn "*ashldi3_internal4"
7219   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7220         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7221                            (match_operand:SI 2 "const_int_operand" "i"))
7222                 (match_operand:DI 3 "const_int_operand" "n")))]
7223   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
7224   "rldic %0,%1,%H2,%W3")
7225
7226 (define_insn "ashldi3_internal5"
7227   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7228         (compare:CC
7229          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7230                             (match_operand:SI 2 "const_int_operand" "i,i"))
7231                  (match_operand:DI 3 "const_int_operand" "n,n"))
7232          (const_int 0)))
7233    (clobber (match_scratch:DI 4 "=r,r"))]
7234   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
7235   "@
7236    rldic. %4,%1,%H2,%W3
7237    #"
7238   [(set_attr "type" "delayed_compare")
7239    (set_attr "length" "4,8")])
7240
7241 (define_split
7242   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7243         (compare:CC
7244          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7245                             (match_operand:SI 2 "const_int_operand" ""))
7246                  (match_operand:DI 3 "const_int_operand" ""))
7247          (const_int 0)))
7248    (clobber (match_scratch:DI 4 ""))]
7249   "TARGET_POWERPC64 && reload_completed
7250    && includes_rldic_lshift_p (operands[2], operands[3])"
7251   [(set (match_dup 4)
7252         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7253                 (match_dup 3)))
7254    (set (match_dup 0)
7255         (compare:CC (match_dup 4)
7256                     (const_int 0)))]
7257   "")
7258
7259 (define_insn "*ashldi3_internal6"
7260   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7261         (compare:CC
7262          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7263                             (match_operand:SI 2 "const_int_operand" "i,i"))
7264                     (match_operand:DI 3 "const_int_operand" "n,n"))
7265          (const_int 0)))
7266    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7267         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7268   "TARGET_POWERPC64 && includes_rldic_lshift_p (operands[2], operands[3])"
7269   "@
7270    rldic. %0,%1,%H2,%W3
7271    #"
7272   [(set_attr "type" "delayed_compare")
7273    (set_attr "length" "4,8")])
7274
7275 (define_split
7276   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
7277         (compare:CC
7278          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7279                             (match_operand:SI 2 "const_int_operand" ""))
7280                  (match_operand:DI 3 "const_int_operand" ""))
7281          (const_int 0)))
7282    (set (match_operand:DI 0 "gpc_reg_operand" "")
7283         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7284   "TARGET_POWERPC64 && reload_completed
7285    && includes_rldic_lshift_p (operands[2], operands[3])"
7286   [(set (match_dup 0)
7287         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7288                 (match_dup 3)))
7289    (set (match_dup 4)
7290         (compare:CC (match_dup 0)
7291                     (const_int 0)))]
7292   "")
7293
7294 (define_insn "*ashldi3_internal7"
7295   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7296         (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7297                            (match_operand:SI 2 "const_int_operand" "i"))
7298                 (match_operand:DI 3 "mask64_operand" "n")))]
7299   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
7300   "rldicr %0,%1,%H2,%S3")
7301
7302 (define_insn "ashldi3_internal8"
7303   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7304         (compare:CC
7305          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7306                             (match_operand:SI 2 "const_int_operand" "i,i"))
7307                  (match_operand:DI 3 "mask64_operand" "n,n"))
7308          (const_int 0)))
7309    (clobber (match_scratch:DI 4 "=r,r"))]
7310   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
7311   "@
7312    rldicr. %4,%1,%H2,%S3
7313    #"
7314   [(set_attr "type" "delayed_compare")
7315    (set_attr "length" "4,8")])
7316
7317 (define_split
7318   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7319         (compare:CC
7320          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7321                             (match_operand:SI 2 "const_int_operand" ""))
7322                  (match_operand:DI 3 "mask64_operand" ""))
7323          (const_int 0)))
7324    (clobber (match_scratch:DI 4 ""))]
7325   "TARGET_POWERPC64 && reload_completed
7326    && includes_rldicr_lshift_p (operands[2], operands[3])"
7327   [(set (match_dup 4)
7328         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7329                 (match_dup 3)))
7330    (set (match_dup 0)
7331         (compare:CC (match_dup 4)
7332                     (const_int 0)))]
7333   "")
7334
7335 (define_insn "*ashldi3_internal9"
7336   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
7337         (compare:CC
7338          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7339                             (match_operand:SI 2 "const_int_operand" "i,i"))
7340                     (match_operand:DI 3 "mask64_operand" "n,n"))
7341          (const_int 0)))
7342    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7343         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7344   "TARGET_POWERPC64 && includes_rldicr_lshift_p (operands[2], operands[3])"
7345   "@
7346    rldicr. %0,%1,%H2,%S3
7347    #"
7348   [(set_attr "type" "delayed_compare")
7349    (set_attr "length" "4,8")])
7350
7351 (define_split
7352   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
7353         (compare:CC
7354          (and:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
7355                             (match_operand:SI 2 "const_int_operand" ""))
7356                  (match_operand:DI 3 "mask64_operand" ""))
7357          (const_int 0)))
7358    (set (match_operand:DI 0 "gpc_reg_operand" "")
7359         (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
7360   "TARGET_POWERPC64 && reload_completed
7361    && includes_rldicr_lshift_p (operands[2], operands[3])"
7362   [(set (match_dup 0)
7363         (and:DI (ashift:DI (match_dup 1) (match_dup 2))
7364                 (match_dup 3)))
7365    (set (match_dup 4)
7366         (compare:CC (match_dup 0)
7367                     (const_int 0)))]
7368   "")
7369
7370 (define_expand "lshrdi3"
7371   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7372         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7373                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7374   "TARGET_POWERPC64 || TARGET_POWER"
7375   "
7376 {
7377   if (TARGET_POWERPC64)
7378     ;
7379   else if (TARGET_POWER)
7380     {
7381       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
7382       DONE;
7383     }
7384   else
7385     FAIL;
7386 }")
7387
7388 (define_insn "*lshrdi3_internal1"
7389   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7390         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7391                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
7392   "TARGET_POWERPC64"
7393   "srd%I2 %0,%1,%H2")
7394
7395 (define_insn "*lshrdi3_internal2"
7396   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7397         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7398                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7399                     (const_int 0)))
7400    (clobber (match_scratch:DI 3 "=r,r"))]
7401   "TARGET_POWERPC64"
7402   "@
7403    srd%I2. %3,%1,%H2
7404    #"
7405   [(set_attr "type" "delayed_compare")
7406    (set_attr "length" "4,8")])
7407
7408 (define_split
7409   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7410         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7411                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7412                     (const_int 0)))
7413    (clobber (match_scratch:DI 3 ""))]
7414   "TARGET_POWERPC64 && reload_completed"
7415   [(set (match_dup 3)
7416         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7417    (set (match_dup 0)
7418         (compare:CC (match_dup 3)
7419                     (const_int 0)))]
7420   "")
7421
7422 (define_insn "*lshrdi3_internal3"
7423   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7424         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7425                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7426                     (const_int 0)))
7427    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7428         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7429   "TARGET_POWERPC64"
7430   "@
7431    srd%I2. %0,%1,%H2
7432    #"
7433   [(set_attr "type" "delayed_compare")
7434    (set_attr "length" "4,8")])
7435
7436 (define_split
7437   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7438         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7439                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7440                     (const_int 0)))
7441    (set (match_operand:DI 0 "gpc_reg_operand" "")
7442         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
7443   "TARGET_POWERPC64 && reload_completed"
7444   [(set (match_dup 0)
7445         (lshiftrt:DI (match_dup 1) (match_dup 2)))
7446    (set (match_dup 3)
7447         (compare:CC (match_dup 0)
7448                     (const_int 0)))]
7449   "")
7450
7451 (define_expand "ashrdi3"
7452   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7453         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7454                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
7455   ""
7456   "
7457 {
7458   if (TARGET_POWERPC64)
7459     ;
7460   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
7461     {
7462       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
7463       DONE;
7464     }
7465   else if (TARGET_32BIT && GET_CODE (operands[2]) == CONST_INT)
7466     {
7467       emit_insn (gen_ashrdi3_no_power (operands[0], operands[1], operands[2]));
7468       DONE;
7469     }
7470   else
7471     FAIL;
7472 }")
7473
7474 (define_insn "*ashrdi3_internal1"
7475   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7476         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
7477                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
7478   "TARGET_POWERPC64"
7479   "srad%I2 %0,%1,%H2")
7480
7481 (define_insn "*ashrdi3_internal2"
7482   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7483         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7484                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7485                     (const_int 0)))
7486    (clobber (match_scratch:DI 3 "=r,r"))]
7487   "TARGET_POWERPC64"
7488   "@
7489    srad%I2. %3,%1,%H2
7490    #"
7491   [(set_attr "type" "delayed_compare")
7492    (set_attr "length" "4,8")])
7493
7494 (define_split
7495   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7496         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7497                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7498                     (const_int 0)))
7499    (clobber (match_scratch:DI 3 ""))]
7500   "TARGET_POWERPC64 && reload_completed"
7501   [(set (match_dup 3)
7502         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7503    (set (match_dup 0)
7504         (compare:CC (match_dup 3)
7505                     (const_int 0)))]
7506   "")
7507
7508 (define_insn "*ashrdi3_internal3"
7509   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7510         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
7511                                  (match_operand:SI 2 "reg_or_cint_operand" "ri,ri"))
7512                     (const_int 0)))
7513    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7514         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7515   "TARGET_POWERPC64"
7516   "@
7517    srad%I2. %0,%1,%H2
7518    #"
7519   [(set_attr "type" "delayed_compare")
7520    (set_attr "length" "4,8")])
7521
7522 (define_split
7523   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7524         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
7525                                  (match_operand:SI 2 "reg_or_cint_operand" ""))
7526                     (const_int 0)))
7527    (set (match_operand:DI 0 "gpc_reg_operand" "")
7528         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
7529   "TARGET_POWERPC64 && reload_completed"
7530   [(set (match_dup 0)
7531         (ashiftrt:DI (match_dup 1) (match_dup 2)))
7532    (set (match_dup 3)
7533         (compare:CC (match_dup 0)
7534                     (const_int 0)))]
7535   "")
7536
7537 (define_insn "anddi3"
7538   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r")
7539         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r")
7540                 (match_operand:DI 2 "and64_2_operand" "?r,S,K,J,t")))
7541    (clobber (match_scratch:CC 3 "=X,X,x,x,X"))]
7542   "TARGET_POWERPC64"
7543   "@
7544    and %0,%1,%2
7545    rldic%B2 %0,%1,0,%S2
7546    andi. %0,%1,%b2
7547    andis. %0,%1,%u2
7548    #"
7549   [(set_attr "length" "4,4,4,4,8")])
7550
7551 (define_split
7552   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7553         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7554                 (match_operand:DI 2 "mask64_2_operand" "")))
7555    (clobber (match_scratch:CC 3 ""))]
7556   "TARGET_POWERPC64
7557     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7558     && !mask64_operand (operands[2], DImode)"
7559   [(set (match_dup 0)
7560         (and:DI (rotate:DI (match_dup 1)
7561                            (match_dup 4))
7562                 (match_dup 5)))
7563    (set (match_dup 0)
7564         (and:DI (rotate:DI (match_dup 0)
7565                            (match_dup 6))
7566                 (match_dup 7)))]
7567   "
7568 {
7569   build_mask64_2_operands (operands[2], &operands[4]);
7570 }")
7571
7572 (define_insn "*anddi3_internal2"
7573   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
7574         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
7575                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
7576                     (const_int 0)))
7577    (clobber (match_scratch:DI 3 "=r,r,r,r,r,r,r,r,r,r"))
7578    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
7579   "TARGET_POWERPC64"
7580   "@
7581    and. %3,%1,%2
7582    rldic%B2. %3,%1,0,%S2
7583    andi. %3,%1,%b2
7584    andis. %3,%1,%u2
7585    #
7586    #
7587    #
7588    #
7589    #
7590    #"
7591   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7592    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7593
7594 (define_split
7595   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7596         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7597                             (match_operand:DI 2 "and64_operand" ""))
7598                     (const_int 0)))
7599    (clobber (match_scratch:DI 3 ""))
7600    (clobber (match_scratch:CC 4 ""))]
7601   "TARGET_POWERPC64 && reload_completed"
7602   [(parallel [(set (match_dup 3)
7603                    (and:DI (match_dup 1)
7604                            (match_dup 2)))
7605               (clobber (match_dup 4))])
7606    (set (match_dup 0)
7607         (compare:CC (match_dup 3)
7608                     (const_int 0)))]
7609   "")
7610
7611 (define_split
7612   [(set (match_operand:CC 0 "cc_reg_operand" "")
7613         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7614                             (match_operand:DI 2 "mask64_2_operand" ""))
7615                     (const_int 0)))
7616    (clobber (match_scratch:DI 3 ""))
7617    (clobber (match_scratch:CC 4 ""))]
7618   "TARGET_POWERPC64 && reload_completed
7619     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7620     && !mask64_operand (operands[2], DImode)"
7621   [(set (match_dup 3)
7622         (and:DI (rotate:DI (match_dup 1)
7623                            (match_dup 5))
7624                 (match_dup 6)))
7625    (parallel [(set (match_dup 0)
7626                    (compare:CC (and:DI (rotate:DI (match_dup 3)
7627                                                   (match_dup 7))
7628                                        (match_dup 8))
7629                                (const_int 0)))
7630               (clobber (match_dup 3))])]
7631   "
7632 {
7633   build_mask64_2_operands (operands[2], &operands[5]);
7634 }")
7635
7636 (define_insn "*anddi3_internal3"
7637   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,x,?y,?y,??y,??y,?y")
7638         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
7639                             (match_operand:DI 2 "and64_2_operand" "r,S,K,J,t,r,S,K,J,t"))
7640                     (const_int 0)))
7641    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
7642         (and:DI (match_dup 1) (match_dup 2)))
7643    (clobber (match_scratch:CC 4 "=X,X,X,X,X,X,X,x,x,X"))]
7644   "TARGET_POWERPC64"
7645   "@
7646    and. %0,%1,%2
7647    rldic%B2. %0,%1,0,%S2
7648    andi. %0,%1,%b2
7649    andis. %0,%1,%u2
7650    #
7651    #
7652    #
7653    #
7654    #
7655    #"
7656   [(set_attr "type" "compare,delayed_compare,compare,compare,delayed_compare,compare,compare,compare,compare,compare")
7657    (set_attr "length" "4,4,4,4,8,8,8,8,8,12")])
7658
7659 (define_split
7660   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7661         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7662                             (match_operand:DI 2 "and64_operand" ""))
7663                     (const_int 0)))
7664    (set (match_operand:DI 0 "gpc_reg_operand" "")
7665         (and:DI (match_dup 1) (match_dup 2)))
7666    (clobber (match_scratch:CC 4 ""))]
7667   "TARGET_POWERPC64 && reload_completed"
7668   [(parallel [(set (match_dup 0)
7669                     (and:DI (match_dup 1) (match_dup 2)))
7670                (clobber (match_dup 4))])
7671    (set (match_dup 3)
7672         (compare:CC (match_dup 0)
7673                     (const_int 0)))]
7674   "")
7675
7676 (define_split
7677   [(set (match_operand:CC 3 "cc_reg_operand" "")
7678         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
7679                             (match_operand:DI 2 "mask64_2_operand" ""))
7680                     (const_int 0)))
7681    (set (match_operand:DI 0 "gpc_reg_operand" "")
7682         (and:DI (match_dup 1) (match_dup 2)))
7683    (clobber (match_scratch:CC 4 ""))]
7684   "TARGET_POWERPC64 && reload_completed
7685     && (fixed_regs[CR0_REGNO] || !logical_operand (operands[2], DImode))
7686     && !mask64_operand (operands[2], DImode)"
7687   [(set (match_dup 0)
7688         (and:DI (rotate:DI (match_dup 1)
7689                            (match_dup 5))
7690                 (match_dup 6)))
7691    (parallel [(set (match_dup 3)
7692                    (compare:CC (and:DI (rotate:DI (match_dup 0)
7693                                                   (match_dup 7))
7694                                        (match_dup 8))
7695                                (const_int 0)))
7696               (set (match_dup 0)
7697                    (and:DI (rotate:DI (match_dup 0)
7698                                       (match_dup 7))
7699                            (match_dup 8)))])]
7700   "
7701 {
7702   build_mask64_2_operands (operands[2], &operands[5]);
7703 }")
7704
7705 (define_expand "iordi3"
7706   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7707         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
7708                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7709   "TARGET_POWERPC64"
7710   "
7711 {
7712   if (non_logical_cint_operand (operands[2], DImode))
7713     {
7714       HOST_WIDE_INT value;
7715       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7716                  ? operands[0] : gen_reg_rtx (DImode));
7717
7718       if (GET_CODE (operands[2]) == CONST_INT)
7719         {
7720           value = INTVAL (operands[2]);
7721           emit_insn (gen_iordi3 (tmp, operands[1],
7722                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7723         }
7724       else
7725         {
7726           value = CONST_DOUBLE_LOW (operands[2]);
7727           emit_insn (gen_iordi3 (tmp, operands[1],
7728                                  immed_double_const (value
7729                                                      & (~ (HOST_WIDE_INT) 0xffff),
7730                                                      0, DImode)));
7731         }
7732
7733       emit_insn (gen_iordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7734       DONE;
7735     }
7736 }")
7737
7738 (define_expand "xordi3"
7739   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7740         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
7741                 (match_operand:DI 2 "reg_or_logical_cint_operand" "")))]
7742   "TARGET_POWERPC64"
7743   "
7744 {
7745   if (non_logical_cint_operand (operands[2], DImode))
7746     {
7747       HOST_WIDE_INT value;
7748       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
7749                  ? operands[0] : gen_reg_rtx (DImode));
7750
7751       if (GET_CODE (operands[2]) == CONST_INT)
7752         {
7753           value = INTVAL (operands[2]);
7754           emit_insn (gen_xordi3 (tmp, operands[1],
7755                                  GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
7756         }
7757       else
7758         {
7759           value = CONST_DOUBLE_LOW (operands[2]);
7760           emit_insn (gen_xordi3 (tmp, operands[1],
7761                                  immed_double_const (value
7762                                                      & (~ (HOST_WIDE_INT) 0xffff),
7763                                                      0, DImode)));
7764         }
7765
7766       emit_insn (gen_xordi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
7767       DONE;
7768     }
7769 }")
7770
7771 (define_insn "*booldi3_internal1"
7772   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
7773         (match_operator:DI 3 "boolean_or_operator"
7774          [(match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
7775           (match_operand:DI 2 "logical_operand" "r,K,JF")]))]
7776   "TARGET_POWERPC64"
7777   "@
7778    %q3 %0,%1,%2
7779    %q3i %0,%1,%b2
7780    %q3is %0,%1,%u2")
7781
7782 (define_insn "*booldi3_internal2"
7783   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7784         (compare:CC (match_operator:DI 4 "boolean_or_operator"
7785          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7786           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7787          (const_int 0)))
7788    (clobber (match_scratch:DI 3 "=r,r"))]
7789   "TARGET_POWERPC64"
7790   "@
7791    %q4. %3,%1,%2
7792    #"
7793   [(set_attr "type" "compare")
7794    (set_attr "length" "4,8")])
7795
7796 (define_split
7797   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7798         (compare:CC (match_operator:DI 4 "boolean_operator"
7799          [(match_operand:DI 1 "gpc_reg_operand" "")
7800           (match_operand:DI 2 "gpc_reg_operand" "")])
7801          (const_int 0)))
7802    (clobber (match_scratch:DI 3 ""))]
7803   "TARGET_POWERPC64 && reload_completed"
7804   [(set (match_dup 3) (match_dup 4))
7805    (set (match_dup 0)
7806         (compare:CC (match_dup 3)
7807                     (const_int 0)))]
7808   "")
7809
7810 (define_insn "*booldi3_internal3"
7811   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7812         (compare:CC (match_operator:DI 4 "boolean_operator"
7813          [(match_operand:DI 1 "gpc_reg_operand" "%r,r")
7814           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7815          (const_int 0)))
7816    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7817         (match_dup 4))]
7818   "TARGET_POWERPC64"
7819   "@
7820    %q4. %0,%1,%2
7821    #"
7822   [(set_attr "type" "compare")
7823    (set_attr "length" "4,8")])
7824
7825 (define_split
7826   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7827         (compare:CC (match_operator:DI 4 "boolean_operator"
7828          [(match_operand:DI 1 "gpc_reg_operand" "")
7829           (match_operand:DI 2 "gpc_reg_operand" "")])
7830          (const_int 0)))
7831    (set (match_operand:DI 0 "gpc_reg_operand" "")
7832         (match_dup 4))]
7833   "TARGET_POWERPC64 && reload_completed"
7834   [(set (match_dup 0) (match_dup 4))
7835    (set (match_dup 3)
7836         (compare:CC (match_dup 0)
7837                     (const_int 0)))]
7838   "")
7839
7840 ;; Split an logical operation that we can't do in one insn into two insns, 
7841 ;; each of which does one 16-bit part.  This is used by combine.
7842
7843 (define_split
7844   [(set (match_operand:DI 0 "gpc_reg_operand" "")
7845         (match_operator:DI 3 "boolean_or_operator"
7846          [(match_operand:DI 1 "gpc_reg_operand" "")
7847           (match_operand:DI 2 "non_logical_cint_operand" "")]))]
7848   "TARGET_POWERPC64"
7849   [(set (match_dup 0) (match_dup 4))
7850    (set (match_dup 0) (match_dup 5))]
7851 "
7852 {
7853   rtx i3,i4;
7854   
7855   if (GET_CODE (operands[2]) == CONST_DOUBLE)
7856     {
7857       HOST_WIDE_INT value = CONST_DOUBLE_LOW (operands[2]);
7858       i3 = immed_double_const (value & (~ (HOST_WIDE_INT) 0xffff),
7859                                         0, DImode);
7860       i4 = GEN_INT (value & 0xffff);
7861     }
7862   else
7863     {
7864       i3 = GEN_INT (INTVAL (operands[2])
7865                              & (~ (HOST_WIDE_INT) 0xffff));
7866       i4 = GEN_INT (INTVAL (operands[2]) & 0xffff);
7867     }
7868   operands[4] = gen_rtx (GET_CODE (operands[3]), DImode,
7869                          operands[1], i3);
7870   operands[5] = gen_rtx (GET_CODE (operands[3]), DImode,
7871                          operands[0], i4);
7872 }")
7873
7874 (define_insn "*boolcdi3_internal1"
7875   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7876         (match_operator:DI 3 "boolean_operator"
7877          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7878           (match_operand:DI 2 "gpc_reg_operand" "r")]))]
7879   "TARGET_POWERPC64"
7880   "%q3 %0,%2,%1")
7881
7882 (define_insn "*boolcdi3_internal2"
7883   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7884         (compare:CC (match_operator:DI 4 "boolean_operator"
7885          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7886           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7887          (const_int 0)))
7888    (clobber (match_scratch:DI 3 "=r,r"))]
7889   "TARGET_POWERPC64"
7890   "@
7891    %q4. %3,%2,%1
7892    #"
7893   [(set_attr "type" "compare")
7894    (set_attr "length" "4,8")])
7895
7896 (define_split
7897   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7898         (compare:CC (match_operator:DI 4 "boolean_operator"
7899          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7900           (match_operand:DI 2 "gpc_reg_operand" "")])
7901          (const_int 0)))
7902    (clobber (match_scratch:DI 3 ""))]
7903   "TARGET_POWERPC64 && reload_completed"
7904   [(set (match_dup 3) (match_dup 4))
7905    (set (match_dup 0)
7906         (compare:CC (match_dup 3)
7907                     (const_int 0)))]
7908   "")
7909
7910 (define_insn "*boolcdi3_internal3"
7911   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7912         (compare:CC (match_operator:DI 4 "boolean_operator"
7913          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7914           (match_operand:DI 2 "gpc_reg_operand" "r,r")])
7915          (const_int 0)))
7916    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7917         (match_dup 4))]
7918   "TARGET_POWERPC64"
7919   "@
7920    %q4. %0,%2,%1
7921    #"
7922   [(set_attr "type" "compare")
7923    (set_attr "length" "4,8")])
7924
7925 (define_split
7926   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7927         (compare:CC (match_operator:DI 4 "boolean_operator"
7928          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7929           (match_operand:DI 2 "gpc_reg_operand" "")])
7930          (const_int 0)))
7931    (set (match_operand:DI 0 "gpc_reg_operand" "")
7932         (match_dup 4))]
7933   "TARGET_POWERPC64 && reload_completed"
7934   [(set (match_dup 0) (match_dup 4))
7935    (set (match_dup 3)
7936         (compare:CC (match_dup 0)
7937                     (const_int 0)))]
7938   "")
7939
7940 (define_insn "*boolccdi3_internal1"
7941   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
7942         (match_operator:DI 3 "boolean_operator"
7943          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
7944           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))]))]
7945   "TARGET_POWERPC64"
7946   "%q3 %0,%1,%2")
7947
7948 (define_insn "*boolccdi3_internal2"
7949   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
7950         (compare:CC (match_operator:DI 4 "boolean_operator"
7951          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "r,r"))
7952           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7953          (const_int 0)))
7954    (clobber (match_scratch:DI 3 "=r,r"))]
7955   "TARGET_POWERPC64"
7956   "@
7957    %q4. %3,%1,%2
7958    #"
7959   [(set_attr "type" "compare")
7960    (set_attr "length" "4,8")])
7961
7962 (define_split
7963   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
7964         (compare:CC (match_operator:DI 4 "boolean_operator"
7965          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7966           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7967          (const_int 0)))
7968    (clobber (match_scratch:DI 3 ""))]
7969   "TARGET_POWERPC64 && reload_completed"
7970   [(set (match_dup 3) (match_dup 4))
7971    (set (match_dup 0)
7972         (compare:CC (match_dup 3)
7973                     (const_int 0)))]
7974   "")
7975
7976 (define_insn "*boolccdi3_internal3"
7977   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
7978         (compare:CC (match_operator:DI 4 "boolean_operator"
7979          [(not:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r"))
7980           (not:DI (match_operand:DI 2 "gpc_reg_operand" "r,r"))])
7981          (const_int 0)))
7982    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
7983         (match_dup 4))]
7984   "TARGET_POWERPC64"
7985   "@
7986    %q4. %0,%1,%2
7987    #"
7988   [(set_attr "type" "compare")
7989    (set_attr "length" "4,8")])
7990
7991 (define_split
7992   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
7993         (compare:CC (match_operator:DI 4 "boolean_operator"
7994          [(not:DI (match_operand:DI 1 "gpc_reg_operand" ""))
7995           (not:DI (match_operand:DI 2 "gpc_reg_operand" ""))])
7996          (const_int 0)))
7997    (set (match_operand:DI 0 "gpc_reg_operand" "")
7998         (match_dup 4))]
7999   "TARGET_POWERPC64 && reload_completed"
8000   [(set (match_dup 0) (match_dup 4))
8001    (set (match_dup 3)
8002         (compare:CC (match_dup 0)
8003                     (const_int 0)))]
8004   "")
8005 \f
8006 ;; Now define ways of moving data around.
8007
8008 ;; Elf specific ways of loading addresses for non-PIC code.
8009 ;; The output of this could be r0, but we make a very strong
8010 ;; preference for a base register because it will usually
8011 ;; be needed there.
8012 (define_insn "elf_high"
8013   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
8014         (high:SI (match_operand 1 "" "")))]
8015   "TARGET_ELF && ! TARGET_64BIT"
8016   "{liu|lis} %0,%1@ha")
8017
8018 (define_insn "elf_low"
8019   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8020         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
8021                    (match_operand 2 "" "")))]
8022    "TARGET_ELF && ! TARGET_64BIT"
8023    "@
8024     {cal|la} %0,%2@l(%1)
8025     {ai|addic} %0,%1,%K2")
8026
8027 ;; Mach-O PIC trickery.
8028 (define_insn "macho_high"
8029   [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
8030         (high:SI (match_operand 1 "" "")))]
8031   "TARGET_MACHO && ! TARGET_64BIT"
8032   "{liu|lis} %0,ha16(%1)")
8033
8034 (define_insn "macho_low"
8035   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8036         (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r")
8037                    (match_operand 2 "" "")))]
8038    "TARGET_MACHO && ! TARGET_64BIT"
8039    "@
8040     {cal %0,%a2@l(%1)|la %0,lo16(%2)(%1)}
8041     {cal %0,%a2@l(%1)|addic %0,%1,lo16(%2)}")
8042
8043 ;; Set up a register with a value from the GOT table
8044
8045 (define_expand "movsi_got"
8046   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8047         (unspec:SI [(match_operand:SI 1 "got_operand" "")
8048                     (match_dup 2)] 8))]
8049   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8050   "
8051 {
8052   if (GET_CODE (operands[1]) == CONST)
8053     {
8054       rtx offset = const0_rtx;
8055       HOST_WIDE_INT value;
8056
8057       operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
8058       value = INTVAL (offset);
8059       if (value != 0)
8060         {
8061           rtx tmp = (no_new_pseudos ? operands[0] : gen_reg_rtx (Pmode));
8062           emit_insn (gen_movsi_got (tmp, operands[1]));
8063           emit_insn (gen_addsi3 (operands[0], tmp, offset));
8064           DONE;
8065         }
8066     }
8067
8068   operands[2] = rs6000_got_register (operands[1]);
8069 }")
8070
8071 (define_insn "*movsi_got_internal"
8072   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8073         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8074                     (match_operand:SI 2 "gpc_reg_operand" "b")] 8))]
8075   "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
8076   "{l|lwz} %0,%a1@got(%2)"
8077   [(set_attr "type" "load")])
8078
8079 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
8080 ;; didn't get allocated to a hard register.
8081 (define_split 
8082   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8083         (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
8084                     (match_operand:SI 2 "memory_operand" "")] 8))]
8085   "DEFAULT_ABI == ABI_V4
8086     && flag_pic == 1
8087     && (reload_in_progress || reload_completed)"
8088   [(set (match_dup 0) (match_dup 2))
8089    (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)] 8))]
8090   "")
8091
8092 ;; For SI, we special-case integers that can't be loaded in one insn.  We
8093 ;; do the load 16-bits at a time.  We could do this by loading from memory,
8094 ;; and this is even supposed to be faster, but it is simpler not to get
8095 ;; integers in the TOC.
8096 (define_expand "movsi"
8097   [(set (match_operand:SI 0 "general_operand" "")
8098         (match_operand:SI 1 "any_operand" ""))]
8099   ""
8100   "{ rs6000_emit_move (operands[0], operands[1], SImode); DONE; }")
8101
8102 (define_insn "movsi_low"
8103   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8104         (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
8105                            (match_operand 2 "" ""))))]
8106   "TARGET_MACHO && ! TARGET_64BIT"
8107   "{l|lwz} %0,lo16(%2)(%1)"
8108   [(set_attr "type" "load")
8109    (set_attr "length" "4")])
8110
8111 (define_insn "movsi_low_st"
8112   [(set (mem:SI (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
8113                            (match_operand 2 "" "")))
8114         (match_operand:SI 0 "gpc_reg_operand" "r"))]
8115   "TARGET_MACHO && ! TARGET_64BIT"
8116   "{st|stw} %0,lo16(%2)(%1)"
8117   [(set_attr "type" "store")
8118    (set_attr "length" "4")])
8119
8120 (define_insn "movdf_low"
8121   [(set (match_operand:DF 0 "gpc_reg_operand" "=f,!r")
8122         (mem:DF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
8123                            (match_operand 2 "" ""))))]
8124   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
8125   "*
8126 {
8127   switch (which_alternative)
8128     {
8129       case 0:
8130         return \"lfd %0,lo16(%2)(%1)\";
8131       case 1:
8132         {
8133           rtx operands2[4];
8134           operands2[0] = operands[0];
8135           operands2[1] = operands[1];
8136           operands2[2] = operands[2];
8137           operands2[3] = gen_rtx_REG (SImode, RS6000_PIC_OFFSET_TABLE_REGNUM);
8138           output_asm_insn (\"{l|lwz} %0,lo16(%2)(%1)\", operands);
8139           /* We cannot rely on ha16(low half)==ha16(high half), alas,
8140              although in practice it almost always is.  */
8141           output_asm_insn (\"{cau|addis} %L0,%3,ha16(%2+4)\", operands2);
8142           return (\"{l|lwz} %L0,lo16(%2+4)(%L0)\");
8143         }
8144       default:
8145         abort();
8146     }
8147 }"
8148   [(set_attr "type" "load")
8149    (set_attr "length" "4,12")])
8150
8151 (define_insn "movdf_low_st"
8152   [(set (mem:DF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
8153                            (match_operand 2 "" "")))
8154         (match_operand:DF 0 "gpc_reg_operand" "f"))]
8155   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
8156   "stfd %0,lo16(%2)(%1)"
8157   [(set_attr "type" "store")
8158    (set_attr "length" "4")])
8159
8160 (define_insn "movsf_low"
8161   [(set (match_operand:SF 0 "gpc_reg_operand" "=f,!r")
8162         (mem:SF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
8163                            (match_operand 2 "" ""))))]
8164   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
8165   "@
8166    lfs %0,lo16(%2)(%1)
8167    {l|lwz} %0,lo16(%2)(%1)"
8168   [(set_attr "type" "load")
8169    (set_attr "length" "4")])
8170
8171 (define_insn "movsf_low_st"
8172   [(set (mem:SF (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,b")
8173                            (match_operand 2 "" "")))
8174         (match_operand:SF 0 "gpc_reg_operand" "f,!r"))]
8175   "TARGET_MACHO && TARGET_HARD_FLOAT && TARGET_FPRS && ! TARGET_64BIT"
8176   "@
8177    stfs %0,lo16(%2)(%1)
8178    {st|stw} %0,lo16(%2)(%1)"
8179   [(set_attr "type" "store")
8180    (set_attr "length" "4")])
8181
8182 (define_insn "*movsi_internal1"
8183   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,m,r,r,r,r,r,*q,*c*l,*h,*h")
8184         (match_operand:SI 1 "input_operand" "r,U,m,r,I,L,n,R,*h,r,r,r,0"))]
8185   "gpc_reg_operand (operands[0], SImode)
8186    || gpc_reg_operand (operands[1], SImode)"
8187   "@
8188    mr %0,%1
8189    {cal|la} %0,%a1
8190    {l%U1%X1|lwz%U1%X1} %0,%1
8191    {st%U0%X0|stw%U0%X0} %1,%0
8192    {lil|li} %0,%1
8193    {liu|lis} %0,%v1
8194    #
8195    {cal|la} %0,%a1
8196    mf%1 %0
8197    mt%0 %1
8198    mt%0 %1
8199    mt%0 %1
8200    cror 0,0,0"
8201   [(set_attr "type" "*,*,load,store,*,*,*,*,*,*,mtjmpr,*,*")
8202    (set_attr "length" "4,4,4,4,4,4,8,4,4,4,4,4,4")])
8203
8204 ;; Split a load of a large constant into the appropriate two-insn
8205 ;; sequence.
8206
8207 (define_split
8208   [(set (match_operand:SI 0 "gpc_reg_operand" "")
8209         (match_operand:SI 1 "const_int_operand" ""))]
8210   "(unsigned HOST_WIDE_INT) (INTVAL (operands[1]) + 0x8000) >= 0x10000
8211    && (INTVAL (operands[1]) & 0xffff) != 0"
8212   [(set (match_dup 0)
8213         (match_dup 2))
8214    (set (match_dup 0)
8215         (ior:SI (match_dup 0)
8216                 (match_dup 3)))]
8217   "
8218 {
8219   operands[2] = GEN_INT (INTVAL (operands[1]) & (~ (HOST_WIDE_INT) 0xffff));
8220   operands[3] = GEN_INT (INTVAL (operands[1]) & 0xffff);
8221 }")
8222
8223 (define_insn "*movsi_internal2"
8224   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
8225         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r,r")
8226                     (const_int 0)))
8227    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r") (match_dup 1))]
8228   "! TARGET_POWERPC64"
8229   "@
8230    mr. %0,%1
8231    #"
8232   [(set_attr "type" "compare")
8233    (set_attr "length" "4,8")])
8234 \f
8235 (define_split
8236   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
8237         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
8238                     (const_int 0)))
8239    (set (match_operand:SI 0 "gpc_reg_operand" "") (match_dup 1))]
8240   "! TARGET_POWERPC64 && reload_completed"
8241   [(set (match_dup 0) (match_dup 1))
8242    (set (match_dup 2)
8243         (compare:CC (match_dup 0)
8244                     (const_int 0)))]
8245   "")
8246
8247 (define_expand "movhi"
8248   [(set (match_operand:HI 0 "general_operand" "")
8249         (match_operand:HI 1 "any_operand" ""))]
8250   ""
8251   "{ rs6000_emit_move (operands[0], operands[1], HImode); DONE; }")
8252
8253 (define_insn ""
8254   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
8255         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
8256   "gpc_reg_operand (operands[0], HImode)
8257    || gpc_reg_operand (operands[1], HImode)"
8258   "@
8259    mr %0,%1
8260    lhz%U1%X1 %0,%1
8261    sth%U0%X0 %1,%0
8262    {lil|li} %0,%w1
8263    mf%1 %0
8264    mt%0 %1
8265    mt%0 %1
8266    cror 0,0,0"
8267   [(set_attr "type" "*,load,store,*,*,*,mtjmpr,*")])
8268
8269 (define_expand "movqi"
8270   [(set (match_operand:QI 0 "general_operand" "")
8271         (match_operand:QI 1 "any_operand" ""))]
8272   ""
8273   "{ rs6000_emit_move (operands[0], operands[1], QImode); DONE; }")
8274
8275 (define_insn ""
8276   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
8277         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
8278   "gpc_reg_operand (operands[0], QImode)
8279    || gpc_reg_operand (operands[1], QImode)"
8280   "@
8281    mr %0,%1
8282    lbz%U1%X1 %0,%1
8283    stb%U0%X0 %1,%0
8284    {lil|li} %0,%1
8285    mf%1 %0
8286    mt%0 %1
8287    mt%0 %1
8288    cror 0,0,0"
8289   [(set_attr "type" "*,load,store,*,*,*,mtjmpr,*")])
8290 \f
8291 ;; Here is how to move condition codes around.  When we store CC data in
8292 ;; an integer register or memory, we store just the high-order 4 bits.
8293 ;; This lets us not shift in the most common case of CR0.
8294 (define_expand "movcc"
8295   [(set (match_operand:CC 0 "nonimmediate_operand" "")
8296         (match_operand:CC 1 "nonimmediate_operand" ""))]
8297   ""
8298   "")
8299
8300 (define_insn "*movcc_internal1"
8301   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,y,r,r,r,r,m")
8302         (match_operand:CC 1 "nonimmediate_operand" "y,r,r,x,y,r,m,r"))]
8303   "register_operand (operands[0], CCmode)
8304    || register_operand (operands[1], CCmode)"
8305   "@
8306    mcrf %0,%1
8307    mtcrf 128,%1
8308    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
8309    mfcr %0
8310    mfcr %0\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
8311    mr %0,%1
8312    {l%U1%X1|lwz%U1%X1} %0,%1
8313    {st%U0%U1|stw%U0%U1} %1,%0"
8314   [(set_attr "type" "cr_logical,cr_logical,cr_logical,cr_logical,cr_logical,*,load,store")
8315    (set_attr "length" "*,*,12,*,8,*,*,*")])
8316 \f
8317 ;; For floating-point, we normally deal with the floating-point registers
8318 ;; unless -msoft-float is used.  The sole exception is that parameter passing
8319 ;; can produce floating-point values in fixed-point registers.  Unless the
8320 ;; value is a simple constant or already in memory, we deal with this by
8321 ;; allocating memory and copying the value explicitly via that memory location.
8322 (define_expand "movsf"
8323   [(set (match_operand:SF 0 "nonimmediate_operand" "")
8324         (match_operand:SF 1 "any_operand" ""))]
8325   ""
8326   "{ rs6000_emit_move (operands[0], operands[1], SFmode); DONE; }")
8327
8328 (define_split
8329   [(set (match_operand:SF 0 "gpc_reg_operand" "")
8330         (match_operand:SF 1 "const_double_operand" ""))]
8331   "reload_completed
8332    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8333        || (GET_CODE (operands[0]) == SUBREG
8334            && GET_CODE (SUBREG_REG (operands[0])) == REG
8335            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8336   [(set (match_dup 2) (match_dup 3))]
8337   "
8338 {
8339   long l;
8340   REAL_VALUE_TYPE rv;
8341
8342   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8343   REAL_VALUE_TO_TARGET_SINGLE (rv, l);
8344
8345   if (! TARGET_POWERPC64)
8346     operands[2] = operand_subword (operands[0], 0, 0, SFmode);
8347   else
8348     operands[2] = gen_lowpart (SImode, operands[0]);
8349
8350   operands[3] = gen_int_mode (l, SImode);
8351 }")
8352
8353 (define_insn "*movsf_hardfloat"
8354   [(set (match_operand:SF 0 "nonimmediate_operand" "=!r,!r,m,f,f,m,!r,!r")
8355         (match_operand:SF 1 "input_operand" "r,m,r,f,m,f,G,Fn"))]
8356   "(gpc_reg_operand (operands[0], SFmode)
8357    || gpc_reg_operand (operands[1], SFmode))
8358    && (TARGET_HARD_FLOAT && TARGET_FPRS)"
8359   "@
8360    mr %0,%1
8361    {l%U1%X1|lwz%U1%X1} %0,%1
8362    {st%U0%X0|stw%U0%X0} %1,%0
8363    fmr %0,%1
8364    lfs%U1%X1 %0,%1
8365    stfs%U0%X0 %1,%0
8366    #
8367    #"
8368   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,*")
8369    (set_attr "length" "4,4,4,4,4,4,4,8")])
8370
8371 (define_insn "*movsf_softfloat"
8372   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,r")
8373         (match_operand:SF 1 "input_operand" "r,m,r,I,L,R,G,Fn"))]
8374   "(gpc_reg_operand (operands[0], SFmode)
8375    || gpc_reg_operand (operands[1], SFmode))
8376    && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
8377   "@
8378    mr %0,%1
8379    {l%U1%X1|lwz%U1%X1} %0,%1
8380    {st%U0%X0|stw%U0%X0} %1,%0
8381    {lil|li} %0,%1
8382    {liu|lis} %0,%v1
8383    {cal|la} %0,%a1
8384    #
8385    #"
8386   [(set_attr "type" "*,load,store,*,*,*,*,*")
8387    (set_attr "length" "4,4,4,4,4,4,4,8")])
8388
8389 \f
8390 (define_expand "movdf"
8391   [(set (match_operand:DF 0 "nonimmediate_operand" "")
8392         (match_operand:DF 1 "any_operand" ""))]
8393   ""
8394   "{ rs6000_emit_move (operands[0], operands[1], DFmode); DONE; }")
8395
8396 (define_split
8397   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8398         (match_operand:DF 1 "const_int_operand" ""))]
8399   "! TARGET_POWERPC64 && reload_completed
8400    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8401        || (GET_CODE (operands[0]) == SUBREG
8402            && GET_CODE (SUBREG_REG (operands[0])) == REG
8403            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8404   [(set (match_dup 2) (match_dup 4))
8405    (set (match_dup 3) (match_dup 1))]
8406   "
8407 {
8408   int endian = (WORDS_BIG_ENDIAN == 0);
8409   HOST_WIDE_INT value = INTVAL (operands[1]);
8410
8411   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8412   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8413 #if HOST_BITS_PER_WIDE_INT == 32
8414   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8415 #else
8416   operands[4] = GEN_INT (value >> 32);
8417   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8418 #endif
8419 }")
8420
8421 (define_split
8422   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8423         (match_operand:DF 1 "const_double_operand" ""))]
8424   "! TARGET_POWERPC64 && reload_completed
8425    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8426        || (GET_CODE (operands[0]) == SUBREG
8427            && GET_CODE (SUBREG_REG (operands[0])) == REG
8428            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8429   [(set (match_dup 2) (match_dup 4))
8430    (set (match_dup 3) (match_dup 5))]
8431   "
8432 {
8433   int endian = (WORDS_BIG_ENDIAN == 0);
8434   long l[2];
8435   REAL_VALUE_TYPE rv;
8436
8437   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8438   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8439
8440   operands[2] = operand_subword (operands[0], endian, 0, DFmode);
8441   operands[3] = operand_subword (operands[0], 1 - endian, 0, DFmode);
8442   operands[4] = gen_int_mode (l[endian], SImode);
8443   operands[5] = gen_int_mode (l[1 - endian], SImode);
8444 }")
8445
8446 (define_split
8447   [(set (match_operand:DF 0 "gpc_reg_operand" "")
8448         (match_operand:DF 1 "easy_fp_constant" ""))]
8449   "TARGET_POWERPC64 && reload_completed
8450    && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
8451        || (GET_CODE (operands[0]) == SUBREG
8452            && GET_CODE (SUBREG_REG (operands[0])) == REG
8453            && REGNO (SUBREG_REG (operands[0])) <= 31))"
8454   [(set (match_dup 2) (match_dup 3))]
8455   "
8456 {
8457   int endian = (WORDS_BIG_ENDIAN == 0);
8458   long l[2];
8459   REAL_VALUE_TYPE rv;
8460   HOST_WIDE_INT val;
8461
8462   REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
8463   REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
8464
8465   operands[2] = gen_lowpart (DImode, operands[0]);
8466   /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN.  */
8467 #if HOST_BITS_PER_WIDE_INT >= 64
8468   val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32 |
8469         ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
8470
8471   operands[3] = immed_double_const (val, -(val < 0), DImode);
8472 #else
8473   operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
8474 #endif
8475 }")
8476
8477 ;; Don't have reload use general registers to load a constant.  First,
8478 ;; it might not work if the output operand is the equivalent of
8479 ;; a non-offsettable memref, but also it is less efficient than loading
8480 ;; the constant into an FP register, since it will probably be used there.
8481 ;; The "??" is a kludge until we can figure out a more reasonable way
8482 ;; of handling these non-offsettable values.
8483 (define_insn "*movdf_hardfloat32"
8484   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,!r,!r,!r,f,f,m")
8485         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F,f,m,f"))]
8486   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8487    && (gpc_reg_operand (operands[0], DFmode)
8488        || gpc_reg_operand (operands[1], DFmode))"
8489   "*
8490 {
8491   switch (which_alternative)
8492     {
8493     default:
8494       abort ();
8495     case 0:
8496       /* We normally copy the low-numbered register first.  However, if
8497          the first register operand 0 is the same as the second register
8498          of operand 1, we must copy in the opposite order.  */
8499       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8500         return \"mr %L0,%L1\;mr %0,%1\";
8501       else
8502         return \"mr %0,%1\;mr %L0,%L1\";
8503     case 1:
8504       if (offsettable_memref_p (operands[1])
8505           || (GET_CODE (operands[1]) == MEM
8506               && (GET_CODE (XEXP (operands[1], 0)) == LO_SUM
8507                   || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
8508                   || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)))
8509         {
8510           /* If the low-address word is used in the address, we must load
8511              it last.  Otherwise, load it first.  Note that we cannot have
8512              auto-increment in that case since the address register is
8513              known to be dead.  */
8514           if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8515                                  operands[1], 0))
8516             return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8517           else
8518             return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8519         }
8520       else
8521         {
8522           rtx addreg;
8523
8524           addreg = find_addr_reg (XEXP (operands[1], 0));
8525           if (refers_to_regno_p (REGNO (operands[0]),
8526                                  REGNO (operands[0]) + 1,
8527                                  operands[1], 0))
8528             {
8529               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8530               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8531               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8532               return \"{lx|lwzx} %0,%1\";
8533             }
8534           else
8535             {
8536               output_asm_insn (\"{lx|lwzx} %0,%1\", operands);
8537               output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8538               output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
8539               output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8540               return \"\";
8541             }
8542         }
8543     case 2:
8544       if (offsettable_memref_p (operands[0])
8545           || (GET_CODE (operands[0]) == MEM
8546               && (GET_CODE (XEXP (operands[0], 0)) == LO_SUM
8547                   || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
8548                   || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)))
8549         return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8550       else
8551         {
8552           rtx addreg;
8553
8554           addreg = find_addr_reg (XEXP (operands[0], 0));
8555           output_asm_insn (\"{stx|stwx} %1,%0\", operands);
8556           output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
8557           output_asm_insn (\"{stx|stwx} %L1,%0\", operands);
8558           output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
8559           return \"\";
8560         }
8561     case 3:
8562     case 4:
8563     case 5:
8564       return \"#\";
8565     case 6:
8566       return \"fmr %0,%1\";
8567     case 7:
8568       return \"lfd%U1%X1 %0,%1\";
8569     case 8:
8570       return \"stfd%U0%X0 %1,%0\";
8571     }
8572 }"
8573   [(set_attr "type" "*,load,store,*,*,*,fp,fpload,fpstore")
8574    (set_attr "length" "8,16,16,8,12,16,*,*,*")])
8575
8576 (define_insn "*movdf_softfloat32"
8577   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
8578         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
8579   "! TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8580    && (gpc_reg_operand (operands[0], DFmode)
8581        || gpc_reg_operand (operands[1], DFmode))"
8582   "*
8583 {
8584   switch (which_alternative)
8585     {
8586     default:
8587       abort ();
8588     case 0:
8589       /* We normally copy the low-numbered register first.  However, if
8590          the first register operand 0 is the same as the second register of
8591          operand 1, we must copy in the opposite order.  */
8592       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8593         return \"mr %L0,%L1\;mr %0,%1\";
8594       else
8595         return \"mr %0,%1\;mr %L0,%L1\";
8596     case 1:
8597       /* If the low-address word is used in the address, we must load
8598          it last.  Otherwise, load it first.  Note that we cannot have
8599          auto-increment in that case since the address register is
8600          known to be dead.  */
8601       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8602                              operands[1], 0))
8603         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8604       else
8605         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8606     case 2:
8607       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8608     case 3:
8609     case 4:
8610     case 5:
8611       return \"#\";
8612     }
8613 }"
8614   [(set_attr "type" "*,load,store,*,*,*")
8615    (set_attr "length" "8,8,8,8,12,16")])
8616
8617 (define_insn "*movdf_hardfloat64"
8618   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,m,!r,!r,!r,f,f,m")
8619         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F,f,m,f"))]
8620   "TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
8621    && (gpc_reg_operand (operands[0], DFmode)
8622        || gpc_reg_operand (operands[1], DFmode))"
8623   "@
8624    mr %0,%1
8625    ld%U1%X1 %0,%1
8626    std%U0%X0 %1,%0
8627    #
8628    #
8629    #
8630    fmr %0,%1
8631    lfd%U1%X1 %0,%1
8632    stfd%U0%X0 %1,%0"
8633   [(set_attr "type" "*,load,store,*,*,*,fp,fpload,fpstore")
8634    (set_attr "length" "4,4,4,8,12,16,4,4,4")])
8635
8636 (define_insn "*movdf_softfloat64"
8637   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
8638         (match_operand:DF 1 "input_operand" "r,m,r,G,H,F"))]
8639   "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8640    && (gpc_reg_operand (operands[0], DFmode)
8641        || gpc_reg_operand (operands[1], DFmode))"
8642   "@
8643    mr %0,%1
8644    ld%U1%X1 %0,%1
8645    std%U0%X0 %1,%0
8646    #
8647    #
8648    #"
8649   [(set_attr "type" "*,load,store,*,*,*")
8650    (set_attr "length" "*,*,*,8,12,16")])
8651 \f
8652 (define_expand "movtf"
8653   [(set (match_operand:TF 0 "general_operand" "")
8654         (match_operand:TF 1 "any_operand" ""))]
8655   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8656    && TARGET_LONG_DOUBLE_128"
8657   "{ rs6000_emit_move (operands[0], operands[1], TFmode); DONE; }")
8658
8659 (define_insn "*movtf_internal"
8660   [(set (match_operand:TF 0 "nonimmediate_operand" "=f,f,m,!r,!r,!r")
8661         (match_operand:TF 1 "input_operand" "f,m,f,G,H,F"))]
8662   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8663    && TARGET_LONG_DOUBLE_128
8664    && (gpc_reg_operand (operands[0], TFmode)
8665        || gpc_reg_operand (operands[1], TFmode))"
8666   "*
8667 {
8668   switch (which_alternative)
8669     {
8670     default:
8671       abort ();
8672     case 0:
8673       /* We normally copy the low-numbered register first.  However, if
8674          the first register operand 0 is the same as the second register of
8675          operand 1, we must copy in the opposite order.  */
8676       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8677         return \"fmr %L0,%L1\;fmr %0,%1\";
8678       else
8679         return \"fmr %0,%1\;fmr %L0,%L1\";
8680     case 1:
8681       return \"lfd %0,%1\;lfd %L0,%L1\";
8682     case 2:
8683       return \"stfd %1,%0\;stfd %L1,%L0\";
8684     case 3:
8685     case 4:
8686     case 5:
8687       return \"#\";
8688     }
8689 }"
8690   [(set_attr "type" "fp,fpload,fpstore,*,*,*")
8691    (set_attr "length" "8,8,8,12,16,20")])
8692
8693 (define_split
8694   [(set (match_operand:TF 0 "gpc_reg_operand" "")
8695         (match_operand:TF 1 "const_double_operand" ""))]
8696   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8697    && TARGET_LONG_DOUBLE_128"
8698   [(set (match_dup 3) (match_dup 1))
8699    (set (match_dup 0)
8700         (float_extend:TF (match_dup 3)))]
8701   "
8702 {
8703   operands[2] = operand_subword (operands[1], 0, 0, DFmode);
8704   operands[3] = gen_reg_rtx (DFmode);
8705 }")
8706
8707 (define_insn_and_split "extenddftf2"
8708   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8709         (float_extend:TF (match_operand:DF 1 "gpc_reg_operand" "f")))]
8710   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8711    && TARGET_LONG_DOUBLE_128"
8712   "#"
8713   ""
8714   [(set (match_dup 2) (match_dup 3))]
8715   "
8716 {
8717   operands[2] = gen_rtx_REG (DFmode, REGNO (operands[0] + 1));
8718   operands[3] = CONST0_RTX (DFmode);
8719 }")
8720
8721 (define_insn_and_split "extendsftf2"
8722   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8723         (float_extend:TF (match_operand:SF 1 "gpc_reg_operand" "f")))]
8724   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8725    && TARGET_LONG_DOUBLE_128"
8726   "#"
8727   ""
8728   [(set (match_dup 2) (match_dup 3))]
8729   "
8730 {
8731   operands[2] = gen_rtx_REG (SFmode, REGNO (operands[0] + 1));
8732   operands[3] = CONST0_RTX (SFmode);
8733 }")
8734
8735 (define_insn "trunctfdf2"
8736   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
8737         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8738   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8739    && TARGET_LONG_DOUBLE_128"
8740   "fadd %0,%1,%L1"
8741   [(set_attr "type" "fp")
8742    (set_attr "length" "8")])
8743
8744 (define_insn_and_split "trunctfsf2"
8745   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
8746         (float_truncate:SF (match_operand:TF 1 "gpc_reg_operand" "f")))
8747    (clobber (match_scratch:DF 2 "=f"))]
8748   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT
8749    && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8750   "#"
8751   "&& reload_completed"
8752   [(set (match_dup 2)
8753         (float_truncate:DF (match_dup 1)))
8754    (set (match_dup 0)
8755         (float_truncate:SF (match_dup 2)))]
8756   "")
8757
8758 (define_insn_and_split "floatditf2"
8759   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8760         (float:TF (match_operand:DI 1 "gpc_reg_operand" "*f")))
8761    (clobber (match_scratch:DF 2 "=f"))]
8762   "DEFAULT_ABI == ABI_AIX && TARGET_POWERPC64
8763    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8764   "#"
8765   "&& reload_completed"
8766   [(set (match_dup 2)
8767         (float:DF (match_operand:DI 1 "gpc_reg_operand" "")))
8768    (set (match_operand:TF 0 "gpc_reg_operand" "")
8769         (float_extend:TF (match_dup 2)))]
8770   "")
8771
8772 (define_insn_and_split "floatsitf2"
8773   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8774         (float:TF (match_operand:SI 1 "gpc_reg_operand" "r")))
8775    (clobber (match_scratch:DF 2 "=f"))]
8776   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8777    && TARGET_LONG_DOUBLE_128"
8778   "#"
8779   "&& reload_completed"
8780   [(set (match_dup 2)
8781         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))
8782    (set (match_operand:TF 0 "gpc_reg_operand" "")
8783         (float_extend:TF (match_dup 2)))]
8784   "")
8785
8786 (define_insn_and_split "fix_trunctfdi2"
8787   [(set (match_operand:DI 0 "gpc_reg_operand" "=*f")
8788         (fix:DI (match_operand:TF 1 "gpc_reg_operand" "f")))]
8789   "DEFAULT_ABI == ABI_AIX && TARGET_POWERPC64
8790    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
8791   "#"
8792   "&& reload_completed"
8793   [(set (match_dup 2)
8794         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))
8795    (set (match_operand:DI 0 "gpc_reg_operand" "")
8796         (fix:SI (match_dup 2)))]
8797   "")
8798
8799 (define_insn_and_split "fix_trunctfsi2"
8800   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8801         (fix:SI (match_operand:TF 1 "gpc_reg_operand" "f")))]
8802   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8803    && TARGET_LONG_DOUBLE_128"
8804   "#"
8805   "&& reload_completed"
8806   [(set (match_dup 2)
8807         (float_truncate:DF (match_operand:TF 1 "gpc_reg_operand" "")))
8808    (set (match_operand:SI 0 "gpc_reg_operand" "")
8809         (fix:SI (match_dup 2)))]
8810   "")
8811
8812 (define_insn "negtf2"
8813   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8814         (neg:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8815   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8816    && TARGET_LONG_DOUBLE_128"
8817   "*
8818 {
8819   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8820     return \"fneg %L0,%L1\;fneg %0,%1\";
8821   else
8822     return \"fneg %0,%1\;fneg %L0,%L1\";
8823 }"
8824   [(set_attr "type" "fp")
8825    (set_attr "length" "8")])
8826
8827 (define_insn "abstf2"
8828   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8829         (abs:TF (match_operand:TF 1 "gpc_reg_operand" "f")))]
8830   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8831    && TARGET_LONG_DOUBLE_128"
8832   "*
8833 {
8834   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8835     return \"fabs %L0,%L1\;fabs %0,%1\";
8836   else
8837     return \"fabs %0,%1\;fabs %L0,%L1\";
8838 }"
8839   [(set_attr "type" "fp")
8840    (set_attr "length" "8")])
8841
8842 (define_insn ""
8843   [(set (match_operand:TF 0 "gpc_reg_operand" "=f")
8844         (neg:TF (abs:TF (match_operand:TF 1 "gpc_reg_operand" "f"))))]
8845   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
8846    && TARGET_LONG_DOUBLE_128"
8847   "*
8848 {
8849   if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8850     return \"fnabs %L0,%L1\;fnabs %0,%1\";
8851   else
8852     return \"fnabs %0,%1\;fnabs %L0,%L1\";
8853 }"
8854   [(set_attr "type" "fp")
8855    (set_attr "length" "8")])
8856 \f
8857 ;; Next come the multi-word integer load and store and the load and store
8858 ;; multiple insns.
8859 (define_expand "movdi"
8860   [(set (match_operand:DI 0 "general_operand" "")
8861         (match_operand:DI 1 "any_operand" ""))]
8862   ""
8863   "{ rs6000_emit_move (operands[0], operands[1], DImode); DONE; }")
8864
8865 (define_insn "*movdi_internal32"
8866   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,f,f,m,r,r,r,r,r")
8867         (match_operand:DI 1 "input_operand" "r,m,r,f,m,f,IJK,n,G,H,F"))]
8868   "! TARGET_POWERPC64
8869    && (gpc_reg_operand (operands[0], DImode)
8870        || gpc_reg_operand (operands[1], DImode))"
8871   "*
8872 {
8873   switch (which_alternative)
8874     {
8875     default:
8876       abort ();
8877     case 0:
8878       /* We normally copy the low-numbered register first.  However, if
8879          the first register operand 0 is the same as the second register of
8880          operand 1, we must copy in the opposite order.  */
8881       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
8882         return \"mr %L0,%L1\;mr %0,%1\";
8883       else
8884         return \"mr %0,%1\;mr %L0,%L1\";
8885     case 1:
8886       /* If the low-address word is used in the address, we must load it
8887          last.  Otherwise, load it first.  Note that we cannot have
8888          auto-increment in that case since the address register is known to be
8889          dead.  */
8890       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
8891                              operands[1], 0))
8892         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
8893       else
8894         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
8895     case 2:
8896       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
8897     case 3:
8898       return \"fmr %0,%1\";
8899     case 4:
8900       return \"lfd%U1%X1 %0,%1\";
8901     case 5:
8902       return \"stfd%U0%X0 %1,%0\";
8903     case 6:
8904     case 7:
8905     case 8:
8906     case 9:
8907     case 10:
8908       return \"#\";
8909     }
8910 }"
8911   [(set_attr "type" "*,load,store,fp,fpload,fpstore,*,*,*,*,*")
8912    (set_attr "length" "8,8,8,*,*,*,8,12,8,12,16")])
8913
8914 (define_split
8915   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8916         (match_operand:DI 1 "const_int_operand" ""))]
8917   "! TARGET_POWERPC64 && reload_completed"
8918   [(set (match_dup 2) (match_dup 4))
8919    (set (match_dup 3) (match_dup 1))]
8920   "
8921 {
8922   HOST_WIDE_INT value = INTVAL (operands[1]);
8923   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8924                                        DImode);
8925   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8926                                        DImode);
8927 #if HOST_BITS_PER_WIDE_INT == 32
8928   operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
8929 #else
8930   operands[4] = GEN_INT (value >> 32);
8931   operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
8932 #endif
8933 }")
8934
8935 (define_split
8936   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8937         (match_operand:DI 1 "const_double_operand" ""))]
8938   "HOST_BITS_PER_WIDE_INT == 32 && ! TARGET_POWERPC64 && reload_completed"
8939   [(set (match_dup 2) (match_dup 4))
8940    (set (match_dup 3) (match_dup 5))]
8941   "
8942 {
8943   operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
8944                                        DImode);
8945   operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
8946                                        DImode);
8947   operands[4] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
8948   operands[5] = GEN_INT (CONST_DOUBLE_LOW  (operands[1]));
8949 }")
8950
8951 (define_insn "*movdi_internal64"
8952   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,f,f,m,r,*h,*h")
8953         (match_operand:DI 1 "input_operand" "r,m,r,I,L,nF,R,f,m,f,*h,r,0"))]
8954   "TARGET_POWERPC64
8955    && (gpc_reg_operand (operands[0], DImode)
8956        || gpc_reg_operand (operands[1], DImode))"
8957   "@
8958    mr %0,%1
8959    ld%U1%X1 %0,%1
8960    std%U0%X0 %1,%0
8961    li %0,%1
8962    lis %0,%v1
8963    #
8964    {cal|la} %0,%a1
8965    fmr %0,%1
8966    lfd%U1%X1 %0,%1
8967    stfd%U0%X0 %1,%0
8968    mf%1 %0
8969    mt%0 %1
8970    cror 0,0,0"
8971   [(set_attr "type" "*,load,store,*,*,*,*,fp,fpload,fpstore,*,mtjmpr,*")
8972    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
8973
8974 ;; immediate value valid for a single instruction hiding in a const_double
8975 (define_insn ""
8976   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
8977         (match_operand:DI 1 "const_double_operand" "F"))]
8978   "HOST_BITS_PER_WIDE_INT == 32 && TARGET_POWERPC64
8979    && GET_CODE (operands[1]) == CONST_DOUBLE
8980    && num_insns_constant (operands[1], DImode) == 1"
8981   "*
8982 {
8983   return ((unsigned HOST_WIDE_INT)
8984           (CONST_DOUBLE_LOW (operands[1]) + 0x8000) < 0x10000)
8985          ? \"li %0,%1\" : \"lis %0,%v1\";
8986 }")
8987
8988 ;; Generate all one-bits and clear left or right.
8989 ;; Use (and:DI (rotate:DI ...)) to avoid anddi3 unnecessary clobber.
8990 (define_split
8991   [(set (match_operand:DI 0 "gpc_reg_operand" "")
8992         (match_operand:DI 1 "mask64_operand" ""))]
8993   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
8994   [(set (match_dup 0) (const_int -1))
8995    (set (match_dup 0)
8996         (and:DI (rotate:DI (match_dup 0)
8997                            (const_int 0))
8998                 (match_dup 1)))]
8999   "")
9000
9001 ;; Split a load of a large constant into the appropriate five-instruction
9002 ;; sequence.  Handle anything in a constant number of insns.
9003 ;; When non-easy constants can go in the TOC, this should use
9004 ;; easy_fp_constant predicate.
9005 (define_split
9006   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9007         (match_operand:DI 1 "const_int_operand" ""))]
9008   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9009   [(set (match_dup 0) (match_dup 2))
9010    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
9011   "
9012 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
9013
9014   if (tem == operands[0])
9015     DONE;
9016   else
9017     FAIL;
9018 }")
9019
9020 (define_split
9021   [(set (match_operand:DI 0 "gpc_reg_operand" "")
9022         (match_operand:DI 1 "const_double_operand" ""))]
9023   "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9024   [(set (match_dup 0) (match_dup 2))
9025    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
9026   "
9027 { rtx tem = rs6000_emit_set_const (operands[0], DImode, operands[1], 5);
9028
9029   if (tem == operands[0])
9030     DONE;
9031   else
9032     FAIL;
9033 }")
9034
9035 ;; Split a load of a large constant into the appropriate five-instruction
9036 (define_insn "*movdi_internal2"
9037   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
9038         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "r,r")
9039                     (const_int 0)))
9040    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r") (match_dup 1))]
9041   "TARGET_POWERPC64"
9042   "@
9043    mr. %0,%1
9044    #"
9045   [(set_attr "type" "compare")
9046    (set_attr "length" "4,8")])
9047
9048 (define_split
9049   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
9050         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "")
9051                     (const_int 0)))
9052    (set (match_operand:DI 0 "gpc_reg_operand" "") (match_dup 1))]
9053   "TARGET_POWERPC64 && reload_completed"
9054   [(set (match_dup 0) (match_dup 1))
9055    (set (match_dup 2)
9056         (compare:CC (match_dup 0)
9057                     (const_int 0)))]
9058   "")
9059 \f
9060 ;; TImode is similar, except that we usually want to compute the address into
9061 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
9062 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
9063 (define_expand "movti"
9064   [(parallel [(set (match_operand:TI 0 "general_operand" "")
9065                    (match_operand:TI 1 "general_operand" ""))
9066               (clobber (scratch:SI))])]
9067   "TARGET_STRING || TARGET_POWERPC64"
9068   "{ rs6000_emit_move (operands[0], operands[1], TImode); DONE; }")
9069
9070 ;; We say that MQ is clobbered in the last alternative because the first
9071 ;; alternative would never get used otherwise since it would need a reload
9072 ;; while the 2nd alternative would not.  We put memory cases first so they
9073 ;; are preferred.  Otherwise, we'd try to reload the output instead of
9074 ;; giving the SCRATCH mq.
9075 (define_insn "*movti_power"
9076   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
9077         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))
9078    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X"))]
9079   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
9080    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
9081   "*
9082 {
9083   switch (which_alternative)
9084     {
9085     default:
9086       abort ();
9087
9088     case 0:
9089       return \"{stsi|stswi} %1,%P0,16\";
9090
9091     case 1:
9092       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\;{st|stw} %Y1,%Y0\;{st|stw} %Z1,%Z0\";
9093
9094     case 2:
9095       /* Normally copy registers with lowest numbered register copied first.
9096          But copy in the other order if the first register of the output
9097          is the second, third, or fourth register in the input.  */
9098       if (REGNO (operands[0]) >= REGNO (operands[1]) + 1
9099           && REGNO (operands[0]) <= REGNO (operands[1]) + 3)
9100         return \"mr %Z0,%Z1\;mr %Y0,%Y1\;mr %L0,%L1\;mr %0,%1\";
9101       else
9102         return \"mr %0,%1\;mr %L0,%L1\;mr %Y0,%Y1\;mr %Z0,%Z1\";
9103     case 3:
9104       /* If the address is not used in the output, we can use lsi.  Otherwise,
9105          fall through to generating four loads.  */
9106       if (! reg_overlap_mentioned_p (operands[0], operands[1]))
9107         return \"{lsi|lswi} %0,%P1,16\";
9108       /* ... fall through ...  */
9109     case 4:
9110       /* If the address register is the same as the register for the lowest-
9111          addressed word, load it last.  Similarly for the next two words.
9112          Otherwise load lowest address to highest.  */
9113       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
9114                              operands[1], 0))
9115         return \"{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %0,%1\";
9116       else if (refers_to_regno_p (REGNO (operands[0]) + 1,
9117                                   REGNO (operands[0]) + 2, operands[1], 0))
9118         return \"{l|lwz} %0,%1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %L0,%L1\";
9119       else if (refers_to_regno_p (REGNO (operands[0]) + 2,
9120                                   REGNO (operands[0]) + 3, operands[1], 0))
9121         return \"{l|lwz} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Z0,%Z1\;{l|lwz} %Y0,%Y1\";
9122       else
9123         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\";
9124     }
9125 }"
9126   [(set_attr "type" "store,store,*,load,load")
9127    (set_attr "length" "*,16,16,*,16")])
9128
9129 (define_insn "*movti_string"
9130   [(set (match_operand:TI 0 "reg_or_mem_operand" "=m,????r,????r")
9131         (match_operand:TI 1 "reg_or_mem_operand" "r,r,m"))
9132    (clobber (match_scratch:SI 2 "=X,X,X"))]
9133   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
9134    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
9135   "*
9136 {
9137   switch (which_alternative)
9138     {
9139     default:
9140       abort ();
9141
9142     case 0:
9143       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\;{st|stw} %Y1,%Y0\;{st|stw} %Z1,%Z0\";
9144
9145     case 1:
9146       /* Normally copy registers with lowest numbered register copied first.
9147          But copy in the other order if the first register of the output
9148          is the second, third, or fourth register in the input.  */
9149       if (REGNO (operands[0]) >= REGNO (operands[1]) + 1
9150           && REGNO (operands[0]) <= REGNO (operands[1]) + 3)
9151         return \"mr %Z0,%Z1\;mr %Y0,%Y1\;mr %L0,%L1\;mr %0,%1\";
9152       else
9153         return \"mr %0,%1\;mr %L0,%L1\;mr %Y0,%Y1\;mr %Z0,%Z1\";
9154     case 2:
9155       /* If the address register is the same as the register for the lowest-
9156          addressed word, load it last.  Similarly for the next two words.
9157          Otherwise load lowest address to highest.  */
9158       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
9159                              operands[1], 0))
9160         return \"{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %0,%1\";
9161       else if (refers_to_regno_p (REGNO (operands[0]) + 1,
9162                                   REGNO (operands[0]) + 2, operands[1], 0))
9163         return \"{l|lwz} %0,%1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %L0,%L1\";
9164       else if (refers_to_regno_p (REGNO (operands[0]) + 2,
9165                                   REGNO (operands[0]) + 3, operands[1], 0))
9166         return \"{l|lwz} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Z0,%Z1\;{l|lwz} %Y0,%Y1\";
9167       else
9168         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\";
9169     }
9170 }"
9171   [(set_attr "type" "store,*,load")
9172    (set_attr "length" "16,16,16")])
9173
9174 (define_insn "*movti_ppc64"
9175   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,r,m")
9176         (match_operand:TI 1 "input_operand" "r,m,r"))]
9177   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
9178    || gpc_reg_operand (operands[1], TImode))"
9179   "*
9180 {
9181   switch (which_alternative)
9182     {
9183     default:
9184       abort ();
9185     case 0:
9186       /* We normally copy the low-numbered register first.  However, if
9187          the first register operand 0 is the same as the second register of
9188          operand 1, we must copy in the opposite order.  */
9189       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
9190         return \"mr %L0,%L1\;mr %0,%1\";
9191       else
9192         return \"mr %0,%1\;mr %L0,%L1\";
9193     case 1:
9194       /* If the low-address word is used in the address, we must load it
9195          last.  Otherwise, load it first.  Note that we cannot have
9196          auto-increment in that case since the address register is known to be
9197          dead.  */
9198       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
9199                              operands[1], 0))
9200         return \"ld %L0,%L1\;ld %0,%1\";
9201       else
9202         return \"ld%U1 %0,%1\;ld %L0,%L1\";
9203     case 2:
9204       return \"std%U0 %1,%0\;std %L1,%L0\";
9205     }
9206 }"
9207   [(set_attr "type" "*,load,store")
9208    (set_attr "length" "8,8,8")])
9209 \f
9210 (define_expand "load_multiple"
9211   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
9212                           (match_operand:SI 1 "" ""))
9213                      (use (match_operand:SI 2 "" ""))])]
9214   "TARGET_STRING && !TARGET_POWERPC64"
9215   "
9216 {
9217   int regno;
9218   int count;
9219   rtx op1;
9220   int i;
9221
9222   /* Support only loading a constant number of fixed-point registers from
9223      memory and only bother with this if more than two; the machine
9224      doesn't support more than eight.  */
9225   if (GET_CODE (operands[2]) != CONST_INT
9226       || INTVAL (operands[2]) <= 2
9227       || INTVAL (operands[2]) > 8
9228       || GET_CODE (operands[1]) != MEM
9229       || GET_CODE (operands[0]) != REG
9230       || REGNO (operands[0]) >= 32)
9231     FAIL;
9232
9233   count = INTVAL (operands[2]);
9234   regno = REGNO (operands[0]);
9235
9236   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
9237   op1 = replace_equiv_address (operands[1],
9238                                force_reg (SImode, XEXP (operands[1], 0)));
9239
9240   for (i = 0; i < count; i++)
9241     XVECEXP (operands[3], 0, i)
9242       = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno + i),
9243                      adjust_address (op1, SImode, i * 4));
9244 }")
9245
9246 (define_insn ""
9247   [(match_parallel 0 "load_multiple_operation"
9248                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
9249                          (mem:SI (match_operand:SI 2 "gpc_reg_operand" "b")))])]
9250   "TARGET_STRING"
9251   "*
9252 {
9253   /* We have to handle the case where the pseudo used to contain the address
9254      is assigned to one of the output registers.  */
9255   int i, j;
9256   int words = XVECLEN (operands[0], 0);
9257   rtx xop[10];
9258
9259   if (XVECLEN (operands[0], 0) == 1)
9260     return \"{l|lwz} %1,0(%2)\";
9261
9262   for (i = 0; i < words; i++)
9263     if (refers_to_regno_p (REGNO (operands[1]) + i,
9264                            REGNO (operands[1]) + i + 1, operands[2], 0))
9265       {
9266         if (i == words-1)
9267           {
9268             xop[0] = operands[1];
9269             xop[1] = operands[2];
9270             xop[2] = GEN_INT (4 * (words-1));
9271             output_asm_insn (\"{lsi|lswi} %0,%1,%2\;{l|lwz} %1,%2(%1)\", xop);
9272             return \"\";
9273           }
9274         else if (i == 0)
9275           {
9276             xop[0] = operands[1];
9277             xop[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
9278             xop[2] = GEN_INT (4 * (words-1));
9279             output_asm_insn (\"{cal %0,4(%0)|addi %0,%0,4}\;{lsi|lswi} %1,%0,%2\;{l|lwz} %0,-4(%0)\", xop);
9280             return \"\";
9281           }
9282         else
9283           {
9284             for (j = 0; j < words; j++)
9285               if (j != i)
9286                 {
9287                   xop[0] = gen_rtx_REG (SImode, REGNO (operands[1]) + j);
9288                   xop[1] = operands[2];
9289                   xop[2] = GEN_INT (j * 4);
9290                   output_asm_insn (\"{l|lwz} %0,%2(%1)\", xop);
9291                 }
9292             xop[0] = operands[2];
9293             xop[1] = GEN_INT (i * 4);
9294             output_asm_insn (\"{l|lwz} %0,%1(%0)\", xop);
9295             return \"\";
9296           }
9297       }
9298
9299   return \"{lsi|lswi} %1,%2,%N0\";
9300 }"
9301   [(set_attr "type" "load")
9302    (set_attr "length" "32")])
9303
9304 \f
9305 (define_expand "store_multiple"
9306   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
9307                           (match_operand:SI 1 "" ""))
9308                      (clobber (scratch:SI))
9309                      (use (match_operand:SI 2 "" ""))])]
9310   "TARGET_STRING && !TARGET_POWERPC64"
9311   "
9312 {
9313   int regno;
9314   int count;
9315   rtx to;
9316   rtx op0;
9317   int i;
9318
9319   /* Support only storing a constant number of fixed-point registers to
9320      memory and only bother with this if more than two; the machine
9321      doesn't support more than eight.  */
9322   if (GET_CODE (operands[2]) != CONST_INT
9323       || INTVAL (operands[2]) <= 2
9324       || INTVAL (operands[2]) > 8
9325       || GET_CODE (operands[0]) != MEM
9326       || GET_CODE (operands[1]) != REG
9327       || REGNO (operands[1]) >= 32)
9328     FAIL;
9329
9330   count = INTVAL (operands[2]);
9331   regno = REGNO (operands[1]);
9332
9333   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
9334   to = force_reg (SImode, XEXP (operands[0], 0));
9335   op0 = replace_equiv_address (operands[0], to);
9336
9337   XVECEXP (operands[3], 0, 0)
9338     = gen_rtx_SET (VOIDmode, adjust_address (op0, SImode, 0), operands[1]);
9339   XVECEXP (operands[3], 0, 1) = gen_rtx_CLOBBER (VOIDmode,
9340                                                  gen_rtx_SCRATCH (SImode));
9341
9342   for (i = 1; i < count; i++)
9343     XVECEXP (operands[3], 0, i + 1)
9344       = gen_rtx_SET (VOIDmode,
9345                      adjust_address (op0, SImode, i * 4),
9346                      gen_rtx_REG (SImode, regno + i));
9347 }")
9348
9349 (define_insn ""
9350   [(match_parallel 0 "store_multiple_operation"
9351                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
9352                          (match_operand:SI 2 "gpc_reg_operand" "r"))
9353                     (clobber (match_scratch:SI 3 "=q"))])]
9354   "TARGET_STRING && TARGET_POWER"
9355   "{stsi|stswi} %2,%P1,%O0"
9356   [(set_attr "type" "store")])
9357
9358 (define_insn ""
9359   [(match_parallel 0 "store_multiple_operation"
9360                    [(set (mem:SI (match_operand:SI 1 "gpc_reg_operand" "b"))
9361                          (match_operand:SI 2 "gpc_reg_operand" "r"))
9362                     (clobber (match_scratch:SI 3 "X"))])]
9363   "TARGET_STRING && ! TARGET_POWER"
9364   "{stsi|stswi} %2,%1,%O0"
9365   [(set_attr "type" "store")])
9366
9367 \f
9368 ;; String/block move insn.
9369 ;; Argument 0 is the destination
9370 ;; Argument 1 is the source
9371 ;; Argument 2 is the length
9372 ;; Argument 3 is the alignment
9373
9374 (define_expand "movstrsi"
9375   [(parallel [(set (match_operand:BLK 0 "" "")
9376                    (match_operand:BLK 1 "" ""))
9377               (use (match_operand:SI 2 "" ""))
9378               (use (match_operand:SI 3 "" ""))])]
9379   ""
9380   "
9381 {
9382   if (expand_block_move (operands))
9383     DONE;
9384   else
9385     FAIL;
9386 }")
9387
9388 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
9389 ;; register allocator doesn't have a clue about allocating 8 word registers.
9390 ;; rD/rS = r5 is preferred, efficient form.
9391 (define_expand "movstrsi_8reg"
9392   [(parallel [(set (match_operand 0 "" "")
9393                    (match_operand 1 "" ""))
9394               (use (match_operand 2 "" ""))
9395               (use (match_operand 3 "" ""))
9396               (clobber (reg:SI  5))
9397               (clobber (reg:SI  6))
9398               (clobber (reg:SI  7))
9399               (clobber (reg:SI  8))
9400               (clobber (reg:SI  9))
9401               (clobber (reg:SI 10))
9402               (clobber (reg:SI 11))
9403               (clobber (reg:SI 12))
9404               (clobber (match_scratch:SI 4 ""))])]
9405   "TARGET_STRING"
9406   "")
9407
9408 (define_insn ""
9409   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9410         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9411    (use (match_operand:SI 2 "immediate_operand" "i"))
9412    (use (match_operand:SI 3 "immediate_operand" "i"))
9413    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9414    (clobber (reg:SI  6))
9415    (clobber (reg:SI  7))
9416    (clobber (reg:SI  8))
9417    (clobber (reg:SI  9))
9418    (clobber (reg:SI 10))
9419    (clobber (reg:SI 11))
9420    (clobber (reg:SI 12))
9421    (clobber (match_scratch:SI 5 "=q"))]
9422   "TARGET_STRING && TARGET_POWER
9423    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9424        || INTVAL (operands[2]) == 0)
9425    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9426    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9427    && REGNO (operands[4]) == 5"
9428   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9429   [(set_attr "type" "load")
9430    (set_attr "length" "8")])
9431
9432 (define_insn ""
9433   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9434         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9435    (use (match_operand:SI 2 "immediate_operand" "i"))
9436    (use (match_operand:SI 3 "immediate_operand" "i"))
9437    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9438    (clobber (reg:SI  6))
9439    (clobber (reg:SI  7))
9440    (clobber (reg:SI  8))
9441    (clobber (reg:SI  9))
9442    (clobber (reg:SI 10))
9443    (clobber (reg:SI 11))
9444    (clobber (reg:SI 12))
9445    (clobber (match_scratch:SI 5 "X"))]
9446   "TARGET_STRING && ! TARGET_POWER
9447    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9448        || INTVAL (operands[2]) == 0)
9449    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9450    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9451    && REGNO (operands[4]) == 5"
9452   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9453   [(set_attr "type" "load")
9454    (set_attr "length" "8")])
9455
9456 (define_insn ""
9457   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9458         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9459    (use (match_operand:SI 2 "immediate_operand" "i"))
9460    (use (match_operand:SI 3 "immediate_operand" "i"))
9461    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9462    (clobber (reg:SI  6))
9463    (clobber (reg:SI  7))
9464    (clobber (reg:SI  8))
9465    (clobber (reg:SI  9))
9466    (clobber (reg:SI 10))
9467    (clobber (reg:SI 11))
9468    (clobber (reg:SI 12))
9469    (clobber (match_scratch:SI 5 "X"))]
9470   "TARGET_STRING && TARGET_POWERPC64
9471    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32)
9472        || INTVAL (operands[2]) == 0)
9473    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
9474    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
9475    && REGNO (operands[4]) == 5"
9476   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9477   [(set_attr "type" "load")
9478    (set_attr "length" "8")])
9479
9480 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
9481 ;; register allocator doesn't have a clue about allocating 6 word registers.
9482 ;; rD/rS = r5 is preferred, efficient form.
9483 (define_expand "movstrsi_6reg"
9484   [(parallel [(set (match_operand 0 "" "")
9485                    (match_operand 1 "" ""))
9486               (use (match_operand 2 "" ""))
9487               (use (match_operand 3 "" ""))
9488               (clobber (reg:SI  5))
9489               (clobber (reg:SI  6))
9490               (clobber (reg:SI  7))
9491               (clobber (reg:SI  8))
9492               (clobber (reg:SI  9))
9493               (clobber (reg:SI 10))
9494               (clobber (match_scratch:SI 4 ""))])]
9495   "TARGET_STRING"
9496   "")
9497
9498 (define_insn ""
9499   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9500         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9501    (use (match_operand:SI 2 "immediate_operand" "i"))
9502    (use (match_operand:SI 3 "immediate_operand" "i"))
9503    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9504    (clobber (reg:SI  6))
9505    (clobber (reg:SI  7))
9506    (clobber (reg:SI  8))
9507    (clobber (reg:SI  9))
9508    (clobber (reg:SI 10))
9509    (clobber (match_scratch:SI 5 "=q"))]
9510   "TARGET_STRING && TARGET_POWER
9511    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
9512    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9513    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9514    && REGNO (operands[4]) == 5"
9515   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9516   [(set_attr "type" "load")
9517    (set_attr "length" "8")])
9518
9519 (define_insn ""
9520   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9521         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9522    (use (match_operand:SI 2 "immediate_operand" "i"))
9523    (use (match_operand:SI 3 "immediate_operand" "i"))
9524    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9525    (clobber (reg:SI  6))
9526    (clobber (reg:SI  7))
9527    (clobber (reg:SI  8))
9528    (clobber (reg:SI  9))
9529    (clobber (reg:SI 10))
9530    (clobber (match_scratch:SI 5 "X"))]
9531   "TARGET_STRING && ! TARGET_POWER
9532    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9533    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9534    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9535    && REGNO (operands[4]) == 5"
9536   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9537   [(set_attr "type" "load")
9538    (set_attr "length" "8")])
9539
9540 (define_insn ""
9541   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9542         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9543    (use (match_operand:SI 2 "immediate_operand" "i"))
9544    (use (match_operand:SI 3 "immediate_operand" "i"))
9545    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9546    (clobber (reg:SI  6))
9547    (clobber (reg:SI  7))
9548    (clobber (reg:SI  8))
9549    (clobber (reg:SI  9))
9550    (clobber (reg:SI 10))
9551    (clobber (match_scratch:SI 5 "X"))]
9552   "TARGET_STRING && TARGET_POWERPC64
9553    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
9554    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 10)
9555    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 10)
9556    && REGNO (operands[4]) == 5"
9557   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9558   [(set_attr "type" "load")
9559    (set_attr "length" "8")])
9560
9561 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill
9562 ;; problems with TImode.
9563 ;; rD/rS = r5 is preferred, efficient form.
9564 (define_expand "movstrsi_4reg"
9565   [(parallel [(set (match_operand 0 "" "")
9566                    (match_operand 1 "" ""))
9567               (use (match_operand 2 "" ""))
9568               (use (match_operand 3 "" ""))
9569               (clobber (reg:SI 5))
9570               (clobber (reg:SI 6))
9571               (clobber (reg:SI 7))
9572               (clobber (reg:SI 8))
9573               (clobber (match_scratch:SI 4 ""))])]
9574   "TARGET_STRING"
9575   "")
9576
9577 (define_insn ""
9578   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9579         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9580    (use (match_operand:SI 2 "immediate_operand" "i"))
9581    (use (match_operand:SI 3 "immediate_operand" "i"))
9582    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9583    (clobber (reg:SI 6))
9584    (clobber (reg:SI 7))
9585    (clobber (reg:SI 8))
9586    (clobber (match_scratch:SI 5 "=q"))]
9587   "TARGET_STRING && TARGET_POWER
9588    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9589    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9590    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9591    && REGNO (operands[4]) == 5"
9592   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9593   [(set_attr "type" "load")
9594    (set_attr "length" "8")])
9595
9596 (define_insn ""
9597   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9598         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9599    (use (match_operand:SI 2 "immediate_operand" "i"))
9600    (use (match_operand:SI 3 "immediate_operand" "i"))
9601    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9602    (clobber (reg:SI 6))
9603    (clobber (reg:SI 7))
9604    (clobber (reg:SI 8))
9605    (clobber (match_scratch:SI 5 "X"))]
9606   "TARGET_STRING && ! TARGET_POWER
9607    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9608    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9609    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9610    && REGNO (operands[4]) == 5"
9611   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9612   [(set_attr "type" "load")
9613    (set_attr "length" "8")])
9614
9615 (define_insn ""
9616   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9617         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9618    (use (match_operand:SI 2 "immediate_operand" "i"))
9619    (use (match_operand:SI 3 "immediate_operand" "i"))
9620    (clobber (match_operand:SI 4 "gpc_reg_operand" "=r"))
9621    (clobber (reg:SI 6))
9622    (clobber (reg:SI 7))
9623    (clobber (reg:SI 8))
9624    (clobber (match_scratch:SI 5 "X"))]
9625   "TARGET_STRING && TARGET_POWERPC64
9626    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
9627    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 8)
9628    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 8)
9629    && REGNO (operands[4]) == 5"
9630   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9631   [(set_attr "type" "load")
9632    (set_attr "length" "8")])
9633
9634 ;; Move up to 8 bytes at a time.
9635 (define_expand "movstrsi_2reg"
9636   [(parallel [(set (match_operand 0 "" "")
9637                    (match_operand 1 "" ""))
9638               (use (match_operand 2 "" ""))
9639               (use (match_operand 3 "" ""))
9640               (clobber (match_scratch:DI 4 ""))
9641               (clobber (match_scratch:SI 5 ""))])]
9642   "TARGET_STRING && ! TARGET_POWERPC64"
9643   "")
9644
9645 (define_insn ""
9646   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9647         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9648    (use (match_operand:SI 2 "immediate_operand" "i"))
9649    (use (match_operand:SI 3 "immediate_operand" "i"))
9650    (clobber (match_scratch:DI 4 "=&r"))
9651    (clobber (match_scratch:SI 5 "=q"))]
9652   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
9653    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9654   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9655   [(set_attr "type" "load")
9656    (set_attr "length" "8")])
9657
9658 (define_insn ""
9659   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9660         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9661    (use (match_operand:SI 2 "immediate_operand" "i"))
9662    (use (match_operand:SI 3 "immediate_operand" "i"))
9663    (clobber (match_scratch:DI 4 "=&r"))
9664    (clobber (match_scratch:SI 5 "X"))]
9665   "TARGET_STRING && ! TARGET_POWER && ! TARGET_POWERPC64
9666    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
9667   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9668   [(set_attr "type" "load")
9669    (set_attr "length" "8")])
9670
9671 ;; Move up to 4 bytes at a time.
9672 (define_expand "movstrsi_1reg"
9673   [(parallel [(set (match_operand 0 "" "")
9674                    (match_operand 1 "" ""))
9675               (use (match_operand 2 "" ""))
9676               (use (match_operand 3 "" ""))
9677               (clobber (match_scratch:SI 4 ""))
9678               (clobber (match_scratch:SI 5 ""))])]
9679   "TARGET_STRING"
9680   "")
9681
9682 (define_insn ""
9683   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9684         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9685    (use (match_operand:SI 2 "immediate_operand" "i"))
9686    (use (match_operand:SI 3 "immediate_operand" "i"))
9687    (clobber (match_scratch:SI 4 "=&r"))
9688    (clobber (match_scratch:SI 5 "=q"))]
9689   "TARGET_STRING && TARGET_POWER
9690    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9691   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9692   [(set_attr "type" "load")
9693    (set_attr "length" "8")])
9694
9695 (define_insn ""
9696   [(set (mem:BLK (match_operand:SI 0 "gpc_reg_operand" "b"))
9697         (mem:BLK (match_operand:SI 1 "gpc_reg_operand" "b")))
9698    (use (match_operand:SI 2 "immediate_operand" "i"))
9699    (use (match_operand:SI 3 "immediate_operand" "i"))
9700    (clobber (match_scratch:SI 4 "=&r"))
9701    (clobber (match_scratch:SI 5 "X"))]
9702   "TARGET_STRING && ! TARGET_POWER
9703    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9704   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9705   [(set_attr "type" "load")
9706    (set_attr "length" "8")])
9707
9708 (define_insn ""
9709   [(set (mem:BLK (match_operand:DI 0 "gpc_reg_operand" "b"))
9710         (mem:BLK (match_operand:DI 1 "gpc_reg_operand" "b")))
9711    (use (match_operand:SI 2 "immediate_operand" "i"))
9712    (use (match_operand:SI 3 "immediate_operand" "i"))
9713    (clobber (match_scratch:SI 4 "=&r"))
9714    (clobber (match_scratch:SI 5 "X"))]
9715   "TARGET_STRING && TARGET_POWERPC64
9716    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
9717   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
9718   [(set_attr "type" "load")
9719    (set_attr "length" "8")])
9720
9721 \f
9722 ;; Define insns that do load or store with update.  Some of these we can
9723 ;; get by using pre-decrement or pre-increment, but the hardware can also
9724 ;; do cases where the increment is not the size of the object.
9725 ;;
9726 ;; In all these cases, we use operands 0 and 1 for the register being
9727 ;; incremented because those are the operands that local-alloc will
9728 ;; tie and these are the pair most likely to be tieable (and the ones
9729 ;; that will benefit the most).
9730
9731 (define_insn "*movdi_update1"
9732   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
9733         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9734                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I"))))
9735    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9736         (plus:DI (match_dup 1) (match_dup 2)))]
9737   "TARGET_POWERPC64 && TARGET_UPDATE"
9738   "@
9739    ldux %3,%0,%2
9740    ldu %3,%2(%0)"
9741   [(set_attr "type" "load")])
9742
9743 (define_insn "*movdi_update2"
9744   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
9745         (sign_extend:DI
9746          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
9747                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
9748    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
9749         (plus:DI (match_dup 1) (match_dup 2)))]
9750   "TARGET_POWERPC64"
9751   "lwaux %3,%0,%2"
9752   [(set_attr "type" "load")])
9753
9754 (define_insn "movdi_update"
9755   [(set (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
9756                          (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I")))
9757         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
9758    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
9759         (plus:DI (match_dup 1) (match_dup 2)))]
9760   "TARGET_POWERPC64 && TARGET_UPDATE"
9761   "@
9762    stdux %3,%0,%2
9763    stdu %3,%2(%0)"
9764   [(set_attr "type" "store")])
9765
9766 (define_insn "*movsi_update1"
9767   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9768         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9769                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9770    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9771         (plus:SI (match_dup 1) (match_dup 2)))]
9772   ""
9773   "@
9774    {lux|lwzux} %3,%0,%2
9775    {lu|lwzu} %3,%2(%0)"
9776   [(set_attr "type" "load")])
9777
9778 (define_insn "movsi_update"
9779   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9780                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9781         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
9782    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9783         (plus:SI (match_dup 1) (match_dup 2)))]
9784   "TARGET_UPDATE"
9785   "@
9786    {stux|stwux} %3,%0,%2
9787    {stu|stwu} %3,%2(%0)"
9788   [(set_attr "type" "store")])
9789
9790 (define_insn "*movhi_update"
9791   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
9792         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9793                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9794    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9795         (plus:SI (match_dup 1) (match_dup 2)))]
9796   "TARGET_UPDATE"
9797   "@
9798    lhzux %3,%0,%2
9799    lhzu %3,%2(%0)"
9800   [(set_attr "type" "load")])
9801
9802 (define_insn "*movhi_update2"
9803   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9804         (zero_extend:SI
9805          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9806                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9807    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9808         (plus:SI (match_dup 1) (match_dup 2)))]
9809   "TARGET_UPDATE"
9810   "@
9811    lhzux %3,%0,%2
9812    lhzu %3,%2(%0)"
9813   [(set_attr "type" "load")])
9814
9815 (define_insn "*movhi_update3"
9816   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9817         (sign_extend:SI
9818          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9819                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9820    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9821         (plus:SI (match_dup 1) (match_dup 2)))]
9822   "TARGET_UPDATE"
9823   "@
9824    lhaux %3,%0,%2
9825    lhau %3,%2(%0)"
9826   [(set_attr "type" "load")])
9827
9828 (define_insn "*movhi_update4"
9829   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9830                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9831         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
9832    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9833         (plus:SI (match_dup 1) (match_dup 2)))]
9834   "TARGET_UPDATE"
9835   "@
9836    sthux %3,%0,%2
9837    sthu %3,%2(%0)"
9838   [(set_attr "type" "store")])
9839
9840 (define_insn "*movqi_update1"
9841   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
9842         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9843                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9844    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9845         (plus:SI (match_dup 1) (match_dup 2)))]
9846   "TARGET_UPDATE"
9847   "@
9848    lbzux %3,%0,%2
9849    lbzu %3,%2(%0)"
9850   [(set_attr "type" "load")])
9851
9852 (define_insn "*movqi_update2"
9853   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
9854         (zero_extend:SI
9855          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9856                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
9857    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9858         (plus:SI (match_dup 1) (match_dup 2)))]
9859   "TARGET_UPDATE"
9860   "@
9861    lbzux %3,%0,%2
9862    lbzu %3,%2(%0)"
9863   [(set_attr "type" "load")])
9864
9865 (define_insn "*movqi_update3"
9866   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9867                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9868         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
9869    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9870         (plus:SI (match_dup 1) (match_dup 2)))]
9871   "TARGET_UPDATE"
9872   "@
9873    stbux %3,%0,%2
9874    stbu %3,%2(%0)"
9875   [(set_attr "type" "store")])
9876
9877 (define_insn "*movsf_update1"
9878   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
9879         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9880                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9881    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9882         (plus:SI (match_dup 1) (match_dup 2)))]
9883   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9884   "@
9885    lfsux %3,%0,%2
9886    lfsu %3,%2(%0)"
9887   [(set_attr "type" "fpload")])
9888
9889 (define_insn "*movsf_update2"
9890   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9891                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9892         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
9893    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9894         (plus:SI (match_dup 1) (match_dup 2)))]
9895   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9896   "@
9897    stfsux %3,%0,%2
9898    stfsu %3,%2(%0)"
9899   [(set_attr "type" "fpstore")])
9900
9901 (define_insn "*movsf_update3"
9902   [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
9903         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9904                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9905    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9906         (plus:SI (match_dup 1) (match_dup 2)))]
9907   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9908   "@
9909    {lux|lwzux} %3,%0,%2
9910    {lu|lwzu} %3,%2(%0)"
9911   [(set_attr "type" "load")])
9912
9913 (define_insn "*movsf_update4"
9914   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9915                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9916         (match_operand:SF 3 "gpc_reg_operand" "r,r"))
9917    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9918         (plus:SI (match_dup 1) (match_dup 2)))]
9919   "(TARGET_SOFT_FLOAT || !TARGET_FPRS) && TARGET_UPDATE"
9920   "@
9921    {stux|stwux} %3,%0,%2
9922    {stu|stwu} %3,%2(%0)"
9923   [(set_attr "type" "store")])
9924
9925 (define_insn "*movdf_update1"
9926   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
9927         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9928                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
9929    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9930         (plus:SI (match_dup 1) (match_dup 2)))]
9931   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9932   "@
9933    lfdux %3,%0,%2
9934    lfdu %3,%2(%0)"
9935   [(set_attr "type" "fpload")])
9936
9937 (define_insn "*movdf_update2"
9938   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
9939                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
9940         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
9941    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
9942         (plus:SI (match_dup 1) (match_dup 2)))]
9943   "TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_UPDATE"
9944   "@
9945    stfdux %3,%0,%2
9946    stfdu %3,%2(%0)"
9947   [(set_attr "type" "fpstore")])
9948
9949 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
9950
9951 (define_peephole
9952   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
9953         (match_operand:DF 1 "memory_operand" ""))
9954    (set (match_operand:DF 2 "gpc_reg_operand" "=f")
9955         (match_operand:DF 3 "memory_operand" ""))]
9956   "TARGET_POWER2
9957    && TARGET_HARD_FLOAT && TARGET_FPRS
9958    && registers_ok_for_quad_peep (operands[0], operands[2])
9959    && ! MEM_VOLATILE_P (operands[1]) && ! MEM_VOLATILE_P (operands[3])
9960    && addrs_ok_for_quad_peep (XEXP (operands[1], 0), XEXP (operands[3], 0))"
9961   "lfq%U1%X1 %0,%1")
9962
9963 (define_peephole
9964   [(set (match_operand:DF 0 "memory_operand" "")
9965         (match_operand:DF 1 "gpc_reg_operand" "f"))
9966    (set (match_operand:DF 2 "memory_operand" "")
9967         (match_operand:DF 3 "gpc_reg_operand" "f"))]
9968   "TARGET_POWER2
9969    && TARGET_HARD_FLOAT && TARGET_FPRS
9970    && registers_ok_for_quad_peep (operands[1], operands[3])
9971    && ! MEM_VOLATILE_P (operands[0]) && ! MEM_VOLATILE_P (operands[2])
9972    && addrs_ok_for_quad_peep (XEXP (operands[0], 0), XEXP (operands[2], 0))"
9973   "stfq%U0%X0 %1,%0")
9974 \f
9975 ;; Next come insns related to the calling sequence.
9976 ;;
9977 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
9978 ;; We move the back-chain and decrement the stack pointer.
9979
9980 (define_expand "allocate_stack"
9981   [(set (match_operand 0 "gpc_reg_operand" "=r")
9982         (minus (reg 1) (match_operand 1 "reg_or_short_operand" "")))
9983    (set (reg 1)
9984         (minus (reg 1) (match_dup 1)))]
9985   ""
9986   "
9987 { rtx chain = gen_reg_rtx (Pmode);
9988   rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
9989   rtx neg_op0;
9990
9991   emit_move_insn (chain, stack_bot);
9992
9993   /* Check stack bounds if necessary.  */
9994   if (current_function_limit_stack)
9995     {
9996       rtx available;
9997       available = expand_binop (Pmode, sub_optab, 
9998                                 stack_pointer_rtx, stack_limit_rtx,
9999                                 NULL_RTX, 1, OPTAB_WIDEN);
10000       emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
10001     }
10002
10003   if (GET_CODE (operands[1]) != CONST_INT
10004       || INTVAL (operands[1]) < -32767
10005       || INTVAL (operands[1]) > 32768)
10006     {
10007       neg_op0 = gen_reg_rtx (Pmode);
10008       if (TARGET_32BIT)
10009         emit_insn (gen_negsi2 (neg_op0, operands[1]));
10010       else
10011         emit_insn (gen_negdi2 (neg_op0, operands[1]));
10012     }
10013   else
10014     neg_op0 = GEN_INT (- INTVAL (operands[1]));
10015
10016   if (TARGET_UPDATE)
10017     emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update : gen_movdi_update))
10018                 (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
10019
10020   else
10021     {
10022       emit_insn ((* ((TARGET_32BIT) ? gen_addsi3 : gen_adddi3))
10023                  (stack_pointer_rtx, stack_pointer_rtx, neg_op0));
10024       emit_move_insn (gen_rtx_MEM (Pmode, stack_pointer_rtx), chain);
10025     }
10026
10027   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
10028   DONE;
10029 }")
10030
10031 ;; These patterns say how to save and restore the stack pointer.  We need not
10032 ;; save the stack pointer at function level since we are careful to
10033 ;; preserve the backchain.  At block level, we have to restore the backchain
10034 ;; when we restore the stack pointer.
10035 ;;
10036 ;; For nonlocal gotos, we must save both the stack pointer and its
10037 ;; backchain and restore both.  Note that in the nonlocal case, the
10038 ;; save area is a memory location.
10039
10040 (define_expand "save_stack_function"
10041   [(match_operand 0 "any_operand" "")
10042    (match_operand 1 "any_operand" "")]
10043   ""
10044   "DONE;")
10045
10046 (define_expand "restore_stack_function"
10047   [(match_operand 0 "any_operand" "")
10048    (match_operand 1 "any_operand" "")]
10049   ""
10050   "DONE;")
10051
10052 (define_expand "restore_stack_block"
10053   [(use (match_operand 0 "register_operand" ""))
10054    (set (match_dup 2) (match_dup 3))
10055    (set (match_dup 0) (match_operand 1 "register_operand" ""))
10056    (set (match_dup 3) (match_dup 2))]
10057   ""
10058   "
10059 {
10060   operands[2] = gen_reg_rtx (Pmode);
10061   operands[3] = gen_rtx_MEM (Pmode, operands[0]);
10062 }")
10063
10064 (define_expand "save_stack_nonlocal"
10065   [(match_operand 0 "memory_operand" "")
10066    (match_operand 1 "register_operand" "")]
10067   ""
10068   "
10069 {
10070   rtx temp = gen_reg_rtx (Pmode);
10071
10072   /* Copy the backchain to the first word, sp to the second.  */
10073   emit_move_insn (temp, gen_rtx_MEM (Pmode, operands[1]));
10074   emit_move_insn (operand_subword (operands[0], 0, 0,
10075                                    (TARGET_32BIT ? DImode : TImode)),
10076                   temp);
10077   emit_move_insn (operand_subword (operands[0], 1, 0, (TARGET_32BIT ? DImode : TImode)),
10078                   operands[1]);
10079   DONE;
10080 }")
10081
10082 (define_expand "restore_stack_nonlocal"
10083   [(match_operand 0 "register_operand" "")
10084    (match_operand 1 "memory_operand" "")]
10085   ""
10086   "
10087 {
10088   rtx temp = gen_reg_rtx (Pmode);
10089
10090   /* Restore the backchain from the first word, sp from the second.  */
10091   emit_move_insn (temp,
10092                   operand_subword (operands[1], 0, 0, (TARGET_32BIT ? DImode : TImode)));
10093   emit_move_insn (operands[0],
10094                   operand_subword (operands[1], 1, 0,
10095                                    (TARGET_32BIT ? DImode : TImode)));
10096   emit_move_insn (gen_rtx_MEM (Pmode, operands[0]), temp);
10097   DONE;
10098 }")
10099 \f
10100 ;; TOC register handling.
10101
10102 ;; Code to initialize the TOC register...
10103
10104 (define_insn "load_toc_aix_si"
10105   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10106                    (unspec:SI [(const_int 0)] 7))
10107               (use (reg:SI 2))])]
10108   "DEFAULT_ABI == ABI_AIX && TARGET_32BIT"
10109   "*
10110 {
10111   char buf[30];
10112   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10113   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10114   operands[2] = gen_rtx_REG (Pmode, 2);
10115   return \"{l|lwz} %0,%1(%2)\";
10116 }"
10117   [(set_attr "type" "load")])
10118
10119 (define_insn "load_toc_aix_di"
10120   [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
10121                    (unspec:DI [(const_int 0)] 7))
10122               (use (reg:DI 2))])]
10123   "DEFAULT_ABI == ABI_AIX && TARGET_64BIT"
10124   "*
10125 {
10126   char buf[30];
10127 #ifdef TARGET_RELOCATABLE
10128   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\",
10129                                !TARGET_MINIMAL_TOC || TARGET_RELOCATABLE);
10130 #else
10131   ASM_GENERATE_INTERNAL_LABEL (buf, \"LCTOC\", 1);
10132 #endif
10133   if (TARGET_ELF)
10134     strcat (buf, \"@toc\");
10135   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
10136   operands[2] = gen_rtx_REG (Pmode, 2);
10137   return \"ld %0,%1(%2)\";
10138 }"
10139   [(set_attr "type" "load")])
10140
10141 (define_insn "load_toc_v4_pic_si"
10142   [(set (match_operand:SI 0 "register_operand" "=l")
10143         (unspec:SI [(const_int 0)] 7))]
10144   "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
10145   "bl _GLOBAL_OFFSET_TABLE_@local-4"
10146   [(set_attr "type" "branch")
10147    (set_attr "length" "4")])
10148
10149 (define_insn "load_toc_v4_PIC_1"
10150   [(set (match_operand:SI 0 "register_operand" "=l")
10151         (match_operand:SI 1 "immediate_operand" "s"))
10152    (unspec [(match_dup 1)] 7)]
10153   "TARGET_ELF && flag_pic == 2"
10154   "bl %1\\n%1:"
10155   [(set_attr "type" "branch")
10156    (set_attr "length" "4")])
10157
10158 (define_insn "load_toc_v4_PIC_1b"
10159   [(set (match_operand:SI 0 "register_operand" "=l")
10160         (match_operand:SI 1 "immediate_operand" "s"))
10161    (unspec [(match_dup 1) (match_operand 2 "immediate_operand" "s")] 6)]
10162   "TARGET_ELF && flag_pic == 2"
10163   "bl %1\\n\\t.long %2-%1+4\\n%1:"
10164   [(set_attr "type" "branch")
10165    (set_attr "length" "8")])
10166
10167 (define_insn "load_toc_v4_PIC_2"
10168   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
10169         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
10170                    (minus:SI (match_operand:SI 2 "immediate_operand" "s")
10171                              (match_operand:SI 3 "immediate_operand" "s")))))]
10172   "TARGET_ELF && flag_pic == 2"
10173   "{l|lwz} %0,%2-%3(%1)"
10174   [(set_attr "type" "load")])
10175
10176 (define_insn "load_macho_picbase"
10177   [(set (match_operand:SI 0 "register_operand" "=l")
10178         (unspec:SI [(const_int 0)] 15))]
10179   "(DEFAULT_ABI == ABI_DARWIN) && flag_pic"
10180   "*
10181 {
10182 #if TARGET_MACHO
10183   char *picbase = machopic_function_base_name ();
10184   operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (picbase, -1));
10185 #endif
10186   return \"bcl 20,31,%1\\n%1:\";
10187 }"
10188   [(set_attr "type" "branch")
10189    (set_attr "length" "4")])
10190
10191 ;; If the TOC is shared over a translation unit, as happens with all
10192 ;; the kinds of PIC that we support, we need to restore the TOC
10193 ;; pointer only when jumping over units of translation.
10194
10195 (define_expand "builtin_setjmp_receiver"
10196   [(use (label_ref (match_operand 0 "" "")))]
10197   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10198    || (TARGET_TOC && TARGET_MINIMAL_TOC)"
10199   "
10200 {
10201   rs6000_emit_load_toc_table (FALSE);
10202   DONE;
10203 }")
10204 \f
10205 ;; A function pointer under AIX is a pointer to a data area whose first word
10206 ;; contains the actual address of the function, whose second word contains a
10207 ;; pointer to its TOC, and whose third word contains a value to place in the
10208 ;; static chain register (r11).  Note that if we load the static chain, our
10209 ;; "trampoline" need not have any executable code.
10210
10211 (define_expand "call_indirect_aix32"
10212   [(set (match_dup 2)
10213         (mem:SI (match_operand:SI 0 "gpc_reg_operand" "")))
10214    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10215         (reg:SI 2))
10216    (set (reg:SI 2)
10217         (mem:SI (plus:SI (match_dup 0)
10218                          (const_int 4))))
10219    (set (reg:SI 11)
10220         (mem:SI (plus:SI (match_dup 0)
10221                          (const_int 8))))
10222    (parallel [(call (mem:SI (match_dup 2))
10223                     (match_operand 1 "" ""))
10224               (use (reg:SI 2))
10225               (use (reg:SI 11))
10226               (set (reg:SI 2)
10227                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10228               (clobber (scratch:SI))])]
10229   "TARGET_32BIT"
10230   "
10231 { operands[2] = gen_reg_rtx (SImode); }")
10232
10233 (define_expand "call_indirect_aix64"
10234   [(set (match_dup 2)
10235         (mem:DI (match_operand:DI 0 "gpc_reg_operand" "")))
10236    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10237         (reg:DI 2))
10238    (set (reg:DI 2)
10239         (mem:DI (plus:DI (match_dup 0)
10240                          (const_int 8))))
10241    (set (reg:DI 11)
10242         (mem:DI (plus:DI (match_dup 0)
10243                          (const_int 16))))
10244    (parallel [(call (mem:SI (match_dup 2))
10245                     (match_operand 1 "" ""))
10246               (use (reg:DI 2))
10247               (use (reg:DI 11))
10248               (set (reg:DI 2)
10249                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10250               (clobber (scratch:SI))])]
10251   "TARGET_64BIT"
10252   "
10253 { operands[2] = gen_reg_rtx (DImode); }")
10254
10255 (define_expand "call_value_indirect_aix32"
10256   [(set (match_dup 3)
10257         (mem:SI (match_operand:SI 1 "gpc_reg_operand" "")))
10258    (set (mem:SI (plus:SI (reg:SI 1) (const_int 20)))
10259         (reg:SI 2))
10260    (set (reg:SI 2)
10261         (mem:SI (plus:SI (match_dup 1)
10262                          (const_int 4))))
10263    (set (reg:SI 11)
10264         (mem:SI (plus:SI (match_dup 1)
10265                          (const_int 8))))
10266    (parallel [(set (match_operand 0 "" "")
10267                    (call (mem:SI (match_dup 3))
10268                          (match_operand 2 "" "")))
10269               (use (reg:SI 2))
10270               (use (reg:SI 11))
10271               (set (reg:SI 2)
10272                    (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10273               (clobber (scratch:SI))])]
10274   "TARGET_32BIT"
10275   "
10276 { operands[3] = gen_reg_rtx (SImode); }")
10277
10278 (define_expand "call_value_indirect_aix64"
10279   [(set (match_dup 3)
10280         (mem:DI (match_operand:DI 1 "gpc_reg_operand" "")))
10281    (set (mem:DI (plus:DI (reg:DI 1) (const_int 40)))
10282         (reg:DI 2))
10283    (set (reg:DI 2)
10284         (mem:DI (plus:DI (match_dup 1)
10285                          (const_int 8))))
10286    (set (reg:DI 11)
10287         (mem:DI (plus:DI (match_dup 1)
10288                          (const_int 16))))
10289    (parallel [(set (match_operand 0 "" "")
10290                    (call (mem:SI (match_dup 3))
10291                          (match_operand 2 "" "")))
10292               (use (reg:DI 2))
10293               (use (reg:DI 11))
10294               (set (reg:DI 2)
10295                    (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10296               (clobber (scratch:SI))])]
10297   "TARGET_64BIT"
10298   "
10299 { operands[3] = gen_reg_rtx (DImode); }")
10300
10301 ;; Now the definitions for the call and call_value insns
10302 (define_expand "call"
10303   [(parallel [(call (mem:SI (match_operand 0 "address_operand" ""))
10304                     (match_operand 1 "" ""))
10305               (use (match_operand 2 "" ""))
10306               (clobber (scratch:SI))])]
10307   ""
10308   "
10309 {
10310 #if TARGET_MACHO
10311   if (flag_pic)
10312     operands[0] = machopic_indirect_call_target (operands[0]);
10313 #endif
10314
10315   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
10316     abort ();
10317
10318   operands[0] = XEXP (operands[0], 0);
10319
10320   if (GET_CODE (operands[0]) != SYMBOL_REF
10321       || (INTVAL (operands[2]) & CALL_LONG) != 0)
10322     {
10323       if (INTVAL (operands[2]) & CALL_LONG)
10324         operands[0] = rs6000_longcall_ref (operands[0]);
10325
10326       if (DEFAULT_ABI == ABI_V4
10327           || DEFAULT_ABI == ABI_AIX_NODESC
10328           || DEFAULT_ABI == ABI_DARWIN)
10329         operands[0] = force_reg (Pmode, operands[0]);
10330
10331       else if (DEFAULT_ABI == ABI_AIX)
10332         {
10333           /* AIX function pointers are really pointers to a three word
10334              area.  */
10335           emit_call_insn (TARGET_32BIT
10336                           ? gen_call_indirect_aix32 (force_reg (SImode,
10337                                                                 operands[0]),
10338                                                      operands[1])
10339                           : gen_call_indirect_aix64 (force_reg (DImode,
10340                                                                 operands[0]),
10341                                                      operands[1]));
10342           DONE;
10343         }
10344       else
10345         abort ();
10346     }
10347 }")
10348
10349 (define_expand "call_value"
10350   [(parallel [(set (match_operand 0 "" "")
10351                    (call (mem:SI (match_operand 1 "address_operand" ""))
10352                          (match_operand 2 "" "")))
10353               (use (match_operand 3 "" ""))
10354               (clobber (scratch:SI))])]
10355   ""
10356   "
10357 {
10358 #if TARGET_MACHO
10359   if (flag_pic)
10360     operands[1] = machopic_indirect_call_target (operands[1]);
10361 #endif
10362
10363   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
10364     abort ();
10365
10366   operands[1] = XEXP (operands[1], 0);
10367
10368   if (GET_CODE (operands[1]) != SYMBOL_REF
10369       || (INTVAL (operands[3]) & CALL_LONG) != 0)
10370     {
10371       if (INTVAL (operands[3]) & CALL_LONG)
10372         operands[1] = rs6000_longcall_ref (operands[1]);
10373
10374       if (DEFAULT_ABI == ABI_V4
10375           || DEFAULT_ABI == ABI_AIX_NODESC
10376           || DEFAULT_ABI == ABI_DARWIN)
10377         operands[0] = force_reg (Pmode, operands[0]);
10378
10379       else if (DEFAULT_ABI == ABI_AIX)
10380         {
10381           /* AIX function pointers are really pointers to a three word
10382              area.  */
10383           emit_call_insn (TARGET_32BIT
10384                           ? gen_call_value_indirect_aix32 (operands[0],
10385                                                            force_reg (SImode,
10386                                                                       operands[1]),
10387                                                            operands[2])
10388                           : gen_call_value_indirect_aix64 (operands[0],
10389                                                            force_reg (DImode,
10390                                                                       operands[1]),
10391                                                            operands[2]));
10392           DONE;
10393         }
10394       else
10395         abort ();
10396     }
10397 }")
10398
10399 ;; Call to function in current module.  No TOC pointer reload needed.
10400 ;; Operand2 is non-zero if we are using the V.4 calling sequence and
10401 ;; either the function was not prototyped, or it was prototyped as a
10402 ;; variable argument function.  It is > 0 if FP registers were passed
10403 ;; and < 0 if they were not.
10404
10405 (define_insn "*call_local32"
10406   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
10407          (match_operand 1 "" "g,g"))
10408    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10409    (clobber (match_scratch:SI 3 "=l,l"))]
10410   "(INTVAL (operands[2]) & CALL_LONG) == 0"
10411   "*
10412 {
10413   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10414     output_asm_insn (\"crxor 6,6,6\", operands);
10415
10416   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10417     output_asm_insn (\"creqv 6,6,6\", operands);
10418
10419   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10420 }"
10421   [(set_attr "type" "branch")
10422    (set_attr "length" "4,8")])
10423
10424 (define_insn "*call_local64"
10425   [(call (mem:SI (match_operand:DI 0 "current_file_function_operand" "s,s"))
10426          (match_operand 1 "" "g,g"))
10427    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10428    (clobber (match_scratch:SI 3 "=l,l"))]
10429   "TARGET_64BIT && (INTVAL (operands[2]) & CALL_LONG) == 0"
10430   "*
10431 {
10432   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10433     output_asm_insn (\"crxor 6,6,6\", operands);
10434
10435   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10436     output_asm_insn (\"creqv 6,6,6\", operands);
10437
10438   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z0@local\" : \"bl %z0\";
10439 }"
10440   [(set_attr "type" "branch")
10441    (set_attr "length" "4,8")])
10442
10443 (define_insn "*call_value_local32"
10444   [(set (match_operand 0 "" "")
10445         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
10446               (match_operand 2 "" "g,g")))
10447    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10448    (clobber (match_scratch:SI 4 "=l,l"))]
10449   "(INTVAL (operands[3]) & CALL_LONG) == 0"
10450   "*
10451 {
10452   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10453     output_asm_insn (\"crxor 6,6,6\", operands);
10454
10455   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10456     output_asm_insn (\"creqv 6,6,6\", operands);
10457
10458   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10459 }"
10460   [(set_attr "type" "branch")
10461    (set_attr "length" "4,8")])
10462
10463
10464 (define_insn "*call_value_local64"
10465   [(set (match_operand 0 "" "")
10466         (call (mem:SI (match_operand:DI 1 "current_file_function_operand" "s,s"))
10467               (match_operand 2 "" "g,g")))
10468    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10469    (clobber (match_scratch:SI 4 "=l,l"))]
10470   "TARGET_64BIT && (INTVAL (operands[3]) & CALL_LONG) == 0"
10471   "*
10472 {
10473   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10474     output_asm_insn (\"crxor 6,6,6\", operands);
10475
10476   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10477     output_asm_insn (\"creqv 6,6,6\", operands);
10478
10479   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"bl %z1@local\" : \"bl %z1\";
10480 }"
10481   [(set_attr "type" "branch")
10482    (set_attr "length" "4,8")])
10483
10484 ;; Call to function which may be in another module.  Restore the TOC
10485 ;; pointer (r2) after the call unless this is System V.
10486 ;; Operand2 is non-zero if we are using the V.4 calling sequence and
10487 ;; either the function was not prototyped, or it was prototyped as a
10488 ;; variable argument function.  It is > 0 if FP registers were passed
10489 ;; and < 0 if they were not.
10490
10491 (define_insn "*call_indirect_nonlocal_aix32"
10492   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl"))
10493          (match_operand 1 "" "g"))
10494    (use (reg:SI 2))
10495    (use (reg:SI 11))
10496    (set (reg:SI 2)
10497         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10498    (clobber (match_scratch:SI 2 "=l"))]
10499   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10500   "b%T0l\;{l|lwz} 2,20(1)"
10501   [(set_attr "type" "jmpreg")
10502    (set_attr "length" "8")])
10503
10504 (define_insn "*call_nonlocal_aix32"
10505   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s"))
10506          (match_operand 1 "" "g"))
10507    (use (match_operand:SI 2 "immediate_operand" "O"))
10508    (clobber (match_scratch:SI 3 "=l"))]
10509   "TARGET_32BIT
10510    && DEFAULT_ABI == ABI_AIX
10511    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10512   "bl %z0\;%."
10513   [(set_attr "type" "branch")
10514    (set_attr "length" "8")])
10515
10516 (define_insn "*call_indirect_nonlocal_aix64"
10517   [(call (mem:SI (match_operand:DI 0 "register_operand" "cl"))
10518          (match_operand 1 "" "g"))
10519    (use (reg:DI 2))
10520    (use (reg:DI 11))
10521    (set (reg:DI 2)
10522         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10523    (clobber (match_scratch:SI 2 "=l"))]
10524   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10525   "b%T0l\;ld 2,40(1)"
10526   [(set_attr "type" "jmpreg")
10527    (set_attr "length" "8")])
10528
10529 (define_insn "*call_nonlocal_aix64"
10530   [(call (mem:SI (match_operand:DI 0 "symbol_ref_operand" "s"))
10531          (match_operand 1 "" "g"))
10532    (use (match_operand:SI 2 "immediate_operand" "O"))
10533    (clobber (match_scratch:SI 3 "=l"))]
10534   "TARGET_64BIT 
10535    && DEFAULT_ABI == ABI_AIX
10536    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10537   "bl %z0\;%."
10538   [(set_attr "type" "branch")
10539    (set_attr "length" "8")])
10540
10541 (define_insn "*call_value_indirect_nonlocal_aix32"
10542   [(set (match_operand 0 "" "")
10543         (call (mem:SI (match_operand:SI 1 "register_operand" "cl"))
10544               (match_operand 2 "" "g")))
10545    (use (reg:SI 2))
10546    (use (reg:SI 11))
10547    (set (reg:SI 2)
10548         (mem:SI (plus:SI (reg:SI 1) (const_int 20))))
10549    (clobber (match_scratch:SI 3 "=l"))]
10550   "TARGET_32BIT && DEFAULT_ABI == ABI_AIX"
10551   "b%T1l\;{l|lwz} 2,20(1)"
10552   [(set_attr "type" "jmpreg")
10553    (set_attr "length" "8")])
10554
10555 (define_insn "*call_value_nonlocal_aix32"
10556   [(set (match_operand 0 "" "")
10557         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s"))
10558               (match_operand 2 "" "g")))
10559    (use (match_operand:SI 3 "immediate_operand" "O"))
10560    (clobber (match_scratch:SI 4 "=l"))]
10561   "TARGET_32BIT
10562    && DEFAULT_ABI == ABI_AIX
10563    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10564   "bl %z1\;%."
10565   [(set_attr "type" "branch")
10566    (set_attr "length" "8")])
10567
10568 (define_insn "*call_value_indirect_nonlocal_aix64"
10569   [(set (match_operand 0 "" "")
10570         (call (mem:SI (match_operand:DI 1 "register_operand" "cl"))
10571               (match_operand 2 "" "g")))
10572    (use (reg:DI 2))
10573    (use (reg:DI 11))
10574    (set (reg:DI 2)
10575         (mem:DI (plus:DI (reg:DI 1) (const_int 40))))
10576    (clobber (match_scratch:SI 3 "=l"))]
10577   "TARGET_64BIT && DEFAULT_ABI == ABI_AIX"
10578   "b%T1l\;ld 2,40(1)"
10579   [(set_attr "type" "jmpreg")
10580    (set_attr "length" "8")])
10581
10582 (define_insn "*call_value_nonlocal_aix64"
10583   [(set (match_operand 0 "" "")
10584         (call (mem:SI (match_operand:DI 1 "symbol_ref_operand" "s"))
10585               (match_operand 2 "" "g")))
10586    (use (match_operand:SI 3 "immediate_operand" "O"))
10587    (clobber (match_scratch:SI 4 "=l"))]
10588   "TARGET_64BIT 
10589    && DEFAULT_ABI == ABI_AIX
10590    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10591   "bl %z1\;%."
10592   [(set_attr "type" "branch")
10593    (set_attr "length" "8")])
10594
10595 ;; A function pointer under System V is just a normal pointer
10596 ;; operands[0] is the function pointer
10597 ;; operands[1] is the stack size to clean up
10598 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
10599 ;; which indicates how to set cr1
10600
10601 (define_insn "*call_indirect_nonlocal_sysv"
10602   [(call (mem:SI (match_operand:SI 0 "register_operand" "cl,cl"))
10603          (match_operand 1 "" "g,g"))
10604    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10605    (clobber (match_scratch:SI 3 "=l,l"))]
10606   "DEFAULT_ABI == ABI_AIX_NODESC
10607    || DEFAULT_ABI == ABI_V4
10608    || DEFAULT_ABI == ABI_DARWIN"
10609 {
10610   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10611     output_asm_insn ("crxor 6,6,6", operands);
10612
10613   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10614     output_asm_insn ("creqv 6,6,6", operands);
10615
10616   return "b%T0l";
10617 }
10618   [(set_attr "type" "jmpreg,jmpreg")
10619    (set_attr "length" "4,8")])
10620
10621 (define_insn "*call_nonlocal_sysv"
10622   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" "s,s"))
10623          (match_operand 1 "" "g,g"))
10624    (use (match_operand:SI 2 "immediate_operand" "O,n"))
10625    (clobber (match_scratch:SI 3 "=l,l"))]
10626   "(DEFAULT_ABI == ABI_AIX_NODESC
10627     || DEFAULT_ABI == ABI_V4
10628     || DEFAULT_ABI == ABI_DARWIN)
10629    && (INTVAL (operands[2]) & CALL_LONG) == 0"
10630 {
10631   if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
10632     output_asm_insn ("crxor 6,6,6", operands);
10633
10634   else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
10635     output_asm_insn ("creqv 6,6,6", operands);
10636
10637   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z0@plt" : "bl %z0";
10638 }
10639   [(set_attr "type" "branch,branch")
10640    (set_attr "length" "4,8")])
10641
10642 (define_insn "*call_value_indirect_nonlocal_sysv"
10643   [(set (match_operand 0 "" "")
10644         (call (mem:SI (match_operand:SI 1 "register_operand" "cl,cl"))
10645               (match_operand 2 "" "g,g")))
10646    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10647    (clobber (match_scratch:SI 4 "=l,l"))]
10648   "DEFAULT_ABI == ABI_AIX_NODESC
10649    || DEFAULT_ABI == ABI_V4
10650    || DEFAULT_ABI == ABI_DARWIN"
10651 {
10652   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10653     output_asm_insn ("crxor 6,6,6", operands);
10654
10655   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10656     output_asm_insn ("creqv 6,6,6", operands);
10657
10658   return "b%T1l";
10659 }
10660   [(set_attr "type" "jmpreg,jmpreg")
10661    (set_attr "length" "4,8")])
10662
10663 (define_insn "*call_value_nonlocal_sysv"
10664   [(set (match_operand 0 "" "")
10665         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" "s,s"))
10666               (match_operand 2 "" "g,g")))
10667    (use (match_operand:SI 3 "immediate_operand" "O,n"))
10668    (clobber (match_scratch:SI 4 "=l,l"))]
10669   "(DEFAULT_ABI == ABI_AIX_NODESC
10670     || DEFAULT_ABI == ABI_V4
10671     || DEFAULT_ABI == ABI_DARWIN)
10672    && (INTVAL (operands[3]) & CALL_LONG) == 0"
10673 {
10674   if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
10675     output_asm_insn ("crxor 6,6,6", operands);
10676
10677   else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
10678     output_asm_insn ("creqv 6,6,6", operands);
10679
10680   return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z1@plt" : "bl %z1";
10681 }
10682   [(set_attr "type" "branch,branch")
10683    (set_attr "length" "4,8")])
10684
10685 ;; Call subroutine returning any type.
10686 (define_expand "untyped_call"
10687   [(parallel [(call (match_operand 0 "" "")
10688                     (const_int 0))
10689               (match_operand 1 "" "")
10690               (match_operand 2 "" "")])]
10691   ""
10692   "
10693 {
10694   int i;
10695
10696   emit_call_insn (GEN_CALL (operands[0], const0_rtx, const0_rtx, const0_rtx));
10697
10698   for (i = 0; i < XVECLEN (operands[2], 0); i++)
10699     {
10700       rtx set = XVECEXP (operands[2], 0, i);
10701       emit_move_insn (SET_DEST (set), SET_SRC (set));
10702     }
10703
10704   /* The optimizer does not know that the call sets the function value
10705      registers we stored in the result block.  We avoid problems by
10706      claiming that all hard registers are used and clobbered at this
10707      point.  */
10708   emit_insn (gen_blockage ());
10709
10710   DONE;
10711 }")
10712
10713 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
10714 ;; all of memory.  This blocks insns from being moved across this point.
10715
10716 (define_insn "blockage"
10717   [(unspec_volatile [(const_int 0)] 0)]
10718   ""
10719   "")
10720 \f
10721 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
10722 ;; signed & unsigned, and one type of branch.
10723 ;;
10724 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
10725 ;; insns, and branches.  We store the operands of compares until we see
10726 ;; how it is used.
10727 (define_expand "cmpsi"
10728   [(set (cc0)
10729         (compare (match_operand:SI 0 "gpc_reg_operand" "")
10730                  (match_operand:SI 1 "reg_or_short_operand" "")))]
10731   ""
10732   "
10733 {
10734   /* Take care of the possibility that operands[1] might be negative but
10735      this might be a logical operation.  That insn doesn't exist.  */
10736   if (GET_CODE (operands[1]) == CONST_INT
10737       && INTVAL (operands[1]) < 0)
10738     operands[1] = force_reg (SImode, operands[1]);
10739
10740   rs6000_compare_op0 = operands[0];
10741   rs6000_compare_op1 = operands[1];
10742   rs6000_compare_fp_p = 0;
10743   DONE;
10744 }")
10745
10746 (define_expand "cmpdi"
10747   [(set (cc0)
10748         (compare (match_operand:DI 0 "gpc_reg_operand" "")
10749                  (match_operand:DI 1 "reg_or_short_operand" "")))]
10750   "TARGET_POWERPC64"
10751   "
10752 {
10753   /* Take care of the possibility that operands[1] might be negative but
10754      this might be a logical operation.  That insn doesn't exist.  */
10755   if (GET_CODE (operands[1]) == CONST_INT
10756       && INTVAL (operands[1]) < 0)
10757     operands[1] = force_reg (DImode, operands[1]);
10758
10759   rs6000_compare_op0 = operands[0];
10760   rs6000_compare_op1 = operands[1];
10761   rs6000_compare_fp_p = 0;
10762   DONE;
10763 }")
10764
10765 (define_expand "cmpsf"
10766   [(set (cc0) (compare (match_operand:SF 0 "gpc_reg_operand" "")
10767                        (match_operand:SF 1 "gpc_reg_operand" "")))]
10768   "TARGET_HARD_FLOAT"
10769   "
10770 {
10771   rs6000_compare_op0 = operands[0];
10772   rs6000_compare_op1 = operands[1];
10773   rs6000_compare_fp_p = 1;
10774   DONE;
10775 }")
10776
10777 (define_expand "cmpdf"
10778   [(set (cc0) (compare (match_operand:DF 0 "gpc_reg_operand" "")
10779                        (match_operand:DF 1 "gpc_reg_operand" "")))]
10780   "TARGET_HARD_FLOAT && TARGET_FPRS"
10781   "
10782 {
10783   rs6000_compare_op0 = operands[0];
10784   rs6000_compare_op1 = operands[1];
10785   rs6000_compare_fp_p = 1;
10786   DONE;
10787 }")
10788
10789 (define_expand "cmptf"
10790   [(set (cc0) (compare (match_operand:TF 0 "gpc_reg_operand" "")
10791                        (match_operand:TF 1 "gpc_reg_operand" "")))]
10792   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT
10793    && TARGET_FPRS && TARGET_LONG_DOUBLE_128"
10794   "
10795 {
10796   rs6000_compare_op0 = operands[0];
10797   rs6000_compare_op1 = operands[1];
10798   rs6000_compare_fp_p = 1;
10799   DONE;
10800 }")
10801
10802 (define_expand "beq"
10803   [(use (match_operand 0 "" ""))]
10804   ""
10805   "{ rs6000_emit_cbranch (EQ, operands[0]); DONE; }")
10806
10807 (define_expand "bne"
10808   [(use (match_operand 0 "" ""))]
10809   ""
10810   "{ rs6000_emit_cbranch (NE, operands[0]); DONE; }")
10811
10812 (define_expand "bge"
10813   [(use (match_operand 0 "" ""))]
10814   ""
10815   "{ rs6000_emit_cbranch (GE, operands[0]); DONE; }")
10816
10817 (define_expand "bgt"
10818   [(use (match_operand 0 "" ""))]
10819   ""
10820   "{ rs6000_emit_cbranch (GT, operands[0]); DONE; }")
10821
10822 (define_expand "ble"
10823   [(use (match_operand 0 "" ""))]
10824   ""
10825   "{ rs6000_emit_cbranch (LE, operands[0]); DONE; }")
10826
10827 (define_expand "blt"
10828   [(use (match_operand 0 "" ""))]
10829   ""
10830   "{ rs6000_emit_cbranch (LT, operands[0]); DONE; }")
10831
10832 (define_expand "bgeu"
10833   [(use (match_operand 0 "" ""))]
10834   ""
10835   "{ rs6000_emit_cbranch (GEU, operands[0]); DONE; }")
10836
10837 (define_expand "bgtu"
10838   [(use (match_operand 0 "" ""))]
10839   ""
10840   "{ rs6000_emit_cbranch (GTU, operands[0]); DONE; }")
10841
10842 (define_expand "bleu"
10843   [(use (match_operand 0 "" ""))]
10844   ""
10845   "{ rs6000_emit_cbranch (LEU, operands[0]); DONE; }")
10846
10847 (define_expand "bltu"
10848   [(use (match_operand 0 "" ""))]
10849   ""
10850   "{ rs6000_emit_cbranch (LTU, operands[0]); DONE; }")
10851
10852 (define_expand "bunordered"
10853   [(use (match_operand 0 "" ""))]
10854   ""
10855   "{ rs6000_emit_cbranch (UNORDERED, operands[0]); DONE; }")
10856
10857 (define_expand "bordered"
10858   [(use (match_operand 0 "" ""))]
10859   ""
10860   "{ rs6000_emit_cbranch (ORDERED, operands[0]); DONE; }")
10861
10862 (define_expand "buneq"
10863   [(use (match_operand 0 "" ""))]
10864   ""
10865   "{ rs6000_emit_cbranch (UNEQ, operands[0]); DONE; }")
10866
10867 (define_expand "bunge"
10868   [(use (match_operand 0 "" ""))]
10869   ""
10870   "{ rs6000_emit_cbranch (UNGE, operands[0]); DONE; }")
10871
10872 (define_expand "bungt"
10873   [(use (match_operand 0 "" ""))]
10874   ""
10875   "{ rs6000_emit_cbranch (UNGT, operands[0]); DONE; }")
10876
10877 (define_expand "bunle"
10878   [(use (match_operand 0 "" ""))]
10879   ""
10880   "{ rs6000_emit_cbranch (UNLE, operands[0]); DONE; }")
10881
10882 (define_expand "bunlt"
10883   [(use (match_operand 0 "" ""))]
10884   ""
10885   "{ rs6000_emit_cbranch (UNLT, operands[0]); DONE; }")
10886
10887 (define_expand "bltgt"
10888   [(use (match_operand 0 "" ""))]
10889   ""
10890   "{ rs6000_emit_cbranch (LTGT, operands[0]); DONE; }")
10891
10892 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
10893 ;; For SEQ, likewise, except that comparisons with zero should be done
10894 ;; with an scc insns.  However, due to the order that combine see the
10895 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
10896 ;; the cases we don't want to handle.
10897 (define_expand "seq"
10898   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10899   ""
10900   "{ rs6000_emit_sCOND (EQ, operands[0]); DONE; }")
10901
10902 (define_expand "sne"
10903   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10904   ""
10905   "
10906
10907   if (! rs6000_compare_fp_p)
10908     FAIL;
10909
10910   rs6000_emit_sCOND (NE, operands[0]); 
10911   DONE;
10912 }")
10913
10914 ;; A > 0 is best done using the portable sequence, so fail in that case.
10915 (define_expand "sgt"
10916   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10917   ""
10918   "
10919 {
10920   if (! rs6000_compare_fp_p
10921       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
10922     FAIL;
10923
10924   rs6000_emit_sCOND (GT, operands[0]); 
10925   DONE;
10926 }")
10927
10928 ;; A < 0 is best done in the portable way for A an integer.
10929 (define_expand "slt"
10930   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10931   ""
10932   "
10933 {
10934   if (! rs6000_compare_fp_p 
10935       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
10936     FAIL;
10937
10938   rs6000_emit_sCOND (LT, operands[0]); 
10939   DONE;
10940 }")
10941
10942 ;; A >= 0 is best done the portable way for A an integer.
10943 (define_expand "sge"
10944   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10945   ""
10946   "
10947 {
10948   if (! rs6000_compare_fp_p
10949       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
10950     FAIL;
10951
10952   rs6000_emit_sCOND (GE, operands[0]);
10953   DONE;
10954 }")
10955
10956 ;; A <= 0 is best done the portable way for A an integer.
10957 (define_expand "sle"
10958   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10959   ""
10960   "
10961 {
10962   if (! rs6000_compare_fp_p
10963       && (! TARGET_POWER || rs6000_compare_op1 == const0_rtx))
10964     FAIL;
10965
10966   rs6000_emit_sCOND (LE, operands[0]); 
10967   DONE;
10968 }")
10969
10970 (define_expand "sgtu"
10971   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10972   ""
10973   "{ rs6000_emit_sCOND (GTU, operands[0]); DONE; }")
10974
10975 (define_expand "sltu"
10976   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10977   ""
10978   "{ rs6000_emit_sCOND (LTU, operands[0]); DONE; }")
10979
10980 (define_expand "sgeu"
10981   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10982   ""
10983   "{ rs6000_emit_sCOND (GEU, operands[0]); DONE; }")
10984
10985 (define_expand "sleu"
10986   [(clobber (match_operand:SI 0 "gpc_reg_operand" ""))]
10987   ""
10988   "{ rs6000_emit_sCOND (LEU, operands[0]); DONE; }")
10989 \f
10990 ;; Here are the actual compare insns.
10991 (define_insn "*cmpsi_internal1"
10992   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
10993         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
10994                     (match_operand:SI 2 "reg_or_short_operand" "rI")))]
10995   ""
10996   "{cmp%I2|cmpw%I2} %0,%1,%2"
10997   [(set_attr "type" "compare")])
10998
10999 (define_insn "*cmpdi_internal1"
11000   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
11001         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "r")
11002                     (match_operand:DI 2 "reg_or_short_operand" "rI")))]
11003   "TARGET_POWERPC64"
11004   "cmpd%I2 %0,%1,%2"
11005   [(set_attr "type" "compare")])
11006
11007 ;; If we are comparing a register for equality with a large constant,
11008 ;; we can do this with an XOR followed by a compare.  But we need a scratch
11009 ;; register for the result of the XOR.
11010
11011 (define_split
11012   [(set (match_operand:CC 0 "cc_reg_operand" "")
11013         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11014                     (match_operand:SI 2 "non_short_cint_operand" "")))
11015    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
11016   "find_single_use (operands[0], insn, 0)
11017    && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
11018        || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
11019   [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
11020    (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
11021   "
11022 {
11023   /* Get the constant we are comparing against, C,  and see what it looks like
11024      sign-extended to 16 bits.  Then see what constant could be XOR'ed
11025      with C to get the sign-extended value.  */
11026
11027   HOST_WIDE_INT c = INTVAL (operands[2]);
11028   HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000;
11029   HOST_WIDE_INT xorv = c ^ sextc;
11030
11031   operands[4] = GEN_INT (xorv);
11032   operands[5] = GEN_INT (sextc);
11033 }")
11034
11035 (define_insn "*cmpsi_internal2"
11036   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11037         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11038                        (match_operand:SI 2 "reg_or_u_short_operand" "rK")))]
11039   ""
11040   "{cmpl%I2|cmplw%I2} %0,%1,%b2"
11041   [(set_attr "type" "compare")])
11042
11043 (define_insn "*cmpdi_internal2"
11044   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
11045         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
11046                        (match_operand:DI 2 "reg_or_u_short_operand" "rK")))]
11047   ""
11048   "cmpld%I2 %0,%1,%b2"
11049   [(set_attr "type" "compare")])
11050
11051 ;; The following two insns don't exist as single insns, but if we provide
11052 ;; them, we can swap an add and compare, which will enable us to overlap more
11053 ;; of the required delay between a compare and branch.  We generate code for
11054 ;; them by splitting.
11055
11056 (define_insn ""
11057   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
11058         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
11059                     (match_operand:SI 2 "short_cint_operand" "i")))
11060    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11061         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11062   ""
11063   "#"
11064   [(set_attr "length" "8")])
11065
11066 (define_insn ""
11067   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
11068         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
11069                        (match_operand:SI 2 "u_short_cint_operand" "i")))
11070    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
11071         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
11072   ""
11073   "#"
11074   [(set_attr "length" "8")])
11075
11076 (define_split
11077   [(set (match_operand:CC 3 "cc_reg_operand" "")
11078         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
11079                     (match_operand:SI 2 "short_cint_operand" "")))
11080    (set (match_operand:SI 0 "gpc_reg_operand" "")
11081         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11082   ""
11083   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
11084    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11085
11086 (define_split
11087   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
11088         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
11089                        (match_operand:SI 2 "u_short_cint_operand" "")))
11090    (set (match_operand:SI 0 "gpc_reg_operand" "")
11091         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
11092   ""
11093   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
11094    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
11095
11096 (define_insn "*cmpsf_internal1"
11097   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11098         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
11099                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
11100   "TARGET_HARD_FLOAT && TARGET_FPRS"
11101   "fcmpu %0,%1,%2"
11102   [(set_attr "type" "fpcompare")])
11103
11104 (define_insn "*cmpdf_internal1"
11105   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11106         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
11107                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
11108   "TARGET_HARD_FLOAT && TARGET_FPRS"
11109   "fcmpu %0,%1,%2"
11110   [(set_attr "type" "fpcompare")])
11111
11112 ;; Only need to compare second words if first words equal
11113 (define_insn "*cmptf_internal1"
11114   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
11115         (compare:CCFP (match_operand:TF 1 "gpc_reg_operand" "f")
11116                       (match_operand:TF 2 "gpc_reg_operand" "f")))]
11117   "DEFAULT_ABI == ABI_AIX && TARGET_HARD_FLOAT && TARGET_FPRS
11118    && TARGET_LONG_DOUBLE_128"
11119   "fcmpu %0,%1,%2\;bne %0,$+4\;fcmpu %0,%L1,%L2"
11120   [(set_attr "type" "fpcompare")
11121    (set_attr "length" "12")])
11122 \f
11123 ;; Now we have the scc insns.  We can do some combinations because of the
11124 ;; way the machine works.
11125 ;;
11126 ;; Note that this is probably faster if we can put an insn between the
11127 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
11128 ;; cases the insns below which don't use an intermediate CR field will
11129 ;; be used instead.
11130 (define_insn ""
11131   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11132         (match_operator:SI 1 "scc_comparison_operator"
11133                            [(match_operand 2 "cc_reg_operand" "y")
11134                             (const_int 0)]))]
11135   ""
11136   "%D1mfcr %0\;{rlinm|rlwinm} %0,%0,%J1,1"
11137   [(set_attr "type" "cr_logical")
11138    (set_attr "length" "12")])
11139
11140 ;; Same as above, but get the OV/ORDERED bit.
11141 (define_insn "move_from_CR_ov_bit"
11142   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11143         (unspec:SI [(match_operand 1 "cc_reg_operand" "y")] 724))]
11144   "TARGET_ISEL"
11145   "%D1mfcr %0\;{rlinm|rlwinm} %0,%0,%t1,1"
11146   [(set_attr "length" "12")])
11147
11148 (define_insn ""
11149   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11150         (match_operator:DI 1 "scc_comparison_operator"
11151                            [(match_operand 2 "cc_reg_operand" "y")
11152                             (const_int 0)]))]
11153   "TARGET_POWERPC64"
11154   "%D1mfcr %0\;{rlinm|rlwinm} %0,%0,%J1,1"
11155   [(set_attr "type" "cr_logical")
11156    (set_attr "length" "12")])
11157
11158 (define_insn ""
11159   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11160         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11161                                        [(match_operand 2 "cc_reg_operand" "y,y")
11162                                         (const_int 0)])
11163                     (const_int 0)))
11164    (set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
11165         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11166   "! TARGET_POWERPC64"
11167   "@
11168    %D1mfcr %3\;{rlinm.|rlwinm.} %3,%3,%J1,1
11169    #"
11170   [(set_attr "type" "delayed_compare")
11171    (set_attr "length" "12,16")])
11172
11173 (define_split
11174   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11175         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
11176                                        [(match_operand 2 "cc_reg_operand" "")
11177                                         (const_int 0)])
11178                     (const_int 0)))
11179    (set (match_operand:SI 3 "gpc_reg_operand" "")
11180         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
11181   "! TARGET_POWERPC64 && reload_completed"
11182   [(set (match_dup 3)
11183         (match_op_dup 1 [(match_dup 2) (const_int 0)]))
11184    (set (match_dup 0)
11185         (compare:CC (match_dup 3)
11186                     (const_int 0)))]
11187   "")
11188
11189 (define_insn ""
11190   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11191         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11192                                       [(match_operand 2 "cc_reg_operand" "y")
11193                                        (const_int 0)])
11194                    (match_operand:SI 3 "const_int_operand" "n")))]
11195   ""
11196   "*
11197 {
11198   int is_bit = ccr_bit (operands[1], 1);
11199   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11200   int count;
11201
11202   if (is_bit >= put_bit)
11203     count = is_bit - put_bit;
11204   else
11205     count = 32 - (put_bit - is_bit);
11206
11207   operands[4] = GEN_INT (count);
11208   operands[5] = GEN_INT (put_bit);
11209
11210   return \"%D1mfcr %0\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
11211 }"
11212   [(set_attr "type" "cr_logical")
11213    (set_attr "length" "12")])
11214
11215 (define_insn ""
11216   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11217         (compare:CC
11218          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11219                                        [(match_operand 2 "cc_reg_operand" "y,y")
11220                                         (const_int 0)])
11221                     (match_operand:SI 3 "const_int_operand" "n,n"))
11222          (const_int 0)))
11223    (set (match_operand:SI 4 "gpc_reg_operand" "=r,r")
11224         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11225                    (match_dup 3)))]
11226   ""
11227   "*
11228 {
11229   int is_bit = ccr_bit (operands[1], 1);
11230   int put_bit = 31 - (INTVAL (operands[3]) & 31);
11231   int count;
11232
11233   /* Force split for non-cc0 compare.  */
11234   if (which_alternative == 1)
11235      return \"#\";
11236
11237   if (is_bit >= put_bit)
11238     count = is_bit - put_bit;
11239   else
11240     count = 32 - (put_bit - is_bit);
11241
11242   operands[5] = GEN_INT (count);
11243   operands[6] = GEN_INT (put_bit);
11244
11245   return \"%D1mfcr %4\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
11246 }"
11247   [(set_attr "type" "delayed_compare")
11248    (set_attr "length" "12,16")])
11249
11250 (define_split
11251   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11252         (compare:CC
11253          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
11254                                        [(match_operand 2 "cc_reg_operand" "")
11255                                         (const_int 0)])
11256                     (match_operand:SI 3 "const_int_operand" ""))
11257          (const_int 0)))
11258    (set (match_operand:SI 4 "gpc_reg_operand" "")
11259         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11260                    (match_dup 3)))]
11261   "reload_completed"
11262   [(set (match_dup 4)
11263         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
11264                    (match_dup 3)))
11265    (set (match_dup 0)
11266         (compare:CC (match_dup 4)
11267                     (const_int 0)))]
11268   "")
11269
11270 ;; There is a 3 cycle delay between consecutive mfcr instructions
11271 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
11272
11273 (define_peephole
11274   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11275         (match_operator:SI 1 "scc_comparison_operator"
11276                            [(match_operand 2 "cc_reg_operand" "y")
11277                             (const_int 0)]))
11278    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
11279         (match_operator:SI 4 "scc_comparison_operator"
11280                            [(match_operand 5 "cc_reg_operand" "y")
11281                             (const_int 0)]))]
11282   "REGNO (operands[2]) != REGNO (operands[5])"
11283   "%D1%D4mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11284   [(set_attr "type" "cr_logical")
11285    (set_attr "length" "20")])
11286
11287 (define_peephole
11288   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11289         (match_operator:DI 1 "scc_comparison_operator"
11290                            [(match_operand 2 "cc_reg_operand" "y")
11291                             (const_int 0)]))
11292    (set (match_operand:DI 3 "gpc_reg_operand" "=r")
11293         (match_operator:DI 4 "scc_comparison_operator"
11294                            [(match_operand 5 "cc_reg_operand" "y")
11295                             (const_int 0)]))]
11296   "TARGET_POWERPC64 && REGNO (operands[2]) != REGNO (operands[5])"
11297   "%D1%D4mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
11298   [(set_attr "type" "cr_logical")
11299    (set_attr "length" "20")])
11300
11301 ;; There are some scc insns that can be done directly, without a compare.
11302 ;; These are faster because they don't involve the communications between
11303 ;; the FXU and branch units.   In fact, we will be replacing all of the
11304 ;; integer scc insns here or in the portable methods in emit_store_flag.
11305 ;;
11306 ;; Also support (neg (scc ..)) since that construct is used to replace
11307 ;; branches, (plus (scc ..) ..) since that construct is common and
11308 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
11309 ;; cases where it is no more expensive than (neg (scc ..)).
11310
11311 ;; Have reload force a constant into a register for the simple insns that
11312 ;; otherwise won't accept constants.  We do this because it is faster than
11313 ;; the cmp/mfcr sequence we would otherwise generate.
11314
11315 (define_insn ""
11316   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11317         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11318                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I")))
11319    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
11320   "! TARGET_POWERPC64"
11321   "@
11322    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11323    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
11324    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11325    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
11326    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
11327   [(set_attr "length" "12,8,12,12,12")])
11328
11329 (define_insn ""
11330   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r")
11331         (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r")
11332                (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I")))
11333    (clobber (match_scratch:DI 3 "=r,&r,r,r,r"))]
11334   "TARGET_POWERPC64"
11335   "@
11336    xor %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0
11337    subfic %3,%1,0\;adde %0,%3,%1
11338    xori %0,%1,%b2\;subfic %3,%0,0\;adde %0,%3,%0
11339    xoris %0,%1,%u2\;subfic %3,%0,0\;adde %0,%3,%0
11340    subfic %0,%1,%2\;subfic %3,%0,0\;adde %0,%3,%0"
11341   [(set_attr "length" "12,8,12,12,12")])
11342
11343 (define_insn ""
11344   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11345         (compare:CC
11346          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11347                 (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11348          (const_int 0)))
11349    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11350         (eq:SI (match_dup 1) (match_dup 2)))
11351    (clobber (match_scratch:SI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11352   "! TARGET_POWERPC64"
11353   "@
11354    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11355    {sfi|subfic} %3,%1,0\;{ae.|adde.} %0,%3,%1
11356    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11357    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11358    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
11359    #
11360    #
11361    #
11362    #
11363    #"
11364   [(set_attr "type" "compare")
11365    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11366
11367 (define_split
11368   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11369         (compare:CC
11370          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11371                 (match_operand:SI 2 "reg_or_cint_operand" ""))
11372          (const_int 0)))
11373    (set (match_operand:SI 0 "gpc_reg_operand" "")
11374         (eq:SI (match_dup 1) (match_dup 2)))
11375    (clobber (match_scratch:SI 3 ""))]
11376   "! TARGET_POWERPC64 && reload_completed"
11377   [(parallel [(set (match_dup 0)
11378         (eq:SI (match_dup 1) (match_dup 2)))
11379    (clobber (match_dup 3))])
11380    (set (match_dup 4)
11381         (compare:CC (match_dup 0)
11382                     (const_int 0)))]
11383   "")
11384
11385 (define_insn ""
11386   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11387         (compare:CC
11388          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11389                 (match_operand:DI 2 "reg_or_cint_operand" "r,O,K,J,I,r,O,K,J,I"))
11390          (const_int 0)))
11391    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r,r,r")
11392         (eq:DI (match_dup 1) (match_dup 2)))
11393    (clobber (match_scratch:DI 3 "=r,&r,r,r,r,r,&r,r,r,r"))]
11394   "TARGET_POWERPC64"
11395   "@
11396    xor %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11397    subfic %3,%1,0\;adde. %0,%3,%1
11398    xori %0,%1,%b2\;subfic %3,%0,0\;adde. %0,%3,%0
11399    xoris %0,%1,%u2\;subfic %3,%0,0\;adde. %0,%3,%0
11400    subfic %0,%1,%2\;subfic %3,%0,0\;adde. %0,%3,%0
11401    #
11402    #
11403    #
11404    #
11405    #"
11406   [(set_attr "type" "compare")
11407    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11408
11409 (define_split
11410   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11411         (compare:CC
11412          (eq:DI (match_operand:DI 1 "gpc_reg_operand" "")
11413                 (match_operand:DI 2 "reg_or_cint_operand" ""))
11414          (const_int 0)))
11415    (set (match_operand:DI 0 "gpc_reg_operand" "")
11416         (eq:DI (match_dup 1) (match_dup 2)))
11417    (clobber (match_scratch:DI 3 ""))]
11418   "TARGET_POWERPC64 && reload_completed"
11419   [(parallel [(set (match_dup 0)
11420         (eq:DI (match_dup 1) (match_dup 2)))
11421    (clobber (match_dup 3))])
11422    (set (match_dup 4)
11423         (compare:CC (match_dup 0)
11424                     (const_int 0)))]
11425   "")
11426
11427 ;; We have insns of the form shown by the first define_insn below.  If
11428 ;; there is something inside the comparison operation, we must split it.
11429 (define_split
11430   [(set (match_operand:SI 0 "gpc_reg_operand" "")
11431         (plus:SI (match_operator 1 "comparison_operator"
11432                                  [(match_operand:SI 2 "" "")
11433                                   (match_operand:SI 3
11434                                                     "reg_or_cint_operand" "")])
11435                  (match_operand:SI 4 "gpc_reg_operand" "")))
11436    (clobber (match_operand:SI 5 "register_operand" ""))]
11437   "! gpc_reg_operand (operands[2], SImode)"
11438   [(set (match_dup 5) (match_dup 2))
11439    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
11440                                (match_dup 4)))])
11441
11442 (define_insn ""
11443   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r")
11444         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11445                         (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))
11446                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))]
11447   "! TARGET_POWERPC64"
11448   "@
11449    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11450    {sfi|subfic} %0,%1,0\;{aze|addze} %0,%3
11451    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11452    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11453    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
11454   [(set_attr "length" "12,8,12,12,12")])
11455
11456 (define_insn ""
11457   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11458         (compare:CC
11459          (plus:SI
11460           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11461                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11462           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11463          (const_int 0)))
11464    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r"))]
11465   "! TARGET_POWERPC64"
11466   "@
11467    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11468    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
11469    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11470    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11471    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11472    #
11473    #
11474    #
11475    #
11476    #"
11477   [(set_attr "type" "compare")
11478    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11479
11480 (define_split
11481   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11482         (compare:CC
11483          (plus:SI
11484           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11485                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11486           (match_operand:SI 3 "gpc_reg_operand" ""))
11487          (const_int 0)))
11488    (clobber (match_scratch:SI 4 ""))]
11489   "! TARGET_POWERPC64 && reload_completed"
11490   [(set (match_dup 4)
11491         (plus:SI (eq:SI (match_dup 1)
11492                  (match_dup 2))
11493           (match_dup 3)))
11494    (set (match_dup 0)
11495         (compare:CC (match_dup 4)
11496                     (const_int 0)))]
11497   "")
11498
11499 (define_insn ""
11500   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x,?y,?y,?y,?y,?y")
11501         (compare:CC
11502          (plus:SI
11503           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r,r,r")
11504                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I,r,O,K,L,I"))
11505           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r,r,r,r,r,r"))
11506          (const_int 0)))
11507    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r,&r,&r,&r,&r,&r,&r")
11508         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11509   "! TARGET_POWERPC64"
11510   "@
11511    xor %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11512    {sfi|subfic} %0,%1,0\;{aze.|addze.} %0,%3
11513    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11514    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11515    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11516    #
11517    #
11518    #
11519    #
11520    #"
11521   [(set_attr "type" "compare")
11522    (set_attr "length" "12,8,12,12,12,16,12,16,16,16")])
11523
11524 (define_split
11525   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11526         (compare:CC
11527          (plus:SI
11528           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "")
11529                  (match_operand:SI 2 "reg_or_cint_operand" ""))
11530           (match_operand:SI 3 "gpc_reg_operand" ""))
11531          (const_int 0)))
11532    (set (match_operand:SI 0 "gpc_reg_operand" "")
11533         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11534   "! TARGET_POWERPC64 && reload_completed"
11535   [(set (match_dup 0)
11536         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
11537    (set (match_dup 4)
11538         (compare:CC (match_dup 0)
11539                     (const_int 0)))]
11540   "")
11541
11542 (define_insn ""
11543   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
11544         (neg:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
11545                        (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,L,I"))))]
11546   "! TARGET_POWERPC64"
11547   "@
11548    xor %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11549    {ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0
11550    {xoril|xori} %0,%1,%b2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11551    {xoriu|xoris} %0,%1,%u2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11552    {sfi|subfic} %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
11553    [(set_attr "length" "12,8,12,12,12")])
11554
11555 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
11556 ;; since it nabs/sr is just as fast.
11557 (define_insn "*ne0"
11558   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
11559         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11560                      (const_int 31)))
11561    (clobber (match_scratch:SI 2 "=&r"))]
11562   "! TARGET_POWER && ! TARGET_POWERPC64 && !TARGET_ISEL"
11563   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
11564   [(set_attr "length" "8")])
11565
11566 (define_insn ""
11567   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11568         (lshiftrt:DI (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11569                      (const_int 63)))
11570    (clobber (match_scratch:DI 2 "=&r"))]
11571   "TARGET_POWERPC64"
11572   "addic %2,%1,-1\;subfe %0,%2,%1"
11573   [(set_attr "length" "8")])
11574
11575 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
11576 (define_insn ""
11577   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11578         (plus:SI (lshiftrt:SI
11579                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
11580                   (const_int 31))
11581                  (match_operand:SI 2 "gpc_reg_operand" "r")))
11582    (clobber (match_scratch:SI 3 "=&r"))]
11583   "! TARGET_POWERPC64"
11584   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
11585   [(set_attr "length" "8")])
11586
11587 (define_insn ""
11588   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11589         (plus:DI (lshiftrt:DI
11590                   (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
11591                   (const_int 63))
11592                  (match_operand:DI 2 "gpc_reg_operand" "r")))
11593    (clobber (match_scratch:DI 3 "=&r"))]
11594   "TARGET_POWERPC64"
11595   "addic %3,%1,-1\;addze %0,%2"
11596   [(set_attr "length" "8")])
11597
11598 (define_insn ""
11599   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11600         (compare:CC
11601          (plus:SI (lshiftrt:SI
11602                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11603                    (const_int 31))
11604                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11605          (const_int 0)))
11606    (clobber (match_scratch:SI 3 "=&r,&r"))
11607    (clobber (match_scratch:SI 4 "=X,&r"))]
11608   "! TARGET_POWERPC64"
11609   "@
11610    {ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2
11611    #"
11612   [(set_attr "type" "compare")
11613    (set_attr "length" "8,12")])
11614
11615 (define_split
11616   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11617         (compare:CC
11618          (plus:SI (lshiftrt:SI
11619                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11620                    (const_int 31))
11621                   (match_operand:SI 2 "gpc_reg_operand" ""))
11622          (const_int 0)))
11623    (clobber (match_scratch:SI 3 ""))
11624    (clobber (match_scratch:SI 4 ""))]
11625   "! TARGET_POWERPC64 && reload_completed"
11626   [(parallel [(set (match_dup 3)
11627                    (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1)))
11628                                          (const_int 31))
11629                             (match_dup 2)))
11630               (clobber (match_dup 4))])
11631    (set (match_dup 0)
11632         (compare:CC (match_dup 3)
11633                     (const_int 0)))]
11634   "")
11635
11636 (define_insn ""
11637   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11638         (compare:CC
11639          (plus:DI (lshiftrt:DI
11640                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11641                    (const_int 63))
11642                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11643          (const_int 0)))
11644    (clobber (match_scratch:DI 3 "=&r,&r"))]
11645   "TARGET_POWERPC64"
11646   "@
11647    addic %3,%1,-1\;addze. %3,%2
11648    #"
11649   [(set_attr "type" "compare")
11650    (set_attr "length" "8,12")])
11651
11652 (define_split
11653   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11654         (compare:CC
11655          (plus:DI (lshiftrt:DI
11656                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11657                    (const_int 63))
11658                   (match_operand:DI 2 "gpc_reg_operand" ""))
11659          (const_int 0)))
11660    (clobber (match_scratch:DI 3 ""))]
11661   "TARGET_POWERPC64 && reload_completed"
11662   [(set (match_dup 3)
11663         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1)))
11664                    (const_int 63))
11665                   (match_dup 2)))
11666    (set (match_dup 0)
11667         (compare:CC (match_dup 3)
11668                     (const_int 0)))]
11669   "")
11670
11671 (define_insn ""
11672   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11673         (compare:CC
11674          (plus:SI (lshiftrt:SI
11675                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")))
11676                    (const_int 31))
11677                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
11678          (const_int 0)))
11679    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11680         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11681                  (match_dup 2)))
11682    (clobber (match_scratch:SI 3 "=&r,&r"))]
11683   "! TARGET_POWERPC64"
11684   "@
11685    {ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2
11686    #"
11687   [(set_attr "type" "compare")
11688    (set_attr "length" "8,12")])
11689
11690 (define_split
11691   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11692         (compare:CC
11693          (plus:SI (lshiftrt:SI
11694                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))
11695                    (const_int 31))
11696                   (match_operand:SI 2 "gpc_reg_operand" ""))
11697          (const_int 0)))
11698    (set (match_operand:SI 0 "gpc_reg_operand" "")
11699         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11700                  (match_dup 2)))
11701    (clobber (match_scratch:SI 3 ""))]
11702   "! TARGET_POWERPC64 && reload_completed"
11703   [(parallel [(set (match_dup 0)
11704         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
11705                  (match_dup 2)))
11706    (clobber (match_dup 3))])
11707    (set (match_dup 4)
11708         (compare:CC (match_dup 0)
11709                     (const_int 0)))]
11710   "")
11711
11712 (define_insn ""
11713   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
11714         (compare:CC
11715          (plus:DI (lshiftrt:DI
11716                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")))
11717                    (const_int 63))
11718                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
11719          (const_int 0)))
11720    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
11721         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11722                  (match_dup 2)))
11723    (clobber (match_scratch:DI 3 "=&r,&r"))]
11724   "TARGET_POWERPC64"
11725   "@
11726    addic %3,%1,-1\;addze. %0,%2
11727    #"
11728   [(set_attr "type" "compare")
11729    (set_attr "length" "8,12")])
11730
11731 (define_split
11732   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11733         (compare:CC
11734          (plus:DI (lshiftrt:DI
11735                    (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "")))
11736                    (const_int 63))
11737                   (match_operand:DI 2 "gpc_reg_operand" ""))
11738          (const_int 0)))
11739    (set (match_operand:DI 0 "gpc_reg_operand" "")
11740         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11741                  (match_dup 2)))
11742    (clobber (match_scratch:DI 3 ""))]
11743   "TARGET_POWERPC64 && reload_completed"
11744   [(parallel [(set (match_dup 0)
11745         (plus:DI (lshiftrt:DI (neg:DI (abs:DI (match_dup 1))) (const_int 63))
11746                  (match_dup 2)))
11747    (clobber (match_dup 3))])
11748    (set (match_dup 4)
11749         (compare:CC (match_dup 0)
11750                     (const_int 0)))]
11751   "")
11752
11753 (define_insn ""
11754   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11755         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
11756                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
11757    (clobber (match_scratch:SI 3 "=r,X"))]
11758   "TARGET_POWER"
11759   "@
11760    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
11761    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
11762   [(set_attr "length" "12")])
11763
11764 (define_insn ""
11765   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
11766         (compare:CC
11767          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
11768                 (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
11769          (const_int 0)))
11770    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
11771         (le:SI (match_dup 1) (match_dup 2)))
11772    (clobber (match_scratch:SI 3 "=r,X,r,X"))]
11773   "TARGET_POWER"
11774   "@
11775    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
11776    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31
11777    #
11778    #"
11779   [(set_attr "type" "compare,delayed_compare,compare,delayed_compare")
11780    (set_attr "length" "12,12,16,16")])
11781
11782 (define_split
11783   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11784         (compare:CC
11785          (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
11786                 (match_operand:SI 2 "reg_or_short_operand" ""))
11787          (const_int 0)))
11788    (set (match_operand:SI 0 "gpc_reg_operand" "")
11789         (le:SI (match_dup 1) (match_dup 2)))
11790    (clobber (match_scratch:SI 3 ""))]
11791   "TARGET_POWER && reload_completed"
11792   [(parallel [(set (match_dup 0)
11793         (le:SI (match_dup 1) (match_dup 2)))
11794    (clobber (match_dup 3))])
11795    (set (match_dup 4)
11796         (compare:CC (match_dup 0)
11797                     (const_int 0)))]
11798   "")
11799
11800 (define_insn ""
11801   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
11802         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
11803                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
11804                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
11805   "TARGET_POWER"
11806   "@
11807    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3
11808    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze|addze} %0,%3"
11809   [(set_attr "length" "12")])
11810
11811 (define_insn ""
11812   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
11813         (compare:CC
11814          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
11815                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
11816                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
11817          (const_int 0)))
11818    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
11819   "TARGET_POWER"
11820   "@
11821    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
11822    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3
11823    #
11824    #"
11825   [(set_attr "type" "compare")
11826    (set_attr "length" "12,12,16,16")])
11827
11828 (define_split
11829   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
11830         (compare:CC
11831          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
11832                          (match_operand:SI 2 "reg_or_short_operand" ""))
11833                   (match_operand:SI 3 "gpc_reg_operand" ""))
11834          (const_int 0)))
11835    (clobber (match_scratch:SI 4 ""))]
11836   "TARGET_POWER && reload_completed"
11837   [(set (match_dup 4)
11838         (plus:SI (le:SI (match_dup 1) (match_dup 2))
11839                  (match_dup 3)))
11840    (set (match_dup 0)
11841         (compare:CC (match_dup 4)
11842                     (const_int 0)))]
11843   "")
11844
11845 (define_insn ""
11846   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
11847         (compare:CC
11848          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
11849                          (match_operand:SI 2 "reg_or_short_operand" "r,O,r,O"))
11850                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
11851          (const_int 0)))
11852    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
11853         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11854   "TARGET_POWER"
11855   "@
11856    doz %0,%2,%1\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
11857    {srai|srawi} %0,%1,31\;{sf|subfc} %0,%1,%0\;{aze.|addze.} %0,%3
11858    #
11859    #"
11860   [(set_attr "type" "compare")
11861    (set_attr "length" "12,12,16,16")])
11862
11863 (define_split
11864   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
11865         (compare:CC
11866          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "")
11867                          (match_operand:SI 2 "reg_or_short_operand" ""))
11868                   (match_operand:SI 3 "gpc_reg_operand" ""))
11869          (const_int 0)))
11870    (set (match_operand:SI 0 "gpc_reg_operand" "")
11871         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
11872   "TARGET_POWER && reload_completed"
11873   [(set (match_dup 0)
11874         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
11875    (set (match_dup 4)
11876         (compare:CC (match_dup 0)
11877                     (const_int 0)))]
11878   "")
11879
11880 (define_insn ""
11881   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11882         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
11883                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
11884   "TARGET_POWER"
11885   "@
11886    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
11887    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
11888   [(set_attr "length" "12")])
11889
11890 (define_insn ""
11891   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11892         (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
11893                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
11894   "! TARGET_POWERPC64"
11895   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
11896   [(set_attr "length" "12")])
11897
11898 (define_insn ""
11899   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11900         (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
11901                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
11902   "TARGET_POWERPC64"
11903   "subf%I2c %0,%1,%2\;li %0,0\;adde %0,%0,%0"
11904   [(set_attr "length" "12")])
11905
11906 (define_insn ""
11907   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
11908         (compare:CC
11909          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
11910                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
11911          (const_int 0)))
11912    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
11913         (leu:DI (match_dup 1) (match_dup 2)))]
11914   "TARGET_POWERPC64"
11915   "@
11916    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
11917    #"
11918   [(set_attr "type" "compare")
11919    (set_attr "length" "12,16")])
11920
11921 (define_split
11922   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
11923         (compare:CC
11924          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "")
11925                  (match_operand:DI 2 "reg_or_short_operand" ""))
11926          (const_int 0)))
11927    (set (match_operand:DI 0 "gpc_reg_operand" "")
11928         (leu:DI (match_dup 1) (match_dup 2)))]
11929   "TARGET_POWERPC64 && reload_completed"
11930   [(set (match_dup 0)
11931         (leu:DI (match_dup 1) (match_dup 2)))
11932    (set (match_dup 3)
11933         (compare:CC (match_dup 0)
11934                     (const_int 0)))]
11935   "")
11936
11937 (define_insn ""
11938   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
11939         (compare:CC
11940          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
11941                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
11942          (const_int 0)))
11943    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
11944         (leu:SI (match_dup 1) (match_dup 2)))]
11945   "! TARGET_POWERPC64"
11946   "@
11947    {sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
11948    #"
11949   [(set_attr "type" "compare")
11950    (set_attr "length" "12,16")])
11951
11952 (define_split
11953   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
11954         (compare:CC
11955          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
11956                  (match_operand:SI 2 "reg_or_short_operand" ""))
11957          (const_int 0)))
11958    (set (match_operand:SI 0 "gpc_reg_operand" "")
11959         (leu:SI (match_dup 1) (match_dup 2)))]
11960   "! TARGET_POWERPC64 && reload_completed"
11961   [(set (match_dup 0)
11962         (leu:SI (match_dup 1) (match_dup 2)))
11963    (set (match_dup 3)
11964         (compare:CC (match_dup 0)
11965                     (const_int 0)))]
11966   "")
11967
11968 (define_insn ""
11969   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
11970         (compare:CC
11971          (leu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
11972                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
11973          (const_int 0)))
11974    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
11975         (leu:DI (match_dup 1) (match_dup 2)))]
11976   "TARGET_POWERPC64"
11977   "@
11978    subf%I2c %0,%1,%2\;li %0,0\;adde. %0,%0,%0
11979    #"
11980   [(set_attr "type" "compare")
11981    (set_attr "length" "12,16")])
11982
11983 (define_insn ""
11984   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
11985         (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
11986                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
11987                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
11988   "! TARGET_POWERPC64"
11989   "{sf%I2|subf%I2c} %0,%1,%2\;{aze|addze} %0,%3"
11990   [(set_attr "length" "8")])
11991
11992 (define_insn ""
11993   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
11994         (compare:CC
11995          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
11996                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
11997                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
11998          (const_int 0)))
11999    (clobber (match_scratch:SI 4 "=&r,&r"))]
12000   "! TARGET_POWERPC64"
12001   "@
12002    {sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3
12003    #"
12004   [(set_attr "type" "compare")
12005    (set_attr "length" "8,12")])
12006
12007 (define_split
12008   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12009         (compare:CC
12010          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12011                           (match_operand:SI 2 "reg_or_short_operand" ""))
12012                   (match_operand:SI 3 "gpc_reg_operand" ""))
12013          (const_int 0)))
12014    (clobber (match_scratch:SI 4 ""))]
12015   "! TARGET_POWERPC64 && reload_completed"
12016   [(set (match_dup 4)
12017         (plus:SI (leu:SI (match_dup 1) (match_dup 2))
12018                   (match_dup 3)))
12019    (set (match_dup 0)
12020         (compare:CC (match_dup 4)
12021                     (const_int 0)))]
12022   "")
12023
12024 (define_insn ""
12025   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12026         (compare:CC
12027          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12028                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12029                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12030          (const_int 0)))
12031    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12032         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12033   "! TARGET_POWERPC64"
12034   "@
12035    {sf%I2|subf%I2c} %0,%1,%2\;{aze.|addze.} %0,%3
12036    #"
12037   [(set_attr "type" "compare")
12038    (set_attr "length" "8,12")])
12039
12040 (define_split
12041   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12042         (compare:CC
12043          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12044                           (match_operand:SI 2 "reg_or_short_operand" ""))
12045                   (match_operand:SI 3 "gpc_reg_operand" ""))
12046          (const_int 0)))
12047    (set (match_operand:SI 0 "gpc_reg_operand" "")
12048         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12049   "! TARGET_POWERPC64 && reload_completed"
12050   [(set (match_dup 0)
12051         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12052    (set (match_dup 4)
12053         (compare:CC (match_dup 0)
12054                     (const_int 0)))]
12055   "")
12056
12057 (define_insn ""
12058   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12059         (neg:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12060                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12061   "! TARGET_POWERPC64"
12062   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
12063    [(set_attr "length" "12")])
12064
12065 (define_insn ""
12066   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12067         (and:SI (neg:SI
12068                  (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12069                          (match_operand:SI 2 "reg_or_short_operand" "rI")))
12070                 (match_operand:SI 3 "gpc_reg_operand" "r")))]
12071   "! TARGET_POWERPC64"
12072   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12073   [(set_attr "length" "12")])
12074
12075 (define_insn ""
12076   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12077         (compare:CC
12078          (and:SI (neg:SI
12079                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12080                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12081                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12082          (const_int 0)))
12083    (clobber (match_scratch:SI 4 "=&r,&r"))]
12084   "! TARGET_POWERPC64"
12085   "@
12086    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12087    #"
12088   [(set_attr "type" "compare")
12089    (set_attr "length" "12,16")])
12090
12091 (define_split
12092   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12093         (compare:CC
12094          (and:SI (neg:SI
12095                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12096                           (match_operand:SI 2 "reg_or_short_operand" "")))
12097                  (match_operand:SI 3 "gpc_reg_operand" ""))
12098          (const_int 0)))
12099    (clobber (match_scratch:SI 4 ""))]
12100   "! TARGET_POWERPC64 && reload_completed"
12101   [(set (match_dup 4)
12102         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12103                 (match_dup 3)))
12104    (set (match_dup 0)
12105         (compare:CC (match_dup 4)
12106                     (const_int 0)))]
12107   "")
12108
12109 (define_insn ""
12110   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12111         (compare:CC
12112          (and:SI (neg:SI
12113                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12114                           (match_operand:SI 2 "reg_or_short_operand" "rI,rI")))
12115                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12116          (const_int 0)))
12117    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12118         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12119   "! TARGET_POWERPC64"
12120   "@
12121    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12122    #"
12123   [(set_attr "type" "compare")
12124    (set_attr "length" "12,16")])
12125
12126 (define_split
12127   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12128         (compare:CC
12129          (and:SI (neg:SI
12130                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12131                           (match_operand:SI 2 "reg_or_short_operand" "")))
12132                  (match_operand:SI 3 "gpc_reg_operand" ""))
12133          (const_int 0)))
12134    (set (match_operand:SI 0 "gpc_reg_operand" "")
12135         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12136   "! TARGET_POWERPC64 && reload_completed"
12137   [(set (match_dup 0)
12138         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2)))
12139                 (match_dup 3)))
12140    (set (match_dup 4)
12141         (compare:CC (match_dup 0)
12142                     (const_int 0)))]
12143   "")
12144
12145 (define_insn ""
12146   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12147         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12148                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
12149   "TARGET_POWER"
12150   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
12151    [(set_attr "length" "12")])
12152
12153 (define_insn ""
12154   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12155         (compare:CC
12156          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12157                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12158          (const_int 0)))
12159    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12160         (lt:SI (match_dup 1) (match_dup 2)))]
12161   "TARGET_POWER"
12162   "@
12163    doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
12164    #"
12165   [(set_attr "type" "delayed_compare")
12166    (set_attr "length" "12,16")])
12167
12168 (define_split
12169   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12170         (compare:CC
12171          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12172                 (match_operand:SI 2 "reg_or_short_operand" ""))
12173          (const_int 0)))
12174    (set (match_operand:SI 0 "gpc_reg_operand" "")
12175         (lt:SI (match_dup 1) (match_dup 2)))]
12176   "TARGET_POWER && reload_completed"
12177   [(set (match_dup 0)
12178         (lt:SI (match_dup 1) (match_dup 2)))
12179    (set (match_dup 3)
12180         (compare:CC (match_dup 0)
12181                     (const_int 0)))]
12182   "")
12183
12184 (define_insn ""
12185   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12186         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12187                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12188                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12189   "TARGET_POWER"
12190   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
12191   [(set_attr "length" "12")])
12192
12193 (define_insn ""
12194   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12195         (compare:CC
12196          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12197                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12198                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12199          (const_int 0)))
12200    (clobber (match_scratch:SI 4 "=&r,&r"))]
12201   "TARGET_POWER"
12202   "@
12203    doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
12204    #"
12205   [(set_attr "type" "compare")
12206    (set_attr "length" "12,16")])
12207
12208 (define_split
12209   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12210         (compare:CC
12211          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12212                          (match_operand:SI 2 "reg_or_short_operand" ""))
12213                   (match_operand:SI 3 "gpc_reg_operand" ""))
12214          (const_int 0)))
12215    (clobber (match_scratch:SI 4 ""))]
12216   "TARGET_POWER && reload_completed"
12217   [(set (match_dup 4)
12218         (plus:SI (lt:SI (match_dup 1) (match_dup 2))
12219                  (match_dup 3)))
12220    (set (match_dup 0)
12221         (compare:CC (match_dup 4)
12222                     (const_int 0)))]
12223   "")
12224
12225 (define_insn ""
12226   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12227         (compare:CC
12228          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12229                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12230                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12231          (const_int 0)))
12232    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12233         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12234   "TARGET_POWER"
12235   "@
12236    doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
12237    #"
12238   [(set_attr "type" "compare")
12239    (set_attr "length" "12,16")])
12240
12241 (define_split
12242   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12243         (compare:CC
12244          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12245                          (match_operand:SI 2 "reg_or_short_operand" ""))
12246                   (match_operand:SI 3 "gpc_reg_operand" ""))
12247          (const_int 0)))
12248    (set (match_operand:SI 0 "gpc_reg_operand" "")
12249         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12250   "TARGET_POWER && reload_completed"
12251   [(set (match_dup 0)
12252         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12253    (set (match_dup 4)
12254         (compare:CC (match_dup 0)
12255                     (const_int 0)))]
12256   "")
12257
12258 (define_insn ""
12259   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12260         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12261                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12262   "TARGET_POWER"
12263   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
12264   [(set_attr "length" "12")])
12265
12266 (define_insn ""
12267   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12268         (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12269                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12270   "! TARGET_POWERPC64"
12271   "@
12272    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg %0,%0
12273    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
12274   [(set_attr "length" "12")])
12275
12276 (define_insn ""
12277   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12278         (compare:CC
12279          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12280                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12281          (const_int 0)))
12282    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12283         (ltu:SI (match_dup 1) (match_dup 2)))]
12284   "! TARGET_POWERPC64"
12285   "@
12286    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12287    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
12288    #
12289    #"
12290   [(set_attr "type" "compare")
12291    (set_attr "length" "12,12,16,16")])
12292
12293 (define_split
12294   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12295         (compare:CC
12296          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12297                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12298          (const_int 0)))
12299    (set (match_operand:SI 0 "gpc_reg_operand" "")
12300         (ltu:SI (match_dup 1) (match_dup 2)))]
12301   "! TARGET_POWERPC64 && reload_completed"
12302   [(set (match_dup 0)
12303         (ltu:SI (match_dup 1) (match_dup 2)))
12304    (set (match_dup 3)
12305         (compare:CC (match_dup 0)
12306                     (const_int 0)))]
12307   "")
12308
12309 (define_insn ""
12310   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12311         (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12312                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12313                  (match_operand:SI 3 "reg_or_short_operand" "rI,rI")))]
12314   "! TARGET_POWERPC64"
12315   "@
12316   {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3
12317   {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3"
12318  [(set_attr "length" "12")])
12319
12320 (define_insn ""
12321   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12322         (compare:CC
12323          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12324                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12325                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12326          (const_int 0)))
12327    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12328   "! TARGET_POWERPC64"
12329   "@
12330    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
12331    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
12332    #
12333    #"
12334   [(set_attr "type" "compare")
12335    (set_attr "length" "12,12,16,16")])
12336
12337 (define_split
12338   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12339         (compare:CC
12340          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12341                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12342                   (match_operand:SI 3 "gpc_reg_operand" ""))
12343          (const_int 0)))
12344    (clobber (match_scratch:SI 4 ""))]
12345   "! TARGET_POWERPC64 && reload_completed"
12346   [(set (match_dup 4)
12347         (plus:SI (ltu:SI (match_dup 1) (match_dup 2))
12348                  (match_dup 3)))
12349    (set (match_dup 0)
12350         (compare:CC (match_dup 4)
12351                     (const_int 0)))]
12352   "")
12353
12354 (define_insn ""
12355   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12356         (compare:CC
12357          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12358                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12359                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12360          (const_int 0)))
12361    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12362         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12363   "! TARGET_POWERPC64"
12364   "@
12365    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
12366    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
12367    #
12368    #"
12369   [(set_attr "type" "compare")
12370    (set_attr "length" "12,12,16,16")])
12371
12372 (define_split
12373   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12374         (compare:CC
12375          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12376                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12377                   (match_operand:SI 3 "gpc_reg_operand" ""))
12378          (const_int 0)))
12379    (set (match_operand:SI 0 "gpc_reg_operand" "")
12380         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12381   "! TARGET_POWERPC64 && reload_completed"
12382   [(set (match_dup 0)
12383         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12384    (set (match_dup 4)
12385         (compare:CC (match_dup 0)
12386                     (const_int 0)))]
12387   "")
12388
12389 (define_insn ""
12390   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12391         (neg:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12392                         (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))))]
12393   "! TARGET_POWERPC64"
12394   "@
12395    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
12396    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
12397   [(set_attr "length" "8")])
12398
12399 (define_insn ""
12400   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12401         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12402                (match_operand:SI 2 "reg_or_short_operand" "rI")))
12403    (clobber (match_scratch:SI 3 "=r"))]
12404   "TARGET_POWER"
12405   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
12406    [(set_attr "length" "12")])
12407
12408 (define_insn ""
12409   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12410         (compare:CC
12411          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12412                 (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12413          (const_int 0)))
12414    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12415         (ge:SI (match_dup 1) (match_dup 2)))
12416    (clobber (match_scratch:SI 3 "=r,r"))]
12417   "TARGET_POWER"
12418   "@
12419    doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
12420    #"
12421   [(set_attr "type" "compare")
12422    (set_attr "length" "12,16")])
12423
12424 (define_split
12425   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12426         (compare:CC
12427          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12428                 (match_operand:SI 2 "reg_or_short_operand" ""))
12429          (const_int 0)))
12430    (set (match_operand:SI 0 "gpc_reg_operand" "")
12431         (ge:SI (match_dup 1) (match_dup 2)))
12432    (clobber (match_scratch:SI 3 ""))]
12433   "TARGET_POWER && reload_completed"
12434   [(parallel [(set (match_dup 0)
12435                    (ge:SI (match_dup 1) (match_dup 2)))
12436               (clobber (match_dup 3))])
12437    (set (match_dup 4)
12438         (compare:CC (match_dup 0)
12439                     (const_int 0)))]
12440   "")
12441
12442 (define_insn ""
12443   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12444         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12445                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
12446                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
12447   "TARGET_POWER"
12448   "doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze|addze} %0,%3"
12449   [(set_attr "length" "12")])
12450
12451 (define_insn ""
12452   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12453         (compare:CC
12454          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12455                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12456                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12457          (const_int 0)))
12458    (clobber (match_scratch:SI 4 "=&r,&r"))]
12459   "TARGET_POWER"
12460   "@
12461    doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
12462    #"
12463   [(set_attr "type" "compare")
12464    (set_attr "length" "12,16")])
12465
12466 (define_split
12467   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12468         (compare:CC
12469          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12470                          (match_operand:SI 2 "reg_or_short_operand" ""))
12471                   (match_operand:SI 3 "gpc_reg_operand" ""))
12472          (const_int 0)))
12473    (clobber (match_scratch:SI 4 ""))]
12474   "TARGET_POWER && reload_completed"
12475   [(set (match_dup 4)
12476         (plus:SI (ge:SI (match_dup 1) (match_dup 2))
12477                  (match_dup 3)))
12478    (set (match_dup 0)
12479         (compare:CC (match_dup 4)
12480                     (const_int 0)))]
12481   "")
12482
12483 (define_insn ""
12484   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
12485         (compare:CC
12486          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12487                          (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
12488                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
12489          (const_int 0)))
12490    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12491         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12492   "TARGET_POWER"
12493   "@
12494    doz%I2 %0,%1,%2\;{sfi|subfic} %0,%0,0\;{aze.|addze.} %0,%3
12495    #"
12496   [(set_attr "type" "compare")
12497    (set_attr "length" "12,16")])
12498
12499 (define_split
12500   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12501         (compare:CC
12502          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "")
12503                          (match_operand:SI 2 "reg_or_short_operand" ""))
12504                   (match_operand:SI 3 "gpc_reg_operand" ""))
12505          (const_int 0)))
12506    (set (match_operand:SI 0 "gpc_reg_operand" "")
12507         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12508   "TARGET_POWER && reload_completed"
12509   [(set (match_dup 0)
12510         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12511    (set (match_dup 4)
12512         (compare:CC (match_dup 0)
12513                     (const_int 0)))]
12514   "")
12515
12516 (define_insn ""
12517   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12518         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12519                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
12520   "TARGET_POWER"
12521   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
12522   [(set_attr "length" "12")])
12523
12524 (define_insn ""
12525   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12526         (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12527                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
12528   "! TARGET_POWERPC64"
12529   "@
12530    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
12531    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
12532   [(set_attr "length" "12")])
12533
12534 (define_insn ""
12535   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12536         (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12537                 (match_operand:DI 2 "reg_or_neg_short_operand" "r,P")))]
12538   "TARGET_POWERPC64"
12539   "@
12540    subfc %0,%2,%1\;li %0,0\;adde %0,%0,%0
12541    addic %0,%1,%n2\;li %0,0\;adde %0,%0,%0"
12542   [(set_attr "length" "12")])
12543
12544 (define_insn ""
12545   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12546         (compare:CC
12547          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12548                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12549          (const_int 0)))
12550    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
12551         (geu:SI (match_dup 1) (match_dup 2)))]
12552   "! TARGET_POWERPC64"
12553   "@
12554    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12555    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
12556    #
12557    #"
12558   [(set_attr "type" "compare")
12559    (set_attr "length" "12,12,16,16")])
12560
12561 (define_split
12562   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12563         (compare:CC
12564          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12565                  (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12566          (const_int 0)))
12567    (set (match_operand:SI 0 "gpc_reg_operand" "")
12568         (geu:SI (match_dup 1) (match_dup 2)))]
12569   "! TARGET_POWERPC64 && reload_completed"
12570   [(set (match_dup 0)
12571         (geu:SI (match_dup 1) (match_dup 2)))
12572    (set (match_dup 3)
12573         (compare:CC (match_dup 0)
12574                     (const_int 0)))]
12575   "")
12576
12577 (define_insn ""
12578   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
12579         (compare:CC
12580          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
12581                  (match_operand:DI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12582          (const_int 0)))
12583    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
12584         (geu:DI (match_dup 1) (match_dup 2)))]
12585   "TARGET_POWERPC64"
12586   "@
12587    subfc %0,%2,%1\;li %0,0\;adde. %0,%0,%0
12588    addic %0,%1,%n2\;li %0,0\;adde. %0,%0,%0
12589    #
12590    #"
12591   [(set_attr "type" "compare")
12592    (set_attr "length" "12,12,16,16")])
12593
12594 (define_split
12595   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12596         (compare:CC
12597          (geu:DI (match_operand:DI 1 "gpc_reg_operand" "")
12598                  (match_operand:DI 2 "reg_or_neg_short_operand" ""))
12599          (const_int 0)))
12600    (set (match_operand:DI 0 "gpc_reg_operand" "")
12601         (geu:DI (match_dup 1) (match_dup 2)))]
12602   "TARGET_POWERPC64 && reload_completed"
12603   [(set (match_dup 0)
12604         (geu:DI (match_dup 1) (match_dup 2)))
12605    (set (match_dup 3)
12606         (compare:CC (match_dup 0)
12607                     (const_int 0)))]
12608   "")
12609
12610 (define_insn ""
12611   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12612         (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12613                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
12614                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12615   "! TARGET_POWERPC64"
12616   "@
12617    {sf|subfc} %0,%2,%1\;{aze|addze} %0,%3
12618    {ai|addic} %0,%1,%n2\;{aze|addze} %0,%3"
12619   [(set_attr "length" "8")])
12620
12621 (define_insn ""
12622   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12623         (compare:CC
12624          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12625                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12626                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12627          (const_int 0)))
12628    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12629   "! TARGET_POWERPC64"
12630   "@
12631    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
12632    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3
12633    #
12634    #"
12635   [(set_attr "type" "compare")
12636    (set_attr "length" "8,8,12,12")])
12637
12638 (define_split
12639   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12640         (compare:CC
12641          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12642                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12643                   (match_operand:SI 3 "gpc_reg_operand" ""))
12644          (const_int 0)))
12645    (clobber (match_scratch:SI 4 ""))]
12646   "! TARGET_POWERPC64 && reload_completed"
12647   [(set (match_dup 4)
12648         (plus:SI (geu:SI (match_dup 1) (match_dup 2))
12649                   (match_dup 3)))
12650    (set (match_dup 0)
12651         (compare:CC (match_dup 4)
12652                     (const_int 0)))]
12653   "")
12654
12655 (define_insn ""
12656   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12657         (compare:CC
12658          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12659                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P"))
12660                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12661          (const_int 0)))
12662    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12663         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12664   "! TARGET_POWERPC64"
12665   "@
12666    {sf|subfc} %0,%2,%1\;{aze.|addze.} %0,%3
12667    {ai|addic} %0,%1,%n2\;{aze.|addze.} %0,%3
12668    #
12669    #"
12670   [(set_attr "type" "compare")
12671    (set_attr "length" "8,8,12,12")])
12672
12673 (define_split
12674   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12675         (compare:CC
12676          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12677                           (match_operand:SI 2 "reg_or_neg_short_operand" ""))
12678                   (match_operand:SI 3 "gpc_reg_operand" ""))
12679          (const_int 0)))
12680    (set (match_operand:SI 0 "gpc_reg_operand" "")
12681         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
12682   "! TARGET_POWERPC64 && reload_completed"
12683   [(set (match_dup 0)
12684         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
12685    (set (match_dup 4)
12686         (compare:CC (match_dup 0)
12687                     (const_int 0)))]
12688   "")
12689
12690 (define_insn ""
12691   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12692         (neg:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12693                         (match_operand:SI 2 "reg_or_short_operand" "r,I"))))]
12694   "! TARGET_POWERPC64"
12695   "@
12696    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
12697    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
12698   [(set_attr "length" "12")])
12699
12700 (define_insn ""
12701   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12702         (and:SI (neg:SI
12703                  (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12704                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
12705                 (match_operand:SI 3 "gpc_reg_operand" "r,r")))]
12706   "! TARGET_POWERPC64"
12707   "@
12708    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0
12709    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc %0,%3,%0"
12710   [(set_attr "length" "12")])
12711
12712 (define_insn ""
12713   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
12714         (compare:CC
12715          (and:SI (neg:SI
12716                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12717                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12718                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12719          (const_int 0)))
12720    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
12721   "! TARGET_POWERPC64"
12722   "@
12723    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12724    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
12725    #
12726    #"
12727   [(set_attr "type" "compare")
12728    (set_attr "length" "12,12,16,16")])
12729
12730 (define_split
12731   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12732         (compare:CC
12733          (and:SI (neg:SI
12734                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12735                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12736                  (match_operand:SI 3 "gpc_reg_operand" ""))
12737          (const_int 0)))
12738    (clobber (match_scratch:SI 4 ""))]
12739   "! TARGET_POWERPC64 && reload_completed"
12740   [(set (match_dup 4)
12741         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2)))
12742                 (match_dup 3)))
12743    (set (match_dup 0)
12744         (compare:CC (match_dup 4)
12745                     (const_int 0)))]
12746   "")
12747
12748 (define_insn ""
12749   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
12750         (compare:CC
12751          (and:SI (neg:SI
12752                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
12753                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P,r,P")))
12754                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
12755          (const_int 0)))
12756    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
12757         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12758   "! TARGET_POWERPC64"
12759   "@
12760    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12761    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;andc. %0,%3,%0
12762    #
12763    #"
12764   [(set_attr "type" "compare")
12765    (set_attr "length" "12,12,16,16")])
12766
12767 (define_split
12768   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
12769         (compare:CC
12770          (and:SI (neg:SI
12771                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "")
12772                           (match_operand:SI 2 "reg_or_neg_short_operand" "")))
12773                  (match_operand:SI 3 "gpc_reg_operand" ""))
12774          (const_int 0)))
12775    (set (match_operand:SI 0 "gpc_reg_operand" "")
12776         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))]
12777   "! TARGET_POWERPC64 && reload_completed"
12778   [(set (match_dup 0)
12779         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
12780    (set (match_dup 4)
12781         (compare:CC (match_dup 0)
12782                     (const_int 0)))]
12783   "")
12784
12785 (define_insn ""
12786   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12787         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12788                (const_int 0)))]
12789   "! TARGET_POWERPC64"
12790   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri|srwi} %0,%0,31"
12791   [(set_attr "length" "12")])
12792
12793 (define_insn ""
12794   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
12795         (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
12796                (const_int 0)))]
12797   "TARGET_POWERPC64"
12798   "subfic %0,%1,0\;addme %0,%0\;srdi %0,%0,63"
12799   [(set_attr "length" "12")])
12800
12801 (define_insn ""
12802   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
12803         (compare:CC
12804          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12805                 (const_int 0))
12806          (const_int 0)))
12807    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12808         (gt:SI (match_dup 1) (const_int 0)))]
12809   "! TARGET_POWERPC64"
12810   "@
12811    {sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri.|srwi.} %0,%0,31
12812    #"
12813   [(set_attr "type" "delayed_compare")
12814    (set_attr "length" "12,16")])
12815
12816 (define_split
12817   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
12818         (compare:CC
12819          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12820                 (const_int 0))
12821          (const_int 0)))
12822    (set (match_operand:SI 0 "gpc_reg_operand" "")
12823         (gt:SI (match_dup 1) (const_int 0)))]
12824   "! TARGET_POWERPC64 && reload_completed"
12825   [(set (match_dup 0)
12826         (gt:SI (match_dup 1) (const_int 0)))
12827    (set (match_dup 2)
12828         (compare:CC (match_dup 0)
12829                     (const_int 0)))]
12830   "")
12831
12832 (define_insn ""
12833   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
12834         (compare:CC
12835          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12836                 (const_int 0))
12837          (const_int 0)))
12838    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
12839         (gt:DI (match_dup 1) (const_int 0)))]
12840   "TARGET_POWERPC64"
12841   "@
12842    subfic %0,%1,0\;addme %0,%0\;srdi. %0,%0,63
12843    #"
12844   [(set_attr "type" "delayed_compare")
12845    (set_attr "length" "12,16")])
12846
12847 (define_split
12848   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
12849         (compare:CC
12850          (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
12851                 (const_int 0))
12852          (const_int 0)))
12853    (set (match_operand:DI 0 "gpc_reg_operand" "")
12854         (gt:DI (match_dup 1) (const_int 0)))]
12855   "TARGET_POWERPC64 && reload_completed"
12856   [(set (match_dup 0)
12857         (gt:DI (match_dup 1) (const_int 0)))
12858    (set (match_dup 2)
12859         (compare:CC (match_dup 0)
12860                     (const_int 0)))]
12861   "")
12862
12863 (define_insn ""
12864   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
12865         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12866                (match_operand:SI 2 "reg_or_short_operand" "r")))]
12867   "TARGET_POWER"
12868   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
12869   [(set_attr "length" "12")])
12870
12871 (define_insn ""
12872   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12873         (compare:CC
12874          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12875                 (match_operand:SI 2 "reg_or_short_operand" "r,r"))
12876          (const_int 0)))
12877    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
12878         (gt:SI (match_dup 1) (match_dup 2)))]
12879   "TARGET_POWER"
12880   "@
12881    doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31
12882    #"
12883   [(set_attr "type" "delayed_compare")
12884    (set_attr "length" "12,16")])
12885
12886 (define_split
12887   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
12888         (compare:CC
12889          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12890                 (match_operand:SI 2 "reg_or_short_operand" ""))
12891          (const_int 0)))
12892    (set (match_operand:SI 0 "gpc_reg_operand" "")
12893         (gt:SI (match_dup 1) (match_dup 2)))]
12894   "TARGET_POWER && reload_completed"
12895   [(set (match_dup 0)
12896         (gt:SI (match_dup 1) (match_dup 2)))
12897    (set (match_dup 3)
12898         (compare:CC (match_dup 0)
12899                     (const_int 0)))]
12900   "")
12901
12902 (define_insn ""
12903   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
12904         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
12905                         (const_int 0))
12906                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
12907   "! TARGET_POWERPC64"
12908   "{a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze|addze} %0,%2"
12909   [(set_attr "length" "12")])
12910
12911 (define_insn ""
12912   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
12913         (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
12914                         (const_int 0))
12915                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
12916   "TARGET_POWERPC64"
12917   "addc %0,%1,%1\;subfe %0,%1,%0\;addze %0,%2"
12918   [(set_attr "length" "12")])
12919
12920 (define_insn ""
12921   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12922         (compare:CC
12923          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12924                          (const_int 0))
12925                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
12926          (const_int 0)))
12927    (clobber (match_scratch:SI 3 "=&r,&r"))]
12928   "! TARGET_POWERPC64"
12929   "@
12930    {a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2
12931    #"
12932   [(set_attr "type" "compare")
12933    (set_attr "length" "12,16")])
12934
12935 (define_split
12936   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12937         (compare:CC
12938          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
12939                          (const_int 0))
12940                   (match_operand:SI 2 "gpc_reg_operand" ""))
12941          (const_int 0)))
12942    (clobber (match_scratch:SI 3 ""))]
12943   "! TARGET_POWERPC64 && reload_completed"
12944   [(set (match_dup 3)
12945         (plus:SI (gt:SI (match_dup 1) (const_int 0))
12946                   (match_dup 2)))
12947    (set (match_dup 0)
12948         (compare:CC (match_dup 3)
12949                     (const_int 0)))]
12950   "")
12951
12952 (define_insn ""
12953   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
12954         (compare:CC
12955          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
12956                          (const_int 0))
12957                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
12958          (const_int 0)))
12959    (clobber (match_scratch:DI 3 "=&r,&r"))]
12960   "TARGET_POWERPC64"
12961   "@
12962    addc %3,%1,%1\;subfe %3,%1,%3\;addze. %3,%2
12963    #"
12964   [(set_attr "type" "compare")
12965    (set_attr "length" "12,16")])
12966
12967 (define_split
12968   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
12969         (compare:CC
12970          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
12971                          (const_int 0))
12972                   (match_operand:DI 2 "gpc_reg_operand" ""))
12973          (const_int 0)))
12974    (clobber (match_scratch:DI 3 ""))]
12975   "TARGET_POWERPC64 && reload_completed"
12976   [(set (match_dup 3)
12977         (plus:DI (gt:DI (match_dup 1) (const_int 0))
12978                  (match_dup 2)))
12979    (set (match_dup 0)
12980         (compare:CC (match_dup 3)
12981                     (const_int 0)))]
12982   "")
12983
12984 (define_insn ""
12985   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
12986         (compare:CC
12987          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
12988                          (const_int 0))
12989                   (match_operand:SI 2 "gpc_reg_operand" "r,r"))
12990          (const_int 0)))
12991    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
12992         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
12993   "! TARGET_POWERPC64"
12994   "@
12995    {a|addc} %0,%1,%1\;{sfe|subfe} %0,%1,%0\;{aze.|addze.} %0,%2
12996    #"
12997   [(set_attr "type" "compare")
12998    (set_attr "length" "12,16")])
12999
13000 (define_split
13001   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13002         (compare:CC
13003          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13004                          (const_int 0))
13005                   (match_operand:SI 2 "gpc_reg_operand" ""))
13006          (const_int 0)))
13007    (set (match_operand:SI 0 "gpc_reg_operand" "")
13008         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))]
13009   "! TARGET_POWERPC64 && reload_completed"
13010   [(set (match_dup 0)
13011         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
13012    (set (match_dup 3)
13013         (compare:CC (match_dup 0)
13014                     (const_int 0)))]
13015   "")
13016
13017 (define_insn ""
13018   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13019         (compare:CC
13020          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13021                          (const_int 0))
13022                   (match_operand:DI 2 "gpc_reg_operand" "r,r"))
13023          (const_int 0)))
13024    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13025         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13026   "TARGET_POWERPC64"
13027   "@
13028    addc %0,%1,%1\;subfe %0,%1,%0\;addze. %0,%2
13029    #"
13030   [(set_attr "type" "compare")
13031    (set_attr "length" "12,16")])
13032
13033 (define_split
13034   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13035         (compare:CC
13036          (plus:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "")
13037                          (const_int 0))
13038                   (match_operand:DI 2 "gpc_reg_operand" ""))
13039          (const_int 0)))
13040    (set (match_operand:DI 0 "gpc_reg_operand" "")
13041         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))]
13042   "TARGET_POWERPC64 && reload_completed"
13043   [(set (match_dup 0)
13044         (plus:DI (gt:DI (match_dup 1) (const_int 0)) (match_dup 2)))
13045    (set (match_dup 3)
13046         (compare:CC (match_dup 0)
13047                     (const_int 0)))]
13048   "")
13049
13050 (define_insn ""
13051   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
13052         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13053                         (match_operand:SI 2 "reg_or_short_operand" "r"))
13054                  (match_operand:SI 3 "gpc_reg_operand" "r")))]
13055   "TARGET_POWER"
13056   "doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze|addze} %0,%3"
13057   [(set_attr "length" "12")])
13058
13059 (define_insn ""
13060   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
13061         (compare:CC
13062          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13063                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13064                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13065          (const_int 0)))
13066    (clobber (match_scratch:SI 4 "=&r,&r"))]
13067   "TARGET_POWER"
13068   "@
13069    doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3
13070    #"
13071   [(set_attr "type" "compare")
13072    (set_attr "length" "12,16")])
13073
13074 (define_split
13075   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13076         (compare:CC
13077          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13078                          (match_operand:SI 2 "reg_or_short_operand" ""))
13079                   (match_operand:SI 3 "gpc_reg_operand" ""))
13080          (const_int 0)))
13081    (clobber (match_scratch:SI 4 ""))]
13082   "TARGET_POWER && reload_completed"
13083   [(set (match_dup 4)
13084         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13085    (set (match_dup 0)
13086         (compare:CC (match_dup 4)
13087                     (const_int 0)))]
13088   "")
13089
13090 (define_insn ""
13091   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
13092         (compare:CC
13093          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13094                          (match_operand:SI 2 "reg_or_short_operand" "r,r"))
13095                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
13096          (const_int 0)))
13097    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13098         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13099   "TARGET_POWER"
13100   "@
13101    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{aze.|addze.} %0,%3
13102    #"
13103   [(set_attr "type" "compare")
13104    (set_attr "length" "12,16")])
13105
13106 (define_split
13107   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13108         (compare:CC
13109          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
13110                          (match_operand:SI 2 "reg_or_short_operand" ""))
13111                   (match_operand:SI 3 "gpc_reg_operand" ""))
13112          (const_int 0)))
13113    (set (match_operand:SI 0 "gpc_reg_operand" "")
13114         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13115   "TARGET_POWER && reload_completed"
13116   [(set (match_dup 0)
13117         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13118    (set (match_dup 4)
13119         (compare:CC (match_dup 0)
13120                     (const_int 0)))]
13121   "")
13122
13123 (define_insn ""
13124   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13125         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13126                        (const_int 0))))]
13127   "! TARGET_POWERPC64"
13128   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{srai|srawi} %0,%0,31"
13129   [(set_attr "length" "12")])
13130
13131 (define_insn ""
13132   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13133         (neg:DI (gt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13134                        (const_int 0))))]
13135   "TARGET_POWERPC64"
13136   "subfic %0,%1,0\;addme %0,%0\;sradi %0,%0,63"
13137   [(set_attr "length" "12")])
13138
13139 (define_insn ""
13140   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13141         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13142                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
13143   "TARGET_POWER"
13144   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
13145   [(set_attr "length" "12")])
13146
13147 (define_insn ""
13148   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13149         (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13150                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
13151   "! TARGET_POWERPC64"
13152   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
13153   [(set_attr "length" "12")])
13154
13155 (define_insn ""
13156   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13157         (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13158                 (match_operand:DI 2 "reg_or_short_operand" "rI")))]
13159   "TARGET_POWERPC64"
13160   "subf%I2c %0,%1,%2\;subfe %0,%0,%0\;neg %0,%0"
13161   [(set_attr "length" "12")])
13162
13163 (define_insn ""
13164   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13165         (compare:CC
13166          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13167                  (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
13168          (const_int 0)))
13169    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
13170         (gtu:SI (match_dup 1) (match_dup 2)))]
13171   "! TARGET_POWERPC64"
13172   "@
13173    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
13174    #"
13175   [(set_attr "type" "compare")
13176    (set_attr "length" "12,16")])
13177
13178 (define_split
13179   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13180         (compare:CC
13181          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13182                  (match_operand:SI 2 "reg_or_short_operand" ""))
13183          (const_int 0)))
13184    (set (match_operand:SI 0 "gpc_reg_operand" "")
13185         (gtu:SI (match_dup 1) (match_dup 2)))]
13186   "! TARGET_POWERPC64 && reload_completed"
13187   [(set (match_dup 0)
13188         (gtu:SI (match_dup 1) (match_dup 2)))
13189    (set (match_dup 3)
13190         (compare:CC (match_dup 0)
13191                     (const_int 0)))]
13192   "")
13193
13194 (define_insn ""
13195   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
13196         (compare:CC
13197          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13198                  (match_operand:DI 2 "reg_or_short_operand" "rI,rI"))
13199          (const_int 0)))
13200    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
13201         (gtu:DI (match_dup 1) (match_dup 2)))]
13202   "TARGET_POWERPC64"
13203   "@
13204    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;neg. %0,%0
13205    #"
13206   [(set_attr "type" "compare")
13207    (set_attr "length" "12,16")])
13208
13209 (define_split
13210   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
13211         (compare:CC
13212          (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13213                  (match_operand:DI 2 "reg_or_short_operand" ""))
13214          (const_int 0)))
13215    (set (match_operand:DI 0 "gpc_reg_operand" "")
13216         (gtu:DI (match_dup 1) (match_dup 2)))]
13217   "TARGET_POWERPC64 && reload_completed"
13218   [(set (match_dup 0)
13219         (gtu:DI (match_dup 1) (match_dup 2)))
13220    (set (match_dup 3)
13221         (compare:CC (match_dup 0)
13222                     (const_int 0)))]
13223   "")
13224
13225 (define_insn ""
13226   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r")
13227         (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
13228                          (match_operand:SI 2 "reg_or_short_operand" "I,rI"))
13229                  (match_operand:SI 3 "reg_or_short_operand" "r,rI")))]
13230   "! TARGET_POWERPC64"
13231   "@
13232    {ai|addic} %0,%1,%k2\;{aze|addze} %0,%3
13233    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;{sf%I3|subf%I3c} %0,%0,%3"
13234   [(set_attr "length" "8,12")])
13235
13236 (define_insn ""
13237   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r")
13238         (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
13239                          (match_operand:DI 2 "reg_or_short_operand" "I,rI"))
13240                  (match_operand:DI 3 "reg_or_short_operand" "r,rI")))]
13241   "TARGET_POWERPC64"
13242   "@
13243    addic %0,%1,%k2\;addze %0,%3
13244    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;subf%I3c %0,%0,%3"
13245   [(set_attr "length" "8,12")])
13246
13247 (define_insn ""
13248   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13249         (compare:CC
13250          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13251                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13252                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13253          (const_int 0)))
13254    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r"))]
13255   "! TARGET_POWERPC64"
13256   "@
13257    {ai|addic} %4,%1,%k2\;{aze.|addze.} %4,%3
13258    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
13259    #
13260    #"
13261   [(set_attr "type" "compare")
13262    (set_attr "length" "8,12,12,16")])
13263
13264 (define_split
13265   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13266         (compare:CC
13267          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13268                           (match_operand:SI 2 "reg_or_short_operand" ""))
13269                   (match_operand:SI 3 "gpc_reg_operand" ""))
13270          (const_int 0)))
13271    (clobber (match_scratch:SI 4 ""))]
13272   "! TARGET_POWERPC64 && reload_completed"
13273   [(set (match_dup 4)
13274         (plus:SI (gtu:SI (match_dup 1) (match_dup 2))
13275                  (match_dup 3)))
13276    (set (match_dup 0)
13277         (compare:CC (match_dup 4)
13278                     (const_int 0)))]
13279   "")
13280
13281 (define_insn ""
13282   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
13283         (compare:CC
13284          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13285                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13286                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13287          (const_int 0)))
13288    (clobber (match_scratch:DI 4 "=&r,&r,&r,&r"))]
13289   "TARGET_POWERPC64"
13290   "@
13291    addic %4,%1,%k2\;addze. %4,%3
13292    subf%I2c %4,%1,%2\;subfe %4,%4,%4\;subfc. %4,%4,%3
13293    #
13294    #"
13295   [(set_attr "type" "compare")
13296    (set_attr "length" "8,12,12,16")])
13297
13298 (define_split
13299   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
13300         (compare:CC
13301          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13302                           (match_operand:DI 2 "reg_or_short_operand" ""))
13303                   (match_operand:DI 3 "gpc_reg_operand" ""))
13304          (const_int 0)))
13305    (clobber (match_scratch:DI 4 ""))]
13306   "TARGET_POWERPC64 && reload_completed"
13307   [(set (match_dup 4)
13308         (plus:DI (gtu:DI (match_dup 1) (match_dup 2))
13309                   (match_dup 3)))
13310    (set (match_dup 0)
13311         (compare:CC (match_dup 4)
13312                     (const_int 0)))]
13313   "")
13314
13315 (define_insn ""
13316   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13317         (compare:CC
13318          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
13319                           (match_operand:SI 2 "reg_or_short_operand" "I,r,I,r"))
13320                   (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r"))
13321          (const_int 0)))
13322    (set (match_operand:SI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13323         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13324   "! TARGET_POWERPC64"
13325   "@
13326    {ai|addic} %0,%1,%k2\;{aze.|addze.} %0,%3
13327    {sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;{sf.|subfc.} %0,%0,%3
13328    #
13329    #"
13330   [(set_attr "type" "compare")
13331    (set_attr "length" "8,12,12,16")])
13332
13333 (define_split
13334   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13335         (compare:CC
13336          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "")
13337                           (match_operand:SI 2 "reg_or_short_operand" ""))
13338                   (match_operand:SI 3 "gpc_reg_operand" ""))
13339          (const_int 0)))
13340    (set (match_operand:SI 0 "gpc_reg_operand" "")
13341         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13342   "! TARGET_POWERPC64 && reload_completed"
13343   [(set (match_dup 0)
13344         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
13345    (set (match_dup 4)
13346         (compare:CC (match_dup 0)
13347                     (const_int 0)))]
13348   "")
13349
13350 (define_insn ""
13351   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,?y,?y")
13352         (compare:CC
13353          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,r,r")
13354                           (match_operand:DI 2 "reg_or_short_operand" "I,r,I,r"))
13355                   (match_operand:DI 3 "gpc_reg_operand" "r,r,r,r"))
13356          (const_int 0)))
13357    (set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,&r,&r")
13358         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13359   "TARGET_POWERPC64"
13360   "@
13361    addic %0,%1,%k2\;addze. %0,%3
13362    subf%I2c %0,%1,%2\;subfe %0,%0,%0\;subfc. %0,%0,%3
13363    #
13364    #"
13365   [(set_attr "type" "compare")
13366    (set_attr "length" "8,12,12,16")])
13367
13368 (define_split
13369   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
13370         (compare:CC
13371          (plus:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "")
13372                           (match_operand:DI 2 "reg_or_short_operand" ""))
13373                   (match_operand:DI 3 "gpc_reg_operand" ""))
13374          (const_int 0)))
13375    (set (match_operand:DI 0 "gpc_reg_operand" "")
13376         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))]
13377   "TARGET_POWERPC64 && reload_completed"
13378   [(set (match_dup 0)
13379         (plus:DI (gtu:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
13380    (set (match_dup 4)
13381         (compare:CC (match_dup 0)
13382                     (const_int 0)))]
13383   "")
13384
13385 (define_insn ""
13386   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13387         (neg:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
13388                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
13389   "! TARGET_POWERPC64"
13390   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
13391   [(set_attr "length" "8")])
13392
13393 (define_insn ""
13394   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
13395         (neg:DI (gtu:DI (match_operand:DI 1 "gpc_reg_operand" "r")
13396                         (match_operand:DI 2 "reg_or_short_operand" "rI"))))]
13397   "TARGET_POWERPC64"
13398   "subf%I2c %0,%1,%2\;subfe %0,%0,%0"
13399   [(set_attr "length" "8")])
13400 \f
13401 ;; Define both directions of branch and return.  If we need a reload
13402 ;; register, we'd rather use CR0 since it is much easier to copy a
13403 ;; register CC value to there.
13404
13405 (define_insn ""
13406   [(set (pc)
13407         (if_then_else (match_operator 1 "branch_comparison_operator"
13408                                       [(match_operand 2
13409                                                       "cc_reg_operand" "x,?y")
13410                                        (const_int 0)])
13411                       (label_ref (match_operand 0 "" ""))
13412                       (pc)))]
13413   ""
13414   "*
13415 {
13416   return output_cbranch (operands[1], \"%l0\", 0, insn);
13417 }"
13418   [(set_attr "type" "branch")])
13419
13420 (define_insn ""
13421   [(set (pc)
13422         (if_then_else (match_operator 0 "branch_comparison_operator"
13423                                       [(match_operand 1
13424                                                       "cc_reg_operand" "x,?y")
13425                                        (const_int 0)])
13426                       (return)
13427                       (pc)))]
13428   "direct_return ()"
13429   "*
13430 {
13431   return output_cbranch (operands[0], NULL, 0, insn);
13432 }"
13433   [(set_attr "type" "branch")
13434    (set_attr "length" "4")])
13435
13436 (define_insn ""
13437   [(set (pc)
13438         (if_then_else (match_operator 1 "branch_comparison_operator"
13439                                       [(match_operand 2
13440                                                       "cc_reg_operand" "x,?y")
13441                                        (const_int 0)])
13442                       (pc)
13443                       (label_ref (match_operand 0 "" ""))))]
13444   ""
13445   "*
13446 {
13447   return output_cbranch (operands[1], \"%l0\", 1, insn);
13448 }"
13449   [(set_attr "type" "branch")])
13450
13451 (define_insn ""
13452   [(set (pc)
13453         (if_then_else (match_operator 0 "branch_comparison_operator"
13454                                       [(match_operand 1
13455                                                       "cc_reg_operand" "x,?y")
13456                                        (const_int 0)])
13457                       (pc)
13458                       (return)))]
13459   "direct_return ()"
13460   "*
13461 {
13462   return output_cbranch (operands[0], NULL, 1, insn);
13463 }"
13464   [(set_attr "type" "branch")
13465    (set_attr "length" "4")])
13466
13467 ;; Logic on condition register values.
13468
13469 ; This pattern matches things like
13470 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13471 ;                                          (eq:SI (reg:CCFP 68) (const_int 0)))
13472 ;                                  (const_int 1)))
13473 ; which are generated by the branch logic.
13474
13475 (define_insn ""
13476   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13477         (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13478                         [(match_operator:SI 2 
13479                                       "branch_positive_comparison_operator"
13480                                       [(match_operand 3
13481                                                       "cc_reg_operand" "y")
13482                                        (const_int 0)])
13483                          (match_operator:SI 4 
13484                                       "branch_positive_comparison_operator"
13485                                       [(match_operand 5
13486                                                       "cc_reg_operand" "y")
13487                                        (const_int 0)])])
13488                       (const_int 1)))]
13489   ""
13490   "cr%q1 %E0,%j2,%j4"
13491   [(set_attr "type" "cr_logical")])
13492
13493 ; Why is the constant -1 here, but 1 in the previous pattern?
13494 ; Because ~1 has all but the low bit set.
13495 (define_insn ""
13496   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13497         (compare:CCEQ (match_operator:SI 1 "boolean_or_operator"
13498                         [(not:SI (match_operator:SI 2 
13499                                       "branch_positive_comparison_operator"
13500                                       [(match_operand 3
13501                                                       "cc_reg_operand" "y")
13502                                        (const_int 0)]))
13503                          (match_operator:SI 4
13504                                 "branch_positive_comparison_operator"
13505                                 [(match_operand 5
13506                                                 "cc_reg_operand" "y")
13507                                  (const_int 0)])])
13508                       (const_int -1)))]
13509   ""
13510   "cr%q1 %E0,%j2,%j4"
13511   [(set_attr "type" "cr_logical")])
13512
13513 (define_insn ""
13514   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13515         (compare:CCEQ (match_operator:SI 1
13516                                       "branch_positive_comparison_operator"
13517                                       [(match_operand 2
13518                                                       "cc_reg_operand" "y")
13519                                        (const_int 0)])
13520                       (const_int 0)))]
13521   ""
13522   "{crnor %E0,%j1,%j1|crnot %E0,%j1}"
13523   [(set_attr "type" "cr_logical")])
13524
13525 ;; If we are comparing the result of two comparisons, this can be done
13526 ;; using creqv or crxor.
13527
13528 (define_insn_and_split ""
13529   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13530         (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13531                               [(match_operand 2 "cc_reg_operand" "y")
13532                                (const_int 0)])
13533                       (match_operator 3 "branch_comparison_operator"
13534                               [(match_operand 4 "cc_reg_operand" "y")
13535                                (const_int 0)])))]
13536   ""
13537   "#"
13538   ""
13539   [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13540                                     (match_dup 5)))]
13541   "
13542 {
13543   int positive_1, positive_2;
13544
13545   positive_1 = branch_positive_comparison_operator (operands[1], CCEQmode);
13546   positive_2 = branch_positive_comparison_operator (operands[3], CCEQmode);
13547
13548   if (! positive_1)
13549     operands[1] = gen_rtx (rs6000_reverse_condition (GET_MODE (operands[2]),
13550                                                      GET_CODE (operands[1])),
13551                            SImode,
13552                            operands[2], const0_rtx);
13553   else if (GET_MODE (operands[1]) != SImode)
13554     operands[1] = gen_rtx (GET_CODE (operands[1]),
13555                            SImode,
13556                            operands[2], const0_rtx);
13557
13558   if (! positive_2)
13559     operands[3] = gen_rtx (rs6000_reverse_condition (GET_MODE (operands[4]),
13560                                                      GET_CODE (operands[3])),
13561                            SImode,
13562                            operands[4], const0_rtx);
13563   else if (GET_MODE (operands[3]) != SImode)
13564     operands[3] = gen_rtx (GET_CODE (operands[3]),
13565                            SImode,
13566                            operands[4], const0_rtx);
13567
13568   if (positive_1 == positive_2)
13569     {
13570       operands[1] = gen_rtx_NOT (SImode, operands[1]);
13571       operands[5] = constm1_rtx;
13572     }
13573   else
13574     {
13575       operands[5] = const1_rtx;
13576     }
13577 }")
13578
13579 ;; Unconditional branch and return.
13580
13581 (define_insn "jump"
13582   [(set (pc)
13583         (label_ref (match_operand 0 "" "")))]
13584   ""
13585   "b %l0"
13586   [(set_attr "type" "branch")])
13587
13588 (define_insn "return"
13589   [(return)]
13590   "direct_return ()"
13591   "{br|blr}"
13592   [(set_attr "type" "jmpreg")])
13593
13594 (define_expand "indirect_jump"
13595   [(set (pc) (match_operand 0 "register_operand" ""))]
13596   ""
13597   "
13598 {
13599   if (TARGET_32BIT)
13600     emit_jump_insn (gen_indirect_jumpsi (operands[0]));
13601   else
13602     emit_jump_insn (gen_indirect_jumpdi (operands[0]));
13603   DONE;
13604 }")
13605
13606 (define_insn "indirect_jumpsi"
13607   [(set (pc) (match_operand:SI 0 "register_operand" "c,*l"))]
13608   "TARGET_32BIT"
13609   "@
13610    bctr
13611    {br|blr}"
13612   [(set_attr "type" "jmpreg")])
13613
13614 (define_insn "indirect_jumpdi"
13615   [(set (pc) (match_operand:DI 0 "register_operand" "c,*l"))]
13616   "TARGET_64BIT"
13617   "@
13618    bctr
13619    blr"
13620   [(set_attr "type" "jmpreg")])
13621
13622 ;; Table jump for switch statements:
13623 (define_expand "tablejump"
13624   [(use (match_operand 0 "" ""))
13625    (use (label_ref (match_operand 1 "" "")))]
13626   ""
13627   "
13628 {
13629   if (TARGET_32BIT)
13630     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
13631   else
13632     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
13633   DONE;
13634 }")
13635
13636 (define_expand "tablejumpsi"
13637   [(set (match_dup 3)
13638         (plus:SI (match_operand:SI 0 "" "")
13639                  (match_dup 2)))
13640    (parallel [(set (pc) (match_dup 3))
13641               (use (label_ref (match_operand 1 "" "")))])]
13642   "TARGET_32BIT"
13643   "
13644 { operands[0] = force_reg (SImode, operands[0]);
13645   operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
13646   operands[3] = gen_reg_rtx (SImode);
13647 }")
13648
13649 (define_expand "tablejumpdi"
13650   [(set (match_dup 4) 
13651         (sign_extend:DI (match_operand:SI 0 "lwa_operand" "rm")))
13652    (set (match_dup 3)
13653         (plus:DI (match_dup 4)
13654                  (match_dup 2)))
13655    (parallel [(set (pc) (match_dup 3))
13656               (use (label_ref (match_operand 1 "" "")))])]
13657   "TARGET_64BIT"
13658   "
13659 { operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
13660   operands[3] = gen_reg_rtx (DImode);
13661   operands[4] = gen_reg_rtx (DImode);
13662 }")
13663
13664 (define_insn ""
13665   [(set (pc)
13666         (match_operand:SI 0 "register_operand" "c,*l"))
13667    (use (label_ref (match_operand 1 "" "")))]
13668   "TARGET_32BIT"
13669   "@
13670    bctr
13671    {br|blr}"
13672   [(set_attr "type" "jmpreg")])
13673
13674 (define_insn ""
13675   [(set (pc)
13676         (match_operand:DI 0 "register_operand" "c,*l"))
13677    (use (label_ref (match_operand 1 "" "")))]
13678   "TARGET_64BIT"
13679   "@
13680    bctr
13681    blr"
13682   [(set_attr "type" "jmpreg")])
13683
13684 (define_insn "nop"
13685   [(const_int 0)]
13686   ""
13687   "{cror 0,0,0|nop}")
13688 \f
13689 ;; Define the subtract-one-and-jump insns, starting with the template
13690 ;; so loop.c knows what to generate.
13691
13692 (define_expand "doloop_end"
13693   [(use (match_operand 0 "" ""))        ; loop pseudo
13694    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
13695    (use (match_operand 2 "" ""))        ; max iterations
13696    (use (match_operand 3 "" ""))        ; loop level
13697    (use (match_operand 4 "" ""))]       ; label
13698   ""
13699   "
13700 {
13701   /* Only use this on innermost loops.  */
13702   if (INTVAL (operands[3]) > 1)
13703     FAIL;
13704   if (TARGET_POWERPC64)
13705     {
13706       if (GET_MODE (operands[0]) != DImode)
13707         FAIL;
13708       emit_jump_insn (gen_ctrdi (operands[0], operands[4]));
13709     }
13710   else
13711     {
13712       if (GET_MODE (operands[0]) != SImode)
13713         FAIL;
13714       emit_jump_insn (gen_ctrsi (operands[0], operands[4]));
13715     }
13716   DONE;
13717 }")
13718
13719 (define_expand "ctrsi"
13720   [(parallel [(set (pc)
13721                    (if_then_else (ne (match_operand:SI 0 "register_operand" "")
13722                                      (const_int 1))
13723                                  (label_ref (match_operand 1 "" ""))
13724                                  (pc)))
13725               (set (match_dup 0)
13726                    (plus:SI (match_dup 0)
13727                             (const_int -1)))
13728               (clobber (match_scratch:CC 2 ""))
13729               (clobber (match_scratch:SI 3 ""))])]
13730   "! TARGET_POWERPC64"
13731   "")
13732
13733 (define_expand "ctrdi"
13734   [(parallel [(set (pc)
13735                    (if_then_else (ne (match_operand:DI 0 "register_operand" "")
13736                                      (const_int 1))
13737                                  (label_ref (match_operand 1 "" ""))
13738                                  (pc)))
13739               (set (match_dup 0)
13740                    (plus:DI (match_dup 0)
13741                             (const_int -1)))
13742               (clobber (match_scratch:CC 2 ""))
13743               (clobber (match_scratch:DI 3 ""))])]
13744   "TARGET_POWERPC64"
13745   "")
13746
13747 ;; We need to be able to do this for any operand, including MEM, or we
13748 ;; will cause reload to blow up since we don't allow output reloads on
13749 ;; JUMP_INSNs.
13750 ;; For the length attribute to be calculated correctly, the
13751 ;; label MUST be operand 0.
13752
13753 (define_insn "*ctrsi_internal1"
13754   [(set (pc)
13755         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r")
13756                           (const_int 1))
13757                       (label_ref (match_operand 0 "" ""))
13758                       (pc)))
13759    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
13760         (plus:SI (match_dup 1)
13761                  (const_int -1)))
13762    (clobber (match_scratch:CC 3 "=X,&x,&x"))
13763    (clobber (match_scratch:SI 4 "=X,X,r"))]
13764   "! TARGET_POWERPC64"
13765   "*
13766 {
13767   if (which_alternative != 0)
13768     return \"#\";
13769   else if (get_attr_length (insn) == 4)
13770     return \"{bdn|bdnz} %l0\";
13771   else
13772     return \"bdz $+8\;b %l0\";
13773 }"
13774   [(set_attr "type" "branch")
13775    (set_attr "length" "*,12,16")])
13776
13777 (define_insn "*ctrsi_internal2"
13778   [(set (pc)
13779         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r")
13780                           (const_int 1))
13781                       (pc)
13782                       (label_ref (match_operand 0 "" ""))))
13783    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
13784         (plus:SI (match_dup 1)
13785                  (const_int -1)))
13786    (clobber (match_scratch:CC 3 "=X,&x,&x"))
13787    (clobber (match_scratch:SI 4 "=X,X,r"))]
13788   "! TARGET_POWERPC64"
13789   "*
13790 {
13791   if (which_alternative != 0)
13792     return \"#\";
13793   else if (get_attr_length (insn) == 4)
13794     return \"bdz %l0\";
13795   else
13796     return \"{bdn|bdnz} $+8\;b %l0\";
13797 }"
13798   [(set_attr "type" "branch")
13799    (set_attr "length" "*,12,16")])
13800
13801 (define_insn "*ctrdi_internal1"
13802   [(set (pc)
13803         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r")
13804                           (const_int 1))
13805                       (label_ref (match_operand 0 "" ""))
13806                       (pc)))
13807    (set (match_operand:DI 2 "register_operand" "=1,*r,m*c*l")
13808         (plus:DI (match_dup 1)
13809                  (const_int -1)))
13810    (clobber (match_scratch:CC 3 "=X,&x,&x"))
13811    (clobber (match_scratch:DI 4 "=X,X,r"))]
13812   "TARGET_POWERPC64"
13813   "*
13814 {
13815   if (which_alternative != 0)
13816     return \"#\";
13817   else if (get_attr_length (insn) == 4)
13818     return \"{bdn|bdnz} %l0\";
13819   else
13820     return \"bdz $+8\;b %l0\";
13821 }"
13822   [(set_attr "type" "branch")
13823    (set_attr "length" "*,12,16")])
13824
13825 (define_insn "*ctrdi_internal2"
13826   [(set (pc)
13827         (if_then_else (ne (match_operand:DI 1 "register_operand" "c,*r,*r")
13828                           (const_int 1))
13829                       (pc)
13830                       (label_ref (match_operand 0 "" ""))))
13831    (set (match_operand:DI 2 "register_operand" "=1,*r,m*c*l")
13832         (plus:DI (match_dup 1)
13833                  (const_int -1)))
13834    (clobber (match_scratch:CC 3 "=X,&x,&x"))
13835    (clobber (match_scratch:DI 4 "=X,X,r"))]
13836   "TARGET_POWERPC64"
13837   "*
13838 {
13839   if (which_alternative != 0)
13840     return \"#\";
13841   else if (get_attr_length (insn) == 4)
13842     return \"bdz %l0\";
13843   else
13844     return \"{bdn|bdnz} $+8\;b %l0\";
13845 }"
13846   [(set_attr "type" "branch")
13847    (set_attr "length" "*,12,16")])
13848
13849 ;; Similar, but we can use GE since we have a REG_NONNEG.
13850
13851 (define_insn "*ctrsi_internal3"
13852   [(set (pc)
13853         (if_then_else (ge (match_operand:SI 1 "register_operand" "c,*r,*r")
13854                           (const_int 0))
13855                       (label_ref (match_operand 0 "" ""))
13856                       (pc)))
13857    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
13858         (plus:SI (match_dup 1)
13859                  (const_int -1)))
13860    (clobber (match_scratch:CC 3 "=X,&x,&X"))
13861    (clobber (match_scratch:SI 4 "=X,X,r"))]
13862   "! TARGET_POWERPC64 && find_reg_note (insn, REG_NONNEG, 0)"
13863   "*
13864 {
13865   if (which_alternative != 0)
13866     return \"#\";
13867   else if (get_attr_length (insn) == 4)
13868     return \"{bdn|bdnz} %l0\";
13869   else
13870     return \"bdz $+8\;b %l0\";
13871 }"
13872   [(set_attr "type" "branch")
13873    (set_attr "length" "*,12,16")])
13874
13875 (define_insn "*ctrsi_internal4"
13876   [(set (pc)
13877         (if_then_else (ge (match_operand:SI 1 "register_operand" "c,*r,*r")
13878                           (const_int 0))
13879                       (pc)
13880                       (label_ref (match_operand 0 "" ""))))
13881    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
13882         (plus:SI (match_dup 1)
13883                  (const_int -1)))
13884    (clobber (match_scratch:CC 3 "=X,&x,&X"))
13885    (clobber (match_scratch:SI 4 "=X,X,r"))]
13886   "! TARGET_POWERPC64 && find_reg_note (insn, REG_NONNEG, 0)"
13887   "*
13888 {
13889   if (which_alternative != 0)
13890     return \"#\";
13891   else if (get_attr_length (insn) == 4)
13892     return \"bdz %l0\";
13893   else
13894     return \"{bdn|bdnz} $+8\;b %l0\";
13895 }"
13896   [(set_attr "type" "branch")
13897    (set_attr "length" "*,12,16")])
13898
13899 (define_insn "*ctrdi_internal3"
13900   [(set (pc)
13901         (if_then_else (ge (match_operand:DI 1 "register_operand" "c,*r,*r")
13902                           (const_int 0))
13903                       (label_ref (match_operand 0 "" ""))
13904                       (pc)))
13905    (set (match_operand:DI 2 "register_operand" "=1,*r,m*c*l")
13906         (plus:DI (match_dup 1)
13907                  (const_int -1)))
13908    (clobber (match_scratch:CC 3 "=X,&x,&x"))
13909    (clobber (match_scratch:DI 4 "=X,X,r"))]
13910   "TARGET_POWERPC64 && find_reg_note (insn, REG_NONNEG, 0)"
13911   "*
13912 {
13913   if (which_alternative != 0)
13914     return \"#\";
13915   else if (get_attr_length (insn) == 4)
13916     return \"{bdn|bdnz} %l0\";
13917   else
13918     return \"bdz $+8\;b %l0\";
13919 }"
13920   [(set_attr "type" "branch")
13921    (set_attr "length" "*,12,16")])
13922
13923 (define_insn "*ctrdi_internal4"
13924   [(set (pc)
13925         (if_then_else (ge (match_operand:DI 1 "register_operand" "c,*r,*r")
13926                           (const_int 0))
13927                       (pc)
13928                       (label_ref (match_operand 0 "" ""))))
13929    (set (match_operand:DI 2 "register_operand" "=1,*r,m*c*l")
13930         (plus:DI (match_dup 1)
13931                  (const_int -1)))
13932    (clobber (match_scratch:CC 3 "=X,&x,&x"))
13933    (clobber (match_scratch:DI 4 "=X,X,r"))]
13934   "TARGET_POWERPC64 && find_reg_note (insn, REG_NONNEG, 0)"
13935   "*
13936 {
13937   if (which_alternative != 0)
13938     return \"#\";
13939   else if (get_attr_length (insn) == 4)
13940     return \"bdz %l0\";
13941   else
13942     return \"{bdn|bdnz} $+8\;b %l0\";
13943 }"
13944   [(set_attr "type" "branch")
13945    (set_attr "length" "*,12,16")])
13946
13947 ;; Similar but use EQ
13948
13949 (define_insn "*ctrsi_internal5"
13950   [(set (pc)
13951         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r")
13952                           (const_int 1))
13953                       (label_ref (match_operand 0 "" ""))
13954                       (pc)))
13955    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
13956         (plus:SI (match_dup 1)
13957                  (const_int -1)))
13958    (clobber (match_scratch:CC 3 "=X,&x,&x"))
13959    (clobber (match_scratch:SI 4 "=X,X,r"))]
13960   "! TARGET_POWERPC64"
13961   "*
13962 {
13963   if (which_alternative != 0)
13964     return \"#\";
13965   else if (get_attr_length (insn) == 4)
13966     return \"bdz %l0\";
13967   else
13968     return \"{bdn|bdnz} $+8\;b %l0\";
13969 }"
13970   [(set_attr "type" "branch")
13971    (set_attr "length" "*,12,16")])
13972
13973 (define_insn "*ctrsi_internal6"
13974   [(set (pc)
13975         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r")
13976                           (const_int 1))
13977                       (pc)
13978                       (label_ref (match_operand 0 "" ""))))
13979    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
13980         (plus:SI (match_dup 1)
13981                  (const_int -1)))
13982    (clobber (match_scratch:CC 3 "=X,&x,&x"))
13983    (clobber (match_scratch:SI 4 "=X,X,r"))]
13984   "! TARGET_POWERPC64"
13985   "*
13986 {
13987   if (which_alternative != 0)
13988     return \"#\";
13989   else if (get_attr_length (insn) == 4)
13990     return \"{bdn|bdnz} %l0\";
13991   else
13992     return \"bdz $+8\;b %l0\";
13993 }"
13994   [(set_attr "type" "branch")
13995    (set_attr "length" "*,12,16")])
13996
13997 (define_insn "*ctrdi_internal5"
13998   [(set (pc)
13999         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r")
14000                           (const_int 1))
14001                       (label_ref (match_operand 0 "" ""))
14002                       (pc)))
14003    (set (match_operand:DI 2 "register_operand" "=1,*r,m*c*l")
14004         (plus:DI (match_dup 1)
14005                  (const_int -1)))
14006    (clobber (match_scratch:CC 3 "=X,&x,&x"))
14007    (clobber (match_scratch:DI 4 "=X,X,r"))]
14008   "TARGET_POWERPC64"
14009   "*
14010 {
14011   if (which_alternative != 0)
14012     return \"#\";
14013   else if (get_attr_length (insn) == 4)
14014     return \"bdz %l0\";
14015   else
14016     return \"{bdn|bdnz} $+8\;b %l0\";
14017 }"
14018   [(set_attr "type" "branch")
14019    (set_attr "length" "*,12,16")])
14020
14021 (define_insn "*ctrdi_internal6"
14022   [(set (pc)
14023         (if_then_else (eq (match_operand:DI 1 "register_operand" "c,*r,*r")
14024                           (const_int 1))
14025                       (pc)
14026                       (label_ref (match_operand 0 "" ""))))
14027    (set (match_operand:DI 2 "register_operand" "=1,*r,m*c*l")
14028         (plus:DI (match_dup 1)
14029                  (const_int -1)))
14030    (clobber (match_scratch:CC 3 "=X,&x,&x"))
14031    (clobber (match_scratch:DI 4 "=X,X,r"))]
14032   "TARGET_POWERPC64"
14033   "*
14034 {
14035   if (which_alternative != 0)
14036     return \"#\";
14037   else if (get_attr_length (insn) == 4)
14038     return \"{bdn|bdnz} %l0\";
14039   else
14040     return \"bdz $+8\;b %l0\";
14041 }"
14042   [(set_attr "type" "branch")
14043    (set_attr "length" "*,12,16")])
14044
14045 ;; Now the splitters if we could not allocate the CTR register
14046
14047 (define_split
14048   [(set (pc)
14049         (if_then_else (match_operator 2 "comparison_operator"
14050                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14051                                        (const_int 1)])
14052                       (match_operand 5 "" "")
14053                       (match_operand 6 "" "")))
14054    (set (match_operand:SI 0 "gpc_reg_operand" "")
14055         (plus:SI (match_dup 1)
14056                  (const_int -1)))
14057    (clobber (match_scratch:CC 3 ""))
14058    (clobber (match_scratch:SI 4 ""))]
14059   "! TARGET_POWERPC64 && reload_completed"
14060   [(parallel [(set (match_dup 3)
14061                    (compare:CC (plus:SI (match_dup 1)
14062                                         (const_int -1))
14063                                (const_int 0)))
14064               (set (match_dup 0)
14065                    (plus:SI (match_dup 1)
14066                             (const_int -1)))])
14067    (set (pc) (if_then_else (match_dup 7)
14068                            (match_dup 5)
14069                            (match_dup 6)))]
14070   "
14071 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14072                          const0_rtx); }")
14073
14074 (define_split
14075   [(set (pc)
14076         (if_then_else (match_operator 2 "comparison_operator"
14077                                       [(match_operand:SI 1 "gpc_reg_operand" "")
14078                                        (const_int 1)])
14079                       (match_operand 5 "" "")
14080                       (match_operand 6 "" "")))
14081    (set (match_operand:SI 0 "nonimmediate_operand" "")
14082         (plus:SI (match_dup 1) (const_int -1)))
14083    (clobber (match_scratch:CC 3 ""))
14084    (clobber (match_scratch:SI 4 ""))]
14085   "! TARGET_POWERPC64 && reload_completed
14086    && ! gpc_reg_operand (operands[0], SImode)"
14087   [(parallel [(set (match_dup 3)
14088                    (compare:CC (plus:SI (match_dup 1)
14089                                         (const_int -1))
14090                                (const_int 0)))
14091               (set (match_dup 4)
14092                    (plus:SI (match_dup 1)
14093                             (const_int -1)))])
14094    (set (match_dup 0)
14095         (match_dup 4))
14096    (set (pc) (if_then_else (match_dup 7)
14097                            (match_dup 5)
14098                            (match_dup 6)))]
14099   "
14100 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14101                          const0_rtx); }")
14102 (define_split
14103   [(set (pc)
14104         (if_then_else (match_operator 2 "comparison_operator"
14105                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14106                                        (const_int 1)])
14107                       (match_operand 5 "" "")
14108                       (match_operand 6 "" "")))
14109    (set (match_operand:DI 0 "gpc_reg_operand" "")
14110         (plus:DI (match_dup 1)
14111                  (const_int -1)))
14112    (clobber (match_scratch:CC 3 ""))
14113    (clobber (match_scratch:DI 4 ""))]
14114   "TARGET_POWERPC64 && reload_completed"
14115   [(parallel [(set (match_dup 3)
14116                    (compare:CC (plus:DI (match_dup 1)
14117                                         (const_int -1))
14118                                (const_int 0)))
14119               (set (match_dup 0)
14120                    (plus:DI (match_dup 1)
14121                             (const_int -1)))])
14122    (set (pc) (if_then_else (match_dup 7)
14123                            (match_dup 5)
14124                            (match_dup 6)))]
14125   "
14126 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14127                          const0_rtx); }")
14128
14129 (define_split
14130   [(set (pc)
14131         (if_then_else (match_operator 2 "comparison_operator"
14132                                       [(match_operand:DI 1 "gpc_reg_operand" "")
14133                                        (const_int 1)])
14134                       (match_operand 5 "" "")
14135                       (match_operand 6 "" "")))
14136    (set (match_operand:DI 0 "nonimmediate_operand" "")
14137         (plus:DI (match_dup 1) (const_int -1)))
14138    (clobber (match_scratch:CC 3 ""))
14139    (clobber (match_scratch:DI 4 ""))]
14140   "TARGET_POWERPC64 && reload_completed
14141    && ! gpc_reg_operand (operands[0], DImode)"
14142   [(parallel [(set (match_dup 3)
14143                    (compare:CC (plus:DI (match_dup 1)
14144                                         (const_int -1))
14145                                (const_int 0)))
14146               (set (match_dup 4)
14147                    (plus:DI (match_dup 1)
14148                             (const_int -1)))])
14149    (set (match_dup 0)
14150         (match_dup 4))
14151    (set (pc) (if_then_else (match_dup 7)
14152                            (match_dup 5)
14153                            (match_dup 6)))]
14154   "
14155 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
14156                          const0_rtx); }")
14157
14158 \f
14159 (define_insn "trap"
14160   [(trap_if (const_int 1) (const_int 0))]
14161   ""
14162   "{t 31,0,0|trap}")
14163
14164 (define_expand "conditional_trap"
14165   [(trap_if (match_operator 0 "trap_comparison_operator"
14166                             [(match_dup 2) (match_dup 3)])
14167             (match_operand 1 "const_int_operand" ""))]
14168   ""
14169   "if (rs6000_compare_fp_p || operands[1] != const0_rtx) FAIL;
14170    operands[2] = rs6000_compare_op0;
14171    operands[3] = rs6000_compare_op1;")
14172
14173 (define_insn ""
14174   [(trap_if (match_operator 0 "trap_comparison_operator"
14175                             [(match_operand:SI 1 "register_operand" "r")
14176                              (match_operand:SI 2 "reg_or_short_operand" "rI")])
14177             (const_int 0))]
14178   ""
14179   "{t|tw}%V0%I2 %1,%2")
14180
14181 (define_insn ""
14182   [(trap_if (match_operator 0 "trap_comparison_operator"
14183                             [(match_operand:DI 1 "register_operand" "r")
14184                              (match_operand:DI 2 "reg_or_short_operand" "rI")])
14185             (const_int 0))]
14186   "TARGET_POWERPC64"
14187   "td%V0%I2 %1,%2")
14188 \f
14189 ;; Insns related to generating the function prologue and epilogue.
14190
14191 (define_expand "prologue"
14192   [(use (const_int 0))]
14193   "TARGET_SCHED_PROLOG"
14194   "
14195 {
14196       rs6000_emit_prologue ();
14197       DONE;
14198 }")
14199
14200 (define_insn "movesi_from_cr"
14201   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14202         (unspec:SI [(reg:CC 68) (reg:CC 69) (reg:CC 70) (reg:CC 71) 
14203                     (reg:CC 72) (reg:CC 73) (reg:CC 74) (reg:CC 75)] 19))]
14204   ""
14205   "mfcr %0"
14206   [(set_attr "type" "cr_logical")])
14207
14208 (define_insn "*stmw"
14209  [(match_parallel 0 "stmw_operation"
14210                   [(set (match_operand:SI 1 "memory_operand" "=m")
14211                         (match_operand:SI 2 "gpc_reg_operand" "r"))])]
14212  "TARGET_MULTIPLE"
14213  "{stm|stmw} %2,%1")
14214  
14215 (define_insn "*save_fpregs_si"
14216  [(match_parallel 0 "any_operand"
14217                   [(clobber (match_operand:SI 1 "register_operand" "=l"))
14218                    (use (match_operand:SI 2 "call_operand" "s"))
14219                    (set (match_operand:DF 3 "memory_operand" "=m")
14220                         (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14221  "TARGET_32BIT"
14222  "bl %z2")
14223
14224 (define_insn "*save_fpregs_di"
14225  [(match_parallel 0 "any_operand"
14226                   [(clobber (match_operand:DI 1 "register_operand" "=l"))
14227                    (use (match_operand:DI 2 "call_operand" "s"))
14228                    (set (match_operand:DF 3 "memory_operand" "=m")
14229                         (match_operand:DF 4 "gpc_reg_operand" "f"))])]
14230  "TARGET_64BIT"
14231  "bl %z2")
14232
14233 ; These are to explain that changes to the stack pointer should
14234 ; not be moved over stores to stack memory.
14235 (define_insn "stack_tie"
14236   [(set (match_operand:BLK 0 "memory_operand" "+m")
14237         (unspec:BLK [(match_dup 0)] 5))]
14238   ""
14239   ""
14240   [(set_attr "length" "0")])
14241
14242
14243 (define_expand "epilogue"
14244   [(use (const_int 0))]
14245   "TARGET_SCHED_PROLOG"
14246   "
14247 {
14248       rs6000_emit_epilogue (FALSE);
14249       DONE;
14250 }")
14251
14252 ; On some processors, doing the mtcrf one CC register at a time is
14253 ; faster (like on the 604e).  On others, doing them all at once is
14254 ; faster; for instance, on the 601 and 750.
14255
14256 (define_expand "movsi_to_cr_one"
14257   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14258         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14259                     (match_dup 2)] 20))]
14260   ""
14261   "operands[2] = GEN_INT (1 << (75 - REGNO (operands[0])));")
14262
14263 (define_insn "*movsi_to_cr"
14264   [(match_parallel 0 "mtcrf_operation"
14265                    [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14266                          (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14267                                      (match_operand 3 "immediate_operand" "n")]
14268                          20))])]
14269  ""
14270  "*
14271 {
14272   int mask = 0;
14273   int i;
14274   for (i = 0; i < XVECLEN (operands[0], 0); i++)
14275     mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14276   operands[4] = GEN_INT (mask);
14277   return \"mtcrf %4,%2\";
14278 }"
14279   [(set_attr "type" "cr_logical")])
14280
14281 (define_insn ""
14282   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14283         (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14284                     (match_operand 2 "immediate_operand" "n")] 20))]
14285   "GET_CODE (operands[0]) == REG 
14286    && CR_REGNO_P (REGNO (operands[0]))
14287    && GET_CODE (operands[2]) == CONST_INT
14288    && INTVAL (operands[2]) == 1 << (75 - REGNO (operands[0]))"
14289   "mtcrf %R0,%1"
14290   [(set_attr "type" "cr_logical")])
14291
14292 ; The load-multiple instructions have similar properties.
14293 ; Note that "load_multiple" is a name known to the machine-independent
14294 ; code that actually corresponds to the powerpc load-string.
14295
14296 (define_insn "*lmw"
14297   [(match_parallel 0 "lmw_operation"
14298                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14299                          (match_operand:SI 2 "memory_operand" "m"))])]
14300   "TARGET_MULTIPLE"
14301   "{lm|lmw} %1,%2")
14302  
14303 (define_insn "*return_internal_si"
14304   [(return)
14305    (use (match_operand:SI 0 "register_operand" "lc"))]
14306   "TARGET_32BIT"
14307   "b%T0"
14308   [(set_attr "type" "jmpreg")])
14309
14310 (define_insn "*return_internal_di"
14311   [(return)
14312    (use (match_operand:DI 0 "register_operand" "lc"))]
14313   "TARGET_64BIT"
14314   "b%T0"
14315   [(set_attr "type" "jmpreg")])
14316
14317 ; FIXME: This would probably be somewhat simpler if the Cygnus sibcall
14318 ; stuff was in GCC.  Oh, and "any_operand" is a bit flexible...
14319
14320 (define_insn "*return_and_restore_fpregs_si"
14321  [(match_parallel 0 "any_operand"
14322                   [(return)
14323                    (use (match_operand:SI 1 "register_operand" "l"))
14324                    (use (match_operand:SI 2 "call_operand" "s"))
14325                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14326                         (match_operand:DF 4 "memory_operand" "m"))])]
14327  "TARGET_32BIT"
14328  "b %z2")
14329
14330 (define_insn "*return_and_restore_fpregs_di"
14331  [(match_parallel 0 "any_operand"
14332                   [(return)
14333                    (use (match_operand:DI 1 "register_operand" "l"))
14334                    (use (match_operand:DI 2 "call_operand" "s"))
14335                    (set (match_operand:DF 3 "gpc_reg_operand" "=f")
14336                         (match_operand:DF 4 "memory_operand" "m"))])]
14337  "TARGET_64BIT"
14338  "b %z2")
14339
14340 ; This is used in compiling the unwind routines.
14341 (define_expand "eh_return"
14342   [(use (match_operand 0 "general_operand" ""))
14343    (use (match_operand 1 "general_operand" ""))]
14344   ""
14345   "
14346 {
14347 #if TARGET_AIX
14348     rs6000_emit_eh_toc_restore (operands[0]);
14349 #endif
14350   if (TARGET_32BIT)
14351     emit_insn (gen_eh_set_lr_si (operands[1]));
14352   else
14353     emit_insn (gen_eh_set_lr_di (operands[1]));
14354   emit_move_insn (EH_RETURN_STACKADJ_RTX, operands[0]);
14355   DONE;
14356 }")
14357
14358 ; We can't expand this before we know where the link register is stored.
14359 (define_insn "eh_set_lr_si"
14360   [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")] 9)
14361    (clobber (match_scratch:SI 1 "=&b"))]
14362   "TARGET_32BIT"
14363   "#")
14364
14365 (define_insn "eh_set_lr_di"
14366   [(unspec_volatile [(match_operand:DI 0 "register_operand" "r")] 9)
14367    (clobber (match_scratch:DI 1 "=&b"))]
14368   "TARGET_64BIT"
14369   "#")
14370
14371 (define_split
14372   [(unspec_volatile [(match_operand 0 "register_operand" "")] 9)
14373    (clobber (match_scratch 1 ""))]
14374   "reload_completed"
14375   [(const_int 0)]
14376   "
14377 {
14378   rs6000_stack_t *info = rs6000_stack_info ();
14379
14380   if (info->lr_save_p)
14381     {
14382       rtx frame_rtx = stack_pointer_rtx;
14383       int sp_offset = 0;
14384       rtx tmp;
14385
14386       if (frame_pointer_needed
14387           || current_function_calls_alloca
14388           || info->total_size > 32767)
14389         {
14390           emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx));
14391           frame_rtx = operands[1];
14392         }
14393       else if (info->push_p)
14394         sp_offset = info->total_size;
14395
14396       tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset);
14397       tmp = gen_rtx_MEM (Pmode, tmp);
14398       emit_move_insn (tmp, operands[0]);
14399     }
14400   else
14401     emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]);
14402   DONE;
14403 }")
14404
14405 (define_insn "prefetch"
14406   [(prefetch (match_operand:V4SI 0 "address_operand" "p")
14407              (match_operand:SI 1 "const_int_operand" "n")
14408              (match_operand:SI 2 "const_int_operand" "n"))]
14409   "TARGET_POWERPC"
14410   "*
14411 {
14412   if (GET_CODE (operands[0]) == REG)
14413     return INTVAL (operands[1]) ? \"dcbtst 0,%0\" : \"dcbt 0,%0\";
14414   return INTVAL (operands[1]) ? \"dcbtst %a0\" : \"dcbt %a0\";
14415 }"
14416   [(set_attr "type" "load")])
14417
14418 (include "altivec.md")
14419 (include "spe.md")