OSDN Git Service

PR target/26350
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / rs6000.md
1 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
2 ;; Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
4 ;; Free Software Foundation, Inc.
5 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
6
7 ;; This file is part of GCC.
8
9 ;; GCC is free software; you can redistribute it and/or modify it
10 ;; under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 2, or (at your
12 ;; option) any later version.
13
14 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
15 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
17 ;; License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GCC; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
22 ;; MA 02110-1301, USA.
23
24 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
25
26 ;;
27 ;; UNSPEC usage
28 ;;
29
30 (define_constants
31   [(UNSPEC_FRSP                 0)      ; frsp for POWER machines
32    (UNSPEC_TIE                  5)      ; tie stack contents and stack pointer
33    (UNSPEC_TOCPTR               6)      ; address of a word pointing to the TOC
34    (UNSPEC_TOC                  7)      ; address of the TOC (more-or-less)
35    (UNSPEC_MOVSI_GOT            8)
36    (UNSPEC_MV_CR_OV             9)      ; move_from_CR_ov_bit
37    (UNSPEC_FCTIWZ               10)
38    (UNSPEC_FRIM                 11)
39    (UNSPEC_FRIN                 12)
40    (UNSPEC_FRIP                 13)
41    (UNSPEC_FRIZ                 14)
42    (UNSPEC_LD_MPIC              15)     ; load_macho_picbase
43    (UNSPEC_MPIC_CORRECT         16)     ; macho_correct_pic
44    (UNSPEC_TLSGD                17)
45    (UNSPEC_TLSLD                18)
46    (UNSPEC_MOVESI_FROM_CR       19)
47    (UNSPEC_MOVESI_TO_CR         20)
48    (UNSPEC_TLSDTPREL            21)
49    (UNSPEC_TLSDTPRELHA          22)
50    (UNSPEC_TLSDTPRELLO          23)
51    (UNSPEC_TLSGOTDTPREL         24)
52    (UNSPEC_TLSTPREL             25)
53    (UNSPEC_TLSTPRELHA           26)
54    (UNSPEC_TLSTPRELLO           27)
55    (UNSPEC_TLSGOTTPREL          28)
56    (UNSPEC_TLSTLS               29)
57    (UNSPEC_FIX_TRUNC_TF         30)     ; fadd, rounding towards zero
58    (UNSPEC_MV_CR_GT             31)     ; move_from_CR_eq_bit
59    (UNSPEC_STFIWX               32)
60    (UNSPEC_POPCNTB              33)
61    (UNSPEC_FRES                 34)
62    (UNSPEC_SP_SET               35)
63    (UNSPEC_SP_TEST              36)
64    (UNSPEC_SYNC                 37)
65    (UNSPEC_LWSYNC               38)
66    (UNSPEC_ISYNC                39)
67    (UNSPEC_SYNC_OP              40)
68    (UNSPEC_ATOMIC               41)
69    (UNSPEC_CMPXCHG              42)
70    (UNSPEC_XCHG                 43)
71    (UNSPEC_AND                  44)
72   ])
73
74 ;;
75 ;; UNSPEC_VOLATILE usage
76 ;;
77
78 (define_constants
79   [(UNSPECV_BLOCK               0)
80    (UNSPECV_LL                  1)      ; load-locked
81    (UNSPECV_SC                  2)      ; store-conditional
82    (UNSPECV_EH_RR               9)      ; eh_reg_restore
83   ])
84 \f
85 ;; Define an insn type attribute.  This is used in function unit delay
86 ;; computations.
87 (define_attr "type" "integer,two,three,load,load_ext,load_ext_u,load_ext_ux,load_ux,load_u,store,store_ux,store_u,fpload,fpload_ux,fpload_u,fpstore,fpstore_ux,fpstore_u,vecload,vecstore,imul,imul2,imul3,lmul,idiv,ldiv,insert_word,branch,cmp,fast_compare,compare,delayed_compare,imul_compare,lmul_compare,fpcompare,cr_logical,delayed_cr,mfcr,mfcrf,mtcr,mfjmpr,mtjmpr,fp,fpsimple,dmul,sdiv,ddiv,ssqrt,dsqrt,jmpreg,brinc,vecsimple,veccomplex,vecdiv,veccmp,veccmpsimple,vecperm,vecfloat,vecfdiv,isync,sync,load_l,store_c"
88   (const_string "integer"))
89
90 ;; Length (in bytes).
91 ; '(pc)' in the following doesn't include the instruction itself; it is
92 ; calculated as if the instruction had zero size.
93 (define_attr "length" ""
94   (if_then_else (eq_attr "type" "branch")
95                 (if_then_else (and (ge (minus (match_dup 0) (pc))
96                                        (const_int -32768))
97                                    (lt (minus (match_dup 0) (pc))
98                                        (const_int 32764)))
99                               (const_int 4)
100                               (const_int 8))
101                 (const_int 4)))
102
103 ;; Processor type -- this attribute must exactly match the processor_type
104 ;; enumeration in rs6000.h.
105
106 (define_attr "cpu" "rios1,rios2,rs64a,mpccore,ppc403,ppc405,ppc440,ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,ppc750,ppc7400,ppc7450,ppc8540,power4,power5"
107   (const (symbol_ref "rs6000_cpu_attr")))
108
109 (automata_option "ndfa")
110
111 (include "rios1.md")
112 (include "rios2.md")
113 (include "rs64.md")
114 (include "mpc.md")
115 (include "40x.md")
116 (include "440.md")
117 (include "603.md")
118 (include "6xx.md")
119 (include "7xx.md")
120 (include "7450.md")
121 (include "8540.md")
122 (include "power4.md")
123 (include "power5.md")
124
125 (include "predicates.md")
126
127 (include "darwin.md")
128
129 \f
130 ;; Mode macros
131
132 ; This mode macro allows :GPR to be used to indicate the allowable size
133 ; of whole values in GPRs.
134 (define_mode_macro GPR [SI (DI "TARGET_POWERPC64")])
135
136 ; Any supported integer mode.
137 (define_mode_macro INT [QI HI SI DI TI])
138
139 ; Any supported integer mode that fits in one register.
140 (define_mode_macro INT1 [QI HI SI (DI "TARGET_POWERPC64")])
141
142 ; extend modes for DImode
143 (define_mode_macro QHSI [QI HI SI])
144
145 ; SImode or DImode, even if DImode doesn't fit in GPRs.
146 (define_mode_macro SDI [SI DI])
147
148 ; The size of a pointer.  Also, the size of the value that a record-condition
149 ; (one with a '.') will compare.
150 (define_mode_macro P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
151
152 ; Any hardware-supported floating-point mode
153 (define_mode_macro FP [(SF "TARGET_HARD_FLOAT")
154   (DF "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)")
155   (TF "!TARGET_IEEEQUAD
156    && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128")])
157
158 ; Various instructions that come in SI and DI forms.
159 ; A generic w/d attribute, for things like cmpw/cmpd.
160 (define_mode_attr wd [(QI "b") (HI "h") (SI "w") (DI "d")])
161
162 ; DImode bits
163 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
164
165 \f
166 ;; Start with fixed-point load and store insns.  Here we put only the more
167 ;; complex forms.  Basic data transfer is done later.
168
169 (define_expand "zero_extend<mode>di2"
170   [(set (match_operand:DI 0 "gpc_reg_operand" "")
171         (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "")))]
172   "TARGET_POWERPC64"
173   "")
174
175 (define_insn "*zero_extend<mode>di2_internal1"
176   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
177         (zero_extend:DI (match_operand:QHSI 1 "reg_or_mem_operand" "m,r")))]
178   "TARGET_POWERPC64"
179   "@
180    l<wd>z%U1%X1 %0,%1
181    rldicl %0,%1,0,<dbits>"
182   [(set_attr "type" "load,*")])
183
184 (define_insn "*zero_extend<mode>di2_internal2"
185   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
186         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
187                     (const_int 0)))
188    (clobber (match_scratch:DI 2 "=r,r"))]
189   "TARGET_64BIT"
190   "@
191    rldicl. %2,%1,0,<dbits>
192    #"
193   [(set_attr "type" "compare")
194    (set_attr "length" "4,8")])
195
196 (define_split
197   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
198         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
199                     (const_int 0)))
200    (clobber (match_scratch:DI 2 ""))]
201   "TARGET_POWERPC64 && reload_completed"
202   [(set (match_dup 2)
203         (zero_extend:DI (match_dup 1)))
204    (set (match_dup 0)
205         (compare:CC (match_dup 2)
206                     (const_int 0)))]
207   "")
208
209 (define_insn "*zero_extend<mode>di2_internal3"
210   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
211         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" "r,r"))
212                     (const_int 0)))
213    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
214         (zero_extend:DI (match_dup 1)))]
215   "TARGET_64BIT"
216   "@
217    rldicl. %0,%1,0,<dbits>
218    #"
219   [(set_attr "type" "compare")
220    (set_attr "length" "4,8")])
221
222 (define_split
223   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
224         (compare:CC (zero_extend:DI (match_operand:QHSI 1 "gpc_reg_operand" ""))
225                     (const_int 0)))
226    (set (match_operand:DI 0 "gpc_reg_operand" "")
227         (zero_extend:DI (match_dup 1)))]
228   "TARGET_POWERPC64 && reload_completed"
229   [(set (match_dup 0)
230         (zero_extend:DI (match_dup 1)))
231    (set (match_dup 2)
232         (compare:CC (match_dup 0)
233                     (const_int 0)))]
234   "")
235
236 (define_insn "extendqidi2"
237   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
238         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
239   "TARGET_POWERPC64"
240   "extsb %0,%1")
241
242 (define_insn ""
243   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
244         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
245                     (const_int 0)))
246    (clobber (match_scratch:DI 2 "=r,r"))]
247   "TARGET_64BIT"
248   "@
249    extsb. %2,%1
250    #"
251   [(set_attr "type" "compare")
252    (set_attr "length" "4,8")])
253
254 (define_split
255   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
256         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
257                     (const_int 0)))
258    (clobber (match_scratch:DI 2 ""))]
259   "TARGET_POWERPC64 && reload_completed"
260   [(set (match_dup 2)
261         (sign_extend:DI (match_dup 1)))
262    (set (match_dup 0)
263         (compare:CC (match_dup 2)
264                     (const_int 0)))]
265   "")
266
267 (define_insn ""
268   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
269         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
270                     (const_int 0)))
271    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
272         (sign_extend:DI (match_dup 1)))]
273   "TARGET_64BIT"
274   "@
275    extsb. %0,%1
276    #"
277   [(set_attr "type" "compare")
278    (set_attr "length" "4,8")])
279
280 (define_split
281   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
282         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" ""))
283                     (const_int 0)))
284    (set (match_operand:DI 0 "gpc_reg_operand" "")
285         (sign_extend:DI (match_dup 1)))]
286   "TARGET_POWERPC64 && reload_completed"
287   [(set (match_dup 0)
288         (sign_extend:DI (match_dup 1)))
289    (set (match_dup 2)
290         (compare:CC (match_dup 0)
291                     (const_int 0)))]
292   "")
293
294 (define_expand "extendhidi2"
295   [(set (match_operand:DI 0 "gpc_reg_operand" "")
296         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
297   "TARGET_POWERPC64"
298   "")
299
300 (define_insn ""
301   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
302         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
303   "TARGET_POWERPC64"
304   "@
305    lha%U1%X1 %0,%1
306    extsh %0,%1"
307   [(set_attr "type" "load_ext,*")])
308
309 (define_insn ""
310   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
311         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
312                     (const_int 0)))
313    (clobber (match_scratch:DI 2 "=r,r"))]
314   "TARGET_64BIT"
315   "@
316    extsh. %2,%1
317    #"
318   [(set_attr "type" "compare")
319    (set_attr "length" "4,8")])
320
321 (define_split
322   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
323         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
324                     (const_int 0)))
325    (clobber (match_scratch:DI 2 ""))]
326   "TARGET_POWERPC64 && reload_completed"
327   [(set (match_dup 2)
328         (sign_extend:DI (match_dup 1)))
329    (set (match_dup 0)
330         (compare:CC (match_dup 2)
331                     (const_int 0)))]
332   "")
333
334 (define_insn ""
335   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
336         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
337                     (const_int 0)))
338    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
339         (sign_extend:DI (match_dup 1)))]
340   "TARGET_64BIT"
341   "@
342    extsh. %0,%1
343    #"
344   [(set_attr "type" "compare")
345    (set_attr "length" "4,8")])
346
347 (define_split
348   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
349         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" ""))
350                     (const_int 0)))
351    (set (match_operand:DI 0 "gpc_reg_operand" "")
352         (sign_extend:DI (match_dup 1)))]
353   "TARGET_POWERPC64 && reload_completed"
354   [(set (match_dup 0)
355         (sign_extend:DI (match_dup 1)))
356    (set (match_dup 2)
357         (compare:CC (match_dup 0)
358                     (const_int 0)))]
359   "")
360
361 (define_expand "extendsidi2"
362   [(set (match_operand:DI 0 "gpc_reg_operand" "")
363         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
364   "TARGET_POWERPC64"
365   "")
366
367 (define_insn ""
368   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
369         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
370   "TARGET_POWERPC64"
371   "@
372    lwa%U1%X1 %0,%1
373    extsw %0,%1"
374   [(set_attr "type" "load_ext,*")])
375
376 (define_insn ""
377   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
378         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
379                     (const_int 0)))
380    (clobber (match_scratch:DI 2 "=r,r"))]
381   "TARGET_64BIT"
382   "@
383    extsw. %2,%1
384    #"
385   [(set_attr "type" "compare")
386    (set_attr "length" "4,8")])
387
388 (define_split
389   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
390         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
391                     (const_int 0)))
392    (clobber (match_scratch:DI 2 ""))]
393   "TARGET_POWERPC64 && reload_completed"
394   [(set (match_dup 2)
395         (sign_extend:DI (match_dup 1)))
396    (set (match_dup 0)
397         (compare:CC (match_dup 2)
398                     (const_int 0)))]
399   "")
400
401 (define_insn ""
402   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
403         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
404                     (const_int 0)))
405    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
406         (sign_extend:DI (match_dup 1)))]
407   "TARGET_64BIT"
408   "@
409    extsw. %0,%1
410    #"
411   [(set_attr "type" "compare")
412    (set_attr "length" "4,8")])
413
414 (define_split
415   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
416         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
417                     (const_int 0)))
418    (set (match_operand:DI 0 "gpc_reg_operand" "")
419         (sign_extend:DI (match_dup 1)))]
420   "TARGET_POWERPC64 && reload_completed"
421   [(set (match_dup 0)
422         (sign_extend:DI (match_dup 1)))
423    (set (match_dup 2)
424         (compare:CC (match_dup 0)
425                     (const_int 0)))]
426   "")
427
428 (define_expand "zero_extendqisi2"
429   [(set (match_operand:SI 0 "gpc_reg_operand" "")
430         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
431   ""
432   "")
433
434 (define_insn ""
435   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
436         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
437   ""
438   "@
439    lbz%U1%X1 %0,%1
440    {rlinm|rlwinm} %0,%1,0,0xff"
441   [(set_attr "type" "load,*")])
442
443 (define_insn ""
444   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
445         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
446                     (const_int 0)))
447    (clobber (match_scratch:SI 2 "=r,r"))]
448   ""
449   "@
450    {andil.|andi.} %2,%1,0xff
451    #"
452   [(set_attr "type" "compare")
453    (set_attr "length" "4,8")])
454
455 (define_split
456   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
457         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
458                     (const_int 0)))
459    (clobber (match_scratch:SI 2 ""))]
460   "reload_completed"
461   [(set (match_dup 2)
462         (zero_extend:SI (match_dup 1)))
463    (set (match_dup 0)
464         (compare:CC (match_dup 2)
465                     (const_int 0)))]
466   "")
467
468 (define_insn ""
469   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
470         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
471                     (const_int 0)))
472    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
473         (zero_extend:SI (match_dup 1)))]
474   ""
475   "@
476    {andil.|andi.} %0,%1,0xff
477    #"
478   [(set_attr "type" "compare")
479    (set_attr "length" "4,8")])
480
481 (define_split
482   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
483         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
484                     (const_int 0)))
485    (set (match_operand:SI 0 "gpc_reg_operand" "")
486         (zero_extend:SI (match_dup 1)))]
487   "reload_completed"
488   [(set (match_dup 0)
489         (zero_extend:SI (match_dup 1)))
490    (set (match_dup 2)
491         (compare:CC (match_dup 0)
492                     (const_int 0)))]
493   "")
494
495 (define_expand "extendqisi2"
496   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
497    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
498   ""
499   "
500 {
501   if (TARGET_POWERPC)
502     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
503   else if (TARGET_POWER)
504     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
505   else
506     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
507   DONE;
508 }")
509
510 (define_insn "extendqisi2_ppc"
511   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
512         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
513   "TARGET_POWERPC"
514   "extsb %0,%1")
515
516 (define_insn ""
517   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
518         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
519                     (const_int 0)))
520    (clobber (match_scratch:SI 2 "=r,r"))]
521   "TARGET_POWERPC"
522   "@
523    extsb. %2,%1
524    #"
525   [(set_attr "type" "compare")
526    (set_attr "length" "4,8")])
527
528 (define_split
529   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
530         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
531                     (const_int 0)))
532    (clobber (match_scratch:SI 2 ""))]
533   "TARGET_POWERPC && reload_completed"
534   [(set (match_dup 2)
535         (sign_extend:SI (match_dup 1)))
536    (set (match_dup 0)
537         (compare:CC (match_dup 2)
538                     (const_int 0)))]
539   "")
540
541 (define_insn ""
542   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
543         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
544                     (const_int 0)))
545    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
546         (sign_extend:SI (match_dup 1)))]
547   "TARGET_POWERPC"
548   "@
549    extsb. %0,%1
550    #"
551   [(set_attr "type" "compare")
552    (set_attr "length" "4,8")])
553
554 (define_split
555   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
556         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" ""))
557                     (const_int 0)))
558    (set (match_operand:SI 0 "gpc_reg_operand" "")
559         (sign_extend:SI (match_dup 1)))]
560   "TARGET_POWERPC && reload_completed"
561   [(set (match_dup 0)
562         (sign_extend:SI (match_dup 1)))
563    (set (match_dup 2)
564         (compare:CC (match_dup 0)
565                     (const_int 0)))]
566   "")
567
568 (define_expand "extendqisi2_power"
569   [(parallel [(set (match_dup 2)
570                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
571                               (const_int 24)))
572               (clobber (scratch:SI))])
573    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
574                    (ashiftrt:SI (match_dup 2)
575                                 (const_int 24)))
576               (clobber (scratch:SI))])]
577   "TARGET_POWER"
578   "
579 { operands[1] = gen_lowpart (SImode, operands[1]);
580   operands[2] = gen_reg_rtx (SImode); }")
581
582 (define_expand "extendqisi2_no_power"
583   [(set (match_dup 2)
584         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
585                    (const_int 24)))
586    (set (match_operand:SI 0 "gpc_reg_operand" "")
587         (ashiftrt:SI (match_dup 2)
588                      (const_int 24)))]
589   "! TARGET_POWER && ! TARGET_POWERPC"
590   "
591 { operands[1] = gen_lowpart (SImode, operands[1]);
592   operands[2] = gen_reg_rtx (SImode); }")
593
594 (define_expand "zero_extendqihi2"
595   [(set (match_operand:HI 0 "gpc_reg_operand" "")
596         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
597   ""
598   "")
599
600 (define_insn ""
601   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
602         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
603   ""
604   "@
605    lbz%U1%X1 %0,%1
606    {rlinm|rlwinm} %0,%1,0,0xff"
607   [(set_attr "type" "load,*")])
608
609 (define_insn ""
610   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
611         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
612                     (const_int 0)))
613    (clobber (match_scratch:HI 2 "=r,r"))]
614   ""
615   "@
616    {andil.|andi.} %2,%1,0xff
617    #"
618   [(set_attr "type" "compare")
619    (set_attr "length" "4,8")])
620
621 (define_split
622   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
623         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
624                     (const_int 0)))
625    (clobber (match_scratch:HI 2 ""))]
626   "reload_completed"
627   [(set (match_dup 2)
628         (zero_extend:HI (match_dup 1)))
629    (set (match_dup 0)
630         (compare:CC (match_dup 2)
631                     (const_int 0)))]
632   "")
633
634 (define_insn ""
635   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
636         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
637                     (const_int 0)))
638    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
639         (zero_extend:HI (match_dup 1)))]
640   ""
641   "@
642    {andil.|andi.} %0,%1,0xff
643    #"
644   [(set_attr "type" "compare")
645    (set_attr "length" "4,8")])
646
647 (define_split
648   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
649         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
650                     (const_int 0)))
651    (set (match_operand:HI 0 "gpc_reg_operand" "")
652         (zero_extend:HI (match_dup 1)))]
653   "reload_completed"
654   [(set (match_dup 0)
655         (zero_extend:HI (match_dup 1)))
656    (set (match_dup 2)
657         (compare:CC (match_dup 0)
658                     (const_int 0)))]
659   "")
660
661 (define_expand "extendqihi2"
662   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
663    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
664   ""
665   "
666 {
667   if (TARGET_POWERPC)
668     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
669   else if (TARGET_POWER)
670     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
671   else
672     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
673   DONE;
674 }")
675
676 (define_insn "extendqihi2_ppc"
677   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
678         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
679   "TARGET_POWERPC"
680   "extsb %0,%1")
681
682 (define_insn ""
683   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
684         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
685                     (const_int 0)))
686    (clobber (match_scratch:HI 2 "=r,r"))]
687   "TARGET_POWERPC"
688   "@
689    extsb. %2,%1
690    #"
691   [(set_attr "type" "compare")
692    (set_attr "length" "4,8")])
693
694 (define_split
695   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
696         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
697                     (const_int 0)))
698    (clobber (match_scratch:HI 2 ""))]
699   "TARGET_POWERPC && reload_completed"
700   [(set (match_dup 2)
701         (sign_extend:HI (match_dup 1)))
702    (set (match_dup 0)
703         (compare:CC (match_dup 2)
704                     (const_int 0)))]
705   "")
706
707 (define_insn ""
708   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
709         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
710                     (const_int 0)))
711    (set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
712         (sign_extend:HI (match_dup 1)))]
713   "TARGET_POWERPC"
714   "@
715    extsb. %0,%1
716    #"
717   [(set_attr "type" "compare")
718    (set_attr "length" "4,8")])
719
720 (define_split
721   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
722         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" ""))
723                     (const_int 0)))
724    (set (match_operand:HI 0 "gpc_reg_operand" "")
725         (sign_extend:HI (match_dup 1)))]
726   "TARGET_POWERPC && reload_completed"
727   [(set (match_dup 0)
728         (sign_extend:HI (match_dup 1)))
729    (set (match_dup 2)
730         (compare:CC (match_dup 0)
731                     (const_int 0)))]
732   "")
733
734 (define_expand "extendqihi2_power"
735   [(parallel [(set (match_dup 2)
736                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
737                               (const_int 24)))
738               (clobber (scratch:SI))])
739    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
740                    (ashiftrt:SI (match_dup 2)
741                                 (const_int 24)))
742               (clobber (scratch:SI))])]
743   "TARGET_POWER"
744   "
745 { operands[0] = gen_lowpart (SImode, operands[0]);
746   operands[1] = gen_lowpart (SImode, operands[1]);
747   operands[2] = gen_reg_rtx (SImode); }")
748
749 (define_expand "extendqihi2_no_power"
750   [(set (match_dup 2)
751         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
752                    (const_int 24)))
753    (set (match_operand:HI 0 "gpc_reg_operand" "")
754         (ashiftrt:SI (match_dup 2)
755                      (const_int 24)))]
756   "! TARGET_POWER && ! TARGET_POWERPC"
757   "
758 { operands[0] = gen_lowpart (SImode, operands[0]);
759   operands[1] = gen_lowpart (SImode, operands[1]);
760   operands[2] = gen_reg_rtx (SImode); }")
761
762 (define_expand "zero_extendhisi2"
763   [(set (match_operand:SI 0 "gpc_reg_operand" "")
764         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
765   ""
766   "")
767
768 (define_insn ""
769   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
770         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
771   ""
772   "@
773    lhz%U1%X1 %0,%1
774    {rlinm|rlwinm} %0,%1,0,0xffff"
775   [(set_attr "type" "load,*")])
776
777 (define_insn ""
778   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
779         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
780                     (const_int 0)))
781    (clobber (match_scratch:SI 2 "=r,r"))]
782   ""
783   "@
784    {andil.|andi.} %2,%1,0xffff
785    #"
786   [(set_attr "type" "compare")
787    (set_attr "length" "4,8")])
788
789 (define_split
790   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
791         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
792                     (const_int 0)))
793    (clobber (match_scratch:SI 2 ""))]
794   "reload_completed"
795   [(set (match_dup 2)
796         (zero_extend:SI (match_dup 1)))
797    (set (match_dup 0)
798         (compare:CC (match_dup 2)
799                     (const_int 0)))]
800   "")
801
802 (define_insn ""
803   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
804         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
805                     (const_int 0)))
806    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
807         (zero_extend:SI (match_dup 1)))]
808   ""
809   "@
810    {andil.|andi.} %0,%1,0xffff
811    #"
812   [(set_attr "type" "compare")
813    (set_attr "length" "4,8")])
814
815 (define_split
816   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
817         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
818                     (const_int 0)))
819    (set (match_operand:SI 0 "gpc_reg_operand" "")
820         (zero_extend:SI (match_dup 1)))]
821   "reload_completed"
822   [(set (match_dup 0)
823         (zero_extend:SI (match_dup 1)))
824    (set (match_dup 2)
825         (compare:CC (match_dup 0)
826                     (const_int 0)))]
827   "")
828
829 (define_expand "extendhisi2"
830   [(set (match_operand:SI 0 "gpc_reg_operand" "")
831         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
832   ""
833   "")
834
835 (define_insn ""
836   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
837         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
838   ""
839   "@
840    lha%U1%X1 %0,%1
841    {exts|extsh} %0,%1"
842   [(set_attr "type" "load_ext,*")])
843
844 (define_insn ""
845   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
846         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
847                     (const_int 0)))
848    (clobber (match_scratch:SI 2 "=r,r"))]
849   ""
850   "@
851    {exts.|extsh.} %2,%1
852    #"
853   [(set_attr "type" "compare")
854    (set_attr "length" "4,8")])
855
856 (define_split
857   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
858         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
859                     (const_int 0)))
860    (clobber (match_scratch:SI 2 ""))]
861   "reload_completed"
862   [(set (match_dup 2)
863         (sign_extend:SI (match_dup 1)))
864    (set (match_dup 0)
865         (compare:CC (match_dup 2)
866                     (const_int 0)))]
867   "")
868
869 (define_insn ""
870   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
871         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
872                     (const_int 0)))
873    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
874         (sign_extend:SI (match_dup 1)))]
875   ""
876   "@
877    {exts.|extsh.} %0,%1
878    #"
879   [(set_attr "type" "compare")
880    (set_attr "length" "4,8")])
881 \f
882 ;; IBM 405 and 440 half-word multiplication operations.
883
884 (define_insn "*macchwc"
885   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
886         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
887                                        (match_operand:SI 2 "gpc_reg_operand" "r")
888                                        (const_int 16))
889                                       (sign_extend:SI
890                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
891                              (match_operand:SI 4 "gpc_reg_operand" "0"))
892                     (const_int 0)))
893    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
894         (plus:SI (mult:SI (ashiftrt:SI
895                            (match_dup 2)
896                            (const_int 16))
897                           (sign_extend:SI
898                            (match_dup 1)))
899                  (match_dup 4)))]
900   "TARGET_MULHW"
901   "macchw. %0, %1, %2"
902   [(set_attr "type" "imul3")])
903
904 (define_insn "*macchw"
905   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
906         (plus:SI (mult:SI (ashiftrt:SI
907                            (match_operand:SI 2 "gpc_reg_operand" "r")
908                            (const_int 16))
909                           (sign_extend:SI
910                            (match_operand:HI 1 "gpc_reg_operand" "r")))
911                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
912   "TARGET_MULHW"
913   "macchw %0, %1, %2"
914   [(set_attr "type" "imul3")])
915
916 (define_insn "*macchwuc"
917   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
918         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
919                                        (match_operand:SI 2 "gpc_reg_operand" "r")
920                                        (const_int 16))
921                                       (zero_extend:SI
922                                        (match_operand:HI 1 "gpc_reg_operand" "r")))
923                              (match_operand:SI 4 "gpc_reg_operand" "0"))
924                     (const_int 0)))
925    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
926         (plus:SI (mult:SI (lshiftrt:SI
927                            (match_dup 2)
928                            (const_int 16))
929                           (zero_extend:SI
930                            (match_dup 1)))
931                  (match_dup 4)))]
932   "TARGET_MULHW"
933   "macchwu. %0, %1, %2"
934   [(set_attr "type" "imul3")])
935
936 (define_insn "*macchwu"
937   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
938         (plus:SI (mult:SI (lshiftrt:SI
939                            (match_operand:SI 2 "gpc_reg_operand" "r")
940                            (const_int 16))
941                           (zero_extend:SI
942                            (match_operand:HI 1 "gpc_reg_operand" "r")))
943                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
944   "TARGET_MULHW"
945   "macchwu %0, %1, %2"
946   [(set_attr "type" "imul3")])
947
948 (define_insn "*machhwc"
949   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
950         (compare:CC (plus:SI (mult:SI (ashiftrt:SI
951                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
952                                        (const_int 16))
953                                       (ashiftrt:SI
954                                        (match_operand:SI 2 "gpc_reg_operand" "r")
955                                        (const_int 16)))
956                              (match_operand:SI 4 "gpc_reg_operand" "0"))
957                     (const_int 0)))
958    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
959         (plus:SI (mult:SI (ashiftrt:SI
960                            (match_dup 1)
961                            (const_int 16))
962                           (ashiftrt:SI
963                            (match_dup 2)
964                            (const_int 16)))
965                  (match_dup 4)))]
966   "TARGET_MULHW"
967   "machhw. %0, %1, %2"
968   [(set_attr "type" "imul3")])
969
970 (define_insn "*machhw"
971   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
972         (plus:SI (mult:SI (ashiftrt:SI
973                            (match_operand:SI 1 "gpc_reg_operand" "%r")
974                            (const_int 16))
975                           (ashiftrt:SI
976                            (match_operand:SI 2 "gpc_reg_operand" "r")
977                            (const_int 16)))
978                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
979   "TARGET_MULHW"
980   "machhw %0, %1, %2"
981   [(set_attr "type" "imul3")])
982
983 (define_insn "*machhwuc"
984   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
985         (compare:CC (plus:SI (mult:SI (lshiftrt:SI
986                                        (match_operand:SI 1 "gpc_reg_operand" "%r")
987                                        (const_int 16))
988                                       (lshiftrt:SI
989                                        (match_operand:SI 2 "gpc_reg_operand" "r")
990                                        (const_int 16)))
991                              (match_operand:SI 4 "gpc_reg_operand" "0"))
992                     (const_int 0)))
993    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
994         (plus:SI (mult:SI (lshiftrt:SI
995                            (match_dup 1)
996                            (const_int 16))
997                           (lshiftrt:SI
998                            (match_dup 2)
999                            (const_int 16)))
1000                  (match_dup 4)))]
1001   "TARGET_MULHW"
1002   "machhwu. %0, %1, %2"
1003   [(set_attr "type" "imul3")])
1004
1005 (define_insn "*machhwu"
1006   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1007         (plus:SI (mult:SI (lshiftrt:SI
1008                            (match_operand:SI 1 "gpc_reg_operand" "%r")
1009                            (const_int 16))
1010                           (lshiftrt:SI
1011                            (match_operand:SI 2 "gpc_reg_operand" "r")
1012                            (const_int 16)))
1013                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1014   "TARGET_MULHW"
1015   "machhwu %0, %1, %2"
1016   [(set_attr "type" "imul3")])
1017
1018 (define_insn "*maclhwc"
1019   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1020         (compare:CC (plus:SI (mult:SI (sign_extend:SI
1021                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1022                                       (sign_extend:SI
1023                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1024                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1025                     (const_int 0)))
1026    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1027         (plus:SI (mult:SI (sign_extend:SI
1028                            (match_dup 1))
1029                           (sign_extend:SI
1030                            (match_dup 2)))
1031                  (match_dup 4)))]
1032   "TARGET_MULHW"
1033   "maclhw. %0, %1, %2"
1034   [(set_attr "type" "imul3")])
1035
1036 (define_insn "*maclhw"
1037   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1038         (plus:SI (mult:SI (sign_extend:SI
1039                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1040                           (sign_extend:SI
1041                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1042                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1043   "TARGET_MULHW"
1044   "maclhw %0, %1, %2"
1045   [(set_attr "type" "imul3")])
1046
1047 (define_insn "*maclhwuc"
1048   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1049         (compare:CC (plus:SI (mult:SI (zero_extend:SI
1050                                        (match_operand:HI 1 "gpc_reg_operand" "%r"))
1051                                       (zero_extend:SI
1052                                        (match_operand:HI 2 "gpc_reg_operand" "r")))
1053                              (match_operand:SI 4 "gpc_reg_operand" "0"))
1054                     (const_int 0)))
1055    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1056         (plus:SI (mult:SI (zero_extend:SI
1057                            (match_dup 1))
1058                           (zero_extend:SI
1059                            (match_dup 2)))
1060                  (match_dup 4)))]
1061   "TARGET_MULHW"
1062   "maclhwu. %0, %1, %2"
1063   [(set_attr "type" "imul3")])
1064
1065 (define_insn "*maclhwu"
1066   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1067         (plus:SI (mult:SI (zero_extend:SI
1068                            (match_operand:HI 1 "gpc_reg_operand" "%r"))
1069                           (zero_extend:SI
1070                            (match_operand:HI 2 "gpc_reg_operand" "r")))
1071                  (match_operand:SI 3 "gpc_reg_operand" "0")))]
1072   "TARGET_MULHW"
1073   "maclhwu %0, %1, %2"
1074   [(set_attr "type" "imul3")])
1075
1076 (define_insn "*nmacchwc"
1077   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1078         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1079                               (mult:SI (ashiftrt:SI
1080                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1081                                         (const_int 16))
1082                                        (sign_extend:SI
1083                                         (match_operand:HI 1 "gpc_reg_operand" "r"))))
1084                     (const_int 0)))
1085    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1086         (minus:SI (match_dup 4)
1087                   (mult:SI (ashiftrt:SI
1088                             (match_dup 2)
1089                             (const_int 16))
1090                            (sign_extend:SI
1091                             (match_dup 1)))))]
1092   "TARGET_MULHW"
1093   "nmacchw. %0, %1, %2"
1094   [(set_attr "type" "imul3")])
1095
1096 (define_insn "*nmacchw"
1097   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1098         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1099                   (mult:SI (ashiftrt:SI
1100                             (match_operand:SI 2 "gpc_reg_operand" "r")
1101                             (const_int 16))
1102                            (sign_extend:SI
1103                             (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1104   "TARGET_MULHW"
1105   "nmacchw %0, %1, %2"
1106   [(set_attr "type" "imul3")])
1107
1108 (define_insn "*nmachhwc"
1109   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1110         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1111                               (mult:SI (ashiftrt:SI
1112                                         (match_operand:SI 1 "gpc_reg_operand" "%r")
1113                                         (const_int 16))
1114                                        (ashiftrt:SI
1115                                         (match_operand:SI 2 "gpc_reg_operand" "r")
1116                                         (const_int 16))))
1117                     (const_int 0)))
1118    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1119         (minus:SI (match_dup 4)
1120                   (mult:SI (ashiftrt:SI
1121                             (match_dup 1)
1122                             (const_int 16))
1123                            (ashiftrt:SI
1124                             (match_dup 2)
1125                             (const_int 16)))))]
1126   "TARGET_MULHW"
1127   "nmachhw. %0, %1, %2"
1128   [(set_attr "type" "imul3")])
1129
1130 (define_insn "*nmachhw"
1131   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1132         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1133                   (mult:SI (ashiftrt:SI
1134                             (match_operand:SI 1 "gpc_reg_operand" "%r")
1135                             (const_int 16))
1136                            (ashiftrt:SI
1137                             (match_operand:SI 2 "gpc_reg_operand" "r")
1138                             (const_int 16)))))]
1139   "TARGET_MULHW"
1140   "nmachhw %0, %1, %2"
1141   [(set_attr "type" "imul3")])
1142
1143 (define_insn "*nmaclhwc"
1144   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1145         (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1146                               (mult:SI (sign_extend:SI
1147                                         (match_operand:HI 1 "gpc_reg_operand" "%r"))
1148                                        (sign_extend:SI
1149                                         (match_operand:HI 2 "gpc_reg_operand" "r"))))
1150                     (const_int 0)))
1151    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1152         (minus:SI (match_dup 4)
1153                   (mult:SI (sign_extend:SI
1154                             (match_dup 1))
1155                            (sign_extend:SI
1156                             (match_dup 2)))))]
1157   "TARGET_MULHW"
1158   "nmaclhw. %0, %1, %2"
1159   [(set_attr "type" "imul3")])
1160
1161 (define_insn "*nmaclhw"
1162   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1163         (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1164                   (mult:SI (sign_extend:SI
1165                             (match_operand:HI 1 "gpc_reg_operand" "%r"))
1166                            (sign_extend:SI
1167                             (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1168   "TARGET_MULHW"
1169   "nmaclhw %0, %1, %2"
1170   [(set_attr "type" "imul3")])
1171
1172 (define_insn "*mulchwc"
1173   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1174         (compare:CC (mult:SI (ashiftrt:SI
1175                               (match_operand:SI 2 "gpc_reg_operand" "r")
1176                               (const_int 16))
1177                              (sign_extend:SI
1178                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1179                     (const_int 0)))
1180    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1181         (mult:SI (ashiftrt:SI
1182                   (match_dup 2)
1183                   (const_int 16))
1184                  (sign_extend:SI
1185                   (match_dup 1))))]
1186   "TARGET_MULHW"
1187   "mulchw. %0, %1, %2"
1188   [(set_attr "type" "imul3")])
1189
1190 (define_insn "*mulchw"
1191   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1192         (mult:SI (ashiftrt:SI
1193                   (match_operand:SI 2 "gpc_reg_operand" "r")
1194                   (const_int 16))
1195                  (sign_extend:SI
1196                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1197   "TARGET_MULHW"
1198   "mulchw %0, %1, %2"
1199   [(set_attr "type" "imul3")])
1200
1201 (define_insn "*mulchwuc"
1202   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1203         (compare:CC (mult:SI (lshiftrt:SI
1204                               (match_operand:SI 2 "gpc_reg_operand" "r")
1205                               (const_int 16))
1206                              (zero_extend:SI
1207                               (match_operand:HI 1 "gpc_reg_operand" "r")))
1208                     (const_int 0)))
1209    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1210         (mult:SI (lshiftrt:SI
1211                   (match_dup 2)
1212                   (const_int 16))
1213                  (zero_extend:SI
1214                   (match_dup 1))))]
1215   "TARGET_MULHW"
1216   "mulchwu. %0, %1, %2"
1217   [(set_attr "type" "imul3")])
1218
1219 (define_insn "*mulchwu"
1220   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1221         (mult:SI (lshiftrt:SI
1222                   (match_operand:SI 2 "gpc_reg_operand" "r")
1223                   (const_int 16))
1224                  (zero_extend:SI
1225                   (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1226   "TARGET_MULHW"
1227   "mulchwu %0, %1, %2"
1228   [(set_attr "type" "imul3")])
1229
1230 (define_insn "*mulhhwc"
1231   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1232         (compare:CC (mult:SI (ashiftrt:SI
1233                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1234                               (const_int 16))
1235                              (ashiftrt:SI
1236                               (match_operand:SI 2 "gpc_reg_operand" "r")
1237                               (const_int 16)))
1238                     (const_int 0)))
1239    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1240         (mult:SI (ashiftrt:SI
1241                   (match_dup 1)
1242                   (const_int 16))
1243                  (ashiftrt:SI
1244                   (match_dup 2)
1245                   (const_int 16))))]
1246   "TARGET_MULHW"
1247   "mulhhw. %0, %1, %2"
1248   [(set_attr "type" "imul3")])
1249
1250 (define_insn "*mulhhw"
1251   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1252         (mult:SI (ashiftrt:SI
1253                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1254                   (const_int 16))
1255                  (ashiftrt:SI
1256                   (match_operand:SI 2 "gpc_reg_operand" "r")
1257                   (const_int 16))))]
1258   "TARGET_MULHW"
1259   "mulhhw %0, %1, %2"
1260   [(set_attr "type" "imul3")])
1261
1262 (define_insn "*mulhhwuc"
1263   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1264         (compare:CC (mult:SI (lshiftrt:SI
1265                               (match_operand:SI 1 "gpc_reg_operand" "%r")
1266                               (const_int 16))
1267                              (lshiftrt:SI
1268                               (match_operand:SI 2 "gpc_reg_operand" "r")
1269                               (const_int 16)))
1270                     (const_int 0)))
1271    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1272         (mult:SI (lshiftrt:SI
1273                   (match_dup 1)
1274                   (const_int 16))
1275                  (lshiftrt:SI
1276                   (match_dup 2)
1277                   (const_int 16))))]
1278   "TARGET_MULHW"
1279   "mulhhwu. %0, %1, %2"
1280   [(set_attr "type" "imul3")])
1281
1282 (define_insn "*mulhhwu"
1283   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1284         (mult:SI (lshiftrt:SI
1285                   (match_operand:SI 1 "gpc_reg_operand" "%r")
1286                   (const_int 16))
1287                  (lshiftrt:SI
1288                   (match_operand:SI 2 "gpc_reg_operand" "r")
1289                   (const_int 16))))]
1290   "TARGET_MULHW"
1291   "mulhhwu %0, %1, %2"
1292   [(set_attr "type" "imul3")])
1293
1294 (define_insn "*mullhwc"
1295   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1296         (compare:CC (mult:SI (sign_extend:SI
1297                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1298                              (sign_extend:SI
1299                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1300                     (const_int 0)))
1301    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1302         (mult:SI (sign_extend:SI
1303                   (match_dup 1))
1304                  (sign_extend:SI
1305                   (match_dup 2))))]
1306   "TARGET_MULHW"
1307   "mullhw. %0, %1, %2"
1308   [(set_attr "type" "imul3")])
1309
1310 (define_insn "*mullhw"
1311   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1312         (mult:SI (sign_extend:SI
1313                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1314                  (sign_extend:SI
1315                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1316   "TARGET_MULHW"
1317   "mullhw %0, %1, %2"
1318   [(set_attr "type" "imul3")])
1319
1320 (define_insn "*mullhwuc"
1321   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1322         (compare:CC (mult:SI (zero_extend:SI
1323                               (match_operand:HI 1 "gpc_reg_operand" "%r"))
1324                              (zero_extend:SI
1325                               (match_operand:HI 2 "gpc_reg_operand" "r")))
1326                     (const_int 0)))
1327    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1328         (mult:SI (zero_extend:SI
1329                   (match_dup 1))
1330                  (zero_extend:SI
1331                   (match_dup 2))))]
1332   "TARGET_MULHW"
1333   "mullhwu. %0, %1, %2"
1334   [(set_attr "type" "imul3")])
1335
1336 (define_insn "*mullhwu"
1337   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1338         (mult:SI (zero_extend:SI
1339                   (match_operand:HI 1 "gpc_reg_operand" "%r"))
1340                  (zero_extend:SI
1341                   (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1342   "TARGET_MULHW"
1343   "mullhwu %0, %1, %2"
1344   [(set_attr "type" "imul3")])
1345 \f
1346 (define_split
1347   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1348         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" ""))
1349                     (const_int 0)))
1350    (set (match_operand:SI 0 "gpc_reg_operand" "")
1351         (sign_extend:SI (match_dup 1)))]
1352   "reload_completed"
1353   [(set (match_dup 0)
1354         (sign_extend:SI (match_dup 1)))
1355    (set (match_dup 2)
1356         (compare:CC (match_dup 0)
1357                     (const_int 0)))]
1358   "")
1359
1360 ;; Fixed-point arithmetic insns.
1361
1362 (define_expand "add<mode>3"
1363   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1364         (plus:SDI (match_operand:SDI 1 "gpc_reg_operand" "")
1365                   (match_operand:SDI 2 "reg_or_add_cint_operand" "")))]
1366   ""
1367   "
1368 {
1369   if (<MODE>mode == DImode && ! TARGET_POWERPC64)
1370     {
1371       if (non_short_cint_operand (operands[2], DImode))
1372         FAIL;
1373     }
1374   else if (GET_CODE (operands[2]) == CONST_INT
1375            && ! add_operand (operands[2], <MODE>mode))
1376     {
1377       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
1378                  ? operands[0] : gen_reg_rtx (<MODE>mode));
1379
1380       HOST_WIDE_INT val = INTVAL (operands[2]);
1381       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1382       HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1383
1384       if (<MODE>mode == DImode && !CONST_OK_FOR_LETTER_P (rest, 'L'))
1385         FAIL;
1386
1387       /* The ordering here is important for the prolog expander.
1388          When space is allocated from the stack, adding 'low' first may
1389          produce a temporary deallocation (which would be bad).  */
1390       emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1391       emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1392       DONE;
1393     }
1394 }")
1395
1396 ;; Discourage ai/addic because of carry but provide it in an alternative
1397 ;; allowing register zero as source.
1398 (define_insn "*add<mode>3_internal1"
1399   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,?r,r")
1400         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,r,b")
1401                   (match_operand:GPR 2 "add_operand" "r,I,I,L")))]
1402   ""
1403   "@
1404    {cax|add} %0,%1,%2
1405    {cal %0,%2(%1)|addi %0,%1,%2}
1406    {ai|addic} %0,%1,%2
1407    {cau|addis} %0,%1,%v2"
1408   [(set_attr "length" "4,4,4,4")])
1409
1410 (define_insn "addsi3_high"
1411   [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1412         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1413                  (high:SI (match_operand 2 "" ""))))]
1414   "TARGET_MACHO && !TARGET_64BIT"
1415   "{cau|addis} %0,%1,ha16(%2)"
1416   [(set_attr "length" "4")])
1417
1418 (define_insn "*add<mode>3_internal2"
1419   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,?y,?y")
1420         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1421                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1422                     (const_int 0)))
1423    (clobber (match_scratch:P 3 "=r,r,r,r"))]
1424   ""
1425   "@
1426    {cax.|add.} %3,%1,%2
1427    {ai.|addic.} %3,%1,%2
1428    #
1429    #"
1430   [(set_attr "type" "fast_compare,compare,compare,compare")
1431    (set_attr "length" "4,4,8,8")])
1432
1433 (define_split
1434   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1435         (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1436                               (match_operand:GPR 2 "reg_or_short_operand" ""))
1437                     (const_int 0)))
1438    (clobber (match_scratch:GPR 3 ""))]
1439   "reload_completed"
1440   [(set (match_dup 3)
1441         (plus:GPR (match_dup 1)
1442                  (match_dup 2)))
1443    (set (match_dup 0)
1444         (compare:CC (match_dup 3)
1445                     (const_int 0)))]
1446   "")
1447
1448 (define_insn "*add<mode>3_internal3"
1449   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,?y,?y")
1450         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "%r,r,r,r")
1451                             (match_operand:P 2 "reg_or_short_operand" "r,I,r,I"))
1452                     (const_int 0)))
1453    (set (match_operand:P 0 "gpc_reg_operand" "=r,r,r,r")
1454         (plus:P (match_dup 1)
1455                 (match_dup 2)))]
1456   ""
1457   "@
1458    {cax.|add.} %0,%1,%2
1459    {ai.|addic.} %0,%1,%2
1460    #
1461    #"
1462   [(set_attr "type" "fast_compare,compare,compare,compare")
1463    (set_attr "length" "4,4,8,8")])
1464
1465 (define_split
1466   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1467         (compare:CC (plus:P (match_operand:P 1 "gpc_reg_operand" "")
1468                             (match_operand:P 2 "reg_or_short_operand" ""))
1469                     (const_int 0)))
1470    (set (match_operand:P 0 "gpc_reg_operand" "")
1471         (plus:P (match_dup 1) (match_dup 2)))]
1472   "reload_completed"
1473   [(set (match_dup 0)
1474         (plus:P (match_dup 1)
1475                 (match_dup 2)))
1476    (set (match_dup 3)
1477         (compare:CC (match_dup 0)
1478                     (const_int 0)))]
1479   "")
1480
1481 ;; Split an add that we can't do in one insn into two insns, each of which
1482 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
1483 ;; add should be last in case the result gets used in an address.
1484
1485 (define_split
1486   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
1487         (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
1488                   (match_operand:GPR 2 "non_add_cint_operand" "")))]
1489   ""
1490   [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1491    (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1492 "
1493 {
1494   HOST_WIDE_INT val = INTVAL (operands[2]);
1495   HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
1496   HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1497
1498   operands[4] = GEN_INT (low);
1499   if (<MODE>mode == SImode || CONST_OK_FOR_LETTER_P (rest, 'L'))
1500     operands[3] = GEN_INT (rest);
1501   else if (! no_new_pseudos)
1502     {
1503       operands[3] = gen_reg_rtx (DImode);
1504       emit_move_insn (operands[3], operands[2]);
1505       emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1506       DONE;
1507     }
1508   else
1509     FAIL;
1510 }")
1511
1512 (define_insn "one_cmpl<mode>2"
1513   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1514         (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1515   ""
1516   "nor %0,%1,%1")
1517
1518 (define_insn ""
1519   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1520         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1521                     (const_int 0)))
1522    (clobber (match_scratch:P 2 "=r,r"))]
1523   ""
1524   "@
1525    nor. %2,%1,%1
1526    #"
1527   [(set_attr "type" "compare")
1528    (set_attr "length" "4,8")])
1529
1530 (define_split
1531   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1532         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1533                     (const_int 0)))
1534    (clobber (match_scratch:P 2 ""))]
1535   "reload_completed"
1536   [(set (match_dup 2)
1537         (not:P (match_dup 1)))
1538    (set (match_dup 0)
1539         (compare:CC (match_dup 2)
1540                     (const_int 0)))]
1541   "")
1542
1543 (define_insn ""
1544   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1545         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1546                     (const_int 0)))
1547    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1548         (not:P (match_dup 1)))]
1549   ""
1550   "@
1551    nor. %0,%1,%1
1552    #"
1553   [(set_attr "type" "compare")
1554    (set_attr "length" "4,8")])
1555
1556 (define_split
1557   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
1558         (compare:CC (not:P (match_operand:P 1 "gpc_reg_operand" ""))
1559                     (const_int 0)))
1560    (set (match_operand:P 0 "gpc_reg_operand" "")
1561         (not:P (match_dup 1)))]
1562   "reload_completed"
1563   [(set (match_dup 0)
1564         (not:P (match_dup 1)))
1565    (set (match_dup 2)
1566         (compare:CC (match_dup 0)
1567                     (const_int 0)))]
1568   "")
1569
1570 (define_insn ""
1571   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1572         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
1573                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
1574   "! TARGET_POWERPC"
1575   "{sf%I1|subf%I1c} %0,%2,%1")
1576
1577 (define_insn ""
1578   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1579         (minus:GPR (match_operand:GPR 1 "reg_or_short_operand" "r,I")
1580                    (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
1581   "TARGET_POWERPC"
1582   "@
1583    subf %0,%2,%1
1584    subfic %0,%2,%1")
1585
1586 (define_insn ""
1587   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1588         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1589                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1590                     (const_int 0)))
1591    (clobber (match_scratch:SI 3 "=r,r"))]
1592   "! TARGET_POWERPC"
1593   "@
1594    {sf.|subfc.} %3,%2,%1
1595    #"
1596   [(set_attr "type" "compare")
1597    (set_attr "length" "4,8")])
1598
1599 (define_insn ""
1600   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1601         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1602                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1603                     (const_int 0)))
1604    (clobber (match_scratch:P 3 "=r,r"))]
1605   "TARGET_POWERPC"
1606   "@
1607    subf. %3,%2,%1
1608    #"
1609   [(set_attr "type" "fast_compare")
1610    (set_attr "length" "4,8")])
1611
1612 (define_split
1613   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1614         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1615                              (match_operand:P 2 "gpc_reg_operand" ""))
1616                     (const_int 0)))
1617    (clobber (match_scratch:P 3 ""))]
1618   "reload_completed"
1619   [(set (match_dup 3)
1620         (minus:P (match_dup 1)
1621                   (match_dup 2)))
1622    (set (match_dup 0)
1623         (compare:CC (match_dup 3)
1624                     (const_int 0)))]
1625   "")
1626
1627 (define_insn ""
1628   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1629         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
1630                               (match_operand:SI 2 "gpc_reg_operand" "r,r"))
1631                     (const_int 0)))
1632    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1633         (minus:SI (match_dup 1) (match_dup 2)))]
1634   "! TARGET_POWERPC"
1635   "@
1636    {sf.|subfc.} %0,%2,%1
1637    #"
1638   [(set_attr "type" "compare")
1639    (set_attr "length" "4,8")])
1640
1641 (define_insn ""
1642   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1643         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
1644                              (match_operand:P 2 "gpc_reg_operand" "r,r"))
1645                     (const_int 0)))
1646    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
1647         (minus:P (match_dup 1)
1648                   (match_dup 2)))]
1649   "TARGET_POWERPC"
1650   "@
1651    subf. %0,%2,%1
1652    #"
1653   [(set_attr "type" "fast_compare")
1654    (set_attr "length" "4,8")])
1655
1656 (define_split
1657   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1658         (compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "")
1659                              (match_operand:P 2 "gpc_reg_operand" ""))
1660                     (const_int 0)))
1661    (set (match_operand:P 0 "gpc_reg_operand" "")
1662         (minus:P (match_dup 1)
1663                   (match_dup 2)))]
1664   "reload_completed"
1665   [(set (match_dup 0)
1666         (minus:P (match_dup 1)
1667                   (match_dup 2)))
1668    (set (match_dup 3)
1669         (compare:CC (match_dup 0)
1670                     (const_int 0)))]
1671   "")
1672
1673 (define_expand "sub<mode>3"
1674   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1675         (minus:SDI (match_operand:SDI 1 "reg_or_short_operand" "")
1676                    (match_operand:SDI 2 "reg_or_sub_cint_operand" "")))]
1677   ""
1678   "
1679 {
1680   if (GET_CODE (operands[2]) == CONST_INT)
1681     {
1682       emit_insn (gen_add<mode>3 (operands[0], operands[1],
1683                                  negate_rtx (<MODE>mode, operands[2])));
1684       DONE;
1685     }
1686 }")
1687
1688 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1689 ;; instruction and some auxiliary computations.  Then we just have a single
1690 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1691 ;; combine.
1692
1693 (define_expand "sminsi3"
1694   [(set (match_dup 3)
1695         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1696                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1697                          (const_int 0)
1698                          (minus:SI (match_dup 2) (match_dup 1))))
1699    (set (match_operand:SI 0 "gpc_reg_operand" "")
1700         (minus:SI (match_dup 2) (match_dup 3)))]
1701   "TARGET_POWER || TARGET_ISEL"
1702   "
1703 {
1704   if (TARGET_ISEL)
1705     {
1706       operands[2] = force_reg (SImode, operands[2]);
1707       rs6000_emit_minmax (operands[0], SMIN, operands[1], operands[2]);
1708       DONE;
1709     }
1710
1711   operands[3] = gen_reg_rtx (SImode);
1712 }")
1713
1714 (define_split
1715   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1716         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1717                  (match_operand:SI 2 "reg_or_short_operand" "")))
1718    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1719   "TARGET_POWER"
1720   [(set (match_dup 3)
1721         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1722                          (const_int 0)
1723                          (minus:SI (match_dup 2) (match_dup 1))))
1724    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1725   "")
1726
1727 (define_expand "smaxsi3"
1728   [(set (match_dup 3)
1729         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1730                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1731                          (const_int 0)
1732                          (minus:SI (match_dup 2) (match_dup 1))))
1733    (set (match_operand:SI 0 "gpc_reg_operand" "")
1734         (plus:SI (match_dup 3) (match_dup 1)))]
1735   "TARGET_POWER || TARGET_ISEL"
1736   "
1737 {
1738   if (TARGET_ISEL)
1739     {
1740       operands[2] = force_reg (SImode, operands[2]);
1741       rs6000_emit_minmax (operands[0], SMAX, operands[1], operands[2]);
1742       DONE;
1743     }
1744   operands[3] = gen_reg_rtx (SImode);
1745 }")
1746
1747 (define_split
1748   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1749         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1750                  (match_operand:SI 2 "reg_or_short_operand" "")))
1751    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1752   "TARGET_POWER"
1753   [(set (match_dup 3)
1754         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1755                          (const_int 0)
1756                          (minus:SI (match_dup 2) (match_dup 1))))
1757    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1758   "")
1759
1760 (define_expand "uminsi3"
1761   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1762                               (match_dup 5)))
1763    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1764                               (match_dup 5)))
1765    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1766                                        (const_int 0)
1767                                        (minus:SI (match_dup 4) (match_dup 3))))
1768    (set (match_operand:SI 0 "gpc_reg_operand" "")
1769         (minus:SI (match_dup 2) (match_dup 3)))]
1770   "TARGET_POWER || TARGET_ISEL"
1771   "
1772 {
1773   if (TARGET_ISEL)
1774     {
1775       rs6000_emit_minmax (operands[0], UMIN, operands[1], operands[2]);
1776       DONE;
1777     }
1778   operands[3] = gen_reg_rtx (SImode);
1779   operands[4] = gen_reg_rtx (SImode);
1780   operands[5] = GEN_INT (-2147483647 - 1);
1781 }")
1782
1783 (define_expand "umaxsi3"
1784   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1785                               (match_dup 5)))
1786    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1787                               (match_dup 5)))
1788    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1789                                        (const_int 0)
1790                                        (minus:SI (match_dup 4) (match_dup 3))))
1791    (set (match_operand:SI 0 "gpc_reg_operand" "")
1792         (plus:SI (match_dup 3) (match_dup 1)))]
1793   "TARGET_POWER || TARGET_ISEL"
1794   "
1795 {
1796   if (TARGET_ISEL)
1797     {
1798       rs6000_emit_minmax (operands[0], UMAX, operands[1], operands[2]);
1799       DONE;
1800     }
1801   operands[3] = gen_reg_rtx (SImode);
1802   operands[4] = gen_reg_rtx (SImode);
1803   operands[5] = GEN_INT (-2147483647 - 1);
1804 }")
1805
1806 (define_insn ""
1807   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1808         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1809                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1810                          (const_int 0)
1811                          (minus:SI (match_dup 2) (match_dup 1))))]
1812   "TARGET_POWER"
1813   "doz%I2 %0,%1,%2")
1814
1815 (define_insn ""
1816   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1817         (compare:CC
1818          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1819                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1820                           (const_int 0)
1821                           (minus:SI (match_dup 2) (match_dup 1)))
1822          (const_int 0)))
1823    (clobber (match_scratch:SI 3 "=r,r"))]
1824   "TARGET_POWER"
1825   "@
1826    doz%I2. %3,%1,%2
1827    #"
1828   [(set_attr "type" "delayed_compare")
1829    (set_attr "length" "4,8")])
1830
1831 (define_split
1832   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1833         (compare:CC
1834          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1835                               (match_operand:SI 2 "reg_or_short_operand" ""))
1836                           (const_int 0)
1837                           (minus:SI (match_dup 2) (match_dup 1)))
1838          (const_int 0)))
1839    (clobber (match_scratch:SI 3 ""))]
1840   "TARGET_POWER && reload_completed"
1841   [(set (match_dup 3)
1842         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1843                           (const_int 0)
1844                           (minus:SI (match_dup 2) (match_dup 1))))
1845    (set (match_dup 0)
1846         (compare:CC (match_dup 3)
1847                     (const_int 0)))]
1848   "")
1849
1850 (define_insn ""
1851   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1852         (compare:CC
1853          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r,r")
1854                               (match_operand:SI 2 "reg_or_short_operand" "rI,rI"))
1855                           (const_int 0)
1856                           (minus:SI (match_dup 2) (match_dup 1)))
1857          (const_int 0)))
1858    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1859         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1860                          (const_int 0)
1861                          (minus:SI (match_dup 2) (match_dup 1))))]
1862   "TARGET_POWER"
1863   "@
1864    doz%I2. %0,%1,%2
1865    #"
1866   [(set_attr "type" "delayed_compare")
1867    (set_attr "length" "4,8")])
1868
1869 (define_split
1870   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
1871         (compare:CC
1872          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "")
1873                               (match_operand:SI 2 "reg_or_short_operand" ""))
1874                           (const_int 0)
1875                           (minus:SI (match_dup 2) (match_dup 1)))
1876          (const_int 0)))
1877    (set (match_operand:SI 0 "gpc_reg_operand" "")
1878         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1879                          (const_int 0)
1880                          (minus:SI (match_dup 2) (match_dup 1))))]
1881   "TARGET_POWER && reload_completed"
1882   [(set (match_dup 0)
1883         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1884                          (const_int 0)
1885                          (minus:SI (match_dup 2) (match_dup 1))))
1886    (set (match_dup 3)
1887         (compare:CC (match_dup 0)
1888                     (const_int 0)))]
1889   "")
1890
1891 ;; We don't need abs with condition code because such comparisons should
1892 ;; never be done.
1893 (define_expand "abssi2"
1894   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1895         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1896   ""
1897   "
1898 {
1899   if (TARGET_ISEL)
1900     {
1901       emit_insn (gen_abssi2_isel (operands[0], operands[1]));
1902       DONE;
1903     }
1904   else if (! TARGET_POWER)
1905     {
1906       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1907       DONE;
1908     }
1909 }")
1910
1911 (define_insn "*abssi2_power"
1912   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1913         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1914   "TARGET_POWER"
1915   "abs %0,%1")
1916
1917 (define_insn_and_split "abssi2_isel"
1918   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1919         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "b")))
1920    (clobber (match_scratch:SI 2 "=&b"))
1921    (clobber (match_scratch:CC 3 "=y"))]
1922   "TARGET_ISEL"
1923   "#"
1924   "&& reload_completed"
1925   [(set (match_dup 2) (neg:SI (match_dup 1)))
1926    (set (match_dup 3)
1927         (compare:CC (match_dup 1)
1928                     (const_int 0)))
1929    (set (match_dup 0)
1930         (if_then_else:SI (ge (match_dup 3)
1931                              (const_int 0))
1932                          (match_dup 1)
1933                          (match_dup 2)))]
1934   "")
1935
1936 (define_insn_and_split "abssi2_nopower"
1937   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1938         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1939    (clobber (match_scratch:SI 2 "=&r,&r"))]
1940   "! TARGET_POWER && ! TARGET_ISEL"
1941   "#"
1942   "&& reload_completed"
1943   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1944    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1945    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1946   "")
1947
1948 (define_insn "*nabs_power"
1949   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1950         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
1951   "TARGET_POWER"
1952   "nabs %0,%1")
1953
1954 (define_insn_and_split "*nabs_nopower"
1955   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1956         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1957    (clobber (match_scratch:SI 2 "=&r,&r"))]
1958   "! TARGET_POWER"
1959   "#"
1960   "&& reload_completed"
1961   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1962    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1963    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
1964   "")
1965
1966 (define_expand "neg<mode>2"
1967   [(set (match_operand:SDI 0 "gpc_reg_operand" "")
1968         (neg:SDI (match_operand:SDI 1 "gpc_reg_operand" "")))]
1969   ""
1970   "")
1971
1972 (define_insn "*neg<mode>2_internal"
1973   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
1974         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
1975   ""
1976   "neg %0,%1")
1977
1978 (define_insn ""
1979   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
1980         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
1981                     (const_int 0)))
1982    (clobber (match_scratch:P 2 "=r,r"))]
1983   ""
1984   "@
1985    neg. %2,%1
1986    #"
1987   [(set_attr "type" "fast_compare")
1988    (set_attr "length" "4,8")])
1989
1990 (define_split
1991   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
1992         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
1993                     (const_int 0)))
1994    (clobber (match_scratch:P 2 ""))]
1995   "reload_completed"
1996   [(set (match_dup 2)
1997         (neg:P (match_dup 1)))
1998    (set (match_dup 0)
1999         (compare:CC (match_dup 2)
2000                     (const_int 0)))]
2001   "")
2002
2003 (define_insn ""
2004   [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2005         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" "r,r"))
2006                     (const_int 0)))
2007    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2008         (neg:P (match_dup 1)))]
2009   ""
2010   "@
2011    neg. %0,%1
2012    #"
2013   [(set_attr "type" "fast_compare")
2014    (set_attr "length" "4,8")])
2015
2016 (define_split
2017   [(set (match_operand:CC 2 "cc_reg_not_cr0_operand" "")
2018         (compare:CC (neg:P (match_operand:P 1 "gpc_reg_operand" ""))
2019                     (const_int 0)))
2020    (set (match_operand:P 0 "gpc_reg_operand" "")
2021         (neg:P (match_dup 1)))]
2022   "reload_completed"
2023   [(set (match_dup 0)
2024         (neg:P (match_dup 1)))
2025    (set (match_dup 2)
2026         (compare:CC (match_dup 0)
2027                     (const_int 0)))]
2028   "")
2029
2030 (define_insn "clz<mode>2"
2031   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2032         (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2033   ""
2034   "{cntlz|cntlz<wd>} %0,%1")
2035
2036 (define_expand "ctz<mode>2"
2037   [(set (match_dup 2)
2038         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))
2039    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2040                                           (match_dup 2)))
2041               (clobber (scratch:CC))])
2042    (set (match_dup 4) (clz:GPR (match_dup 3)))
2043    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2044         (minus:GPR (match_dup 5) (match_dup 4)))]
2045   ""
2046   {
2047      operands[2] = gen_reg_rtx (<MODE>mode);
2048      operands[3] = gen_reg_rtx (<MODE>mode);
2049      operands[4] = gen_reg_rtx (<MODE>mode);
2050      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
2051   })
2052
2053 (define_expand "ffs<mode>2"
2054   [(set (match_dup 2)
2055         (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))
2056    (parallel [(set (match_dup 3) (and:GPR (match_dup 1)
2057                                           (match_dup 2)))
2058               (clobber (scratch:CC))])
2059    (set (match_dup 4) (clz:GPR (match_dup 3)))
2060    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2061         (minus:GPR (match_dup 5) (match_dup 4)))]
2062   ""
2063   {
2064      operands[2] = gen_reg_rtx (<MODE>mode);
2065      operands[3] = gen_reg_rtx (<MODE>mode);
2066      operands[4] = gen_reg_rtx (<MODE>mode);
2067      operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
2068   })
2069
2070 (define_expand "popcount<mode>2"
2071   [(set (match_dup 2)
2072         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2073                      UNSPEC_POPCNTB))
2074    (set (match_dup 3)
2075         (mult:GPR (match_dup 2) (match_dup 4)))
2076    (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2077         (lshiftrt:GPR (match_dup 3) (match_dup 5)))]
2078   "TARGET_POPCNTB"
2079   {
2080     operands[2] = gen_reg_rtx (<MODE>mode);
2081     operands[3] = gen_reg_rtx (<MODE>mode);
2082     operands[4] = force_reg (<MODE>mode,
2083                              <MODE>mode == SImode
2084                              ? GEN_INT (0x01010101)
2085                              : GEN_INT ((HOST_WIDE_INT)
2086                                         0x01010101 << 32 | 0x01010101));
2087     operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 8);
2088   })
2089
2090 (define_insn "popcntb<mode>2"
2091   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2092         (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2093                      UNSPEC_POPCNTB))]
2094   "TARGET_POPCNTB"
2095   "popcntb %0,%1")
2096
2097 (define_expand "mulsi3"
2098   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2099    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2100    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
2101   ""
2102   "
2103 {
2104   if (TARGET_POWER)
2105     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
2106   else
2107     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
2108   DONE;
2109 }")
2110
2111 (define_insn "mulsi3_mq"
2112   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2113         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2114                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
2115    (clobber (match_scratch:SI 3 "=q,q"))]
2116   "TARGET_POWER"
2117   "@
2118    {muls|mullw} %0,%1,%2
2119    {muli|mulli} %0,%1,%2"
2120    [(set (attr "type")
2121       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2122                 (const_string "imul3")
2123              (match_operand:SI 2 "short_cint_operand" "")
2124                 (const_string "imul2")]
2125         (const_string "imul")))])
2126
2127 (define_insn "mulsi3_no_mq"
2128   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2129         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2130                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
2131   "! TARGET_POWER"
2132   "@
2133    {muls|mullw} %0,%1,%2
2134    {muli|mulli} %0,%1,%2"
2135    [(set (attr "type")
2136       (cond [(match_operand:SI 2 "s8bit_cint_operand" "")
2137                 (const_string "imul3")
2138              (match_operand:SI 2 "short_cint_operand" "")
2139                 (const_string "imul2")]
2140         (const_string "imul")))])
2141
2142 (define_insn "*mulsi3_mq_internal1"
2143   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2144         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2145                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2146                     (const_int 0)))
2147    (clobber (match_scratch:SI 3 "=r,r"))
2148    (clobber (match_scratch:SI 4 "=q,q"))]
2149   "TARGET_POWER"
2150   "@
2151    {muls.|mullw.} %3,%1,%2
2152    #"
2153   [(set_attr "type" "imul_compare")
2154    (set_attr "length" "4,8")])
2155
2156 (define_split
2157   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2158         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2159                              (match_operand:SI 2 "gpc_reg_operand" ""))
2160                     (const_int 0)))
2161    (clobber (match_scratch:SI 3 ""))
2162    (clobber (match_scratch:SI 4 ""))]
2163   "TARGET_POWER && reload_completed"
2164   [(parallel [(set (match_dup 3)
2165         (mult:SI (match_dup 1) (match_dup 2)))
2166    (clobber (match_dup 4))])
2167    (set (match_dup 0)
2168         (compare:CC (match_dup 3)
2169                     (const_int 0)))]
2170   "")
2171
2172 (define_insn "*mulsi3_no_mq_internal1"
2173   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2174         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2175                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2176                     (const_int 0)))
2177    (clobber (match_scratch:SI 3 "=r,r"))]
2178   "! TARGET_POWER"
2179   "@
2180    {muls.|mullw.} %3,%1,%2
2181    #"
2182   [(set_attr "type" "imul_compare")
2183    (set_attr "length" "4,8")])
2184
2185 (define_split
2186   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2187         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2188                              (match_operand:SI 2 "gpc_reg_operand" ""))
2189                     (const_int 0)))
2190    (clobber (match_scratch:SI 3 ""))]
2191   "! TARGET_POWER && reload_completed"
2192   [(set (match_dup 3)
2193         (mult:SI (match_dup 1) (match_dup 2)))
2194    (set (match_dup 0)
2195         (compare:CC (match_dup 3)
2196                     (const_int 0)))]
2197   "")
2198
2199 (define_insn "*mulsi3_mq_internal2"
2200   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2201         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2202                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2203                     (const_int 0)))
2204    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2205         (mult:SI (match_dup 1) (match_dup 2)))
2206    (clobber (match_scratch:SI 4 "=q,q"))]
2207   "TARGET_POWER"
2208   "@
2209    {muls.|mullw.} %0,%1,%2
2210    #"
2211   [(set_attr "type" "imul_compare")
2212    (set_attr "length" "4,8")])
2213
2214 (define_split
2215   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2216         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2217                              (match_operand:SI 2 "gpc_reg_operand" ""))
2218                     (const_int 0)))
2219    (set (match_operand:SI 0 "gpc_reg_operand" "")
2220         (mult:SI (match_dup 1) (match_dup 2)))
2221    (clobber (match_scratch:SI 4 ""))]
2222   "TARGET_POWER && reload_completed"
2223   [(parallel [(set (match_dup 0)
2224         (mult:SI (match_dup 1) (match_dup 2)))
2225    (clobber (match_dup 4))])
2226    (set (match_dup 3)
2227         (compare:CC (match_dup 0)
2228                     (const_int 0)))]
2229   "")
2230
2231 (define_insn "*mulsi3_no_mq_internal2"
2232   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2233         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
2234                              (match_operand:SI 2 "gpc_reg_operand" "r,r"))
2235                     (const_int 0)))
2236    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2237         (mult:SI (match_dup 1) (match_dup 2)))]
2238   "! TARGET_POWER"
2239   "@
2240    {muls.|mullw.} %0,%1,%2
2241    #"
2242   [(set_attr "type" "imul_compare")
2243    (set_attr "length" "4,8")])
2244
2245 (define_split
2246   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2247         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "")
2248                              (match_operand:SI 2 "gpc_reg_operand" ""))
2249                     (const_int 0)))
2250    (set (match_operand:SI 0 "gpc_reg_operand" "")
2251         (mult:SI (match_dup 1) (match_dup 2)))]
2252   "! TARGET_POWER && reload_completed"
2253   [(set (match_dup 0)
2254         (mult:SI (match_dup 1) (match_dup 2)))
2255    (set (match_dup 3)
2256         (compare:CC (match_dup 0)
2257                     (const_int 0)))]
2258   "")
2259
2260 ;; Operand 1 is divided by operand 2; quotient goes to operand
2261 ;; 0 and remainder to operand 3.
2262 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
2263
2264 (define_expand "divmodsi4"
2265   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2266                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
2267                            (match_operand:SI 2 "gpc_reg_operand" "")))
2268               (set (match_operand:SI 3 "register_operand" "")
2269                    (mod:SI (match_dup 1) (match_dup 2)))])]
2270   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
2271   "
2272 {
2273   if (! TARGET_POWER && ! TARGET_POWERPC)
2274     {
2275       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2276       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2277       emit_insn (gen_divss_call ());
2278       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2279       emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2280       DONE;
2281     }
2282 }")
2283
2284 (define_insn "*divmodsi4_internal"
2285   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2286         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2287                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2288    (set (match_operand:SI 3 "register_operand" "=q")
2289         (mod:SI (match_dup 1) (match_dup 2)))]
2290   "TARGET_POWER"
2291   "divs %0,%1,%2"
2292   [(set_attr "type" "idiv")])
2293
2294 (define_expand "udiv<mode>3"
2295   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2296         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2297                   (match_operand:GPR 2 "gpc_reg_operand" "")))]
2298   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
2299   "
2300 {
2301   if (! TARGET_POWER && ! TARGET_POWERPC)
2302     {
2303       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2304       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2305       emit_insn (gen_quous_call ());
2306       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2307       DONE;
2308     }
2309   else if (TARGET_POWER)
2310     {
2311       emit_insn (gen_udivsi3_mq (operands[0], operands[1], operands[2]));
2312       DONE;
2313     }
2314 }")
2315
2316 (define_insn "udivsi3_mq"
2317   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2318         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2319                  (match_operand:SI 2 "gpc_reg_operand" "r")))
2320    (clobber (match_scratch:SI 3 "=q"))]
2321   "TARGET_POWERPC && TARGET_POWER"
2322   "divwu %0,%1,%2"
2323   [(set_attr "type" "idiv")])
2324
2325 (define_insn "*udivsi3_no_mq"
2326   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2327         (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2328                   (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2329   "TARGET_POWERPC && ! TARGET_POWER"
2330   "div<wd>u %0,%1,%2"
2331   [(set_attr "type" "idiv")])
2332
2333 ;; For powers of two we can do srai/aze for divide and then adjust for
2334 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
2335 ;; used; for PowerPC, force operands into register and do a normal divide;
2336 ;; for AIX common-mode, use quoss call on register operands.
2337 (define_expand "div<mode>3"
2338   [(set (match_operand:GPR 0 "gpc_reg_operand" "")
2339         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2340                  (match_operand:GPR 2 "reg_or_cint_operand" "")))]
2341   ""
2342   "
2343 {
2344   if (GET_CODE (operands[2]) == CONST_INT
2345       && INTVAL (operands[2]) > 0
2346       && exact_log2 (INTVAL (operands[2])) >= 0)
2347     ;
2348   else if (TARGET_POWERPC)
2349     {
2350       operands[2] = force_reg (SImode, operands[2]);
2351       if (TARGET_POWER)
2352         {
2353           emit_insn (gen_divsi3_mq (operands[0], operands[1], operands[2]));
2354           DONE;
2355         }
2356     }
2357   else if (TARGET_POWER)
2358     FAIL;
2359   else
2360     {
2361       emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2362       emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2363       emit_insn (gen_quoss_call ());
2364       emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2365       DONE;
2366     }
2367 }")
2368
2369 (define_insn "divsi3_mq"
2370   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2371         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2372                 (match_operand:SI 2 "gpc_reg_operand" "r")))
2373    (clobber (match_scratch:SI 3 "=q"))]
2374   "TARGET_POWERPC && TARGET_POWER"
2375   "divw %0,%1,%2"
2376   [(set_attr "type" "idiv")])
2377
2378 (define_insn "*div<mode>3_no_mq"
2379   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2380         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2381                  (match_operand:GPR 2 "gpc_reg_operand" "r")))]
2382   "TARGET_POWERPC && ! TARGET_POWER"
2383   "div<wd> %0,%1,%2"
2384   [(set_attr "type" "idiv")])
2385
2386 (define_expand "mod<mode>3"
2387   [(use (match_operand:GPR 0 "gpc_reg_operand" ""))
2388    (use (match_operand:GPR 1 "gpc_reg_operand" ""))
2389    (use (match_operand:GPR 2 "reg_or_cint_operand" ""))]
2390   ""
2391   "
2392 {
2393   int i;
2394   rtx temp1;
2395   rtx temp2;
2396
2397   if (GET_CODE (operands[2]) != CONST_INT
2398       || INTVAL (operands[2]) <= 0
2399       || (i = exact_log2 (INTVAL (operands[2]))) < 0)
2400     FAIL;
2401
2402   temp1 = gen_reg_rtx (<MODE>mode);
2403   temp2 = gen_reg_rtx (<MODE>mode);
2404
2405   emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
2406   emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
2407   emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
2408   DONE;
2409 }")
2410
2411 (define_insn ""
2412   [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2413         (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2414                  (match_operand:GPR 2 "exact_log2_cint_operand" "N")))]
2415   ""
2416   "{srai|sra<wd>i} %0,%1,%p2\;{aze|addze} %0,%0"
2417   [(set_attr "type" "two")
2418    (set_attr "length" "8")])
2419
2420 (define_insn ""
2421   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2422         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2423                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2424                     (const_int 0)))
2425    (clobber (match_scratch:P 3 "=r,r"))]
2426   ""
2427   "@
2428    {srai|sra<wd>i} %3,%1,%p2\;{aze.|addze.} %3,%3
2429    #"
2430   [(set_attr "type" "compare")
2431    (set_attr "length" "8,12")])
2432
2433 (define_split
2434   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2435         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2436                              (match_operand:GPR 2 "exact_log2_cint_operand"
2437                               ""))
2438                     (const_int 0)))
2439    (clobber (match_scratch:GPR 3 ""))]
2440   "reload_completed"
2441   [(set (match_dup 3)
2442         (div:<MODE> (match_dup 1) (match_dup 2)))
2443    (set (match_dup 0)
2444         (compare:CC (match_dup 3)
2445                     (const_int 0)))]
2446   "")
2447
2448 (define_insn ""
2449   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2450         (compare:CC (div:P (match_operand:P 1 "gpc_reg_operand" "r,r")
2451                            (match_operand:P 2 "exact_log2_cint_operand" "N,N"))
2452                     (const_int 0)))
2453    (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2454         (div:P (match_dup 1) (match_dup 2)))]
2455   ""
2456   "@
2457    {srai|sra<wd>i} %0,%1,%p2\;{aze.|addze.} %0,%0
2458    #"
2459   [(set_attr "type" "compare")
2460    (set_attr "length" "8,12")])
2461
2462 (define_split
2463   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2464         (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2465                              (match_operand:GPR 2 "exact_log2_cint_operand"
2466                               ""))
2467                     (const_int 0)))
2468    (set (match_operand:GPR 0 "gpc_reg_operand" "")
2469         (div:GPR (match_dup 1) (match_dup 2)))]
2470   "reload_completed"
2471   [(set (match_dup 0)
2472         (div:<MODE> (match_dup 1) (match_dup 2)))
2473    (set (match_dup 3)
2474         (compare:CC (match_dup 0)
2475                     (const_int 0)))]
2476   "")
2477
2478 (define_insn ""
2479   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2480         (udiv:SI
2481          (plus:DI (ashift:DI
2482                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
2483                    (const_int 32))
2484                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
2485          (match_operand:SI 3 "gpc_reg_operand" "r")))
2486    (set (match_operand:SI 2 "register_operand" "=*q")
2487         (umod:SI
2488          (plus:DI (ashift:DI
2489                    (zero_extend:DI (match_dup 1)) (const_int 32))
2490                   (zero_extend:DI (match_dup 4)))
2491          (match_dup 3)))]
2492   "TARGET_POWER"
2493   "div %0,%1,%3"
2494   [(set_attr "type" "idiv")])
2495
2496 ;; To do unsigned divide we handle the cases of the divisor looking like a
2497 ;; negative number.  If it is a constant that is less than 2**31, we don't
2498 ;; have to worry about the branches.  So make a few subroutines here.
2499 ;;
2500 ;; First comes the normal case.
2501 (define_expand "udivmodsi4_normal"
2502   [(set (match_dup 4) (const_int 0))
2503    (parallel [(set (match_operand:SI 0 "" "")
2504                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2505                                                 (const_int 32))
2506                                      (zero_extend:DI (match_operand:SI 1 "" "")))
2507                             (match_operand:SI 2 "" "")))
2508               (set (match_operand:SI 3 "" "")
2509                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
2510                                                 (const_int 32))
2511                                      (zero_extend:DI (match_dup 1)))
2512                             (match_dup 2)))])]
2513   "TARGET_POWER"
2514   "
2515 { operands[4] = gen_reg_rtx (SImode); }")
2516
2517 ;; This handles the branches.
2518 (define_expand "udivmodsi4_tests"
2519   [(set (match_operand:SI 0 "" "") (const_int 0))
2520    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
2521    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
2522    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
2523                            (label_ref (match_operand:SI 4 "" "")) (pc)))
2524    (set (match_dup 0) (const_int 1))
2525    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
2526    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
2527    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
2528                            (label_ref (match_dup 4)) (pc)))]
2529   "TARGET_POWER"
2530   "
2531 { operands[5] = gen_reg_rtx (CCUNSmode);
2532   operands[6] = gen_reg_rtx (CCmode);
2533 }")
2534
2535 (define_expand "udivmodsi4"
2536   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
2537                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
2538                             (match_operand:SI 2 "reg_or_cint_operand" "")))
2539               (set (match_operand:SI 3 "gpc_reg_operand" "")
2540                    (umod:SI (match_dup 1) (match_dup 2)))])]
2541   ""
2542   "
2543 {
2544   rtx label = 0;
2545
2546   if (! TARGET_POWER)
2547     {
2548       if (! TARGET_POWERPC)
2549         {
2550           emit_move_insn (gen_rtx_REG (SImode, 3), operands[1]);
2551           emit_move_insn (gen_rtx_REG (SImode, 4), operands[2]);
2552           emit_insn (gen_divus_call ());
2553           emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
2554           emit_move_insn (operands[3], gen_rtx_REG (SImode, 4));
2555           DONE;
2556         }
2557       else
2558         FAIL;
2559     }
2560
2561   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
2562     {
2563       operands[2] = force_reg (SImode, operands[2]);
2564       label = gen_label_rtx ();
2565       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
2566                                   operands[3], label));
2567     }
2568   else
2569     operands[2] = force_reg (SImode, operands[2]);
2570
2571   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
2572                                operands[3]));
2573   if (label)
2574     emit_label (label);
2575
2576   DONE;
2577 }")
2578
2579 ;; AIX architecture-independent common-mode multiply (DImode),
2580 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
2581 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
2582 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
2583 ;; assumed unused if generating common-mode, so ignore.
2584 (define_insn "mulh_call"
2585   [(set (reg:SI 3)
2586         (truncate:SI
2587          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
2588                                (sign_extend:DI (reg:SI 4)))
2589                       (const_int 32))))
2590    (clobber (match_scratch:SI 0 "=l"))]
2591   "! TARGET_POWER && ! TARGET_POWERPC"
2592   "bla __mulh"
2593   [(set_attr "type" "imul")])
2594
2595 (define_insn "mull_call"
2596   [(set (reg:DI 3)
2597         (mult:DI (sign_extend:DI (reg:SI 3))
2598                  (sign_extend:DI (reg:SI 4))))
2599    (clobber (match_scratch:SI 0 "=l"))
2600    (clobber (reg:SI 0))]
2601   "! TARGET_POWER && ! TARGET_POWERPC"
2602   "bla __mull"
2603   [(set_attr "type" "imul")])
2604
2605 (define_insn "divss_call"
2606   [(set (reg:SI 3)
2607         (div:SI (reg:SI 3) (reg:SI 4)))
2608    (set (reg:SI 4)
2609         (mod:SI (reg:SI 3) (reg:SI 4)))
2610    (clobber (match_scratch:SI 0 "=l"))
2611    (clobber (reg:SI 0))]
2612   "! TARGET_POWER && ! TARGET_POWERPC"
2613   "bla __divss"
2614   [(set_attr "type" "idiv")])
2615
2616 (define_insn "divus_call"
2617   [(set (reg:SI 3)
2618         (udiv:SI (reg:SI 3) (reg:SI 4)))
2619    (set (reg:SI 4)
2620         (umod:SI (reg:SI 3) (reg:SI 4)))
2621    (clobber (match_scratch:SI 0 "=l"))
2622    (clobber (reg:SI 0))
2623    (clobber (match_scratch:CC 1 "=x"))
2624    (clobber (reg:CC 69))]
2625   "! TARGET_POWER && ! TARGET_POWERPC"
2626   "bla __divus"
2627   [(set_attr "type" "idiv")])
2628
2629 (define_insn "quoss_call"
2630   [(set (reg:SI 3)
2631         (div:SI (reg:SI 3) (reg:SI 4)))
2632    (clobber (match_scratch:SI 0 "=l"))]
2633   "! TARGET_POWER && ! TARGET_POWERPC"
2634   "bla __quoss"
2635   [(set_attr "type" "idiv")])
2636
2637 (define_insn "quous_call"
2638   [(set (reg:SI 3)
2639         (udiv:SI (reg:SI 3) (reg:SI 4)))
2640    (clobber (match_scratch:SI 0 "=l"))
2641    (clobber (reg:SI 0))
2642    (clobber (match_scratch:CC 1 "=x"))
2643    (clobber (reg:CC 69))]
2644   "! TARGET_POWER && ! TARGET_POWERPC"
2645   "bla __quous"
2646   [(set_attr "type" "idiv")])
2647 \f
2648 ;; Logical instructions
2649 ;; The logical instructions are mostly combined by using match_operator,
2650 ;; but the plain AND insns are somewhat different because there is no
2651 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
2652 ;; those rotate-and-mask operations.  Thus, the AND insns come first.
2653
2654 (define_insn "andsi3"
2655   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
2656         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
2657                 (match_operand:SI 2 "and_operand" "?r,T,K,L")))
2658    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
2659   ""
2660   "@
2661    and %0,%1,%2
2662    {rlinm|rlwinm} %0,%1,0,%m2,%M2
2663    {andil.|andi.} %0,%1,%b2
2664    {andiu.|andis.} %0,%1,%u2"
2665   [(set_attr "type" "*,*,compare,compare")])
2666
2667 ;; Note to set cr's other than cr0 we do the and immediate and then
2668 ;; the test again -- this avoids a mfcr which on the higher end
2669 ;; machines causes an execution serialization
2670
2671 (define_insn "*andsi3_internal2"
2672   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2673         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2674                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2675                     (const_int 0)))
2676    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2677    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2678   "TARGET_32BIT"
2679   "@
2680    and. %3,%1,%2
2681    {andil.|andi.} %3,%1,%b2
2682    {andiu.|andis.} %3,%1,%u2
2683    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2684    #
2685    #
2686    #
2687    #"
2688   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2689    (set_attr "length" "4,4,4,4,8,8,8,8")])
2690
2691 (define_insn "*andsi3_internal3"
2692   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2693         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2694                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2695                     (const_int 0)))
2696    (clobber (match_scratch:SI 3 "=r,r,r,r,r,r,r,r"))
2697    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2698   "TARGET_64BIT"
2699   "@
2700    #
2701    {andil.|andi.} %3,%1,%b2
2702    {andiu.|andis.} %3,%1,%u2
2703    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2
2704    #
2705    #
2706    #
2707    #"
2708   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2709    (set_attr "length" "8,4,4,4,8,8,8,8")])
2710
2711 (define_split
2712   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2713         (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "")
2714                              (match_operand:GPR 2 "and_operand" ""))
2715                     (const_int 0)))
2716    (clobber (match_scratch:GPR 3 ""))
2717    (clobber (match_scratch:CC 4 ""))]
2718   "reload_completed"
2719   [(parallel [(set (match_dup 3)
2720                    (and:<MODE> (match_dup 1)
2721                                (match_dup 2)))
2722               (clobber (match_dup 4))])
2723    (set (match_dup 0)
2724         (compare:CC (match_dup 3)
2725                     (const_int 0)))]
2726   "")
2727
2728 ;; We don't have a 32 bit "and. rt,ra,rb" for ppc64.  cr is set from the
2729 ;; whole 64 bit reg, and we don't know what is in the high 32 bits.
2730
2731 (define_split
2732   [(set (match_operand:CC 0 "cc_reg_operand" "")
2733         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2734                             (match_operand:SI 2 "gpc_reg_operand" ""))
2735                     (const_int 0)))
2736    (clobber (match_scratch:SI 3 ""))
2737    (clobber (match_scratch:CC 4 ""))]
2738   "TARGET_POWERPC64 && reload_completed"
2739   [(parallel [(set (match_dup 3)
2740                    (and:SI (match_dup 1)
2741                            (match_dup 2)))
2742               (clobber (match_dup 4))])
2743    (set (match_dup 0)
2744         (compare:CC (match_dup 3)
2745                     (const_int 0)))]
2746   "")
2747
2748 (define_insn "*andsi3_internal4"
2749   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2750         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2751                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2752                     (const_int 0)))
2753    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2754         (and:SI (match_dup 1)
2755                 (match_dup 2)))
2756    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2757   "TARGET_32BIT"
2758   "@
2759    and. %0,%1,%2
2760    {andil.|andi.} %0,%1,%b2
2761    {andiu.|andis.} %0,%1,%u2
2762    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2763    #
2764    #
2765    #
2766    #"
2767   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2768    (set_attr "length" "4,4,4,4,8,8,8,8")])
2769
2770 (define_insn "*andsi3_internal5"
2771   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x,?y,??y,??y,?y")
2772         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r,r,r,r")
2773                             (match_operand:SI 2 "and_operand" "r,K,L,T,r,K,L,T"))
2774                     (const_int 0)))
2775    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r,r,r,r")
2776         (and:SI (match_dup 1)
2777                 (match_dup 2)))
2778    (clobber (match_scratch:CC 4 "=X,X,X,X,X,x,x,X"))]
2779   "TARGET_64BIT"
2780   "@
2781    #
2782    {andil.|andi.} %0,%1,%b2
2783    {andiu.|andis.} %0,%1,%u2
2784    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2
2785    #
2786    #
2787    #
2788    #"
2789   [(set_attr "type" "compare,compare,compare,delayed_compare,compare,compare,compare,compare")
2790    (set_attr "length" "8,4,4,4,8,8,8,8")])
2791
2792 (define_split
2793   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2794         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2795                             (match_operand:SI 2 "and_operand" ""))
2796                     (const_int 0)))
2797    (set (match_operand:SI 0 "gpc_reg_operand" "")
2798         (and:SI (match_dup 1)
2799                 (match_dup 2)))
2800    (clobber (match_scratch:CC 4 ""))]
2801   "reload_completed"
2802   [(parallel [(set (match_dup 0)
2803                    (and:SI (match_dup 1)
2804                            (match_dup 2)))
2805               (clobber (match_dup 4))])
2806    (set (match_dup 3)
2807         (compare:CC (match_dup 0)
2808                     (const_int 0)))]
2809   "")
2810
2811 (define_split
2812   [(set (match_operand:CC 3 "cc_reg_operand" "")
2813         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
2814                             (match_operand:SI 2 "gpc_reg_operand" ""))
2815                     (const_int 0)))
2816    (set (match_operand:SI 0 "gpc_reg_operand" "")
2817         (and:SI (match_dup 1)
2818                 (match_dup 2)))
2819    (clobber (match_scratch:CC 4 ""))]
2820   "TARGET_POWERPC64 && reload_completed"
2821   [(parallel [(set (match_dup 0)
2822                    (and:SI (match_dup 1)
2823                            (match_dup 2)))
2824               (clobber (match_dup 4))])
2825    (set (match_dup 3)
2826         (compare:CC (match_dup 0)
2827                     (const_int 0)))]
2828   "")
2829
2830 ;; Handle the PowerPC64 rlwinm corner case
2831
2832 (define_insn_and_split "*andsi3_internal6"
2833   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2834         (and:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2835                 (match_operand:SI 2 "mask_operand_wrap" "i")))]
2836   "TARGET_POWERPC64"
2837   "#"
2838   "TARGET_POWERPC64"
2839   [(set (match_dup 0)
2840         (and:SI (rotate:SI (match_dup 1) (match_dup 3))
2841                 (match_dup 4)))
2842    (set (match_dup 0)
2843         (rotate:SI (match_dup 0) (match_dup 5)))]
2844   "
2845 {
2846   int mb = extract_MB (operands[2]);
2847   int me = extract_ME (operands[2]);
2848   operands[3] = GEN_INT (me + 1);
2849   operands[5] = GEN_INT (32 - (me + 1));
2850   operands[4] = GEN_INT (~((HOST_WIDE_INT) -1 << (33 + me - mb)));
2851 }"
2852   [(set_attr "length" "8")])
2853
2854 (define_expand "iorsi3"
2855   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2856         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
2857                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2858   ""
2859   "
2860 {
2861   if (GET_CODE (operands[2]) == CONST_INT
2862       && ! logical_operand (operands[2], SImode))
2863     {
2864       HOST_WIDE_INT value = INTVAL (operands[2]);
2865       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2866                  ? operands[0] : gen_reg_rtx (SImode));
2867
2868       emit_insn (gen_iorsi3 (tmp, operands[1],
2869                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2870       emit_insn (gen_iorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2871       DONE;
2872     }
2873 }")
2874
2875 (define_expand "xorsi3"
2876   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2877         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
2878                 (match_operand:SI 2 "reg_or_logical_cint_operand" "")))]
2879   ""
2880   "
2881 {
2882   if (GET_CODE (operands[2]) == CONST_INT
2883       && ! logical_operand (operands[2], SImode))
2884     {
2885       HOST_WIDE_INT value = INTVAL (operands[2]);
2886       rtx tmp = ((no_new_pseudos || rtx_equal_p (operands[0], operands[1]))
2887                  ? operands[0] : gen_reg_rtx (SImode));
2888
2889       emit_insn (gen_xorsi3 (tmp, operands[1],
2890                              GEN_INT (value & (~ (HOST_WIDE_INT) 0xffff))));
2891       emit_insn (gen_xorsi3 (operands[0], tmp, GEN_INT (value & 0xffff)));
2892       DONE;
2893     }
2894 }")
2895
2896 (define_insn "*boolsi3_internal1"
2897   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
2898         (match_operator:SI 3 "boolean_or_operator"
2899          [(match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
2900           (match_operand:SI 2 "logical_operand" "r,K,L")]))]
2901   ""
2902   "@
2903    %q3 %0,%1,%2
2904    {%q3il|%q3i} %0,%1,%b2
2905    {%q3iu|%q3is} %0,%1,%u2")
2906
2907 (define_insn "*boolsi3_internal2"
2908   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2909         (compare:CC (match_operator:SI 4 "boolean_or_operator"
2910          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2911           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2912          (const_int 0)))
2913    (clobber (match_scratch:SI 3 "=r,r"))]
2914   "TARGET_32BIT"
2915   "@
2916    %q4. %3,%1,%2
2917    #"
2918   [(set_attr "type" "compare")
2919    (set_attr "length" "4,8")])
2920
2921 (define_split
2922   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
2923         (compare:CC (match_operator:SI 4 "boolean_operator"
2924          [(match_operand:SI 1 "gpc_reg_operand" "")
2925           (match_operand:SI 2 "gpc_reg_operand" "")])
2926          (const_int 0)))
2927    (clobber (match_scratch:SI 3 ""))]
2928   "TARGET_32BIT && reload_completed"
2929   [(set (match_dup 3) (match_dup 4))
2930    (set (match_dup 0)
2931         (compare:CC (match_dup 3)
2932                     (const_int 0)))]
2933   "")
2934
2935 (define_insn "*boolsi3_internal3"
2936   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2937         (compare:CC (match_operator:SI 4 "boolean_operator"
2938          [(match_operand:SI 1 "gpc_reg_operand" "%r,r")
2939           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
2940          (const_int 0)))
2941    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2942         (match_dup 4))]
2943   "TARGET_32BIT"
2944   "@
2945    %q4. %0,%1,%2
2946    #"
2947   [(set_attr "type" "compare")
2948    (set_attr "length" "4,8")])
2949
2950 (define_split
2951   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
2952         (compare:CC (match_operator:SI 4 "boolean_operator"
2953          [(match_operand:SI 1 "gpc_reg_operand" "")
2954           (match_operand:SI 2 "gpc_reg_operand" "")])
2955          (const_int 0)))
2956    (set (match_operand:SI 0 "gpc_reg_operand" "")
2957         (match_dup 4))]
2958   "TARGET_32BIT && reload_completed"
2959   [(set (match_dup 0) (match_dup 4))
2960    (set (match_dup 3)
2961         (compare:CC (match_dup 0)
2962                     (const_int 0)))]
2963   "")
2964
2965 ;; Split a logical operation that we can't do in one insn into two insns,
2966 ;; each of which does one 16-bit part.  This is used by combine.
2967
2968 (define_split
2969   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2970         (match_operator:SI 3 "boolean_or_operator"
2971          [(match_operand:SI 1 "gpc_reg_operand" "")
2972           (match_operand:SI 2 "non_logical_cint_operand" "")]))]
2973   ""
2974   [(set (match_dup 0) (match_dup 4))
2975    (set (match_dup 0) (match_dup 5))]
2976 "
2977 {
2978   rtx i;
2979   i = GEN_INT (INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
2980   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2981                                 operands[1], i);
2982   i = GEN_INT (INTVAL (operands[2]) & 0xffff);
2983   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2984                                 operands[0], i);
2985 }")
2986
2987 (define_insn "*boolcsi3_internal1"
2988   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2989         (match_operator:SI 3 "boolean_operator"
2990          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
2991           (match_operand:SI 2 "gpc_reg_operand" "r")]))]
2992   ""
2993   "%q3 %0,%2,%1")
2994
2995 (define_insn "*boolcsi3_internal2"
2996   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
2997         (compare:CC (match_operator:SI 4 "boolean_operator"
2998          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
2999           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3000          (const_int 0)))
3001    (clobber (match_scratch:SI 3 "=r,r"))]
3002   "TARGET_32BIT"
3003   "@
3004    %q4. %3,%2,%1
3005    #"
3006   [(set_attr "type" "compare")
3007    (set_attr "length" "4,8")])
3008
3009 (define_split
3010   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3011         (compare:CC (match_operator:SI 4 "boolean_operator"
3012          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3013           (match_operand:SI 2 "gpc_reg_operand" "")])
3014          (const_int 0)))
3015    (clobber (match_scratch:SI 3 ""))]
3016   "TARGET_32BIT && reload_completed"
3017   [(set (match_dup 3) (match_dup 4))
3018    (set (match_dup 0)
3019         (compare:CC (match_dup 3)
3020                     (const_int 0)))]
3021   "")
3022
3023 (define_insn "*boolcsi3_internal3"
3024   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3025         (compare:CC (match_operator:SI 4 "boolean_operator"
3026          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3027           (match_operand:SI 2 "gpc_reg_operand" "r,r")])
3028          (const_int 0)))
3029    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3030         (match_dup 4))]
3031   "TARGET_32BIT"
3032   "@
3033    %q4. %0,%2,%1
3034    #"
3035   [(set_attr "type" "compare")
3036    (set_attr "length" "4,8")])
3037
3038 (define_split
3039   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3040         (compare:CC (match_operator:SI 4 "boolean_operator"
3041          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3042           (match_operand:SI 2 "gpc_reg_operand" "")])
3043          (const_int 0)))
3044    (set (match_operand:SI 0 "gpc_reg_operand" "")
3045         (match_dup 4))]
3046   "TARGET_32BIT && reload_completed"
3047   [(set (match_dup 0) (match_dup 4))
3048    (set (match_dup 3)
3049         (compare:CC (match_dup 0)
3050                     (const_int 0)))]
3051   "")
3052
3053 (define_insn "*boolccsi3_internal1"
3054   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3055         (match_operator:SI 3 "boolean_operator"
3056          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
3057           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))]))]
3058   ""
3059   "%q3 %0,%1,%2")
3060
3061 (define_insn "*boolccsi3_internal2"
3062   [(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
3063         (compare:CC (match_operator:SI 4 "boolean_operator"
3064          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
3065           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3066          (const_int 0)))
3067    (clobber (match_scratch:SI 3 "=r,r"))]
3068   "TARGET_32BIT"
3069   "@
3070    %q4. %3,%1,%2
3071    #"
3072   [(set_attr "type" "compare")
3073    (set_attr "length" "4,8")])
3074
3075 (define_split
3076   [(set (match_operand:CC 0 "cc_reg_not_cr0_operand" "")
3077         (compare:CC (match_operator:SI 4 "boolean_operator"
3078          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3079           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3080          (const_int 0)))
3081    (clobber (match_scratch:SI 3 ""))]
3082   "TARGET_32BIT && reload_completed"
3083   [(set (match_dup 3) (match_dup 4))
3084    (set (match_dup 0)
3085         (compare:CC (match_dup 3)
3086                     (const_int 0)))]
3087   "")
3088
3089 (define_insn "*boolccsi3_internal3"
3090   [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3091         (compare:CC (match_operator:SI 4 "boolean_operator"
3092          [(not:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r"))
3093           (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))])
3094          (const_int 0)))
3095    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3096         (match_dup 4))]
3097   "TARGET_32BIT"
3098   "@
3099    %q4. %0,%1,%2
3100    #"
3101   [(set_attr "type" "compare")
3102    (set_attr "length" "4,8")])
3103
3104 (define_split
3105   [(set (match_operand:CC 3 "cc_reg_not_cr0_operand" "")
3106         (compare:CC (match_operator:SI 4 "boolean_operator"
3107          [(not:SI (match_operand:SI 1 "gpc_reg_operand" ""))
3108           (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))])
3109          (const_int 0)))
3110    (set (match_operand:SI 0 "gpc_reg_operand" "")
3111         (match_dup 4))]
3112   "TARGET_32BIT && reload_completed"
3113   [(set (match_dup 0) (match_dup 4))
3114    (set (match_dup 3)
3115         (compare:CC (match_dup 0)
3116                     (const_int 0)))]
3117   "")
3118
3119 ;; maskir insn.  We need four forms because things might be in arbitrary
3120 ;; orders.  Don't define forms that only set CR fields because these
3121 ;; would modify an input register.
3122
3123 (define_insn "*maskir_internal1"
3124   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3125         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3126                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3127                 (and:SI (match_dup 2)
3128                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
3129   "TARGET_POWER"
3130   "maskir %0,%3,%2")
3131
3132 (define_insn "*maskir_internal2"
3133   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3134         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
3135                         (match_operand:SI 1 "gpc_reg_operand" "0"))
3136                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3137                         (match_dup 2))))]
3138   "TARGET_POWER"
3139   "maskir %0,%3,%2")
3140
3141 (define_insn "*maskir_internal3"
3142   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3143         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
3144                         (match_operand:SI 3 "gpc_reg_operand" "r"))
3145                 (and:SI (not:SI (match_dup 2))
3146                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3147   "TARGET_POWER"
3148   "maskir %0,%3,%2")
3149
3150 (define_insn "*maskir_internal4"
3151   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3152         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
3153                         (match_operand:SI 2 "gpc_reg_operand" "r"))
3154                 (and:SI (not:SI (match_dup 2))
3155                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
3156   "TARGET_POWER"
3157   "maskir %0,%3,%2")
3158
3159 (define_insn "*maskir_internal5"
3160   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3161         (compare:CC
3162          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3163                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3164                  (and:SI (match_dup 2)
3165                          (match_operand:SI 3 "gpc_reg_operand" "r,r")))
3166          (const_int 0)))
3167    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3168         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3169                 (and:SI (match_dup 2) (match_dup 3))))]
3170   "TARGET_POWER"
3171   "@
3172    maskir. %0,%3,%2
3173    #"
3174   [(set_attr "type" "compare")
3175    (set_attr "length" "4,8")])
3176
3177 (define_split
3178   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3179         (compare:CC
3180          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3181                          (match_operand:SI 1 "gpc_reg_operand" ""))
3182                  (and:SI (match_dup 2)
3183                          (match_operand:SI 3 "gpc_reg_operand" "")))
3184          (const_int 0)))
3185    (set (match_operand:SI 0 "gpc_reg_operand" "")
3186         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3187                 (and:SI (match_dup 2) (match_dup 3))))]
3188   "TARGET_POWER && reload_completed"
3189   [(set (match_dup 0)
3190         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3191                 (and:SI (match_dup 2) (match_dup 3))))
3192    (set (match_dup 4)
3193         (compare:CC (match_dup 0)
3194                     (const_int 0)))]
3195   "")
3196
3197 (define_insn "*maskir_internal6"
3198   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3199         (compare:CC
3200          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r,r"))
3201                          (match_operand:SI 1 "gpc_reg_operand" "0,0"))
3202                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,r")
3203                          (match_dup 2)))
3204          (const_int 0)))
3205    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3206         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3207                 (and:SI (match_dup 3) (match_dup 2))))]
3208   "TARGET_POWER"
3209   "@
3210    maskir. %0,%3,%2
3211    #"
3212   [(set_attr "type" "compare")
3213    (set_attr "length" "4,8")])
3214
3215 (define_split
3216   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3217         (compare:CC
3218          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" ""))
3219                          (match_operand:SI 1 "gpc_reg_operand" ""))
3220                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "")
3221                          (match_dup 2)))
3222          (const_int 0)))
3223    (set (match_operand:SI 0 "gpc_reg_operand" "")
3224         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3225                 (and:SI (match_dup 3) (match_dup 2))))]
3226   "TARGET_POWER && reload_completed"
3227   [(set (match_dup 0)
3228         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
3229                 (and:SI (match_dup 3) (match_dup 2))))
3230    (set (match_dup 4)
3231         (compare:CC (match_dup 0)
3232                     (const_int 0)))]
3233   "")
3234
3235 (define_insn "*maskir_internal7"
3236   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
3237         (compare:CC
3238          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r,r")
3239                          (match_operand:SI 3 "gpc_reg_operand" "r,r"))
3240                  (and:SI (not:SI (match_dup 2))
3241                          (match_operand:SI 1 "gpc_reg_operand" "0,0")))
3242          (const_int 0)))
3243    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
3244         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3245                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3246   "TARGET_POWER"
3247   "@
3248    maskir. %0,%3,%2
3249    #"
3250   [(set_attr "type" "compare")
3251    (set_attr "length" "4,8")])
3252
3253 (define_split
3254   [(set (match_operand:CC 4 "cc_reg_not_cr0_operand" "")
3255         (compare:CC
3256          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "")
3257                          (match_operand:SI 3 "gpc_reg_operand" ""))
3258                  (and:SI (not:SI (match_dup 2))
3259                          (match_operand:SI 1 "gpc_reg_operand" "")))
3260          (const_int 0)))
3261    (set (match_operand:SI 0 "gpc_reg_operand" "")
3262         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3263                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
3264   "TARGET_POWER && reload_completed"
3265   [(set (match_dup 0)
3266         (ior:SI (and:SI (match_dup 2) (match_dup 3))
3267                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))
3268    (set (match_dup 4)
3269         (compare:CC (match_dup 0)
3270                     (const_int 0)))]
3271   "")
3272
3273 (define_insn "*maskir_internal8"
3274   [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")