OSDN Git Service

89f075e98443c41d53fe35fa0773b2529297e97c
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / i386.md
1 ;; GCC machine description for IA-32 and x86-64.
2 ;; Copyright (C) 1988, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
5 ;; Mostly by William Schelter.
6 ;; x86_64 support added by Jan Hubicka
7 ;;
8 ;; This file is part of GCC.
9 ;;
10 ;; GCC is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
13 ;; any later version.
14 ;;
15 ;; GCC is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19 ;;
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GCC; see the file COPYING3.  If not see
22 ;; <http://www.gnu.org/licenses/>.  */
23 ;;
24 ;; The original PO technology requires these to be ordered by speed,
25 ;; so that assigner will pick the fastest.
26 ;;
27 ;; See file "rtl.def" for documentation on define_insn, match_*, et. al.
28 ;;
29 ;; The special asm out single letter directives following a '%' are:
30 ;; L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
31 ;; C -- print opcode suffix for set/cmov insn.
32 ;; c -- like C, but print reversed condition
33 ;; E,e -- likewise, but for compare-and-branch fused insn.
34 ;; F,f -- likewise, but for floating-point.
35 ;; O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
36 ;;      otherwise nothing
37 ;; R -- print the prefix for register names.
38 ;; z -- print the opcode suffix for the size of the current operand.
39 ;; Z -- likewise, with special suffixes for x87 instructions.
40 ;; * -- print a star (in certain assembler syntax)
41 ;; A -- print an absolute memory reference.
42 ;; w -- print the operand as if it's a "word" (HImode) even if it isn't.
43 ;; s -- print a shift double count, followed by the assemblers argument
44 ;;      delimiter.
45 ;; b -- print the QImode name of the register for the indicated operand.
46 ;;      %b0 would print %al if operands[0] is reg 0.
47 ;; w --  likewise, print the HImode name of the register.
48 ;; k --  likewise, print the SImode name of the register.
49 ;; q --  likewise, print the DImode name of the register.
50 ;; x --  likewise, print the V4SFmode name of the register.
51 ;; t --  likewise, print the V8SFmode name of the register.
52 ;; h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
53 ;; y -- print "st(0)" instead of "st" as a register.
54 ;; d -- print duplicated register operand for AVX instruction.
55 ;; D -- print condition for SSE cmp instruction.
56 ;; P -- if PIC, print an @PLT suffix.
57 ;; X -- don't print any sort of PIC '@' suffix for a symbol.
58 ;; & -- print some in-use local-dynamic symbol name.
59 ;; H -- print a memory address offset by 8; used for sse high-parts
60 ;; + -- print a branch hint as 'cs' or 'ds' prefix
61 ;; ; -- print a semicolon (after prefixes due to bug in older gas).
62
63 ;; UNSPEC usage:
64
65 (define_constants
66   [; Relocation specifiers
67    (UNSPEC_GOT                  0)
68    (UNSPEC_GOTOFF               1)
69    (UNSPEC_GOTPCREL             2)
70    (UNSPEC_GOTTPOFF             3)
71    (UNSPEC_TPOFF                4)
72    (UNSPEC_NTPOFF               5)
73    (UNSPEC_DTPOFF               6)
74    (UNSPEC_GOTNTPOFF            7)
75    (UNSPEC_INDNTPOFF            8)
76    (UNSPEC_PLTOFF               9)
77    (UNSPEC_MACHOPIC_OFFSET      10)
78
79    ; Prologue support
80    (UNSPEC_STACK_ALLOC          11)
81    (UNSPEC_SET_GOT              12)
82    (UNSPEC_SSE_PROLOGUE_SAVE    13)
83    (UNSPEC_REG_SAVE             14)
84    (UNSPEC_DEF_CFA              15)
85    (UNSPEC_SET_RIP              16)
86    (UNSPEC_SET_GOT_OFFSET       17)
87    (UNSPEC_MEMORY_BLOCKAGE      18)
88
89    ; TLS support
90    (UNSPEC_TP                   20)
91    (UNSPEC_TLS_GD               21)
92    (UNSPEC_TLS_LD_BASE          22)
93    (UNSPEC_TLSDESC              23)
94
95    ; Other random patterns
96    (UNSPEC_SCAS                 30)
97    (UNSPEC_FNSTSW               31)
98    (UNSPEC_SAHF                 32)
99    (UNSPEC_FSTCW                33)
100    (UNSPEC_ADD_CARRY            34)
101    (UNSPEC_FLDCW                35)
102    (UNSPEC_REP                  36)
103    (UNSPEC_LD_MPIC              38)     ; load_macho_picbase
104    (UNSPEC_TRUNC_NOOP           39)
105
106    ; For SSE/MMX support:
107    (UNSPEC_FIX_NOTRUNC          40)
108    (UNSPEC_MASKMOV              41)
109    (UNSPEC_MOVMSK               42)
110    (UNSPEC_MOVNT                43)
111    (UNSPEC_MOVU                 44)
112    (UNSPEC_RCP                  45)
113    (UNSPEC_RSQRT                46)
114    (UNSPEC_SFENCE               47)
115    (UNSPEC_PFRCP                49)
116    (UNSPEC_PFRCPIT1             40)
117    (UNSPEC_PFRCPIT2             41)
118    (UNSPEC_PFRSQRT              42)
119    (UNSPEC_PFRSQIT1             43)
120    (UNSPEC_MFENCE               44)
121    (UNSPEC_LFENCE               45)
122    (UNSPEC_PSADBW               46)
123    (UNSPEC_LDDQU                47)
124    (UNSPEC_MS_TO_SYSV_CALL      48)
125
126    ; Generic math support
127    (UNSPEC_COPYSIGN             50)
128    (UNSPEC_IEEE_MIN             51)     ; not commutative
129    (UNSPEC_IEEE_MAX             52)     ; not commutative
130
131    ; x87 Floating point
132    (UNSPEC_SIN                  60)
133    (UNSPEC_COS                  61)
134    (UNSPEC_FPATAN               62)
135    (UNSPEC_FYL2X                63)
136    (UNSPEC_FYL2XP1              64)
137    (UNSPEC_FRNDINT              65)
138    (UNSPEC_FIST                 66)
139    (UNSPEC_F2XM1                67)
140    (UNSPEC_TAN                  68)
141    (UNSPEC_FXAM                 69)
142
143    ; x87 Rounding
144    (UNSPEC_FRNDINT_FLOOR        70)
145    (UNSPEC_FRNDINT_CEIL         71)
146    (UNSPEC_FRNDINT_TRUNC        72)
147    (UNSPEC_FRNDINT_MASK_PM      73)
148    (UNSPEC_FIST_FLOOR           74)
149    (UNSPEC_FIST_CEIL            75)
150
151    ; x87 Double output FP
152    (UNSPEC_SINCOS_COS           80)
153    (UNSPEC_SINCOS_SIN           81)
154    (UNSPEC_XTRACT_FRACT         84)
155    (UNSPEC_XTRACT_EXP           85)
156    (UNSPEC_FSCALE_FRACT         86)
157    (UNSPEC_FSCALE_EXP           87)
158    (UNSPEC_FPREM_F              88)
159    (UNSPEC_FPREM_U              89)
160    (UNSPEC_FPREM1_F             90)
161    (UNSPEC_FPREM1_U             91)
162
163    (UNSPEC_C2_FLAG              95)
164    (UNSPEC_FXAM_MEM             96)
165
166    ; SSP patterns
167    (UNSPEC_SP_SET               100)
168    (UNSPEC_SP_TEST              101)
169    (UNSPEC_SP_TLS_SET           102)
170    (UNSPEC_SP_TLS_TEST          103)
171
172    ; SSSE3
173    (UNSPEC_PSHUFB               120)
174    (UNSPEC_PSIGN                121)
175    (UNSPEC_PALIGNR              122)
176
177    ; For SSE4A support
178    (UNSPEC_EXTRQI               130)
179    (UNSPEC_EXTRQ                131)
180    (UNSPEC_INSERTQI             132)
181    (UNSPEC_INSERTQ              133)
182
183    ; For SSE4.1 support
184    (UNSPEC_BLENDV               134)
185    (UNSPEC_INSERTPS             135)
186    (UNSPEC_DP                   136)
187    (UNSPEC_MOVNTDQA             137)
188    (UNSPEC_MPSADBW              138)
189    (UNSPEC_PHMINPOSUW           139)
190    (UNSPEC_PTEST                140)
191    (UNSPEC_ROUND                141)
192
193    ; For SSE4.2 support
194    (UNSPEC_CRC32                143)
195    (UNSPEC_PCMPESTR             144)
196    (UNSPEC_PCMPISTR             145)
197
198    ; For FMA4 support
199    (UNSPEC_FMA4_INTRINSIC       150)
200    (UNSPEC_FMA4_FMADDSUB        151)
201    (UNSPEC_FMA4_FMSUBADD        152)
202    ; For AES support
203    (UNSPEC_AESENC               159)
204    (UNSPEC_AESENCLAST           160)
205    (UNSPEC_AESDEC               161)
206    (UNSPEC_AESDECLAST           162)
207    (UNSPEC_AESIMC               163)
208    (UNSPEC_AESKEYGENASSIST      164)
209
210    ; For PCLMUL support
211    (UNSPEC_PCLMUL               165)
212
213    ; For AVX support
214    (UNSPEC_PCMP                 166)
215    (UNSPEC_VPERMIL              167)
216    (UNSPEC_VPERMIL2F128         168)
217    (UNSPEC_MASKLOAD             169)
218    (UNSPEC_MASKSTORE            170)
219    (UNSPEC_CAST                 171)
220    (UNSPEC_VTESTP               172)
221   ])
222
223 (define_constants
224   [(UNSPECV_BLOCKAGE            0)
225    (UNSPECV_STACK_PROBE         1)
226    (UNSPECV_EMMS                2)
227    (UNSPECV_LDMXCSR             3)
228    (UNSPECV_STMXCSR             4)
229    (UNSPECV_FEMMS               5)
230    (UNSPECV_CLFLUSH             6)
231    (UNSPECV_ALIGN               7)
232    (UNSPECV_MONITOR             8)
233    (UNSPECV_MWAIT               9)
234    (UNSPECV_CMPXCHG             10)
235    (UNSPECV_XCHG                12)
236    (UNSPECV_LOCK                13)
237    (UNSPECV_PROLOGUE_USE        14)
238    (UNSPECV_CLD                 15)
239    (UNSPECV_VZEROALL            16)
240    (UNSPECV_VZEROUPPER          17)
241    (UNSPECV_RDTSC               18)
242    (UNSPECV_RDTSCP              19)
243    (UNSPECV_RDPMC               20)
244   ])
245
246 ;; Constants to represent pcomtrue/pcomfalse variants
247 (define_constants
248   [(PCOM_FALSE                  0)
249    (PCOM_TRUE                   1)
250    (COM_FALSE_S                 2)
251    (COM_FALSE_P                 3)
252    (COM_TRUE_S                  4)
253    (COM_TRUE_P                  5)
254   ])
255
256 ;; Registers by name.
257 (define_constants
258   [(AX_REG                       0)
259    (DX_REG                       1)
260    (CX_REG                       2)
261    (BX_REG                       3)
262    (SI_REG                       4)
263    (DI_REG                       5)
264    (BP_REG                       6)
265    (SP_REG                       7)
266    (ST0_REG                      8)
267    (ST1_REG                      9)
268    (ST2_REG                     10)
269    (ST3_REG                     11)
270    (ST4_REG                     12)
271    (ST5_REG                     13)
272    (ST6_REG                     14)
273    (ST7_REG                     15)
274    (FLAGS_REG                   17)
275    (FPSR_REG                    18)
276    (FPCR_REG                    19)
277    (XMM0_REG                    21)
278    (XMM1_REG                    22)
279    (XMM2_REG                    23)
280    (XMM3_REG                    24)
281    (XMM4_REG                    25)
282    (XMM5_REG                    26)
283    (XMM6_REG                    27)
284    (XMM7_REG                    28)
285    (MM0_REG                     29)
286    (MM1_REG                     30)
287    (MM2_REG                     31)
288    (MM3_REG                     32)
289    (MM4_REG                     33)
290    (MM5_REG                     34)
291    (MM6_REG                     35)
292    (MM7_REG                     36)
293    (R8_REG                      37)
294    (R9_REG                      38)
295    (R10_REG                     39)
296    (R11_REG                     40)
297    (R12_REG                     41)
298    (R13_REG                     42)
299    (XMM8_REG                    45)
300    (XMM9_REG                    46)
301    (XMM10_REG                   47)
302    (XMM11_REG                   48)
303    (XMM12_REG                   49)
304    (XMM13_REG                   50)
305    (XMM14_REG                   51)
306    (XMM15_REG                   52)
307   ])
308
309 ;; Insns whose names begin with "x86_" are emitted by gen_FOO calls
310 ;; from i386.c.
311
312 ;; In C guard expressions, put expressions which may be compile-time
313 ;; constants first.  This allows for better optimization.  For
314 ;; example, write "TARGET_64BIT && reload_completed", not
315 ;; "reload_completed && TARGET_64BIT".
316
317 \f
318 ;; Processor type.
319 (define_attr "cpu" "none,pentium,pentiumpro,geode,k6,athlon,k8,core2,atom,
320                     generic64,amdfam10"
321   (const (symbol_ref "ix86_schedule")))
322
323 ;; A basic instruction type.  Refinements due to arguments to be
324 ;; provided in other attributes.
325 (define_attr "type"
326   "other,multi,
327    alu,alu1,negnot,imov,imovx,lea,
328    incdec,ishift,ishift1,rotate,rotate1,imul,idiv,
329    icmp,test,ibr,setcc,icmov,
330    push,pop,call,callv,leave,
331    str,bitmanip,
332    fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,fxch,fistp,fisttp,frndint,
333    sselog,sselog1,sseiadd,sseiadd1,sseishft,sseimul,
334    sse,ssemov,sseadd,ssemul,ssecmp,ssecomi,ssecvt,ssecvt1,sseicvt,ssediv,sseins,
335    ssemuladd,sse4arg,
336    mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft"
337   (const_string "other"))
338
339 ;; Main data type used by the insn
340 (define_attr "mode"
341   "unknown,none,QI,HI,SI,DI,TI,OI,SF,DF,XF,TF,V8SF,V4DF,V4SF,V2DF,V2SF,V1DF"
342   (const_string "unknown"))
343
344 ;; The CPU unit operations uses.
345 (define_attr "unit" "integer,i387,sse,mmx,unknown"
346   (cond [(eq_attr "type" "fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,fxch,fistp,fisttp,frndint")
347            (const_string "i387")
348          (eq_attr "type" "sselog,sselog1,sseiadd,sseiadd1,sseishft,sseimul,
349                           sse,ssemov,sseadd,ssemul,ssecmp,ssecomi,ssecvt,
350                           ssecvt1,sseicvt,ssediv,sseins,ssemuladd,sse4arg")
351            (const_string "sse")
352          (eq_attr "type" "mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft")
353            (const_string "mmx")
354          (eq_attr "type" "other")
355            (const_string "unknown")]
356          (const_string "integer")))
357
358 ;; The (bounding maximum) length of an instruction immediate.
359 (define_attr "length_immediate" ""
360   (cond [(eq_attr "type" "incdec,setcc,icmov,str,lea,other,multi,idiv,leave,
361                           bitmanip")
362            (const_int 0)
363          (eq_attr "unit" "i387,sse,mmx")
364            (const_int 0)
365          (eq_attr "type" "alu,alu1,negnot,imovx,ishift,rotate,ishift1,rotate1,
366                           imul,icmp,push,pop")
367            (symbol_ref "ix86_attr_length_immediate_default(insn,1)")
368          (eq_attr "type" "imov,test")
369            (symbol_ref "ix86_attr_length_immediate_default(insn,0)")
370          (eq_attr "type" "call")
371            (if_then_else (match_operand 0 "constant_call_address_operand" "")
372              (const_int 4)
373              (const_int 0))
374          (eq_attr "type" "callv")
375            (if_then_else (match_operand 1 "constant_call_address_operand" "")
376              (const_int 4)
377              (const_int 0))
378          ;; We don't know the size before shorten_branches.  Expect
379          ;; the instruction to fit for better scheduling.
380          (eq_attr "type" "ibr")
381            (const_int 1)
382          ]
383          (symbol_ref "/* Update immediate_length and other attributes! */
384                       gcc_unreachable (),1")))
385
386 ;; The (bounding maximum) length of an instruction address.
387 (define_attr "length_address" ""
388   (cond [(eq_attr "type" "str,other,multi,fxch")
389            (const_int 0)
390          (and (eq_attr "type" "call")
391               (match_operand 0 "constant_call_address_operand" ""))
392              (const_int 0)
393          (and (eq_attr "type" "callv")
394               (match_operand 1 "constant_call_address_operand" ""))
395              (const_int 0)
396          ]
397          (symbol_ref "ix86_attr_length_address_default (insn)")))
398
399 ;; Set when length prefix is used.
400 (define_attr "prefix_data16" ""
401   (cond [(eq_attr "type" "ssemuladd,sse4arg,sseiadd1,ssecvt1")
402            (const_int 0)
403          (eq_attr "mode" "HI")
404            (const_int 1)
405          (and (eq_attr "unit" "sse") (eq_attr "mode" "V2DF,TI"))
406            (const_int 1)
407         ]
408         (const_int 0)))
409
410 ;; Set when string REP prefix is used.
411 (define_attr "prefix_rep" ""
412   (cond [(eq_attr "type" "ssemuladd,sse4arg,sseiadd1,ssecvt1")
413            (const_int 0)
414          (and (eq_attr "unit" "sse") (eq_attr "mode" "SF,DF"))
415            (const_int 1)
416         ]
417         (const_int 0)))
418
419 ;; Set when 0f opcode prefix is used.
420 (define_attr "prefix_0f" ""
421   (if_then_else
422     (ior (eq_attr "type" "imovx,setcc,icmov,bitmanip")
423          (eq_attr "unit" "sse,mmx"))
424     (const_int 1)
425     (const_int 0)))
426
427 ;; Set when REX opcode prefix is used.
428 (define_attr "prefix_rex" ""
429   (cond [(ne (symbol_ref "!TARGET_64BIT") (const_int 0))
430            (const_int 0)
431          (and (eq_attr "mode" "DI")
432               (and (eq_attr "type" "!push,pop,call,callv,leave,ibr")
433                    (eq_attr "unit" "!mmx")))
434            (const_int 1)
435          (and (eq_attr "mode" "QI")
436               (ne (symbol_ref "x86_extended_QIreg_mentioned_p (insn)")
437                   (const_int 0)))
438            (const_int 1)
439          (ne (symbol_ref "x86_extended_reg_mentioned_p (insn)")
440              (const_int 0))
441            (const_int 1)
442          (and (eq_attr "type" "imovx")
443               (match_operand:QI 1 "ext_QIreg_operand" ""))
444            (const_int 1)
445         ]
446         (const_int 0)))
447
448 ;; There are also additional prefixes in 3DNOW, SSSE3.
449 ;; ssemuladd,sse4arg default to 0f24/0f25 and DREX byte,
450 ;; sseiadd1,ssecvt1 to 0f7a with no DREX byte.
451 ;; 3DNOW has 0f0f prefix, SSSE3 and SSE4_{1,2} 0f38/0f3a.
452 (define_attr "prefix_extra" ""
453   (cond [(eq_attr "type" "ssemuladd,sse4arg")
454            (const_int 2)
455          (eq_attr "type" "sseiadd1,ssecvt1")
456            (const_int 1)
457         ]
458         (const_int 0)))
459
460 ;; Prefix used: original, VEX or maybe VEX.
461 (define_attr "prefix" "orig,vex,maybe_vex"
462   (if_then_else (eq_attr "mode" "OI,V8SF,V4DF")
463     (const_string "vex")
464     (const_string "orig")))
465
466 ;; VEX W bit is used.
467 (define_attr "prefix_vex_w" "" (const_int 0))
468
469 ;; The length of VEX prefix
470 ;; Only instructions with 0f prefix can have 2 byte VEX prefix,
471 ;; 0f38/0f3a prefixes can't.  In i386.md 0f3[8a] is
472 ;; still prefix_0f 1, with prefix_extra 1.
473 (define_attr "length_vex" ""
474   (if_then_else (and (eq_attr "prefix_0f" "1")
475                      (eq_attr "prefix_extra" "0"))
476     (if_then_else (eq_attr "prefix_vex_w" "1")
477       (symbol_ref "ix86_attr_length_vex_default (insn, 1, 1)")
478       (symbol_ref "ix86_attr_length_vex_default (insn, 1, 0)"))
479     (if_then_else (eq_attr "prefix_vex_w" "1")
480       (symbol_ref "ix86_attr_length_vex_default (insn, 0, 1)")
481       (symbol_ref "ix86_attr_length_vex_default (insn, 0, 0)"))))
482
483 ;; Set when modrm byte is used.
484 (define_attr "modrm" ""
485   (cond [(eq_attr "type" "str,leave")
486            (const_int 0)
487          (eq_attr "unit" "i387")
488            (const_int 0)
489          (and (eq_attr "type" "incdec")
490               (and (eq (symbol_ref "TARGET_64BIT") (const_int 0))
491                    (ior (match_operand:SI 1 "register_operand" "")
492                         (match_operand:HI 1 "register_operand" ""))))
493            (const_int 0)
494          (and (eq_attr "type" "push")
495               (not (match_operand 1 "memory_operand" "")))
496            (const_int 0)
497          (and (eq_attr "type" "pop")
498               (not (match_operand 0 "memory_operand" "")))
499            (const_int 0)
500          (and (eq_attr "type" "imov")
501               (and (not (eq_attr "mode" "DI"))
502                    (ior (and (match_operand 0 "register_operand" "")
503                              (match_operand 1 "immediate_operand" ""))
504                         (ior (and (match_operand 0 "ax_reg_operand" "")
505                                   (match_operand 1 "memory_displacement_only_operand" ""))
506                              (and (match_operand 0 "memory_displacement_only_operand" "")
507                                   (match_operand 1 "ax_reg_operand" ""))))))
508            (const_int 0)
509          (and (eq_attr "type" "call")
510               (match_operand 0 "constant_call_address_operand" ""))
511              (const_int 0)
512          (and (eq_attr "type" "callv")
513               (match_operand 1 "constant_call_address_operand" ""))
514              (const_int 0)
515          (and (eq_attr "type" "alu,alu1,icmp,test")
516               (match_operand 0 "ax_reg_operand" ""))
517              (symbol_ref "(get_attr_length_immediate (insn) <= (get_attr_mode (insn) != MODE_QI))")
518          ]
519          (const_int 1)))
520
521 ;; The (bounding maximum) length of an instruction in bytes.
522 ;; ??? fistp and frndint are in fact fldcw/{fistp,frndint}/fldcw sequences.
523 ;; Later we may want to split them and compute proper length as for
524 ;; other insns.
525 (define_attr "length" ""
526   (cond [(eq_attr "type" "other,multi,fistp,frndint")
527            (const_int 16)
528          (eq_attr "type" "fcmp")
529            (const_int 4)
530          (eq_attr "unit" "i387")
531            (plus (const_int 2)
532                  (plus (attr "prefix_data16")
533                        (attr "length_address")))
534          (ior (eq_attr "prefix" "vex")
535               (and (eq_attr "prefix" "maybe_vex")
536                     (ne (symbol_ref "TARGET_AVX") (const_int 0))))
537            (plus (attr "length_vex")
538                  (plus (attr "length_immediate")
539                        (plus (attr "modrm")
540                              (attr "length_address"))))]
541          (plus (plus (attr "modrm")
542                      (plus (attr "prefix_0f")
543                            (plus (attr "prefix_rex")
544                                  (plus (attr "prefix_extra")
545                                        (const_int 1)))))
546                (plus (attr "prefix_rep")
547                      (plus (attr "prefix_data16")
548                            (plus (attr "length_immediate")
549                                  (attr "length_address")))))))
550
551 ;; The `memory' attribute is `none' if no memory is referenced, `load' or
552 ;; `store' if there is a simple memory reference therein, or `unknown'
553 ;; if the instruction is complex.
554
555 (define_attr "memory" "none,load,store,both,unknown"
556   (cond [(eq_attr "type" "other,multi,str")
557            (const_string "unknown")
558          (eq_attr "type" "lea,fcmov,fpspc")
559            (const_string "none")
560          (eq_attr "type" "fistp,leave")
561            (const_string "both")
562          (eq_attr "type" "frndint")
563            (const_string "load")
564          (eq_attr "type" "push")
565            (if_then_else (match_operand 1 "memory_operand" "")
566              (const_string "both")
567              (const_string "store"))
568          (eq_attr "type" "pop")
569            (if_then_else (match_operand 0 "memory_operand" "")
570              (const_string "both")
571              (const_string "load"))
572          (eq_attr "type" "setcc")
573            (if_then_else (match_operand 0 "memory_operand" "")
574              (const_string "store")
575              (const_string "none"))
576          (eq_attr "type" "icmp,test,ssecmp,ssecomi,mmxcmp,fcmp")
577            (if_then_else (ior (match_operand 0 "memory_operand" "")
578                               (match_operand 1 "memory_operand" ""))
579              (const_string "load")
580              (const_string "none"))
581          (eq_attr "type" "ibr")
582            (if_then_else (match_operand 0 "memory_operand" "")
583              (const_string "load")
584              (const_string "none"))
585          (eq_attr "type" "call")
586            (if_then_else (match_operand 0 "constant_call_address_operand" "")
587              (const_string "none")
588              (const_string "load"))
589          (eq_attr "type" "callv")
590            (if_then_else (match_operand 1 "constant_call_address_operand" "")
591              (const_string "none")
592              (const_string "load"))
593          (and (eq_attr "type" "alu1,negnot,ishift1,sselog1")
594               (match_operand 1 "memory_operand" ""))
595            (const_string "both")
596          (and (match_operand 0 "memory_operand" "")
597               (match_operand 1 "memory_operand" ""))
598            (const_string "both")
599          (match_operand 0 "memory_operand" "")
600            (const_string "store")
601          (match_operand 1 "memory_operand" "")
602            (const_string "load")
603          (and (eq_attr "type"
604                  "!alu1,negnot,ishift1,
605                    imov,imovx,icmp,test,bitmanip,
606                    fmov,fcmp,fsgn,
607                    sse,ssemov,ssecmp,ssecomi,ssecvt,ssecvt1,sseicvt,sselog1,
608                    sseiadd1,mmx,mmxmov,mmxcmp,mmxcvt")
609               (match_operand 2 "memory_operand" ""))
610            (const_string "load")
611          (and (eq_attr "type" "icmov,ssemuladd,sse4arg")
612               (match_operand 3 "memory_operand" ""))
613            (const_string "load")
614         ]
615         (const_string "none")))
616
617 ;; Indicates if an instruction has both an immediate and a displacement.
618
619 (define_attr "imm_disp" "false,true,unknown"
620   (cond [(eq_attr "type" "other,multi")
621            (const_string "unknown")
622          (and (eq_attr "type" "icmp,test,imov,alu1,ishift1,rotate1")
623               (and (match_operand 0 "memory_displacement_operand" "")
624                    (match_operand 1 "immediate_operand" "")))
625            (const_string "true")
626          (and (eq_attr "type" "alu,ishift,rotate,imul,idiv")
627               (and (match_operand 0 "memory_displacement_operand" "")
628                    (match_operand 2 "immediate_operand" "")))
629            (const_string "true")
630         ]
631         (const_string "false")))
632
633 ;; Indicates if an FP operation has an integer source.
634
635 (define_attr "fp_int_src" "false,true"
636   (const_string "false"))
637
638 ;; Defines rounding mode of an FP operation.
639
640 (define_attr "i387_cw" "trunc,floor,ceil,mask_pm,uninitialized,any"
641   (const_string "any"))
642
643 ;; Define attribute to classify add/sub insns that consumes carry flag (CF)
644 (define_attr "use_carry" "0,1" (const_string "0"))
645
646 ;; Define attribute to indicate unaligned ssemov insns
647 (define_attr "movu" "0,1" (const_string "0"))
648
649 ;; Describe a user's asm statement.
650 (define_asm_attributes
651   [(set_attr "length" "128")
652    (set_attr "type" "multi")])
653
654 ;; All integer comparison codes.
655 (define_code_iterator int_cond [ne eq ge gt le lt geu gtu leu ltu ])
656
657 ;; All floating-point comparison codes.
658 (define_code_iterator fp_cond [unordered ordered
659                                uneq unge ungt unle unlt ltgt ])
660
661 (define_code_iterator plusminus [plus minus])
662
663 (define_code_iterator sat_plusminus [ss_plus us_plus ss_minus us_minus])
664
665 ;; Base name for define_insn
666 (define_code_attr plusminus_insn
667   [(plus "add") (ss_plus "ssadd") (us_plus "usadd")
668    (minus "sub") (ss_minus "sssub") (us_minus "ussub")])
669
670 ;; Base name for insn mnemonic.
671 (define_code_attr plusminus_mnemonic
672   [(plus "add") (ss_plus "adds") (us_plus "addus")
673    (minus "sub") (ss_minus "subs") (us_minus "subus")])
674
675 ;; Mark commutative operators as such in constraints.
676 (define_code_attr comm [(plus "%") (ss_plus "%") (us_plus "%")
677                         (minus "") (ss_minus "") (us_minus "")])
678
679 ;; Mapping of signed max and min
680 (define_code_iterator smaxmin [smax smin])
681
682 ;; Mapping of unsigned max and min
683 (define_code_iterator umaxmin [umax umin])
684
685 ;; Mapping of signed/unsigned max and min
686 (define_code_iterator maxmin [smax smin umax umin])
687
688 ;; Base name for integer and FP insn mnemonic
689 (define_code_attr maxminiprefix [(smax "maxs") (smin "mins")
690                                  (umax "maxu") (umin "minu")])
691 (define_code_attr maxminfprefix [(smax "max") (smin "min")])
692
693 ;; Mapping of parallel logic operators
694 (define_code_iterator plogic [and ior xor])
695
696 ;; Base name for insn mnemonic.
697 (define_code_attr plogicprefix [(and "and") (ior "or") (xor "xor")])
698
699 ;; Mapping of abs neg operators
700 (define_code_iterator absneg [abs neg])
701
702 ;; Base name for x87 insn mnemonic.
703 (define_code_attr absnegprefix [(abs "abs") (neg "chs")])
704
705 ;; Used in signed and unsigned widening multiplications.
706 (define_code_iterator any_extend [sign_extend zero_extend])
707
708 ;; Used in signed and unsigned divisions.
709 (define_code_iterator any_div [div udiv])
710
711 ;; Various insn prefixes for signed and unsigned operations.
712 (define_code_attr u [(sign_extend "") (zero_extend "u")
713                      (div "") (udiv "u")])
714 (define_code_attr s [(sign_extend "s") (zero_extend "u")])
715
716 ;; Instruction prefix for signed and unsigned operations.
717 (define_code_attr sgnprefix [(sign_extend "i") (zero_extend "")
718                              (div "i") (udiv "")])
719
720 ;; All single word integer modes.
721 (define_mode_iterator SWI [QI HI SI (DI "TARGET_64BIT")])
722
723 ;; Single word integer modes without QImode.
724 (define_mode_iterator SWI248 [HI SI (DI "TARGET_64BIT")])
725
726 ;; Single word integer modes without QImode and HImode.
727 (define_mode_iterator SWI48 [SI (DI "TARGET_64BIT")])
728
729 ;; All math-dependant single and double word integer modes.
730 (define_mode_iterator SDWIM [(QI "TARGET_QIMODE_MATH")
731                              (HI "TARGET_HIMODE_MATH")
732                              SI DI (TI "TARGET_64BIT")])
733
734 ;; Math-dependant single word integer modes without QImode.
735 (define_mode_iterator SWIM248 [(HI "TARGET_HIMODE_MATH")
736                                SI (DI "TARGET_64BIT")])
737
738 ;; Half mode for double word integer modes.
739 (define_mode_iterator DWIH [(SI "!TARGET_64BIT")
740                             (DI "TARGET_64BIT")])
741
742 ;; Double word integer modes.
743 (define_mode_attr DWI [(SI "DI") (DI "TI")])
744 (define_mode_attr dwi [(SI "di") (DI "ti")])
745
746 ;; Instruction suffix for integer modes.
747 (define_mode_attr imodesuffix [(QI "b") (HI "w") (SI "l") (DI "q")])
748
749 ;; Register class for integer modes.
750 (define_mode_attr r [(QI "q") (HI "r") (SI "r") (DI "r")])
751
752 ;; Immediate operand constraint for integer modes.
753 (define_mode_attr i [(QI "n") (HI "n") (SI "i") (DI "e")])
754
755 ;; General operand constraint for word modes.
756 (define_mode_attr g [(SI "g") (DI "rme")])
757
758 ;; Immediate operand constraint for double integer modes.
759 (define_mode_attr di [(SI "iF") (DI "e")])
760
761 ;; General operand predicate for integer modes.
762 (define_mode_attr general_operand
763         [(QI "general_operand")
764          (HI "general_operand")
765          (SI "general_operand")
766          (DI "x86_64_general_operand")
767          (TI "x86_64_general_operand")])
768
769 ;; SSE and x87 SFmode and DFmode floating point modes
770 (define_mode_iterator MODEF [SF DF])
771
772 ;; All x87 floating point modes
773 (define_mode_iterator X87MODEF [SF DF XF])
774
775 ;; All integer modes handled by x87 fisttp operator.
776 (define_mode_iterator X87MODEI [HI SI DI])
777
778 ;; All integer modes handled by integer x87 operators.
779 (define_mode_iterator X87MODEI12 [HI SI])
780
781 ;; All integer modes handled by SSE cvtts?2si* operators.
782 (define_mode_iterator SSEMODEI24 [SI DI])
783
784 ;; SSE asm suffix for floating point modes
785 (define_mode_attr ssemodefsuffix [(SF "s") (DF "d")])
786
787 ;; SSE vector mode corresponding to a scalar mode
788 (define_mode_attr ssevecmode
789   [(QI "V16QI") (HI "V8HI") (SI "V4SI") (DI "V2DI") (SF "V4SF") (DF "V2DF")])
790
791 ;; Instruction suffix for REX 64bit operators.
792 (define_mode_attr rex64suffix [(SI "") (DI "{q}")])
793
794 ;; This mode iterator allows :P to be used for patterns that operate on
795 ;; pointer-sized quantities.  Exactly one of the two alternatives will match.
796 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
797 \f
798 ;; Scheduling descriptions
799
800 (include "pentium.md")
801 (include "ppro.md")
802 (include "k6.md")
803 (include "athlon.md")
804 (include "geode.md")
805 (include "atom.md")
806
807 \f
808 ;; Operand and operator predicates and constraints
809
810 (include "predicates.md")
811 (include "constraints.md")
812
813 \f
814 ;; Compare and branch/compare and store instructions.
815
816 (define_expand "cbranchti4"
817   [(set (reg:CC FLAGS_REG)
818         (compare:CC (match_operand:TI 1 "nonimmediate_operand" "")
819                     (match_operand:TI 2 "x86_64_general_operand" "")))
820    (set (pc) (if_then_else
821               (match_operator 0 "comparison_operator"
822                [(reg:CC FLAGS_REG)
823                 (const_int 0)])
824               (label_ref (match_operand 3 "" ""))
825               (pc)))]
826   "TARGET_64BIT"
827 {
828   if (MEM_P (operands[1]) && MEM_P (operands[2]))
829     operands[1] = force_reg (TImode, operands[1]);
830   ix86_compare_op0 = operands[1];
831   ix86_compare_op1 = operands[2];
832   ix86_expand_branch (GET_CODE (operands[0]), operands[3]);
833   DONE;
834 })
835
836 (define_expand "cbranchdi4"
837   [(set (reg:CC FLAGS_REG)
838         (compare:CC (match_operand:DI 1 "nonimmediate_operand" "")
839                     (match_operand:DI 2 "x86_64_general_operand" "")))
840    (set (pc) (if_then_else
841               (match_operator 0 "comparison_operator"
842                [(reg:CC FLAGS_REG)
843                 (const_int 0)])
844               (label_ref (match_operand 3 "" ""))
845               (pc)))]
846   ""
847 {
848   if (MEM_P (operands[1]) && MEM_P (operands[2]))
849     operands[1] = force_reg (DImode, operands[1]);
850   ix86_compare_op0 = operands[1];
851   ix86_compare_op1 = operands[2];
852   ix86_expand_branch (GET_CODE (operands[0]), operands[3]);
853   DONE;
854 })
855
856 (define_expand "cstoredi4"
857   [(set (reg:CC FLAGS_REG)
858         (compare:CC (match_operand:DI 2 "nonimmediate_operand" "")
859                     (match_operand:DI 3 "x86_64_general_operand" "")))
860    (set (match_operand:QI 0 "register_operand" "")
861               (match_operator 1 "comparison_operator"
862                [(reg:CC FLAGS_REG)
863                 (const_int 0)]))]
864   "TARGET_64BIT"
865 {
866   if (MEM_P (operands[2]) && MEM_P (operands[3]))
867     operands[2] = force_reg (DImode, operands[2]);
868   ix86_compare_op0 = operands[2];
869   ix86_compare_op1 = operands[3];
870   ix86_expand_setcc (GET_CODE (operands[1]), operands[0]);
871   DONE;
872 })
873
874 (define_expand "cbranchsi4"
875   [(set (reg:CC FLAGS_REG)
876         (compare:CC (match_operand:SI 1 "cmpsi_operand" "")
877                     (match_operand:SI 2 "general_operand" "")))
878    (set (pc) (if_then_else
879               (match_operator 0 "comparison_operator"
880                [(reg:CC FLAGS_REG)
881                 (const_int 0)])
882               (label_ref (match_operand 3 "" ""))
883               (pc)))]
884   ""
885 {
886   if (MEM_P (operands[1]) && MEM_P (operands[2]))
887     operands[1] = force_reg (SImode, operands[1]);
888   ix86_compare_op0 = operands[1];
889   ix86_compare_op1 = operands[2];
890   ix86_expand_branch (GET_CODE (operands[0]), operands[3]);
891   DONE;
892 })
893
894 (define_expand "cstoresi4"
895   [(set (reg:CC FLAGS_REG)
896         (compare:CC (match_operand:SI 2 "cmpsi_operand" "")
897                     (match_operand:SI 3 "general_operand" "")))
898    (set (match_operand:QI 0 "register_operand" "")
899               (match_operator 1 "comparison_operator"
900                [(reg:CC FLAGS_REG)
901                 (const_int 0)]))]
902   ""
903 {
904   if (MEM_P (operands[2]) && MEM_P (operands[3]))
905     operands[2] = force_reg (SImode, operands[2]);
906   ix86_compare_op0 = operands[2];
907   ix86_compare_op1 = operands[3];
908   ix86_expand_setcc (GET_CODE (operands[1]), operands[0]);
909   DONE;
910 })
911
912 (define_expand "cbranchhi4"
913   [(set (reg:CC FLAGS_REG)
914         (compare:CC (match_operand:HI 1 "nonimmediate_operand" "")
915                     (match_operand:HI 2 "general_operand" "")))
916    (set (pc) (if_then_else
917               (match_operator 0 "comparison_operator"
918                [(reg:CC FLAGS_REG)
919                 (const_int 0)])
920               (label_ref (match_operand 3 "" ""))
921               (pc)))]
922   ""
923 {
924   if (MEM_P (operands[1]) && MEM_P (operands[2]))
925     operands[1] = force_reg (HImode, operands[1]);
926   ix86_compare_op0 = operands[1];
927   ix86_compare_op1 = operands[2];
928   ix86_expand_branch (GET_CODE (operands[0]), operands[3]);
929   DONE;
930 })
931
932 (define_expand "cstorehi4"
933   [(set (reg:CC FLAGS_REG)
934         (compare:CC (match_operand:HI 2 "nonimmediate_operand" "")
935                     (match_operand:HI 3 "general_operand" "")))
936    (set (match_operand:QI 0 "register_operand" "")
937               (match_operator 1 "comparison_operator"
938                [(reg:CC FLAGS_REG)
939                 (const_int 0)]))]
940   ""
941 {
942   if (MEM_P (operands[2]) && MEM_P (operands[3]))
943     operands[2] = force_reg (HImode, operands[2]);
944   ix86_compare_op0 = operands[2];
945   ix86_compare_op1 = operands[3];
946   ix86_expand_setcc (GET_CODE (operands[1]), operands[0]);
947   DONE;
948 })
949
950
951 (define_expand "cbranchqi4"
952   [(set (reg:CC FLAGS_REG)
953         (compare:CC (match_operand:QI 1 "nonimmediate_operand" "")
954                     (match_operand:QI 2 "general_operand" "")))
955    (set (pc) (if_then_else
956               (match_operator 0 "comparison_operator"
957                [(reg:CC FLAGS_REG)
958                 (const_int 0)])
959               (label_ref (match_operand 3 "" ""))
960               (pc)))]
961   ""
962 {
963   if (MEM_P (operands[1]) && MEM_P (operands[2]))
964     operands[1] = force_reg (QImode, operands[1]);
965   ix86_compare_op0 = operands[1];
966   ix86_compare_op1 = operands[2];
967   ix86_expand_branch (GET_CODE (operands[0]), operands[3]);
968   DONE;
969 })
970
971
972 (define_expand "cstoreqi4"
973   [(set (reg:CC FLAGS_REG)
974         (compare:CC (match_operand:QI 2 "nonimmediate_operand" "")
975                     (match_operand:QI 3 "general_operand" "")))
976    (set (match_operand:QI 0 "register_operand" "")
977               (match_operator 1 "comparison_operator"
978                [(reg:CC FLAGS_REG)
979                 (const_int 0)]))]
980   ""
981 {
982   if (MEM_P (operands[2]) && MEM_P (operands[3]))
983     operands[2] = force_reg (QImode, operands[2]);
984   ix86_compare_op0 = operands[2];
985   ix86_compare_op1 = operands[3];
986   ix86_expand_setcc (GET_CODE (operands[1]), operands[0]);
987   DONE;
988 })
989
990
991 (define_insn "cmpdi_ccno_1_rex64"
992   [(set (reg FLAGS_REG)
993         (compare (match_operand:DI 0 "nonimmediate_operand" "r,?mr")
994                  (match_operand:DI 1 "const0_operand" "")))]
995   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
996   "@
997    test{q}\t%0, %0
998    cmp{q}\t{%1, %0|%0, %1}"
999   [(set_attr "type" "test,icmp")
1000    (set_attr "length_immediate" "0,1")
1001    (set_attr "mode" "DI")])
1002
1003 (define_insn "*cmpdi_minus_1_rex64"
1004   [(set (reg FLAGS_REG)
1005         (compare (minus:DI (match_operand:DI 0 "nonimmediate_operand" "rm,r")
1006                            (match_operand:DI 1 "x86_64_general_operand" "re,mr"))
1007                  (const_int 0)))]
1008   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)"
1009   "cmp{q}\t{%1, %0|%0, %1}"
1010   [(set_attr "type" "icmp")
1011    (set_attr "mode" "DI")])
1012
1013 (define_expand "cmpdi_1_rex64"
1014   [(set (reg:CC FLAGS_REG)
1015         (compare:CC (match_operand:DI 0 "nonimmediate_operand" "")
1016                     (match_operand:DI 1 "general_operand" "")))]
1017   "TARGET_64BIT"
1018   "")
1019
1020 (define_insn "cmpdi_1_insn_rex64"
1021   [(set (reg FLAGS_REG)
1022         (compare (match_operand:DI 0 "nonimmediate_operand" "mr,r")
1023                  (match_operand:DI 1 "x86_64_general_operand" "re,mr")))]
1024   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1025   "cmp{q}\t{%1, %0|%0, %1}"
1026   [(set_attr "type" "icmp")
1027    (set_attr "mode" "DI")])
1028
1029
1030 (define_insn "*cmpsi_ccno_1"
1031   [(set (reg FLAGS_REG)
1032         (compare (match_operand:SI 0 "nonimmediate_operand" "r,?mr")
1033                  (match_operand:SI 1 "const0_operand" "")))]
1034   "ix86_match_ccmode (insn, CCNOmode)"
1035   "@
1036    test{l}\t%0, %0
1037    cmp{l}\t{%1, %0|%0, %1}"
1038   [(set_attr "type" "test,icmp")
1039    (set_attr "length_immediate" "0,1")
1040    (set_attr "mode" "SI")])
1041
1042 (define_insn "*cmpsi_minus_1"
1043   [(set (reg FLAGS_REG)
1044         (compare (minus:SI (match_operand:SI 0 "nonimmediate_operand" "rm,r")
1045                            (match_operand:SI 1 "general_operand" "ri,mr"))
1046                  (const_int 0)))]
1047   "ix86_match_ccmode (insn, CCGOCmode)"
1048   "cmp{l}\t{%1, %0|%0, %1}"
1049   [(set_attr "type" "icmp")
1050    (set_attr "mode" "SI")])
1051
1052 (define_expand "cmpsi_1"
1053   [(set (reg:CC FLAGS_REG)
1054         (compare:CC (match_operand:SI 0 "nonimmediate_operand" "")
1055                     (match_operand:SI 1 "general_operand" "")))]
1056   ""
1057   "")
1058
1059 (define_insn "*cmpsi_1_insn"
1060   [(set (reg FLAGS_REG)
1061         (compare (match_operand:SI 0 "nonimmediate_operand" "rm,r")
1062                  (match_operand:SI 1 "general_operand" "ri,mr")))]
1063   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
1064     && ix86_match_ccmode (insn, CCmode)"
1065   "cmp{l}\t{%1, %0|%0, %1}"
1066   [(set_attr "type" "icmp")
1067    (set_attr "mode" "SI")])
1068
1069 (define_insn "*cmphi_ccno_1"
1070   [(set (reg FLAGS_REG)
1071         (compare (match_operand:HI 0 "nonimmediate_operand" "r,?mr")
1072                  (match_operand:HI 1 "const0_operand" "")))]
1073   "ix86_match_ccmode (insn, CCNOmode)"
1074   "@
1075    test{w}\t%0, %0
1076    cmp{w}\t{%1, %0|%0, %1}"
1077   [(set_attr "type" "test,icmp")
1078    (set_attr "length_immediate" "0,1")
1079    (set_attr "mode" "HI")])
1080
1081 (define_insn "*cmphi_minus_1"
1082   [(set (reg FLAGS_REG)
1083         (compare (minus:HI (match_operand:HI 0 "nonimmediate_operand" "rm,r")
1084                            (match_operand:HI 1 "general_operand" "rn,mr"))
1085                  (const_int 0)))]
1086   "ix86_match_ccmode (insn, CCGOCmode)"
1087   "cmp{w}\t{%1, %0|%0, %1}"
1088   [(set_attr "type" "icmp")
1089    (set_attr "mode" "HI")])
1090
1091 (define_insn "*cmphi_1"
1092   [(set (reg FLAGS_REG)
1093         (compare (match_operand:HI 0 "nonimmediate_operand" "rm,r")
1094                  (match_operand:HI 1 "general_operand" "rn,mr")))]
1095   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
1096    && ix86_match_ccmode (insn, CCmode)"
1097   "cmp{w}\t{%1, %0|%0, %1}"
1098   [(set_attr "type" "icmp")
1099    (set_attr "mode" "HI")])
1100
1101 (define_insn "*cmpqi_ccno_1"
1102   [(set (reg FLAGS_REG)
1103         (compare (match_operand:QI 0 "nonimmediate_operand" "q,?mq")
1104                  (match_operand:QI 1 "const0_operand" "")))]
1105   "ix86_match_ccmode (insn, CCNOmode)"
1106   "@
1107    test{b}\t%0, %0
1108    cmp{b}\t{$0, %0|%0, 0}"
1109   [(set_attr "type" "test,icmp")
1110    (set_attr "length_immediate" "0,1")
1111    (set_attr "mode" "QI")])
1112
1113 (define_insn "*cmpqi_1"
1114   [(set (reg FLAGS_REG)
1115         (compare (match_operand:QI 0 "nonimmediate_operand" "qm,q")
1116                  (match_operand:QI 1 "general_operand" "qn,mq")))]
1117   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
1118     && ix86_match_ccmode (insn, CCmode)"
1119   "cmp{b}\t{%1, %0|%0, %1}"
1120   [(set_attr "type" "icmp")
1121    (set_attr "mode" "QI")])
1122
1123 (define_insn "*cmpqi_minus_1"
1124   [(set (reg FLAGS_REG)
1125         (compare (minus:QI (match_operand:QI 0 "nonimmediate_operand" "qm,q")
1126                            (match_operand:QI 1 "general_operand" "qn,mq"))
1127                  (const_int 0)))]
1128   "ix86_match_ccmode (insn, CCGOCmode)"
1129   "cmp{b}\t{%1, %0|%0, %1}"
1130   [(set_attr "type" "icmp")
1131    (set_attr "mode" "QI")])
1132
1133 (define_insn "*cmpqi_ext_1"
1134   [(set (reg FLAGS_REG)
1135         (compare
1136           (match_operand:QI 0 "general_operand" "Qm")
1137           (subreg:QI
1138             (zero_extract:SI
1139               (match_operand 1 "ext_register_operand" "Q")
1140               (const_int 8)
1141               (const_int 8)) 0)))]
1142   "!TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1143   "cmp{b}\t{%h1, %0|%0, %h1}"
1144   [(set_attr "type" "icmp")
1145    (set_attr "mode" "QI")])
1146
1147 (define_insn "*cmpqi_ext_1_rex64"
1148   [(set (reg FLAGS_REG)
1149         (compare
1150           (match_operand:QI 0 "register_operand" "Q")
1151           (subreg:QI
1152             (zero_extract:SI
1153               (match_operand 1 "ext_register_operand" "Q")
1154               (const_int 8)
1155               (const_int 8)) 0)))]
1156   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1157   "cmp{b}\t{%h1, %0|%0, %h1}"
1158   [(set_attr "type" "icmp")
1159    (set_attr "mode" "QI")])
1160
1161 (define_insn "*cmpqi_ext_2"
1162   [(set (reg FLAGS_REG)
1163         (compare
1164           (subreg:QI
1165             (zero_extract:SI
1166               (match_operand 0 "ext_register_operand" "Q")
1167               (const_int 8)
1168               (const_int 8)) 0)
1169           (match_operand:QI 1 "const0_operand" "")))]
1170   "ix86_match_ccmode (insn, CCNOmode)"
1171   "test{b}\t%h0, %h0"
1172   [(set_attr "type" "test")
1173    (set_attr "length_immediate" "0")
1174    (set_attr "mode" "QI")])
1175
1176 (define_expand "cmpqi_ext_3"
1177   [(set (reg:CC FLAGS_REG)
1178         (compare:CC
1179           (subreg:QI
1180             (zero_extract:SI
1181               (match_operand 0 "ext_register_operand" "")
1182               (const_int 8)
1183               (const_int 8)) 0)
1184           (match_operand:QI 1 "general_operand" "")))]
1185   ""
1186   "")
1187
1188 (define_insn "cmpqi_ext_3_insn"
1189   [(set (reg FLAGS_REG)
1190         (compare
1191           (subreg:QI
1192             (zero_extract:SI
1193               (match_operand 0 "ext_register_operand" "Q")
1194               (const_int 8)
1195               (const_int 8)) 0)
1196           (match_operand:QI 1 "general_operand" "Qmn")))]
1197   "!TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1198   "cmp{b}\t{%1, %h0|%h0, %1}"
1199   [(set_attr "type" "icmp")
1200    (set_attr "modrm" "1")
1201    (set_attr "mode" "QI")])
1202
1203 (define_insn "cmpqi_ext_3_insn_rex64"
1204   [(set (reg FLAGS_REG)
1205         (compare
1206           (subreg:QI
1207             (zero_extract:SI
1208               (match_operand 0 "ext_register_operand" "Q")
1209               (const_int 8)
1210               (const_int 8)) 0)
1211           (match_operand:QI 1 "nonmemory_operand" "Qn")))]
1212   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1213   "cmp{b}\t{%1, %h0|%h0, %1}"
1214   [(set_attr "type" "icmp")
1215    (set_attr "modrm" "1")
1216    (set_attr "mode" "QI")])
1217
1218 (define_insn "*cmpqi_ext_4"
1219   [(set (reg FLAGS_REG)
1220         (compare
1221           (subreg:QI
1222             (zero_extract:SI
1223               (match_operand 0 "ext_register_operand" "Q")
1224               (const_int 8)
1225               (const_int 8)) 0)
1226           (subreg:QI
1227             (zero_extract:SI
1228               (match_operand 1 "ext_register_operand" "Q")
1229               (const_int 8)
1230               (const_int 8)) 0)))]
1231   "ix86_match_ccmode (insn, CCmode)"
1232   "cmp{b}\t{%h1, %h0|%h0, %h1}"
1233   [(set_attr "type" "icmp")
1234    (set_attr "mode" "QI")])
1235
1236 ;; These implement float point compares.
1237 ;; %%% See if we can get away with VOIDmode operands on the actual insns,
1238 ;; which would allow mix and match FP modes on the compares.  Which is what
1239 ;; the old patterns did, but with many more of them.
1240
1241 (define_expand "cbranchxf4"
1242   [(set (reg:CC FLAGS_REG)
1243         (compare:CC (match_operand:XF 1 "nonmemory_operand" "")
1244                     (match_operand:XF 2 "nonmemory_operand" "")))
1245    (set (pc) (if_then_else
1246               (match_operator 0 "ix86_fp_comparison_operator"
1247                [(reg:CC FLAGS_REG)
1248                 (const_int 0)])
1249               (label_ref (match_operand 3 "" ""))
1250               (pc)))]
1251   "TARGET_80387"
1252 {
1253   ix86_compare_op0 = operands[1];
1254   ix86_compare_op1 = operands[2];
1255   ix86_expand_branch (GET_CODE (operands[0]), operands[3]);
1256   DONE;
1257 })
1258
1259 (define_expand "cstorexf4"
1260   [(set (reg:CC FLAGS_REG)
1261         (compare:CC (match_operand:XF 2 "nonmemory_operand" "")
1262                     (match_operand:XF 3 "nonmemory_operand" "")))
1263    (set (match_operand:QI 0 "register_operand" "")
1264               (match_operator 1 "ix86_fp_comparison_operator"
1265                [(reg:CC FLAGS_REG)
1266                 (const_int 0)]))]
1267   "TARGET_80387"
1268 {
1269   ix86_compare_op0 = operands[2];
1270   ix86_compare_op1 = operands[3];
1271   ix86_expand_setcc (GET_CODE (operands[1]), operands[0]);
1272   DONE;
1273 })
1274
1275 (define_expand "cbranch<mode>4"
1276   [(set (reg:CC FLAGS_REG)
1277         (compare:CC (match_operand:MODEF 1 "cmp_fp_expander_operand" "")
1278                     (match_operand:MODEF 2 "cmp_fp_expander_operand" "")))
1279    (set (pc) (if_then_else
1280               (match_operator 0 "ix86_fp_comparison_operator"
1281                [(reg:CC FLAGS_REG)
1282                 (const_int 0)])
1283               (label_ref (match_operand 3 "" ""))
1284               (pc)))]
1285   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
1286 {
1287   ix86_compare_op0 = operands[1];
1288   ix86_compare_op1 = operands[2];
1289   ix86_expand_branch (GET_CODE (operands[0]), operands[3]);
1290   DONE;
1291 })
1292
1293 (define_expand "cstore<mode>4"
1294   [(set (reg:CC FLAGS_REG)
1295         (compare:CC (match_operand:MODEF 2 "cmp_fp_expander_operand" "")
1296                     (match_operand:MODEF 3 "cmp_fp_expander_operand" "")))
1297    (set (match_operand:QI 0 "register_operand" "")
1298               (match_operator 1 "ix86_fp_comparison_operator"
1299                [(reg:CC FLAGS_REG)
1300                 (const_int 0)]))]
1301   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
1302 {
1303   ix86_compare_op0 = operands[2];
1304   ix86_compare_op1 = operands[3];
1305   ix86_expand_setcc (GET_CODE (operands[1]), operands[0]);
1306   DONE;
1307 })
1308
1309 (define_expand "cbranchcc4"
1310   [(set (pc) (if_then_else
1311               (match_operator 0 "comparison_operator"
1312                [(match_operand 1 "flags_reg_operand" "")
1313                 (match_operand 2 "const0_operand" "")])
1314               (label_ref (match_operand 3 "" ""))
1315               (pc)))]
1316   ""
1317 {
1318   ix86_compare_op0 = operands[1];
1319   ix86_compare_op1 = operands[2];
1320   ix86_expand_branch (GET_CODE (operands[0]), operands[3]);
1321   DONE;
1322 })
1323
1324 (define_expand "cstorecc4"
1325   [(set (match_operand:QI 0 "register_operand" "")
1326               (match_operator 1 "comparison_operator"
1327                [(match_operand 2 "flags_reg_operand" "")
1328                 (match_operand 3 "const0_operand" "")]))]
1329   ""
1330 {
1331   ix86_compare_op0 = operands[2];
1332   ix86_compare_op1 = operands[3];
1333   ix86_expand_setcc (GET_CODE (operands[1]), operands[0]);
1334   DONE;
1335 })
1336
1337
1338 ;; FP compares, step 1:
1339 ;; Set the FP condition codes.
1340 ;;
1341 ;; CCFPmode     compare with exceptions
1342 ;; CCFPUmode    compare with no exceptions
1343
1344 ;; We may not use "#" to split and emit these, since the REG_DEAD notes
1345 ;; used to manage the reg stack popping would not be preserved.
1346
1347 (define_insn "*cmpfp_0"
1348   [(set (match_operand:HI 0 "register_operand" "=a")
1349         (unspec:HI
1350           [(compare:CCFP
1351              (match_operand 1 "register_operand" "f")
1352              (match_operand 2 "const0_operand" ""))]
1353         UNSPEC_FNSTSW))]
1354   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1355    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1356   "* return output_fp_compare (insn, operands, 0, 0);"
1357   [(set_attr "type" "multi")
1358    (set_attr "unit" "i387")
1359    (set (attr "mode")
1360      (cond [(match_operand:SF 1 "" "")
1361               (const_string "SF")
1362             (match_operand:DF 1 "" "")
1363               (const_string "DF")
1364            ]
1365            (const_string "XF")))])
1366
1367 (define_insn_and_split "*cmpfp_0_cc"
1368   [(set (reg:CCFP FLAGS_REG)
1369         (compare:CCFP
1370           (match_operand 1 "register_operand" "f")
1371           (match_operand 2 "const0_operand" "")))
1372    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1373   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1374    && TARGET_SAHF && !TARGET_CMOVE
1375    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1376   "#"
1377   "&& reload_completed"
1378   [(set (match_dup 0)
1379         (unspec:HI
1380           [(compare:CCFP (match_dup 1)(match_dup 2))]
1381         UNSPEC_FNSTSW))
1382    (set (reg:CC FLAGS_REG)
1383         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1384   ""
1385   [(set_attr "type" "multi")
1386    (set_attr "unit" "i387")
1387    (set (attr "mode")
1388      (cond [(match_operand:SF 1 "" "")
1389               (const_string "SF")
1390             (match_operand:DF 1 "" "")
1391               (const_string "DF")
1392            ]
1393            (const_string "XF")))])
1394
1395 (define_insn "*cmpfp_xf"
1396   [(set (match_operand:HI 0 "register_operand" "=a")
1397         (unspec:HI
1398           [(compare:CCFP
1399              (match_operand:XF 1 "register_operand" "f")
1400              (match_operand:XF 2 "register_operand" "f"))]
1401           UNSPEC_FNSTSW))]
1402   "TARGET_80387"
1403   "* return output_fp_compare (insn, operands, 0, 0);"
1404   [(set_attr "type" "multi")
1405    (set_attr "unit" "i387")
1406    (set_attr "mode" "XF")])
1407
1408 (define_insn_and_split "*cmpfp_xf_cc"
1409   [(set (reg:CCFP FLAGS_REG)
1410         (compare:CCFP
1411           (match_operand:XF 1 "register_operand" "f")
1412           (match_operand:XF 2 "register_operand" "f")))
1413    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1414   "TARGET_80387
1415    && TARGET_SAHF && !TARGET_CMOVE"
1416   "#"
1417   "&& reload_completed"
1418   [(set (match_dup 0)
1419         (unspec:HI
1420           [(compare:CCFP (match_dup 1)(match_dup 2))]
1421         UNSPEC_FNSTSW))
1422    (set (reg:CC FLAGS_REG)
1423         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1424   ""
1425   [(set_attr "type" "multi")
1426    (set_attr "unit" "i387")
1427    (set_attr "mode" "XF")])
1428
1429 (define_insn "*cmpfp_<mode>"
1430   [(set (match_operand:HI 0 "register_operand" "=a")
1431         (unspec:HI
1432           [(compare:CCFP
1433              (match_operand:MODEF 1 "register_operand" "f")
1434              (match_operand:MODEF 2 "nonimmediate_operand" "fm"))]
1435           UNSPEC_FNSTSW))]
1436   "TARGET_80387"
1437   "* return output_fp_compare (insn, operands, 0, 0);"
1438   [(set_attr "type" "multi")
1439    (set_attr "unit" "i387")
1440    (set_attr "mode" "<MODE>")])
1441
1442 (define_insn_and_split "*cmpfp_<mode>_cc"
1443   [(set (reg:CCFP FLAGS_REG)
1444         (compare:CCFP
1445           (match_operand:MODEF 1 "register_operand" "f")
1446           (match_operand:MODEF 2 "nonimmediate_operand" "fm")))
1447    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1448   "TARGET_80387
1449    && TARGET_SAHF && !TARGET_CMOVE"
1450   "#"
1451   "&& reload_completed"
1452   [(set (match_dup 0)
1453         (unspec:HI
1454           [(compare:CCFP (match_dup 1)(match_dup 2))]
1455         UNSPEC_FNSTSW))
1456    (set (reg:CC FLAGS_REG)
1457         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1458   ""
1459   [(set_attr "type" "multi")
1460    (set_attr "unit" "i387")
1461    (set_attr "mode" "<MODE>")])
1462
1463 (define_insn "*cmpfp_u"
1464   [(set (match_operand:HI 0 "register_operand" "=a")
1465         (unspec:HI
1466           [(compare:CCFPU
1467              (match_operand 1 "register_operand" "f")
1468              (match_operand 2 "register_operand" "f"))]
1469           UNSPEC_FNSTSW))]
1470   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1471    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1472   "* return output_fp_compare (insn, operands, 0, 1);"
1473   [(set_attr "type" "multi")
1474    (set_attr "unit" "i387")
1475    (set (attr "mode")
1476      (cond [(match_operand:SF 1 "" "")
1477               (const_string "SF")
1478             (match_operand:DF 1 "" "")
1479               (const_string "DF")
1480            ]
1481            (const_string "XF")))])
1482
1483 (define_insn_and_split "*cmpfp_u_cc"
1484   [(set (reg:CCFPU FLAGS_REG)
1485         (compare:CCFPU
1486           (match_operand 1 "register_operand" "f")
1487           (match_operand 2 "register_operand" "f")))
1488    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1489   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1490    && TARGET_SAHF && !TARGET_CMOVE
1491    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1492   "#"
1493   "&& reload_completed"
1494   [(set (match_dup 0)
1495         (unspec:HI
1496           [(compare:CCFPU (match_dup 1)(match_dup 2))]
1497         UNSPEC_FNSTSW))
1498    (set (reg:CC FLAGS_REG)
1499         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1500   ""
1501   [(set_attr "type" "multi")
1502    (set_attr "unit" "i387")
1503    (set (attr "mode")
1504      (cond [(match_operand:SF 1 "" "")
1505               (const_string "SF")
1506             (match_operand:DF 1 "" "")
1507               (const_string "DF")
1508            ]
1509            (const_string "XF")))])
1510
1511 (define_insn "*cmpfp_<mode>"
1512   [(set (match_operand:HI 0 "register_operand" "=a")
1513         (unspec:HI
1514           [(compare:CCFP
1515              (match_operand 1 "register_operand" "f")
1516              (match_operator 3 "float_operator"
1517                [(match_operand:X87MODEI12 2 "memory_operand" "m")]))]
1518           UNSPEC_FNSTSW))]
1519   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1520    && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))
1521    && (GET_MODE (operands [3]) == GET_MODE (operands[1]))"
1522   "* return output_fp_compare (insn, operands, 0, 0);"
1523   [(set_attr "type" "multi")
1524    (set_attr "unit" "i387")
1525    (set_attr "fp_int_src" "true")
1526    (set_attr "mode" "<MODE>")])
1527
1528 (define_insn_and_split "*cmpfp_<mode>_cc"
1529   [(set (reg:CCFP FLAGS_REG)
1530         (compare:CCFP
1531           (match_operand 1 "register_operand" "f")
1532           (match_operator 3 "float_operator"
1533             [(match_operand:X87MODEI12 2 "memory_operand" "m")])))
1534    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1535   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1536    && TARGET_SAHF && !TARGET_CMOVE
1537    && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))
1538    && (GET_MODE (operands [3]) == GET_MODE (operands[1]))"
1539   "#"
1540   "&& reload_completed"
1541   [(set (match_dup 0)
1542         (unspec:HI
1543           [(compare:CCFP
1544              (match_dup 1)
1545              (match_op_dup 3 [(match_dup 2)]))]
1546         UNSPEC_FNSTSW))
1547    (set (reg:CC FLAGS_REG)
1548         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1549   ""
1550   [(set_attr "type" "multi")
1551    (set_attr "unit" "i387")
1552    (set_attr "fp_int_src" "true")
1553    (set_attr "mode" "<MODE>")])
1554
1555 ;; FP compares, step 2
1556 ;; Move the fpsw to ax.
1557
1558 (define_insn "x86_fnstsw_1"
1559   [(set (match_operand:HI 0 "register_operand" "=a")
1560         (unspec:HI [(reg:CCFP FPSR_REG)] UNSPEC_FNSTSW))]
1561   "TARGET_80387"
1562   "fnstsw\t%0"
1563   [(set (attr "length") (symbol_ref "ix86_attr_length_address_default (insn) + 2"))
1564    (set_attr "mode" "SI")
1565    (set_attr "unit" "i387")])
1566
1567 ;; FP compares, step 3
1568 ;; Get ax into flags, general case.
1569
1570 (define_insn "x86_sahf_1"
1571   [(set (reg:CC FLAGS_REG)
1572         (unspec:CC [(match_operand:HI 0 "register_operand" "a")]
1573                    UNSPEC_SAHF))]
1574   "TARGET_SAHF"
1575 {
1576 #ifdef HAVE_AS_IX86_SAHF
1577   return "sahf";
1578 #else
1579   return ASM_BYTE "0x9e";
1580 #endif
1581 }
1582   [(set_attr "length" "1")
1583    (set_attr "athlon_decode" "vector")
1584    (set_attr "amdfam10_decode" "direct")
1585    (set_attr "mode" "SI")])
1586
1587 ;; Pentium Pro can do steps 1 through 3 in one go.
1588 ;; comi*, ucomi*, fcomi*, ficomi*,fucomi* (i387 instructions set condition codes)
1589 (define_insn "*cmpfp_i_mixed"
1590   [(set (reg:CCFP FLAGS_REG)
1591         (compare:CCFP (match_operand 0 "register_operand" "f,x")
1592                       (match_operand 1 "nonimmediate_operand" "f,xm")))]
1593   "TARGET_MIX_SSE_I387
1594    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1595    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1596   "* return output_fp_compare (insn, operands, 1, 0);"
1597   [(set_attr "type" "fcmp,ssecomi")
1598    (set_attr "prefix" "orig,maybe_vex")
1599    (set (attr "mode")
1600      (if_then_else (match_operand:SF 1 "" "")
1601         (const_string "SF")
1602         (const_string "DF")))
1603    (set (attr "prefix_rep")
1604         (if_then_else (eq_attr "type" "ssecomi")
1605                       (const_string "0")
1606                       (const_string "*")))
1607    (set (attr "prefix_data16")
1608         (cond [(eq_attr "type" "fcmp")
1609                  (const_string "*")
1610                (eq_attr "mode" "DF")
1611                  (const_string "1")
1612               ]
1613               (const_string "0")))
1614    (set_attr "athlon_decode" "vector")
1615    (set_attr "amdfam10_decode" "direct")])
1616
1617 (define_insn "*cmpfp_i_sse"
1618   [(set (reg:CCFP FLAGS_REG)
1619         (compare:CCFP (match_operand 0 "register_operand" "x")
1620                       (match_operand 1 "nonimmediate_operand" "xm")))]
1621   "TARGET_SSE_MATH
1622    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1623    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1624   "* return output_fp_compare (insn, operands, 1, 0);"
1625   [(set_attr "type" "ssecomi")
1626    (set_attr "prefix" "maybe_vex")
1627    (set (attr "mode")
1628      (if_then_else (match_operand:SF 1 "" "")
1629         (const_string "SF")
1630         (const_string "DF")))
1631    (set_attr "prefix_rep" "0")
1632    (set (attr "prefix_data16")
1633         (if_then_else (eq_attr "mode" "DF")
1634                       (const_string "1")
1635                       (const_string "0")))
1636    (set_attr "athlon_decode" "vector")
1637    (set_attr "amdfam10_decode" "direct")])
1638
1639 (define_insn "*cmpfp_i_i387"
1640   [(set (reg:CCFP FLAGS_REG)
1641         (compare:CCFP (match_operand 0 "register_operand" "f")
1642                       (match_operand 1 "register_operand" "f")))]
1643   "X87_FLOAT_MODE_P (GET_MODE (operands[0]))
1644    && TARGET_CMOVE
1645    && !(SSE_FLOAT_MODE_P (GET_MODE (operands[0])) && TARGET_SSE_MATH)
1646    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1647   "* return output_fp_compare (insn, operands, 1, 0);"
1648   [(set_attr "type" "fcmp")
1649    (set (attr "mode")
1650      (cond [(match_operand:SF 1 "" "")
1651               (const_string "SF")
1652             (match_operand:DF 1 "" "")
1653               (const_string "DF")
1654            ]
1655            (const_string "XF")))
1656    (set_attr "athlon_decode" "vector")
1657    (set_attr "amdfam10_decode" "direct")])
1658
1659 (define_insn "*cmpfp_iu_mixed"
1660   [(set (reg:CCFPU FLAGS_REG)
1661         (compare:CCFPU (match_operand 0 "register_operand" "f,x")
1662                        (match_operand 1 "nonimmediate_operand" "f,xm")))]
1663   "TARGET_MIX_SSE_I387
1664    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1665    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1666   "* return output_fp_compare (insn, operands, 1, 1);"
1667   [(set_attr "type" "fcmp,ssecomi")
1668    (set_attr "prefix" "orig,maybe_vex")
1669    (set (attr "mode")
1670      (if_then_else (match_operand:SF 1 "" "")
1671         (const_string "SF")
1672         (const_string "DF")))
1673    (set (attr "prefix_rep")
1674         (if_then_else (eq_attr "type" "ssecomi")
1675                       (const_string "0")
1676                       (const_string "*")))
1677    (set (attr "prefix_data16")
1678         (cond [(eq_attr "type" "fcmp")
1679                  (const_string "*")
1680                (eq_attr "mode" "DF")
1681                  (const_string "1")
1682               ]
1683               (const_string "0")))
1684    (set_attr "athlon_decode" "vector")
1685    (set_attr "amdfam10_decode" "direct")])
1686
1687 (define_insn "*cmpfp_iu_sse"
1688   [(set (reg:CCFPU FLAGS_REG)
1689         (compare:CCFPU (match_operand 0 "register_operand" "x")
1690                        (match_operand 1 "nonimmediate_operand" "xm")))]
1691   "TARGET_SSE_MATH
1692    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1693    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1694   "* return output_fp_compare (insn, operands, 1, 1);"
1695   [(set_attr "type" "ssecomi")
1696    (set_attr "prefix" "maybe_vex")
1697    (set (attr "mode")
1698      (if_then_else (match_operand:SF 1 "" "")
1699         (const_string "SF")
1700         (const_string "DF")))
1701    (set_attr "prefix_rep" "0")
1702    (set (attr "prefix_data16")
1703         (if_then_else (eq_attr "mode" "DF")
1704                       (const_string "1")
1705                       (const_string "0")))
1706    (set_attr "athlon_decode" "vector")
1707    (set_attr "amdfam10_decode" "direct")])
1708
1709 (define_insn "*cmpfp_iu_387"
1710   [(set (reg:CCFPU FLAGS_REG)
1711         (compare:CCFPU (match_operand 0 "register_operand" "f")
1712                        (match_operand 1 "register_operand" "f")))]
1713   "X87_FLOAT_MODE_P (GET_MODE (operands[0]))
1714    && TARGET_CMOVE
1715    && !(SSE_FLOAT_MODE_P (GET_MODE (operands[0])) && TARGET_SSE_MATH)
1716    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1717   "* return output_fp_compare (insn, operands, 1, 1);"
1718   [(set_attr "type" "fcmp")
1719    (set (attr "mode")
1720      (cond [(match_operand:SF 1 "" "")
1721               (const_string "SF")
1722             (match_operand:DF 1 "" "")
1723               (const_string "DF")
1724            ]
1725            (const_string "XF")))
1726    (set_attr "athlon_decode" "vector")
1727    (set_attr "amdfam10_decode" "direct")])
1728 \f
1729 ;; Move instructions.
1730
1731 ;; General case of fullword move.
1732
1733 (define_expand "movsi"
1734   [(set (match_operand:SI 0 "nonimmediate_operand" "")
1735         (match_operand:SI 1 "general_operand" ""))]
1736   ""
1737   "ix86_expand_move (SImode, operands); DONE;")
1738
1739 ;; Push/pop instructions.  They are separate since autoinc/dec is not a
1740 ;; general_operand.
1741 ;;
1742 ;; %%% We don't use a post-inc memory reference because x86 is not a
1743 ;; general AUTO_INC_DEC host, which impacts how it is treated in flow.
1744 ;; Changing this impacts compiler performance on other non-AUTO_INC_DEC
1745 ;; targets without our curiosities, and it is just as easy to represent
1746 ;; this differently.
1747
1748 (define_insn "*pushsi2"
1749   [(set (match_operand:SI 0 "push_operand" "=<")
1750         (match_operand:SI 1 "general_no_elim_operand" "ri*m"))]
1751   "!TARGET_64BIT"
1752   "push{l}\t%1"
1753   [(set_attr "type" "push")
1754    (set_attr "mode" "SI")])
1755
1756 ;; For 64BIT abi we always round up to 8 bytes.
1757 (define_insn "*pushsi2_rex64"
1758   [(set (match_operand:SI 0 "push_operand" "=X")
1759         (match_operand:SI 1 "nonmemory_no_elim_operand" "ri"))]
1760   "TARGET_64BIT"
1761   "push{q}\t%q1"
1762   [(set_attr "type" "push")
1763    (set_attr "mode" "SI")])
1764
1765 (define_insn "*pushsi2_prologue"
1766   [(set (match_operand:SI 0 "push_operand" "=<")
1767         (match_operand:SI 1 "general_no_elim_operand" "ri*m"))
1768    (clobber (mem:BLK (scratch)))]
1769   "!TARGET_64BIT"
1770   "push{l}\t%1"
1771   [(set_attr "type" "push")
1772    (set_attr "mode" "SI")])
1773
1774 (define_insn "*popsi1_epilogue"
1775   [(set (match_operand:SI 0 "nonimmediate_operand" "=r*m")
1776         (mem:SI (reg:SI SP_REG)))
1777    (set (reg:SI SP_REG)
1778         (plus:SI (reg:SI SP_REG) (const_int 4)))
1779    (clobber (mem:BLK (scratch)))]
1780   "!TARGET_64BIT"
1781   "pop{l}\t%0"
1782   [(set_attr "type" "pop")
1783    (set_attr "mode" "SI")])
1784
1785 (define_insn "popsi1"
1786   [(set (match_operand:SI 0 "nonimmediate_operand" "=r*m")
1787         (mem:SI (reg:SI SP_REG)))
1788    (set (reg:SI SP_REG)
1789         (plus:SI (reg:SI SP_REG) (const_int 4)))]
1790   "!TARGET_64BIT"
1791   "pop{l}\t%0"
1792   [(set_attr "type" "pop")
1793    (set_attr "mode" "SI")])
1794
1795 (define_insn "*movsi_xor"
1796   [(set (match_operand:SI 0 "register_operand" "=r")
1797         (match_operand:SI 1 "const0_operand" ""))
1798    (clobber (reg:CC FLAGS_REG))]
1799   "reload_completed"
1800   "xor{l}\t%0, %0"
1801   [(set_attr "type" "alu1")
1802    (set_attr "mode" "SI")
1803    (set_attr "length_immediate" "0")])
1804
1805 (define_insn "*movsi_or"
1806   [(set (match_operand:SI 0 "register_operand" "=r")
1807         (match_operand:SI 1 "immediate_operand" "i"))
1808    (clobber (reg:CC FLAGS_REG))]
1809   "reload_completed
1810    && operands[1] == constm1_rtx"
1811 {
1812   operands[1] = constm1_rtx;
1813   return "or{l}\t{%1, %0|%0, %1}";
1814 }
1815   [(set_attr "type" "alu1")
1816    (set_attr "mode" "SI")
1817    (set_attr "length_immediate" "1")])
1818
1819 (define_insn "*movsi_1"
1820   [(set (match_operand:SI 0 "nonimmediate_operand"
1821                         "=r,m ,*y,*y,?rm,?*y,*x,*x,?r ,m ,?*Yi,*x")
1822         (match_operand:SI 1 "general_operand"
1823                         "g ,ri,C ,*y,*y ,rm ,C ,*x,*Yi,*x,r   ,m "))]
1824   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
1825 {
1826   switch (get_attr_type (insn))
1827     {
1828     case TYPE_SSELOG1:
1829       if (get_attr_mode (insn) == MODE_TI)
1830         return "%vpxor\t%0, %d0";
1831       return "%vxorps\t%0, %d0";
1832
1833     case TYPE_SSEMOV:
1834       switch (get_attr_mode (insn))
1835         {
1836         case MODE_TI:
1837           return "%vmovdqa\t{%1, %0|%0, %1}";
1838         case MODE_V4SF:
1839           return "%vmovaps\t{%1, %0|%0, %1}";
1840         case MODE_SI:
1841           return "%vmovd\t{%1, %0|%0, %1}";
1842         case MODE_SF:
1843           return "%vmovss\t{%1, %0|%0, %1}";
1844         default:
1845           gcc_unreachable ();
1846         }
1847
1848     case TYPE_MMX:
1849       return "pxor\t%0, %0";
1850
1851     case TYPE_MMXMOV:
1852       if (get_attr_mode (insn) == MODE_DI)
1853         return "movq\t{%1, %0|%0, %1}";
1854       return "movd\t{%1, %0|%0, %1}";
1855
1856     case TYPE_LEA:
1857       return "lea{l}\t{%1, %0|%0, %1}";
1858
1859     default:
1860       gcc_assert (!flag_pic || LEGITIMATE_PIC_OPERAND_P (operands[1]));
1861       return "mov{l}\t{%1, %0|%0, %1}";
1862     }
1863 }
1864   [(set (attr "type")
1865      (cond [(eq_attr "alternative" "2")
1866               (const_string "mmx")
1867             (eq_attr "alternative" "3,4,5")
1868               (const_string "mmxmov")
1869             (eq_attr "alternative" "6")
1870               (const_string "sselog1")
1871             (eq_attr "alternative" "7,8,9,10,11")
1872               (const_string "ssemov")
1873             (match_operand:DI 1 "pic_32bit_operand" "")
1874               (const_string "lea")
1875            ]
1876            (const_string "imov")))
1877    (set (attr "prefix")
1878      (if_then_else (eq_attr "alternative" "0,1,2,3,4,5")
1879        (const_string "orig")
1880        (const_string "maybe_vex")))
1881    (set (attr "prefix_data16")
1882      (if_then_else (and (eq_attr "type" "ssemov") (eq_attr "mode" "SI"))
1883        (const_string "1")
1884        (const_string "*")))
1885    (set (attr "mode")
1886      (cond [(eq_attr "alternative" "2,3")
1887               (const_string "DI")
1888             (eq_attr "alternative" "6,7")
1889               (if_then_else
1890                 (eq (symbol_ref "TARGET_SSE2") (const_int 0))
1891                 (const_string "V4SF")
1892                 (const_string "TI"))
1893             (and (eq_attr "alternative" "8,9,10,11")
1894                  (eq (symbol_ref "TARGET_SSE2") (const_int 0)))
1895               (const_string "SF")
1896            ]
1897            (const_string "SI")))])
1898
1899 ;; Stores and loads of ax to arbitrary constant address.
1900 ;; We fake an second form of instruction to force reload to load address
1901 ;; into register when rax is not available
1902 (define_insn "*movabssi_1_rex64"
1903   [(set (mem:SI (match_operand:DI 0 "x86_64_movabs_operand" "i,r"))
1904         (match_operand:SI 1 "nonmemory_operand" "a,er"))]
1905   "TARGET_64BIT && ix86_check_movabs (insn, 0)"
1906   "@
1907    movabs{l}\t{%1, %P0|%P0, %1}
1908    mov{l}\t{%1, %a0|%a0, %1}"
1909   [(set_attr "type" "imov")
1910    (set_attr "modrm" "0,*")
1911    (set_attr "length_address" "8,0")
1912    (set_attr "length_immediate" "0,*")
1913    (set_attr "memory" "store")
1914    (set_attr "mode" "SI")])
1915
1916 (define_insn "*movabssi_2_rex64"
1917   [(set (match_operand:SI 0 "register_operand" "=a,r")
1918         (mem:SI (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
1919   "TARGET_64BIT && ix86_check_movabs (insn, 1)"
1920   "@
1921    movabs{l}\t{%P1, %0|%0, %P1}
1922    mov{l}\t{%a1, %0|%0, %a1}"
1923   [(set_attr "type" "imov")
1924    (set_attr "modrm" "0,*")
1925    (set_attr "length_address" "8,0")
1926    (set_attr "length_immediate" "0")
1927    (set_attr "memory" "load")
1928    (set_attr "mode" "SI")])
1929
1930 (define_insn "*swapsi"
1931   [(set (match_operand:SI 0 "register_operand" "+r")
1932         (match_operand:SI 1 "register_operand" "+r"))
1933    (set (match_dup 1)
1934         (match_dup 0))]
1935   ""
1936   "xchg{l}\t%1, %0"
1937   [(set_attr "type" "imov")
1938    (set_attr "mode" "SI")
1939    (set_attr "pent_pair" "np")
1940    (set_attr "athlon_decode" "vector")
1941    (set_attr "amdfam10_decode" "double")])
1942
1943 (define_expand "movhi"
1944   [(set (match_operand:HI 0 "nonimmediate_operand" "")
1945         (match_operand:HI 1 "general_operand" ""))]
1946   ""
1947   "ix86_expand_move (HImode, operands); DONE;")
1948
1949 (define_insn "*pushhi2"
1950   [(set (match_operand:HI 0 "push_operand" "=X")
1951         (match_operand:HI 1 "nonmemory_no_elim_operand" "rn"))]
1952   "!TARGET_64BIT"
1953   "push{l}\t%k1"
1954   [(set_attr "type" "push")
1955    (set_attr "mode" "SI")])
1956
1957 ;; For 64BIT abi we always round up to 8 bytes.
1958 (define_insn "*pushhi2_rex64"
1959   [(set (match_operand:HI 0 "push_operand" "=X")
1960         (match_operand:HI 1 "nonmemory_no_elim_operand" "rn"))]
1961   "TARGET_64BIT"
1962   "push{q}\t%q1"
1963   [(set_attr "type" "push")
1964    (set_attr "mode" "DI")])
1965
1966 (define_insn "*movhi_1"
1967   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,r,m")
1968         (match_operand:HI 1 "general_operand" "r,rn,rm,rn"))]
1969   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
1970 {
1971   switch (get_attr_type (insn))
1972     {
1973     case TYPE_IMOVX:
1974       /* movzwl is faster than movw on p2 due to partial word stalls,
1975          though not as fast as an aligned movl.  */
1976       return "movz{wl|x}\t{%1, %k0|%k0, %1}";
1977     default:
1978       if (get_attr_mode (insn) == MODE_SI)
1979         return "mov{l}\t{%k1, %k0|%k0, %k1}";
1980       else
1981         return "mov{w}\t{%1, %0|%0, %1}";
1982     }
1983 }
1984   [(set (attr "type")
1985      (cond [(ne (symbol_ref "optimize_function_for_size_p (cfun)") (const_int 0))
1986               (const_string "imov")
1987             (and (eq_attr "alternative" "0")
1988                  (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
1989                           (const_int 0))
1990                       (eq (symbol_ref "TARGET_HIMODE_MATH")
1991                           (const_int 0))))
1992               (const_string "imov")
1993             (and (eq_attr "alternative" "1,2")
1994                  (match_operand:HI 1 "aligned_operand" ""))
1995               (const_string "imov")
1996             (and (ne (symbol_ref "TARGET_MOVX")
1997                      (const_int 0))
1998                  (eq_attr "alternative" "0,2"))
1999               (const_string "imovx")
2000            ]
2001            (const_string "imov")))
2002     (set (attr "mode")
2003       (cond [(eq_attr "type" "imovx")
2004                (const_string "SI")
2005              (and (eq_attr "alternative" "1,2")
2006                   (match_operand:HI 1 "aligned_operand" ""))
2007                (const_string "SI")
2008              (and (eq_attr "alternative" "0")
2009                   (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2010                            (const_int 0))
2011                        (eq (symbol_ref "TARGET_HIMODE_MATH")
2012                            (const_int 0))))
2013                (const_string "SI")
2014             ]
2015             (const_string "HI")))])
2016
2017 ;; Stores and loads of ax to arbitrary constant address.
2018 ;; We fake an second form of instruction to force reload to load address
2019 ;; into register when rax is not available
2020 (define_insn "*movabshi_1_rex64"
2021   [(set (mem:HI (match_operand:DI 0 "x86_64_movabs_operand" "i,r"))
2022         (match_operand:HI 1 "nonmemory_operand" "a,er"))]
2023   "TARGET_64BIT && ix86_check_movabs (insn, 0)"
2024   "@
2025    movabs{w}\t{%1, %P0|%P0, %1}
2026    mov{w}\t{%1, %a0|%a0, %1}"
2027   [(set_attr "type" "imov")
2028    (set_attr "modrm" "0,*")
2029    (set_attr "length_address" "8,0")
2030    (set_attr "length_immediate" "0,*")
2031    (set_attr "memory" "store")
2032    (set_attr "mode" "HI")])
2033
2034 (define_insn "*movabshi_2_rex64"
2035   [(set (match_operand:HI 0 "register_operand" "=a,r")
2036         (mem:HI (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
2037   "TARGET_64BIT && ix86_check_movabs (insn, 1)"
2038   "@
2039    movabs{w}\t{%P1, %0|%0, %P1}
2040    mov{w}\t{%a1, %0|%0, %a1}"
2041   [(set_attr "type" "imov")
2042    (set_attr "modrm" "0,*")
2043    (set_attr "length_address" "8,0")
2044    (set_attr "length_immediate" "0")
2045    (set_attr "memory" "load")
2046    (set_attr "mode" "HI")])
2047
2048 (define_insn "*swaphi_1"
2049   [(set (match_operand:HI 0 "register_operand" "+r")
2050         (match_operand:HI 1 "register_operand" "+r"))
2051    (set (match_dup 1)
2052         (match_dup 0))]
2053   "!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)"
2054   "xchg{l}\t%k1, %k0"
2055   [(set_attr "type" "imov")
2056    (set_attr "mode" "SI")
2057    (set_attr "pent_pair" "np")
2058    (set_attr "athlon_decode" "vector")
2059    (set_attr "amdfam10_decode" "double")])
2060
2061 ;; Not added amdfam10_decode since TARGET_PARTIAL_REG_STALL is disabled for AMDFAM10
2062 (define_insn "*swaphi_2"
2063   [(set (match_operand:HI 0 "register_operand" "+r")
2064         (match_operand:HI 1 "register_operand" "+r"))
2065    (set (match_dup 1)
2066         (match_dup 0))]
2067   "TARGET_PARTIAL_REG_STALL"
2068   "xchg{w}\t%1, %0"
2069   [(set_attr "type" "imov")
2070    (set_attr "mode" "HI")
2071    (set_attr "pent_pair" "np")
2072    (set_attr "athlon_decode" "vector")])
2073
2074 (define_expand "movstricthi"
2075   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" ""))
2076         (match_operand:HI 1 "general_operand" ""))]
2077   ""
2078 {
2079   if (TARGET_PARTIAL_REG_STALL && optimize_function_for_speed_p (cfun))
2080     FAIL;
2081   /* Don't generate memory->memory moves, go through a register */
2082   if (MEM_P (operands[0]) && MEM_P (operands[1]))
2083     operands[1] = force_reg (HImode, operands[1]);
2084 })
2085
2086 (define_insn "*movstricthi_1"
2087   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+rm,r"))
2088         (match_operand:HI 1 "general_operand" "rn,m"))]
2089   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
2090    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2091   "mov{w}\t{%1, %0|%0, %1}"
2092   [(set_attr "type" "imov")
2093    (set_attr "mode" "HI")])
2094
2095 (define_insn "*movstricthi_xor"
2096   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+r"))
2097         (match_operand:HI 1 "const0_operand" ""))
2098    (clobber (reg:CC FLAGS_REG))]
2099   "reload_completed"
2100   "xor{w}\t%0, %0"
2101   [(set_attr "type" "alu1")
2102    (set_attr "mode" "HI")
2103    (set_attr "length_immediate" "0")])
2104
2105 (define_expand "movqi"
2106   [(set (match_operand:QI 0 "nonimmediate_operand" "")
2107         (match_operand:QI 1 "general_operand" ""))]
2108   ""
2109   "ix86_expand_move (QImode, operands); DONE;")
2110
2111 ;; emit_push_insn when it calls move_by_pieces requires an insn to
2112 ;; "push a byte".  But actually we use pushl, which has the effect
2113 ;; of rounding the amount pushed up to a word.
2114
2115 (define_insn "*pushqi2"
2116   [(set (match_operand:QI 0 "push_operand" "=X")
2117         (match_operand:QI 1 "nonmemory_no_elim_operand" "rn"))]
2118   "!TARGET_64BIT"
2119   "push{l}\t%k1"
2120   [(set_attr "type" "push")
2121    (set_attr "mode" "SI")])
2122
2123 ;; For 64BIT abi we always round up to 8 bytes.
2124 (define_insn "*pushqi2_rex64"
2125   [(set (match_operand:QI 0 "push_operand" "=X")
2126         (match_operand:QI 1 "nonmemory_no_elim_operand" "qn"))]
2127   "TARGET_64BIT"
2128   "push{q}\t%q1"
2129   [(set_attr "type" "push")
2130    (set_attr "mode" "DI")])
2131
2132 ;; Situation is quite tricky about when to choose full sized (SImode) move
2133 ;; over QImode moves.  For Q_REG -> Q_REG move we use full size only for
2134 ;; partial register dependency machines (such as AMD Athlon), where QImode
2135 ;; moves issue extra dependency and for partial register stalls machines
2136 ;; that don't use QImode patterns (and QImode move cause stall on the next
2137 ;; instruction).
2138 ;;
2139 ;; For loads of Q_REG to NONQ_REG we use full sized moves except for partial
2140 ;; register stall machines with, where we use QImode instructions, since
2141 ;; partial register stall can be caused there.  Then we use movzx.
2142 (define_insn "*movqi_1"
2143   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,q ,q ,r,r ,?r,m")
2144         (match_operand:QI 1 "general_operand"      " q,qn,qm,q,rn,qm,qn"))]
2145   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2146 {
2147   switch (get_attr_type (insn))
2148     {
2149     case TYPE_IMOVX:
2150       gcc_assert (ANY_QI_REG_P (operands[1]) || MEM_P (operands[1]));
2151       return "movz{bl|x}\t{%1, %k0|%k0, %1}";
2152     default:
2153       if (get_attr_mode (insn) == MODE_SI)
2154         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2155       else
2156         return "mov{b}\t{%1, %0|%0, %1}";
2157     }
2158 }
2159   [(set (attr "type")
2160      (cond [(and (eq_attr "alternative" "5")
2161                  (not (match_operand:QI 1 "aligned_operand" "")))
2162               (const_string "imovx")
2163             (ne (symbol_ref "optimize_function_for_size_p (cfun)") (const_int 0))
2164               (const_string "imov")
2165             (and (eq_attr "alternative" "3")
2166                  (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2167                           (const_int 0))
2168                       (eq (symbol_ref "TARGET_QIMODE_MATH")
2169                           (const_int 0))))
2170               (const_string "imov")
2171             (eq_attr "alternative" "3,5")
2172               (const_string "imovx")
2173             (and (ne (symbol_ref "TARGET_MOVX")
2174                      (const_int 0))
2175                  (eq_attr "alternative" "2"))
2176               (const_string "imovx")
2177            ]
2178            (const_string "imov")))
2179    (set (attr "mode")
2180       (cond [(eq_attr "alternative" "3,4,5")
2181                (const_string "SI")
2182              (eq_attr "alternative" "6")
2183                (const_string "QI")
2184              (eq_attr "type" "imovx")
2185                (const_string "SI")
2186              (and (eq_attr "type" "imov")
2187                   (and (eq_attr "alternative" "0,1")
2188                        (and (ne (symbol_ref "TARGET_PARTIAL_REG_DEPENDENCY")
2189                                 (const_int 0))
2190                             (and (eq (symbol_ref "optimize_function_for_size_p (cfun)")
2191                                      (const_int 0))
2192                                  (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2193                                      (const_int 0))))))
2194                (const_string "SI")
2195              ;; Avoid partial register stalls when not using QImode arithmetic
2196              (and (eq_attr "type" "imov")
2197                   (and (eq_attr "alternative" "0,1")
2198                        (and (ne (symbol_ref "TARGET_PARTIAL_REG_STALL")
2199                                 (const_int 0))
2200                             (eq (symbol_ref "TARGET_QIMODE_MATH")
2201                                 (const_int 0)))))
2202                (const_string "SI")
2203            ]
2204            (const_string "QI")))])
2205
2206 (define_insn "*swapqi_1"
2207   [(set (match_operand:QI 0 "register_operand" "+r")
2208         (match_operand:QI 1 "register_operand" "+r"))
2209    (set (match_dup 1)
2210         (match_dup 0))]
2211   "!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)"
2212   "xchg{l}\t%k1, %k0"
2213   [(set_attr "type" "imov")
2214    (set_attr "mode" "SI")
2215    (set_attr "pent_pair" "np")
2216    (set_attr "athlon_decode" "vector")
2217    (set_attr "amdfam10_decode" "vector")])
2218
2219 ;; Not added amdfam10_decode since TARGET_PARTIAL_REG_STALL is disabled for AMDFAM10
2220 (define_insn "*swapqi_2"
2221   [(set (match_operand:QI 0 "register_operand" "+q")
2222         (match_operand:QI 1 "register_operand" "+q"))
2223    (set (match_dup 1)
2224         (match_dup 0))]
2225   "TARGET_PARTIAL_REG_STALL"
2226   "xchg{b}\t%1, %0"
2227   [(set_attr "type" "imov")
2228    (set_attr "mode" "QI")
2229    (set_attr "pent_pair" "np")
2230    (set_attr "athlon_decode" "vector")])
2231
2232 (define_expand "movstrictqi"
2233   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" ""))
2234         (match_operand:QI 1 "general_operand" ""))]
2235   ""
2236 {
2237   if (TARGET_PARTIAL_REG_STALL && optimize_function_for_speed_p (cfun))
2238     FAIL;
2239   /* Don't generate memory->memory moves, go through a register.  */
2240   if (MEM_P (operands[0]) && MEM_P (operands[1]))
2241     operands[1] = force_reg (QImode, operands[1]);
2242 })
2243
2244 (define_insn "*movstrictqi_1"
2245   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
2246         (match_operand:QI 1 "general_operand" "*qn,m"))]
2247   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
2248    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2249   "mov{b}\t{%1, %0|%0, %1}"
2250   [(set_attr "type" "imov")
2251    (set_attr "mode" "QI")])
2252
2253 (define_insn "*movstrictqi_xor"
2254   [(set (strict_low_part (match_operand:QI 0 "q_regs_operand" "+q"))
2255         (match_operand:QI 1 "const0_operand" ""))
2256    (clobber (reg:CC FLAGS_REG))]
2257   "reload_completed"
2258   "xor{b}\t%0, %0"
2259   [(set_attr "type" "alu1")
2260    (set_attr "mode" "QI")
2261    (set_attr "length_immediate" "0")])
2262
2263 (define_insn "*movsi_extv_1"
2264   [(set (match_operand:SI 0 "register_operand" "=R")
2265         (sign_extract:SI (match_operand 1 "ext_register_operand" "Q")
2266                          (const_int 8)
2267                          (const_int 8)))]
2268   ""
2269   "movs{bl|x}\t{%h1, %0|%0, %h1}"
2270   [(set_attr "type" "imovx")
2271    (set_attr "mode" "SI")])
2272
2273 (define_insn "*movhi_extv_1"
2274   [(set (match_operand:HI 0 "register_operand" "=R")
2275         (sign_extract:HI (match_operand 1 "ext_register_operand" "Q")
2276                          (const_int 8)
2277                          (const_int 8)))]
2278   ""
2279   "movs{bl|x}\t{%h1, %k0|%k0, %h1}"
2280   [(set_attr "type" "imovx")
2281    (set_attr "mode" "SI")])
2282
2283 (define_insn "*movqi_extv_1"
2284   [(set (match_operand:QI 0 "nonimmediate_operand" "=Qm,?r")
2285         (sign_extract:QI (match_operand 1 "ext_register_operand" "Q,Q")
2286                          (const_int 8)
2287                          (const_int 8)))]
2288   "!TARGET_64BIT"
2289 {
2290   switch (get_attr_type (insn))
2291     {
2292     case TYPE_IMOVX:
2293       return "movs{bl|x}\t{%h1, %k0|%k0, %h1}";
2294     default:
2295       return "mov{b}\t{%h1, %0|%0, %h1}";
2296     }
2297 }
2298   [(set (attr "type")
2299      (if_then_else (and (match_operand:QI 0 "register_operand" "")
2300                         (ior (not (match_operand:QI 0 "q_regs_operand" ""))
2301                              (ne (symbol_ref "TARGET_MOVX")
2302                                  (const_int 0))))
2303         (const_string "imovx")
2304         (const_string "imov")))
2305    (set (attr "mode")
2306      (if_then_else (eq_attr "type" "imovx")
2307         (const_string "SI")
2308         (const_string "QI")))])
2309
2310 (define_insn "*movqi_extv_1_rex64"
2311   [(set (match_operand:QI 0 "register_operand" "=Q,?R")
2312         (sign_extract:QI (match_operand 1 "ext_register_operand" "Q,Q")
2313                          (const_int 8)
2314                          (const_int 8)))]
2315   "TARGET_64BIT"
2316 {
2317   switch (get_attr_type (insn))
2318     {
2319     case TYPE_IMOVX:
2320       return "movs{bl|x}\t{%h1, %k0|%k0, %h1}";
2321     default:
2322       return "mov{b}\t{%h1, %0|%0, %h1}";
2323     }
2324 }
2325   [(set (attr "type")
2326      (if_then_else (and (match_operand:QI 0 "register_operand" "")
2327                         (ior (not (match_operand:QI 0 "q_regs_operand" ""))
2328                              (ne (symbol_ref "TARGET_MOVX")
2329                                  (const_int 0))))
2330         (const_string "imovx")
2331         (const_string "imov")))
2332    (set (attr "mode")
2333      (if_then_else (eq_attr "type" "imovx")
2334         (const_string "SI")
2335         (const_string "QI")))])
2336
2337 ;; Stores and loads of ax to arbitrary constant address.
2338 ;; We fake an second form of instruction to force reload to load address
2339 ;; into register when rax is not available
2340 (define_insn "*movabsqi_1_rex64"
2341   [(set (mem:QI (match_operand:DI 0 "x86_64_movabs_operand" "i,r"))
2342         (match_operand:QI 1 "nonmemory_operand" "a,er"))]
2343   "TARGET_64BIT && ix86_check_movabs (insn, 0)"
2344   "@
2345    movabs{b}\t{%1, %P0|%P0, %1}
2346    mov{b}\t{%1, %a0|%a0, %1}"
2347   [(set_attr "type" "imov")
2348    (set_attr "modrm" "0,*")
2349    (set_attr "length_address" "8,0")
2350    (set_attr "length_immediate" "0,*")
2351    (set_attr "memory" "store")
2352    (set_attr "mode" "QI")])
2353
2354 (define_insn "*movabsqi_2_rex64"
2355   [(set (match_operand:QI 0 "register_operand" "=a,r")
2356         (mem:QI (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
2357   "TARGET_64BIT && ix86_check_movabs (insn, 1)"
2358   "@
2359    movabs{b}\t{%P1, %0|%0, %P1}
2360    mov{b}\t{%a1, %0|%0, %a1}"
2361   [(set_attr "type" "imov")
2362    (set_attr "modrm" "0,*")
2363    (set_attr "length_address" "8,0")
2364    (set_attr "length_immediate" "0")
2365    (set_attr "memory" "load")
2366    (set_attr "mode" "QI")])
2367
2368 (define_insn "*movdi_extzv_1"
2369   [(set (match_operand:DI 0 "register_operand" "=R")
2370         (zero_extract:DI (match_operand 1 "ext_register_operand" "Q")
2371                          (const_int 8)
2372                          (const_int 8)))]
2373   "TARGET_64BIT"
2374   "movz{bl|x}\t{%h1, %k0|%k0, %h1}"
2375   [(set_attr "type" "imovx")
2376    (set_attr "mode" "SI")])
2377
2378 (define_insn "*movsi_extzv_1"
2379   [(set (match_operand:SI 0 "register_operand" "=R")
2380         (zero_extract:SI (match_operand 1 "ext_register_operand" "Q")
2381                          (const_int 8)
2382                          (const_int 8)))]
2383   ""
2384   "movz{bl|x}\t{%h1, %0|%0, %h1}"
2385   [(set_attr "type" "imovx")
2386    (set_attr "mode" "SI")])
2387
2388 (define_insn "*movqi_extzv_2"
2389   [(set (match_operand:QI 0 "nonimmediate_operand" "=Qm,?R")
2390         (subreg:QI (zero_extract:SI (match_operand 1 "ext_register_operand" "Q,Q")
2391                                     (const_int 8)
2392                                     (const_int 8)) 0))]
2393   "!TARGET_64BIT"
2394 {
2395   switch (get_attr_type (insn))
2396     {
2397     case TYPE_IMOVX:
2398       return "movz{bl|x}\t{%h1, %k0|%k0, %h1}";
2399     default:
2400       return "mov{b}\t{%h1, %0|%0, %h1}";
2401     }
2402 }
2403   [(set (attr "type")
2404      (if_then_else (and (match_operand:QI 0 "register_operand" "")
2405                         (ior (not (match_operand:QI 0 "q_regs_operand" ""))
2406                              (ne (symbol_ref "TARGET_MOVX")
2407                                  (const_int 0))))
2408         (const_string "imovx")
2409         (const_string "imov")))
2410    (set (attr "mode")
2411      (if_then_else (eq_attr "type" "imovx")
2412         (const_string "SI")
2413         (const_string "QI")))])
2414
2415 (define_insn "*movqi_extzv_2_rex64"
2416   [(set (match_operand:QI 0 "register_operand" "=Q,?R")
2417         (subreg:QI (zero_extract:SI (match_operand 1 "ext_register_operand" "Q,Q")
2418                                     (const_int 8)
2419                                     (const_int 8)) 0))]
2420   "TARGET_64BIT"
2421 {
2422   switch (get_attr_type (insn))
2423     {
2424     case TYPE_IMOVX:
2425       return "movz{bl|x}\t{%h1, %k0|%k0, %h1}";
2426     default:
2427       return "mov{b}\t{%h1, %0|%0, %h1}";
2428     }
2429 }
2430   [(set (attr "type")
2431      (if_then_else (ior (not (match_operand:QI 0 "q_regs_operand" ""))
2432                         (ne (symbol_ref "TARGET_MOVX")
2433                             (const_int 0)))
2434         (const_string "imovx")
2435         (const_string "imov")))
2436    (set (attr "mode")
2437      (if_then_else (eq_attr "type" "imovx")
2438         (const_string "SI")
2439         (const_string "QI")))])
2440
2441 (define_insn "movsi_insv_1"
2442   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
2443                          (const_int 8)
2444                          (const_int 8))
2445         (match_operand:SI 1 "general_operand" "Qmn"))]
2446   "!TARGET_64BIT"
2447   "mov{b}\t{%b1, %h0|%h0, %b1}"
2448   [(set_attr "type" "imov")
2449    (set_attr "mode" "QI")])
2450
2451 (define_insn "*movsi_insv_1_rex64"
2452   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
2453                          (const_int 8)
2454                          (const_int 8))
2455         (match_operand:SI 1 "nonmemory_operand" "Qn"))]
2456   "TARGET_64BIT"
2457   "mov{b}\t{%b1, %h0|%h0, %b1}"
2458   [(set_attr "type" "imov")
2459    (set_attr "mode" "QI")])
2460
2461 (define_insn "movdi_insv_1_rex64"
2462   [(set (zero_extract:DI (match_operand 0 "ext_register_operand" "+Q")
2463                          (const_int 8)
2464                          (const_int 8))
2465         (match_operand:DI 1 "nonmemory_operand" "Qn"))]
2466   "TARGET_64BIT"
2467   "mov{b}\t{%b1, %h0|%h0, %b1}"
2468   [(set_attr "type" "imov")
2469    (set_attr "mode" "QI")])
2470
2471 (define_insn "*movqi_insv_2"
2472   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
2473                          (const_int 8)
2474                          (const_int 8))
2475         (lshiftrt:SI (match_operand:SI 1 "register_operand" "Q")
2476                      (const_int 8)))]
2477   ""
2478   "mov{b}\t{%h1, %h0|%h0, %h1}"
2479   [(set_attr "type" "imov")
2480    (set_attr "mode" "QI")])
2481
2482 (define_expand "movdi"
2483   [(set (match_operand:DI 0 "nonimmediate_operand" "")
2484         (match_operand:DI 1 "general_operand" ""))]
2485   ""
2486   "ix86_expand_move (DImode, operands); DONE;")
2487
2488 (define_insn "*pushdi"
2489   [(set (match_operand:DI 0 "push_operand" "=<")
2490         (match_operand:DI 1 "general_no_elim_operand" "riF*m"))]
2491   "!TARGET_64BIT"
2492   "#")
2493
2494 (define_insn "*pushdi2_rex64"
2495   [(set (match_operand:DI 0 "push_operand" "=<,!<")
2496         (match_operand:DI 1 "general_no_elim_operand" "re*m,n"))]
2497   "TARGET_64BIT"
2498   "@
2499    push{q}\t%1
2500    #"
2501   [(set_attr "type" "push,multi")
2502    (set_attr "mode" "DI")])
2503
2504 ;; Convert impossible pushes of immediate to existing instructions.
2505 ;; First try to get scratch register and go through it.  In case this
2506 ;; fails, push sign extended lower part first and then overwrite
2507 ;; upper part by 32bit move.
2508 (define_peephole2
2509   [(match_scratch:DI 2 "r")
2510    (set (match_operand:DI 0 "push_operand" "")
2511         (match_operand:DI 1 "immediate_operand" ""))]
2512   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2513    && !x86_64_immediate_operand (operands[1], DImode)"
2514   [(set (match_dup 2) (match_dup 1))
2515    (set (match_dup 0) (match_dup 2))]
2516   "")
2517
2518 ;; We need to define this as both peepholer and splitter for case
2519 ;; peephole2 pass is not run.
2520 ;; "&& 1" is needed to keep it from matching the previous pattern.
2521 (define_peephole2
2522   [(set (match_operand:DI 0 "push_operand" "")
2523         (match_operand:DI 1 "immediate_operand" ""))]
2524   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2525    && !x86_64_immediate_operand (operands[1], DImode) && 1"
2526   [(set (match_dup 0) (match_dup 1))
2527    (set (match_dup 2) (match_dup 3))]
2528   "split_di (&operands[1], 1, &operands[2], &operands[3]);
2529    operands[1] = gen_lowpart (DImode, operands[2]);
2530    operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (DImode, stack_pointer_rtx,
2531                                                     GEN_INT (4)));
2532   ")
2533
2534 (define_split
2535   [(set (match_operand:DI 0 "push_operand" "")
2536         (match_operand:DI 1 "immediate_operand" ""))]
2537   "TARGET_64BIT && ((optimize > 0 && flag_peephole2)
2538                     ? epilogue_completed : reload_completed)
2539    && !symbolic_operand (operands[1], DImode)
2540    && !x86_64_immediate_operand (operands[1], DImode)"
2541   [(set (match_dup 0) (match_dup 1))
2542    (set (match_dup 2) (match_dup 3))]
2543   "split_di (&operands[1], 1, &operands[2], &operands[3]);
2544    operands[1] = gen_lowpart (DImode, operands[2]);
2545    operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (DImode, stack_pointer_rtx,
2546                                                     GEN_INT (4)));
2547   ")
2548
2549 (define_insn "*pushdi2_prologue_rex64"
2550   [(set (match_operand:DI 0 "push_operand" "=<")
2551         (match_operand:DI 1 "general_no_elim_operand" "re*m"))
2552    (clobber (mem:BLK (scratch)))]
2553   "TARGET_64BIT"
2554   "push{q}\t%1"
2555   [(set_attr "type" "push")
2556    (set_attr "mode" "DI")])
2557
2558 (define_insn "*popdi1_epilogue_rex64"
2559   [(set (match_operand:DI 0 "nonimmediate_operand" "=r*m")
2560         (mem:DI (reg:DI SP_REG)))
2561    (set (reg:DI SP_REG)
2562         (plus:DI (reg:DI SP_REG) (const_int 8)))
2563    (clobber (mem:BLK (scratch)))]
2564   "TARGET_64BIT"
2565   "pop{q}\t%0"
2566   [(set_attr "type" "pop")
2567    (set_attr "mode" "DI")])
2568
2569 (define_insn "popdi1"
2570   [(set (match_operand:DI 0 "nonimmediate_operand" "=r*m")
2571         (mem:DI (reg:DI SP_REG)))
2572    (set (reg:DI SP_REG)
2573         (plus:DI (reg:DI SP_REG) (const_int 8)))]
2574   "TARGET_64BIT"
2575   "pop{q}\t%0"
2576   [(set_attr "type" "pop")
2577    (set_attr "mode" "DI")])
2578
2579 (define_insn "*movdi_xor_rex64"
2580   [(set (match_operand:DI 0 "register_operand" "=r")
2581         (match_operand:DI 1 "const0_operand" ""))
2582    (clobber (reg:CC FLAGS_REG))]
2583   "TARGET_64BIT
2584    && reload_completed"
2585   "xor{l}\t%k0, %k0";
2586   [(set_attr "type" "alu1")
2587    (set_attr "mode" "SI")
2588    (set_attr "length_immediate" "0")])
2589
2590 (define_insn "*movdi_or_rex64"
2591   [(set (match_operand:DI 0 "register_operand" "=r")
2592         (match_operand:DI 1 "const_int_operand" "i"))
2593    (clobber (reg:CC FLAGS_REG))]
2594   "TARGET_64BIT
2595    && reload_completed
2596    && operands[1] == constm1_rtx"
2597 {
2598   operands[1] = constm1_rtx;
2599   return "or{q}\t{%1, %0|%0, %1}";
2600 }
2601   [(set_attr "type" "alu1")
2602    (set_attr "mode" "DI")
2603    (set_attr "length_immediate" "1")])
2604
2605 (define_insn "*movdi_2"
2606   [(set (match_operand:DI 0 "nonimmediate_operand"
2607                         "=r  ,o  ,*y,m*y,*y,*Y2,m  ,*Y2,*Y2,*x,m ,*x,*x")
2608         (match_operand:DI 1 "general_operand"
2609                         "riFo,riF,C ,*y ,m ,C  ,*Y2,*Y2,m  ,C ,*x,*x,m "))]
2610   "!TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2611   "@
2612    #
2613    #
2614    pxor\t%0, %0
2615    movq\t{%1, %0|%0, %1}
2616    movq\t{%1, %0|%0, %1}
2617    %vpxor\t%0, %d0
2618    %vmovq\t{%1, %0|%0, %1}
2619    %vmovdqa\t{%1, %0|%0, %1}
2620    %vmovq\t{%1, %0|%0, %1}
2621    xorps\t%0, %0
2622    movlps\t{%1, %0|%0, %1}
2623    movaps\t{%1, %0|%0, %1}
2624    movlps\t{%1, %0|%0, %1}"
2625   [(set_attr "type" "*,*,mmx,mmxmov,mmxmov,sselog1,ssemov,ssemov,ssemov,sselog1,ssemov,ssemov,ssemov")
2626    (set (attr "prefix")
2627      (if_then_else (eq_attr "alternative" "5,6,7,8")
2628        (const_string "vex")
2629        (const_string "orig")))
2630    (set_attr "mode" "DI,DI,DI,DI,DI,TI,DI,TI,DI,V4SF,V2SF,V4SF,V2SF")])
2631
2632 (define_split
2633   [(set (match_operand:DI 0 "push_operand" "")
2634         (match_operand:DI 1 "general_operand" ""))]
2635   "!TARGET_64BIT && reload_completed
2636    && (! MMX_REG_P (operands[1]) && !SSE_REG_P (operands[1]))"
2637   [(const_int 0)]
2638   "ix86_split_long_move (operands); DONE;")
2639
2640 ;; %%% This multiword shite has got to go.
2641 (define_split
2642   [(set (match_operand:DI 0 "nonimmediate_operand" "")
2643         (match_operand:DI 1 "general_operand" ""))]
2644   "!TARGET_64BIT && reload_completed
2645    && (!MMX_REG_P (operands[0]) && !SSE_REG_P (operands[0]))
2646    && (!MMX_REG_P (operands[1]) && !SSE_REG_P (operands[1]))"
2647   [(const_int 0)]
2648   "ix86_split_long_move (operands); DONE;")
2649
2650 (define_insn "*movdi_1_rex64"
2651   [(set (match_operand:DI 0 "nonimmediate_operand"
2652           "=r,r  ,r,m ,!m,*y,*y,?r ,m ,?*Ym,?*y,*x,*x,?r ,m,?*Yi,*x,?*x,?*Ym")
2653         (match_operand:DI 1 "general_operand"
2654           "Z ,rem,i,re,n ,C ,*y,*Ym,*y,r   ,m  ,C ,*x,*Yi,*x,r  ,m ,*Ym,*x"))]
2655   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2656 {
2657   switch (get_attr_type (insn))
2658     {
2659     case TYPE_SSECVT:
2660       if (SSE_REG_P (operands[0]))
2661         return "movq2dq\t{%1, %0|%0, %1}";
2662       else
2663         return "movdq2q\t{%1, %0|%0, %1}";
2664
2665     case TYPE_SSEMOV:
2666       if (TARGET_AVX)
2667         {
2668           if (get_attr_mode (insn) == MODE_TI)
2669             return "vmovdqa\t{%1, %0|%0, %1}";
2670           else
2671             return "vmovq\t{%1, %0|%0, %1}";
2672         }
2673
2674       if (get_attr_mode (insn) == MODE_TI)
2675         return "movdqa\t{%1, %0|%0, %1}";
2676       /* FALLTHRU */
2677
2678     case TYPE_MMXMOV:
2679       /* Moves from and into integer register is done using movd
2680          opcode with REX prefix.  */
2681       if (GENERAL_REG_P (operands[0]) || GENERAL_REG_P (operands[1]))
2682         return "movd\t{%1, %0|%0, %1}";
2683       return "movq\t{%1, %0|%0, %1}";
2684
2685     case TYPE_SSELOG1:
2686       return "%vpxor\t%0, %d0";
2687
2688     case TYPE_MMX:
2689       return "pxor\t%0, %0";
2690
2691     case TYPE_MULTI:
2692       return "#";
2693
2694     case TYPE_LEA:
2695       return "lea{q}\t{%a1, %0|%0, %a1}";
2696
2697     default:
2698       gcc_assert (!flag_pic || LEGITIMATE_PIC_OPERAND_P (operands[1]));
2699       if (get_attr_mode (insn) == MODE_SI)
2700         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2701       else if (which_alternative == 2)
2702         return "movabs{q}\t{%1, %0|%0, %1}";
2703       else
2704         return "mov{q}\t{%1, %0|%0, %1}";
2705     }
2706 }
2707   [(set (attr "type")
2708      (cond [(eq_attr "alternative" "5")
2709               (const_string "mmx")
2710             (eq_attr "alternative" "6,7,8,9,10")
2711               (const_string "mmxmov")
2712             (eq_attr "alternative" "11")
2713               (const_string "sselog1")
2714             (eq_attr "alternative" "12,13,14,15,16")
2715               (const_string "ssemov")
2716             (eq_attr "alternative" "17,18")
2717               (const_string "ssecvt")
2718             (eq_attr "alternative" "4")
2719               (const_string "multi")
2720             (match_operand:DI 1 "pic_32bit_operand" "")
2721               (const_string "lea")
2722            ]
2723            (const_string "imov")))
2724    (set (attr "modrm")
2725      (if_then_else
2726        (and (eq_attr "alternative" "2") (eq_attr "type" "imov"))
2727          (const_string "0")
2728          (const_string "*")))
2729    (set (attr "length_immediate")
2730      (if_then_else
2731        (and (eq_attr "alternative" "2") (eq_attr "type" "imov"))
2732          (const_string "8")
2733          (const_string "*")))
2734    (set_attr "prefix_rex" "*,*,*,*,*,*,*,1,*,1,*,*,*,*,*,*,*,*,*")
2735    (set_attr "prefix_data16" "*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,1,*,*,*")
2736    (set (attr "prefix")
2737      (if_then_else (eq_attr "alternative" "11,12,13,14,15,16")
2738        (const_string "maybe_vex")
2739        (const_string "orig")))
2740    (set_attr "mode" "SI,DI,DI,DI,SI,DI,DI,DI,DI,DI,DI,TI,TI,DI,DI,DI,DI,DI,DI")])
2741
2742 ;; Stores and loads of ax to arbitrary constant address.
2743 ;; We fake an second form of instruction to force reload to load address
2744 ;; into register when rax is not available
2745 (define_insn "*movabsdi_1_rex64"
2746   [(set (mem:DI (match_operand:DI 0 "x86_64_movabs_operand" "i,r"))
2747         (match_operand:DI 1 "nonmemory_operand" "a,er"))]
2748   "TARGET_64BIT && ix86_check_movabs (insn, 0)"
2749   "@
2750    movabs{q}\t{%1, %P0|%P0, %1}
2751    mov{q}\t{%1, %a0|%a0, %1}"
2752   [(set_attr "type" "imov")
2753    (set_attr "modrm" "0,*")
2754    (set_attr "length_address" "8,0")
2755    (set_attr "length_immediate" "0,*")
2756    (set_attr "memory" "store")
2757    (set_attr "mode" "DI")])
2758
2759 (define_insn "*movabsdi_2_rex64"
2760   [(set (match_operand:DI 0 "register_operand" "=a,r")
2761         (mem:DI (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
2762   "TARGET_64BIT && ix86_check_movabs (insn, 1)"
2763   "@
2764    movabs{q}\t{%P1, %0|%0, %P1}
2765    mov{q}\t{%a1, %0|%0, %a1}"
2766   [(set_attr "type" "imov")
2767    (set_attr "modrm" "0,*")
2768    (set_attr "length_address" "8,0")
2769    (set_attr "length_immediate" "0")
2770    (set_attr "memory" "load")
2771    (set_attr "mode" "DI")])
2772
2773 ;; Convert impossible stores of immediate to existing instructions.
2774 ;; First try to get scratch register and go through it.  In case this
2775 ;; fails, move by 32bit parts.
2776 (define_peephole2
2777   [(match_scratch:DI 2 "r")
2778    (set (match_operand:DI 0 "memory_operand" "")
2779         (match_operand:DI 1 "immediate_operand" ""))]
2780   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2781    && !x86_64_immediate_operand (operands[1], DImode)"
2782   [(set (match_dup 2) (match_dup 1))
2783    (set (match_dup 0) (match_dup 2))]
2784   "")
2785
2786 ;; We need to define this as both peepholer and splitter for case
2787 ;; peephole2 pass is not run.
2788 ;; "&& 1" is needed to keep it from matching the previous pattern.
2789 (define_peephole2
2790   [(set (match_operand:DI 0 "memory_operand" "")
2791         (match_operand:DI 1 "immediate_operand" ""))]
2792   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2793    && !x86_64_immediate_operand (operands[1], DImode) && 1"
2794   [(set (match_dup 2) (match_dup 3))
2795    (set (match_dup 4) (match_dup 5))]
2796   "split_di (&operands[0], 2, &operands[2], &operands[4]);")
2797
2798 (define_split
2799   [(set (match_operand:DI 0 "memory_operand" "")
2800         (match_operand:DI 1 "immediate_operand" ""))]
2801   "TARGET_64BIT && ((optimize > 0 && flag_peephole2)
2802                     ? epilogue_completed : reload_completed)
2803    && !symbolic_operand (operands[1], DImode)
2804    && !x86_64_immediate_operand (operands[1], DImode)"
2805   [(set (match_dup 2) (match_dup 3))
2806    (set (match_dup 4) (match_dup 5))]
2807   "split_di (&operands[0], 2, &operands[2], &operands[4]);")
2808
2809 (define_insn "*swapdi_rex64"
2810   [(set (match_operand:DI 0 "register_operand" "+r")
2811         (match_operand:DI 1 "register_operand" "+r"))
2812    (set (match_dup 1)
2813         (match_dup 0))]
2814   "TARGET_64BIT"
2815   "xchg{q}\t%1, %0"
2816   [(set_attr "type" "imov")
2817    (set_attr "mode" "DI")
2818    (set_attr "pent_pair" "np")
2819    (set_attr "athlon_decode" "vector")
2820    (set_attr "amdfam10_decode" "double")])
2821
2822 (define_expand "movoi"
2823   [(set (match_operand:OI 0 "nonimmediate_operand" "")
2824         (match_operand:OI 1 "general_operand" ""))]
2825   "TARGET_AVX"
2826   "ix86_expand_move (OImode, operands); DONE;")
2827
2828 (define_insn "*movoi_internal"
2829   [(set (match_operand:OI 0 "nonimmediate_operand" "=x,x,m")
2830         (match_operand:OI 1 "vector_move_operand" "C,xm,x"))]
2831   "TARGET_AVX
2832    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2833 {
2834   switch (which_alternative)
2835     {
2836     case 0:
2837       return "vxorps\t%0, %0, %0";
2838     case 1:
2839     case 2:
2840       if (misaligned_operand (operands[0], OImode)
2841           || misaligned_operand (operands[1], OImode))
2842         return "vmovdqu\t{%1, %0|%0, %1}";
2843       else
2844         return "vmovdqa\t{%1, %0|%0, %1}";
2845     default:
2846       gcc_unreachable ();
2847     }
2848 }
2849   [(set_attr "type" "sselog1,ssemov,ssemov")
2850    (set_attr "prefix" "vex")
2851    (set_attr "mode" "OI")])
2852
2853 (define_expand "movti"
2854   [(set (match_operand:TI 0 "nonimmediate_operand" "")
2855         (match_operand:TI 1 "nonimmediate_operand" ""))]
2856   "TARGET_SSE || TARGET_64BIT"
2857 {
2858   if (TARGET_64BIT)
2859     ix86_expand_move (TImode, operands);
2860   else if (push_operand (operands[0], TImode))
2861     ix86_expand_push (TImode, operands[1]);
2862   else
2863     ix86_expand_vector_move (TImode, operands);
2864   DONE;
2865 })
2866
2867 (define_insn "*movti_internal"
2868   [(set (match_operand:TI 0 "nonimmediate_operand" "=x,x,m")
2869         (match_operand:TI 1 "vector_move_operand" "C,xm,x"))]
2870   "TARGET_SSE && !TARGET_64BIT
2871    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2872 {
2873   switch (which_alternative)
2874     {
2875     case 0:
2876       if (get_attr_mode (insn) == MODE_V4SF)
2877         return "%vxorps\t%0, %d0";
2878       else
2879         return "%vpxor\t%0, %d0";
2880     case 1:
2881     case 2:
2882       /* TDmode values are passed as TImode on the stack.  Moving them
2883          to stack may result in unaligned memory access.  */
2884       if (misaligned_operand (operands[0], TImode)
2885           || misaligned_operand (operands[1], TImode))
2886         {
2887           if (get_attr_mode (insn) == MODE_V4SF)
2888             return "%vmovups\t{%1, %0|%0, %1}";
2889          else
2890            return "%vmovdqu\t{%1, %0|%0, %1}";
2891         }
2892       else
2893         {
2894           if (get_attr_mode (insn) == MODE_V4SF)
2895             return "%vmovaps\t{%1, %0|%0, %1}";
2896          else
2897            return "%vmovdqa\t{%1, %0|%0, %1}";
2898         }
2899     default:
2900       gcc_unreachable ();
2901     }
2902 }
2903   [(set_attr "type" "sselog1,ssemov,ssemov")
2904    (set_attr "prefix" "maybe_vex")
2905    (set (attr "mode")
2906         (cond [(ior (eq (symbol_ref "TARGET_SSE2") (const_int 0))
2907                     (ne (symbol_ref "optimize_function_for_size_p (cfun)") (const_int 0)))
2908                  (const_string "V4SF")
2909                (and (eq_attr "alternative" "2")
2910                     (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
2911                         (const_int 0)))
2912                  (const_string "V4SF")]
2913               (const_string "TI")))])
2914
2915 (define_insn "*movti_rex64"
2916   [(set (match_operand:TI 0 "nonimmediate_operand" "=!r,o,x,x,xm")
2917         (match_operand:TI 1 "general_operand" "riFo,riF,C,xm,x"))]
2918   "TARGET_64BIT
2919    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2920 {
2921   switch (which_alternative)
2922     {
2923     case 0:
2924     case 1:
2925       return "#";
2926     case 2:
2927       if (get_attr_mode (insn) == MODE_V4SF)
2928         return "%vxorps\t%0, %d0";
2929       else
2930         return "%vpxor\t%0, %d0";
2931     case 3:
2932     case 4:
2933       /* TDmode values are passed as TImode on the stack.  Moving them
2934          to stack may result in unaligned memory access.  */
2935       if (misaligned_operand (operands[0], TImode)
2936           || misaligned_operand (operands[1], TImode))
2937         {
2938           if (get_attr_mode (insn) == MODE_V4SF)
2939             return "%vmovups\t{%1, %0|%0, %1}";
2940          else
2941            return "%vmovdqu\t{%1, %0|%0, %1}";
2942         }
2943       else
2944         {
2945           if (get_attr_mode (insn) == MODE_V4SF)
2946             return "%vmovaps\t{%1, %0|%0, %1}";
2947          else
2948            return "%vmovdqa\t{%1, %0|%0, %1}";
2949         }
2950     default:
2951       gcc_unreachable ();
2952     }
2953 }
2954   [(set_attr "type" "*,*,sselog1,ssemov,ssemov")
2955    (set_attr "prefix" "*,*,maybe_vex,maybe_vex,maybe_vex")
2956    (set (attr "mode")
2957         (cond [(eq_attr "alternative" "2,3")
2958                  (if_then_else
2959                    (ne (symbol_ref "optimize_function_for_size_p (cfun)")
2960                        (const_int 0))
2961                    (const_string "V4SF")
2962                    (const_string "TI"))
2963                (eq_attr "alternative" "4")
2964                  (if_then_else
2965                    (ior (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
2966                             (const_int 0))
2967                         (ne (symbol_ref "optimize_function_for_size_p (cfun)")
2968                             (const_int 0)))
2969                    (const_string "V4SF")
2970                    (const_string "TI"))]
2971                (const_string "DI")))])
2972
2973 (define_split
2974   [(set (match_operand:TI 0 "nonimmediate_operand" "")
2975         (match_operand:TI 1 "general_operand" ""))]
2976   "reload_completed && !SSE_REG_P (operands[0])
2977    && !SSE_REG_P (operands[1])"
2978   [(const_int 0)]
2979   "ix86_split_long_move (operands); DONE;")
2980
2981 ;; This expands to what emit_move_complex would generate if we didn't
2982 ;; have a movti pattern.  Having this avoids problems with reload on
2983 ;; 32-bit targets when SSE is present, but doesn't seem to be harmful
2984 ;; to have around all the time.
2985 (define_expand "movcdi"
2986   [(set (match_operand:CDI 0 "nonimmediate_operand" "")
2987         (match_operand:CDI 1 "general_operand" ""))]
2988   ""
2989 {
2990   if (push_operand (operands[0], CDImode))
2991     emit_move_complex_push (CDImode, operands[0], operands[1]);
2992   else
2993     emit_move_complex_parts (operands[0], operands[1]);
2994   DONE;
2995 })
2996
2997 (define_expand "movsf"
2998   [(set (match_operand:SF 0 "nonimmediate_operand" "")
2999         (match_operand:SF 1 "general_operand" ""))]
3000   ""
3001   "ix86_expand_move (SFmode, operands); DONE;")
3002
3003 (define_insn "*pushsf"
3004   [(set (match_operand:SF 0 "push_operand" "=<,<,<")
3005         (match_operand:SF 1 "general_no_elim_operand" "f,rFm,x"))]
3006   "!TARGET_64BIT"
3007 {
3008   /* Anything else should be already split before reg-stack.  */
3009   gcc_assert (which_alternative == 1);
3010   return "push{l}\t%1";
3011 }
3012   [(set_attr "type" "multi,push,multi")
3013    (set_attr "unit" "i387,*,*")
3014    (set_attr "mode" "SF,SI,SF")])
3015
3016 (define_insn "*pushsf_rex64"
3017   [(set (match_operand:SF 0 "push_operand" "=X,X,X")
3018         (match_operand:SF 1 "nonmemory_no_elim_operand" "f,rF,x"))]
3019   "TARGET_64BIT"
3020 {
3021   /* Anything else should be already split before reg-stack.  */
3022   gcc_assert (which_alternative == 1);
3023   return "push{q}\t%q1";
3024 }
3025   [(set_attr "type" "multi,push,multi")
3026    (set_attr "unit" "i387,*,*")
3027    (set_attr "mode" "SF,DI,SF")])
3028
3029 (define_split
3030   [(set (match_operand:SF 0 "push_operand" "")
3031         (match_operand:SF 1 "memory_operand" ""))]
3032   "reload_completed
3033    && MEM_P (operands[1])
3034    && (operands[2] = find_constant_src (insn))"
3035   [(set (match_dup 0)
3036         (match_dup 2))])
3037
3038 ;; %%% Kill this when call knows how to work this out.
3039 (define_split
3040   [(set (match_operand:SF 0 "push_operand" "")
3041         (match_operand:SF 1 "any_fp_register_operand" ""))]
3042   "!TARGET_64BIT"
3043   [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int -4)))
3044    (set (mem:SF (reg:SI SP_REG)) (match_dup 1))])
3045
3046 (define_split
3047   [(set (match_operand:SF 0 "push_operand" "")
3048         (match_operand:SF 1 "any_fp_register_operand" ""))]
3049   "TARGET_64BIT"
3050   [(set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int -8)))
3051    (set (mem:SF (reg:DI SP_REG)) (match_dup 1))])
3052
3053 (define_insn "*movsf_1"
3054   [(set (match_operand:SF 0 "nonimmediate_operand"
3055           "=f,m,f,r  ,m ,x,x,x ,m,!*y,!m,!*y,?Yi,?r,!*Ym,!r")
3056         (match_operand:SF 1 "general_operand"
3057           "fm,f,G,rmF,Fr,C,x,xm,x,m  ,*y,*y ,r  ,Yi,r   ,*Ym"))]
3058   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
3059    && (reload_in_progress || reload_completed
3060        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3061        || (!TARGET_SSE_MATH && optimize_function_for_size_p (cfun)
3062            && standard_80387_constant_p (operands[1]))
3063        || GET_CODE (operands[1]) != CONST_DOUBLE
3064        || memory_operand (operands[0], SFmode))"
3065 {
3066   switch (which_alternative)
3067     {
3068     case 0:
3069     case 1:
3070       return output_387_reg_move (insn, operands);
3071
3072     case 2:
3073       return standard_80387_constant_opcode (operands[1]);
3074
3075     case 3:
3076     case 4:
3077       return "mov{l}\t{%1, %0|%0, %1}";
3078     case 5:
3079       if (get_attr_mode (insn) == MODE_TI)
3080         return "%vpxor\t%0, %d0";
3081       else
3082         return "%vxorps\t%0, %d0";
3083     case 6:
3084       if (get_attr_mode (insn) == MODE_V4SF)
3085         return "%vmovaps\t{%1, %0|%0, %1}";
3086       else
3087         return "%vmovss\t{%1, %d0|%d0, %1}";
3088     case 7:
3089       if (TARGET_AVX)
3090         return REG_P (operands[1]) ? "vmovss\t{%1, %0, %0|%0, %0, %1}"
3091                                    : "vmovss\t{%1, %0|%0, %1}";
3092       else
3093         return "movss\t{%1, %0|%0, %1}";
3094     case 8:
3095       return "%vmovss\t{%1, %0|%0, %1}";
3096
3097     case 9: case 10: case 14: case 15:
3098       return "movd\t{%1, %0|%0, %1}";
3099     case 12: case 13:
3100       return "%vmovd\t{%1, %0|%0, %1}";
3101
3102     case 11:
3103       return "movq\t{%1, %0|%0, %1}";
3104
3105     default:
3106       gcc_unreachable ();
3107     }
3108 }
3109   [(set_attr "type" "fmov,fmov,fmov,imov,imov,sselog1,ssemov,ssemov,ssemov,mmxmov,mmxmov,mmxmov,ssemov,ssemov,mmxmov,mmxmov")
3110    (set (attr "prefix")
3111      (if_then_else (eq_attr "alternative" "5,6,7,8,12,13")
3112        (const_string "maybe_vex")
3113        (const_string "orig")))
3114    (set (attr "mode")
3115         (cond [(eq_attr "alternative" "3,4,9,10")
3116                  (const_string "SI")
3117                (eq_attr "alternative" "5")
3118                  (if_then_else
3119                    (and (and (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
3120                                  (const_int 0))
3121                              (ne (symbol_ref "TARGET_SSE2")
3122                                  (const_int 0)))
3123                         (eq (symbol_ref "optimize_function_for_size_p (cfun)")
3124                             (const_int 0)))
3125                    (const_string "TI")
3126                    (const_string "V4SF"))
3127                /* For architectures resolving dependencies on
3128                   whole SSE registers use APS move to break dependency
3129                   chains, otherwise use short move to avoid extra work.
3130
3131                   Do the same for architectures resolving dependencies on
3132                   the parts.  While in DF mode it is better to always handle
3133                   just register parts, the SF mode is different due to lack
3134                   of instructions to load just part of the register.  It is
3135                   better to maintain the whole registers in single format
3136                   to avoid problems on using packed logical operations.  */
3137                (eq_attr "alternative" "6")
3138                  (if_then_else
3139                    (ior (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3140                             (const_int 0))
3141                         (ne (symbol_ref "TARGET_SSE_SPLIT_REGS")
3142                             (const_int 0)))
3143                    (const_string "V4SF")
3144                    (const_string "SF"))
3145                (eq_attr "alternative" "11")
3146                  (const_string "DI")]
3147                (const_string "SF")))])
3148
3149 (define_insn "*swapsf"
3150   [(set (match_operand:SF 0 "fp_register_operand" "+f")
3151         (match_operand:SF 1 "fp_register_operand" "+f"))
3152    (set (match_dup 1)
3153         (match_dup 0))]
3154   "reload_completed || TARGET_80387"
3155 {
3156   if (STACK_TOP_P (operands[0]))
3157     return "fxch\t%1";
3158   else
3159     return "fxch\t%0";
3160 }
3161   [(set_attr "type" "fxch")
3162    (set_attr "mode" "SF")])
3163
3164 (define_expand "movdf"
3165   [(set (match_operand:DF 0 "nonimmediate_operand" "")
3166         (match_operand:DF 1 "general_operand" ""))]
3167   ""
3168   "ix86_expand_move (DFmode, operands); DONE;")
3169
3170 ;; Size of pushdf is 3 (for sub) + 2 (for fstp) + memory operand size.
3171 ;; Size of pushdf using integer instructions is 2+2*memory operand size
3172 ;; On the average, pushdf using integers can be still shorter.  Allow this
3173 ;; pattern for optimize_size too.
3174
3175 (define_insn "*pushdf_nointeger"
3176   [(set (match_operand:DF 0 "push_operand" "=<,<,<,<")
3177         (match_operand:DF 1 "general_no_elim_operand" "f,Fo,*r,Y2"))]
3178   "!TARGET_64BIT && !TARGET_INTEGER_DFMODE_MOVES"
3179 {
3180   /* This insn should be already split before reg-stack.  */
3181   gcc_unreachable ();
3182 }
3183   [(set_attr "type" "multi")
3184    (set_attr "unit" "i387,*,*,*")
3185    (set_attr "mode" "DF,SI,SI,DF")])
3186
3187 (define_insn "*pushdf_integer"
3188   [(set (match_operand:DF 0 "push_operand" "=<,<,<")
3189         (match_operand:DF 1 "general_no_elim_operand" "f,rFo,Y2"))]
3190   "TARGET_64BIT || TARGET_INTEGER_DFMODE_MOVES"
3191 {
3192   /* This insn should be already split before reg-stack.  */
3193   gcc_unreachable ();
3194 }
3195   [(set_attr "type" "multi")
3196    (set_attr "unit" "i387,*,*")
3197    (set_attr "mode" "DF,SI,DF")])
3198
3199 ;; %%% Kill this when call knows how to work this out.
3200 (define_split
3201   [(set (match_operand:DF 0 "push_operand" "")
3202         (match_operand:DF 1 "any_fp_register_operand" ""))]
3203   "reload_completed"
3204   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -8)))
3205    (set (mem:DF (reg:P SP_REG)) (match_dup 1))]
3206   "")
3207
3208 (define_split
3209   [(set (match_operand:DF 0 "push_operand" "")
3210         (match_operand:DF 1 "general_operand" ""))]
3211   "reload_completed"
3212   [(const_int 0)]
3213   "ix86_split_long_move (operands); DONE;")
3214
3215 ;; Moving is usually shorter when only FP registers are used. This separate
3216 ;; movdf pattern avoids the use of integer registers for FP operations
3217 ;; when optimizing for size.
3218
3219 (define_insn "*movdf_nointeger"
3220   [(set (match_operand:DF 0 "nonimmediate_operand"
3221                         "=f,m,f,*r  ,o  ,Y2*x,Y2*x,Y2*x ,m  ")
3222         (match_operand:DF 1 "general_operand"
3223                         "fm,f,G,*roF,*Fr,C   ,Y2*x,mY2*x,Y2*x"))]
3224   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
3225    && ((optimize_function_for_size_p (cfun)
3226        || !TARGET_INTEGER_DFMODE_MOVES) && !TARGET_64BIT)
3227    && (reload_in_progress || reload_completed
3228        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3229        || (!(TARGET_SSE2 && TARGET_SSE_MATH)
3230            && optimize_function_for_size_p (cfun)
3231            && !memory_operand (operands[0], DFmode)
3232            && standard_80387_constant_p (operands[1]))
3233        || GET_CODE (operands[1]) != CONST_DOUBLE
3234        || ((optimize_function_for_size_p (cfun)
3235             || !TARGET_MEMORY_MISMATCH_STALL
3236             || reload_in_progress || reload_completed)
3237            && memory_operand (operands[0], DFmode)))"
3238 {
3239   switch (which_alternative)
3240     {
3241     case 0:
3242     case 1:
3243       return output_387_reg_move (insn, operands);
3244
3245     case 2:
3246       return standard_80387_constant_opcode (operands[1]);
3247
3248     case 3:
3249     case 4:
3250       return "#";
3251     case 5:
3252       switch (get_attr_mode (insn))
3253         {
3254         case MODE_V4SF:
3255           return "%vxorps\t%0, %d0";
3256         case MODE_V2DF:
3257           return "%vxorpd\t%0, %d0";
3258         case MODE_TI:
3259           return "%vpxor\t%0, %d0";
3260         default:
3261           gcc_unreachable ();
3262         }
3263     case 6:
3264     case 7:
3265     case 8:
3266       switch (get_attr_mode (insn))
3267         {
3268         case MODE_V4SF:
3269           return "%vmovaps\t{%1, %0|%0, %1}";
3270         case MODE_V2DF:
3271           return "%vmovapd\t{%1, %0|%0, %1}";
3272         case MODE_TI:
3273           return "%vmovdqa\t{%1, %0|%0, %1}";
3274         case MODE_DI:
3275           return "%vmovq\t{%1, %0|%0, %1}";
3276         case MODE_DF:
3277           if (TARGET_AVX)
3278             {
3279               if (REG_P (operands[0]) && REG_P (operands[1]))
3280                 return "vmovsd\t{%1, %0, %0|%0, %0, %1}";
3281               else
3282                 return "vmovsd\t{%1, %0|%0, %1}";
3283             }
3284           else
3285             return "movsd\t{%1, %0|%0, %1}";
3286         case MODE_V1DF:
3287           if (TARGET_AVX)
3288             {
3289               if (REG_P (operands[0]))
3290                 return "vmovlpd\t{%1, %0, %0|%0, %0, %1}";
3291               else
3292                 return "vmovlpd\t{%1, %0|%0, %1}";
3293             }
3294           else
3295             return "movlpd\t{%1, %0|%0, %1}";
3296         case MODE_V2SF:
3297           if (TARGET_AVX)
3298             {
3299               if (REG_P (operands[0]))
3300                 return "vmovlps\t{%1, %0, %0|%0, %0, %1}";
3301               else
3302                 return "vmovlps\t{%1, %0|%0, %1}";
3303             }
3304           else
3305             return "movlps\t{%1, %0|%0, %1}";
3306         default:
3307           gcc_unreachable ();
3308         }
3309
3310     default:
3311       gcc_unreachable ();
3312     }
3313 }
3314   [(set_attr "type" "fmov,fmov,fmov,multi,multi,sselog1,ssemov,ssemov,ssemov")
3315    (set (attr "prefix")
3316      (if_then_else (eq_attr "alternative" "0,1,2,3,4")
3317        (const_string "orig")
3318        (const_string "maybe_vex")))
3319    (set (attr "prefix_data16")
3320      (if_then_else (eq_attr "mode" "V1DF")
3321        (const_string "1")
3322        (const_string "*")))
3323    (set (attr "mode")
3324         (cond [(eq_attr "alternative" "0,1,2")
3325                  (const_string "DF")
3326                (eq_attr "alternative" "3,4")
3327                  (const_string "SI")
3328
3329                /* For SSE1, we have many fewer alternatives.  */
3330                (eq (symbol_ref "TARGET_SSE2") (const_int 0))
3331                  (cond [(eq_attr "alternative" "5,6")
3332                           (const_string "V4SF")
3333                        ]
3334                    (const_string "V2SF"))
3335
3336                /* xorps is one byte shorter.  */
3337                (eq_attr "alternative" "5")
3338                  (cond [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3339                             (const_int 0))
3340                           (const_string "V4SF")
3341                         (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
3342                             (const_int 0))
3343                           (const_string "TI")
3344                        ]
3345                        (const_string "V2DF"))
3346
3347                /* For architectures resolving dependencies on
3348                   whole SSE registers use APD move to break dependency
3349                   chains, otherwise use short move to avoid extra work.
3350
3351                   movaps encodes one byte shorter.  */
3352                (eq_attr "alternative" "6")
3353                  (cond
3354                    [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3355                         (const_int 0))
3356                       (const_string "V4SF")
3357                     (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3358                         (const_int 0))
3359                       (const_string "V2DF")
3360                    ]
3361                    (const_string "DF"))
3362                /* For architectures resolving dependencies on register
3363                   parts we may avoid extra work to zero out upper part
3364                   of register.  */
3365                (eq_attr "alternative" "7")
3366                  (if_then_else
3367                    (ne (symbol_ref "TARGET_SSE_SPLIT_REGS")
3368                        (const_int 0))
3369                    (const_string "V1DF")
3370                    (const_string "DF"))
3371               ]
3372               (const_string "DF")))])
3373
3374 (define_insn "*movdf_integer_rex64"
3375   [(set (match_operand:DF 0 "nonimmediate_operand"
3376                 "=f,m,f,r  ,m ,Y2*x,Y2*x,Y2*x,m   ,Yi,r ")
3377         (match_operand:DF 1 "general_operand"
3378                 "fm,f,G,rmF,Fr,C   ,Y2*x,m   ,Y2*x,r ,Yi"))]
3379   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))
3380    && (reload_in_progress || reload_completed
3381        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3382        || (!(TARGET_SSE2 && TARGET_SSE_MATH)
3383            && optimize_function_for_size_p (cfun)
3384            && standard_80387_constant_p (operands[1]))
3385        || GET_CODE (operands[1]) != CONST_DOUBLE
3386        || memory_operand (operands[0], DFmode))"
3387 {
3388   switch (which_alternative)
3389     {
3390     case 0:
3391     case 1:
3392       return output_387_reg_move (insn, operands);
3393
3394     case 2:
3395       return standard_80387_constant_opcode (operands[1]);
3396
3397     case 3:
3398     case 4:
3399       return "#";
3400
3401     case 5:
3402       switch (get_attr_mode (insn))
3403         {
3404         case MODE_V4SF:
3405           return "%vxorps\t%0, %d0";
3406         case MODE_V2DF:
3407           return "%vxorpd\t%0, %d0";
3408         case MODE_TI:
3409           return "%vpxor\t%0, %d0";
3410         default:
3411           gcc_unreachable ();
3412         }
3413     case 6:
3414     case 7:
3415     case 8:
3416       switch (get_attr_mode (insn))
3417         {
3418         case MODE_V4SF:
3419           return "%vmovaps\t{%1, %0|%0, %1}";
3420         case MODE_V2DF:
3421           return "%vmovapd\t{%1, %0|%0, %1}";
3422         case MODE_TI:
3423           return "%vmovdqa\t{%1, %0|%0, %1}";
3424         case MODE_DI:
3425           return "%vmovq\t{%1, %0|%0, %1}";
3426         case MODE_DF:
3427           if (TARGET_AVX)
3428             {
3429               if (REG_P (operands[0]) && REG_P (operands[1]))
3430                 return "vmovsd\t{%1, %0, %0|%0, %0, %1}";
3431               else
3432                 return "vmovsd\t{%1, %0|%0, %1}";
3433             }
3434           else
3435             return "movsd\t{%1, %0|%0, %1}";
3436         case MODE_V1DF:
3437           return "%vmovlpd\t{%1, %d0|%d0, %1}";
3438         case MODE_V2SF:
3439           return "%vmovlps\t{%1, %d0|%d0, %1}";
3440         default:
3441           gcc_unreachable ();
3442         }
3443
3444     case 9:
3445     case 10:
3446     return "%vmovd\t{%1, %0|%0, %1}";
3447
3448     default:
3449       gcc_unreachable();
3450     }
3451 }
3452   [(set_attr "type" "fmov,fmov,fmov,multi,multi,sselog1,ssemov,ssemov,ssemov,ssemov,ssemov")
3453    (set (attr "prefix")
3454      (if_then_else (eq_attr "alternative" "0,1,2,3,4")
3455        (const_string "orig")
3456        (const_string "maybe_vex")))
3457    (set (attr "prefix_data16")
3458      (if_then_else (eq_attr "mode" "V1DF")
3459        (const_string "1")
3460        (const_string "*")))
3461    (set (attr "mode")
3462         (cond [(eq_attr "alternative" "0,1,2")
3463                  (const_string "DF")
3464                (eq_attr "alternative" "3,4,9,10")
3465                  (const_string "DI")
3466
3467                /* For SSE1, we have many fewer alternatives.  */
3468                (eq (symbol_ref "TARGET_SSE2") (const_int 0))
3469                  (cond [(eq_attr "alternative" "5,6")
3470                           (const_string "V4SF")
3471                        ]
3472                    (const_string "V2SF"))
3473
3474                /* xorps is one byte shorter.  */
3475                (eq_attr "alternative" "5")
3476                  (cond [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3477                             (const_int 0))
3478                           (const_string "V4SF")
3479                         (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
3480                             (const_int 0))
3481                           (const_string "TI")
3482                        ]
3483                        (const_string "V2DF"))
3484
3485                /* For architectures resolving dependencies on
3486                   whole SSE registers use APD move to break dependency
3487                   chains, otherwise use short move to avoid extra work.
3488
3489                   movaps encodes one byte shorter.  */
3490                (eq_attr "alternative" "6")
3491                  (cond
3492                    [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3493                         (const_int 0))
3494                       (const_string "V4SF")
3495                     (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3496                         (const_int 0))
3497                       (const_string "V2DF")
3498                    ]
3499                    (const_string "DF"))
3500                /* For architectures resolving dependencies on register
3501                   parts we may avoid extra work to zero out upper part
3502                   of register.  */
3503                (eq_attr "alternative" "7")
3504                  (if_then_else
3505                    (ne (symbol_ref "TARGET_SSE_SPLIT_REGS")
3506                        (const_int 0))
3507                    (const_string "V1DF")
3508                    (const_string "DF"))
3509               ]
3510               (const_string "DF")))])
3511
3512 (define_insn "*movdf_integer"
3513   [(set (match_operand:DF 0 "nonimmediate_operand"
3514                 "=f,m,f,r  ,o ,Y2*x,Y2*x,Y2*x,m   ")
3515         (match_operand:DF 1 "general_operand"
3516                 "fm,f,G,roF,Fr,C   ,Y2*x,m   ,Y2*x"))]
3517   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
3518    && optimize_function_for_speed_p (cfun)
3519    && TARGET_INTEGER_DFMODE_MOVES
3520    && (reload_in_progress || reload_completed
3521        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3522        || (!(TARGET_SSE2 && TARGET_SSE_MATH)
3523            && optimize_function_for_size_p (cfun)
3524            && standard_80387_constant_p (operands[1]))
3525        || GET_CODE (operands[1]) != CONST_DOUBLE
3526        || memory_operand (operands[0], DFmode))"
3527 {
3528   switch (which_alternative)
3529     {
3530     case 0:
3531     case 1:
3532       return output_387_reg_move (insn, operands);
3533
3534     case 2:
3535       return standard_80387_constant_opcode (operands[1]);
3536
3537     case 3:
3538     case 4:
3539       return "#";
3540
3541     case 5:
3542       switch (get_attr_mode (insn))
3543         {
3544         case MODE_V4SF:
3545           return "xorps\t%0, %0";
3546         case MODE_V2DF:
3547           return "xorpd\t%0, %0";
3548         case MODE_TI:
3549           return "pxor\t%0, %0";
3550         default:
3551           gcc_unreachable ();
3552         }
3553     case 6:
3554     case 7:
3555     case 8:
3556       switch (get_attr_mode (insn))
3557         {
3558         case MODE_V4SF:
3559           return "movaps\t{%1, %0|%0, %1}";
3560         case MODE_V2DF:
3561           return "movapd\t{%1, %0|%0, %1}";
3562         case MODE_TI:
3563           return "movdqa\t{%1, %0|%0, %1}";
3564         case MODE_DI:
3565           return "movq\t{%1, %0|%0, %1}";
3566         case MODE_DF:
3567           return "movsd\t{%1, %0|%0, %1}";
3568         case MODE_V1DF:
3569           return "movlpd\t{%1, %0|%0, %1}";
3570         case MODE_V2SF:
3571           return "movlps\t{%1, %0|%0, %1}";
3572         default:
3573           gcc_unreachable ();
3574         }
3575
3576     default:
3577       gcc_unreachable();
3578     }
3579 }
3580   [(set_attr "type" "fmov,fmov,fmov,multi,multi,sselog1,ssemov,ssemov,ssemov")
3581    (set (attr "prefix_data16")
3582      (if_then_else (eq_attr "mode" "V1DF")
3583        (const_string "1")
3584        (const_string "*")))
3585    (set (attr "mode")
3586         (cond [(eq_attr "alternative" "0,1,2")
3587                  (const_string "DF")
3588                (eq_attr "alternative" "3,4")
3589                  (const_string "SI")
3590
3591                /* For SSE1, we have many fewer alternatives.  */
3592                (eq (symbol_ref "TARGET_SSE2") (const_int 0))
3593                  (cond [(eq_attr "alternative" "5,6")
3594                           (const_string "V4SF")
3595                        ]
3596                    (const_string "V2SF"))
3597
3598                /* xorps is one byte shorter.  */
3599                (eq_attr "alternative" "5")
3600                  (cond [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3601                             (const_int 0))
3602                           (const_string "V4SF")
3603                         (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
3604                             (const_int 0))
3605                           (const_string "TI")
3606                        ]
3607                        (const_string "V2DF"))
3608
3609                /* For architectures resolving dependencies on
3610                   whole SSE registers use APD move to break dependency
3611                   chains, otherwise use short move to avoid extra work.
3612
3613                   movaps encodes one byte shorter.  */
3614                (eq_attr "alternative" "6")
3615                  (cond
3616                    [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3617                         (const_int 0))
3618                       (const_string "V4SF")
3619                     (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3620                         (const_int 0))
3621                       (const_string "V2DF")
3622                    ]
3623                    (const_string "DF"))
3624                /* For architectures resolving dependencies on register
3625                   parts we may avoid extra work to zero out upper part
3626                   of register.  */
3627                (eq_attr "alternative" "7")
3628                  (if_then_else
3629                    (ne (symbol_ref "TARGET_SSE_SPLIT_REGS")
3630                        (const_int 0))
3631                    (const_string "V1DF")
3632                    (const_string "DF"))
3633               ]
3634               (const_string "DF")))])
3635
3636 (define_split
3637   [(set (match_operand:DF 0 "nonimmediate_operand" "")
3638         (match_operand:DF 1 "general_operand" ""))]
3639   "reload_completed
3640    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
3641    && ! (ANY_FP_REG_P (operands[0]) ||
3642          (GET_CODE (operands[0]) == SUBREG
3643           && ANY_FP_REG_P (SUBREG_REG (operands[0]))))
3644    && ! (ANY_FP_REG_P (operands[1]) ||
3645          (GET_CODE (operands[1]) == SUBREG
3646           && ANY_FP_REG_P (SUBREG_REG (operands[1]))))"
3647   [(const_int 0)]
3648   "ix86_split_long_move (operands); DONE;")
3649
3650 (define_insn "*swapdf"
3651   [(set (match_operand:DF 0 "fp_register_operand" "+f")
3652         (match_operand:DF 1 "fp_register_operand" "+f"))
3653    (set (match_dup 1)
3654         (match_dup 0))]
3655   "reload_completed || TARGET_80387"
3656 {
3657   if (STACK_TOP_P (operands[0]))
3658     return "fxch\t%1";
3659   else
3660     return "fxch\t%0";
3661 }
3662   [(set_attr "type" "fxch")
3663    (set_attr "mode" "DF")])
3664
3665 (define_expand "movxf"
3666   [(set (match_operand:XF 0 "nonimmediate_operand" "")
3667         (match_operand:XF 1 "general_operand" ""))]
3668   ""
3669   "ix86_expand_move (XFmode, operands); DONE;")
3670
3671 ;; Size of pushdf is 3 (for sub) + 2 (for fstp) + memory operand size.
3672 ;; Size of pushdf using integer instructions is 3+3*memory operand size
3673 ;; Pushing using integer instructions is longer except for constants
3674 ;; and direct memory references.
3675 ;; (assuming that any given constant is pushed only once, but this ought to be
3676 ;;  handled elsewhere).
3677
3678 (define_insn "*pushxf_nointeger"
3679   [(set (match_operand:XF 0 "push_operand" "=X,X,X")
3680         (match_operand:XF 1 "general_no_elim_operand" "f,Fo,*r"))]
3681   "optimize_function_for_size_p (cfun)"
3682 {
3683   /* This insn should be already split before reg-stack.  */
3684   gcc_unreachable ();
3685 }
3686   [(set_attr "type" "multi")
3687    (set_attr "unit" "i387,*,*")
3688    (set_attr "mode" "XF,SI,SI")])
3689
3690 (define_insn "*pushxf_integer"
3691   [(set (match_operand:XF 0 "push_operand" "=<,<")
3692         (match_operand:XF 1 "general_no_elim_operand" "f,ro"))]
3693   "optimize_function_for_speed_p (cfun)"
3694 {
3695   /* This insn should be already split before reg-stack.  */
3696   gcc_unreachable ();
3697 }
3698   [(set_attr "type" "multi")
3699    (set_attr "unit" "i387,*")
3700    (set_attr "mode" "XF,SI")])
3701
3702 (define_split
3703   [(set (match_operand 0 "push_operand" "")
3704         (match_operand 1 "general_operand" ""))]
3705   "reload_completed
3706    && (GET_MODE (operands[0]) == XFmode
3707        || GET_MODE (operands[0]) == DFmode)
3708    && !ANY_FP_REG_P (operands[1])"
3709   [(const_int 0)]
3710   "ix86_split_long_move (operands); DONE;")
3711
3712 (define_split
3713   [(set (match_operand:XF 0 "push_operand" "")
3714         (match_operand:XF 1 "any_fp_register_operand" ""))]
3715   ""
3716   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
3717    (set (mem:XF (reg:P SP_REG)) (match_dup 1))]
3718   "operands[2] = GEN_INT (TARGET_128BIT_LONG_DOUBLE ? -16 : -12);")
3719
3720 ;; Do not use integer registers when optimizing for size
3721 (define_insn "*movxf_nointeger"
3722   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m,f,*r,o")
3723         (match_operand:XF 1 "general_operand" "fm,f,G,*roF,F*r"))]
3724   "optimize_function_for_size_p (cfun)
3725    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
3726    && (reload_in_progress || reload_completed
3727        || standard_80387_constant_p (operands[1])
3728        || GET_CODE (operands[1]) != CONST_DOUBLE
3729        || memory_operand (operands[0], XFmode))"
3730 {
3731   switch (which_alternative)
3732     {
3733     case 0:
3734     case 1:
3735       return output_387_reg_move (insn, operands);
3736
3737     case 2:
3738       return standard_80387_constant_opcode (operands[1]);
3739
3740     case 3: case 4:
3741       return "#";
3742     default:
3743       gcc_unreachable ();
3744     }
3745 }
3746   [(set_attr "type" "fmov,fmov,fmov,multi,multi")
3747    (set_attr "mode" "XF,XF,XF,SI,SI")])
3748
3749 (define_insn "*movxf_integer"
3750   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m,f,r,o")
3751         (match_operand:XF 1 "general_operand" "fm,f,G,roF,Fr"))]
3752   "optimize_function_for_speed_p (cfun)
3753    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
3754    && (reload_in_progress || reload_completed
3755        || GET_CODE (operands[1]) != CONST_DOUBLE
3756        || memory_operand (operands[0], XFmode))"
3757 {
3758   switch (which_alternative)
3759     {
3760     case 0:
3761     case 1:
3762       return output_387_reg_move (insn, operands);
3763
3764     case 2:
3765       return standard_80387_constant_opcode (operands[1]);
3766
3767     case 3: case 4:
3768       return "#";
3769
3770     default:
3771       gcc_unreachable ();
3772     }
3773 }
3774   [(set_attr "type" "fmov,fmov,fmov,multi,multi")
3775    (set_attr "mode" "XF,XF,XF,SI,SI")])
3776
3777 (define_expand "movtf"
3778   [(set (match_operand:TF 0 "nonimmediate_operand" "")
3779         (match_operand:TF 1 "nonimmediate_operand" ""))]
3780   "TARGET_SSE2"
3781 {
3782   ix86_expand_move (TFmode, operands);
3783   DONE;
3784 })
3785
3786 (define_insn "*movtf_internal"
3787   [(set (match_operand:TF 0 "nonimmediate_operand" "=x,m,x,?r,?o")
3788         (match_operand:TF 1 "general_operand" "xm,x,C,roF,Fr"))]
3789   "TARGET_SSE2
3790    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
3791 {
3792   switch (which_alternative)
3793     {
3794     case 0:
3795     case 1:
3796       if (get_attr_mode (insn) == MODE_V4SF)
3797         return "%vmovaps\t{%1, %0|%0, %1}";
3798       else
3799         return "%vmovdqa\t{%1, %0|%0, %1}";
3800     case 2:
3801       if (get_attr_mode (insn) == MODE_V4SF)
3802         return "%vxorps\t%0, %d0";
3803       else
3804         return "%vpxor\t%0, %d0";
3805     case 3:
3806     case 4:
3807         return "#";
3808     default:
3809       gcc_unreachable ();
3810     }
3811 }
3812   [(set_attr "type" "ssemov,ssemov,sselog1,*,*")
3813    (set_attr "prefix" "maybe_vex,maybe_vex,maybe_vex,*,*")
3814    (set (attr "mode")
3815         (cond [(eq_attr "alternative" "0,2")
3816                  (if_then_else
3817                    (ne (symbol_ref "optimize_function_for_size_p (cfun)")
3818                        (const_int 0))
3819                    (const_string "V4SF")
3820                    (const_string "TI"))
3821                (eq_attr "alternative" "1")
3822                  (if_then_else
3823                    (ior (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
3824                             (const_int 0))
3825                         (ne (symbol_ref "optimize_function_for_size_p (cfun)")
3826                             (const_int 0)))
3827                    (const_string "V4SF")
3828                    (const_string "TI"))]
3829                (const_string "DI")))])
3830
3831 (define_insn "*pushtf_sse"
3832   [(set (match_operand:TF 0 "push_operand" "=<,<,<")
3833         (match_operand:TF 1 "general_no_elim_operand" "x,Fo,*r"))]
3834   "TARGET_SSE2"
3835 {
3836   /* This insn should be already split before reg-stack.  */
3837   gcc_unreachable ();
3838 }
3839   [(set_attr "type" "multi")
3840    (set_attr "unit" "sse,*,*")
3841    (set_attr "mode" "TF,SI,SI")])
3842
3843 (define_split
3844   [(set (match_operand:TF 0 "push_operand" "")
3845         (match_operand:TF 1 "general_operand" ""))]
3846   "TARGET_SSE2 && reload_completed
3847    && !SSE_REG_P (operands[1])"
3848   [(const_int 0)]
3849   "ix86_split_long_move (operands); DONE;")
3850
3851 (define_split
3852   [(set (match_operand:TF 0 "push_operand" "")
3853         (match_operand:TF 1 "any_fp_register_operand" ""))]
3854   "TARGET_SSE2"
3855   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -16)))
3856    (set (mem:TF (reg:P SP_REG)) (match_dup 1))]
3857   "")
3858
3859 (define_split
3860   [(set (match_operand 0 "nonimmediate_operand" "")
3861         (match_operand 1 "general_operand" ""))]
3862   "reload_completed
3863    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
3864    && GET_MODE (operands[0]) == XFmode
3865    && ! (ANY_FP_REG_P (operands[0]) ||
3866          (GET_CODE (operands[0]) == SUBREG
3867           && ANY_FP_REG_P (SUBREG_REG (operands[0]))))
3868    && ! (ANY_FP_REG_P (operands[1]) ||
3869          (GET_CODE (operands[1]) == SUBREG
3870           && ANY_FP_REG_P (SUBREG_REG (operands[1]))))"
3871   [(const_int 0)]
3872   "ix86_split_long_move (operands); DONE;")
3873
3874 (define_split
3875   [(set (match_operand 0 "register_operand" "")
3876         (match_operand 1 "memory_operand" ""))]
3877   "reload_completed
3878    && MEM_P (operands[1])
3879    && (GET_MODE (operands[0]) == TFmode
3880        || GET_MODE (operands[0]) == XFmode
3881        || GET_MODE (operands[0]) == SFmode
3882        || GET_MODE (operands[0]) == DFmode)
3883    && (operands[2] = find_constant_src (insn))"
3884   [(set (match_dup 0) (match_dup 2))]
3885 {
3886   rtx c = operands[2];
3887   rtx r = operands[0];
3888
3889   if (GET_CODE (r) == SUBREG)
3890     r = SUBREG_REG (r);
3891
3892   if (SSE_REG_P (r))
3893     {
3894       if (!standard_sse_constant_p (c))
3895         FAIL;
3896     }
3897   else if (FP_REG_P (r))
3898     {
3899       if (!standard_80387_constant_p (c))
3900         FAIL;
3901     }
3902   else if (MMX_REG_P (r))
3903     FAIL;
3904 })
3905
3906 (define_split
3907   [(set (match_operand 0 "register_operand" "")
3908         (float_extend (match_operand 1 "memory_operand" "")))]
3909   "reload_completed
3910    && MEM_P (operands[1])
3911    && (GET_MODE (operands[0]) == TFmode
3912        || GET_MODE (operands[0]) == XFmode
3913        || GET_MODE (operands[0]) == SFmode
3914        || GET_MODE (operands[0]) == DFmode)
3915    && (operands[2] = find_constant_src (insn))"
3916   [(set (match_dup 0) (match_dup 2))]
3917 {
3918   rtx c = operands[2];
3919   rtx r = operands[0];
3920
3921   if (GET_CODE (r) == SUBREG)
3922     r = SUBREG_REG (r);
3923
3924   if (SSE_REG_P (r))
3925     {
3926       if (!standard_sse_constant_p (c))
3927         FAIL;
3928     }
3929   else if (FP_REG_P (r))
3930     {
3931       if (!standard_80387_constant_p (c))
3932         FAIL;
3933     }
3934   else if (MMX_REG_P (r))
3935     FAIL;
3936 })
3937
3938 (define_insn "swapxf"
3939   [(set (match_operand:XF 0 "register_operand" "+f")
3940         (match_operand:XF 1 "register_operand" "+f"))
3941    (set (match_dup 1)
3942         (match_dup 0))]
3943   "TARGET_80387"
3944 {
3945   if (STACK_TOP_P (operands[0]))
3946     return "fxch\t%1";
3947   else
3948     return "fxch\t%0";
3949 }
3950   [(set_attr "type" "fxch")
3951    (set_attr "mode" "XF")])
3952
3953 ;; Split the load of -0.0 or -1.0 into fldz;fchs or fld1;fchs sequence
3954 (define_split
3955   [(set (match_operand:X87MODEF 0 "register_operand" "")
3956         (match_operand:X87MODEF 1 "immediate_operand" ""))]
3957   "reload_completed && FP_REGNO_P (REGNO (operands[0]))
3958    && (standard_80387_constant_p (operands[1]) == 8
3959        || standard_80387_constant_p (operands[1]) == 9)"
3960   [(set (match_dup 0)(match_dup 1))
3961    (set (match_dup 0)
3962         (neg:X87MODEF (match_dup 0)))]
3963 {
3964   REAL_VALUE_TYPE r;
3965
3966   REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
3967   if (real_isnegzero (&r))
3968     operands[1] = CONST0_RTX (<MODE>mode);
3969   else
3970     operands[1] = CONST1_RTX (<MODE>mode);
3971 })
3972
3973 (define_split
3974   [(set (match_operand:TF 0 "nonimmediate_operand" "")
3975         (match_operand:TF 1 "general_operand" ""))]
3976   "reload_completed
3977    && !(SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]))"
3978   [(const_int 0)]
3979   "ix86_split_long_move (operands); DONE;")
3980 \f
3981 ;; Zero extension instructions
3982
3983 (define_expand "zero_extendhisi2"
3984   [(set (match_operand:SI 0 "register_operand" "")
3985      (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "")))]
3986   ""
3987 {
3988   if (TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))
3989     {
3990       operands[1] = force_reg (HImode, operands[1]);
3991       emit_insn (gen_zero_extendhisi2_and (operands[0], operands[1]));
3992       DONE;
3993     }
3994 })
3995
3996 (define_insn "zero_extendhisi2_and"
3997   [(set (match_operand:SI 0 "register_operand" "=r")
3998      (zero_extend:SI (match_operand:HI 1 "register_operand" "0")))
3999    (clobber (reg:CC FLAGS_REG))]
4000   "TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
4001   "#"
4002   [(set_attr "type" "alu1")
4003    (set_attr "mode" "SI")])
4004
4005 (define_split
4006   [(set (match_operand:SI 0 "register_operand" "")
4007         (zero_extend:SI (match_operand:HI 1 "register_operand" "")))
4008    (clobber (reg:CC FLAGS_REG))]
4009   "reload_completed && TARGET_ZERO_EXTEND_WITH_AND
4010    && optimize_function_for_speed_p (cfun)"
4011   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (const_int 65535)))
4012               (clobber (reg:CC FLAGS_REG))])]
4013   "")
4014
4015 (define_insn "*zero_extendhisi2_movzwl"
4016   [(set (match_operand:SI 0 "register_operand" "=r")
4017      (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "rm")))]
4018   "!TARGET_ZERO_EXTEND_WITH_AND
4019    || optimize_function_for_size_p (cfun)"
4020   "movz{wl|x}\t{%1, %0|%0, %1}"
4021   [(set_attr "type" "imovx")
4022    (set_attr "mode" "SI")])
4023
4024 (define_expand "zero_extendqihi2"
4025   [(parallel
4026     [(set (match_operand:HI 0 "register_operand" "")
4027        (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))
4028      (clobber (reg:CC FLAGS_REG))])]
4029   ""
4030   "")
4031
4032 (define_insn "*zero_extendqihi2_and"
4033   [(set (match_operand:HI 0 "register_operand" "=r,?&q")
4034      (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,qm")))
4035    (clobber (reg:CC FLAGS_REG))]
4036   "TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
4037   "#"
4038   [(set_attr "type" "alu1")
4039    (set_attr "mode" "HI")])
4040
4041 (define_insn "*zero_extendqihi2_movzbw_and"
4042   [(set (match_operand:HI 0 "register_operand" "=r,r")
4043      (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "qm,0")))
4044    (clobber (reg:CC FLAGS_REG))]
4045   "!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun)"
4046   "#"
4047   [(set_attr "type" "imovx,alu1")
4048    (set_attr "mode" "HI")])
4049
4050 ; zero extend to SImode here to avoid partial register stalls
4051 (define_insn "*zero_extendqihi2_movzbl"
4052   [(set (match_operand:HI 0 "register_operand" "=r")
4053      (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
4054   "(!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun))
4055    && reload_completed"
4056   "movz{bl|x}\t{%1, %k0|%k0, %1}"
4057   [(set_attr "type" "imovx")
4058    (set_attr "mode" "SI")])
4059
4060 ;; For the movzbw case strip only the clobber
4061 (define_split
4062   [(set (match_operand:HI 0 "register_operand" "")
4063         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))
4064    (clobber (reg:CC FLAGS_REG))]
4065   "reload_completed
4066    && (!TARGET_ZERO_EXTEND_WITH_AND
4067        || optimize_function_for_size_p (cfun))
4068    && (!REG_P (operands[1]) || ANY_QI_REG_P (operands[1]))"
4069   [(set (match_operand:HI 0 "register_operand" "")
4070         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))])
4071
4072 ;; When source and destination does not overlap, clear destination
4073 ;; first and then do the movb
4074 (define_split
4075   [(set (match_operand:HI 0 "register_operand" "")
4076         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))
4077    (clobber (reg:CC FLAGS_REG))]
4078   "reload_completed
4079    && ANY_QI_REG_P (operands[0])
4080    && (TARGET_ZERO_EXTEND_WITH_AND
4081        && optimize_function_for_speed_p (cfun))
4082    && !reg_overlap_mentioned_p (operands[0], operands[1])"
4083   [(set (strict_low_part (match_dup 2)) (match_dup 1))]
4084 {
4085   operands[2] = gen_lowpart (QImode, operands[0]);
4086   ix86_expand_clear (operands[0]);
4087 })
4088
4089 ;; Rest is handled by single and.
4090 (define_split
4091   [(set (match_operand:HI 0 "register_operand" "")
4092         (zero_extend:HI (match_operand:QI 1 "register_operand" "")))
4093    (clobber (reg:CC FLAGS_REG))]
4094   "reload_completed
4095    && true_regnum (operands[0]) == true_regnum (operands[1])"
4096   [(parallel [(set (match_dup 0) (and:HI (match_dup 0) (const_int 255)))
4097               (clobber (reg:CC FLAGS_REG))])]
4098   "")
4099
4100 (define_expand "zero_extendqisi2"
4101   [(parallel
4102     [(set (match_operand:SI 0 "register_operand" "")
4103        (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))
4104      (clobber (reg:CC FLAGS_REG))])]
4105   ""
4106   "")
4107
4108 (define_insn "*zero_extendqisi2_and"
4109   [(set (match_operand:SI 0 "register_operand" "=r,?&q")
4110      (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "0,qm")))
4111    (clobber (reg:CC FLAGS_REG))]
4112   "TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
4113   "#"
4114   [(set_attr "type" "alu1")
4115    (set_attr "mode" "SI")])
4116
4117 (define_insn "*zero_extendqisi2_movzbl_and"
4118   [(set (match_operand:SI 0 "register_operand" "=r,r")
4119      (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm,0")))
4120    (clobber (reg:CC FLAGS_REG))]
4121   "!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun)"
4122   "#"
4123   [(set_attr "type" "imovx,alu1")
4124    (set_attr "mode" "SI")])
4125
4126 (define_insn "*zero_extendqisi2_movzbl"
4127   [(set (match_operand:SI 0 "register_operand" "=r")
4128      (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
4129   "(!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun))
4130    && reload_completed"
4131   "movz{bl|x}\t{%1, %0|%0, %1}"
4132   [(set_attr "type" "imovx")
4133    (set_attr "mode" "SI")])
4134
4135 ;; For the movzbl case strip only the clobber
4136 (define_split
4137   [(set (match_operand:SI 0 "register_operand" "")
4138         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))
4139    (clobber (reg:CC FLAGS_REG))]
4140   "reload_completed
4141    && (!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun))
4142    && (!REG_P (operands[1]) || ANY_QI_REG_P (operands[1]))"
4143   [(set (match_dup 0)
4144         (zero_extend:SI (match_dup 1)))])
4145
4146 ;; When source and destination does not overlap, clear destination
4147 ;; first and then do the movb
4148 (define_split
4149   [(set (match_operand:SI 0 "register_operand" "")
4150         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))
4151    (clobber (reg:CC FLAGS_REG))]
4152   "reload_completed
4153    && ANY_QI_REG_P (operands[0])
4154    && (ANY_QI_REG_P (operands[1]) || MEM_P (operands[1]))
4155    && (TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))
4156    && !reg_overlap_mentioned_p (operands[0], operands[1])"
4157   [(set (strict_low_part (match_dup 2)) (match_dup 1))]
4158 {
4159   operands[2] = gen_lowpart (QImode, operands[0]);
4160   ix86_expand_clear (operands[0]);
4161 })
4162
4163 ;; Rest is handled by single and.
4164 (define_split
4165   [(set (match_operand:SI 0 "register_operand" "")
4166         (zero_extend:SI (match_operand:QI 1 "register_operand" "")))
4167    (clobber (reg:CC FLAGS_REG))]
4168   "reload_completed
4169    && true_regnum (operands[0]) == true_regnum (operands[1])"
4170   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (const_int 255)))
4171               (clobber (reg:CC FLAGS_REG))])]
4172   "")
4173
4174 ;; %%% Kill me once multi-word ops are sane.
4175 (define_expand "zero_extendsidi2"
4176   [(set (match_operand:DI 0 "register_operand" "")
4177      (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))]
4178   ""
4179 {
4180   if (!TARGET_64BIT)
4181     {
4182       emit_insn (gen_zero_extendsidi2_32 (operands[0], operands[1]));
4183       DONE;
4184     }
4185 })
4186
4187 (define_insn "zero_extendsidi2_32"
4188   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,?r,?o,?*Ym,?*y,?*Yi,*Y2")
4189         (zero_extend:DI
4190          (match_operand:SI 1 "nonimmediate_operand" "0,rm,r ,r   ,m  ,r   ,m")))
4191    (clobber (reg:CC FLAGS_REG))]
4192   "!TARGET_64BIT"
4193   "@
4194    #
4195    #
4196    #
4197    movd\t{%1, %0|%0, %1}
4198    movd\t{%1, %0|%0, %1}
4199    %vmovd\t{%1, %0|%0, %1}
4200    %vmovd\t{%1, %0|%0, %1}"
4201   [(set_attr "type" "multi,multi,multi,mmxmov,mmxmov,ssemov,ssemov")
4202    (set_attr "prefix" "*,*,*,orig,orig,maybe_vex,maybe_vex")
4203    (set_attr "mode" "SI,SI,SI,DI,DI,TI,TI")])
4204
4205 (define_insn "zero_extendsidi2_rex64"
4206   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,o,?*Ym,?*y,?*Yi,*Y2")
4207      (zero_extend:DI
4208        (match_operand:SI 1 "nonimmediate_operand"  "rm,0,r   ,m  ,r   ,m")))]
4209   "TARGET_64BIT"
4210   "@
4211    mov\t{%k1, %k0|%k0, %k1}
4212    #
4213    movd\t{%1, %0|%0, %1}
4214    movd\t{%1, %0|%0, %1}
4215    %vmovd\t{%1, %0|%0, %1}
4216    %vmovd\t{%1, %0|%0, %1}"
4217   [(set_attr "type" "imovx,imov,mmxmov,mmxmov,ssemov,ssemov")
4218    (set_attr "prefix" "orig,*,orig,orig,maybe_vex,maybe_vex")
4219    (set_attr "prefix_0f" "0,*,*,*,*,*")
4220    (set_attr "mode" "SI,DI,DI,DI,TI,TI")])
4221
4222 (define_split
4223   [(set (match_operand:DI 0 "memory_operand" "")
4224      (zero_extend:DI (match_dup 0)))]
4225   "TARGET_64BIT"
4226   [(set (match_dup 4) (const_int 0))]
4227   "split_di (&operands[0], 1, &operands[3], &operands[4]);")
4228
4229 (define_split
4230   [(set (match_operand:DI 0 "register_operand" "")
4231         (zero_extend:DI (match_operand:SI 1 "register_operand" "")))
4232    (clobber (reg:CC FLAGS_REG))]
4233   "!TARGET_64BIT && reload_completed
4234    && true_regnum (operands[0]) == true_regnum (operands[1])"
4235   [(set (match_dup 4) (const_int 0))]
4236   "split_di (&operands[0], 1, &operands[3], &operands[4]);")
4237
4238 (define_split
4239   [(set (match_operand:DI 0 "nonimmediate_operand" "")
4240         (zero_extend:DI (match_operand:SI 1 "general_operand" "")))
4241    (clobber (reg:CC FLAGS_REG))]
4242   "!TARGET_64BIT && reload_completed
4243    && !SSE_REG_P (operands[0]) && !MMX_REG_P (operands[0])"
4244   [(set (match_dup 3) (match_dup 1))
4245    (set (match_dup 4) (const_int 0))]
4246   "split_di (&operands[0], 1, &operands[3], &operands[4]);")
4247
4248 (define_insn "zero_extendhidi2"
4249   [(set (match_operand:DI 0 "register_operand" "=r")
4250      (zero_extend:DI (match_operand:HI 1 "nonimmediate_operand" "rm")))]
4251   "TARGET_64BIT"
4252   "movz{wl|x}\t{%1, %k0|%k0, %1}"
4253   [(set_attr "type" "imovx")
4254    (set_attr "mode" "SI")])
4255
4256 (define_insn "zero_extendqidi2"
4257   [(set (match_operand:DI 0 "register_operand" "=r")
4258      (zero_extend:DI (match_operand:QI 1 "nonimmediate_operand" "rm")))]
4259   "TARGET_64BIT"
4260   "movz{bl|x}\t{%1, %k0|%k0, %1}"
4261   [(set_attr "type" "imovx")
4262    (set_attr "mode" "SI")])
4263 \f
4264 ;; Sign extension instructions
4265
4266 (define_expand "extendsidi2"
4267   [(parallel [(set (match_operand:DI 0 "register_operand" "")
4268                    (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
4269               (clobber (reg:CC FLAGS_REG))
4270               (clobber (match_scratch:SI 2 ""))])]
4271   ""
4272 {
4273   if (TARGET_64BIT)
4274     {
4275       emit_insn (gen_extendsidi2_rex64 (operands[0], operands[1]));
4276       DONE;
4277     }
4278 })
4279
4280 (define_insn "*extendsidi2_1"
4281   [(set (match_operand:DI 0 "nonimmediate_operand" "=*A,r,?r,?*o")
4282         (sign_extend:DI (match_operand:SI 1 "register_operand" "0,0,r,r")))
4283    (clobber (reg:CC FLAGS_REG))
4284    (clobber (match_scratch:SI 2 "=X,X,X,&r"))]
4285   "!TARGET_64BIT"
4286   "#")
4287
4288 (define_insn "extendsidi2_rex64"
4289   [(set (match_operand:DI 0 "register_operand" "=*a,r")
4290         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "*0,rm")))]
4291   "TARGET_64BIT"
4292   "@
4293    {cltq|cdqe}
4294    movs{lq|x}\t{%1, %0|%0, %1}"
4295   [(set_attr "type" "imovx")
4296    (set_attr "mode" "DI")
4297    (set_attr "prefix_0f" "0")
4298    (set_attr "modrm" "0,1")])
4299
4300 (define_insn "extendhidi2"
4301   [(set (match_operand:DI 0 "register_operand" "=r")
4302         (sign_extend:DI (match_operand:HI 1 "nonimmediate_operand" "rm")))]
4303   "TARGET_64BIT"
4304   "movs{wq|x}\t{%1, %0|%0, %1}"
4305   [(set_attr "type" "imovx")
4306    (set_attr "mode" "DI")])
4307
4308 (define_insn "extendqidi2"
4309   [(set (match_operand:DI 0 "register_operand" "=r")
4310         (sign_extend:DI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
4311   "TARGET_64BIT"
4312   "movs{bq|x}\t{%1, %0|%0, %1}"
4313    [(set_attr "type" "imovx")
4314     (set_attr "mode" "DI")])
4315
4316 ;; Extend to memory case when source register does die.
4317 (define_split
4318   [(set (match_operand:DI 0 "memory_operand" "")
4319         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
4320    (clobber (reg:CC FLAGS_REG))
4321    (clobber (match_operand:SI 2 "register_operand" ""))]
4322   "(reload_completed
4323     && dead_or_set_p (insn, operands[1])
4324     && !reg_mentioned_p (operands[1], operands[0]))"
4325   [(set (match_dup 3) (match_dup 1))
4326    (parallel [(set (match_dup 1) (ashiftrt:SI (match_dup 1) (const_int 31)))
4327               (clobber (reg:CC FLAGS_REG))])
4328    (set (match_dup 4) (match_dup 1))]
4329   "split_di (&operands[0], 1, &operands[3], &operands[4]);")
4330
4331 ;; Extend to memory case when source register does not die.
4332 (define_split
4333   [(set (match_operand:DI 0 "memory_operand" "")
4334         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
4335    (clobber (reg:CC FLAGS_REG))
4336    (clobber (match_operand:SI 2 "register_operand" ""))]
4337   "reload_completed"
4338   [(const_int 0)]
4339 {
4340   split_di (&operands[0], 1, &operands[3], &operands[4]);
4341
4342   emit_move_insn (operands[3], operands[1]);
4343
4344   /* Generate a cltd if possible and doing so it profitable.  */
4345   if ((optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
4346       && true_regnum (operands[1]) == AX_REG
4347       && true_regnum (operands[2]) == DX_REG)
4348     {
4349       emit_insn (gen_ashrsi3_31 (operands[2], operands[1], GEN_INT (31)));
4350     }
4351   else
4352     {
4353       emit_move_insn (operands[2], operands[1]);
4354       emit_insn (gen_ashrsi3_31 (operands[2], operands[2], GEN_INT (31)));
4355     }
4356   emit_move_insn (operands[4], operands[2]);
4357   DONE;
4358 })
4359
4360 ;; Extend to register case.  Optimize case where source and destination
4361 ;; registers match and cases where we can use cltd.
4362 (define_split
4363   [(set (match_operand:DI 0 "register_operand" "")
4364         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
4365    (clobber (reg:CC FLAGS_REG))
4366    (clobber (match_scratch:SI 2 ""))]
4367   "reload_completed"
4368   [(const_int 0)]
4369 {
4370   split_di (&operands[0], 1, &operands[3], &operands[4]);
4371
4372   if (true_regnum (operands[3]) != true_regnum (operands[1]))
4373     emit_move_insn (operands[3], operands[1]);
4374
4375   /* Generate a cltd if possible and doing so it profitable.  */
4376   if ((optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
4377       && true_regnum (operands[3]) == AX_REG)
4378     {
4379       emit_insn (gen_ashrsi3_31 (operands[4], operands[3], GEN_INT (31)));
4380       DONE;
4381     }
4382
4383   if (true_regnum (operands[4]) != true_regnum (operands[1]))
4384     emit_move_insn (operands[4], operands[1]);
4385
4386   emit_insn (gen_ashrsi3_31 (operands[4], operands[4], GEN_INT (31)));
4387   DONE;
4388 })
4389
4390 (define_insn "extendhisi2"
4391   [(set (match_operand:SI 0 "register_operand" "=*a,r")
4392         (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "*0,rm")))]
4393   ""
4394 {
4395   switch (get_attr_prefix_0f (insn))
4396     {
4397     case 0:
4398       return "{cwtl|cwde}";
4399     default:
4400       return "movs{wl|x}\t{%1, %0|%0, %1}";
4401     }
4402 }
4403   [(set_attr "type" "imovx")
4404    (set_attr "mode" "SI")
4405    (set (attr "prefix_0f")
4406      ;; movsx is short decodable while cwtl is vector decoded.
4407      (if_then_else (and (eq_attr "cpu" "!k6")
4408                         (eq_attr "alternative" "0"))
4409         (const_string "0")
4410         (const_string "1")))
4411    (set (attr "modrm")
4412      (if_then_else (eq_attr "prefix_0f" "0")
4413         (const_string "0")
4414         (const_string "1")))])
4415
4416 (define_insn "*extendhisi2_zext"
4417   [(set (match_operand:DI 0 "register_operand" "=*a,r")
4418         (zero_extend:DI
4419           (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "*0,rm"))))]
4420   "TARGET_64BIT"
4421 {
4422   switch (get_attr_prefix_0f (insn))
4423     {
4424     case 0:
4425       return "{cwtl|cwde}";
4426     default:
4427       return "movs{wl|x}\t{%1, %k0|%k0, %1}";
4428     }
4429 }
4430   [(set_attr "type" "imovx")
4431    (set_attr "mode" "SI")
4432    (set (attr "prefix_0f")
4433      ;; movsx is short decodable while cwtl is vector decoded.
4434      (if_then_else (and (eq_attr "cpu" "!k6")
4435                         (eq_attr "alternative" "0"))
4436         (const_string "0")
4437         (const_string "1")))
4438    (set (attr "modrm")
4439      (if_then_else (eq_attr "prefix_0f" "0")
4440         (const_string "0")
4441         (const_string "1")))])
4442
4443 (define_insn "extendqihi2"
4444   [(set (match_operand:HI 0 "register_operand" "=*a,r")
4445         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "*0,qm")))]
4446   ""
4447 {
4448   switch (get_attr_prefix_0f (insn))
4449     {
4450     case 0:
4451       return "{cbtw|cbw}";
4452     default:
4453       return "movs{bw|x}\t{%1, %0|%0, %1}";
4454     }
4455 }
4456   [(set_attr "type" "imovx")
4457    (set_attr "mode" "HI")
4458    (set (attr "prefix_0f")
4459      ;; movsx is short decodable while cwtl is vector decoded.
4460      (if_then_else (and (eq_attr "cpu" "!k6")
4461                         (eq_attr "alternative" "0"))
4462         (const_string "0")
4463         (const_string "1")))
4464    (set (attr "modrm")
4465      (if_then_else (eq_attr "prefix_0f" "0")
4466         (const_string "0")
4467         (const_string "1")))])
4468
4469 (define_insn "extendqisi2"
4470   [(set (match_operand:SI 0 "register_operand" "=r")
4471         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
4472   ""
4473   "movs{bl|x}\t{%1, %0|%0, %1}"
4474    [(set_attr "type" "imovx")
4475     (set_attr "mode" "SI")])
4476
4477 (define_insn "*extendqisi2_zext"
4478   [(set (match_operand:DI 0 "register_operand" "=r")
4479         (zero_extend:DI
4480           (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm"))))]
4481   "TARGET_64BIT"
4482   "movs{bl|x}\t{%1, %k0|%k0, %1}"
4483    [(set_attr "type" "imovx")
4484     (set_attr "mode" "SI")])
4485 \f
4486 ;; Conversions between float and double.
4487
4488 ;; These are all no-ops in the model used for the 80387.  So just
4489 ;; emit moves.
4490
4491 ;; %%% Kill these when call knows how to work out a DFmode push earlier.
4492 (define_insn "*dummy_extendsfdf2"
4493   [(set (match_operand:DF 0 "push_operand" "=<")
4494         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "fY2")))]
4495   "0"
4496   "#")
4497
4498 (define_split
4499   [(set (match_operand:DF 0 "push_operand" "")
4500         (float_extend:DF (match_operand:SF 1 "fp_register_operand" "")))]
4501   ""
4502   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -8)))
4503    (set (mem:DF (reg:P SP_REG)) (float_extend:DF (match_dup 1)))])
4504
4505 (define_insn "*dummy_extendsfxf2"
4506   [(set (match_operand:XF 0 "push_operand" "=<")
4507         (float_extend:XF (match_operand:SF 1 "nonimmediate_operand" "f")))]
4508   "0"
4509   "#")
4510
4511 (define_split
4512   [(set (match_operand:XF 0 "push_operand" "")
4513         (float_extend:XF (match_operand:SF 1 "fp_register_operand" "")))]
4514   ""
4515   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
4516    (set (mem:XF (reg:P SP_REG)) (float_extend:XF (match_dup 1)))]
4517   "operands[2] = GEN_INT (TARGET_128BIT_LONG_DOUBLE ? -16 : -12);")
4518
4519 (define_split
4520   [(set (match_operand:XF 0 "push_operand" "")
4521         (float_extend:XF (match_operand:DF 1 "fp_register_operand" "")))]
4522   ""
4523   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
4524    (set (mem:DF (reg:P SP_REG)) (float_extend:XF (match_dup 1)))]
4525   "operands[2] = GEN_INT (TARGET_128BIT_LONG_DOUBLE ? -16 : -12);")
4526
4527 (define_expand "extendsfdf2"
4528   [(set (match_operand:DF 0 "nonimmediate_operand" "")
4529         (float_extend:DF (match_operand:SF 1 "general_operand" "")))]
4530   "TARGET_80387 || (TARGET_SSE2 && TARGET_SSE_MATH)"
4531 {
4532   /* ??? Needed for compress_float_constant since all fp constants
4533      are LEGITIMATE_CONSTANT_P.  */
4534   if (GET_CODE (operands[1]) == CONST_DOUBLE)
4535     {
4536       if ((!TARGET_SSE2 || TARGET_MIX_SSE_I387)
4537           && standard_80387_constant_p (operands[1]) > 0)
4538         {
4539           operands[1] = simplify_const_unary_operation
4540             (FLOAT_EXTEND, DFmode, operands[1], SFmode);
4541           emit_move_insn_1 (operands[0], operands[1]);
4542           DONE;
4543         }
4544       operands[1] = validize_mem (force_const_mem (SFmode, operands[1]));
4545     }
4546 })
4547
4548 /* For converting SF(xmm2) to DF(xmm1), use the following code instead of
4549    cvtss2sd:
4550       unpcklps xmm2,xmm2   ; packed conversion might crash on signaling NaNs
4551       cvtps2pd xmm2,xmm1
4552    We do the conversion post reload to avoid producing of 128bit spills
4553    that might lead to ICE on 32bit target.  The sequence unlikely combine
4554    anyway.  */
4555 (define_split
4556   [(set (match_operand:DF 0 "register_operand" "")
4557         (float_extend:DF
4558           (match_operand:SF 1 "nonimmediate_operand" "")))]
4559   "TARGET_USE_VECTOR_FP_CONVERTS
4560    && optimize_insn_for_speed_p ()
4561    && reload_completed && SSE_REG_P (operands[0])"
4562    [(set (match_dup 2)
4563          (float_extend:V2DF
4564            (vec_select:V2SF
4565              (match_dup 3)
4566              (parallel [(const_int 0) (const_int 1)]))))]
4567 {
4568   operands[2] = simplify_gen_subreg (V2DFmode, operands[0], DFmode, 0);
4569   operands[3] = simplify_gen_subreg (V4SFmode, operands[0], DFmode, 0);
4570   /* Use movss for loading from memory, unpcklps reg, reg for registers.
4571      Try to avoid move when unpacking can be done in source.  */
4572   if (REG_P (operands[1]))
4573     {
4574       /* If it is unsafe to overwrite upper half of source, we need
4575          to move to destination and unpack there.  */
4576       if ((ORIGINAL_REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
4577            || PSEUDO_REGNO_BYTES (ORIGINAL_REGNO (operands[1])) > 4)
4578           && true_regnum (operands[0]) != true_regnum (operands[1]))
4579         {
4580           rtx tmp = gen_rtx_REG (SFmode, true_regnum (operands[0]));
4581           emit_move_insn (tmp, operands[1]);
4582         }
4583       else
4584         operands[3] = simplify_gen_subreg (V4SFmode, operands[1], SFmode, 0);
4585       emit_insn (gen_sse_unpcklps (operands[3], operands[3], operands[3]));
4586     }
4587   else
4588     emit_insn (gen_vec_setv4sf_0 (operands[3],
4589                                   CONST0_RTX (V4SFmode), operands[1]));
4590 })
4591
4592 (define_insn "*extendsfdf2_mixed"
4593   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,m,x")
4594         (float_extend:DF
4595           (match_operand:SF 1 "nonimmediate_operand" "fm,f,xm")))]
4596   "TARGET_SSE2 && TARGET_MIX_SSE_I387"
4597 {
4598   switch (which_alternative)
4599     {
4600     case 0:
4601     case 1:
4602       return output_387_reg_move (insn, operands);
4603
4604     case 2:
4605       return "%vcvtss2sd\t{%1, %d0|%d0, %1}";
4606
4607     default:
4608       gcc_unreachable ();
4609     }
4610 }
4611   [(set_attr "type" "fmov,fmov,ssecvt")
4612    (set_attr "prefix" "orig,orig,maybe_vex")
4613    (set_attr "mode" "SF,XF,DF")])
4614
4615 (define_insn "*extendsfdf2_sse"
4616   [(set (match_operand:DF 0 "nonimmediate_operand" "=x")
4617         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "xm")))]
4618   "TARGET_SSE2 && TARGET_SSE_MATH"
4619   "%vcvtss2sd\t{%1, %d0|%d0, %1}"
4620   [(set_attr "type" "ssecvt")
4621    (set_attr "prefix" "maybe_vex")
4622    (set_attr "mode" "DF")])
4623
4624 (define_insn "*extendsfdf2_i387"
4625   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,m")
4626         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "fm,f")))]
4627   "TARGET_80387"
4628   "* return output_387_reg_move (insn, operands);"
4629   [(set_attr "type" "fmov")
4630    (set_attr "mode" "SF,XF")])
4631
4632 (define_expand "extend<mode>xf2"
4633   [(set (match_operand:XF 0 "nonimmediate_operand" "")
4634         (float_extend:XF (match_operand:MODEF 1 "general_operand" "")))]
4635   "TARGET_80387"
4636 {
4637   /* ??? Needed for compress_float_constant since all fp constants
4638      are LEGITIMATE_CONSTANT_P.  */
4639   if (GET_CODE (operands[1]) == CONST_DOUBLE)
4640     {
4641       if (standard_80387_constant_p (operands[1]) > 0)
4642         {
4643           operands[1] = simplify_const_unary_operation
4644             (FLOAT_EXTEND, XFmode, operands[1], <MODE>mode);
4645           emit_move_insn_1 (operands[0], operands[1]);
4646           DONE;
4647         }
4648       operands[1] = validize_mem (force_const_mem (<MODE>mode, operands[1]));
4649     }
4650 })
4651
4652 (define_insn "*extend<mode>xf2_i387"
4653   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m")
4654         (float_extend:XF
4655           (match_operand:MODEF 1 "nonimmediate_operand" "fm,f")))]
4656   "TARGET_80387"
4657   "* return output_387_reg_move (insn, operands);"
4658   [(set_attr "type" "fmov")
4659    (set_attr "mode" "<MODE>,XF")])
4660
4661 ;; %%% This seems bad bad news.
4662 ;; This cannot output into an f-reg because there is no way to be sure
4663 ;; of truncating in that case.  Otherwise this is just like a simple move
4664 ;; insn.  So we pretend we can output to a reg in order to get better
4665 ;; register preferencing, but we really use a stack slot.
4666
4667 ;; Conversion from DFmode to SFmode.
4668
4669 (define_expand "truncdfsf2"
4670   [(set (match_operand:SF 0 "nonimmediate_operand" "")
4671         (float_truncate:SF
4672           (match_operand:DF 1 "nonimmediate_operand" "")))]
4673   "TARGET_80387 || (TARGET_SSE2 && TARGET_SSE_MATH)"
4674 {
4675   if (TARGET_SSE2 && TARGET_SSE_MATH && !TARGET_MIX_SSE_I387)
4676     ;
4677   else if (flag_unsafe_math_optimizations)
4678     ;
4679   else
4680     {
4681       enum ix86_stack_slot slot = (virtuals_instantiated
4682                                    ? SLOT_TEMP
4683                                    : SLOT_VIRTUAL);
4684       rtx temp = assign_386_stack_local (SFmode, slot);
4685       emit_insn (gen_truncdfsf2_with_temp (operands[0], operands[1], temp));
4686       DONE;
4687     }
4688 })
4689
4690 /* For converting DF(xmm2) to SF(xmm1), use the following code instead of
4691    cvtsd2ss:
4692       unpcklpd xmm2,xmm2   ; packed conversion might crash on signaling NaNs
4693       cvtpd2ps xmm2,xmm1
4694    We do the conversion post reload to avoid producing of 128bit spills
4695    that might lead to ICE on 32bit target.  The sequence unlikely combine
4696    anyway.  */
4697 (define_split
4698   [(set (match_operand:SF 0 "register_operand" "")
4699         (float_truncate:SF
4700           (match_operand:DF 1 "nonimmediate_operand" "")))]
4701   "TARGET_USE_VECTOR_FP_CONVERTS
4702    && optimize_insn_for_speed_p ()
4703    && reload_completed && SSE_REG_P (operands[0])"
4704    [(set (match_dup 2)
4705          (vec_concat:V4SF
4706            (float_truncate:V2SF
4707              (match_dup 4))
4708            (match_dup 3)))]
4709 {
4710   operands[2] = simplify_gen_subreg (V4SFmode, operands[0], SFmode, 0);
4711   operands[3] = CONST0_RTX (V2SFmode);
4712   operands[4] = simplify_gen_subreg (V2DFmode, operands[0], SFmode, 0);
4713   /* Use movsd for loading from memory, unpcklpd for registers.
4714      Try to avoid move when unpacking can be done in source, or SSE3
4715      movddup is available.  */
4716   if (REG_P (operands[1]))
4717     {
4718       if (!TARGET_SSE3
4719           && true_regnum (operands[0]) != true_regnum (operands[1])
4720           && (ORIGINAL_REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
4721               || PSEUDO_REGNO_BYTES (ORIGINAL_REGNO (operands[1])) > 8))
4722         {
4723           rtx tmp = simplify_gen_subreg (DFmode, operands[0], SFmode, 0);
4724           emit_move_insn (tmp, operands[1]);
4725           operands[1] = tmp;
4726         }
4727       else if (!TARGET_SSE3)
4728         operands[4] = simplify_gen_subreg (V2DFmode, operands[1], DFmode, 0);
4729       emit_insn (gen_vec_dupv2df (operands[4], operands[1]));
4730     }
4731   else
4732     emit_insn (gen_sse2_loadlpd (operands[4],
4733                                  CONST0_RTX (V2DFmode), operands[1]));
4734 })
4735
4736 (define_expand "truncdfsf2_with_temp"
4737   [(parallel [(set (match_operand:SF 0 "" "")
4738                    (float_truncate:SF (match_operand:DF 1 "" "")))
4739               (clobber (match_operand:SF 2 "" ""))])]
4740   "")
4741
4742 (define_insn "*truncdfsf_fast_mixed"
4743   [(set (match_operand:SF 0 "nonimmediate_operand"   "=fm,x")
4744         (float_truncate:SF
4745           (match_operand:DF 1 "nonimmediate_operand" "f  ,xm")))]
4746   "TARGET_SSE2 && TARGET_MIX_SSE_I387 && flag_unsafe_math_optimizations"
4747 {
4748   switch (which_alternative)
4749     {
4750     case 0:
4751       return output_387_reg_move (insn, operands);
4752     case 1:
4753       return "%vcvtsd2ss\t{%1, %d0|%d0, %1}";
4754     default:
4755       gcc_unreachable ();
4756     }
4757 }
4758   [(set_attr "type" "fmov,ssecvt")
4759    (set_attr "prefix" "orig,maybe_vex")
4760    (set_attr "mode" "SF")])
4761
4762 ;; Yes, this one doesn't depend on flag_unsafe_math_optimizations,
4763 ;; because nothing we do here is unsafe.
4764 (define_insn "*truncdfsf_fast_sse"
4765   [(set (match_operand:SF 0 "nonimmediate_operand"   "=x")
4766         (float_truncate:SF
4767           (match_operand:DF 1 "nonimmediate_operand" "xm")))]
4768   "TARGET_SSE2 && TARGET_SSE_MATH"
4769   "%vcvtsd2ss\t{%1, %d0|%d0, %1}"
4770   [(set_attr "type" "ssecvt")
4771    (set_attr "prefix" "maybe_vex")
4772    (set_attr "mode" "SF")])
4773
4774 (define_insn "*truncdfsf_fast_i387"
4775   [(set (match_operand:SF 0 "nonimmediate_operand"   "=fm")
4776         (float_truncate:SF
4777           (match_operand:DF 1 "nonimmediate_operand" "f")))]
4778   "TARGET_80387 && flag_unsafe_math_optimizations"
4779   "* return output_387_reg_move (insn, operands);"
4780   [(set_attr "type" "fmov")
4781    (set_attr "mode" "SF")])
4782
4783 (define_insn "*truncdfsf_mixed"
4784   [(set (match_operand:SF 0 "nonimmediate_operand"   "=m,Y2 ,?f,?x,?*r")
4785         (float_truncate:SF
4786           (match_operand:DF 1 "nonimmediate_operand" "f ,Y2m,f ,f ,f")))
4787    (clobber (match_operand:SF 2 "memory_operand"     "=X,X  ,m ,m ,m"))]
4788   "TARGET_MIX_SSE_I387"
4789 {
4790   switch (which_alternative)
4791     {
4792     case 0:
4793       return output_387_reg_move (insn, operands);
4794     case 1:
4795       return "%vcvtsd2ss\t{%1, %d0|%d0, %1}";
4796
4797     default:
4798       return "#";
4799     }
4800 }
4801   [(set_attr "type" "fmov,ssecvt,multi,multi,multi")
4802    (set_attr "unit" "*,*,i387,i387,i387")
4803    (set_attr "prefix" "orig,maybe_vex,orig,orig,orig")
4804    (set_attr "mode" "SF")])
4805
4806 (define_insn "*truncdfsf_i387"
4807   [(set (match_operand:SF 0 "nonimmediate_operand"   "=m,?f,?x,?*r")
4808         (float_truncate:SF
4809           (match_operand:DF 1 "nonimmediate_operand" "f ,f ,f ,f")))
4810    (clobber (match_operand:SF 2 "memory_operand"     "=X,m ,m ,m"))]
4811   "TARGET_80387"
4812 {
4813   switch (which_alternative)
4814     {
4815     case 0:
4816       return output_387_reg_move (insn, operands);
4817
4818     default:
4819       return "#";
4820     }
4821 }
4822   [(set_attr "type" "fmov,multi,multi,multi")
4823    (set_attr "unit" "*,i387,i387,i387")
4824    (set_attr "mode" "SF")])
4825
4826 (define_insn "*truncdfsf2_i387_1"
4827   [(set (match_operand:SF 0 "memory_operand" "=m")
4828         (float_truncate:SF
4829           (match_operand:DF 1 "register_operand" "f")))]
4830   "TARGET_80387
4831    && !(TARGET_SSE2 && TARGET_SSE_MATH)
4832    && !TARGET_MIX_SSE_I387"
4833   "* return output_387_reg_move (insn, operands);"
4834   [(set_attr "type" "fmov")
4835    (set_attr "mode" "SF")])
4836
4837 (define_split
4838   [(set (match_operand:SF 0 "register_operand" "")
4839         (float_truncate:SF
4840          (match_operand:DF 1 "fp_register_operand" "")))
4841    (clobber (match_operand 2 "" ""))]
4842   "reload_completed"
4843   [(set (match_dup 2) (match_dup 1))
4844    (set (match_dup 0) (match_dup 2))]
4845 {
4846   operands[1] = gen_rtx_REG (SFmode, true_regnum (operands[1]));
4847 })
4848
4849 ;; Conversion from XFmode to {SF,DF}mode
4850
4851 (define_expand "truncxf<mode>2"
4852   [(parallel [(set (match_operand:MODEF 0 "nonimmediate_operand" "")
4853                    (float_truncate:MODEF
4854                      (match_operand:XF 1 "register_operand" "")))
4855               (clobber (match_dup 2))])]
4856   "TARGET_80387"
4857 {
4858   if (flag_unsafe_math_optimizations)
4859     {
4860       rtx reg = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (<MODE>mode);
4861       emit_insn (gen_truncxf<mode>2_i387_noop (reg, operands[1]));
4862       if (reg != operands[0])
4863         emit_move_insn (operands[0], reg);
4864       DONE;
4865     }
4866   else
4867     {
4868      enum ix86_stack_slot slot = (virtuals_instantiated
4869                                   ? SLOT_TEMP
4870                                   : SLOT_VIRTUAL);
4871       operands[2] = assign_386_stack_local (<MODE>mode, slot);
4872     }
4873 })
4874
4875 (define_insn "*truncxfsf2_mixed"
4876   [(set (match_operand:SF 0 "nonimmediate_operand" "=m,?f,?x,?*r")
4877         (float_truncate:SF
4878           (match_operand:XF 1 "register_operand"   "f ,f ,f ,f")))
4879    (clobber (match_operand:SF 2 "memory_operand"   "=X,m ,m ,m"))]
4880   "TARGET_80387"
4881 {
4882   gcc_assert (!which_alternative);
4883   return output_387_reg_move (insn, operands);
4884 }
4885   [(set_attr "type" "fmov,multi,multi,multi")
4886    (set_attr "unit" "*,i387,i387,i387")
4887    (set_attr "mode" "SF")])
4888
4889 (define_insn "*truncxfdf2_mixed"
4890   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,?f,?Y2,?*r")
4891         (float_truncate:DF
4892           (match_operand:XF 1 "register_operand"   "f ,f ,f  ,f")))
4893    (clobber (match_operand:DF 2 "memory_operand"   "=X,m ,m  ,m"))]
4894   "TARGET_80387"
4895 {
4896   gcc_assert (!which_alternative);
4897   return output_387_reg_move (insn, operands);
4898 }
4899   [(set_attr "type" "fmov,multi,multi,multi")
4900    (set_attr "unit" "*,i387,i387,i387")
4901    (set_attr "mode" "DF")])
4902
4903 (define_insn "truncxf<mode>2_i387_noop"
4904   [(set (match_operand:MODEF 0 "register_operand" "=f")
4905         (float_truncate:MODEF
4906           (match_operand:XF 1 "register_operand" "f")))]
4907   "TARGET_80387 && flag_unsafe_math_optimizations"
4908   "* return output_387_reg_move (insn, operands);"
4909   [(set_attr "type" "fmov")
4910    (set_attr "mode" "<MODE>")])
4911
4912 (define_insn "*truncxf<mode>2_i387"
4913   [(set (match_operand:MODEF 0 "memory_operand" "=m")
4914         (float_truncate:MODEF
4915           (match_operand:XF 1 "register_operand" "f")))]
4916   "TARGET_80387"
4917   "* return output_387_reg_move (insn, operands);"
4918   [(set_attr "type" "fmov")
4919    (set_attr "mode" "<MODE>")])
4920
4921 (define_split
4922   [(set (match_operand:MODEF 0 "register_operand" "")
4923         (float_truncate:MODEF
4924           (match_operand:XF 1 "register_operand" "")))
4925    (clobber (match_operand:MODEF 2 "memory_operand" ""))]
4926   "TARGET_80387 && reload_completed"
4927   [(set (match_dup 2) (float_truncate:MODEF (match_dup 1)))
4928    (set (match_dup 0) (match_dup 2))]
4929   "")
4930
4931 (define_split
4932   [(set (match_operand:MODEF 0 "memory_operand" "")
4933         (float_truncate:MODEF
4934           (match_operand:XF 1 "register_operand" "")))
4935    (clobber (match_operand:MODEF 2 "memory_operand" ""))]
4936   "TARGET_80387"
4937   [(set (match_dup 0) (float_truncate:MODEF (match_dup 1)))]
4938   "")
4939 \f
4940 ;; Signed conversion to DImode.
4941
4942 (define_expand "fix_truncxfdi2"
4943   [(parallel [(set (match_operand:DI 0 "nonimmediate_operand" "")
4944                    (fix:DI (match_operand:XF 1 "register_operand" "")))
4945               (clobber (reg:CC FLAGS_REG))])]
4946   "TARGET_80387"
4947 {
4948   if (TARGET_FISTTP)
4949    {
4950      emit_insn (gen_fix_truncdi_fisttp_i387_1 (operands[0], operands[1]));
4951      DONE;
4952    }
4953 })
4954
4955 (define_expand "fix_trunc<mode>di2"
4956   [(parallel [(set (match_operand:DI 0 "nonimmediate_operand" "")
4957                    (fix:DI (match_operand:MODEF 1 "register_operand" "")))
4958               (clobber (reg:CC FLAGS_REG))])]
4959   "TARGET_80387 || (TARGET_64BIT && SSE_FLOAT_MODE_P (<MODE>mode))"
4960 {
4961   if (TARGET_FISTTP
4962       && !(TARGET_64BIT && SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))
4963    {
4964      emit_insn (gen_fix_truncdi_fisttp_i387_1 (operands[0], operands[1]));
4965      DONE;
4966    }
4967   if (TARGET_64BIT && SSE_FLOAT_MODE_P (<MODE>mode))
4968    {
4969      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (DImode);
4970      emit_insn (gen_fix_trunc<mode>di_sse (out, operands[1]));
4971      if (out != operands[0])
4972         emit_move_insn (operands[0], out);
4973      DONE;
4974    }
4975 })
4976
4977 ;; Signed conversion to SImode.
4978
4979 (define_expand "fix_truncxfsi2"
4980   [(parallel [(set (match_operand:SI 0 "nonimmediate_operand" "")
4981                    (fix:SI (match_operand:XF 1 "register_operand" "")))
4982               (clobber (reg:CC FLAGS_REG))])]
4983   "TARGET_80387"
4984 {
4985   if (TARGET_FISTTP)
4986    {
4987      emit_insn (gen_fix_truncsi_fisttp_i387_1 (operands[0], operands[1]));
4988      DONE;
4989    }
4990 })
4991
4992 (define_expand "fix_trunc<mode>si2"
4993   [(parallel [(set (match_operand:SI 0 "nonimmediate_operand" "")
4994                    (fix:SI (match_operand:MODEF 1 "register_operand" "")))
4995               (clobber (reg:CC FLAGS_REG))])]
4996   "TARGET_80387 || SSE_FLOAT_MODE_P (<MODE>mode)"
4997 {
4998   if (TARGET_FISTTP
4999       && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))
5000    {
5001      emit_insn (gen_fix_truncsi_fisttp_i387_1 (operands[0], operands[1]));
5002      DONE;
5003    }
5004   if (SSE_FLOAT_MODE_P (<MODE>mode))
5005    {
5006      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (SImode);
5007      emit_insn (gen_fix_trunc<mode>si_sse (out, operands[1]));
5008      if (out != operands[0])
5009         emit_move_insn (operands[0], out);
5010      DONE;
5011    }
5012 })
5013
5014 ;; Signed conversion to HImode.
5015
5016 (define_expand "fix_trunc<mode>hi2"
5017   [(parallel [(set (match_operand:HI 0 "nonimmediate_operand" "")
5018                    (fix:HI (match_operand:X87MODEF 1 "register_operand" "")))
5019               (clobber (reg:CC FLAGS_REG))])]
5020   "TARGET_80387
5021    && !(SSE_FLOAT_MODE_P (<MODE>mode) && (!TARGET_FISTTP || TARGET_SSE_MATH))"
5022 {
5023   if (TARGET_FISTTP)
5024    {
5025      emit_insn (gen_fix_trunchi_fisttp_i387_1 (operands[0], operands[1]));
5026      DONE;
5027    }
5028 })
5029
5030 ;; Unsigned conversion to SImode.
5031
5032 (define_expand "fixuns_trunc<mode>si2"
5033   [(parallel
5034     [(set (match_operand:SI 0 "register_operand" "")
5035           (unsigned_fix:SI
5036             (match_operand:MODEF 1 "nonimmediate_operand" "")))
5037      (use (match_dup 2))
5038      (clobber (match_scratch:<ssevecmode> 3 ""))
5039      (clobber (match_scratch:<ssevecmode> 4 ""))])]
5040   "!TARGET_64BIT && TARGET_SSE2 && TARGET_SSE_MATH"
5041 {
5042   enum machine_mode mode = <MODE>mode;
5043   enum machine_mode vecmode = <ssevecmode>mode;
5044   REAL_VALUE_TYPE TWO31r;
5045   rtx two31;
5046
5047   if (optimize_insn_for_size_p ())
5048     FAIL;
5049
5050   real_ldexp (&TWO31r, &dconst1, 31);
5051   two31 = const_double_from_real_value (TWO31r, mode);
5052   two31 = ix86_build_const_vector (mode, true, two31);
5053   operands[2] = force_reg (vecmode, two31);
5054 })
5055
5056 (define_insn_and_split "*fixuns_trunc<mode>_1"
5057   [(set (match_operand:SI 0 "register_operand" "=&x,&x")
5058         (unsigned_fix:SI
5059           (match_operand:MODEF 3 "nonimmediate_operand" "xm,xm")))
5060    (use (match_operand:<ssevecmode> 4  "nonimmediate_operand" "m,x"))
5061    (clobber (match_scratch:<ssevecmode> 1 "=x,&x"))
5062    (clobber (match_scratch:<ssevecmode> 2 "=x,x"))]
5063   "!TARGET_64BIT && TARGET_SSE2 && TARGET_SSE_MATH
5064    && optimize_function_for_speed_p (cfun)"
5065   "#"
5066   "&& reload_completed"
5067   [(const_int 0)]
5068 {
5069   ix86_split_convert_uns_si_sse (operands);
5070   DONE;
5071 })
5072
5073 ;; Unsigned conversion to HImode.
5074 ;; Without these patterns, we'll try the unsigned SI conversion which
5075 ;; is complex for SSE, rather than the signed SI conversion, which isn't.
5076
5077 (define_expand "fixuns_trunc<mode>hi2"
5078   [(set (match_dup 2)
5079         (fix:SI (match_operand:MODEF 1 "nonimmediate_operand" "")))
5080    (set (match_operand:HI 0 "nonimmediate_operand" "")
5081         (subreg:HI (match_dup 2) 0))]
5082   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
5083   "operands[2] = gen_reg_rtx (SImode);")
5084
5085 ;; When SSE is available, it is always faster to use it!
5086 (define_insn "fix_trunc<mode>di_sse"
5087   [(set (match_operand:DI 0 "register_operand" "=r,r")
5088         (fix:DI (match_operand:MODEF 1 "nonimmediate_operand" "x,m")))]
5089   "TARGET_64BIT && SSE_FLOAT_MODE_P (<MODE>mode)
5090    && (!TARGET_FISTTP || TARGET_SSE_MATH)"
5091   "%vcvtts<ssemodefsuffix>2si{q}\t{%1, %0|%0, %1}"
5092   [(set_attr "type" "sseicvt")
5093    (set_attr "prefix" "maybe_vex")
5094    (set_attr "prefix_rex" "1")
5095    (set_attr "mode" "<MODE>")
5096    (set_attr "athlon_decode" "double,vector")
5097    (set_attr "amdfam10_decode" "double,double")])
5098
5099 (define_insn "fix_trunc<mode>si_sse"
5100   [(set (match_operand:SI 0 "register_operand" "=r,r")
5101         (fix:SI (match_operand:MODEF 1 "nonimmediate_operand" "x,m")))]
5102   "SSE_FLOAT_MODE_P (<MODE>mode)
5103    && (!TARGET_FISTTP || TARGET_SSE_MATH)"
5104   "%vcvtts<ssemodefsuffix>2si\t{%1, %0|%0, %1}"
5105   [(set_attr "type" "sseicvt")
5106    (set_attr "prefix" "maybe_vex")
5107    (set_attr "mode" "<MODE>")
5108    (set_attr "athlon_decode" "double,vector")
5109    (set_attr "amdfam10_decode" "double,double")])
5110
5111 ;; Shorten x87->SSE reload sequences of fix_trunc?f?i_sse patterns.
5112 (define_peephole2
5113   [(set (match_operand:MODEF 0 "register_operand" "")
5114         (match_operand:MODEF 1 "memory_operand" ""))
5115    (set (match_operand:SSEMODEI24 2 "register_operand" "")
5116         (fix:SSEMODEI24 (match_dup 0)))]
5117   "TARGET_SHORTEN_X87_SSE
5118    && peep2_reg_dead_p (2, operands[0])"
5119   [(set (match_dup 2) (fix:SSEMODEI24 (match_dup 1)))]
5120   "")
5121
5122 ;; Avoid vector decoded forms of the instruction.
5123 (define_peephole2
5124   [(match_scratch:DF 2 "Y2")
5125    (set (match_operand:SSEMODEI24 0 "register_operand" "")
5126         (fix:SSEMODEI24 (match_operand:DF 1 "memory_operand" "")))]
5127   "TARGET_AVOID_VECTOR_DECODE && optimize_insn_for_speed_p ()"
5128   [(set (match_dup 2) (match_dup 1))
5129    (set (match_dup 0) (fix:SSEMODEI24 (match_dup 2)))]
5130   "")
5131
5132 (define_peephole2
5133   [(match_scratch:SF 2 "x")
5134    (set (match_operand:SSEMODEI24 0 "register_operand" "")
5135         (fix:SSEMODEI24 (match_operand:SF 1 "memory_operand" "")))]
5136   "TARGET_AVOID_VECTOR_DECODE && optimize_insn_for_speed_p ()"
5137   [(set (match_dup 2) (match_dup 1))
5138    (set (match_dup 0) (fix:SSEMODEI24 (match_dup 2)))]
5139   "")
5140
5141 (define_insn_and_split "fix_trunc<mode>_fisttp_i387_1"
5142   [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "")
5143         (fix:X87MODEI (match_operand 1 "register_operand" "")))]
5144   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
5145    && TARGET_FISTTP
5146    && !((SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
5147          && (TARGET_64BIT || <MODE>mode != DImode))
5148         && TARGET_SSE_MATH)
5149    && can_create_pseudo_p ()"
5150   "#"
5151   "&& 1"
5152   [(const_int 0)]
5153 {
5154   if (memory_operand (operands[0], VOIDmode))
5155     emit_insn (gen_fix_trunc<mode>_i387_fisttp (operands[0], operands[1]));
5156   else
5157     {
5158       operands[2] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
5159       emit_insn (gen_fix_trunc<mode>_i387_fisttp_with_temp (operands[0],
5160                                                             operands[1],
5161                                                             operands[2]));
5162     }
5163   DONE;
5164 }
5165   [(set_attr "type" "fisttp")
5166    (set_attr "mode" "<MODE>")])
5167
5168 (define_insn "fix_trunc<mode>_i387_fisttp"
5169   [(set (match_operand:X87MODEI 0 "memory_operand" "=m")
5170         (fix:X87MODEI (match_operand 1 "register_operand" "f")))
5171    (clobber (match_scratch:XF 2 "=&1f"))]
5172   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
5173    && TARGET_FISTTP
5174    && !((SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
5175          && (TARGET_64BIT || <MODE>mode != DImode))
5176         && TARGET_SSE_MATH)"
5177   "* return output_fix_trunc (insn, operands, 1);"
5178   [(set_attr "type" "fisttp")
5179    (set_attr "mode" "<MODE>")])
5180
5181 (define_insn "fix_trunc<mode>_i387_fisttp_with_temp"
5182   [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "=m,?r")
5183         (fix:X87MODEI (match_operand 1 "register_operand" "f,f")))
5184    (clobber (match_operand:X87MODEI 2 "memory_operand" "=X,m"))
5185    (clobber (match_scratch:XF 3 "=&1f,&1f"))]
5186   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
5187    && TARGET_FISTTP
5188    && !((SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
5189         && (TARGET_64BIT || <MODE>mode != DImode))
5190         && TARGET_SSE_MATH)"
5191   "#"
5192   [(set_attr "type" "fisttp")
5193    (set_attr "mode" "<MODE>")])
5194
5195 (define_split
5196   [(set (match_operand:X87MODEI 0 "register_operand" "")
5197         (fix:X87MODEI (match_operand 1 "register_operand" "")))
5198    (clobber (match_operand:X87MODEI 2 "memory_operand" ""))
5199    (clobber (match_scratch 3 ""))]
5200   "reload_completed"
5201   [(parallel [(set (match_dup 2) (fix:X87MODEI (match_dup 1)))
5202               (clobber (match_dup 3))])
5203    (set (match_dup 0) (match_dup 2))]
5204   "")
5205
5206 (define_split
5207   [(set (match_operand:X87MODEI 0 "memory_operand" "")
5208         (fix:X87MODEI (match_operand 1 "register_operand" "")))
5209    (clobber (match_operand:X87MODEI 2 "memory_operand" ""))
5210    (clobber (match_scratch 3 ""))]
5211   "reload_completed"
5212   [(parallel [(set (match_dup 0) (fix:X87MODEI (match_dup 1)))
5213               (clobber (match_dup 3))])]
5214   "")
5215
5216 ;; See the comments in i386.h near OPTIMIZE_MODE_SWITCHING for the description
5217 ;; of the machinery. Please note the clobber of FLAGS_REG. In i387 control
5218 ;; word calculation (inserted by LCM in mode switching pass) a FLAGS_REG
5219 ;; clobbering insns can be used. Look at emit_i387_cw_initialization ()
5220 ;; function in i386.c.
5221 (define_insn_and_split "*fix_trunc<mode>_i387_1"
5222   [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "")
5223         (fix:X87MODEI (match_operand 1 "register_operand" "")))
5224    (clobber (reg:CC FLAGS_REG))]
5225   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
5226    && !TARGET_FISTTP
5227    && !(SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
5228          && (TARGET_64BIT || <MODE>mode != DImode))
5229    && can_create_pseudo_p ()"
5230   "#"
5231   "&& 1"
5232   [(const_int 0)]
5233 {
5234   ix86_optimize_mode_switching[I387_TRUNC] = 1;
5235
5236   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
5237   operands[3] = assign_386_stack_local (HImode, SLOT_CW_TRUNC);
5238   if (memory_operand (operands[0], VOIDmode))
5239     emit_insn (gen_fix_trunc<mode>_i387 (operands[0], operands[1],
5240                                          operands[2], operands[3]));
5241   else
5242     {
5243       operands[4] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
5244       emit_insn (gen_fix_trunc<mode>_i387_with_temp (operands[0], operands[1],
5245                                                      operands[2], operands[3],
5246                                                      operands[4]));
5247     }
5248   DONE;
5249 }
5250   [(set_attr "type" "fistp")
5251    (set_attr "i387_cw" "trunc")
5252    (set_attr "mode" "<MODE>")])
5253
5254 (define_insn "fix_truncdi_i387"
5255   [(set (match_operand:DI 0 "memory_operand" "=m")
5256         (fix:DI (match_operand 1 "register_operand" "f")))
5257    (use (match_operand:HI 2 "memory_operand" "m"))
5258    (use (match_operand:HI 3 "memory_operand" "m"))
5259    (clobber (match_scratch:XF 4 "=&1f"))]
5260   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
5261    && !TARGET_FISTTP
5262    && !(TARGET_64BIT && SSE_FLOAT_MODE_P (GET_MODE (operands[1])))"
5263   "* return output_fix_trunc (insn, operands, 0);"
5264   [(set_attr "type" "fistp")
5265    (set_attr "i387_cw" "trunc")
5266    (set_attr "mode" "DI")])
5267
5268 (define_insn "fix_truncdi_i387_with_temp"
5269   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
5270         (fix:DI (match_operand 1 "register_operand" "f,f")))
5271    (use (match_operand:HI 2 "memory_operand" "m,m"))
5272    (use (match_operand:HI 3 "memory_operand" "m,m"))
5273    (clobber (match_operand:DI 4 "memory_operand" "=X,m"))
5274    (clobber (match_scratch:XF 5 "=&1f,&1f"))]
5275   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
5276    && !TARGET_FISTTP
5277    && !(TARGET_64BIT && SSE_FLOAT_MODE_P (GET_MODE (operands[1])))"
5278   "#"
5279   [(set_attr "type" "fistp")
5280    (set_attr "i387_cw" "trunc")
5281    (set_attr "mode" "DI")])
5282
5283 (define_split
5284   [(set (match_operand:DI 0 "register_operand" "")
5285         (fix:DI (match_operand 1 "register_operand" "")))
5286    (use (match_operand:HI 2 "memory_operand" ""))
5287    (use (match_operand:HI 3 "memory_operand" ""))
5288    (clobber (match_operand:DI 4 "memory_operand" ""))
5289    (clobber (match_scratch 5 ""))]
5290   "reload_completed"
5291   [(parallel [(set (match_dup 4) (fix:DI (match_dup 1)))
5292               (use (match_dup 2))
5293               (use (match_dup 3))
5294               (clobber (match_dup 5))])
5295    (set (match_dup 0) (match_dup 4))]
5296   "")
5297
5298 (define_split
5299   [(set (match_operand:DI 0 "memory_operand" "")
5300         (fix:DI (match_operand 1 "register_operand" "")))
5301    (use (match_operand:HI 2 "memory_operand" ""))
5302    (use (match_operand:HI 3 "memory_operand" ""))
5303    (clobber (match_operand:DI 4 "memory_operand" ""))
5304    (clobber (match_scratch 5 ""))]
5305   "reload_completed"
5306   [(parallel [(set (match_dup 0) (fix:DI (match_dup 1)))
5307               (use (match_dup 2))
5308               (use (match_dup 3))
5309               (clobber (match_dup 5))])]
5310   "")
5311
5312 (define_insn "fix_trunc<mode>_i387"
5313   [(set (match_operand:X87MODEI12 0 "memory_operand" "=m")
5314         (fix:X87MODEI12 (match_operand 1 "register_operand" "f")))
5315    (use (match_operand:HI 2 "memory_operand" "m"))
5316    (use (match_operand:HI 3 "memory_operand" "m"))]
5317   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
5318    && !TARGET_FISTTP
5319    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
5320   "* return output_fix_trunc (insn, operands, 0);"
5321   [(set_attr "type" "fistp")
5322    (set_attr "i387_cw" "trunc")
5323    (set_attr "mode" "<MODE>")])
5324
5325 (define_insn "fix_trunc<mode>_i387_with_temp"
5326   [(set (match_operand:X87MODEI12 0 "nonimmediate_operand" "=m,?r")
5327         (fix:X87MODEI12 (match_operand 1 "register_operand" "f,f")))
5328    (use (match_operand:HI 2 "memory_operand" "m,m"))
5329    (use (match_operand:HI 3 "memory_operand" "m,m"))
5330    (clobber (match_operand:X87MODEI12 4 "memory_operand" "=X,m"))]
5331   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
5332    && !TARGET_FISTTP
5333    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
5334   "#"
5335   [(set_attr "type" "fistp")
5336    (set_attr "i387_cw" "trunc")
5337    (set_attr "mode" "<MODE>")])
5338
5339 (define_split
5340   [(set (match_operand:X87MODEI12 0 "register_operand" "")
5341         (fix:X87MODEI12 (match_operand 1 "register_operand" "")))
5342    (use (match_operand:HI 2 "memory_operand" ""))
5343    (use (match_operand:HI 3 "memory_operand" ""))
5344    (clobber (match_operand:X87MODEI12 4 "memory_operand" ""))]
5345   "reload_completed"
5346   [(parallel [(set (match_dup 4) (fix:X87MODEI12 (match_dup 1)))
5347               (use (match_dup 2))
5348               (use (match_dup 3))])
5349    (set (match_dup 0) (match_dup 4))]
5350   "")
5351
5352 (define_split
5353   [(set (match_operand:X87MODEI12 0 "memory_operand" "")
5354         (fix:X87MODEI12 (match_operand 1 "register_operand" "")))
5355    (use (match_operand:HI 2 "memory_operand" ""))
5356    (use (match_operand:HI 3 "memory_operand" ""))
5357    (clobber (match_operand:X87MODEI12 4 "memory_operand" ""))]
5358   "reload_completed"
5359   [(parallel [(set (match_dup 0) (fix:X87MODEI12 (match_dup 1)))
5360               (use (match_dup 2))
5361               (use (match_dup 3))])]
5362   "")
5363
5364 (define_insn "x86_fnstcw_1"
5365   [(set (match_operand:HI 0 "memory_operand" "=m")
5366         (unspec:HI [(reg:HI FPCR_REG)] UNSPEC_FSTCW))]
5367   "TARGET_80387"
5368   "fnstcw\t%0"
5369   [(set (attr "length") (symbol_ref "ix86_attr_length_address_default (insn) + 2"))
5370    (set_attr "mode" "HI")
5371    (set_attr "unit" "i387")])
5372
5373 (define_insn "x86_fldcw_1"
5374   [(set (reg:HI FPCR_REG)
5375         (unspec:HI [(match_operand:HI 0 "memory_operand" "m")] UNSPEC_FLDCW))]
5376   "TARGET_80387"
5377   "fldcw\t%0"
5378   [(set (attr "length") (symbol_ref "ix86_attr_length_address_default (insn) + 2"))
5379    (set_attr "mode" "HI")
5380    (set_attr "unit" "i387")
5381    (set_attr "athlon_decode" "vector")
5382    (set_attr "amdfam10_decode" "vector")])
5383 \f
5384 ;; Conversion between fixed point and floating point.
5385
5386 ;; Even though we only accept memory inputs, the backend _really_
5387 ;; wants to be able to do this between registers.
5388
5389 (define_expand "floathi<mode>2"
5390   [(set (match_operand:X87MODEF 0 "register_operand" "")
5391         (float:X87MODEF (match_operand:HI 1 "nonimmediate_operand" "")))]
5392   "TARGET_80387
5393    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
5394        || TARGET_MIX_SSE_I387)"
5395   "")
5396
5397 ;; Pre-reload splitter to add memory clobber to the pattern.
5398 (define_insn_and_split "*floathi<mode>2_1"
5399   [(set (match_operand:X87MODEF 0 "register_operand" "")
5400         (float:X87MODEF (match_operand:HI 1 "register_operand" "")))]
5401   "TARGET_80387
5402    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
5403        || TARGET_MIX_SSE_I387)
5404    && can_create_pseudo_p ()"
5405   "#"
5406   "&& 1"
5407   [(parallel [(set (match_dup 0)
5408               (float:X87MODEF (match_dup 1)))
5409    (clobber (match_dup 2))])]
5410   "operands[2] = assign_386_stack_local (HImode, SLOT_TEMP);")
5411
5412 (define_insn "*floathi<mode>2_i387_with_temp"
5413   [(set (match_operand:X87MODEF 0 "register_operand" "=f,f")
5414         (float:X87MODEF (match_operand:HI 1 "nonimmediate_operand" "m,?r")))
5415   (clobber (match_operand:HI 2 "memory_operand" "=m,m"))]
5416   "TARGET_80387
5417    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
5418        || TARGET_MIX_SSE_I387)"
5419   "#"
5420   [(set_attr "type" "fmov,multi")
5421    (set_attr "mode" "<MODE>")
5422    (set_attr "unit" "*,i387")
5423    (set_attr "fp_int_src" "true")])
5424
5425 (define_insn "*floathi<mode>2_i387"
5426   [(set (match_operand:X87MODEF 0 "register_operand" "=f")
5427         (float:X87MODEF (match_operand:HI 1 "memory_operand" "m")))]
5428   "TARGET_80387
5429    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
5430        || TARGET_MIX_SSE_I387)"
5431   "fild%Z1\t%1"
5432   [(set_attr "type" "fmov")
5433    (set_attr "mode" "<MODE>")
5434    (set_attr "fp_int_src" "true")])
5435
5436 (define_split
5437   [(set (match_operand:X87MODEF 0 "register_operand" "")
5438         (float:X87MODEF (match_operand:HI 1 "register_operand" "")))
5439    (clobber (match_operand:HI 2 "memory_operand" ""))]
5440   "TARGET_80387
5441    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
5442        || TARGET_MIX_SSE_I387)
5443    && reload_completed"
5444   [(set (match_dup 2) (match_dup 1))
5445    (set (match_dup 0) (float:X87MODEF (match_dup 2)))]
5446   "")
5447
5448 (define_split
5449   [(set (match_operand:X87MODEF 0 "register_operand" "")
5450         (float:X87MODEF (match_operand:HI 1 "memory_operand" "")))
5451    (clobber (match_operand:HI 2 "memory_operand" ""))]
5452    "TARGET_80387
5453     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
5454         || TARGET_MIX_SSE_I387)
5455     && reload_completed"
5456   [(set (match_dup 0) (float:X87MODEF (match_dup 1)))]
5457   "")
5458
5459 (define_expand "float<SSEMODEI24:mode><X87MODEF:mode>2"
5460   [(set (match_operand:X87MODEF 0 "register_operand" "")
5461         (float:X87MODEF
5462           (match_operand:SSEMODEI24 1 "nonimmediate_operand" "")))]
5463   "TARGET_80387
5464    || ((<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5465        && SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH)"
5466   "
5467 {
5468   if (!((<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5469         && SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH)
5470       && !X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, <SSEMODEI24:MODE>mode))
5471     {
5472       rtx reg = gen_reg_rtx (XFmode);
5473       rtx insn;
5474
5475       emit_insn (gen_float<SSEMODEI24:mode>xf2 (reg, operands[1]));
5476
5477       if (<X87MODEF:MODE>mode == SFmode)
5478         insn = gen_truncxfsf2 (operands[0], reg);
5479       else if (<X87MODEF:MODE>mode == DFmode)
5480         insn = gen_truncxfdf2 (operands[0], reg);
5481       else
5482         gcc_unreachable ();
5483
5484       emit_insn (insn);
5485       DONE;
5486     }
5487 }")
5488
5489 ;; Pre-reload splitter to add memory clobber to the pattern.
5490 (define_insn_and_split "*float<SSEMODEI24:mode><X87MODEF:mode>2_1"
5491   [(set (match_operand:X87MODEF 0 "register_operand" "")
5492         (float:X87MODEF (match_operand:SSEMODEI24 1 "register_operand" "")))]
5493   "((TARGET_80387
5494      && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, <SSEMODEI24:MODE>mode)
5495      && (!((<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5496            && SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH)
5497          || TARGET_MIX_SSE_I387))
5498     || ((<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5499         && SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH
5500         && ((<SSEMODEI24:MODE>mode == SImode
5501              && TARGET_SSE2 && TARGET_USE_VECTOR_CONVERTS
5502              && optimize_function_for_speed_p (cfun)
5503              && flag_trapping_math)
5504             || !(TARGET_INTER_UNIT_CONVERSIONS
5505                  || optimize_function_for_size_p (cfun)))))
5506    && can_create_pseudo_p ()"
5507   "#"
5508   "&& 1"
5509   [(parallel [(set (match_dup 0) (float:X87MODEF (match_dup 1)))
5510               (clobber (match_dup 2))])]
5511 {
5512   operands[2] = assign_386_stack_local (<SSEMODEI24:MODE>mode, SLOT_TEMP);
5513
5514   /* Avoid store forwarding (partial memory) stall penalty
5515      by passing DImode value through XMM registers.  */
5516   if (<SSEMODEI24:MODE>mode == DImode && !TARGET_64BIT
5517       && TARGET_80387 && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES
5518       && optimize_function_for_speed_p (cfun))
5519     {
5520       emit_insn (gen_floatdi<X87MODEF:mode>2_i387_with_xmm (operands[0],
5521                                                             operands[1],
5522                                                             operands[2]));
5523       DONE;
5524     }
5525 })
5526
5527 (define_insn "*floatsi<mode>2_vector_mixed_with_temp"
5528   [(set (match_operand:MODEF 0 "register_operand" "=f,f,x,x,x")
5529         (float:MODEF
5530           (match_operand:SI 1 "nonimmediate_operand" "m,?r,r,m,!x")))
5531    (clobber (match_operand:SI 2 "memory_operand" "=X,m,m,X,m"))]
5532   "TARGET_SSE2 && TARGET_MIX_SSE_I387
5533    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)"
5534   "#"
5535   [(set_attr "type" "fmov,multi,sseicvt,sseicvt,sseicvt")
5536    (set_attr "mode" "<MODE>,<MODE>,<MODE>,<MODE>,<ssevecmode>")
5537    (set_attr "unit" "*,i387,*,*,*")
5538    (set_attr "athlon_decode" "*,*,double,direct,double")
5539    (set_attr "amdfam10_decode" "*,*,vector,double,double")
5540    (set_attr "fp_int_src" "true")])
5541
5542 (define_insn "*floatsi<mode>2_vector_mixed"
5543   [(set (match_operand:MODEF 0 "register_operand" "=f,x")
5544         (float:MODEF (match_operand:SI 1 "memory_operand" "m,m")))]
5545   "TARGET_SSE2 && TARGET_MIX_SSE_I387
5546    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)"
5547   "@
5548    fild%Z1\t%1
5549    #"
5550   [(set_attr "type" "fmov,sseicvt")
5551    (set_attr "mode" "<MODE>,<ssevecmode>")
5552    (set_attr "unit" "i387,*")
5553    (set_attr "athlon_decode" "*,direct")
5554    (set_attr "amdfam10_decode" "*,double")
5555    (set_attr "fp_int_src" "true")])
5556
5557 (define_insn "*float<SSEMODEI24:mode><MODEF:mode>2_mixed_with_temp"
5558   [(set (match_operand:MODEF 0 "register_operand" "=f,f,x,x")
5559         (float:MODEF
5560           (match_operand:SSEMODEI24 1 "nonimmediate_operand" "m,?r,r,m")))
5561   (clobber (match_operand:SSEMODEI24 2 "memory_operand" "=X,m,m,X"))]
5562   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5563    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_MIX_SSE_I387"
5564   "#"
5565   [(set_attr "type" "fmov,multi,sseicvt,sseicvt")
5566    (set_attr "mode" "<MODEF:MODE>")
5567    (set_attr "unit" "*,i387,*,*")
5568    (set_attr "athlon_decode" "*,*,double,direct")
5569    (set_attr "amdfam10_decode" "*,*,vector,double")
5570    (set_attr "fp_int_src" "true")])
5571
5572 (define_split
5573   [(set (match_operand:MODEF 0 "register_operand" "")
5574         (float:MODEF (match_operand:SSEMODEI24 1 "register_operand" "")))
5575    (clobber (match_operand:SSEMODEI24 2 "memory_operand" ""))]
5576   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5577    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_MIX_SSE_I387
5578    && TARGET_INTER_UNIT_CONVERSIONS
5579    && reload_completed
5580    && (SSE_REG_P (operands[0])
5581        || (GET_CODE (operands[0]) == SUBREG
5582            && SSE_REG_P (operands[0])))"
5583   [(set (match_dup 0) (float:MODEF (match_dup 1)))]
5584   "")
5585
5586 (define_split
5587   [(set (match_operand:MODEF 0 "register_operand" "")
5588         (float:MODEF (match_operand:SSEMODEI24 1 "register_operand" "")))
5589    (clobber (match_operand:SSEMODEI24 2 "memory_operand" ""))]
5590   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5591    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_MIX_SSE_I387
5592    && !(TARGET_INTER_UNIT_CONVERSIONS || optimize_function_for_size_p (cfun))
5593    && reload_completed
5594    && (SSE_REG_P (operands[0])
5595        || (GET_CODE (operands[0]) == SUBREG
5596            && SSE_REG_P (operands[0])))"
5597   [(set (match_dup 2) (match_dup 1))
5598    (set (match_dup 0) (float:MODEF (match_dup 2)))]
5599   "")
5600
5601 (define_insn "*float<SSEMODEI24:mode><MODEF:mode>2_mixed_interunit"
5602   [(set (match_operand:MODEF 0 "register_operand" "=f,x,x")
5603         (float:MODEF
5604           (match_operand:SSEMODEI24 1 "nonimmediate_operand" "m,r,m")))]
5605   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5606    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_MIX_SSE_I387
5607    && (TARGET_INTER_UNIT_CONVERSIONS || optimize_function_for_size_p (cfun))"
5608   "@
5609    fild%Z1\t%1
5610    %vcvtsi2s<MODEF:ssemodefsuffix><SSEMODEI24:rex64suffix>\t{%1, %d0|%d0, %1}
5611    %vcvtsi2s<MODEF:ssemodefsuffix><SSEMODEI24:rex64suffix>\t{%1, %d0|%d0, %1}"
5612   [(set_attr "type" "fmov,sseicvt,sseicvt")
5613    (set_attr "prefix" "orig,maybe_vex,maybe_vex")
5614    (set_attr "mode" "<MODEF:MODE>")
5615    (set (attr "prefix_rex")
5616      (if_then_else
5617        (and (eq_attr "prefix" "maybe_vex")
5618             (ne (symbol_ref "<SSEMODEI24:MODE>mode == DImode") (const_int 0)))
5619        (const_string "1")
5620        (const_string "*")))
5621    (set_attr "unit" "i387,*,*")
5622    (set_attr "athlon_decode" "*,double,direct")
5623    (set_attr "amdfam10_decode" "*,vector,double")
5624    (set_attr "fp_int_src" "true")])
5625
5626 (define_insn "*float<SSEMODEI24:mode><MODEF:mode>2_mixed_nointerunit"
5627   [(set (match_operand:MODEF 0 "register_operand" "=f,x")
5628         (float:MODEF
5629           (match_operand:SSEMODEI24 1 "memory_operand" "m,m")))]
5630   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5631    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_MIX_SSE_I387
5632    && !(TARGET_INTER_UNIT_CONVERSIONS || optimize_function_for_size_p (cfun))"
5633   "@
5634    fild%Z1\t%1
5635    %vcvtsi2s<MODEF:ssemodefsuffix><SSEMODEI24:rex64suffix>\t{%1, %d0|%d0, %1}"
5636   [(set_attr "type" "fmov,sseicvt")
5637    (set_attr "prefix" "orig,maybe_vex")
5638    (set_attr "mode" "<MODEF:MODE>")
5639    (set (attr "prefix_rex")
5640      (if_then_else
5641        (and (eq_attr "prefix" "maybe_vex")
5642             (ne (symbol_ref "<SSEMODEI24:MODE>mode == DImode") (const_int 0)))
5643        (const_string "1")
5644        (const_string "*")))
5645    (set_attr "athlon_decode" "*,direct")
5646    (set_attr "amdfam10_decode" "*,double")
5647    (set_attr "fp_int_src" "true")])
5648
5649 (define_insn "*floatsi<mode>2_vector_sse_with_temp"
5650   [(set (match_operand:MODEF 0 "register_operand" "=x,x,x")
5651         (float:MODEF
5652           (match_operand:SI 1 "nonimmediate_operand" "r,m,!x")))
5653    (clobber (match_operand:SI 2 "memory_operand" "=m,X,m"))]
5654   "TARGET_SSE2 && TARGET_SSE_MATH
5655    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)"
5656   "#"
5657   [(set_attr "type" "sseicvt")
5658    (set_attr "mode" "<MODE>,<MODE>,<ssevecmode>")
5659    (set_attr "athlon_decode" "double,direct,double")
5660    (set_attr "amdfam10_decode" "vector,double,double")
5661    (set_attr "fp_int_src" "true")])
5662
5663 (define_insn "*floatsi<mode>2_vector_sse"
5664   [(set (match_operand:MODEF 0 "register_operand" "=x")
5665         (float:MODEF (match_operand:SI 1 "memory_operand" "m")))]
5666   "TARGET_SSE2 && TARGET_SSE_MATH
5667    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)"
5668   "#"
5669   [(set_attr "type" "sseicvt")
5670    (set_attr "mode" "<MODE>")
5671    (set_attr "athlon_decode" "direct")
5672    (set_attr "amdfam10_decode" "double")
5673    (set_attr "fp_int_src" "true")])
5674
5675 (define_split
5676   [(set (match_operand:MODEF 0 "register_operand" "")
5677         (float:MODEF (match_operand:SI 1 "register_operand" "")))
5678    (clobber (match_operand:SI 2 "memory_operand" ""))]
5679   "TARGET_SSE2 && TARGET_SSE_MATH
5680    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)
5681    && reload_completed
5682    && (SSE_REG_P (operands[0])
5683        || (GET_CODE (operands[0]) == SUBREG
5684            && SSE_REG_P (operands[0])))"
5685   [(const_int 0)]
5686 {
5687   rtx op1 = operands[1];
5688
5689   operands[3] = simplify_gen_subreg (<ssevecmode>mode, operands[0],
5690                                      <MODE>mode, 0);
5691   if (GET_CODE (op1) == SUBREG)
5692     op1 = SUBREG_REG (op1);
5693
5694   if (GENERAL_REG_P (op1) && TARGET_INTER_UNIT_MOVES)
5695     {
5696       operands[4] = simplify_gen_subreg (V4SImode, operands[0], <MODE>mode, 0);
5697       emit_insn (gen_sse2_loadld (operands[4],
5698                                   CONST0_RTX (V4SImode), operands[1]));
5699     }
5700   /* We can ignore possible trapping value in the
5701      high part of SSE register for non-trapping math. */
5702   else if (SSE_REG_P (op1) && !flag_trapping_math)
5703     operands[4] = simplify_gen_subreg (V4SImode, operands[1], SImode, 0);
5704   else
5705     {
5706       operands[4] = simplify_gen_subreg (V4SImode, operands[0], <MODE>mode, 0);
5707       emit_move_insn (operands[2], operands[1]);
5708       emit_insn (gen_sse2_loadld (operands[4],
5709                                   CONST0_RTX (V4SImode), operands[2]));
5710     }
5711   emit_insn
5712     (gen_sse2_cvtdq2p<ssemodefsuffix> (operands[3], operands[4]));
5713   DONE;
5714 })
5715
5716 (define_split
5717   [(set (match_operand:MODEF 0 "register_operand" "")
5718         (float:MODEF (match_operand:SI 1 "memory_operand" "")))
5719    (clobber (match_operand:SI 2 "memory_operand" ""))]
5720   "TARGET_SSE2 && TARGET_SSE_MATH
5721    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)
5722    && reload_completed
5723    && (SSE_REG_P (operands[0])
5724        || (GET_CODE (operands[0]) == SUBREG
5725            && SSE_REG_P (operands[0])))"
5726   [(const_int 0)]
5727 {
5728   operands[3] = simplify_gen_subreg (<ssevecmode>mode, operands[0],
5729                                      <MODE>mode, 0);
5730   operands[4] = simplify_gen_subreg (V4SImode, operands[0], <MODE>mode, 0);
5731
5732   emit_insn (gen_sse2_loadld (operands[4],
5733                               CONST0_RTX (V4SImode), operands[1]));
5734   emit_insn
5735     (gen_sse2_cvtdq2p<ssemodefsuffix> (operands[3], operands[4]));
5736   DONE;
5737 })
5738
5739 (define_split
5740   [(set (match_operand:MODEF 0 "register_operand" "")
5741         (float:MODEF (match_operand:SI 1 "register_operand" "")))]
5742   "TARGET_SSE2 && TARGET_SSE_MATH
5743    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)
5744    && reload_completed
5745    && (SSE_REG_P (operands[0])
5746        || (GET_CODE (operands[0]) == SUBREG
5747            && SSE_REG_P (operands[0])))"
5748   [(const_int 0)]
5749 {
5750   rtx op1 = operands[1];
5751
5752   operands[3] = simplify_gen_subreg (<ssevecmode>mode, operands[0],
5753                                      <MODE>mode, 0);
5754   if (GET_CODE (op1) == SUBREG)
5755     op1 = SUBREG_REG (op1);
5756
5757   if (GENERAL_REG_P (op1) && TARGET_INTER_UNIT_MOVES)
5758     {
5759       operands[4] = simplify_gen_subreg (V4SImode, operands[0], <MODE>mode, 0);
5760       emit_insn (gen_sse2_loadld (operands[4],
5761                                   CONST0_RTX (V4SImode), operands[1]));
5762     }
5763   /* We can ignore possible trapping value in the
5764      high part of SSE register for non-trapping math. */
5765   else if (SSE_REG_P (op1) && !flag_trapping_math)
5766     operands[4] = simplify_gen_subreg (V4SImode, operands[1], SImode, 0);
5767   else
5768     gcc_unreachable ();
5769   emit_insn
5770     (gen_sse2_cvtdq2p<ssemodefsuffix> (operands[3], operands[4]));
5771   DONE;
5772 })
5773
5774 (define_split
5775   [(set (match_operand:MODEF 0 "register_operand" "")
5776         (float:MODEF (match_operand:SI 1 "memory_operand" "")))]
5777   "TARGET_SSE2 && TARGET_SSE_MATH
5778    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)
5779    && reload_completed
5780    && (SSE_REG_P (operands[0])
5781        || (GET_CODE (operands[0]) == SUBREG
5782            && SSE_REG_P (operands[0])))"
5783   [(const_int 0)]
5784 {
5785   operands[3] = simplify_gen_subreg (<ssevecmode>mode, operands[0],
5786                                      <MODE>mode, 0);
5787   operands[4] = simplify_gen_subreg (V4SImode, operands[0], <MODE>mode, 0);
5788
5789   emit_insn (gen_sse2_loadld (operands[4],
5790                               CONST0_RTX (V4SImode), operands[1]));
5791   emit_insn
5792     (gen_sse2_cvtdq2p<ssemodefsuffix> (operands[3], operands[4]));
5793   DONE;
5794 })
5795
5796 (define_insn "*float<SSEMODEI24:mode><MODEF:mode>2_sse_with_temp"
5797   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
5798         (float:MODEF
5799           (match_operand:SSEMODEI24 1 "nonimmediate_operand" "r,m")))
5800   (clobber (match_operand:SSEMODEI24 2 "memory_operand" "=m,X"))]
5801   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5802    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH"
5803   "#"
5804   [(set_attr "type" "sseicvt")
5805    (set_attr "mode" "<MODEF:MODE>")
5806    (set_attr "athlon_decode" "double,direct")
5807    (set_attr "amdfam10_decode" "vector,double")
5808    (set_attr "fp_int_src" "true")])
5809
5810 (define_insn "*float<SSEMODEI24:mode><MODEF:mode>2_sse_interunit"
5811   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
5812         (float:MODEF
5813           (match_operand:SSEMODEI24 1 "nonimmediate_operand" "r,m")))]
5814   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5815    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
5816    && (TARGET_INTER_UNIT_CONVERSIONS || optimize_function_for_size_p (cfun))"
5817   "%vcvtsi2s<MODEF:ssemodefsuffix><SSEMODEI24:rex64suffix>\t{%1, %d0|%d0, %1}"
5818   [(set_attr "type" "sseicvt")
5819    (set_attr "prefix" "maybe_vex")
5820    (set_attr "mode" "<MODEF:MODE>")
5821    (set (attr "prefix_rex")
5822      (if_then_else
5823        (and (eq_attr "prefix" "maybe_vex")
5824             (ne (symbol_ref "<SSEMODEI24:MODE>mode == DImode") (const_int 0)))
5825        (const_string "1")
5826        (const_string "*")))
5827    (set_attr "athlon_decode" "double,direct")
5828    (set_attr "amdfam10_decode" "vector,double")
5829    (set_attr "fp_int_src" "true")])
5830
5831 (define_split
5832   [(set (match_operand:MODEF 0 "register_operand" "")
5833         (float:MODEF (match_operand:SSEMODEI24 1 "nonimmediate_operand" "")))
5834    (clobber (match_operand:SSEMODEI24 2 "memory_operand" ""))]
5835   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5836    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
5837    && (TARGET_INTER_UNIT_CONVERSIONS || optimize_function_for_size_p (cfun))
5838    && reload_completed
5839    && (SSE_REG_P (operands[0])
5840        || (GET_CODE (operands[0]) == SUBREG
5841            && SSE_REG_P (operands[0])))"
5842   [(set (match_dup 0) (float:MODEF (match_dup 1)))]
5843   "")
5844
5845 (define_insn "*float<SSEMODEI24:mode><MODEF:mode>2_sse_nointerunit"
5846   [(set (match_operand:MODEF 0 "register_operand" "=x")
5847         (float:MODEF
5848           (match_operand:SSEMODEI24 1 "memory_operand" "m")))]
5849   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5850    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
5851    && !(TARGET_INTER_UNIT_CONVERSIONS || optimize_function_for_size_p (cfun))"
5852   "%vcvtsi2s<MODEF:ssemodefsuffix><SSEMODEI24:rex64suffix>\t{%1, %d0|%d0, %1}"
5853   [(set_attr "type" "sseicvt")
5854    (set_attr "prefix" "maybe_vex")
5855    (set_attr "mode" "<MODEF:MODE>")
5856    (set (attr "prefix_rex")
5857      (if_then_else
5858        (and (eq_attr "prefix" "maybe_vex")
5859             (ne (symbol_ref "<SSEMODEI24:MODE>mode == DImode") (const_int 0)))
5860        (const_string "1")
5861        (const_string "*")))
5862    (set_attr "athlon_decode" "direct")
5863    (set_attr "amdfam10_decode" "double")
5864    (set_attr "fp_int_src" "true")])
5865
5866 (define_split
5867   [(set (match_operand:MODEF 0 "register_operand" "")
5868         (float:MODEF (match_operand:SSEMODEI24 1 "register_operand" "")))
5869    (clobber (match_operand:SSEMODEI24 2 "memory_operand" ""))]
5870   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5871    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
5872    && !(TARGET_INTER_UNIT_CONVERSIONS || optimize_function_for_size_p (cfun))
5873    && reload_completed
5874    && (SSE_REG_P (operands[0])
5875        || (GET_CODE (operands[0]) == SUBREG
5876            && SSE_REG_P (operands[0])))"
5877   [(set (match_dup 2) (match_dup 1))
5878    (set (match_dup 0) (float:MODEF (match_dup 2)))]
5879   "")
5880
5881 (define_split
5882   [(set (match_operand:MODEF 0 "register_operand" "")
5883         (float:MODEF (match_operand:SSEMODEI24 1 "memory_operand" "")))
5884    (clobber (match_operand:SSEMODEI24 2 "memory_operand" ""))]
5885   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5886    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
5887    && reload_completed
5888    && (SSE_REG_P (operands[0])
5889        || (GET_CODE (operands[0]) == SUBREG
5890            && SSE_REG_P (operands[0])))"
5891   [(set (match_dup 0) (float:MODEF (match_dup 1)))]
5892   "")
5893
5894 (define_insn "*float<SSEMODEI24:mode><X87MODEF:mode>2_i387_with_temp"
5895   [(set (match_operand:X87MODEF 0 "register_operand" "=f,f")
5896         (float:X87MODEF
5897           (match_operand:SSEMODEI24 1 "nonimmediate_operand" "m,?r")))
5898   (clobber (match_operand:SSEMODEI24 2 "memory_operand" "=X,m"))]
5899   "TARGET_80387
5900    && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, <SSEMODEI24:MODE>mode)"
5901   "@
5902    fild%Z1\t%1
5903    #"
5904   [(set_attr "type" "fmov,multi")
5905    (set_attr "mode" "<X87MODEF:MODE>")
5906    (set_attr "unit" "*,i387")
5907    (set_attr "fp_int_src" "true")])
5908
5909 (define_insn "*float<SSEMODEI24:mode><X87MODEF:mode>2_i387"
5910   [(set (match_operand:X87MODEF 0 "register_operand" "=f")
5911         (float:X87MODEF
5912           (match_operand:SSEMODEI24 1 "memory_operand" "m")))]
5913   "TARGET_80387
5914    && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, <SSEMODEI24:MODE>mode)"
5915   "fild%Z1\t%1"
5916   [(set_attr "type" "fmov")
5917    (set_attr "mode" "<X87MODEF:MODE>")
5918    (set_attr "fp_int_src" "true")])
5919
5920 (define_split
5921   [(set (match_operand:X87MODEF 0 "register_operand" "")
5922         (float:X87MODEF (match_operand:SSEMODEI24 1 "register_operand" "")))
5923    (clobber (match_operand:SSEMODEI24 2 "memory_operand" ""))]
5924   "TARGET_80387
5925    && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, <SSEMODEI24:MODE>mode)
5926    && reload_completed
5927    && FP_REG_P (operands[0])"
5928   [(set (match_dup 2) (match_dup 1))
5929    (set (match_dup 0) (float:X87MODEF (match_dup 2)))]
5930   "")
5931
5932 (define_split
5933   [(set (match_operand:X87MODEF 0 "register_operand" "")
5934         (float:X87MODEF (match_operand:SSEMODEI24 1 "memory_operand" "")))
5935    (clobber (match_operand:SSEMODEI24 2 "memory_operand" ""))]
5936   "TARGET_80387
5937    && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, <SSEMODEI24:MODE>mode)
5938    && reload_completed
5939    && FP_REG_P (operands[0])"
5940   [(set (match_dup 0) (float:X87MODEF (match_dup 1)))]
5941   "")
5942
5943 ;; Avoid store forwarding (partial memory) stall penalty
5944 ;; by passing DImode value through XMM registers.  */
5945
5946 (define_insn "floatdi<X87MODEF:mode>2_i387_with_xmm"
5947   [(set (match_operand:X87MODEF 0 "register_operand" "=f,f")
5948         (float:X87MODEF
5949           (match_operand:DI 1 "nonimmediate_operand" "m,?r")))
5950    (clobber (match_scratch:V4SI 3 "=X,x"))
5951    (clobber (match_scratch:V4SI 4 "=X,x"))
5952    (clobber (match_operand:DI 2 "memory_operand" "=X,m"))]
5953   "TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5954    && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES
5955    && !TARGET_64BIT && optimize_function_for_speed_p (cfun)"
5956   "#"
5957   [(set_attr "type" "multi")
5958    (set_attr "mode" "<X87MODEF:MODE>")
5959    (set_attr "unit" "i387")
5960    (set_attr "fp_int_src" "true")])
5961
5962 (define_split
5963   [(set (match_operand:X87MODEF 0 "register_operand" "")
5964         (float:X87MODEF (match_operand:DI 1 "register_operand" "")))
5965    (clobber (match_scratch:V4SI 3 ""))
5966    (clobber (match_scratch:V4SI 4 ""))
5967    (clobber (match_operand:DI 2 "memory_operand" ""))]
5968   "TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5969    && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES
5970    && !TARGET_64BIT && optimize_function_for_speed_p (cfun)
5971    && reload_completed
5972    && FP_REG_P (operands[0])"
5973   [(set (match_dup 2) (match_dup 3))
5974    (set (match_dup 0) (float:X87MODEF (match_dup 2)))]
5975 {
5976   /* The DImode arrived in a pair of integral registers (e.g. %edx:%eax).
5977      Assemble the 64-bit DImode value in an xmm register.  */
5978   emit_insn (gen_sse2_loadld (operands[3], CONST0_RTX (V4SImode),
5979                               gen_rtx_SUBREG (SImode, operands[1], 0)));
5980   emit_insn (gen_sse2_loadld (operands[4], CONST0_RTX (V4SImode),
5981                               gen_rtx_SUBREG (SImode, operands[1], 4)));
5982   emit_insn (gen_sse2_punpckldq (operands[3], operands[3], operands[4]));
5983
5984   operands[3] = gen_rtx_REG (DImode, REGNO (operands[3]));
5985 })
5986
5987 (define_split
5988   [(set (match_operand:X87MODEF 0 "register_operand" "")
5989         (float:X87MODEF (match_operand:DI 1 "memory_operand" "")))
5990    (clobber (match_scratch:V4SI 3 ""))
5991    (clobber (match_scratch:V4SI 4 ""))
5992    (clobber (match_operand:DI 2 "memory_operand" ""))]
5993   "TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5994    && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES
5995    && !TARGET_64BIT && optimize_function_for_speed_p (cfun)
5996    && reload_completed
5997    && FP_REG_P (operands[0])"
5998   [(set (match_dup 0) (float:X87MODEF (match_dup 1)))]
5999   "")
6000
6001 ;; Avoid store forwarding (partial memory) stall penalty by extending
6002 ;; SImode value to DImode through XMM register instead of pushing two
6003 ;; SImode values to stack. Note that even !TARGET_INTER_UNIT_MOVES
6004 ;; targets benefit from this optimization. Also note that fild
6005 ;; loads from memory only.
6006
6007 (define_insn "*floatunssi<mode>2_1"
6008   [(set (match_operand:X87MODEF 0 "register_operand" "=f,f")
6009         (unsigned_float:X87MODEF
6010           (match_operand:SI 1 "nonimmediate_operand" "x,m")))
6011    (clobber (match_operand:DI 2 "memory_operand" "=m,m"))
6012    (clobber (match_scratch:SI 3 "=X,x"))]
6013   "!TARGET_64BIT
6014    && TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
6015    && TARGET_SSE"
6016   "#"
6017   [(set_attr "type" "multi")
6018    (set_attr "mode" "<MODE>")])
6019
6020 (define_split
6021   [(set (match_operand:X87MODEF 0 "register_operand" "")
6022         (unsigned_float:X87MODEF
6023           (match_operand:SI 1 "register_operand" "")))
6024    (clobber (match_operand:DI 2 "memory_operand" ""))
6025    (clobber (match_scratch:SI 3 ""))]
6026   "!TARGET_64BIT
6027    && TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
6028    && TARGET_SSE
6029    && reload_completed"
6030   [(set (match_dup 2) (match_dup 1))
6031    (set (match_dup 0)
6032         (float:X87MODEF (match_dup 2)))]
6033   "operands[1] = simplify_gen_subreg (DImode, operands[1], SImode, 0);")
6034
6035 (define_split
6036   [(set (match_operand:X87MODEF 0 "register_operand" "")
6037         (unsigned_float:X87MODEF
6038           (match_operand:SI 1 "memory_operand" "")))
6039    (clobber (match_operand:DI 2 "memory_operand" ""))
6040    (clobber (match_scratch:SI 3 ""))]
6041   "!TARGET_64BIT
6042    && TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
6043    && TARGET_SSE
6044    && reload_completed"
6045   [(set (match_dup 2) (match_dup 3))
6046    (set (match_dup 0)
6047         (float:X87MODEF (match_dup 2)))]
6048 {
6049   emit_move_insn (operands[3], operands[1]);
6050   operands[3] = simplify_gen_subreg (DImode, operands[3], SImode, 0);
6051 })
6052
6053 (define_expand "floatunssi<mode>2"
6054   [(parallel
6055      [(set (match_operand:X87MODEF 0 "register_operand" "")
6056            (unsigned_float:X87MODEF
6057              (match_operand:SI 1 "nonimmediate_operand" "")))
6058       (clobber (match_dup 2))
6059       (clobber (match_scratch:SI 3 ""))])]
6060   "!TARGET_64BIT
6061    && ((TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
6062         && TARGET_SSE)
6063        || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))"
6064 {
6065   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
6066     {
6067       ix86_expand_convert_uns_si<mode>_sse (operands[0], operands[1]);
6068       DONE;
6069     }
6070   else
6071     {
6072       enum ix86_stack_slot slot = (virtuals_instantiated
6073                                    ? SLOT_TEMP
6074                                    : SLOT_VIRTUAL);
6075       operands[2] = assign_386_stack_local (DImode, slot);
6076     }
6077 })
6078
6079 (define_expand "floatunsdisf2"
6080   [(use (match_operand:SF 0 "register_operand" ""))
6081    (use (match_operand:DI 1 "nonimmediate_operand" ""))]
6082   "TARGET_64BIT && TARGET_SSE_MATH"
6083   "x86_emit_floatuns (operands); DONE;")
6084
6085 (define_expand "floatunsdidf2"
6086   [(use (match_operand:DF 0 "register_operand" ""))
6087    (use (match_operand:DI 1 "nonimmediate_operand" ""))]
6088   "(TARGET_64BIT || TARGET_KEEPS_VECTOR_ALIGNED_STACK)
6089    && TARGET_SSE2 && TARGET_SSE_MATH"
6090 {
6091   if (TARGET_64BIT)
6092     x86_emit_floatuns (operands);
6093   else
6094     ix86_expand_convert_uns_didf_sse (operands[0], operands[1]);
6095   DONE;
6096 })
6097 \f
6098 ;; Add instructions
6099
6100 (define_expand "add<mode>3"
6101   [(set (match_operand:SDWIM 0 "nonimmediate_operand" "")
6102         (plus:SDWIM (match_operand:SDWIM 1 "nonimmediate_operand" "")
6103                     (match_operand:SDWIM 2 "<general_operand>" "")))]
6104   ""
6105   "ix86_expand_binary_operator (PLUS, <MODE>mode, operands); DONE;")
6106
6107 (define_insn_and_split "*add<dwi>3_doubleword"
6108   [(set (match_operand:<DWI> 0 "nonimmediate_operand" "=r,o")
6109         (plus:<DWI>
6110           (match_operand:<DWI> 1 "nonimmediate_operand" "%0,0")
6111           (match_operand:<DWI> 2 "<general_operand>" "ro<di>,r<di>")))
6112    (clobber (reg:CC FLAGS_REG))]
6113   "ix86_binary_operator_ok (PLUS, <DWI>mode, operands)"
6114   "#"
6115   "reload_completed"
6116   [(parallel [(set (reg:CC FLAGS_REG)
6117                    (unspec:CC [(match_dup 1) (match_dup 2)]
6118                               UNSPEC_ADD_CARRY))
6119               (set (match_dup 0)
6120                    (plus:DWIH (match_dup 1) (match_dup 2)))])
6121    (parallel [(set (match_dup 3)
6122                    (plus:DWIH
6123                      (plus:DWIH
6124                        (ltu:DWIH (reg:CC FLAGS_REG) (const_int 0))
6125                        (match_dup 4))
6126                      (match_dup 5)))
6127               (clobber (reg:CC FLAGS_REG))])]
6128   "split_<dwi> (&operands[0], 3, &operands[0], &operands[3]);")
6129
6130 (define_insn "add<mode>3_carry"
6131   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6132         (plus:SWI
6133           (plus:SWI (match_operand:SWI 3 "ix86_carry_flag_operator" "")
6134                     (match_operand:SWI 1 "nonimmediate_operand" "%0,0"))
6135           (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m")))
6136    (clobber (reg:CC FLAGS_REG))]
6137   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
6138   "adc{<imodesuffix>}\t{%2, %0|%0, %2}"
6139   [(set_attr "type" "alu")
6140    (set_attr "use_carry" "1")
6141    (set_attr "pent_pair" "pu")
6142    (set_attr "mode" "<MODE>")])
6143
6144 (define_insn "*addsi3_carry_zext"
6145   [(set (match_operand:DI 0 "register_operand" "=r")
6146         (zero_extend:DI
6147           (plus:SI
6148             (plus:SI (match_operand:SI 3 "ix86_carry_flag_operator" "")
6149                      (match_operand:SI 1 "nonimmediate_operand" "%0"))
6150           (match_operand:SI 2 "general_operand" "g"))))
6151    (clobber (reg:CC FLAGS_REG))]
6152   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, SImode, operands)"
6153   "adc{l}\t{%2, %k0|%k0, %2}"
6154   [(set_attr "type" "alu")
6155    (set_attr "use_carry" "1")
6156    (set_attr "pent_pair" "pu")
6157    (set_attr "mode" "SI")])
6158
6159 (define_insn "*add<mode>3_cc"
6160   [(set (reg:CC FLAGS_REG)
6161         (unspec:CC
6162           [(match_operand:SWI48 1 "nonimmediate_operand" "%0,0")
6163            (match_operand:SWI48 2 "<general_operand>" "r<i>,rm")]
6164           UNSPEC_ADD_CARRY))
6165    (set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,r")
6166         (plus:SWI48 (match_dup 1) (match_dup 2)))]
6167   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
6168   "add{<imodesuffix>}\t{%2, %0|%0, %2}"
6169   [(set_attr "type" "alu")
6170    (set_attr "mode" "<MODE>")])
6171
6172 (define_insn "addqi3_cc"
6173   [(set (reg:CC FLAGS_REG)
6174         (unspec:CC
6175           [(match_operand:QI 1 "nonimmediate_operand" "%0,0")
6176            (match_operand:QI 2 "general_operand" "qn,qm")]
6177           UNSPEC_ADD_CARRY))
6178    (set (match_operand:QI 0 "nonimmediate_operand" "=qm,q")
6179         (plus:QI (match_dup 1) (match_dup 2)))]
6180   "ix86_binary_operator_ok (PLUS, QImode, operands)"
6181   "add{b}\t{%2, %0|%0, %2}"
6182   [(set_attr "type" "alu")
6183    (set_attr "mode" "QI")])
6184
6185 (define_insn "*add<mode>3_cconly_overflow"
6186   [(set (reg:CCC FLAGS_REG)
6187         (compare:CCC
6188           (plus:SWI
6189             (match_operand:SWI 1 "nonimmediate_operand" "%0")
6190             (match_operand:SWI 2 "<general_operand>" "<r><i>m"))
6191           (match_dup 1)))
6192    (clobber (match_scratch:SWI 0 "=<r>"))]
6193   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
6194   "add{<imodesuffix>}\t{%2, %0|%0, %2}"
6195   [(set_attr "type" "alu")
6196    (set_attr "mode" "<MODE>")])
6197
6198 (define_insn "*lea_1"
6199   [(set (match_operand:DWIH 0 "register_operand" "=r")
6200         (match_operand:DWIH 1 "no_seg_address_operand" "p"))]
6201   ""
6202   "lea{<imodesuffix>}\t{%a1, %0|%0, %a1}"
6203   [(set_attr "type" "lea")
6204    (set_attr "mode" "<MODE>")])
6205
6206 (define_insn "*lea_2"
6207   [(set (match_operand:SI 0 "register_operand" "=r")
6208         (subreg:SI (match_operand:DI 1 "no_seg_address_operand" "p") 0))]
6209   "TARGET_64BIT"
6210   "lea{l}\t{%a1, %0|%0, %a1}"
6211   [(set_attr "type" "lea")
6212    (set_attr "mode" "SI")])
6213
6214 (define_insn "*lea_2_zext"
6215   [(set (match_operand:DI 0 "register_operand" "=r")
6216         (zero_extend:DI
6217           (subreg:SI (match_operand:DI 1 "no_seg_address_operand" "p") 0)))]
6218   "TARGET_64BIT"
6219   "lea{l}\t{%a1, %k0|%k0, %a1}"
6220   [(set_attr "type" "lea")
6221    (set_attr "mode" "SI")])
6222
6223 (define_insn "*add<mode>_1"
6224   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=r,rm,r,r")
6225         (plus:SWI48
6226           (match_operand:SWI48 1 "nonimmediate_operand" "%0,0,r,r")
6227           (match_operand:SWI48 2 "<general_operand>" "<g>,r<i>,0,l<i>")))
6228    (clobber (reg:CC FLAGS_REG))]
6229   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
6230 {
6231   switch (get_attr_type (insn))
6232     {
6233     case TYPE_LEA:
6234       operands[2] = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
6235       return "lea{<imodesuffix>}\t{%a2, %0|%0, %a2}";
6236
6237     case TYPE_INCDEC:
6238       gcc_assert (rtx_equal_p (operands[0], operands[1]));
6239       if (operands[2] == const1_rtx)
6240         return "inc{<imodesuffix>}\t%0";
6241       else
6242         {
6243           gcc_assert (operands[2] == constm1_rtx);
6244           return "dec{<imodesuffix>}\t%0";
6245         }
6246
6247     default:
6248       /* Use add as much as possible to replace lea for AGU optimization. */
6249       if (which_alternative == 2 && TARGET_OPT_AGU)
6250         return "add{<imodesuffix>}\t{%1, %0|%0, %1}";
6251         
6252       gcc_assert (rtx_equal_p (operands[0], operands[1]));
6253
6254       /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
6255          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6256       if (CONST_INT_P (operands[2])
6257           /* Avoid overflows.  */
6258           && (<MODE>mode != DImode
6259               || ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
6260           && (INTVAL (operands[2]) == 128
6261               || (INTVAL (operands[2]) < 0
6262                   && INTVAL (operands[2]) != -128)))
6263         {
6264           operands[2] = GEN_INT (-INTVAL (operands[2]));
6265           return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
6266         }
6267       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
6268     }
6269 }
6270   [(set (attr "type")
6271      (cond [(and (eq_attr "alternative" "2") 
6272                  (eq (symbol_ref "TARGET_OPT_AGU") (const_int 0)))
6273               (const_string "lea")
6274             (eq_attr "alternative" "3")
6275               (const_string "lea")
6276             ; Current assemblers are broken and do not allow @GOTOFF in
6277             ; ought but a memory context.
6278             (match_operand:SWI48 2 "pic_symbolic_operand" "")
6279               (const_string "lea")
6280             (match_operand:SWI48 2 "incdec_operand" "")
6281               (const_string "incdec")
6282            ]
6283            (const_string "alu")))
6284    (set (attr "length_immediate")
6285       (if_then_else
6286         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6287         (const_string "1")
6288         (const_string "*")))
6289    (set_attr "mode" "<MODE>")])
6290
6291 ;; It may seem that nonimmediate operand is proper one for operand 1.
6292 ;; The addsi_1 pattern allows nonimmediate operand at that place and
6293 ;; we take care in ix86_binary_operator_ok to not allow two memory
6294 ;; operands so proper swapping will be done in reload.  This allow
6295 ;; patterns constructed from addsi_1 to match.
6296
6297 (define_insn "*addsi_1_zext"
6298   [(set (match_operand:DI 0 "register_operand" "=r,r")
6299         (zero_extend:DI
6300           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0,r")
6301                    (match_operand:SI 2 "general_operand" "g,li"))))
6302    (clobber (reg:CC FLAGS_REG))]
6303   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, SImode, operands)"
6304 {
6305   switch (get_attr_type (insn))
6306     {
6307     case TYPE_LEA:
6308       operands[2] = XEXP (SET_SRC (XVECEXP (PATTERN (insn), 0, 0)), 0);
6309       return "lea{l}\t{%a2, %k0|%k0, %a2}";
6310
6311     case TYPE_INCDEC:
6312       if (operands[2] == const1_rtx)
6313         return "inc{l}\t%k0";
6314       else
6315         {
6316           gcc_assert (operands[2] == constm1_rtx);
6317           return "dec{l}\t%k0";
6318         }
6319
6320     default:
6321       /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
6322          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6323       if (CONST_INT_P (operands[2])
6324           && (INTVAL (operands[2]) == 128
6325               || (INTVAL (operands[2]) < 0
6326                   && INTVAL (operands[2]) != -128)))
6327         {
6328           operands[2] = GEN_INT (-INTVAL (operands[2]));
6329           return "sub{l}\t{%2, %k0|%k0, %2}";
6330         }
6331       return "add{l}\t{%2, %k0|%k0, %2}";
6332     }
6333 }
6334   [(set (attr "type")
6335      (cond [(eq_attr "alternative" "1")
6336               (const_string "lea")
6337             ; Current assemblers are broken and do not allow @GOTOFF in
6338             ; ought but a memory context.
6339             (match_operand:SI 2 "pic_symbolic_operand" "")
6340               (const_string "lea")
6341             (match_operand:SI 2 "incdec_operand" "")
6342               (const_string "incdec")
6343            ]
6344            (const_string "alu")))
6345    (set (attr "length_immediate")
6346       (if_then_else
6347         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6348         (const_string "1")
6349         (const_string "*")))
6350    (set_attr "mode" "SI")])
6351
6352 (define_insn "*addhi_1"
6353   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
6354         (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
6355                  (match_operand:HI 2 "general_operand" "rn,rm")))
6356    (clobber (reg:CC FLAGS_REG))]
6357   "TARGET_PARTIAL_REG_STALL
6358    && ix86_binary_operator_ok (PLUS, HImode, operands)"
6359 {
6360   switch (get_attr_type (insn))
6361     {
6362     case TYPE_INCDEC:
6363       if (operands[2] == const1_rtx)
6364         return "inc{w}\t%0";
6365       else
6366         {
6367           gcc_assert (operands[2] == constm1_rtx);
6368           return "dec{w}\t%0";
6369         }
6370
6371     default:
6372       /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
6373          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6374       if (CONST_INT_P (operands[2])
6375           && (INTVAL (operands[2]) == 128
6376               || (INTVAL (operands[2]) < 0
6377                   && INTVAL (operands[2]) != -128)))
6378         {
6379           operands[2] = GEN_INT (-INTVAL (operands[2]));
6380           return "sub{w}\t{%2, %0|%0, %2}";
6381         }
6382       return "add{w}\t{%2, %0|%0, %2}";
6383     }
6384 }
6385   [(set (attr "type")
6386      (if_then_else (match_operand:HI 2 "incdec_operand" "")
6387         (const_string "incdec")
6388         (const_string "alu")))
6389    (set (attr "length_immediate")
6390       (if_then_else
6391         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6392         (const_string "1")
6393         (const_string "*")))
6394    (set_attr "mode" "HI")])
6395
6396 ;; %%% After Dave's SUBREG_BYTE stuff goes in, re-enable incb %ah
6397 ;; type optimizations enabled by define-splits.  This is not important
6398 ;; for PII, and in fact harmful because of partial register stalls.
6399
6400 (define_insn "*addhi_1_lea"
6401   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r,r")
6402         (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,r")
6403                  (match_operand:HI 2 "general_operand" "rn,rm,ln")))
6404    (clobber (reg:CC FLAGS_REG))]
6405   "!TARGET_PARTIAL_REG_STALL
6406    && ix86_binary_operator_ok (PLUS, HImode, operands)"
6407 {
6408   switch (get_attr_type (insn))
6409     {
6410     case TYPE_LEA:
6411       return "#";
6412     case TYPE_INCDEC:
6413       if (operands[2] == const1_rtx)
6414         return "inc{w}\t%0";
6415       else
6416         {
6417           gcc_assert (operands[2] == constm1_rtx);
6418           return "dec{w}\t%0";
6419         }
6420
6421     default:
6422       /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
6423          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6424       if (CONST_INT_P (operands[2])
6425           && (INTVAL (operands[2]) == 128
6426               || (INTVAL (operands[2]) < 0
6427                   && INTVAL (operands[2]) != -128)))
6428         {
6429           operands[2] = GEN_INT (-INTVAL (operands[2]));
6430           return "sub{w}\t{%2, %0|%0, %2}";
6431         }
6432       return "add{w}\t{%2, %0|%0, %2}";
6433     }
6434 }
6435   [(set (attr "type")
6436      (if_then_else (eq_attr "alternative" "2")
6437         (const_string "lea")
6438         (if_then_else (match_operand:HI 2 "incdec_operand" "")
6439            (const_string "incdec")
6440            (const_string "alu"))))
6441    (set (attr "length_immediate")
6442       (if_then_else
6443         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6444         (const_string "1")
6445         (const_string "*")))
6446    (set_attr "mode" "HI,HI,SI")])
6447
6448 (define_insn "*addqi_1"
6449   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q,r")
6450         (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
6451                  (match_operand:QI 2 "general_operand" "qn,qmn,rn")))
6452    (clobber (reg:CC FLAGS_REG))]
6453   "TARGET_PARTIAL_REG_STALL
6454    && ix86_binary_operator_ok (PLUS, QImode, operands)"
6455 {
6456   int widen = (which_alternative == 2);
6457   switch (get_attr_type (insn))
6458     {
6459     case TYPE_INCDEC:
6460       if (operands[2] == const1_rtx)
6461         return widen ? "inc{l}\t%k0" : "inc{b}\t%0";
6462       else
6463         {
6464           gcc_assert (operands[2] == constm1_rtx);
6465           return widen ? "dec{l}\t%k0" : "dec{b}\t%0";
6466         }
6467
6468     default:
6469       /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.
6470          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6471       if (CONST_INT_P (operands[2])
6472           && (INTVAL (operands[2]) == 128
6473               || (INTVAL (operands[2]) < 0
6474                   && INTVAL (operands[2]) != -128)))
6475         {
6476           operands[2] = GEN_INT (-INTVAL (operands[2]));
6477           if (widen)
6478             return "sub{l}\t{%2, %k0|%k0, %2}";
6479           else
6480             return "sub{b}\t{%2, %0|%0, %2}";
6481         }
6482       if (widen)
6483         return "add{l}\t{%k2, %k0|%k0, %k2}";
6484       else
6485         return "add{b}\t{%2, %0|%0, %2}";
6486     }
6487 }
6488   [(set (attr "type")
6489      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6490         (const_string "incdec")
6491         (const_string "alu")))
6492    (set (attr "length_immediate")
6493       (if_then_else
6494         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6495         (const_string "1")
6496         (const_string "*")))
6497    (set_attr "mode" "QI,QI,SI")])
6498
6499 ;; %%% Potential partial reg stall on alternative 2.  What to do?
6500 (define_insn "*addqi_1_lea"
6501   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q,r,r")
6502         (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0,r")
6503                  (match_operand:QI 2 "general_operand" "qn,qmn,rn,ln")))
6504    (clobber (reg:CC FLAGS_REG))]
6505   "!TARGET_PARTIAL_REG_STALL
6506    && ix86_binary_operator_ok (PLUS, QImode, operands)"
6507 {
6508   int widen = (which_alternative == 2);
6509   switch (get_attr_type (insn))
6510     {
6511     case TYPE_LEA:
6512       return "#";
6513     case TYPE_INCDEC:
6514       if (operands[2] == const1_rtx)
6515         return widen ? "inc{l}\t%k0" : "inc{b}\t%0";
6516       else
6517         {
6518           gcc_assert (operands[2] == constm1_rtx);
6519           return widen ? "dec{l}\t%k0" : "dec{b}\t%0";
6520         }
6521
6522     default:
6523       /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.
6524          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6525       if (CONST_INT_P (operands[2])
6526           && (INTVAL (operands[2]) == 128
6527               || (INTVAL (operands[2]) < 0
6528                   && INTVAL (operands[2]) != -128)))
6529         {
6530           operands[2] = GEN_INT (-INTVAL (operands[2]));
6531           if (widen)
6532             return "sub{l}\t{%2, %k0|%k0, %2}";
6533           else
6534             return "sub{b}\t{%2, %0|%0, %2}";
6535         }
6536       if (widen)
6537         return "add{l}\t{%k2, %k0|%k0, %k2}";
6538       else
6539         return "add{b}\t{%2, %0|%0, %2}";
6540     }
6541 }
6542   [(set (attr "type")
6543      (if_then_else (eq_attr "alternative" "3")
6544         (const_string "lea")
6545         (if_then_else (match_operand:QI 2 "incdec_operand" "")
6546            (const_string "incdec")
6547            (const_string "alu"))))
6548    (set (attr "length_immediate")
6549       (if_then_else
6550         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6551         (const_string "1")
6552         (const_string "*")))
6553    (set_attr "mode" "QI,QI,SI,SI")])
6554
6555 (define_insn "*addqi_1_slp"
6556   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
6557         (plus:QI (match_dup 0)
6558                  (match_operand:QI 1 "general_operand" "qn,qnm")))
6559    (clobber (reg:CC FLAGS_REG))]
6560   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
6561    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
6562 {
6563   switch (get_attr_type (insn))
6564     {
6565     case TYPE_INCDEC:
6566       if (operands[1] == const1_rtx)
6567         return "inc{b}\t%0";
6568       else
6569         {
6570           gcc_assert (operands[1] == constm1_rtx);
6571           return "dec{b}\t%0";
6572         }
6573
6574     default:
6575       /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.  */
6576       if (CONST_INT_P (operands[1])
6577           && INTVAL (operands[1]) < 0)
6578         {
6579           operands[1] = GEN_INT (-INTVAL (operands[1]));
6580           return "sub{b}\t{%1, %0|%0, %1}";
6581         }
6582       return "add{b}\t{%1, %0|%0, %1}";
6583     }
6584 }
6585   [(set (attr "type")
6586      (if_then_else (match_operand:QI 1 "incdec_operand" "")
6587         (const_string "incdec")
6588         (const_string "alu1")))
6589    (set (attr "memory")
6590      (if_then_else (match_operand 1 "memory_operand" "")
6591         (const_string "load")
6592         (const_string "none")))
6593    (set_attr "mode" "QI")])
6594
6595 (define_insn "*add<mode>_2"
6596   [(set (reg FLAGS_REG)
6597         (compare
6598           (plus:SWI48
6599             (match_operand:SWI48 1 "nonimmediate_operand" "%0,0")
6600             (match_operand:SWI48 2 "<general_operand>" "<g>,r<i>"))
6601           (const_int 0)))
6602    (set (match_operand:SWI48 0 "nonimmediate_operand" "=r,rm")
6603         (plus:SWI48 (match_dup 1) (match_dup 2)))]
6604   "ix86_match_ccmode (insn, CCGOCmode)
6605    && ix86_binary_operator_ok (PLUS, <MODE>mode, operands)
6606    /* Current assemblers are broken and do not allow @GOTOFF in
6607       ought but a memory context.  */
6608    && ! pic_symbolic_operand (operands[2], VOIDmode)"
6609 {
6610   switch (get_attr_type (insn))
6611     {
6612     case TYPE_INCDEC:
6613       gcc_assert (rtx_equal_p (operands[0], operands[1]));
6614       if (operands[2] == const1_rtx)
6615         return "inc{<imodesuffix>}\t%0";
6616       else
6617         {
6618           gcc_assert (operands[2] == constm1_rtx);
6619           return "dec{<imodesuffix>}\t%0";
6620         }
6621
6622     default:
6623       gcc_assert (rtx_equal_p (operands[0], operands[1]));
6624       /* ???? In DImode, we ought to handle there the 32bit case too
6625          - do we need new constraint?  */
6626       /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
6627          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6628       if (CONST_INT_P (operands[2])
6629           /* Avoid overflows.  */
6630           && (<MODE>mode != DImode
6631               || ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
6632           && (INTVAL (operands[2]) == 128
6633               || (INTVAL (operands[2]) < 0
6634                   && INTVAL (operands[2]) != -128)))
6635         {
6636           operands[2] = GEN_INT (-INTVAL (operands[2]));
6637           return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
6638         }
6639       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
6640     }
6641 }
6642   [(set (attr "type")
6643      (if_then_else (match_operand:SWI48 2 "incdec_operand" "")
6644         (const_string "incdec")
6645         (const_string "alu")))
6646    (set (attr "length_immediate")
6647       (if_then_else
6648         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6649         (const_string "1")
6650         (const_string "*")))
6651    (set_attr "mode" "<MODE>")])
6652
6653 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
6654 (define_insn "*addsi_2_zext"
6655   [(set (reg FLAGS_REG)
6656         (compare
6657           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
6658                    (match_operand:SI 2 "general_operand" "g"))
6659           (const_int 0)))
6660    (set (match_operand:DI 0 "register_operand" "=r")
6661         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))]
6662   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
6663    && ix86_binary_operator_ok (PLUS, SImode, operands)
6664    /* Current assemblers are broken and do not allow @GOTOFF in
6665       ought but a memory context.  */
6666    && ! pic_symbolic_operand (operands[2], VOIDmode)"
6667 {
6668   switch (get_attr_type (insn))
6669     {
6670     case TYPE_INCDEC:
6671       if (operands[2] == const1_rtx)
6672         return "inc{l}\t%k0";
6673       else
6674         {
6675           gcc_assert (operands[2] == constm1_rtx);
6676           return "dec{l}\t%k0";
6677         }
6678
6679     default:
6680       /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
6681          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6682       if (CONST_INT_P (operands[2])
6683           && (INTVAL (operands[2]) == 128
6684               || (INTVAL (operands[2]) < 0
6685                   && INTVAL (operands[2]) != -128)))
6686         {
6687           operands[2] = GEN_INT (-INTVAL (operands[2]));
6688           return "sub{l}\t{%2, %k0|%k0, %2}";
6689         }
6690       return "add{l}\t{%2, %k0|%k0, %2}";
6691     }
6692 }
6693   [(set (attr "type")
6694      (if_then_else (match_operand:SI 2 "incdec_operand" "")
6695         (const_string "incdec")
6696         (const_string "alu")))
6697    (set (attr "length_immediate")
6698       (if_then_else
6699         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6700         (const_string "1")
6701         (const_string "*")))
6702    (set_attr "mode" "SI")])
6703
6704 (define_insn "*addhi_2"
6705   [(set (reg FLAGS_REG)
6706         (compare
6707           (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
6708                    (match_operand:HI 2 "general_operand" "rmn,rn"))
6709           (const_int 0)))
6710    (set (match_operand:HI 0 "nonimmediate_operand" "=r,rm")
6711         (plus:HI (match_dup 1) (match_dup 2)))]
6712   "ix86_match_ccmode (insn, CCGOCmode)
6713    && ix86_binary_operator_ok (PLUS, HImode, operands)"
6714 {
6715   switch (get_attr_type (insn))
6716     {
6717     case TYPE_INCDEC:
6718       if (operands[2] == const1_rtx)
6719         return "inc{w}\t%0";
6720       else
6721         {
6722           gcc_assert (operands[2] == constm1_rtx);
6723           return "dec{w}\t%0";
6724         }
6725
6726     default:
6727       /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
6728          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6729       if (CONST_INT_P (operands[2])
6730           && (INTVAL (operands[2]) == 128
6731               || (INTVAL (operands[2]) < 0
6732                   && INTVAL (operands[2]) != -128)))
6733         {
6734           operands[2] = GEN_INT (-INTVAL (operands[2]));
6735           return "sub{w}\t{%2, %0|%0, %2}";
6736         }
6737       return "add{w}\t{%2, %0|%0, %2}";
6738     }
6739 }
6740   [(set (attr "type")
6741      (if_then_else (match_operand:HI 2 "incdec_operand" "")
6742         (const_string "incdec")
6743         (const_string "alu")))
6744    (set (attr "length_immediate")
6745       (if_then_else
6746         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6747         (const_string "1")
6748         (const_string "*")))
6749    (set_attr "mode" "HI")])
6750
6751 (define_insn "*addqi_2"
6752   [(set (reg FLAGS_REG)
6753         (compare
6754           (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0")
6755                    (match_operand:QI 2 "general_operand" "qmn,qn"))
6756           (const_int 0)))
6757    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm")
6758         (plus:QI (match_dup 1) (match_dup 2)))]
6759   "ix86_match_ccmode (insn, CCGOCmode)
6760    && ix86_binary_operator_ok (PLUS, QImode, operands)"
6761 {
6762   switch (get_attr_type (insn))
6763     {
6764     case TYPE_INCDEC:
6765       if (operands[2] == const1_rtx)
6766         return "inc{b}\t%0";
6767       else
6768         {
6769           gcc_assert (operands[2] == constm1_rtx
6770                       || (CONST_INT_P (operands[2])
6771                           && INTVAL (operands[2]) == 255));
6772           return "dec{b}\t%0";
6773         }
6774
6775     default:
6776       /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.  */
6777       if (CONST_INT_P (operands[2])
6778           && INTVAL (operands[2]) < 0)
6779         {
6780           operands[2] = GEN_INT (-INTVAL (operands[2]));
6781           return "sub{b}\t{%2, %0|%0, %2}";
6782         }
6783       return "add{b}\t{%2, %0|%0, %2}";
6784     }
6785 }
6786   [(set (attr "type")
6787      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6788         (const_string "incdec")
6789         (const_string "alu")))
6790    (set_attr "mode" "QI")])
6791
6792 (define_insn "*add<mode>_3"
6793   [(set (reg FLAGS_REG)
6794         (compare
6795           (neg:SWI48 (match_operand:SWI48 2 "<general_operand>" "<g>"))
6796           (match_operand:SWI48 1 "nonimmediate_operand" "%0")))
6797    (clobber (match_scratch:SWI48 0 "=r"))]
6798   "ix86_match_ccmode (insn, CCZmode)
6799    && !(MEM_P (operands[1]) && MEM_P (operands[2]))
6800    /* Current assemblers are broken and do not allow @GOTOFF in
6801       ought but a memory context.  */
6802    && ! pic_symbolic_operand (operands[2], VOIDmode)"
6803 {
6804   switch (get_attr_type (insn))
6805     {
6806     case TYPE_INCDEC:
6807       gcc_assert (rtx_equal_p (operands[0], operands[1]));
6808       if (operands[2] == const1_rtx)
6809         return "inc{<imodesuffix>}\t%0";
6810       else
6811         {
6812           gcc_assert (operands[2] == constm1_rtx);
6813           return "dec{<imodesuffix>}\t%0";
6814         }
6815
6816     default:
6817       gcc_assert (rtx_equal_p (operands[0], operands[1]));
6818       /* ???? In DImode, we ought to handle there the 32bit case too
6819          - do we need new constraint?  */
6820       /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
6821          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6822       if (CONST_INT_P (operands[2])
6823           /* Avoid overflows.  */
6824           && (<MODE>mode != DImode
6825               || ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
6826           && (INTVAL (operands[2]) == 128
6827               || (INTVAL (operands[2]) < 0
6828                   && INTVAL (operands[2]) != -128)))
6829         {
6830           operands[2] = GEN_INT (-INTVAL (operands[2]));
6831           return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
6832         }
6833       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
6834     }
6835 }
6836   [(set (attr "type")
6837      (if_then_else (match_operand:SWI48 2 "incdec_operand" "")
6838         (const_string "incdec")
6839         (const_string "alu")))
6840    (set (attr "length_immediate")
6841       (if_then_else
6842         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6843         (const_string "1")
6844         (const_string "*")))
6845    (set_attr "mode" "<MODE>")])
6846
6847 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
6848 (define_insn "*addsi_3_zext"
6849   [(set (reg FLAGS_REG)
6850         (compare
6851           (neg:SI (match_operand:SI 2 "general_operand" "g"))
6852           (match_operand:SI 1 "nonimmediate_operand" "%0")))
6853    (set (match_operand:DI 0 "register_operand" "=r")
6854         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))]
6855   "TARGET_64BIT && ix86_match_ccmode (insn, CCZmode)
6856    && ix86_binary_operator_ok (PLUS, SImode, operands)
6857    /* Current assemblers are broken and do not allow @GOTOFF in
6858       ought but a memory context.  */
6859    && ! pic_symbolic_operand (operands[2], VOIDmode)"
6860 {
6861   switch (get_attr_type (insn))
6862     {
6863     case TYPE_INCDEC:
6864       if (operands[2] == const1_rtx)
6865         return "inc{l}\t%k0";
6866       else
6867         {
6868           gcc_assert (operands[2] == constm1_rtx);
6869           return "dec{l}\t%k0";
6870         }
6871
6872     default:
6873       /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
6874          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6875       if (CONST_INT_P (operands[2])
6876           && (INTVAL (operands[2]) == 128
6877               || (INTVAL (operands[2]) < 0
6878                   && INTVAL (operands[2]) != -128)))
6879         {
6880           operands[2] = GEN_INT (-INTVAL (operands[2]));
6881           return "sub{l}\t{%2, %k0|%k0, %2}";
6882         }
6883       return "add{l}\t{%2, %k0|%k0, %2}";
6884     }
6885 }
6886   [(set (attr "type")
6887      (if_then_else (match_operand:SI 2 "incdec_operand" "")
6888         (const_string "incdec")
6889         (const_string "alu")))
6890    (set (attr "length_immediate")
6891       (if_then_else
6892         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6893         (const_string "1")
6894         (const_string "*")))
6895    (set_attr "mode" "SI")])
6896
6897 (define_insn "*addhi_3"
6898   [(set (reg FLAGS_REG)
6899         (compare
6900           (neg:HI (match_operand:HI 2 "general_operand" "rmn"))
6901           (match_operand:HI 1 "nonimmediate_operand" "%0")))
6902    (clobber (match_scratch:HI 0 "=r"))]
6903   "ix86_match_ccmode (insn, CCZmode)
6904    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6905 {
6906   switch (get_attr_type (insn))
6907     {
6908     case TYPE_INCDEC:
6909       if (operands[2] == const1_rtx)
6910         return "inc{w}\t%0";
6911       else
6912         {
6913           gcc_assert (operands[2] == constm1_rtx);
6914           return "dec{w}\t%0";
6915         }
6916
6917     default:
6918       /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
6919          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
6920       if (CONST_INT_P (operands[2])
6921           && (INTVAL (operands[2]) == 128
6922               || (INTVAL (operands[2]) < 0
6923                   && INTVAL (operands[2]) != -128)))
6924         {
6925           operands[2] = GEN_INT (-INTVAL (operands[2]));
6926           return "sub{w}\t{%2, %0|%0, %2}";
6927         }
6928       return "add{w}\t{%2, %0|%0, %2}";
6929     }
6930 }
6931   [(set (attr "type")
6932      (if_then_else (match_operand:HI 2 "incdec_operand" "")
6933         (const_string "incdec")
6934         (const_string "alu")))
6935    (set (attr "length_immediate")
6936       (if_then_else
6937         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6938         (const_string "1")
6939         (const_string "*")))
6940    (set_attr "mode" "HI")])
6941
6942 (define_insn "*addqi_3"
6943   [(set (reg FLAGS_REG)
6944         (compare
6945           (neg:QI (match_operand:QI 2 "general_operand" "qmn"))
6946           (match_operand:QI 1 "nonimmediate_operand" "%0")))
6947    (clobber (match_scratch:QI 0 "=q"))]
6948   "ix86_match_ccmode (insn, CCZmode)
6949    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6950 {
6951   switch (get_attr_type (insn))
6952     {
6953     case TYPE_INCDEC:
6954       if (operands[2] == const1_rtx)
6955         return "inc{b}\t%0";
6956       else
6957         {
6958           gcc_assert (operands[2] == constm1_rtx
6959                       || (CONST_INT_P (operands[2])
6960                           && INTVAL (operands[2]) == 255));
6961           return "dec{b}\t%0";
6962         }
6963
6964     default:
6965       /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.  */
6966       if (CONST_INT_P (operands[2])
6967           && INTVAL (operands[2]) < 0)
6968         {
6969           operands[2] = GEN_INT (-INTVAL (operands[2]));
6970           return "sub{b}\t{%2, %0|%0, %2}";
6971         }
6972       return "add{b}\t{%2, %0|%0, %2}";
6973     }
6974 }
6975   [(set (attr "type")
6976      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6977         (const_string "incdec")
6978         (const_string "alu")))
6979    (set_attr "mode" "QI")])
6980
6981 ; For comparisons against 1, -1 and 128, we may generate better code
6982 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
6983 ; is matched then.  We can't accept general immediate, because for
6984 ; case of overflows,  the result is messed up.
6985 ; This pattern also don't hold of 0x8000000000000000, since the value
6986 ; overflows when negated.
6987 ; Also carry flag is reversed compared to cmp, so this conversion is valid
6988 ; only for comparisons not depending on it.
6989
6990 (define_insn "*adddi_4"
6991   [(set (reg FLAGS_REG)
6992         (compare
6993           (match_operand:DI 1 "nonimmediate_operand" "0")
6994           (match_operand:DI 2 "x86_64_immediate_operand" "e")))
6995    (clobber (match_scratch:DI 0 "=rm"))]
6996   "TARGET_64BIT
6997    && ix86_match_ccmode (insn, CCGCmode)"
6998 {
6999   switch (get_attr_type (insn))
7000     {
7001     case TYPE_INCDEC:
7002       if (operands[2] == constm1_rtx)
7003         return "inc{q}\t%0";
7004       else
7005         {
7006           gcc_assert (operands[2] == const1_rtx);
7007           return "dec{q}\t%0";
7008         }
7009
7010     default:
7011       gcc_assert (rtx_equal_p (operands[0], operands[1]));
7012       /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
7013          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
7014       if ((INTVAL (operands[2]) == -128
7015            || (INTVAL (operands[2]) > 0
7016                && INTVAL (operands[2]) != 128))
7017           /* Avoid overflows.  */
7018           && ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
7019         return "sub{q}\t{%2, %0|%0, %2}";
7020       operands[2] = GEN_INT (-INTVAL (operands[2]));
7021       return "add{q}\t{%2, %0|%0, %2}";
7022     }
7023 }
7024   [(set (attr "type")
7025      (if_then_else (match_operand:DI 2 "incdec_operand" "")
7026         (const_string "incdec")
7027         (const_string "alu")))
7028    (set (attr "length_immediate")
7029       (if_then_else
7030         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
7031         (const_string "1")
7032         (const_string "*")))
7033    (set_attr "mode" "DI")])
7034
7035 ; For comparisons against 1, -1 and 128, we may generate better code
7036 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
7037 ; is matched then.  We can't accept general immediate, because for
7038 ; case of overflows,  the result is messed up.
7039 ; This pattern also don't hold of 0x80000000, since the value overflows
7040 ; when negated.
7041 ; Also carry flag is reversed compared to cmp, so this conversion is valid
7042 ; only for comparisons not depending on it.
7043
7044 (define_insn "*addsi_4"
7045   [(set (reg FLAGS_REG)
7046         (compare
7047           (match_operand:SI 1 "nonimmediate_operand" "0")
7048           (match_operand:SI 2 "const_int_operand" "n")))
7049    (clobber (match_scratch:SI 0 "=rm"))]
7050   "ix86_match_ccmode (insn, CCGCmode)
7051    && (INTVAL (operands[2]) & 0xffffffff) != 0x80000000"
7052 {
7053   switch (get_attr_type (insn))
7054     {
7055     case TYPE_INCDEC:
7056       if (operands[2] == constm1_rtx)
7057         return "inc{l}\t%0";
7058       else
7059         {
7060           gcc_assert (operands[2] == const1_rtx);
7061           return "dec{l}\t%0";
7062         }
7063
7064     default:
7065       gcc_assert (rtx_equal_p (operands[0], operands[1]));
7066       /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
7067          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
7068       if ((INTVAL (operands[2]) == -128
7069            || (INTVAL (operands[2]) > 0
7070                && INTVAL (operands[2]) != 128)))
7071         return "sub{l}\t{%2, %0|%0, %2}";
7072       operands[2] = GEN_INT (-INTVAL (operands[2]));
7073       return "add{l}\t{%2, %0|%0, %2}";
7074     }
7075 }
7076   [(set (attr "type")
7077      (if_then_else (match_operand:SI 2 "incdec_operand" "")
7078         (const_string "incdec")
7079         (const_string "alu")))
7080    (set (attr "length_immediate")
7081       (if_then_else
7082         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
7083         (const_string "1")
7084         (const_string "*")))
7085    (set_attr "mode" "SI")])
7086
7087 ; See comments above addsi_4 for details.
7088
7089 (define_insn "*addhi_4"
7090   [(set (reg FLAGS_REG)
7091         (compare
7092           (match_operand:HI 1 "nonimmediate_operand" "0")
7093           (match_operand:HI 2 "const_int_operand" "n")))
7094    (clobber (match_scratch:HI 0 "=rm"))]
7095   "ix86_match_ccmode (insn, CCGCmode)
7096    && (INTVAL (operands[2]) & 0xffff) != 0x8000"
7097 {
7098   switch (get_attr_type (insn))
7099     {
7100     case TYPE_INCDEC:
7101       if (operands[2] == constm1_rtx)
7102         return "inc{w}\t%0";
7103       else
7104         {
7105           gcc_assert (operands[2] == const1_rtx);
7106           return "dec{w}\t%0";
7107         }
7108
7109     default:
7110       gcc_assert (rtx_equal_p (operands[0], operands[1]));
7111       /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
7112          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
7113       if ((INTVAL (operands[2]) == -128
7114            || (INTVAL (operands[2]) > 0
7115                && INTVAL (operands[2]) != 128)))
7116         return "sub{w}\t{%2, %0|%0, %2}";
7117       operands[2] = GEN_INT (-INTVAL (operands[2]));
7118       return "add{w}\t{%2, %0|%0, %2}";
7119     }
7120 }
7121   [(set (attr "type")
7122      (if_then_else (match_operand:HI 2 "incdec_operand" "")
7123         (const_string "incdec")
7124         (const_string "alu")))
7125    (set (attr "length_immediate")
7126       (if_then_else
7127         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
7128         (const_string "1")
7129         (const_string "*")))
7130    (set_attr "mode" "HI")])
7131
7132 ; See comments above addsi_4 for details.
7133
7134 (define_insn "*addqi_4"
7135   [(set (reg FLAGS_REG)
7136         (compare
7137           (match_operand:QI 1 "nonimmediate_operand" "0")
7138           (match_operand:QI 2 "const_int_operand" "n")))
7139    (clobber (match_scratch:QI 0 "=qm"))]
7140   "ix86_match_ccmode (insn, CCGCmode)
7141    && (INTVAL (operands[2]) & 0xff) != 0x80"
7142 {
7143   switch (get_attr_type (insn))
7144     {
7145     case TYPE_INCDEC:
7146       if (operands[2] == constm1_rtx
7147           || (CONST_INT_P (operands[2])
7148               && INTVAL (operands[2]) == 255))
7149         return "inc{b}\t%0";
7150       else
7151         {
7152           gcc_assert (operands[2] == const1_rtx);
7153           return "dec{b}\t%0";
7154         }
7155
7156     default:
7157       gcc_assert (rtx_equal_p (operands[0], operands[1]));
7158       if (INTVAL (operands[2]) < 0)
7159         {
7160           operands[2] = GEN_INT (-INTVAL (operands[2]));
7161           return "add{b}\t{%2, %0|%0, %2}";
7162         }
7163       return "sub{b}\t{%2, %0|%0, %2}";
7164     }
7165 }
7166   [(set (attr "type")
7167      (if_then_else (match_operand:HI 2 "incdec_operand" "")
7168         (const_string "incdec")
7169         (const_string "alu")))
7170    (set_attr "mode" "QI")])
7171
7172 (define_insn "*add<mode>_5"
7173   [(set (reg FLAGS_REG)
7174         (compare
7175           (plus:SWI48
7176             (match_operand:SWI48 1 "nonimmediate_operand" "%0")
7177             (match_operand:SWI48 2 "<general_operand>" "<g>"))
7178           (const_int 0)))
7179    (clobber (match_scratch:SWI48 0 "=r"))]
7180   "ix86_match_ccmode (insn, CCGOCmode)
7181    && !(MEM_P (operands[1]) && MEM_P (operands[2]))
7182    /* Current assemblers are broken and do not allow @GOTOFF in
7183       ought but a memory context.  */
7184    && ! pic_symbolic_operand (operands[2], VOIDmode)"
7185 {
7186   switch (get_attr_type (insn))
7187     {
7188     case TYPE_INCDEC:
7189       gcc_assert (rtx_equal_p (operands[0], operands[1]));
7190       if (operands[2] == const1_rtx)
7191         return "inc{<imodesuffix>}\t%0";
7192       else
7193         {
7194           gcc_assert (operands[2] == constm1_rtx);
7195           return "dec{<imodesuffix>}\t%0";
7196         }
7197
7198     default:
7199       gcc_assert (rtx_equal_p (operands[0], operands[1]));
7200       /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
7201          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
7202       if (CONST_INT_P (operands[2])
7203           /* Avoid overflows.  */
7204           && (<MODE>mode != DImode
7205               || ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1))))
7206           && (INTVAL (operands[2]) == 128
7207               || (INTVAL (operands[2]) < 0
7208                   && INTVAL (operands[2]) != -128)))
7209         {
7210           operands[2] = GEN_INT (-INTVAL (operands[2]));
7211           return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
7212         }
7213       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
7214     }
7215 }
7216   [(set (attr "type")
7217      (if_then_else (match_operand:SWI48 2 "incdec_operand" "")
7218         (const_string "incdec")
7219         (const_string "alu")))
7220    (set (attr "length_immediate")
7221       (if_then_else
7222         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
7223         (const_string "1")
7224         (const_string "*")))
7225    (set_attr "mode" "<MODE>")])
7226
7227 (define_insn "*addhi_5"
7228   [(set (reg FLAGS_REG)
7229         (compare
7230           (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0")
7231                    (match_operand:HI 2 "general_operand" "rmn"))
7232           (const_int 0)))
7233    (clobber (match_scratch:HI 0 "=r"))]
7234   "ix86_match_ccmode (insn, CCGOCmode)
7235    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
7236 {
7237   switch (get_attr_type (insn))
7238     {
7239     case TYPE_INCDEC:
7240       if (operands[2] == const1_rtx)
7241         return "inc{w}\t%0";
7242       else
7243         {
7244           gcc_assert (operands[2] == constm1_rtx);
7245           return "dec{w}\t%0";
7246         }
7247
7248     default:
7249       /* Make things pretty and `subw $4,%ax' rather than `addw $-4,%ax'.
7250          Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
7251       if (CONST_INT_P (operands[2])
7252           && (INTVAL (operands[2]) == 128
7253               || (INTVAL (operands[2]) < 0
7254                   && INTVAL (operands[2]) != -128)))
7255         {
7256           operands[2] = GEN_INT (-INTVAL (operands[2]));
7257           return "sub{w}\t{%2, %0|%0, %2}";
7258         }
7259       return "add{w}\t{%2, %0|%0, %2}";
7260     }
7261 }
7262   [(set (attr "type")
7263      (if_then_else (match_operand:HI 2 "incdec_operand" "")
7264         (const_string "incdec")
7265         (const_string "alu")))
7266    (set (attr "length_immediate")
7267       (if_then_else
7268         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
7269         (const_string "1")
7270         (const_string "*")))
7271    (set_attr "mode" "HI")])
7272
7273 (define_insn "*addqi_5"
7274   [(set (reg FLAGS_REG)
7275         (compare
7276           (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0")
7277                    (match_operand:QI 2 "general_operand" "qmn"))
7278           (const_int 0)))
7279    (clobber (match_scratch:QI 0 "=q"))]
7280   "ix86_match_ccmode (insn, CCGOCmode)
7281    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
7282 {
7283   switch (get_attr_type (insn))
7284     {
7285     case TYPE_INCDEC:
7286       if (operands[2] == const1_rtx)
7287         return "inc{b}\t%0";
7288       else
7289         {
7290           gcc_assert (operands[2] == constm1_rtx
7291                       || (CONST_INT_P (operands[2])
7292                           && INTVAL (operands[2]) == 255));
7293           return "dec{b}\t%0";
7294         }
7295
7296     default:
7297       /* Make things pretty and `subb $4,%al' rather than `addb $-4,%al'.  */
7298       if (CONST_INT_P (operands[2])
7299           && INTVAL (operands[2]) < 0)
7300         {
7301           operands[2] = GEN_INT (-INTVAL (operands[2]));
7302           return "sub{b}\t{%2, %0|%0, %2}";
7303         }
7304       return "add{b}\t{%2, %0|%0, %2}";
7305     }
7306 }
7307   [(set (attr "type")
7308      (if_then_else (match_operand:QI 2 "incdec_operand" "")
7309         (const_string "incdec")
7310         (const_string "alu")))
7311    (set_attr "mode" "QI")])
7312
7313 (define_insn "*addqi_ext_1_rex64"
7314   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
7315                          (const_int 8)
7316                          (const_int 8))
7317         (plus:SI
7318           (zero_extract:SI
7319             (match_operand 1 "ext_register_operand" "0")
7320             (const_int 8)
7321             (const_int 8))
7322           (match_operand:QI 2 "nonmemory_operand" "Qn")))
7323    (clobber (reg:CC FLAGS_REG))]
7324   "TARGET_64BIT"
7325 {
7326   switch (get_attr_type (insn))
7327     {
7328     case TYPE_INCDEC:
7329       if (operands[2] == const1_rtx)
7330         return "inc{b}\t%h0";
7331       else
7332         {
7333           gcc_assert (operands[2] == constm1_rtx
7334                       || (CONST_INT_P (operands[2])
7335                           && INTVAL (operands[2]) == 255));
7336           return "dec{b}\t%h0";
7337         }
7338
7339     default:
7340       return "add{b}\t{%2, %h0|%h0, %2}";
7341     }
7342 }
7343   [(set (attr "type")
7344      (if_then_else (match_operand:QI 2 "incdec_operand" "")
7345         (const_string "incdec")
7346         (const_string "alu")))
7347    (set_attr "modrm" "1")
7348    (set_attr "mode" "QI")])
7349
7350 (define_insn "addqi_ext_1"
7351   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
7352                          (const_int 8)
7353                          (const_int 8))
7354         (plus:SI
7355           (zero_extract:SI
7356             (match_operand 1 "ext_register_operand" "0")
7357             (const_int 8)
7358             (const_int 8))
7359           (match_operand:QI 2 "general_operand" "Qmn")))
7360    (clobber (reg:CC FLAGS_REG))]
7361   "!TARGET_64BIT"
7362 {
7363   switch (get_attr_type (insn))
7364     {
7365     case TYPE_INCDEC:
7366       if (operands[2] == const1_rtx)
7367         return "inc{b}\t%h0";
7368       else
7369         {
7370           gcc_assert (operands[2] == constm1_rtx
7371                       || (CONST_INT_P (operands[2])
7372                           && INTVAL (operands[2]) == 255));
7373           return "dec{b}\t%h0";
7374         }
7375
7376     default:
7377       return "add{b}\t{%2, %h0|%h0, %2}";
7378     }
7379 }
7380   [(set (attr "type")
7381      (if_then_else (match_operand:QI 2 "incdec_operand" "")
7382         (const_string "incdec")
7383         (const_string "alu")))
7384    (set_attr "modrm" "1")
7385    (set_attr "mode" "QI")])
7386
7387 (define_insn "*addqi_ext_2"
7388   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
7389                          (const_int 8)
7390                          (const_int 8))
7391         (plus:SI
7392           (zero_extract:SI
7393             (match_operand 1 "ext_register_operand" "%0")
7394             (const_int 8)
7395             (const_int 8))
7396           (zero_extract:SI
7397             (match_operand 2 "ext_register_operand" "Q")
7398             (const_int 8)
7399             (const_int 8))))
7400    (clobber (reg:CC FLAGS_REG))]
7401   ""
7402   "add{b}\t{%h2, %h0|%h0, %h2}"
7403   [(set_attr "type" "alu")
7404    (set_attr "mode" "QI")])
7405
7406 ;; The lea patterns for non-Pmodes needs to be matched by
7407 ;; several insns converted to real lea by splitters.
7408
7409 (define_insn_and_split "*lea_general_1"
7410   [(set (match_operand 0 "register_operand" "=r")
7411         (plus (plus (match_operand 1 "index_register_operand" "l")
7412                     (match_operand 2 "register_operand" "r"))
7413               (match_operand 3 "immediate_operand" "i")))]
7414   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode
7415     || (TARGET_64BIT && GET_MODE (operands[0]) == SImode))
7416    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
7417    && GET_MODE (operands[0]) == GET_MODE (operands[1])
7418    && GET_MODE (operands[0]) == GET_MODE (operands[2])
7419    && (GET_MODE (operands[0]) == GET_MODE (operands[3])
7420        || GET_MODE (operands[3]) == VOIDmode)"
7421   "#"
7422   "&& reload_completed"
7423   [(const_int 0)]
7424 {
7425   rtx pat;
7426   operands[0] = gen_lowpart (SImode, operands[0]);
7427   operands[1] = gen_lowpart (Pmode, operands[1]);
7428   operands[2] = gen_lowpart (Pmode, operands[2]);
7429   operands[3] = gen_lowpart (Pmode, operands[3]);
7430   pat = gen_rtx_PLUS (Pmode, gen_rtx_PLUS (Pmode, operands[1], operands[2]),
7431                       operands[3]);
7432   if (Pmode != SImode)
7433     pat = gen_rtx_SUBREG (SImode, pat, 0);
7434   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
7435   DONE;
7436 }
7437   [(set_attr "type" "lea")
7438    (set_attr "mode" "SI")])
7439
7440 (define_insn_and_split "*lea_general_1_zext"
7441   [(set (match_operand:DI 0 "register_operand" "=r")
7442         (zero_extend:DI
7443           (plus:SI (plus:SI
7444                      (match_operand:SI 1 "index_register_operand" "l")
7445                      (match_operand:SI 2 "register_operand" "r"))
7446                    (match_operand:SI 3 "immediate_operand" "i"))))]
7447   "TARGET_64BIT"
7448   "#"
7449   "&& reload_completed"
7450   [(set (match_dup 0)
7451         (zero_extend:DI (subreg:SI (plus:DI (plus:DI (match_dup 1)
7452                                                      (match_dup 2))
7453                                             (match_dup 3)) 0)))]
7454 {
7455   operands[1] = gen_lowpart (Pmode, operands[1]);
7456   operands[2] = gen_lowpart (Pmode, operands[2]);
7457   operands[3] = gen_lowpart (Pmode, operands[3]);
7458 }
7459   [(set_attr "type" "lea")
7460    (set_attr "mode" "SI")])
7461
7462 (define_insn_and_split "*lea_general_2"
7463   [(set (match_operand 0 "register_operand" "=r")
7464         (plus (mult (match_operand 1 "index_register_operand" "l")
7465                     (match_operand 2 "const248_operand" "i"))
7466               (match_operand 3 "nonmemory_operand" "ri")))]
7467   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode
7468     || (TARGET_64BIT && GET_MODE (operands[0]) == SImode))
7469    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
7470    && GET_MODE (operands[0]) == GET_MODE (operands[1])
7471    && (GET_MODE (operands[0]) == GET_MODE (operands[3])
7472        || GET_MODE (operands[3]) == VOIDmode)"
7473   "#"
7474   "&& reload_completed"
7475   [(const_int 0)]
7476 {
7477   rtx pat;
7478   operands[0] = gen_lowpart (SImode, operands[0]);
7479   operands[1] = gen_lowpart (Pmode, operands[1]);
7480   operands[3] = gen_lowpart (Pmode, operands[3]);
7481   pat = gen_rtx_PLUS (Pmode, gen_rtx_MULT (Pmode, operands[1], operands[2]),
7482                       operands[3]);
7483   if (Pmode != SImode)
7484     pat = gen_rtx_SUBREG (SImode, pat, 0);
7485   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
7486   DONE;
7487 }
7488   [(set_attr "type" "lea")
7489    (set_attr "mode" "SI")])
7490
7491 (define_insn_and_split "*lea_general_2_zext"
7492   [(set (match_operand:DI 0 "register_operand" "=r")
7493         (zero_extend:DI
7494           (plus:SI (mult:SI
7495                      (match_operand:SI 1 "index_register_operand" "l")
7496                      (match_operand:SI 2 "const248_operand" "n"))
7497                    (match_operand:SI 3 "nonmemory_operand" "ri"))))]
7498   "TARGET_64BIT"
7499   "#"
7500   "&& reload_completed"
7501   [(set (match_dup 0)
7502         (zero_extend:DI (subreg:SI (plus:DI (mult:DI (match_dup 1)
7503                                                      (match_dup 2))
7504                                             (match_dup 3)) 0)))]
7505 {
7506   operands[1] = gen_lowpart (Pmode, operands[1]);
7507   operands[3] = gen_lowpart (Pmode, operands[3]);
7508 }
7509   [(set_attr "type" "lea")
7510    (set_attr "mode" "SI")])
7511
7512 (define_insn_and_split "*lea_general_3"
7513   [(set (match_operand 0 "register_operand" "=r")
7514         (plus (plus (mult (match_operand 1 "index_register_operand" "l")
7515                           (match_operand 2 "const248_operand" "i"))
7516                     (match_operand 3 "register_operand" "r"))
7517               (match_operand 4 "immediate_operand" "i")))]
7518   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode
7519     || (TARGET_64BIT && GET_MODE (operands[0]) == SImode))
7520    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
7521    && GET_MODE (operands[0]) == GET_MODE (operands[1])
7522    && GET_MODE (operands[0]) == GET_MODE (operands[3])"
7523   "#"
7524   "&& reload_completed"
7525   [(const_int 0)]
7526 {
7527   rtx pat;
7528   operands[0] = gen_lowpart (SImode, operands[0]);
7529   operands[1] = gen_lowpart (Pmode, operands[1]);
7530   operands[3] = gen_lowpart (Pmode, operands[3]);
7531   operands[4] = gen_lowpart (Pmode, operands[4]);
7532   pat = gen_rtx_PLUS (Pmode,
7533                       gen_rtx_PLUS (Pmode, gen_rtx_MULT (Pmode, operands[1],
7534                                                          operands[2]),
7535                                     operands[3]),
7536                       operands[4]);
7537   if (Pmode != SImode)
7538     pat = gen_rtx_SUBREG (SImode, pat, 0);
7539   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
7540   DONE;
7541 }
7542   [(set_attr "type" "lea")
7543    (set_attr "mode" "SI")])
7544
7545 (define_insn_and_split "*lea_general_3_zext"
7546   [(set (match_operand:DI 0 "register_operand" "=r")
7547         (zero_extend:DI
7548           (plus:SI (plus:SI
7549                      (mult:SI
7550                        (match_operand:SI 1 "index_register_operand" "l")
7551                        (match_operand:SI 2 "const248_operand" "n"))
7552                      (match_operand:SI 3 "register_operand" "r"))
7553                    (match_operand:SI 4 "immediate_operand" "i"))))]
7554   "TARGET_64BIT"
7555   "#"
7556   "&& reload_completed"
7557   [(set (match_dup 0)
7558         (zero_extend:DI (subreg:SI (plus:DI (plus:DI (mult:DI (match_dup 1)
7559                                                               (match_dup 2))
7560                                                      (match_dup 3))
7561                                             (match_dup 4)) 0)))]
7562 {
7563   operands[1] = gen_lowpart (Pmode, operands[1]);
7564   operands[3] = gen_lowpart (Pmode, operands[3]);
7565   operands[4] = gen_lowpart (Pmode, operands[4]);
7566 }
7567   [(set_attr "type" "lea")
7568    (set_attr "mode" "SI")])
7569
7570 ;; Convert lea to the lea pattern to avoid flags dependency.
7571 (define_split
7572   [(set (match_operand:DI 0 "register_operand" "")
7573         (plus:DI (match_operand:DI 1 "register_operand" "")
7574                  (match_operand:DI 2 "x86_64_nonmemory_operand" "")))
7575    (clobber (reg:CC FLAGS_REG))]
7576   "TARGET_64BIT && reload_completed 
7577    && ix86_lea_for_add_ok (PLUS, insn, operands)"
7578   [(set (match_dup 0)
7579         (plus:DI (match_dup 1)
7580                  (match_dup 2)))]
7581   "")
7582
7583 ;; Convert lea to the lea pattern to avoid flags dependency.
7584 (define_split
7585   [(set (match_operand 0 "register_operand" "")
7586         (plus (match_operand 1 "register_operand" "")
7587               (match_operand 2 "nonmemory_operand" "")))
7588    (clobber (reg:CC FLAGS_REG))]
7589   "reload_completed && ix86_lea_for_add_ok (PLUS, insn, operands)" 
7590   [(const_int 0)]
7591 {
7592   rtx pat;
7593   /* In -fPIC mode the constructs like (const (unspec [symbol_ref]))
7594      may confuse gen_lowpart.  */
7595   if (GET_MODE (operands[0]) != Pmode)
7596     {
7597       operands[1] = gen_lowpart (Pmode, operands[1]);
7598       operands[2] = gen_lowpart (Pmode, operands[2]);
7599     }
7600   operands[0] = gen_lowpart (SImode, operands[0]);
7601   pat = gen_rtx_PLUS (Pmode, operands[1], operands[2]);
7602   if (Pmode != SImode)
7603     pat = gen_rtx_SUBREG (SImode, pat, 0);
7604   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
7605   DONE;
7606 })
7607
7608 ;; Convert lea to the lea pattern to avoid flags dependency.
7609 (define_split
7610   [(set (match_operand:DI 0 "register_operand" "")
7611         (zero_extend:DI
7612           (plus:SI (match_operand:SI 1 "register_operand" "")
7613                    (match_operand:SI 2 "nonmemory_operand" ""))))
7614    (clobber (reg:CC FLAGS_REG))]
7615   "TARGET_64BIT && reload_completed
7616    && true_regnum (operands[0]) != true_regnum (operands[1])"
7617   [(set (match_dup 0)
7618         (zero_extend:DI (subreg:SI (plus:DI (match_dup 1) (match_dup 2)) 0)))]
7619 {
7620   operands[1] = gen_lowpart (Pmode, operands[1]);
7621   operands[2] = gen_lowpart (Pmode, operands[2]);
7622 })
7623 \f
7624 ;; Subtract instructions
7625
7626 (define_expand "sub<mode>3"
7627   [(set (match_operand:SDWIM 0 "nonimmediate_operand" "")
7628         (minus:SDWIM (match_operand:SDWIM 1 "nonimmediate_operand" "")
7629                      (match_operand:SDWIM 2 "<general_operand>" "")))]
7630   ""
7631   "ix86_expand_binary_operator (MINUS, <MODE>mode, operands); DONE;")
7632
7633 (define_insn_and_split "*sub<dwi>3_doubleword"
7634   [(set (match_operand:<DWI> 0 "nonimmediate_operand" "=r,o")
7635         (minus:<DWI>
7636           (match_operand:<DWI> 1 "nonimmediate_operand" "0,0")
7637           (match_operand:<DWI> 2 "<general_operand>" "ro<di>,r<di>")))
7638    (clobber (reg:CC FLAGS_REG))]
7639   "ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
7640   "#"
7641   "reload_completed"
7642   [(parallel [(set (reg:CC FLAGS_REG)
7643                    (compare:CC (match_dup 1) (match_dup 2)))
7644               (set (match_dup 0)
7645                    (minus:DWIH (match_dup 1) (match_dup 2)))])
7646    (parallel [(set (match_dup 3)
7647                    (minus:DWIH
7648                      (match_dup 4)
7649                      (plus:DWIH
7650                        (ltu:DWIH (reg:CC FLAGS_REG) (const_int 0))
7651                        (match_dup 5))))
7652               (clobber (reg:CC FLAGS_REG))])]
7653   "split_<dwi> (&operands[0], 3, &operands[0], &operands[3]);")
7654
7655 (define_insn "sub<mode>3_carry"
7656   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
7657           (minus:SWI
7658             (match_operand:SWI 1 "nonimmediate_operand" "0,0")
7659             (plus:SWI
7660               (match_operand:SWI 3 "ix86_carry_flag_operator" "")
7661               (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m"))))
7662    (clobber (reg:CC FLAGS_REG))]
7663   "ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
7664   "sbb{<imodesuffix>}\t{%2, %0|%0, %2}"
7665   [(set_attr "type" "alu")
7666    (set_attr "use_carry" "1")
7667    (set_attr "pent_pair" "pu")
7668    (set_attr "mode" "<MODE>")])
7669
7670 (define_insn "*subsi3_carry_zext"
7671   [(set (match_operand:DI 0 "register_operand" "=r")
7672           (zero_extend:DI
7673             (minus:SI (match_operand:SI 1 "register_operand" "0")
7674               (plus:SI (match_operand:SI 3 "ix86_carry_flag_operator" "")
7675                  (match_operand:SI 2 "general_operand" "g")))))
7676    (clobber (reg:CC FLAGS_REG))]
7677   "TARGET_64BIT && ix86_binary_operator_ok (MINUS, SImode, operands)"
7678   "sbb{l}\t{%2, %k0|%k0, %2}"
7679   [(set_attr "type" "alu")
7680    (set_attr "pent_pair" "pu")
7681    (set_attr "mode" "SI")])
7682
7683 (define_insn "*sub<mode>3_cconly_overflow"
7684   [(set (reg:CCC FLAGS_REG)
7685         (compare:CCC
7686           (minus:SWI
7687             (match_operand:SWI 0 "nonimmediate_operand" "<r>m,<r>")
7688             (match_operand:SWI 1 "<general_operand>" "<r><i>,<r>m"))
7689           (match_dup 0)))]
7690   ""
7691   "cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
7692   [(set_attr "type" "icmp")
7693    (set_attr "mode" "<MODE>")])
7694
7695 (define_insn "*sub<mode>_1"
7696   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
7697         (minus:SWI
7698           (match_operand:SWI 1 "nonimmediate_operand" "0,0")
7699           (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m")))
7700    (clobber (reg:CC FLAGS_REG))]
7701   "ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
7702   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
7703   [(set_attr "type" "alu")
7704    (set_attr "mode" "<MODE>")])
7705
7706 (define_insn "*subsi_1_zext"
7707   [(set (match_operand:DI 0 "register_operand" "=r")
7708         (zero_extend:DI
7709           (minus:SI (match_operand:SI 1 "register_operand" "0")
7710                     (match_operand:SI 2 "general_operand" "g"))))
7711    (clobber (reg:CC FLAGS_REG))]
7712   "TARGET_64BIT && ix86_binary_operator_ok (MINUS, SImode, operands)"
7713   "sub{l}\t{%2, %k0|%k0, %2}"
7714   [(set_attr "type" "alu")
7715    (set_attr "mode" "SI")])
7716
7717 (define_insn "*subqi_1_slp"
7718   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
7719         (minus:QI (match_dup 0)
7720                   (match_operand:QI 1 "general_operand" "qn,qm")))
7721    (clobber (reg:CC FLAGS_REG))]
7722   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
7723    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7724   "sub{b}\t{%1, %0|%0, %1}"
7725   [(set_attr "type" "alu1")
7726    (set_attr "mode" "QI")])
7727
7728 (define_insn "*sub<mode>_2"
7729   [(set (reg FLAGS_REG)
7730         (compare
7731           (minus:SWI
7732             (match_operand:SWI 1 "nonimmediate_operand" "0,0")
7733             (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m"))
7734           (const_int 0)))
7735    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
7736         (minus:SWI (match_dup 1) (match_dup 2)))]
7737   "ix86_match_ccmode (insn, CCGOCmode)
7738    && ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
7739   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
7740   [(set_attr "type" "alu")
7741    (set_attr "mode" "<MODE>")])
7742
7743 (define_insn "*subsi_2_zext"
7744   [(set (reg FLAGS_REG)
7745         (compare
7746           (minus:SI (match_operand:SI 1 "register_operand" "0")
7747                     (match_operand:SI 2 "general_operand" "g"))
7748           (const_int 0)))
7749    (set (match_operand:DI 0 "register_operand" "=r")
7750         (zero_extend:DI
7751           (minus:SI (match_dup 1)
7752                     (match_dup 2))))]
7753   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
7754    && ix86_binary_operator_ok (MINUS, SImode, operands)"
7755   "sub{l}\t{%2, %k0|%k0, %2}"
7756   [(set_attr "type" "alu")
7757    (set_attr "mode" "SI")])
7758
7759 (define_insn "*sub<mode>_3"
7760   [(set (reg FLAGS_REG)
7761         (compare (match_operand:SWI 1 "nonimmediate_operand" "0,0")
7762                  (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m")))
7763    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
7764         (minus:SWI (match_dup 1) (match_dup 2)))]
7765   "ix86_match_ccmode (insn, CCmode)
7766    && ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
7767   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
7768   [(set_attr "type" "alu")
7769    (set_attr "mode" "<MODE>")])
7770
7771 (define_insn "*subsi_3_zext"
7772   [(set (reg FLAGS_REG)
7773         (compare (match_operand:SI 1 "register_operand" "0")
7774                  (match_operand:SI 2 "general_operand" "g")))
7775    (set (match_operand:DI 0 "register_operand" "=r")
7776         (zero_extend:DI
7777           (minus:SI (match_dup 1)
7778                     (match_dup 2))))]
7779   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)
7780    && ix86_binary_operator_ok (MINUS, SImode, operands)"
7781   "sub{l}\t{%2, %1|%1, %2}"
7782   [(set_attr "type" "alu")
7783    (set_attr "mode" "SI")])
7784
7785
7786 (define_insn "*<plusminus_insn><mode>3_cc_overflow"
7787   [(set (reg:CCC FLAGS_REG)
7788         (compare:CCC
7789             (plusminus:SWI
7790                 (match_operand:SWI 1 "nonimmediate_operand" "<comm>0,0")
7791                 (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m"))
7792             (match_dup 1)))
7793    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
7794         (plusminus:SWI (match_dup 1) (match_dup 2)))]
7795   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
7796   "<plusminus_mnemonic>{<imodesuffix>}\t{%2, %0|%0, %2}"
7797   [(set_attr "type" "alu")
7798    (set_attr "mode" "<MODE>")])
7799
7800 (define_insn "*<plusminus_insn>si3_zext_cc_overflow"
7801   [(set (reg:CCC FLAGS_REG)
7802         (compare:CCC
7803           (plusminus:SI
7804             (match_operand:SI 1 "nonimmediate_operand" "<comm>0")
7805             (match_operand:SI 2 "general_operand" "g"))
7806           (match_dup 1)))
7807    (set (match_operand:DI 0 "register_operand" "=r")
7808         (zero_extend:DI (plusminus:SI (match_dup 1) (match_dup 2))))]
7809   "TARGET_64BIT && ix86_binary_operator_ok (<CODE>, SImode, operands)"
7810   "<plusminus_mnemonic>{l}\t{%2, %k0|%k0, %2}"
7811   [(set_attr "type" "alu")
7812    (set_attr "mode" "SI")])
7813
7814 ;; The patterns that match these are at the end of this file.
7815
7816 (define_expand "<plusminus_insn>xf3"
7817   [(set (match_operand:XF 0 "register_operand" "")
7818         (plusminus:XF
7819           (match_operand:XF 1 "register_operand" "")
7820           (match_operand:XF 2 "register_operand" "")))]
7821   "TARGET_80387"
7822   "")
7823
7824 (define_expand "<plusminus_insn><mode>3"
7825   [(set (match_operand:MODEF 0 "register_operand" "")
7826         (plusminus:MODEF
7827           (match_operand:MODEF 1 "register_operand" "")
7828           (match_operand:MODEF 2 "nonimmediate_operand" "")))]
7829   "(TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode))
7830     || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
7831   "")
7832 \f
7833 ;; Multiply instructions
7834
7835 (define_expand "mul<mode>3"
7836   [(parallel [(set (match_operand:SWIM248 0 "register_operand" "")
7837                    (mult:SWIM248
7838                      (match_operand:SWIM248 1 "register_operand" "")
7839                      (match_operand:SWIM248 2 "<general_operand>" "")))
7840               (clobber (reg:CC FLAGS_REG))])]
7841   ""
7842   "")
7843
7844 (define_expand "mulqi3"
7845   [(parallel [(set (match_operand:QI 0 "register_operand" "")
7846                    (mult:QI
7847                      (match_operand:QI 1 "register_operand" "")
7848                      (match_operand:QI 2 "nonimmediate_operand" "")))
7849               (clobber (reg:CC FLAGS_REG))])]
7850   "TARGET_QIMODE_MATH"
7851   "")
7852
7853 ;; On AMDFAM10
7854 ;; IMUL reg32/64, reg32/64, imm8        Direct
7855 ;; IMUL reg32/64, mem32/64, imm8        VectorPath
7856 ;; IMUL reg32/64, reg32/64, imm32       Direct
7857 ;; IMUL reg32/64, mem32/64, imm32       VectorPath
7858 ;; IMUL reg32/64, reg32/64              Direct
7859 ;; IMUL reg32/64, mem32/64              Direct
7860
7861 (define_insn "*mul<mode>3_1"
7862   [(set (match_operand:SWI48 0 "register_operand" "=r,r,r")
7863         (mult:SWI48
7864           (match_operand:SWI48 1 "nonimmediate_operand" "%rm,rm,0")
7865           (match_operand:SWI48 2 "<general_operand>" "K,<i>,mr")))
7866    (clobber (reg:CC FLAGS_REG))]
7867   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
7868   "@
7869    imul{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}
7870    imul{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}
7871    imul{<imodesuffix>}\t{%2, %0|%0, %2}"
7872   [(set_attr "type" "imul")
7873    (set_attr "prefix_0f" "0,0,1")
7874    (set (attr "athlon_decode")
7875         (cond [(eq_attr "cpu" "athlon")
7876                   (const_string "vector")
7877                (eq_attr "alternative" "1")
7878                   (const_string "vector")
7879                (and (eq_attr "alternative" "2")
7880                     (match_operand 1 "memory_operand" ""))
7881                   (const_string "vector")]
7882               (const_string "direct")))
7883    (set (attr "amdfam10_decode")
7884         (cond [(and (eq_attr "alternative" "0,1")
7885                     (match_operand 1 "memory_operand" ""))
7886                   (const_string "vector")]
7887               (const_string "direct")))
7888    (set_attr "mode" "<MODE>")])
7889
7890 (define_insn "*mulsi3_1_zext"
7891   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
7892         (zero_extend:DI
7893           (mult:SI (match_operand:SI 1 "nonimmediate_operand" "%rm,rm,0")
7894                    (match_operand:SI 2 "general_operand" "K,i,mr"))))
7895    (clobber (reg:CC FLAGS_REG))]
7896   "TARGET_64BIT
7897    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
7898   "@
7899    imul{l}\t{%2, %1, %k0|%k0, %1, %2}
7900    imul{l}\t{%2, %1, %k0|%k0, %1, %2}
7901    imul{l}\t{%2, %k0|%k0, %2}"
7902   [(set_attr "type" "imul")
7903    (set_attr "prefix_0f" "0,0,1")
7904    (set (attr "athlon_decode")
7905         (cond [(eq_attr "cpu" "athlon")
7906                   (const_string "vector")
7907                (eq_attr "alternative" "1")
7908                   (const_string "vector")
7909                (and (eq_attr "alternative" "2")
7910                     (match_operand 1 "memory_operand" ""))
7911                   (const_string "vector")]
7912               (const_string "direct")))
7913    (set (attr "amdfam10_decode")
7914         (cond [(and (eq_attr "alternative" "0,1")
7915                     (match_operand 1 "memory_operand" ""))
7916                   (const_string "vector")]
7917               (const_string "direct")))
7918    (set_attr "mode" "SI")])
7919
7920 ;; On AMDFAM10
7921 ;; IMUL reg16, reg16, imm8      VectorPath
7922 ;; IMUL reg16, mem16, imm8      VectorPath
7923 ;; IMUL reg16, reg16, imm16     VectorPath
7924 ;; IMUL reg16, mem16, imm16     VectorPath
7925 ;; IMUL reg16, reg16            Direct
7926 ;; IMUL reg16, mem16            Direct
7927
7928 (define_insn "*mulhi3_1"
7929   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
7930         (mult:HI (match_operand:HI 1 "nonimmediate_operand" "%rm,rm,0")
7931                  (match_operand:HI 2 "general_operand" "K,n,mr")))
7932    (clobber (reg:CC FLAGS_REG))]
7933   "TARGET_HIMODE_MATH
7934    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
7935   "@
7936    imul{w}\t{%2, %1, %0|%0, %1, %2}
7937    imul{w}\t{%2, %1, %0|%0, %1, %2}
7938    imul{w}\t{%2, %0|%0, %2}"
7939   [(set_attr "type" "imul")
7940    (set_attr "prefix_0f" "0,0,1")
7941    (set (attr "athlon_decode")
7942         (cond [(eq_attr "cpu" "athlon")
7943                   (const_string "vector")
7944                (eq_attr "alternative" "1,2")
7945                   (const_string "vector")]
7946               (const_string "direct")))
7947    (set (attr "amdfam10_decode")
7948         (cond [(eq_attr "alternative" "0,1")
7949                   (const_string "vector")]
7950               (const_string "direct")))
7951    (set_attr "mode" "HI")])
7952
7953 ;;On AMDFAM10
7954 ;; MUL reg8     Direct
7955 ;; MUL mem8     Direct
7956
7957 (define_insn "*mulqi3_1"
7958   [(set (match_operand:QI 0 "register_operand" "=a")
7959         (mult:QI (match_operand:QI 1 "nonimmediate_operand" "%0")
7960                  (match_operand:QI 2 "nonimmediate_operand" "qm")))
7961    (clobber (reg:CC FLAGS_REG))]
7962   "TARGET_QIMODE_MATH
7963    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
7964   "mul{b}\t%2"
7965   [(set_attr "type" "imul")
7966    (set_attr "length_immediate" "0")
7967    (set (attr "athlon_decode")
7968      (if_then_else (eq_attr "cpu" "athlon")
7969         (const_string "vector")
7970         (const_string "direct")))
7971    (set_attr "amdfam10_decode" "direct")
7972    (set_attr "mode" "QI")])
7973
7974 (define_expand "<u>mul<mode><dwi>3"
7975   [(parallel [(set (match_operand:<DWI> 0 "register_operand" "")
7976                    (mult:<DWI>
7977                      (any_extend:<DWI>
7978                        (match_operand:DWIH 1 "nonimmediate_operand" ""))
7979                      (any_extend:<DWI>
7980                        (match_operand:DWIH 2 "register_operand" ""))))
7981               (clobber (reg:CC FLAGS_REG))])]
7982   ""
7983   "")
7984
7985 (define_expand "<u>mulqihi3"
7986   [(parallel [(set (match_operand:HI 0 "register_operand" "")
7987                    (mult:HI
7988                      (any_extend:HI
7989                        (match_operand:QI 1 "nonimmediate_operand" ""))
7990                      (any_extend:HI
7991                        (match_operand:QI 2 "register_operand" ""))))
7992               (clobber (reg:CC FLAGS_REG))])]
7993   "TARGET_QIMODE_MATH"
7994   "")
7995
7996 (define_insn "*<u>mul<mode><dwi>3_1"
7997   [(set (match_operand:<DWI> 0 "register_operand" "=A")
7998         (mult:<DWI>
7999           (any_extend:<DWI>
8000             (match_operand:DWIH 1 "nonimmediate_operand" "%0"))
8001           (any_extend:<DWI>
8002             (match_operand:DWIH 2 "nonimmediate_operand" "rm"))))
8003    (clobber (reg:CC FLAGS_REG))]
8004   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
8005   "<sgnprefix>mul{<imodesuffix>}\t%2"
8006   [(set_attr "type" "imul")
8007    (set_attr "length_immediate" "0")
8008    (set (attr "athlon_decode")
8009      (if_then_else (eq_attr "cpu" "athlon")
8010         (const_string "vector")
8011         (const_string "double")))
8012    (set_attr "amdfam10_decode" "double")
8013    (set_attr "mode" "<MODE>")])
8014
8015 (define_insn "*<u>mulqihi3_1"
8016   [(set (match_operand:HI 0 "register_operand" "=a")
8017         (mult:HI
8018           (any_extend:HI
8019             (match_operand:QI 1 "nonimmediate_operand" "%0"))
8020           (any_extend:HI
8021             (match_operand:QI 2 "nonimmediate_operand" "qm"))))
8022    (clobber (reg:CC FLAGS_REG))]
8023   "TARGET_QIMODE_MATH
8024    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
8025   "<sgnprefix>mul{b}\t%2"
8026   [(set_attr "type" "imul")
8027    (set_attr "length_immediate" "0")
8028    (set (attr "athlon_decode")
8029      (if_then_else (eq_attr "cpu" "athlon")
8030         (const_string "vector")
8031         (const_string "direct")))
8032    (set_attr "amdfam10_decode" "direct")
8033    (set_attr "mode" "QI")])
8034
8035 (define_expand "<s>mul<mode>3_highpart"
8036   [(parallel [(set (match_operand:SWI48 0 "register_operand" "")
8037                    (truncate:SWI48
8038                      (lshiftrt:<DWI>
8039                        (mult:<DWI>
8040                          (any_extend:<DWI>
8041                            (match_operand:SWI48 1 "nonimmediate_operand" ""))
8042                          (any_extend:<DWI>
8043                            (match_operand:SWI48 2 "register_operand" "")))
8044                        (match_dup 4))))
8045               (clobber (match_scratch:SWI48 3 ""))
8046               (clobber (reg:CC FLAGS_REG))])]
8047   ""
8048   "operands[4] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));")
8049
8050 (define_insn "*<s>muldi3_highpart_1"
8051   [(set (match_operand:DI 0 "register_operand" "=d")
8052         (truncate:DI
8053           (lshiftrt:TI
8054             (mult:TI
8055               (any_extend:TI
8056                 (match_operand:DI 1 "nonimmediate_operand" "%a"))
8057               (any_extend:TI
8058                 (match_operand:DI 2 "nonimmediate_operand" "rm")))
8059             (const_int 64))))
8060    (clobber (match_scratch:DI 3 "=1"))
8061    (clobber (reg:CC FLAGS_REG))]
8062   "TARGET_64BIT
8063    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
8064   "<sgnprefix>mul{q}\t%2"
8065   [(set_attr "type" "imul")
8066    (set_attr "length_immediate" "0")
8067    (set (attr "athlon_decode")
8068      (if_then_else (eq_attr "cpu" "athlon")
8069         (const_string "vector")
8070         (const_string "double")))
8071    (set_attr "amdfam10_decode" "double")
8072    (set_attr "mode" "DI")])
8073
8074 (define_insn "*<s>mulsi3_highpart_1"
8075   [(set (match_operand:SI 0 "register_operand" "=d")
8076         (truncate:SI
8077           (lshiftrt:DI
8078             (mult:DI
8079               (any_extend:DI
8080                 (match_operand:SI 1 "nonimmediate_operand" "%a"))
8081               (any_extend:DI
8082                 (match_operand:SI 2 "nonimmediate_operand" "rm")))
8083             (const_int 32))))
8084    (clobber (match_scratch:SI 3 "=1"))
8085    (clobber (reg:CC FLAGS_REG))]
8086   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
8087   "<sgnprefix>mul{l}\t%2"
8088   [(set_attr "type" "imul")
8089    (set_attr "length_immediate" "0")
8090    (set (attr "athlon_decode")
8091      (if_then_else (eq_attr "cpu" "athlon")
8092         (const_string "vector")
8093         (const_string "double")))
8094    (set_attr "amdfam10_decode" "double")
8095    (set_attr "mode" "SI")])
8096
8097 (define_insn "*<s>mulsi3_highpart_zext"
8098   [(set (match_operand:DI 0 "register_operand" "=d")
8099         (zero_extend:DI (truncate:SI
8100           (lshiftrt:DI
8101             (mult:DI (any_extend:DI
8102                        (match_operand:SI 1 "nonimmediate_operand" "%a"))
8103                      (any_extend:DI
8104                        (match_operand:SI 2 "nonimmediate_operand" "rm")))
8105             (const_int 32)))))
8106    (clobber (match_scratch:SI 3 "=1"))
8107    (clobber (reg:CC FLAGS_REG))]
8108   "TARGET_64BIT
8109    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
8110   "<sgnprefix>mul{l}\t%2"
8111   [(set_attr "type" "imul")
8112    (set_attr "length_immediate" "0")
8113    (set (attr "athlon_decode")
8114      (if_then_else (eq_attr "cpu" "athlon")
8115         (const_string "vector")
8116         (const_string "double")))
8117    (set_attr "amdfam10_decode" "double")
8118    (set_attr "mode" "SI")])
8119
8120 ;; The patterns that match these are at the end of this file.
8121
8122 (define_expand "mulxf3"
8123   [(set (match_operand:XF 0 "register_operand" "")
8124         (mult:XF (match_operand:XF 1 "register_operand" "")
8125                  (match_operand:XF 2 "register_operand" "")))]
8126   "TARGET_80387"
8127   "")
8128
8129 (define_expand "mul<mode>3"
8130   [(set (match_operand:MODEF 0 "register_operand" "")
8131         (mult:MODEF (match_operand:MODEF 1 "register_operand" "")
8132                     (match_operand:MODEF 2 "nonimmediate_operand" "")))]
8133   "(TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode))
8134     || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
8135   "")
8136 \f
8137 ;; Divide instructions
8138
8139 (define_insn "<u>divqi3"
8140   [(set (match_operand:QI 0 "register_operand" "=a")
8141         (any_div:QI
8142           (match_operand:HI 1 "register_operand" "0")
8143           (match_operand:QI 2 "nonimmediate_operand" "qm")))
8144    (clobber (reg:CC FLAGS_REG))]
8145   "TARGET_QIMODE_MATH"
8146   "<sgnprefix>div{b}\t%2"
8147   [(set_attr "type" "idiv")
8148    (set_attr "mode" "QI")])
8149
8150 ;; The patterns that match these are at the end of this file.
8151
8152 (define_expand "divxf3"
8153   [(set (match_operand:XF 0 "register_operand" "")
8154         (div:XF (match_operand:XF 1 "register_operand" "")
8155                 (match_operand:XF 2 "register_operand" "")))]
8156   "TARGET_80387"
8157   "")
8158
8159 (define_expand "divdf3"
8160   [(set (match_operand:DF 0 "register_operand" "")
8161         (div:DF (match_operand:DF 1 "register_operand" "")
8162                 (match_operand:DF 2 "nonimmediate_operand" "")))]
8163    "(TARGET_80387 && X87_ENABLE_ARITH (DFmode))
8164     || (TARGET_SSE2 && TARGET_SSE_MATH)"
8165    "")
8166
8167 (define_expand "divsf3"
8168   [(set (match_operand:SF 0 "register_operand" "")
8169         (div:SF (match_operand:SF 1 "register_operand" "")
8170                 (match_operand:SF 2 "nonimmediate_operand" "")))]
8171   "(TARGET_80387 && X87_ENABLE_ARITH (SFmode))
8172     || TARGET_SSE_MATH"
8173 {
8174   if (TARGET_SSE_MATH && TARGET_RECIP && optimize_insn_for_speed_p ()
8175       && flag_finite_math_only && !flag_trapping_math
8176       && flag_unsafe_math_optimizations)
8177     {
8178       ix86_emit_swdivsf (operands[0], operands[1],
8179                          operands[2], SFmode);
8180       DONE;
8181     }
8182 })
8183 \f
8184 ;; Divmod instructions.
8185
8186 (define_expand "divmod<mode>4"
8187   [(parallel [(set (match_operand:SWIM248 0 "register_operand" "")
8188                    (div:SWIM248
8189                      (match_operand:SWIM248 1 "register_operand" "")
8190                      (match_operand:SWIM248 2 "nonimmediate_operand" "")))
8191               (set (match_operand:SWIM248 3 "register_operand" "")
8192                    (mod:SWIM248 (match_dup 1) (match_dup 2)))
8193               (clobber (reg:CC FLAGS_REG))])]
8194   ""
8195   "")
8196
8197 (define_insn_and_split "*divmod<mode>4"
8198   [(set (match_operand:SWIM248 0 "register_operand" "=a")
8199         (div:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
8200                     (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
8201    (set (match_operand:SWIM248 1 "register_operand" "=&d")
8202         (mod:SWIM248 (match_dup 2) (match_dup 3)))
8203    (clobber (reg:CC FLAGS_REG))]
8204   ""
8205   "#"
8206   "&& reload_completed"
8207   [(parallel [(set (match_dup 1)
8208                    (ashiftrt:SWIM248 (match_dup 4) (match_dup 5)))
8209               (clobber (reg:CC FLAGS_REG))])
8210    (parallel [(set (match_dup 0)
8211                    (div:SWIM248 (match_dup 2) (match_dup 3)))
8212               (set (match_dup 1)
8213                    (mod:SWIM248 (match_dup 2) (match_dup 3)))
8214               (use (match_dup 1))
8215               (clobber (reg:CC FLAGS_REG))])]
8216 {
8217   operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - 1);
8218
8219   if (<MODE>mode != HImode
8220       && (optimize_function_for_size_p (cfun) || TARGET_USE_CLTD))
8221     operands[4] = operands[2];
8222   else
8223     {
8224       /* Avoid use of cltd in favor of a mov+shift.  */
8225       emit_move_insn (operands[1], operands[2]);
8226       operands[4] = operands[1];
8227     }
8228 }
8229   [(set_attr "type" "multi")
8230    (set_attr "mode" "<MODE>")])
8231
8232 (define_insn "*divmod<mode>4_noext"
8233   [(set (match_operand:SWIM248 0 "register_operand" "=a")
8234         (div:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
8235                     (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
8236    (set (match_operand:SWIM248 1 "register_operand" "=d")
8237         (mod:SWIM248 (match_dup 2) (match_dup 3)))
8238    (use (match_operand:SWIM248 4 "register_operand" "1"))
8239    (clobber (reg:CC FLAGS_REG))]
8240   ""
8241   "idiv{<imodesuffix>}\t%3"
8242   [(set_attr "type" "idiv")
8243    (set_attr "mode" "<MODE>")])
8244
8245 (define_expand "udivmod<mode>4"
8246   [(parallel [(set (match_operand:SWIM248 0 "register_operand" "")
8247                    (udiv:SWIM248
8248                      (match_operand:SWIM248 1 "register_operand" "")
8249                      (match_operand:SWIM248 2 "nonimmediate_operand" "")))
8250               (set (match_operand:SWIM248 3 "register_operand" "")
8251                    (umod:SWIM248 (match_dup 1) (match_dup 2)))
8252               (clobber (reg:CC FLAGS_REG))])]
8253   ""
8254   "")
8255
8256 (define_insn_and_split "*udivmod<mode>4"
8257   [(set (match_operand:SWIM248 0 "register_operand" "=a")
8258         (udiv:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
8259                       (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
8260    (set (match_operand:SWIM248 1 "register_operand" "=&d")
8261         (umod:SWIM248 (match_dup 2) (match_dup 3)))
8262    (clobber (reg:CC FLAGS_REG))]
8263   ""
8264   "#"
8265   "&& reload_completed"
8266   [(set (match_dup 1) (const_int 0))
8267    (parallel [(set (match_dup 0)
8268                    (udiv:SWIM248 (match_dup 2) (match_dup 3)))
8269               (set (match_dup 1)
8270                    (umod:SWIM248 (match_dup 2) (match_dup 3)))
8271               (use (match_dup 1))
8272               (clobber (reg:CC FLAGS_REG))])]
8273   ""
8274   [(set_attr "type" "multi")
8275    (set_attr "mode" "<MODE>")])
8276
8277 (define_insn "*udivmod<mode>4_noext"
8278   [(set (match_operand:SWIM248 0 "register_operand" "=a")
8279         (udiv:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
8280                       (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
8281    (set (match_operand:SWIM248 1 "register_operand" "=d")
8282         (umod:SWIM248 (match_dup 2) (match_dup 3)))
8283    (use (match_operand:SWIM248 4 "register_operand" "1"))
8284    (clobber (reg:CC FLAGS_REG))]
8285   ""
8286   "div{<imodesuffix>}\t%3"
8287   [(set_attr "type" "idiv")
8288    (set_attr "mode" "<MODE>")])
8289
8290 ;; We cannot use div/idiv for double division, because it causes
8291 ;; "division by zero" on the overflow and that's not what we expect
8292 ;; from truncate.  Because true (non truncating) double division is
8293 ;; never generated, we can't create this insn anyway.
8294 ;
8295 ;(define_insn ""
8296 ;  [(set (match_operand:SI 0 "register_operand" "=a")
8297 ;       (truncate:SI
8298 ;         (udiv:DI (match_operand:DI 1 "register_operand" "A")
8299 ;                  (zero_extend:DI
8300 ;                    (match_operand:SI 2 "nonimmediate_operand" "rm")))))
8301 ;   (set (match_operand:SI 3 "register_operand" "=d")
8302 ;       (truncate:SI
8303 ;         (umod:DI (match_dup 1) (zero_extend:DI (match_dup 2)))))
8304 ;   (clobber (reg:CC FLAGS_REG))]
8305 ;  ""
8306 ;  "div{l}\t{%2, %0|%0, %2}"
8307 ;  [(set_attr "type" "idiv")])
8308 \f
8309 ;;- Logical AND instructions
8310
8311 ;; On Pentium, "test imm, reg" is pairable only with eax, ax, and al.
8312 ;; Note that this excludes ah.
8313
8314 (define_insn "*testdi_1_rex64"
8315   [(set (reg FLAGS_REG)
8316         (compare
8317           (and:DI (match_operand:DI 0 "nonimmediate_operand" "%!*a,r,!*a,r,rm")
8318                   (match_operand:DI 1 "x86_64_szext_general_operand" "Z,Z,e,e,re"))
8319           (const_int 0)))]
8320   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8321    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8322   "@
8323    test{l}\t{%k1, %k0|%k0, %k1}
8324    test{l}\t{%k1, %k0|%k0, %k1}
8325    test{q}\t{%1, %0|%0, %1}
8326    test{q}\t{%1, %0|%0, %1}
8327    test{q}\t{%1, %0|%0, %1}"
8328   [(set_attr "type" "test")
8329    (set_attr "modrm" "0,1,0,1,1")
8330    (set_attr "mode" "SI,SI,DI,DI,DI")
8331    (set_attr "pent_pair" "uv,np,uv,np,uv")])
8332
8333 (define_insn "testsi_1"
8334   [(set (reg FLAGS_REG)
8335         (compare
8336           (and:SI (match_operand:SI 0 "nonimmediate_operand" "%!*a,r,rm")
8337                   (match_operand:SI 1 "general_operand" "i,i,ri"))
8338           (const_int 0)))]
8339   "ix86_match_ccmode (insn, CCNOmode)
8340    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8341   "test{l}\t{%1, %0|%0, %1}"
8342   [(set_attr "type" "test")
8343    (set_attr "modrm" "0,1,1")
8344    (set_attr "mode" "SI")
8345    (set_attr "pent_pair" "uv,np,uv")])
8346
8347 (define_expand "testsi_ccno_1"
8348   [(set (reg:CCNO FLAGS_REG)
8349         (compare:CCNO
8350           (and:SI (match_operand:SI 0 "nonimmediate_operand" "")
8351                   (match_operand:SI 1 "nonmemory_operand" ""))
8352           (const_int 0)))]
8353   ""
8354   "")
8355
8356 (define_insn "*testhi_1"
8357   [(set (reg FLAGS_REG)
8358         (compare (and:HI (match_operand:HI 0 "nonimmediate_operand" "%!*a,r,rm")
8359                          (match_operand:HI 1 "general_operand" "n,n,rn"))
8360                  (const_int 0)))]
8361   "ix86_match_ccmode (insn, CCNOmode)
8362    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8363   "test{w}\t{%1, %0|%0, %1}"
8364   [(set_attr "type" "test")
8365    (set_attr "modrm" "0,1,1")
8366    (set_attr "mode" "HI")
8367    (set_attr "pent_pair" "uv,np,uv")])
8368
8369 (define_expand "testqi_ccz_1"
8370   [(set (reg:CCZ FLAGS_REG)
8371         (compare:CCZ (and:QI (match_operand:QI 0 "nonimmediate_operand" "")
8372                              (match_operand:QI 1 "nonmemory_operand" ""))
8373                  (const_int 0)))]
8374   ""
8375   "")
8376
8377 (define_insn "*testqi_1_maybe_si"
8378   [(set (reg FLAGS_REG)
8379         (compare
8380           (and:QI
8381             (match_operand:QI 0 "nonimmediate_operand" "%!*a,q,qm,r")
8382             (match_operand:QI 1 "general_operand" "n,n,qn,n"))
8383           (const_int 0)))]
8384    "!(MEM_P (operands[0]) && MEM_P (operands[1]))
8385     && ix86_match_ccmode (insn,
8386                          CONST_INT_P (operands[1])
8387                          && INTVAL (operands[1]) >= 0 ? CCNOmode : CCZmode)"
8388 {
8389   if (which_alternative == 3)
8390     {
8391       if (CONST_INT_P (operands[1]) && INTVAL (operands[1]) < 0)
8392         operands[1] = GEN_INT (INTVAL (operands[1]) & 0xff);
8393       return "test{l}\t{%1, %k0|%k0, %1}";
8394     }
8395   return "test{b}\t{%1, %0|%0, %1}";
8396 }
8397   [(set_attr "type" "test")
8398    (set_attr "modrm" "0,1,1,1")
8399    (set_attr "mode" "QI,QI,QI,SI")
8400    (set_attr "pent_pair" "uv,np,uv,np")])
8401
8402 (define_insn "*testqi_1"
8403   [(set (reg FLAGS_REG)
8404         (compare
8405           (and:QI
8406             (match_operand:QI 0 "nonimmediate_operand" "%!*a,q,qm")
8407             (match_operand:QI 1 "general_operand" "n,n,qn"))
8408           (const_int 0)))]
8409   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
8410    && ix86_match_ccmode (insn, CCNOmode)"
8411   "test{b}\t{%1, %0|%0, %1}"
8412   [(set_attr "type" "test")
8413    (set_attr "modrm" "0,1,1")
8414    (set_attr "mode" "QI")
8415    (set_attr "pent_pair" "uv,np,uv")])
8416
8417 (define_expand "testqi_ext_ccno_0"
8418   [(set (reg:CCNO FLAGS_REG)
8419         (compare:CCNO
8420           (and:SI
8421             (zero_extract:SI
8422               (match_operand 0 "ext_register_operand" "")
8423               (const_int 8)
8424               (const_int 8))
8425             (match_operand 1 "const_int_operand" ""))
8426           (const_int 0)))]
8427   ""
8428   "")
8429
8430 (define_insn "*testqi_ext_0"
8431   [(set (reg FLAGS_REG)
8432         (compare
8433           (and:SI
8434             (zero_extract:SI
8435               (match_operand 0 "ext_register_operand" "Q")
8436               (const_int 8)
8437               (const_int 8))
8438             (match_operand 1 "const_int_operand" "n"))
8439           (const_int 0)))]
8440   "ix86_match_ccmode (insn, CCNOmode)"
8441   "test{b}\t{%1, %h0|%h0, %1}"
8442   [(set_attr "type" "test")
8443    (set_attr "mode" "QI")
8444    (set_attr "length_immediate" "1")
8445    (set_attr "modrm" "1")
8446    (set_attr "pent_pair" "np")])
8447
8448 (define_insn "*testqi_ext_1"
8449   [(set (reg FLAGS_REG)
8450         (compare
8451           (and:SI
8452             (zero_extract:SI
8453               (match_operand 0 "ext_register_operand" "Q")
8454               (const_int 8)
8455               (const_int 8))
8456             (zero_extend:SI
8457               (match_operand:QI 1 "general_operand" "Qm")))
8458           (const_int 0)))]
8459   "!TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8460    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8461   "test{b}\t{%1, %h0|%h0, %1}"
8462   [(set_attr "type" "test")
8463    (set_attr "mode" "QI")])
8464
8465 (define_insn "*testqi_ext_1_rex64"
8466   [(set (reg FLAGS_REG)
8467         (compare
8468           (and:SI
8469             (zero_extract:SI
8470               (match_operand 0 "ext_register_operand" "Q")
8471               (const_int 8)
8472               (const_int 8))
8473             (zero_extend:SI
8474               (match_operand:QI 1 "register_operand" "Q")))
8475           (const_int 0)))]
8476   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
8477   "test{b}\t{%1, %h0|%h0, %1}"
8478   [(set_attr "type" "test")
8479    (set_attr "mode" "QI")])
8480
8481 (define_insn "*testqi_ext_2"
8482   [(set (reg FLAGS_REG)
8483         (compare
8484           (and:SI
8485             (zero_extract:SI
8486               (match_operand 0 "ext_register_operand" "Q")
8487               (const_int 8)
8488               (const_int 8))
8489             (zero_extract:SI
8490               (match_operand 1 "ext_register_operand" "Q")
8491               (const_int 8)
8492               (const_int 8)))
8493           (const_int 0)))]
8494   "ix86_match_ccmode (insn, CCNOmode)"
8495   "test{b}\t{%h1, %h0|%h0, %h1}"
8496   [(set_attr "type" "test")
8497    (set_attr "mode" "QI")])
8498
8499 ;; Combine likes to form bit extractions for some tests.  Humor it.
8500 (define_insn "*testqi_ext_3"
8501   [(set (reg FLAGS_REG)
8502         (compare (zero_extract:SI
8503                    (match_operand 0 "nonimmediate_operand" "rm")
8504                    (match_operand:SI 1 "const_int_operand" "")
8505                    (match_operand:SI 2 "const_int_operand" ""))
8506                  (const_int 0)))]
8507   "ix86_match_ccmode (insn, CCNOmode)
8508    && INTVAL (operands[1]) > 0
8509    && INTVAL (operands[2]) >= 0
8510    && INTVAL (operands[1]) + INTVAL (operands[2]) <= 32
8511    && (GET_MODE (operands[0]) == SImode
8512        || (TARGET_64BIT && GET_MODE (operands[0]) == DImode)
8513        || GET_MODE (operands[0]) == HImode
8514        || GET_MODE (operands[0]) == QImode)"
8515   "#")
8516
8517 (define_insn "*testqi_ext_3_rex64"
8518   [(set (reg FLAGS_REG)
8519         (compare (zero_extract:DI
8520                    (match_operand 0 "nonimmediate_operand" "rm")
8521                    (match_operand:DI 1 "const_int_operand" "")
8522                    (match_operand:DI 2 "const_int_operand" ""))
8523                  (const_int 0)))]
8524   "TARGET_64BIT
8525    && ix86_match_ccmode (insn, CCNOmode)
8526    && INTVAL (operands[1]) > 0
8527    && INTVAL (operands[2]) >= 0
8528    /* Ensure that resulting mask is zero or sign extended operand.  */
8529    && (INTVAL (operands[1]) + INTVAL (operands[2]) <= 32
8530        || (INTVAL (operands[1]) + INTVAL (operands[2]) == 64
8531            && INTVAL (operands[1]) > 32))
8532    && (GET_MODE (operands[0]) == SImode
8533        || GET_MODE (operands[0]) == DImode
8534        || GET_MODE (operands[0]) == HImode
8535        || GET_MODE (operands[0]) == QImode)"
8536   "#")
8537
8538 (define_split
8539   [(set (match_operand 0 "flags_reg_operand" "")
8540         (match_operator 1 "compare_operator"
8541           [(zero_extract
8542              (match_operand 2 "nonimmediate_operand" "")
8543              (match_operand 3 "const_int_operand" "")
8544              (match_operand 4 "const_int_operand" ""))
8545            (const_int 0)]))]
8546   "ix86_match_ccmode (insn, CCNOmode)"
8547   [(set (match_dup 0) (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
8548 {
8549   rtx val = operands[2];
8550   HOST_WIDE_INT len = INTVAL (operands[3]);
8551   HOST_WIDE_INT pos = INTVAL (operands[4]);
8552   HOST_WIDE_INT mask;
8553   enum machine_mode mode, submode;
8554
8555   mode = GET_MODE (val);
8556   if (MEM_P (val))
8557     {
8558       /* ??? Combine likes to put non-volatile mem extractions in QImode
8559          no matter the size of the test.  So find a mode that works.  */
8560       if (! MEM_VOLATILE_P (val))
8561         {
8562           mode = smallest_mode_for_size (pos + len, MODE_INT);
8563           val = adjust_address (val, mode, 0);
8564         }
8565     }
8566   else if (GET_CODE (val) == SUBREG
8567            && (submode = GET_MODE (SUBREG_REG (val)),
8568                GET_MODE_BITSIZE (mode) > GET_MODE_BITSIZE (submode))
8569            && pos + len <= GET_MODE_BITSIZE (submode))
8570     {
8571       /* Narrow a paradoxical subreg to prevent partial register stalls.  */
8572       mode = submode;
8573       val = SUBREG_REG (val);
8574     }
8575   else if (mode == HImode && pos + len <= 8)
8576     {
8577       /* Small HImode tests can be converted to QImode.  */
8578       mode = QImode;
8579       val = gen_lowpart (QImode, val);
8580     }
8581
8582   if (len == HOST_BITS_PER_WIDE_INT)
8583     mask = -1;
8584   else
8585     mask = ((HOST_WIDE_INT)1 << len) - 1;
8586   mask <<= pos;
8587
8588   operands[2] = gen_rtx_AND (mode, val, gen_int_mode (mask, mode));
8589 })
8590
8591 ;; Convert HImode/SImode test instructions with immediate to QImode ones.
8592 ;; i386 does not allow to encode test with 8bit sign extended immediate, so
8593 ;; this is relatively important trick.
8594 ;; Do the conversion only post-reload to avoid limiting of the register class
8595 ;; to QI regs.
8596 (define_split
8597   [(set (match_operand 0 "flags_reg_operand" "")
8598         (match_operator 1 "compare_operator"
8599           [(and (match_operand 2 "register_operand" "")
8600                 (match_operand 3 "const_int_operand" ""))
8601            (const_int 0)]))]
8602    "reload_completed
8603     && QI_REG_P (operands[2])
8604     && GET_MODE (operands[2]) != QImode
8605     && ((ix86_match_ccmode (insn, CCZmode)
8606          && !(INTVAL (operands[3]) & ~(255 << 8)))
8607         || (ix86_match_ccmode (insn, CCNOmode)
8608             && !(INTVAL (operands[3]) & ~(127 << 8))))"
8609   [(set (match_dup 0)
8610         (match_op_dup 1
8611           [(and:SI (zero_extract:SI (match_dup 2) (const_int 8) (const_int 8))
8612                    (match_dup 3))
8613            (const_int 0)]))]
8614   "operands[2] = gen_lowpart (SImode, operands[2]);
8615    operands[3] = gen_int_mode (INTVAL (operands[3]) >> 8, SImode);")
8616
8617 (define_split
8618   [(set (match_operand 0 "flags_reg_operand" "")
8619         (match_operator 1 "compare_operator"
8620           [(and (match_operand 2 "nonimmediate_operand" "")
8621                 (match_operand 3 "const_int_operand" ""))
8622            (const_int 0)]))]
8623    "reload_completed
8624     && GET_MODE (operands[2]) != QImode
8625     && (!REG_P (operands[2]) || ANY_QI_REG_P (operands[2]))
8626     && ((ix86_match_ccmode (insn, CCZmode)
8627          && !(INTVAL (operands[3]) & ~255))
8628         || (ix86_match_ccmode (insn, CCNOmode)
8629             && !(INTVAL (operands[3]) & ~127)))"
8630   [(set (match_dup 0)
8631         (match_op_dup 1 [(and:QI (match_dup 2) (match_dup 3))
8632                          (const_int 0)]))]
8633   "operands[2] = gen_lowpart (QImode, operands[2]);
8634    operands[3] = gen_lowpart (QImode, operands[3]);")
8635
8636
8637 ;; %%% This used to optimize known byte-wide and operations to memory,
8638 ;; and sometimes to QImode registers.  If this is considered useful,
8639 ;; it should be done with splitters.
8640
8641 (define_expand "anddi3"
8642   [(set (match_operand:DI 0 "nonimmediate_operand" "")
8643         (and:DI (match_operand:DI 1 "nonimmediate_operand" "")
8644                 (match_operand:DI 2 "x86_64_szext_general_operand" "")))]
8645   "TARGET_64BIT"
8646   "ix86_expand_binary_operator (AND, DImode, operands); DONE;")
8647
8648 (define_insn "*anddi_1_rex64"
8649   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,rm,r,r")
8650         (and:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0,0,qm")
8651                 (match_operand:DI 2 "x86_64_szext_general_operand" "Z,re,rm,L")))
8652    (clobber (reg:CC FLAGS_REG))]
8653   "TARGET_64BIT && ix86_binary_operator_ok (AND, DImode, operands)"
8654 {
8655   switch (get_attr_type (insn))
8656     {
8657     case TYPE_IMOVX:
8658       {
8659         enum machine_mode mode;
8660
8661         gcc_assert (CONST_INT_P (operands[2]));
8662         if (INTVAL (operands[2]) == 0xff)
8663           mode = QImode;
8664         else
8665           {
8666             gcc_assert (INTVAL (operands[2]) == 0xffff);
8667             mode = HImode;
8668           }
8669
8670         operands[1] = gen_lowpart (mode, operands[1]);
8671         if (mode == QImode)
8672           return "movz{bl|x}\t{%1, %k0|%k0, %1}";
8673         else
8674           return "movz{wl|x}\t{%1, %k0|%k0, %1}";
8675       }
8676
8677     default:
8678       gcc_assert (rtx_equal_p (operands[0], operands[1]));
8679       if (get_attr_mode (insn) == MODE_SI)
8680         return "and{l}\t{%k2, %k0|%k0, %k2}";
8681       else
8682         return "and{q}\t{%2, %0|%0, %2}";
8683     }
8684 }
8685   [(set_attr "type" "alu,alu,alu,imovx")
8686    (set_attr "length_immediate" "*,*,*,0")
8687    (set (attr "prefix_rex")
8688      (if_then_else
8689        (and (eq_attr "type" "imovx")
8690             (and (ne (symbol_ref "INTVAL (operands[2]) == 0xff") (const_int 0))
8691                  (match_operand 1 "ext_QIreg_nomode_operand" "")))
8692        (const_string "1")
8693        (const_string "*")))
8694    (set_attr "mode" "SI,DI,DI,SI")])
8695
8696 (define_insn "*anddi_2"
8697   [(set (reg FLAGS_REG)
8698         (compare (and:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0,0")
8699                          (match_operand:DI 2 "x86_64_szext_general_operand" "Z,rem,re"))
8700                  (const_int 0)))
8701    (set (match_operand:DI 0 "nonimmediate_operand" "=r,r,rm")
8702         (and:DI (match_dup 1) (match_dup 2)))]
8703   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8704    && ix86_binary_operator_ok (AND, DImode, operands)"
8705   "@
8706    and{l}\t{%k2, %k0|%k0, %k2}
8707    and{q}\t{%2, %0|%0, %2}
8708    and{q}\t{%2, %0|%0, %2}"
8709   [(set_attr "type" "alu")
8710    (set_attr "mode" "SI,DI,DI")])
8711
8712 (define_expand "andsi3"
8713   [(set (match_operand:SI 0 "nonimmediate_operand" "")
8714         (and:SI (match_operand:SI 1 "nonimmediate_operand" "")
8715                 (match_operand:SI 2 "general_operand" "")))]
8716   ""
8717   "ix86_expand_binary_operator (AND, SImode, operands); DONE;")
8718
8719 (define_insn "*andsi_1"
8720   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r,r")
8721         (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,qm")
8722                 (match_operand:SI 2 "general_operand" "ri,rm,L")))
8723    (clobber (reg:CC FLAGS_REG))]
8724   "ix86_binary_operator_ok (AND, SImode, operands)"
8725 {
8726   switch (get_attr_type (insn))
8727     {
8728     case TYPE_IMOVX:
8729       {
8730         enum machine_mode mode;
8731
8732         gcc_assert (CONST_INT_P (operands[2]));
8733         if (INTVAL (operands[2]) == 0xff)
8734           mode = QImode;
8735         else
8736           {
8737             gcc_assert (INTVAL (operands[2]) == 0xffff);
8738             mode = HImode;
8739           }
8740
8741         operands[1] = gen_lowpart (mode, operands[1]);
8742         if (mode == QImode)
8743           return "movz{bl|x}\t{%1, %0|%0, %1}";
8744         else
8745           return "movz{wl|x}\t{%1, %0|%0, %1}";
8746       }
8747
8748     default:
8749       gcc_assert (rtx_equal_p (operands[0], operands[1]));
8750       return "and{l}\t{%2, %0|%0, %2}";
8751     }
8752 }
8753   [(set_attr "type" "alu,alu,imovx")
8754    (set (attr "prefix_rex")
8755      (if_then_else
8756        (and (eq_attr "type" "imovx")
8757             (and (ne (symbol_ref "INTVAL (operands[2]) == 0xff") (const_int 0))
8758                  (match_operand 1 "ext_QIreg_nomode_operand" "")))
8759        (const_string "1")
8760        (const_string "*")))
8761    (set_attr "length_immediate" "*,*,0")
8762    (set_attr "mode" "SI")])
8763
8764 (define_split
8765   [(set (match_operand 0 "register_operand" "")
8766         (and (match_dup 0)
8767              (const_int -65536)))
8768    (clobber (reg:CC FLAGS_REG))]
8769   "optimize_function_for_size_p (cfun) || (TARGET_FAST_PREFIX && !TARGET_PARTIAL_REG_STALL)"
8770   [(set (strict_low_part (match_dup 1)) (const_int 0))]
8771   "operands[1] = gen_lowpart (HImode, operands[0]);")
8772
8773 (define_split
8774   [(set (match_operand 0 "ext_register_operand" "")
8775         (and (match_dup 0)
8776              (const_int -256)))
8777    (clobber (reg:CC FLAGS_REG))]
8778   "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_REG_STALL) && reload_completed"
8779   [(set (strict_low_part (match_dup 1)) (const_int 0))]
8780   "operands[1] = gen_lowpart (QImode, operands[0]);")
8781
8782 (define_split
8783   [(set (match_operand 0 "ext_register_operand" "")
8784         (and (match_dup 0)
8785              (const_int -65281)))
8786    (clobber (reg:CC FLAGS_REG))]
8787   "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_REG_STALL) && reload_completed"
8788   [(parallel [(set (zero_extract:SI (match_dup 0)
8789                                     (const_int 8)
8790                                     (const_int 8))
8791                    (xor:SI
8792                      (zero_extract:SI (match_dup 0)
8793                                       (const_int 8)
8794                                       (const_int 8))
8795                      (zero_extract:SI (match_dup 0)
8796                                       (const_int 8)
8797                                       (const_int 8))))
8798               (clobber (reg:CC FLAGS_REG))])]
8799   "operands[0] = gen_lowpart (SImode, operands[0]);")
8800
8801 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8802 (define_insn "*andsi_1_zext"
8803   [(set (match_operand:DI 0 "register_operand" "=r")
8804         (zero_extend:DI
8805           (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8806                   (match_operand:SI 2 "general_operand" "g"))))
8807    (clobber (reg:CC FLAGS_REG))]
8808   "TARGET_64BIT && ix86_binary_operator_ok (AND, SImode, operands)"
8809   "and{l}\t{%2, %k0|%k0, %2}"
8810   [(set_attr "type" "alu")
8811    (set_attr "mode" "SI")])
8812
8813 (define_insn "*andsi_2"
8814   [(set (reg FLAGS_REG)
8815         (compare (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
8816                          (match_operand:SI 2 "general_operand" "g,ri"))
8817                  (const_int 0)))
8818    (set (match_operand:SI 0 "nonimmediate_operand" "=r,rm")
8819         (and:SI (match_dup 1) (match_dup 2)))]
8820   "ix86_match_ccmode (insn, CCNOmode)
8821    && ix86_binary_operator_ok (AND, SImode, operands)"
8822   "and{l}\t{%2, %0|%0, %2}"
8823   [(set_attr "type" "alu")
8824    (set_attr "mode" "SI")])
8825
8826 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8827 (define_insn "*andsi_2_zext"
8828   [(set (reg FLAGS_REG)
8829         (compare (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8830                          (match_operand:SI 2 "general_operand" "g"))
8831                  (const_int 0)))
8832    (set (match_operand:DI 0 "register_operand" "=r")
8833         (zero_extend:DI (and:SI (match_dup 1) (match_dup 2))))]
8834   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8835    && ix86_binary_operator_ok (AND, SImode, operands)"
8836   "and{l}\t{%2, %k0|%k0, %2}"
8837   [(set_attr "type" "alu")
8838    (set_attr "mode" "SI")])
8839
8840 (define_expand "andhi3"
8841   [(set (match_operand:HI 0 "nonimmediate_operand" "")
8842         (and:HI (match_operand:HI 1 "nonimmediate_operand" "")
8843                 (match_operand:HI 2 "general_operand" "")))]
8844   "TARGET_HIMODE_MATH"
8845   "ix86_expand_binary_operator (AND, HImode, operands); DONE;")
8846
8847 (define_insn "*andhi_1"
8848   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r,r")
8849         (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,qm")
8850                 (match_operand:HI 2 "general_operand" "rn,rm,L")))
8851    (clobber (reg:CC FLAGS_REG))]
8852   "ix86_binary_operator_ok (AND, HImode, operands)"
8853 {
8854   switch (get_attr_type (insn))
8855     {
8856     case TYPE_IMOVX:
8857       gcc_assert (CONST_INT_P (operands[2]));
8858       gcc_assert (INTVAL (operands[2]) == 0xff);
8859       return "movz{bl|x}\t{%b1, %k0|%k0, %b1}";
8860
8861     default:
8862       gcc_assert (rtx_equal_p (operands[0], operands[1]));
8863
8864       return "and{w}\t{%2, %0|%0, %2}";
8865     }
8866 }
8867   [(set_attr "type" "alu,alu,imovx")
8868    (set_attr "length_immediate" "*,*,0")
8869    (set (attr "prefix_rex")
8870      (if_then_else
8871        (and (eq_attr "type" "imovx")
8872             (match_operand 1 "ext_QIreg_nomode_operand" ""))
8873        (const_string "1")
8874        (const_string "*")))
8875    (set_attr "mode" "HI,HI,SI")])
8876
8877 (define_insn "*andhi_2"
8878   [(set (reg FLAGS_REG)
8879         (compare (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
8880                          (match_operand:HI 2 "general_operand" "rmn,rn"))
8881                  (const_int 0)))
8882    (set (match_operand:HI 0 "nonimmediate_operand" "=r,rm")
8883         (and:HI (match_dup 1) (match_dup 2)))]
8884   "ix86_match_ccmode (insn, CCNOmode)
8885    && ix86_binary_operator_ok (AND, HImode, operands)"
8886   "and{w}\t{%2, %0|%0, %2}"
8887   [(set_attr "type" "alu")
8888    (set_attr "mode" "HI")])
8889
8890 (define_expand "andqi3"
8891   [(set (match_operand:QI 0 "nonimmediate_operand" "")
8892         (and:QI (match_operand:QI 1 "nonimmediate_operand" "")
8893                 (match_operand:QI 2 "general_operand" "")))]
8894   "TARGET_QIMODE_MATH"
8895   "ix86_expand_binary_operator (AND, QImode, operands); DONE;")
8896
8897 ;; %%% Potential partial reg stall on alternative 2.  What to do?
8898 (define_insn "*andqi_1"
8899   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q,r")
8900         (and:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
8901                 (match_operand:QI 2 "general_operand" "qn,qmn,rn")))
8902    (clobber (reg:CC FLAGS_REG))]
8903   "ix86_binary_operator_ok (AND, QImode, operands)"
8904   "@
8905    and{b}\t{%2, %0|%0, %2}
8906    and{b}\t{%2, %0|%0, %2}
8907    and{l}\t{%k2, %k0|%k0, %k2}"
8908   [(set_attr "type" "alu")
8909    (set_attr "mode" "QI,QI,SI")])
8910
8911 (define_insn "*andqi_1_slp"
8912   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
8913         (and:QI (match_dup 0)
8914                 (match_operand:QI 1 "general_operand" "qn,qmn")))
8915    (clobber (reg:CC FLAGS_REG))]
8916   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8917    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8918   "and{b}\t{%1, %0|%0, %1}"
8919   [(set_attr "type" "alu1")
8920    (set_attr "mode" "QI")])
8921
8922 (define_insn "*andqi_2_maybe_si"
8923   [(set (reg FLAGS_REG)
8924         (compare (and:QI
8925                       (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
8926                       (match_operand:QI 2 "general_operand" "qmn,qn,n"))
8927                  (const_int 0)))
8928    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm,*r")
8929         (and:QI (match_dup 1) (match_dup 2)))]
8930   "ix86_binary_operator_ok (AND, QImode, operands)
8931    && ix86_match_ccmode (insn,
8932                          CONST_INT_P (operands[2])
8933                          && INTVAL (operands[2]) >= 0 ? CCNOmode : CCZmode)"
8934 {
8935   if (which_alternative == 2)
8936     {
8937       if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) < 0)
8938         operands[2] = GEN_INT (INTVAL (operands[2]) & 0xff);
8939       return "and{l}\t{%2, %k0|%k0, %2}";
8940     }
8941   return "and{b}\t{%2, %0|%0, %2}";
8942 }
8943   [(set_attr "type" "alu")
8944    (set_attr "mode" "QI,QI,SI")])
8945
8946 (define_insn "*andqi_2"
8947   [(set (reg FLAGS_REG)
8948         (compare (and:QI
8949                    (match_operand:QI 1 "nonimmediate_operand" "%0,0")
8950                    (match_operand:QI 2 "general_operand" "qmn,qn"))
8951                  (const_int 0)))
8952    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm")
8953         (and:QI (match_dup 1) (match_dup 2)))]
8954   "ix86_match_ccmode (insn, CCNOmode)
8955    && ix86_binary_operator_ok (AND, QImode, operands)"
8956   "and{b}\t{%2, %0|%0, %2}"
8957   [(set_attr "type" "alu")
8958    (set_attr "mode" "QI")])
8959
8960 (define_insn "*andqi_2_slp"
8961   [(set (reg FLAGS_REG)
8962         (compare (and:QI
8963                    (match_operand:QI 0 "nonimmediate_operand" "+q,qm")
8964                    (match_operand:QI 1 "nonimmediate_operand" "qmn,qn"))
8965                  (const_int 0)))
8966    (set (strict_low_part (match_dup 0))
8967         (and:QI (match_dup 0) (match_dup 1)))]
8968   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8969    && ix86_match_ccmode (insn, CCNOmode)
8970    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8971   "and{b}\t{%1, %0|%0, %1}"
8972   [(set_attr "type" "alu1")
8973    (set_attr "mode" "QI")])
8974
8975 ;; ??? A bug in recog prevents it from recognizing a const_int as an
8976 ;; operand to zero_extend in andqi_ext_1.  It was checking explicitly
8977 ;; for a QImode operand, which of course failed.
8978
8979 (define_insn "andqi_ext_0"
8980   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8981                          (const_int 8)
8982                          (const_int 8))
8983         (and:SI
8984           (zero_extract:SI
8985             (match_operand 1 "ext_register_operand" "0")
8986             (const_int 8)
8987             (const_int 8))
8988           (match_operand 2 "const_int_operand" "n")))
8989    (clobber (reg:CC FLAGS_REG))]
8990   ""
8991   "and{b}\t{%2, %h0|%h0, %2}"
8992   [(set_attr "type" "alu")
8993    (set_attr "length_immediate" "1")
8994    (set_attr "modrm" "1")
8995    (set_attr "mode" "QI")])
8996
8997 ;; Generated by peephole translating test to and.  This shows up
8998 ;; often in fp comparisons.
8999
9000 (define_insn "*andqi_ext_0_cc"
9001   [(set (reg FLAGS_REG)
9002         (compare
9003           (and:SI
9004             (zero_extract:SI
9005               (match_operand 1 "ext_register_operand" "0")
9006               (const_int 8)
9007               (const_int 8))
9008             (match_operand 2 "const_int_operand" "n"))
9009           (const_int 0)))
9010    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9011                          (const_int 8)
9012                          (const_int 8))
9013         (and:SI
9014           (zero_extract:SI
9015             (match_dup 1)
9016             (const_int 8)
9017             (const_int 8))
9018           (match_dup 2)))]
9019   "ix86_match_ccmode (insn, CCNOmode)"
9020   "and{b}\t{%2, %h0|%h0, %2}"
9021   [(set_attr "type" "alu")
9022    (set_attr "length_immediate" "1")
9023    (set_attr "modrm" "1")
9024    (set_attr "mode" "QI")])
9025
9026 (define_insn "*andqi_ext_1"
9027   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9028                          (const_int 8)
9029                          (const_int 8))
9030         (and:SI
9031           (zero_extract:SI
9032             (match_operand 1 "ext_register_operand" "0")
9033             (const_int 8)
9034             (const_int 8))
9035           (zero_extend:SI
9036             (match_operand:QI 2 "general_operand" "Qm"))))
9037    (clobber (reg:CC FLAGS_REG))]
9038   "!TARGET_64BIT"
9039   "and{b}\t{%2, %h0|%h0, %2}"
9040   [(set_attr "type" "alu")
9041    (set_attr "length_immediate" "0")
9042    (set_attr "mode" "QI")])
9043
9044 (define_insn "*andqi_ext_1_rex64"
9045   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9046                          (const_int 8)
9047                          (const_int 8))
9048         (and:SI
9049           (zero_extract:SI
9050             (match_operand 1 "ext_register_operand" "0")
9051             (const_int 8)
9052             (const_int 8))
9053           (zero_extend:SI
9054             (match_operand 2 "ext_register_operand" "Q"))))
9055    (clobber (reg:CC FLAGS_REG))]
9056   "TARGET_64BIT"
9057   "and{b}\t{%2, %h0|%h0, %2}"
9058   [(set_attr "type" "alu")
9059    (set_attr "length_immediate" "0")
9060    (set_attr "mode" "QI")])
9061
9062 (define_insn "*andqi_ext_2"
9063   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9064                          (const_int 8)
9065                          (const_int 8))
9066         (and:SI
9067           (zero_extract:SI
9068             (match_operand 1 "ext_register_operand" "%0")
9069             (const_int 8)
9070             (const_int 8))
9071           (zero_extract:SI
9072             (match_operand 2 "ext_register_operand" "Q")
9073             (const_int 8)
9074             (const_int 8))))
9075    (clobber (reg:CC FLAGS_REG))]
9076   ""
9077   "and{b}\t{%h2, %h0|%h0, %h2}"
9078   [(set_attr "type" "alu")
9079    (set_attr "length_immediate" "0")
9080    (set_attr "mode" "QI")])
9081
9082 ;; Convert wide AND instructions with immediate operand to shorter QImode
9083 ;; equivalents when possible.
9084 ;; Don't do the splitting with memory operands, since it introduces risk
9085 ;; of memory mismatch stalls.  We may want to do the splitting for optimizing
9086 ;; for size, but that can (should?) be handled by generic code instead.
9087 (define_split
9088   [(set (match_operand 0 "register_operand" "")
9089         (and (match_operand 1 "register_operand" "")
9090              (match_operand 2 "const_int_operand" "")))
9091    (clobber (reg:CC FLAGS_REG))]
9092    "reload_completed
9093     && QI_REG_P (operands[0])
9094     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
9095     && !(~INTVAL (operands[2]) & ~(255 << 8))
9096     && GET_MODE (operands[0]) != QImode"
9097   [(parallel [(set (zero_extract:SI (match_dup 0) (const_int 8) (const_int 8))
9098                    (and:SI (zero_extract:SI (match_dup 1)
9099                                             (const_int 8) (const_int 8))
9100                            (match_dup 2)))
9101               (clobber (reg:CC FLAGS_REG))])]
9102   "operands[0] = gen_lowpart (SImode, operands[0]);
9103    operands[1] = gen_lowpart (SImode, operands[1]);
9104    operands[2] = gen_int_mode ((INTVAL (operands[2]) >> 8) & 0xff, SImode);")
9105
9106 ;; Since AND can be encoded with sign extended immediate, this is only
9107 ;; profitable when 7th bit is not set.
9108 (define_split
9109   [(set (match_operand 0 "register_operand" "")
9110         (and (match_operand 1 "general_operand" "")
9111              (match_operand 2 "const_int_operand" "")))
9112    (clobber (reg:CC FLAGS_REG))]
9113    "reload_completed
9114     && ANY_QI_REG_P (operands[0])
9115     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
9116     && !(~INTVAL (operands[2]) & ~255)
9117     && !(INTVAL (operands[2]) & 128)
9118     && GET_MODE (operands[0]) != QImode"
9119   [(parallel [(set (strict_low_part (match_dup 0))
9120                    (and:QI (match_dup 1)
9121                            (match_dup 2)))
9122               (clobber (reg:CC FLAGS_REG))])]
9123   "operands[0] = gen_lowpart (QImode, operands[0]);
9124    operands[1] = gen_lowpart (QImode, operands[1]);
9125    operands[2] = gen_lowpart (QImode, operands[2]);")
9126 \f
9127 ;; Logical inclusive OR instructions
9128
9129 ;; %%% This used to optimize known byte-wide and operations to memory.
9130 ;; If this is considered useful, it should be done with splitters.
9131
9132 (define_expand "iordi3"
9133   [(set (match_operand:DI 0 "nonimmediate_operand" "")
9134         (ior:DI (match_operand:DI 1 "nonimmediate_operand" "")
9135                 (match_operand:DI 2 "x86_64_general_operand" "")))]
9136   "TARGET_64BIT"
9137   "ix86_expand_binary_operator (IOR, DImode, operands); DONE;")
9138
9139 (define_insn "*iordi_1_rex64"
9140   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
9141         (ior:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
9142                 (match_operand:DI 2 "x86_64_general_operand" "re,rme")))
9143    (clobber (reg:CC FLAGS_REG))]
9144   "TARGET_64BIT
9145    && ix86_binary_operator_ok (IOR, DImode, operands)"
9146   "or{q}\t{%2, %0|%0, %2}"
9147   [(set_attr "type" "alu")
9148    (set_attr "mode" "DI")])
9149
9150 (define_insn "*iordi_2_rex64"
9151   [(set (reg FLAGS_REG)
9152         (compare (ior:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
9153                          (match_operand:DI 2 "x86_64_general_operand" "rem,re"))
9154                  (const_int 0)))
9155    (set (match_operand:DI 0 "nonimmediate_operand" "=r,rm")
9156         (ior:DI (match_dup 1) (match_dup 2)))]
9157   "TARGET_64BIT
9158    && ix86_match_ccmode (insn, CCNOmode)
9159    && ix86_binary_operator_ok (IOR, DImode, operands)"
9160   "or{q}\t{%2, %0|%0, %2}"
9161   [(set_attr "type" "alu")
9162    (set_attr "mode" "DI")])
9163
9164 (define_insn "*iordi_3_rex64"
9165   [(set (reg FLAGS_REG)
9166         (compare (ior:DI (match_operand:DI 1 "nonimmediate_operand" "%0")
9167                          (match_operand:DI 2 "x86_64_general_operand" "rem"))
9168                  (const_int 0)))
9169    (clobber (match_scratch:DI 0 "=r"))]
9170   "TARGET_64BIT
9171    && ix86_match_ccmode (insn, CCNOmode)
9172    && ix86_binary_operator_ok (IOR, DImode, operands)"
9173   "or{q}\t{%2, %0|%0, %2}"
9174   [(set_attr "type" "alu")
9175    (set_attr "mode" "DI")])
9176
9177
9178 (define_expand "iorsi3"
9179   [(set (match_operand:SI 0 "nonimmediate_operand" "")
9180         (ior:SI (match_operand:SI 1 "nonimmediate_operand" "")
9181                 (match_operand:SI 2 "general_operand" "")))]
9182   ""
9183   "ix86_expand_binary_operator (IOR, SImode, operands); DONE;")
9184
9185 (define_insn "*iorsi_1"
9186   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
9187         (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
9188                 (match_operand:SI 2 "general_operand" "ri,g")))
9189    (clobber (reg:CC FLAGS_REG))]
9190   "ix86_binary_operator_ok (IOR, SImode, operands)"
9191   "or{l}\t{%2, %0|%0, %2}"
9192   [(set_attr "type" "alu")
9193    (set_attr "mode" "SI")])
9194
9195 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
9196 (define_insn "*iorsi_1_zext"
9197   [(set (match_operand:DI 0 "register_operand" "=r")
9198         (zero_extend:DI
9199           (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
9200                   (match_operand:SI 2 "general_operand" "g"))))
9201    (clobber (reg:CC FLAGS_REG))]
9202   "TARGET_64BIT && ix86_binary_operator_ok (IOR, SImode, operands)"
9203   "or{l}\t{%2, %k0|%k0, %2}"
9204   [(set_attr "type" "alu")
9205    (set_attr "mode" "SI")])
9206
9207 (define_insn "*iorsi_1_zext_imm"
9208   [(set (match_operand:DI 0 "register_operand" "=r")
9209         (ior:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "%0"))
9210                 (match_operand:DI 2 "x86_64_zext_immediate_operand" "Z")))
9211    (clobber (reg:CC FLAGS_REG))]
9212   "TARGET_64BIT"
9213   "or{l}\t{%2, %k0|%k0, %2}"
9214   [(set_attr "type" "alu")
9215    (set_attr "mode" "SI")])
9216
9217 (define_insn "*iorsi_2"
9218   [(set (reg FLAGS_REG)
9219         (compare (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
9220                          (match_operand:SI 2 "general_operand" "g,ri"))
9221                  (const_int 0)))
9222    (set (match_operand:SI 0 "nonimmediate_operand" "=r,rm")
9223         (ior:SI (match_dup 1) (match_dup 2)))]
9224   "ix86_match_ccmode (insn, CCNOmode)
9225    && ix86_binary_operator_ok (IOR, SImode, operands)"
9226   "or{l}\t{%2, %0|%0, %2}"
9227   [(set_attr "type" "alu")
9228    (set_attr "mode" "SI")])
9229
9230 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
9231 ;; ??? Special case for immediate operand is missing - it is tricky.
9232 (define_insn "*iorsi_2_zext"
9233   [(set (reg FLAGS_REG)
9234         (compare (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
9235                          (match_operand:SI 2 "general_operand" "g"))
9236                  (const_int 0)))
9237    (set (match_operand:DI 0 "register_operand" "=r")
9238         (zero_extend:DI (ior:SI (match_dup 1) (match_dup 2))))]
9239   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
9240    && ix86_binary_operator_ok (IOR, SImode, operands)"
9241   "or{l}\t{%2, %k0|%k0, %2}"
9242   [(set_attr "type" "alu")
9243    (set_attr "mode" "SI")])
9244
9245 (define_insn "*iorsi_2_zext_imm"
9246   [(set (reg FLAGS_REG)
9247         (compare (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
9248                          (match_operand 2 "x86_64_zext_immediate_operand" "Z"))
9249                  (const_int 0)))
9250    (set (match_operand:DI 0 "register_operand" "=r")
9251         (ior:DI (zero_extend:DI (match_dup 1)) (match_dup 2)))]
9252   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
9253    && ix86_binary_operator_ok (IOR, SImode, operands)"
9254   "or{l}\t{%2, %k0|%k0, %2}"
9255   [(set_attr "type" "alu")
9256    (set_attr "mode" "SI")])
9257
9258 (define_insn "*iorsi_3"
9259   [(set (reg FLAGS_REG)
9260         (compare (ior:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
9261                          (match_operand:SI 2 "general_operand" "g"))
9262                  (const_int 0)))
9263    (clobber (match_scratch:SI 0 "=r"))]
9264   "ix86_match_ccmode (insn, CCNOmode)
9265    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
9266   "or{l}\t{%2, %0|%0, %2}"
9267   [(set_attr "type" "alu")
9268    (set_attr "mode" "SI")])
9269
9270 (define_expand "iorhi3"
9271   [(set (match_operand:HI 0 "nonimmediate_operand" "")
9272         (ior:HI (match_operand:HI 1 "nonimmediate_operand" "")
9273                 (match_operand:HI 2 "general_operand" "")))]
9274   "TARGET_HIMODE_MATH"
9275   "ix86_expand_binary_operator (IOR, HImode, operands); DONE;")
9276
9277 (define_insn "*iorhi_1"
9278   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,m")
9279         (ior:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
9280                 (match_operand:HI 2 "general_operand" "rmn,rn")))
9281    (clobber (reg:CC FLAGS_REG))]
9282   "ix86_binary_operator_ok (IOR, HImode, operands)"
9283   "or{w}\t{%2, %0|%0, %2}"
9284   [(set_attr "type" "alu")
9285    (set_attr "mode" "HI")])
9286
9287 (define_insn "*iorhi_2"
9288   [(set (reg FLAGS_REG)
9289         (compare (ior:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
9290                          (match_operand:HI 2 "general_operand" "rmn,rn"))
9291                  (const_int 0)))
9292    (set (match_operand:HI 0 "nonimmediate_operand" "=r,rm")
9293         (ior:HI (match_dup 1) (match_dup 2)))]
9294   "ix86_match_ccmode (insn, CCNOmode)
9295    && ix86_binary_operator_ok (IOR, HImode, operands)"
9296   "or{w}\t{%2, %0|%0, %2}"
9297   [(set_attr "type" "alu")
9298    (set_attr "mode" "HI")])
9299
9300 (define_insn "*iorhi_3"
9301   [(set (reg FLAGS_REG)
9302         (compare (ior:HI (match_operand:HI 1 "nonimmediate_operand" "%0")
9303                          (match_operand:HI 2 "general_operand" "rmn"))
9304                  (const_int 0)))
9305    (clobber (match_scratch:HI 0 "=r"))]
9306   "ix86_match_ccmode (insn, CCNOmode)
9307    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
9308   "or{w}\t{%2, %0|%0, %2}"
9309   [(set_attr "type" "alu")
9310    (set_attr "mode" "HI")])
9311
9312 (define_expand "iorqi3"
9313   [(set (match_operand:QI 0 "nonimmediate_operand" "")
9314         (ior:QI (match_operand:QI 1 "nonimmediate_operand" "")
9315                 (match_operand:QI 2 "general_operand" "")))]
9316   "TARGET_QIMODE_MATH"
9317   "ix86_expand_binary_operator (IOR, QImode, operands); DONE;")
9318
9319 ;; %%% Potential partial reg stall on alternative 2.  What to do?
9320 (define_insn "*iorqi_1"
9321   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,m,r")
9322         (ior:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
9323                 (match_operand:QI 2 "general_operand" "qmn,qn,rn")))
9324    (clobber (reg:CC FLAGS_REG))]
9325   "ix86_binary_operator_ok (IOR, QImode, operands)"
9326   "@
9327    or{b}\t{%2, %0|%0, %2}
9328    or{b}\t{%2, %0|%0, %2}
9329    or{l}\t{%k2, %k0|%k0, %k2}"
9330   [(set_attr "type" "alu")
9331    (set_attr "mode" "QI,QI,SI")])
9332
9333 (define_insn "*iorqi_1_slp"
9334   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+q,m"))
9335         (ior:QI (match_dup 0)
9336                 (match_operand:QI 1 "general_operand" "qmn,qn")))
9337    (clobber (reg:CC FLAGS_REG))]
9338   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
9339    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
9340   "or{b}\t{%1, %0|%0, %1}"
9341   [(set_attr "type" "alu1")
9342    (set_attr "mode" "QI")])
9343
9344 (define_insn "*iorqi_2"
9345   [(set (reg FLAGS_REG)
9346         (compare (ior:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0")
9347                          (match_operand:QI 2 "general_operand" "qmn,qn"))
9348                  (const_int 0)))
9349    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm")
9350         (ior:QI (match_dup 1) (match_dup 2)))]
9351   "ix86_match_ccmode (insn, CCNOmode)
9352    && ix86_binary_operator_ok (IOR, QImode, operands)"
9353   "or{b}\t{%2, %0|%0, %2}"
9354   [(set_attr "type" "alu")
9355    (set_attr "mode" "QI")])
9356
9357 (define_insn "*iorqi_2_slp"
9358   [(set (reg FLAGS_REG)
9359         (compare (ior:QI (match_operand:QI 0 "nonimmediate_operand" "+q,qm")
9360                          (match_operand:QI 1 "general_operand" "qmn,qn"))
9361                  (const_int 0)))
9362    (set (strict_low_part (match_dup 0))
9363         (ior:QI (match_dup 0) (match_dup 1)))]
9364   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
9365    && ix86_match_ccmode (insn, CCNOmode)
9366    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
9367   "or{b}\t{%1, %0|%0, %1}"
9368   [(set_attr "type" "alu1")
9369    (set_attr "mode" "QI")])
9370
9371 (define_insn "*iorqi_3"
9372   [(set (reg FLAGS_REG)
9373         (compare (ior:QI (match_operand:QI 1 "nonimmediate_operand" "%0")
9374                          (match_operand:QI 2 "general_operand" "qmn"))
9375                  (const_int 0)))
9376    (clobber (match_scratch:QI 0 "=q"))]
9377   "ix86_match_ccmode (insn, CCNOmode)
9378    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
9379   "or{b}\t{%2, %0|%0, %2}"
9380   [(set_attr "type" "alu")
9381    (set_attr "mode" "QI")])
9382
9383 (define_insn "*iorqi_ext_0"
9384   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9385                          (const_int 8)
9386                          (const_int 8))
9387         (ior:SI
9388           (zero_extract:SI
9389             (match_operand 1 "ext_register_operand" "0")
9390             (const_int 8)
9391             (const_int 8))
9392           (match_operand 2 "const_int_operand" "n")))
9393    (clobber (reg:CC FLAGS_REG))]
9394   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))"
9395   "or{b}\t{%2, %h0|%h0, %2}"
9396   [(set_attr "type" "alu")
9397    (set_attr "length_immediate" "1")
9398    (set_attr "modrm" "1")
9399    (set_attr "mode" "QI")])
9400
9401 (define_insn "*iorqi_ext_1"
9402   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9403                          (const_int 8)
9404                          (const_int 8))
9405         (ior:SI
9406           (zero_extract:SI
9407             (match_operand 1 "ext_register_operand" "0")
9408             (const_int 8)
9409             (const_int 8))
9410           (zero_extend:SI
9411             (match_operand:QI 2 "general_operand" "Qm"))))
9412    (clobber (reg:CC FLAGS_REG))]
9413   "!TARGET_64BIT
9414    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))"
9415   "or{b}\t{%2, %h0|%h0, %2}"
9416   [(set_attr "type" "alu")
9417    (set_attr "length_immediate" "0")
9418    (set_attr "mode" "QI")])
9419
9420 (define_insn "*iorqi_ext_1_rex64"
9421   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9422                          (const_int 8)
9423                          (const_int 8))
9424         (ior:SI
9425           (zero_extract:SI
9426             (match_operand 1 "ext_register_operand" "0")
9427             (const_int 8)
9428             (const_int 8))
9429           (zero_extend:SI
9430             (match_operand 2 "ext_register_operand" "Q"))))
9431    (clobber (reg:CC FLAGS_REG))]
9432   "TARGET_64BIT
9433    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))"
9434   "or{b}\t{%2, %h0|%h0, %2}"
9435   [(set_attr "type" "alu")
9436    (set_attr "length_immediate" "0")
9437    (set_attr "mode" "QI")])
9438
9439 (define_insn "*iorqi_ext_2"
9440   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9441                          (const_int 8)
9442                          (const_int 8))
9443         (ior:SI
9444           (zero_extract:SI (match_operand 1 "ext_register_operand" "0")
9445                            (const_int 8)
9446                            (const_int 8))
9447           (zero_extract:SI (match_operand 2 "ext_register_operand" "Q")
9448                            (const_int 8)
9449                            (const_int 8))))
9450    (clobber (reg:CC FLAGS_REG))]
9451   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))"
9452   "ior{b}\t{%h2, %h0|%h0, %h2}"
9453   [(set_attr "type" "alu")
9454    (set_attr "length_immediate" "0")
9455    (set_attr "mode" "QI")])
9456
9457 (define_split
9458   [(set (match_operand 0 "register_operand" "")
9459         (ior (match_operand 1 "register_operand" "")
9460              (match_operand 2 "const_int_operand" "")))
9461    (clobber (reg:CC FLAGS_REG))]
9462    "reload_completed
9463     && QI_REG_P (operands[0])
9464     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
9465     && !(INTVAL (operands[2]) & ~(255 << 8))
9466     && GET_MODE (operands[0]) != QImode"
9467   [(parallel [(set (zero_extract:SI (match_dup 0) (const_int 8) (const_int 8))
9468                    (ior:SI (zero_extract:SI (match_dup 1)
9469                                             (const_int 8) (const_int 8))
9470                            (match_dup 2)))
9471               (clobber (reg:CC FLAGS_REG))])]
9472   "operands[0] = gen_lowpart (SImode, operands[0]);
9473    operands[1] = gen_lowpart (SImode, operands[1]);
9474    operands[2] = gen_int_mode ((INTVAL (operands[2]) >> 8) & 0xff, SImode);")
9475
9476 ;; Since OR can be encoded with sign extended immediate, this is only
9477 ;; profitable when 7th bit is set.
9478 (define_split
9479   [(set (match_operand 0 "register_operand" "")
9480         (ior (match_operand 1 "general_operand" "")
9481              (match_operand 2 "const_int_operand" "")))
9482    (clobber (reg:CC FLAGS_REG))]
9483    "reload_completed
9484     && ANY_QI_REG_P (operands[0])
9485     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
9486     && !(INTVAL (operands[2]) & ~255)
9487     && (INTVAL (operands[2]) & 128)
9488     && GET_MODE (operands[0]) != QImode"
9489   [(parallel [(set (strict_low_part (match_dup 0))
9490                    (ior:QI (match_dup 1)
9491                            (match_dup 2)))
9492               (clobber (reg:CC FLAGS_REG))])]
9493   "operands[0] = gen_lowpart (QImode, operands[0]);
9494    operands[1] = gen_lowpart (QImode, operands[1]);
9495    operands[2] = gen_lowpart (QImode, operands[2]);")
9496 \f
9497 ;; Logical XOR instructions
9498
9499 ;; %%% This used to optimize known byte-wide and operations to memory.
9500 ;; If this is considered useful, it should be done with splitters.
9501
9502 (define_expand "xordi3"
9503   [(set (match_operand:DI 0 "nonimmediate_operand" "")
9504         (xor:DI (match_operand:DI 1 "nonimmediate_operand" "")
9505                 (match_operand:DI 2 "x86_64_general_operand" "")))]
9506   "TARGET_64BIT"
9507   "ix86_expand_binary_operator (XOR, DImode, operands); DONE;")
9508
9509 (define_insn "*xordi_1_rex64"
9510   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
9511         (xor:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
9512                 (match_operand:DI 2 "x86_64_general_operand" "re,rm")))
9513    (clobber (reg:CC FLAGS_REG))]
9514   "TARGET_64BIT
9515    && ix86_binary_operator_ok (XOR, DImode, operands)"
9516   "xor{q}\t{%2, %0|%0, %2}"
9517   [(set_attr "type" "alu")
9518    (set_attr "mode" "DI")])
9519
9520 (define_insn "*xordi_2_rex64"
9521   [(set (reg FLAGS_REG)
9522         (compare (xor:DI (match_operand:DI 1 "nonimmediate_operand" "%0,0")
9523                          (match_operand:DI 2 "x86_64_general_operand" "rem,re"))
9524                  (const_int 0)))
9525    (set (match_operand:DI 0 "nonimmediate_operand" "=r,rm")
9526         (xor:DI (match_dup 1) (match_dup 2)))]
9527   "TARGET_64BIT
9528    && ix86_match_ccmode (insn, CCNOmode)
9529    && ix86_binary_operator_ok (XOR, DImode, operands)"
9530   "xor{q}\t{%2, %0|%0, %2}"
9531   [(set_attr "type" "alu")
9532    (set_attr "mode" "DI")])
9533
9534 (define_insn "*xordi_3_rex64"
9535   [(set (reg FLAGS_REG)
9536         (compare (xor:DI (match_operand:DI 1 "nonimmediate_operand" "%0")
9537                          (match_operand:DI 2 "x86_64_general_operand" "rem"))
9538                  (const_int 0)))
9539    (clobber (match_scratch:DI 0 "=r"))]
9540   "TARGET_64BIT
9541    && ix86_match_ccmode (insn, CCNOmode)
9542    && ix86_binary_operator_ok (XOR, DImode, operands)"
9543   "xor{q}\t{%2, %0|%0, %2}"
9544   [(set_attr "type" "alu")
9545    (set_attr "mode" "DI")])
9546
9547 (define_expand "xorsi3"
9548   [(set (match_operand:SI 0 "nonimmediate_operand" "")
9549         (xor:SI (match_operand:SI 1 "nonimmediate_operand" "")
9550                 (match_operand:SI 2 "general_operand" "")))]
9551   ""
9552   "ix86_expand_binary_operator (XOR, SImode, operands); DONE;")
9553
9554 (define_insn "*xorsi_1"
9555   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
9556         (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
9557                 (match_operand:SI 2 "general_operand" "ri,rm")))
9558    (clobber (reg:CC FLAGS_REG))]
9559   "ix86_binary_operator_ok (XOR, SImode, operands)"
9560   "xor{l}\t{%2, %0|%0, %2}"
9561   [(set_attr "type" "alu")
9562    (set_attr "mode" "SI")])
9563
9564 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
9565 ;; Add speccase for immediates
9566 (define_insn "*xorsi_1_zext"
9567   [(set (match_operand:DI 0 "register_operand" "=r")
9568         (zero_extend:DI
9569           (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
9570                   (match_operand:SI 2 "general_operand" "g"))))
9571    (clobber (reg:CC FLAGS_REG))]
9572   "TARGET_64BIT && ix86_binary_operator_ok (XOR, SImode, operands)"
9573   "xor{l}\t{%2, %k0|%k0, %2}"
9574   [(set_attr "type" "alu")
9575    (set_attr "mode" "SI")])
9576
9577 (define_insn "*xorsi_1_zext_imm"
9578   [(set (match_operand:DI 0 "register_operand" "=r")
9579         (xor:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "%0"))
9580                 (match_operand:DI 2 "x86_64_zext_immediate_operand" "Z")))
9581    (clobber (reg:CC FLAGS_REG))]
9582   "TARGET_64BIT && ix86_binary_operator_ok (XOR, SImode, operands)"
9583   "xor{l}\t{%2, %k0|%k0, %2}"
9584   [(set_attr "type" "alu")
9585    (set_attr "mode" "SI")])
9586
9587 (define_insn "*xorsi_2"
9588   [(set (reg FLAGS_REG)
9589         (compare (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0")
9590                          (match_operand:SI 2 "general_operand" "g,ri"))
9591                  (const_int 0)))
9592    (set (match_operand:SI 0 "nonimmediate_operand" "=r,rm")
9593         (xor:SI (match_dup 1) (match_dup 2)))]
9594   "ix86_match_ccmode (insn, CCNOmode)
9595    && ix86_binary_operator_ok (XOR, SImode, operands)"
9596   "xor{l}\t{%2, %0|%0, %2}"
9597   [(set_attr "type" "alu")
9598    (set_attr "mode" "SI")])
9599
9600 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
9601 ;; ??? Special case for immediate operand is missing - it is tricky.
9602 (define_insn "*xorsi_2_zext"
9603   [(set (reg FLAGS_REG)
9604         (compare (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
9605                          (match_operand:SI 2 "general_operand" "g"))
9606                  (const_int 0)))
9607    (set (match_operand:DI 0 "register_operand" "=r")
9608         (zero_extend:DI (xor:SI (match_dup 1) (match_dup 2))))]
9609   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
9610    && ix86_binary_operator_ok (XOR, SImode, operands)"
9611   "xor{l}\t{%2, %k0|%k0, %2}"
9612   [(set_attr "type" "alu")
9613    (set_attr "mode" "SI")])
9614
9615 (define_insn "*xorsi_2_zext_imm"
9616   [(set (reg FLAGS_REG)
9617         (compare (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
9618                          (match_operand 2 "x86_64_zext_immediate_operand" "Z"))
9619                  (const_int 0)))
9620    (set (match_operand:DI 0 "register_operand" "=r")
9621         (xor:DI (zero_extend:DI (match_dup 1)) (match_dup 2)))]
9622   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
9623    && ix86_binary_operator_ok (XOR, SImode, operands)"
9624   "xor{l}\t{%2, %k0|%k0, %2}"
9625   [(set_attr "type" "alu")
9626    (set_attr "mode" "SI")])
9627
9628 (define_insn "*xorsi_3"
9629   [(set (reg FLAGS_REG)
9630         (compare (xor:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
9631                          (match_operand:SI 2 "general_operand" "g"))
9632                  (const_int 0)))
9633    (clobber (match_scratch:SI 0 "=r"))]
9634   "ix86_match_ccmode (insn, CCNOmode)
9635    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
9636   "xor{l}\t{%2, %0|%0, %2}"
9637   [(set_attr "type" "alu")
9638    (set_attr "mode" "SI")])
9639
9640 (define_expand "xorhi3"
9641   [(set (match_operand:HI 0 "nonimmediate_operand" "")
9642         (xor:HI (match_operand:HI 1 "nonimmediate_operand" "")
9643                 (match_operand:HI 2 "general_operand" "")))]
9644   "TARGET_HIMODE_MATH"
9645   "ix86_expand_binary_operator (XOR, HImode, operands); DONE;")
9646
9647 (define_insn "*xorhi_1"
9648   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,m")
9649         (xor:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
9650                 (match_operand:HI 2 "general_operand" "rmn,rn")))
9651    (clobber (reg:CC FLAGS_REG))]
9652   "ix86_binary_operator_ok (XOR, HImode, operands)"
9653   "xor{w}\t{%2, %0|%0, %2}"
9654   [(set_attr "type" "alu")
9655    (set_attr "mode" "HI")])
9656
9657 (define_insn "*xorhi_2"
9658   [(set (reg FLAGS_REG)
9659         (compare (xor:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
9660                          (match_operand:HI 2 "general_operand" "rmn,rn"))
9661                  (const_int 0)))
9662    (set (match_operand:HI 0 "nonimmediate_operand" "=r,rm")
9663         (xor:HI (match_dup 1) (match_dup 2)))]
9664   "ix86_match_ccmode (insn, CCNOmode)
9665    && ix86_binary_operator_ok (XOR, HImode, operands)"
9666   "xor{w}\t{%2, %0|%0, %2}"
9667   [(set_attr "type" "alu")
9668    (set_attr "mode" "HI")])
9669
9670 (define_insn "*xorhi_3"
9671   [(set (reg FLAGS_REG)
9672         (compare (xor:HI (match_operand:HI 1 "nonimmediate_operand" "%0")
9673                          (match_operand:HI 2 "general_operand" "rmn"))
9674                  (const_int 0)))
9675    (clobber (match_scratch:HI 0 "=r"))]
9676   "ix86_match_ccmode (insn, CCNOmode)
9677    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
9678   "xor{w}\t{%2, %0|%0, %2}"
9679   [(set_attr "type" "alu")
9680    (set_attr "mode" "HI")])
9681
9682 (define_expand "xorqi3"
9683   [(set (match_operand:QI 0 "nonimmediate_operand" "")
9684         (xor:QI (match_operand:QI 1 "nonimmediate_operand" "")
9685                 (match_operand:QI 2 "general_operand" "")))]
9686   "TARGET_QIMODE_MATH"
9687   "ix86_expand_binary_operator (XOR, QImode, operands); DONE;")
9688
9689 ;; %%% Potential partial reg stall on alternative 2.  What to do?
9690 (define_insn "*xorqi_1"
9691   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,m,r")
9692         (xor:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
9693                 (match_operand:QI 2 "general_operand" "qmn,qn,rn")))
9694    (clobber (reg:CC FLAGS_REG))]
9695   "ix86_binary_operator_ok (XOR, QImode, operands)"
9696   "@
9697    xor{b}\t{%2, %0|%0, %2}
9698    xor{b}\t{%2, %0|%0, %2}
9699    xor{l}\t{%k2, %k0|%k0, %k2}"
9700   [(set_attr "type" "alu")
9701    (set_attr "mode" "QI,QI,SI")])
9702
9703 (define_insn "*xorqi_1_slp"
9704   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
9705         (xor:QI (match_dup 0)
9706                 (match_operand:QI 1 "general_operand" "qn,qmn")))
9707    (clobber (reg:CC FLAGS_REG))]
9708   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
9709    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
9710   "xor{b}\t{%1, %0|%0, %1}"
9711   [(set_attr "type" "alu1")
9712    (set_attr "mode" "QI")])
9713
9714 (define_insn "*xorqi_ext_0"
9715   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9716                          (const_int 8)
9717                          (const_int 8))
9718         (xor:SI
9719           (zero_extract:SI
9720             (match_operand 1 "ext_register_operand" "0")
9721             (const_int 8)
9722             (const_int 8))
9723           (match_operand 2 "const_int_operand" "n")))
9724    (clobber (reg:CC FLAGS_REG))]
9725   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))"
9726   "xor{b}\t{%2, %h0|%h0, %2}"
9727   [(set_attr "type" "alu")
9728    (set_attr "length_immediate" "1")
9729    (set_attr "modrm" "1")
9730    (set_attr "mode" "QI")])
9731
9732 (define_insn "*xorqi_ext_1"
9733   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9734                          (const_int 8)
9735                          (const_int 8))
9736         (xor:SI
9737           (zero_extract:SI
9738             (match_operand 1 "ext_register_operand" "0")
9739             (const_int 8)
9740             (const_int 8))
9741           (zero_extend:SI
9742             (match_operand:QI 2 "general_operand" "Qm"))))
9743    (clobber (reg:CC FLAGS_REG))]
9744   "!TARGET_64BIT
9745    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))"
9746   "xor{b}\t{%2, %h0|%h0, %2}"
9747   [(set_attr "type" "alu")
9748    (set_attr "length_immediate" "0")
9749    (set_attr "mode" "QI")])
9750
9751 (define_insn "*xorqi_ext_1_rex64"
9752   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9753                          (const_int 8)
9754                          (const_int 8))
9755         (xor:SI
9756           (zero_extract:SI
9757             (match_operand 1 "ext_register_operand" "0")
9758             (const_int 8)
9759             (const_int 8))
9760           (zero_extend:SI
9761             (match_operand 2 "ext_register_operand" "Q"))))
9762    (clobber (reg:CC FLAGS_REG))]
9763   "TARGET_64BIT
9764    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))"
9765   "xor{b}\t{%2, %h0|%h0, %2}"
9766   [(set_attr "type" "alu")
9767    (set_attr "length_immediate" "0")
9768    (set_attr "mode" "QI")])
9769
9770 (define_insn "*xorqi_ext_2"
9771   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9772                          (const_int 8)
9773                          (const_int 8))
9774         (xor:SI
9775           (zero_extract:SI (match_operand 1 "ext_register_operand" "0")
9776                            (const_int 8)
9777                            (const_int 8))
9778           (zero_extract:SI (match_operand 2 "ext_register_operand" "Q")
9779                            (const_int 8)
9780                            (const_int 8))))
9781    (clobber (reg:CC FLAGS_REG))]
9782   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))"
9783   "xor{b}\t{%h2, %h0|%h0, %h2}"
9784   [(set_attr "type" "alu")
9785    (set_attr "length_immediate" "0")
9786    (set_attr "mode" "QI")])
9787
9788 (define_insn "*xorqi_cc_1"
9789   [(set (reg FLAGS_REG)
9790         (compare
9791           (xor:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0")
9792                   (match_operand:QI 2 "general_operand" "qmn,qn"))
9793           (const_int 0)))
9794    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm")
9795         (xor:QI (match_dup 1) (match_dup 2)))]
9796   "ix86_match_ccmode (insn, CCNOmode)
9797    && ix86_binary_operator_ok (XOR, QImode, operands)"
9798   "xor{b}\t{%2, %0|%0, %2}"
9799   [(set_attr "type" "alu")
9800    (set_attr "mode" "QI")])
9801
9802 (define_insn "*xorqi_2_slp"
9803   [(set (reg FLAGS_REG)
9804         (compare (xor:QI (match_operand:QI 0 "nonimmediate_operand" "+q,qm")
9805                          (match_operand:QI 1 "general_operand" "qmn,qn"))
9806                  (const_int 0)))
9807    (set (strict_low_part (match_dup 0))
9808         (xor:QI (match_dup 0) (match_dup 1)))]
9809   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
9810    && ix86_match_ccmode (insn, CCNOmode)
9811    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
9812   "xor{b}\t{%1, %0|%0, %1}"
9813   [(set_attr "type" "alu1")
9814    (set_attr "mode" "QI")])
9815
9816 (define_insn "*xorqi_cc_2"
9817   [(set (reg FLAGS_REG)
9818         (compare
9819           (xor:QI (match_operand:QI 1 "nonimmediate_operand" "%0")
9820                   (match_operand:QI 2 "general_operand" "qmn"))
9821           (const_int 0)))
9822    (clobber (match_scratch:QI 0 "=q"))]
9823   "ix86_match_ccmode (insn, CCNOmode)
9824    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
9825   "xor{b}\t{%2, %0|%0, %2}"
9826   [(set_attr "type" "alu")
9827    (set_attr "mode" "QI")])
9828
9829 (define_insn "*xorqi_cc_ext_1"
9830   [(set (reg FLAGS_REG)
9831         (compare
9832           (xor:SI
9833             (zero_extract:SI
9834               (match_operand 1 "ext_register_operand" "0")
9835               (const_int 8)
9836               (const_int 8))
9837             (match_operand:QI 2 "general_operand" "qmn"))
9838           (const_int 0)))
9839    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=q")
9840                          (const_int 8)
9841                          (const_int 8))
9842         (xor:SI
9843           (zero_extract:SI (match_dup 1) (const_int 8) (const_int 8))
9844           (match_dup 2)))]
9845   "!TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
9846   "xor{b}\t{%2, %h0|%h0, %2}"
9847   [(set_attr "type" "alu")
9848    (set_attr "modrm" "1")
9849    (set_attr "mode" "QI")])
9850
9851 (define_insn "*xorqi_cc_ext_1_rex64"
9852   [(set (reg FLAGS_REG)
9853         (compare
9854           (xor:SI
9855             (zero_extract:SI
9856               (match_operand 1 "ext_register_operand" "0")
9857               (const_int 8)
9858               (const_int 8))
9859             (match_operand:QI 2 "nonmemory_operand" "Qn"))
9860           (const_int 0)))
9861    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
9862                          (const_int 8)
9863                          (const_int 8))
9864         (xor:SI
9865           (zero_extract:SI (match_dup 1) (const_int 8) (const_int 8))
9866           (match_dup 2)))]
9867   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
9868   "xor{b}\t{%2, %h0|%h0, %2}"
9869   [(set_attr "type" "alu")
9870    (set_attr "modrm" "1")
9871    (set_attr "mode" "QI")])
9872
9873 (define_expand "xorqi_cc_ext_1"
9874   [(parallel [
9875      (set (reg:CCNO FLAGS_REG)
9876           (compare:CCNO
9877             (xor:SI
9878               (zero_extract:SI
9879                 (match_operand 1 "ext_register_operand" "")
9880                 (const_int 8)
9881                 (const_int 8))
9882               (match_operand:QI 2 "general_operand" ""))
9883             (const_int 0)))
9884      (set (zero_extract:SI (match_operand 0 "ext_register_operand" "")
9885                            (const_int 8)
9886                            (const_int 8))
9887           (xor:SI
9888             (zero_extract:SI (match_dup 1) (const_int 8) (const_int 8))
9889             (match_dup 2)))])]
9890   ""
9891   "")
9892
9893 (define_split
9894   [(set (match_operand 0 "register_operand" "")
9895         (xor (match_operand 1 "register_operand" "")
9896              (match_operand 2 "const_int_operand" "")))
9897    (clobber (reg:CC FLAGS_REG))]
9898    "reload_completed
9899     && QI_REG_P (operands[0])
9900     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
9901     && !(INTVAL (operands[2]) & ~(255 << 8))
9902     && GET_MODE (operands[0]) != QImode"
9903   [(parallel [(set (zero_extract:SI (match_dup 0) (const_int 8) (const_int 8))
9904                    (xor:SI (zero_extract:SI (match_dup 1)
9905                                             (const_int 8) (const_int 8))
9906                            (match_dup 2)))
9907               (clobber (reg:CC FLAGS_REG))])]
9908   "operands[0] = gen_lowpart (SImode, operands[0]);
9909    operands[1] = gen_lowpart (SImode, operands[1]);
9910    operands[2] = gen_int_mode ((INTVAL (operands[2]) >> 8) & 0xff, SImode);")
9911
9912 ;; Since XOR can be encoded with sign extended immediate, this is only
9913 ;; profitable when 7th bit is set.
9914 (define_split
9915   [(set (match_operand 0 "register_operand" "")
9916         (xor (match_operand 1 "general_operand" "")
9917              (match_operand 2 "const_int_operand" "")))
9918    (clobber (reg:CC FLAGS_REG))]
9919    "reload_completed
9920     && ANY_QI_REG_P (operands[0])
9921     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
9922     && !(INTVAL (operands[2]) & ~255)
9923     && (INTVAL (operands[2]) & 128)
9924     && GET_MODE (operands[0]) != QImode"
9925   [(parallel [(set (strict_low_part (match_dup 0))
9926                    (xor:QI (match_dup 1)
9927                            (match_dup 2)))
9928               (clobber (reg:CC FLAGS_REG))])]
9929   "operands[0] = gen_lowpart (QImode, operands[0]);
9930    operands[1] = gen_lowpart (QImode, operands[1]);
9931    operands[2] = gen_lowpart (QImode, operands[2]);")
9932 \f
9933 ;; Negation instructions
9934
9935 (define_expand "negti2"
9936   [(set (match_operand:TI 0 "nonimmediate_operand" "")
9937         (neg:TI (match_operand:TI 1 "nonimmediate_operand" "")))]
9938   "TARGET_64BIT"
9939   "ix86_expand_unary_operator (NEG, TImode, operands); DONE;")
9940
9941 (define_insn "*negti2_1"
9942   [(set (match_operand:TI 0 "nonimmediate_operand" "=ro")
9943         (neg:TI (match_operand:TI 1 "nonimmediate_operand" "0")))
9944    (clobber (reg:CC FLAGS_REG))]
9945   "TARGET_64BIT
9946    && ix86_unary_operator_ok (NEG, TImode, operands)"
9947   "#")
9948
9949 (define_split
9950   [(set (match_operand:TI 0 "nonimmediate_operand" "")
9951         (neg:TI (match_operand:TI 1 "nonimmediate_operand" "")))
9952    (clobber (reg:CC FLAGS_REG))]
9953   "TARGET_64BIT && reload_completed"
9954   [(parallel
9955     [(set (reg:CCZ FLAGS_REG)
9956           (compare:CCZ (neg:DI (match_dup 1)) (const_int 0)))
9957      (set (match_dup 0) (neg:DI (match_dup 1)))])
9958    (parallel
9959     [(set (match_dup 2)
9960           (plus:DI (plus:DI (ltu:DI (reg:CC FLAGS_REG) (const_int 0))
9961                             (match_dup 3))
9962                    (const_int 0)))
9963      (clobber (reg:CC FLAGS_REG))])
9964    (parallel
9965     [(set (match_dup 2)
9966           (neg:DI (match_dup 2)))
9967      (clobber (reg:CC FLAGS_REG))])]
9968   "split_ti (&operands[0], 2, &operands[0], &operands[2]);")
9969
9970 (define_expand "negdi2"
9971   [(set (match_operand:DI 0 "nonimmediate_operand" "")
9972         (neg:DI (match_operand:DI 1 "nonimmediate_operand" "")))]
9973   ""
9974   "ix86_expand_unary_operator (NEG, DImode, operands); DONE;")
9975
9976 (define_insn "*negdi2_1"
9977   [(set (match_operand:DI 0 "nonimmediate_operand" "=ro")
9978         (neg:DI (match_operand:DI 1 "general_operand" "0")))
9979    (clobber (reg:CC FLAGS_REG))]
9980   "!TARGET_64BIT
9981    && ix86_unary_operator_ok (NEG, DImode, operands)"
9982   "#")
9983
9984 (define_split
9985   [(set (match_operand:DI 0 "nonimmediate_operand" "")
9986         (neg:DI (match_operand:DI 1 "general_operand" "")))
9987    (clobber (reg:CC FLAGS_REG))]
9988   "!TARGET_64BIT && reload_completed"
9989   [(parallel
9990     [(set (reg:CCZ FLAGS_REG)
9991           (compare:CCZ (neg:SI (match_dup 1)) (const_int 0)))
9992      (set (match_dup 0) (neg:SI (match_dup 1)))])
9993    (parallel
9994     [(set (match_dup 2)
9995           (plus:SI (plus:SI (ltu:SI (reg:CC FLAGS_REG) (const_int 0))
9996                             (match_dup 3))
9997                    (const_int 0)))
9998      (clobber (reg:CC FLAGS_REG))])
9999    (parallel
10000     [(set (match_dup 2)
10001           (neg:SI (match_dup 2)))
10002      (clobber (reg:CC FLAGS_REG))])]
10003   "split_di (&operands[0], 2, &operands[0], &operands[2]);");
10004
10005 (define_insn "*negdi2_1_rex64"
10006   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
10007         (neg:DI (match_operand:DI 1 "nonimmediate_operand" "0")))
10008    (clobber (reg:CC FLAGS_REG))]
10009   "TARGET_64BIT && ix86_unary_operator_ok (NEG, DImode, operands)"
10010   "neg{q}\t%0"
10011   [(set_attr "type" "negnot")
10012    (set_attr "mode" "DI")])
10013
10014 ;; The problem with neg is that it does not perform (compare x 0),
10015 ;; it really performs (compare 0 x), which leaves us with the zero
10016 ;; flag being the only useful item.
10017
10018 (define_insn "*negdi2_cmpz_rex64"
10019   [(set (reg:CCZ FLAGS_REG)
10020         (compare:CCZ (neg:DI (match_operand:DI 1 "nonimmediate_operand" "0"))
10021                      (const_int 0)))
10022    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
10023         (neg:DI (match_dup 1)))]
10024   "TARGET_64BIT && ix86_unary_operator_ok (NEG, DImode, operands)"
10025   "neg{q}\t%0"
10026   [(set_attr "type" "negnot")
10027    (set_attr "mode" "DI")])
10028
10029
10030 (define_expand "negsi2"
10031   [(set (match_operand:SI 0 "nonimmediate_operand" "")
10032         (neg:SI (match_operand:SI 1 "nonimmediate_operand" "")))]
10033   ""
10034   "ix86_expand_unary_operator (NEG, SImode, operands); DONE;")
10035
10036 (define_insn "*negsi2_1"
10037   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
10038         (neg:SI (match_operand:SI 1 "nonimmediate_operand" "0")))
10039    (clobber (reg:CC FLAGS_REG))]
10040   "ix86_unary_operator_ok (NEG, SImode, operands)"
10041   "neg{l}\t%0"
10042   [(set_attr "type" "negnot")
10043    (set_attr "mode" "SI")])
10044
10045 ;; Combine is quite creative about this pattern.
10046 (define_insn "*negsi2_1_zext"
10047   [(set (match_operand:DI 0 "register_operand" "=r")
10048         (lshiftrt:DI (neg:DI (ashift:DI (match_operand:DI 1 "register_operand" "0")
10049                                         (const_int 32)))
10050                      (const_int 32)))
10051    (clobber (reg:CC FLAGS_REG))]
10052   "TARGET_64BIT && ix86_unary_operator_ok (NEG, SImode, operands)"
10053   "neg{l}\t%k0"
10054   [(set_attr "type" "negnot")
10055    (set_attr "mode" "SI")])
10056
10057 ;; The problem with neg is that it does not perform (compare x 0),
10058 ;; it really performs (compare 0 x), which leaves us with the zero
10059 ;; flag being the only useful item.
10060
10061 (define_insn "*negsi2_cmpz"
10062   [(set (reg:CCZ FLAGS_REG)
10063         (compare:CCZ (neg:SI (match_operand:SI 1 "nonimmediate_operand" "0"))
10064                      (const_int 0)))
10065    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
10066         (neg:SI (match_dup 1)))]
10067   "ix86_unary_operator_ok (NEG, SImode, operands)"
10068   "neg{l}\t%0"
10069   [(set_attr "type" "negnot")
10070    (set_attr "mode" "SI")])
10071
10072 (define_insn "*negsi2_cmpz_zext"
10073   [(set (reg:CCZ FLAGS_REG)
10074         (compare:CCZ (lshiftrt:DI
10075                        (neg:DI (ashift:DI
10076                                  (match_operand:DI 1 "register_operand" "0")
10077                                  (const_int 32)))
10078                        (const_int 32))
10079                      (const_int 0)))
10080    (set (match_operand:DI 0 "register_operand" "=r")
10081         (lshiftrt:DI (neg:DI (ashift:DI (match_dup 1)
10082                                         (const_int 32)))
10083                      (const_int 32)))]
10084   "TARGET_64BIT && ix86_unary_operator_ok (NEG, SImode, operands)"
10085   "neg{l}\t%k0"
10086   [(set_attr "type" "negnot")
10087    (set_attr "mode" "SI")])
10088
10089 (define_expand "neghi2"
10090   [(set (match_operand:HI 0 "nonimmediate_operand" "")
10091         (neg:HI (match_operand:HI 1 "nonimmediate_operand" "")))]
10092   "TARGET_HIMODE_MATH"
10093   "ix86_expand_unary_operator (NEG, HImode, operands); DONE;")
10094
10095 (define_insn "*neghi2_1"
10096   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
10097         (neg:HI (match_operand:HI 1 "nonimmediate_operand" "0")))
10098    (clobber (reg:CC FLAGS_REG))]
10099   "ix86_unary_operator_ok (NEG, HImode, operands)"
10100   "neg{w}\t%0"
10101   [(set_attr "type" "negnot")
10102    (set_attr "mode" "HI")])
10103
10104 (define_insn "*neghi2_cmpz"
10105   [(set (reg:CCZ FLAGS_REG)
10106         (compare:CCZ (neg:HI (match_operand:HI 1 "nonimmediate_operand" "0"))
10107                      (const_int 0)))
10108    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
10109         (neg:HI (match_dup 1)))]
10110   "ix86_unary_operator_ok (NEG, HImode, operands)"
10111   "neg{w}\t%0"
10112   [(set_attr "type" "negnot")
10113    (set_attr "mode" "HI")])
10114
10115 (define_expand "negqi2"
10116   [(set (match_operand:QI 0 "nonimmediate_operand" "")
10117         (neg:QI (match_operand:QI 1 "nonimmediate_operand" "")))]
10118   "TARGET_QIMODE_MATH"
10119   "ix86_expand_unary_operator (NEG, QImode, operands); DONE;")
10120
10121 (define_insn "*negqi2_1"
10122   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
10123         (neg:QI (match_operand:QI 1 "nonimmediate_operand" "0")))
10124    (clobber (reg:CC FLAGS_REG))]
10125   "ix86_unary_operator_ok (NEG, QImode, operands)"
10126   "neg{b}\t%0"
10127   [(set_attr "type" "negnot")
10128    (set_attr "mode" "QI")])
10129
10130 (define_insn "*negqi2_cmpz"
10131   [(set (reg:CCZ FLAGS_REG)
10132         (compare:CCZ (neg:QI (match_operand:QI 1 "nonimmediate_operand" "0"))
10133                      (const_int 0)))
10134    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
10135         (neg:QI (match_dup 1)))]
10136   "ix86_unary_operator_ok (NEG, QImode, operands)"
10137   "neg{b}\t%0"
10138   [(set_attr "type" "negnot")
10139    (set_attr "mode" "QI")])
10140
10141 ;; Changing of sign for FP values is doable using integer unit too.
10142
10143 (define_expand "<code><mode>2"
10144   [(set (match_operand:X87MODEF 0 "register_operand" "")
10145         (absneg:X87MODEF (match_operand:X87MODEF 1 "register_operand" "")))]
10146   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
10147   "ix86_expand_fp_absneg_operator (<CODE>, <MODE>mode, operands); DONE;")
10148
10149 (define_insn "*absneg<mode>2_mixed"
10150   [(set (match_operand:MODEF 0 "register_operand" "=x,x,f,!r")
10151         (match_operator:MODEF 3 "absneg_operator"
10152           [(match_operand:MODEF 1 "register_operand" "0,x,0,0")]))
10153    (use (match_operand:<ssevecmode> 2 "nonimmediate_operand" "xm,0,X,X"))
10154    (clobber (reg:CC FLAGS_REG))]
10155   "TARGET_MIX_SSE_I387 && SSE_FLOAT_MODE_P (<MODE>mode)"
10156   "#")
10157
10158 (define_insn "*absneg<mode>2_sse"
10159   [(set (match_operand:MODEF 0 "register_operand" "=x,x,!r")
10160         (match_operator:MODEF 3 "absneg_operator"
10161           [(match_operand:MODEF 1 "register_operand" "0 ,x,0")]))
10162    (use (match_operand:<ssevecmode> 2 "register_operand" "xm,0,X"))
10163    (clobber (reg:CC FLAGS_REG))]
10164   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
10165   "#")
10166
10167 (define_insn "*absneg<mode>2_i387"
10168   [(set (match_operand:X87MODEF 0 "register_operand" "=f,!r")
10169         (match_operator:X87MODEF 3 "absneg_operator"
10170           [(match_operand:X87MODEF 1 "register_operand" "0,0")]))
10171    (use (match_operand 2 "" ""))
10172    (clobber (reg:CC FLAGS_REG))]
10173   "TARGET_80387 && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
10174   "#")
10175
10176 (define_expand "<code>tf2"
10177   [(set (match_operand:TF 0 "register_operand" "")
10178         (absneg:TF (match_operand:TF 1 "register_operand" "")))]
10179   "TARGET_SSE2"
10180   "ix86_expand_fp_absneg_operator (<CODE>, TFmode, operands); DONE;")
10181
10182 (define_insn "*absnegtf2_sse"
10183   [(set (match_operand:TF 0 "register_operand" "=x,x")
10184         (match_operator:TF 3 "absneg_operator"
10185           [(match_operand:TF 1 "register_operand" "0,x")]))
10186    (use (match_operand:TF 2 "nonimmediate_operand" "xm,0"))
10187    (clobber (reg:CC FLAGS_REG))]
10188   "TARGET_SSE2"
10189   "#")
10190
10191 ;; Splitters for fp abs and neg.
10192
10193 (define_split
10194   [(set (match_operand 0 "fp_register_operand" "")
10195         (match_operator 1 "absneg_operator" [(match_dup 0)]))
10196    (use (match_operand 2 "" ""))
10197    (clobber (reg:CC FLAGS_REG))]
10198   "reload_completed"
10199   [(set (match_dup 0) (match_op_dup 1 [(match_dup 0)]))])
10200
10201 (define_split
10202   [(set (match_operand 0 "register_operand" "")
10203         (match_operator 3 "absneg_operator"
10204           [(match_operand 1 "register_operand" "")]))
10205    (use (match_operand 2 "nonimmediate_operand" ""))
10206    (clobber (reg:CC FLAGS_REG))]
10207   "reload_completed && SSE_REG_P (operands[0])"
10208   [(set (match_dup 0) (match_dup 3))]
10209 {
10210   enum machine_mode mode = GET_MODE (operands[0]);
10211   enum machine_mode vmode = GET_MODE (operands[2]);
10212   rtx tmp;
10213
10214   operands[0] = simplify_gen_subreg (vmode, operands[0], mode, 0);
10215   operands[1] = simplify_gen_subreg (vmode, operands[1], mode, 0);
10216   if (operands_match_p (operands[0], operands[2]))
10217     {
10218       tmp = operands[1];
10219       operands[1] = operands[2];
10220       operands[2] = tmp;
10221     }
10222   if (GET_CODE (operands[3]) == ABS)
10223     tmp = gen_rtx_AND (vmode, operands[1], operands[2]);
10224   else
10225     tmp = gen_rtx_XOR (vmode, operands[1], operands[2]);
10226   operands[3] = tmp;
10227 })
10228
10229 (define_split
10230   [(set (match_operand:SF 0 "register_operand" "")
10231         (match_operator:SF 1 "absneg_operator" [(match_dup 0)]))
10232    (use (match_operand:V4SF 2 "" ""))
10233    (clobber (reg:CC FLAGS_REG))]
10234   "reload_completed"
10235   [(parallel [(set (match_dup 0) (match_dup 1))
10236               (clobber (reg:CC FLAGS_REG))])]
10237 {
10238   rtx tmp;
10239   operands[0] = gen_lowpart (SImode, operands[0]);
10240   if (GET_CODE (operands[1]) == ABS)
10241     {
10242       tmp = gen_int_mode (0x7fffffff, SImode);
10243       tmp = gen_rtx_AND (SImode, operands[0], tmp);
10244     }
10245   else
10246     {
10247       tmp = gen_int_mode (0x80000000, SImode);
10248       tmp = gen_rtx_XOR (SImode, operands[0], tmp);
10249     }
10250   operands[1] = tmp;
10251 })
10252
10253 (define_split
10254   [(set (match_operand:DF 0 "register_operand" "")
10255         (match_operator:DF 1 "absneg_operator" [(match_dup 0)]))
10256    (use (match_operand 2 "" ""))
10257    (clobber (reg:CC FLAGS_REG))]
10258   "reload_completed"
10259   [(parallel [(set (match_dup 0) (match_dup 1))
10260               (clobber (reg:CC FLAGS_REG))])]
10261 {
10262   rtx tmp;
10263   if (TARGET_64BIT)
10264     {
10265       tmp = gen_lowpart (DImode, operands[0]);
10266       tmp = gen_rtx_ZERO_EXTRACT (DImode, tmp, const1_rtx, GEN_INT (63));
10267       operands[0] = tmp;
10268
10269       if (GET_CODE (operands[1]) == ABS)
10270         tmp = const0_rtx;
10271       else
10272         tmp = gen_rtx_NOT (DImode, tmp);
10273     }
10274   else
10275     {
10276       operands[0] = gen_highpart (SImode, operands[0]);
10277       if (GET_CODE (operands[1]) == ABS)
10278         {
10279           tmp = gen_int_mode (0x7fffffff, SImode);
10280           tmp = gen_rtx_AND (SImode, operands[0], tmp);
10281         }
10282       else
10283         {
10284           tmp = gen_int_mode (0x80000000, SImode);
10285           tmp = gen_rtx_XOR (SImode, operands[0], tmp);
10286         }
10287     }
10288   operands[1] = tmp;
10289 })
10290
10291 (define_split
10292   [(set (match_operand:XF 0 "register_operand" "")
10293         (match_operator:XF 1 "absneg_operator" [(match_dup 0)]))
10294    (use (match_operand 2 "" ""))
10295    (clobber (reg:CC FLAGS_REG))]
10296   "reload_completed"
10297   [(parallel [(set (match_dup 0) (match_dup 1))
10298               (clobber (reg:CC FLAGS_REG))])]
10299 {
10300   rtx tmp;
10301   operands[0] = gen_rtx_REG (SImode,
10302                              true_regnum (operands[0])
10303                              + (TARGET_64BIT ? 1 : 2));
10304   if (GET_CODE (operands[1]) == ABS)
10305     {
10306       tmp = GEN_INT (0x7fff);
10307       tmp = gen_rtx_AND (SImode, operands[0], tmp);
10308     }
10309   else
10310     {
10311       tmp = GEN_INT (0x8000);
10312       tmp = gen_rtx_XOR (SImode, operands[0], tmp);
10313     }
10314   operands[1] = tmp;
10315 })
10316
10317 ;; Conditionalize these after reload. If they match before reload, we
10318 ;; lose the clobber and ability to use integer instructions.
10319
10320 (define_insn "*<code><mode>2_1"
10321   [(set (match_operand:X87MODEF 0 "register_operand" "=f")
10322         (absneg:X87MODEF (match_operand:X87MODEF 1 "register_operand" "0")))]
10323   "TARGET_80387
10324    && (reload_completed
10325        || !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))"
10326   "f<absnegprefix>"
10327   [(set_attr "type" "fsgn")
10328    (set_attr "mode" "<MODE>")])
10329
10330 (define_insn "*<code>extendsfdf2"
10331   [(set (match_operand:DF 0 "register_operand" "=f")
10332         (absneg:DF (float_extend:DF
10333                      (match_operand:SF 1 "register_operand" "0"))))]
10334   "TARGET_80387 && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387)"
10335   "f<absnegprefix>"
10336   [(set_attr "type" "fsgn")
10337    (set_attr "mode" "DF")])
10338
10339 (define_insn "*<code>extendsfxf2"
10340   [(set (match_operand:XF 0 "register_operand" "=f")
10341         (absneg:XF (float_extend:XF
10342                      (match_operand:SF 1 "register_operand" "0"))))]
10343   "TARGET_80387"
10344   "f<absnegprefix>"
10345   [(set_attr "type" "fsgn")
10346    (set_attr "mode" "XF")])
10347
10348 (define_insn "*<code>extenddfxf2"
10349   [(set (match_operand:XF 0 "register_operand" "=f")
10350         (absneg:XF (float_extend:XF
10351                       (match_operand:DF 1 "register_operand" "0"))))]
10352   "TARGET_80387"
10353   "f<absnegprefix>"
10354   [(set_attr "type" "fsgn")
10355    (set_attr "mode" "XF")])
10356
10357 ;; Copysign instructions
10358
10359 (define_mode_iterator CSGNMODE [SF DF TF])
10360 (define_mode_attr CSGNVMODE [(SF "V4SF") (DF "V2DF") (TF "TF")])
10361
10362 (define_expand "copysign<mode>3"
10363   [(match_operand:CSGNMODE 0 "register_operand" "")
10364    (match_operand:CSGNMODE 1 "nonmemory_operand" "")
10365    (match_operand:CSGNMODE 2 "register_operand" "")]
10366   "(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
10367    || (TARGET_SSE2 && (<MODE>mode == TFmode))"
10368 {
10369   ix86_expand_copysign (operands);
10370   DONE;
10371 })
10372
10373 (define_insn_and_split "copysign<mode>3_const"
10374   [(set (match_operand:CSGNMODE 0 "register_operand" "=x")
10375         (unspec:CSGNMODE
10376           [(match_operand:<CSGNVMODE> 1 "vector_move_operand" "xmC")
10377            (match_operand:CSGNMODE 2 "register_operand" "0")
10378            (match_operand:<CSGNVMODE> 3 "nonimmediate_operand" "xm")]
10379           UNSPEC_COPYSIGN))]
10380   "(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
10381    || (TARGET_SSE2 && (<MODE>mode == TFmode))"
10382   "#"
10383   "&& reload_completed"
10384   [(const_int 0)]
10385 {
10386   ix86_split_copysign_const (operands);
10387   DONE;
10388 })
10389
10390 (define_insn "copysign<mode>3_var"
10391   [(set (match_operand:CSGNMODE 0 "register_operand" "=x,x,x,x,x")
10392         (unspec:CSGNMODE
10393           [(match_operand:CSGNMODE 2 "register_operand" "x,0,0,x,x")
10394            (match_operand:CSGNMODE 3 "register_operand" "1,1,x,1,x")
10395            (match_operand:<CSGNVMODE> 4 "nonimmediate_operand" "X,xm,xm,0,0")
10396            (match_operand:<CSGNVMODE> 5 "nonimmediate_operand" "0,xm,1,xm,1")]
10397           UNSPEC_COPYSIGN))
10398    (clobber (match_scratch:<CSGNVMODE> 1 "=x,x,x,x,x"))]
10399   "(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
10400    || (TARGET_SSE2 && (<MODE>mode == TFmode))"
10401   "#")
10402
10403 (define_split
10404   [(set (match_operand:CSGNMODE 0 "register_operand" "")
10405         (unspec:CSGNMODE
10406           [(match_operand:CSGNMODE 2 "register_operand" "")
10407            (match_operand:CSGNMODE 3 "register_operand" "")
10408            (match_operand:<CSGNVMODE> 4 "" "")
10409            (match_operand:<CSGNVMODE> 5 "" "")]
10410           UNSPEC_COPYSIGN))
10411    (clobber (match_scratch:<CSGNVMODE> 1 ""))]
10412   "((SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
10413     || (TARGET_SSE2 && (<MODE>mode == TFmode)))
10414    && reload_completed"
10415   [(const_int 0)]
10416 {
10417   ix86_split_copysign_var (operands);
10418   DONE;
10419 })
10420 \f
10421 ;; One complement instructions
10422
10423 (define_expand "one_cmpldi2"
10424   [(set (match_operand:DI 0 "nonimmediate_operand" "")
10425         (not:DI (match_operand:DI 1 "nonimmediate_operand" "")))]
10426   "TARGET_64BIT"
10427   "ix86_expand_unary_operator (NOT, DImode, operands); DONE;")
10428
10429 (define_insn "*one_cmpldi2_1_rex64"
10430   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
10431         (not:DI (match_operand:DI 1 "nonimmediate_operand" "0")))]
10432   "TARGET_64BIT && ix86_unary_operator_ok (NOT, DImode, operands)"
10433   "not{q}\t%0"
10434   [(set_attr "type" "negnot")
10435    (set_attr "mode" "DI")])
10436
10437 (define_insn "*one_cmpldi2_2_rex64"
10438   [(set (reg FLAGS_REG)
10439         (compare (not:DI (match_operand:DI 1 "nonimmediate_operand" "0"))
10440                  (const_int 0)))
10441    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
10442         (not:DI (match_dup 1)))]
10443   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
10444    && ix86_unary_operator_ok (NOT, DImode, operands)"
10445   "#"
10446   [(set_attr "type" "alu1")
10447    (set_attr "mode" "DI")])
10448
10449 (define_split
10450   [(set (match_operand 0 "flags_reg_operand" "")
10451         (match_operator 2 "compare_operator"
10452           [(not:DI (match_operand:DI 3 "nonimmediate_operand" ""))
10453            (const_int 0)]))
10454    (set (match_operand:DI 1 "nonimmediate_operand" "")
10455         (not:DI (match_dup 3)))]
10456   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
10457   [(parallel [(set (match_dup 0)
10458                    (match_op_dup 2
10459                      [(xor:DI (match_dup 3) (const_int -1))
10460                       (const_int 0)]))
10461               (set (match_dup 1)
10462                    (xor:DI (match_dup 3) (const_int -1)))])]
10463   "")
10464
10465 (define_expand "one_cmplsi2"
10466   [(set (match_operand:SI 0 "nonimmediate_operand" "")
10467         (not:SI (match_operand:SI 1 "nonimmediate_operand" "")))]
10468   ""
10469   "ix86_expand_unary_operator (NOT, SImode, operands); DONE;")
10470
10471 (define_insn "*one_cmplsi2_1"
10472   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
10473         (not:SI (match_operand:SI 1 "nonimmediate_operand" "0")))]
10474   "ix86_unary_operator_ok (NOT, SImode, operands)"
10475   "not{l}\t%0"
10476   [(set_attr "type" "negnot")
10477    (set_attr "mode" "SI")])
10478
10479 ;; ??? Currently never generated - xor is used instead.
10480 (define_insn "*one_cmplsi2_1_zext"
10481   [(set (match_operand:DI 0 "register_operand" "=r")
10482         (zero_extend:DI (not:SI (match_operand:SI 1 "register_operand" "0"))))]
10483   "TARGET_64BIT && ix86_unary_operator_ok (NOT, SImode, operands)"
10484   "not{l}\t%k0"
10485   [(set_attr "type" "negnot")
10486    (set_attr "mode" "SI")])
10487
10488 (define_insn "*one_cmplsi2_2"
10489   [(set (reg FLAGS_REG)
10490         (compare (not:SI (match_operand:SI 1 "nonimmediate_operand" "0"))
10491                  (const_int 0)))
10492    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
10493         (not:SI (match_dup 1)))]
10494   "ix86_match_ccmode (insn, CCNOmode)
10495    && ix86_unary_operator_ok (NOT, SImode, operands)"
10496   "#"
10497   [(set_attr "type" "alu1")
10498    (set_attr "mode" "SI")])
10499
10500 (define_split
10501   [(set (match_operand 0 "flags_reg_operand" "")
10502         (match_operator 2 "compare_operator"
10503           [(not:SI (match_operand:SI 3 "nonimmediate_operand" ""))
10504            (const_int 0)]))
10505    (set (match_operand:SI 1 "nonimmediate_operand" "")
10506         (not:SI (match_dup 3)))]
10507   "ix86_match_ccmode (insn, CCNOmode)"
10508   [(parallel [(set (match_dup 0)
10509                    (match_op_dup 2 [(xor:SI (match_dup 3) (const_int -1))
10510                                     (const_int 0)]))
10511               (set (match_dup 1)
10512                    (xor:SI (match_dup 3) (const_int -1)))])]
10513   "")
10514
10515 ;; ??? Currently never generated - xor is used instead.
10516 (define_insn "*one_cmplsi2_2_zext"
10517   [(set (reg FLAGS_REG)
10518         (compare (not:SI (match_operand:SI 1 "register_operand" "0"))
10519                  (const_int 0)))
10520    (set (match_operand:DI 0 "register_operand" "=r")
10521         (zero_extend:DI (not:SI (match_dup 1))))]
10522   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
10523    && ix86_unary_operator_ok (NOT, SImode, operands)"
10524   "#"
10525   [(set_attr "type" "alu1")
10526    (set_attr "mode" "SI")])
10527
10528 (define_split
10529   [(set (match_operand 0 "flags_reg_operand" "")
10530         (match_operator 2 "compare_operator"
10531           [(not:SI (match_operand:SI 3 "register_operand" ""))
10532            (const_int 0)]))
10533    (set (match_operand:DI 1 "register_operand" "")
10534         (zero_extend:DI (not:SI (match_dup 3))))]
10535   "ix86_match_ccmode (insn, CCNOmode)"
10536   [(parallel [(set (match_dup 0)
10537                    (match_op_dup 2 [(xor:SI (match_dup 3) (const_int -1))
10538                                     (const_int 0)]))
10539               (set (match_dup 1)
10540                    (zero_extend:DI (xor:SI (match_dup 3) (const_int -1))))])]
10541   "")
10542
10543 (define_expand "one_cmplhi2"
10544   [(set (match_operand:HI 0 "nonimmediate_operand" "")
10545         (not:HI (match_operand:HI 1 "nonimmediate_operand" "")))]
10546   "TARGET_HIMODE_MATH"
10547   "ix86_expand_unary_operator (NOT, HImode, operands); DONE;")
10548
10549 (define_insn "*one_cmplhi2_1"
10550   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
10551         (not:HI (match_operand:HI 1 "nonimmediate_operand" "0")))]
10552   "ix86_unary_operator_ok (NOT, HImode, operands)"
10553   "not{w}\t%0"
10554   [(set_attr "type" "negnot")
10555    (set_attr "mode" "HI")])
10556
10557 (define_insn "*one_cmplhi2_2"
10558   [(set (reg FLAGS_REG)
10559         (compare (not:HI (match_operand:HI 1 "nonimmediate_operand" "0"))
10560                  (const_int 0)))
10561    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
10562         (not:HI (match_dup 1)))]
10563   "ix86_match_ccmode (insn, CCNOmode)
10564    && ix86_unary_operator_ok (NEG, HImode, operands)"
10565   "#"
10566   [(set_attr "type" "alu1")
10567    (set_attr "mode" "HI")])
10568
10569 (define_split
10570   [(set (match_operand 0 "flags_reg_operand" "")
10571         (match_operator 2 "compare_operator"
10572           [(not:HI (match_operand:HI 3 "nonimmediate_operand" ""))
10573            (const_int 0)]))
10574    (set (match_operand:HI 1 "nonimmediate_operand" "")
10575         (not:HI (match_dup 3)))]
10576   "ix86_match_ccmode (insn, CCNOmode)"
10577   [(parallel [(set (match_dup 0)
10578                    (match_op_dup 2 [(xor:HI (match_dup 3) (const_int -1))
10579                                     (const_int 0)]))
10580               (set (match_dup 1)
10581                    (xor:HI (match_dup 3) (const_int -1)))])]
10582   "")
10583
10584 ;; %%% Potential partial reg stall on alternative 1.  What to do?
10585 (define_expand "one_cmplqi2"
10586   [(set (match_operand:QI 0 "nonimmediate_operand" "")
10587         (not:QI (match_operand:QI 1 "nonimmediate_operand" "")))]
10588   "TARGET_QIMODE_MATH"
10589   "ix86_expand_unary_operator (NOT, QImode, operands); DONE;")
10590
10591 (define_insn "*one_cmplqi2_1"
10592   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r")
10593         (not:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")))]
10594   "ix86_unary_operator_ok (NOT, QImode, operands)"
10595   "@
10596    not{b}\t%0
10597    not{l}\t%k0"
10598   [(set_attr "type" "negnot")
10599    (set_attr "mode" "QI,SI")])
10600
10601 (define_insn "*one_cmplqi2_2"
10602   [(set (reg FLAGS_REG)
10603         (compare (not:QI (match_operand:QI 1 "nonimmediate_operand" "0"))
10604                  (const_int 0)))
10605    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
10606         (not:QI (match_dup 1)))]
10607   "ix86_match_ccmode (insn, CCNOmode)
10608    && ix86_unary_operator_ok (NOT, QImode, operands)"
10609   "#"
10610   [(set_attr "type" "alu1")
10611    (set_attr "mode" "QI")])
10612
10613 (define_split
10614   [(set (match_operand 0 "flags_reg_operand" "")
10615         (match_operator 2 "compare_operator"
10616           [(not:QI (match_operand:QI 3 "nonimmediate_operand" ""))
10617            (const_int 0)]))
10618    (set (match_operand:QI 1 "nonimmediate_operand" "")
10619         (not:QI (match_dup 3)))]
10620   "ix86_match_ccmode (insn, CCNOmode)"
10621   [(parallel [(set (match_dup 0)
10622                    (match_op_dup 2 [(xor:QI (match_dup 3) (const_int -1))
10623                                     (const_int 0)]))
10624               (set (match_dup 1)
10625                    (xor:QI (match_dup 3) (const_int -1)))])]
10626   "")
10627 \f
10628 ;; Arithmetic shift instructions
10629
10630 ;; DImode shifts are implemented using the i386 "shift double" opcode,
10631 ;; which is written as "sh[lr]d[lw] imm,reg,reg/mem".  If the shift count
10632 ;; is variable, then the count is in %cl and the "imm" operand is dropped
10633 ;; from the assembler input.
10634 ;;
10635 ;; This instruction shifts the target reg/mem as usual, but instead of
10636 ;; shifting in zeros, bits are shifted in from reg operand.  If the insn
10637 ;; is a left shift double, bits are taken from the high order bits of
10638 ;; reg, else if the insn is a shift right double, bits are taken from the
10639 ;; low order bits of reg.  So if %eax is "1234" and %edx is "5678",
10640 ;; "shldl $8,%edx,%eax" leaves %edx unchanged and sets %eax to "2345".
10641 ;;
10642 ;; Since sh[lr]d does not change the `reg' operand, that is done
10643 ;; separately, making all shifts emit pairs of shift double and normal
10644 ;; shift.  Since sh[lr]d does not shift more than 31 bits, and we wish to
10645 ;; support a 63 bit shift, each shift where the count is in a reg expands
10646 ;; to a pair of shifts, a branch, a shift by 32 and a label.
10647 ;;
10648 ;; If the shift count is a constant, we need never emit more than one
10649 ;; shift pair, instead using moves and sign extension for counts greater
10650 ;; than 31.
10651
10652 (define_expand "ashlti3"
10653   [(set (match_operand:TI 0 "register_operand" "")
10654         (ashift:TI (match_operand:TI 1 "reg_or_pm1_operand" "")
10655                    (match_operand:QI 2 "nonmemory_operand" "")))]
10656   "TARGET_64BIT"
10657   "ix86_expand_binary_operator (ASHIFT, TImode, operands); DONE;")
10658
10659 ;; This pattern must be defined before *ashlti3_1 to prevent
10660 ;; combine pass from converting sse2_ashlti3 to *ashlti3_1.
10661
10662 (define_insn "*avx_ashlti3"
10663   [(set (match_operand:TI 0 "register_operand" "=x")
10664         (ashift:TI (match_operand:TI 1 "register_operand" "x")
10665                    (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n")))]
10666   "TARGET_AVX"
10667 {
10668   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
10669   return "vpslldq\t{%2, %1, %0|%0, %1, %2}";
10670 }
10671   [(set_attr "type" "sseishft")
10672    (set_attr "prefix" "vex")
10673    (set_attr "length_immediate" "1")
10674    (set_attr "mode" "TI")])
10675
10676 (define_insn "sse2_ashlti3"
10677   [(set (match_operand:TI 0 "register_operand" "=x")
10678         (ashift:TI (match_operand:TI 1 "register_operand" "0")
10679                    (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n")))]
10680   "TARGET_SSE2"
10681 {
10682   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
10683   return "pslldq\t{%2, %0|%0, %2}";
10684 }
10685   [(set_attr "type" "sseishft")
10686    (set_attr "prefix_data16" "1")
10687    (set_attr "length_immediate" "1")
10688    (set_attr "mode" "TI")])
10689
10690 (define_insn "*ashlti3_1"
10691   [(set (match_operand:TI 0 "register_operand" "=&r,r")
10692         (ashift:TI (match_operand:TI 1 "reg_or_pm1_operand" "n,0")
10693                    (match_operand:QI 2 "nonmemory_operand" "Oc,Oc")))
10694    (clobber (reg:CC FLAGS_REG))]
10695   "TARGET_64BIT"
10696   "#"
10697   [(set_attr "type" "multi")])
10698
10699 (define_peephole2
10700   [(match_scratch:DI 3 "r")
10701    (parallel [(set (match_operand:TI 0 "register_operand" "")
10702                    (ashift:TI (match_operand:TI 1 "nonmemory_operand" "")
10703                               (match_operand:QI 2 "nonmemory_operand" "")))
10704               (clobber (reg:CC FLAGS_REG))])
10705    (match_dup 3)]
10706   "TARGET_64BIT"
10707   [(const_int 0)]
10708   "ix86_split_ashl (operands, operands[3], TImode); DONE;")
10709
10710 (define_split
10711   [(set (match_operand:TI 0 "register_operand" "")
10712         (ashift:TI (match_operand:TI 1 "nonmemory_operand" "")
10713                    (match_operand:QI 2 "nonmemory_operand" "")))
10714    (clobber (reg:CC FLAGS_REG))]
10715   "TARGET_64BIT && ((optimize > 0 && flag_peephole2)
10716                     ? epilogue_completed : reload_completed)"
10717   [(const_int 0)]
10718   "ix86_split_ashl (operands, NULL_RTX, TImode); DONE;")
10719
10720 (define_insn "x86_64_shld"
10721   [(set (match_operand:DI 0 "nonimmediate_operand" "+r*m")
10722         (ior:DI (ashift:DI (match_dup 0)
10723                   (match_operand:QI 2 "nonmemory_operand" "Jc"))
10724                 (lshiftrt:DI (match_operand:DI 1 "register_operand" "r")
10725                   (minus:QI (const_int 64) (match_dup 2)))))
10726    (clobber (reg:CC FLAGS_REG))]
10727   "TARGET_64BIT"
10728   "shld{q}\t{%s2%1, %0|%0, %1, %2}"
10729   [(set_attr "type" "ishift")
10730    (set_attr "prefix_0f" "1")
10731    (set_attr "mode" "DI")
10732    (set_attr "athlon_decode" "vector")
10733    (set_attr "amdfam10_decode" "vector")])
10734
10735 (define_expand "x86_64_shift_adj_1"
10736   [(set (reg:CCZ FLAGS_REG)
10737         (compare:CCZ (and:QI (match_operand:QI 2 "register_operand" "")
10738                              (const_int 64))
10739                      (const_int 0)))
10740    (set (match_operand:DI 0 "register_operand" "")
10741         (if_then_else:DI (ne (reg:CCZ FLAGS_REG) (const_int 0))
10742                          (match_operand:DI 1 "register_operand" "")
10743                          (match_dup 0)))
10744    (set (match_dup 1)
10745         (if_then_else:DI (ne (reg:CCZ FLAGS_REG) (const_int 0))
10746                          (match_operand:DI 3 "register_operand" "r")
10747                          (match_dup 1)))]
10748   "TARGET_64BIT"
10749   "")
10750
10751 (define_expand "x86_64_shift_adj_2"
10752   [(use (match_operand:DI 0 "register_operand" ""))
10753    (use (match_operand:DI 1 "register_operand" ""))
10754    (use (match_operand:QI 2 "register_operand" ""))]
10755   "TARGET_64BIT"
10756 {
10757   rtx label = gen_label_rtx ();
10758   rtx tmp;
10759
10760   emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (64)));
10761
10762   tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
10763   tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
10764   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
10765                               gen_rtx_LABEL_REF (VOIDmode, label),
10766                               pc_rtx);
10767   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
10768   JUMP_LABEL (tmp) = label;
10769
10770   emit_move_insn (operands[0], operands[1]);
10771   ix86_expand_clear (operands[1]);
10772
10773   emit_label (label);
10774   LABEL_NUSES (label) = 1;
10775
10776   DONE;
10777 })
10778
10779 (define_expand "ashldi3"
10780   [(set (match_operand:DI 0 "shiftdi_operand" "")
10781         (ashift:DI (match_operand:DI 1 "ashldi_input_operand" "")
10782                    (match_operand:QI 2 "nonmemory_operand" "")))]
10783   ""
10784   "ix86_expand_binary_operator (ASHIFT, DImode, operands); DONE;")
10785
10786 (define_insn "*ashldi3_1_rex64"
10787   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r")
10788         (ashift:DI (match_operand:DI 1 "nonimmediate_operand" "0,l")
10789                    (match_operand:QI 2 "nonmemory_operand" "cJ,M")))
10790    (clobber (reg:CC FLAGS_REG))]
10791   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFT, DImode, operands)"
10792 {
10793   switch (get_attr_type (insn))
10794     {
10795     case TYPE_ALU:
10796       gcc_assert (operands[2] == const1_rtx);
10797       gcc_assert (rtx_equal_p (operands[0], operands[1]));
10798       return "add{q}\t%0, %0";
10799
10800     case TYPE_LEA:
10801       gcc_assert (CONST_INT_P (operands[2]));
10802       gcc_assert ((unsigned HOST_WIDE_INT) INTVAL (operands[2]) <= 3);
10803       operands[1] = gen_rtx_MULT (DImode, operands[1],
10804                                   GEN_INT (1 << INTVAL (operands[2])));
10805       return "lea{q}\t{%a1, %0|%0, %a1}";
10806
10807     default:
10808       if (REG_P (operands[2]))
10809         return "sal{q}\t{%b2, %0|%0, %b2}";
10810       else if (operands[2] == const1_rtx
10811                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10812         return "sal{q}\t%0";
10813       else
10814         return "sal{q}\t{%2, %0|%0, %2}";
10815     }
10816 }
10817   [(set (attr "type")
10818      (cond [(eq_attr "alternative" "1")
10819               (const_string "lea")
10820             (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
10821                           (const_int 0))
10822                       (match_operand 0 "register_operand" ""))
10823                  (match_operand 2 "const1_operand" ""))
10824               (const_string "alu")
10825            ]
10826            (const_string "ishift")))
10827    (set (attr "length_immediate")
10828      (if_then_else
10829        (ior (eq_attr "type" "alu")
10830             (and (eq_attr "type" "ishift")
10831                  (and (match_operand 2 "const1_operand" "")
10832                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
10833                           (const_int 0)))))
10834        (const_string "0")
10835        (const_string "*")))
10836    (set_attr "mode" "DI")])
10837
10838 ;; Convert lea to the lea pattern to avoid flags dependency.
10839 (define_split
10840   [(set (match_operand:DI 0 "register_operand" "")
10841         (ashift:DI (match_operand:DI 1 "index_register_operand" "")
10842                    (match_operand:QI 2 "immediate_operand" "")))
10843    (clobber (reg:CC FLAGS_REG))]
10844   "TARGET_64BIT && reload_completed
10845    && true_regnum (operands[0]) != true_regnum (operands[1])"
10846   [(set (match_dup 0)
10847         (mult:DI (match_dup 1)
10848                  (match_dup 2)))]
10849   "operands[2] = gen_int_mode (1 << INTVAL (operands[2]), DImode);")
10850
10851 ;; This pattern can't accept a variable shift count, since shifts by
10852 ;; zero don't affect the flags.  We assume that shifts by constant
10853 ;; zero are optimized away.
10854 (define_insn "*ashldi3_cmp_rex64"
10855   [(set (reg FLAGS_REG)
10856         (compare
10857           (ashift:DI (match_operand:DI 1 "nonimmediate_operand" "0")
10858                      (match_operand:QI 2 "const_1_to_63_operand" "J"))
10859           (const_int 0)))
10860    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
10861         (ashift:DI (match_dup 1) (match_dup 2)))]
10862   "TARGET_64BIT
10863    && (optimize_function_for_size_p (cfun)
10864        || !TARGET_PARTIAL_FLAG_REG_STALL
10865        || (operands[2] == const1_rtx
10866            && (TARGET_SHIFT1
10867                || (TARGET_DOUBLE_WITH_ADD && REG_P (operands[0])))))
10868    && ix86_match_ccmode (insn, CCGOCmode)
10869    && ix86_binary_operator_ok (ASHIFT, DImode, operands)"
10870 {
10871   switch (get_attr_type (insn))
10872     {
10873     case TYPE_ALU:
10874       gcc_assert (operands[2] == const1_rtx);
10875       return "add{q}\t%0, %0";
10876
10877     default:
10878       if (REG_P (operands[2]))
10879         return "sal{q}\t{%b2, %0|%0, %b2}";
10880       else if (operands[2] == const1_rtx
10881                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10882         return "sal{q}\t%0";
10883       else
10884         return "sal{q}\t{%2, %0|%0, %2}";
10885     }
10886 }
10887   [(set (attr "type")
10888      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
10889                           (const_int 0))
10890                       (match_operand 0 "register_operand" ""))
10891                  (match_operand 2 "const1_operand" ""))
10892               (const_string "alu")
10893            ]
10894            (const_string "ishift")))
10895    (set (attr "length_immediate")
10896      (if_then_else
10897        (ior (eq_attr "type" "alu")
10898             (and (eq_attr "type" "ishift")
10899                  (and (match_operand 2 "const1_operand" "")
10900                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
10901                           (const_int 0)))))
10902        (const_string "0")
10903        (const_string "*")))
10904    (set_attr "mode" "DI")])
10905
10906 (define_insn "*ashldi3_cconly_rex64"
10907   [(set (reg FLAGS_REG)
10908         (compare
10909           (ashift:DI (match_operand:DI 1 "nonimmediate_operand" "0")
10910                      (match_operand:QI 2 "const_1_to_63_operand" "J"))
10911           (const_int 0)))
10912    (clobber (match_scratch:DI 0 "=r"))]
10913   "TARGET_64BIT
10914    && (optimize_function_for_size_p (cfun)
10915        || !TARGET_PARTIAL_FLAG_REG_STALL
10916        || (operands[2] == const1_rtx
10917            && (TARGET_SHIFT1
10918                || TARGET_DOUBLE_WITH_ADD)))
10919    && ix86_match_ccmode (insn, CCGOCmode)
10920    && ix86_binary_operator_ok (ASHIFT, DImode, operands)"
10921 {
10922   switch (get_attr_type (insn))
10923     {
10924     case TYPE_ALU:
10925       gcc_assert (operands[2] == const1_rtx);
10926       return "add{q}\t%0, %0";
10927
10928     default:
10929       if (REG_P (operands[2]))
10930         return "sal{q}\t{%b2, %0|%0, %b2}";
10931       else if (operands[2] == const1_rtx
10932                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10933         return "sal{q}\t%0";
10934       else
10935         return "sal{q}\t{%2, %0|%0, %2}";
10936     }
10937 }
10938   [(set (attr "type")
10939      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
10940                           (const_int 0))
10941                       (match_operand 0 "register_operand" ""))
10942                  (match_operand 2 "const1_operand" ""))
10943               (const_string "alu")
10944            ]
10945            (const_string "ishift")))
10946    (set (attr "length_immediate")
10947      (if_then_else
10948        (ior (eq_attr "type" "alu")
10949             (and (eq_attr "type" "ishift")
10950                  (and (match_operand 2 "const1_operand" "")
10951                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
10952                           (const_int 0)))))
10953        (const_string "0")
10954        (const_string "*")))
10955    (set_attr "mode" "DI")])
10956
10957 (define_insn "*ashldi3_1"
10958   [(set (match_operand:DI 0 "register_operand" "=&r,r")
10959         (ashift:DI (match_operand:DI 1 "reg_or_pm1_operand" "n,0")
10960                    (match_operand:QI 2 "nonmemory_operand" "Jc,Jc")))
10961    (clobber (reg:CC FLAGS_REG))]
10962   "!TARGET_64BIT"
10963   "#"
10964   [(set_attr "type" "multi")])
10965
10966 ;; By default we don't ask for a scratch register, because when DImode
10967 ;; values are manipulated, registers are already at a premium.  But if
10968 ;; we have one handy, we won't turn it away.
10969 (define_peephole2
10970   [(match_scratch:SI 3 "r")
10971    (parallel [(set (match_operand:DI 0 "register_operand" "")
10972                    (ashift:DI (match_operand:DI 1 "nonmemory_operand" "")
10973                               (match_operand:QI 2 "nonmemory_operand" "")))
10974               (clobber (reg:CC FLAGS_REG))])
10975    (match_dup 3)]
10976   "!TARGET_64BIT && TARGET_CMOVE"
10977   [(const_int 0)]
10978   "ix86_split_ashl (operands, operands[3], DImode); DONE;")
10979
10980 (define_split
10981   [(set (match_operand:DI 0 "register_operand" "")
10982         (ashift:DI (match_operand:DI 1 "nonmemory_operand" "")
10983                    (match_operand:QI 2 "nonmemory_operand" "")))
10984    (clobber (reg:CC FLAGS_REG))]
10985   "!TARGET_64BIT && ((optimize > 0 && flag_peephole2)
10986                      ? epilogue_completed : reload_completed)"
10987   [(const_int 0)]
10988   "ix86_split_ashl (operands, NULL_RTX, DImode); DONE;")
10989
10990 (define_insn "x86_shld"
10991   [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m")
10992         (ior:SI (ashift:SI (match_dup 0)
10993                   (match_operand:QI 2 "nonmemory_operand" "Ic"))
10994                 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
10995                   (minus:QI (const_int 32) (match_dup 2)))))
10996    (clobber (reg:CC FLAGS_REG))]
10997   ""
10998   "shld{l}\t{%s2%1, %0|%0, %1, %2}"
10999   [(set_attr "type" "ishift")
11000    (set_attr "prefix_0f" "1")
11001    (set_attr "mode" "SI")
11002    (set_attr "pent_pair" "np")
11003    (set_attr "athlon_decode" "vector")
11004    (set_attr "amdfam10_decode" "vector")])
11005
11006 (define_expand "x86_shift_adj_1"
11007   [(set (reg:CCZ FLAGS_REG)
11008         (compare:CCZ (and:QI (match_operand:QI 2 "register_operand" "")
11009                              (const_int 32))
11010                      (const_int 0)))
11011    (set (match_operand:SI 0 "register_operand" "")
11012         (if_then_else:SI (ne (reg:CCZ FLAGS_REG) (const_int 0))
11013                          (match_operand:SI 1 "register_operand" "")
11014                          (match_dup 0)))
11015    (set (match_dup 1)
11016         (if_then_else:SI (ne (reg:CCZ FLAGS_REG) (const_int 0))
11017                          (match_operand:SI 3 "register_operand" "r")
11018                          (match_dup 1)))]
11019   "TARGET_CMOVE"
11020   "")
11021
11022 (define_expand "x86_shift_adj_2"
11023   [(use (match_operand:SI 0 "register_operand" ""))
11024    (use (match_operand:SI 1 "register_operand" ""))
11025    (use (match_operand:QI 2 "register_operand" ""))]
11026   ""
11027 {
11028   rtx label = gen_label_rtx ();
11029   rtx tmp;
11030
11031   emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (32)));
11032
11033   tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
11034   tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
11035   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
11036                               gen_rtx_LABEL_REF (VOIDmode, label),
11037                               pc_rtx);
11038   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
11039   JUMP_LABEL (tmp) = label;
11040
11041   emit_move_insn (operands[0], operands[1]);
11042   ix86_expand_clear (operands[1]);
11043
11044   emit_label (label);
11045   LABEL_NUSES (label) = 1;
11046
11047   DONE;
11048 })
11049
11050 (define_expand "ashlsi3"
11051   [(set (match_operand:SI 0 "nonimmediate_operand" "")
11052         (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "")
11053                    (match_operand:QI 2 "nonmemory_operand" "")))]
11054   ""
11055   "ix86_expand_binary_operator (ASHIFT, SImode, operands); DONE;")
11056
11057 (define_insn "*ashlsi3_1"
11058   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r")
11059         (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "0,l")
11060                    (match_operand:QI 2 "nonmemory_operand" "cI,M")))
11061    (clobber (reg:CC FLAGS_REG))]
11062   "ix86_binary_operator_ok (ASHIFT, SImode, operands)"
11063 {
11064   switch (get_attr_type (insn))
11065     {
11066     case TYPE_ALU:
11067       gcc_assert (operands[2] == const1_rtx);
11068       gcc_assert (rtx_equal_p (operands[0], operands[1]));
11069       return "add{l}\t%0, %0";
11070
11071     case TYPE_LEA:
11072       return "#";
11073
11074     default:
11075       if (REG_P (operands[2]))
11076         return "sal{l}\t{%b2, %0|%0, %b2}";
11077       else if (operands[2] == const1_rtx
11078                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
11079         return "sal{l}\t%0";
11080       else
11081         return "sal{l}\t{%2, %0|%0, %2}";
11082     }
11083 }
11084   [(set (attr "type")
11085      (cond [(eq_attr "alternative" "1")
11086               (const_string "lea")
11087             (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11088                           (const_int 0))
11089                       (match_operand 0 "register_operand" ""))
11090                  (match_operand 2 "const1_operand" ""))
11091               (const_string "alu")
11092            ]
11093            (const_string "ishift")))
11094    (set (attr "length_immediate")
11095      (if_then_else
11096        (ior (eq_attr "type" "alu")
11097             (and (eq_attr "type" "ishift")
11098                  (and (match_operand 2 "const1_operand" "")
11099                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
11100                           (const_int 0)))))
11101        (const_string "0")
11102        (const_string "*")))
11103    (set_attr "mode" "SI")])
11104
11105 ;; Convert lea to the lea pattern to avoid flags dependency.
11106 (define_split
11107   [(set (match_operand 0 "register_operand" "")
11108         (ashift (match_operand 1 "index_register_operand" "")
11109                 (match_operand:QI 2 "const_int_operand" "")))
11110    (clobber (reg:CC FLAGS_REG))]
11111   "reload_completed
11112    && true_regnum (operands[0]) != true_regnum (operands[1])
11113    && GET_MODE_SIZE (GET_MODE (operands[0])) <= 4"
11114   [(const_int 0)]
11115 {
11116   rtx pat;
11117   enum machine_mode mode = GET_MODE (operands[0]);
11118
11119   if (GET_MODE_SIZE (mode) < 4)
11120     operands[0] = gen_lowpart (SImode, operands[0]);
11121   if (mode != Pmode)
11122     operands[1] = gen_lowpart (Pmode, operands[1]);
11123   operands[2] = gen_int_mode (1 << INTVAL (operands[2]), Pmode);
11124
11125   pat = gen_rtx_MULT (Pmode, operands[1], operands[2]);
11126   if (Pmode != SImode)
11127     pat = gen_rtx_SUBREG (SImode, pat, 0);
11128   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
11129   DONE;
11130 })
11131
11132 ;; Rare case of shifting RSP is handled by generating move and shift
11133 (define_split
11134   [(set (match_operand 0 "register_operand" "")
11135         (ashift (match_operand 1 "register_operand" "")
11136                 (match_operand:QI 2 "const_int_operand" "")))
11137    (clobber (reg:CC FLAGS_REG))]
11138   "reload_completed
11139    && true_regnum (operands[0]) != true_regnum (operands[1])"
11140   [(const_int 0)]
11141 {
11142   rtx pat, clob;
11143   emit_move_insn (operands[0], operands[1]);
11144   pat = gen_rtx_SET (VOIDmode, operands[0],
11145                      gen_rtx_ASHIFT (GET_MODE (operands[0]),
11146                                      operands[0], operands[2]));
11147   clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
11148   emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, pat, clob)));
11149   DONE;
11150 })
11151
11152 (define_insn "*ashlsi3_1_zext"
11153   [(set (match_operand:DI 0 "register_operand" "=r,r")
11154         (zero_extend:DI (ashift:SI (match_operand:SI 1 "register_operand" "0,l")
11155                         (match_operand:QI 2 "nonmemory_operand" "cI,M"))))
11156    (clobber (reg:CC FLAGS_REG))]
11157   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
11158 {
11159   switch (get_attr_type (insn))
11160     {
11161     case TYPE_ALU:
11162       gcc_assert (operands[2] == const1_rtx);
11163       return "add{l}\t%k0, %k0";
11164
11165     case TYPE_LEA:
11166       return "#";
11167
11168     default:
11169       if (REG_P (operands[2]))
11170         return "sal{l}\t{%b2, %k0|%k0, %b2}";
11171       else if (operands[2] == const1_rtx
11172                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
11173         return "sal{l}\t%k0";
11174       else
11175         return "sal{l}\t{%2, %k0|%k0, %2}";
11176     }
11177 }
11178   [(set (attr "type")
11179      (cond [(eq_attr "alternative" "1")
11180               (const_string "lea")
11181             (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11182                      (const_int 0))
11183                  (match_operand 2 "const1_operand" ""))
11184               (const_string "alu")
11185            ]
11186            (const_string "ishift")))
11187    (set (attr "length_immediate")
11188      (if_then_else
11189        (ior (eq_attr "type" "alu")
11190             (and (eq_attr "type" "ishift")
11191                  (and (match_operand 2 "const1_operand" "")
11192                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
11193                           (const_int 0)))))
11194        (const_string "0")
11195        (const_string "*")))
11196    (set_attr "mode" "SI")])
11197
11198 ;; Convert lea to the lea pattern to avoid flags dependency.
11199 (define_split
11200   [(set (match_operand:DI 0 "register_operand" "")
11201         (zero_extend:DI (ashift (match_operand 1 "register_operand" "")
11202                                 (match_operand:QI 2 "const_int_operand" ""))))
11203    (clobber (reg:CC FLAGS_REG))]
11204   "TARGET_64BIT && reload_completed
11205    && true_regnum (operands[0]) != true_regnum (operands[1])"
11206   [(set (match_dup 0) (zero_extend:DI
11207                         (subreg:SI (mult:SI (match_dup 1)
11208                                             (match_dup 2)) 0)))]
11209 {
11210   operands[1] = gen_lowpart (Pmode, operands[1]);
11211   operands[2] = gen_int_mode (1 << INTVAL (operands[2]), Pmode);
11212 })
11213
11214 ;; This pattern can't accept a variable shift count, since shifts by
11215 ;; zero don't affect the flags.  We assume that shifts by constant
11216 ;; zero are optimized away.
11217 (define_insn "*ashlsi3_cmp"
11218   [(set (reg FLAGS_REG)
11219         (compare
11220           (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "0")
11221                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
11222           (const_int 0)))
11223    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
11224         (ashift:SI (match_dup 1) (match_dup 2)))]
11225    "(optimize_function_for_size_p (cfun)
11226      || !TARGET_PARTIAL_FLAG_REG_STALL
11227      || (operands[2] == const1_rtx
11228          && (TARGET_SHIFT1
11229              || (TARGET_DOUBLE_WITH_ADD && REG_P (operands[0])))))
11230    && ix86_match_ccmode (insn, CCGOCmode)
11231    && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
11232 {
11233   switch (get_attr_type (insn))
11234     {
11235     case TYPE_ALU:
11236       gcc_assert (operands[2] == const1_rtx);
11237       return "add{l}\t%0, %0";
11238
11239     default:
11240       if (REG_P (operands[2]))
11241         return "sal{l}\t{%b2, %0|%0, %b2}";
11242       else if (operands[2] == const1_rtx
11243                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
11244         return "sal{l}\t%0";
11245       else
11246         return "sal{l}\t{%2, %0|%0, %2}";
11247     }
11248 }
11249   [(set (attr "type")
11250      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11251                           (const_int 0))
11252                       (match_operand 0 "register_operand" ""))
11253                  (match_operand 2 "const1_operand" ""))
11254               (const_string "alu")
11255            ]
11256            (const_string "ishift")))
11257    (set (attr "length_immediate")
11258      (if_then_else
11259        (ior (eq_attr "type" "alu")
11260             (and (eq_attr "type" "ishift")
11261                  (and (match_operand 2 "const1_operand" "")
11262                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
11263                           (const_int 0)))))
11264        (const_string "0")
11265        (const_string "*")))
11266    (set_attr "mode" "SI")])
11267
11268 (define_insn "*ashlsi3_cconly"
11269   [(set (reg FLAGS_REG)
11270         (compare
11271           (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "0")
11272                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
11273           (const_int 0)))
11274    (clobber (match_scratch:SI 0 "=r"))]
11275   "(optimize_function_for_size_p (cfun)
11276     || !TARGET_PARTIAL_FLAG_REG_STALL
11277     || (operands[2] == const1_rtx
11278         && (TARGET_SHIFT1
11279             || TARGET_DOUBLE_WITH_ADD)))
11280    && ix86_match_ccmode (insn, CCGOCmode)
11281    && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
11282 {
11283   switch (get_attr_type (insn))
11284     {
11285     case TYPE_ALU:
11286       gcc_assert (operands[2] == const1_rtx);
11287       return "add{l}\t%0, %0";
11288
11289     default:
11290       if (REG_P (operands[2]))
11291         return "sal{l}\t{%b2, %0|%0, %b2}";
11292       else if (operands[2] == const1_rtx
11293                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
11294         return "sal{l}\t%0";
11295       else
11296         return "sal{l}\t{%2, %0|%0, %2}";
11297     }
11298 }
11299   [(set (attr "type")
11300      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11301                           (const_int 0))
11302                       (match_operand 0 "register_operand" ""))
11303                  (match_operand 2 "const1_operand" ""))
11304               (const_string "alu")
11305            ]
11306            (const_string "ishift")))
11307    (set (attr "length_immediate")
11308      (if_then_else
11309        (ior (eq_attr "type" "alu")
11310             (and (eq_attr "type" "ishift")
11311                  (and (match_operand 2 "const1_operand" "")
11312                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
11313                           (const_int 0)))))
11314        (const_string "0")
11315        (const_string "*")))
11316    (set_attr "mode" "SI")])
11317
11318 (define_insn "*ashlsi3_cmp_zext"
11319   [(set (reg FLAGS_REG)
11320         (compare
11321           (ashift:SI (match_operand:SI 1 "register_operand" "0")
11322                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
11323           (const_int 0)))
11324    (set (match_operand:DI 0 "register_operand" "=r")
11325         (zero_extend:DI (ashift:SI (match_dup 1) (match_dup 2))))]
11326   "TARGET_64BIT
11327    && (optimize_function_for_size_p (cfun)
11328        || !TARGET_PARTIAL_FLAG_REG_STALL
11329        || (operands[2] == const1_rtx
11330            && (TARGET_SHIFT1
11331                || TARGET_DOUBLE_WITH_ADD)))
11332    && ix86_match_ccmode (insn, CCGOCmode)
11333    && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
11334 {
11335   switch (get_attr_type (insn))
11336     {
11337     case TYPE_ALU:
11338       gcc_assert (operands[2] == const1_rtx);
11339       return "add{l}\t%k0, %k0";
11340
11341     default:
11342       if (REG_P (operands[2]))
11343         return "sal{l}\t{%b2, %k0|%k0, %b2}";
11344       else if (operands[2] == const1_rtx
11345                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
11346         return "sal{l}\t%k0";
11347       else
11348         return "sal{l}\t{%2, %k0|%k0, %2}";
11349     }
11350 }
11351   [(set (attr "type")
11352      (cond [(and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11353                      (const_int 0))
11354                  (match_operand 2 "const1_operand" ""))
11355               (const_string "alu")
11356            ]
11357            (const_string "ishift")))
11358    (set (attr "length_immediate")
11359      (if_then_else
11360        (ior (eq_attr "type" "alu")
11361             (and (eq_attr "type" "ishift")
11362                  (and (match_operand 2 "const1_operand" "")
11363                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
11364                           (const_int 0)))))
11365        (const_string "0")
11366        (const_string "*")))
11367    (set_attr "mode" "SI")])
11368
11369 (define_expand "ashlhi3"
11370   [(set (match_operand:HI 0 "nonimmediate_operand" "")
11371         (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "")
11372                    (match_operand:QI 2 "nonmemory_operand" "")))]
11373   "TARGET_HIMODE_MATH"
11374   "ix86_expand_binary_operator (ASHIFT, HImode, operands); DONE;")
11375
11376 (define_insn "*ashlhi3_1_lea"
11377   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
11378         (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0,l")
11379                    (match_operand:QI 2 "nonmemory_operand" "cI,M")))
11380    (clobber (reg:CC FLAGS_REG))]
11381   "!TARGET_PARTIAL_REG_STALL
11382    && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
11383 {
11384   switch (get_attr_type (insn))
11385     {
11386     case TYPE_LEA:
11387       return "#";
11388     case TYPE_ALU:
11389       gcc_assert (operands[2] == const1_rtx);
11390       return "add{w}\t%0, %0";
11391
11392     default:
11393       if (REG_P (operands[2]))
11394         return "sal{w}\t{%b2, %0|%0, %b2}";
11395       else if (operands[2] == const1_rtx
11396                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
11397         return "sal{w}\t%0";
11398       else
11399         return "sal{w}\t{%2, %0|%0, %2}";
11400     }
11401 }
11402   [(set (attr "type")
11403      (cond [(eq_attr "alternative" "1")
11404               (const_string "lea")
11405             (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11406                           (const_int 0))
11407                       (match_operand 0 "register_operand" ""))
11408                  (match_operand 2 "const1_operand" ""))
11409               (const_string "alu")
11410            ]
11411            (const_string "ishift")))
11412    (set (attr "length_immediate")
11413      (if_then_else
11414        (ior (eq_attr "type" "alu")
11415             (and (eq_attr "type" "ishift")
11416                  (and (match_operand 2 "const1_operand" "")
11417                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
11418                           (const_int 0)))))
11419        (const_string "0")
11420        (const_string "*")))
11421    (set_attr "mode" "HI,SI")])
11422
11423 (define_insn "*ashlhi3_1"
11424   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
11425         (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0")
11426                    (match_operand:QI 2 "nonmemory_operand" "cI")))
11427    (clobber (reg:CC FLAGS_REG))]
11428   "TARGET_PARTIAL_REG_STALL
11429    && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
11430 {
11431   switch (get_attr_type (insn))
11432     {
11433     case TYPE_ALU:
11434       gcc_assert (operands[2] == const1_rtx);
11435       return "add{w}\t%0, %0";
11436
11437     default:
11438       if (REG_P (operands[2]))
11439         return "sal{w}\t{%b2, %0|%0, %b2}";
11440       else if (operands[2] == const1_rtx
11441                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
11442         return "sal{w}\t%0";
11443       else
11444         return "sal{w}\t{%2, %0|%0, %2}";
11445     }
11446 }
11447   [(set (attr "type")
11448      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11449                           (const_int 0))
11450                       (match_operand 0 "register_operand" ""))
11451                  (match_operand 2 "const1_operand" ""))
11452               (const_string "alu")
11453            ]
11454            (const_string "ishift")))
11455    (set (attr "length_immediate")
11456      (if_then_else
11457        (ior (eq_attr "type" "alu")
11458             (and (eq_attr "type" "ishift")
11459                  (and (match_operand 2 "const1_operand" "")
11460                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
11461                           (const_int 0)))))
11462        (const_string "0")
11463        (const_string "*")))
11464    (set_attr "mode" "HI")])
11465
11466 ;; This pattern can't accept a variable shift count, since shifts by
11467 ;; zero don't affect the flags.  We assume that shifts by constant
11468 ;; zero are optimized away.
11469 (define_insn "*ashlhi3_cmp"
11470   [(set (reg FLAGS_REG)
11471         (compare
11472           (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0")
11473                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
11474           (const_int 0)))
11475    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
11476         (ashift:HI (match_dup 1) (match_dup 2)))]
11477   "(optimize_function_for_size_p (cfun)
11478     || !TARGET_PARTIAL_FLAG_REG_STALL
11479     || (operands[2] == const1_rtx
11480         && (TARGET_SHIFT1
11481             || (TARGET_DOUBLE_WITH_ADD && REG_P (operands[0])))))
11482    && ix86_match_ccmode (insn, CCGOCmode)
11483    && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
11484 {
11485   switch (get_attr_type (insn))
11486     {
11487     case TYPE_ALU:
11488       gcc_assert (operands[2] == const1_rtx);
11489       return "add{w}\t%0, %0";
11490
11491     default:
11492       if (REG_P (operands[2]))
11493         return "sal{w}\t{%b2, %0|%0, %b2}";
11494       else if (operands[2] == const1_rtx
11495                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
11496         return "sal{w}\t%0";
11497       else
11498         return "sal{w}\t{%2, %0|%0, %2}";
11499     }
11500 }
11501   [(set (attr "type")
11502      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11503                           (const_int 0))
11504                       (match_operand 0 "register_operand" ""))
11505                  (match_operand 2 "const1_operand" ""))
11506               (const_string "alu")
11507            ]
11508            (const_string "ishift")))
11509    (set (attr "length_immediate")
11510      (if_then_else
11511        (ior (eq_attr "type" "alu")
11512             (and (eq_attr "type" "ishift")
11513                  (and (match_operand 2 "const1_operand" "")
11514                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
11515                           (const_int 0)))))
11516        (const_string "0")
11517        (const_string "*")))
11518    (set_attr "mode" "HI")])
11519
11520 (define_insn "*ashlhi3_cconly"
11521   [(set (reg FLAGS_REG)
11522         (compare
11523           (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0")
11524                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
11525           (const_int 0)))
11526    (clobber (match_scratch:HI 0 "=r"))]
11527   "(optimize_function_for_size_p (cfun)
11528     || !TARGET_PARTIAL_FLAG_REG_STALL
11529     || (operands[2] == const1_rtx
11530         && (TARGET_SHIFT1
11531             || TARGET_DOUBLE_WITH_ADD)))
11532    && ix86_match_ccmode (insn, CCGOCmode)
11533    && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
11534 {
11535   switch (get_attr_type (insn))
11536     {
11537     case TYPE_ALU:
11538       gcc_assert (operands[2] == const1_rtx);
11539       return "add{w}\t%0, %0";
11540
11541     default:
11542       if (REG_P (operands[2]))
11543         return "sal{w}\t{%b2, %0|%0, %b2}";
11544       else if (operands[2] == const1_rtx
11545                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
11546         return "sal{w}\t%0";
11547       else
11548         return "sal{w}\t{%2, %0|%0, %2}";
11549     }
11550 }
11551   [(set (attr "type")
11552      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11553                           (const_int 0))
11554                       (match_operand 0 "register_operand" ""))
11555                  (match_operand 2 "const1_operand" ""))
11556               (const_string "alu")
11557            ]
11558            (const_string "ishift")))
11559    (set (attr "length_immediate")
11560      (if_then_else
11561        (ior (eq_attr "type" "alu")
11562             (and (eq_attr "type" "ishift")
11563                  (and (match_operand 2 "const1_operand" "")
11564                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
11565                           (const_int 0)))))
11566        (const_string "0")
11567        (const_string "*")))
11568    (set_attr "mode" "HI")])
11569
11570 (define_expand "ashlqi3"
11571   [(set (match_operand:QI 0 "nonimmediate_operand" "")
11572         (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "")
11573                    (match_operand:QI 2 "nonmemory_operand" "")))]
11574   "TARGET_QIMODE_MATH"
11575   "ix86_expand_binary_operator (ASHIFT, QImode, operands); DONE;")
11576
11577 ;; %%% Potential partial reg stall on alternative 2.  What to do?
11578
11579 (define_insn "*ashlqi3_1_lea"
11580   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r,r")
11581         (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0,0,l")
11582                    (match_operand:QI 2 "nonmemory_operand" "cI,cI,M")))
11583    (clobber (reg:CC FLAGS_REG))]
11584   "!TARGET_PARTIAL_REG_STALL
11585    && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
11586 {
11587   switch (get_attr_type (insn))
11588     {
11589     case TYPE_LEA:
11590       return "#";
11591     case TYPE_ALU:
11592       gcc_assert (operands[2] == const1_rtx);
11593       if (REG_P (operands[1]) && !ANY_QI_REG_P (operands[1]))
11594         return "add{l}\t%k0, %k0";
11595       else
11596         return "add{b}\t%0, %0";
11597
11598     default:
11599       if (REG_P (operands[2]))
11600         {
11601           if (get_attr_mode (insn) == MODE_SI)
11602             return "sal{l}\t{%b2, %k0|%k0, %b2}";
11603           else
11604             return "sal{b}\t{%b2, %0|%0, %b2}";
11605         }
11606       else if (operands[2] == const1_rtx
11607                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
11608         {
11609           if (get_attr_mode (insn) == MODE_SI)
11610             return "sal{l}\t%0";
11611           else
11612             return "sal{b}\t%0";
11613         }
11614       else
11615         {
11616           if (get_attr_mode (insn) == MODE_SI)
11617             return "sal{l}\t{%2, %k0|%k0, %2}";
11618           else
11619             return "sal{b}\t{%2, %0|%0, %2}";
11620         }
11621     }
11622 }
11623   [(set (attr "type")
11624      (cond [(eq_attr "alternative" "2")
11625               (const_string "lea")
11626             (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11627                           (const_int 0))
11628                       (match_operand 0 "register_operand" ""))
11629                  (match_operand 2 "const1_operand" ""))
11630               (const_string "alu")
11631            ]
11632            (const_string "ishift")))
11633    (set (attr "length_immediate")
11634      (if_then_else
11635        (ior (eq_attr "type" "alu")
11636             (and (eq_attr "type" "ishift")
11637                  (and (match_operand 2 "const1_operand" "")
11638                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
11639                           (const_int 0)))))
11640        (const_string "0")
11641        (const_string "*")))
11642    (set_attr "mode" "QI,SI,SI")])
11643
11644 (define_insn "*ashlqi3_1"
11645   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r")
11646         (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
11647                    (match_operand:QI 2 "nonmemory_operand" "cI,cI")))
11648    (clobber (reg:CC FLAGS_REG))]
11649   "TARGET_PARTIAL_REG_STALL
11650    && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
11651 {
11652   switch (get_attr_type (insn))
11653     {
11654     case TYPE_ALU:
11655       gcc_assert (operands[2] == const1_rtx);
11656       if (REG_P (operands[1]) && !ANY_QI_REG_P (operands[1]))
11657         return "add{l}\t%k0, %k0";
11658       else
11659         return "add{b}\t%0, %0";
11660
11661     default:
11662       if (REG_P (operands[2]))
11663         {
11664           if (get_attr_mode (insn) == MODE_SI)
11665             return "sal{l}\t{%b2, %k0|%k0, %b2}";
11666           else
11667             return "sal{b}\t{%b2, %0|%0, %b2}";
11668         }
11669       else if (operands[2] == const1_rtx
11670                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
11671         {
11672           if (get_attr_mode (insn) == MODE_SI)
11673             return "sal{l}\t%0";
11674           else
11675             return "sal{b}\t%0";
11676         }
11677       else
11678         {
11679           if (get_attr_mode (insn) == MODE_SI)
11680             return "sal{l}\t{%2, %k0|%k0, %2}";
11681           else
11682             return "sal{b}\t{%2, %0|%0, %2}";
11683         }
11684     }
11685 }
11686   [(set (attr "type")
11687      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11688                           (const_int 0))
11689                       (match_operand 0 "register_operand" ""))
11690                  (match_operand 2 "const1_operand" ""))
11691               (const_string "alu")
11692            ]
11693            (const_string "ishift")))
11694    (set (attr "length_immediate")
11695      (if_then_else
11696        (ior (eq_attr "type" "alu")
11697             (and (eq_attr "type" "ishift")
11698                  (and (match_operand 2 "const1_operand" "")
11699                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
11700                           (const_int 0)))))
11701        (const_string "0")
11702        (const_string "*")))
11703    (set_attr "mode" "QI,SI")])
11704
11705 ;; This pattern can't accept a variable shift count, since shifts by
11706 ;; zero don't affect the flags.  We assume that shifts by constant
11707 ;; zero are optimized away.
11708 (define_insn "*ashlqi3_cmp"
11709   [(set (reg FLAGS_REG)
11710         (compare
11711           (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0")
11712                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
11713           (const_int 0)))
11714    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
11715         (ashift:QI (match_dup 1) (match_dup 2)))]
11716   "(optimize_function_for_size_p (cfun)
11717     || !TARGET_PARTIAL_FLAG_REG_STALL
11718     || (operands[2] == const1_rtx
11719         && (TARGET_SHIFT1
11720             || (TARGET_DOUBLE_WITH_ADD && REG_P (operands[0])))))
11721    && ix86_match_ccmode (insn, CCGOCmode)
11722    && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
11723 {
11724   switch (get_attr_type (insn))
11725     {
11726     case TYPE_ALU:
11727       gcc_assert (operands[2] == const1_rtx);
11728       return "add{b}\t%0, %0";
11729
11730     default:
11731       if (REG_P (operands[2]))
11732         return "sal{b}\t{%b2, %0|%0, %b2}";
11733       else if (operands[2] == const1_rtx
11734                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
11735         return "sal{b}\t%0";
11736       else
11737         return "sal{b}\t{%2, %0|%0, %2}";
11738     }
11739 }
11740   [(set (attr "type")
11741      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11742                           (const_int 0))
11743                       (match_operand 0 "register_operand" ""))
11744                  (match_operand 2 "const1_operand" ""))
11745               (const_string "alu")
11746            ]
11747            (const_string "ishift")))
11748    (set (attr "length_immediate")
11749      (if_then_else
11750        (ior (eq_attr "type" "alu")
11751             (and (eq_attr "type" "ishift")
11752                  (and (match_operand 2 "const1_operand" "")
11753                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
11754                           (const_int 0)))))
11755        (const_string "0")
11756        (const_string "*")))
11757    (set_attr "mode" "QI")])
11758
11759 (define_insn "*ashlqi3_cconly"
11760   [(set (reg FLAGS_REG)
11761         (compare
11762           (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0")
11763                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
11764           (const_int 0)))
11765    (clobber (match_scratch:QI 0 "=q"))]
11766   "(optimize_function_for_size_p (cfun)
11767     || !TARGET_PARTIAL_FLAG_REG_STALL
11768     || (operands[2] == const1_rtx
11769         && (TARGET_SHIFT1
11770             || TARGET_DOUBLE_WITH_ADD)))
11771    && ix86_match_ccmode (insn, CCGOCmode)
11772    && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
11773 {
11774   switch (get_attr_type (insn))
11775     {
11776     case TYPE_ALU:
11777       gcc_assert (operands[2] == const1_rtx);
11778       return "add{b}\t%0, %0";
11779
11780     default:
11781       if (REG_P (operands[2]))
11782         return "sal{b}\t{%b2, %0|%0, %b2}";
11783       else if (operands[2] == const1_rtx
11784                && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
11785         return "sal{b}\t%0";
11786       else
11787         return "sal{b}\t{%2, %0|%0, %2}";
11788     }
11789 }
11790   [(set (attr "type")
11791      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
11792                           (const_int 0))
11793                       (match_operand 0 "register_operand" ""))
11794                  (match_operand 2 "const1_operand" ""))
11795               (const_string "alu")
11796            ]
11797            (const_string "ishift")))
11798    (set (attr "length_immediate")
11799      (if_then_else
11800        (ior (eq_attr "type" "alu")
11801             (and (eq_attr "type" "ishift")
11802                  (and (match_operand 2 "const1_operand" "")
11803                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
11804                           (const_int 0)))))
11805        (const_string "0")
11806        (const_string "*")))
11807    (set_attr "mode" "QI")])
11808
11809 ;; See comment above `ashldi3' about how this works.
11810
11811 (define_expand "ashrti3"
11812   [(set (match_operand:TI 0 "register_operand" "")
11813         (ashiftrt:TI (match_operand:TI 1 "register_operand" "")
11814                      (match_operand:QI 2 "nonmemory_operand" "")))]
11815   "TARGET_64BIT"
11816   "ix86_expand_binary_operator (ASHIFTRT, TImode, operands); DONE;")
11817
11818 (define_insn "*ashrti3_1"
11819   [(set (match_operand:TI 0 "register_operand" "=r")
11820         (ashiftrt:TI (match_operand:TI 1 "register_operand" "0")
11821                      (match_operand:QI 2 "nonmemory_operand" "Oc")))
11822    (clobber (reg:CC FLAGS_REG))]
11823   "TARGET_64BIT"
11824   "#"
11825   [(set_attr "type" "multi")])
11826
11827 (define_peephole2
11828   [(match_scratch:DI 3 "r")
11829    (parallel [(set (match_operand:TI 0 "register_operand" "")
11830                    (ashiftrt:TI (match_operand:TI 1 "register_operand" "")
11831                                 (match_operand:QI 2 "nonmemory_operand" "")))
11832               (clobber (reg:CC FLAGS_REG))])
11833    (match_dup 3)]
11834   "TARGET_64BIT"
11835   [(const_int 0)]
11836   "ix86_split_ashr (operands, operands[3], TImode); DONE;")
11837
11838 (define_split
11839   [(set (match_operand:TI 0 "register_operand" "")
11840         (ashiftrt:TI (match_operand:TI 1 "register_operand" "")
11841                      (match_operand:QI 2 "nonmemory_operand" "")))
11842    (clobber (reg:CC FLAGS_REG))]
11843   "TARGET_64BIT && ((optimize > 0 && flag_peephole2)
11844                     ? epilogue_completed : reload_completed)"
11845   [(const_int 0)]
11846   "ix86_split_ashr (operands, NULL_RTX, TImode); DONE;")
11847
11848 (define_insn "x86_64_shrd"
11849   [(set (match_operand:DI 0 "nonimmediate_operand" "+r*m")
11850         (ior:DI (ashiftrt:DI (match_dup 0)
11851                   (match_operand:QI 2 "nonmemory_operand" "Jc"))
11852                 (ashift:DI (match_operand:DI 1 "register_operand" "r")
11853                   (minus:QI (const_int 64) (match_dup 2)))))
11854    (clobber (reg:CC FLAGS_REG))]
11855   "TARGET_64BIT"
11856   "shrd{q}\t{%s2%1, %0|%0, %1, %2}"
11857   [(set_attr "type" "ishift")
11858    (set_attr "prefix_0f" "1")
11859    (set_attr "mode" "DI")
11860    (set_attr "athlon_decode" "vector")
11861    (set_attr "amdfam10_decode" "vector")])
11862
11863 (define_expand "ashrdi3"
11864   [(set (match_operand:DI 0 "shiftdi_operand" "")
11865         (ashiftrt:DI (match_operand:DI 1 "shiftdi_operand" "")
11866                      (match_operand:QI 2 "nonmemory_operand" "")))]
11867   ""
11868   "ix86_expand_binary_operator (ASHIFTRT, DImode, operands); DONE;")
11869
11870 (define_expand "x86_64_shift_adj_3"
11871   [(use (match_operand:DI 0 "register_operand" ""))
11872    (use (match_operand:DI 1 "register_operand" ""))
11873    (use (match_operand:QI 2 "register_operand" ""))]
11874   ""
11875 {
11876   rtx label = gen_label_rtx ();
11877   rtx tmp;
11878
11879   emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (64)));
11880
11881   tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
11882   tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
11883   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
11884                               gen_rtx_LABEL_REF (VOIDmode, label),
11885                               pc_rtx);
11886   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
11887   JUMP_LABEL (tmp) = label;
11888
11889   emit_move_insn (operands[0], operands[1]);
11890   emit_insn (gen_ashrdi3_63_rex64 (operands[1], operands[1], GEN_INT (63)));
11891
11892   emit_label (label);
11893   LABEL_NUSES (label) = 1;
11894
11895   DONE;
11896 })
11897
11898 (define_insn "ashrdi3_63_rex64"
11899   [(set (match_operand:DI 0 "nonimmediate_operand" "=*d,rm")
11900         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "*a,0")
11901                      (match_operand:DI 2 "const_int_operand" "i,i")))
11902    (clobber (reg:CC FLAGS_REG))]
11903   "TARGET_64BIT && INTVAL (operands[2]) == 63
11904    && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
11905    && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
11906   "@
11907    {cqto|cqo}
11908    sar{q}\t{%2, %0|%0, %2}"
11909   [(set_attr "type" "imovx,ishift")
11910    (set_attr "prefix_0f" "0,*")
11911    (set_attr "length_immediate" "0,*")
11912    (set_attr "modrm" "0,1")
11913    (set_attr "mode" "DI")])
11914
11915 (define_insn "*ashrdi3_1_one_bit_rex64"
11916   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
11917         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
11918                      (match_operand:QI 2 "const1_operand" "")))
11919    (clobber (reg:CC FLAGS_REG))]
11920   "TARGET_64BIT
11921    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
11922    && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
11923   "sar{q}\t%0"
11924   [(set_attr "type" "ishift")
11925    (set_attr "length_immediate" "0")
11926    (set_attr "mode" "DI")])
11927
11928 (define_insn "*ashrdi3_1_rex64"
11929   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,rm")
11930         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
11931                      (match_operand:QI 2 "nonmemory_operand" "J,c")))
11932    (clobber (reg:CC FLAGS_REG))]
11933   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
11934   "@
11935    sar{q}\t{%2, %0|%0, %2}
11936    sar{q}\t{%b2, %0|%0, %b2}"
11937   [(set_attr "type" "ishift")
11938    (set_attr "mode" "DI")])
11939
11940 ;; This pattern can't accept a variable shift count, since shifts by
11941 ;; zero don't affect the flags.  We assume that shifts by constant
11942 ;; zero are optimized away.
11943 (define_insn "*ashrdi3_one_bit_cmp_rex64"
11944   [(set (reg FLAGS_REG)
11945         (compare
11946           (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
11947                        (match_operand:QI 2 "const1_operand" ""))
11948           (const_int 0)))
11949    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
11950         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
11951   "TARGET_64BIT
11952    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
11953    && ix86_match_ccmode (insn, CCGOCmode)
11954    && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
11955   "sar{q}\t%0"
11956   [(set_attr "type" "ishift")
11957    (set_attr "length_immediate" "0")
11958    (set_attr "mode" "DI")])
11959
11960 (define_insn "*ashrdi3_one_bit_cconly_rex64"
11961   [(set (reg FLAGS_REG)
11962         (compare
11963           (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
11964                        (match_operand:QI 2 "const1_operand" ""))
11965           (const_int 0)))
11966    (clobber (match_scratch:DI 0 "=r"))]
11967   "TARGET_64BIT
11968    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
11969    && ix86_match_ccmode (insn, CCGOCmode)
11970    && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
11971   "sar{q}\t%0"
11972   [(set_attr "type" "ishift")
11973    (set_attr "length_immediate" "0")
11974    (set_attr "mode" "DI")])
11975
11976 ;; This pattern can't accept a variable shift count, since shifts by
11977 ;; zero don't affect the flags.  We assume that shifts by constant
11978 ;; zero are optimized away.
11979 (define_insn "*ashrdi3_cmp_rex64"
11980   [(set (reg FLAGS_REG)
11981         (compare
11982           (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
11983                        (match_operand:QI 2 "const_1_to_63_operand" "J"))
11984           (const_int 0)))
11985    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
11986         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
11987   "TARGET_64BIT
11988    && (optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
11989    && ix86_match_ccmode (insn, CCGOCmode)
11990    && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
11991   "sar{q}\t{%2, %0|%0, %2}"
11992   [(set_attr "type" "ishift")
11993    (set_attr "mode" "DI")])
11994
11995 (define_insn "*ashrdi3_cconly_rex64"
11996   [(set (reg FLAGS_REG)
11997         (compare
11998           (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
11999                        (match_operand:QI 2 "const_1_to_63_operand" "J"))
12000           (const_int 0)))
12001    (clobber (match_scratch:DI 0 "=r"))]
12002   "TARGET_64BIT
12003    && (optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
12004    && ix86_match_ccmode (insn, CCGOCmode)
12005    && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
12006   "sar{q}\t{%2, %0|%0, %2}"
12007   [(set_attr "type" "ishift")
12008    (set_attr "mode" "DI")])
12009
12010 (define_insn "*ashrdi3_1"
12011   [(set (match_operand:DI 0 "register_operand" "=r")
12012         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0")
12013                      (match_operand:QI 2 "nonmemory_operand" "Jc")))
12014    (clobber (reg:CC FLAGS_REG))]
12015   "!TARGET_64BIT"
12016   "#"
12017   [(set_attr "type" "multi")])
12018
12019 ;; By default we don't ask for a scratch register, because when DImode
12020 ;; values are manipulated, registers are already at a premium.  But if
12021 ;; we have one handy, we won't turn it away.
12022 (define_peephole2
12023   [(match_scratch:SI 3 "r")
12024    (parallel [(set (match_operand:DI 0 "register_operand" "")
12025                    (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
12026                                 (match_operand:QI 2 "nonmemory_operand" "")))
12027               (clobber (reg:CC FLAGS_REG))])
12028    (match_dup 3)]
12029   "!TARGET_64BIT && TARGET_CMOVE"
12030   [(const_int 0)]
12031   "ix86_split_ashr (operands, operands[3], DImode); DONE;")
12032
12033 (define_split
12034   [(set (match_operand:DI 0 "register_operand" "")
12035         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
12036                      (match_operand:QI 2 "nonmemory_operand" "")))
12037    (clobber (reg:CC FLAGS_REG))]
12038   "!TARGET_64BIT && ((optimize > 0 && flag_peephole2)
12039                      ? epilogue_completed : reload_completed)"
12040   [(const_int 0)]
12041   "ix86_split_ashr (operands, NULL_RTX, DImode); DONE;")
12042
12043 (define_insn "x86_shrd"
12044   [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m")
12045         (ior:SI (ashiftrt:SI (match_dup 0)
12046                   (match_operand:QI 2 "nonmemory_operand" "Ic"))
12047                 (ashift:SI (match_operand:SI 1 "register_operand" "r")
12048                   (minus:QI (const_int 32) (match_dup 2)))))
12049    (clobber (reg:CC FLAGS_REG))]
12050   ""
12051   "shrd{l}\t{%s2%1, %0|%0, %1, %2}"
12052   [(set_attr "type" "ishift")
12053    (set_attr "prefix_0f" "1")
12054    (set_attr "pent_pair" "np")
12055    (set_attr "mode" "SI")])
12056
12057 (define_expand "x86_shift_adj_3"
12058   [(use (match_operand:SI 0 "register_operand" ""))
12059    (use (match_operand:SI 1 "register_operand" ""))
12060    (use (match_operand:QI 2 "register_operand" ""))]
12061   ""
12062 {
12063   rtx label = gen_label_rtx ();
12064   rtx tmp;
12065
12066   emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (32)));
12067
12068   tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
12069   tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
12070   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
12071                               gen_rtx_LABEL_REF (VOIDmode, label),
12072                               pc_rtx);
12073   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
12074   JUMP_LABEL (tmp) = label;
12075
12076   emit_move_insn (operands[0], operands[1]);
12077   emit_insn (gen_ashrsi3_31 (operands[1], operands[1], GEN_INT (31)));
12078
12079   emit_label (label);
12080   LABEL_NUSES (label) = 1;
12081
12082   DONE;
12083 })
12084
12085 (define_expand "ashrsi3_31"
12086   [(parallel [(set (match_operand:SI 0 "nonimmediate_operand" "=*d,rm")
12087                    (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "*a,0")
12088                                 (match_operand:SI 2 "const_int_operand" "i,i")))
12089               (clobber (reg:CC FLAGS_REG))])]
12090   "")
12091
12092 (define_insn "*ashrsi3_31"
12093   [(set (match_operand:SI 0 "nonimmediate_operand" "=*d,rm")
12094         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "*a,0")
12095                      (match_operand:SI 2 "const_int_operand" "i,i")))
12096    (clobber (reg:CC FLAGS_REG))]
12097   "INTVAL (operands[2]) == 31
12098    && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
12099    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
12100   "@
12101    {cltd|cdq}
12102    sar{l}\t{%2, %0|%0, %2}"
12103   [(set_attr "type" "imovx,ishift")
12104    (set_attr "prefix_0f" "0,*")
12105    (set_attr "length_immediate" "0,*")
12106    (set_attr "modrm" "0,1")
12107    (set_attr "mode" "SI")])
12108
12109 (define_insn "*ashrsi3_31_zext"
12110   [(set (match_operand:DI 0 "register_operand" "=*d,r")
12111         (zero_extend:DI (ashiftrt:SI (match_operand:SI 1 "register_operand" "*a,0")
12112                                      (match_operand:SI 2 "const_int_operand" "i,i"))))
12113    (clobber (reg:CC FLAGS_REG))]
12114   "TARGET_64BIT && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
12115    && INTVAL (operands[2]) == 31
12116    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
12117   "@
12118    {cltd|cdq}
12119    sar{l}\t{%2, %k0|%k0, %2}"
12120   [(set_attr "type" "imovx,ishift")
12121    (set_attr "prefix_0f" "0,*")
12122    (set_attr "length_immediate" "0,*")
12123    (set_attr "modrm" "0,1")
12124    (set_attr "mode" "SI")])
12125
12126 (define_expand "ashrsi3"
12127   [(set (match_operand:SI 0 "nonimmediate_operand" "")
12128         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "")
12129                      (match_operand:QI 2 "nonmemory_operand" "")))]
12130   ""
12131   "ix86_expand_binary_operator (ASHIFTRT, SImode, operands); DONE;")
12132
12133 (define_insn "*ashrsi3_1_one_bit"
12134   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
12135         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12136                      (match_operand:QI 2 "const1_operand" "")))
12137    (clobber (reg:CC FLAGS_REG))]
12138   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12139    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
12140   "sar{l}\t%0"
12141   [(set_attr "type" "ishift")
12142    (set_attr "length_immediate" "0")
12143    (set_attr "mode" "SI")])
12144
12145 (define_insn "*ashrsi3_1_one_bit_zext"
12146   [(set (match_operand:DI 0 "register_operand" "=r")
12147         (zero_extend:DI (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
12148                                      (match_operand:QI 2 "const1_operand" ""))))
12149    (clobber (reg:CC FLAGS_REG))]
12150   "TARGET_64BIT
12151    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12152    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
12153   "sar{l}\t%k0"
12154   [(set_attr "type" "ishift")
12155    (set_attr "length_immediate" "0")
12156    (set_attr "mode" "SI")])
12157
12158 (define_insn "*ashrsi3_1"
12159   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,rm")
12160         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
12161                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12162    (clobber (reg:CC FLAGS_REG))]
12163   "ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
12164   "@
12165    sar{l}\t{%2, %0|%0, %2}
12166    sar{l}\t{%b2, %0|%0, %b2}"
12167   [(set_attr "type" "ishift")
12168    (set_attr "mode" "SI")])
12169
12170 (define_insn "*ashrsi3_1_zext"
12171   [(set (match_operand:DI 0 "register_operand" "=r,r")
12172         (zero_extend:DI (ashiftrt:SI (match_operand:SI 1 "register_operand" "0,0")
12173                                      (match_operand:QI 2 "nonmemory_operand" "I,c"))))
12174    (clobber (reg:CC FLAGS_REG))]
12175   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
12176   "@
12177    sar{l}\t{%2, %k0|%k0, %2}
12178    sar{l}\t{%b2, %k0|%k0, %b2}"
12179   [(set_attr "type" "ishift")
12180    (set_attr "mode" "SI")])
12181
12182 ;; This pattern can't accept a variable shift count, since shifts by
12183 ;; zero don't affect the flags.  We assume that shifts by constant
12184 ;; zero are optimized away.
12185 (define_insn "*ashrsi3_one_bit_cmp"
12186   [(set (reg FLAGS_REG)
12187         (compare
12188           (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12189                        (match_operand:QI 2 "const1_operand" ""))
12190           (const_int 0)))
12191    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
12192         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
12193   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12194    && ix86_match_ccmode (insn, CCGOCmode)
12195    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
12196   "sar{l}\t%0"
12197   [(set_attr "type" "ishift")
12198    (set_attr "length_immediate" "0")
12199    (set_attr "mode" "SI")])
12200
12201 (define_insn "*ashrsi3_one_bit_cconly"
12202   [(set (reg FLAGS_REG)
12203         (compare
12204           (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12205                        (match_operand:QI 2 "const1_operand" ""))
12206           (const_int 0)))
12207    (clobber (match_scratch:SI 0 "=r"))]
12208   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12209    && ix86_match_ccmode (insn, CCGOCmode)
12210    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
12211   "sar{l}\t%0"
12212   [(set_attr "type" "ishift")
12213    (set_attr "length_immediate" "0")
12214    (set_attr "mode" "SI")])
12215
12216 (define_insn "*ashrsi3_one_bit_cmp_zext"
12217   [(set (reg FLAGS_REG)
12218         (compare
12219           (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
12220                        (match_operand:QI 2 "const1_operand" ""))
12221           (const_int 0)))
12222    (set (match_operand:DI 0 "register_operand" "=r")
12223         (zero_extend:DI (ashiftrt:SI (match_dup 1) (match_dup 2))))]
12224   "TARGET_64BIT
12225    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12226    && ix86_match_ccmode (insn, CCmode)
12227    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
12228   "sar{l}\t%k0"
12229   [(set_attr "type" "ishift")
12230    (set_attr "length_immediate" "0")
12231    (set_attr "mode" "SI")])
12232
12233 ;; This pattern can't accept a variable shift count, since shifts by
12234 ;; zero don't affect the flags.  We assume that shifts by constant
12235 ;; zero are optimized away.
12236 (define_insn "*ashrsi3_cmp"
12237   [(set (reg FLAGS_REG)
12238         (compare
12239           (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12240                        (match_operand:QI 2 "const_1_to_31_operand" "I"))
12241           (const_int 0)))
12242    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
12243         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
12244   "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
12245    && ix86_match_ccmode (insn, CCGOCmode)
12246    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
12247   "sar{l}\t{%2, %0|%0, %2}"
12248   [(set_attr "type" "ishift")
12249    (set_attr "mode" "SI")])
12250
12251 (define_insn "*ashrsi3_cconly"
12252   [(set (reg FLAGS_REG)
12253         (compare
12254           (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12255                        (match_operand:QI 2 "const_1_to_31_operand" "I"))
12256           (const_int 0)))
12257    (clobber (match_scratch:SI 0 "=r"))]
12258   "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
12259    && ix86_match_ccmode (insn, CCGOCmode)
12260    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
12261   "sar{l}\t{%2, %0|%0, %2}"
12262   [(set_attr "type" "ishift")
12263    (set_attr "mode" "SI")])
12264
12265 (define_insn "*ashrsi3_cmp_zext"
12266   [(set (reg FLAGS_REG)
12267         (compare
12268           (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
12269                        (match_operand:QI 2 "const_1_to_31_operand" "I"))
12270           (const_int 0)))
12271    (set (match_operand:DI 0 "register_operand" "=r")
12272         (zero_extend:DI (ashiftrt:SI (match_dup 1) (match_dup 2))))]
12273   "TARGET_64BIT
12274    && (optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
12275    && ix86_match_ccmode (insn, CCGOCmode)
12276    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
12277   "sar{l}\t{%2, %k0|%k0, %2}"
12278   [(set_attr "type" "ishift")
12279    (set_attr "mode" "SI")])
12280
12281 (define_expand "ashrhi3"
12282   [(set (match_operand:HI 0 "nonimmediate_operand" "")
12283         (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "")
12284                      (match_operand:QI 2 "nonmemory_operand" "")))]
12285   "TARGET_HIMODE_MATH"
12286   "ix86_expand_binary_operator (ASHIFTRT, HImode, operands); DONE;")
12287
12288 (define_insn "*ashrhi3_1_one_bit"
12289   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12290         (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12291                      (match_operand:QI 2 "const1_operand" "")))
12292    (clobber (reg:CC FLAGS_REG))]
12293   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12294    && ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
12295   "sar{w}\t%0"
12296   [(set_attr "type" "ishift")
12297    (set_attr "length_immediate" "0")
12298    (set_attr "mode" "HI")])
12299
12300 (define_insn "*ashrhi3_1"
12301   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,rm")
12302         (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
12303                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12304    (clobber (reg:CC FLAGS_REG))]
12305   "ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
12306   "@
12307    sar{w}\t{%2, %0|%0, %2}
12308    sar{w}\t{%b2, %0|%0, %b2}"
12309   [(set_attr "type" "ishift")
12310    (set_attr "mode" "HI")])
12311
12312 ;; This pattern can't accept a variable shift count, since shifts by
12313 ;; zero don't affect the flags.  We assume that shifts by constant
12314 ;; zero are optimized away.
12315 (define_insn "*ashrhi3_one_bit_cmp"
12316   [(set (reg FLAGS_REG)
12317         (compare
12318           (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12319                        (match_operand:QI 2 "const1_operand" ""))
12320           (const_int 0)))
12321    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12322         (ashiftrt:HI (match_dup 1) (match_dup 2)))]
12323   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12324    && ix86_match_ccmode (insn, CCGOCmode)
12325    && ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
12326   "sar{w}\t%0"
12327   [(set_attr "type" "ishift")
12328    (set_attr "length_immediate" "0")
12329    (set_attr "mode" "HI")])
12330
12331 (define_insn "*ashrhi3_one_bit_cconly"
12332   [(set (reg FLAGS_REG)
12333         (compare
12334           (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12335                        (match_operand:QI 2 "const1_operand" ""))
12336           (const_int 0)))
12337    (clobber (match_scratch:HI 0 "=r"))]
12338   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12339    && ix86_match_ccmode (insn, CCGOCmode)
12340    && ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
12341   "sar{w}\t%0"
12342   [(set_attr "type" "ishift")
12343    (set_attr "length_immediate" "0")
12344    (set_attr "mode" "HI")])
12345
12346 ;; This pattern can't accept a variable shift count, since shifts by
12347 ;; zero don't affect the flags.  We assume that shifts by constant
12348 ;; zero are optimized away.
12349 (define_insn "*ashrhi3_cmp"
12350   [(set (reg FLAGS_REG)
12351         (compare
12352           (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12353                        (match_operand:QI 2 "const_1_to_31_operand" "I"))
12354           (const_int 0)))
12355    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12356         (ashiftrt:HI (match_dup 1) (match_dup 2)))]
12357   "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
12358    && ix86_match_ccmode (insn, CCGOCmode)
12359    && ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
12360   "sar{w}\t{%2, %0|%0, %2}"
12361   [(set_attr "type" "ishift")
12362    (set_attr "mode" "HI")])
12363
12364 (define_insn "*ashrhi3_cconly"
12365   [(set (reg FLAGS_REG)
12366         (compare
12367           (ashiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12368                        (match_operand:QI 2 "const_1_to_31_operand" "I"))
12369           (const_int 0)))
12370    (clobber (match_scratch:HI 0 "=r"))]
12371   "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
12372    && ix86_match_ccmode (insn, CCGOCmode)
12373    && ix86_binary_operator_ok (ASHIFTRT, HImode, operands)"
12374   "sar{w}\t{%2, %0|%0, %2}"
12375   [(set_attr "type" "ishift")
12376    (set_attr "mode" "HI")])
12377
12378 (define_expand "ashrqi3"
12379   [(set (match_operand:QI 0 "nonimmediate_operand" "")
12380         (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "")
12381                      (match_operand:QI 2 "nonmemory_operand" "")))]
12382   "TARGET_QIMODE_MATH"
12383   "ix86_expand_binary_operator (ASHIFTRT, QImode, operands); DONE;")
12384
12385 (define_insn "*ashrqi3_1_one_bit"
12386   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
12387         (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12388                      (match_operand:QI 2 "const1_operand" "")))
12389    (clobber (reg:CC FLAGS_REG))]
12390   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12391    && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
12392   "sar{b}\t%0"
12393   [(set_attr "type" "ishift")
12394    (set_attr "length_immediate" "0")
12395    (set_attr "mode" "QI")])
12396
12397 (define_insn "*ashrqi3_1_one_bit_slp"
12398   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
12399         (ashiftrt:QI (match_dup 0)
12400                      (match_operand:QI 1 "const1_operand" "")))
12401    (clobber (reg:CC FLAGS_REG))]
12402   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
12403    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12404    && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
12405   "sar{b}\t%0"
12406   [(set_attr "type" "ishift1")
12407    (set_attr "length_immediate" "0")
12408    (set_attr "mode" "QI")])
12409
12410 (define_insn "*ashrqi3_1"
12411   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,qm")
12412         (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
12413                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12414    (clobber (reg:CC FLAGS_REG))]
12415   "ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
12416   "@
12417    sar{b}\t{%2, %0|%0, %2}
12418    sar{b}\t{%b2, %0|%0, %b2}"
12419   [(set_attr "type" "ishift")
12420    (set_attr "mode" "QI")])
12421
12422 (define_insn "*ashrqi3_1_slp"
12423   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,qm"))
12424         (ashiftrt:QI (match_dup 0)
12425                      (match_operand:QI 1 "nonmemory_operand" "I,c")))
12426    (clobber (reg:CC FLAGS_REG))]
12427   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
12428    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
12429   "@
12430    sar{b}\t{%1, %0|%0, %1}
12431    sar{b}\t{%b1, %0|%0, %b1}"
12432   [(set_attr "type" "ishift1")
12433    (set_attr "mode" "QI")])
12434
12435 ;; This pattern can't accept a variable shift count, since shifts by
12436 ;; zero don't affect the flags.  We assume that shifts by constant
12437 ;; zero are optimized away.
12438 (define_insn "*ashrqi3_one_bit_cmp"
12439   [(set (reg FLAGS_REG)
12440         (compare
12441           (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12442                        (match_operand:QI 2 "const1_operand" "I"))
12443           (const_int 0)))
12444    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
12445         (ashiftrt:QI (match_dup 1) (match_dup 2)))]
12446   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12447    && ix86_match_ccmode (insn, CCGOCmode)
12448    && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
12449   "sar{b}\t%0"
12450   [(set_attr "type" "ishift")
12451    (set_attr "length_immediate" "0")
12452    (set_attr "mode" "QI")])
12453
12454 (define_insn "*ashrqi3_one_bit_cconly"
12455   [(set (reg FLAGS_REG)
12456         (compare
12457           (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12458                        (match_operand:QI 2 "const1_operand" ""))
12459           (const_int 0)))
12460    (clobber (match_scratch:QI 0 "=q"))]
12461   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12462    && ix86_match_ccmode (insn, CCGOCmode)
12463    && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
12464   "sar{b}\t%0"
12465   [(set_attr "type" "ishift")
12466    (set_attr "length_immediate" "0")
12467    (set_attr "mode" "QI")])
12468
12469 ;; This pattern can't accept a variable shift count, since shifts by
12470 ;; zero don't affect the flags.  We assume that shifts by constant
12471 ;; zero are optimized away.
12472 (define_insn "*ashrqi3_cmp"
12473   [(set (reg FLAGS_REG)
12474         (compare
12475           (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12476                        (match_operand:QI 2 "const_1_to_31_operand" "I"))
12477           (const_int 0)))
12478    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
12479         (ashiftrt:QI (match_dup 1) (match_dup 2)))]
12480   "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
12481    && ix86_match_ccmode (insn, CCGOCmode)
12482    && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
12483   "sar{b}\t{%2, %0|%0, %2}"
12484   [(set_attr "type" "ishift")
12485    (set_attr "mode" "QI")])
12486
12487 (define_insn "*ashrqi3_cconly"
12488   [(set (reg FLAGS_REG)
12489         (compare
12490           (ashiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12491                        (match_operand:QI 2 "const_1_to_31_operand" "I"))
12492           (const_int 0)))
12493    (clobber (match_scratch:QI 0 "=q"))]
12494   "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
12495    && ix86_match_ccmode (insn, CCGOCmode)
12496    && ix86_binary_operator_ok (ASHIFTRT, QImode, operands)"
12497   "sar{b}\t{%2, %0|%0, %2}"
12498   [(set_attr "type" "ishift")
12499    (set_attr "mode" "QI")])
12500
12501 \f
12502 ;; Logical shift instructions
12503
12504 ;; See comment above `ashldi3' about how this works.
12505
12506 (define_expand "lshrti3"
12507   [(set (match_operand:TI 0 "register_operand" "")
12508         (lshiftrt:TI (match_operand:TI 1 "register_operand" "")
12509                      (match_operand:QI 2 "nonmemory_operand" "")))]
12510   "TARGET_64BIT"
12511   "ix86_expand_binary_operator (LSHIFTRT, TImode, operands); DONE;")
12512
12513 ;; This pattern must be defined before *lshrti3_1 to prevent
12514 ;; combine pass from converting sse2_lshrti3 to *lshrti3_1.
12515
12516 (define_insn "*avx_lshrti3"
12517   [(set (match_operand:TI 0 "register_operand" "=x")
12518         (lshiftrt:TI (match_operand:TI 1 "register_operand" "x")
12519                      (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n")))]
12520   "TARGET_AVX"
12521 {
12522   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
12523   return "vpsrldq\t{%2, %1, %0|%0, %1, %2}";
12524 }
12525   [(set_attr "type" "sseishft")
12526    (set_attr "prefix" "vex")
12527    (set_attr "length_immediate" "1")
12528    (set_attr "mode" "TI")])
12529
12530 (define_insn "sse2_lshrti3"
12531   [(set (match_operand:TI 0 "register_operand" "=x")
12532         (lshiftrt:TI (match_operand:TI 1 "register_operand" "0")
12533                      (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n")))]
12534   "TARGET_SSE2"
12535 {
12536   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
12537   return "psrldq\t{%2, %0|%0, %2}";
12538 }
12539   [(set_attr "type" "sseishft")
12540    (set_attr "prefix_data16" "1")
12541    (set_attr "length_immediate" "1")
12542    (set_attr "mode" "TI")])
12543
12544 (define_insn "*lshrti3_1"
12545   [(set (match_operand:TI 0 "register_operand" "=r")
12546         (lshiftrt:TI (match_operand:TI 1 "register_operand" "0")
12547                      (match_operand:QI 2 "nonmemory_operand" "Oc")))
12548    (clobber (reg:CC FLAGS_REG))]
12549   "TARGET_64BIT"
12550   "#"
12551   [(set_attr "type" "multi")])
12552
12553 (define_peephole2
12554   [(match_scratch:DI 3 "r")
12555    (parallel [(set (match_operand:TI 0 "register_operand" "")
12556                    (lshiftrt:TI (match_operand:TI 1 "register_operand" "")
12557                                 (match_operand:QI 2 "nonmemory_operand" "")))
12558               (clobber (reg:CC FLAGS_REG))])
12559    (match_dup 3)]
12560   "TARGET_64BIT"
12561   [(const_int 0)]
12562   "ix86_split_lshr (operands, operands[3], TImode); DONE;")
12563
12564 (define_split
12565   [(set (match_operand:TI 0 "register_operand" "")
12566         (lshiftrt:TI (match_operand:TI 1 "register_operand" "")
12567                      (match_operand:QI 2 "nonmemory_operand" "")))
12568    (clobber (reg:CC FLAGS_REG))]
12569   "TARGET_64BIT && ((optimize > 0 && flag_peephole2)
12570                     ? epilogue_completed : reload_completed)"
12571   [(const_int 0)]
12572   "ix86_split_lshr (operands, NULL_RTX, TImode); DONE;")
12573
12574 (define_expand "lshrdi3"
12575   [(set (match_operand:DI 0 "shiftdi_operand" "")
12576         (lshiftrt:DI (match_operand:DI 1 "shiftdi_operand" "")
12577                      (match_operand:QI 2 "nonmemory_operand" "")))]
12578   ""
12579   "ix86_expand_binary_operator (LSHIFTRT, DImode, operands); DONE;")
12580
12581 (define_insn "*lshrdi3_1_one_bit_rex64"
12582   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
12583         (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
12584                      (match_operand:QI 2 "const1_operand" "")))
12585    (clobber (reg:CC FLAGS_REG))]
12586   "TARGET_64BIT
12587    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12588    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12589   "shr{q}\t%0"
12590   [(set_attr "type" "ishift")
12591    (set_attr "length_immediate" "0")
12592    (set_attr "mode" "DI")])
12593
12594 (define_insn "*lshrdi3_1_rex64"
12595   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,rm")
12596         (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
12597                      (match_operand:QI 2 "nonmemory_operand" "J,c")))
12598    (clobber (reg:CC FLAGS_REG))]
12599   "TARGET_64BIT && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12600   "@
12601    shr{q}\t{%2, %0|%0, %2}
12602    shr{q}\t{%b2, %0|%0, %b2}"
12603   [(set_attr "type" "ishift")
12604    (set_attr "mode" "DI")])
12605
12606 ;; This pattern can't accept a variable shift count, since shifts by
12607 ;; zero don't affect the flags.  We assume that shifts by constant
12608 ;; zero are optimized away.
12609 (define_insn "*lshrdi3_cmp_one_bit_rex64"
12610   [(set (reg FLAGS_REG)
12611         (compare
12612           (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
12613                        (match_operand:QI 2 "const1_operand" ""))
12614           (const_int 0)))
12615    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
12616         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
12617   "TARGET_64BIT
12618    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12619    && ix86_match_ccmode (insn, CCGOCmode)
12620    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12621   "shr{q}\t%0"
12622   [(set_attr "type" "ishift")
12623    (set_attr "length_immediate" "0")
12624    (set_attr "mode" "DI")])
12625
12626 (define_insn "*lshrdi3_cconly_one_bit_rex64"
12627   [(set (reg FLAGS_REG)
12628         (compare
12629           (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
12630                        (match_operand:QI 2 "const1_operand" ""))
12631           (const_int 0)))
12632    (clobber (match_scratch:DI 0 "=r"))]
12633   "TARGET_64BIT
12634    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12635    && ix86_match_ccmode (insn, CCGOCmode)
12636    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12637   "shr{q}\t%0"
12638   [(set_attr "type" "ishift")
12639    (set_attr "length_immediate" "0")
12640    (set_attr "mode" "DI")])
12641
12642 ;; This pattern can't accept a variable shift count, since shifts by
12643 ;; zero don't affect the flags.  We assume that shifts by constant
12644 ;; zero are optimized away.
12645 (define_insn "*lshrdi3_cmp_rex64"
12646   [(set (reg FLAGS_REG)
12647         (compare
12648           (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
12649                        (match_operand:QI 2 "const_1_to_63_operand" "J"))
12650           (const_int 0)))
12651    (set (match_operand:DI 0 "nonimmediate_operand" "=rm")
12652         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
12653   "TARGET_64BIT
12654    && (optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
12655    && ix86_match_ccmode (insn, CCGOCmode)
12656    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12657   "shr{q}\t{%2, %0|%0, %2}"
12658   [(set_attr "type" "ishift")
12659    (set_attr "mode" "DI")])
12660
12661 (define_insn "*lshrdi3_cconly_rex64"
12662   [(set (reg FLAGS_REG)
12663         (compare
12664           (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0")
12665                        (match_operand:QI 2 "const_1_to_63_operand" "J"))
12666           (const_int 0)))
12667    (clobber (match_scratch:DI 0 "=r"))]
12668   "TARGET_64BIT
12669    && (optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
12670    && ix86_match_ccmode (insn, CCGOCmode)
12671    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12672   "shr{q}\t{%2, %0|%0, %2}"
12673   [(set_attr "type" "ishift")
12674    (set_attr "mode" "DI")])
12675
12676 (define_insn "*lshrdi3_1"
12677   [(set (match_operand:DI 0 "register_operand" "=r")
12678         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0")
12679                      (match_operand:QI 2 "nonmemory_operand" "Jc")))
12680    (clobber (reg:CC FLAGS_REG))]
12681   "!TARGET_64BIT"
12682   "#"
12683   [(set_attr "type" "multi")])
12684
12685 ;; By default we don't ask for a scratch register, because when DImode
12686 ;; values are manipulated, registers are already at a premium.  But if
12687 ;; we have one handy, we won't turn it away.
12688 (define_peephole2
12689   [(match_scratch:SI 3 "r")
12690    (parallel [(set (match_operand:DI 0 "register_operand" "")
12691                    (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
12692                                 (match_operand:QI 2 "nonmemory_operand" "")))
12693               (clobber (reg:CC FLAGS_REG))])
12694    (match_dup 3)]
12695   "!TARGET_64BIT && TARGET_CMOVE"
12696   [(const_int 0)]
12697   "ix86_split_lshr (operands, operands[3], DImode); DONE;")
12698
12699 (define_split
12700   [(set (match_operand:DI 0 "register_operand" "")
12701         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
12702                      (match_operand:QI 2 "nonmemory_operand" "")))
12703    (clobber (reg:CC FLAGS_REG))]
12704   "!TARGET_64BIT && ((optimize > 0 && flag_peephole2)
12705                      ? epilogue_completed : reload_completed)"
12706   [(const_int 0)]
12707   "ix86_split_lshr (operands, NULL_RTX, DImode); DONE;")
12708
12709 (define_expand "lshrsi3"
12710   [(set (match_operand:SI 0 "nonimmediate_operand" "")
12711         (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "")
12712                      (match_operand:QI 2 "nonmemory_operand" "")))]
12713   ""
12714   "ix86_expand_binary_operator (LSHIFTRT, SImode, operands); DONE;")
12715
12716 (define_insn "*lshrsi3_1_one_bit"
12717   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
12718         (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12719                      (match_operand:QI 2 "const1_operand" "")))
12720    (clobber (reg:CC FLAGS_REG))]
12721   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12722    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12723   "shr{l}\t%0"
12724   [(set_attr "type" "ishift")
12725    (set_attr "length_immediate" "0")
12726    (set_attr "mode" "SI")])
12727
12728 (define_insn "*lshrsi3_1_one_bit_zext"
12729   [(set (match_operand:DI 0 "register_operand" "=r")
12730         (lshiftrt:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "0"))
12731                      (match_operand:QI 2 "const1_operand" "")))
12732    (clobber (reg:CC FLAGS_REG))]
12733   "TARGET_64BIT
12734    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12735    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12736   "shr{l}\t%k0"
12737   [(set_attr "type" "ishift")
12738    (set_attr "length_immediate" "0")
12739    (set_attr "mode" "SI")])
12740
12741 (define_insn "*lshrsi3_1"
12742   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,rm")
12743         (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
12744                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12745    (clobber (reg:CC FLAGS_REG))]
12746   "ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12747   "@
12748    shr{l}\t{%2, %0|%0, %2}
12749    shr{l}\t{%b2, %0|%0, %b2}"
12750   [(set_attr "type" "ishift")
12751    (set_attr "mode" "SI")])
12752
12753 (define_insn "*lshrsi3_1_zext"
12754   [(set (match_operand:DI 0 "register_operand" "=r,r")
12755         (zero_extend:DI
12756           (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
12757                        (match_operand:QI 2 "nonmemory_operand" "I,c"))))
12758    (clobber (reg:CC FLAGS_REG))]
12759   "TARGET_64BIT && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12760   "@
12761    shr{l}\t{%2, %k0|%k0, %2}
12762    shr{l}\t{%b2, %k0|%k0, %b2}"
12763   [(set_attr "type" "ishift")
12764    (set_attr "mode" "SI")])
12765
12766 ;; This pattern can't accept a variable shift count, since shifts by
12767 ;; zero don't affect the flags.  We assume that shifts by constant
12768 ;; zero are optimized away.
12769 (define_insn "*lshrsi3_one_bit_cmp"
12770   [(set (reg FLAGS_REG)
12771         (compare
12772           (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12773                        (match_operand:QI 2 "const1_operand" ""))
12774           (const_int 0)))
12775    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
12776         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
12777   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12778    && ix86_match_ccmode (insn, CCGOCmode)
12779    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12780   "shr{l}\t%0"
12781   [(set_attr "type" "ishift")
12782    (set_attr "length_immediate" "0")
12783    (set_attr "mode" "SI")])
12784
12785 (define_insn "*lshrsi3_one_bit_cconly"
12786   [(set (reg FLAGS_REG)
12787         (compare
12788           (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12789                        (match_operand:QI 2 "const1_operand" ""))
12790           (const_int 0)))
12791    (clobber (match_scratch:SI 0 "=r"))]
12792   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12793    && ix86_match_ccmode (insn, CCGOCmode)
12794    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12795   "shr{l}\t%0"
12796   [(set_attr "type" "ishift")
12797    (set_attr "length_immediate" "0")
12798    (set_attr "mode" "SI")])
12799
12800 (define_insn "*lshrsi3_cmp_one_bit_zext"
12801   [(set (reg FLAGS_REG)
12802         (compare
12803           (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
12804                        (match_operand:QI 2 "const1_operand" ""))
12805           (const_int 0)))
12806    (set (match_operand:DI 0 "register_operand" "=r")
12807         (lshiftrt:DI (zero_extend:DI (match_dup 1)) (match_dup 2)))]
12808   "TARGET_64BIT
12809    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12810    && ix86_match_ccmode (insn, CCGOCmode)
12811    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12812   "shr{l}\t%k0"
12813   [(set_attr "type" "ishift")
12814    (set_attr "length_immediate" "0")
12815    (set_attr "mode" "SI")])
12816
12817 ;; This pattern can't accept a variable shift count, since shifts by
12818 ;; zero don't affect the flags.  We assume that shifts by constant
12819 ;; zero are optimized away.
12820 (define_insn "*lshrsi3_cmp"
12821   [(set (reg FLAGS_REG)
12822         (compare
12823           (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12824                        (match_operand:QI 2 "const_1_to_31_operand" "I"))
12825           (const_int 0)))
12826    (set (match_operand:SI 0 "nonimmediate_operand" "=rm")
12827         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
12828   "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
12829    && ix86_match_ccmode (insn, CCGOCmode)
12830    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12831   "shr{l}\t{%2, %0|%0, %2}"
12832   [(set_attr "type" "ishift")
12833    (set_attr "mode" "SI")])
12834
12835 (define_insn "*lshrsi3_cconly"
12836   [(set (reg FLAGS_REG)
12837       (compare
12838         (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0")
12839                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
12840         (const_int 0)))
12841    (clobber (match_scratch:SI 0 "=r"))]
12842   "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
12843    && ix86_match_ccmode (insn, CCGOCmode)
12844    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12845   "shr{l}\t{%2, %0|%0, %2}"
12846   [(set_attr "type" "ishift")
12847    (set_attr "mode" "SI")])
12848
12849 (define_insn "*lshrsi3_cmp_zext"
12850   [(set (reg FLAGS_REG)
12851         (compare
12852           (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
12853                        (match_operand:QI 2 "const_1_to_31_operand" "I"))
12854           (const_int 0)))
12855    (set (match_operand:DI 0 "register_operand" "=r")
12856         (lshiftrt:DI (zero_extend:DI (match_dup 1)) (match_dup 2)))]
12857   "TARGET_64BIT
12858    && (optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
12859    && ix86_match_ccmode (insn, CCGOCmode)
12860    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12861   "shr{l}\t{%2, %k0|%k0, %2}"
12862   [(set_attr "type" "ishift")
12863    (set_attr "mode" "SI")])
12864
12865 (define_expand "lshrhi3"
12866   [(set (match_operand:HI 0 "nonimmediate_operand" "")
12867         (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "")
12868                      (match_operand:QI 2 "nonmemory_operand" "")))]
12869   "TARGET_HIMODE_MATH"
12870   "ix86_expand_binary_operator (LSHIFTRT, HImode, operands); DONE;")
12871
12872 (define_insn "*lshrhi3_1_one_bit"
12873   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12874         (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12875                      (match_operand:QI 2 "const1_operand" "")))
12876    (clobber (reg:CC FLAGS_REG))]
12877   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12878    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12879   "shr{w}\t%0"
12880   [(set_attr "type" "ishift")
12881    (set_attr "length_immediate" "0")
12882    (set_attr "mode" "HI")])
12883
12884 (define_insn "*lshrhi3_1"
12885   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,rm")
12886         (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
12887                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12888    (clobber (reg:CC FLAGS_REG))]
12889   "ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12890   "@
12891    shr{w}\t{%2, %0|%0, %2}
12892    shr{w}\t{%b2, %0|%0, %b2}"
12893   [(set_attr "type" "ishift")
12894    (set_attr "mode" "HI")])
12895
12896 ;; This pattern can't accept a variable shift count, since shifts by
12897 ;; zero don't affect the flags.  We assume that shifts by constant
12898 ;; zero are optimized away.
12899 (define_insn "*lshrhi3_one_bit_cmp"
12900   [(set (reg FLAGS_REG)
12901         (compare
12902           (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12903                        (match_operand:QI 2 "const1_operand" ""))
12904           (const_int 0)))
12905    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12906         (lshiftrt:HI (match_dup 1) (match_dup 2)))]
12907   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12908    && ix86_match_ccmode (insn, CCGOCmode)
12909    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12910   "shr{w}\t%0"
12911   [(set_attr "type" "ishift")
12912    (set_attr "length_immediate" "0")
12913    (set_attr "mode" "HI")])
12914
12915 (define_insn "*lshrhi3_one_bit_cconly"
12916   [(set (reg FLAGS_REG)
12917         (compare
12918           (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12919                        (match_operand:QI 2 "const1_operand" ""))
12920           (const_int 0)))
12921    (clobber (match_scratch:HI 0 "=r"))]
12922   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12923    && ix86_match_ccmode (insn, CCGOCmode)
12924    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12925   "shr{w}\t%0"
12926   [(set_attr "type" "ishift")
12927    (set_attr "length_immediate" "0")
12928    (set_attr "mode" "HI")])
12929
12930 ;; This pattern can't accept a variable shift count, since shifts by
12931 ;; zero don't affect the flags.  We assume that shifts by constant
12932 ;; zero are optimized away.
12933 (define_insn "*lshrhi3_cmp"
12934   [(set (reg FLAGS_REG)
12935         (compare
12936           (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12937                        (match_operand:QI 2 "const_1_to_31_operand" "I"))
12938           (const_int 0)))
12939    (set (match_operand:HI 0 "nonimmediate_operand" "=rm")
12940         (lshiftrt:HI (match_dup 1) (match_dup 2)))]
12941   "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
12942    && ix86_match_ccmode (insn, CCGOCmode)
12943    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12944   "shr{w}\t{%2, %0|%0, %2}"
12945   [(set_attr "type" "ishift")
12946    (set_attr "mode" "HI")])
12947
12948 (define_insn "*lshrhi3_cconly"
12949   [(set (reg FLAGS_REG)
12950         (compare
12951           (lshiftrt:HI (match_operand:HI 1 "nonimmediate_operand" "0")
12952                        (match_operand:QI 2 "const_1_to_31_operand" "I"))
12953           (const_int 0)))
12954    (clobber (match_scratch:HI 0 "=r"))]
12955   "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
12956    && ix86_match_ccmode (insn, CCGOCmode)
12957    && ix86_binary_operator_ok (LSHIFTRT, HImode, operands)"
12958   "shr{w}\t{%2, %0|%0, %2}"
12959   [(set_attr "type" "ishift")
12960    (set_attr "mode" "HI")])
12961
12962 (define_expand "lshrqi3"
12963   [(set (match_operand:QI 0 "nonimmediate_operand" "")
12964         (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "")
12965                      (match_operand:QI 2 "nonmemory_operand" "")))]
12966   "TARGET_QIMODE_MATH"
12967   "ix86_expand_binary_operator (LSHIFTRT, QImode, operands); DONE;")
12968
12969 (define_insn "*lshrqi3_1_one_bit"
12970   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
12971         (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
12972                      (match_operand:QI 2 "const1_operand" "")))
12973    (clobber (reg:CC FLAGS_REG))]
12974   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
12975    && ix86_binary_operator_ok (LSHIFTRT, QImode, operands)"
12976   "shr{b}\t%0"
12977   [(set_attr "type" "ishift")
12978    (set_attr "length_immediate" "0")
12979    (set_attr "mode" "QI")])
12980
12981 (define_insn "*lshrqi3_1_one_bit_slp"
12982   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
12983         (lshiftrt:QI (match_dup 0)
12984                      (match_operand:QI 1 "const1_operand" "")))
12985    (clobber (reg:CC FLAGS_REG))]
12986   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
12987    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))"
12988   "shr{b}\t%0"
12989   [(set_attr "type" "ishift1")
12990    (set_attr "length_immediate" "0")
12991    (set_attr "mode" "QI")])
12992
12993 (define_insn "*lshrqi3_1"
12994   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,qm")
12995         (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
12996                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
12997    (clobber (reg:CC FLAGS_REG))]
12998   "ix86_binary_operator_ok (LSHIFTRT, QImode, operands)"
12999   "@
13000    shr{b}\t{%2, %0|%0, %2}
13001    shr{b}\t{%b2, %0|%0, %b2}"
13002   [(set_attr "type" "ishift")
13003    (set_attr "mode" "QI")])
13004
13005 (define_insn "*lshrqi3_1_slp"
13006   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,qm"))
13007         (lshiftrt:QI (match_dup 0)
13008                      (match_operand:QI 1 "nonmemory_operand" "I,c")))
13009    (clobber (reg:CC FLAGS_REG))]
13010   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
13011    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
13012   "@
13013    shr{b}\t{%1, %0|%0, %1}
13014    shr{b}\t{%b1, %0|%0, %b1}"
13015   [(set_attr "type" "ishift1")
13016    (set_attr "mode" "QI")])
13017
13018 ;; This pattern can't accept a variable shift count, since shifts by
13019 ;; zero don't affect the flags.  We assume that shifts by constant
13020 ;; zero are optimized away.
13021 (define_insn "*lshrqi2_one_bit_cmp"
13022   [(set (reg FLAGS_REG)
13023         (compare
13024           (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
13025                        (match_operand:QI 2 "const1_operand" ""))
13026           (const_int 0)))
13027    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
13028         (lshiftrt:QI (match_dup 1) (match_dup 2)))]
13029   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
13030    && ix86_match_ccmode (insn, CCGOCmode)
13031    && ix86_binary_operator_ok (LSHIFTRT, QImode, operands)"
13032   "shr{b}\t%0"
13033   [(set_attr "type" "ishift")
13034    (set_attr "length_immediate" "0")
13035    (set_attr "mode" "QI")])
13036
13037 (define_insn "*lshrqi2_one_bit_cconly"
13038   [(set (reg FLAGS_REG)
13039         (compare
13040           (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
13041                        (match_operand:QI 2 "const1_operand" ""))
13042           (const_int 0)))
13043    (clobber (match_scratch:QI 0 "=q"))]
13044   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
13045    && ix86_match_ccmode (insn, CCGOCmode)
13046    && ix86_binary_operator_ok (LSHIFTRT, QImode, operands)"
13047   "shr{b}\t%0"
13048   [(set_attr "type" "ishift")
13049    (set_attr "length_immediate" "0")
13050    (set_attr "mode" "QI")])
13051
13052 ;; This pattern can't accept a variable shift count, since shifts by
13053 ;; zero don't affect the flags.  We assume that shifts by constant
13054 ;; zero are optimized away.
13055 (define_insn "*lshrqi2_cmp"
13056   [(set (reg FLAGS_REG)
13057         (compare
13058           (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
13059                        (match_operand:QI 2 "const_1_to_31_operand" "I"))
13060           (const_int 0)))
13061    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
13062         (lshiftrt:QI (match_dup 1) (match_dup 2)))]
13063   "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
13064    && ix86_match_ccmode (insn, CCGOCmode)
13065    && ix86_binary_operator_ok (LSHIFTRT, QImode, operands)"
13066   "shr{b}\t{%2, %0|%0, %2}"
13067   [(set_attr "type" "ishift")
13068    (set_attr "mode" "QI")])
13069
13070 (define_insn "*lshrqi2_cconly"
13071   [(set (reg FLAGS_REG)
13072         (compare
13073           (lshiftrt:QI (match_operand:QI 1 "nonimmediate_operand" "0")
13074                        (match_operand:QI 2 "const_1_to_31_operand" "I"))
13075           (const_int 0)))
13076    (clobber (match_scratch:QI 0 "=q"))]
13077   "(optimize_function_for_size_p (cfun) || !TARGET_PARTIAL_FLAG_REG_STALL)
13078    && ix86_match_ccmode (insn, CCGOCmode)
13079    && ix86_binary_operator_ok (LSHIFTRT, QImode, operands)"
13080   "shr{b}\t{%2, %0|%0, %2}"
13081   [(set_attr "type" "ishift")
13082    (set_attr "mode" "QI")])
13083 \f
13084 ;; Rotate instructions
13085
13086 (define_expand "rotldi3"
13087   [(set (match_operand:DI 0 "shiftdi_operand" "")
13088         (rotate:DI (match_operand:DI 1 "shiftdi_operand" "")
13089                    (match_operand:QI 2 "nonmemory_operand" "")))]
13090  ""
13091 {
13092   if (TARGET_64BIT)
13093     {
13094       ix86_expand_binary_operator (ROTATE, DImode, operands);
13095       DONE;
13096     }
13097   if (!const_1_to_31_operand (operands[2], VOIDmode))
13098     FAIL;
13099   emit_insn (gen_ix86_rotldi3 (operands[0], operands[1], operands[2]));
13100   DONE;
13101 })
13102
13103 ;; Implement rotation using two double-precision shift instructions
13104 ;; and a scratch register.
13105 (define_insn_and_split "ix86_rotldi3"
13106  [(set (match_operand:DI 0 "register_operand" "=r")
13107        (rotate:DI (match_operand:DI 1 "register_operand" "0")
13108                   (match_operand:QI 2 "const_1_to_31_operand" "I")))
13109   (clobber (reg:CC FLAGS_REG))
13110   (clobber (match_scratch:SI 3 "=&r"))]
13111  "!TARGET_64BIT"
13112  ""
13113  "&& reload_completed"
13114  [(set (match_dup 3) (match_dup 4))
13115   (parallel
13116    [(set (match_dup 4)
13117          (ior:SI (ashift:SI (match_dup 4) (match_dup 2))
13118                  (lshiftrt:SI (match_dup 5)
13119                               (minus:QI (const_int 32) (match_dup 2)))))
13120     (clobber (reg:CC FLAGS_REG))])
13121   (parallel
13122    [(set (match_dup 5)
13123          (ior:SI (ashift:SI (match_dup 5) (match_dup 2))
13124                  (lshiftrt:SI (match_dup 3)
13125                               (minus:QI (const_int 32) (match_dup 2)))))
13126     (clobber (reg:CC FLAGS_REG))])]
13127  "split_di (&operands[0], 1, &operands[4], &operands[5]);")
13128
13129 (define_insn "*rotlsi3_1_one_bit_rex64"
13130   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
13131         (rotate:DI (match_operand:DI 1 "nonimmediate_operand" "0")
13132                    (match_operand:QI 2 "const1_operand" "")))
13133    (clobber (reg:CC FLAGS_REG))]
13134   "TARGET_64BIT
13135    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
13136    && ix86_binary_operator_ok (ROTATE, DImode, operands)"
13137   "rol{q}\t%0"
13138   [(set_attr "type" "rotate")
13139    (set_attr "length_immediate" "0")
13140    (set_attr "mode" "DI")])
13141
13142 (define_insn "*rotldi3_1_rex64"
13143   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,rm")
13144         (rotate:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
13145                    (match_operand:QI 2 "nonmemory_operand" "e,c")))
13146    (clobber (reg:CC FLAGS_REG))]
13147   "TARGET_64BIT && ix86_binary_operator_ok (ROTATE, DImode, operands)"
13148   "@
13149    rol{q}\t{%2, %0|%0, %2}
13150    rol{q}\t{%b2, %0|%0, %b2}"
13151   [(set_attr "type" "rotate")
13152    (set_attr "mode" "DI")])
13153
13154 (define_expand "rotlsi3"
13155   [(set (match_operand:SI 0 "nonimmediate_operand" "")
13156         (rotate:SI (match_operand:SI 1 "nonimmediate_operand" "")
13157                    (match_operand:QI 2 "nonmemory_operand" "")))]
13158   ""
13159   "ix86_expand_binary_operator (ROTATE, SImode, operands); DONE;")
13160
13161 (define_insn "*rotlsi3_1_one_bit"
13162   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
13163         (rotate:SI (match_operand:SI 1 "nonimmediate_operand" "0")
13164                    (match_operand:QI 2 "const1_operand" "")))
13165    (clobber (reg:CC FLAGS_REG))]
13166   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
13167    && ix86_binary_operator_ok (ROTATE, SImode, operands)"
13168   "rol{l}\t%0"
13169   [(set_attr "type" "rotate")
13170    (set_attr "length_immediate" "0")
13171    (set_attr "mode" "SI")])
13172
13173 (define_insn "*rotlsi3_1_one_bit_zext"
13174   [(set (match_operand:DI 0 "register_operand" "=r")
13175         (zero_extend:DI
13176           (rotate:SI (match_operand:SI 1 "register_operand" "0")
13177                      (match_operand:QI 2 "const1_operand" ""))))
13178    (clobber (reg:CC FLAGS_REG))]
13179   "TARGET_64BIT
13180    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
13181    && ix86_binary_operator_ok (ROTATE, SImode, operands)"
13182   "rol{l}\t%k0"
13183   [(set_attr "type" "rotate")
13184    (set_attr "length_immediate" "0")
13185    (set_attr "mode" "SI")])
13186
13187 (define_insn "*rotlsi3_1"
13188   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,rm")
13189         (rotate:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
13190                    (match_operand:QI 2 "nonmemory_operand" "I,c")))
13191    (clobber (reg:CC FLAGS_REG))]
13192   "ix86_binary_operator_ok (ROTATE, SImode, operands)"
13193   "@
13194    rol{l}\t{%2, %0|%0, %2}
13195    rol{l}\t{%b2, %0|%0, %b2}"
13196   [(set_attr "type" "rotate")
13197    (set_attr "mode" "SI")])
13198
13199 (define_insn "*rotlsi3_1_zext"
13200   [(set (match_operand:DI 0 "register_operand" "=r,r")
13201         (zero_extend:DI
13202           (rotate:SI (match_operand:SI 1 "register_operand" "0,0")
13203                      (match_operand:QI 2 "nonmemory_operand" "I,c"))))
13204    (clobber (reg:CC FLAGS_REG))]
13205   "TARGET_64BIT && ix86_binary_operator_ok (ROTATE, SImode, operands)"
13206   "@
13207    rol{l}\t{%2, %k0|%k0, %2}
13208    rol{l}\t{%b2, %k0|%k0, %b2}"
13209   [(set_attr "type" "rotate")
13210    (set_attr "mode" "SI")])
13211
13212 (define_expand "rotlhi3"
13213   [(set (match_operand:HI 0 "nonimmediate_operand" "")
13214         (rotate:HI (match_operand:HI 1 "nonimmediate_operand" "")
13215                    (match_operand:QI 2 "nonmemory_operand" "")))]
13216   "TARGET_HIMODE_MATH"
13217   "ix86_expand_binary_operator (ROTATE, HImode, operands); DONE;")
13218
13219 (define_insn "*rotlhi3_1_one_bit"
13220   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
13221         (rotate:HI (match_operand:HI 1 "nonimmediate_operand" "0")
13222                    (match_operand:QI 2 "const1_operand" "")))
13223    (clobber (reg:CC FLAGS_REG))]
13224   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
13225    && ix86_binary_operator_ok (ROTATE, HImode, operands)"
13226   "rol{w}\t%0"
13227   [(set_attr "type" "rotate")
13228    (set_attr "length_immediate" "0")
13229    (set_attr "mode" "HI")])
13230
13231 (define_insn "*rotlhi3_1"
13232   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,rm")
13233         (rotate:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
13234                    (match_operand:QI 2 "nonmemory_operand" "I,c")))
13235    (clobber (reg:CC FLAGS_REG))]
13236   "ix86_binary_operator_ok (ROTATE, HImode, operands)"
13237   "@
13238    rol{w}\t{%2, %0|%0, %2}
13239    rol{w}\t{%b2, %0|%0, %b2}"
13240   [(set_attr "type" "rotate")
13241    (set_attr "mode" "HI")])
13242
13243 (define_split
13244  [(set (match_operand:HI 0 "register_operand" "")
13245        (rotate:HI (match_dup 0) (const_int 8)))
13246   (clobber (reg:CC FLAGS_REG))]
13247  "reload_completed"
13248  [(parallel [(set (strict_low_part (match_dup 0))
13249                   (bswap:HI (match_dup 0)))
13250              (clobber (reg:CC FLAGS_REG))])]
13251  "")
13252
13253 (define_expand "rotlqi3"
13254   [(set (match_operand:QI 0 "nonimmediate_operand" "")
13255         (rotate:QI (match_operand:QI 1 "nonimmediate_operand" "")
13256                    (match_operand:QI 2 "nonmemory_operand" "")))]
13257   "TARGET_QIMODE_MATH"
13258   "ix86_expand_binary_operator (ROTATE, QImode, operands); DONE;")
13259
13260 (define_insn "*rotlqi3_1_one_bit_slp"
13261   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
13262         (rotate:QI (match_dup 0)
13263                    (match_operand:QI 1 "const1_operand" "")))
13264    (clobber (reg:CC FLAGS_REG))]
13265   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
13266    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))"
13267   "rol{b}\t%0"
13268   [(set_attr "type" "rotate1")
13269    (set_attr "length_immediate" "0")
13270    (set_attr "mode" "QI")])
13271
13272 (define_insn "*rotlqi3_1_one_bit"
13273   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
13274         (rotate:QI (match_operand:QI 1 "nonimmediate_operand" "0")
13275                    (match_operand:QI 2 "const1_operand" "")))
13276    (clobber (reg:CC FLAGS_REG))]
13277   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
13278    && ix86_binary_operator_ok (ROTATE, QImode, operands)"
13279   "rol{b}\t%0"
13280   [(set_attr "type" "rotate")
13281    (set_attr "length_immediate" "0")
13282    (set_attr "mode" "QI")])
13283
13284 (define_insn "*rotlqi3_1_slp"
13285   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,qm"))
13286         (rotate:QI (match_dup 0)
13287                    (match_operand:QI 1 "nonmemory_operand" "I,c")))
13288    (clobber (reg:CC FLAGS_REG))]
13289   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
13290    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
13291   "@
13292    rol{b}\t{%1, %0|%0, %1}
13293    rol{b}\t{%b1, %0|%0, %b1}"
13294   [(set_attr "type" "rotate1")
13295    (set_attr "mode" "QI")])
13296
13297 (define_insn "*rotlqi3_1"
13298   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,qm")
13299         (rotate:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
13300                    (match_operand:QI 2 "nonmemory_operand" "I,c")))
13301    (clobber (reg:CC FLAGS_REG))]
13302   "ix86_binary_operator_ok (ROTATE, QImode, operands)"
13303   "@
13304    rol{b}\t{%2, %0|%0, %2}
13305    rol{b}\t{%b2, %0|%0, %b2}"
13306   [(set_attr "type" "rotate")
13307    (set_attr "mode" "QI")])
13308
13309 (define_expand "rotrdi3"
13310   [(set (match_operand:DI 0 "shiftdi_operand" "")
13311         (rotate:DI (match_operand:DI 1 "shiftdi_operand" "")
13312                    (match_operand:QI 2 "nonmemory_operand" "")))]
13313  ""
13314 {
13315   if (TARGET_64BIT)
13316     {
13317       ix86_expand_binary_operator (ROTATERT, DImode, operands);
13318       DONE;
13319     }
13320   if (!const_1_to_31_operand (operands[2], VOIDmode))
13321     FAIL;
13322   emit_insn (gen_ix86_rotrdi3 (operands[0], operands[1], operands[2]));
13323   DONE;
13324 })
13325
13326 ;; Implement rotation using two double-precision shift instructions
13327 ;; and a scratch register.
13328 (define_insn_and_split "ix86_rotrdi3"
13329  [(set (match_operand:DI 0 "register_operand" "=r")
13330        (rotatert:DI (match_operand:DI 1 "register_operand" "0")
13331                     (match_operand:QI 2 "const_1_to_31_operand" "I")))
13332   (clobber (reg:CC FLAGS_REG))
13333   (clobber (match_scratch:SI 3 "=&r"))]
13334  "!TARGET_64BIT"
13335  ""
13336  "&& reload_completed"
13337  [(set (match_dup 3) (match_dup 4))
13338   (parallel
13339    [(set (match_dup 4)
13340          (ior:SI (ashiftrt:SI (match_dup 4) (match_dup 2))
13341                  (ashift:SI (match_dup 5)
13342                             (minus:QI (const_int 32) (match_dup 2)))))
13343     (clobber (reg:CC FLAGS_REG))])
13344   (parallel
13345    [(set (match_dup 5)
13346          (ior:SI (ashiftrt:SI (match_dup 5) (match_dup 2))
13347                  (ashift:SI (match_dup 3)
13348                             (minus:QI (const_int 32) (match_dup 2)))))
13349     (clobber (reg:CC FLAGS_REG))])]
13350  "split_di (&operands[0], 1, &operands[4], &operands[5]);")
13351
13352 (define_insn "*rotrdi3_1_one_bit_rex64"
13353   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
13354         (rotatert:DI (match_operand:DI 1 "nonimmediate_operand" "0")
13355                      (match_operand:QI 2 "const1_operand" "")))
13356    (clobber (reg:CC FLAGS_REG))]
13357   "TARGET_64BIT
13358    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
13359    && ix86_binary_operator_ok (ROTATERT, DImode, operands)"
13360   "ror{q}\t%0"
13361   [(set_attr "type" "rotate")
13362    (set_attr "length_immediate" "0")
13363    (set_attr "mode" "DI")])
13364
13365 (define_insn "*rotrdi3_1_rex64"
13366   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,rm")
13367         (rotatert:DI (match_operand:DI 1 "nonimmediate_operand" "0,0")
13368                      (match_operand:QI 2 "nonmemory_operand" "J,c")))
13369    (clobber (reg:CC FLAGS_REG))]
13370   "TARGET_64BIT && ix86_binary_operator_ok (ROTATERT, DImode, operands)"
13371   "@
13372    ror{q}\t{%2, %0|%0, %2}
13373    ror{q}\t{%b2, %0|%0, %b2}"
13374   [(set_attr "type" "rotate")
13375    (set_attr "mode" "DI")])
13376
13377 (define_expand "rotrsi3"
13378   [(set (match_operand:SI 0 "nonimmediate_operand" "")
13379         (rotatert:SI (match_operand:SI 1 "nonimmediate_operand" "")
13380                      (match_operand:QI 2 "nonmemory_operand" "")))]
13381   ""
13382   "ix86_expand_binary_operator (ROTATERT, SImode, operands); DONE;")
13383
13384 (define_insn "*rotrsi3_1_one_bit"
13385   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
13386         (rotatert:SI (match_operand:SI 1 "nonimmediate_operand" "0")
13387                      (match_operand:QI 2 "const1_operand" "")))
13388    (clobber (reg:CC FLAGS_REG))]
13389   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
13390    && ix86_binary_operator_ok (ROTATERT, SImode, operands)"
13391   "ror{l}\t%0"
13392   [(set_attr "type" "rotate")
13393    (set_attr "length_immediate" "0")
13394    (set_attr "mode" "SI")])
13395
13396 (define_insn "*rotrsi3_1_one_bit_zext"
13397   [(set (match_operand:DI 0 "register_operand" "=r")
13398         (zero_extend:DI
13399           (rotatert:SI (match_operand:SI 1 "register_operand" "0")
13400                        (match_operand:QI 2 "const1_operand" ""))))
13401    (clobber (reg:CC FLAGS_REG))]
13402   "TARGET_64BIT
13403    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
13404    && ix86_binary_operator_ok (ROTATERT, SImode, operands)"
13405   "ror{l}\t%k0"
13406   [(set_attr "type" "rotate")
13407    (set_attr "length_immediate" "0")
13408    (set_attr "mode" "SI")])
13409
13410 (define_insn "*rotrsi3_1"
13411   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,rm")
13412         (rotatert:SI (match_operand:SI 1 "nonimmediate_operand" "0,0")
13413                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
13414    (clobber (reg:CC FLAGS_REG))]
13415   "ix86_binary_operator_ok (ROTATERT, SImode, operands)"
13416   "@
13417    ror{l}\t{%2, %0|%0, %2}
13418    ror{l}\t{%b2, %0|%0, %b2}"
13419   [(set_attr "type" "rotate")
13420    (set_attr "mode" "SI")])
13421
13422 (define_insn "*rotrsi3_1_zext"
13423   [(set (match_operand:DI 0 "register_operand" "=r,r")
13424         (zero_extend:DI
13425           (rotatert:SI (match_operand:SI 1 "register_operand" "0,0")
13426                        (match_operand:QI 2 "nonmemory_operand" "I,c"))))
13427    (clobber (reg:CC FLAGS_REG))]
13428   "TARGET_64BIT && ix86_binary_operator_ok (ROTATERT, SImode, operands)"
13429   "@
13430    ror{l}\t{%2, %k0|%k0, %2}
13431    ror{l}\t{%b2, %k0|%k0, %b2}"
13432   [(set_attr "type" "rotate")
13433    (set_attr "mode" "SI")])
13434
13435 (define_expand "rotrhi3"
13436   [(set (match_operand:HI 0 "nonimmediate_operand" "")
13437         (rotatert:HI (match_operand:HI 1 "nonimmediate_operand" "")
13438                      (match_operand:QI 2 "nonmemory_operand" "")))]
13439   "TARGET_HIMODE_MATH"
13440   "ix86_expand_binary_operator (ROTATERT, HImode, operands); DONE;")
13441
13442 (define_insn "*rotrhi3_one_bit"
13443   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
13444         (rotatert:HI (match_operand:HI 1 "nonimmediate_operand" "0")
13445                      (match_operand:QI 2 "const1_operand" "")))
13446    (clobber (reg:CC FLAGS_REG))]
13447   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
13448    && ix86_binary_operator_ok (ROTATERT, HImode, operands)"
13449   "ror{w}\t%0"
13450   [(set_attr "type" "rotate")
13451    (set_attr "length_immediate" "0")
13452    (set_attr "mode" "HI")])
13453
13454 (define_insn "*rotrhi3_1"
13455   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,rm")
13456         (rotatert:HI (match_operand:HI 1 "nonimmediate_operand" "0,0")
13457                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
13458    (clobber (reg:CC FLAGS_REG))]
13459   "ix86_binary_operator_ok (ROTATERT, HImode, operands)"
13460   "@
13461    ror{w}\t{%2, %0|%0, %2}
13462    ror{w}\t{%b2, %0|%0, %b2}"
13463   [(set_attr "type" "rotate")
13464    (set_attr "mode" "HI")])
13465
13466 (define_split
13467  [(set (match_operand:HI 0 "register_operand" "")
13468        (rotatert:HI (match_dup 0) (const_int 8)))
13469   (clobber (reg:CC FLAGS_REG))]
13470  "reload_completed"
13471  [(parallel [(set (strict_low_part (match_dup 0))
13472                   (bswap:HI (match_dup 0)))
13473              (clobber (reg:CC FLAGS_REG))])]
13474  "")
13475
13476 (define_expand "rotrqi3"
13477   [(set (match_operand:QI 0 "nonimmediate_operand" "")
13478         (rotatert:QI (match_operand:QI 1 "nonimmediate_operand" "")
13479                      (match_operand:QI 2 "nonmemory_operand" "")))]
13480   "TARGET_QIMODE_MATH"
13481   "ix86_expand_binary_operator (ROTATERT, QImode, operands); DONE;")
13482
13483 (define_insn "*rotrqi3_1_one_bit"
13484   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
13485         (rotatert:QI (match_operand:QI 1 "nonimmediate_operand" "0")
13486                      (match_operand:QI 2 "const1_operand" "")))
13487    (clobber (reg:CC FLAGS_REG))]
13488   "(TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
13489    && ix86_binary_operator_ok (ROTATERT, QImode, operands)"
13490   "ror{b}\t%0"
13491   [(set_attr "type" "rotate")
13492    (set_attr "length_immediate" "0")
13493    (set_attr "mode" "QI")])
13494
13495 (define_insn "*rotrqi3_1_one_bit_slp"
13496   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
13497         (rotatert:QI (match_dup 0)
13498                      (match_operand:QI 1 "const1_operand" "")))
13499    (clobber (reg:CC FLAGS_REG))]
13500   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
13501    && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))"
13502   "ror{b}\t%0"
13503   [(set_attr "type" "rotate1")
13504    (set_attr "length_immediate" "0")
13505    (set_attr "mode" "QI")])
13506
13507 (define_insn "*rotrqi3_1"
13508   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,qm")
13509         (rotatert:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
13510                      (match_operand:QI 2 "nonmemory_operand" "I,c")))
13511    (clobber (reg:CC FLAGS_REG))]
13512   "ix86_binary_operator_ok (ROTATERT, QImode, operands)"
13513   "@
13514    ror{b}\t{%2, %0|%0, %2}
13515    ror{b}\t{%b2, %0|%0, %b2}"
13516   [(set_attr "type" "rotate")
13517    (set_attr "mode" "QI")])
13518
13519 (define_insn "*rotrqi3_1_slp"
13520   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,qm"))
13521         (rotatert:QI (match_dup 0)
13522                      (match_operand:QI 1 "nonmemory_operand" "I,c")))
13523    (clobber (reg:CC FLAGS_REG))]
13524   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
13525    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
13526   "@
13527    ror{b}\t{%1, %0|%0, %1}
13528    ror{b}\t{%b1, %0|%0, %b1}"
13529   [(set_attr "type" "rotate1")
13530    (set_attr "mode" "QI")])
13531 \f
13532 ;; Bit set / bit test instructions
13533
13534 (define_expand "extv"
13535   [(set (match_operand:SI 0 "register_operand" "")
13536         (sign_extract:SI (match_operand:SI 1 "register_operand" "")
13537                          (match_operand:SI 2 "const8_operand" "")
13538                          (match_operand:SI 3 "const8_operand" "")))]
13539   ""
13540 {
13541   /* Handle extractions from %ah et al.  */
13542   if (INTVAL (operands[2]) != 8 || INTVAL (operands[3]) != 8)
13543     FAIL;
13544
13545   /* From mips.md: extract_bit_field doesn't verify that our source
13546      matches the predicate, so check it again here.  */
13547   if (! ext_register_operand (operands[1], VOIDmode))
13548     FAIL;
13549 })
13550
13551 (define_expand "extzv"
13552   [(set (match_operand:SI 0 "register_operand" "")
13553         (zero_extract:SI (match_operand 1 "ext_register_operand" "")
13554                          (match_operand:SI 2 "const8_operand" "")
13555                          (match_operand:SI 3 "const8_operand" "")))]
13556   ""
13557 {
13558   /* Handle extractions from %ah et al.  */
13559   if (INTVAL (operands[2]) != 8 || INTVAL (operands[3]) != 8)
13560     FAIL;
13561
13562   /* From mips.md: extract_bit_field doesn't verify that our source
13563      matches the predicate, so check it again here.  */
13564   if (! ext_register_operand (operands[1], VOIDmode))
13565     FAIL;
13566 })
13567
13568 (define_expand "insv"
13569   [(set (zero_extract (match_operand 0 "ext_register_operand" "")
13570                       (match_operand 1 "const8_operand" "")
13571                       (match_operand 2 "const8_operand" ""))
13572         (match_operand 3 "register_operand" ""))]
13573   ""
13574 {
13575   /* Handle insertions to %ah et al.  */
13576   if (INTVAL (operands[1]) != 8 || INTVAL (operands[2]) != 8)
13577     FAIL;
13578
13579   /* From mips.md: insert_bit_field doesn't verify that our source
13580      matches the predicate, so check it again here.  */
13581   if (! ext_register_operand (operands[0], VOIDmode))
13582     FAIL;
13583
13584   if (TARGET_64BIT)
13585     emit_insn (gen_movdi_insv_1_rex64 (operands[0], operands[3]));
13586   else
13587     emit_insn (gen_movsi_insv_1 (operands[0], operands[3]));
13588
13589   DONE;
13590 })
13591
13592 ;; %%% bts, btr, btc, bt.
13593 ;; In general these instructions are *slow* when applied to memory,
13594 ;; since they enforce atomic operation.  When applied to registers,
13595 ;; it depends on the cpu implementation.  They're never faster than
13596 ;; the corresponding and/ior/xor operations, so with 32-bit there's
13597 ;; no point.  But in 64-bit, we can't hold the relevant immediates
13598 ;; within the instruction itself, so operating on bits in the high
13599 ;; 32-bits of a register becomes easier.
13600 ;;
13601 ;; These are slow on Nocona, but fast on Athlon64.  We do require the use
13602 ;; of btrq and btcq for corner cases of post-reload expansion of absdf and
13603 ;; negdf respectively, so they can never be disabled entirely.
13604
13605 (define_insn "*btsq"
13606   [(set (zero_extract:DI (match_operand:DI 0 "register_operand" "+r")
13607                          (const_int 1)
13608                          (match_operand:DI 1 "const_0_to_63_operand" ""))
13609         (const_int 1))
13610    (clobber (reg:CC FLAGS_REG))]
13611   "TARGET_64BIT && (TARGET_USE_BT || reload_completed)"
13612   "bts{q}\t{%1, %0|%0, %1}"
13613   [(set_attr "type" "alu1")
13614    (set_attr "prefix_0f" "1")
13615    (set_attr "mode" "DI")])
13616
13617 (define_insn "*btrq"
13618   [(set (zero_extract:DI (match_operand:DI 0 "register_operand" "+r")
13619                          (const_int 1)
13620                          (match_operand:DI 1 "const_0_to_63_operand" ""))
13621         (const_int 0))
13622    (clobber (reg:CC FLAGS_REG))]
13623   "TARGET_64BIT && (TARGET_USE_BT || reload_completed)"
13624   "btr{q}\t{%1, %0|%0, %1}"
13625   [(set_attr "type" "alu1")
13626    (set_attr "prefix_0f" "1")
13627    (set_attr "mode" "DI")])
13628
13629 (define_insn "*btcq"
13630   [(set (zero_extract:DI (match_operand:DI 0 "register_operand" "+r")
13631                          (const_int 1)
13632                          (match_operand:DI 1 "const_0_to_63_operand" ""))
13633         (not:DI (zero_extract:DI (match_dup 0) (const_int 1) (match_dup 1))))
13634    (clobber (reg:CC FLAGS_REG))]
13635   "TARGET_64BIT && (TARGET_USE_BT || reload_completed)"
13636   "btc{q}\t{%1, %0|%0, %1}"
13637   [(set_attr "type" "alu1")
13638    (set_attr "prefix_0f" "1")
13639    (set_attr "mode" "DI")])
13640
13641 ;; Allow Nocona to avoid these instructions if a register is available.
13642
13643 (define_peephole2
13644   [(match_scratch:DI 2 "r")
13645    (parallel [(set (zero_extract:DI
13646                      (match_operand:DI 0 "register_operand" "")
13647                      (const_int 1)
13648                      (match_operand:DI 1 "const_0_to_63_operand" ""))
13649                    (const_int 1))
13650               (clobber (reg:CC FLAGS_REG))])]
13651   "TARGET_64BIT && !TARGET_USE_BT"
13652   [(const_int 0)]
13653 {
13654   HOST_WIDE_INT i = INTVAL (operands[1]), hi, lo;
13655   rtx op1;
13656
13657   if (HOST_BITS_PER_WIDE_INT >= 64)
13658     lo = (HOST_WIDE_INT)1 << i, hi = 0;
13659   else if (i < HOST_BITS_PER_WIDE_INT)
13660     lo = (HOST_WIDE_INT)1 << i, hi = 0;
13661   else
13662     lo = 0, hi = (HOST_WIDE_INT)1 << (i - HOST_BITS_PER_WIDE_INT);
13663
13664   op1 = immed_double_const (lo, hi, DImode);
13665   if (i >= 31)
13666     {
13667       emit_move_insn (operands[2], op1);
13668       op1 = operands[2];
13669     }
13670
13671   emit_insn (gen_iordi3 (operands[0], operands[0], op1));
13672   DONE;
13673 })
13674
13675 (define_peephole2
13676   [(match_scratch:DI 2 "r")
13677    (parallel [(set (zero_extract:DI
13678                      (match_operand:DI 0 "register_operand" "")
13679                      (const_int 1)
13680                      (match_operand:DI 1 "const_0_to_63_operand" ""))
13681                    (const_int 0))
13682               (clobber (reg:CC FLAGS_REG))])]
13683   "TARGET_64BIT && !TARGET_USE_BT"
13684   [(const_int 0)]
13685 {
13686   HOST_WIDE_INT i = INTVAL (operands[1]), hi, lo;
13687   rtx op1;
13688
13689   if (HOST_BITS_PER_WIDE_INT >= 64)
13690     lo = (HOST_WIDE_INT)1 << i, hi = 0;
13691   else if (i < HOST_BITS_PER_WIDE_INT)
13692     lo = (HOST_WIDE_INT)1 << i, hi = 0;
13693   else
13694     lo = 0, hi = (HOST_WIDE_INT)1 << (i - HOST_BITS_PER_WIDE_INT);
13695
13696   op1 = immed_double_const (~lo, ~hi, DImode);
13697   if (i >= 32)
13698     {
13699       emit_move_insn (operands[2], op1);
13700       op1 = operands[2];
13701     }
13702
13703   emit_insn (gen_anddi3 (operands[0], operands[0], op1));
13704   DONE;
13705 })
13706
13707 (define_peephole2
13708   [(match_scratch:DI 2 "r")
13709    (parallel [(set (zero_extract:DI
13710                      (match_operand:DI 0 "register_operand" "")
13711                      (const_int 1)
13712                      (match_operand:DI 1 "const_0_to_63_operand" ""))
13713               (not:DI (zero_extract:DI
13714                         (match_dup 0) (const_int 1) (match_dup 1))))
13715               (clobber (reg:CC FLAGS_REG))])]
13716   "TARGET_64BIT && !TARGET_USE_BT"
13717   [(const_int 0)]
13718 {
13719   HOST_WIDE_INT i = INTVAL (operands[1]), hi, lo;
13720   rtx op1;
13721
13722   if (HOST_BITS_PER_WIDE_INT >= 64)
13723     lo = (HOST_WIDE_INT)1 << i, hi = 0;
13724   else if (i < HOST_BITS_PER_WIDE_INT)
13725     lo = (HOST_WIDE_INT)1 << i, hi = 0;
13726   else
13727     lo = 0, hi = (HOST_WIDE_INT)1 << (i - HOST_BITS_PER_WIDE_INT);
13728
13729   op1 = immed_double_const (lo, hi, DImode);
13730   if (i >= 31)
13731     {
13732       emit_move_insn (operands[2], op1);
13733       op1 = operands[2];
13734     }
13735
13736   emit_insn (gen_xordi3 (operands[0], operands[0], op1));
13737   DONE;
13738 })
13739
13740 (define_insn "*btdi_rex64"
13741   [(set (reg:CCC FLAGS_REG)
13742         (compare:CCC
13743           (zero_extract:DI
13744             (match_operand:DI 0 "register_operand" "r")
13745             (const_int 1)
13746             (match_operand:DI 1 "nonmemory_operand" "rN"))
13747           (const_int 0)))]
13748   "TARGET_64BIT && (TARGET_USE_BT || optimize_function_for_size_p (cfun))"
13749   "bt{q}\t{%1, %0|%0, %1}"
13750   [(set_attr "type" "alu1")
13751    (set_attr "prefix_0f" "1")
13752    (set_attr "mode" "DI")])
13753
13754 (define_insn "*btsi"
13755   [(set (reg:CCC FLAGS_REG)
13756         (compare:CCC
13757           (zero_extract:SI
13758             (match_operand:SI 0 "register_operand" "r")
13759             (const_int 1)
13760             (match_operand:SI 1 "nonmemory_operand" "rN"))
13761           (const_int 0)))]
13762   "TARGET_USE_BT || optimize_function_for_size_p (cfun)"
13763   "bt{l}\t{%1, %0|%0, %1}"
13764   [(set_attr "type" "alu1")
13765    (set_attr "prefix_0f" "1")
13766    (set_attr "mode" "SI")])
13767 \f
13768 ;; Store-flag instructions.
13769
13770 ;; For all sCOND expanders, also expand the compare or test insn that
13771 ;; generates cc0.  Generate an equality comparison if `seq' or `sne'.
13772
13773 (define_insn_and_split "*setcc_di_1"
13774   [(set (match_operand:DI 0 "register_operand" "=q")
13775         (match_operator:DI 1 "ix86_comparison_operator"
13776           [(reg FLAGS_REG) (const_int 0)]))]
13777   "TARGET_64BIT && !TARGET_PARTIAL_REG_STALL"
13778   "#"
13779   "&& reload_completed"
13780   [(set (match_dup 2) (match_dup 1))
13781    (set (match_dup 0) (zero_extend:DI (match_dup 2)))]
13782 {
13783   PUT_MODE (operands[1], QImode);
13784   operands[2] = gen_lowpart (QImode, operands[0]);
13785 })
13786
13787 (define_insn_and_split "*setcc_si_1_and"
13788   [(set (match_operand:SI 0 "register_operand" "=q")
13789         (match_operator:SI 1 "ix86_comparison_operator"
13790           [(reg FLAGS_REG) (const_int 0)]))
13791    (clobber (reg:CC FLAGS_REG))]
13792   "!TARGET_PARTIAL_REG_STALL
13793    && TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
13794   "#"
13795   "&& reload_completed"
13796   [(set (match_dup 2) (match_dup 1))
13797    (parallel [(set (match_dup 0) (zero_extend:SI (match_dup 2)))
13798               (clobber (reg:CC FLAGS_REG))])]
13799 {
13800   PUT_MODE (operands[1], QImode);
13801   operands[2] = gen_lowpart (QImode, operands[0]);
13802 })
13803
13804 (define_insn_and_split "*setcc_si_1_movzbl"
13805   [(set (match_operand:SI 0 "register_operand" "=q")
13806         (match_operator:SI 1 "ix86_comparison_operator"
13807           [(reg FLAGS_REG) (const_int 0)]))]
13808   "!TARGET_PARTIAL_REG_STALL
13809    && (!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun))"
13810   "#"
13811   "&& reload_completed"
13812   [(set (match_dup 2) (match_dup 1))
13813    (set (match_dup 0) (zero_extend:SI (match_dup 2)))]
13814 {
13815   PUT_MODE (operands[1], QImode);
13816   operands[2] = gen_lowpart (QImode, operands[0]);
13817 })
13818
13819 (define_insn_and_split "*setcc_<mode>_2"
13820   [(set (match_operand:SWI48 0 "register_operand" "=q")
13821         (match_operator:SWI48 1 "ix86_comparison_operator"
13822           [(reg FLAGS_REG) (const_int 0)]))
13823    (clobber (reg:CC FLAGS_REG))]
13824   "TARGET_PARTIAL_REG_STALL"
13825   "#"
13826   "&& reload_completed"
13827   [(set (strict_low_part (match_dup 2)) (match_dup 1))]
13828 {
13829   PUT_MODE (operands[1], QImode);
13830   operands[2] = gen_lowpart (QImode, operands[0]);
13831   ix86_expand_clear (operands[0]);
13832 })
13833
13834 (define_insn "*setcc_qi"
13835   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
13836         (match_operator:QI 1 "ix86_comparison_operator"
13837           [(reg FLAGS_REG) (const_int 0)]))]
13838   ""
13839   "set%C1\t%0"
13840   [(set_attr "type" "setcc")
13841    (set_attr "mode" "QI")])
13842
13843 (define_insn "*setcc_qi_slp"
13844   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
13845         (match_operator:QI 1 "ix86_comparison_operator"
13846           [(reg FLAGS_REG) (const_int 0)]))]
13847   ""
13848   "set%C1\t%0"
13849   [(set_attr "type" "setcc")
13850    (set_attr "mode" "QI")])
13851
13852 ;; In general it is not safe to assume too much about CCmode registers,
13853 ;; so simplify-rtx stops when it sees a second one.  Under certain
13854 ;; conditions this is safe on x86, so help combine not create
13855 ;;
13856 ;;      seta    %al
13857 ;;      testb   %al, %al
13858 ;;      sete    %al
13859
13860 (define_split
13861   [(set (match_operand:QI 0 "nonimmediate_operand" "")
13862         (ne:QI (match_operator 1 "ix86_comparison_operator"
13863                  [(reg FLAGS_REG) (const_int 0)])
13864             (const_int 0)))]
13865   ""
13866   [(set (match_dup 0) (match_dup 1))]
13867 {
13868   PUT_MODE (operands[1], QImode);
13869 })
13870
13871 (define_split
13872   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" ""))
13873         (ne:QI (match_operator 1 "ix86_comparison_operator"
13874                  [(reg FLAGS_REG) (const_int 0)])
13875             (const_int 0)))]
13876   ""
13877   [(set (match_dup 0) (match_dup 1))]
13878 {
13879   PUT_MODE (operands[1], QImode);
13880 })
13881
13882 (define_split
13883   [(set (match_operand:QI 0 "nonimmediate_operand" "")
13884         (eq:QI (match_operator 1 "ix86_comparison_operator"
13885                  [(reg FLAGS_REG) (const_int 0)])
13886             (const_int 0)))]
13887   ""
13888   [(set (match_dup 0) (match_dup 1))]
13889 {
13890   rtx new_op1 = copy_rtx (operands[1]);
13891   operands[1] = new_op1;
13892   PUT_MODE (new_op1, QImode);
13893   PUT_CODE (new_op1, ix86_reverse_condition (GET_CODE (new_op1),
13894                                              GET_MODE (XEXP (new_op1, 0))));
13895
13896   /* Make sure that (a) the CCmode we have for the flags is strong
13897      enough for the reversed compare or (b) we have a valid FP compare.  */
13898   if (! ix86_comparison_operator (new_op1, VOIDmode))
13899     FAIL;
13900 })
13901
13902 (define_split
13903   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" ""))
13904         (eq:QI (match_operator 1 "ix86_comparison_operator"
13905                  [(reg FLAGS_REG) (const_int 0)])
13906             (const_int 0)))]
13907   ""
13908   [(set (match_dup 0) (match_dup 1))]
13909 {
13910   rtx new_op1 = copy_rtx (operands[1]);
13911   operands[1] = new_op1;
13912   PUT_MODE (new_op1, QImode);
13913   PUT_CODE (new_op1, ix86_reverse_condition (GET_CODE (new_op1),
13914                                              GET_MODE (XEXP (new_op1, 0))));
13915
13916   /* Make sure that (a) the CCmode we have for the flags is strong
13917      enough for the reversed compare or (b) we have a valid FP compare.  */
13918   if (! ix86_comparison_operator (new_op1, VOIDmode))
13919     FAIL;
13920 })
13921
13922 ;; The SSE store flag instructions saves 0 or 0xffffffff to the result.
13923 ;; subsequent logical operations are used to imitate conditional moves.
13924 ;; 0xffffffff is NaN, but not in normalized form, so we can't represent
13925 ;; it directly.
13926
13927 (define_insn "*avx_setcc<mode>"
13928   [(set (match_operand:MODEF 0 "register_operand" "=x")
13929         (match_operator:MODEF 1 "avx_comparison_float_operator"
13930           [(match_operand:MODEF 2 "register_operand" "x")
13931            (match_operand:MODEF 3 "nonimmediate_operand" "xm")]))]
13932   "TARGET_AVX"
13933   "vcmp%D1s<ssemodefsuffix>\t{%3, %2, %0|%0, %2, %3}"
13934   [(set_attr "type" "ssecmp")
13935    (set_attr "prefix" "vex")
13936    (set_attr "length_immediate" "1")
13937    (set_attr "mode" "<MODE>")])
13938
13939 (define_insn "*sse_setcc<mode>"
13940   [(set (match_operand:MODEF 0 "register_operand" "=x")
13941         (match_operator:MODEF 1 "sse_comparison_operator"
13942           [(match_operand:MODEF 2 "register_operand" "0")
13943            (match_operand:MODEF 3 "nonimmediate_operand" "xm")]))]
13944   "SSE_FLOAT_MODE_P (<MODE>mode)"
13945   "cmp%D1s<ssemodefsuffix>\t{%3, %0|%0, %3}"
13946   [(set_attr "type" "ssecmp")
13947    (set_attr "length_immediate" "1")
13948    (set_attr "mode" "<MODE>")])
13949 \f
13950 ;; Basic conditional jump instructions.
13951 ;; We ignore the overflow flag for signed branch instructions.
13952
13953 (define_insn "*jcc_1"
13954   [(set (pc)
13955         (if_then_else (match_operator 1 "ix86_comparison_operator"
13956                                       [(reg FLAGS_REG) (const_int 0)])
13957                       (label_ref (match_operand 0 "" ""))
13958                       (pc)))]
13959   ""
13960   "%+j%C1\t%l0"
13961   [(set_attr "type" "ibr")
13962    (set_attr "modrm" "0")
13963    (set (attr "length")
13964            (if_then_else (and (ge (minus (match_dup 0) (pc))
13965                                   (const_int -126))
13966                               (lt (minus (match_dup 0) (pc))
13967                                   (const_int 128)))
13968              (const_int 2)
13969              (const_int 6)))])
13970
13971 (define_insn "*jcc_2"
13972   [(set (pc)
13973         (if_then_else (match_operator 1 "ix86_comparison_operator"
13974                                       [(reg FLAGS_REG) (const_int 0)])
13975                       (pc)
13976                       (label_ref (match_operand 0 "" ""))))]
13977   ""
13978   "%+j%c1\t%l0"
13979   [(set_attr "type" "ibr")
13980    (set_attr "modrm" "0")
13981    (set (attr "length")
13982            (if_then_else (and (ge (minus (match_dup 0) (pc))
13983                                   (const_int -126))
13984                               (lt (minus (match_dup 0) (pc))
13985                                   (const_int 128)))
13986              (const_int 2)
13987              (const_int 6)))])
13988
13989 ;; In general it is not safe to assume too much about CCmode registers,
13990 ;; so simplify-rtx stops when it sees a second one.  Under certain
13991 ;; conditions this is safe on x86, so help combine not create
13992 ;;
13993 ;;      seta    %al
13994 ;;      testb   %al, %al
13995 ;;      je      Lfoo
13996
13997 (define_split
13998   [(set (pc)
13999         (if_then_else (ne (match_operator 0 "ix86_comparison_operator"
14000                                       [(reg FLAGS_REG) (const_int 0)])
14001                           (const_int 0))
14002                       (label_ref (match_operand 1 "" ""))
14003                       (pc)))]
14004   ""
14005   [(set (pc)
14006         (if_then_else (match_dup 0)
14007                       (label_ref (match_dup 1))
14008                       (pc)))]
14009 {
14010   PUT_MODE (operands[0], VOIDmode);
14011 })
14012
14013 (define_split
14014   [(set (pc)
14015         (if_then_else (eq (match_operator 0 "ix86_comparison_operator"
14016                                       [(reg FLAGS_REG) (const_int 0)])
14017                           (const_int 0))
14018                       (label_ref (match_operand 1 "" ""))
14019                       (pc)))]
14020   ""
14021   [(set (pc)
14022         (if_then_else (match_dup 0)
14023                       (label_ref (match_dup 1))
14024                       (pc)))]
14025 {
14026   rtx new_op0 = copy_rtx (operands[0]);
14027   operands[0] = new_op0;
14028   PUT_MODE (new_op0, VOIDmode);
14029   PUT_CODE (new_op0, ix86_reverse_condition (GET_CODE (new_op0),
14030                                              GET_MODE (XEXP (new_op0, 0))));
14031
14032   /* Make sure that (a) the CCmode we have for the flags is strong
14033      enough for the reversed compare or (b) we have a valid FP compare.  */
14034   if (! ix86_comparison_operator (new_op0, VOIDmode))
14035     FAIL;
14036 })
14037
14038 ;; zero_extend in SImode is correct, since this is what combine pass
14039 ;; generates from shift insn with QImode operand.  Actually, the mode of
14040 ;; operand 2 (bit offset operand) doesn't matter since bt insn takes
14041 ;; appropriate modulo of the bit offset value.
14042
14043 (define_insn_and_split "*jcc_btdi_rex64"
14044   [(set (pc)
14045         (if_then_else (match_operator 0 "bt_comparison_operator"
14046                         [(zero_extract:DI
14047                            (match_operand:DI 1 "register_operand" "r")
14048                            (const_int 1)
14049                            (zero_extend:SI
14050                              (match_operand:QI 2 "register_operand" "r")))
14051                          (const_int 0)])
14052                       (label_ref (match_operand 3 "" ""))
14053                       (pc)))
14054    (clobber (reg:CC FLAGS_REG))]
14055   "TARGET_64BIT && (TARGET_USE_BT || optimize_function_for_size_p (cfun))"
14056   "#"
14057   "&& 1"
14058   [(set (reg:CCC FLAGS_REG)
14059         (compare:CCC
14060           (zero_extract:DI
14061             (match_dup 1)
14062             (const_int 1)
14063             (match_dup 2))
14064           (const_int 0)))
14065    (set (pc)
14066         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
14067                       (label_ref (match_dup 3))
14068                       (pc)))]
14069 {
14070   operands[2] = simplify_gen_subreg (DImode, operands[2], QImode, 0);
14071
14072   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
14073 })
14074
14075 ;; avoid useless masking of bit offset operand
14076 (define_insn_and_split "*jcc_btdi_mask_rex64"
14077   [(set (pc)
14078         (if_then_else (match_operator 0 "bt_comparison_operator"
14079                         [(zero_extract:DI
14080                            (match_operand:DI 1 "register_operand" "r")
14081                            (const_int 1)
14082                            (and:SI
14083                              (match_operand:SI 2 "register_operand" "r")
14084                              (match_operand:SI 3 "const_int_operand" "n")))])
14085                       (label_ref (match_operand 4 "" ""))
14086                       (pc)))
14087    (clobber (reg:CC FLAGS_REG))]
14088   "TARGET_64BIT && (TARGET_USE_BT || optimize_function_for_size_p (cfun))
14089    && (INTVAL (operands[3]) & 0x3f) == 0x3f"
14090   "#"
14091   "&& 1"
14092   [(set (reg:CCC FLAGS_REG)
14093         (compare:CCC
14094           (zero_extract:DI
14095             (match_dup 1)
14096             (const_int 1)
14097             (match_dup 2))
14098           (const_int 0)))
14099    (set (pc)
14100         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
14101                       (label_ref (match_dup 4))
14102                       (pc)))]
14103 {
14104   operands[2] = simplify_gen_subreg (DImode, operands[2], SImode, 0);
14105
14106   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
14107 })
14108
14109 (define_insn_and_split "*jcc_btsi"
14110   [(set (pc)
14111         (if_then_else (match_operator 0 "bt_comparison_operator"
14112                         [(zero_extract:SI
14113                            (match_operand:SI 1 "register_operand" "r")
14114                            (const_int 1)
14115                            (zero_extend:SI
14116                              (match_operand:QI 2 "register_operand" "r")))
14117                          (const_int 0)])
14118                       (label_ref (match_operand 3 "" ""))
14119                       (pc)))
14120    (clobber (reg:CC FLAGS_REG))]
14121   "TARGET_USE_BT || optimize_function_for_size_p (cfun)"
14122   "#"
14123   "&& 1"
14124   [(set (reg:CCC FLAGS_REG)
14125         (compare:CCC
14126           (zero_extract:SI
14127             (match_dup 1)
14128             (const_int 1)
14129             (match_dup 2))
14130           (const_int 0)))
14131    (set (pc)
14132         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
14133                       (label_ref (match_dup 3))
14134                       (pc)))]
14135 {
14136   operands[2] = simplify_gen_subreg (SImode, operands[2], QImode, 0);
14137
14138   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
14139 })
14140
14141 ;; avoid useless masking of bit offset operand
14142 (define_insn_and_split "*jcc_btsi_mask"
14143   [(set (pc)
14144         (if_then_else (match_operator 0 "bt_comparison_operator"
14145                         [(zero_extract:SI
14146                            (match_operand:SI 1 "register_operand" "r")
14147                            (const_int 1)
14148                            (and:SI
14149                              (match_operand:SI 2 "register_operand" "r")
14150                              (match_operand:SI 3 "const_int_operand" "n")))])
14151                       (label_ref (match_operand 4 "" ""))
14152                       (pc)))
14153    (clobber (reg:CC FLAGS_REG))]
14154   "(TARGET_USE_BT || optimize_function_for_size_p (cfun))
14155    && (INTVAL (operands[3]) & 0x1f) == 0x1f"
14156   "#"
14157   "&& 1"
14158   [(set (reg:CCC FLAGS_REG)
14159         (compare:CCC
14160           (zero_extract:SI
14161             (match_dup 1)
14162             (const_int 1)
14163             (match_dup 2))
14164           (const_int 0)))
14165    (set (pc)
14166         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
14167                       (label_ref (match_dup 4))
14168                       (pc)))]
14169   "PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));")
14170
14171 (define_insn_and_split "*jcc_btsi_1"
14172   [(set (pc)
14173         (if_then_else (match_operator 0 "bt_comparison_operator"
14174                         [(and:SI
14175                            (lshiftrt:SI
14176                              (match_operand:SI 1 "register_operand" "r")
14177                              (match_operand:QI 2 "register_operand" "r"))
14178                            (const_int 1))
14179                          (const_int 0)])
14180                       (label_ref (match_operand 3 "" ""))
14181                       (pc)))
14182    (clobber (reg:CC FLAGS_REG))]
14183   "TARGET_USE_BT || optimize_function_for_size_p (cfun)"
14184   "#"
14185   "&& 1"
14186   [(set (reg:CCC FLAGS_REG)
14187         (compare:CCC
14188           (zero_extract:SI
14189             (match_dup 1)
14190             (const_int 1)
14191             (match_dup 2))
14192           (const_int 0)))
14193    (set (pc)
14194         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
14195                       (label_ref (match_dup 3))
14196                       (pc)))]
14197 {
14198   operands[2] = simplify_gen_subreg (SImode, operands[2], QImode, 0);
14199
14200   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
14201 })
14202
14203 ;; avoid useless masking of bit offset operand
14204 (define_insn_and_split "*jcc_btsi_mask_1"
14205   [(set (pc)
14206         (if_then_else
14207           (match_operator 0 "bt_comparison_operator"
14208             [(and:SI
14209                (lshiftrt:SI
14210                  (match_operand:SI 1 "register_operand" "r")
14211                  (subreg:QI
14212                    (and:SI
14213                      (match_operand:SI 2 "register_operand" "r")
14214                      (match_operand:SI 3 "const_int_operand" "n")) 0))
14215                (const_int 1))
14216              (const_int 0)])
14217           (label_ref (match_operand 4 "" ""))
14218           (pc)))
14219    (clobber (reg:CC FLAGS_REG))]
14220   "(TARGET_USE_BT || optimize_function_for_size_p (cfun))
14221    && (INTVAL (operands[3]) & 0x1f) == 0x1f"
14222   "#"
14223   "&& 1"
14224   [(set (reg:CCC FLAGS_REG)
14225         (compare:CCC
14226           (zero_extract:SI
14227             (match_dup 1)
14228             (const_int 1)
14229             (match_dup 2))
14230           (const_int 0)))
14231    (set (pc)
14232         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
14233                       (label_ref (match_dup 4))
14234                       (pc)))]
14235   "PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));")
14236
14237 ;; Define combination compare-and-branch fp compare instructions to help
14238 ;; combine.
14239
14240 (define_insn "*fp_jcc_3_387"
14241   [(set (pc)
14242         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
14243                         [(match_operand 1 "register_operand" "f")
14244                          (match_operand 2 "nonimmediate_operand" "fm")])
14245           (label_ref (match_operand 3 "" ""))
14246           (pc)))
14247    (clobber (reg:CCFP FPSR_REG))
14248    (clobber (reg:CCFP FLAGS_REG))
14249    (clobber (match_scratch:HI 4 "=a"))]
14250   "TARGET_80387
14251    && (GET_MODE (operands[1]) == SFmode || GET_MODE (operands[1]) == DFmode)
14252    && GET_MODE (operands[1]) == GET_MODE (operands[2])
14253    && SELECT_CC_MODE (GET_CODE (operands[0]),
14254                       operands[1], operands[2]) == CCFPmode
14255    && !TARGET_CMOVE"
14256   "#")
14257
14258 (define_insn "*fp_jcc_4_387"
14259   [(set (pc)
14260         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
14261                         [(match_operand 1 "register_operand" "f")
14262                          (match_operand 2 "nonimmediate_operand" "fm")])
14263           (pc)
14264           (label_ref (match_operand 3 "" ""))))
14265    (clobber (reg:CCFP FPSR_REG))
14266    (clobber (reg:CCFP FLAGS_REG))
14267    (clobber (match_scratch:HI 4 "=a"))]
14268   "TARGET_80387
14269    && (GET_MODE (operands[1]) == SFmode || GET_MODE (operands[1]) == DFmode)
14270    && GET_MODE (operands[1]) == GET_MODE (operands[2])
14271    && SELECT_CC_MODE (GET_CODE (operands[0]),
14272                       operands[1], operands[2]) == CCFPmode
14273    && !TARGET_CMOVE"
14274   "#")
14275
14276 (define_insn "*fp_jcc_5_387"
14277   [(set (pc)
14278         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
14279                         [(match_operand 1 "register_operand" "f")
14280                          (match_operand 2 "register_operand" "f")])
14281           (label_ref (match_operand 3 "" ""))
14282           (pc)))
14283    (clobber (reg:CCFP FPSR_REG))
14284    (clobber (reg:CCFP FLAGS_REG))
14285    (clobber (match_scratch:HI 4 "=a"))]
14286   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
14287    && GET_MODE (operands[1]) == GET_MODE (operands[2])
14288    && !TARGET_CMOVE"
14289   "#")
14290
14291 (define_insn "*fp_jcc_6_387"
14292   [(set (pc)
14293         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
14294                         [(match_operand 1 "register_operand" "f")
14295                          (match_operand 2 "register_operand" "f")])
14296           (pc)
14297           (label_ref (match_operand 3 "" ""))))
14298    (clobber (reg:CCFP FPSR_REG))
14299    (clobber (reg:CCFP FLAGS_REG))
14300    (clobber (match_scratch:HI 4 "=a"))]
14301   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
14302    && GET_MODE (operands[1]) == GET_MODE (operands[2])
14303    && !TARGET_CMOVE"
14304   "#")
14305
14306 (define_insn "*fp_jcc_7_387"
14307   [(set (pc)
14308         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
14309                         [(match_operand 1 "register_operand" "f")
14310                          (match_operand 2 "const0_operand" "")])
14311           (label_ref (match_operand 3 "" ""))
14312           (pc)))
14313    (clobber (reg:CCFP FPSR_REG))
14314    (clobber (reg:CCFP FLAGS_REG))
14315    (clobber (match_scratch:HI 4 "=a"))]
14316   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
14317    && GET_MODE (operands[1]) == GET_MODE (operands[2])
14318    && SELECT_CC_MODE (GET_CODE (operands[0]),
14319                       operands[1], operands[2]) == CCFPmode
14320    && !TARGET_CMOVE"
14321   "#")
14322
14323 ;; The order of operands in *fp_jcc_8_387 is forced by combine in
14324 ;; simplify_comparison () function. Float operator is treated as RTX_OBJ
14325 ;; with a precedence over other operators and is always put in the first
14326 ;; place. Swap condition and operands to match ficom instruction.
14327
14328 (define_insn "*fp_jcc_8<mode>_387"
14329   [(set (pc)
14330         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
14331                         [(match_operator 1 "float_operator"
14332                            [(match_operand:X87MODEI12 2 "nonimmediate_operand" "m,?r")])
14333                            (match_operand 3 "register_operand" "f,f")])
14334           (label_ref (match_operand 4 "" ""))
14335           (pc)))
14336    (clobber (reg:CCFP FPSR_REG))
14337    (clobber (reg:CCFP FLAGS_REG))
14338    (clobber (match_scratch:HI 5 "=a,a"))]
14339   "X87_FLOAT_MODE_P (GET_MODE (operands[3]))
14340    && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))
14341    && GET_MODE (operands[1]) == GET_MODE (operands[3])
14342    && ix86_fp_compare_mode (swap_condition (GET_CODE (operands[0]))) == CCFPmode
14343    && !TARGET_CMOVE"
14344   "#")
14345
14346 (define_split
14347   [(set (pc)
14348         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
14349                         [(match_operand 1 "register_operand" "")
14350                          (match_operand 2 "nonimmediate_operand" "")])
14351           (match_operand 3 "" "")
14352           (match_operand 4 "" "")))
14353    (clobber (reg:CCFP FPSR_REG))
14354    (clobber (reg:CCFP FLAGS_REG))]
14355   "reload_completed"
14356   [(const_int 0)]
14357 {
14358   ix86_split_fp_branch (GET_CODE (operands[0]), operands[1], operands[2],
14359                         operands[3], operands[4], NULL_RTX, NULL_RTX);
14360   DONE;
14361 })
14362
14363 (define_split
14364   [(set (pc)
14365         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
14366                         [(match_operand 1 "register_operand" "")
14367                          (match_operand 2 "general_operand" "")])
14368           (match_operand 3 "" "")
14369           (match_operand 4 "" "")))
14370    (clobber (reg:CCFP FPSR_REG))
14371    (clobber (reg:CCFP FLAGS_REG))
14372    (clobber (match_scratch:HI 5 "=a"))]
14373   "reload_completed"
14374   [(const_int 0)]
14375 {
14376   ix86_split_fp_branch (GET_CODE (operands[0]), operands[1], operands[2],
14377                         operands[3], operands[4], operands[5], NULL_RTX);
14378   DONE;
14379 })
14380
14381 (define_split
14382   [(set (pc)
14383         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
14384                         [(match_operator 1 "float_operator"
14385                            [(match_operand:X87MODEI12 2 "memory_operand" "")])
14386                            (match_operand 3 "register_operand" "")])
14387           (match_operand 4 "" "")
14388           (match_operand 5 "" "")))
14389    (clobber (reg:CCFP FPSR_REG))
14390    (clobber (reg:CCFP FLAGS_REG))
14391    (clobber (match_scratch:HI 6 "=a"))]
14392   "reload_completed"
14393   [(const_int 0)]
14394 {
14395   operands[7] = gen_rtx_FLOAT (GET_MODE (operands[1]), operands[2]);
14396   ix86_split_fp_branch (swap_condition (GET_CODE (operands[0])),
14397                         operands[3], operands[7],
14398                         operands[4], operands[5], operands[6], NULL_RTX);
14399   DONE;
14400 })
14401
14402 ;; %%% Kill this when reload knows how to do it.
14403 (define_split
14404   [(set (pc)
14405         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
14406                         [(match_operator 1 "float_operator"
14407                            [(match_operand:X87MODEI12 2 "register_operand" "")])
14408                            (match_operand 3 "register_operand" "")])
14409           (match_operand 4 "" "")
14410           (match_operand 5 "" "")))
14411    (clobber (reg:CCFP FPSR_REG))
14412    (clobber (reg:CCFP FLAGS_REG))
14413    (clobber (match_scratch:HI 6 "=a"))]
14414   "reload_completed"
14415   [(const_int 0)]
14416 {
14417   operands[7] = ix86_force_to_memory (GET_MODE (operands[2]), operands[2]);
14418   operands[7] = gen_rtx_FLOAT (GET_MODE (operands[1]), operands[7]);
14419   ix86_split_fp_branch (swap_condition (GET_CODE (operands[0])),
14420                         operands[3], operands[7],
14421                         operands[4], operands[5], operands[6], operands[2]);
14422   DONE;
14423 })
14424 \f
14425 ;; Unconditional and other jump instructions
14426
14427 (define_insn "jump"
14428   [(set (pc)
14429         (label_ref (match_operand 0 "" "")))]
14430   ""
14431   "jmp\t%l0"
14432   [(set_attr "type" "ibr")
14433    (set (attr "length")
14434            (if_then_else (and (ge (minus (match_dup 0) (pc))
14435                                   (const_int -126))
14436                               (lt (minus (match_dup 0) (pc))
14437                                   (const_int 128)))
14438              (const_int 2)
14439              (const_int 5)))
14440    (set_attr "modrm" "0")])
14441
14442 (define_expand "indirect_jump"
14443   [(set (pc) (match_operand 0 "nonimmediate_operand" ""))]
14444   ""
14445   "")
14446
14447 (define_insn "*indirect_jump"
14448   [(set (pc) (match_operand:P 0 "nonimmediate_operand" "rm"))]
14449   ""
14450   "jmp\t%A0"
14451   [(set_attr "type" "ibr")
14452    (set_attr "length_immediate" "0")])
14453
14454 (define_expand "tablejump"
14455   [(parallel [(set (pc) (match_operand 0 "nonimmediate_operand" ""))
14456               (use (label_ref (match_operand 1 "" "")))])]
14457   ""
14458 {
14459   /* In PIC mode, the table entries are stored GOT (32-bit) or PC (64-bit)
14460      relative.  Convert the relative address to an absolute address.  */
14461   if (flag_pic)
14462     {
14463       rtx op0, op1;
14464       enum rtx_code code;
14465
14466       /* We can't use @GOTOFF for text labels on VxWorks;
14467          see gotoff_operand.  */
14468       if (TARGET_64BIT || TARGET_VXWORKS_RTP)
14469         {
14470           code = PLUS;
14471           op0 = operands[0];
14472           op1 = gen_rtx_LABEL_REF (Pmode, operands[1]);
14473         }
14474       else if (TARGET_MACHO || HAVE_AS_GOTOFF_IN_DATA)
14475         {
14476           code = PLUS;
14477           op0 = operands[0];
14478           op1 = pic_offset_table_rtx;
14479         }
14480       else
14481         {
14482           code = MINUS;
14483           op0 = pic_offset_table_rtx;
14484           op1 = operands[0];
14485         }
14486
14487       operands[0] = expand_simple_binop (Pmode, code, op0, op1, NULL_RTX, 0,
14488                                          OPTAB_DIRECT);
14489     }
14490 })
14491
14492 (define_insn "*tablejump_1"
14493   [(set (pc) (match_operand:P 0 "nonimmediate_operand" "rm"))
14494    (use (label_ref (match_operand 1 "" "")))]
14495   ""
14496   "jmp\t%A0"
14497   [(set_attr "type" "ibr")
14498    (set_attr "length_immediate" "0")])
14499 \f
14500 ;; Convert setcc + movzbl to xor + setcc if operands don't overlap.
14501
14502 (define_peephole2
14503   [(set (reg FLAGS_REG) (match_operand 0 "" ""))
14504    (set (match_operand:QI 1 "register_operand" "")
14505         (match_operator:QI 2 "ix86_comparison_operator"
14506           [(reg FLAGS_REG) (const_int 0)]))
14507    (set (match_operand 3 "q_regs_operand" "")
14508         (zero_extend (match_dup 1)))]
14509   "(peep2_reg_dead_p (3, operands[1])
14510     || operands_match_p (operands[1], operands[3]))
14511    && ! reg_overlap_mentioned_p (operands[3], operands[0])"
14512   [(set (match_dup 4) (match_dup 0))
14513    (set (strict_low_part (match_dup 5))
14514         (match_dup 2))]
14515 {
14516   operands[4] = gen_rtx_REG (GET_MODE (operands[0]), FLAGS_REG);
14517   operands[5] = gen_lowpart (QImode, operands[3]);
14518   ix86_expand_clear (operands[3]);
14519 })
14520
14521 ;; Similar, but match zero_extendhisi2_and, which adds a clobber.
14522
14523 (define_peephole2
14524   [(set (reg FLAGS_REG) (match_operand 0 "" ""))
14525    (set (match_operand:QI 1 "register_operand" "")
14526         (match_operator:QI 2 "ix86_comparison_operator"
14527           [(reg FLAGS_REG) (const_int 0)]))
14528    (parallel [(set (match_operand 3 "q_regs_operand" "")
14529                    (zero_extend (match_dup 1)))
14530               (clobber (reg:CC FLAGS_REG))])]
14531   "(peep2_reg_dead_p (3, operands[1])
14532     || operands_match_p (operands[1], operands[3]))
14533    && ! reg_overlap_mentioned_p (operands[3], operands[0])"
14534   [(set (match_dup 4) (match_dup 0))
14535    (set (strict_low_part (match_dup 5))
14536         (match_dup 2))]
14537 {
14538   operands[4] = gen_rtx_REG (GET_MODE (operands[0]), FLAGS_REG);
14539   operands[5] = gen_lowpart (QImode, operands[3]);
14540   ix86_expand_clear (operands[3]);
14541 })
14542 \f
14543 ;; Call instructions.
14544
14545 ;; The predicates normally associated with named expanders are not properly
14546 ;; checked for calls.  This is a bug in the generic code, but it isn't that
14547 ;; easy to fix.  Ignore it for now and be prepared to fix things up.
14548
14549 ;; Call subroutine returning no value.
14550
14551 (define_expand "call_pop"
14552   [(parallel [(call (match_operand:QI 0 "" "")
14553                     (match_operand:SI 1 "" ""))
14554               (set (reg:SI SP_REG)
14555                    (plus:SI (reg:SI SP_REG)
14556                             (match_operand:SI 3 "" "")))])]
14557   "!TARGET_64BIT"
14558 {
14559   ix86_expand_call (NULL, operands[0], operands[1], operands[2], operands[3], 0);
14560   DONE;
14561 })
14562
14563 (define_insn "*call_pop_0"
14564   [(call (mem:QI (match_operand:SI 0 "constant_call_address_operand" ""))
14565          (match_operand:SI 1 "" ""))
14566    (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
14567                             (match_operand:SI 2 "immediate_operand" "")))]
14568   "!TARGET_64BIT"
14569 {
14570   if (SIBLING_CALL_P (insn))
14571     return "jmp\t%P0";
14572   else
14573     return "call\t%P0";
14574 }
14575   [(set_attr "type" "call")])
14576
14577 (define_insn "*call_pop_1"
14578   [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "rsm"))
14579          (match_operand:SI 1 "" ""))
14580    (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
14581                             (match_operand:SI 2 "immediate_operand" "i")))]
14582   "!SIBLING_CALL_P (insn) && !TARGET_64BIT"
14583 {
14584   if (constant_call_address_operand (operands[0], Pmode))
14585     return "call\t%P0";
14586   return "call\t%A0";
14587 }
14588   [(set_attr "type" "call")])
14589
14590 (define_insn "*sibcall_pop_1"
14591   [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "s,U"))
14592          (match_operand:SI 1 "" ""))
14593    (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
14594                             (match_operand:SI 2 "immediate_operand" "i,i")))]
14595   "SIBLING_CALL_P (insn) && !TARGET_64BIT"
14596   "@
14597    jmp\t%P0
14598    jmp\t%A0"
14599   [(set_attr "type" "call")])
14600
14601 (define_expand "call"
14602   [(call (match_operand:QI 0 "" "")
14603          (match_operand 1 "" ""))
14604    (use (match_operand 2 "" ""))]
14605   ""
14606 {
14607   ix86_expand_call (NULL, operands[0], operands[1], operands[2], NULL, 0);
14608   DONE;
14609 })
14610
14611 (define_expand "sibcall"
14612   [(call (match_operand:QI 0 "" "")
14613          (match_operand 1 "" ""))
14614    (use (match_operand 2 "" ""))]
14615   ""
14616 {
14617   ix86_expand_call (NULL, operands[0], operands[1], operands[2], NULL, 1);
14618   DONE;
14619 })
14620
14621 (define_insn "*call_0"
14622   [(call (mem:QI (match_operand 0 "constant_call_address_operand" ""))
14623          (match_operand 1 "" ""))]
14624   ""
14625 {
14626   if (SIBLING_CALL_P (insn))
14627     return "jmp\t%P0";
14628   else
14629     return "call\t%P0";
14630 }
14631   [(set_attr "type" "call")])
14632
14633 (define_insn "*call_1"
14634   [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "rsm"))
14635          (match_operand 1 "" ""))]
14636   "!SIBLING_CALL_P (insn) && !TARGET_64BIT"
14637 {
14638   if (constant_call_address_operand (operands[0], Pmode))
14639     return "call\t%P0";
14640   return "call\t%A0";
14641 }
14642   [(set_attr "type" "call")])
14643
14644 (define_insn "*sibcall_1"
14645   [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "s,U"))
14646          (match_operand 1 "" ""))]
14647   "SIBLING_CALL_P (insn) && !TARGET_64BIT"
14648   "@
14649    jmp\t%P0
14650    jmp\t%A0"
14651   [(set_attr "type" "call")])
14652
14653 (define_insn "*call_1_rex64"
14654   [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rsm"))
14655          (match_operand 1 "" ""))]
14656   "!SIBLING_CALL_P (insn) && TARGET_64BIT
14657    && ix86_cmodel != CM_LARGE && ix86_cmodel != CM_LARGE_PIC"
14658 {
14659   if (constant_call_address_operand (operands[0], Pmode))
14660     return "call\t%P0";
14661   return "call\t%A0";
14662 }
14663   [(set_attr "type" "call")])
14664
14665 (define_insn "*call_1_rex64_ms_sysv"
14666   [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rsm"))
14667          (match_operand 1 "" ""))
14668    (unspec [(const_int 0)] UNSPEC_MS_TO_SYSV_CALL)
14669    (clobber (reg:TI XMM6_REG))
14670    (clobber (reg:TI XMM7_REG))
14671    (clobber (reg:TI XMM8_REG))
14672    (clobber (reg:TI XMM9_REG))
14673    (clobber (reg:TI XMM10_REG))
14674    (clobber (reg:TI XMM11_REG))
14675    (clobber (reg:TI XMM12_REG))
14676    (clobber (reg:TI XMM13_REG))
14677    (clobber (reg:TI XMM14_REG))
14678    (clobber (reg:TI XMM15_REG))
14679    (clobber (reg:DI SI_REG))
14680    (clobber (reg:DI DI_REG))]
14681   "!SIBLING_CALL_P (insn) && TARGET_64BIT"
14682 {
14683   if (constant_call_address_operand (operands[0], Pmode))
14684     return "call\t%P0";
14685   return "call\t%A0";
14686 }
14687   [(set_attr "type" "call")])
14688
14689 (define_insn "*call_1_rex64_large"
14690   [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rm"))
14691          (match_operand 1 "" ""))]
14692   "!SIBLING_CALL_P (insn) && TARGET_64BIT"
14693   "call\t%A0"
14694   [(set_attr "type" "call")])
14695
14696 (define_insn "*sibcall_1_rex64"
14697   [(call (mem:QI (match_operand:DI 0 "sibcall_insn_operand" "s,U"))
14698          (match_operand 1 "" ""))]
14699   "SIBLING_CALL_P (insn) && TARGET_64BIT"
14700   "@
14701    jmp\t%P0
14702    jmp\t%A0"
14703   [(set_attr "type" "call")])
14704
14705 ;; Call subroutine, returning value in operand 0
14706 (define_expand "call_value_pop"
14707   [(parallel [(set (match_operand 0 "" "")
14708                    (call (match_operand:QI 1 "" "")
14709                          (match_operand:SI 2 "" "")))
14710               (set (reg:SI SP_REG)
14711                    (plus:SI (reg:SI SP_REG)
14712                             (match_operand:SI 4 "" "")))])]
14713   "!TARGET_64BIT"
14714 {
14715   ix86_expand_call (operands[0], operands[1], operands[2],
14716                     operands[3], operands[4], 0);
14717   DONE;
14718 })
14719
14720 (define_expand "call_value"
14721   [(set (match_operand 0 "" "")
14722         (call (match_operand:QI 1 "" "")
14723               (match_operand:SI 2 "" "")))
14724    (use (match_operand:SI 3 "" ""))]
14725   ;; Operand 2 not used on the i386.
14726   ""
14727 {
14728   ix86_expand_call (operands[0], operands[1], operands[2], operands[3], NULL, 0);
14729   DONE;
14730 })
14731
14732 (define_expand "sibcall_value"
14733   [(set (match_operand 0 "" "")
14734         (call (match_operand:QI 1 "" "")
14735               (match_operand:SI 2 "" "")))
14736    (use (match_operand:SI 3 "" ""))]
14737   ;; Operand 2 not used on the i386.
14738   ""
14739 {
14740   ix86_expand_call (operands[0], operands[1], operands[2], operands[3], NULL, 1);
14741   DONE;
14742 })
14743
14744 ;; Call subroutine returning any type.
14745
14746 (define_expand "untyped_call"
14747   [(parallel [(call (match_operand 0 "" "")
14748                     (const_int 0))
14749               (match_operand 1 "" "")
14750               (match_operand 2 "" "")])]
14751   ""
14752 {
14753   int i;
14754
14755   /* In order to give reg-stack an easier job in validating two
14756      coprocessor registers as containing a possible return value,
14757      simply pretend the untyped call returns a complex long double
14758      value. 
14759
14760      We can't use SSE_REGPARM_MAX here since callee is unprototyped
14761      and should have the default ABI.  */
14762
14763   ix86_expand_call ((TARGET_FLOAT_RETURNS_IN_80387
14764                      ? gen_rtx_REG (XCmode, FIRST_FLOAT_REG) : NULL),
14765                     operands[0], const0_rtx,
14766                     GEN_INT ((TARGET_64BIT
14767                               ? (ix86_abi == SYSV_ABI
14768                                  ? X86_64_SSE_REGPARM_MAX
14769                                  : X86_64_MS_SSE_REGPARM_MAX)
14770                               : X86_32_SSE_REGPARM_MAX)
14771                              - 1),
14772                     NULL, 0);
14773
14774   for (i = 0; i < XVECLEN (operands[2], 0); i++)
14775     {
14776       rtx set = XVECEXP (operands[2], 0, i);
14777       emit_move_insn (SET_DEST (set), SET_SRC (set));
14778     }
14779
14780   /* The optimizer does not know that the call sets the function value
14781      registers we stored in the result block.  We avoid problems by
14782      claiming that all hard registers are used and clobbered at this
14783      point.  */
14784   emit_insn (gen_blockage ());
14785
14786   DONE;
14787 })
14788 \f
14789 ;; Prologue and epilogue instructions
14790
14791 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
14792 ;; all of memory.  This blocks insns from being moved across this point.
14793
14794 (define_insn "blockage"
14795   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
14796   ""
14797   ""
14798   [(set_attr "length" "0")])
14799
14800 ;; Do not schedule instructions accessing memory across this point.
14801
14802 (define_expand "memory_blockage"
14803   [(set (match_dup 0)
14804         (unspec:BLK [(match_dup 0)] UNSPEC_MEMORY_BLOCKAGE))]
14805   ""
14806 {
14807   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
14808   MEM_VOLATILE_P (operands[0]) = 1;
14809 })
14810
14811 (define_insn "*memory_blockage"
14812   [(set (match_operand:BLK 0 "" "")
14813         (unspec:BLK [(match_dup 0)] UNSPEC_MEMORY_BLOCKAGE))]
14814   ""
14815   ""
14816   [(set_attr "length" "0")])
14817
14818 ;; As USE insns aren't meaningful after reload, this is used instead
14819 ;; to prevent deleting instructions setting registers for PIC code
14820 (define_insn "prologue_use"
14821   [(unspec_volatile [(match_operand 0 "" "")] UNSPECV_PROLOGUE_USE)]
14822   ""
14823   ""
14824   [(set_attr "length" "0")])
14825
14826 ;; Insn emitted into the body of a function to return from a function.
14827 ;; This is only done if the function's epilogue is known to be simple.
14828 ;; See comments for ix86_can_use_return_insn_p in i386.c.
14829
14830 (define_expand "return"
14831   [(return)]
14832   "ix86_can_use_return_insn_p ()"
14833 {
14834   if (crtl->args.pops_args)
14835     {
14836       rtx popc = GEN_INT (crtl->args.pops_args);
14837       emit_jump_insn (gen_return_pop_internal (popc));
14838       DONE;
14839     }
14840 })
14841
14842 (define_insn "return_internal"
14843   [(return)]
14844   "reload_completed"
14845   "ret"
14846   [(set_attr "length" "1")
14847    (set_attr "atom_unit" "jeu")
14848    (set_attr "length_immediate" "0")
14849    (set_attr "modrm" "0")])
14850
14851 ;; Used by x86_machine_dependent_reorg to avoid penalty on single byte RET
14852 ;; instruction Athlon and K8 have.
14853
14854 (define_insn "return_internal_long"
14855   [(return)
14856    (unspec [(const_int 0)] UNSPEC_REP)]
14857   "reload_completed"
14858   "rep\;ret"
14859   [(set_attr "length" "2")
14860    (set_attr "atom_unit" "jeu")
14861    (set_attr "length_immediate" "0")
14862    (set_attr "prefix_rep" "1")
14863    (set_attr "modrm" "0")])
14864
14865 (define_insn "return_pop_internal"
14866   [(return)
14867    (use (match_operand:SI 0 "const_int_operand" ""))]
14868   "reload_completed"
14869   "ret\t%0"
14870   [(set_attr "length" "3")
14871    (set_attr "atom_unit" "jeu")
14872    (set_attr "length_immediate" "2")
14873    (set_attr "modrm" "0")])
14874
14875 (define_insn "return_indirect_internal"
14876   [(return)
14877    (use (match_operand:SI 0 "register_operand" "r"))]
14878   "reload_completed"
14879   "jmp\t%A0"
14880   [(set_attr "type" "ibr")
14881    (set_attr "length_immediate" "0")])
14882
14883 (define_insn "nop"
14884   [(const_int 0)]
14885   ""
14886   "nop"
14887   [(set_attr "length" "1")
14888    (set_attr "length_immediate" "0")
14889    (set_attr "modrm" "0")])
14890
14891 ;; Pad to 16-byte boundary, max skip in op0.  Used to avoid
14892 ;; branch prediction penalty for the third jump in a 16-byte
14893 ;; block on K8.
14894
14895 (define_insn "pad"
14896   [(unspec_volatile [(match_operand 0 "" "")] UNSPECV_ALIGN)]
14897   ""
14898 {
14899 #ifdef ASM_OUTPUT_MAX_SKIP_PAD
14900   ASM_OUTPUT_MAX_SKIP_PAD (asm_out_file, 4, (int)INTVAL (operands[0]));
14901 #else
14902   /* It is tempting to use ASM_OUTPUT_ALIGN here, but we don't want to do that.
14903      The align insn is used to avoid 3 jump instructions in the row to improve
14904      branch prediction and the benefits hardly outweigh the cost of extra 8
14905      nops on the average inserted by full alignment pseudo operation.  */
14906 #endif
14907   return "";
14908 }
14909   [(set_attr "length" "16")])
14910
14911 (define_expand "prologue"
14912   [(const_int 0)]
14913   ""
14914   "ix86_expand_prologue (); DONE;")
14915
14916 (define_insn "set_got"
14917   [(set (match_operand:SI 0 "register_operand" "=r")
14918         (unspec:SI [(const_int 0)] UNSPEC_SET_GOT))
14919    (clobber (reg:CC FLAGS_REG))]
14920   "!TARGET_64BIT"
14921   { return output_set_got (operands[0], NULL_RTX); }
14922   [(set_attr "type" "multi")
14923    (set_attr "length" "12")])
14924
14925 (define_insn "set_got_labelled"
14926   [(set (match_operand:SI 0 "register_operand" "=r")
14927         (unspec:SI [(label_ref (match_operand 1 "" ""))]
14928          UNSPEC_SET_GOT))
14929    (clobber (reg:CC FLAGS_REG))]
14930   "!TARGET_64BIT"
14931   { return output_set_got (operands[0], operands[1]); }
14932   [(set_attr "type" "multi")
14933    (set_attr "length" "12")])
14934
14935 (define_insn "set_got_rex64"
14936   [(set (match_operand:DI 0 "register_operand" "=r")
14937         (unspec:DI [(const_int 0)] UNSPEC_SET_GOT))]
14938   "TARGET_64BIT"
14939   "lea{q}\t{_GLOBAL_OFFSET_TABLE_(%%rip), %0|%0, _GLOBAL_OFFSET_TABLE_[rip]}"
14940   [(set_attr "type" "lea")
14941    (set_attr "length_address" "4")
14942    (set_attr "mode" "DI")])
14943
14944 (define_insn "set_rip_rex64"
14945   [(set (match_operand:DI 0 "register_operand" "=r")
14946         (unspec:DI [(label_ref (match_operand 1 "" ""))] UNSPEC_SET_RIP))]
14947   "TARGET_64BIT"
14948   "lea{q}\t{%l1(%%rip), %0|%0, %l1[rip]}"
14949   [(set_attr "type" "lea")
14950    (set_attr "length_address" "4")
14951    (set_attr "mode" "DI")])
14952
14953 (define_insn "set_got_offset_rex64"
14954   [(set (match_operand:DI 0 "register_operand" "=r")
14955         (unspec:DI
14956           [(label_ref (match_operand 1 "" ""))]
14957           UNSPEC_SET_GOT_OFFSET))]
14958   "TARGET_64BIT"
14959   "movabs{q}\t{$_GLOBAL_OFFSET_TABLE_-%l1, %0|%0, OFFSET FLAT:_GLOBAL_OFFSET_TABLE_-%l1}"
14960   [(set_attr "type" "imov")
14961    (set_attr "length_immediate" "0")
14962    (set_attr "length_address" "8")
14963    (set_attr "mode" "DI")])
14964
14965 (define_expand "epilogue"
14966   [(const_int 0)]
14967   ""
14968   "ix86_expand_epilogue (1); DONE;")
14969
14970 (define_expand "sibcall_epilogue"
14971   [(const_int 0)]
14972   ""
14973   "ix86_expand_epilogue (0); DONE;")
14974
14975 (define_expand "eh_return"
14976   [(use (match_operand 0 "register_operand" ""))]
14977   ""
14978 {
14979   rtx tmp, sa = EH_RETURN_STACKADJ_RTX, ra = operands[0];
14980
14981   /* Tricky bit: we write the address of the handler to which we will
14982      be returning into someone else's stack frame, one word below the
14983      stack address we wish to restore.  */
14984   tmp = gen_rtx_PLUS (Pmode, arg_pointer_rtx, sa);
14985   tmp = plus_constant (tmp, -UNITS_PER_WORD);
14986   tmp = gen_rtx_MEM (Pmode, tmp);
14987   emit_move_insn (tmp, ra);
14988
14989   emit_jump_insn (gen_eh_return_internal ());
14990   emit_barrier ();
14991   DONE;
14992 })
14993
14994 (define_insn_and_split "eh_return_internal"
14995   [(eh_return)]
14996   ""
14997   "#"
14998   "epilogue_completed"
14999   [(const_int 0)]
15000   "ix86_expand_epilogue (2); DONE;")
15001
15002 (define_insn "leave"
15003   [(set (reg:SI SP_REG) (plus:SI (reg:SI BP_REG) (const_int 4)))
15004    (set (reg:SI BP_REG) (mem:SI (reg:SI BP_REG)))
15005    (clobber (mem:BLK (scratch)))]
15006   "!TARGET_64BIT"
15007   "leave"
15008   [(set_attr "type" "leave")])
15009
15010 (define_insn "leave_rex64"
15011   [(set (reg:DI SP_REG) (plus:DI (reg:DI BP_REG) (const_int 8)))
15012    (set (reg:DI BP_REG) (mem:DI (reg:DI BP_REG)))
15013    (clobber (mem:BLK (scratch)))]
15014   "TARGET_64BIT"
15015   "leave"
15016   [(set_attr "type" "leave")])
15017 \f
15018 (define_expand "ffssi2"
15019   [(parallel
15020      [(set (match_operand:SI 0 "register_operand" "")
15021            (ffs:SI (match_operand:SI 1 "nonimmediate_operand" "")))
15022       (clobber (match_scratch:SI 2 ""))
15023       (clobber (reg:CC FLAGS_REG))])]
15024   ""
15025 {
15026   if (TARGET_CMOVE)
15027     {
15028       emit_insn (gen_ffs_cmove (operands[0], operands[1]));
15029       DONE;
15030     }
15031 })
15032
15033 (define_expand "ffs_cmove"
15034   [(set (match_dup 2) (const_int -1))
15035    (parallel [(set (reg:CCZ FLAGS_REG)
15036                    (compare:CCZ (match_operand:SI 1 "nonimmediate_operand" "")
15037                                 (const_int 0)))
15038               (set (match_operand:SI 0 "register_operand" "")
15039                    (ctz:SI (match_dup 1)))])
15040    (set (match_dup 0) (if_then_else:SI
15041                         (eq (reg:CCZ FLAGS_REG) (const_int 0))
15042                         (match_dup 2)
15043                         (match_dup 0)))
15044    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 1)))
15045               (clobber (reg:CC FLAGS_REG))])]
15046   "TARGET_CMOVE"
15047   "operands[2] = gen_reg_rtx (SImode);")
15048
15049 (define_insn_and_split "*ffs_no_cmove"
15050   [(set (match_operand:SI 0 "register_operand" "=r")
15051         (ffs:SI (match_operand:SI 1 "nonimmediate_operand" "rm")))
15052    (clobber (match_scratch:SI 2 "=&q"))
15053    (clobber (reg:CC FLAGS_REG))]
15054   "!TARGET_CMOVE"
15055   "#"
15056   "&& reload_completed"
15057   [(parallel [(set (reg:CCZ FLAGS_REG)
15058                    (compare:CCZ (match_dup 1) (const_int 0)))
15059               (set (match_dup 0) (ctz:SI (match_dup 1)))])
15060    (set (strict_low_part (match_dup 3))
15061         (eq:QI (reg:CCZ FLAGS_REG) (const_int 0)))
15062    (parallel [(set (match_dup 2) (neg:SI (match_dup 2)))
15063               (clobber (reg:CC FLAGS_REG))])
15064    (parallel [(set (match_dup 0) (ior:SI (match_dup 0) (match_dup 2)))
15065               (clobber (reg:CC FLAGS_REG))])
15066    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 1)))
15067               (clobber (reg:CC FLAGS_REG))])]
15068 {
15069   operands[3] = gen_lowpart (QImode, operands[2]);
15070   ix86_expand_clear (operands[2]);
15071 })
15072
15073 (define_insn "*ffssi_1"
15074   [(set (reg:CCZ FLAGS_REG)
15075         (compare:CCZ (match_operand:SI 1 "nonimmediate_operand" "rm")
15076                      (const_int 0)))
15077    (set (match_operand:SI 0 "register_operand" "=r")
15078         (ctz:SI (match_dup 1)))]
15079   ""
15080   "bsf{l}\t{%1, %0|%0, %1}"
15081   [(set_attr "type" "alu1")
15082    (set_attr "prefix_0f" "1")
15083    (set_attr "mode" "SI")])
15084
15085 (define_expand "ffsdi2"
15086   [(set (match_dup 2) (const_int -1))
15087    (parallel [(set (reg:CCZ FLAGS_REG)
15088                    (compare:CCZ (match_operand:DI 1 "nonimmediate_operand" "")
15089                                 (const_int 0)))
15090               (set (match_operand:DI 0 "register_operand" "")
15091                    (ctz:DI (match_dup 1)))])
15092    (set (match_dup 0) (if_then_else:DI
15093                         (eq (reg:CCZ FLAGS_REG) (const_int 0))
15094                         (match_dup 2)
15095                         (match_dup 0)))
15096    (parallel [(set (match_dup 0) (plus:DI (match_dup 0) (const_int 1)))
15097               (clobber (reg:CC FLAGS_REG))])]
15098   "TARGET_64BIT"
15099   "operands[2] = gen_reg_rtx (DImode);")
15100
15101 (define_insn "*ffsdi_1"
15102   [(set (reg:CCZ FLAGS_REG)
15103         (compare:CCZ (match_operand:DI 1 "nonimmediate_operand" "rm")
15104                      (const_int 0)))
15105    (set (match_operand:DI 0 "register_operand" "=r")
15106         (ctz:DI (match_dup 1)))]
15107   "TARGET_64BIT"
15108   "bsf{q}\t{%1, %0|%0, %1}"
15109   [(set_attr "type" "alu1")
15110    (set_attr "prefix_0f" "1")
15111    (set_attr "mode" "DI")])
15112
15113 (define_insn "ctzsi2"
15114   [(set (match_operand:SI 0 "register_operand" "=r")
15115         (ctz:SI (match_operand:SI 1 "nonimmediate_operand" "rm")))
15116    (clobber (reg:CC FLAGS_REG))]
15117   ""
15118   "bsf{l}\t{%1, %0|%0, %1}"
15119   [(set_attr "type" "alu1")
15120    (set_attr "prefix_0f" "1")
15121    (set_attr "mode" "SI")])
15122
15123 (define_insn "ctzdi2"
15124   [(set (match_operand:DI 0 "register_operand" "=r")
15125         (ctz:DI (match_operand:DI 1 "nonimmediate_operand" "rm")))
15126    (clobber (reg:CC FLAGS_REG))]
15127   "TARGET_64BIT"
15128   "bsf{q}\t{%1, %0|%0, %1}"
15129   [(set_attr "type" "alu1")
15130    (set_attr "prefix_0f" "1")
15131    (set_attr "mode" "DI")])
15132
15133 (define_expand "clzsi2"
15134   [(parallel
15135      [(set (match_operand:SI 0 "register_operand" "")
15136            (minus:SI (const_int 31)
15137                      (clz:SI (match_operand:SI 1 "nonimmediate_operand" ""))))
15138       (clobber (reg:CC FLAGS_REG))])
15139    (parallel
15140      [(set (match_dup 0) (xor:SI (match_dup 0) (const_int 31)))
15141       (clobber (reg:CC FLAGS_REG))])]
15142   ""
15143 {
15144   if (TARGET_ABM)
15145     {
15146       emit_insn (gen_clzsi2_abm (operands[0], operands[1]));
15147       DONE;
15148     }
15149 })
15150
15151 (define_insn "clzsi2_abm"
15152   [(set (match_operand:SI 0 "register_operand" "=r")
15153         (clz:SI (match_operand:SI 1 "nonimmediate_operand" "rm")))
15154    (clobber (reg:CC FLAGS_REG))]
15155   "TARGET_ABM"
15156   "lzcnt{l}\t{%1, %0|%0, %1}"
15157   [(set_attr "prefix_rep" "1")
15158    (set_attr "type" "bitmanip")
15159    (set_attr "mode" "SI")])
15160
15161 (define_insn "bsr"
15162   [(set (match_operand:SI 0 "register_operand" "=r")
15163         (minus:SI (const_int 31)
15164                   (clz:SI (match_operand:SI 1 "nonimmediate_operand" "rm"))))
15165    (clobber (reg:CC FLAGS_REG))]
15166   ""
15167   "bsr{l}\t{%1, %0|%0, %1}"
15168   [(set_attr "type" "alu1")
15169    (set_attr "prefix_0f" "1")
15170    (set_attr "mode" "SI")])
15171
15172 (define_insn "popcount<mode>2"
15173   [(set (match_operand:SWI248 0 "register_operand" "=r")
15174         (popcount:SWI248
15175           (match_operand:SWI248 1 "nonimmediate_operand" "rm")))
15176    (clobber (reg:CC FLAGS_REG))]
15177   "TARGET_POPCNT"
15178 {
15179 #if TARGET_MACHO
15180   return "popcnt\t{%1, %0|%0, %1}";
15181 #else
15182   return "popcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
15183 #endif
15184 }
15185   [(set_attr "prefix_rep" "1")
15186    (set_attr "type" "bitmanip")
15187    (set_attr "mode" "<MODE>")])
15188
15189 (define_insn "*popcount<mode>2_cmp"
15190   [(set (reg FLAGS_REG)
15191         (compare
15192           (popcount:SWI248
15193             (match_operand:SWI248 1 "nonimmediate_operand" "rm"))
15194           (const_int 0)))
15195    (set (match_operand:SWI248 0 "register_operand" "=r")
15196         (popcount:SWI248 (match_dup 1)))]
15197   "TARGET_POPCNT && ix86_match_ccmode (insn, CCZmode)"
15198 {
15199 #if TARGET_MACHO
15200   return "popcnt\t{%1, %0|%0, %1}";
15201 #else
15202   return "popcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
15203 #endif
15204 }
15205   [(set_attr "prefix_rep" "1")
15206    (set_attr "type" "bitmanip")
15207    (set_attr "mode" "<MODE>")])
15208
15209 (define_insn "*popcountsi2_cmp_zext"
15210   [(set (reg FLAGS_REG)
15211         (compare
15212           (popcount:SI (match_operand:SI 1 "nonimmediate_operand" "rm"))
15213           (const_int 0)))
15214    (set (match_operand:DI 0 "register_operand" "=r")
15215         (zero_extend:DI(popcount:SI (match_dup 1))))]
15216   "TARGET_64BIT && TARGET_POPCNT && ix86_match_ccmode (insn, CCZmode)"
15217 {
15218 #if TARGET_MACHO
15219   return "popcnt\t{%1, %0|%0, %1}";
15220 #else
15221   return "popcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
15222 #endif
15223 }
15224   [(set_attr "prefix_rep" "1")
15225    (set_attr "type" "bitmanip")
15226    (set_attr "mode" "SI")])
15227
15228 (define_expand "bswapsi2"
15229   [(set (match_operand:SI 0 "register_operand" "")
15230         (bswap:SI (match_operand:SI 1 "register_operand" "")))]
15231   ""
15232 {
15233   if (!(TARGET_BSWAP || TARGET_MOVBE))
15234     {
15235       rtx x = operands[0];
15236
15237       emit_move_insn (x, operands[1]);
15238       emit_insn (gen_bswaphi_lowpart (gen_lowpart (HImode, x)));
15239       emit_insn (gen_rotlsi3 (x, x, GEN_INT (16)));
15240       emit_insn (gen_bswaphi_lowpart (gen_lowpart (HImode, x)));
15241       DONE;
15242     }
15243 })
15244
15245 (define_insn "*bswapsi_movbe"
15246   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,m")
15247         (bswap:SI (match_operand:SI 1 "nonimmediate_operand" "0,m,r")))]
15248   "TARGET_MOVBE && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
15249   "@
15250     bswap\t%0
15251     movbe\t{%1, %0|%0, %1}
15252     movbe\t{%1, %0|%0, %1}"
15253   [(set_attr "type" "*,imov,imov")
15254    (set_attr "modrm" "*,1,1")
15255    (set_attr "prefix_0f" "1")
15256    (set_attr "prefix_extra" "*,1,1")
15257    (set_attr "length" "2,*,*")
15258    (set_attr "mode" "SI")])
15259
15260 (define_insn "*bswapsi_1"
15261   [(set (match_operand:SI 0 "register_operand" "=r")
15262         (bswap:SI (match_operand:SI 1 "register_operand" "0")))]
15263   "TARGET_BSWAP"
15264   "bswap\t%0"
15265   [(set_attr "prefix_0f" "1")
15266    (set_attr "length" "2")])
15267
15268 (define_insn "*bswaphi_lowpart_1"
15269   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+Q,r"))
15270         (bswap:HI (match_dup 0)))
15271    (clobber (reg:CC FLAGS_REG))]
15272   "TARGET_USE_XCHGB || optimize_function_for_size_p (cfun)"
15273   "@
15274     xchg{b}\t{%h0, %b0|%b0, %h0}
15275     rol{w}\t{$8, %0|%0, 8}"
15276   [(set_attr "length" "2,4")
15277    (set_attr "mode" "QI,HI")])
15278
15279 (define_insn "bswaphi_lowpart"
15280   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+r"))
15281         (bswap:HI (match_dup 0)))
15282    (clobber (reg:CC FLAGS_REG))]
15283   ""
15284   "rol{w}\t{$8, %0|%0, 8}"
15285   [(set_attr "length" "4")
15286    (set_attr "mode" "HI")])
15287
15288 (define_expand "bswapdi2"
15289   [(set (match_operand:DI 0 "register_operand" "")
15290         (bswap:DI (match_operand:DI 1 "register_operand" "")))]
15291   "TARGET_64BIT"
15292   "")
15293
15294 (define_insn "*bswapdi_movbe"
15295   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m")
15296         (bswap:DI (match_operand:DI 1 "nonimmediate_operand" "0,m,r")))]
15297   "TARGET_64BIT && TARGET_MOVBE
15298    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
15299   "@
15300     bswap\t%0
15301     movbe\t{%1, %0|%0, %1}
15302     movbe\t{%1, %0|%0, %1}"
15303   [(set_attr "type" "*,imov,imov")
15304    (set_attr "modrm" "*,1,1")
15305    (set_attr "prefix_0f" "1")
15306    (set_attr "prefix_extra" "*,1,1")
15307    (set_attr "length" "3,*,*")
15308    (set_attr "mode" "DI")])
15309
15310 (define_insn "*bswapdi_1"
15311   [(set (match_operand:DI 0 "register_operand" "=r")
15312         (bswap:DI (match_operand:DI 1 "register_operand" "0")))]
15313   "TARGET_64BIT"
15314   "bswap\t%0"
15315   [(set_attr "prefix_0f" "1")
15316    (set_attr "length" "3")])
15317
15318 (define_expand "clzdi2"
15319   [(parallel
15320      [(set (match_operand:DI 0 "register_operand" "")
15321            (minus:DI (const_int 63)
15322                      (clz:DI (match_operand:DI 1 "nonimmediate_operand" ""))))
15323       (clobber (reg:CC FLAGS_REG))])
15324    (parallel
15325      [(set (match_dup 0) (xor:DI (match_dup 0) (const_int 63)))
15326       (clobber (reg:CC FLAGS_REG))])]
15327   "TARGET_64BIT"
15328 {
15329   if (TARGET_ABM)
15330     {
15331       emit_insn (gen_clzdi2_abm (operands[0], operands[1]));
15332       DONE;
15333     }
15334 })
15335
15336 (define_insn "clzdi2_abm"
15337   [(set (match_operand:DI 0 "register_operand" "=r")
15338         (clz:DI (match_operand:DI 1 "nonimmediate_operand" "rm")))
15339    (clobber (reg:CC FLAGS_REG))]
15340   "TARGET_64BIT && TARGET_ABM"
15341   "lzcnt{q}\t{%1, %0|%0, %1}"
15342   [(set_attr "prefix_rep" "1")
15343    (set_attr "type" "bitmanip")
15344    (set_attr "mode" "DI")])
15345
15346 (define_insn "bsr_rex64"
15347   [(set (match_operand:DI 0 "register_operand" "=r")
15348         (minus:DI (const_int 63)
15349                   (clz:DI (match_operand:DI 1 "nonimmediate_operand" "rm"))))
15350    (clobber (reg:CC FLAGS_REG))]
15351   "TARGET_64BIT"
15352   "bsr{q}\t{%1, %0|%0, %1}"
15353   [(set_attr "type" "alu1")
15354    (set_attr "prefix_0f" "1")
15355    (set_attr "mode" "DI")])
15356
15357 (define_expand "clzhi2"
15358   [(parallel
15359      [(set (match_operand:HI 0 "register_operand" "")
15360            (minus:HI (const_int 15)
15361                      (clz:HI (match_operand:HI 1 "nonimmediate_operand" ""))))
15362       (clobber (reg:CC FLAGS_REG))])
15363    (parallel
15364      [(set (match_dup 0) (xor:HI (match_dup 0) (const_int 15)))
15365       (clobber (reg:CC FLAGS_REG))])]
15366   ""
15367 {
15368   if (TARGET_ABM)
15369     {
15370       emit_insn (gen_clzhi2_abm (operands[0], operands[1]));
15371       DONE;
15372     }
15373 })
15374
15375 (define_insn "clzhi2_abm"
15376   [(set (match_operand:HI 0 "register_operand" "=r")
15377         (clz:HI (match_operand:HI 1 "nonimmediate_operand" "rm")))
15378    (clobber (reg:CC FLAGS_REG))]
15379   "TARGET_ABM"
15380   "lzcnt{w}\t{%1, %0|%0, %1}"
15381   [(set_attr "prefix_rep" "1")
15382    (set_attr "type" "bitmanip")
15383    (set_attr "mode" "HI")])
15384
15385 (define_insn "*bsrhi"
15386   [(set (match_operand:HI 0 "register_operand" "=r")
15387         (minus:HI (const_int 15)
15388                   (clz:HI (match_operand:HI 1 "nonimmediate_operand" "rm"))))
15389    (clobber (reg:CC FLAGS_REG))]
15390   ""
15391   "bsr{w}\t{%1, %0|%0, %1}"
15392   [(set_attr "type" "alu1")
15393    (set_attr "prefix_0f" "1")
15394    (set_attr "mode" "HI")])
15395
15396 (define_expand "paritydi2"
15397   [(set (match_operand:DI 0 "register_operand" "")
15398         (parity:DI (match_operand:DI 1 "register_operand" "")))]
15399   "! TARGET_POPCNT"
15400 {
15401   rtx scratch = gen_reg_rtx (QImode);
15402   rtx cond;
15403
15404   emit_insn (gen_paritydi2_cmp (NULL_RTX, NULL_RTX,
15405                                 NULL_RTX, operands[1]));
15406
15407   cond = gen_rtx_fmt_ee (ORDERED, QImode,
15408                          gen_rtx_REG (CCmode, FLAGS_REG),
15409                          const0_rtx);
15410   emit_insn (gen_rtx_SET (VOIDmode, scratch, cond));
15411
15412   if (TARGET_64BIT)
15413     emit_insn (gen_zero_extendqidi2 (operands[0], scratch));
15414   else
15415     {
15416       rtx tmp = gen_reg_rtx (SImode);
15417
15418       emit_insn (gen_zero_extendqisi2 (tmp, scratch));
15419       emit_insn (gen_zero_extendsidi2 (operands[0], tmp));
15420     }
15421   DONE;
15422 })
15423
15424 (define_insn_and_split "paritydi2_cmp"
15425   [(set (reg:CC FLAGS_REG)
15426         (parity:CC (match_operand:DI 3 "register_operand" "0")))
15427    (clobber (match_scratch:DI 0 "=r"))
15428    (clobber (match_scratch:SI 1 "=&r"))
15429    (clobber (match_scratch:HI 2 "=Q"))]
15430   "! TARGET_POPCNT"
15431   "#"
15432   "&& reload_completed"
15433   [(parallel
15434      [(set (match_dup 1)
15435            (xor:SI (match_dup 1) (match_dup 4)))
15436       (clobber (reg:CC FLAGS_REG))])
15437    (parallel
15438      [(set (reg:CC FLAGS_REG)
15439            (parity:CC (match_dup 1)))
15440       (clobber (match_dup 1))
15441       (clobber (match_dup 2))])]
15442 {
15443   operands[4] = gen_lowpart (SImode, operands[3]);
15444
15445   if (TARGET_64BIT)
15446     {
15447       emit_move_insn (operands[1], gen_lowpart (SImode, operands[3]));
15448       emit_insn (gen_lshrdi3 (operands[3], operands[3], GEN_INT (32)));
15449     }
15450   else
15451     operands[1] = gen_highpart (SImode, operands[3]);
15452 })
15453
15454 (define_expand "paritysi2"
15455   [(set (match_operand:SI 0 "register_operand" "")
15456         (parity:SI (match_operand:SI 1 "register_operand" "")))]
15457   "! TARGET_POPCNT"
15458 {
15459   rtx scratch = gen_reg_rtx (QImode);
15460   rtx cond;
15461
15462   emit_insn (gen_paritysi2_cmp (NULL_RTX, NULL_RTX, operands[1]));
15463
15464   cond = gen_rtx_fmt_ee (ORDERED, QImode,
15465                          gen_rtx_REG (CCmode, FLAGS_REG),
15466                          const0_rtx);
15467   emit_insn (gen_rtx_SET (VOIDmode, scratch, cond));
15468
15469   emit_insn (gen_zero_extendqisi2 (operands[0], scratch));
15470   DONE;
15471 })
15472
15473 (define_insn_and_split "paritysi2_cmp"
15474   [(set (reg:CC FLAGS_REG)
15475         (parity:CC (match_operand:SI 2 "register_operand" "0")))
15476    (clobber (match_scratch:SI 0 "=r"))
15477    (clobber (match_scratch:HI 1 "=&Q"))]
15478   "! TARGET_POPCNT"
15479   "#"
15480   "&& reload_completed"
15481   [(parallel
15482      [(set (match_dup 1)
15483            (xor:HI (match_dup 1) (match_dup 3)))
15484       (clobber (reg:CC FLAGS_REG))])
15485    (parallel
15486      [(set (reg:CC FLAGS_REG)
15487            (parity:CC (match_dup 1)))
15488       (clobber (match_dup 1))])]
15489 {
15490   operands[3] = gen_lowpart (HImode, operands[2]);
15491
15492   emit_move_insn (operands[1], gen_lowpart (HImode, operands[2]));
15493   emit_insn (gen_lshrsi3 (operands[2], operands[2], GEN_INT (16)));
15494 })
15495
15496 (define_insn "*parityhi2_cmp"
15497   [(set (reg:CC FLAGS_REG)
15498         (parity:CC (match_operand:HI 1 "register_operand" "0")))
15499    (clobber (match_scratch:HI 0 "=Q"))]
15500   "! TARGET_POPCNT"
15501   "xor{b}\t{%h0, %b0|%b0, %h0}"
15502   [(set_attr "length" "2")
15503    (set_attr "mode" "HI")])
15504
15505 (define_insn "*parityqi2_cmp"
15506   [(set (reg:CC FLAGS_REG)
15507         (parity:CC (match_operand:QI 0 "register_operand" "q")))]
15508   "! TARGET_POPCNT"
15509   "test{b}\t%0, %0"
15510   [(set_attr "length" "2")
15511    (set_attr "mode" "QI")])
15512 \f
15513 ;; Thread-local storage patterns for ELF.
15514 ;;
15515 ;; Note that these code sequences must appear exactly as shown
15516 ;; in order to allow linker relaxation.
15517
15518 (define_insn "*tls_global_dynamic_32_gnu"
15519   [(set (match_operand:SI 0 "register_operand" "=a")
15520         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
15521                     (match_operand:SI 2 "tls_symbolic_operand" "")
15522                     (match_operand:SI 3 "call_insn_operand" "")]
15523                     UNSPEC_TLS_GD))
15524    (clobber (match_scratch:SI 4 "=d"))
15525    (clobber (match_scratch:SI 5 "=c"))
15526    (clobber (reg:CC FLAGS_REG))]
15527   "!TARGET_64BIT && TARGET_GNU_TLS"
15528   "lea{l}\t{%a2@TLSGD(,%1,1), %0|%0, %a2@TLSGD[%1*1]}\;call\t%P3"
15529   [(set_attr "type" "multi")
15530    (set_attr "length" "12")])
15531
15532 (define_insn "*tls_global_dynamic_32_sun"
15533   [(set (match_operand:SI 0 "register_operand" "=a")
15534         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
15535                     (match_operand:SI 2 "tls_symbolic_operand" "")
15536                     (match_operand:SI 3 "call_insn_operand" "")]
15537                     UNSPEC_TLS_GD))
15538    (clobber (match_scratch:SI 4 "=d"))
15539    (clobber (match_scratch:SI 5 "=c"))
15540    (clobber (reg:CC FLAGS_REG))]
15541   "!TARGET_64BIT && TARGET_SUN_TLS"
15542   "lea{l}\t{%a2@DTLNDX(%1), %4|%4, %a2@DTLNDX[%1]}
15543         push{l}\t%4\;call\t%a2@TLSPLT\;pop{l}\t%4\;nop"
15544   [(set_attr "type" "multi")
15545    (set_attr "length" "14")])
15546
15547 (define_expand "tls_global_dynamic_32"
15548   [(parallel [(set (match_operand:SI 0 "register_operand" "")
15549                    (unspec:SI
15550                     [(match_dup 2)
15551                      (match_operand:SI 1 "tls_symbolic_operand" "")
15552                      (match_dup 3)]
15553                     UNSPEC_TLS_GD))
15554               (clobber (match_scratch:SI 4 ""))
15555               (clobber (match_scratch:SI 5 ""))
15556               (clobber (reg:CC FLAGS_REG))])]
15557   ""
15558 {
15559   if (flag_pic)
15560     operands[2] = pic_offset_table_rtx;
15561   else
15562     {
15563       operands[2] = gen_reg_rtx (Pmode);
15564       emit_insn (gen_set_got (operands[2]));
15565     }
15566   if (TARGET_GNU2_TLS)
15567     {
15568        emit_insn (gen_tls_dynamic_gnu2_32
15569                   (operands[0], operands[1], operands[2]));
15570        DONE;
15571     }
15572   operands[3] = ix86_tls_get_addr ();
15573 })
15574
15575 (define_insn "*tls_global_dynamic_64"
15576   [(set (match_operand:DI 0 "register_operand" "=a")
15577         (call:DI (mem:QI (match_operand:DI 2 "call_insn_operand" ""))
15578                  (match_operand:DI 3 "" "")))
15579    (unspec:DI [(match_operand:DI 1 "tls_symbolic_operand" "")]
15580               UNSPEC_TLS_GD)]
15581   "TARGET_64BIT"
15582   { return ASM_BYTE "0x66\n\tlea{q}\t{%a1@TLSGD(%%rip), %%rdi|rdi, %a1@TLSGD[rip]}\n" ASM_SHORT "0x6666\n\trex64\n\tcall\t%P2"; }
15583   [(set_attr "type" "multi")
15584    (set_attr "length" "16")])
15585
15586 (define_expand "tls_global_dynamic_64"
15587   [(parallel [(set (match_operand:DI 0 "register_operand" "")
15588                    (call:DI (mem:QI (match_dup 2)) (const_int 0)))
15589               (unspec:DI [(match_operand:DI 1 "tls_symbolic_operand" "")]
15590                          UNSPEC_TLS_GD)])]
15591   ""
15592 {
15593   if (TARGET_GNU2_TLS)
15594     {
15595        emit_insn (gen_tls_dynamic_gnu2_64
15596                   (operands[0], operands[1]));
15597        DONE;
15598     }
15599   operands[2] = ix86_tls_get_addr ();
15600 })
15601
15602 (define_insn "*tls_local_dynamic_base_32_gnu"
15603   [(set (match_operand:SI 0 "register_operand" "=a")
15604         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
15605                     (match_operand:SI 2 "call_insn_operand" "")]
15606                    UNSPEC_TLS_LD_BASE))
15607    (clobber (match_scratch:SI 3 "=d"))
15608    (clobber (match_scratch:SI 4 "=c"))
15609    (clobber (reg:CC FLAGS_REG))]
15610   "!TARGET_64BIT && TARGET_GNU_TLS"
15611   "lea{l}\t{%&@TLSLDM(%1), %0|%0, %&@TLSLDM[%1]}\;call\t%P2"
15612   [(set_attr "type" "multi")
15613    (set_attr "length" "11")])
15614
15615 (define_insn "*tls_local_dynamic_base_32_sun"
15616   [(set (match_operand:SI 0 "register_operand" "=a")
15617         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
15618                     (match_operand:SI 2 "call_insn_operand" "")]
15619                    UNSPEC_TLS_LD_BASE))
15620    (clobber (match_scratch:SI 3 "=d"))
15621    (clobber (match_scratch:SI 4 "=c"))
15622    (clobber (reg:CC FLAGS_REG))]
15623   "!TARGET_64BIT && TARGET_SUN_TLS"
15624   "lea{l}\t{%&@TMDNX(%1), %3|%3, %&@TMDNX[%1]}
15625         push{l}\t%3\;call\t%&@TLSPLT\;pop{l}\t%3"
15626   [(set_attr "type" "multi")
15627    (set_attr "length" "13")])
15628
15629 (define_expand "tls_local_dynamic_base_32"
15630   [(parallel [(set (match_operand:SI 0 "register_operand" "")
15631                    (unspec:SI [(match_dup 1) (match_dup 2)]
15632                               UNSPEC_TLS_LD_BASE))
15633               (clobber (match_scratch:SI 3 ""))
15634               (clobber (match_scratch:SI 4 ""))
15635               (clobber (reg:CC FLAGS_REG))])]
15636   ""
15637 {
15638   if (flag_pic)
15639     operands[1] = pic_offset_table_rtx;
15640   else
15641     {
15642       operands[1] = gen_reg_rtx (Pmode);
15643       emit_insn (gen_set_got (operands[1]));
15644     }
15645   if (TARGET_GNU2_TLS)
15646     {
15647        emit_insn (gen_tls_dynamic_gnu2_32
15648                   (operands[0], ix86_tls_module_base (), operands[1]));
15649        DONE;
15650     }
15651   operands[2] = ix86_tls_get_addr ();
15652 })
15653
15654 (define_insn "*tls_local_dynamic_base_64"
15655   [(set (match_operand:DI 0 "register_operand" "=a")
15656         (call:DI (mem:QI (match_operand:DI 1 "call_insn_operand" ""))
15657                  (match_operand:DI 2 "" "")))
15658    (unspec:DI [(const_int 0)] UNSPEC_TLS_LD_BASE)]
15659   "TARGET_64BIT"
15660   "lea{q}\t{%&@TLSLD(%%rip), %%rdi|rdi, %&@TLSLD[rip]}\;call\t%P1"
15661   [(set_attr "type" "multi")
15662    (set_attr "length" "12")])
15663
15664 (define_expand "tls_local_dynamic_base_64"
15665   [(parallel [(set (match_operand:DI 0 "register_operand" "")
15666                    (call:DI (mem:QI (match_dup 1)) (const_int 0)))
15667               (unspec:DI [(const_int 0)] UNSPEC_TLS_LD_BASE)])]
15668   ""
15669 {
15670   if (TARGET_GNU2_TLS)
15671     {
15672        emit_insn (gen_tls_dynamic_gnu2_64
15673                   (operands[0], ix86_tls_module_base ()));
15674        DONE;
15675     }
15676   operands[1] = ix86_tls_get_addr ();
15677 })
15678
15679 ;; Local dynamic of a single variable is a lose.  Show combine how
15680 ;; to convert that back to global dynamic.
15681
15682 (define_insn_and_split "*tls_local_dynamic_32_once"
15683   [(set (match_operand:SI 0 "register_operand" "=a")
15684         (plus:SI (unspec:SI [(match_operand:SI 1 "register_operand" "b")
15685                              (match_operand:SI 2 "call_insn_operand" "")]
15686                             UNSPEC_TLS_LD_BASE)
15687                  (const:SI (unspec:SI
15688                             [(match_operand:SI 3 "tls_symbolic_operand" "")]
15689                             UNSPEC_DTPOFF))))
15690    (clobber (match_scratch:SI 4 "=d"))
15691    (clobber (match_scratch:SI 5 "=c"))
15692    (clobber (reg:CC FLAGS_REG))]
15693   ""
15694   "#"
15695   ""
15696   [(parallel [(set (match_dup 0)
15697                    (unspec:SI [(match_dup 1) (match_dup 3) (match_dup 2)]
15698                               UNSPEC_TLS_GD))
15699               (clobber (match_dup 4))
15700               (clobber (match_dup 5))
15701               (clobber (reg:CC FLAGS_REG))])]
15702   "")
15703
15704 ;; Load and add the thread base pointer from %gs:0.
15705
15706 (define_insn "*load_tp_si"
15707   [(set (match_operand:SI 0 "register_operand" "=r")
15708         (unspec:SI [(const_int 0)] UNSPEC_TP))]
15709   "!TARGET_64BIT"
15710   "mov{l}\t{%%gs:0, %0|%0, DWORD PTR gs:0}"
15711   [(set_attr "type" "imov")
15712    (set_attr "modrm" "0")
15713    (set_attr "length" "7")
15714    (set_attr "memory" "load")
15715    (set_attr "imm_disp" "false")])
15716
15717 (define_insn "*add_tp_si"
15718   [(set (match_operand:SI 0 "register_operand" "=r")
15719         (plus:SI (unspec:SI [(const_int 0)] UNSPEC_TP)
15720                  (match_operand:SI 1 "register_operand" "0")))
15721    (clobber (reg:CC FLAGS_REG))]
15722   "!TARGET_64BIT"
15723   "add{l}\t{%%gs:0, %0|%0, DWORD PTR gs:0}"
15724   [(set_attr "type" "alu")
15725    (set_attr "modrm" "0")
15726    (set_attr "length" "7")
15727    (set_attr "memory" "load")
15728    (set_attr "imm_disp" "false")])
15729
15730 (define_insn "*load_tp_di"
15731   [(set (match_operand:DI 0 "register_operand" "=r")
15732         (unspec:DI [(const_int 0)] UNSPEC_TP))]
15733   "TARGET_64BIT"
15734   "mov{q}\t{%%fs:0, %0|%0, QWORD PTR fs:0}"
15735   [(set_attr "type" "imov")
15736    (set_attr "modrm" "0")
15737    (set_attr "length" "7")
15738    (set_attr "memory" "load")
15739    (set_attr "imm_disp" "false")])
15740
15741 (define_insn "*add_tp_di"
15742   [(set (match_operand:DI 0 "register_operand" "=r")
15743         (plus:DI (unspec:DI [(const_int 0)] UNSPEC_TP)
15744                  (match_operand:DI 1 "register_operand" "0")))
15745    (clobber (reg:CC FLAGS_REG))]
15746   "TARGET_64BIT"
15747   "add{q}\t{%%fs:0, %0|%0, QWORD PTR fs:0}"
15748   [(set_attr "type" "alu")
15749    (set_attr "modrm" "0")
15750    (set_attr "length" "7")
15751    (set_attr "memory" "load")
15752    (set_attr "imm_disp" "false")])
15753
15754 ;; GNU2 TLS patterns can be split.
15755
15756 (define_expand "tls_dynamic_gnu2_32"
15757   [(set (match_dup 3)
15758         (plus:SI (match_operand:SI 2 "register_operand" "")
15759                  (const:SI
15760                   (unspec:SI [(match_operand:SI 1 "tls_symbolic_operand" "")]
15761                              UNSPEC_TLSDESC))))
15762    (parallel
15763     [(set (match_operand:SI 0 "register_operand" "")
15764           (unspec:SI [(match_dup 1) (match_dup 3)
15765                       (match_dup 2) (reg:SI SP_REG)]
15766                       UNSPEC_TLSDESC))
15767      (clobber (reg:CC FLAGS_REG))])]
15768   "!TARGET_64BIT && TARGET_GNU2_TLS"
15769 {
15770   operands[3] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
15771   ix86_tls_descriptor_calls_expanded_in_cfun = true;
15772 })
15773
15774 (define_insn "*tls_dynamic_lea_32"
15775   [(set (match_operand:SI 0 "register_operand" "=r")
15776         (plus:SI (match_operand:SI 1 "register_operand" "b")
15777                  (const:SI
15778                   (unspec:SI [(match_operand:SI 2 "tls_symbolic_operand" "")]
15779                               UNSPEC_TLSDESC))))]
15780   "!TARGET_64BIT && TARGET_GNU2_TLS"
15781   "lea{l}\t{%a2@TLSDESC(%1), %0|%0, %a2@TLSDESC[%1]}"
15782   [(set_attr "type" "lea")
15783    (set_attr "mode" "SI")
15784    (set_attr "length" "6")
15785    (set_attr "length_address" "4")])
15786
15787 (define_insn "*tls_dynamic_call_32"
15788   [(set (match_operand:SI 0 "register_operand" "=a")
15789         (unspec:SI [(match_operand:SI 1 "tls_symbolic_operand" "")
15790                     (match_operand:SI 2 "register_operand" "0")
15791                     ;; we have to make sure %ebx still points to the GOT
15792                     (match_operand:SI 3 "register_operand" "b")
15793                     (reg:SI SP_REG)]
15794                    UNSPEC_TLSDESC))
15795    (clobber (reg:CC FLAGS_REG))]
15796   "!TARGET_64BIT && TARGET_GNU2_TLS"
15797   "call\t{*%a1@TLSCALL(%2)|[DWORD PTR [%2+%a1@TLSCALL]]}"
15798   [(set_attr "type" "call")
15799    (set_attr "length" "2")
15800    (set_attr "length_address" "0")])
15801
15802 (define_insn_and_split "*tls_dynamic_gnu2_combine_32"
15803   [(set (match_operand:SI 0 "register_operand" "=&a")
15804         (plus:SI
15805          (unspec:SI [(match_operand:SI 3 "tls_modbase_operand" "")
15806                      (match_operand:SI 4 "" "")
15807                      (match_operand:SI 2 "register_operand" "b")
15808                      (reg:SI SP_REG)]
15809                     UNSPEC_TLSDESC)
15810          (const:SI (unspec:SI
15811                     [(match_operand:SI 1 "tls_symbolic_operand" "")]
15812                     UNSPEC_DTPOFF))))
15813    (clobber (reg:CC FLAGS_REG))]
15814   "!TARGET_64BIT && TARGET_GNU2_TLS"
15815   "#"
15816   ""
15817   [(set (match_dup 0) (match_dup 5))]
15818 {
15819   operands[5] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
15820   emit_insn (gen_tls_dynamic_gnu2_32 (operands[5], operands[1], operands[2]));
15821 })
15822
15823 (define_expand "tls_dynamic_gnu2_64"
15824   [(set (match_dup 2)
15825         (unspec:DI [(match_operand:DI 1 "tls_symbolic_operand" "")]
15826                    UNSPEC_TLSDESC))
15827    (parallel
15828     [(set (match_operand:DI 0 "register_operand" "")
15829           (unspec:DI [(match_dup 1) (match_dup 2) (reg:DI SP_REG)]
15830                      UNSPEC_TLSDESC))
15831      (clobber (reg:CC FLAGS_REG))])]
15832   "TARGET_64BIT && TARGET_GNU2_TLS"
15833 {
15834   operands[2] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
15835   ix86_tls_descriptor_calls_expanded_in_cfun = true;
15836 })
15837
15838 (define_insn "*tls_dynamic_lea_64"
15839   [(set (match_operand:DI 0 "register_operand" "=r")
15840         (unspec:DI [(match_operand:DI 1 "tls_symbolic_operand" "")]
15841                    UNSPEC_TLSDESC))]
15842   "TARGET_64BIT && TARGET_GNU2_TLS"
15843   "lea{q}\t{%a1@TLSDESC(%%rip), %0|%0, %a1@TLSDESC[rip]}"
15844   [(set_attr "type" "lea")
15845    (set_attr "mode" "DI")
15846    (set_attr "length" "7")
15847    (set_attr "length_address" "4")])
15848
15849 (define_insn "*tls_dynamic_call_64"
15850   [(set (match_operand:DI 0 "register_operand" "=a")
15851         (unspec:DI [(match_operand:DI 1 "tls_symbolic_operand" "")
15852                     (match_operand:DI 2 "register_operand" "0")
15853                     (reg:DI SP_REG)]
15854                    UNSPEC_TLSDESC))
15855    (clobber (reg:CC FLAGS_REG))]
15856   "TARGET_64BIT && TARGET_GNU2_TLS"
15857   "call\t{*%a1@TLSCALL(%2)|[QWORD PTR [%2+%a1@TLSCALL]]}"
15858   [(set_attr "type" "call")
15859    (set_attr "length" "2")
15860    (set_attr "length_address" "0")])
15861
15862 (define_insn_and_split "*tls_dynamic_gnu2_combine_64"
15863   [(set (match_operand:DI 0 "register_operand" "=&a")
15864         (plus:DI
15865          (unspec:DI [(match_operand:DI 2 "tls_modbase_operand" "")
15866                      (match_operand:DI 3 "" "")
15867                      (reg:DI SP_REG)]
15868                     UNSPEC_TLSDESC)
15869          (const:DI (unspec:DI
15870                     [(match_operand:DI 1 "tls_symbolic_operand" "")]
15871                     UNSPEC_DTPOFF))))
15872    (clobber (reg:CC FLAGS_REG))]
15873   "TARGET_64BIT && TARGET_GNU2_TLS"
15874   "#"
15875   ""
15876   [(set (match_dup 0) (match_dup 4))]
15877 {
15878   operands[4] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
15879   emit_insn (gen_tls_dynamic_gnu2_64 (operands[4], operands[1]));
15880 })
15881
15882 ;;
15883 \f
15884 ;; These patterns match the binary 387 instructions for addM3, subM3,
15885 ;; mulM3 and divM3.  There are three patterns for each of DFmode and
15886 ;; SFmode.  The first is the normal insn, the second the same insn but
15887 ;; with one operand a conversion, and the third the same insn but with
15888 ;; the other operand a conversion.  The conversion may be SFmode or
15889 ;; SImode if the target mode DFmode, but only SImode if the target mode
15890 ;; is SFmode.
15891
15892 ;; Gcc is slightly more smart about handling normal two address instructions
15893 ;; so use special patterns for add and mull.
15894
15895 (define_insn "*fop_<mode>_comm_mixed_avx"
15896   [(set (match_operand:MODEF 0 "register_operand" "=f,x")
15897         (match_operator:MODEF 3 "binary_fp_operator"
15898           [(match_operand:MODEF 1 "nonimmediate_operand" "%0,x")
15899            (match_operand:MODEF 2 "nonimmediate_operand" "fm,xm")]))]
15900   "AVX_FLOAT_MODE_P (<MODE>mode) && TARGET_MIX_SSE_I387
15901    && COMMUTATIVE_ARITH_P (operands[3])
15902    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
15903   "* return output_387_binary_op (insn, operands);"
15904   [(set (attr "type")
15905         (if_then_else (eq_attr "alternative" "1")
15906            (if_then_else (match_operand:MODEF 3 "mult_operator" "")
15907               (const_string "ssemul")
15908               (const_string "sseadd"))
15909            (if_then_else (match_operand:MODEF 3 "mult_operator" "")
15910               (const_string "fmul")
15911               (const_string "fop"))))
15912    (set_attr "prefix" "orig,maybe_vex")
15913    (set_attr "mode" "<MODE>")])
15914
15915 (define_insn "*fop_<mode>_comm_mixed"
15916   [(set (match_operand:MODEF 0 "register_operand" "=f,x")
15917         (match_operator:MODEF 3 "binary_fp_operator"
15918           [(match_operand:MODEF 1 "nonimmediate_operand" "%0,0")
15919            (match_operand:MODEF 2 "nonimmediate_operand" "fm,xm")]))]
15920   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_MIX_SSE_I387
15921    && COMMUTATIVE_ARITH_P (operands[3])
15922    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
15923   "* return output_387_binary_op (insn, operands);"
15924   [(set (attr "type")
15925         (if_then_else (eq_attr "alternative" "1")
15926            (if_then_else (match_operand:MODEF 3 "mult_operator" "")
15927               (const_string "ssemul")
15928               (const_string "sseadd"))
15929            (if_then_else (match_operand:MODEF 3 "mult_operator" "")
15930               (const_string "fmul")
15931               (const_string "fop"))))
15932    (set_attr "mode" "<MODE>")])
15933
15934 (define_insn "*fop_<mode>_comm_avx"
15935   [(set (match_operand:MODEF 0 "register_operand" "=x")
15936         (match_operator:MODEF 3 "binary_fp_operator"
15937           [(match_operand:MODEF 1 "nonimmediate_operand" "%x")
15938            (match_operand:MODEF 2 "nonimmediate_operand" "xm")]))]
15939   "AVX_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15940    && COMMUTATIVE_ARITH_P (operands[3])
15941    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
15942   "* return output_387_binary_op (insn, operands);"
15943   [(set (attr "type")
15944         (if_then_else (match_operand:MODEF 3 "mult_operator" "")
15945            (const_string "ssemul")
15946            (const_string "sseadd")))
15947    (set_attr "prefix" "vex")
15948    (set_attr "mode" "<MODE>")])
15949
15950 (define_insn "*fop_<mode>_comm_sse"
15951   [(set (match_operand:MODEF 0 "register_operand" "=x")
15952         (match_operator:MODEF 3 "binary_fp_operator"
15953           [(match_operand:MODEF 1 "nonimmediate_operand" "%0")
15954            (match_operand:MODEF 2 "nonimmediate_operand" "xm")]))]
15955   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15956    && COMMUTATIVE_ARITH_P (operands[3])
15957    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
15958   "* return output_387_binary_op (insn, operands);"
15959   [(set (attr "type")
15960         (if_then_else (match_operand:MODEF 3 "mult_operator" "")
15961            (const_string "ssemul")
15962            (const_string "sseadd")))
15963    (set_attr "mode" "<MODE>")])
15964
15965 (define_insn "*fop_<mode>_comm_i387"
15966   [(set (match_operand:MODEF 0 "register_operand" "=f")
15967         (match_operator:MODEF 3 "binary_fp_operator"
15968           [(match_operand:MODEF 1 "nonimmediate_operand" "%0")
15969            (match_operand:MODEF 2 "nonimmediate_operand" "fm")]))]
15970   "TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode)
15971    && COMMUTATIVE_ARITH_P (operands[3])
15972    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
15973   "* return output_387_binary_op (insn, operands);"
15974   [(set (attr "type")
15975         (if_then_else (match_operand:MODEF 3 "mult_operator" "")
15976            (const_string "fmul")
15977            (const_string "fop")))
15978    (set_attr "mode" "<MODE>")])
15979
15980 (define_insn "*fop_<mode>_1_mixed_avx"
15981   [(set (match_operand:MODEF 0 "register_operand" "=f,f,x")
15982         (match_operator:MODEF 3 "binary_fp_operator"
15983           [(match_operand:MODEF 1 "nonimmediate_operand" "0,fm,x")
15984            (match_operand:MODEF 2 "nonimmediate_operand" "fm,0,xm")]))]
15985   "AVX_FLOAT_MODE_P (<MODE>mode) && TARGET_MIX_SSE_I387
15986    && !COMMUTATIVE_ARITH_P (operands[3])
15987    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
15988   "* return output_387_binary_op (insn, operands);"
15989   [(set (attr "type")
15990         (cond [(and (eq_attr "alternative" "2")
15991                     (match_operand:MODEF 3 "mult_operator" ""))
15992                  (const_string "ssemul")
15993                (and (eq_attr "alternative" "2")
15994                     (match_operand:MODEF 3 "div_operator" ""))
15995                  (const_string "ssediv")
15996                (eq_attr "alternative" "2")
15997                  (const_string "sseadd")
15998                (match_operand:MODEF 3 "mult_operator" "")
15999                  (const_string "fmul")
16000                (match_operand:MODEF 3 "div_operator" "")
16001                  (const_string "fdiv")
16002               ]
16003               (const_string "fop")))
16004    (set_attr "prefix" "orig,orig,maybe_vex")
16005    (set_attr "mode" "<MODE>")])
16006
16007 (define_insn "*fop_<mode>_1_mixed"
16008   [(set (match_operand:MODEF 0 "register_operand" "=f,f,x")
16009         (match_operator:MODEF 3 "binary_fp_operator"
16010           [(match_operand:MODEF 1 "nonimmediate_operand" "0,fm,0")
16011            (match_operand:MODEF 2 "nonimmediate_operand" "fm,0,xm")]))]
16012   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_MIX_SSE_I387
16013    && !COMMUTATIVE_ARITH_P (operands[3])
16014    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
16015   "* return output_387_binary_op (insn, operands);"
16016   [(set (attr "type")
16017         (cond [(and (eq_attr "alternative" "2")
16018                     (match_operand:MODEF 3 "mult_operator" ""))
16019                  (const_string "ssemul")
16020                (and (eq_attr "alternative" "2")
16021                     (match_operand:MODEF 3 "div_operator" ""))
16022                  (const_string "ssediv")
16023                (eq_attr "alternative" "2")
16024                  (const_string "sseadd")
16025                (match_operand:MODEF 3 "mult_operator" "")
16026                  (const_string "fmul")
16027                (match_operand:MODEF 3 "div_operator" "")
16028                  (const_string "fdiv")
16029               ]
16030               (const_string "fop")))
16031    (set_attr "mode" "<MODE>")])
16032
16033 (define_insn "*rcpsf2_sse"
16034   [(set (match_operand:SF 0 "register_operand" "=x")
16035         (unspec:SF [(match_operand:SF 1 "nonimmediate_operand" "xm")]
16036                    UNSPEC_RCP))]
16037   "TARGET_SSE_MATH"
16038   "%vrcpss\t{%1, %d0|%d0, %1}"
16039   [(set_attr "type" "sse")
16040    (set_attr "atom_sse_attr" "rcp")
16041    (set_attr "prefix" "maybe_vex")
16042    (set_attr "mode" "SF")])
16043
16044 (define_insn "*fop_<mode>_1_avx"
16045   [(set (match_operand:MODEF 0 "register_operand" "=x")
16046         (match_operator:MODEF 3 "binary_fp_operator"
16047           [(match_operand:MODEF 1 "register_operand" "x")
16048            (match_operand:MODEF 2 "nonimmediate_operand" "xm")]))]
16049   "AVX_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
16050    && !COMMUTATIVE_ARITH_P (operands[3])"
16051   "* return output_387_binary_op (insn, operands);"
16052   [(set (attr "type")
16053         (cond [(match_operand:MODEF 3 "mult_operator" "")
16054                  (const_string "ssemul")
16055                (match_operand:MODEF 3 "div_operator" "")
16056                  (const_string "ssediv")
16057               ]
16058               (const_string "sseadd")))
16059    (set_attr "prefix" "vex")
16060    (set_attr "mode" "<MODE>")])
16061
16062 (define_insn "*fop_<mode>_1_sse"
16063   [(set (match_operand:MODEF 0 "register_operand" "=x")
16064         (match_operator:MODEF 3 "binary_fp_operator"
16065           [(match_operand:MODEF 1 "register_operand" "0")
16066            (match_operand:MODEF 2 "nonimmediate_operand" "xm")]))]
16067   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
16068    && !COMMUTATIVE_ARITH_P (operands[3])"
16069   "* return output_387_binary_op (insn, operands);"
16070   [(set (attr "type")
16071         (cond [(match_operand:MODEF 3 "mult_operator" "")
16072                  (const_string "ssemul")
16073                (match_operand:MODEF 3 "div_operator" "")
16074                  (const_string "ssediv")
16075               ]
16076               (const_string "sseadd")))
16077    (set_attr "mode" "<MODE>")])
16078
16079 ;; This pattern is not fully shadowed by the pattern above.
16080 (define_insn "*fop_<mode>_1_i387"
16081   [(set (match_operand:MODEF 0 "register_operand" "=f,f")
16082         (match_operator:MODEF 3 "binary_fp_operator"
16083           [(match_operand:MODEF 1 "nonimmediate_operand" "0,fm")
16084            (match_operand:MODEF 2 "nonimmediate_operand" "fm,0")]))]
16085   "TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode)
16086    && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
16087    && !COMMUTATIVE_ARITH_P (operands[3])
16088    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
16089   "* return output_387_binary_op (insn, operands);"
16090   [(set (attr "type")
16091         (cond [(match_operand:MODEF 3 "mult_operator" "")
16092                  (const_string "fmul")
16093                (match_operand:MODEF 3 "div_operator" "")
16094                  (const_string "fdiv")
16095               ]
16096               (const_string "fop")))
16097    (set_attr "mode" "<MODE>")])
16098
16099 ;; ??? Add SSE splitters for these!
16100 (define_insn "*fop_<MODEF:mode>_2_i387"
16101   [(set (match_operand:MODEF 0 "register_operand" "=f,f")
16102         (match_operator:MODEF 3 "binary_fp_operator"
16103           [(float:MODEF
16104              (match_operand:X87MODEI12 1 "nonimmediate_operand" "m,?r"))
16105            (match_operand:MODEF 2 "register_operand" "0,0")]))]
16106   "TARGET_80387 && X87_ENABLE_FLOAT (<MODEF:MODE>mode, <X87MODEI12:MODE>mode)
16107    && !(SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH)
16108    && (TARGET_USE_<X87MODEI12:MODE>MODE_FIOP || optimize_function_for_size_p (cfun))"
16109   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
16110   [(set (attr "type")
16111         (cond [(match_operand:MODEF 3 "mult_operator" "")
16112                  (const_string "fmul")
16113                (match_operand:MODEF 3 "div_operator" "")
16114                  (const_string "fdiv")
16115               ]
16116               (const_string "fop")))
16117    (set_attr "fp_int_src" "true")
16118    (set_attr "mode" "<X87MODEI12:MODE>")])
16119
16120 (define_insn "*fop_<MODEF:mode>_3_i387"
16121   [(set (match_operand:MODEF 0 "register_operand" "=f,f")
16122         (match_operator:MODEF 3 "binary_fp_operator"
16123           [(match_operand:MODEF 1 "register_operand" "0,0")
16124            (float:MODEF
16125              (match_operand:X87MODEI12 2 "nonimmediate_operand" "m,?r"))]))]
16126   "TARGET_80387 && X87_ENABLE_FLOAT (<MODEF:MODE>mode, <X87MODEI12:MODE>mode)
16127    && !(SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH)
16128    && (TARGET_USE_<X87MODEI12:MODE>MODE_FIOP || optimize_function_for_size_p (cfun))"
16129   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
16130   [(set (attr "type")
16131         (cond [(match_operand:MODEF 3 "mult_operator" "")
16132                  (const_string "fmul")
16133                (match_operand:MODEF 3 "div_operator" "")
16134                  (const_string "fdiv")
16135               ]
16136               (const_string "fop")))
16137    (set_attr "fp_int_src" "true")
16138    (set_attr "mode" "<MODE>")])
16139
16140 (define_insn "*fop_df_4_i387"
16141   [(set (match_operand:DF 0 "register_operand" "=f,f")
16142         (match_operator:DF 3 "binary_fp_operator"
16143            [(float_extend:DF
16144              (match_operand:SF 1 "nonimmediate_operand" "fm,0"))
16145             (match_operand:DF 2 "register_operand" "0,f")]))]
16146   "TARGET_80387 && X87_ENABLE_ARITH (DFmode)
16147    && !(TARGET_SSE2 && TARGET_SSE_MATH)
16148    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
16149   "* return output_387_binary_op (insn, operands);"
16150   [(set (attr "type")
16151         (cond [(match_operand:DF 3 "mult_operator" "")
16152                  (const_string "fmul")
16153                (match_operand:DF 3 "div_operator" "")
16154                  (const_string "fdiv")
16155               ]
16156               (const_string "fop")))
16157    (set_attr "mode" "SF")])
16158
16159 (define_insn "*fop_df_5_i387"
16160   [(set (match_operand:DF 0 "register_operand" "=f,f")
16161         (match_operator:DF 3 "binary_fp_operator"
16162           [(match_operand:DF 1 "register_operand" "0,f")
16163            (float_extend:DF
16164             (match_operand:SF 2 "nonimmediate_operand" "fm,0"))]))]
16165   "TARGET_80387 && X87_ENABLE_ARITH (DFmode)
16166    && !(TARGET_SSE2 && TARGET_SSE_MATH)"
16167   "* return output_387_binary_op (insn, operands);"
16168   [(set (attr "type")
16169         (cond [(match_operand:DF 3 "mult_operator" "")
16170                  (const_string "fmul")
16171                (match_operand:DF 3 "div_operator" "")
16172                  (const_string "fdiv")
16173               ]
16174               (const_string "fop")))
16175    (set_attr "mode" "SF")])
16176
16177 (define_insn "*fop_df_6_i387"
16178   [(set (match_operand:DF 0 "register_operand" "=f,f")
16179         (match_operator:DF 3 "binary_fp_operator"
16180           [(float_extend:DF
16181             (match_operand:SF 1 "register_operand" "0,f"))
16182            (float_extend:DF
16183             (match_operand:SF 2 "nonimmediate_operand" "fm,0"))]))]
16184   "TARGET_80387 && X87_ENABLE_ARITH (DFmode)
16185    && !(TARGET_SSE2 && TARGET_SSE_MATH)"
16186   "* return output_387_binary_op (insn, operands);"
16187   [(set (attr "type")
16188         (cond [(match_operand:DF 3 "mult_operator" "")
16189                  (const_string "fmul")
16190                (match_operand:DF 3 "div_operator" "")
16191                  (const_string "fdiv")
16192               ]
16193               (const_string "fop")))
16194    (set_attr "mode" "SF")])
16195
16196 (define_insn "*fop_xf_comm_i387"
16197   [(set (match_operand:XF 0 "register_operand" "=f")
16198         (match_operator:XF 3 "binary_fp_operator"
16199                         [(match_operand:XF 1 "register_operand" "%0")
16200                          (match_operand:XF 2 "register_operand" "f")]))]
16201   "TARGET_80387
16202    && COMMUTATIVE_ARITH_P (operands[3])"
16203   "* return output_387_binary_op (insn, operands);"
16204   [(set (attr "type")
16205         (if_then_else (match_operand:XF 3 "mult_operator" "")
16206            (const_string "fmul")
16207            (const_string "fop")))
16208    (set_attr "mode" "XF")])
16209
16210 (define_insn "*fop_xf_1_i387"
16211   [(set (match_operand:XF 0 "register_operand" "=f,f")
16212         (match_operator:XF 3 "binary_fp_operator"
16213                         [(match_operand:XF 1 "register_operand" "0,f")
16214                          (match_operand:XF 2 "register_operand" "f,0")]))]
16215   "TARGET_80387
16216    && !COMMUTATIVE_ARITH_P (operands[3])"
16217   "* return output_387_binary_op (insn, operands);"
16218   [(set (attr "type")
16219         (cond [(match_operand:XF 3 "mult_operator" "")
16220                  (const_string "fmul")
16221                (match_operand:XF 3 "div_operator" "")
16222                  (const_string "fdiv")
16223               ]
16224               (const_string "fop")))
16225    (set_attr "mode" "XF")])
16226
16227 (define_insn "*fop_xf_2_i387"
16228   [(set (match_operand:XF 0 "register_operand" "=f,f")
16229         (match_operator:XF 3 "binary_fp_operator"
16230           [(float:XF
16231              (match_operand:X87MODEI12 1 "nonimmediate_operand" "m,?r"))
16232            (match_operand:XF 2 "register_operand" "0,0")]))]
16233   "TARGET_80387 && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))"
16234   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
16235   [(set (attr "type")
16236         (cond [(match_operand:XF 3 "mult_operator" "")
16237                  (const_string "fmul")
16238                (match_operand:XF 3 "div_operator" "")
16239                  (const_string "fdiv")
16240               ]
16241               (const_string "fop")))
16242    (set_attr "fp_int_src" "true")
16243    (set_attr "mode" "<MODE>")])
16244
16245 (define_insn "*fop_xf_3_i387"
16246   [(set (match_operand:XF 0 "register_operand" "=f,f")
16247         (match_operator:XF 3 "binary_fp_operator"
16248           [(match_operand:XF 1 "register_operand" "0,0")
16249            (float:XF
16250              (match_operand:X87MODEI12 2 "nonimmediate_operand" "m,?r"))]))]
16251   "TARGET_80387 && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))"
16252   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
16253   [(set (attr "type")
16254         (cond [(match_operand:XF 3 "mult_operator" "")
16255                  (const_string "fmul")
16256                (match_operand:XF 3 "div_operator" "")
16257                  (const_string "fdiv")
16258               ]
16259               (const_string "fop")))
16260    (set_attr "fp_int_src" "true")
16261    (set_attr "mode" "<MODE>")])
16262
16263 (define_insn "*fop_xf_4_i387"
16264   [(set (match_operand:XF 0 "register_operand" "=f,f")
16265         (match_operator:XF 3 "binary_fp_operator"
16266            [(float_extend:XF
16267               (match_operand:MODEF 1 "nonimmediate_operand" "fm,0"))
16268             (match_operand:XF 2 "register_operand" "0,f")]))]
16269   "TARGET_80387"
16270   "* return output_387_binary_op (insn, operands);"
16271   [(set (attr "type")
16272         (cond [(match_operand:XF 3 "mult_operator" "")
16273                  (const_string "fmul")
16274                (match_operand:XF 3 "div_operator" "")
16275                  (const_string "fdiv")
16276               ]
16277               (const_string "fop")))
16278    (set_attr "mode" "<MODE>")])
16279
16280 (define_insn "*fop_xf_5_i387"
16281   [(set (match_operand:XF 0 "register_operand" "=f,f")
16282         (match_operator:XF 3 "binary_fp_operator"
16283           [(match_operand:XF 1 "register_operand" "0,f")
16284            (float_extend:XF
16285              (match_operand:MODEF 2 "nonimmediate_operand" "fm,0"))]))]
16286   "TARGET_80387"
16287   "* return output_387_binary_op (insn, operands);"
16288   [(set (attr "type")
16289         (cond [(match_operand:XF 3 "mult_operator" "")
16290                  (const_string "fmul")
16291                (match_operand:XF 3 "div_operator" "")
16292                  (const_string "fdiv")
16293               ]
16294               (const_string "fop")))
16295    (set_attr "mode" "<MODE>")])
16296
16297 (define_insn "*fop_xf_6_i387"
16298   [(set (match_operand:XF 0 "register_operand" "=f,f")
16299         (match_operator:XF 3 "binary_fp_operator"
16300           [(float_extend:XF
16301              (match_operand:MODEF 1 "register_operand" "0,f"))
16302            (float_extend:XF
16303              (match_operand:MODEF 2 "nonimmediate_operand" "fm,0"))]))]
16304   "TARGET_80387"
16305   "* return output_387_binary_op (insn, operands);"
16306   [(set (attr "type")
16307         (cond [(match_operand:XF 3 "mult_operator" "")
16308                  (const_string "fmul")
16309                (match_operand:XF 3 "div_operator" "")
16310                  (const_string "fdiv")
16311               ]
16312               (const_string "fop")))
16313    (set_attr "mode" "<MODE>")])
16314
16315 (define_split
16316   [(set (match_operand 0 "register_operand" "")
16317         (match_operator 3 "binary_fp_operator"
16318            [(float (match_operand:X87MODEI12 1 "register_operand" ""))
16319             (match_operand 2 "register_operand" "")]))]
16320   "reload_completed
16321    && X87_FLOAT_MODE_P (GET_MODE (operands[0]))
16322    && X87_ENABLE_FLOAT (GET_MODE (operands[0]), GET_MODE (operands[1]))"
16323   [(const_int 0)]
16324 {
16325   operands[4] = ix86_force_to_memory (GET_MODE (operands[1]), operands[1]);
16326   operands[4] = gen_rtx_FLOAT (GET_MODE (operands[0]), operands[4]);
16327   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
16328                           gen_rtx_fmt_ee (GET_CODE (operands[3]),
16329                                           GET_MODE (operands[3]),
16330                                           operands[4],
16331                                           operands[2])));
16332   ix86_free_from_memory (GET_MODE (operands[1]));
16333   DONE;
16334 })
16335
16336 (define_split
16337   [(set (match_operand 0 "register_operand" "")
16338         (match_operator 3 "binary_fp_operator"
16339            [(match_operand 1 "register_operand" "")
16340             (float (match_operand:X87MODEI12 2 "register_operand" ""))]))]
16341   "reload_completed
16342    && X87_FLOAT_MODE_P (GET_MODE (operands[0]))
16343    && X87_ENABLE_FLOAT (GET_MODE (operands[0]), GET_MODE (operands[2]))"
16344   [(const_int 0)]
16345 {
16346   operands[4] = ix86_force_to_memory (GET_MODE (operands[2]), operands[2]);
16347   operands[4] = gen_rtx_FLOAT (GET_MODE (operands[0]), operands[4]);
16348   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
16349                           gen_rtx_fmt_ee (GET_CODE (operands[3]),
16350                                           GET_MODE (operands[3]),
16351                                           operands[1],
16352                                           operands[4])));
16353   ix86_free_from_memory (GET_MODE (operands[2]));
16354   DONE;
16355 })
16356 \f
16357 ;; FPU special functions.
16358
16359 ;; This pattern implements a no-op XFmode truncation for
16360 ;; all fancy i386 XFmode math functions.
16361
16362 (define_insn "truncxf<mode>2_i387_noop_unspec"
16363   [(set (match_operand:MODEF 0 "register_operand" "=f")
16364         (unspec:MODEF [(match_operand:XF 1 "register_operand" "f")]
16365         UNSPEC_TRUNC_NOOP))]
16366   "TARGET_USE_FANCY_MATH_387"
16367   "* return output_387_reg_move (insn, operands);"
16368   [(set_attr "type" "fmov")
16369    (set_attr "mode" "<MODE>")])
16370
16371 (define_insn "sqrtxf2"
16372   [(set (match_operand:XF 0 "register_operand" "=f")
16373         (sqrt:XF (match_operand:XF 1 "register_operand" "0")))]
16374   "TARGET_USE_FANCY_MATH_387"
16375   "fsqrt"
16376   [(set_attr "type" "fpspc")
16377    (set_attr "mode" "XF")
16378    (set_attr "athlon_decode" "direct")
16379    (set_attr "amdfam10_decode" "direct")])
16380
16381 (define_insn "sqrt_extend<mode>xf2_i387"
16382   [(set (match_operand:XF 0 "register_operand" "=f")
16383         (sqrt:XF
16384           (float_extend:XF
16385             (match_operand:MODEF 1 "register_operand" "0"))))]
16386   "TARGET_USE_FANCY_MATH_387"
16387   "fsqrt"
16388   [(set_attr "type" "fpspc")
16389    (set_attr "mode" "XF")
16390    (set_attr "athlon_decode" "direct")
16391    (set_attr "amdfam10_decode" "direct")])
16392
16393 (define_insn "*rsqrtsf2_sse"
16394   [(set (match_operand:SF 0 "register_operand" "=x")
16395         (unspec:SF [(match_operand:SF 1 "nonimmediate_operand" "xm")]
16396                    UNSPEC_RSQRT))]
16397   "TARGET_SSE_MATH"
16398   "%vrsqrtss\t{%1, %d0|%d0, %1}"
16399   [(set_attr "type" "sse")
16400    (set_attr "atom_sse_attr" "rcp")
16401    (set_attr "prefix" "maybe_vex")
16402    (set_attr "mode" "SF")])
16403
16404 (define_expand "rsqrtsf2"
16405   [(set (match_operand:SF 0 "register_operand" "")
16406         (unspec:SF [(match_operand:SF 1 "nonimmediate_operand" "")]
16407                    UNSPEC_RSQRT))]
16408   "TARGET_SSE_MATH"
16409 {
16410   ix86_emit_swsqrtsf (operands[0], operands[1], SFmode, 1);
16411   DONE;
16412 })
16413
16414 (define_insn "*sqrt<mode>2_sse"
16415   [(set (match_operand:MODEF 0 "register_operand" "=x")
16416         (sqrt:MODEF
16417           (match_operand:MODEF 1 "nonimmediate_operand" "xm")))]
16418   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
16419   "%vsqrts<ssemodefsuffix>\t{%1, %d0|%d0, %1}"
16420   [(set_attr "type" "sse")
16421    (set_attr "atom_sse_attr" "sqrt")
16422    (set_attr "prefix" "maybe_vex")
16423    (set_attr "mode" "<MODE>")
16424    (set_attr "athlon_decode" "*")
16425    (set_attr "amdfam10_decode" "*")])
16426
16427 (define_expand "sqrt<mode>2"
16428   [(set (match_operand:MODEF 0 "register_operand" "")
16429         (sqrt:MODEF
16430           (match_operand:MODEF 1 "nonimmediate_operand" "")))]
16431   "(TARGET_USE_FANCY_MATH_387 && X87_ENABLE_ARITH (<MODE>mode))
16432    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
16433 {
16434   if (<MODE>mode == SFmode
16435       && TARGET_SSE_MATH && TARGET_RECIP && !optimize_function_for_size_p (cfun)
16436       && flag_finite_math_only && !flag_trapping_math
16437       && flag_unsafe_math_optimizations)
16438     {
16439       ix86_emit_swsqrtsf (operands[0], operands[1], SFmode, 0);
16440       DONE;
16441     }
16442
16443   if (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))
16444     {
16445       rtx op0 = gen_reg_rtx (XFmode);
16446       rtx op1 = force_reg (<MODE>mode, operands[1]);
16447
16448       emit_insn (gen_sqrt_extend<mode>xf2_i387 (op0, op1));
16449       emit_insn (gen_truncxf<mode>2_i387_noop_unspec (operands[0], op0));
16450       DONE;
16451    }
16452 })
16453
16454 (define_insn "fpremxf4_i387"
16455   [(set (match_operand:XF 0 "register_operand" "=f")
16456         (unspec:XF [(match_operand:XF 2 "register_operand" "0")
16457                     (match_operand:XF 3 "register_operand" "1")]
16458                    UNSPEC_FPREM_F))
16459    (set (match_operand:XF 1 "register_operand" "=u")
16460         (unspec:XF [(match_dup 2) (match_dup 3)]
16461                    UNSPEC_FPREM_U))
16462    (set (reg:CCFP FPSR_REG)
16463         (unspec:CCFP [(match_dup 2) (match_dup 3)]
16464                      UNSPEC_C2_FLAG))]
16465   "TARGET_USE_FANCY_MATH_387"
16466   "fprem"
16467   [(set_attr "type" "fpspc")
16468    (set_attr "mode" "XF")])
16469
16470 (define_expand "fmodxf3"
16471   [(use (match_operand:XF 0 "register_operand" ""))
16472    (use (match_operand:XF 1 "general_operand" ""))
16473    (use (match_operand:XF 2 "general_operand" ""))]
16474   "TARGET_USE_FANCY_MATH_387"
16475 {
16476   rtx label = gen_label_rtx ();
16477
16478   rtx op1 = gen_reg_rtx (XFmode);
16479   rtx op2 = gen_reg_rtx (XFmode);
16480
16481   emit_move_insn (op2, operands[2]);
16482   emit_move_insn (op1, operands[1]);
16483
16484   emit_label (label);
16485   emit_insn (gen_fpremxf4_i387 (op1, op2, op1, op2));
16486   ix86_emit_fp_unordered_jump (label);
16487   LABEL_NUSES (label) = 1;
16488
16489   emit_move_insn (operands[0], op1);
16490   DONE;
16491 })
16492
16493 (define_expand "fmod<mode>3"
16494   [(use (match_operand:MODEF 0 "register_operand" ""))
16495    (use (match_operand:MODEF 1 "general_operand" ""))
16496    (use (match_operand:MODEF 2 "general_operand" ""))]
16497   "TARGET_USE_FANCY_MATH_387"
16498 {
16499   rtx label = gen_label_rtx ();
16500
16501   rtx op1 = gen_reg_rtx (XFmode);
16502   rtx op2 = gen_reg_rtx (XFmode);
16503
16504   emit_insn (gen_extend<mode>xf2 (op2, operands[2]));
16505   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
16506
16507   emit_label (label);
16508   emit_insn (gen_fpremxf4_i387 (op1, op2, op1, op2));
16509   ix86_emit_fp_unordered_jump (label);
16510   LABEL_NUSES (label) = 1;
16511
16512   /* Truncate the result properly for strict SSE math.  */
16513   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
16514       && !TARGET_MIX_SSE_I387)
16515     emit_insn (gen_truncxf<mode>2 (operands[0], op1));
16516   else
16517     emit_insn (gen_truncxf<mode>2_i387_noop_unspec (operands[0], op1));
16518
16519   DONE;
16520 })
16521
16522 (define_insn "fprem1xf4_i387"
16523   [(set (match_operand:XF 0 "register_operand" "=f")
16524         (unspec:XF [(match_operand:XF 2 "register_operand" "0")
16525                     (match_operand:XF 3 "register_operand" "1")]
16526                    UNSPEC_FPREM1_F))
16527    (set (match_operand:XF 1 "register_operand" "=u")
16528         (unspec:XF [(match_dup 2) (match_dup 3)]
16529                    UNSPEC_FPREM1_U))
16530    (set (reg:CCFP FPSR_REG)
16531         (unspec:CCFP [(match_dup 2) (match_dup 3)]
16532                      UNSPEC_C2_FLAG))]
16533   "TARGET_USE_FANCY_MATH_387"
16534   "fprem1"
16535   [(set_attr "type" "fpspc")
16536    (set_attr "mode" "XF")])
16537
16538 (define_expand "remainderxf3"
16539   [(use (match_operand:XF 0 "register_operand" ""))
16540    (use (match_operand:XF 1 "general_operand" ""))
16541    (use (match_operand:XF 2 "general_operand" ""))]
16542   "TARGET_USE_FANCY_MATH_387"
16543 {
16544   rtx label = gen_label_rtx ();
16545
16546   rtx op1 = gen_reg_rtx (XFmode);
16547   rtx op2 = gen_reg_rtx (XFmode);
16548
16549   emit_move_insn (op2, operands[2]);
16550   emit_move_insn (op1, operands[1]);
16551
16552   emit_label (label);
16553   emit_insn (gen_fprem1xf4_i387 (op1, op2, op1, op2));
16554   ix86_emit_fp_unordered_jump (label);
16555   LABEL_NUSES (label) = 1;
16556
16557   emit_move_insn (operands[0], op1);
16558   DONE;
16559 })
16560
16561 (define_expand "remainder<mode>3"
16562   [(use (match_operand:MODEF 0 "register_operand" ""))
16563    (use (match_operand:MODEF 1 "general_operand" ""))
16564    (use (match_operand:MODEF 2 "general_operand" ""))]
16565   "TARGET_USE_FANCY_MATH_387"
16566 {
16567   rtx label = gen_label_rtx ();
16568
16569   rtx op1 = gen_reg_rtx (XFmode);
16570   rtx op2 = gen_reg_rtx (XFmode);
16571
16572   emit_insn (gen_extend<mode>xf2 (op2, operands[2]));
16573   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
16574
16575   emit_label (label);
16576
16577   emit_insn (gen_fprem1xf4_i387 (op1, op2, op1, op2));
16578   ix86_emit_fp_unordered_jump (label);
16579   LABEL_NUSES (label) = 1;
16580
16581   /* Truncate the result properly for strict SSE math.  */
16582   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
16583       && !TARGET_MIX_SSE_I387)
16584     emit_insn (gen_truncxf<mode>2 (operands[0], op1));
16585   else
16586     emit_insn (gen_truncxf<mode>2_i387_noop_unspec (operands[0], op1));
16587
16588   DONE;
16589 })
16590
16591 (define_insn "*sinxf2_i387"
16592   [(set (match_operand:XF 0 "register_operand" "=f")
16593         (unspec:XF [(match_operand:XF 1 "register_operand" "0")] UNSPEC_SIN))]
16594   "TARGET_USE_FANCY_MATH_387
16595    && flag_unsafe_math_optimizations"
16596   "fsin"
16597   [(set_attr "type" "fpspc")
16598    (set_attr "mode" "XF")])
16599
16600 (define_insn "*sin_extend<mode>xf2_i387"
16601   [(set (match_operand:XF 0 "register_operand" "=f")
16602         (unspec:XF [(float_extend:XF
16603                       (match_operand:MODEF 1 "register_operand" "0"))]
16604                    UNSPEC_SIN))]
16605   "TARGET_USE_FANCY_MATH_387
16606    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
16607        || TARGET_MIX_SSE_I387)
16608    && flag_unsafe_math_optimizations"
16609   "fsin"
16610   [(set_attr "type" "fpspc")
16611    (set_attr "mode" "XF")])
16612
16613 (define_insn "*cosxf2_i387"
16614   [(set (match_operand:XF 0 "register_operand" "=f")
16615         (unspec:XF [(match_operand:XF 1 "register_operand" "0")] UNSPEC_COS))]
16616   "TARGET_USE_FANCY_MATH_387
16617    && flag_unsafe_math_optimizations"
16618   "fcos"
16619   [(set_attr "type" "fpspc")
16620    (set_attr "mode" "XF")])
16621
16622 (define_insn "*cos_extend<mode>xf2_i387"
16623   [(set (match_operand:XF 0 "register_operand" "=f")
16624         (unspec:XF [(float_extend:XF
16625                       (match_operand:MODEF 1 "register_operand" "0"))]
16626                    UNSPEC_COS))]
16627   "TARGET_USE_FANCY_MATH_387
16628    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
16629        || TARGET_MIX_SSE_I387)
16630    && flag_unsafe_math_optimizations"
16631   "fcos"
16632   [(set_attr "type" "fpspc")
16633    (set_attr "mode" "XF")])
16634
16635 ;; When sincos pattern is defined, sin and cos builtin functions will be
16636 ;; expanded to sincos pattern with one of its outputs left unused.
16637 ;; CSE pass will figure out if two sincos patterns can be combined,
16638 ;; otherwise sincos pattern will be split back to sin or cos pattern,
16639 ;; depending on the unused output.
16640
16641 (define_insn "sincosxf3"
16642   [(set (match_operand:XF 0 "register_operand" "=f")
16643         (unspec:XF [(match_operand:XF 2 "register_operand" "0")]
16644                    UNSPEC_SINCOS_COS))
16645    (set (match_operand:XF 1 "register_operand" "=u")
16646         (unspec:XF [(match_dup 2)] UNSPEC_SINCOS_SIN))]
16647   "TARGET_USE_FANCY_MATH_387
16648    && flag_unsafe_math_optimizations"
16649   "fsincos"
16650   [(set_attr "type" "fpspc")
16651    (set_attr "mode" "XF")])
16652
16653 (define_split
16654   [(set (match_operand:XF 0 "register_operand" "")
16655         (unspec:XF [(match_operand:XF 2 "register_operand" "")]
16656                    UNSPEC_SINCOS_COS))
16657    (set (match_operand:XF 1 "register_operand" "")
16658         (unspec:XF [(match_dup 2)] UNSPEC_SINCOS_SIN))]
16659   "find_regno_note (insn, REG_UNUSED, REGNO (operands[0]))
16660    && !(reload_completed || reload_in_progress)"
16661   [(set (match_dup 1) (unspec:XF [(match_dup 2)] UNSPEC_SIN))]
16662   "")
16663
16664 (define_split
16665   [(set (match_operand:XF 0 "register_operand" "")
16666         (unspec:XF [(match_operand:XF 2 "register_operand" "")]
16667                    UNSPEC_SINCOS_COS))
16668    (set (match_operand:XF 1 "register_operand" "")
16669         (unspec:XF [(match_dup 2)] UNSPEC_SINCOS_SIN))]
16670   "find_regno_note (insn, REG_UNUSED, REGNO (operands[1]))
16671    && !(reload_completed || reload_in_progress)"
16672   [(set (match_dup 0) (unspec:XF [(match_dup 2)] UNSPEC_COS))]
16673   "")
16674
16675 (define_insn "sincos_extend<mode>xf3_i387"
16676   [(set (match_operand:XF 0 "register_operand" "=f")
16677         (unspec:XF [(float_extend:XF
16678                       (match_operand:MODEF 2 "register_operand" "0"))]
16679                    UNSPEC_SINCOS_COS))
16680    (set (match_operand:XF 1 "register_operand" "=u")
16681         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SINCOS_SIN))]
16682   "TARGET_USE_FANCY_MATH_387
16683    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
16684        || TARGET_MIX_SSE_I387)
16685    && flag_unsafe_math_optimizations"
16686   "fsincos"
16687   [(set_attr "type" "fpspc")
16688    (set_attr "mode" "XF")])
16689
16690 (define_split
16691   [(set (match_operand:XF 0 "register_operand" "")
16692         (unspec:XF [(float_extend:XF
16693                       (match_operand:MODEF 2 "register_operand" ""))]
16694                    UNSPEC_SINCOS_COS))
16695    (set (match_operand:XF 1 "register_operand" "")
16696         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SINCOS_SIN))]
16697   "find_regno_note (insn, REG_UNUSED, REGNO (operands[0]))
16698    && !(reload_completed || reload_in_progress)"
16699   [(set (match_dup 1) (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SIN))]
16700   "")
16701
16702 (define_split
16703   [(set (match_operand:XF 0 "register_operand" "")
16704         (unspec:XF [(float_extend:XF
16705                       (match_operand:MODEF 2 "register_operand" ""))]
16706                    UNSPEC_SINCOS_COS))
16707    (set (match_operand:XF 1 "register_operand" "")
16708         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SINCOS_SIN))]
16709   "find_regno_note (insn, REG_UNUSED, REGNO (operands[1]))
16710    && !(reload_completed || reload_in_progress)"
16711   [(set (match_dup 0) (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_COS))]
16712   "")
16713
16714 (define_expand "sincos<mode>3"
16715   [(use (match_operand:MODEF 0 "register_operand" ""))
16716    (use (match_operand:MODEF 1 "register_operand" ""))
16717    (use (match_operand:MODEF 2 "register_operand" ""))]
16718   "TARGET_USE_FANCY_MATH_387
16719    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
16720        || TARGET_MIX_SSE_I387)
16721    && flag_unsafe_math_optimizations"
16722 {
16723   rtx op0 = gen_reg_rtx (XFmode);
16724   rtx op1 = gen_reg_rtx (XFmode);
16725
16726   emit_insn (gen_sincos_extend<mode>xf3_i387 (op0, op1, operands[2]));
16727   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
16728   emit_insn (gen_truncxf<mode>2_i387_noop (operands[1], op1));
16729   DONE;
16730 })
16731
16732 (define_insn "fptanxf4_i387"
16733   [(set (match_operand:XF 0 "register_operand" "=f")
16734         (match_operand:XF 3 "const_double_operand" "F"))
16735    (set (match_operand:XF 1 "register_operand" "=u")
16736         (unspec:XF [(match_operand:XF 2 "register_operand" "0")]
16737                    UNSPEC_TAN))]
16738   "TARGET_USE_FANCY_MATH_387
16739    && flag_unsafe_math_optimizations
16740    && standard_80387_constant_p (operands[3]) == 2"
16741   "fptan"
16742   [(set_attr "type" "fpspc")
16743    (set_attr "mode" "XF")])
16744
16745 (define_insn "fptan_extend<mode>xf4_i387"
16746   [(set (match_operand:MODEF 0 "register_operand" "=f")
16747         (match_operand:MODEF 3 "const_double_operand" "F"))
16748    (set (match_operand:XF 1 "register_operand" "=u")
16749         (unspec:XF [(float_extend:XF
16750                       (match_operand:MODEF 2 "register_operand" "0"))]
16751                    UNSPEC_TAN))]
16752   "TARGET_USE_FANCY_MATH_387
16753    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
16754        || TARGET_MIX_SSE_I387)
16755    && flag_unsafe_math_optimizations
16756    && standard_80387_constant_p (operands[3]) == 2"
16757   "fptan"
16758   [(set_attr "type" "fpspc")
16759    (set_attr "mode" "XF")])
16760
16761 (define_expand "tanxf2"
16762   [(use (match_operand:XF 0 "register_operand" ""))
16763    (use (match_operand:XF 1 "register_operand" ""))]
16764   "TARGET_USE_FANCY_MATH_387
16765    && flag_unsafe_math_optimizations"
16766 {
16767   rtx one = gen_reg_rtx (XFmode);
16768   rtx op2 = CONST1_RTX (XFmode); /* fld1 */
16769
16770   emit_insn (gen_fptanxf4_i387 (one, operands[0], operands[1], op2));
16771   DONE;
16772 })
16773
16774 (define_expand "tan<mode>2"
16775   [(use (match_operand:MODEF 0 "register_operand" ""))
16776    (use (match_operand:MODEF 1 "register_operand" ""))]
16777   "TARGET_USE_FANCY_MATH_387
16778    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
16779        || TARGET_MIX_SSE_I387)
16780    && flag_unsafe_math_optimizations"
16781 {
16782   rtx op0 = gen_reg_rtx (XFmode);
16783
16784   rtx one = gen_reg_rtx (<MODE>mode);
16785   rtx op2 = CONST1_RTX (<MODE>mode); /* fld1 */
16786
16787   emit_insn (gen_fptan_extend<mode>xf4_i387 (one, op0,
16788                                              operands[1], op2));
16789   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
16790   DONE;
16791 })
16792
16793 (define_insn "*fpatanxf3_i387"
16794   [(set (match_operand:XF 0 "register_operand" "=f")
16795         (unspec:XF [(match_operand:XF 1 "register_operand" "0")
16796                     (match_operand:XF 2 "register_operand" "u")]
16797                    UNSPEC_FPATAN))
16798    (clobber (match_scratch:XF 3 "=2"))]
16799   "TARGET_USE_FANCY_MATH_387
16800    && flag_unsafe_math_optimizations"
16801   "fpatan"
16802   [(set_attr "type" "fpspc")
16803    (set_attr "mode" "XF")])
16804
16805 (define_insn "fpatan_extend<mode>xf3_i387"
16806   [(set (match_operand:XF 0 "register_operand" "=f")
16807         (unspec:XF [(float_extend:XF
16808                       (match_operand:MODEF 1 "register_operand" "0"))
16809                     (float_extend:XF
16810                       (match_operand:MODEF 2 "register_operand" "u"))]
16811                    UNSPEC_FPATAN))
16812    (clobber (match_scratch:XF 3 "=2"))]
16813   "TARGET_USE_FANCY_MATH_387
16814    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
16815        || TARGET_MIX_SSE_I387)
16816    && flag_unsafe_math_optimizations"
16817   "fpatan"
16818   [(set_attr "type" "fpspc")
16819    (set_attr "mode" "XF")])
16820
16821 (define_expand "atan2xf3"
16822   [(parallel [(set (match_operand:XF 0 "register_operand" "")
16823                    (unspec:XF [(match_operand:XF 2 "register_operand" "")
16824                                (match_operand:XF 1 "register_operand" "")]
16825                               UNSPEC_FPATAN))
16826               (clobber (match_scratch:XF 3 ""))])]
16827   "TARGET_USE_FANCY_MATH_387
16828    && flag_unsafe_math_optimizations"
16829   "")
16830
16831 (define_expand "atan2<mode>3"
16832   [(use (match_operand:MODEF 0 "register_operand" ""))
16833    (use (match_operand:MODEF 1 "register_operand" ""))
16834    (use (match_operand:MODEF 2 "register_operand" ""))]
16835   "TARGET_USE_FANCY_MATH_387
16836    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
16837        || TARGET_MIX_SSE_I387)
16838    && flag_unsafe_math_optimizations"
16839 {
16840   rtx op0 = gen_reg_rtx (XFmode);
16841
16842   emit_insn (gen_fpatan_extend<mode>xf3_i387 (op0, operands[2], operands[1]));
16843   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
16844   DONE;
16845 })
16846
16847 (define_expand "atanxf2"
16848   [(parallel [(set (match_operand:XF 0 "register_operand" "")
16849                    (unspec:XF [(match_dup 2)
16850                                (match_operand:XF 1 "register_operand" "")]
16851                               UNSPEC_FPATAN))
16852               (clobber (match_scratch:XF 3 ""))])]
16853   "TARGET_USE_FANCY_MATH_387
16854    && flag_unsafe_math_optimizations"
16855 {
16856   operands[2] = gen_reg_rtx (XFmode);
16857   emit_move_insn (operands[2], CONST1_RTX (XFmode));  /* fld1 */
16858 })
16859
16860 (define_expand "atan<mode>2"
16861   [(use (match_operand:MODEF 0 "register_operand" ""))
16862    (use (match_operand:MODEF 1 "register_operand" ""))]
16863   "TARGET_USE_FANCY_MATH_387
16864    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
16865        || TARGET_MIX_SSE_I387)
16866    && flag_unsafe_math_optimizations"
16867 {
16868   rtx op0 = gen_reg_rtx (XFmode);
16869
16870   rtx op2 = gen_reg_rtx (<MODE>mode);
16871   emit_move_insn (op2, CONST1_RTX (<MODE>mode));  /* fld1 */
16872
16873   emit_insn (gen_fpatan_extend<mode>xf3_i387 (op0, op2, operands[1]));
16874   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
16875   DONE;
16876 })
16877
16878 (define_expand "asinxf2"
16879   [(set (match_dup 2)
16880         (mult:XF (match_operand:XF 1 "register_operand" "")
16881                  (match_dup 1)))
16882    (set (match_dup 4) (minus:XF (match_dup 3) (match_dup 2)))
16883    (set (match_dup 5) (sqrt:XF (match_dup 4)))
16884    (parallel [(set (match_operand:XF 0 "register_operand" "")
16885                    (unspec:XF [(match_dup 5) (match_dup 1)]
16886                               UNSPEC_FPATAN))
16887               (clobber (match_scratch:XF 6 ""))])]
16888   "TARGET_USE_FANCY_MATH_387
16889    && flag_unsafe_math_optimizations"
16890 {
16891   int i;
16892
16893   if (optimize_insn_for_size_p ())
16894     FAIL;
16895
16896   for (i = 2; i < 6; i++)
16897     operands[i] = gen_reg_rtx (XFmode);
16898
16899   emit_move_insn (operands[3], CONST1_RTX (XFmode));  /* fld1 */
16900 })
16901
16902 (define_expand "asin<mode>2"
16903   [(use (match_operand:MODEF 0 "register_operand" ""))
16904    (use (match_operand:MODEF 1 "general_operand" ""))]
16905  "TARGET_USE_FANCY_MATH_387
16906    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
16907        || TARGET_MIX_SSE_I387)
16908    && flag_unsafe_math_optimizations"
16909 {
16910   rtx op0 = gen_reg_rtx (XFmode);
16911   rtx op1 = gen_reg_rtx (XFmode);
16912
16913   if (optimize_insn_for_size_p ())
16914     FAIL;
16915
16916   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
16917   emit_insn (gen_asinxf2 (op0, op1));
16918   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
16919   DONE;
16920 })
16921
16922 (define_expand "acosxf2"
16923   [(set (match_dup 2)
16924         (mult:XF (match_operand:XF 1 "register_operand" "")
16925                  (match_dup 1)))
16926    (set (match_dup 4) (minus:XF (match_dup 3) (match_dup 2)))
16927    (set (match_dup 5) (sqrt:XF (match_dup 4)))
16928    (parallel [(set (match_operand:XF 0 "register_operand" "")
16929                    (unspec:XF [(match_dup 1) (match_dup 5)]
16930                               UNSPEC_FPATAN))
16931               (clobber (match_scratch:XF 6 ""))])]
16932   "TARGET_USE_FANCY_MATH_387
16933    && flag_unsafe_math_optimizations"
16934 {
16935   int i;
16936
16937   if (optimize_insn_for_size_p ())
16938     FAIL;
16939
16940   for (i = 2; i < 6; i++)
16941     operands[i] = gen_reg_rtx (XFmode);
16942
16943   emit_move_insn (operands[3], CONST1_RTX (XFmode));  /* fld1 */
16944 })
16945
16946 (define_expand "acos<mode>2"
16947   [(use (match_operand:MODEF 0 "register_operand" ""))
16948    (use (match_operand:MODEF 1 "general_operand" ""))]
16949  "TARGET_USE_FANCY_MATH_387
16950    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
16951        || TARGET_MIX_SSE_I387)
16952    && flag_unsafe_math_optimizations"
16953 {
16954   rtx op0 = gen_reg_rtx (XFmode);
16955   rtx op1 = gen_reg_rtx (XFmode);
16956
16957   if (optimize_insn_for_size_p ())
16958     FAIL;
16959
16960   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
16961   emit_insn (gen_acosxf2 (op0, op1));
16962   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
16963   DONE;
16964 })
16965
16966 (define_insn "fyl2xxf3_i387"
16967   [(set (match_operand:XF 0 "register_operand" "=f")
16968         (unspec:XF [(match_operand:XF 1 "register_operand" "0")
16969                     (match_operand:XF 2 "register_operand" "u")]
16970                    UNSPEC_FYL2X))
16971    (clobber (match_scratch:XF 3 "=2"))]
16972   "TARGET_USE_FANCY_MATH_387
16973    && flag_unsafe_math_optimizations"
16974   "fyl2x"
16975   [(set_attr "type" "fpspc")
16976    (set_attr "mode" "XF")])
16977
16978 (define_insn "fyl2x_extend<mode>xf3_i387"
16979   [(set (match_operand:XF 0 "register_operand" "=f")
16980         (unspec:XF [(float_extend:XF
16981                       (match_operand:MODEF 1 "register_operand" "0"))
16982                     (match_operand:XF 2 "register_operand" "u")]
16983                    UNSPEC_FYL2X))
16984    (clobber (match_scratch:XF 3 "=2"))]
16985   "TARGET_USE_FANCY_MATH_387
16986    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
16987        || TARGET_MIX_SSE_I387)
16988    && flag_unsafe_math_optimizations"
16989   "fyl2x"
16990   [(set_attr "type" "fpspc")
16991    (set_attr "mode" "XF")])
16992
16993 (define_expand "logxf2"
16994   [(parallel [(set (match_operand:XF 0 "register_operand" "")
16995                    (unspec:XF [(match_operand:XF 1 "register_operand" "")
16996                                (match_dup 2)] UNSPEC_FYL2X))
16997               (clobber (match_scratch:XF 3 ""))])]
16998   "TARGET_USE_FANCY_MATH_387
16999    && flag_unsafe_math_optimizations"
17000 {
17001   operands[2] = gen_reg_rtx (XFmode);
17002   emit_move_insn (operands[2], standard_80387_constant_rtx (4)); /* fldln2 */
17003 })
17004
17005 (define_expand "log<mode>2"
17006   [(use (match_operand:MODEF 0 "register_operand" ""))
17007    (use (match_operand:MODEF 1 "register_operand" ""))]
17008   "TARGET_USE_FANCY_MATH_387
17009    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17010        || TARGET_MIX_SSE_I387)
17011    && flag_unsafe_math_optimizations"
17012 {
17013   rtx op0 = gen_reg_rtx (XFmode);
17014
17015   rtx op2 = gen_reg_rtx (XFmode);
17016   emit_move_insn (op2, standard_80387_constant_rtx (4)); /* fldln2 */
17017
17018   emit_insn (gen_fyl2x_extend<mode>xf3_i387 (op0, operands[1], op2));
17019   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
17020   DONE;
17021 })
17022
17023 (define_expand "log10xf2"
17024   [(parallel [(set (match_operand:XF 0 "register_operand" "")
17025                    (unspec:XF [(match_operand:XF 1 "register_operand" "")
17026                                (match_dup 2)] UNSPEC_FYL2X))
17027               (clobber (match_scratch:XF 3 ""))])]
17028   "TARGET_USE_FANCY_MATH_387
17029    && flag_unsafe_math_optimizations"
17030 {
17031   operands[2] = gen_reg_rtx (XFmode);
17032   emit_move_insn (operands[2], standard_80387_constant_rtx (3)); /* fldlg2 */
17033 })
17034
17035 (define_expand "log10<mode>2"
17036   [(use (match_operand:MODEF 0 "register_operand" ""))
17037    (use (match_operand:MODEF 1 "register_operand" ""))]
17038   "TARGET_USE_FANCY_MATH_387
17039    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17040        || TARGET_MIX_SSE_I387)
17041    && flag_unsafe_math_optimizations"
17042 {
17043   rtx op0 = gen_reg_rtx (XFmode);
17044
17045   rtx op2 = gen_reg_rtx (XFmode);
17046   emit_move_insn (op2, standard_80387_constant_rtx (3)); /* fldlg2 */
17047
17048   emit_insn (gen_fyl2x_extend<mode>xf3_i387 (op0, operands[1], op2));
17049   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
17050   DONE;
17051 })
17052
17053 (define_expand "log2xf2"
17054   [(parallel [(set (match_operand:XF 0 "register_operand" "")
17055                    (unspec:XF [(match_operand:XF 1 "register_operand" "")
17056                                (match_dup 2)] UNSPEC_FYL2X))
17057               (clobber (match_scratch:XF 3 ""))])]
17058   "TARGET_USE_FANCY_MATH_387
17059    && flag_unsafe_math_optimizations"
17060 {
17061   operands[2] = gen_reg_rtx (XFmode);
17062   emit_move_insn (operands[2], CONST1_RTX (XFmode)); /* fld1 */
17063 })
17064
17065 (define_expand "log2<mode>2"
17066   [(use (match_operand:MODEF 0 "register_operand" ""))
17067    (use (match_operand:MODEF 1 "register_operand" ""))]
17068   "TARGET_USE_FANCY_MATH_387
17069    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17070        || TARGET_MIX_SSE_I387)
17071    && flag_unsafe_math_optimizations"
17072 {
17073   rtx op0 = gen_reg_rtx (XFmode);
17074
17075   rtx op2 = gen_reg_rtx (XFmode);
17076   emit_move_insn (op2, CONST1_RTX (XFmode)); /* fld1 */
17077
17078   emit_insn (gen_fyl2x_extend<mode>xf3_i387 (op0, operands[1], op2));
17079   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
17080   DONE;
17081 })
17082
17083 (define_insn "fyl2xp1xf3_i387"
17084   [(set (match_operand:XF 0 "register_operand" "=f")
17085         (unspec:XF [(match_operand:XF 1 "register_operand" "0")
17086                     (match_operand:XF 2 "register_operand" "u")]
17087                    UNSPEC_FYL2XP1))
17088    (clobber (match_scratch:XF 3 "=2"))]
17089   "TARGET_USE_FANCY_MATH_387
17090    && flag_unsafe_math_optimizations"
17091   "fyl2xp1"
17092   [(set_attr "type" "fpspc")
17093    (set_attr "mode" "XF")])
17094
17095 (define_insn "fyl2xp1_extend<mode>xf3_i387"
17096   [(set (match_operand:XF 0 "register_operand" "=f")
17097         (unspec:XF [(float_extend:XF
17098                       (match_operand:MODEF 1 "register_operand" "0"))
17099                     (match_operand:XF 2 "register_operand" "u")]
17100                    UNSPEC_FYL2XP1))
17101    (clobber (match_scratch:XF 3 "=2"))]
17102   "TARGET_USE_FANCY_MATH_387
17103    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17104        || TARGET_MIX_SSE_I387)
17105    && flag_unsafe_math_optimizations"
17106   "fyl2xp1"
17107   [(set_attr "type" "fpspc")
17108    (set_attr "mode" "XF")])
17109
17110 (define_expand "log1pxf2"
17111   [(use (match_operand:XF 0 "register_operand" ""))
17112    (use (match_operand:XF 1 "register_operand" ""))]
17113   "TARGET_USE_FANCY_MATH_387
17114    && flag_unsafe_math_optimizations"
17115 {
17116   if (optimize_insn_for_size_p ())
17117     FAIL;
17118
17119   ix86_emit_i387_log1p (operands[0], operands[1]);
17120   DONE;
17121 })
17122
17123 (define_expand "log1p<mode>2"
17124   [(use (match_operand:MODEF 0 "register_operand" ""))
17125    (use (match_operand:MODEF 1 "register_operand" ""))]
17126   "TARGET_USE_FANCY_MATH_387
17127    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17128        || TARGET_MIX_SSE_I387)
17129    && flag_unsafe_math_optimizations"
17130 {
17131   rtx op0;
17132
17133   if (optimize_insn_for_size_p ())
17134     FAIL;
17135
17136   op0 = gen_reg_rtx (XFmode);
17137
17138   operands[1] = gen_rtx_FLOAT_EXTEND (XFmode, operands[1]);
17139
17140   ix86_emit_i387_log1p (op0, operands[1]);
17141   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
17142   DONE;
17143 })
17144
17145 (define_insn "fxtractxf3_i387"
17146   [(set (match_operand:XF 0 "register_operand" "=f")
17147         (unspec:XF [(match_operand:XF 2 "register_operand" "0")]
17148                    UNSPEC_XTRACT_FRACT))
17149    (set (match_operand:XF 1 "register_operand" "=u")
17150         (unspec:XF [(match_dup 2)] UNSPEC_XTRACT_EXP))]
17151   "TARGET_USE_FANCY_MATH_387
17152    && flag_unsafe_math_optimizations"
17153   "fxtract"
17154   [(set_attr "type" "fpspc")
17155    (set_attr "mode" "XF")])
17156
17157 (define_insn "fxtract_extend<mode>xf3_i387"
17158   [(set (match_operand:XF 0 "register_operand" "=f")
17159         (unspec:XF [(float_extend:XF
17160                       (match_operand:MODEF 2 "register_operand" "0"))]
17161                    UNSPEC_XTRACT_FRACT))
17162    (set (match_operand:XF 1 "register_operand" "=u")
17163         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_XTRACT_EXP))]
17164   "TARGET_USE_FANCY_MATH_387
17165    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17166        || TARGET_MIX_SSE_I387)
17167    && flag_unsafe_math_optimizations"
17168   "fxtract"
17169   [(set_attr "type" "fpspc")
17170    (set_attr "mode" "XF")])
17171
17172 (define_expand "logbxf2"
17173   [(parallel [(set (match_dup 2)
17174                    (unspec:XF [(match_operand:XF 1 "register_operand" "")]
17175                               UNSPEC_XTRACT_FRACT))
17176               (set (match_operand:XF 0 "register_operand" "")
17177                    (unspec:XF [(match_dup 1)] UNSPEC_XTRACT_EXP))])]
17178   "TARGET_USE_FANCY_MATH_387
17179    && flag_unsafe_math_optimizations"
17180 {
17181   operands[2] = gen_reg_rtx (XFmode);
17182 })
17183
17184 (define_expand "logb<mode>2"
17185   [(use (match_operand:MODEF 0 "register_operand" ""))
17186    (use (match_operand:MODEF 1 "register_operand" ""))]
17187   "TARGET_USE_FANCY_MATH_387
17188    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17189        || TARGET_MIX_SSE_I387)
17190    && flag_unsafe_math_optimizations"
17191 {
17192   rtx op0 = gen_reg_rtx (XFmode);
17193   rtx op1 = gen_reg_rtx (XFmode);
17194
17195   emit_insn (gen_fxtract_extend<mode>xf3_i387 (op0, op1, operands[1]));
17196   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op1));
17197   DONE;
17198 })
17199
17200 (define_expand "ilogbxf2"
17201   [(use (match_operand:SI 0 "register_operand" ""))
17202    (use (match_operand:XF 1 "register_operand" ""))]
17203   "TARGET_USE_FANCY_MATH_387
17204    && flag_unsafe_math_optimizations"
17205 {
17206   rtx op0, op1;
17207
17208   if (optimize_insn_for_size_p ())
17209     FAIL;
17210
17211   op0 = gen_reg_rtx (XFmode);
17212   op1 = gen_reg_rtx (XFmode);
17213
17214   emit_insn (gen_fxtractxf3_i387 (op0, op1, operands[1]));
17215   emit_insn (gen_fix_truncxfsi2 (operands[0], op1));
17216   DONE;
17217 })
17218
17219 (define_expand "ilogb<mode>2"
17220   [(use (match_operand:SI 0 "register_operand" ""))
17221    (use (match_operand:MODEF 1 "register_operand" ""))]
17222   "TARGET_USE_FANCY_MATH_387
17223    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17224        || TARGET_MIX_SSE_I387)
17225    && flag_unsafe_math_optimizations"
17226 {
17227   rtx op0, op1;
17228
17229   if (optimize_insn_for_size_p ())
17230     FAIL;
17231
17232   op0 = gen_reg_rtx (XFmode);
17233   op1 = gen_reg_rtx (XFmode);
17234
17235   emit_insn (gen_fxtract_extend<mode>xf3_i387 (op0, op1, operands[1]));
17236   emit_insn (gen_fix_truncxfsi2 (operands[0], op1));
17237   DONE;
17238 })
17239
17240 (define_insn "*f2xm1xf2_i387"
17241   [(set (match_operand:XF 0 "register_operand" "=f")
17242         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
17243                    UNSPEC_F2XM1))]
17244   "TARGET_USE_FANCY_MATH_387
17245    && flag_unsafe_math_optimizations"
17246   "f2xm1"
17247   [(set_attr "type" "fpspc")
17248    (set_attr "mode" "XF")])
17249
17250 (define_insn "*fscalexf4_i387"
17251   [(set (match_operand:XF 0 "register_operand" "=f")
17252         (unspec:XF [(match_operand:XF 2 "register_operand" "0")
17253                     (match_operand:XF 3 "register_operand" "1")]
17254                    UNSPEC_FSCALE_FRACT))
17255    (set (match_operand:XF 1 "register_operand" "=u")
17256         (unspec:XF [(match_dup 2) (match_dup 3)]
17257                    UNSPEC_FSCALE_EXP))]
17258   "TARGET_USE_FANCY_MATH_387
17259    && flag_unsafe_math_optimizations"
17260   "fscale"
17261   [(set_attr "type" "fpspc")
17262    (set_attr "mode" "XF")])
17263
17264 (define_expand "expNcorexf3"
17265   [(set (match_dup 3) (mult:XF (match_operand:XF 1 "register_operand" "")
17266                                (match_operand:XF 2 "register_operand" "")))
17267    (set (match_dup 4) (unspec:XF [(match_dup 3)] UNSPEC_FRNDINT))
17268    (set (match_dup 5) (minus:XF (match_dup 3) (match_dup 4)))
17269    (set (match_dup 6) (unspec:XF [(match_dup 5)] UNSPEC_F2XM1))
17270    (set (match_dup 8) (plus:XF (match_dup 6) (match_dup 7)))
17271    (parallel [(set (match_operand:XF 0 "register_operand" "")
17272                    (unspec:XF [(match_dup 8) (match_dup 4)]
17273                               UNSPEC_FSCALE_FRACT))
17274               (set (match_dup 9)
17275                    (unspec:XF [(match_dup 8) (match_dup 4)]
17276                               UNSPEC_FSCALE_EXP))])]
17277   "TARGET_USE_FANCY_MATH_387
17278    && flag_unsafe_math_optimizations"
17279 {
17280   int i;
17281
17282   if (optimize_insn_for_size_p ())
17283     FAIL;
17284
17285   for (i = 3; i < 10; i++)
17286     operands[i] = gen_reg_rtx (XFmode);
17287
17288   emit_move_insn (operands[7], CONST1_RTX (XFmode));  /* fld1 */
17289 })
17290
17291 (define_expand "expxf2"
17292   [(use (match_operand:XF 0 "register_operand" ""))
17293    (use (match_operand:XF 1 "register_operand" ""))]
17294   "TARGET_USE_FANCY_MATH_387
17295    && flag_unsafe_math_optimizations"
17296 {
17297   rtx op2;
17298
17299   if (optimize_insn_for_size_p ())
17300     FAIL;
17301
17302   op2 = gen_reg_rtx (XFmode);
17303   emit_move_insn (op2, standard_80387_constant_rtx (5)); /* fldl2e */
17304
17305   emit_insn (gen_expNcorexf3 (operands[0], operands[1], op2));
17306   DONE;
17307 })
17308
17309 (define_expand "exp<mode>2"
17310   [(use (match_operand:MODEF 0 "register_operand" ""))
17311    (use (match_operand:MODEF 1 "general_operand" ""))]
17312  "TARGET_USE_FANCY_MATH_387
17313    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17314        || TARGET_MIX_SSE_I387)
17315    && flag_unsafe_math_optimizations"
17316 {
17317   rtx op0, op1;
17318
17319   if (optimize_insn_for_size_p ())
17320     FAIL;
17321
17322   op0 = gen_reg_rtx (XFmode);
17323   op1 = gen_reg_rtx (XFmode);
17324
17325   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
17326   emit_insn (gen_expxf2 (op0, op1));
17327   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
17328   DONE;
17329 })
17330
17331 (define_expand "exp10xf2"
17332   [(use (match_operand:XF 0 "register_operand" ""))
17333    (use (match_operand:XF 1 "register_operand" ""))]
17334   "TARGET_USE_FANCY_MATH_387
17335    && flag_unsafe_math_optimizations"
17336 {
17337   rtx op2;
17338
17339   if (optimize_insn_for_size_p ())
17340     FAIL;
17341
17342   op2 = gen_reg_rtx (XFmode);
17343   emit_move_insn (op2, standard_80387_constant_rtx (6)); /* fldl2t */
17344
17345   emit_insn (gen_expNcorexf3 (operands[0], operands[1], op2));
17346   DONE;
17347 })
17348
17349 (define_expand "exp10<mode>2"
17350   [(use (match_operand:MODEF 0 "register_operand" ""))
17351    (use (match_operand:MODEF 1 "general_operand" ""))]
17352  "TARGET_USE_FANCY_MATH_387
17353    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17354        || TARGET_MIX_SSE_I387)
17355    && flag_unsafe_math_optimizations"
17356 {
17357   rtx op0, op1;
17358
17359   if (optimize_insn_for_size_p ())
17360     FAIL;
17361
17362   op0 = gen_reg_rtx (XFmode);
17363   op1 = gen_reg_rtx (XFmode);
17364
17365   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
17366   emit_insn (gen_exp10xf2 (op0, op1));
17367   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
17368   DONE;
17369 })
17370
17371 (define_expand "exp2xf2"
17372   [(use (match_operand:XF 0 "register_operand" ""))
17373    (use (match_operand:XF 1 "register_operand" ""))]
17374   "TARGET_USE_FANCY_MATH_387
17375    && flag_unsafe_math_optimizations"
17376 {
17377   rtx op2;
17378
17379   if (optimize_insn_for_size_p ())
17380     FAIL;
17381
17382   op2 = gen_reg_rtx (XFmode);
17383   emit_move_insn (op2, CONST1_RTX (XFmode));  /* fld1 */
17384
17385   emit_insn (gen_expNcorexf3 (operands[0], operands[1], op2));
17386   DONE;
17387 })
17388
17389 (define_expand "exp2<mode>2"
17390   [(use (match_operand:MODEF 0 "register_operand" ""))
17391    (use (match_operand:MODEF 1 "general_operand" ""))]
17392  "TARGET_USE_FANCY_MATH_387
17393    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17394        || TARGET_MIX_SSE_I387)
17395    && flag_unsafe_math_optimizations"
17396 {
17397   rtx op0, op1;
17398
17399   if (optimize_insn_for_size_p ())
17400     FAIL;
17401
17402   op0 = gen_reg_rtx (XFmode);
17403   op1 = gen_reg_rtx (XFmode);
17404
17405   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
17406   emit_insn (gen_exp2xf2 (op0, op1));
17407   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
17408   DONE;
17409 })
17410
17411 (define_expand "expm1xf2"
17412   [(set (match_dup 3) (mult:XF (match_operand:XF 1 "register_operand" "")
17413                                (match_dup 2)))
17414    (set (match_dup 4) (unspec:XF [(match_dup 3)] UNSPEC_FRNDINT))
17415    (set (match_dup 5) (minus:XF (match_dup 3) (match_dup 4)))
17416    (set (match_dup 9) (float_extend:XF (match_dup 13)))
17417    (set (match_dup 6) (unspec:XF [(match_dup 5)] UNSPEC_F2XM1))
17418    (parallel [(set (match_dup 7)
17419                    (unspec:XF [(match_dup 6) (match_dup 4)]
17420                               UNSPEC_FSCALE_FRACT))
17421               (set (match_dup 8)
17422                    (unspec:XF [(match_dup 6) (match_dup 4)]
17423                               UNSPEC_FSCALE_EXP))])
17424    (parallel [(set (match_dup 10)
17425                    (unspec:XF [(match_dup 9) (match_dup 8)]
17426                               UNSPEC_FSCALE_FRACT))
17427               (set (match_dup 11)
17428                    (unspec:XF [(match_dup 9) (match_dup 8)]
17429                               UNSPEC_FSCALE_EXP))])
17430    (set (match_dup 12) (minus:XF (match_dup 10)
17431                                  (float_extend:XF (match_dup 13))))
17432    (set (match_operand:XF 0 "register_operand" "")
17433         (plus:XF (match_dup 12) (match_dup 7)))]
17434   "TARGET_USE_FANCY_MATH_387
17435    && flag_unsafe_math_optimizations"
17436 {
17437   int i;
17438
17439   if (optimize_insn_for_size_p ())
17440     FAIL;
17441
17442   for (i = 2; i < 13; i++)
17443     operands[i] = gen_reg_rtx (XFmode);
17444
17445   operands[13]
17446     = validize_mem (force_const_mem (SFmode, CONST1_RTX (SFmode))); /* fld1 */
17447
17448   emit_move_insn (operands[2], standard_80387_constant_rtx (5)); /* fldl2e */
17449 })
17450
17451 (define_expand "expm1<mode>2"
17452   [(use (match_operand:MODEF 0 "register_operand" ""))
17453    (use (match_operand:MODEF 1 "general_operand" ""))]
17454  "TARGET_USE_FANCY_MATH_387
17455    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17456        || TARGET_MIX_SSE_I387)
17457    && flag_unsafe_math_optimizations"
17458 {
17459   rtx op0, op1;
17460
17461   if (optimize_insn_for_size_p ())
17462     FAIL;
17463
17464   op0 = gen_reg_rtx (XFmode);
17465   op1 = gen_reg_rtx (XFmode);
17466
17467   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
17468   emit_insn (gen_expm1xf2 (op0, op1));
17469   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
17470   DONE;
17471 })
17472
17473 (define_expand "ldexpxf3"
17474   [(set (match_dup 3)
17475         (float:XF (match_operand:SI 2 "register_operand" "")))
17476    (parallel [(set (match_operand:XF 0 " register_operand" "")
17477                    (unspec:XF [(match_operand:XF 1 "register_operand" "")
17478                                (match_dup 3)]
17479                               UNSPEC_FSCALE_FRACT))
17480               (set (match_dup 4)
17481                    (unspec:XF [(match_dup 1) (match_dup 3)]
17482                               UNSPEC_FSCALE_EXP))])]
17483   "TARGET_USE_FANCY_MATH_387
17484    && flag_unsafe_math_optimizations"
17485 {
17486   if (optimize_insn_for_size_p ())
17487     FAIL;
17488
17489   operands[3] = gen_reg_rtx (XFmode);
17490   operands[4] = gen_reg_rtx (XFmode);
17491 })
17492
17493 (define_expand "ldexp<mode>3"
17494   [(use (match_operand:MODEF 0 "register_operand" ""))
17495    (use (match_operand:MODEF 1 "general_operand" ""))
17496    (use (match_operand:SI 2 "register_operand" ""))]
17497  "TARGET_USE_FANCY_MATH_387
17498    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17499        || TARGET_MIX_SSE_I387)
17500    && flag_unsafe_math_optimizations"
17501 {
17502   rtx op0, op1;
17503
17504   if (optimize_insn_for_size_p ())
17505     FAIL;
17506
17507   op0 = gen_reg_rtx (XFmode);
17508   op1 = gen_reg_rtx (XFmode);
17509
17510   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
17511   emit_insn (gen_ldexpxf3 (op0, op1, operands[2]));
17512   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
17513   DONE;
17514 })
17515
17516 (define_expand "scalbxf3"
17517   [(parallel [(set (match_operand:XF 0 " register_operand" "")
17518                    (unspec:XF [(match_operand:XF 1 "register_operand" "")
17519                                (match_operand:XF 2 "register_operand" "")]
17520                               UNSPEC_FSCALE_FRACT))
17521               (set (match_dup 3)
17522                    (unspec:XF [(match_dup 1) (match_dup 2)]
17523                               UNSPEC_FSCALE_EXP))])]
17524   "TARGET_USE_FANCY_MATH_387
17525    && flag_unsafe_math_optimizations"
17526 {
17527   if (optimize_insn_for_size_p ())
17528     FAIL;
17529
17530   operands[3] = gen_reg_rtx (XFmode);
17531 })
17532
17533 (define_expand "scalb<mode>3"
17534   [(use (match_operand:MODEF 0 "register_operand" ""))
17535    (use (match_operand:MODEF 1 "general_operand" ""))
17536    (use (match_operand:MODEF 2 "general_operand" ""))]
17537  "TARGET_USE_FANCY_MATH_387
17538    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17539        || TARGET_MIX_SSE_I387)
17540    && flag_unsafe_math_optimizations"
17541 {
17542   rtx op0, op1, op2;
17543
17544   if (optimize_insn_for_size_p ())
17545     FAIL;
17546
17547   op0 = gen_reg_rtx (XFmode);
17548   op1 = gen_reg_rtx (XFmode);
17549   op2 = gen_reg_rtx (XFmode);
17550
17551   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
17552   emit_insn (gen_extend<mode>xf2 (op2, operands[2]));
17553   emit_insn (gen_scalbxf3 (op0, op1, op2));
17554   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
17555   DONE;
17556 })
17557
17558 (define_expand "significandxf2"
17559   [(parallel [(set (match_operand:XF 0 "register_operand" "")
17560                    (unspec:XF [(match_operand:XF 1 "register_operand" "")]
17561                               UNSPEC_XTRACT_FRACT))
17562               (set (match_dup 2)
17563                    (unspec:XF [(match_dup 1)] UNSPEC_XTRACT_EXP))])]
17564   "TARGET_USE_FANCY_MATH_387
17565    && flag_unsafe_math_optimizations"
17566 {
17567   operands[2] = gen_reg_rtx (XFmode);
17568 })
17569
17570 (define_expand "significand<mode>2"
17571   [(use (match_operand:MODEF 0 "register_operand" ""))
17572    (use (match_operand:MODEF 1 "register_operand" ""))]
17573   "TARGET_USE_FANCY_MATH_387
17574    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17575        || TARGET_MIX_SSE_I387)
17576    && flag_unsafe_math_optimizations"
17577 {
17578   rtx op0 = gen_reg_rtx (XFmode);
17579   rtx op1 = gen_reg_rtx (XFmode);
17580
17581   emit_insn (gen_fxtract_extend<mode>xf3_i387 (op0, op1, operands[1]));
17582   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
17583   DONE;
17584 })
17585 \f
17586
17587 (define_insn "sse4_1_round<mode>2"
17588   [(set (match_operand:MODEF 0 "register_operand" "=x")
17589         (unspec:MODEF [(match_operand:MODEF 1 "register_operand" "x")
17590                        (match_operand:SI 2 "const_0_to_15_operand" "n")]
17591                       UNSPEC_ROUND))]
17592   "TARGET_ROUND"
17593   "%vrounds<ssemodefsuffix>\t{%2, %1, %d0|%d0, %1, %2}"
17594   [(set_attr "type" "ssecvt")
17595    (set_attr "prefix_extra" "1")
17596    (set_attr "prefix" "maybe_vex")
17597    (set_attr "mode" "<MODE>")])
17598
17599 (define_insn "rintxf2"
17600   [(set (match_operand:XF 0 "register_operand" "=f")
17601         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
17602                    UNSPEC_FRNDINT))]
17603   "TARGET_USE_FANCY_MATH_387
17604    && flag_unsafe_math_optimizations"
17605   "frndint"
17606   [(set_attr "type" "fpspc")
17607    (set_attr "mode" "XF")])
17608
17609 (define_expand "rint<mode>2"
17610   [(use (match_operand:MODEF 0 "register_operand" ""))
17611    (use (match_operand:MODEF 1 "register_operand" ""))]
17612   "(TARGET_USE_FANCY_MATH_387
17613     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17614         || TARGET_MIX_SSE_I387)
17615     && flag_unsafe_math_optimizations)
17616    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
17617        && !flag_trapping_math)"
17618 {
17619   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
17620       && !flag_trapping_math)
17621     {
17622       if (!TARGET_ROUND && optimize_insn_for_size_p ())
17623         FAIL;
17624       if (TARGET_ROUND)
17625         emit_insn (gen_sse4_1_round<mode>2
17626                    (operands[0], operands[1], GEN_INT (0x04)));
17627       else
17628         ix86_expand_rint (operand0, operand1);
17629     }
17630   else
17631     {
17632       rtx op0 = gen_reg_rtx (XFmode);
17633       rtx op1 = gen_reg_rtx (XFmode);
17634
17635       emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
17636       emit_insn (gen_rintxf2 (op0, op1));
17637
17638       emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
17639     }
17640   DONE;
17641 })
17642
17643 (define_expand "round<mode>2"
17644   [(match_operand:MODEF 0 "register_operand" "")
17645    (match_operand:MODEF 1 "nonimmediate_operand" "")]
17646   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
17647    && !flag_trapping_math && !flag_rounding_math"
17648 {
17649   if (optimize_insn_for_size_p ())
17650     FAIL;
17651   if (TARGET_64BIT || (<MODE>mode != DFmode))
17652     ix86_expand_round (operand0, operand1);
17653   else
17654     ix86_expand_rounddf_32 (operand0, operand1);
17655   DONE;
17656 })
17657
17658 (define_insn_and_split "*fistdi2_1"
17659   [(set (match_operand:DI 0 "nonimmediate_operand" "")
17660         (unspec:DI [(match_operand:XF 1 "register_operand" "")]
17661                    UNSPEC_FIST))]
17662   "TARGET_USE_FANCY_MATH_387
17663    && can_create_pseudo_p ()"
17664   "#"
17665   "&& 1"
17666   [(const_int 0)]
17667 {
17668   if (memory_operand (operands[0], VOIDmode))
17669     emit_insn (gen_fistdi2 (operands[0], operands[1]));
17670   else
17671     {
17672       operands[2] = assign_386_stack_local (DImode, SLOT_TEMP);
17673       emit_insn (gen_fistdi2_with_temp (operands[0], operands[1],
17674                                          operands[2]));
17675     }
17676   DONE;
17677 }
17678   [(set_attr "type" "fpspc")
17679    (set_attr "mode" "DI")])
17680
17681 (define_insn "fistdi2"
17682   [(set (match_operand:DI 0 "memory_operand" "=m")
17683         (unspec:DI [(match_operand:XF 1 "register_operand" "f")]
17684                    UNSPEC_FIST))
17685    (clobber (match_scratch:XF 2 "=&1f"))]
17686   "TARGET_USE_FANCY_MATH_387"
17687   "* return output_fix_trunc (insn, operands, 0);"
17688   [(set_attr "type" "fpspc")
17689    (set_attr "mode" "DI")])
17690
17691 (define_insn "fistdi2_with_temp"
17692   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
17693         (unspec:DI [(match_operand:XF 1 "register_operand" "f,f")]
17694                    UNSPEC_FIST))
17695    (clobber (match_operand:DI 2 "memory_operand" "=X,m"))
17696    (clobber (match_scratch:XF 3 "=&1f,&1f"))]
17697   "TARGET_USE_FANCY_MATH_387"
17698   "#"
17699   [(set_attr "type" "fpspc")
17700    (set_attr "mode" "DI")])
17701
17702 (define_split
17703   [(set (match_operand:DI 0 "register_operand" "")
17704         (unspec:DI [(match_operand:XF 1 "register_operand" "")]
17705                    UNSPEC_FIST))
17706    (clobber (match_operand:DI 2 "memory_operand" ""))
17707    (clobber (match_scratch 3 ""))]
17708   "reload_completed"
17709   [(parallel [(set (match_dup 2) (unspec:DI [(match_dup 1)] UNSPEC_FIST))
17710               (clobber (match_dup 3))])
17711    (set (match_dup 0) (match_dup 2))]
17712   "")
17713
17714 (define_split
17715   [(set (match_operand:DI 0 "memory_operand" "")
17716         (unspec:DI [(match_operand:XF 1 "register_operand" "")]
17717                    UNSPEC_FIST))
17718    (clobber (match_operand:DI 2 "memory_operand" ""))
17719    (clobber (match_scratch 3 ""))]
17720   "reload_completed"
17721   [(parallel [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_FIST))
17722               (clobber (match_dup 3))])]
17723   "")
17724
17725 (define_insn_and_split "*fist<mode>2_1"
17726   [(set (match_operand:X87MODEI12 0 "register_operand" "")
17727         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "")]
17728                            UNSPEC_FIST))]
17729   "TARGET_USE_FANCY_MATH_387
17730    && can_create_pseudo_p ()"
17731   "#"
17732   "&& 1"
17733   [(const_int 0)]
17734 {
17735   operands[2] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
17736   emit_insn (gen_fist<mode>2_with_temp (operands[0], operands[1],
17737                                         operands[2]));
17738   DONE;
17739 }
17740   [(set_attr "type" "fpspc")
17741    (set_attr "mode" "<MODE>")])
17742
17743 (define_insn "fist<mode>2"
17744   [(set (match_operand:X87MODEI12 0 "memory_operand" "=m")
17745         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "f")]
17746                            UNSPEC_FIST))]
17747   "TARGET_USE_FANCY_MATH_387"
17748   "* return output_fix_trunc (insn, operands, 0);"
17749   [(set_attr "type" "fpspc")
17750    (set_attr "mode" "<MODE>")])
17751
17752 (define_insn "fist<mode>2_with_temp"
17753   [(set (match_operand:X87MODEI12 0 "register_operand" "=r")
17754         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "f")]
17755                            UNSPEC_FIST))
17756    (clobber (match_operand:X87MODEI12 2 "memory_operand" "=m"))]
17757   "TARGET_USE_FANCY_MATH_387"
17758   "#"
17759   [(set_attr "type" "fpspc")
17760    (set_attr "mode" "<MODE>")])
17761
17762 (define_split
17763   [(set (match_operand:X87MODEI12 0 "register_operand" "")
17764         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "")]
17765                            UNSPEC_FIST))
17766    (clobber (match_operand:X87MODEI12 2 "memory_operand" ""))]
17767   "reload_completed"
17768   [(set (match_dup 2) (unspec:X87MODEI12 [(match_dup 1)] UNSPEC_FIST))
17769    (set (match_dup 0) (match_dup 2))]
17770   "")
17771
17772 (define_split
17773   [(set (match_operand:X87MODEI12 0 "memory_operand" "")
17774         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "")]
17775                            UNSPEC_FIST))
17776    (clobber (match_operand:X87MODEI12 2 "memory_operand" ""))]
17777   "reload_completed"
17778   [(set (match_dup 0) (unspec:X87MODEI12 [(match_dup 1)] UNSPEC_FIST))]
17779   "")
17780
17781 (define_expand "lrintxf<mode>2"
17782   [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "")
17783      (unspec:X87MODEI [(match_operand:XF 1 "register_operand" "")]
17784                       UNSPEC_FIST))]
17785   "TARGET_USE_FANCY_MATH_387"
17786   "")
17787
17788 (define_expand "lrint<MODEF:mode><SSEMODEI24:mode>2"
17789   [(set (match_operand:SSEMODEI24 0 "nonimmediate_operand" "")
17790      (unspec:SSEMODEI24 [(match_operand:MODEF 1 "register_operand" "")]
17791                         UNSPEC_FIX_NOTRUNC))]
17792   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
17793    && ((<SSEMODEI24:MODE>mode != DImode) || TARGET_64BIT)"
17794   "")
17795
17796 (define_expand "lround<MODEF:mode><SSEMODEI24:mode>2"
17797   [(match_operand:SSEMODEI24 0 "nonimmediate_operand" "")
17798    (match_operand:MODEF 1 "register_operand" "")]
17799   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
17800    && ((<SSEMODEI24:MODE>mode != DImode) || TARGET_64BIT)
17801    && !flag_trapping_math && !flag_rounding_math"
17802 {
17803   if (optimize_insn_for_size_p ())
17804     FAIL;
17805   ix86_expand_lround (operand0, operand1);
17806   DONE;
17807 })
17808
17809 ;; Rounding mode control word calculation could clobber FLAGS_REG.
17810 (define_insn_and_split "frndintxf2_floor"
17811   [(set (match_operand:XF 0 "register_operand" "")
17812         (unspec:XF [(match_operand:XF 1 "register_operand" "")]
17813          UNSPEC_FRNDINT_FLOOR))
17814    (clobber (reg:CC FLAGS_REG))]
17815   "TARGET_USE_FANCY_MATH_387
17816    && flag_unsafe_math_optimizations
17817    && can_create_pseudo_p ()"
17818   "#"
17819   "&& 1"
17820   [(const_int 0)]
17821 {
17822   ix86_optimize_mode_switching[I387_FLOOR] = 1;
17823
17824   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
17825   operands[3] = assign_386_stack_local (HImode, SLOT_CW_FLOOR);
17826
17827   emit_insn (gen_frndintxf2_floor_i387 (operands[0], operands[1],
17828                                         operands[2], operands[3]));
17829   DONE;
17830 }
17831   [(set_attr "type" "frndint")
17832    (set_attr "i387_cw" "floor")
17833    (set_attr "mode" "XF")])
17834
17835 (define_insn "frndintxf2_floor_i387"
17836   [(set (match_operand:XF 0 "register_operand" "=f")
17837         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
17838          UNSPEC_FRNDINT_FLOOR))
17839    (use (match_operand:HI 2 "memory_operand" "m"))
17840    (use (match_operand:HI 3 "memory_operand" "m"))]
17841   "TARGET_USE_FANCY_MATH_387
17842    && flag_unsafe_math_optimizations"
17843   "fldcw\t%3\n\tfrndint\n\tfldcw\t%2"
17844   [(set_attr "type" "frndint")
17845    (set_attr "i387_cw" "floor")
17846    (set_attr "mode" "XF")])
17847
17848 (define_expand "floorxf2"
17849   [(use (match_operand:XF 0 "register_operand" ""))
17850    (use (match_operand:XF 1 "register_operand" ""))]
17851   "TARGET_USE_FANCY_MATH_387
17852    && flag_unsafe_math_optimizations"
17853 {
17854   if (optimize_insn_for_size_p ())
17855     FAIL;
17856   emit_insn (gen_frndintxf2_floor (operands[0], operands[1]));
17857   DONE;
17858 })
17859
17860 (define_expand "floor<mode>2"
17861   [(use (match_operand:MODEF 0 "register_operand" ""))
17862    (use (match_operand:MODEF 1 "register_operand" ""))]
17863   "(TARGET_USE_FANCY_MATH_387
17864     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
17865         || TARGET_MIX_SSE_I387)
17866     && flag_unsafe_math_optimizations)
17867    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
17868        && !flag_trapping_math)"
17869 {
17870   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
17871       && !flag_trapping_math
17872       && (TARGET_ROUND || optimize_insn_for_speed_p ()))
17873     {
17874       if (!TARGET_ROUND && optimize_insn_for_size_p ())
17875         FAIL;
17876       if (TARGET_ROUND)
17877         emit_insn (gen_sse4_1_round<mode>2
17878                    (operands[0], operands[1], GEN_INT (0x01)));
17879       else if (TARGET_64BIT || (<MODE>mode != DFmode))
17880         ix86_expand_floorceil (operand0, operand1, true);
17881       else
17882         ix86_expand_floorceildf_32 (operand0, operand1, true);
17883     }
17884   else
17885     {
17886       rtx op0, op1;
17887
17888       if (optimize_insn_for_size_p ())
17889         FAIL;
17890
17891       op0 = gen_reg_rtx (XFmode);
17892       op1 = gen_reg_rtx (XFmode);
17893       emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
17894       emit_insn (gen_frndintxf2_floor (op0, op1));
17895
17896       emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
17897     }
17898   DONE;
17899 })
17900
17901 (define_insn_and_split "*fist<mode>2_floor_1"
17902   [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "")
17903         (unspec:X87MODEI [(match_operand:XF 1 "register_operand" "")]
17904          UNSPEC_FIST_FLOOR))
17905    (clobber (reg:CC FLAGS_REG))]
17906   "TARGET_USE_FANCY_MATH_387
17907    && flag_unsafe_math_optimizations
17908    && can_create_pseudo_p ()"
17909   "#"
17910   "&& 1"
17911   [(const_int 0)]
17912 {
17913   ix86_optimize_mode_switching[I387_FLOOR] = 1;
17914
17915   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
17916   operands[3] = assign_386_stack_local (HImode, SLOT_CW_FLOOR);
17917   if (memory_operand (operands[0], VOIDmode))
17918     emit_insn (gen_fist<mode>2_floor (operands[0], operands[1],
17919                                       operands[2], operands[3]));
17920   else
17921     {
17922       operands[4] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
17923       emit_insn (gen_fist<mode>2_floor_with_temp (operands[0], operands[1],
17924                                                   operands[2], operands[3],
17925                                                   operands[4]));
17926     }
17927   DONE;
17928 }
17929   [(set_attr "type" "fistp")
17930    (set_attr "i387_cw" "floor")
17931    (set_attr "mode" "<MODE>")])
17932
17933 (define_insn "fistdi2_floor"
17934   [(set (match_operand:DI 0 "memory_operand" "=m")
17935         (unspec:DI [(match_operand:XF 1 "register_operand" "f")]
17936          UNSPEC_FIST_FLOOR))
17937    (use (match_operand:HI 2 "memory_operand" "m"))
17938    (use (match_operand:HI 3 "memory_operand" "m"))
17939    (clobber (match_scratch:XF 4 "=&1f"))]
17940   "TARGET_USE_FANCY_MATH_387
17941    && flag_unsafe_math_optimizations"
17942   "* return output_fix_trunc (insn, operands, 0);"
17943   [(set_attr "type" "fistp")
17944    (set_attr "i387_cw" "floor")
17945    (set_attr "mode" "DI")])
17946
17947 (define_insn "fistdi2_floor_with_temp"
17948   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
17949         (unspec:DI [(match_operand:XF 1 "register_operand" "f,f")]
17950          UNSPEC_FIST_FLOOR))
17951    (use (match_operand:HI 2 "memory_operand" "m,m"))
17952    (use (match_operand:HI 3 "memory_operand" "m,m"))
17953    (clobber (match_operand:DI 4 "memory_operand" "=X,m"))
17954    (clobber (match_scratch:XF 5 "=&1f,&1f"))]
17955   "TARGET_USE_FANCY_MATH_387
17956    && flag_unsafe_math_optimizations"
17957   "#"
17958   [(set_attr "type" "fistp")
17959    (set_attr "i387_cw" "floor")
17960    (set_attr "mode" "DI")])
17961
17962 (define_split
17963   [(set (match_operand:DI 0 "register_operand" "")
17964         (unspec:DI [(match_operand:XF 1 "register_operand" "")]
17965          UNSPEC_FIST_FLOOR))
17966    (use (match_operand:HI 2 "memory_operand" ""))
17967    (use (match_operand:HI 3 "memory_operand" ""))
17968    (clobber (match_operand:DI 4 "memory_operand" ""))
17969    (clobber (match_scratch 5 ""))]
17970   "reload_completed"
17971   [(parallel [(set (match_dup 4) (unspec:DI [(match_dup 1)] UNSPEC_FIST_FLOOR))
17972               (use (match_dup 2))
17973               (use (match_dup 3))
17974               (clobber (match_dup 5))])
17975    (set (match_dup 0) (match_dup 4))]
17976   "")
17977
17978 (define_split
17979   [(set (match_operand:DI 0 "memory_operand" "")
17980         (unspec:DI [(match_operand:XF 1 "register_operand" "")]
17981          UNSPEC_FIST_FLOOR))
17982    (use (match_operand:HI 2 "memory_operand" ""))
17983    (use (match_operand:HI 3 "memory_operand" ""))
17984    (clobber (match_operand:DI 4 "memory_operand" ""))
17985    (clobber (match_scratch 5 ""))]
17986   "reload_completed"
17987   [(parallel [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_FIST_FLOOR))
17988               (use (match_dup 2))
17989               (use (match_dup 3))
17990               (clobber (match_dup 5))])]
17991   "")
17992
17993 (define_insn "fist<mode>2_floor"
17994   [(set (match_operand:X87MODEI12 0 "memory_operand" "=m")
17995         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "f")]
17996          UNSPEC_FIST_FLOOR))
17997    (use (match_operand:HI 2 "memory_operand" "m"))
17998    (use (match_operand:HI 3 "memory_operand" "m"))]
17999   "TARGET_USE_FANCY_MATH_387
18000    && flag_unsafe_math_optimizations"
18001   "* return output_fix_trunc (insn, operands, 0);"
18002   [(set_attr "type" "fistp")
18003    (set_attr "i387_cw" "floor")
18004    (set_attr "mode" "<MODE>")])
18005
18006 (define_insn "fist<mode>2_floor_with_temp"
18007   [(set (match_operand:X87MODEI12 0 "nonimmediate_operand" "=m,?r")
18008         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "f,f")]
18009          UNSPEC_FIST_FLOOR))
18010    (use (match_operand:HI 2 "memory_operand" "m,m"))
18011    (use (match_operand:HI 3 "memory_operand" "m,m"))
18012    (clobber (match_operand:X87MODEI12 4 "memory_operand" "=X,m"))]
18013   "TARGET_USE_FANCY_MATH_387
18014    && flag_unsafe_math_optimizations"
18015   "#"
18016   [(set_attr "type" "fistp")
18017    (set_attr "i387_cw" "floor")
18018    (set_attr "mode" "<MODE>")])
18019
18020 (define_split
18021   [(set (match_operand:X87MODEI12 0 "register_operand" "")
18022         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "")]
18023          UNSPEC_FIST_FLOOR))
18024    (use (match_operand:HI 2 "memory_operand" ""))
18025    (use (match_operand:HI 3 "memory_operand" ""))
18026    (clobber (match_operand:X87MODEI12 4 "memory_operand" ""))]
18027   "reload_completed"
18028   [(parallel [(set (match_dup 4) (unspec:X87MODEI12 [(match_dup 1)]
18029                                   UNSPEC_FIST_FLOOR))
18030               (use (match_dup 2))
18031               (use (match_dup 3))])
18032    (set (match_dup 0) (match_dup 4))]
18033   "")
18034
18035 (define_split
18036   [(set (match_operand:X87MODEI12 0 "memory_operand" "")
18037         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "")]
18038          UNSPEC_FIST_FLOOR))
18039    (use (match_operand:HI 2 "memory_operand" ""))
18040    (use (match_operand:HI 3 "memory_operand" ""))
18041    (clobber (match_operand:X87MODEI12 4 "memory_operand" ""))]
18042   "reload_completed"
18043   [(parallel [(set (match_dup 0) (unspec:X87MODEI12 [(match_dup 1)]
18044                                   UNSPEC_FIST_FLOOR))
18045               (use (match_dup 2))
18046               (use (match_dup 3))])]
18047   "")
18048
18049 (define_expand "lfloorxf<mode>2"
18050   [(parallel [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "")
18051                    (unspec:X87MODEI [(match_operand:XF 1 "register_operand" "")]
18052                     UNSPEC_FIST_FLOOR))
18053               (clobber (reg:CC FLAGS_REG))])]
18054   "TARGET_USE_FANCY_MATH_387
18055    && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387)
18056    && flag_unsafe_math_optimizations"
18057   "")
18058
18059 (define_expand "lfloor<MODEF:mode><SWI48:mode>2"
18060   [(match_operand:SWI48 0 "nonimmediate_operand" "")
18061    (match_operand:MODEF 1 "register_operand" "")]
18062   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
18063    && !flag_trapping_math"
18064 {
18065   if (TARGET_64BIT && optimize_insn_for_size_p ())
18066     FAIL;
18067   ix86_expand_lfloorceil (operand0, operand1, true);
18068   DONE;
18069 })
18070
18071 ;; Rounding mode control word calculation could clobber FLAGS_REG.
18072 (define_insn_and_split "frndintxf2_ceil"
18073   [(set (match_operand:XF 0 "register_operand" "")
18074         (unspec:XF [(match_operand:XF 1 "register_operand" "")]
18075          UNSPEC_FRNDINT_CEIL))
18076    (clobber (reg:CC FLAGS_REG))]
18077   "TARGET_USE_FANCY_MATH_387
18078    && flag_unsafe_math_optimizations
18079    && can_create_pseudo_p ()"
18080   "#"
18081   "&& 1"
18082   [(const_int 0)]
18083 {
18084   ix86_optimize_mode_switching[I387_CEIL] = 1;
18085
18086   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
18087   operands[3] = assign_386_stack_local (HImode, SLOT_CW_CEIL);
18088
18089   emit_insn (gen_frndintxf2_ceil_i387 (operands[0], operands[1],
18090                                        operands[2], operands[3]));
18091   DONE;
18092 }
18093   [(set_attr "type" "frndint")
18094    (set_attr "i387_cw" "ceil")
18095    (set_attr "mode" "XF")])
18096
18097 (define_insn "frndintxf2_ceil_i387"
18098   [(set (match_operand:XF 0 "register_operand" "=f")
18099         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
18100          UNSPEC_FRNDINT_CEIL))
18101    (use (match_operand:HI 2 "memory_operand" "m"))
18102    (use (match_operand:HI 3 "memory_operand" "m"))]
18103   "TARGET_USE_FANCY_MATH_387
18104    && flag_unsafe_math_optimizations"
18105   "fldcw\t%3\n\tfrndint\n\tfldcw\t%2"
18106   [(set_attr "type" "frndint")
18107    (set_attr "i387_cw" "ceil")
18108    (set_attr "mode" "XF")])
18109
18110 (define_expand "ceilxf2"
18111   [(use (match_operand:XF 0 "register_operand" ""))
18112    (use (match_operand:XF 1 "register_operand" ""))]
18113   "TARGET_USE_FANCY_MATH_387
18114    && flag_unsafe_math_optimizations"
18115 {
18116   if (optimize_insn_for_size_p ())
18117     FAIL;
18118   emit_insn (gen_frndintxf2_ceil (operands[0], operands[1]));
18119   DONE;
18120 })
18121
18122 (define_expand "ceil<mode>2"
18123   [(use (match_operand:MODEF 0 "register_operand" ""))
18124    (use (match_operand:MODEF 1 "register_operand" ""))]
18125   "(TARGET_USE_FANCY_MATH_387
18126     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
18127         || TARGET_MIX_SSE_I387)
18128     && flag_unsafe_math_optimizations)
18129    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
18130        && !flag_trapping_math)"
18131 {
18132   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
18133       && !flag_trapping_math
18134       && (TARGET_ROUND || optimize_insn_for_speed_p ()))
18135     {
18136       if (TARGET_ROUND)
18137         emit_insn (gen_sse4_1_round<mode>2
18138                    (operands[0], operands[1], GEN_INT (0x02)));
18139       else if (optimize_insn_for_size_p ())
18140         FAIL;
18141       else if (TARGET_64BIT || (<MODE>mode != DFmode))
18142         ix86_expand_floorceil (operand0, operand1, false);
18143       else
18144         ix86_expand_floorceildf_32 (operand0, operand1, false);
18145     }
18146   else
18147     {
18148       rtx op0, op1;
18149
18150       if (optimize_insn_for_size_p ())
18151         FAIL;
18152
18153       op0 = gen_reg_rtx (XFmode);
18154       op1 = gen_reg_rtx (XFmode);
18155       emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
18156       emit_insn (gen_frndintxf2_ceil (op0, op1));
18157
18158       emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
18159     }
18160   DONE;
18161 })
18162
18163 (define_insn_and_split "*fist<mode>2_ceil_1"
18164   [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "")
18165         (unspec:X87MODEI [(match_operand:XF 1 "register_operand" "")]
18166          UNSPEC_FIST_CEIL))
18167    (clobber (reg:CC FLAGS_REG))]
18168   "TARGET_USE_FANCY_MATH_387
18169    && flag_unsafe_math_optimizations
18170    && can_create_pseudo_p ()"
18171   "#"
18172   "&& 1"
18173   [(const_int 0)]
18174 {
18175   ix86_optimize_mode_switching[I387_CEIL] = 1;
18176
18177   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
18178   operands[3] = assign_386_stack_local (HImode, SLOT_CW_CEIL);
18179   if (memory_operand (operands[0], VOIDmode))
18180     emit_insn (gen_fist<mode>2_ceil (operands[0], operands[1],
18181                                      operands[2], operands[3]));
18182   else
18183     {
18184       operands[4] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
18185       emit_insn (gen_fist<mode>2_ceil_with_temp (operands[0], operands[1],
18186                                                  operands[2], operands[3],
18187                                                  operands[4]));
18188     }
18189   DONE;
18190 }
18191   [(set_attr "type" "fistp")
18192    (set_attr "i387_cw" "ceil")
18193    (set_attr "mode" "<MODE>")])
18194
18195 (define_insn "fistdi2_ceil"
18196   [(set (match_operand:DI 0 "memory_operand" "=m")
18197         (unspec:DI [(match_operand:XF 1 "register_operand" "f")]
18198          UNSPEC_FIST_CEIL))
18199    (use (match_operand:HI 2 "memory_operand" "m"))
18200    (use (match_operand:HI 3 "memory_operand" "m"))
18201    (clobber (match_scratch:XF 4 "=&1f"))]
18202   "TARGET_USE_FANCY_MATH_387
18203    && flag_unsafe_math_optimizations"
18204   "* return output_fix_trunc (insn, operands, 0);"
18205   [(set_attr "type" "fistp")
18206    (set_attr "i387_cw" "ceil")
18207    (set_attr "mode" "DI")])
18208
18209 (define_insn "fistdi2_ceil_with_temp"
18210   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
18211         (unspec:DI [(match_operand:XF 1 "register_operand" "f,f")]
18212          UNSPEC_FIST_CEIL))
18213    (use (match_operand:HI 2 "memory_operand" "m,m"))
18214    (use (match_operand:HI 3 "memory_operand" "m,m"))
18215    (clobber (match_operand:DI 4 "memory_operand" "=X,m"))
18216    (clobber (match_scratch:XF 5 "=&1f,&1f"))]
18217   "TARGET_USE_FANCY_MATH_387
18218    && flag_unsafe_math_optimizations"
18219   "#"
18220   [(set_attr "type" "fistp")
18221    (set_attr "i387_cw" "ceil")
18222    (set_attr "mode" "DI")])
18223
18224 (define_split
18225   [(set (match_operand:DI 0 "register_operand" "")
18226         (unspec:DI [(match_operand:XF 1 "register_operand" "")]
18227          UNSPEC_FIST_CEIL))
18228    (use (match_operand:HI 2 "memory_operand" ""))
18229    (use (match_operand:HI 3 "memory_operand" ""))
18230    (clobber (match_operand:DI 4 "memory_operand" ""))
18231    (clobber (match_scratch 5 ""))]
18232   "reload_completed"
18233   [(parallel [(set (match_dup 4) (unspec:DI [(match_dup 1)] UNSPEC_FIST_CEIL))
18234               (use (match_dup 2))
18235               (use (match_dup 3))
18236               (clobber (match_dup 5))])
18237    (set (match_dup 0) (match_dup 4))]
18238   "")
18239
18240 (define_split
18241   [(set (match_operand:DI 0 "memory_operand" "")
18242         (unspec:DI [(match_operand:XF 1 "register_operand" "")]
18243          UNSPEC_FIST_CEIL))
18244    (use (match_operand:HI 2 "memory_operand" ""))
18245    (use (match_operand:HI 3 "memory_operand" ""))
18246    (clobber (match_operand:DI 4 "memory_operand" ""))
18247    (clobber (match_scratch 5 ""))]
18248   "reload_completed"
18249   [(parallel [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_FIST_CEIL))
18250               (use (match_dup 2))
18251               (use (match_dup 3))
18252               (clobber (match_dup 5))])]
18253   "")
18254
18255 (define_insn "fist<mode>2_ceil"
18256   [(set (match_operand:X87MODEI12 0 "memory_operand" "=m")
18257         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "f")]
18258          UNSPEC_FIST_CEIL))
18259    (use (match_operand:HI 2 "memory_operand" "m"))
18260    (use (match_operand:HI 3 "memory_operand" "m"))]
18261   "TARGET_USE_FANCY_MATH_387
18262    && flag_unsafe_math_optimizations"
18263   "* return output_fix_trunc (insn, operands, 0);"
18264   [(set_attr "type" "fistp")
18265    (set_attr "i387_cw" "ceil")
18266    (set_attr "mode" "<MODE>")])
18267
18268 (define_insn "fist<mode>2_ceil_with_temp"
18269   [(set (match_operand:X87MODEI12 0 "nonimmediate_operand" "=m,?r")
18270         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "f,f")]
18271          UNSPEC_FIST_CEIL))
18272    (use (match_operand:HI 2 "memory_operand" "m,m"))
18273    (use (match_operand:HI 3 "memory_operand" "m,m"))
18274    (clobber (match_operand:X87MODEI12 4 "memory_operand" "=X,m"))]
18275   "TARGET_USE_FANCY_MATH_387
18276    && flag_unsafe_math_optimizations"
18277   "#"
18278   [(set_attr "type" "fistp")
18279    (set_attr "i387_cw" "ceil")
18280    (set_attr "mode" "<MODE>")])
18281
18282 (define_split
18283   [(set (match_operand:X87MODEI12 0 "register_operand" "")
18284         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "")]
18285          UNSPEC_FIST_CEIL))
18286    (use (match_operand:HI 2 "memory_operand" ""))
18287    (use (match_operand:HI 3 "memory_operand" ""))
18288    (clobber (match_operand:X87MODEI12 4 "memory_operand" ""))]
18289   "reload_completed"
18290   [(parallel [(set (match_dup 4) (unspec:X87MODEI12 [(match_dup 1)]
18291                                   UNSPEC_FIST_CEIL))
18292               (use (match_dup 2))
18293               (use (match_dup 3))])
18294    (set (match_dup 0) (match_dup 4))]
18295   "")
18296
18297 (define_split
18298   [(set (match_operand:X87MODEI12 0 "memory_operand" "")
18299         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "")]
18300          UNSPEC_FIST_CEIL))
18301    (use (match_operand:HI 2 "memory_operand" ""))
18302    (use (match_operand:HI 3 "memory_operand" ""))
18303    (clobber (match_operand:X87MODEI12 4 "memory_operand" ""))]
18304   "reload_completed"
18305   [(parallel [(set (match_dup 0) (unspec:X87MODEI12 [(match_dup 1)]
18306                                   UNSPEC_FIST_CEIL))
18307               (use (match_dup 2))
18308               (use (match_dup 3))])]
18309   "")
18310
18311 (define_expand "lceilxf<mode>2"
18312   [(parallel [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "")
18313                    (unspec:X87MODEI [(match_operand:XF 1 "register_operand" "")]
18314                     UNSPEC_FIST_CEIL))
18315               (clobber (reg:CC FLAGS_REG))])]
18316   "TARGET_USE_FANCY_MATH_387
18317    && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387)
18318    && flag_unsafe_math_optimizations"
18319   "")
18320
18321 (define_expand "lceil<MODEF:mode><SWI48:mode>2"
18322   [(match_operand:SWI48 0 "nonimmediate_operand" "")
18323    (match_operand:MODEF 1 "register_operand" "")]
18324   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
18325    && !flag_trapping_math"
18326 {
18327   ix86_expand_lfloorceil (operand0, operand1, false);
18328   DONE;
18329 })
18330
18331 ;; Rounding mode control word calculation could clobber FLAGS_REG.
18332 (define_insn_and_split "frndintxf2_trunc"
18333   [(set (match_operand:XF 0 "register_operand" "")
18334         (unspec:XF [(match_operand:XF 1 "register_operand" "")]
18335          UNSPEC_FRNDINT_TRUNC))
18336    (clobber (reg:CC FLAGS_REG))]
18337   "TARGET_USE_FANCY_MATH_387
18338    && flag_unsafe_math_optimizations
18339    && can_create_pseudo_p ()"
18340   "#"
18341   "&& 1"
18342   [(const_int 0)]
18343 {
18344   ix86_optimize_mode_switching[I387_TRUNC] = 1;
18345
18346   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
18347   operands[3] = assign_386_stack_local (HImode, SLOT_CW_TRUNC);
18348
18349   emit_insn (gen_frndintxf2_trunc_i387 (operands[0], operands[1],
18350                                         operands[2], operands[3]));
18351   DONE;
18352 }
18353   [(set_attr "type" "frndint")
18354    (set_attr "i387_cw" "trunc")
18355    (set_attr "mode" "XF")])
18356
18357 (define_insn "frndintxf2_trunc_i387"
18358   [(set (match_operand:XF 0 "register_operand" "=f")
18359         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
18360          UNSPEC_FRNDINT_TRUNC))
18361    (use (match_operand:HI 2 "memory_operand" "m"))
18362    (use (match_operand:HI 3 "memory_operand" "m"))]
18363   "TARGET_USE_FANCY_MATH_387
18364    && flag_unsafe_math_optimizations"
18365   "fldcw\t%3\n\tfrndint\n\tfldcw\t%2"
18366   [(set_attr "type" "frndint")
18367    (set_attr "i387_cw" "trunc")
18368    (set_attr "mode" "XF")])
18369
18370 (define_expand "btruncxf2"
18371   [(use (match_operand:XF 0 "register_operand" ""))
18372    (use (match_operand:XF 1 "register_operand" ""))]
18373   "TARGET_USE_FANCY_MATH_387
18374    && flag_unsafe_math_optimizations"
18375 {
18376   if (optimize_insn_for_size_p ())
18377     FAIL;
18378   emit_insn (gen_frndintxf2_trunc (operands[0], operands[1]));
18379   DONE;
18380 })
18381
18382 (define_expand "btrunc<mode>2"
18383   [(use (match_operand:MODEF 0 "register_operand" ""))
18384    (use (match_operand:MODEF 1 "register_operand" ""))]
18385   "(TARGET_USE_FANCY_MATH_387
18386     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
18387         || TARGET_MIX_SSE_I387)
18388     && flag_unsafe_math_optimizations)
18389    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
18390        && !flag_trapping_math)"
18391 {
18392   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
18393       && !flag_trapping_math
18394       && (TARGET_ROUND || optimize_insn_for_speed_p ()))
18395     {
18396       if (TARGET_ROUND)
18397         emit_insn (gen_sse4_1_round<mode>2
18398                    (operands[0], operands[1], GEN_INT (0x03)));
18399       else if (optimize_insn_for_size_p ())
18400         FAIL;
18401       else if (TARGET_64BIT || (<MODE>mode != DFmode))
18402         ix86_expand_trunc (operand0, operand1);
18403       else
18404         ix86_expand_truncdf_32 (operand0, operand1);
18405     }
18406   else
18407     {
18408       rtx op0, op1;
18409
18410       if (optimize_insn_for_size_p ())
18411         FAIL;
18412
18413       op0 = gen_reg_rtx (XFmode);
18414       op1 = gen_reg_rtx (XFmode);
18415       emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
18416       emit_insn (gen_frndintxf2_trunc (op0, op1));
18417
18418       emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
18419     }
18420   DONE;
18421 })
18422
18423 ;; Rounding mode control word calculation could clobber FLAGS_REG.
18424 (define_insn_and_split "frndintxf2_mask_pm"
18425   [(set (match_operand:XF 0 "register_operand" "")
18426         (unspec:XF [(match_operand:XF 1 "register_operand" "")]
18427          UNSPEC_FRNDINT_MASK_PM))
18428    (clobber (reg:CC FLAGS_REG))]
18429   "TARGET_USE_FANCY_MATH_387
18430    && flag_unsafe_math_optimizations
18431    && can_create_pseudo_p ()"
18432   "#"
18433   "&& 1"
18434   [(const_int 0)]
18435 {
18436   ix86_optimize_mode_switching[I387_MASK_PM] = 1;
18437
18438   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
18439   operands[3] = assign_386_stack_local (HImode, SLOT_CW_MASK_PM);
18440
18441   emit_insn (gen_frndintxf2_mask_pm_i387 (operands[0], operands[1],
18442                                           operands[2], operands[3]));
18443   DONE;
18444 }
18445   [(set_attr "type" "frndint")
18446    (set_attr "i387_cw" "mask_pm")
18447    (set_attr "mode" "XF")])
18448
18449 (define_insn "frndintxf2_mask_pm_i387"
18450   [(set (match_operand:XF 0 "register_operand" "=f")
18451         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
18452          UNSPEC_FRNDINT_MASK_PM))
18453    (use (match_operand:HI 2 "memory_operand" "m"))
18454    (use (match_operand:HI 3 "memory_operand" "m"))]
18455   "TARGET_USE_FANCY_MATH_387
18456    && flag_unsafe_math_optimizations"
18457   "fldcw\t%3\n\tfrndint\n\tfclex\n\tfldcw\t%2"
18458   [(set_attr "type" "frndint")
18459    (set_attr "i387_cw" "mask_pm")
18460    (set_attr "mode" "XF")])
18461
18462 (define_expand "nearbyintxf2"
18463   [(use (match_operand:XF 0 "register_operand" ""))
18464    (use (match_operand:XF 1 "register_operand" ""))]
18465   "TARGET_USE_FANCY_MATH_387
18466    && flag_unsafe_math_optimizations"
18467 {
18468   emit_insn (gen_frndintxf2_mask_pm (operands[0], operands[1]));
18469
18470   DONE;
18471 })
18472
18473 (define_expand "nearbyint<mode>2"
18474   [(use (match_operand:MODEF 0 "register_operand" ""))
18475    (use (match_operand:MODEF 1 "register_operand" ""))]
18476   "TARGET_USE_FANCY_MATH_387
18477    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
18478        || TARGET_MIX_SSE_I387)
18479    && flag_unsafe_math_optimizations"
18480 {
18481   rtx op0 = gen_reg_rtx (XFmode);
18482   rtx op1 = gen_reg_rtx (XFmode);
18483
18484   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
18485   emit_insn (gen_frndintxf2_mask_pm (op0, op1));
18486
18487   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
18488   DONE;
18489 })
18490
18491 (define_insn "fxam<mode>2_i387"
18492   [(set (match_operand:HI 0 "register_operand" "=a")
18493         (unspec:HI
18494           [(match_operand:X87MODEF 1 "register_operand" "f")]
18495           UNSPEC_FXAM))]
18496   "TARGET_USE_FANCY_MATH_387"
18497   "fxam\n\tfnstsw\t%0"
18498   [(set_attr "type" "multi")
18499    (set_attr "length" "4")
18500    (set_attr "unit" "i387")
18501    (set_attr "mode" "<MODE>")])
18502
18503 (define_insn_and_split "fxam<mode>2_i387_with_temp"
18504   [(set (match_operand:HI 0 "register_operand" "")
18505         (unspec:HI
18506           [(match_operand:MODEF 1 "memory_operand" "")]
18507           UNSPEC_FXAM_MEM))]
18508   "TARGET_USE_FANCY_MATH_387
18509    && can_create_pseudo_p ()"
18510   "#"
18511   "&& 1"
18512   [(set (match_dup 2)(match_dup 1))
18513    (set (match_dup 0)
18514         (unspec:HI [(match_dup 2)] UNSPEC_FXAM))]
18515 {
18516   operands[2] = gen_reg_rtx (<MODE>mode);
18517
18518   MEM_VOLATILE_P (operands[1]) = 1;
18519 }
18520   [(set_attr "type" "multi")
18521    (set_attr "unit" "i387")
18522    (set_attr "mode" "<MODE>")])
18523
18524 (define_expand "isinfxf2"
18525   [(use (match_operand:SI 0 "register_operand" ""))
18526    (use (match_operand:XF 1 "register_operand" ""))]
18527   "TARGET_USE_FANCY_MATH_387
18528    && TARGET_C99_FUNCTIONS"
18529 {
18530   rtx mask = GEN_INT (0x45);
18531   rtx val = GEN_INT (0x05);
18532
18533   rtx cond;
18534
18535   rtx scratch = gen_reg_rtx (HImode);
18536   rtx res = gen_reg_rtx (QImode);
18537
18538   emit_insn (gen_fxamxf2_i387 (scratch, operands[1]));
18539
18540   emit_insn (gen_andqi_ext_0 (scratch, scratch, mask));
18541   emit_insn (gen_cmpqi_ext_3 (scratch, val));
18542   cond = gen_rtx_fmt_ee (EQ, QImode,
18543                          gen_rtx_REG (CCmode, FLAGS_REG),
18544                          const0_rtx);
18545   emit_insn (gen_rtx_SET (VOIDmode, res, cond));
18546   emit_insn (gen_zero_extendqisi2 (operands[0], res));
18547   DONE;
18548 })
18549
18550 (define_expand "isinf<mode>2"
18551   [(use (match_operand:SI 0 "register_operand" ""))
18552    (use (match_operand:MODEF 1 "nonimmediate_operand" ""))]
18553   "TARGET_USE_FANCY_MATH_387
18554    && TARGET_C99_FUNCTIONS
18555    && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
18556 {
18557   rtx mask = GEN_INT (0x45);
18558   rtx val = GEN_INT (0x05);
18559
18560   rtx cond;
18561
18562   rtx scratch = gen_reg_rtx (HImode);
18563   rtx res = gen_reg_rtx (QImode);
18564
18565   /* Remove excess precision by forcing value through memory. */
18566   if (memory_operand (operands[1], VOIDmode))
18567     emit_insn (gen_fxam<mode>2_i387_with_temp (scratch, operands[1]));
18568   else
18569     {
18570       enum ix86_stack_slot slot = (virtuals_instantiated
18571                                    ? SLOT_TEMP
18572                                    : SLOT_VIRTUAL);
18573       rtx temp = assign_386_stack_local (<MODE>mode, slot);
18574
18575       emit_move_insn (temp, operands[1]);
18576       emit_insn (gen_fxam<mode>2_i387_with_temp (scratch, temp));
18577     }
18578
18579   emit_insn (gen_andqi_ext_0 (scratch, scratch, mask));
18580   emit_insn (gen_cmpqi_ext_3 (scratch, val));
18581   cond = gen_rtx_fmt_ee (EQ, QImode,
18582                          gen_rtx_REG (CCmode, FLAGS_REG),
18583                          const0_rtx);
18584   emit_insn (gen_rtx_SET (VOIDmode, res, cond));
18585   emit_insn (gen_zero_extendqisi2 (operands[0], res));
18586   DONE;
18587 })
18588
18589 (define_expand "signbit<mode>2"
18590   [(use (match_operand:SI 0 "register_operand" ""))
18591    (use (match_operand:X87MODEF 1 "register_operand" ""))]
18592   "TARGET_USE_FANCY_MATH_387
18593    && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
18594 {
18595   rtx mask = GEN_INT (0x0200);
18596
18597   rtx scratch = gen_reg_rtx (HImode);
18598
18599   emit_insn (gen_fxam<mode>2_i387 (scratch, operands[1]));
18600   emit_insn (gen_andsi3 (operands[0], gen_lowpart (SImode, scratch), mask));
18601   DONE;
18602 })
18603 \f
18604 ;; Block operation instructions
18605
18606 (define_insn "cld"
18607   [(unspec_volatile [(const_int 0)] UNSPECV_CLD)]
18608   ""
18609   "cld"
18610   [(set_attr "length" "1")
18611    (set_attr "length_immediate" "0")
18612    (set_attr "modrm" "0")])
18613
18614 (define_expand "movmemsi"
18615   [(use (match_operand:BLK 0 "memory_operand" ""))
18616    (use (match_operand:BLK 1 "memory_operand" ""))
18617    (use (match_operand:SI 2 "nonmemory_operand" ""))
18618    (use (match_operand:SI 3 "const_int_operand" ""))
18619    (use (match_operand:SI 4 "const_int_operand" ""))
18620    (use (match_operand:SI 5 "const_int_operand" ""))]
18621   ""
18622 {
18623  if (ix86_expand_movmem (operands[0], operands[1], operands[2], operands[3],
18624                          operands[4], operands[5]))
18625    DONE;
18626  else
18627    FAIL;
18628 })
18629
18630 (define_expand "movmemdi"
18631   [(use (match_operand:BLK 0 "memory_operand" ""))
18632    (use (match_operand:BLK 1 "memory_operand" ""))
18633    (use (match_operand:DI 2 "nonmemory_operand" ""))
18634    (use (match_operand:DI 3 "const_int_operand" ""))
18635    (use (match_operand:SI 4 "const_int_operand" ""))
18636    (use (match_operand:SI 5 "const_int_operand" ""))]
18637   "TARGET_64BIT"
18638 {
18639  if (ix86_expand_movmem (operands[0], operands[1], operands[2], operands[3],
18640                          operands[4], operands[5]))
18641    DONE;
18642  else
18643    FAIL;
18644 })
18645
18646 ;; Most CPUs don't like single string operations
18647 ;; Handle this case here to simplify previous expander.
18648
18649 (define_expand "strmov"
18650   [(set (match_dup 4) (match_operand 3 "memory_operand" ""))
18651    (set (match_operand 1 "memory_operand" "") (match_dup 4))
18652    (parallel [(set (match_operand 0 "register_operand" "") (match_dup 5))
18653               (clobber (reg:CC FLAGS_REG))])
18654    (parallel [(set (match_operand 2 "register_operand" "") (match_dup 6))
18655               (clobber (reg:CC FLAGS_REG))])]
18656   ""
18657 {
18658   rtx adjust = GEN_INT (GET_MODE_SIZE (GET_MODE (operands[1])));
18659
18660   /* If .md ever supports :P for Pmode, these can be directly
18661      in the pattern above.  */
18662   operands[5] = gen_rtx_PLUS (Pmode, operands[0], adjust);
18663   operands[6] = gen_rtx_PLUS (Pmode, operands[2], adjust);
18664
18665   /* Can't use this if the user has appropriated esi or edi.  */
18666   if ((TARGET_SINGLE_STRINGOP || optimize_insn_for_size_p ())
18667       && !(fixed_regs[SI_REG] || fixed_regs[DI_REG]))
18668     {
18669       emit_insn (gen_strmov_singleop (operands[0], operands[1],
18670                                       operands[2], operands[3],
18671                                       operands[5], operands[6]));
18672       DONE;
18673     }
18674
18675   operands[4] = gen_reg_rtx (GET_MODE (operands[1]));
18676 })
18677
18678 (define_expand "strmov_singleop"
18679   [(parallel [(set (match_operand 1 "memory_operand" "")
18680                    (match_operand 3 "memory_operand" ""))
18681               (set (match_operand 0 "register_operand" "")
18682                    (match_operand 4 "" ""))
18683               (set (match_operand 2 "register_operand" "")
18684                    (match_operand 5 "" ""))])]
18685   ""
18686   "ix86_current_function_needs_cld = 1;")
18687
18688 (define_insn "*strmovdi_rex_1"
18689   [(set (mem:DI (match_operand:DI 2 "register_operand" "0"))
18690         (mem:DI (match_operand:DI 3 "register_operand" "1")))
18691    (set (match_operand:DI 0 "register_operand" "=D")
18692         (plus:DI (match_dup 2)
18693                  (const_int 8)))
18694    (set (match_operand:DI 1 "register_operand" "=S")
18695         (plus:DI (match_dup 3)
18696                  (const_int 8)))]
18697   "TARGET_64BIT"
18698   "movsq"
18699   [(set_attr "type" "str")
18700    (set_attr "mode" "DI")
18701    (set_attr "memory" "both")])
18702
18703 (define_insn "*strmovsi_1"
18704   [(set (mem:SI (match_operand:SI 2 "register_operand" "0"))
18705         (mem:SI (match_operand:SI 3 "register_operand" "1")))
18706    (set (match_operand:SI 0 "register_operand" "=D")
18707         (plus:SI (match_dup 2)
18708                  (const_int 4)))
18709    (set (match_operand:SI 1 "register_operand" "=S")
18710         (plus:SI (match_dup 3)
18711                  (const_int 4)))]
18712   "!TARGET_64BIT"
18713   "movs{l|d}"
18714   [(set_attr "type" "str")
18715    (set_attr "mode" "SI")
18716    (set_attr "memory" "both")])
18717
18718 (define_insn "*strmovsi_rex_1"
18719   [(set (mem:SI (match_operand:DI 2 "register_operand" "0"))
18720         (mem:SI (match_operand:DI 3 "register_operand" "1")))
18721    (set (match_operand:DI 0 "register_operand" "=D")
18722         (plus:DI (match_dup 2)
18723                  (const_int 4)))
18724    (set (match_operand:DI 1 "register_operand" "=S")
18725         (plus:DI (match_dup 3)
18726                  (const_int 4)))]
18727   "TARGET_64BIT"
18728   "movs{l|d}"
18729   [(set_attr "type" "str")
18730    (set_attr "mode" "SI")
18731    (set_attr "memory" "both")])
18732
18733 (define_insn "*strmovhi_1"
18734   [(set (mem:HI (match_operand:SI 2 "register_operand" "0"))
18735         (mem:HI (match_operand:SI 3 "register_operand" "1")))
18736    (set (match_operand:SI 0 "register_operand" "=D")
18737         (plus:SI (match_dup 2)
18738                  (const_int 2)))
18739    (set (match_operand:SI 1 "register_operand" "=S")
18740         (plus:SI (match_dup 3)
18741                  (const_int 2)))]
18742   "!TARGET_64BIT"
18743   "movsw"
18744   [(set_attr "type" "str")
18745    (set_attr "memory" "both")
18746    (set_attr "mode" "HI")])
18747
18748 (define_insn "*strmovhi_rex_1"
18749   [(set (mem:HI (match_operand:DI 2 "register_operand" "0"))
18750         (mem:HI (match_operand:DI 3 "register_operand" "1")))
18751    (set (match_operand:DI 0 "register_operand" "=D")
18752         (plus:DI (match_dup 2)
18753                  (const_int 2)))
18754    (set (match_operand:DI 1 "register_operand" "=S")
18755         (plus:DI (match_dup 3)
18756                  (const_int 2)))]
18757   "TARGET_64BIT"
18758   "movsw"
18759   [(set_attr "type" "str")
18760    (set_attr "memory" "both")
18761    (set_attr "mode" "HI")])
18762
18763 (define_insn "*strmovqi_1"
18764   [(set (mem:QI (match_operand:SI 2 "register_operand" "0"))
18765         (mem:QI (match_operand:SI 3 "register_operand" "1")))
18766    (set (match_operand:SI 0 "register_operand" "=D")
18767         (plus:SI (match_dup 2)
18768                  (const_int 1)))
18769    (set (match_operand:SI 1 "register_operand" "=S")
18770         (plus:SI (match_dup 3)
18771                  (const_int 1)))]
18772   "!TARGET_64BIT"
18773   "movsb"
18774   [(set_attr "type" "str")
18775    (set_attr "memory" "both")
18776    (set_attr "mode" "QI")])
18777
18778 (define_insn "*strmovqi_rex_1"
18779   [(set (mem:QI (match_operand:DI 2 "register_operand" "0"))
18780         (mem:QI (match_operand:DI 3 "register_operand" "1")))
18781    (set (match_operand:DI 0 "register_operand" "=D")
18782         (plus:DI (match_dup 2)
18783                  (const_int 1)))
18784    (set (match_operand:DI 1 "register_operand" "=S")
18785         (plus:DI (match_dup 3)
18786                  (const_int 1)))]
18787   "TARGET_64BIT"
18788   "movsb"
18789   [(set_attr "type" "str")
18790    (set_attr "memory" "both")
18791    (set_attr "prefix_rex" "0")
18792    (set_attr "mode" "QI")])
18793
18794 (define_expand "rep_mov"
18795   [(parallel [(set (match_operand 4 "register_operand" "") (const_int 0))
18796               (set (match_operand 0 "register_operand" "")
18797                    (match_operand 5 "" ""))
18798               (set (match_operand 2 "register_operand" "")
18799                    (match_operand 6 "" ""))
18800               (set (match_operand 1 "memory_operand" "")
18801                    (match_operand 3 "memory_operand" ""))
18802               (use (match_dup 4))])]
18803   ""
18804   "ix86_current_function_needs_cld = 1;")
18805
18806 (define_insn "*rep_movdi_rex64"
18807   [(set (match_operand:DI 2 "register_operand" "=c") (const_int 0))
18808    (set (match_operand:DI 0 "register_operand" "=D")
18809         (plus:DI (ashift:DI (match_operand:DI 5 "register_operand" "2")
18810                             (const_int 3))
18811                  (match_operand:DI 3 "register_operand" "0")))
18812    (set (match_operand:DI 1 "register_operand" "=S")
18813         (plus:DI (ashift:DI (match_dup 5) (const_int 3))
18814                  (match_operand:DI 4 "register_operand" "1")))
18815    (set (mem:BLK (match_dup 3))
18816         (mem:BLK (match_dup 4)))
18817    (use (match_dup 5))]
18818   "TARGET_64BIT"
18819   "rep movsq"
18820   [(set_attr "type" "str")
18821    (set_attr "prefix_rep" "1")
18822    (set_attr "memory" "both")
18823    (set_attr "mode" "DI")])
18824
18825 (define_insn "*rep_movsi"
18826   [(set (match_operand:SI 2 "register_operand" "=c") (const_int 0))
18827    (set (match_operand:SI 0 "register_operand" "=D")
18828         (plus:SI (ashift:SI (match_operand:SI 5 "register_operand" "2")
18829                             (const_int 2))
18830                  (match_operand:SI 3 "register_operand" "0")))
18831    (set (match_operand:SI 1 "register_operand" "=S")
18832         (plus:SI (ashift:SI (match_dup 5) (const_int 2))
18833                  (match_operand:SI 4 "register_operand" "1")))
18834    (set (mem:BLK (match_dup 3))
18835         (mem:BLK (match_dup 4)))
18836    (use (match_dup 5))]
18837   "!TARGET_64BIT"
18838   "rep movs{l|d}"
18839   [(set_attr "type" "str")
18840    (set_attr "prefix_rep" "1")
18841    (set_attr "memory" "both")
18842    (set_attr "mode" "SI")])
18843
18844 (define_insn "*rep_movsi_rex64"
18845   [(set (match_operand:DI 2 "register_operand" "=c") (const_int 0))
18846    (set (match_operand:DI 0 "register_operand" "=D")
18847         (plus:DI (ashift:DI (match_operand:DI 5 "register_operand" "2")
18848                             (const_int 2))
18849                  (match_operand:DI 3 "register_operand" "0")))
18850    (set (match_operand:DI 1 "register_operand" "=S")
18851         (plus:DI (ashift:DI (match_dup 5) (const_int 2))
18852                  (match_operand:DI 4 "register_operand" "1")))
18853    (set (mem:BLK (match_dup 3))
18854         (mem:BLK (match_dup 4)))
18855    (use (match_dup 5))]
18856   "TARGET_64BIT"
18857   "rep movs{l|d}"
18858   [(set_attr "type" "str")
18859    (set_attr "prefix_rep" "1")
18860    (set_attr "memory" "both")
18861    (set_attr "mode" "SI")])
18862
18863 (define_insn "*rep_movqi"
18864   [(set (match_operand:SI 2 "register_operand" "=c") (const_int 0))
18865    (set (match_operand:SI 0 "register_operand" "=D")
18866         (plus:SI (match_operand:SI 3 "register_operand" "0")
18867                  (match_operand:SI 5 "register_operand" "2")))
18868    (set (match_operand:SI 1 "register_operand" "=S")
18869         (plus:SI (match_operand:SI 4 "register_operand" "1") (match_dup 5)))
18870    (set (mem:BLK (match_dup 3))
18871         (mem:BLK (match_dup 4)))
18872    (use (match_dup 5))]
18873   "!TARGET_64BIT"
18874   "rep movsb"
18875   [(set_attr "type" "str")
18876    (set_attr "prefix_rep" "1")
18877    (set_attr "memory" "both")
18878    (set_attr "mode" "SI")])
18879
18880 (define_insn "*rep_movqi_rex64"
18881   [(set (match_operand:DI 2 "register_operand" "=c") (const_int 0))
18882    (set (match_operand:DI 0 "register_operand" "=D")
18883         (plus:DI (match_operand:DI 3 "register_operand" "0")
18884                  (match_operand:DI 5 "register_operand" "2")))
18885    (set (match_operand:DI 1 "register_operand" "=S")
18886         (plus:DI (match_operand:DI 4 "register_operand" "1") (match_dup 5)))
18887    (set (mem:BLK (match_dup 3))
18888         (mem:BLK (match_dup 4)))
18889    (use (match_dup 5))]
18890   "TARGET_64BIT"
18891   "rep movsb"
18892   [(set_attr "type" "str")
18893    (set_attr "prefix_rep" "1")
18894    (set_attr "memory" "both")
18895    (set_attr "mode" "SI")])
18896
18897 (define_expand "setmemsi"
18898    [(use (match_operand:BLK 0 "memory_operand" ""))
18899     (use (match_operand:SI 1 "nonmemory_operand" ""))
18900     (use (match_operand 2 "const_int_operand" ""))
18901     (use (match_operand 3 "const_int_operand" ""))
18902     (use (match_operand:SI 4 "const_int_operand" ""))
18903     (use (match_operand:SI 5 "const_int_operand" ""))]
18904   ""
18905 {
18906  if (ix86_expand_setmem (operands[0], operands[1],
18907                          operands[2], operands[3],
18908                          operands[4], operands[5]))
18909    DONE;
18910  else
18911    FAIL;
18912 })
18913
18914 (define_expand "setmemdi"
18915    [(use (match_operand:BLK 0 "memory_operand" ""))
18916     (use (match_operand:DI 1 "nonmemory_operand" ""))
18917     (use (match_operand 2 "const_int_operand" ""))
18918     (use (match_operand 3 "const_int_operand" ""))
18919     (use (match_operand 4 "const_int_operand" ""))
18920     (use (match_operand 5 "const_int_operand" ""))]
18921   "TARGET_64BIT"
18922 {
18923  if (ix86_expand_setmem (operands[0], operands[1],
18924                          operands[2], operands[3],
18925                          operands[4], operands[5]))
18926    DONE;
18927  else
18928    FAIL;
18929 })
18930
18931 ;; Most CPUs don't like single string operations
18932 ;; Handle this case here to simplify previous expander.
18933
18934 (define_expand "strset"
18935   [(set (match_operand 1 "memory_operand" "")
18936         (match_operand 2 "register_operand" ""))
18937    (parallel [(set (match_operand 0 "register_operand" "")
18938                    (match_dup 3))
18939               (clobber (reg:CC FLAGS_REG))])]
18940   ""
18941 {
18942   if (GET_MODE (operands[1]) != GET_MODE (operands[2]))
18943     operands[1] = adjust_address_nv (operands[1], GET_MODE (operands[2]), 0);
18944
18945   /* If .md ever supports :P for Pmode, this can be directly
18946      in the pattern above.  */
18947   operands[3] = gen_rtx_PLUS (Pmode, operands[0],
18948                               GEN_INT (GET_MODE_SIZE (GET_MODE
18949                                                       (operands[2]))));
18950   if (TARGET_SINGLE_STRINGOP || optimize_insn_for_size_p ())
18951     {
18952       emit_insn (gen_strset_singleop (operands[0], operands[1], operands[2],
18953                                       operands[3]));
18954       DONE;
18955     }
18956 })
18957
18958 (define_expand "strset_singleop"
18959   [(parallel [(set (match_operand 1 "memory_operand" "")
18960                    (match_operand 2 "register_operand" ""))
18961               (set (match_operand 0 "register_operand" "")
18962                    (match_operand 3 "" ""))])]
18963   ""
18964   "ix86_current_function_needs_cld = 1;")
18965
18966 (define_insn "*strsetdi_rex_1"
18967   [(set (mem:DI (match_operand:DI 1 "register_operand" "0"))
18968         (match_operand:DI 2 "register_operand" "a"))
18969    (set (match_operand:DI 0 "register_operand" "=D")
18970         (plus:DI (match_dup 1)
18971                  (const_int 8)))]
18972   "TARGET_64BIT"
18973   "stosq"
18974   [(set_attr "type" "str")
18975    (set_attr "memory" "store")
18976    (set_attr "mode" "DI")])
18977
18978 (define_insn "*strsetsi_1"
18979   [(set (mem:SI (match_operand:SI 1 "register_operand" "0"))
18980         (match_operand:SI 2 "register_operand" "a"))
18981    (set (match_operand:SI 0 "register_operand" "=D")
18982         (plus:SI (match_dup 1)
18983                  (const_int 4)))]
18984   "!TARGET_64BIT"
18985   "stos{l|d}"
18986   [(set_attr "type" "str")
18987    (set_attr "memory" "store")
18988    (set_attr "mode" "SI")])
18989
18990 (define_insn "*strsetsi_rex_1"
18991   [(set (mem:SI (match_operand:DI 1 "register_operand" "0"))
18992         (match_operand:SI 2 "register_operand" "a"))
18993    (set (match_operand:DI 0 "register_operand" "=D")
18994         (plus:DI (match_dup 1)
18995                  (const_int 4)))]
18996   "TARGET_64BIT"
18997   "stos{l|d}"
18998   [(set_attr "type" "str")
18999    (set_attr "memory" "store")
19000    (set_attr "mode" "SI")])
19001
19002 (define_insn "*strsethi_1"
19003   [(set (mem:HI (match_operand:SI 1 "register_operand" "0"))
19004         (match_operand:HI 2 "register_operand" "a"))
19005    (set (match_operand:SI 0 "register_operand" "=D")
19006         (plus:SI (match_dup 1)
19007                  (const_int 2)))]
19008   "!TARGET_64BIT"
19009   "stosw"
19010   [(set_attr "type" "str")
19011    (set_attr "memory" "store")
19012    (set_attr "mode" "HI")])
19013
19014 (define_insn "*strsethi_rex_1"
19015   [(set (mem:HI (match_operand:DI 1 "register_operand" "0"))
19016         (match_operand:HI 2 "register_operand" "a"))
19017    (set (match_operand:DI 0 "register_operand" "=D")
19018         (plus:DI (match_dup 1)
19019                  (const_int 2)))]
19020   "TARGET_64BIT"
19021   "stosw"
19022   [(set_attr "type" "str")
19023    (set_attr "memory" "store")
19024    (set_attr "mode" "HI")])
19025
19026 (define_insn "*strsetqi_1"
19027   [(set (mem:QI (match_operand:SI 1 "register_operand" "0"))
19028         (match_operand:QI 2 "register_operand" "a"))
19029    (set (match_operand:SI 0 "register_operand" "=D")
19030         (plus:SI (match_dup 1)
19031                  (const_int 1)))]
19032   "!TARGET_64BIT"
19033   "stosb"
19034   [(set_attr "type" "str")
19035    (set_attr "memory" "store")
19036    (set_attr "mode" "QI")])
19037
19038 (define_insn "*strsetqi_rex_1"
19039   [(set (mem:QI (match_operand:DI 1 "register_operand" "0"))
19040         (match_operand:QI 2 "register_operand" "a"))
19041    (set (match_operand:DI 0 "register_operand" "=D")
19042         (plus:DI (match_dup 1)
19043                  (const_int 1)))]
19044   "TARGET_64BIT"
19045   "stosb"
19046   [(set_attr "type" "str")
19047    (set_attr "memory" "store")
19048    (set_attr "prefix_rex" "0")
19049    (set_attr "mode" "QI")])
19050
19051 (define_expand "rep_stos"
19052   [(parallel [(set (match_operand 1 "register_operand" "") (const_int 0))
19053               (set (match_operand 0 "register_operand" "")
19054                    (match_operand 4 "" ""))
19055               (set (match_operand 2 "memory_operand" "") (const_int 0))
19056               (use (match_operand 3 "register_operand" ""))
19057               (use (match_dup 1))])]
19058   ""
19059   "ix86_current_function_needs_cld = 1;")
19060
19061 (define_insn "*rep_stosdi_rex64"
19062   [(set (match_operand:DI 1 "register_operand" "=c") (const_int 0))
19063    (set (match_operand:DI 0 "register_operand" "=D")
19064         (plus:DI (ashift:DI (match_operand:DI 4 "register_operand" "1")
19065                             (const_int 3))
19066                  (match_operand:DI 3 "register_operand" "0")))
19067    (set (mem:BLK (match_dup 3))
19068         (const_int 0))
19069    (use (match_operand:DI 2 "register_operand" "a"))
19070    (use (match_dup 4))]
19071   "TARGET_64BIT"
19072   "rep stosq"
19073   [(set_attr "type" "str")
19074    (set_attr "prefix_rep" "1")
19075    (set_attr "memory" "store")
19076    (set_attr "mode" "DI")])
19077
19078 (define_insn "*rep_stossi"
19079   [(set (match_operand:SI 1 "register_operand" "=c") (const_int 0))
19080    (set (match_operand:SI 0 "register_operand" "=D")
19081         (plus:SI (ashift:SI (match_operand:SI 4 "register_operand" "1")
19082                             (const_int 2))
19083                  (match_operand:SI 3 "register_operand" "0")))
19084    (set (mem:BLK (match_dup 3))
19085         (const_int 0))
19086    (use (match_operand:SI 2 "register_operand" "a"))
19087    (use (match_dup 4))]
19088   "!TARGET_64BIT"
19089   "rep stos{l|d}"
19090   [(set_attr "type" "str")
19091    (set_attr "prefix_rep" "1")
19092    (set_attr "memory" "store")
19093    (set_attr "mode" "SI")])
19094
19095 (define_insn "*rep_stossi_rex64"
19096   [(set (match_operand:DI 1 "register_operand" "=c") (const_int 0))
19097    (set (match_operand:DI 0 "register_operand" "=D")
19098         (plus:DI (ashift:DI (match_operand:DI 4 "register_operand" "1")
19099                             (const_int 2))
19100                  (match_operand:DI 3 "register_operand" "0")))
19101    (set (mem:BLK (match_dup 3))
19102         (const_int 0))
19103    (use (match_operand:SI 2 "register_operand" "a"))
19104    (use (match_dup 4))]
19105   "TARGET_64BIT"
19106   "rep stos{l|d}"
19107   [(set_attr "type" "str")
19108    (set_attr "prefix_rep" "1")
19109    (set_attr "memory" "store")
19110    (set_attr "mode" "SI")])
19111
19112 (define_insn "*rep_stosqi"
19113   [(set (match_operand:SI 1 "register_operand" "=c") (const_int 0))
19114    (set (match_operand:SI 0 "register_operand" "=D")
19115         (plus:SI (match_operand:SI 3 "register_operand" "0")
19116                  (match_operand:SI 4 "register_operand" "1")))
19117    (set (mem:BLK (match_dup 3))
19118         (const_int 0))
19119    (use (match_operand:QI 2 "register_operand" "a"))
19120    (use (match_dup 4))]
19121   "!TARGET_64BIT"
19122   "rep stosb"
19123   [(set_attr "type" "str")
19124    (set_attr "prefix_rep" "1")
19125    (set_attr "memory" "store")
19126    (set_attr "mode" "QI")])
19127
19128 (define_insn "*rep_stosqi_rex64"
19129   [(set (match_operand:DI 1 "register_operand" "=c") (const_int 0))
19130    (set (match_operand:DI 0 "register_operand" "=D")
19131         (plus:DI (match_operand:DI 3 "register_operand" "0")
19132                  (match_operand:DI 4 "register_operand" "1")))
19133    (set (mem:BLK (match_dup 3))
19134         (const_int 0))
19135    (use (match_operand:QI 2 "register_operand" "a"))
19136    (use (match_dup 4))]
19137   "TARGET_64BIT"
19138   "rep stosb"
19139   [(set_attr "type" "str")
19140    (set_attr "prefix_rep" "1")
19141    (set_attr "memory" "store")
19142    (set_attr "prefix_rex" "0")
19143    (set_attr "mode" "QI")])
19144
19145 (define_expand "cmpstrnsi"
19146   [(set (match_operand:SI 0 "register_operand" "")
19147         (compare:SI (match_operand:BLK 1 "general_operand" "")
19148                     (match_operand:BLK 2 "general_operand" "")))
19149    (use (match_operand 3 "general_operand" ""))
19150    (use (match_operand 4 "immediate_operand" ""))]
19151   ""
19152 {
19153   rtx addr1, addr2, out, outlow, count, countreg, align;
19154
19155   if (optimize_insn_for_size_p () && !TARGET_INLINE_ALL_STRINGOPS)
19156     FAIL;
19157
19158   /* Can't use this if the user has appropriated esi or edi.  */
19159   if (fixed_regs[SI_REG] || fixed_regs[DI_REG])
19160     FAIL;
19161
19162   out = operands[0];
19163   if (!REG_P (out))
19164     out = gen_reg_rtx (SImode);
19165
19166   addr1 = copy_to_mode_reg (Pmode, XEXP (operands[1], 0));
19167   addr2 = copy_to_mode_reg (Pmode, XEXP (operands[2], 0));
19168   if (addr1 != XEXP (operands[1], 0))
19169     operands[1] = replace_equiv_address_nv (operands[1], addr1);
19170   if (addr2 != XEXP (operands[2], 0))
19171     operands[2] = replace_equiv_address_nv (operands[2], addr2);
19172
19173   count = operands[3];
19174   countreg = ix86_zero_extend_to_Pmode (count);
19175
19176   /* %%% Iff we are testing strict equality, we can use known alignment
19177      to good advantage.  This may be possible with combine, particularly
19178      once cc0 is dead.  */
19179   align = operands[4];
19180
19181   if (CONST_INT_P (count))
19182     {
19183       if (INTVAL (count) == 0)
19184         {
19185           emit_move_insn (operands[0], const0_rtx);
19186           DONE;
19187         }
19188       emit_insn (gen_cmpstrnqi_nz_1 (addr1, addr2, countreg, align,
19189                                      operands[1], operands[2]));
19190     }
19191   else
19192     {
19193       if (TARGET_64BIT)
19194         emit_insn (gen_cmpdi_1_rex64 (countreg, countreg));
19195       else
19196         emit_insn (gen_cmpsi_1 (countreg, countreg));
19197       emit_insn (gen_cmpstrnqi_1 (addr1, addr2, countreg, align,
19198                                   operands[1], operands[2]));
19199     }
19200
19201   outlow = gen_lowpart (QImode, out);
19202   emit_insn (gen_cmpintqi (outlow));
19203   emit_move_insn (out, gen_rtx_SIGN_EXTEND (SImode, outlow));
19204
19205   if (operands[0] != out)
19206     emit_move_insn (operands[0], out);
19207
19208   DONE;
19209 })
19210
19211 ;; Produce a tri-state integer (-1, 0, 1) from condition codes.
19212
19213 (define_expand "cmpintqi"
19214   [(set (match_dup 1)
19215         (gtu:QI (reg:CC FLAGS_REG) (const_int 0)))
19216    (set (match_dup 2)
19217         (ltu:QI (reg:CC FLAGS_REG) (const_int 0)))
19218    (parallel [(set (match_operand:QI 0 "register_operand" "")
19219                    (minus:QI (match_dup 1)
19220                              (match_dup 2)))
19221               (clobber (reg:CC FLAGS_REG))])]
19222   ""
19223   "operands[1] = gen_reg_rtx (QImode);
19224    operands[2] = gen_reg_rtx (QImode);")
19225
19226 ;; memcmp recognizers.  The `cmpsb' opcode does nothing if the count is
19227 ;; zero.  Emit extra code to make sure that a zero-length compare is EQ.
19228
19229 (define_expand "cmpstrnqi_nz_1"
19230   [(parallel [(set (reg:CC FLAGS_REG)
19231                    (compare:CC (match_operand 4 "memory_operand" "")
19232                                (match_operand 5 "memory_operand" "")))
19233               (use (match_operand 2 "register_operand" ""))
19234               (use (match_operand:SI 3 "immediate_operand" ""))
19235               (clobber (match_operand 0 "register_operand" ""))
19236               (clobber (match_operand 1 "register_operand" ""))
19237               (clobber (match_dup 2))])]
19238   ""
19239   "ix86_current_function_needs_cld = 1;")
19240
19241 (define_insn "*cmpstrnqi_nz_1"
19242   [(set (reg:CC FLAGS_REG)
19243         (compare:CC (mem:BLK (match_operand:SI 4 "register_operand" "0"))
19244                     (mem:BLK (match_operand:SI 5 "register_operand" "1"))))
19245    (use (match_operand:SI 6 "register_operand" "2"))
19246    (use (match_operand:SI 3 "immediate_operand" "i"))
19247    (clobber (match_operand:SI 0 "register_operand" "=S"))
19248    (clobber (match_operand:SI 1 "register_operand" "=D"))
19249    (clobber (match_operand:SI 2 "register_operand" "=c"))]
19250   "!TARGET_64BIT"
19251   "repz cmpsb"
19252   [(set_attr "type" "str")
19253    (set_attr "mode" "QI")
19254    (set_attr "prefix_rep" "1")])
19255
19256 (define_insn "*cmpstrnqi_nz_rex_1"
19257   [(set (reg:CC FLAGS_REG)
19258         (compare:CC (mem:BLK (match_operand:DI 4 "register_operand" "0"))
19259                     (mem:BLK (match_operand:DI 5 "register_operand" "1"))))
19260    (use (match_operand:DI 6 "register_operand" "2"))
19261    (use (match_operand:SI 3 "immediate_operand" "i"))
19262    (clobber (match_operand:DI 0 "register_operand" "=S"))
19263    (clobber (match_operand:DI 1 "register_operand" "=D"))
19264    (clobber (match_operand:DI 2 "register_operand" "=c"))]
19265   "TARGET_64BIT"
19266   "repz cmpsb"
19267   [(set_attr "type" "str")
19268    (set_attr "mode" "QI")
19269    (set_attr "prefix_rex" "0")
19270    (set_attr "prefix_rep" "1")])
19271
19272 ;; The same, but the count is not known to not be zero.
19273
19274 (define_expand "cmpstrnqi_1"
19275   [(parallel [(set (reg:CC FLAGS_REG)
19276                 (if_then_else:CC (ne (match_operand 2 "register_operand" "")
19277                                      (const_int 0))
19278                   (compare:CC (match_operand 4 "memory_operand" "")
19279                               (match_operand 5 "memory_operand" ""))
19280                   (const_int 0)))
19281               (use (match_operand:SI 3 "immediate_operand" ""))
19282               (use (reg:CC FLAGS_REG))
19283               (clobber (match_operand 0 "register_operand" ""))
19284               (clobber (match_operand 1 "register_operand" ""))
19285               (clobber (match_dup 2))])]
19286   ""
19287   "ix86_current_function_needs_cld = 1;")
19288
19289 (define_insn "*cmpstrnqi_1"
19290   [(set (reg:CC FLAGS_REG)
19291         (if_then_else:CC (ne (match_operand:SI 6 "register_operand" "2")
19292                              (const_int 0))
19293           (compare:CC (mem:BLK (match_operand:SI 4 "register_operand" "0"))
19294                       (mem:BLK (match_operand:SI 5 "register_operand" "1")))
19295           (const_int 0)))
19296    (use (match_operand:SI 3 "immediate_operand" "i"))
19297    (use (reg:CC FLAGS_REG))
19298    (clobber (match_operand:SI 0 "register_operand" "=S"))
19299    (clobber (match_operand:SI 1 "register_operand" "=D"))
19300    (clobber (match_operand:SI 2 "register_operand" "=c"))]
19301   "!TARGET_64BIT"
19302   "repz cmpsb"
19303   [(set_attr "type" "str")
19304    (set_attr "mode" "QI")
19305    (set_attr "prefix_rep" "1")])
19306
19307 (define_insn "*cmpstrnqi_rex_1"
19308   [(set (reg:CC FLAGS_REG)
19309         (if_then_else:CC (ne (match_operand:DI 6 "register_operand" "2")
19310                              (const_int 0))
19311           (compare:CC (mem:BLK (match_operand:DI 4 "register_operand" "0"))
19312                       (mem:BLK (match_operand:DI 5 "register_operand" "1")))
19313           (const_int 0)))
19314    (use (match_operand:SI 3 "immediate_operand" "i"))
19315    (use (reg:CC FLAGS_REG))
19316    (clobber (match_operand:DI 0 "register_operand" "=S"))
19317    (clobber (match_operand:DI 1 "register_operand" "=D"))
19318    (clobber (match_operand:DI 2 "register_operand" "=c"))]
19319   "TARGET_64BIT"
19320   "repz cmpsb"
19321   [(set_attr "type" "str")
19322    (set_attr "mode" "QI")
19323    (set_attr "prefix_rex" "0")
19324    (set_attr "prefix_rep" "1")])
19325
19326 (define_expand "strlensi"
19327   [(set (match_operand:SI 0 "register_operand" "")
19328         (unspec:SI [(match_operand:BLK 1 "general_operand" "")
19329                     (match_operand:QI 2 "immediate_operand" "")
19330                     (match_operand 3 "immediate_operand" "")] UNSPEC_SCAS))]
19331   ""
19332 {
19333  if (ix86_expand_strlen (operands[0], operands[1], operands[2], operands[3]))
19334    DONE;
19335  else
19336    FAIL;
19337 })
19338
19339 (define_expand "strlendi"
19340   [(set (match_operand:DI 0 "register_operand" "")
19341         (unspec:DI [(match_operand:BLK 1 "general_operand" "")
19342                     (match_operand:QI 2 "immediate_operand" "")
19343                     (match_operand 3 "immediate_operand" "")] UNSPEC_SCAS))]
19344   ""
19345 {
19346  if (ix86_expand_strlen (operands[0], operands[1], operands[2], operands[3]))
19347    DONE;
19348  else
19349    FAIL;
19350 })
19351
19352 (define_expand "strlenqi_1"
19353   [(parallel [(set (match_operand 0 "register_operand" "") (match_operand 2 "" ""))
19354               (clobber (match_operand 1 "register_operand" ""))
19355               (clobber (reg:CC FLAGS_REG))])]
19356   ""
19357   "ix86_current_function_needs_cld = 1;")
19358
19359 (define_insn "*strlenqi_1"
19360   [(set (match_operand:SI 0 "register_operand" "=&c")
19361         (unspec:SI [(mem:BLK (match_operand:SI 5 "register_operand" "1"))
19362                     (match_operand:QI 2 "register_operand" "a")
19363                     (match_operand:SI 3 "immediate_operand" "i")
19364                     (match_operand:SI 4 "register_operand" "0")] UNSPEC_SCAS))
19365    (clobber (match_operand:SI 1 "register_operand" "=D"))
19366    (clobber (reg:CC FLAGS_REG))]
19367   "!TARGET_64BIT"
19368   "repnz scasb"
19369   [(set_attr "type" "str")
19370    (set_attr "mode" "QI")
19371    (set_attr "prefix_rep" "1")])
19372
19373 (define_insn "*strlenqi_rex_1"
19374   [(set (match_operand:DI 0 "register_operand" "=&c")
19375         (unspec:DI [(mem:BLK (match_operand:DI 5 "register_operand" "1"))
19376                     (match_operand:QI 2 "register_operand" "a")
19377                     (match_operand:DI 3 "immediate_operand" "i")
19378                     (match_operand:DI 4 "register_operand" "0")] UNSPEC_SCAS))
19379    (clobber (match_operand:DI 1 "register_operand" "=D"))
19380    (clobber (reg:CC FLAGS_REG))]
19381   "TARGET_64BIT"
19382   "repnz scasb"
19383   [(set_attr "type" "str")
19384    (set_attr "mode" "QI")
19385    (set_attr "prefix_rex" "0")
19386    (set_attr "prefix_rep" "1")])
19387
19388 ;; Peephole optimizations to clean up after cmpstrn*.  This should be
19389 ;; handled in combine, but it is not currently up to the task.
19390 ;; When used for their truth value, the cmpstrn* expanders generate
19391 ;; code like this:
19392 ;;
19393 ;;   repz cmpsb
19394 ;;   seta       %al
19395 ;;   setb       %dl
19396 ;;   cmpb       %al, %dl
19397 ;;   jcc        label
19398 ;;
19399 ;; The intermediate three instructions are unnecessary.
19400
19401 ;; This one handles cmpstrn*_nz_1...
19402 (define_peephole2
19403   [(parallel[
19404      (set (reg:CC FLAGS_REG)
19405           (compare:CC (mem:BLK (match_operand 4 "register_operand" ""))
19406                       (mem:BLK (match_operand 5 "register_operand" ""))))
19407      (use (match_operand 6 "register_operand" ""))
19408      (use (match_operand:SI 3 "immediate_operand" ""))
19409      (clobber (match_operand 0 "register_operand" ""))
19410      (clobber (match_operand 1 "register_operand" ""))
19411      (clobber (match_operand 2 "register_operand" ""))])
19412    (set (match_operand:QI 7 "register_operand" "")
19413         (gtu:QI (reg:CC FLAGS_REG) (const_int 0)))
19414    (set (match_operand:QI 8 "register_operand" "")
19415         (ltu:QI (reg:CC FLAGS_REG) (const_int 0)))
19416    (set (reg FLAGS_REG)
19417         (compare (match_dup 7) (match_dup 8)))
19418   ]
19419   "peep2_reg_dead_p (4, operands[7]) && peep2_reg_dead_p (4, operands[8])"
19420   [(parallel[
19421      (set (reg:CC FLAGS_REG)
19422           (compare:CC (mem:BLK (match_dup 4))
19423                       (mem:BLK (match_dup 5))))
19424      (use (match_dup 6))
19425      (use (match_dup 3))
19426      (clobber (match_dup 0))
19427      (clobber (match_dup 1))
19428      (clobber (match_dup 2))])]
19429   "")
19430
19431 ;; ...and this one handles cmpstrn*_1.
19432 (define_peephole2
19433   [(parallel[
19434      (set (reg:CC FLAGS_REG)
19435           (if_then_else:CC (ne (match_operand 6 "register_operand" "")
19436                                (const_int 0))
19437             (compare:CC (mem:BLK (match_operand 4 "register_operand" ""))
19438                         (mem:BLK (match_operand 5 "register_operand" "")))
19439             (const_int 0)))
19440      (use (match_operand:SI 3 "immediate_operand" ""))
19441      (use (reg:CC FLAGS_REG))
19442      (clobber (match_operand 0 "register_operand" ""))
19443      (clobber (match_operand 1 "register_operand" ""))
19444      (clobber (match_operand 2 "register_operand" ""))])
19445    (set (match_operand:QI 7 "register_operand" "")
19446         (gtu:QI (reg:CC FLAGS_REG) (const_int 0)))
19447    (set (match_operand:QI 8 "register_operand" "")
19448         (ltu:QI (reg:CC FLAGS_REG) (const_int 0)))
19449    (set (reg FLAGS_REG)
19450         (compare (match_dup 7) (match_dup 8)))
19451   ]
19452   "peep2_reg_dead_p (4, operands[7]) && peep2_reg_dead_p (4, operands[8])"
19453   [(parallel[
19454      (set (reg:CC FLAGS_REG)
19455           (if_then_else:CC (ne (match_dup 6)
19456                                (const_int 0))
19457             (compare:CC (mem:BLK (match_dup 4))
19458                         (mem:BLK (match_dup 5)))
19459             (const_int 0)))
19460      (use (match_dup 3))
19461      (use (reg:CC FLAGS_REG))
19462      (clobber (match_dup 0))
19463      (clobber (match_dup 1))
19464      (clobber (match_dup 2))])]
19465   "")
19466
19467
19468 \f
19469 ;; Conditional move instructions.
19470
19471 (define_expand "movdicc"
19472   [(set (match_operand:DI 0 "register_operand" "")
19473         (if_then_else:DI (match_operand 1 "comparison_operator" "")
19474                          (match_operand:DI 2 "general_operand" "")
19475                          (match_operand:DI 3 "general_operand" "")))]
19476   "TARGET_64BIT"
19477   "if (ix86_expand_int_movcc (operands)) DONE; else FAIL;")
19478
19479 (define_insn "x86_movdicc_0_m1_rex64"
19480   [(set (match_operand:DI 0 "register_operand" "=r")
19481         (if_then_else:DI (match_operand 1 "ix86_carry_flag_operator" "")
19482           (const_int -1)
19483           (const_int 0)))
19484    (clobber (reg:CC FLAGS_REG))]
19485   "TARGET_64BIT"
19486   "sbb{q}\t%0, %0"
19487   ; Since we don't have the proper number of operands for an alu insn,
19488   ; fill in all the blanks.
19489   [(set_attr "type" "alu")
19490    (set_attr "use_carry" "1")
19491    (set_attr "pent_pair" "pu")
19492    (set_attr "memory" "none")
19493    (set_attr "imm_disp" "false")
19494    (set_attr "mode" "DI")
19495    (set_attr "length_immediate" "0")])
19496
19497 (define_insn "*x86_movdicc_0_m1_se"
19498   [(set (match_operand:DI 0 "register_operand" "=r")
19499         (sign_extract:DI (match_operand 1 "ix86_carry_flag_operator" "")
19500                          (const_int 1)
19501                          (const_int 0)))
19502    (clobber (reg:CC FLAGS_REG))]
19503   ""
19504   "sbb{q}\t%0, %0"
19505   [(set_attr "type" "alu")
19506    (set_attr "use_carry" "1")
19507    (set_attr "pent_pair" "pu")
19508    (set_attr "memory" "none")
19509    (set_attr "imm_disp" "false")
19510    (set_attr "mode" "DI")
19511    (set_attr "length_immediate" "0")])
19512
19513 (define_insn "*movdicc_c_rex64"
19514   [(set (match_operand:DI 0 "register_operand" "=r,r")
19515         (if_then_else:DI (match_operator 1 "ix86_comparison_operator"
19516                                 [(reg FLAGS_REG) (const_int 0)])
19517                       (match_operand:DI 2 "nonimmediate_operand" "rm,0")
19518                       (match_operand:DI 3 "nonimmediate_operand" "0,rm")))]
19519   "TARGET_64BIT && TARGET_CMOVE
19520    && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
19521   "@
19522    cmov%O2%C1\t{%2, %0|%0, %2}
19523    cmov%O2%c1\t{%3, %0|%0, %3}"
19524   [(set_attr "type" "icmov")
19525    (set_attr "mode" "DI")])
19526
19527 (define_expand "movsicc"
19528   [(set (match_operand:SI 0 "register_operand" "")
19529         (if_then_else:SI (match_operand 1 "comparison_operator" "")
19530                          (match_operand:SI 2 "general_operand" "")
19531                          (match_operand:SI 3 "general_operand" "")))]
19532   ""
19533   "if (ix86_expand_int_movcc (operands)) DONE; else FAIL;")
19534
19535 ;; Data flow gets confused by our desire for `sbbl reg,reg', and clearing
19536 ;; the register first winds up with `sbbl $0,reg', which is also weird.
19537 ;; So just document what we're doing explicitly.
19538
19539 (define_insn "x86_movsicc_0_m1"
19540   [(set (match_operand:SI 0 "register_operand" "=r")
19541         (if_then_else:SI (match_operand 1 "ix86_carry_flag_operator" "")
19542           (const_int -1)
19543           (const_int 0)))
19544    (clobber (reg:CC FLAGS_REG))]
19545   ""
19546   "sbb{l}\t%0, %0"
19547   ; Since we don't have the proper number of operands for an alu insn,
19548   ; fill in all the blanks.
19549   [(set_attr "type" "alu")
19550    (set_attr "use_carry" "1")
19551    (set_attr "pent_pair" "pu")
19552    (set_attr "memory" "none")
19553    (set_attr "imm_disp" "false")
19554    (set_attr "mode" "SI")
19555    (set_attr "length_immediate" "0")])
19556
19557 (define_insn "*x86_movsicc_0_m1_se"
19558   [(set (match_operand:SI 0 "register_operand" "=r")
19559         (sign_extract:SI (match_operand 1 "ix86_carry_flag_operator" "")
19560                          (const_int 1)
19561                          (const_int 0)))
19562    (clobber (reg:CC FLAGS_REG))]
19563   ""
19564   "sbb{l}\t%0, %0"
19565   [(set_attr "type" "alu")
19566    (set_attr "use_carry" "1")
19567    (set_attr "pent_pair" "pu")
19568    (set_attr "memory" "none")
19569    (set_attr "imm_disp" "false")
19570    (set_attr "mode" "SI")
19571    (set_attr "length_immediate" "0")])
19572
19573 (define_insn "*movsicc_noc"
19574   [(set (match_operand:SI 0 "register_operand" "=r,r")
19575         (if_then_else:SI (match_operator 1 "ix86_comparison_operator"
19576                                 [(reg FLAGS_REG) (const_int 0)])
19577                       (match_operand:SI 2 "nonimmediate_operand" "rm,0")
19578                       (match_operand:SI 3 "nonimmediate_operand" "0,rm")))]
19579   "TARGET_CMOVE
19580    && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
19581   "@
19582    cmov%O2%C1\t{%2, %0|%0, %2}
19583    cmov%O2%c1\t{%3, %0|%0, %3}"
19584   [(set_attr "type" "icmov")
19585    (set_attr "mode" "SI")])
19586
19587 (define_expand "movhicc"
19588   [(set (match_operand:HI 0 "register_operand" "")
19589         (if_then_else:HI (match_operand 1 "comparison_operator" "")
19590                          (match_operand:HI 2 "general_operand" "")
19591                          (match_operand:HI 3 "general_operand" "")))]
19592   "TARGET_HIMODE_MATH"
19593   "if (ix86_expand_int_movcc (operands)) DONE; else FAIL;")
19594
19595 (define_insn "*movhicc_noc"
19596   [(set (match_operand:HI 0 "register_operand" "=r,r")
19597         (if_then_else:HI (match_operator 1 "ix86_comparison_operator"
19598                                 [(reg FLAGS_REG) (const_int 0)])
19599                       (match_operand:HI 2 "nonimmediate_operand" "rm,0")
19600                       (match_operand:HI 3 "nonimmediate_operand" "0,rm")))]
19601   "TARGET_CMOVE
19602    && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
19603   "@
19604    cmov%O2%C1\t{%2, %0|%0, %2}
19605    cmov%O2%c1\t{%3, %0|%0, %3}"
19606   [(set_attr "type" "icmov")
19607    (set_attr "mode" "HI")])
19608
19609 (define_expand "movqicc"
19610   [(set (match_operand:QI 0 "register_operand" "")
19611         (if_then_else:QI (match_operand 1 "comparison_operator" "")
19612                          (match_operand:QI 2 "general_operand" "")
19613                          (match_operand:QI 3 "general_operand" "")))]
19614   "TARGET_QIMODE_MATH"
19615   "if (ix86_expand_int_movcc (operands)) DONE; else FAIL;")
19616
19617 (define_insn_and_split "*movqicc_noc"
19618   [(set (match_operand:QI 0 "register_operand" "=r,r")
19619         (if_then_else:QI (match_operator 1 "ix86_comparison_operator"
19620                                 [(match_operand 4 "flags_reg_operand" "")
19621                                  (const_int 0)])
19622                       (match_operand:QI 2 "register_operand" "r,0")
19623                       (match_operand:QI 3 "register_operand" "0,r")))]
19624   "TARGET_CMOVE && !TARGET_PARTIAL_REG_STALL"
19625   "#"
19626   "&& reload_completed"
19627   [(set (match_dup 0)
19628         (if_then_else:SI (match_op_dup 1 [(match_dup 4) (const_int 0)])
19629                       (match_dup 2)
19630                       (match_dup 3)))]
19631   "operands[0] = gen_lowpart (SImode, operands[0]);
19632    operands[2] = gen_lowpart (SImode, operands[2]);
19633    operands[3] = gen_lowpart (SImode, operands[3]);"
19634   [(set_attr "type" "icmov")
19635    (set_attr "mode" "SI")])
19636
19637 (define_expand "mov<mode>cc"
19638   [(set (match_operand:X87MODEF 0 "register_operand" "")
19639         (if_then_else:X87MODEF
19640           (match_operand 1 "ix86_fp_comparison_operator" "")
19641           (match_operand:X87MODEF 2 "register_operand" "")
19642           (match_operand:X87MODEF 3 "register_operand" "")))]
19643   "(TARGET_80387 && TARGET_CMOVE)
19644    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
19645   "if (ix86_expand_fp_movcc (operands)) DONE; else FAIL;")
19646
19647 (define_insn "*movsfcc_1_387"
19648   [(set (match_operand:SF 0 "register_operand" "=f,f,r,r")
19649         (if_then_else:SF (match_operator 1 "fcmov_comparison_operator"
19650                                 [(reg FLAGS_REG) (const_int 0)])
19651                       (match_operand:SF 2 "nonimmediate_operand" "f,0,rm,0")
19652                       (match_operand:SF 3 "nonimmediate_operand" "0,f,0,rm")))]
19653   "TARGET_80387 && TARGET_CMOVE
19654    && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
19655   "@
19656    fcmov%F1\t{%2, %0|%0, %2}
19657    fcmov%f1\t{%3, %0|%0, %3}
19658    cmov%O2%C1\t{%2, %0|%0, %2}
19659    cmov%O2%c1\t{%3, %0|%0, %3}"
19660   [(set_attr "type" "fcmov,fcmov,icmov,icmov")
19661    (set_attr "mode" "SF,SF,SI,SI")])
19662
19663 (define_insn "*movdfcc_1"
19664   [(set (match_operand:DF 0 "register_operand" "=f,f,&r,&r")
19665         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator"
19666                                 [(reg FLAGS_REG) (const_int 0)])
19667                       (match_operand:DF 2 "nonimmediate_operand" "f,0,rm,0")
19668                       (match_operand:DF 3 "nonimmediate_operand" "0,f,0,rm")))]
19669   "!TARGET_64BIT && TARGET_80387 && TARGET_CMOVE
19670    && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
19671   "@
19672    fcmov%F1\t{%2, %0|%0, %2}
19673    fcmov%f1\t{%3, %0|%0, %3}
19674    #
19675    #"
19676   [(set_attr "type" "fcmov,fcmov,multi,multi")
19677    (set_attr "mode" "DF")])
19678
19679 (define_insn "*movdfcc_1_rex64"
19680   [(set (match_operand:DF 0 "register_operand" "=f,f,r,r")
19681         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator"
19682                                 [(reg FLAGS_REG) (const_int 0)])
19683                       (match_operand:DF 2 "nonimmediate_operand" "f,0,rm,0")
19684                       (match_operand:DF 3 "nonimmediate_operand" "0,f,0,rm")))]
19685   "TARGET_64BIT && TARGET_80387 && TARGET_CMOVE
19686    && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
19687   "@
19688    fcmov%F1\t{%2, %0|%0, %2}
19689    fcmov%f1\t{%3, %0|%0, %3}
19690    cmov%O2%C1\t{%2, %0|%0, %2}
19691    cmov%O2%c1\t{%3, %0|%0, %3}"
19692   [(set_attr "type" "fcmov,fcmov,icmov,icmov")
19693    (set_attr "mode" "DF")])
19694
19695 (define_split
19696   [(set (match_operand:DF 0 "register_and_not_any_fp_reg_operand" "")
19697         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator"
19698                                 [(match_operand 4 "flags_reg_operand" "")
19699                                  (const_int 0)])
19700                       (match_operand:DF 2 "nonimmediate_operand" "")
19701                       (match_operand:DF 3 "nonimmediate_operand" "")))]
19702   "!TARGET_64BIT && reload_completed"
19703   [(set (match_dup 2)
19704         (if_then_else:SI (match_op_dup 1 [(match_dup 4) (const_int 0)])
19705                       (match_dup 5)
19706                       (match_dup 6)))
19707    (set (match_dup 3)
19708         (if_then_else:SI (match_op_dup 1 [(match_dup 4) (const_int 0)])
19709                       (match_dup 7)
19710                       (match_dup 8)))]
19711   "split_di (&operands[2], 2, &operands[5], &operands[7]);
19712    split_di (&operands[0], 1, &operands[2], &operands[3]);")
19713
19714 (define_insn "*movxfcc_1"
19715   [(set (match_operand:XF 0 "register_operand" "=f,f")
19716         (if_then_else:XF (match_operator 1 "fcmov_comparison_operator"
19717                                 [(reg FLAGS_REG) (const_int 0)])
19718                       (match_operand:XF 2 "register_operand" "f,0")
19719                       (match_operand:XF 3 "register_operand" "0,f")))]
19720   "TARGET_80387 && TARGET_CMOVE"
19721   "@
19722    fcmov%F1\t{%2, %0|%0, %2}
19723    fcmov%f1\t{%3, %0|%0, %3}"
19724   [(set_attr "type" "fcmov")
19725    (set_attr "mode" "XF")])
19726
19727 ;; These versions of the min/max patterns are intentionally ignorant of
19728 ;; their behavior wrt -0.0 and NaN (via the commutative operand mark).
19729 ;; Since both the tree-level MAX_EXPR and the rtl-level SMAX operator
19730 ;; are undefined in this condition, we're certain this is correct.
19731
19732 (define_insn "*avx_<code><mode>3"
19733   [(set (match_operand:MODEF 0 "register_operand" "=x")
19734         (smaxmin:MODEF
19735           (match_operand:MODEF 1 "nonimmediate_operand" "%x")
19736           (match_operand:MODEF 2 "nonimmediate_operand" "xm")))]
19737   "AVX_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
19738   "v<maxminfprefix>s<ssemodefsuffix>\t{%2, %1, %0|%0, %1, %2}"
19739   [(set_attr "type" "sseadd")
19740    (set_attr "prefix" "vex")
19741    (set_attr "mode" "<MODE>")])
19742
19743 (define_insn "<code><mode>3"
19744   [(set (match_operand:MODEF 0 "register_operand" "=x")
19745         (smaxmin:MODEF
19746           (match_operand:MODEF 1 "nonimmediate_operand" "%0")
19747           (match_operand:MODEF 2 "nonimmediate_operand" "xm")))]
19748   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
19749   "<maxminfprefix>s<ssemodefsuffix>\t{%2, %0|%0, %2}"
19750   [(set_attr "type" "sseadd")
19751    (set_attr "mode" "<MODE>")])
19752
19753 ;; These versions of the min/max patterns implement exactly the operations
19754 ;;   min = (op1 < op2 ? op1 : op2)
19755 ;;   max = (!(op1 < op2) ? op1 : op2)
19756 ;; Their operands are not commutative, and thus they may be used in the
19757 ;; presence of -0.0 and NaN.
19758
19759 (define_insn "*avx_ieee_smin<mode>3"
19760   [(set (match_operand:MODEF 0 "register_operand" "=x")
19761         (unspec:MODEF
19762           [(match_operand:MODEF 1 "register_operand" "x")
19763            (match_operand:MODEF 2 "nonimmediate_operand" "xm")]
19764          UNSPEC_IEEE_MIN))]
19765   "AVX_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
19766   "vmins<ssemodefsuffix>\t{%2, %1, %0|%0, %1, %2}"
19767   [(set_attr "type" "sseadd")
19768    (set_attr "prefix" "vex")
19769    (set_attr "mode" "<MODE>")])
19770
19771 (define_insn "*ieee_smin<mode>3"
19772   [(set (match_operand:MODEF 0 "register_operand" "=x")
19773         (unspec:MODEF
19774           [(match_operand:MODEF 1 "register_operand" "0")
19775            (match_operand:MODEF 2 "nonimmediate_operand" "xm")]
19776          UNSPEC_IEEE_MIN))]
19777   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
19778   "mins<ssemodefsuffix>\t{%2, %0|%0, %2}"
19779   [(set_attr "type" "sseadd")
19780    (set_attr "mode" "<MODE>")])
19781
19782 (define_insn "*avx_ieee_smax<mode>3"
19783   [(set (match_operand:MODEF 0 "register_operand" "=x")
19784         (unspec:MODEF
19785           [(match_operand:MODEF 1 "register_operand" "0")
19786            (match_operand:MODEF 2 "nonimmediate_operand" "xm")]
19787          UNSPEC_IEEE_MAX))]
19788   "AVX_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
19789   "vmaxs<ssemodefsuffix>\t{%2, %1, %0|%0, %1, %2}"
19790   [(set_attr "type" "sseadd")
19791    (set_attr "prefix" "vex")
19792    (set_attr "mode" "<MODE>")])
19793
19794 (define_insn "*ieee_smax<mode>3"
19795   [(set (match_operand:MODEF 0 "register_operand" "=x")
19796         (unspec:MODEF
19797           [(match_operand:MODEF 1 "register_operand" "0")
19798            (match_operand:MODEF 2 "nonimmediate_operand" "xm")]
19799          UNSPEC_IEEE_MAX))]
19800   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
19801   "maxs<ssemodefsuffix>\t{%2, %0|%0, %2}"
19802   [(set_attr "type" "sseadd")
19803    (set_attr "mode" "<MODE>")])
19804
19805 ;; Make two stack loads independent:
19806 ;;   fld aa              fld aa
19807 ;;   fld %st(0)     ->   fld bb
19808 ;;   fmul bb             fmul %st(1), %st
19809 ;;
19810 ;; Actually we only match the last two instructions for simplicity.
19811 (define_peephole2
19812   [(set (match_operand 0 "fp_register_operand" "")
19813         (match_operand 1 "fp_register_operand" ""))
19814    (set (match_dup 0)
19815         (match_operator 2 "binary_fp_operator"
19816            [(match_dup 0)
19817             (match_operand 3 "memory_operand" "")]))]
19818   "REGNO (operands[0]) != REGNO (operands[1])"
19819   [(set (match_dup 0) (match_dup 3))
19820    (set (match_dup 0) (match_dup 4))]
19821
19822   ;; The % modifier is not operational anymore in peephole2's, so we have to
19823   ;; swap the operands manually in the case of addition and multiplication.
19824   "if (COMMUTATIVE_ARITH_P (operands[2]))
19825      operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[2]), GET_MODE (operands[2]),
19826                                  operands[0], operands[1]);
19827    else
19828      operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[2]), GET_MODE (operands[2]),
19829                                  operands[1], operands[0]);")
19830
19831 ;; Conditional addition patterns
19832 (define_expand "add<mode>cc"
19833   [(match_operand:SWI 0 "register_operand" "")
19834    (match_operand 1 "comparison_operator" "")
19835    (match_operand:SWI 2 "register_operand" "")
19836    (match_operand:SWI 3 "const_int_operand" "")]
19837   ""
19838   "if (ix86_expand_int_addcc (operands)) DONE; else FAIL;")
19839
19840 \f
19841 ;; Misc patterns (?)
19842
19843 ;; This pattern exists to put a dependency on all ebp-based memory accesses.
19844 ;; Otherwise there will be nothing to keep
19845 ;;
19846 ;; [(set (reg ebp) (reg esp))]
19847 ;; [(set (reg esp) (plus (reg esp) (const_int -160000)))
19848 ;;  (clobber (eflags)]
19849 ;; [(set (mem (plus (reg ebp) (const_int -160000))) (const_int 0))]
19850 ;;
19851 ;; in proper program order.
19852 (define_insn "pro_epilogue_adjust_stack_1"
19853   [(set (match_operand:SI 0 "register_operand" "=r,r")
19854         (plus:SI (match_operand:SI 1 "register_operand" "0,r")
19855                  (match_operand:SI 2 "immediate_operand" "i,i")))
19856    (clobber (reg:CC FLAGS_REG))
19857    (clobber (mem:BLK (scratch)))]
19858   "!TARGET_64BIT"
19859 {
19860   switch (get_attr_type (insn))
19861     {
19862     case TYPE_IMOV:
19863       return "mov{l}\t{%1, %0|%0, %1}";
19864
19865     case TYPE_ALU:
19866       if (CONST_INT_P (operands[2])
19867           && (INTVAL (operands[2]) == 128
19868               || (INTVAL (operands[2]) < 0
19869                   && INTVAL (operands[2]) != -128)))
19870         {
19871           operands[2] = GEN_INT (-INTVAL (operands[2]));
19872           return "sub{l}\t{%2, %0|%0, %2}";
19873         }
19874       return "add{l}\t{%2, %0|%0, %2}";
19875
19876     case TYPE_LEA:
19877       operands[2] = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
19878       return "lea{l}\t{%a2, %0|%0, %a2}";
19879
19880     default:
19881       gcc_unreachable ();
19882     }
19883 }
19884   [(set (attr "type")
19885         (cond [(and (eq_attr "alternative" "0") 
19886                     (eq (symbol_ref "TARGET_OPT_AGU") (const_int 0)))
19887                  (const_string "alu")
19888                (match_operand:SI 2 "const0_operand" "")
19889                  (const_string "imov")
19890               ]
19891               (const_string "lea")))
19892    (set (attr "length_immediate")
19893         (cond [(eq_attr "type" "imov")
19894                  (const_string "0")
19895                (and (eq_attr "type" "alu")
19896                     (match_operand 2 "const128_operand" ""))
19897                  (const_string "1")
19898               ]
19899               (const_string "*")))
19900    (set_attr "mode" "SI")])
19901
19902 (define_insn "pro_epilogue_adjust_stack_rex64"
19903   [(set (match_operand:DI 0 "register_operand" "=r,r")
19904         (plus:DI (match_operand:DI 1 "register_operand" "0,r")
19905                  (match_operand:DI 2 "x86_64_immediate_operand" "e,e")))
19906    (clobber (reg:CC FLAGS_REG))
19907    (clobber (mem:BLK (scratch)))]
19908   "TARGET_64BIT"
19909 {
19910   switch (get_attr_type (insn))
19911     {
19912     case TYPE_IMOV:
19913       return "mov{q}\t{%1, %0|%0, %1}";
19914
19915     case TYPE_ALU:
19916       if (CONST_INT_P (operands[2])
19917           /* Avoid overflows.  */
19918           && ((INTVAL (operands[2]) & ((((unsigned int) 1) << 31) - 1)))
19919           && (INTVAL (operands[2]) == 128
19920               || (INTVAL (operands[2]) < 0
19921                   && INTVAL (operands[2]) != -128)))
19922         {
19923           operands[2] = GEN_INT (-INTVAL (operands[2]));
19924           return "sub{q}\t{%2, %0|%0, %2}";
19925         }
19926       return "add{q}\t{%2, %0|%0, %2}";
19927
19928     case TYPE_LEA:
19929       operands[2] = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
19930       return "lea{q}\t{%a2, %0|%0, %a2}";
19931
19932     default:
19933       gcc_unreachable ();
19934     }
19935 }
19936   [(set (attr "type")
19937         (cond [(and (eq_attr "alternative" "0")
19938                     (eq (symbol_ref "TARGET_OPT_AGU") (const_int 0)))
19939                  (const_string "alu")
19940                (match_operand:DI 2 "const0_operand" "")
19941                  (const_string "imov")
19942               ]
19943               (const_string "lea")))
19944    (set (attr "length_immediate")
19945         (cond [(eq_attr "type" "imov")
19946                  (const_string "0")
19947                (and (eq_attr "type" "alu")
19948                     (match_operand 2 "const128_operand" ""))
19949                  (const_string "1")
19950               ]
19951               (const_string "*")))
19952    (set_attr "mode" "DI")])
19953
19954 (define_insn "pro_epilogue_adjust_stack_rex64_2"
19955   [(set (match_operand:DI 0 "register_operand" "=r,r")
19956         (plus:DI (match_operand:DI 1 "register_operand" "0,r")
19957                  (match_operand:DI 3 "immediate_operand" "i,i")))
19958    (use (match_operand:DI 2 "register_operand" "r,r"))
19959    (clobber (reg:CC FLAGS_REG))
19960    (clobber (mem:BLK (scratch)))]
19961   "TARGET_64BIT"
19962 {
19963   switch (get_attr_type (insn))
19964     {
19965     case TYPE_ALU:
19966       return "add{q}\t{%2, %0|%0, %2}";
19967
19968     case TYPE_LEA:
19969       operands[2] = gen_rtx_PLUS (DImode, operands[1], operands[2]);
19970       return "lea{q}\t{%a2, %0|%0, %a2}";
19971
19972     default:
19973       gcc_unreachable ();
19974     }
19975 }
19976   [(set_attr "type" "alu,lea")
19977    (set_attr "mode" "DI")])
19978
19979 (define_insn "allocate_stack_worker_32"
19980   [(set (match_operand:SI 0 "register_operand" "=a")
19981         (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "0")]
19982                             UNSPECV_STACK_PROBE))
19983    (set (reg:SI SP_REG) (minus:SI (reg:SI SP_REG) (match_dup 1)))
19984    (clobber (reg:CC FLAGS_REG))]
19985   "!TARGET_64BIT && TARGET_STACK_PROBE"
19986   "call\t___chkstk"
19987   [(set_attr "type" "multi")
19988    (set_attr "length" "5")])
19989
19990 (define_insn "allocate_stack_worker_64"
19991   [(set (match_operand:DI 0 "register_operand" "=a")
19992         (unspec_volatile:DI [(match_operand:DI 1 "register_operand" "0")]
19993                             UNSPECV_STACK_PROBE))
19994    (set (reg:DI SP_REG) (minus:DI (reg:DI SP_REG) (match_dup 1)))
19995    (clobber (reg:DI R10_REG))
19996    (clobber (reg:DI R11_REG))
19997    (clobber (reg:CC FLAGS_REG))]
19998   "TARGET_64BIT && TARGET_STACK_PROBE"
19999   "call\t___chkstk"
20000   [(set_attr "type" "multi")
20001    (set_attr "length" "5")])
20002
20003 (define_expand "allocate_stack"
20004   [(match_operand 0 "register_operand" "")
20005    (match_operand 1 "general_operand" "")]
20006   "TARGET_STACK_PROBE"
20007 {
20008   rtx x;
20009
20010 #ifndef CHECK_STACK_LIMIT
20011 #define CHECK_STACK_LIMIT 0
20012 #endif
20013
20014   if (CHECK_STACK_LIMIT && CONST_INT_P (operands[1])
20015       && INTVAL (operands[1]) < CHECK_STACK_LIMIT)
20016     {
20017       x = expand_simple_binop (Pmode, MINUS, stack_pointer_rtx, operands[1],
20018                                stack_pointer_rtx, 0, OPTAB_DIRECT);
20019       if (x != stack_pointer_rtx)
20020         emit_move_insn (stack_pointer_rtx, x);
20021     }
20022   else
20023     {
20024       x = copy_to_mode_reg (Pmode, operands[1]);
20025       if (TARGET_64BIT)
20026         x = gen_allocate_stack_worker_64 (x, x);
20027       else
20028         x = gen_allocate_stack_worker_32 (x, x);
20029       emit_insn (x);
20030     }
20031
20032   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
20033   DONE;
20034 })
20035
20036 (define_expand "builtin_setjmp_receiver"
20037   [(label_ref (match_operand 0 "" ""))]
20038   "!TARGET_64BIT && flag_pic"
20039 {
20040 #if TARGET_MACHO
20041   if (TARGET_MACHO)
20042     {
20043       rtx xops[3];
20044       rtx picreg = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
20045       rtx label_rtx = gen_label_rtx ();
20046       emit_insn (gen_set_got_labelled (pic_offset_table_rtx, label_rtx));
20047       xops[0] = xops[1] = picreg;
20048       xops[2] = machopic_gen_offset (gen_rtx_LABEL_REF (SImode, label_rtx));
20049       ix86_expand_binary_operator (MINUS, SImode, xops);
20050     }
20051   else
20052 #endif
20053     emit_insn (gen_set_got (pic_offset_table_rtx));
20054   DONE;
20055 })
20056 \f
20057 ;; Avoid redundant prefixes by splitting HImode arithmetic to SImode.
20058
20059 (define_split
20060   [(set (match_operand 0 "register_operand" "")
20061         (match_operator 3 "promotable_binary_operator"
20062            [(match_operand 1 "register_operand" "")
20063             (match_operand 2 "aligned_operand" "")]))
20064    (clobber (reg:CC FLAGS_REG))]
20065   "! TARGET_PARTIAL_REG_STALL && reload_completed
20066    && ((GET_MODE (operands[0]) == HImode
20067         && ((optimize_function_for_speed_p (cfun) && !TARGET_FAST_PREFIX)
20068             /* ??? next two lines just !satisfies_constraint_K (...) */
20069             || !CONST_INT_P (operands[2])
20070             || satisfies_constraint_K (operands[2])))
20071        || (GET_MODE (operands[0]) == QImode
20072            && (TARGET_PROMOTE_QImode || optimize_function_for_size_p (cfun))))"
20073   [(parallel [(set (match_dup 0)
20074                    (match_op_dup 3 [(match_dup 1) (match_dup 2)]))
20075               (clobber (reg:CC FLAGS_REG))])]
20076   "operands[0] = gen_lowpart (SImode, operands[0]);
20077    operands[1] = gen_lowpart (SImode, operands[1]);
20078    if (GET_CODE (operands[3]) != ASHIFT)
20079      operands[2] = gen_lowpart (SImode, operands[2]);
20080    PUT_MODE (operands[3], SImode);")
20081
20082 ; Promote the QImode tests, as i386 has encoding of the AND
20083 ; instruction with 32-bit sign-extended immediate and thus the
20084 ; instruction size is unchanged, except in the %eax case for
20085 ; which it is increased by one byte, hence the ! optimize_size.
20086 (define_split
20087   [(set (match_operand 0 "flags_reg_operand" "")
20088         (match_operator 2 "compare_operator"
20089           [(and (match_operand 3 "aligned_operand" "")
20090                 (match_operand 4 "const_int_operand" ""))
20091            (const_int 0)]))
20092    (set (match_operand 1 "register_operand" "")
20093         (and (match_dup 3) (match_dup 4)))]
20094   "! TARGET_PARTIAL_REG_STALL && reload_completed
20095    && optimize_insn_for_speed_p ()
20096    && ((GET_MODE (operands[1]) == HImode && ! TARGET_FAST_PREFIX)
20097        || (GET_MODE (operands[1]) == QImode && TARGET_PROMOTE_QImode))
20098    /* Ensure that the operand will remain sign-extended immediate.  */
20099    && ix86_match_ccmode (insn, INTVAL (operands[4]) >= 0 ? CCNOmode : CCZmode)"
20100   [(parallel [(set (match_dup 0)
20101                    (match_op_dup 2 [(and:SI (match_dup 3) (match_dup 4))
20102                                     (const_int 0)]))
20103               (set (match_dup 1)
20104                    (and:SI (match_dup 3) (match_dup 4)))])]
20105 {
20106   operands[4]
20107     = gen_int_mode (INTVAL (operands[4])
20108                     & GET_MODE_MASK (GET_MODE (operands[1])), SImode);
20109   operands[1] = gen_lowpart (SImode, operands[1]);
20110   operands[3] = gen_lowpart (SImode, operands[3]);
20111 })
20112
20113 ; Don't promote the QImode tests, as i386 doesn't have encoding of
20114 ; the TEST instruction with 32-bit sign-extended immediate and thus
20115 ; the instruction size would at least double, which is not what we
20116 ; want even with ! optimize_size.
20117 (define_split
20118   [(set (match_operand 0 "flags_reg_operand" "")
20119         (match_operator 1 "compare_operator"
20120           [(and (match_operand:HI 2 "aligned_operand" "")
20121                 (match_operand:HI 3 "const_int_operand" ""))
20122            (const_int 0)]))]
20123   "! TARGET_PARTIAL_REG_STALL && reload_completed
20124    && ! TARGET_FAST_PREFIX
20125    && optimize_insn_for_speed_p ()
20126    /* Ensure that the operand will remain sign-extended immediate.  */
20127    && ix86_match_ccmode (insn, INTVAL (operands[3]) >= 0 ? CCNOmode : CCZmode)"
20128   [(set (match_dup 0)
20129         (match_op_dup 1 [(and:SI (match_dup 2) (match_dup 3))
20130                          (const_int 0)]))]
20131 {
20132   operands[3]
20133     = gen_int_mode (INTVAL (operands[3])
20134                     & GET_MODE_MASK (GET_MODE (operands[2])), SImode);
20135   operands[2] = gen_lowpart (SImode, operands[2]);
20136 })
20137
20138 (define_split
20139   [(set (match_operand 0 "register_operand" "")
20140         (neg (match_operand 1 "register_operand" "")))
20141    (clobber (reg:CC FLAGS_REG))]
20142   "! TARGET_PARTIAL_REG_STALL && reload_completed
20143    && (GET_MODE (operands[0]) == HImode
20144        || (GET_MODE (operands[0]) == QImode
20145            && (TARGET_PROMOTE_QImode
20146                || optimize_insn_for_size_p ())))"
20147   [(parallel [(set (match_dup 0)
20148                    (neg:SI (match_dup 1)))
20149               (clobber (reg:CC FLAGS_REG))])]
20150   "operands[0] = gen_lowpart (SImode, operands[0]);
20151    operands[1] = gen_lowpart (SImode, operands[1]);")
20152
20153 (define_split
20154   [(set (match_operand 0 "register_operand" "")
20155         (not (match_operand 1 "register_operand" "")))]
20156   "! TARGET_PARTIAL_REG_STALL && reload_completed
20157    && (GET_MODE (operands[0]) == HImode
20158        || (GET_MODE (operands[0]) == QImode
20159            && (TARGET_PROMOTE_QImode
20160                || optimize_insn_for_size_p ())))"
20161   [(set (match_dup 0)
20162         (not:SI (match_dup 1)))]
20163   "operands[0] = gen_lowpart (SImode, operands[0]);
20164    operands[1] = gen_lowpart (SImode, operands[1]);")
20165
20166 (define_split
20167   [(set (match_operand 0 "register_operand" "")
20168         (if_then_else (match_operator 1 "comparison_operator"
20169                                 [(reg FLAGS_REG) (const_int 0)])
20170                       (match_operand 2 "register_operand" "")
20171                       (match_operand 3 "register_operand" "")))]
20172   "! TARGET_PARTIAL_REG_STALL && TARGET_CMOVE
20173    && (GET_MODE (operands[0]) == HImode
20174        || (GET_MODE (operands[0]) == QImode
20175            && (TARGET_PROMOTE_QImode
20176                || optimize_insn_for_size_p ())))"
20177   [(set (match_dup 0)
20178         (if_then_else:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
20179   "operands[0] = gen_lowpart (SImode, operands[0]);
20180    operands[2] = gen_lowpart (SImode, operands[2]);
20181    operands[3] = gen_lowpart (SImode, operands[3]);")
20182
20183 \f
20184 ;; RTL Peephole optimizations, run before sched2.  These primarily look to
20185 ;; transform a complex memory operation into two memory to register operations.
20186
20187 ;; Don't push memory operands
20188 (define_peephole2
20189   [(set (match_operand:SI 0 "push_operand" "")
20190         (match_operand:SI 1 "memory_operand" ""))
20191    (match_scratch:SI 2 "r")]
20192   "optimize_insn_for_speed_p () && !TARGET_PUSH_MEMORY
20193    && !RTX_FRAME_RELATED_P (peep2_next_insn (0))"
20194   [(set (match_dup 2) (match_dup 1))
20195    (set (match_dup 0) (match_dup 2))]
20196   "")
20197
20198 (define_peephole2
20199   [(set (match_operand:DI 0 "push_operand" "")
20200         (match_operand:DI 1 "memory_operand" ""))
20201    (match_scratch:DI 2 "r")]
20202   "optimize_insn_for_speed_p () && !TARGET_PUSH_MEMORY
20203    && !RTX_FRAME_RELATED_P (peep2_next_insn (0))"
20204   [(set (match_dup 2) (match_dup 1))
20205    (set (match_dup 0) (match_dup 2))]
20206   "")
20207
20208 ;; We need to handle SFmode only, because DFmode and XFmode is split to
20209 ;; SImode pushes.
20210 (define_peephole2
20211   [(set (match_operand:SF 0 "push_operand" "")
20212         (match_operand:SF 1 "memory_operand" ""))
20213    (match_scratch:SF 2 "r")]
20214   "optimize_insn_for_speed_p () && !TARGET_PUSH_MEMORY
20215    && !RTX_FRAME_RELATED_P (peep2_next_insn (0))"
20216   [(set (match_dup 2) (match_dup 1))
20217    (set (match_dup 0) (match_dup 2))]
20218   "")
20219
20220 (define_peephole2
20221   [(set (match_operand:HI 0 "push_operand" "")
20222         (match_operand:HI 1 "memory_operand" ""))
20223    (match_scratch:HI 2 "r")]
20224   "optimize_insn_for_speed_p () && !TARGET_PUSH_MEMORY
20225    && !RTX_FRAME_RELATED_P (peep2_next_insn (0))"
20226   [(set (match_dup 2) (match_dup 1))
20227    (set (match_dup 0) (match_dup 2))]
20228   "")
20229
20230 (define_peephole2
20231   [(set (match_operand:QI 0 "push_operand" "")
20232         (match_operand:QI 1 "memory_operand" ""))
20233    (match_scratch:QI 2 "q")]
20234   "optimize_insn_for_speed_p () && !TARGET_PUSH_MEMORY
20235    && !RTX_FRAME_RELATED_P (peep2_next_insn (0))"
20236   [(set (match_dup 2) (match_dup 1))
20237    (set (match_dup 0) (match_dup 2))]
20238   "")
20239
20240 ;; Don't move an immediate directly to memory when the instruction
20241 ;; gets too big.
20242 (define_peephole2
20243   [(match_scratch:SI 1 "r")
20244    (set (match_operand:SI 0 "memory_operand" "")
20245         (const_int 0))]
20246   "optimize_insn_for_speed_p ()
20247    && ! TARGET_USE_MOV0
20248    && TARGET_SPLIT_LONG_MOVES
20249    && get_attr_length (insn) >= ix86_cur_cost ()->large_insn
20250    && peep2_regno_dead_p (0, FLAGS_REG)"
20251   [(parallel [(set (match_dup 1) (const_int 0))
20252               (clobber (reg:CC FLAGS_REG))])
20253    (set (match_dup 0) (match_dup 1))]
20254   "")
20255
20256 (define_peephole2
20257   [(match_scratch:HI 1 "r")
20258    (set (match_operand:HI 0 "memory_operand" "")
20259         (const_int 0))]
20260   "optimize_insn_for_speed_p ()
20261    && ! TARGET_USE_MOV0
20262    && TARGET_SPLIT_LONG_MOVES
20263    && get_attr_length (insn) >= ix86_cur_cost ()->large_insn
20264    && peep2_regno_dead_p (0, FLAGS_REG)"
20265   [(parallel [(set (match_dup 2) (const_int 0))
20266               (clobber (reg:CC FLAGS_REG))])
20267    (set (match_dup 0) (match_dup 1))]
20268   "operands[2] = gen_lowpart (SImode, operands[1]);")
20269
20270 (define_peephole2
20271   [(match_scratch:QI 1 "q")
20272    (set (match_operand:QI 0 "memory_operand" "")
20273         (const_int 0))]
20274   "optimize_insn_for_speed_p ()
20275    && ! TARGET_USE_MOV0
20276    && TARGET_SPLIT_LONG_MOVES
20277    && get_attr_length (insn) >= ix86_cur_cost ()->large_insn
20278    && peep2_regno_dead_p (0, FLAGS_REG)"
20279   [(parallel [(set (match_dup 2) (const_int 0))
20280               (clobber (reg:CC FLAGS_REG))])
20281    (set (match_dup 0) (match_dup 1))]
20282   "operands[2] = gen_lowpart (SImode, operands[1]);")
20283
20284 (define_peephole2
20285   [(match_scratch:SI 2 "r")
20286    (set (match_operand:SI 0 "memory_operand" "")
20287         (match_operand:SI 1 "immediate_operand" ""))]
20288   "optimize_insn_for_speed_p ()
20289    && TARGET_SPLIT_LONG_MOVES
20290    && get_attr_length (insn) >= ix86_cur_cost ()->large_insn"
20291   [(set (match_dup 2) (match_dup 1))
20292    (set (match_dup 0) (match_dup 2))]
20293   "")
20294
20295 (define_peephole2
20296   [(match_scratch:HI 2 "r")
20297    (set (match_operand:HI 0 "memory_operand" "")
20298         (match_operand:HI 1 "immediate_operand" ""))]
20299   "optimize_insn_for_speed_p ()
20300    && TARGET_SPLIT_LONG_MOVES
20301    && get_attr_length (insn) >= ix86_cur_cost ()->large_insn"
20302   [(set (match_dup 2) (match_dup 1))
20303    (set (match_dup 0) (match_dup 2))]
20304   "")
20305
20306 (define_peephole2
20307   [(match_scratch:QI 2 "q")
20308    (set (match_operand:QI 0 "memory_operand" "")
20309         (match_operand:QI 1 "immediate_operand" ""))]
20310   "optimize_insn_for_speed_p ()
20311    && TARGET_SPLIT_LONG_MOVES
20312    && get_attr_length (insn) >= ix86_cur_cost ()->large_insn"
20313   [(set (match_dup 2) (match_dup 1))
20314    (set (match_dup 0) (match_dup 2))]
20315   "")
20316
20317 ;; Don't compare memory with zero, load and use a test instead.
20318 (define_peephole2
20319   [(set (match_operand 0 "flags_reg_operand" "")
20320         (match_operator 1 "compare_operator"
20321           [(match_operand:SI 2 "memory_operand" "")
20322            (const_int 0)]))
20323    (match_scratch:SI 3 "r")]
20324   "optimize_insn_for_speed_p () && ix86_match_ccmode (insn, CCNOmode)"
20325   [(set (match_dup 3) (match_dup 2))
20326    (set (match_dup 0) (match_op_dup 1 [(match_dup 3) (const_int 0)]))]
20327   "")
20328
20329 ;; NOT is not pairable on Pentium, while XOR is, but one byte longer.
20330 ;; Don't split NOTs with a displacement operand, because resulting XOR
20331 ;; will not be pairable anyway.
20332 ;;
20333 ;; On AMD K6, NOT is vector decoded with memory operand that cannot be
20334 ;; represented using a modRM byte.  The XOR replacement is long decoded,
20335 ;; so this split helps here as well.
20336 ;;
20337 ;; Note: Can't do this as a regular split because we can't get proper
20338 ;; lifetime information then.
20339
20340 (define_peephole2
20341   [(set (match_operand:SI 0 "nonimmediate_operand" "")
20342         (not:SI (match_operand:SI 1 "nonimmediate_operand" "")))]
20343   "optimize_insn_for_speed_p ()
20344    && ((TARGET_NOT_UNPAIRABLE
20345         && (!MEM_P (operands[0])
20346             || !memory_displacement_operand (operands[0], SImode)))
20347        || (TARGET_NOT_VECTORMODE && long_memory_operand (operands[0], SImode)))
20348    && peep2_regno_dead_p (0, FLAGS_REG)"
20349   [(parallel [(set (match_dup 0)
20350                    (xor:SI (match_dup 1) (const_int -1)))
20351               (clobber (reg:CC FLAGS_REG))])]
20352   "")
20353
20354 (define_peephole2
20355   [(set (match_operand:HI 0 "nonimmediate_operand" "")
20356         (not:HI (match_operand:HI 1 "nonimmediate_operand" "")))]
20357   "optimize_insn_for_speed_p ()
20358    && ((TARGET_NOT_UNPAIRABLE
20359         && (!MEM_P (operands[0])
20360             || !memory_displacement_operand (operands[0], HImode)))
20361        || (TARGET_NOT_VECTORMODE && long_memory_operand (operands[0], HImode)))
20362    && peep2_regno_dead_p (0, FLAGS_REG)"
20363   [(parallel [(set (match_dup 0)
20364                    (xor:HI (match_dup 1) (const_int -1)))
20365               (clobber (reg:CC FLAGS_REG))])]
20366   "")
20367
20368 (define_peephole2
20369   [(set (match_operand:QI 0 "nonimmediate_operand" "")
20370         (not:QI (match_operand:QI 1 "nonimmediate_operand" "")))]
20371   "optimize_insn_for_speed_p ()
20372    && ((TARGET_NOT_UNPAIRABLE
20373         && (!MEM_P (operands[0])
20374             || !memory_displacement_operand (operands[0], QImode)))
20375        || (TARGET_NOT_VECTORMODE && long_memory_operand (operands[0], QImode)))
20376    && peep2_regno_dead_p (0, FLAGS_REG)"
20377   [(parallel [(set (match_dup 0)
20378                    (xor:QI (match_dup 1) (const_int -1)))
20379               (clobber (reg:CC FLAGS_REG))])]
20380   "")
20381
20382 ;; Non pairable "test imm, reg" instructions can be translated to
20383 ;; "and imm, reg" if reg dies.  The "and" form is also shorter (one
20384 ;; byte opcode instead of two, have a short form for byte operands),
20385 ;; so do it for other CPUs as well.  Given that the value was dead,
20386 ;; this should not create any new dependencies.  Pass on the sub-word
20387 ;; versions if we're concerned about partial register stalls.
20388
20389 (define_peephole2
20390   [(set (match_operand 0 "flags_reg_operand" "")
20391         (match_operator 1 "compare_operator"
20392           [(and:SI (match_operand:SI 2 "register_operand" "")
20393                    (match_operand:SI 3 "immediate_operand" ""))
20394            (const_int 0)]))]
20395   "ix86_match_ccmode (insn, CCNOmode)
20396    && (true_regnum (operands[2]) != AX_REG
20397        || satisfies_constraint_K (operands[3]))
20398    && peep2_reg_dead_p (1, operands[2])"
20399   [(parallel
20400      [(set (match_dup 0)
20401            (match_op_dup 1 [(and:SI (match_dup 2) (match_dup 3))
20402                             (const_int 0)]))
20403       (set (match_dup 2)
20404            (and:SI (match_dup 2) (match_dup 3)))])]
20405   "")
20406
20407 ;; We don't need to handle HImode case, because it will be promoted to SImode
20408 ;; on ! TARGET_PARTIAL_REG_STALL
20409
20410 (define_peephole2
20411   [(set (match_operand 0 "flags_reg_operand" "")
20412         (match_operator 1 "compare_operator"
20413           [(and:QI (match_operand:QI 2 "register_operand" "")
20414                    (match_operand:QI 3 "immediate_operand" ""))
20415            (const_int 0)]))]
20416   "! TARGET_PARTIAL_REG_STALL
20417    && ix86_match_ccmode (insn, CCNOmode)
20418    && true_regnum (operands[2]) != AX_REG
20419    && peep2_reg_dead_p (1, operands[2])"
20420   [(parallel
20421      [(set (match_dup 0)
20422            (match_op_dup 1 [(and:QI (match_dup 2) (match_dup 3))
20423                             (const_int 0)]))
20424       (set (match_dup 2)
20425            (and:QI (match_dup 2) (match_dup 3)))])]
20426   "")
20427
20428 (define_peephole2
20429   [(set (match_operand 0 "flags_reg_operand" "")
20430         (match_operator 1 "compare_operator"
20431           [(and:SI
20432              (zero_extract:SI
20433                (match_operand 2 "ext_register_operand" "")
20434                (const_int 8)
20435                (const_int 8))
20436              (match_operand 3 "const_int_operand" ""))
20437            (const_int 0)]))]
20438   "! TARGET_PARTIAL_REG_STALL
20439    && ix86_match_ccmode (insn, CCNOmode)
20440    && true_regnum (operands[2]) != AX_REG
20441    && peep2_reg_dead_p (1, operands[2])"
20442   [(parallel [(set (match_dup 0)
20443                    (match_op_dup 1
20444                      [(and:SI
20445                         (zero_extract:SI
20446                           (match_dup 2)
20447                           (const_int 8)
20448                           (const_int 8))
20449                         (match_dup 3))
20450                       (const_int 0)]))
20451               (set (zero_extract:SI (match_dup 2)
20452                                     (const_int 8)
20453                                     (const_int 8))
20454                    (and:SI
20455                      (zero_extract:SI
20456                        (match_dup 2)
20457                        (const_int 8)
20458                        (const_int 8))
20459                      (match_dup 3)))])]
20460   "")
20461
20462 ;; Don't do logical operations with memory inputs.
20463 (define_peephole2
20464   [(match_scratch:SI 2 "r")
20465    (parallel [(set (match_operand:SI 0 "register_operand" "")
20466                    (match_operator:SI 3 "arith_or_logical_operator"
20467                      [(match_dup 0)
20468                       (match_operand:SI 1 "memory_operand" "")]))
20469               (clobber (reg:CC FLAGS_REG))])]
20470   "optimize_insn_for_speed_p () && ! TARGET_READ_MODIFY"
20471   [(set (match_dup 2) (match_dup 1))
20472    (parallel [(set (match_dup 0)
20473                    (match_op_dup 3 [(match_dup 0) (match_dup 2)]))
20474               (clobber (reg:CC FLAGS_REG))])]
20475   "")
20476
20477 (define_peephole2
20478   [(match_scratch:SI 2 "r")
20479    (parallel [(set (match_operand:SI 0 "register_operand" "")
20480                    (match_operator:SI 3 "arith_or_logical_operator"
20481                      [(match_operand:SI 1 "memory_operand" "")
20482                       (match_dup 0)]))
20483               (clobber (reg:CC FLAGS_REG))])]
20484   "optimize_insn_for_speed_p () && ! TARGET_READ_MODIFY"
20485   [(set (match_dup 2) (match_dup 1))
20486    (parallel [(set (match_dup 0)
20487                    (match_op_dup 3 [(match_dup 2) (match_dup 0)]))
20488               (clobber (reg:CC FLAGS_REG))])]
20489   "")
20490
20491 ;; Prefer Load+RegOp to Mov+MemOp.  Watch out for cases when the memory address
20492 ;; refers to the destination of the load!
20493
20494 (define_peephole2
20495   [(set (match_operand:SI 0 "register_operand" "")
20496         (match_operand:SI 1 "register_operand" ""))
20497    (parallel [(set (match_dup 0)
20498                    (match_operator:SI 3 "commutative_operator"
20499                      [(match_dup 0)
20500                       (match_operand:SI 2 "memory_operand" "")]))
20501               (clobber (reg:CC FLAGS_REG))])]
20502   "REGNO (operands[0]) != REGNO (operands[1])
20503    && GENERAL_REGNO_P (REGNO (operands[0]))
20504    && GENERAL_REGNO_P (REGNO (operands[1]))"
20505   [(set (match_dup 0) (match_dup 4))
20506    (parallel [(set (match_dup 0)
20507                    (match_op_dup 3 [(match_dup 0) (match_dup 1)]))
20508               (clobber (reg:CC FLAGS_REG))])]
20509   "operands[4] = replace_rtx (operands[2], operands[0], operands[1]);")
20510
20511 (define_peephole2
20512   [(set (match_operand 0 "register_operand" "")
20513         (match_operand 1 "register_operand" ""))
20514    (set (match_dup 0)
20515                    (match_operator 3 "commutative_operator"
20516                      [(match_dup 0)
20517                       (match_operand 2 "memory_operand" "")]))]
20518   "REGNO (operands[0]) != REGNO (operands[1])
20519    && ((MMX_REG_P (operands[0]) && MMX_REG_P (operands[1])) 
20520        || (SSE_REG_P (operands[0]) && SSE_REG_P (operands[1])))"
20521   [(set (match_dup 0) (match_dup 2))
20522    (set (match_dup 0)
20523         (match_op_dup 3 [(match_dup 0) (match_dup 1)]))]
20524   "")
20525
20526 ; Don't do logical operations with memory outputs
20527 ;
20528 ; These two don't make sense for PPro/PII -- we're expanding a 4-uop
20529 ; instruction into two 1-uop insns plus a 2-uop insn.  That last has
20530 ; the same decoder scheduling characteristics as the original.
20531
20532 (define_peephole2
20533   [(match_scratch:SI 2 "r")
20534    (parallel [(set (match_operand:SI 0 "memory_operand" "")
20535                    (match_operator:SI 3 "arith_or_logical_operator"
20536                      [(match_dup 0)
20537                       (match_operand:SI 1 "nonmemory_operand" "")]))
20538               (clobber (reg:CC FLAGS_REG))])]
20539   "optimize_insn_for_speed_p () && ! TARGET_READ_MODIFY_WRITE"
20540   [(set (match_dup 2) (match_dup 0))
20541    (parallel [(set (match_dup 2)
20542                    (match_op_dup 3 [(match_dup 2) (match_dup 1)]))
20543               (clobber (reg:CC FLAGS_REG))])
20544    (set (match_dup 0) (match_dup 2))]
20545   "")
20546
20547 (define_peephole2
20548   [(match_scratch:SI 2 "r")
20549    (parallel [(set (match_operand:SI 0 "memory_operand" "")
20550                    (match_operator:SI 3 "arith_or_logical_operator"
20551                      [(match_operand:SI 1 "nonmemory_operand" "")
20552                       (match_dup 0)]))
20553               (clobber (reg:CC FLAGS_REG))])]
20554   "optimize_insn_for_speed_p () && ! TARGET_READ_MODIFY_WRITE"
20555   [(set (match_dup 2) (match_dup 0))
20556    (parallel [(set (match_dup 2)
20557                    (match_op_dup 3 [(match_dup 1) (match_dup 2)]))
20558               (clobber (reg:CC FLAGS_REG))])
20559    (set (match_dup 0) (match_dup 2))]
20560   "")
20561
20562 ;; Attempt to always use XOR for zeroing registers.
20563 (define_peephole2
20564   [(set (match_operand 0 "register_operand" "")
20565         (match_operand 1 "const0_operand" ""))]
20566   "GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
20567    && (! TARGET_USE_MOV0 || optimize_insn_for_size_p ())
20568    && GENERAL_REG_P (operands[0])
20569    && peep2_regno_dead_p (0, FLAGS_REG)"
20570   [(parallel [(set (match_dup 0) (const_int 0))
20571               (clobber (reg:CC FLAGS_REG))])]
20572 {
20573   operands[0] = gen_lowpart (word_mode, operands[0]);
20574 })
20575
20576 (define_peephole2
20577   [(set (strict_low_part (match_operand 0 "register_operand" ""))
20578         (const_int 0))]
20579   "(GET_MODE (operands[0]) == QImode
20580     || GET_MODE (operands[0]) == HImode)
20581    && (! TARGET_USE_MOV0 || optimize_insn_for_size_p ())
20582    && peep2_regno_dead_p (0, FLAGS_REG)"
20583   [(parallel [(set (strict_low_part (match_dup 0)) (const_int 0))
20584               (clobber (reg:CC FLAGS_REG))])])
20585
20586 ;; For HI and SI modes, or $-1,reg is smaller than mov $-1,reg.
20587 (define_peephole2
20588   [(set (match_operand 0 "register_operand" "")
20589         (const_int -1))]
20590   "(GET_MODE (operands[0]) == HImode
20591     || GET_MODE (operands[0]) == SImode
20592     || (GET_MODE (operands[0]) == DImode && TARGET_64BIT))
20593    && (optimize_insn_for_size_p () || TARGET_MOVE_M1_VIA_OR)
20594    && peep2_regno_dead_p (0, FLAGS_REG)"
20595   [(parallel [(set (match_dup 0) (const_int -1))
20596               (clobber (reg:CC FLAGS_REG))])]
20597   "operands[0] = gen_lowpart (GET_MODE (operands[0]) == DImode ? DImode : SImode,
20598                               operands[0]);")
20599
20600 ;; Attempt to convert simple leas to adds. These can be created by
20601 ;; move expanders.
20602 (define_peephole2
20603   [(set (match_operand:SI 0 "register_operand" "")
20604         (plus:SI (match_dup 0)
20605                  (match_operand:SI 1 "nonmemory_operand" "")))]
20606   "peep2_regno_dead_p (0, FLAGS_REG)"
20607   [(parallel [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
20608               (clobber (reg:CC FLAGS_REG))])]
20609   "")
20610
20611 (define_peephole2
20612   [(set (match_operand:SI 0 "register_operand" "")
20613         (subreg:SI (plus:DI (match_operand:DI 1 "register_operand" "")
20614                             (match_operand:DI 2 "nonmemory_operand" "")) 0))]
20615   "peep2_regno_dead_p (0, FLAGS_REG) && REGNO (operands[0]) == REGNO (operands[1])"
20616   [(parallel [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))
20617               (clobber (reg:CC FLAGS_REG))])]
20618   "operands[2] = gen_lowpart (SImode, operands[2]);")
20619
20620 (define_peephole2
20621   [(set (match_operand:DI 0 "register_operand" "")
20622         (plus:DI (match_dup 0)
20623                  (match_operand:DI 1 "x86_64_general_operand" "")))]
20624   "peep2_regno_dead_p (0, FLAGS_REG)"
20625   [(parallel [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
20626               (clobber (reg:CC FLAGS_REG))])]
20627   "")
20628
20629 (define_peephole2
20630   [(set (match_operand:SI 0 "register_operand" "")
20631         (mult:SI (match_dup 0)
20632                  (match_operand:SI 1 "const_int_operand" "")))]
20633   "exact_log2 (INTVAL (operands[1])) >= 0
20634    && peep2_regno_dead_p (0, FLAGS_REG)"
20635   [(parallel [(set (match_dup 0) (ashift:SI (match_dup 0) (match_dup 2)))
20636               (clobber (reg:CC FLAGS_REG))])]
20637   "operands[2] = GEN_INT (exact_log2 (INTVAL (operands[1])));")
20638
20639 (define_peephole2
20640   [(set (match_operand:DI 0 "register_operand" "")
20641         (mult:DI (match_dup 0)
20642                  (match_operand:DI 1 "const_int_operand" "")))]
20643   "exact_log2 (INTVAL (operands[1])) >= 0
20644    && peep2_regno_dead_p (0, FLAGS_REG)"
20645   [(parallel [(set (match_dup 0) (ashift:DI (match_dup 0) (match_dup 2)))
20646               (clobber (reg:CC FLAGS_REG))])]
20647   "operands[2] = GEN_INT (exact_log2 (INTVAL (operands[1])));")
20648
20649 (define_peephole2
20650   [(set (match_operand:SI 0 "register_operand" "")
20651         (subreg:SI (mult:DI (match_operand:DI 1 "register_operand" "")
20652                    (match_operand:DI 2 "const_int_operand" "")) 0))]
20653   "exact_log2 (INTVAL (operands[2])) >= 0
20654    && REGNO (operands[0]) == REGNO (operands[1])
20655    && peep2_regno_dead_p (0, FLAGS_REG)"
20656   [(parallel [(set (match_dup 0) (ashift:SI (match_dup 0) (match_dup 2)))
20657               (clobber (reg:CC FLAGS_REG))])]
20658   "operands[2] = GEN_INT (exact_log2 (INTVAL (operands[2])));")
20659
20660 ;; The ESP adjustments can be done by the push and pop instructions.  Resulting
20661 ;; code is shorter, since push is only 1 byte, while add imm, %esp 3 bytes.  On
20662 ;; many CPUs it is also faster, since special hardware to avoid esp
20663 ;; dependencies is present.
20664
20665 ;; While some of these conversions may be done using splitters, we use peepholes
20666 ;; in order to allow combine_stack_adjustments pass to see nonobfuscated RTL.
20667
20668 ;; Convert prologue esp subtractions to push.
20669 ;; We need register to push.  In order to keep verify_flow_info happy we have
20670 ;; two choices
20671 ;; - use scratch and clobber it in order to avoid dependencies
20672 ;; - use already live register
20673 ;; We can't use the second way right now, since there is no reliable way how to
20674 ;; verify that given register is live.  First choice will also most likely in
20675 ;; fewer dependencies.  On the place of esp adjustments it is very likely that
20676 ;; call clobbered registers are dead.  We may want to use base pointer as an
20677 ;; alternative when no register is available later.
20678
20679 (define_peephole2
20680   [(match_scratch:SI 0 "r")
20681    (parallel [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int -4)))
20682               (clobber (reg:CC FLAGS_REG))
20683               (clobber (mem:BLK (scratch)))])]
20684   "optimize_insn_for_size_p () || !TARGET_SUB_ESP_4"
20685   [(clobber (match_dup 0))
20686    (parallel [(set (mem:SI (pre_dec:SI (reg:SI SP_REG))) (match_dup 0))
20687               (clobber (mem:BLK (scratch)))])])
20688
20689 (define_peephole2
20690   [(match_scratch:SI 0 "r")
20691    (parallel [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int -8)))
20692               (clobber (reg:CC FLAGS_REG))
20693               (clobber (mem:BLK (scratch)))])]
20694   "optimize_insn_for_size_p () || !TARGET_SUB_ESP_8"
20695   [(clobber (match_dup 0))
20696    (set (mem:SI (pre_dec:SI (reg:SI SP_REG))) (match_dup 0))
20697    (parallel [(set (mem:SI (pre_dec:SI (reg:SI SP_REG))) (match_dup 0))
20698               (clobber (mem:BLK (scratch)))])])
20699
20700 ;; Convert esp subtractions to push.
20701 (define_peephole2
20702   [(match_scratch:SI 0 "r")
20703    (parallel [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int -4)))
20704               (clobber (reg:CC FLAGS_REG))])]
20705   "optimize_insn_for_size_p () || !TARGET_SUB_ESP_4"
20706   [(clobber (match_dup 0))
20707    (set (mem:SI (pre_dec:SI (reg:SI SP_REG))) (match_dup 0))])
20708
20709 (define_peephole2
20710   [(match_scratch:SI 0 "r")
20711    (parallel [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int -8)))
20712               (clobber (reg:CC FLAGS_REG))])]
20713   "optimize_insn_for_size_p () || !TARGET_SUB_ESP_8"
20714   [(clobber (match_dup 0))
20715    (set (mem:SI (pre_dec:SI (reg:SI SP_REG))) (match_dup 0))
20716    (set (mem:SI (pre_dec:SI (reg:SI SP_REG))) (match_dup 0))])
20717
20718 ;; Convert epilogue deallocator to pop.
20719 (define_peephole2
20720   [(match_scratch:SI 0 "r")
20721    (parallel [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))
20722               (clobber (reg:CC FLAGS_REG))
20723               (clobber (mem:BLK (scratch)))])]
20724   "optimize_insn_for_size_p () || !TARGET_ADD_ESP_4"
20725   [(parallel [(set (match_dup 0) (mem:SI (reg:SI SP_REG)))
20726               (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))
20727               (clobber (mem:BLK (scratch)))])]
20728   "")
20729
20730 ;; Two pops case is tricky, since pop causes dependency on destination register.
20731 ;; We use two registers if available.
20732 (define_peephole2
20733   [(match_scratch:SI 0 "r")
20734    (match_scratch:SI 1 "r")
20735    (parallel [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 8)))
20736               (clobber (reg:CC FLAGS_REG))
20737               (clobber (mem:BLK (scratch)))])]
20738   "optimize_insn_for_size_p () || !TARGET_ADD_ESP_8"
20739   [(parallel [(set (match_dup 0) (mem:SI (reg:SI SP_REG)))
20740               (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))
20741               (clobber (mem:BLK (scratch)))])
20742    (parallel [(set (match_dup 1) (mem:SI (reg:SI SP_REG)))
20743               (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))])]
20744   "")
20745
20746 (define_peephole2
20747   [(match_scratch:SI 0 "r")
20748    (parallel [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 8)))
20749               (clobber (reg:CC FLAGS_REG))
20750               (clobber (mem:BLK (scratch)))])]
20751   "optimize_insn_for_size_p ()"
20752   [(parallel [(set (match_dup 0) (mem:SI (reg:SI SP_REG)))
20753               (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))
20754               (clobber (mem:BLK (scratch)))])
20755    (parallel [(set (match_dup 0) (mem:SI (reg:SI SP_REG)))
20756               (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))])]
20757   "")
20758
20759 ;; Convert esp additions to pop.
20760 (define_peephole2
20761   [(match_scratch:SI 0 "r")
20762    (parallel [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))
20763               (clobber (reg:CC FLAGS_REG))])]
20764   ""
20765   [(parallel [(set (match_dup 0) (mem:SI (reg:SI SP_REG)))
20766               (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))])]
20767   "")
20768
20769 ;; Two pops case is tricky, since pop causes dependency on destination register.
20770 ;; We use two registers if available.
20771 (define_peephole2
20772   [(match_scratch:SI 0 "r")
20773    (match_scratch:SI 1 "r")
20774    (parallel [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 8)))
20775               (clobber (reg:CC FLAGS_REG))])]
20776   ""
20777   [(parallel [(set (match_dup 0) (mem:SI (reg:SI SP_REG)))
20778               (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))])
20779    (parallel [(set (match_dup 1) (mem:SI (reg:SI SP_REG)))
20780               (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))])]
20781   "")
20782
20783 (define_peephole2
20784   [(match_scratch:SI 0 "r")
20785    (parallel [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 8)))
20786               (clobber (reg:CC FLAGS_REG))])]
20787   "optimize_insn_for_size_p ()"
20788   [(parallel [(set (match_dup 0) (mem:SI (reg:SI SP_REG)))
20789               (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))])
20790    (parallel [(set (match_dup 0) (mem:SI (reg:SI SP_REG)))
20791               (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))])]
20792   "")
20793 \f
20794 ;; Convert compares with 1 to shorter inc/dec operations when CF is not
20795 ;; required and register dies.  Similarly for 128 to -128.
20796 (define_peephole2
20797   [(set (match_operand 0 "flags_reg_operand" "")
20798         (match_operator 1 "compare_operator"
20799           [(match_operand 2 "register_operand" "")
20800            (match_operand 3 "const_int_operand" "")]))]
20801   "(((!TARGET_FUSE_CMP_AND_BRANCH || optimize_insn_for_size_p ())
20802      && incdec_operand (operands[3], GET_MODE (operands[3])))
20803     || (!TARGET_FUSE_CMP_AND_BRANCH
20804         && INTVAL (operands[3]) == 128))
20805    && ix86_match_ccmode (insn, CCGCmode)
20806    && peep2_reg_dead_p (1, operands[2])"
20807   [(parallel [(set (match_dup 0)
20808                    (match_op_dup 1 [(match_dup 2) (match_dup 3)]))
20809               (clobber (match_dup 2))])]
20810   "")
20811 \f
20812 (define_peephole2
20813   [(match_scratch:DI 0 "r")
20814    (parallel [(set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int -8)))
20815               (clobber (reg:CC FLAGS_REG))
20816               (clobber (mem:BLK (scratch)))])]
20817   "optimize_insn_for_size_p () || !TARGET_SUB_ESP_4"
20818   [(clobber (match_dup 0))
20819    (parallel [(set (mem:DI (pre_dec:DI (reg:DI SP_REG))) (match_dup 0))
20820               (clobber (mem:BLK (scratch)))])])
20821
20822 (define_peephole2
20823   [(match_scratch:DI 0 "r")
20824    (parallel [(set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int -16)))
20825               (clobber (reg:CC FLAGS_REG))
20826               (clobber (mem:BLK (scratch)))])]
20827   "optimize_insn_for_size_p () || !TARGET_SUB_ESP_8"
20828   [(clobber (match_dup 0))
20829    (set (mem:DI (pre_dec:DI (reg:DI SP_REG))) (match_dup 0))
20830    (parallel [(set (mem:DI (pre_dec:DI (reg:DI SP_REG))) (match_dup 0))
20831               (clobber (mem:BLK (scratch)))])])
20832
20833 ;; Convert esp subtractions to push.
20834 (define_peephole2
20835   [(match_scratch:DI 0 "r")
20836    (parallel [(set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int -8)))
20837               (clobber (reg:CC FLAGS_REG))])]
20838   "optimize_insn_for_size_p () || !TARGET_SUB_ESP_4"
20839   [(clobber (match_dup 0))
20840    (set (mem:DI (pre_dec:DI (reg:DI SP_REG))) (match_dup 0))])
20841
20842 (define_peephole2
20843   [(match_scratch:DI 0 "r")
20844    (parallel [(set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int -16)))
20845               (clobber (reg:CC FLAGS_REG))])]
20846   "optimize_insn_for_size_p () || !TARGET_SUB_ESP_8"
20847   [(clobber (match_dup 0))
20848    (set (mem:DI (pre_dec:DI (reg:DI SP_REG))) (match_dup 0))
20849    (set (mem:DI (pre_dec:DI (reg:DI SP_REG))) (match_dup 0))])
20850
20851 ;; Convert epilogue deallocator to pop.
20852 (define_peephole2
20853   [(match_scratch:DI 0 "r")
20854    (parallel [(set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 8)))
20855               (clobber (reg:CC FLAGS_REG))
20856               (clobber (mem:BLK (scratch)))])]
20857   "optimize_insn_for_size_p () || !TARGET_ADD_ESP_4"
20858   [(parallel [(set (match_dup 0) (mem:DI (reg:DI SP_REG)))
20859               (set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 8)))
20860               (clobber (mem:BLK (scratch)))])]
20861   "")
20862
20863 ;; Two pops case is tricky, since pop causes dependency on destination register.
20864 ;; We use two registers if available.
20865 (define_peephole2
20866   [(match_scratch:DI 0 "r")
20867    (match_scratch:DI 1 "r")
20868    (parallel [(set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 16)))
20869               (clobber (reg:CC FLAGS_REG))
20870               (clobber (mem:BLK (scratch)))])]
20871   "optimize_insn_for_size_p () || !TARGET_ADD_ESP_8"
20872   [(parallel [(set (match_dup 0) (mem:DI (reg:DI SP_REG)))
20873               (set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 8)))
20874               (clobber (mem:BLK (scratch)))])
20875    (parallel [(set (match_dup 1) (mem:DI (reg:DI SP_REG)))
20876               (set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 8)))])]
20877   "")
20878
20879 (define_peephole2
20880   [(match_scratch:DI 0 "r")
20881    (parallel [(set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 16)))
20882               (clobber (reg:CC FLAGS_REG))
20883               (clobber (mem:BLK (scratch)))])]
20884   "optimize_insn_for_size_p ()"
20885   [(parallel [(set (match_dup 0) (mem:DI (reg:DI SP_REG)))
20886               (set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 8)))
20887               (clobber (mem:BLK (scratch)))])
20888    (parallel [(set (match_dup 0) (mem:DI (reg:DI SP_REG)))
20889               (set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 8)))])]
20890   "")
20891
20892 ;; Convert esp additions to pop.
20893 (define_peephole2
20894   [(match_scratch:DI 0 "r")
20895    (parallel [(set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 8)))
20896               (clobber (reg:CC FLAGS_REG))])]
20897   ""
20898   [(parallel [(set (match_dup 0) (mem:DI (reg:DI SP_REG)))
20899               (set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 8)))])]
20900   "")
20901
20902 ;; Two pops case is tricky, since pop causes dependency on destination register.
20903 ;; We use two registers if available.
20904 (define_peephole2
20905   [(match_scratch:DI 0 "r")
20906    (match_scratch:DI 1 "r")
20907    (parallel [(set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 16)))
20908               (clobber (reg:CC FLAGS_REG))])]
20909   ""
20910   [(parallel [(set (match_dup 0) (mem:DI (reg:DI SP_REG)))
20911               (set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 8)))])
20912    (parallel [(set (match_dup 1) (mem:DI (reg:DI SP_REG)))
20913               (set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 8)))])]
20914   "")
20915
20916 (define_peephole2
20917   [(match_scratch:DI 0 "r")
20918    (parallel [(set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 16)))
20919               (clobber (reg:CC FLAGS_REG))])]
20920   "optimize_insn_for_size_p ()"
20921   [(parallel [(set (match_dup 0) (mem:DI (reg:DI SP_REG)))
20922               (set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 8)))])
20923    (parallel [(set (match_dup 0) (mem:DI (reg:DI SP_REG)))
20924               (set (reg:DI SP_REG) (plus:DI (reg:DI SP_REG) (const_int 8)))])]
20925   "")
20926 \f
20927 ;; Convert imul by three, five and nine into lea
20928 (define_peephole2
20929   [(parallel
20930     [(set (match_operand:SI 0 "register_operand" "")
20931           (mult:SI (match_operand:SI 1 "register_operand" "")
20932                    (match_operand:SI 2 "const_int_operand" "")))
20933      (clobber (reg:CC FLAGS_REG))])]
20934   "INTVAL (operands[2]) == 3
20935    || INTVAL (operands[2]) == 5
20936    || INTVAL (operands[2]) == 9"
20937   [(set (match_dup 0)
20938         (plus:SI (mult:SI (match_dup 1) (match_dup 2))
20939                  (match_dup 1)))]
20940   { operands[2] = GEN_INT (INTVAL (operands[2]) - 1); })
20941
20942 (define_peephole2
20943   [(parallel
20944     [(set (match_operand:SI 0 "register_operand" "")
20945           (mult:SI (match_operand:SI 1 "nonimmediate_operand" "")
20946                    (match_operand:SI 2 "const_int_operand" "")))
20947      (clobber (reg:CC FLAGS_REG))])]
20948   "optimize_insn_for_speed_p ()
20949    && (INTVAL (operands[2]) == 3
20950        || INTVAL (operands[2]) == 5
20951        || INTVAL (operands[2]) == 9)"
20952   [(set (match_dup 0) (match_dup 1))
20953    (set (match_dup 0)
20954         (plus:SI (mult:SI (match_dup 0) (match_dup 2))
20955                  (match_dup 0)))]
20956   { operands[2] = GEN_INT (INTVAL (operands[2]) - 1); })
20957
20958 (define_peephole2
20959   [(parallel
20960     [(set (match_operand:DI 0 "register_operand" "")
20961           (mult:DI (match_operand:DI 1 "register_operand" "")
20962                    (match_operand:DI 2 "const_int_operand" "")))
20963      (clobber (reg:CC FLAGS_REG))])]
20964   "TARGET_64BIT
20965    && (INTVAL (operands[2]) == 3
20966        || INTVAL (operands[2]) == 5
20967        || INTVAL (operands[2]) == 9)"
20968   [(set (match_dup 0)
20969         (plus:DI (mult:DI (match_dup 1) (match_dup 2))
20970                  (match_dup 1)))]
20971   { operands[2] = GEN_INT (INTVAL (operands[2]) - 1); })
20972
20973 (define_peephole2
20974   [(parallel
20975     [(set (match_operand:DI 0 "register_operand" "")
20976           (mult:DI (match_operand:DI 1 "nonimmediate_operand" "")
20977                    (match_operand:DI 2 "const_int_operand" "")))
20978      (clobber (reg:CC FLAGS_REG))])]
20979   "TARGET_64BIT
20980    && optimize_insn_for_speed_p ()
20981    && (INTVAL (operands[2]) == 3
20982        || INTVAL (operands[2]) == 5
20983        || INTVAL (operands[2]) == 9)"
20984   [(set (match_dup 0) (match_dup 1))
20985    (set (match_dup 0)
20986         (plus:DI (mult:DI (match_dup 0) (match_dup 2))
20987                  (match_dup 0)))]
20988   { operands[2] = GEN_INT (INTVAL (operands[2]) - 1); })
20989
20990 ;; Imul $32bit_imm, mem, reg is vector decoded, while
20991 ;; imul $32bit_imm, reg, reg is direct decoded.
20992 (define_peephole2
20993   [(match_scratch:DI 3 "r")
20994    (parallel [(set (match_operand:DI 0 "register_operand" "")
20995                    (mult:DI (match_operand:DI 1 "memory_operand" "")
20996                             (match_operand:DI 2 "immediate_operand" "")))
20997               (clobber (reg:CC FLAGS_REG))])]
20998   "TARGET_SLOW_IMUL_IMM32_MEM && optimize_insn_for_speed_p ()
20999    && !satisfies_constraint_K (operands[2])"
21000   [(set (match_dup 3) (match_dup 1))
21001    (parallel [(set (match_dup 0) (mult:DI (match_dup 3) (match_dup 2)))
21002               (clobber (reg:CC FLAGS_REG))])]
21003 "")
21004
21005 (define_peephole2
21006   [(match_scratch:SI 3 "r")
21007    (parallel [(set (match_operand:SI 0 "register_operand" "")
21008                    (mult:SI (match_operand:SI 1 "memory_operand" "")
21009                             (match_operand:SI 2 "immediate_operand" "")))
21010               (clobber (reg:CC FLAGS_REG))])]
21011   "TARGET_SLOW_IMUL_IMM32_MEM && optimize_insn_for_speed_p ()
21012    && !satisfies_constraint_K (operands[2])"
21013   [(set (match_dup 3) (match_dup 1))
21014    (parallel [(set (match_dup 0) (mult:SI (match_dup 3) (match_dup 2)))
21015               (clobber (reg:CC FLAGS_REG))])]
21016 "")
21017
21018 (define_peephole2
21019   [(match_scratch:SI 3 "r")
21020    (parallel [(set (match_operand:DI 0 "register_operand" "")
21021                    (zero_extend:DI
21022                      (mult:SI (match_operand:SI 1 "memory_operand" "")
21023                               (match_operand:SI 2 "immediate_operand" ""))))
21024               (clobber (reg:CC FLAGS_REG))])]
21025   "TARGET_SLOW_IMUL_IMM32_MEM && optimize_insn_for_speed_p ()
21026    && !satisfies_constraint_K (operands[2])"
21027   [(set (match_dup 3) (match_dup 1))
21028    (parallel [(set (match_dup 0) (zero_extend:DI (mult:SI (match_dup 3) (match_dup 2))))
21029               (clobber (reg:CC FLAGS_REG))])]
21030 "")
21031
21032 ;; imul $8/16bit_imm, regmem, reg is vector decoded.
21033 ;; Convert it into imul reg, reg
21034 ;; It would be better to force assembler to encode instruction using long
21035 ;; immediate, but there is apparently no way to do so.
21036 (define_peephole2
21037   [(parallel [(set (match_operand:DI 0 "register_operand" "")
21038                    (mult:DI (match_operand:DI 1 "nonimmediate_operand" "")
21039                             (match_operand:DI 2 "const_int_operand" "")))
21040               (clobber (reg:CC FLAGS_REG))])
21041    (match_scratch:DI 3 "r")]
21042   "TARGET_SLOW_IMUL_IMM8 && optimize_insn_for_speed_p ()
21043    && satisfies_constraint_K (operands[2])"
21044   [(set (match_dup 3) (match_dup 2))
21045    (parallel [(set (match_dup 0) (mult:DI (match_dup 0) (match_dup 3)))
21046               (clobber (reg:CC FLAGS_REG))])]
21047 {
21048   if (!rtx_equal_p (operands[0], operands[1]))
21049     emit_move_insn (operands[0], operands[1]);
21050 })
21051
21052 (define_peephole2
21053   [(parallel [(set (match_operand:SI 0 "register_operand" "")
21054                    (mult:SI (match_operand:SI 1 "nonimmediate_operand" "")
21055                             (match_operand:SI 2 "const_int_operand" "")))
21056               (clobber (reg:CC FLAGS_REG))])
21057    (match_scratch:SI 3 "r")]
21058   "TARGET_SLOW_IMUL_IMM8 && optimize_insn_for_speed_p ()
21059    && satisfies_constraint_K (operands[2])"
21060   [(set (match_dup 3) (match_dup 2))
21061    (parallel [(set (match_dup 0) (mult:SI (match_dup 0) (match_dup 3)))
21062               (clobber (reg:CC FLAGS_REG))])]
21063 {
21064   if (!rtx_equal_p (operands[0], operands[1]))
21065     emit_move_insn (operands[0], operands[1]);
21066 })
21067
21068 (define_peephole2
21069   [(parallel [(set (match_operand:HI 0 "register_operand" "")
21070                    (mult:HI (match_operand:HI 1 "nonimmediate_operand" "")
21071                             (match_operand:HI 2 "immediate_operand" "")))
21072               (clobber (reg:CC FLAGS_REG))])
21073    (match_scratch:HI 3 "r")]
21074   "TARGET_SLOW_IMUL_IMM8 && optimize_insn_for_speed_p ()"
21075   [(set (match_dup 3) (match_dup 2))
21076    (parallel [(set (match_dup 0) (mult:HI (match_dup 0) (match_dup 3)))
21077               (clobber (reg:CC FLAGS_REG))])]
21078 {
21079   if (!rtx_equal_p (operands[0], operands[1]))
21080     emit_move_insn (operands[0], operands[1]);
21081 })
21082
21083 ;; After splitting up read-modify operations, array accesses with memory
21084 ;; operands might end up in form:
21085 ;;  sall    $2, %eax
21086 ;;  movl    4(%esp), %edx
21087 ;;  addl    %edx, %eax
21088 ;; instead of pre-splitting:
21089 ;;  sall    $2, %eax
21090 ;;  addl    4(%esp), %eax
21091 ;; Turn it into:
21092 ;;  movl    4(%esp), %edx
21093 ;;  leal    (%edx,%eax,4), %eax
21094
21095 (define_peephole2
21096   [(parallel [(set (match_operand 0 "register_operand" "")
21097                    (ashift (match_operand 1 "register_operand" "")
21098                            (match_operand 2 "const_int_operand" "")))
21099                (clobber (reg:CC FLAGS_REG))])
21100    (set (match_operand 3 "register_operand")
21101         (match_operand 4 "x86_64_general_operand" ""))
21102    (parallel [(set (match_operand 5 "register_operand" "")
21103                    (plus (match_operand 6 "register_operand" "")
21104                          (match_operand 7 "register_operand" "")))
21105                    (clobber (reg:CC FLAGS_REG))])]
21106   "INTVAL (operands[2]) >= 0 && INTVAL (operands[2]) <= 3
21107    /* Validate MODE for lea.  */
21108    && ((!TARGET_PARTIAL_REG_STALL
21109         && (GET_MODE (operands[0]) == QImode
21110             || GET_MODE (operands[0]) == HImode))
21111        || GET_MODE (operands[0]) == SImode
21112        || (TARGET_64BIT && GET_MODE (operands[0]) == DImode))
21113    /* We reorder load and the shift.  */
21114    && !rtx_equal_p (operands[1], operands[3])
21115    && !reg_overlap_mentioned_p (operands[0], operands[4])
21116    /* Last PLUS must consist of operand 0 and 3.  */
21117    && !rtx_equal_p (operands[0], operands[3])
21118    && (rtx_equal_p (operands[3], operands[6])
21119        || rtx_equal_p (operands[3], operands[7]))
21120    && (rtx_equal_p (operands[0], operands[6])
21121        || rtx_equal_p (operands[0], operands[7]))
21122    /* The intermediate operand 0 must die or be same as output.  */
21123    && (rtx_equal_p (operands[0], operands[5])
21124        || peep2_reg_dead_p (3, operands[0]))"
21125   [(set (match_dup 3) (match_dup 4))
21126    (set (match_dup 0) (match_dup 1))]
21127 {
21128   enum machine_mode mode = GET_MODE (operands[5]) == DImode ? DImode : SImode;
21129   int scale = 1 << INTVAL (operands[2]);
21130   rtx index = gen_lowpart (Pmode, operands[1]);
21131   rtx base = gen_lowpart (Pmode, operands[3]);
21132   rtx dest = gen_lowpart (mode, operands[5]);
21133
21134   operands[1] = gen_rtx_PLUS (Pmode, base,
21135                               gen_rtx_MULT (Pmode, index, GEN_INT (scale)));
21136   if (mode != Pmode)
21137     operands[1] = gen_rtx_SUBREG (mode, operands[1], 0);
21138   operands[0] = dest;
21139 })
21140 \f
21141 ;; Call-value patterns last so that the wildcard operand does not
21142 ;; disrupt insn-recog's switch tables.
21143
21144 (define_insn "*call_value_pop_0"
21145   [(set (match_operand 0 "" "")
21146         (call (mem:QI (match_operand:SI 1 "constant_call_address_operand" ""))
21147               (match_operand:SI 2 "" "")))
21148    (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
21149                             (match_operand:SI 3 "immediate_operand" "")))]
21150   "!TARGET_64BIT"
21151 {
21152   if (SIBLING_CALL_P (insn))
21153     return "jmp\t%P1";
21154   else
21155     return "call\t%P1";
21156 }
21157   [(set_attr "type" "callv")])
21158
21159 (define_insn "*call_value_pop_1"
21160   [(set (match_operand 0 "" "")
21161         (call (mem:QI (match_operand:SI 1 "call_insn_operand" "rsm"))
21162               (match_operand:SI 2 "" "")))
21163    (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
21164                             (match_operand:SI 3 "immediate_operand" "i")))]
21165   "!SIBLING_CALL_P (insn) && !TARGET_64BIT"
21166 {
21167   if (constant_call_address_operand (operands[1], Pmode))
21168     return "call\t%P1";
21169   return "call\t%A1";
21170 }
21171   [(set_attr "type" "callv")])
21172
21173 (define_insn "*sibcall_value_pop_1"
21174   [(set (match_operand 0 "" "")
21175         (call (mem:QI (match_operand:SI 1 "sibcall_insn_operand" "s,U"))
21176               (match_operand:SI 2 "" "")))
21177    (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
21178                             (match_operand:SI 3 "immediate_operand" "i,i")))]
21179   "SIBLING_CALL_P (insn) && !TARGET_64BIT"
21180   "@
21181    jmp\t%P1
21182    jmp\t%A1"
21183   [(set_attr "type" "callv")])
21184
21185 (define_insn "*call_value_0"
21186   [(set (match_operand 0 "" "")
21187         (call (mem:QI (match_operand:SI 1 "constant_call_address_operand" ""))
21188               (match_operand:SI 2 "" "")))]
21189   "!TARGET_64BIT"
21190 {
21191   if (SIBLING_CALL_P (insn))
21192     return "jmp\t%P1";
21193   else
21194     return "call\t%P1";
21195 }
21196   [(set_attr "type" "callv")])
21197
21198 (define_insn "*call_value_0_rex64"
21199   [(set (match_operand 0 "" "")
21200         (call (mem:QI (match_operand:DI 1 "constant_call_address_operand" ""))
21201               (match_operand:DI 2 "const_int_operand" "")))]
21202   "TARGET_64BIT"
21203 {
21204   if (SIBLING_CALL_P (insn))
21205     return "jmp\t%P1";
21206   else
21207     return "call\t%P1";
21208 }
21209   [(set_attr "type" "callv")])
21210
21211 (define_insn "*call_value_0_rex64_ms_sysv"
21212   [(set (match_operand 0 "" "")
21213         (call (mem:QI (match_operand:DI 1 "constant_call_address_operand" ""))
21214               (match_operand:DI 2 "const_int_operand" "")))
21215    (unspec [(const_int 0)] UNSPEC_MS_TO_SYSV_CALL)
21216    (clobber (reg:TI XMM6_REG))
21217    (clobber (reg:TI XMM7_REG))
21218    (clobber (reg:TI XMM8_REG))
21219    (clobber (reg:TI XMM9_REG))
21220    (clobber (reg:TI XMM10_REG))
21221    (clobber (reg:TI XMM11_REG))
21222    (clobber (reg:TI XMM12_REG))
21223    (clobber (reg:TI XMM13_REG))
21224    (clobber (reg:TI XMM14_REG))
21225    (clobber (reg:TI XMM15_REG))
21226    (clobber (reg:DI SI_REG))
21227    (clobber (reg:DI DI_REG))]
21228   "!SIBLING_CALL_P (insn) && TARGET_64BIT"
21229 {
21230   if (SIBLING_CALL_P (insn))
21231     return "jmp\t%P1";
21232   else
21233     return "call\t%P1";
21234 }
21235   [(set_attr "type" "callv")])
21236
21237 (define_insn "*call_value_1"
21238   [(set (match_operand 0 "" "")
21239         (call (mem:QI (match_operand:SI 1 "call_insn_operand" "rsm"))
21240               (match_operand:SI 2 "" "")))]
21241   "!SIBLING_CALL_P (insn) && !TARGET_64BIT"
21242 {
21243   if (constant_call_address_operand (operands[1], Pmode))
21244     return "call\t%P1";
21245   return "call\t%A1";
21246 }
21247   [(set_attr "type" "callv")])
21248
21249 (define_insn "*sibcall_value_1"
21250   [(set (match_operand 0 "" "")
21251         (call (mem:QI (match_operand:SI 1 "sibcall_insn_operand" "s,U"))
21252               (match_operand:SI 2 "" "")))]
21253   "SIBLING_CALL_P (insn) && !TARGET_64BIT"
21254   "@
21255    jmp\t%P1
21256    jmp\t%A1"
21257   [(set_attr "type" "callv")])
21258
21259 (define_insn "*call_value_1_rex64"
21260   [(set (match_operand 0 "" "")
21261         (call (mem:QI (match_operand:DI 1 "call_insn_operand" "rsm"))
21262               (match_operand:DI 2 "" "")))]
21263   "!SIBLING_CALL_P (insn) && TARGET_64BIT
21264    && ix86_cmodel != CM_LARGE && ix86_cmodel != CM_LARGE_PIC"
21265 {
21266   if (constant_call_address_operand (operands[1], Pmode))
21267     return "call\t%P1";
21268   return "call\t%A1";
21269 }
21270   [(set_attr "type" "callv")])
21271
21272 (define_insn "*call_value_1_rex64_ms_sysv"
21273   [(set (match_operand 0 "" "")
21274         (call (mem:QI (match_operand:DI 1 "call_insn_operand" "rsm"))
21275               (match_operand:DI 2 "" "")))
21276    (unspec [(const_int 0)] UNSPEC_MS_TO_SYSV_CALL)
21277    (clobber (reg:TI 27))
21278    (clobber (reg:TI 28))
21279    (clobber (reg:TI 45))
21280    (clobber (reg:TI 46))
21281    (clobber (reg:TI 47))
21282    (clobber (reg:TI 48))
21283    (clobber (reg:TI 49))
21284    (clobber (reg:TI 50))
21285    (clobber (reg:TI 51))
21286    (clobber (reg:TI 52))
21287    (clobber (reg:DI SI_REG))
21288    (clobber (reg:DI DI_REG))]
21289   "!SIBLING_CALL_P (insn) && TARGET_64BIT"
21290 {
21291   if (constant_call_address_operand (operands[1], Pmode))
21292     return "call\t%P1";
21293   return "call\t%A1";
21294 }
21295   [(set_attr "type" "callv")])
21296
21297 (define_insn "*call_value_1_rex64_large"
21298   [(set (match_operand 0 "" "")
21299         (call (mem:QI (match_operand:DI 1 "call_insn_operand" "rm"))
21300               (match_operand:DI 2 "" "")))]
21301   "!SIBLING_CALL_P (insn) && TARGET_64BIT"
21302   "call\t%A1"
21303   [(set_attr "type" "callv")])
21304
21305 (define_insn "*sibcall_value_1_rex64"
21306   [(set (match_operand 0 "" "")
21307         (call (mem:QI (match_operand:DI 1 "sibcall_insn_operand" "s,U"))
21308               (match_operand:DI 2 "" "")))]
21309   "SIBLING_CALL_P (insn) && TARGET_64BIT"
21310   "@
21311    jmp\t%P1
21312    jmp\t%A1"
21313   [(set_attr "type" "callv")])
21314 \f
21315 ;; We used to use "int $5", in honor of #BR which maps to interrupt vector 5.
21316 ;; That, however, is usually mapped by the OS to SIGSEGV, which is often
21317 ;; caught for use by garbage collectors and the like.  Using an insn that
21318 ;; maps to SIGILL makes it more likely the program will rightfully die.
21319 ;; Keeping with tradition, "6" is in honor of #UD.
21320 (define_insn "trap"
21321   [(trap_if (const_int 1) (const_int 6))]
21322   ""
21323   { return ASM_SHORT "0x0b0f"; }
21324   [(set_attr "length" "2")])
21325
21326 (define_expand "sse_prologue_save"
21327   [(parallel [(set (match_operand:BLK 0 "" "")
21328                    (unspec:BLK [(reg:DI 21)
21329                                 (reg:DI 22)
21330                                 (reg:DI 23)
21331                                 (reg:DI 24)
21332                                 (reg:DI 25)
21333                                 (reg:DI 26)
21334                                 (reg:DI 27)
21335                                 (reg:DI 28)] UNSPEC_SSE_PROLOGUE_SAVE))
21336               (use (match_operand:DI 1 "register_operand" ""))
21337               (use (match_operand:DI 2 "immediate_operand" ""))
21338               (use (label_ref:DI (match_operand 3 "" "")))])]
21339   "TARGET_64BIT"
21340   "")
21341
21342 (define_insn "*sse_prologue_save_insn"
21343   [(set (mem:BLK (plus:DI (match_operand:DI 0 "register_operand" "R")
21344                           (match_operand:DI 4 "const_int_operand" "n")))
21345         (unspec:BLK [(reg:DI 21)
21346                      (reg:DI 22)
21347                      (reg:DI 23)
21348                      (reg:DI 24)
21349                      (reg:DI 25)
21350                      (reg:DI 26)
21351                      (reg:DI 27)
21352                      (reg:DI 28)] UNSPEC_SSE_PROLOGUE_SAVE))
21353    (use (match_operand:DI 1 "register_operand" "r"))
21354    (use (match_operand:DI 2 "const_int_operand" "i"))
21355    (use (label_ref:DI (match_operand 3 "" "X")))]
21356   "TARGET_64BIT
21357    && INTVAL (operands[4]) + X86_64_SSE_REGPARM_MAX * 16 - 16 < 128
21358    && INTVAL (operands[4]) + INTVAL (operands[2]) * 16 >= -128"
21359 {
21360   int i;
21361   operands[0] = gen_rtx_MEM (Pmode,
21362                              gen_rtx_PLUS (Pmode, operands[0], operands[4]));
21363   /* VEX instruction with a REX prefix will #UD.  */
21364   if (TARGET_AVX && GET_CODE (XEXP (operands[0], 0)) != PLUS)
21365     gcc_unreachable ();
21366
21367   output_asm_insn ("jmp\t%A1", operands);
21368   for (i = X86_64_SSE_REGPARM_MAX - 1; i >= INTVAL (operands[2]); i--)
21369     {
21370       operands[4] = adjust_address (operands[0], DImode, i*16);
21371       operands[5] = gen_rtx_REG (TImode, SSE_REGNO (i));
21372       PUT_MODE (operands[4], TImode);
21373       if (GET_CODE (XEXP (operands[0], 0)) != PLUS)
21374         output_asm_insn ("rex", operands);
21375       output_asm_insn ("%vmovaps\t{%5, %4|%4, %5}", operands);
21376     }
21377   (*targetm.asm_out.internal_label) (asm_out_file, "L",
21378                                      CODE_LABEL_NUMBER (operands[3]));
21379   return "";
21380 }
21381   [(set_attr "type" "other")
21382    (set_attr "length_immediate" "0")
21383    (set_attr "length_address" "0")
21384    (set (attr "length")
21385      (if_then_else
21386        (eq (symbol_ref "TARGET_AVX") (const_int 0))
21387        (const_string "34")
21388        (const_string "42")))
21389    (set_attr "memory" "store")
21390    (set_attr "modrm" "0")
21391    (set_attr "prefix" "maybe_vex")
21392    (set_attr "mode" "DI")])
21393
21394 (define_expand "prefetch"
21395   [(prefetch (match_operand 0 "address_operand" "")
21396              (match_operand:SI 1 "const_int_operand" "")
21397              (match_operand:SI 2 "const_int_operand" ""))]
21398   "TARGET_PREFETCH_SSE || TARGET_3DNOW"
21399 {
21400   int rw = INTVAL (operands[1]);
21401   int locality = INTVAL (operands[2]);
21402
21403   gcc_assert (rw == 0 || rw == 1);
21404   gcc_assert (locality >= 0 && locality <= 3);
21405   gcc_assert (GET_MODE (operands[0]) == Pmode
21406               || GET_MODE (operands[0]) == VOIDmode);
21407
21408   /* Use 3dNOW prefetch in case we are asking for write prefetch not
21409      supported by SSE counterpart or the SSE prefetch is not available
21410      (K6 machines).  Otherwise use SSE prefetch as it allows specifying
21411      of locality.  */
21412   if (TARGET_3DNOW && (!TARGET_PREFETCH_SSE || rw))
21413     operands[2] = GEN_INT (3);
21414   else
21415     operands[1] = const0_rtx;
21416 })
21417
21418 (define_insn "*prefetch_sse"
21419   [(prefetch (match_operand:SI 0 "address_operand" "p")
21420              (const_int 0)
21421              (match_operand:SI 1 "const_int_operand" ""))]
21422   "TARGET_PREFETCH_SSE && !TARGET_64BIT"
21423 {
21424   static const char * const patterns[4] = {
21425    "prefetchnta\t%a0", "prefetcht2\t%a0", "prefetcht1\t%a0", "prefetcht0\t%a0"
21426   };
21427
21428   int locality = INTVAL (operands[1]);
21429   gcc_assert (locality >= 0 && locality <= 3);
21430
21431   return patterns[locality];
21432 }
21433   [(set_attr "type" "sse")
21434    (set_attr "atom_sse_attr" "prefetch")
21435    (set (attr "length_address") (symbol_ref "memory_address_length (operands[0])"))
21436    (set_attr "memory" "none")])
21437
21438 (define_insn "*prefetch_sse_rex"
21439   [(prefetch (match_operand:DI 0 "address_operand" "p")
21440              (const_int 0)
21441              (match_operand:SI 1 "const_int_operand" ""))]
21442   "TARGET_PREFETCH_SSE && TARGET_64BIT"
21443 {
21444   static const char * const patterns[4] = {
21445    "prefetchnta\t%a0", "prefetcht2\t%a0", "prefetcht1\t%a0", "prefetcht0\t%a0"
21446   };
21447
21448   int locality = INTVAL (operands[1]);
21449   gcc_assert (locality >= 0 && locality <= 3);
21450
21451   return patterns[locality];
21452 }
21453   [(set_attr "type" "sse")
21454    (set_attr "atom_sse_attr" "prefetch")
21455    (set (attr "length_address") (symbol_ref "memory_address_length (operands[0])"))
21456    (set_attr "memory" "none")])
21457
21458 (define_insn "*prefetch_3dnow"
21459   [(prefetch (match_operand:SI 0 "address_operand" "p")
21460              (match_operand:SI 1 "const_int_operand" "n")
21461              (const_int 3))]
21462   "TARGET_3DNOW && !TARGET_64BIT"
21463 {
21464   if (INTVAL (operands[1]) == 0)
21465     return "prefetch\t%a0";
21466   else
21467     return "prefetchw\t%a0";
21468 }
21469   [(set_attr "type" "mmx")
21470    (set (attr "length_address") (symbol_ref "memory_address_length (operands[0])"))
21471    (set_attr "memory" "none")])
21472
21473 (define_insn "*prefetch_3dnow_rex"
21474   [(prefetch (match_operand:DI 0 "address_operand" "p")
21475              (match_operand:SI 1 "const_int_operand" "n")
21476              (const_int 3))]
21477   "TARGET_3DNOW && TARGET_64BIT"
21478 {
21479   if (INTVAL (operands[1]) == 0)
21480     return "prefetch\t%a0";
21481   else
21482     return "prefetchw\t%a0";
21483 }
21484   [(set_attr "type" "mmx")
21485    (set (attr "length_address") (symbol_ref "memory_address_length (operands[0])"))
21486    (set_attr "memory" "none")])
21487
21488 (define_expand "stack_protect_set"
21489   [(match_operand 0 "memory_operand" "")
21490    (match_operand 1 "memory_operand" "")]
21491   ""
21492 {
21493 #ifdef TARGET_THREAD_SSP_OFFSET
21494   if (TARGET_64BIT)
21495     emit_insn (gen_stack_tls_protect_set_di (operands[0],
21496                                         GEN_INT (TARGET_THREAD_SSP_OFFSET)));
21497   else
21498     emit_insn (gen_stack_tls_protect_set_si (operands[0],
21499                                         GEN_INT (TARGET_THREAD_SSP_OFFSET)));
21500 #else
21501   if (TARGET_64BIT)
21502     emit_insn (gen_stack_protect_set_di (operands[0], operands[1]));
21503   else
21504     emit_insn (gen_stack_protect_set_si (operands[0], operands[1]));
21505 #endif
21506   DONE;
21507 })
21508
21509 (define_insn "stack_protect_set_si"
21510   [(set (match_operand:SI 0 "memory_operand" "=m")
21511         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
21512    (set (match_scratch:SI 2 "=&r") (const_int 0))
21513    (clobber (reg:CC FLAGS_REG))]
21514   ""
21515   "mov{l}\t{%1, %2|%2, %1}\;mov{l}\t{%2, %0|%0, %2}\;xor{l}\t%2, %2"
21516   [(set_attr "type" "multi")])
21517
21518 (define_insn "stack_protect_set_di"
21519   [(set (match_operand:DI 0 "memory_operand" "=m")
21520         (unspec:DI [(match_operand:DI 1 "memory_operand" "m")] UNSPEC_SP_SET))
21521    (set (match_scratch:DI 2 "=&r") (const_int 0))
21522    (clobber (reg:CC FLAGS_REG))]
21523   "TARGET_64BIT"
21524   "mov{q}\t{%1, %2|%2, %1}\;mov{q}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2"
21525   [(set_attr "type" "multi")])
21526
21527 (define_insn "stack_tls_protect_set_si"
21528   [(set (match_operand:SI 0 "memory_operand" "=m")
21529         (unspec:SI [(match_operand:SI 1 "const_int_operand" "i")] UNSPEC_SP_TLS_SET))
21530    (set (match_scratch:SI 2 "=&r") (const_int 0))
21531    (clobber (reg:CC FLAGS_REG))]
21532   ""
21533   "mov{l}\t{%%gs:%P1, %2|%2, DWORD PTR gs:%P1}\;mov{l}\t{%2, %0|%0, %2}\;xor{l}\t%2, %2"
21534   [(set_attr "type" "multi")])
21535
21536 (define_insn "stack_tls_protect_set_di"
21537   [(set (match_operand:DI 0 "memory_operand" "=m")
21538         (unspec:DI [(match_operand:DI 1 "const_int_operand" "i")] UNSPEC_SP_TLS_SET))
21539    (set (match_scratch:DI 2 "=&r") (const_int 0))
21540    (clobber (reg:CC FLAGS_REG))]
21541   "TARGET_64BIT"
21542   {
21543      /* The kernel uses a different segment register for performance reasons; a
21544         system call would not have to trash the userspace segment register,
21545         which would be expensive */
21546      if (ix86_cmodel != CM_KERNEL)
21547         return "mov{q}\t{%%fs:%P1, %2|%2, QWORD PTR fs:%P1}\;mov{q}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2";
21548      else
21549         return "mov{q}\t{%%gs:%P1, %2|%2, QWORD PTR gs:%P1}\;mov{q}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2";
21550   }
21551   [(set_attr "type" "multi")])
21552
21553 (define_expand "stack_protect_test"
21554   [(match_operand 0 "memory_operand" "")
21555    (match_operand 1 "memory_operand" "")
21556    (match_operand 2 "" "")]
21557   ""
21558 {
21559   rtx flags = gen_rtx_REG (CCZmode, FLAGS_REG);
21560
21561 #ifdef TARGET_THREAD_SSP_OFFSET
21562   if (TARGET_64BIT)
21563     emit_insn (gen_stack_tls_protect_test_di (flags, operands[0],
21564                                         GEN_INT (TARGET_THREAD_SSP_OFFSET)));
21565   else
21566     emit_insn (gen_stack_tls_protect_test_si (flags, operands[0],
21567                                         GEN_INT (TARGET_THREAD_SSP_OFFSET)));
21568 #else
21569   if (TARGET_64BIT)
21570     emit_insn (gen_stack_protect_test_di (flags, operands[0], operands[1]));
21571   else
21572     emit_insn (gen_stack_protect_test_si (flags, operands[0], operands[1]));
21573 #endif
21574
21575   emit_jump_insn (gen_cbranchcc4 (gen_rtx_EQ (VOIDmode, flags, const0_rtx),
21576                                   flags, const0_rtx, operands[2]));
21577   DONE;
21578 })
21579
21580 (define_insn "stack_protect_test_si"
21581   [(set (match_operand:CCZ 0 "flags_reg_operand" "")
21582         (unspec:CCZ [(match_operand:SI 1 "memory_operand" "m")
21583                      (match_operand:SI 2 "memory_operand" "m")]
21584                     UNSPEC_SP_TEST))
21585    (clobber (match_scratch:SI 3 "=&r"))]
21586   ""
21587   "mov{l}\t{%1, %3|%3, %1}\;xor{l}\t{%2, %3|%3, %2}"
21588   [(set_attr "type" "multi")])
21589
21590 (define_insn "stack_protect_test_di"
21591   [(set (match_operand:CCZ 0 "flags_reg_operand" "")
21592         (unspec:CCZ [(match_operand:DI 1 "memory_operand" "m")
21593                      (match_operand:DI 2 "memory_operand" "m")]
21594                     UNSPEC_SP_TEST))
21595    (clobber (match_scratch:DI 3 "=&r"))]
21596   "TARGET_64BIT"
21597   "mov{q}\t{%1, %3|%3, %1}\;xor{q}\t{%2, %3|%3, %2}"
21598   [(set_attr "type" "multi")])
21599
21600 (define_insn "stack_tls_protect_test_si"
21601   [(set (match_operand:CCZ 0 "flags_reg_operand" "")
21602         (unspec:CCZ [(match_operand:SI 1 "memory_operand" "m")
21603                      (match_operand:SI 2 "const_int_operand" "i")]
21604                     UNSPEC_SP_TLS_TEST))
21605    (clobber (match_scratch:SI 3 "=r"))]
21606   ""
21607   "mov{l}\t{%1, %3|%3, %1}\;xor{l}\t{%%gs:%P2, %3|%3, DWORD PTR gs:%P2}"
21608   [(set_attr "type" "multi")])
21609
21610 (define_insn "stack_tls_protect_test_di"
21611   [(set (match_operand:CCZ 0 "flags_reg_operand" "")
21612         (unspec:CCZ [(match_operand:DI 1 "memory_operand" "m")
21613                      (match_operand:DI 2 "const_int_operand" "i")]
21614                     UNSPEC_SP_TLS_TEST))
21615    (clobber (match_scratch:DI 3 "=r"))]
21616   "TARGET_64BIT"
21617   {
21618      /* The kernel uses a different segment register for performance reasons; a
21619         system call would not have to trash the userspace segment register,
21620         which would be expensive */
21621      if (ix86_cmodel != CM_KERNEL)
21622         return "mov{q}\t{%1, %3|%3, %1}\;xor{q}\t{%%fs:%P2, %3|%3, QWORD PTR fs:%P2}";
21623      else
21624         return "mov{q}\t{%1, %3|%3, %1}\;xor{q}\t{%%gs:%P2, %3|%3, QWORD PTR gs:%P2}";
21625   }
21626   [(set_attr "type" "multi")])
21627
21628 (define_mode_iterator CRC32MODE [QI HI SI])
21629 (define_mode_attr crc32modesuffix [(QI "b") (HI "w") (SI "l")])
21630 (define_mode_attr crc32modeconstraint [(QI "qm") (HI "rm") (SI "rm")])
21631
21632 (define_insn "sse4_2_crc32<mode>"
21633   [(set (match_operand:SI 0 "register_operand" "=r")
21634         (unspec:SI
21635           [(match_operand:SI 1 "register_operand" "0")
21636            (match_operand:CRC32MODE 2 "nonimmediate_operand" "<crc32modeconstraint>")]
21637           UNSPEC_CRC32))]
21638   "TARGET_SSE4_2 || TARGET_CRC32"
21639   "crc32<crc32modesuffix>\t{%2, %0|%0, %2}"
21640   [(set_attr "type" "sselog1")
21641    (set_attr "prefix_rep" "1")
21642    (set_attr "prefix_extra" "1")
21643    (set (attr "prefix_data16")
21644      (if_then_else (match_operand:HI 2 "" "")
21645        (const_string "1")
21646        (const_string "*")))
21647    (set (attr "prefix_rex")
21648      (if_then_else (match_operand:QI 2 "ext_QIreg_operand" "")
21649        (const_string "1")
21650        (const_string "*")))
21651    (set_attr "mode" "SI")])
21652
21653 (define_insn "sse4_2_crc32di"
21654   [(set (match_operand:DI 0 "register_operand" "=r")
21655         (unspec:DI
21656           [(match_operand:DI 1 "register_operand" "0")
21657            (match_operand:DI 2 "nonimmediate_operand" "rm")]
21658           UNSPEC_CRC32))]
21659   "TARGET_64BIT && (TARGET_SSE4_2 || TARGET_CRC32)"
21660   "crc32q\t{%2, %0|%0, %2}"
21661   [(set_attr "type" "sselog1")
21662    (set_attr "prefix_rep" "1")
21663    (set_attr "prefix_extra" "1")
21664    (set_attr "mode" "DI")])
21665
21666 (define_expand "rdpmc"
21667   [(match_operand:DI 0 "register_operand" "")
21668    (match_operand:SI 1 "register_operand" "")]
21669   ""
21670 {
21671   rtx reg = gen_reg_rtx (DImode);
21672   rtx si;
21673
21674   /* Force operand 1 into ECX.  */
21675   rtx ecx = gen_rtx_REG (SImode, CX_REG);
21676   emit_insn (gen_rtx_SET (VOIDmode, ecx, operands[1]));
21677   si = gen_rtx_UNSPEC_VOLATILE (DImode, gen_rtvec (1, ecx),
21678                                 UNSPECV_RDPMC);
21679
21680   if (TARGET_64BIT)
21681     {
21682       rtvec vec = rtvec_alloc (2);
21683       rtx load = gen_rtx_PARALLEL (VOIDmode, vec);
21684       rtx upper = gen_reg_rtx (DImode);
21685       rtx di = gen_rtx_UNSPEC_VOLATILE (DImode,
21686                                         gen_rtvec (1, const0_rtx),
21687                                         UNSPECV_RDPMC);
21688       RTVEC_ELT (vec, 0) = gen_rtx_SET (VOIDmode, reg, si);
21689       RTVEC_ELT (vec, 1) = gen_rtx_SET (VOIDmode, upper, di);
21690       emit_insn (load);
21691       upper = expand_simple_binop (DImode, ASHIFT, upper, GEN_INT (32),
21692                                    NULL, 1, OPTAB_DIRECT);
21693       reg = expand_simple_binop (DImode, IOR, reg, upper, reg, 1,
21694                                  OPTAB_DIRECT);
21695     }
21696   else
21697     emit_insn (gen_rtx_SET (VOIDmode, reg, si));
21698   emit_insn (gen_rtx_SET (VOIDmode, operands[0], reg));
21699   DONE;
21700 })
21701
21702 (define_insn "*rdpmc"
21703   [(set (match_operand:DI 0 "register_operand" "=A")
21704         (unspec_volatile:DI [(match_operand:SI 1 "register_operand" "c")]
21705                             UNSPECV_RDPMC))]
21706   "!TARGET_64BIT"
21707   "rdpmc"
21708   [(set_attr "type" "other")
21709    (set_attr "length" "2")])
21710
21711 (define_insn "*rdpmc_rex64"
21712   [(set (match_operand:DI 0 "register_operand" "=a")
21713         (unspec_volatile:DI [(match_operand:SI 2 "register_operand" "c")]
21714                             UNSPECV_RDPMC))
21715   (set (match_operand:DI 1 "register_operand" "=d")
21716        (unspec_volatile:DI [(const_int 0)] UNSPECV_RDPMC))]
21717   "TARGET_64BIT"
21718   "rdpmc"
21719   [(set_attr "type" "other")
21720    (set_attr "length" "2")])
21721
21722 (define_expand "rdtsc"
21723   [(set (match_operand:DI 0 "register_operand" "")
21724         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSC))]
21725   ""
21726 {
21727   if (TARGET_64BIT)
21728     {
21729       rtvec vec = rtvec_alloc (2);
21730       rtx load = gen_rtx_PARALLEL (VOIDmode, vec);
21731       rtx upper = gen_reg_rtx (DImode);
21732       rtx lower = gen_reg_rtx (DImode);
21733       rtx src = gen_rtx_UNSPEC_VOLATILE (DImode,
21734                                          gen_rtvec (1, const0_rtx),
21735                                          UNSPECV_RDTSC);
21736       RTVEC_ELT (vec, 0) = gen_rtx_SET (VOIDmode, lower, src);
21737       RTVEC_ELT (vec, 1) = gen_rtx_SET (VOIDmode, upper, src);
21738       emit_insn (load);
21739       upper = expand_simple_binop (DImode, ASHIFT, upper, GEN_INT (32),
21740                                    NULL, 1, OPTAB_DIRECT);
21741       lower = expand_simple_binop (DImode, IOR, lower, upper, lower, 1,
21742                                    OPTAB_DIRECT);
21743       emit_insn (gen_rtx_SET (VOIDmode, operands[0], lower));
21744       DONE;
21745     }
21746 })
21747
21748 (define_insn "*rdtsc"
21749   [(set (match_operand:DI 0 "register_operand" "=A")
21750         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSC))]
21751   "!TARGET_64BIT"
21752   "rdtsc"
21753   [(set_attr "type" "other")
21754    (set_attr "length" "2")])
21755
21756 (define_insn "*rdtsc_rex64"
21757   [(set (match_operand:DI 0 "register_operand" "=a")
21758         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSC))
21759    (set (match_operand:DI 1 "register_operand" "=d")
21760         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSC))]
21761   "TARGET_64BIT"
21762   "rdtsc"
21763   [(set_attr "type" "other")
21764    (set_attr "length" "2")])
21765
21766 (define_expand "rdtscp"
21767   [(match_operand:DI 0 "register_operand" "")
21768    (match_operand:SI 1 "memory_operand" "")]
21769   ""
21770 {
21771   rtx di = gen_rtx_UNSPEC_VOLATILE (DImode,
21772                                     gen_rtvec (1, const0_rtx),
21773                                     UNSPECV_RDTSCP);
21774   rtx si = gen_rtx_UNSPEC_VOLATILE (SImode,
21775                                     gen_rtvec (1, const0_rtx),
21776                                     UNSPECV_RDTSCP);
21777   rtx reg = gen_reg_rtx (DImode);
21778   rtx tmp = gen_reg_rtx (SImode);
21779
21780   if (TARGET_64BIT)
21781     {
21782       rtvec vec = rtvec_alloc (3);
21783       rtx load = gen_rtx_PARALLEL (VOIDmode, vec);
21784       rtx upper = gen_reg_rtx (DImode);
21785       RTVEC_ELT (vec, 0) = gen_rtx_SET (VOIDmode, reg, di);
21786       RTVEC_ELT (vec, 1) = gen_rtx_SET (VOIDmode, upper, di);
21787       RTVEC_ELT (vec, 2) = gen_rtx_SET (VOIDmode, tmp, si);
21788       emit_insn (load);
21789       upper = expand_simple_binop (DImode, ASHIFT, upper, GEN_INT (32),
21790                                    NULL, 1, OPTAB_DIRECT);
21791       reg = expand_simple_binop (DImode, IOR, reg, upper, reg, 1,
21792                                  OPTAB_DIRECT);
21793     }
21794   else
21795     {
21796       rtvec vec = rtvec_alloc (2);
21797       rtx load = gen_rtx_PARALLEL (VOIDmode, vec);
21798       RTVEC_ELT (vec, 0) = gen_rtx_SET (VOIDmode, reg, di);
21799       RTVEC_ELT (vec, 1) = gen_rtx_SET (VOIDmode, tmp, si);
21800       emit_insn (load);
21801     }
21802   emit_insn (gen_rtx_SET (VOIDmode, operands[0], reg));
21803   emit_insn (gen_rtx_SET (VOIDmode, operands[1], tmp));
21804   DONE;
21805 })
21806
21807 (define_insn "*rdtscp"
21808   [(set (match_operand:DI 0 "register_operand" "=A")
21809         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSCP))
21810    (set (match_operand:SI 1 "register_operand" "=c")
21811         (unspec_volatile:SI [(const_int 0)] UNSPECV_RDTSCP))]
21812   "!TARGET_64BIT"
21813   "rdtscp"
21814   [(set_attr "type" "other")
21815    (set_attr "length" "3")])
21816
21817 (define_insn "*rdtscp_rex64"
21818   [(set (match_operand:DI 0 "register_operand" "=a")
21819         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSCP))
21820    (set (match_operand:DI 1 "register_operand" "=d")
21821         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSCP))
21822    (set (match_operand:SI 2 "register_operand" "=c")
21823         (unspec_volatile:SI [(const_int 0)] UNSPECV_RDTSCP))]
21824   "TARGET_64BIT"
21825   "rdtscp"
21826   [(set_attr "type" "other")
21827    (set_attr "length" "3")])
21828
21829 (include "mmx.md")
21830 (include "sse.md")
21831 (include "sync.md")