OSDN Git Service

13a1cded196d935040d49b8d22c3497c02f3bacb
[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, 2010, 2011
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 ;; F,f -- likewise, but for floating-point.
34 ;; O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
35 ;;      otherwise nothing
36 ;; R -- print the prefix for register names.
37 ;; z -- print the opcode suffix for the size of the current operand.
38 ;; Z -- likewise, with special suffixes for x87 instructions.
39 ;; * -- print a star (in certain assembler syntax)
40 ;; A -- print an absolute memory reference.
41 ;; w -- print the operand as if it's a "word" (HImode) even if it isn't.
42 ;; s -- print a shift double count, followed by the assemblers argument
43 ;;      delimiter.
44 ;; b -- print the QImode name of the register for the indicated operand.
45 ;;      %b0 would print %al if operands[0] is reg 0.
46 ;; w --  likewise, print the HImode name of the register.
47 ;; k --  likewise, print the SImode name of the register.
48 ;; q --  likewise, print the DImode name of the register.
49 ;; x --  likewise, print the V4SFmode name of the register.
50 ;; t --  likewise, print the V8SFmode name of the register.
51 ;; h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
52 ;; y -- print "st(0)" instead of "st" as a register.
53 ;; d -- print duplicated register operand for AVX instruction.
54 ;; D -- print condition for SSE cmp instruction.
55 ;; P -- if PIC, print an @PLT suffix.
56 ;; X -- don't print any sort of PIC '@' suffix for a symbol.
57 ;; & -- print some in-use local-dynamic symbol name.
58 ;; H -- print a memory address offset by 8; used for sse high-parts
59 ;; Y -- print condition for XOP pcom* instruction.
60 ;; + -- print a branch hint as 'cs' or 'ds' prefix
61 ;; ; -- print a semicolon (after prefixes due to bug in older gas).
62 ;; @ -- print a segment register of thread base pointer load
63
64 ;; UNSPEC usage:
65
66 (define_c_enum "unspec" [
67   ;; Relocation specifiers
68   UNSPEC_GOT
69   UNSPEC_GOTOFF
70   UNSPEC_GOTPCREL
71   UNSPEC_GOTTPOFF
72   UNSPEC_TPOFF
73   UNSPEC_NTPOFF
74   UNSPEC_DTPOFF
75   UNSPEC_GOTNTPOFF
76   UNSPEC_INDNTPOFF
77   UNSPEC_PLTOFF
78   UNSPEC_MACHOPIC_OFFSET
79   UNSPEC_PCREL
80
81   ;; Prologue support
82   UNSPEC_STACK_ALLOC
83   UNSPEC_SET_GOT
84   UNSPEC_REG_SAVE
85   UNSPEC_DEF_CFA
86   UNSPEC_SET_RIP
87   UNSPEC_SET_GOT_OFFSET
88   UNSPEC_MEMORY_BLOCKAGE
89   UNSPEC_STACK_CHECK
90
91   ;; TLS support
92   UNSPEC_TP
93   UNSPEC_TLS_GD
94   UNSPEC_TLS_LD_BASE
95   UNSPEC_TLSDESC
96   UNSPEC_TLS_IE_SUN
97
98   ;; Other random patterns
99   UNSPEC_SCAS
100   UNSPEC_FNSTSW
101   UNSPEC_SAHF
102   UNSPEC_PARITY
103   UNSPEC_FSTCW
104   UNSPEC_ADD_CARRY
105   UNSPEC_FLDCW
106   UNSPEC_REP
107   UNSPEC_LD_MPIC        ; load_macho_picbase
108   UNSPEC_TRUNC_NOOP
109   UNSPEC_DIV_ALREADY_SPLIT
110   UNSPEC_CALL_NEEDS_VZEROUPPER
111   UNSPEC_PAUSE
112
113   ;; For SSE/MMX support:
114   UNSPEC_FIX_NOTRUNC
115   UNSPEC_MASKMOV
116   UNSPEC_MOVMSK
117   UNSPEC_MOVNT
118   UNSPEC_MOVU
119   UNSPEC_RCP
120   UNSPEC_RSQRT
121   UNSPEC_SFENCE
122   UNSPEC_PFRCP
123   UNSPEC_PFRCPIT1
124   UNSPEC_PFRCPIT2
125   UNSPEC_PFRSQRT
126   UNSPEC_PFRSQIT1
127   UNSPEC_MFENCE
128   UNSPEC_LFENCE
129   UNSPEC_PSADBW
130   UNSPEC_LDDQU
131   UNSPEC_MS_TO_SYSV_CALL
132
133   ;; Generic math support
134   UNSPEC_COPYSIGN
135   UNSPEC_IEEE_MIN       ; not commutative
136   UNSPEC_IEEE_MAX       ; not commutative
137
138   ;; x87 Floating point
139   UNSPEC_SIN
140   UNSPEC_COS
141   UNSPEC_FPATAN
142   UNSPEC_FYL2X
143   UNSPEC_FYL2XP1
144   UNSPEC_FRNDINT
145   UNSPEC_FIST
146   UNSPEC_F2XM1
147   UNSPEC_TAN
148   UNSPEC_FXAM
149
150   ;; x87 Rounding
151   UNSPEC_FRNDINT_FLOOR
152   UNSPEC_FRNDINT_CEIL
153   UNSPEC_FRNDINT_TRUNC
154   UNSPEC_FRNDINT_MASK_PM
155   UNSPEC_FIST_FLOOR
156   UNSPEC_FIST_CEIL
157
158   ;; x87 Double output FP
159   UNSPEC_SINCOS_COS
160   UNSPEC_SINCOS_SIN
161   UNSPEC_XTRACT_FRACT
162   UNSPEC_XTRACT_EXP
163   UNSPEC_FSCALE_FRACT
164   UNSPEC_FSCALE_EXP
165   UNSPEC_FPREM_F
166   UNSPEC_FPREM_U
167   UNSPEC_FPREM1_F
168   UNSPEC_FPREM1_U
169
170   UNSPEC_C2_FLAG
171   UNSPEC_FXAM_MEM
172
173   ;; SSP patterns
174   UNSPEC_SP_SET
175   UNSPEC_SP_TEST
176   UNSPEC_SP_TLS_SET
177   UNSPEC_SP_TLS_TEST
178
179   ;; SSSE3
180   UNSPEC_PSHUFB
181   UNSPEC_PSIGN
182   UNSPEC_PALIGNR
183
184   ;; For SSE4A support
185   UNSPEC_EXTRQI
186   UNSPEC_EXTRQ
187   UNSPEC_INSERTQI
188   UNSPEC_INSERTQ
189
190   ;; For SSE4.1 support
191   UNSPEC_BLENDV
192   UNSPEC_INSERTPS
193   UNSPEC_DP
194   UNSPEC_MOVNTDQA
195   UNSPEC_MPSADBW
196   UNSPEC_PHMINPOSUW
197   UNSPEC_PTEST
198   UNSPEC_ROUND
199
200   ;; For SSE4.2 support
201   UNSPEC_CRC32
202   UNSPEC_PCMPESTR
203   UNSPEC_PCMPISTR
204
205   ;; For FMA4 support
206   UNSPEC_FMADDSUB
207   UNSPEC_XOP_UNSIGNED_CMP
208   UNSPEC_XOP_TRUEFALSE
209   UNSPEC_XOP_PERMUTE
210   UNSPEC_FRCZ
211
212   ;; For AES support
213   UNSPEC_AESENC
214   UNSPEC_AESENCLAST
215   UNSPEC_AESDEC
216   UNSPEC_AESDECLAST
217   UNSPEC_AESIMC
218   UNSPEC_AESKEYGENASSIST
219
220   ;; For PCLMUL support
221   UNSPEC_PCLMUL
222
223   ;; For AVX support
224   UNSPEC_PCMP
225   UNSPEC_VPERMIL
226   UNSPEC_VPERMIL2
227   UNSPEC_VPERMIL2F128
228   UNSPEC_CAST
229   UNSPEC_VTESTP
230   UNSPEC_VCVTPH2PS
231   UNSPEC_VCVTPS2PH
232
233   ;; For BMI support
234   UNSPEC_BEXTR
235
236   ;; For RDRAND support
237   UNSPEC_RDRAND
238 ])
239
240 (define_c_enum "unspecv" [
241   UNSPECV_BLOCKAGE
242   UNSPECV_STACK_PROBE
243   UNSPECV_PROBE_STACK_RANGE
244   UNSPECV_EMMS
245   UNSPECV_LDMXCSR
246   UNSPECV_STMXCSR
247   UNSPECV_FEMMS
248   UNSPECV_CLFLUSH
249   UNSPECV_ALIGN
250   UNSPECV_MONITOR
251   UNSPECV_MWAIT
252   UNSPECV_CMPXCHG
253   UNSPECV_XCHG
254   UNSPECV_LOCK
255   UNSPECV_PROLOGUE_USE
256   UNSPECV_CLD
257   UNSPECV_NOPS
258   UNSPECV_VZEROALL
259   UNSPECV_VZEROUPPER
260   UNSPECV_RDTSC
261   UNSPECV_RDTSCP
262   UNSPECV_RDPMC
263   UNSPECV_LLWP_INTRINSIC
264   UNSPECV_SLWP_INTRINSIC
265   UNSPECV_LWPVAL_INTRINSIC
266   UNSPECV_LWPINS_INTRINSIC
267   UNSPECV_RDFSBASE
268   UNSPECV_RDGSBASE
269   UNSPECV_WRFSBASE
270   UNSPECV_WRGSBASE
271   UNSPECV_SPLIT_STACK_RETURN
272 ])
273
274 ;; Constants to represent rounding modes in the ROUND instruction
275 (define_constants
276   [(ROUND_FLOOR                 0x1)
277    (ROUND_CEIL                  0x2)
278    (ROUND_TRUNC                 0x3)
279    (ROUND_MXCSR                 0x4)
280    (ROUND_NO_EXC                0x8)
281   ])
282
283 ;; Constants to represent pcomtrue/pcomfalse variants
284 (define_constants
285   [(PCOM_FALSE                  0)
286    (PCOM_TRUE                   1)
287    (COM_FALSE_S                 2)
288    (COM_FALSE_P                 3)
289    (COM_TRUE_S                  4)
290    (COM_TRUE_P                  5)
291   ])
292
293 ;; Constants used in the XOP pperm instruction
294 (define_constants
295   [(PPERM_SRC                   0x00)   /* copy source */
296    (PPERM_INVERT                0x20)   /* invert source */
297    (PPERM_REVERSE               0x40)   /* bit reverse source */
298    (PPERM_REV_INV               0x60)   /* bit reverse & invert src */
299    (PPERM_ZERO                  0x80)   /* all 0's */
300    (PPERM_ONES                  0xa0)   /* all 1's */
301    (PPERM_SIGN                  0xc0)   /* propagate sign bit */
302    (PPERM_INV_SIGN              0xe0)   /* invert & propagate sign */
303    (PPERM_SRC1                  0x00)   /* use first source byte */
304    (PPERM_SRC2                  0x10)   /* use second source byte */
305    ])
306
307 ;; Registers by name.
308 (define_constants
309   [(AX_REG                       0)
310    (DX_REG                       1)
311    (CX_REG                       2)
312    (BX_REG                       3)
313    (SI_REG                       4)
314    (DI_REG                       5)
315    (BP_REG                       6)
316    (SP_REG                       7)
317    (ST0_REG                      8)
318    (ST1_REG                      9)
319    (ST2_REG                     10)
320    (ST3_REG                     11)
321    (ST4_REG                     12)
322    (ST5_REG                     13)
323    (ST6_REG                     14)
324    (ST7_REG                     15)
325    (FLAGS_REG                   17)
326    (FPSR_REG                    18)
327    (FPCR_REG                    19)
328    (XMM0_REG                    21)
329    (XMM1_REG                    22)
330    (XMM2_REG                    23)
331    (XMM3_REG                    24)
332    (XMM4_REG                    25)
333    (XMM5_REG                    26)
334    (XMM6_REG                    27)
335    (XMM7_REG                    28)
336    (MM0_REG                     29)
337    (MM1_REG                     30)
338    (MM2_REG                     31)
339    (MM3_REG                     32)
340    (MM4_REG                     33)
341    (MM5_REG                     34)
342    (MM6_REG                     35)
343    (MM7_REG                     36)
344    (R8_REG                      37)
345    (R9_REG                      38)
346    (R10_REG                     39)
347    (R11_REG                     40)
348    (R12_REG                     41)
349    (R13_REG                     42)
350    (XMM8_REG                    45)
351    (XMM9_REG                    46)
352    (XMM10_REG                   47)
353    (XMM11_REG                   48)
354    (XMM12_REG                   49)
355    (XMM13_REG                   50)
356    (XMM14_REG                   51)
357    (XMM15_REG                   52)
358   ])
359
360 ;; Insns whose names begin with "x86_" are emitted by gen_FOO calls
361 ;; from i386.c.
362
363 ;; In C guard expressions, put expressions which may be compile-time
364 ;; constants first.  This allows for better optimization.  For
365 ;; example, write "TARGET_64BIT && reload_completed", not
366 ;; "reload_completed && TARGET_64BIT".
367
368 \f
369 ;; Processor type.
370 (define_attr "cpu" "none,pentium,pentiumpro,geode,k6,athlon,k8,core2,corei7,
371                     atom,generic64,amdfam10,bdver1,btver1"
372   (const (symbol_ref "ix86_schedule")))
373
374 ;; A basic instruction type.  Refinements due to arguments to be
375 ;; provided in other attributes.
376 (define_attr "type"
377   "other,multi,
378    alu,alu1,negnot,imov,imovx,lea,
379    incdec,ishift,ishift1,rotate,rotate1,imul,idiv,
380    icmp,test,ibr,setcc,icmov,
381    push,pop,call,callv,leave,
382    str,bitmanip,
383    fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,fxch,fistp,fisttp,frndint,
384    sselog,sselog1,sseiadd,sseiadd1,sseishft,sseishft1,sseimul,
385    sse,ssemov,sseadd,ssemul,ssecmp,ssecomi,ssecvt,ssecvt1,sseicvt,ssediv,sseins,
386    ssemuladd,sse4arg,lwp,
387    mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft"
388   (const_string "other"))
389
390 ;; Main data type used by the insn
391 (define_attr "mode"
392   "unknown,none,QI,HI,SI,DI,TI,OI,SF,DF,XF,TF,V8SF,V4DF,V4SF,V2DF,V2SF,V1DF"
393   (const_string "unknown"))
394
395 ;; The CPU unit operations uses.
396 (define_attr "unit" "integer,i387,sse,mmx,unknown"
397   (cond [(eq_attr "type" "fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,fxch,fistp,fisttp,frndint")
398            (const_string "i387")
399          (eq_attr "type" "sselog,sselog1,sseiadd,sseiadd1,sseishft,sseishft1,sseimul,
400                           sse,ssemov,sseadd,ssemul,ssecmp,ssecomi,ssecvt,
401                           ssecvt1,sseicvt,ssediv,sseins,ssemuladd,sse4arg")
402            (const_string "sse")
403          (eq_attr "type" "mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft")
404            (const_string "mmx")
405          (eq_attr "type" "other")
406            (const_string "unknown")]
407          (const_string "integer")))
408
409 ;; The (bounding maximum) length of an instruction immediate.
410 (define_attr "length_immediate" ""
411   (cond [(eq_attr "type" "incdec,setcc,icmov,str,lea,other,multi,idiv,leave,
412                           bitmanip")
413            (const_int 0)
414          (eq_attr "unit" "i387,sse,mmx")
415            (const_int 0)
416          (eq_attr "type" "alu,alu1,negnot,imovx,ishift,rotate,ishift1,rotate1,
417                           imul,icmp,push,pop")
418            (symbol_ref "ix86_attr_length_immediate_default (insn, true)")
419          (eq_attr "type" "imov,test")
420            (symbol_ref "ix86_attr_length_immediate_default (insn, false)")
421          (eq_attr "type" "call")
422            (if_then_else (match_operand 0 "constant_call_address_operand" "")
423              (const_int 4)
424              (const_int 0))
425          (eq_attr "type" "callv")
426            (if_then_else (match_operand 1 "constant_call_address_operand" "")
427              (const_int 4)
428              (const_int 0))
429          ;; We don't know the size before shorten_branches.  Expect
430          ;; the instruction to fit for better scheduling.
431          (eq_attr "type" "ibr")
432            (const_int 1)
433          ]
434          (symbol_ref "/* Update immediate_length and other attributes! */
435                       gcc_unreachable (),1")))
436
437 ;; The (bounding maximum) length of an instruction address.
438 (define_attr "length_address" ""
439   (cond [(eq_attr "type" "str,other,multi,fxch")
440            (const_int 0)
441          (and (eq_attr "type" "call")
442               (match_operand 0 "constant_call_address_operand" ""))
443              (const_int 0)
444          (and (eq_attr "type" "callv")
445               (match_operand 1 "constant_call_address_operand" ""))
446              (const_int 0)
447          ]
448          (symbol_ref "ix86_attr_length_address_default (insn)")))
449
450 ;; Set when length prefix is used.
451 (define_attr "prefix_data16" ""
452   (cond [(eq_attr "type" "ssemuladd,sse4arg,sseiadd1,ssecvt1")
453            (const_int 0)
454          (eq_attr "mode" "HI")
455            (const_int 1)
456          (and (eq_attr "unit" "sse") (eq_attr "mode" "V2DF,TI"))
457            (const_int 1)
458         ]
459         (const_int 0)))
460
461 ;; Set when string REP prefix is used.
462 (define_attr "prefix_rep" ""
463   (cond [(eq_attr "type" "ssemuladd,sse4arg,sseiadd1,ssecvt1")
464            (const_int 0)
465          (and (eq_attr "unit" "sse") (eq_attr "mode" "SF,DF"))
466            (const_int 1)
467         ]
468         (const_int 0)))
469
470 ;; Set when 0f opcode prefix is used.
471 (define_attr "prefix_0f" ""
472   (if_then_else
473     (ior (eq_attr "type" "imovx,setcc,icmov,bitmanip")
474          (eq_attr "unit" "sse,mmx"))
475     (const_int 1)
476     (const_int 0)))
477
478 ;; Set when REX opcode prefix is used.
479 (define_attr "prefix_rex" ""
480   (cond [(eq (symbol_ref "TARGET_64BIT") (const_int 0))
481            (const_int 0)
482          (and (eq_attr "mode" "DI")
483               (and (eq_attr "type" "!push,pop,call,callv,leave,ibr")
484                    (eq_attr "unit" "!mmx")))
485            (const_int 1)
486          (and (eq_attr "mode" "QI")
487               (ne (symbol_ref "x86_extended_QIreg_mentioned_p (insn)")
488                   (const_int 0)))
489            (const_int 1)
490          (ne (symbol_ref "x86_extended_reg_mentioned_p (insn)")
491              (const_int 0))
492            (const_int 1)
493          (and (eq_attr "type" "imovx")
494               (match_operand:QI 1 "ext_QIreg_operand" ""))
495            (const_int 1)
496         ]
497         (const_int 0)))
498
499 ;; There are also additional prefixes in 3DNOW, SSSE3.
500 ;; ssemuladd,sse4arg default to 0f24/0f25 and DREX byte,
501 ;; sseiadd1,ssecvt1 to 0f7a with no DREX byte.
502 ;; 3DNOW has 0f0f prefix, SSSE3 and SSE4_{1,2} 0f38/0f3a.
503 (define_attr "prefix_extra" ""
504   (cond [(eq_attr "type" "ssemuladd,sse4arg")
505            (const_int 2)
506          (eq_attr "type" "sseiadd1,ssecvt1")
507            (const_int 1)
508         ]
509         (const_int 0)))
510
511 ;; Prefix used: original, VEX or maybe VEX.
512 (define_attr "prefix" "orig,vex,maybe_vex"
513   (if_then_else (eq_attr "mode" "OI,V8SF,V4DF")
514     (const_string "vex")
515     (const_string "orig")))
516
517 ;; VEX W bit is used.
518 (define_attr "prefix_vex_w" "" (const_int 0))
519
520 ;; The length of VEX prefix
521 ;; Only instructions with 0f prefix can have 2 byte VEX prefix,
522 ;; 0f38/0f3a prefixes can't.  In i386.md 0f3[8a] is
523 ;; still prefix_0f 1, with prefix_extra 1.
524 (define_attr "length_vex" ""
525   (if_then_else (and (eq_attr "prefix_0f" "1")
526                      (eq_attr "prefix_extra" "0"))
527     (if_then_else (eq_attr "prefix_vex_w" "1")
528       (symbol_ref "ix86_attr_length_vex_default (insn, true, true)")
529       (symbol_ref "ix86_attr_length_vex_default (insn, true, false)"))
530     (if_then_else (eq_attr "prefix_vex_w" "1")
531       (symbol_ref "ix86_attr_length_vex_default (insn, false, true)")
532       (symbol_ref "ix86_attr_length_vex_default (insn, false, false)"))))
533
534 ;; Set when modrm byte is used.
535 (define_attr "modrm" ""
536   (cond [(eq_attr "type" "str,leave")
537            (const_int 0)
538          (eq_attr "unit" "i387")
539            (const_int 0)
540          (and (eq_attr "type" "incdec")
541               (and (eq (symbol_ref "TARGET_64BIT") (const_int 0))
542                    (ior (match_operand:SI 1 "register_operand" "")
543                         (match_operand:HI 1 "register_operand" ""))))
544            (const_int 0)
545          (and (eq_attr "type" "push")
546               (not (match_operand 1 "memory_operand" "")))
547            (const_int 0)
548          (and (eq_attr "type" "pop")
549               (not (match_operand 0 "memory_operand" "")))
550            (const_int 0)
551          (and (eq_attr "type" "imov")
552               (and (not (eq_attr "mode" "DI"))
553                    (ior (and (match_operand 0 "register_operand" "")
554                              (match_operand 1 "immediate_operand" ""))
555                         (ior (and (match_operand 0 "ax_reg_operand" "")
556                                   (match_operand 1 "memory_displacement_only_operand" ""))
557                              (and (match_operand 0 "memory_displacement_only_operand" "")
558                                   (match_operand 1 "ax_reg_operand" ""))))))
559            (const_int 0)
560          (and (eq_attr "type" "call")
561               (match_operand 0 "constant_call_address_operand" ""))
562              (const_int 0)
563          (and (eq_attr "type" "callv")
564               (match_operand 1 "constant_call_address_operand" ""))
565              (const_int 0)
566          (and (eq_attr "type" "alu,alu1,icmp,test")
567               (match_operand 0 "ax_reg_operand" ""))
568              (symbol_ref "(get_attr_length_immediate (insn) <= (get_attr_mode (insn) != MODE_QI))")
569          ]
570          (const_int 1)))
571
572 ;; The (bounding maximum) length of an instruction in bytes.
573 ;; ??? fistp and frndint are in fact fldcw/{fistp,frndint}/fldcw sequences.
574 ;; Later we may want to split them and compute proper length as for
575 ;; other insns.
576 (define_attr "length" ""
577   (cond [(eq_attr "type" "other,multi,fistp,frndint")
578            (const_int 16)
579          (eq_attr "type" "fcmp")
580            (const_int 4)
581          (eq_attr "unit" "i387")
582            (plus (const_int 2)
583                  (plus (attr "prefix_data16")
584                        (attr "length_address")))
585          (ior (eq_attr "prefix" "vex")
586               (and (eq_attr "prefix" "maybe_vex")
587                     (ne (symbol_ref "TARGET_AVX") (const_int 0))))
588            (plus (attr "length_vex")
589                  (plus (attr "length_immediate")
590                        (plus (attr "modrm")
591                              (attr "length_address"))))]
592          (plus (plus (attr "modrm")
593                      (plus (attr "prefix_0f")
594                            (plus (attr "prefix_rex")
595                                  (plus (attr "prefix_extra")
596                                        (const_int 1)))))
597                (plus (attr "prefix_rep")
598                      (plus (attr "prefix_data16")
599                            (plus (attr "length_immediate")
600                                  (attr "length_address")))))))
601
602 ;; The `memory' attribute is `none' if no memory is referenced, `load' or
603 ;; `store' if there is a simple memory reference therein, or `unknown'
604 ;; if the instruction is complex.
605
606 (define_attr "memory" "none,load,store,both,unknown"
607   (cond [(eq_attr "type" "other,multi,str,lwp")
608            (const_string "unknown")
609          (eq_attr "type" "lea,fcmov,fpspc")
610            (const_string "none")
611          (eq_attr "type" "fistp,leave")
612            (const_string "both")
613          (eq_attr "type" "frndint")
614            (const_string "load")
615          (eq_attr "type" "push")
616            (if_then_else (match_operand 1 "memory_operand" "")
617              (const_string "both")
618              (const_string "store"))
619          (eq_attr "type" "pop")
620            (if_then_else (match_operand 0 "memory_operand" "")
621              (const_string "both")
622              (const_string "load"))
623          (eq_attr "type" "setcc")
624            (if_then_else (match_operand 0 "memory_operand" "")
625              (const_string "store")
626              (const_string "none"))
627          (eq_attr "type" "icmp,test,ssecmp,ssecomi,mmxcmp,fcmp")
628            (if_then_else (ior (match_operand 0 "memory_operand" "")
629                               (match_operand 1 "memory_operand" ""))
630              (const_string "load")
631              (const_string "none"))
632          (eq_attr "type" "ibr")
633            (if_then_else (match_operand 0 "memory_operand" "")
634              (const_string "load")
635              (const_string "none"))
636          (eq_attr "type" "call")
637            (if_then_else (match_operand 0 "constant_call_address_operand" "")
638              (const_string "none")
639              (const_string "load"))
640          (eq_attr "type" "callv")
641            (if_then_else (match_operand 1 "constant_call_address_operand" "")
642              (const_string "none")
643              (const_string "load"))
644          (and (eq_attr "type" "alu1,negnot,ishift1,sselog1")
645               (match_operand 1 "memory_operand" ""))
646            (const_string "both")
647          (and (match_operand 0 "memory_operand" "")
648               (match_operand 1 "memory_operand" ""))
649            (const_string "both")
650          (match_operand 0 "memory_operand" "")
651            (const_string "store")
652          (match_operand 1 "memory_operand" "")
653            (const_string "load")
654          (and (eq_attr "type"
655                  "!alu1,negnot,ishift1,
656                    imov,imovx,icmp,test,bitmanip,
657                    fmov,fcmp,fsgn,
658                    sse,ssemov,ssecmp,ssecomi,ssecvt,ssecvt1,sseicvt,sselog1,
659                    sseiadd1,mmx,mmxmov,mmxcmp,mmxcvt")
660               (match_operand 2 "memory_operand" ""))
661            (const_string "load")
662          (and (eq_attr "type" "icmov,ssemuladd,sse4arg")
663               (match_operand 3 "memory_operand" ""))
664            (const_string "load")
665         ]
666         (const_string "none")))
667
668 ;; Indicates if an instruction has both an immediate and a displacement.
669
670 (define_attr "imm_disp" "false,true,unknown"
671   (cond [(eq_attr "type" "other,multi")
672            (const_string "unknown")
673          (and (eq_attr "type" "icmp,test,imov,alu1,ishift1,rotate1")
674               (and (match_operand 0 "memory_displacement_operand" "")
675                    (match_operand 1 "immediate_operand" "")))
676            (const_string "true")
677          (and (eq_attr "type" "alu,ishift,rotate,imul,idiv")
678               (and (match_operand 0 "memory_displacement_operand" "")
679                    (match_operand 2 "immediate_operand" "")))
680            (const_string "true")
681         ]
682         (const_string "false")))
683
684 ;; Indicates if an FP operation has an integer source.
685
686 (define_attr "fp_int_src" "false,true"
687   (const_string "false"))
688
689 ;; Defines rounding mode of an FP operation.
690
691 (define_attr "i387_cw" "trunc,floor,ceil,mask_pm,uninitialized,any"
692   (const_string "any"))
693
694 ;; Define attribute to classify add/sub insns that consumes carry flag (CF)
695 (define_attr "use_carry" "0,1" (const_string "0"))
696
697 ;; Define attribute to indicate unaligned ssemov insns
698 (define_attr "movu" "0,1" (const_string "0"))
699
700 ;; Used to control the "enabled" attribute on a per-instruction basis.
701 (define_attr "isa" "base,noavx,avx"
702   (const_string "base"))
703
704 (define_attr "enabled" ""
705   (cond [(eq_attr "isa" "noavx") (symbol_ref "!TARGET_AVX")
706          (eq_attr "isa" "avx") (symbol_ref "TARGET_AVX")
707         ]
708         (const_int 1)))
709
710 ;; Describe a user's asm statement.
711 (define_asm_attributes
712   [(set_attr "length" "128")
713    (set_attr "type" "multi")])
714
715 (define_code_iterator plusminus [plus minus])
716
717 (define_code_iterator sat_plusminus [ss_plus us_plus ss_minus us_minus])
718
719 ;; Base name for define_insn
720 (define_code_attr plusminus_insn
721   [(plus "add") (ss_plus "ssadd") (us_plus "usadd")
722    (minus "sub") (ss_minus "sssub") (us_minus "ussub")])
723
724 ;; Base name for insn mnemonic.
725 (define_code_attr plusminus_mnemonic
726   [(plus "add") (ss_plus "adds") (us_plus "addus")
727    (minus "sub") (ss_minus "subs") (us_minus "subus")])
728 (define_code_attr plusminus_carry_mnemonic
729   [(plus "adc") (minus "sbb")])
730
731 ;; Mark commutative operators as such in constraints.
732 (define_code_attr comm [(plus "%") (ss_plus "%") (us_plus "%")
733                         (minus "") (ss_minus "") (us_minus "")])
734
735 ;; Mapping of signed max and min
736 (define_code_iterator smaxmin [smax smin])
737
738 ;; Mapping of unsigned max and min
739 (define_code_iterator umaxmin [umax umin])
740
741 ;; Base name for integer and FP insn mnemonic
742 (define_code_attr maxmin_int [(smax "maxs") (smin "mins")
743                               (umax "maxu") (umin "minu")])
744 (define_code_attr maxmin_float [(smax "max") (smin "min")])
745
746 ;; Mapping of logic operators
747 (define_code_iterator any_logic [and ior xor])
748 (define_code_iterator any_or [ior xor])
749
750 ;; Base name for insn mnemonic.
751 (define_code_attr logic [(and "and") (ior "or") (xor "xor")])
752
753 ;; Mapping of shift-right operators
754 (define_code_iterator any_shiftrt [lshiftrt ashiftrt])
755
756 ;; Base name for define_insn
757 (define_code_attr shiftrt_insn [(lshiftrt "lshr") (ashiftrt "ashr")])
758
759 ;; Base name for insn mnemonic.
760 (define_code_attr shiftrt [(lshiftrt "shr") (ashiftrt "sar")])
761
762 ;; Mapping of rotate operators
763 (define_code_iterator any_rotate [rotate rotatert])
764
765 ;; Base name for define_insn
766 (define_code_attr rotate_insn [(rotate "rotl") (rotatert "rotr")])
767
768 ;; Base name for insn mnemonic.
769 (define_code_attr rotate [(rotate "rol") (rotatert "ror")])
770
771 ;; Mapping of abs neg operators
772 (define_code_iterator absneg [abs neg])
773
774 ;; Base name for x87 insn mnemonic.
775 (define_code_attr absneg_mnemonic [(abs "abs") (neg "chs")])
776
777 ;; Used in signed and unsigned widening multiplications.
778 (define_code_iterator any_extend [sign_extend zero_extend])
779
780 ;; Various insn prefixes for signed and unsigned operations.
781 (define_code_attr u [(sign_extend "") (zero_extend "u")
782                      (div "") (udiv "u")])
783 (define_code_attr s [(sign_extend "s") (zero_extend "u")])
784
785 ;; Used in signed and unsigned divisions.
786 (define_code_iterator any_div [div udiv])
787
788 ;; Instruction prefix for signed and unsigned operations.
789 (define_code_attr sgnprefix [(sign_extend "i") (zero_extend "")
790                              (div "i") (udiv "")])
791
792 ;; 64bit single word integer modes.
793 (define_mode_iterator SWI1248x [QI HI SI DI])
794
795 ;; 64bit single word integer modes without QImode and HImode.
796 (define_mode_iterator SWI48x [SI DI])
797
798 ;; Single word integer modes.
799 (define_mode_iterator SWI [QI HI SI (DI "TARGET_64BIT")])
800
801 ;; Single word integer modes without SImode and DImode.
802 (define_mode_iterator SWI12 [QI HI])
803
804 ;; Single word integer modes without DImode.
805 (define_mode_iterator SWI124 [QI HI SI])
806
807 ;; Single word integer modes without QImode and DImode.
808 (define_mode_iterator SWI24 [HI SI])
809
810 ;; Single word integer modes without QImode.
811 (define_mode_iterator SWI248 [HI SI (DI "TARGET_64BIT")])
812
813 ;; Single word integer modes without QImode and HImode.
814 (define_mode_iterator SWI48 [SI (DI "TARGET_64BIT")])
815
816 ;; All math-dependant single and double word integer modes.
817 (define_mode_iterator SDWIM [(QI "TARGET_QIMODE_MATH")
818                              (HI "TARGET_HIMODE_MATH")
819                              SI DI (TI "TARGET_64BIT")])
820
821 ;; Math-dependant single word integer modes.
822 (define_mode_iterator SWIM [(QI "TARGET_QIMODE_MATH")
823                             (HI "TARGET_HIMODE_MATH")
824                             SI (DI "TARGET_64BIT")])
825
826 ;; Math-dependant single word integer modes without DImode.
827 (define_mode_iterator SWIM124 [(QI "TARGET_QIMODE_MATH")
828                                (HI "TARGET_HIMODE_MATH")
829                                SI])
830
831 ;; Math-dependant single word integer modes without QImode.
832 (define_mode_iterator SWIM248 [(HI "TARGET_HIMODE_MATH")
833                                SI (DI "TARGET_64BIT")])
834
835 ;; Double word integer modes.
836 (define_mode_iterator DWI [(DI "!TARGET_64BIT")
837                            (TI "TARGET_64BIT")])
838
839 ;; Double word integer modes as mode attribute.
840 (define_mode_attr DWI [(SI "DI") (DI "TI")])
841 (define_mode_attr dwi [(SI "di") (DI "ti")])
842
843 ;; Half mode for double word integer modes.
844 (define_mode_iterator DWIH [(SI "!TARGET_64BIT")
845                             (DI "TARGET_64BIT")])
846
847 ;; Instruction suffix for integer modes.
848 (define_mode_attr imodesuffix [(QI "b") (HI "w") (SI "l") (DI "q")])
849
850 ;; Pointer size prefix for integer modes (Intel asm dialect)
851 (define_mode_attr iptrsize [(QI "BYTE")
852                             (HI "WORD")
853                             (SI "DWORD")
854                             (DI "QWORD")])
855
856 ;; Register class for integer modes.
857 (define_mode_attr r [(QI "q") (HI "r") (SI "r") (DI "r")])
858
859 ;; Immediate operand constraint for integer modes.
860 (define_mode_attr i [(QI "n") (HI "n") (SI "i") (DI "e")])
861
862 ;; General operand constraint for word modes.
863 (define_mode_attr g [(QI "qmn") (HI "rmn") (SI "g") (DI "rme")])
864
865 ;; Immediate operand constraint for double integer modes.
866 (define_mode_attr di [(SI "iF") (DI "e")])
867
868 ;; Immediate operand constraint for shifts.
869 (define_mode_attr S [(QI "I") (HI "I") (SI "I") (DI "J") (TI "O")])
870
871 ;; General operand predicate for integer modes.
872 (define_mode_attr general_operand
873         [(QI "general_operand")
874          (HI "general_operand")
875          (SI "general_operand")
876          (DI "x86_64_general_operand")
877          (TI "x86_64_general_operand")])
878
879 ;; General sign/zero extend operand predicate for integer modes.
880 (define_mode_attr general_szext_operand
881         [(QI "general_operand")
882          (HI "general_operand")
883          (SI "general_operand")
884          (DI "x86_64_szext_general_operand")])
885
886 ;; Immediate operand predicate for integer modes.
887 (define_mode_attr immediate_operand
888         [(QI "immediate_operand")
889          (HI "immediate_operand")
890          (SI "immediate_operand")
891          (DI "x86_64_immediate_operand")])
892
893 ;; Nonmemory operand predicate for integer modes.
894 (define_mode_attr nonmemory_operand
895         [(QI "nonmemory_operand")
896          (HI "nonmemory_operand")
897          (SI "nonmemory_operand")
898          (DI "x86_64_nonmemory_operand")])
899
900 ;; Operand predicate for shifts.
901 (define_mode_attr shift_operand
902         [(QI "nonimmediate_operand")
903          (HI "nonimmediate_operand")
904          (SI "nonimmediate_operand")
905          (DI "shiftdi_operand")
906          (TI "register_operand")])
907
908 ;; Operand predicate for shift argument.
909 (define_mode_attr shift_immediate_operand
910         [(QI "const_1_to_31_operand")
911          (HI "const_1_to_31_operand")
912          (SI "const_1_to_31_operand")
913          (DI "const_1_to_63_operand")])
914
915 ;; Input operand predicate for arithmetic left shifts.
916 (define_mode_attr ashl_input_operand
917         [(QI "nonimmediate_operand")
918          (HI "nonimmediate_operand")
919          (SI "nonimmediate_operand")
920          (DI "ashldi_input_operand")
921          (TI "reg_or_pm1_operand")])
922
923 ;; SSE and x87 SFmode and DFmode floating point modes
924 (define_mode_iterator MODEF [SF DF])
925
926 ;; All x87 floating point modes
927 (define_mode_iterator X87MODEF [SF DF XF])
928
929 ;; All integer modes handled by x87 fisttp operator.
930 (define_mode_iterator X87MODEI [HI SI DI])
931
932 ;; All integer modes handled by integer x87 operators.
933 (define_mode_iterator X87MODEI12 [HI SI])
934
935 ;; All integer modes handled by SSE cvtts?2si* operators.
936 (define_mode_iterator SSEMODEI24 [SI DI])
937
938 ;; SSE instruction suffix for various modes
939 (define_mode_attr ssemodesuffix
940   [(SF "ss") (DF "sd")
941    (V8SF "ps") (V4DF "pd")
942    (V4SF "ps") (V2DF "pd")
943    (V16QI "b") (V8HI "w") (V4SI "d") (V2DI "q")
944    (V8SI "si")])
945
946 ;; SSE vector suffix for floating point modes
947 (define_mode_attr ssevecmodesuffix [(SF "ps") (DF "pd")])
948
949 ;; SSE vector mode corresponding to a scalar mode
950 (define_mode_attr ssevecmode
951   [(QI "V16QI") (HI "V8HI") (SI "V4SI") (DI "V2DI") (SF "V4SF") (DF "V2DF")])
952
953 ;; Instruction suffix for REX 64bit operators.
954 (define_mode_attr rex64suffix [(SI "") (DI "{q}")])
955
956 ;; This mode iterator allows :P to be used for patterns that operate on
957 ;; pointer-sized quantities.  Exactly one of the two alternatives will match.
958 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
959 \f
960 ;; Scheduling descriptions
961
962 (include "pentium.md")
963 (include "ppro.md")
964 (include "k6.md")
965 (include "athlon.md")
966 (include "bdver1.md")
967 (include "geode.md")
968 (include "atom.md")
969 (include "core2.md")
970
971 \f
972 ;; Operand and operator predicates and constraints
973
974 (include "predicates.md")
975 (include "constraints.md")
976
977 \f
978 ;; Compare and branch/compare and store instructions.
979
980 (define_expand "cbranch<mode>4"
981   [(set (reg:CC FLAGS_REG)
982         (compare:CC (match_operand:SDWIM 1 "nonimmediate_operand" "")
983                     (match_operand:SDWIM 2 "<general_operand>" "")))
984    (set (pc) (if_then_else
985                (match_operator 0 "ordered_comparison_operator"
986                 [(reg:CC FLAGS_REG) (const_int 0)])
987                (label_ref (match_operand 3 "" ""))
988                (pc)))]
989   ""
990 {
991   if (MEM_P (operands[1]) && MEM_P (operands[2]))
992     operands[1] = force_reg (<MODE>mode, operands[1]);
993   ix86_expand_branch (GET_CODE (operands[0]),
994                       operands[1], operands[2], operands[3]);
995   DONE;
996 })
997
998 (define_expand "cstore<mode>4"
999   [(set (reg:CC FLAGS_REG)
1000         (compare:CC (match_operand:SWIM 2 "nonimmediate_operand" "")
1001                     (match_operand:SWIM 3 "<general_operand>" "")))
1002    (set (match_operand:QI 0 "register_operand" "")
1003         (match_operator 1 "ordered_comparison_operator"
1004           [(reg:CC FLAGS_REG) (const_int 0)]))]
1005   ""
1006 {
1007   if (MEM_P (operands[2]) && MEM_P (operands[3]))
1008     operands[2] = force_reg (<MODE>mode, operands[2]);
1009   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1010                      operands[2], operands[3]);
1011   DONE;
1012 })
1013
1014 (define_expand "cmp<mode>_1"
1015   [(set (reg:CC FLAGS_REG)
1016         (compare:CC (match_operand:SWI48 0 "nonimmediate_operand" "")
1017                     (match_operand:SWI48 1 "<general_operand>" "")))])
1018
1019 (define_insn "*cmp<mode>_ccno_1"
1020   [(set (reg FLAGS_REG)
1021         (compare (match_operand:SWI 0 "nonimmediate_operand" "<r>,?m<r>")
1022                  (match_operand:SWI 1 "const0_operand" "")))]
1023   "ix86_match_ccmode (insn, CCNOmode)"
1024   "@
1025    test{<imodesuffix>}\t%0, %0
1026    cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
1027   [(set_attr "type" "test,icmp")
1028    (set_attr "length_immediate" "0,1")
1029    (set_attr "mode" "<MODE>")])
1030
1031 (define_insn "*cmp<mode>_1"
1032   [(set (reg FLAGS_REG)
1033         (compare (match_operand:SWI 0 "nonimmediate_operand" "<r>m,<r>")
1034                  (match_operand:SWI 1 "<general_operand>" "<r><i>,<r>m")))]
1035   "ix86_match_ccmode (insn, CCmode)"
1036   "cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
1037   [(set_attr "type" "icmp")
1038    (set_attr "mode" "<MODE>")])
1039
1040 (define_insn "*cmp<mode>_minus_1"
1041   [(set (reg FLAGS_REG)
1042         (compare
1043           (minus:SWI (match_operand:SWI 0 "nonimmediate_operand" "<r>m,<r>")
1044                      (match_operand:SWI 1 "<general_operand>" "<r><i>,<r>m"))
1045           (const_int 0)))]
1046   "ix86_match_ccmode (insn, CCGOCmode)"
1047   "cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
1048   [(set_attr "type" "icmp")
1049    (set_attr "mode" "<MODE>")])
1050
1051 (define_insn "*cmpqi_ext_1"
1052   [(set (reg FLAGS_REG)
1053         (compare
1054           (match_operand:QI 0 "general_operand" "Qm")
1055           (subreg:QI
1056             (zero_extract:SI
1057               (match_operand 1 "ext_register_operand" "Q")
1058               (const_int 8)
1059               (const_int 8)) 0)))]
1060   "!TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1061   "cmp{b}\t{%h1, %0|%0, %h1}"
1062   [(set_attr "type" "icmp")
1063    (set_attr "mode" "QI")])
1064
1065 (define_insn "*cmpqi_ext_1_rex64"
1066   [(set (reg FLAGS_REG)
1067         (compare
1068           (match_operand:QI 0 "register_operand" "Q")
1069           (subreg:QI
1070             (zero_extract:SI
1071               (match_operand 1 "ext_register_operand" "Q")
1072               (const_int 8)
1073               (const_int 8)) 0)))]
1074   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1075   "cmp{b}\t{%h1, %0|%0, %h1}"
1076   [(set_attr "type" "icmp")
1077    (set_attr "mode" "QI")])
1078
1079 (define_insn "*cmpqi_ext_2"
1080   [(set (reg FLAGS_REG)
1081         (compare
1082           (subreg:QI
1083             (zero_extract:SI
1084               (match_operand 0 "ext_register_operand" "Q")
1085               (const_int 8)
1086               (const_int 8)) 0)
1087           (match_operand:QI 1 "const0_operand" "")))]
1088   "ix86_match_ccmode (insn, CCNOmode)"
1089   "test{b}\t%h0, %h0"
1090   [(set_attr "type" "test")
1091    (set_attr "length_immediate" "0")
1092    (set_attr "mode" "QI")])
1093
1094 (define_expand "cmpqi_ext_3"
1095   [(set (reg:CC FLAGS_REG)
1096         (compare:CC
1097           (subreg:QI
1098             (zero_extract:SI
1099               (match_operand 0 "ext_register_operand" "")
1100               (const_int 8)
1101               (const_int 8)) 0)
1102           (match_operand:QI 1 "immediate_operand" "")))])
1103
1104 (define_insn "*cmpqi_ext_3_insn"
1105   [(set (reg FLAGS_REG)
1106         (compare
1107           (subreg:QI
1108             (zero_extract:SI
1109               (match_operand 0 "ext_register_operand" "Q")
1110               (const_int 8)
1111               (const_int 8)) 0)
1112           (match_operand:QI 1 "general_operand" "Qmn")))]
1113   "!TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1114   "cmp{b}\t{%1, %h0|%h0, %1}"
1115   [(set_attr "type" "icmp")
1116    (set_attr "modrm" "1")
1117    (set_attr "mode" "QI")])
1118
1119 (define_insn "*cmpqi_ext_3_insn_rex64"
1120   [(set (reg FLAGS_REG)
1121         (compare
1122           (subreg:QI
1123             (zero_extract:SI
1124               (match_operand 0 "ext_register_operand" "Q")
1125               (const_int 8)
1126               (const_int 8)) 0)
1127           (match_operand:QI 1 "nonmemory_operand" "Qn")))]
1128   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1129   "cmp{b}\t{%1, %h0|%h0, %1}"
1130   [(set_attr "type" "icmp")
1131    (set_attr "modrm" "1")
1132    (set_attr "mode" "QI")])
1133
1134 (define_insn "*cmpqi_ext_4"
1135   [(set (reg FLAGS_REG)
1136         (compare
1137           (subreg:QI
1138             (zero_extract:SI
1139               (match_operand 0 "ext_register_operand" "Q")
1140               (const_int 8)
1141               (const_int 8)) 0)
1142           (subreg:QI
1143             (zero_extract:SI
1144               (match_operand 1 "ext_register_operand" "Q")
1145               (const_int 8)
1146               (const_int 8)) 0)))]
1147   "ix86_match_ccmode (insn, CCmode)"
1148   "cmp{b}\t{%h1, %h0|%h0, %h1}"
1149   [(set_attr "type" "icmp")
1150    (set_attr "mode" "QI")])
1151
1152 ;; These implement float point compares.
1153 ;; %%% See if we can get away with VOIDmode operands on the actual insns,
1154 ;; which would allow mix and match FP modes on the compares.  Which is what
1155 ;; the old patterns did, but with many more of them.
1156
1157 (define_expand "cbranchxf4"
1158   [(set (reg:CC FLAGS_REG)
1159         (compare:CC (match_operand:XF 1 "nonmemory_operand" "")
1160                     (match_operand:XF 2 "nonmemory_operand" "")))
1161    (set (pc) (if_then_else
1162               (match_operator 0 "ix86_fp_comparison_operator"
1163                [(reg:CC FLAGS_REG)
1164                 (const_int 0)])
1165               (label_ref (match_operand 3 "" ""))
1166               (pc)))]
1167   "TARGET_80387"
1168 {
1169   ix86_expand_branch (GET_CODE (operands[0]),
1170                       operands[1], operands[2], operands[3]);
1171   DONE;
1172 })
1173
1174 (define_expand "cstorexf4"
1175   [(set (reg:CC FLAGS_REG)
1176         (compare:CC (match_operand:XF 2 "nonmemory_operand" "")
1177                     (match_operand:XF 3 "nonmemory_operand" "")))
1178    (set (match_operand:QI 0 "register_operand" "")
1179               (match_operator 1 "ix86_fp_comparison_operator"
1180                [(reg:CC FLAGS_REG)
1181                 (const_int 0)]))]
1182   "TARGET_80387"
1183 {
1184   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1185                      operands[2], operands[3]);
1186   DONE;
1187 })
1188
1189 (define_expand "cbranch<mode>4"
1190   [(set (reg:CC FLAGS_REG)
1191         (compare:CC (match_operand:MODEF 1 "cmp_fp_expander_operand" "")
1192                     (match_operand:MODEF 2 "cmp_fp_expander_operand" "")))
1193    (set (pc) (if_then_else
1194               (match_operator 0 "ix86_fp_comparison_operator"
1195                [(reg:CC FLAGS_REG)
1196                 (const_int 0)])
1197               (label_ref (match_operand 3 "" ""))
1198               (pc)))]
1199   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
1200 {
1201   ix86_expand_branch (GET_CODE (operands[0]),
1202                       operands[1], operands[2], operands[3]);
1203   DONE;
1204 })
1205
1206 (define_expand "cstore<mode>4"
1207   [(set (reg:CC FLAGS_REG)
1208         (compare:CC (match_operand:MODEF 2 "cmp_fp_expander_operand" "")
1209                     (match_operand:MODEF 3 "cmp_fp_expander_operand" "")))
1210    (set (match_operand:QI 0 "register_operand" "")
1211               (match_operator 1 "ix86_fp_comparison_operator"
1212                [(reg:CC FLAGS_REG)
1213                 (const_int 0)]))]
1214   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
1215 {
1216   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1217                      operands[2], operands[3]);
1218   DONE;
1219 })
1220
1221 (define_expand "cbranchcc4"
1222   [(set (pc) (if_then_else
1223               (match_operator 0 "comparison_operator"
1224                [(match_operand 1 "flags_reg_operand" "")
1225                 (match_operand 2 "const0_operand" "")])
1226               (label_ref (match_operand 3 "" ""))
1227               (pc)))]
1228   ""
1229 {
1230   ix86_expand_branch (GET_CODE (operands[0]),
1231                       operands[1], operands[2], operands[3]);
1232   DONE;
1233 })
1234
1235 (define_expand "cstorecc4"
1236   [(set (match_operand:QI 0 "register_operand" "")
1237               (match_operator 1 "comparison_operator"
1238                [(match_operand 2 "flags_reg_operand" "")
1239                 (match_operand 3 "const0_operand" "")]))]
1240   ""
1241 {
1242   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1243                      operands[2], operands[3]);
1244   DONE;
1245 })
1246
1247
1248 ;; FP compares, step 1:
1249 ;; Set the FP condition codes.
1250 ;;
1251 ;; CCFPmode     compare with exceptions
1252 ;; CCFPUmode    compare with no exceptions
1253
1254 ;; We may not use "#" to split and emit these, since the REG_DEAD notes
1255 ;; used to manage the reg stack popping would not be preserved.
1256
1257 (define_insn "*cmpfp_0"
1258   [(set (match_operand:HI 0 "register_operand" "=a")
1259         (unspec:HI
1260           [(compare:CCFP
1261              (match_operand 1 "register_operand" "f")
1262              (match_operand 2 "const0_operand" ""))]
1263         UNSPEC_FNSTSW))]
1264   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1265    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1266   "* return output_fp_compare (insn, operands, false, false);"
1267   [(set_attr "type" "multi")
1268    (set_attr "unit" "i387")
1269    (set (attr "mode")
1270      (cond [(match_operand:SF 1 "" "")
1271               (const_string "SF")
1272             (match_operand:DF 1 "" "")
1273               (const_string "DF")
1274            ]
1275            (const_string "XF")))])
1276
1277 (define_insn_and_split "*cmpfp_0_cc"
1278   [(set (reg:CCFP FLAGS_REG)
1279         (compare:CCFP
1280           (match_operand 1 "register_operand" "f")
1281           (match_operand 2 "const0_operand" "")))
1282    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1283   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1284    && TARGET_SAHF && !TARGET_CMOVE
1285    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1286   "#"
1287   "&& reload_completed"
1288   [(set (match_dup 0)
1289         (unspec:HI
1290           [(compare:CCFP (match_dup 1)(match_dup 2))]
1291         UNSPEC_FNSTSW))
1292    (set (reg:CC FLAGS_REG)
1293         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1294   ""
1295   [(set_attr "type" "multi")
1296    (set_attr "unit" "i387")
1297    (set (attr "mode")
1298      (cond [(match_operand:SF 1 "" "")
1299               (const_string "SF")
1300             (match_operand:DF 1 "" "")
1301               (const_string "DF")
1302            ]
1303            (const_string "XF")))])
1304
1305 (define_insn "*cmpfp_xf"
1306   [(set (match_operand:HI 0 "register_operand" "=a")
1307         (unspec:HI
1308           [(compare:CCFP
1309              (match_operand:XF 1 "register_operand" "f")
1310              (match_operand:XF 2 "register_operand" "f"))]
1311           UNSPEC_FNSTSW))]
1312   "TARGET_80387"
1313   "* return output_fp_compare (insn, operands, false, false);"
1314   [(set_attr "type" "multi")
1315    (set_attr "unit" "i387")
1316    (set_attr "mode" "XF")])
1317
1318 (define_insn_and_split "*cmpfp_xf_cc"
1319   [(set (reg:CCFP FLAGS_REG)
1320         (compare:CCFP
1321           (match_operand:XF 1 "register_operand" "f")
1322           (match_operand:XF 2 "register_operand" "f")))
1323    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1324   "TARGET_80387
1325    && TARGET_SAHF && !TARGET_CMOVE"
1326   "#"
1327   "&& reload_completed"
1328   [(set (match_dup 0)
1329         (unspec:HI
1330           [(compare:CCFP (match_dup 1)(match_dup 2))]
1331         UNSPEC_FNSTSW))
1332    (set (reg:CC FLAGS_REG)
1333         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1334   ""
1335   [(set_attr "type" "multi")
1336    (set_attr "unit" "i387")
1337    (set_attr "mode" "XF")])
1338
1339 (define_insn "*cmpfp_<mode>"
1340   [(set (match_operand:HI 0 "register_operand" "=a")
1341         (unspec:HI
1342           [(compare:CCFP
1343              (match_operand:MODEF 1 "register_operand" "f")
1344              (match_operand:MODEF 2 "nonimmediate_operand" "fm"))]
1345           UNSPEC_FNSTSW))]
1346   "TARGET_80387"
1347   "* return output_fp_compare (insn, operands, false, false);"
1348   [(set_attr "type" "multi")
1349    (set_attr "unit" "i387")
1350    (set_attr "mode" "<MODE>")])
1351
1352 (define_insn_and_split "*cmpfp_<mode>_cc"
1353   [(set (reg:CCFP FLAGS_REG)
1354         (compare:CCFP
1355           (match_operand:MODEF 1 "register_operand" "f")
1356           (match_operand:MODEF 2 "nonimmediate_operand" "fm")))
1357    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1358   "TARGET_80387
1359    && TARGET_SAHF && !TARGET_CMOVE"
1360   "#"
1361   "&& reload_completed"
1362   [(set (match_dup 0)
1363         (unspec:HI
1364           [(compare:CCFP (match_dup 1)(match_dup 2))]
1365         UNSPEC_FNSTSW))
1366    (set (reg:CC FLAGS_REG)
1367         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1368   ""
1369   [(set_attr "type" "multi")
1370    (set_attr "unit" "i387")
1371    (set_attr "mode" "<MODE>")])
1372
1373 (define_insn "*cmpfp_u"
1374   [(set (match_operand:HI 0 "register_operand" "=a")
1375         (unspec:HI
1376           [(compare:CCFPU
1377              (match_operand 1 "register_operand" "f")
1378              (match_operand 2 "register_operand" "f"))]
1379           UNSPEC_FNSTSW))]
1380   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1381    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1382   "* return output_fp_compare (insn, operands, false, true);"
1383   [(set_attr "type" "multi")
1384    (set_attr "unit" "i387")
1385    (set (attr "mode")
1386      (cond [(match_operand:SF 1 "" "")
1387               (const_string "SF")
1388             (match_operand:DF 1 "" "")
1389               (const_string "DF")
1390            ]
1391            (const_string "XF")))])
1392
1393 (define_insn_and_split "*cmpfp_u_cc"
1394   [(set (reg:CCFPU FLAGS_REG)
1395         (compare:CCFPU
1396           (match_operand 1 "register_operand" "f")
1397           (match_operand 2 "register_operand" "f")))
1398    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1399   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1400    && TARGET_SAHF && !TARGET_CMOVE
1401    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1402   "#"
1403   "&& reload_completed"
1404   [(set (match_dup 0)
1405         (unspec:HI
1406           [(compare:CCFPU (match_dup 1)(match_dup 2))]
1407         UNSPEC_FNSTSW))
1408    (set (reg:CC FLAGS_REG)
1409         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1410   ""
1411   [(set_attr "type" "multi")
1412    (set_attr "unit" "i387")
1413    (set (attr "mode")
1414      (cond [(match_operand:SF 1 "" "")
1415               (const_string "SF")
1416             (match_operand:DF 1 "" "")
1417               (const_string "DF")
1418            ]
1419            (const_string "XF")))])
1420
1421 (define_insn "*cmpfp_<mode>"
1422   [(set (match_operand:HI 0 "register_operand" "=a")
1423         (unspec:HI
1424           [(compare:CCFP
1425              (match_operand 1 "register_operand" "f")
1426              (match_operator 3 "float_operator"
1427                [(match_operand:X87MODEI12 2 "memory_operand" "m")]))]
1428           UNSPEC_FNSTSW))]
1429   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1430    && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))
1431    && (GET_MODE (operands [3]) == GET_MODE (operands[1]))"
1432   "* return output_fp_compare (insn, operands, false, false);"
1433   [(set_attr "type" "multi")
1434    (set_attr "unit" "i387")
1435    (set_attr "fp_int_src" "true")
1436    (set_attr "mode" "<MODE>")])
1437
1438 (define_insn_and_split "*cmpfp_<mode>_cc"
1439   [(set (reg:CCFP FLAGS_REG)
1440         (compare:CCFP
1441           (match_operand 1 "register_operand" "f")
1442           (match_operator 3 "float_operator"
1443             [(match_operand:X87MODEI12 2 "memory_operand" "m")])))
1444    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1445   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1446    && TARGET_SAHF && !TARGET_CMOVE
1447    && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))
1448    && (GET_MODE (operands [3]) == GET_MODE (operands[1]))"
1449   "#"
1450   "&& reload_completed"
1451   [(set (match_dup 0)
1452         (unspec:HI
1453           [(compare:CCFP
1454              (match_dup 1)
1455              (match_op_dup 3 [(match_dup 2)]))]
1456         UNSPEC_FNSTSW))
1457    (set (reg:CC FLAGS_REG)
1458         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1459   ""
1460   [(set_attr "type" "multi")
1461    (set_attr "unit" "i387")
1462    (set_attr "fp_int_src" "true")
1463    (set_attr "mode" "<MODE>")])
1464
1465 ;; FP compares, step 2
1466 ;; Move the fpsw to ax.
1467
1468 (define_insn "x86_fnstsw_1"
1469   [(set (match_operand:HI 0 "register_operand" "=a")
1470         (unspec:HI [(reg:CCFP FPSR_REG)] UNSPEC_FNSTSW))]
1471   "TARGET_80387"
1472   "fnstsw\t%0"
1473   [(set (attr "length") (symbol_ref "ix86_attr_length_address_default (insn) + 2"))
1474    (set_attr "mode" "SI")
1475    (set_attr "unit" "i387")])
1476
1477 ;; FP compares, step 3
1478 ;; Get ax into flags, general case.
1479
1480 (define_insn "x86_sahf_1"
1481   [(set (reg:CC FLAGS_REG)
1482         (unspec:CC [(match_operand:HI 0 "register_operand" "a")]
1483                    UNSPEC_SAHF))]
1484   "TARGET_SAHF"
1485 {
1486 #ifndef HAVE_AS_IX86_SAHF
1487   if (TARGET_64BIT)
1488     return ASM_BYTE "0x9e";
1489   else
1490 #endif
1491   return "sahf";
1492 }
1493   [(set_attr "length" "1")
1494    (set_attr "athlon_decode" "vector")
1495    (set_attr "amdfam10_decode" "direct")
1496    (set_attr "bdver1_decode" "direct")
1497    (set_attr "mode" "SI")])
1498
1499 ;; Pentium Pro can do steps 1 through 3 in one go.
1500 ;; comi*, ucomi*, fcomi*, ficomi*,fucomi* (i387 instructions set condition codes)
1501 (define_insn "*cmpfp_i_mixed"
1502   [(set (reg:CCFP FLAGS_REG)
1503         (compare:CCFP (match_operand 0 "register_operand" "f,x")
1504                       (match_operand 1 "nonimmediate_operand" "f,xm")))]
1505   "TARGET_MIX_SSE_I387
1506    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1507    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1508   "* return output_fp_compare (insn, operands, true, false);"
1509   [(set_attr "type" "fcmp,ssecomi")
1510    (set_attr "prefix" "orig,maybe_vex")
1511    (set (attr "mode")
1512      (if_then_else (match_operand:SF 1 "" "")
1513         (const_string "SF")
1514         (const_string "DF")))
1515    (set (attr "prefix_rep")
1516         (if_then_else (eq_attr "type" "ssecomi")
1517                       (const_string "0")
1518                       (const_string "*")))
1519    (set (attr "prefix_data16")
1520         (cond [(eq_attr "type" "fcmp")
1521                  (const_string "*")
1522                (eq_attr "mode" "DF")
1523                  (const_string "1")
1524               ]
1525               (const_string "0")))
1526    (set_attr "athlon_decode" "vector")
1527    (set_attr "amdfam10_decode" "direct")
1528    (set_attr "bdver1_decode" "double")])
1529
1530 (define_insn "*cmpfp_i_sse"
1531   [(set (reg:CCFP FLAGS_REG)
1532         (compare:CCFP (match_operand 0 "register_operand" "x")
1533                       (match_operand 1 "nonimmediate_operand" "xm")))]
1534   "TARGET_SSE_MATH
1535    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1536    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1537   "* return output_fp_compare (insn, operands, true, false);"
1538   [(set_attr "type" "ssecomi")
1539    (set_attr "prefix" "maybe_vex")
1540    (set (attr "mode")
1541      (if_then_else (match_operand:SF 1 "" "")
1542         (const_string "SF")
1543         (const_string "DF")))
1544    (set_attr "prefix_rep" "0")
1545    (set (attr "prefix_data16")
1546         (if_then_else (eq_attr "mode" "DF")
1547                       (const_string "1")
1548                       (const_string "0")))
1549    (set_attr "athlon_decode" "vector")
1550    (set_attr "amdfam10_decode" "direct")
1551    (set_attr "bdver1_decode" "double")])
1552
1553 (define_insn "*cmpfp_i_i387"
1554   [(set (reg:CCFP FLAGS_REG)
1555         (compare:CCFP (match_operand 0 "register_operand" "f")
1556                       (match_operand 1 "register_operand" "f")))]
1557   "X87_FLOAT_MODE_P (GET_MODE (operands[0]))
1558    && TARGET_CMOVE
1559    && !(SSE_FLOAT_MODE_P (GET_MODE (operands[0])) && TARGET_SSE_MATH)
1560    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1561   "* return output_fp_compare (insn, operands, true, false);"
1562   [(set_attr "type" "fcmp")
1563    (set (attr "mode")
1564      (cond [(match_operand:SF 1 "" "")
1565               (const_string "SF")
1566             (match_operand:DF 1 "" "")
1567               (const_string "DF")
1568            ]
1569            (const_string "XF")))
1570    (set_attr "athlon_decode" "vector")
1571    (set_attr "amdfam10_decode" "direct")
1572    (set_attr "bdver1_decode" "double")])
1573
1574 (define_insn "*cmpfp_iu_mixed"
1575   [(set (reg:CCFPU FLAGS_REG)
1576         (compare:CCFPU (match_operand 0 "register_operand" "f,x")
1577                        (match_operand 1 "nonimmediate_operand" "f,xm")))]
1578   "TARGET_MIX_SSE_I387
1579    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1580    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1581   "* return output_fp_compare (insn, operands, true, true);"
1582   [(set_attr "type" "fcmp,ssecomi")
1583    (set_attr "prefix" "orig,maybe_vex")
1584    (set (attr "mode")
1585      (if_then_else (match_operand:SF 1 "" "")
1586         (const_string "SF")
1587         (const_string "DF")))
1588    (set (attr "prefix_rep")
1589         (if_then_else (eq_attr "type" "ssecomi")
1590                       (const_string "0")
1591                       (const_string "*")))
1592    (set (attr "prefix_data16")
1593         (cond [(eq_attr "type" "fcmp")
1594                  (const_string "*")
1595                (eq_attr "mode" "DF")
1596                  (const_string "1")
1597               ]
1598               (const_string "0")))
1599    (set_attr "athlon_decode" "vector")
1600    (set_attr "amdfam10_decode" "direct")
1601    (set_attr "bdver1_decode" "double")])
1602
1603 (define_insn "*cmpfp_iu_sse"
1604   [(set (reg:CCFPU FLAGS_REG)
1605         (compare:CCFPU (match_operand 0 "register_operand" "x")
1606                        (match_operand 1 "nonimmediate_operand" "xm")))]
1607   "TARGET_SSE_MATH
1608    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1609    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1610   "* return output_fp_compare (insn, operands, true, true);"
1611   [(set_attr "type" "ssecomi")
1612    (set_attr "prefix" "maybe_vex")
1613    (set (attr "mode")
1614      (if_then_else (match_operand:SF 1 "" "")
1615         (const_string "SF")
1616         (const_string "DF")))
1617    (set_attr "prefix_rep" "0")
1618    (set (attr "prefix_data16")
1619         (if_then_else (eq_attr "mode" "DF")
1620                       (const_string "1")
1621                       (const_string "0")))
1622    (set_attr "athlon_decode" "vector")
1623    (set_attr "amdfam10_decode" "direct")
1624    (set_attr "bdver1_decode" "double")])
1625
1626 (define_insn "*cmpfp_iu_387"
1627   [(set (reg:CCFPU FLAGS_REG)
1628         (compare:CCFPU (match_operand 0 "register_operand" "f")
1629                        (match_operand 1 "register_operand" "f")))]
1630   "X87_FLOAT_MODE_P (GET_MODE (operands[0]))
1631    && TARGET_CMOVE
1632    && !(SSE_FLOAT_MODE_P (GET_MODE (operands[0])) && TARGET_SSE_MATH)
1633    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1634   "* return output_fp_compare (insn, operands, true, true);"
1635   [(set_attr "type" "fcmp")
1636    (set (attr "mode")
1637      (cond [(match_operand:SF 1 "" "")
1638               (const_string "SF")
1639             (match_operand:DF 1 "" "")
1640               (const_string "DF")
1641            ]
1642            (const_string "XF")))
1643    (set_attr "athlon_decode" "vector")
1644    (set_attr "amdfam10_decode" "direct")
1645    (set_attr "bdver1_decode" "direct")])
1646 \f
1647 ;; Push/pop instructions.
1648
1649 (define_insn "*push<mode>2"
1650   [(set (match_operand:DWI 0 "push_operand" "=<")
1651         (match_operand:DWI 1 "general_no_elim_operand" "riF*m"))]
1652   ""
1653   "#")
1654
1655 (define_split
1656   [(set (match_operand:TI 0 "push_operand" "")
1657         (match_operand:TI 1 "general_operand" ""))]
1658   "TARGET_64BIT && reload_completed
1659    && !SSE_REG_P (operands[1])"
1660   [(const_int 0)]
1661   "ix86_split_long_move (operands); DONE;")
1662
1663 (define_insn "*pushdi2_rex64"
1664   [(set (match_operand:DI 0 "push_operand" "=<,!<")
1665         (match_operand:DI 1 "general_no_elim_operand" "re*m,n"))]
1666   "TARGET_64BIT"
1667   "@
1668    push{q}\t%1
1669    #"
1670   [(set_attr "type" "push,multi")
1671    (set_attr "mode" "DI")])
1672
1673 ;; Convert impossible pushes of immediate to existing instructions.
1674 ;; First try to get scratch register and go through it.  In case this
1675 ;; fails, push sign extended lower part first and then overwrite
1676 ;; upper part by 32bit move.
1677 (define_peephole2
1678   [(match_scratch:DI 2 "r")
1679    (set (match_operand:DI 0 "push_operand" "")
1680         (match_operand:DI 1 "immediate_operand" ""))]
1681   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
1682    && !x86_64_immediate_operand (operands[1], DImode)"
1683   [(set (match_dup 2) (match_dup 1))
1684    (set (match_dup 0) (match_dup 2))])
1685
1686 ;; We need to define this as both peepholer and splitter for case
1687 ;; peephole2 pass is not run.
1688 ;; "&& 1" is needed to keep it from matching the previous pattern.
1689 (define_peephole2
1690   [(set (match_operand:DI 0 "push_operand" "")
1691         (match_operand:DI 1 "immediate_operand" ""))]
1692   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
1693    && !x86_64_immediate_operand (operands[1], DImode) && 1"
1694   [(set (match_dup 0) (match_dup 1))
1695    (set (match_dup 2) (match_dup 3))]
1696 {
1697   split_double_mode (DImode, &operands[1], 1, &operands[2], &operands[3]);
1698
1699   operands[1] = gen_lowpart (DImode, operands[2]);
1700   operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (DImode, stack_pointer_rtx,
1701                                                    GEN_INT (4)));
1702 })
1703
1704 (define_split
1705   [(set (match_operand:DI 0 "push_operand" "")
1706         (match_operand:DI 1 "immediate_operand" ""))]
1707   "TARGET_64BIT && ((optimize > 0 && flag_peephole2)
1708                     ? epilogue_completed : reload_completed)
1709    && !symbolic_operand (operands[1], DImode)
1710    && !x86_64_immediate_operand (operands[1], DImode)"
1711   [(set (match_dup 0) (match_dup 1))
1712    (set (match_dup 2) (match_dup 3))]
1713 {
1714   split_double_mode (DImode, &operands[1], 1, &operands[2], &operands[3]);
1715
1716   operands[1] = gen_lowpart (DImode, operands[2]);
1717   operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (DImode, stack_pointer_rtx,
1718                                                    GEN_INT (4)));
1719 })
1720
1721 (define_split
1722   [(set (match_operand:DI 0 "push_operand" "")
1723         (match_operand:DI 1 "general_operand" ""))]
1724   "!TARGET_64BIT && reload_completed
1725    && !(MMX_REG_P (operands[1]) || SSE_REG_P (operands[1]))"
1726   [(const_int 0)]
1727   "ix86_split_long_move (operands); DONE;")
1728
1729 (define_insn "*pushsi2"
1730   [(set (match_operand:SI 0 "push_operand" "=<")
1731         (match_operand:SI 1 "general_no_elim_operand" "ri*m"))]
1732   "!TARGET_64BIT"
1733   "push{l}\t%1"
1734   [(set_attr "type" "push")
1735    (set_attr "mode" "SI")])
1736
1737 ;; emit_push_insn when it calls move_by_pieces requires an insn to
1738 ;; "push a byte/word".  But actually we use pushl, which has the effect
1739 ;; of rounding the amount pushed up to a word.
1740
1741 ;; For TARGET_64BIT we always round up to 8 bytes.
1742 (define_insn "*push<mode>2_rex64"
1743   [(set (match_operand:SWI124 0 "push_operand" "=X")
1744         (match_operand:SWI124 1 "nonmemory_no_elim_operand" "r<i>"))]
1745   "TARGET_64BIT"
1746   "push{q}\t%q1"
1747   [(set_attr "type" "push")
1748    (set_attr "mode" "DI")])
1749
1750 (define_insn "*push<mode>2"
1751   [(set (match_operand:SWI12 0 "push_operand" "=X")
1752         (match_operand:SWI12 1 "nonmemory_no_elim_operand" "rn"))]
1753   "!TARGET_64BIT"
1754   "push{l}\t%k1"
1755   [(set_attr "type" "push")
1756    (set_attr "mode" "SI")])
1757
1758 (define_insn "*push<mode>2_prologue"
1759   [(set (match_operand:P 0 "push_operand" "=<")
1760         (match_operand:P 1 "general_no_elim_operand" "r<i>*m"))
1761    (clobber (mem:BLK (scratch)))]
1762   ""
1763   "push{<imodesuffix>}\t%1"
1764   [(set_attr "type" "push")
1765    (set_attr "mode" "<MODE>")])
1766
1767 (define_insn "*pop<mode>1"
1768   [(set (match_operand:P 0 "nonimmediate_operand" "=r*m")
1769         (match_operand:P 1 "pop_operand" ">"))]
1770   ""
1771   "pop{<imodesuffix>}\t%0"
1772   [(set_attr "type" "pop")
1773    (set_attr "mode" "<MODE>")])
1774
1775 (define_insn "*pop<mode>1_epilogue"
1776   [(set (match_operand:P 0 "nonimmediate_operand" "=r*m")
1777         (match_operand:P 1 "pop_operand" ">"))
1778    (clobber (mem:BLK (scratch)))]
1779   ""
1780   "pop{<imodesuffix>}\t%0"
1781   [(set_attr "type" "pop")
1782    (set_attr "mode" "<MODE>")])
1783 \f
1784 ;; Move instructions.
1785
1786 (define_expand "movoi"
1787   [(set (match_operand:OI 0 "nonimmediate_operand" "")
1788         (match_operand:OI 1 "general_operand" ""))]
1789   "TARGET_AVX"
1790   "ix86_expand_move (OImode, operands); DONE;")
1791
1792 (define_expand "movti"
1793   [(set (match_operand:TI 0 "nonimmediate_operand" "")
1794         (match_operand:TI 1 "nonimmediate_operand" ""))]
1795   "TARGET_64BIT || TARGET_SSE"
1796 {
1797   if (TARGET_64BIT)
1798     ix86_expand_move (TImode, operands);
1799   else if (push_operand (operands[0], TImode))
1800     ix86_expand_push (TImode, operands[1]);
1801   else
1802     ix86_expand_vector_move (TImode, operands);
1803   DONE;
1804 })
1805
1806 ;; This expands to what emit_move_complex would generate if we didn't
1807 ;; have a movti pattern.  Having this avoids problems with reload on
1808 ;; 32-bit targets when SSE is present, but doesn't seem to be harmful
1809 ;; to have around all the time.
1810 (define_expand "movcdi"
1811   [(set (match_operand:CDI 0 "nonimmediate_operand" "")
1812         (match_operand:CDI 1 "general_operand" ""))]
1813   ""
1814 {
1815   if (push_operand (operands[0], CDImode))
1816     emit_move_complex_push (CDImode, operands[0], operands[1]);
1817   else
1818     emit_move_complex_parts (operands[0], operands[1]);
1819   DONE;
1820 })
1821
1822 (define_expand "mov<mode>"
1823   [(set (match_operand:SWI1248x 0 "nonimmediate_operand" "")
1824         (match_operand:SWI1248x 1 "general_operand" ""))]
1825   ""
1826   "ix86_expand_move (<MODE>mode, operands); DONE;")
1827
1828 (define_insn "*mov<mode>_xor"
1829   [(set (match_operand:SWI48 0 "register_operand" "=r")
1830         (match_operand:SWI48 1 "const0_operand" ""))
1831    (clobber (reg:CC FLAGS_REG))]
1832   "reload_completed"
1833   "xor{l}\t%k0, %k0"
1834   [(set_attr "type" "alu1")
1835    (set_attr "mode" "SI")
1836    (set_attr "length_immediate" "0")])
1837
1838 (define_insn "*mov<mode>_or"
1839   [(set (match_operand:SWI48 0 "register_operand" "=r")
1840         (match_operand:SWI48 1 "const_int_operand" ""))
1841    (clobber (reg:CC FLAGS_REG))]
1842   "reload_completed
1843    && operands[1] == constm1_rtx"
1844   "or{<imodesuffix>}\t{%1, %0|%0, %1}"
1845   [(set_attr "type" "alu1")
1846    (set_attr "mode" "<MODE>")
1847    (set_attr "length_immediate" "1")])
1848
1849 (define_insn "*movoi_internal_avx"
1850   [(set (match_operand:OI 0 "nonimmediate_operand" "=x,x,m")
1851         (match_operand:OI 1 "vector_move_operand" "C,xm,x"))]
1852   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1853 {
1854   switch (which_alternative)
1855     {
1856     case 0:
1857       return "vxorps\t%0, %0, %0";
1858     case 1:
1859     case 2:
1860       if (misaligned_operand (operands[0], OImode)
1861           || misaligned_operand (operands[1], OImode))
1862         return "vmovdqu\t{%1, %0|%0, %1}";
1863       else
1864         return "vmovdqa\t{%1, %0|%0, %1}";
1865     default:
1866       gcc_unreachable ();
1867     }
1868 }
1869   [(set_attr "type" "sselog1,ssemov,ssemov")
1870    (set_attr "prefix" "vex")
1871    (set_attr "mode" "OI")])
1872
1873 (define_insn "*movti_internal_rex64"
1874   [(set (match_operand:TI 0 "nonimmediate_operand" "=!r,o,x,x,xm")
1875         (match_operand:TI 1 "general_operand" "riFo,riF,C,xm,x"))]
1876   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1877 {
1878   switch (which_alternative)
1879     {
1880     case 0:
1881     case 1:
1882       return "#";
1883     case 2:
1884       if (get_attr_mode (insn) == MODE_V4SF)
1885         return "%vxorps\t%0, %d0";
1886       else
1887         return "%vpxor\t%0, %d0";
1888     case 3:
1889     case 4:
1890       /* TDmode values are passed as TImode on the stack.  Moving them
1891          to stack may result in unaligned memory access.  */
1892       if (misaligned_operand (operands[0], TImode)
1893           || misaligned_operand (operands[1], TImode))
1894         {
1895           if (get_attr_mode (insn) == MODE_V4SF)
1896             return "%vmovups\t{%1, %0|%0, %1}";
1897           else
1898             return "%vmovdqu\t{%1, %0|%0, %1}";
1899         }
1900       else
1901         {
1902           if (get_attr_mode (insn) == MODE_V4SF)
1903             return "%vmovaps\t{%1, %0|%0, %1}";
1904           else
1905             return "%vmovdqa\t{%1, %0|%0, %1}";
1906         }
1907     default:
1908       gcc_unreachable ();
1909     }
1910 }
1911   [(set_attr "type" "*,*,sselog1,ssemov,ssemov")
1912    (set_attr "prefix" "*,*,maybe_vex,maybe_vex,maybe_vex")
1913    (set (attr "mode")
1914         (cond [(eq_attr "alternative" "2,3")
1915                  (if_then_else
1916                    (ne (symbol_ref "optimize_function_for_size_p (cfun)")
1917                        (const_int 0))
1918                    (const_string "V4SF")
1919                    (const_string "TI"))
1920                (eq_attr "alternative" "4")
1921                  (if_then_else
1922                    (ior (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
1923                             (const_int 0))
1924                         (ne (symbol_ref "optimize_function_for_size_p (cfun)")
1925                             (const_int 0)))
1926                    (const_string "V4SF")
1927                    (const_string "TI"))]
1928                (const_string "DI")))])
1929
1930 (define_split
1931   [(set (match_operand:TI 0 "nonimmediate_operand" "")
1932         (match_operand:TI 1 "general_operand" ""))]
1933   "reload_completed
1934    && !SSE_REG_P (operands[0]) && !SSE_REG_P (operands[1])"
1935   [(const_int 0)]
1936   "ix86_split_long_move (operands); DONE;")
1937
1938 (define_insn "*movti_internal_sse"
1939   [(set (match_operand:TI 0 "nonimmediate_operand" "=x,x,m")
1940         (match_operand:TI 1 "vector_move_operand" "C,xm,x"))]
1941   "TARGET_SSE && !TARGET_64BIT
1942    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1943 {
1944   switch (which_alternative)
1945     {
1946     case 0:
1947       if (get_attr_mode (insn) == MODE_V4SF)
1948         return "%vxorps\t%0, %d0";
1949       else
1950         return "%vpxor\t%0, %d0";
1951     case 1:
1952     case 2:
1953       /* TDmode values are passed as TImode on the stack.  Moving them
1954          to stack may result in unaligned memory access.  */
1955       if (misaligned_operand (operands[0], TImode)
1956           || misaligned_operand (operands[1], TImode))
1957         {
1958           if (get_attr_mode (insn) == MODE_V4SF)
1959             return "%vmovups\t{%1, %0|%0, %1}";
1960           else
1961             return "%vmovdqu\t{%1, %0|%0, %1}";
1962         }
1963       else
1964         {
1965           if (get_attr_mode (insn) == MODE_V4SF)
1966             return "%vmovaps\t{%1, %0|%0, %1}";
1967           else
1968             return "%vmovdqa\t{%1, %0|%0, %1}";
1969         }
1970     default:
1971       gcc_unreachable ();
1972     }
1973 }
1974   [(set_attr "type" "sselog1,ssemov,ssemov")
1975    (set_attr "prefix" "maybe_vex")
1976    (set (attr "mode")
1977         (cond [(ior (eq (symbol_ref "TARGET_SSE2") (const_int 0))
1978                     (ne (symbol_ref "optimize_function_for_size_p (cfun)")
1979                         (const_int 0)))
1980                  (const_string "V4SF")
1981                (and (eq_attr "alternative" "2")
1982                     (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
1983                         (const_int 0)))
1984                  (const_string "V4SF")]
1985               (const_string "TI")))])
1986
1987 (define_insn "*movdi_internal_rex64"
1988   [(set (match_operand:DI 0 "nonimmediate_operand"
1989           "=r,r  ,r,m ,!m,*y,*y,?r ,m ,?*Ym,?*y,*x,*x,?r ,m,?*Yi,*x,?*x,?*Ym")
1990         (match_operand:DI 1 "general_operand"
1991           "Z ,rem,i,re,n ,C ,*y,*Ym,*y,r   ,m  ,C ,*x,*Yi,*x,r  ,m ,*Ym,*x"))]
1992   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1993 {
1994   switch (get_attr_type (insn))
1995     {
1996     case TYPE_SSECVT:
1997       if (SSE_REG_P (operands[0]))
1998         return "movq2dq\t{%1, %0|%0, %1}";
1999       else
2000         return "movdq2q\t{%1, %0|%0, %1}";
2001
2002     case TYPE_SSEMOV:
2003       if (get_attr_mode (insn) == MODE_TI)
2004         return "%vmovdqa\t{%1, %0|%0, %1}";
2005       /* Handle broken assemblers that require movd instead of movq.  */
2006       if (GENERAL_REG_P (operands[0]) || GENERAL_REG_P (operands[1]))
2007         return "%vmovd\t{%1, %0|%0, %1}";
2008       else
2009         return "%vmovq\t{%1, %0|%0, %1}";
2010
2011     case TYPE_MMXMOV:
2012       /* Handle broken assemblers that require movd instead of movq.  */
2013       if (GENERAL_REG_P (operands[0]) || GENERAL_REG_P (operands[1]))
2014         return "movd\t{%1, %0|%0, %1}";
2015       else
2016         return "movq\t{%1, %0|%0, %1}";
2017
2018     case TYPE_SSELOG1:
2019       return "%vpxor\t%0, %d0";
2020
2021     case TYPE_MMX:
2022       return "pxor\t%0, %0";
2023
2024     case TYPE_MULTI:
2025       return "#";
2026
2027     case TYPE_LEA:
2028       return "lea{q}\t{%a1, %0|%0, %a1}";
2029
2030     default:
2031       gcc_assert (!flag_pic || LEGITIMATE_PIC_OPERAND_P (operands[1]));
2032       if (get_attr_mode (insn) == MODE_SI)
2033         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2034       else if (which_alternative == 2)
2035         return "movabs{q}\t{%1, %0|%0, %1}";
2036       else
2037         return "mov{q}\t{%1, %0|%0, %1}";
2038     }
2039 }
2040   [(set (attr "type")
2041      (cond [(eq_attr "alternative" "5")
2042               (const_string "mmx")
2043             (eq_attr "alternative" "6,7,8,9,10")
2044               (const_string "mmxmov")
2045             (eq_attr "alternative" "11")
2046               (const_string "sselog1")
2047             (eq_attr "alternative" "12,13,14,15,16")
2048               (const_string "ssemov")
2049             (eq_attr "alternative" "17,18")
2050               (const_string "ssecvt")
2051             (eq_attr "alternative" "4")
2052               (const_string "multi")
2053             (match_operand:DI 1 "pic_32bit_operand" "")
2054               (const_string "lea")
2055            ]
2056            (const_string "imov")))
2057    (set (attr "modrm")
2058      (if_then_else
2059        (and (eq_attr "alternative" "2") (eq_attr "type" "imov"))
2060          (const_string "0")
2061          (const_string "*")))
2062    (set (attr "length_immediate")
2063      (if_then_else
2064        (and (eq_attr "alternative" "2") (eq_attr "type" "imov"))
2065          (const_string "8")
2066          (const_string "*")))
2067    (set_attr "prefix_rex" "*,*,*,*,*,*,*,1,*,1,*,*,*,*,*,*,*,*,*")
2068    (set_attr "prefix_data16" "*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,1,*,*,*")
2069    (set (attr "prefix")
2070      (if_then_else (eq_attr "alternative" "11,12,13,14,15,16")
2071        (const_string "maybe_vex")
2072        (const_string "orig")))
2073    (set_attr "mode" "SI,DI,DI,DI,SI,DI,DI,DI,DI,DI,DI,TI,TI,DI,DI,DI,DI,DI,DI")])
2074
2075 ;; Convert impossible stores of immediate to existing instructions.
2076 ;; First try to get scratch register and go through it.  In case this
2077 ;; fails, move by 32bit parts.
2078 (define_peephole2
2079   [(match_scratch:DI 2 "r")
2080    (set (match_operand:DI 0 "memory_operand" "")
2081         (match_operand:DI 1 "immediate_operand" ""))]
2082   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2083    && !x86_64_immediate_operand (operands[1], DImode)"
2084   [(set (match_dup 2) (match_dup 1))
2085    (set (match_dup 0) (match_dup 2))])
2086
2087 ;; We need to define this as both peepholer and splitter for case
2088 ;; peephole2 pass is not run.
2089 ;; "&& 1" is needed to keep it from matching the previous pattern.
2090 (define_peephole2
2091   [(set (match_operand:DI 0 "memory_operand" "")
2092         (match_operand:DI 1 "immediate_operand" ""))]
2093   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2094    && !x86_64_immediate_operand (operands[1], DImode) && 1"
2095   [(set (match_dup 2) (match_dup 3))
2096    (set (match_dup 4) (match_dup 5))]
2097   "split_double_mode (DImode, &operands[0], 2, &operands[2], &operands[4]);")
2098
2099 (define_split
2100   [(set (match_operand:DI 0 "memory_operand" "")
2101         (match_operand:DI 1 "immediate_operand" ""))]
2102   "TARGET_64BIT && ((optimize > 0 && flag_peephole2)
2103                     ? epilogue_completed : reload_completed)
2104    && !symbolic_operand (operands[1], DImode)
2105    && !x86_64_immediate_operand (operands[1], DImode)"
2106   [(set (match_dup 2) (match_dup 3))
2107    (set (match_dup 4) (match_dup 5))]
2108   "split_double_mode (DImode, &operands[0], 2, &operands[2], &operands[4]);")
2109
2110 (define_insn "*movdi_internal"
2111   [(set (match_operand:DI 0 "nonimmediate_operand"
2112                         "=r  ,o  ,*y,m*y,*y,*Y2,m  ,*Y2,*Y2,*x,m ,*x,*x")
2113         (match_operand:DI 1 "general_operand"
2114                         "riFo,riF,C ,*y ,m ,C  ,*Y2,*Y2,m  ,C ,*x,*x,m "))]
2115   "!TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2116   "@
2117    #
2118    #
2119    pxor\t%0, %0
2120    movq\t{%1, %0|%0, %1}
2121    movq\t{%1, %0|%0, %1}
2122    %vpxor\t%0, %d0
2123    %vmovq\t{%1, %0|%0, %1}
2124    %vmovdqa\t{%1, %0|%0, %1}
2125    %vmovq\t{%1, %0|%0, %1}
2126    xorps\t%0, %0
2127    movlps\t{%1, %0|%0, %1}
2128    movaps\t{%1, %0|%0, %1}
2129    movlps\t{%1, %0|%0, %1}"
2130   [(set (attr "isa")
2131      (if_then_else (eq_attr "alternative" "9,10,11,12")
2132        (const_string "noavx")
2133        (const_string "base")))
2134    (set_attr "type" "*,*,mmx,mmxmov,mmxmov,sselog1,ssemov,ssemov,ssemov,sselog1,ssemov,ssemov,ssemov")
2135    (set (attr "prefix")
2136      (if_then_else (eq_attr "alternative" "5,6,7,8")
2137        (const_string "maybe_vex")
2138        (const_string "orig")))
2139    (set_attr "mode" "DI,DI,DI,DI,DI,TI,DI,TI,DI,V4SF,V2SF,V4SF,V2SF")])
2140
2141 (define_split
2142   [(set (match_operand:DI 0 "nonimmediate_operand" "")
2143         (match_operand:DI 1 "general_operand" ""))]
2144   "!TARGET_64BIT && reload_completed
2145    && !(MMX_REG_P (operands[0]) || SSE_REG_P (operands[0]))
2146    && !(MMX_REG_P (operands[1]) || SSE_REG_P (operands[1]))"
2147   [(const_int 0)]
2148   "ix86_split_long_move (operands); DONE;")
2149
2150 (define_insn "*movsi_internal"
2151   [(set (match_operand:SI 0 "nonimmediate_operand"
2152                         "=r,m ,*y,*y,?rm,?*y,*x,*x,?r ,m ,?*Yi,*x")
2153         (match_operand:SI 1 "general_operand"
2154                         "g ,ri,C ,*y,*y ,rm ,C ,*x,*Yi,*x,r   ,m "))]
2155   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2156 {
2157   switch (get_attr_type (insn))
2158     {
2159     case TYPE_SSELOG1:
2160       if (get_attr_mode (insn) == MODE_TI)
2161         return "%vpxor\t%0, %d0";
2162       return "%vxorps\t%0, %d0";
2163
2164     case TYPE_SSEMOV:
2165       switch (get_attr_mode (insn))
2166         {
2167         case MODE_TI:
2168           return "%vmovdqa\t{%1, %0|%0, %1}";
2169         case MODE_V4SF:
2170           return "%vmovaps\t{%1, %0|%0, %1}";
2171         case MODE_SI:
2172           return "%vmovd\t{%1, %0|%0, %1}";
2173         case MODE_SF:
2174           return "%vmovss\t{%1, %0|%0, %1}";
2175         default:
2176           gcc_unreachable ();
2177         }
2178
2179     case TYPE_MMX:
2180       return "pxor\t%0, %0";
2181
2182     case TYPE_MMXMOV:
2183       if (get_attr_mode (insn) == MODE_DI)
2184         return "movq\t{%1, %0|%0, %1}";
2185       return "movd\t{%1, %0|%0, %1}";
2186
2187     case TYPE_LEA:
2188       return "lea{l}\t{%a1, %0|%0, %a1}";
2189
2190     default:
2191       gcc_assert (!flag_pic || LEGITIMATE_PIC_OPERAND_P (operands[1]));
2192       return "mov{l}\t{%1, %0|%0, %1}";
2193     }
2194 }
2195   [(set (attr "type")
2196      (cond [(eq_attr "alternative" "2")
2197               (const_string "mmx")
2198             (eq_attr "alternative" "3,4,5")
2199               (const_string "mmxmov")
2200             (eq_attr "alternative" "6")
2201               (const_string "sselog1")
2202             (eq_attr "alternative" "7,8,9,10,11")
2203               (const_string "ssemov")
2204             (match_operand:DI 1 "pic_32bit_operand" "")
2205               (const_string "lea")
2206            ]
2207            (const_string "imov")))
2208    (set (attr "prefix")
2209      (if_then_else (eq_attr "alternative" "0,1,2,3,4,5")
2210        (const_string "orig")
2211        (const_string "maybe_vex")))
2212    (set (attr "prefix_data16")
2213      (if_then_else (and (eq_attr "type" "ssemov") (eq_attr "mode" "SI"))
2214        (const_string "1")
2215        (const_string "*")))
2216    (set (attr "mode")
2217      (cond [(eq_attr "alternative" "2,3")
2218               (const_string "DI")
2219             (eq_attr "alternative" "6,7")
2220               (if_then_else
2221                 (eq (symbol_ref "TARGET_SSE2") (const_int 0))
2222                 (const_string "V4SF")
2223                 (const_string "TI"))
2224             (and (eq_attr "alternative" "8,9,10,11")
2225                  (eq (symbol_ref "TARGET_SSE2") (const_int 0)))
2226               (const_string "SF")
2227            ]
2228            (const_string "SI")))])
2229
2230 (define_insn "*movhi_internal"
2231   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,r,m")
2232         (match_operand:HI 1 "general_operand" "r,rn,rm,rn"))]
2233   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2234 {
2235   switch (get_attr_type (insn))
2236     {
2237     case TYPE_IMOVX:
2238       /* movzwl is faster than movw on p2 due to partial word stalls,
2239          though not as fast as an aligned movl.  */
2240       return "movz{wl|x}\t{%1, %k0|%k0, %1}";
2241     default:
2242       if (get_attr_mode (insn) == MODE_SI)
2243         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2244       else
2245         return "mov{w}\t{%1, %0|%0, %1}";
2246     }
2247 }
2248   [(set (attr "type")
2249      (cond [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
2250                 (const_int 0))
2251               (const_string "imov")
2252             (and (eq_attr "alternative" "0")
2253                  (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2254                           (const_int 0))
2255                       (eq (symbol_ref "TARGET_HIMODE_MATH")
2256                           (const_int 0))))
2257               (const_string "imov")
2258             (and (eq_attr "alternative" "1,2")
2259                  (match_operand:HI 1 "aligned_operand" ""))
2260               (const_string "imov")
2261             (and (ne (symbol_ref "TARGET_MOVX")
2262                      (const_int 0))
2263                  (eq_attr "alternative" "0,2"))
2264               (const_string "imovx")
2265            ]
2266            (const_string "imov")))
2267     (set (attr "mode")
2268       (cond [(eq_attr "type" "imovx")
2269                (const_string "SI")
2270              (and (eq_attr "alternative" "1,2")
2271                   (match_operand:HI 1 "aligned_operand" ""))
2272                (const_string "SI")
2273              (and (eq_attr "alternative" "0")
2274                   (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2275                            (const_int 0))
2276                        (eq (symbol_ref "TARGET_HIMODE_MATH")
2277                            (const_int 0))))
2278                (const_string "SI")
2279             ]
2280             (const_string "HI")))])
2281
2282 ;; Situation is quite tricky about when to choose full sized (SImode) move
2283 ;; over QImode moves.  For Q_REG -> Q_REG move we use full size only for
2284 ;; partial register dependency machines (such as AMD Athlon), where QImode
2285 ;; moves issue extra dependency and for partial register stalls machines
2286 ;; that don't use QImode patterns (and QImode move cause stall on the next
2287 ;; instruction).
2288 ;;
2289 ;; For loads of Q_REG to NONQ_REG we use full sized moves except for partial
2290 ;; register stall machines with, where we use QImode instructions, since
2291 ;; partial register stall can be caused there.  Then we use movzx.
2292 (define_insn "*movqi_internal"
2293   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,q ,q ,r,r ,?r,m")
2294         (match_operand:QI 1 "general_operand"      " q,qn,qm,q,rn,qm,qn"))]
2295   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2296 {
2297   switch (get_attr_type (insn))
2298     {
2299     case TYPE_IMOVX:
2300       gcc_assert (ANY_QI_REG_P (operands[1]) || MEM_P (operands[1]));
2301       return "movz{bl|x}\t{%1, %k0|%k0, %1}";
2302     default:
2303       if (get_attr_mode (insn) == MODE_SI)
2304         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2305       else
2306         return "mov{b}\t{%1, %0|%0, %1}";
2307     }
2308 }
2309   [(set (attr "type")
2310      (cond [(and (eq_attr "alternative" "5")
2311                  (not (match_operand:QI 1 "aligned_operand" "")))
2312               (const_string "imovx")
2313             (ne (symbol_ref "optimize_function_for_size_p (cfun)")
2314                 (const_int 0))
2315               (const_string "imov")
2316             (and (eq_attr "alternative" "3")
2317                  (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2318                           (const_int 0))
2319                       (eq (symbol_ref "TARGET_QIMODE_MATH")
2320                           (const_int 0))))
2321               (const_string "imov")
2322             (eq_attr "alternative" "3,5")
2323               (const_string "imovx")
2324             (and (ne (symbol_ref "TARGET_MOVX")
2325                      (const_int 0))
2326                  (eq_attr "alternative" "2"))
2327               (const_string "imovx")
2328            ]
2329            (const_string "imov")))
2330    (set (attr "mode")
2331       (cond [(eq_attr "alternative" "3,4,5")
2332                (const_string "SI")
2333              (eq_attr "alternative" "6")
2334                (const_string "QI")
2335              (eq_attr "type" "imovx")
2336                (const_string "SI")
2337              (and (eq_attr "type" "imov")
2338                   (and (eq_attr "alternative" "0,1")
2339                        (and (ne (symbol_ref "TARGET_PARTIAL_REG_DEPENDENCY")
2340                                 (const_int 0))
2341                             (and (eq (symbol_ref "optimize_function_for_size_p (cfun)")
2342                                      (const_int 0))
2343                                  (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2344                                      (const_int 0))))))
2345                (const_string "SI")
2346              ;; Avoid partial register stalls when not using QImode arithmetic
2347              (and (eq_attr "type" "imov")
2348                   (and (eq_attr "alternative" "0,1")
2349                        (and (ne (symbol_ref "TARGET_PARTIAL_REG_STALL")
2350                                 (const_int 0))
2351                             (eq (symbol_ref "TARGET_QIMODE_MATH")
2352                                 (const_int 0)))))
2353                (const_string "SI")
2354            ]
2355            (const_string "QI")))])
2356
2357 ;; Stores and loads of ax to arbitrary constant address.
2358 ;; We fake an second form of instruction to force reload to load address
2359 ;; into register when rax is not available
2360 (define_insn "*movabs<mode>_1"
2361   [(set (mem:SWI1248x (match_operand:DI 0 "x86_64_movabs_operand" "i,r"))
2362         (match_operand:SWI1248x 1 "nonmemory_operand" "a,er"))]
2363   "TARGET_64BIT && ix86_check_movabs (insn, 0)"
2364   "@
2365    movabs{<imodesuffix>}\t{%1, %P0|%P0, %1}
2366    mov{<imodesuffix>}\t{%1, %a0|%a0, %1}"
2367   [(set_attr "type" "imov")
2368    (set_attr "modrm" "0,*")
2369    (set_attr "length_address" "8,0")
2370    (set_attr "length_immediate" "0,*")
2371    (set_attr "memory" "store")
2372    (set_attr "mode" "<MODE>")])
2373
2374 (define_insn "*movabs<mode>_2"
2375   [(set (match_operand:SWI1248x 0 "register_operand" "=a,r")
2376         (mem:SWI1248x (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
2377   "TARGET_64BIT && ix86_check_movabs (insn, 1)"
2378   "@
2379    movabs{<imodesuffix>}\t{%P1, %0|%0, %P1}
2380    mov{<imodesuffix>}\t{%a1, %0|%0, %a1}"
2381   [(set_attr "type" "imov")
2382    (set_attr "modrm" "0,*")
2383    (set_attr "length_address" "8,0")
2384    (set_attr "length_immediate" "0")
2385    (set_attr "memory" "load")
2386    (set_attr "mode" "<MODE>")])
2387
2388 (define_insn "*swap<mode>"
2389   [(set (match_operand:SWI48 0 "register_operand" "+r")
2390         (match_operand:SWI48 1 "register_operand" "+r"))
2391    (set (match_dup 1)
2392         (match_dup 0))]
2393   ""
2394   "xchg{<imodesuffix>}\t%1, %0"
2395   [(set_attr "type" "imov")
2396    (set_attr "mode" "<MODE>")
2397    (set_attr "pent_pair" "np")
2398    (set_attr "athlon_decode" "vector")
2399    (set_attr "amdfam10_decode" "double")
2400    (set_attr "bdver1_decode" "double")])
2401
2402 (define_insn "*swap<mode>_1"
2403   [(set (match_operand:SWI12 0 "register_operand" "+r")
2404         (match_operand:SWI12 1 "register_operand" "+r"))
2405    (set (match_dup 1)
2406         (match_dup 0))]
2407   "!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)"
2408   "xchg{l}\t%k1, %k0"
2409   [(set_attr "type" "imov")
2410    (set_attr "mode" "SI")
2411    (set_attr "pent_pair" "np")
2412    (set_attr "athlon_decode" "vector")
2413    (set_attr "amdfam10_decode" "double")
2414    (set_attr "bdver1_decode" "double")])
2415
2416 ;; Not added amdfam10_decode since TARGET_PARTIAL_REG_STALL
2417 ;; is disabled for AMDFAM10
2418 (define_insn "*swap<mode>_2"
2419   [(set (match_operand:SWI12 0 "register_operand" "+<r>")
2420         (match_operand:SWI12 1 "register_operand" "+<r>"))
2421    (set (match_dup 1)
2422         (match_dup 0))]
2423   "TARGET_PARTIAL_REG_STALL"
2424   "xchg{<imodesuffix>}\t%1, %0"
2425   [(set_attr "type" "imov")
2426    (set_attr "mode" "<MODE>")
2427    (set_attr "pent_pair" "np")
2428    (set_attr "athlon_decode" "vector")])
2429
2430 (define_expand "movstrict<mode>"
2431   [(set (strict_low_part (match_operand:SWI12 0 "nonimmediate_operand" ""))
2432         (match_operand:SWI12 1 "general_operand" ""))]
2433   ""
2434 {
2435   if (TARGET_PARTIAL_REG_STALL && optimize_function_for_speed_p (cfun))
2436     FAIL;
2437   if (GET_CODE (operands[0]) == SUBREG
2438       && GET_MODE_CLASS (GET_MODE (SUBREG_REG (operands[0]))) != MODE_INT)
2439     FAIL;
2440   /* Don't generate memory->memory moves, go through a register */
2441   if (MEM_P (operands[0]) && MEM_P (operands[1]))
2442     operands[1] = force_reg (<MODE>mode, operands[1]);
2443 })
2444
2445 (define_insn "*movstrict<mode>_1"
2446   [(set (strict_low_part
2447           (match_operand:SWI12 0 "nonimmediate_operand" "+<r>m,<r>"))
2448         (match_operand:SWI12 1 "general_operand" "<r>n,m"))]
2449   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
2450    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2451   "mov{<imodesuffix>}\t{%1, %0|%0, %1}"
2452   [(set_attr "type" "imov")
2453    (set_attr "mode" "<MODE>")])
2454
2455 (define_insn "*movstrict<mode>_xor"
2456   [(set (strict_low_part (match_operand:SWI12 0 "register_operand" "+<r>"))
2457         (match_operand:SWI12 1 "const0_operand" ""))
2458    (clobber (reg:CC FLAGS_REG))]
2459   "reload_completed"
2460   "xor{<imodesuffix>}\t%0, %0"
2461   [(set_attr "type" "alu1")
2462    (set_attr "mode" "<MODE>")
2463    (set_attr "length_immediate" "0")])
2464
2465 (define_insn "*mov<mode>_extv_1"
2466   [(set (match_operand:SWI24 0 "register_operand" "=R")
2467         (sign_extract:SWI24 (match_operand 1 "ext_register_operand" "Q")
2468                             (const_int 8)
2469                             (const_int 8)))]
2470   ""
2471   "movs{bl|x}\t{%h1, %k0|%k0, %h1}"
2472   [(set_attr "type" "imovx")
2473    (set_attr "mode" "SI")])
2474
2475 (define_insn "*movqi_extv_1_rex64"
2476   [(set (match_operand:QI 0 "register_operand" "=Q,?R")
2477         (sign_extract:QI (match_operand 1 "ext_register_operand" "Q,Q")
2478                          (const_int 8)
2479                          (const_int 8)))]
2480   "TARGET_64BIT"
2481 {
2482   switch (get_attr_type (insn))
2483     {
2484     case TYPE_IMOVX:
2485       return "movs{bl|x}\t{%h1, %k0|%k0, %h1}";
2486     default:
2487       return "mov{b}\t{%h1, %0|%0, %h1}";
2488     }
2489 }
2490   [(set (attr "type")
2491      (if_then_else (ior (not (match_operand:QI 0 "QIreg_operand" ""))
2492                         (ne (symbol_ref "TARGET_MOVX")
2493                             (const_int 0)))
2494         (const_string "imovx")
2495         (const_string "imov")))
2496    (set (attr "mode")
2497      (if_then_else (eq_attr "type" "imovx")
2498         (const_string "SI")
2499         (const_string "QI")))])
2500
2501 (define_insn "*movqi_extv_1"
2502   [(set (match_operand:QI 0 "nonimmediate_operand" "=Qm,?r")
2503         (sign_extract:QI (match_operand 1 "ext_register_operand" "Q,Q")
2504                          (const_int 8)
2505                          (const_int 8)))]
2506   "!TARGET_64BIT"
2507 {
2508   switch (get_attr_type (insn))
2509     {
2510     case TYPE_IMOVX:
2511       return "movs{bl|x}\t{%h1, %k0|%k0, %h1}";
2512     default:
2513       return "mov{b}\t{%h1, %0|%0, %h1}";
2514     }
2515 }
2516   [(set (attr "type")
2517      (if_then_else (and (match_operand:QI 0 "register_operand" "")
2518                         (ior (not (match_operand:QI 0 "QIreg_operand" ""))
2519                              (ne (symbol_ref "TARGET_MOVX")
2520                                  (const_int 0))))
2521         (const_string "imovx")
2522         (const_string "imov")))
2523    (set (attr "mode")
2524      (if_then_else (eq_attr "type" "imovx")
2525         (const_string "SI")
2526         (const_string "QI")))])
2527
2528 (define_insn "*mov<mode>_extzv_1"
2529   [(set (match_operand:SWI48 0 "register_operand" "=R")
2530         (zero_extract:SWI48 (match_operand 1 "ext_register_operand" "Q")
2531                             (const_int 8)
2532                             (const_int 8)))]
2533   ""
2534   "movz{bl|x}\t{%h1, %k0|%k0, %h1}"
2535   [(set_attr "type" "imovx")
2536    (set_attr "mode" "SI")])
2537
2538 (define_insn "*movqi_extzv_2_rex64"
2539   [(set (match_operand:QI 0 "register_operand" "=Q,?R")
2540         (subreg:QI
2541           (zero_extract:SI (match_operand 1 "ext_register_operand" "Q,Q")
2542                            (const_int 8)
2543                            (const_int 8)) 0))]
2544   "TARGET_64BIT"
2545 {
2546   switch (get_attr_type (insn))
2547     {
2548     case TYPE_IMOVX:
2549       return "movz{bl|x}\t{%h1, %k0|%k0, %h1}";
2550     default:
2551       return "mov{b}\t{%h1, %0|%0, %h1}";
2552     }
2553 }
2554   [(set (attr "type")
2555      (if_then_else (ior (not (match_operand:QI 0 "QIreg_operand" ""))
2556                         (ne (symbol_ref "TARGET_MOVX")
2557                             (const_int 0)))
2558         (const_string "imovx")
2559         (const_string "imov")))
2560    (set (attr "mode")
2561      (if_then_else (eq_attr "type" "imovx")
2562         (const_string "SI")
2563         (const_string "QI")))])
2564
2565 (define_insn "*movqi_extzv_2"
2566   [(set (match_operand:QI 0 "nonimmediate_operand" "=Qm,?R")
2567         (subreg:QI
2568           (zero_extract:SI (match_operand 1 "ext_register_operand" "Q,Q")
2569                            (const_int 8)
2570                            (const_int 8)) 0))]
2571   "!TARGET_64BIT"
2572 {
2573   switch (get_attr_type (insn))
2574     {
2575     case TYPE_IMOVX:
2576       return "movz{bl|x}\t{%h1, %k0|%k0, %h1}";
2577     default:
2578       return "mov{b}\t{%h1, %0|%0, %h1}";
2579     }
2580 }
2581   [(set (attr "type")
2582      (if_then_else (and (match_operand:QI 0 "register_operand" "")
2583                         (ior (not (match_operand:QI 0 "QIreg_operand" ""))
2584                              (ne (symbol_ref "TARGET_MOVX")
2585                                  (const_int 0))))
2586         (const_string "imovx")
2587         (const_string "imov")))
2588    (set (attr "mode")
2589      (if_then_else (eq_attr "type" "imovx")
2590         (const_string "SI")
2591         (const_string "QI")))])
2592
2593 (define_expand "mov<mode>_insv_1"
2594   [(set (zero_extract:SWI48 (match_operand 0 "ext_register_operand" "")
2595                             (const_int 8)
2596                             (const_int 8))
2597         (match_operand:SWI48 1 "nonmemory_operand" ""))])
2598
2599 (define_insn "*mov<mode>_insv_1_rex64"
2600   [(set (zero_extract:SWI48x (match_operand 0 "ext_register_operand" "+Q")
2601                              (const_int 8)
2602                              (const_int 8))
2603         (match_operand:SWI48x 1 "nonmemory_operand" "Qn"))]
2604   "TARGET_64BIT"
2605   "mov{b}\t{%b1, %h0|%h0, %b1}"
2606   [(set_attr "type" "imov")
2607    (set_attr "mode" "QI")])
2608
2609 (define_insn "*movsi_insv_1"
2610   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
2611                          (const_int 8)
2612                          (const_int 8))
2613         (match_operand:SI 1 "general_operand" "Qmn"))]
2614   "!TARGET_64BIT"
2615   "mov{b}\t{%b1, %h0|%h0, %b1}"
2616   [(set_attr "type" "imov")
2617    (set_attr "mode" "QI")])
2618
2619 (define_insn "*movqi_insv_2"
2620   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
2621                          (const_int 8)
2622                          (const_int 8))
2623         (lshiftrt:SI (match_operand:SI 1 "register_operand" "Q")
2624                      (const_int 8)))]
2625   ""
2626   "mov{b}\t{%h1, %h0|%h0, %h1}"
2627   [(set_attr "type" "imov")
2628    (set_attr "mode" "QI")])
2629 \f
2630 ;; Floating point push instructions.
2631
2632 (define_insn "*pushtf"
2633   [(set (match_operand:TF 0 "push_operand" "=<,<,<")
2634         (match_operand:TF 1 "general_no_elim_operand" "x,Fo,*r"))]
2635   "TARGET_SSE2"
2636 {
2637   /* This insn should be already split before reg-stack.  */
2638   gcc_unreachable ();
2639 }
2640   [(set_attr "type" "multi")
2641    (set_attr "unit" "sse,*,*")
2642    (set_attr "mode" "TF,SI,SI")])
2643
2644 (define_split
2645   [(set (match_operand:TF 0 "push_operand" "")
2646         (match_operand:TF 1 "sse_reg_operand" ""))]
2647   "TARGET_SSE2 && reload_completed"
2648   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -16)))
2649    (set (mem:TF (reg:P SP_REG)) (match_dup 1))])
2650
2651 (define_split
2652   [(set (match_operand:TF 0 "push_operand" "")
2653         (match_operand:TF 1 "general_operand" ""))]
2654   "TARGET_SSE2 && reload_completed
2655    && !SSE_REG_P (operands[1])"
2656   [(const_int 0)]
2657   "ix86_split_long_move (operands); DONE;")
2658
2659 (define_insn "*pushxf"
2660   [(set (match_operand:XF 0 "push_operand" "=<,<")
2661         (match_operand:XF 1 "general_no_elim_operand" "f,ro"))]
2662   "optimize_function_for_speed_p (cfun)"
2663 {
2664   /* This insn should be already split before reg-stack.  */
2665   gcc_unreachable ();
2666 }
2667   [(set_attr "type" "multi")
2668    (set_attr "unit" "i387,*")
2669    (set_attr "mode" "XF,SI")])
2670
2671 ;; Size of pushxf is 3 (for sub) + 2 (for fstp) + memory operand size.
2672 ;; Size of pushxf using integer instructions is 3+3*memory operand size
2673 ;; Pushing using integer instructions is longer except for constants
2674 ;; and direct memory references (assuming that any given constant is pushed
2675 ;; only once, but this ought to be handled elsewhere).
2676
2677 (define_insn "*pushxf_nointeger"
2678   [(set (match_operand:XF 0 "push_operand" "=X,X,X")
2679         (match_operand:XF 1 "general_no_elim_operand" "f,Fo,*r"))]
2680   "optimize_function_for_size_p (cfun)"
2681 {
2682   /* This insn should be already split before reg-stack.  */
2683   gcc_unreachable ();
2684 }
2685   [(set_attr "type" "multi")
2686    (set_attr "unit" "i387,*,*")
2687    (set_attr "mode" "XF,SI,SI")])
2688
2689 (define_split
2690   [(set (match_operand:XF 0 "push_operand" "")
2691         (match_operand:XF 1 "fp_register_operand" ""))]
2692   "reload_completed"
2693   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
2694    (set (mem:XF (reg:P SP_REG)) (match_dup 1))]
2695   "operands[2] = GEN_INT (-GET_MODE_SIZE (XFmode));")
2696
2697 (define_split
2698   [(set (match_operand:XF 0 "push_operand" "")
2699         (match_operand:XF 1 "general_operand" ""))]
2700   "reload_completed
2701    && !FP_REG_P (operands[1])"
2702   [(const_int 0)]
2703   "ix86_split_long_move (operands); DONE;")
2704
2705 ;; Size of pushdf is 3 (for sub) + 2 (for fstp) + memory operand size.
2706 ;; Size of pushdf using integer instructions is 2+2*memory operand size
2707 ;; On the average, pushdf using integers can be still shorter.
2708
2709 (define_insn "*pushdf"
2710   [(set (match_operand:DF 0 "push_operand" "=<,<,<")
2711         (match_operand:DF 1 "general_no_elim_operand" "f,Yd*rFo,Y2"))]
2712   ""
2713 {
2714   /* This insn should be already split before reg-stack.  */
2715   gcc_unreachable ();
2716 }
2717   [(set_attr "type" "multi")
2718    (set_attr "unit" "i387,*,*")
2719    (set_attr "mode" "DF,SI,DF")])
2720
2721 ;; %%% Kill this when call knows how to work this out.
2722 (define_split
2723   [(set (match_operand:DF 0 "push_operand" "")
2724         (match_operand:DF 1 "any_fp_register_operand" ""))]
2725   "reload_completed"
2726   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -8)))
2727    (set (mem:DF (reg:P SP_REG)) (match_dup 1))])
2728
2729 (define_split
2730   [(set (match_operand:DF 0 "push_operand" "")
2731         (match_operand:DF 1 "general_operand" ""))]
2732   "reload_completed
2733    && !ANY_FP_REG_P (operands[1])"
2734   [(const_int 0)]
2735   "ix86_split_long_move (operands); DONE;")
2736
2737 (define_insn "*pushsf_rex64"
2738   [(set (match_operand:SF 0 "push_operand" "=X,X,X")
2739         (match_operand:SF 1 "nonmemory_no_elim_operand" "f,rF,x"))]
2740   "TARGET_64BIT"
2741 {
2742   /* Anything else should be already split before reg-stack.  */
2743   gcc_assert (which_alternative == 1);
2744   return "push{q}\t%q1";
2745 }
2746   [(set_attr "type" "multi,push,multi")
2747    (set_attr "unit" "i387,*,*")
2748    (set_attr "mode" "SF,DI,SF")])
2749
2750 (define_insn "*pushsf"
2751   [(set (match_operand:SF 0 "push_operand" "=<,<,<")
2752         (match_operand:SF 1 "general_no_elim_operand" "f,rFm,x"))]
2753   "!TARGET_64BIT"
2754 {
2755   /* Anything else should be already split before reg-stack.  */
2756   gcc_assert (which_alternative == 1);
2757   return "push{l}\t%1";
2758 }
2759   [(set_attr "type" "multi,push,multi")
2760    (set_attr "unit" "i387,*,*")
2761    (set_attr "mode" "SF,SI,SF")])
2762
2763 (define_split
2764   [(set (match_operand:SF 0 "push_operand" "")
2765         (match_operand:SF 1 "memory_operand" ""))]
2766   "reload_completed
2767    && MEM_P (operands[1])
2768    && (operands[2] = find_constant_src (insn))"
2769   [(set (match_dup 0)
2770         (match_dup 2))])
2771
2772 ;; %%% Kill this when call knows how to work this out.
2773 (define_split
2774   [(set (match_operand:SF 0 "push_operand" "")
2775         (match_operand:SF 1 "any_fp_register_operand" ""))]
2776   "reload_completed"
2777   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
2778    (set (mem:SF (reg:P SP_REG)) (match_dup 1))]
2779   "operands[2] = GEN_INT (-GET_MODE_SIZE (<MODE>mode));")
2780 \f
2781 ;; Floating point move instructions.
2782
2783 (define_expand "movtf"
2784   [(set (match_operand:TF 0 "nonimmediate_operand" "")
2785         (match_operand:TF 1 "nonimmediate_operand" ""))]
2786   "TARGET_SSE2"
2787 {
2788   ix86_expand_move (TFmode, operands);
2789   DONE;
2790 })
2791
2792 (define_expand "mov<mode>"
2793   [(set (match_operand:X87MODEF 0 "nonimmediate_operand" "")
2794         (match_operand:X87MODEF 1 "general_operand" ""))]
2795   ""
2796   "ix86_expand_move (<MODE>mode, operands); DONE;")
2797
2798 (define_insn "*movtf_internal"
2799   [(set (match_operand:TF 0 "nonimmediate_operand" "=x,m,x,?r,?o")
2800         (match_operand:TF 1 "general_operand" "xm,x,C,roF,Fr"))]
2801   "TARGET_SSE2
2802    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2803 {
2804   switch (which_alternative)
2805     {
2806     case 0:
2807     case 1:
2808       if (get_attr_mode (insn) == MODE_V4SF)
2809         return "%vmovaps\t{%1, %0|%0, %1}";
2810       else
2811         return "%vmovdqa\t{%1, %0|%0, %1}";
2812
2813     case 2:
2814       return standard_sse_constant_opcode (insn, operands[1]);
2815
2816     case 3:
2817     case 4:
2818         return "#";
2819
2820     default:
2821       gcc_unreachable ();
2822     }
2823 }
2824   [(set_attr "type" "ssemov,ssemov,sselog1,*,*")
2825    (set_attr "prefix" "maybe_vex,maybe_vex,maybe_vex,*,*")
2826    (set (attr "mode")
2827         (cond [(eq_attr "alternative" "0,2")
2828                  (if_then_else
2829                    (ne (symbol_ref "optimize_function_for_size_p (cfun)")
2830                        (const_int 0))
2831                    (const_string "V4SF")
2832                    (const_string "TI"))
2833                (eq_attr "alternative" "1")
2834                  (if_then_else
2835                    (ior (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
2836                             (const_int 0))
2837                         (ne (symbol_ref "optimize_function_for_size_p (cfun)")
2838                             (const_int 0)))
2839                    (const_string "V4SF")
2840                    (const_string "TI"))]
2841                (const_string "DI")))])
2842
2843 (define_split
2844   [(set (match_operand:TF 0 "nonimmediate_operand" "")
2845         (match_operand:TF 1 "general_operand" ""))]
2846   "reload_completed
2847    && !(SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]))"
2848   [(const_int 0)]
2849   "ix86_split_long_move (operands); DONE;")
2850
2851 (define_insn "*movxf_internal"
2852   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m,f,Yx*r  ,o")
2853         (match_operand:XF 1 "general_operand"      "fm,f,G,Yx*roF,FYx*r"))]
2854   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
2855    && (!can_create_pseudo_p ()
2856        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
2857        || GET_CODE (operands[1]) != CONST_DOUBLE
2858        || (optimize_function_for_size_p (cfun)
2859            && standard_80387_constant_p (operands[1]) > 0)
2860        || memory_operand (operands[0], XFmode))"
2861 {
2862   switch (which_alternative)
2863     {
2864     case 0:
2865     case 1:
2866       return output_387_reg_move (insn, operands);
2867
2868     case 2:
2869       return standard_80387_constant_opcode (operands[1]);
2870
2871     case 3: case 4:
2872       return "#";
2873     default:
2874       gcc_unreachable ();
2875     }
2876 }
2877   [(set_attr "type" "fmov,fmov,fmov,multi,multi")
2878    (set_attr "mode" "XF,XF,XF,SI,SI")])
2879
2880 (define_split
2881   [(set (match_operand:XF 0 "nonimmediate_operand" "")
2882         (match_operand:XF 1 "general_operand" ""))]
2883   "reload_completed
2884    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
2885    && ! (FP_REG_P (operands[0]) ||
2886          (GET_CODE (operands[0]) == SUBREG
2887           && FP_REG_P (SUBREG_REG (operands[0]))))
2888    && ! (FP_REG_P (operands[1]) ||
2889          (GET_CODE (operands[1]) == SUBREG
2890           && FP_REG_P (SUBREG_REG (operands[1]))))"
2891   [(const_int 0)]
2892   "ix86_split_long_move (operands); DONE;")
2893
2894 (define_insn "*movdf_internal_rex64"
2895   [(set (match_operand:DF 0 "nonimmediate_operand"
2896                 "=f,m,f,r ,m,!r,!m,Y2*x,Y2*x,Y2*x,m   ,Yi,r ")
2897         (match_operand:DF 1 "general_operand"
2898                 "fm,f,G,rm,r,F ,F ,C   ,Y2*x,m   ,Y2*x,r ,Yi"))]
2899   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))
2900    && (!can_create_pseudo_p ()
2901        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
2902        || GET_CODE (operands[1]) != CONST_DOUBLE
2903        || (optimize_function_for_size_p (cfun)
2904            && ((!(TARGET_SSE2 && TARGET_SSE_MATH)
2905                 && standard_80387_constant_p (operands[1]) > 0)
2906                || (TARGET_SSE2 && TARGET_SSE_MATH
2907                    && standard_sse_constant_p (operands[1]))))
2908        || memory_operand (operands[0], DFmode))"
2909 {
2910   switch (which_alternative)
2911     {
2912     case 0:
2913     case 1:
2914       return output_387_reg_move (insn, operands);
2915
2916     case 2:
2917       return standard_80387_constant_opcode (operands[1]);
2918
2919     case 3:
2920     case 4:
2921       return "mov{q}\t{%1, %0|%0, %1}";
2922
2923     case 5:
2924       return "movabs{q}\t{%1, %0|%0, %1}";
2925
2926     case 6:
2927       return "#";
2928
2929     case 7:
2930       return standard_sse_constant_opcode (insn, operands[1]);
2931
2932     case 8:
2933     case 9:
2934     case 10:
2935       switch (get_attr_mode (insn))
2936         {
2937         case MODE_V4SF:
2938           return "%vmovaps\t{%1, %0|%0, %1}";
2939         case MODE_V2DF:
2940           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
2941             return "%vmovaps\t{%1, %0|%0, %1}";
2942           else
2943             return "%vmovapd\t{%1, %0|%0, %1}";
2944         case MODE_TI:
2945           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
2946             return "%vmovaps\t{%1, %0|%0, %1}";
2947           else
2948             return "%vmovdqa\t{%1, %0|%0, %1}";
2949         case MODE_DI:
2950           return "%vmovq\t{%1, %0|%0, %1}";
2951         case MODE_DF:
2952           if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
2953             return "vmovsd\t{%1, %0, %0|%0, %0, %1}";
2954           else
2955             return "%vmovsd\t{%1, %0|%0, %1}";
2956         case MODE_V1DF:
2957           return "%vmovlpd\t{%1, %d0|%d0, %1}";
2958         case MODE_V2SF:
2959           return "%vmovlps\t{%1, %d0|%d0, %1}";
2960         default:
2961           gcc_unreachable ();
2962         }
2963
2964     case 11:
2965     case 12:
2966       /* Handle broken assemblers that require movd instead of movq.  */
2967       return "%vmovd\t{%1, %0|%0, %1}";
2968
2969     default:
2970       gcc_unreachable();
2971     }
2972 }
2973   [(set_attr "type" "fmov,fmov,fmov,imov,imov,imov,multi,sselog1,ssemov,ssemov,ssemov,ssemov,ssemov")
2974    (set (attr "modrm")
2975      (if_then_else
2976        (and (eq_attr "alternative" "5") (eq_attr "type" "imov"))
2977          (const_string "0")
2978          (const_string "*")))
2979    (set (attr "length_immediate")
2980      (if_then_else
2981        (and (eq_attr "alternative" "5") (eq_attr "type" "imov"))
2982          (const_string "8")
2983          (const_string "*")))
2984    (set (attr "prefix")
2985      (if_then_else (eq_attr "alternative" "0,1,2,3,4,5,6")
2986        (const_string "orig")
2987        (const_string "maybe_vex")))
2988    (set (attr "prefix_data16")
2989      (if_then_else (eq_attr "mode" "V1DF")
2990        (const_string "1")
2991        (const_string "*")))
2992    (set (attr "mode")
2993         (cond [(eq_attr "alternative" "0,1,2")
2994                  (const_string "DF")
2995                (eq_attr "alternative" "3,4,5,6,11,12")
2996                  (const_string "DI")
2997
2998                /* For SSE1, we have many fewer alternatives.  */
2999                (eq (symbol_ref "TARGET_SSE2") (const_int 0))
3000                  (cond [(eq_attr "alternative" "7,8")
3001                           (const_string "V4SF")
3002                        ]
3003                    (const_string "V2SF"))
3004
3005                /* xorps is one byte shorter.  */
3006                (eq_attr "alternative" "7")
3007                  (cond [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3008                             (const_int 0))
3009                           (const_string "V4SF")
3010                         (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
3011                             (const_int 0))
3012                           (const_string "TI")
3013                        ]
3014                        (const_string "V2DF"))
3015
3016                /* For architectures resolving dependencies on
3017                   whole SSE registers use APD move to break dependency
3018                   chains, otherwise use short move to avoid extra work.
3019
3020                   movaps encodes one byte shorter.  */
3021                (eq_attr "alternative" "8")
3022                  (cond
3023                    [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3024                         (const_int 0))
3025                       (const_string "V4SF")
3026                     (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3027                         (const_int 0))
3028                       (const_string "V2DF")
3029                    ]
3030                    (const_string "DF"))
3031                /* For architectures resolving dependencies on register
3032                   parts we may avoid extra work to zero out upper part
3033                   of register.  */
3034                (eq_attr "alternative" "9")
3035                  (if_then_else
3036                    (ne (symbol_ref "TARGET_SSE_SPLIT_REGS")
3037                        (const_int 0))
3038                    (const_string "V1DF")
3039                    (const_string "DF"))
3040               ]
3041               (const_string "DF")))])
3042
3043 ;; Possible store forwarding (partial memory) stall in alternative 4.
3044 (define_insn "*movdf_internal"
3045   [(set (match_operand:DF 0 "nonimmediate_operand"
3046                 "=f,m,f,Yd*r  ,o    ,Y2*x,Y2*x,Y2*x,m  ")
3047         (match_operand:DF 1 "general_operand"
3048                 "fm,f,G,Yd*roF,FYd*r,C   ,Y2*x,m   ,Y2*x"))]
3049   "!TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))
3050    && (!can_create_pseudo_p ()
3051        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3052        || GET_CODE (operands[1]) != CONST_DOUBLE
3053        || (!TARGET_INTEGER_DFMODE_MOVES
3054            && ((!(TARGET_SSE2 && TARGET_SSE_MATH)
3055                 && standard_80387_constant_p (operands[1]) > 0)
3056                || (TARGET_SSE2 && TARGET_SSE_MATH
3057                    && standard_sse_constant_p (operands[1])))
3058            && !memory_operand (operands[0], DFmode))
3059        || ((TARGET_INTEGER_DFMODE_MOVES
3060             || !TARGET_MEMORY_MISMATCH_STALL)
3061            && memory_operand (operands[0], DFmode)))"
3062 {
3063   switch (which_alternative)
3064     {
3065     case 0:
3066     case 1:
3067       return output_387_reg_move (insn, operands);
3068
3069     case 2:
3070       return standard_80387_constant_opcode (operands[1]);
3071
3072     case 3:
3073     case 4:
3074       return "#";
3075
3076     case 5:
3077       return standard_sse_constant_opcode (insn, operands[1]);
3078
3079     case 6:
3080     case 7:
3081     case 8:
3082       switch (get_attr_mode (insn))
3083         {
3084         case MODE_V4SF:
3085           return "%vmovaps\t{%1, %0|%0, %1}";
3086         case MODE_V2DF:
3087           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
3088             return "%vmovaps\t{%1, %0|%0, %1}";
3089           else
3090             return "%vmovapd\t{%1, %0|%0, %1}";
3091         case MODE_TI:
3092           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
3093             return "%vmovaps\t{%1, %0|%0, %1}";
3094           else
3095             return "%vmovdqa\t{%1, %0|%0, %1}";
3096         case MODE_DI:
3097           return "%vmovq\t{%1, %0|%0, %1}";
3098         case MODE_DF:
3099           if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
3100             return "vmovsd\t{%1, %0, %0|%0, %0, %1}";
3101           else
3102             return "%vmovsd\t{%1, %0|%0, %1}";
3103         case MODE_V1DF:
3104           if (TARGET_AVX && REG_P (operands[0]))
3105             return "vmovlpd\t{%1, %0, %0|%0, %0, %1}";
3106           else
3107             return "%vmovlpd\t{%1, %0|%0, %1}";
3108         case MODE_V2SF:
3109           if (TARGET_AVX && REG_P (operands[0]))
3110             return "vmovlps\t{%1, %0, %0|%0, %0, %1}";
3111           else
3112             return "%vmovlps\t{%1, %0|%0, %1}";
3113         default:
3114           gcc_unreachable ();
3115         }
3116
3117     default:
3118       gcc_unreachable ();
3119     }
3120 }
3121   [(set_attr "type" "fmov,fmov,fmov,multi,multi,sselog1,ssemov,ssemov,ssemov")
3122    (set (attr "prefix")
3123      (if_then_else (eq_attr "alternative" "0,1,2,3,4")
3124        (const_string "orig")
3125        (const_string "maybe_vex")))
3126    (set (attr "prefix_data16")
3127      (if_then_else (eq_attr "mode" "V1DF")
3128        (const_string "1")
3129        (const_string "*")))
3130    (set (attr "mode")
3131         (cond [(eq_attr "alternative" "0,1,2")
3132                  (const_string "DF")
3133                (eq_attr "alternative" "3,4")
3134                  (const_string "SI")
3135
3136                /* For SSE1, we have many fewer alternatives.  */
3137                (eq (symbol_ref "TARGET_SSE2") (const_int 0))
3138                  (cond [(eq_attr "alternative" "5,6")
3139                           (const_string "V4SF")
3140                        ]
3141                    (const_string "V2SF"))
3142
3143                /* xorps is one byte shorter.  */
3144                (eq_attr "alternative" "5")
3145                  (cond [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3146                             (const_int 0))
3147                           (const_string "V4SF")
3148                         (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
3149                             (const_int 0))
3150                           (const_string "TI")
3151                        ]
3152                        (const_string "V2DF"))
3153
3154                /* For architectures resolving dependencies on
3155                   whole SSE registers use APD move to break dependency
3156                   chains, otherwise use short move to avoid extra work.
3157
3158                   movaps encodes one byte shorter.  */
3159                (eq_attr "alternative" "6")
3160                  (cond
3161                    [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3162                         (const_int 0))
3163                       (const_string "V4SF")
3164                     (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3165                         (const_int 0))
3166                       (const_string "V2DF")
3167                    ]
3168                    (const_string "DF"))
3169                /* For architectures resolving dependencies on register
3170                   parts we may avoid extra work to zero out upper part
3171                   of register.  */
3172                (eq_attr "alternative" "7")
3173                  (if_then_else
3174                    (ne (symbol_ref "TARGET_SSE_SPLIT_REGS")
3175                        (const_int 0))
3176                    (const_string "V1DF")
3177                    (const_string "DF"))
3178               ]
3179               (const_string "DF")))])
3180
3181 (define_split
3182   [(set (match_operand:DF 0 "nonimmediate_operand" "")
3183         (match_operand:DF 1 "general_operand" ""))]
3184   "reload_completed
3185    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
3186    && ! (ANY_FP_REG_P (operands[0]) ||
3187          (GET_CODE (operands[0]) == SUBREG
3188           && ANY_FP_REG_P (SUBREG_REG (operands[0]))))
3189    && ! (ANY_FP_REG_P (operands[1]) ||
3190          (GET_CODE (operands[1]) == SUBREG
3191           && ANY_FP_REG_P (SUBREG_REG (operands[1]))))"
3192   [(const_int 0)]
3193   "ix86_split_long_move (operands); DONE;")
3194
3195 (define_insn "*movsf_internal"
3196   [(set (match_operand:SF 0 "nonimmediate_operand"
3197           "=f,m,f,r  ,m ,x,x,x ,m,!*y,!m,!*y,?Yi,?r,!*Ym,!r")
3198         (match_operand:SF 1 "general_operand"
3199           "fm,f,G,rmF,Fr,C,x,xm,x,m  ,*y,*y ,r  ,Yi,r   ,*Ym"))]
3200   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
3201    && (!can_create_pseudo_p ()
3202        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3203        || GET_CODE (operands[1]) != CONST_DOUBLE
3204        || (optimize_function_for_size_p (cfun)
3205            && ((!TARGET_SSE_MATH
3206                 && standard_80387_constant_p (operands[1]) > 0)
3207                || (TARGET_SSE_MATH
3208                    && standard_sse_constant_p (operands[1]))))
3209        || memory_operand (operands[0], SFmode))"
3210 {
3211   switch (which_alternative)
3212     {
3213     case 0:
3214     case 1:
3215       return output_387_reg_move (insn, operands);
3216
3217     case 2:
3218       return standard_80387_constant_opcode (operands[1]);
3219
3220     case 3:
3221     case 4:
3222       return "mov{l}\t{%1, %0|%0, %1}";
3223
3224     case 5:
3225       return standard_sse_constant_opcode (insn, operands[1]);
3226
3227     case 6:
3228       if (get_attr_mode (insn) == MODE_V4SF)
3229         return "%vmovaps\t{%1, %0|%0, %1}";
3230       else
3231         return "%vmovss\t{%1, %d0|%d0, %1}";
3232     case 7:
3233       if (TARGET_AVX && REG_P (operands[1]))
3234         return "vmovss\t{%1, %0, %0|%0, %0, %1}";
3235       else
3236         return "%vmovss\t{%1, %0|%0, %1}";
3237     case 8:
3238       return "%vmovss\t{%1, %0|%0, %1}";
3239
3240     case 9: case 10: case 14: case 15:
3241       return "movd\t{%1, %0|%0, %1}";
3242
3243     case 11:
3244       return "movq\t{%1, %0|%0, %1}";
3245
3246     case 12: case 13:
3247       return "%vmovd\t{%1, %0|%0, %1}";
3248
3249     default:
3250       gcc_unreachable ();
3251     }
3252 }
3253   [(set_attr "type" "fmov,fmov,fmov,imov,imov,sselog1,ssemov,ssemov,ssemov,mmxmov,mmxmov,mmxmov,ssemov,ssemov,mmxmov,mmxmov")
3254    (set (attr "prefix")
3255      (if_then_else (eq_attr "alternative" "5,6,7,8,12,13")
3256        (const_string "maybe_vex")
3257        (const_string "orig")))
3258    (set (attr "mode")
3259         (cond [(eq_attr "alternative" "3,4,9,10")
3260                  (const_string "SI")
3261                (eq_attr "alternative" "5")
3262                  (if_then_else
3263                    (and (and (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
3264                                  (const_int 0))
3265                              (ne (symbol_ref "TARGET_SSE2")
3266                                  (const_int 0)))
3267                         (eq (symbol_ref "optimize_function_for_size_p (cfun)")
3268                             (const_int 0)))
3269                    (const_string "TI")
3270                    (const_string "V4SF"))
3271                /* For architectures resolving dependencies on
3272                   whole SSE registers use APS move to break dependency
3273                   chains, otherwise use short move to avoid extra work.
3274
3275                   Do the same for architectures resolving dependencies on
3276                   the parts.  While in DF mode it is better to always handle
3277                   just register parts, the SF mode is different due to lack
3278                   of instructions to load just part of the register.  It is
3279                   better to maintain the whole registers in single format
3280                   to avoid problems on using packed logical operations.  */
3281                (eq_attr "alternative" "6")
3282                  (if_then_else
3283                    (ior (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3284                             (const_int 0))
3285                         (ne (symbol_ref "TARGET_SSE_SPLIT_REGS")
3286                             (const_int 0)))
3287                    (const_string "V4SF")
3288                    (const_string "SF"))
3289                (eq_attr "alternative" "11")
3290                  (const_string "DI")]
3291                (const_string "SF")))])
3292
3293 (define_split
3294   [(set (match_operand 0 "register_operand" "")
3295         (match_operand 1 "memory_operand" ""))]
3296   "reload_completed
3297    && MEM_P (operands[1])
3298    && (GET_MODE (operands[0]) == TFmode
3299        || GET_MODE (operands[0]) == XFmode
3300        || GET_MODE (operands[0]) == DFmode
3301        || GET_MODE (operands[0]) == SFmode)
3302    && (operands[2] = find_constant_src (insn))"
3303   [(set (match_dup 0) (match_dup 2))]
3304 {
3305   rtx c = operands[2];
3306   rtx r = operands[0];
3307
3308   if (GET_CODE (r) == SUBREG)
3309     r = SUBREG_REG (r);
3310
3311   if (SSE_REG_P (r))
3312     {
3313       if (!standard_sse_constant_p (c))
3314         FAIL;
3315     }
3316   else if (FP_REG_P (r))
3317     {
3318       if (standard_80387_constant_p (c) < 1)
3319         FAIL;
3320     }
3321   else if (MMX_REG_P (r))
3322     FAIL;
3323 })
3324
3325 (define_split
3326   [(set (match_operand 0 "register_operand" "")
3327         (float_extend (match_operand 1 "memory_operand" "")))]
3328   "reload_completed
3329    && MEM_P (operands[1])
3330    && (GET_MODE (operands[0]) == TFmode
3331        || GET_MODE (operands[0]) == XFmode
3332        || GET_MODE (operands[0]) == DFmode
3333        || GET_MODE (operands[0]) == SFmode)
3334    && (operands[2] = find_constant_src (insn))"
3335   [(set (match_dup 0) (match_dup 2))]
3336 {
3337   rtx c = operands[2];
3338   rtx r = operands[0];
3339
3340   if (GET_CODE (r) == SUBREG)
3341     r = SUBREG_REG (r);
3342
3343   if (SSE_REG_P (r))
3344     {
3345       if (!standard_sse_constant_p (c))
3346         FAIL;
3347     }
3348   else if (FP_REG_P (r))
3349     {
3350       if (standard_80387_constant_p (c) < 1)
3351         FAIL;
3352     }
3353   else if (MMX_REG_P (r))
3354     FAIL;
3355 })
3356
3357 ;; Split the load of -0.0 or -1.0 into fldz;fchs or fld1;fchs sequence
3358 (define_split
3359   [(set (match_operand:X87MODEF 0 "register_operand" "")
3360         (match_operand:X87MODEF 1 "immediate_operand" ""))]
3361   "reload_completed && FP_REGNO_P (REGNO (operands[0]))
3362    && (standard_80387_constant_p (operands[1]) == 8
3363        || standard_80387_constant_p (operands[1]) == 9)"
3364   [(set (match_dup 0)(match_dup 1))
3365    (set (match_dup 0)
3366         (neg:X87MODEF (match_dup 0)))]
3367 {
3368   REAL_VALUE_TYPE r;
3369
3370   REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
3371   if (real_isnegzero (&r))
3372     operands[1] = CONST0_RTX (<MODE>mode);
3373   else
3374     operands[1] = CONST1_RTX (<MODE>mode);
3375 })
3376
3377 (define_insn "swapxf"
3378   [(set (match_operand:XF 0 "register_operand" "+f")
3379         (match_operand:XF 1 "register_operand" "+f"))
3380    (set (match_dup 1)
3381         (match_dup 0))]
3382   "TARGET_80387"
3383 {
3384   if (STACK_TOP_P (operands[0]))
3385     return "fxch\t%1";
3386   else
3387     return "fxch\t%0";
3388 }
3389   [(set_attr "type" "fxch")
3390    (set_attr "mode" "XF")])
3391
3392 (define_insn "*swap<mode>"
3393   [(set (match_operand:MODEF 0 "fp_register_operand" "+f")
3394         (match_operand:MODEF 1 "fp_register_operand" "+f"))
3395    (set (match_dup 1)
3396         (match_dup 0))]
3397   "TARGET_80387 || reload_completed"
3398 {
3399   if (STACK_TOP_P (operands[0]))
3400     return "fxch\t%1";
3401   else
3402     return "fxch\t%0";
3403 }
3404   [(set_attr "type" "fxch")
3405    (set_attr "mode" "<MODE>")])
3406 \f
3407 ;; Zero extension instructions
3408
3409 (define_expand "zero_extendsidi2"
3410   [(set (match_operand:DI 0 "nonimmediate_operand" "")
3411         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))]
3412   ""
3413 {
3414   if (!TARGET_64BIT)
3415     {
3416       emit_insn (gen_zero_extendsidi2_1 (operands[0], operands[1]));
3417       DONE;
3418     }
3419 })
3420
3421 (define_insn "*zero_extendsidi2_rex64"
3422   [(set (match_operand:DI 0 "nonimmediate_operand"  "=r,o,?*Ym,?*y,?*Yi,*Y2")
3423         (zero_extend:DI
3424          (match_operand:SI 1 "nonimmediate_operand" "rm,0,r   ,m  ,r   ,m")))]
3425   "TARGET_64BIT"
3426   "@
3427    mov\t{%k1, %k0|%k0, %k1}
3428    #
3429    movd\t{%1, %0|%0, %1}
3430    movd\t{%1, %0|%0, %1}
3431    %vmovd\t{%1, %0|%0, %1}
3432    %vmovd\t{%1, %0|%0, %1}"
3433   [(set_attr "type" "imovx,imov,mmxmov,mmxmov,ssemov,ssemov")
3434    (set_attr "prefix" "orig,*,orig,orig,maybe_vex,maybe_vex")
3435    (set_attr "prefix_0f" "0,*,*,*,*,*")
3436    (set_attr "mode" "SI,DI,DI,DI,TI,TI")])
3437
3438 (define_split
3439   [(set (match_operand:DI 0 "memory_operand" "")
3440         (zero_extend:DI (match_dup 0)))]
3441   "TARGET_64BIT"
3442   [(set (match_dup 4) (const_int 0))]
3443   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3444
3445 ;; %%% Kill me once multi-word ops are sane.
3446 (define_insn "zero_extendsidi2_1"
3447   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,?r,?o,?*Ym,?*y,?*Yi,*Y2")
3448         (zero_extend:DI
3449          (match_operand:SI 1 "nonimmediate_operand" "0,rm,r ,r   ,m  ,r   ,m")))
3450    (clobber (reg:CC FLAGS_REG))]
3451   "!TARGET_64BIT"
3452   "@
3453    #
3454    #
3455    #
3456    movd\t{%1, %0|%0, %1}
3457    movd\t{%1, %0|%0, %1}
3458    %vmovd\t{%1, %0|%0, %1}
3459    %vmovd\t{%1, %0|%0, %1}"
3460   [(set_attr "type" "multi,multi,multi,mmxmov,mmxmov,ssemov,ssemov")
3461    (set_attr "prefix" "*,*,*,orig,orig,maybe_vex,maybe_vex")
3462    (set_attr "mode" "SI,SI,SI,DI,DI,TI,TI")])
3463
3464 (define_split
3465   [(set (match_operand:DI 0 "register_operand" "")
3466         (zero_extend:DI (match_operand:SI 1 "register_operand" "")))
3467    (clobber (reg:CC FLAGS_REG))]
3468   "!TARGET_64BIT && reload_completed
3469    && true_regnum (operands[0]) == true_regnum (operands[1])"
3470   [(set (match_dup 4) (const_int 0))]
3471   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3472
3473 (define_split
3474   [(set (match_operand:DI 0 "nonimmediate_operand" "")
3475         (zero_extend:DI (match_operand:SI 1 "general_operand" "")))
3476    (clobber (reg:CC FLAGS_REG))]
3477   "!TARGET_64BIT && reload_completed
3478    && !(MMX_REG_P (operands[0]) || SSE_REG_P (operands[0]))"
3479   [(set (match_dup 3) (match_dup 1))
3480    (set (match_dup 4) (const_int 0))]
3481   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3482
3483 (define_insn "zero_extend<mode>di2"
3484   [(set (match_operand:DI 0 "register_operand" "=r")
3485         (zero_extend:DI
3486          (match_operand:SWI12 1 "nonimmediate_operand" "<r>m")))]
3487   "TARGET_64BIT"
3488   "movz{<imodesuffix>l|x}\t{%1, %k0|%k0, %1}"
3489   [(set_attr "type" "imovx")
3490    (set_attr "mode" "SI")])
3491
3492 (define_expand "zero_extendhisi2"
3493   [(set (match_operand:SI 0 "register_operand" "")
3494         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "")))]
3495   ""
3496 {
3497   if (TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))
3498     {
3499       operands[1] = force_reg (HImode, operands[1]);
3500       emit_insn (gen_zero_extendhisi2_and (operands[0], operands[1]));
3501       DONE;
3502     }
3503 })
3504
3505 (define_insn_and_split "zero_extendhisi2_and"
3506   [(set (match_operand:SI 0 "register_operand" "=r")
3507         (zero_extend:SI (match_operand:HI 1 "register_operand" "0")))
3508    (clobber (reg:CC FLAGS_REG))]
3509   "TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
3510   "#"
3511   "&& reload_completed"
3512   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (const_int 65535)))
3513               (clobber (reg:CC FLAGS_REG))])]
3514   ""
3515   [(set_attr "type" "alu1")
3516    (set_attr "mode" "SI")])
3517
3518 (define_insn "*zero_extendhisi2_movzwl"
3519   [(set (match_operand:SI 0 "register_operand" "=r")
3520         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "rm")))]
3521   "!TARGET_ZERO_EXTEND_WITH_AND
3522    || optimize_function_for_size_p (cfun)"
3523   "movz{wl|x}\t{%1, %0|%0, %1}"
3524   [(set_attr "type" "imovx")
3525    (set_attr "mode" "SI")])
3526
3527 (define_expand "zero_extendqi<mode>2"
3528   [(parallel
3529     [(set (match_operand:SWI24 0 "register_operand" "")
3530           (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "")))
3531      (clobber (reg:CC FLAGS_REG))])])
3532
3533 (define_insn "*zero_extendqi<mode>2_and"
3534   [(set (match_operand:SWI24 0 "register_operand" "=r,?&q")
3535         (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "0,qm")))
3536    (clobber (reg:CC FLAGS_REG))]
3537   "TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
3538   "#"
3539   [(set_attr "type" "alu1")
3540    (set_attr "mode" "<MODE>")])
3541
3542 ;; When source and destination does not overlap, clear destination
3543 ;; first and then do the movb
3544 (define_split
3545   [(set (match_operand:SWI24 0 "register_operand" "")
3546         (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "")))
3547    (clobber (reg:CC FLAGS_REG))]
3548   "reload_completed
3549    && (TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))
3550    && ANY_QI_REG_P (operands[0])
3551    && (ANY_QI_REG_P (operands[1]) || MEM_P (operands[1]))
3552    && !reg_overlap_mentioned_p (operands[0], operands[1])"
3553   [(set (strict_low_part (match_dup 2)) (match_dup 1))]
3554 {
3555   operands[2] = gen_lowpart (QImode, operands[0]);
3556   ix86_expand_clear (operands[0]);
3557 })
3558
3559 (define_insn "*zero_extendqi<mode>2_movzbl_and"
3560   [(set (match_operand:SWI24 0 "register_operand" "=r,r")
3561         (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "qm,0")))
3562    (clobber (reg:CC FLAGS_REG))]
3563   "!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun)"
3564   "#"
3565   [(set_attr "type" "imovx,alu1")
3566    (set_attr "mode" "<MODE>")])
3567
3568 ;; For the movzbl case strip only the clobber
3569 (define_split
3570   [(set (match_operand:SWI24 0 "register_operand" "")
3571         (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "")))
3572    (clobber (reg:CC FLAGS_REG))]
3573   "reload_completed
3574    && (!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun))
3575    && (!REG_P (operands[1]) || ANY_QI_REG_P (operands[1]))"
3576   [(set (match_dup 0)
3577         (zero_extend:SWI24 (match_dup 1)))])
3578
3579 ; zero extend to SImode to avoid partial register stalls
3580 (define_insn "*zero_extendqi<mode>2_movzbl"
3581   [(set (match_operand:SWI24 0 "register_operand" "=r")
3582         (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3583   "reload_completed
3584    && (!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun))"
3585   "movz{bl|x}\t{%1, %k0|%k0, %1}"
3586   [(set_attr "type" "imovx")
3587    (set_attr "mode" "SI")])
3588
3589 ;; Rest is handled by single and.
3590 (define_split
3591   [(set (match_operand:SWI24 0 "register_operand" "")
3592         (zero_extend:SWI24 (match_operand:QI 1 "register_operand" "")))
3593    (clobber (reg:CC FLAGS_REG))]
3594   "reload_completed
3595    && true_regnum (operands[0]) == true_regnum (operands[1])"
3596   [(parallel [(set (match_dup 0) (and:SWI24 (match_dup 0) (const_int 255)))
3597               (clobber (reg:CC FLAGS_REG))])])
3598 \f
3599 ;; Sign extension instructions
3600
3601 (define_expand "extendsidi2"
3602   [(set (match_operand:DI 0 "register_operand" "")
3603         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))]
3604   ""
3605 {
3606   if (!TARGET_64BIT)
3607     {
3608       emit_insn (gen_extendsidi2_1 (operands[0], operands[1]));
3609       DONE;
3610     }
3611 })
3612
3613 (define_insn "*extendsidi2_rex64"
3614   [(set (match_operand:DI 0 "register_operand" "=*a,r")
3615         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "*0,rm")))]
3616   "TARGET_64BIT"
3617   "@
3618    {cltq|cdqe}
3619    movs{lq|x}\t{%1, %0|%0, %1}"
3620   [(set_attr "type" "imovx")
3621    (set_attr "mode" "DI")
3622    (set_attr "prefix_0f" "0")
3623    (set_attr "modrm" "0,1")])
3624
3625 (define_insn "extendsidi2_1"
3626   [(set (match_operand:DI 0 "nonimmediate_operand" "=*A,r,?r,?*o")
3627         (sign_extend:DI (match_operand:SI 1 "register_operand" "0,0,r,r")))
3628    (clobber (reg:CC FLAGS_REG))
3629    (clobber (match_scratch:SI 2 "=X,X,X,&r"))]
3630   "!TARGET_64BIT"
3631   "#")
3632
3633 ;; Extend to memory case when source register does die.
3634 (define_split
3635   [(set (match_operand:DI 0 "memory_operand" "")
3636         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3637    (clobber (reg:CC FLAGS_REG))
3638    (clobber (match_operand:SI 2 "register_operand" ""))]
3639   "(reload_completed
3640     && dead_or_set_p (insn, operands[1])
3641     && !reg_mentioned_p (operands[1], operands[0]))"
3642   [(set (match_dup 3) (match_dup 1))
3643    (parallel [(set (match_dup 1) (ashiftrt:SI (match_dup 1) (const_int 31)))
3644               (clobber (reg:CC FLAGS_REG))])
3645    (set (match_dup 4) (match_dup 1))]
3646   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3647
3648 ;; Extend to memory case when source register does not die.
3649 (define_split
3650   [(set (match_operand:DI 0 "memory_operand" "")
3651         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3652    (clobber (reg:CC FLAGS_REG))
3653    (clobber (match_operand:SI 2 "register_operand" ""))]
3654   "reload_completed"
3655   [(const_int 0)]
3656 {
3657   split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);
3658
3659   emit_move_insn (operands[3], operands[1]);
3660
3661   /* Generate a cltd if possible and doing so it profitable.  */
3662   if ((optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
3663       && true_regnum (operands[1]) == AX_REG
3664       && true_regnum (operands[2]) == DX_REG)
3665     {
3666       emit_insn (gen_ashrsi3_cvt (operands[2], operands[1], GEN_INT (31)));
3667     }
3668   else
3669     {
3670       emit_move_insn (operands[2], operands[1]);
3671       emit_insn (gen_ashrsi3_cvt (operands[2], operands[2], GEN_INT (31)));
3672     }
3673   emit_move_insn (operands[4], operands[2]);
3674   DONE;
3675 })
3676
3677 ;; Extend to register case.  Optimize case where source and destination
3678 ;; registers match and cases where we can use cltd.
3679 (define_split
3680   [(set (match_operand:DI 0 "register_operand" "")
3681         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3682    (clobber (reg:CC FLAGS_REG))
3683    (clobber (match_scratch:SI 2 ""))]
3684   "reload_completed"
3685   [(const_int 0)]
3686 {
3687   split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);
3688
3689   if (true_regnum (operands[3]) != true_regnum (operands[1]))
3690     emit_move_insn (operands[3], operands[1]);
3691
3692   /* Generate a cltd if possible and doing so it profitable.  */
3693   if ((optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
3694       && true_regnum (operands[3]) == AX_REG
3695       && true_regnum (operands[4]) == DX_REG)
3696     {
3697       emit_insn (gen_ashrsi3_cvt (operands[4], operands[3], GEN_INT (31)));
3698       DONE;
3699     }
3700
3701   if (true_regnum (operands[4]) != true_regnum (operands[1]))
3702     emit_move_insn (operands[4], operands[1]);
3703
3704   emit_insn (gen_ashrsi3_cvt (operands[4], operands[4], GEN_INT (31)));
3705   DONE;
3706 })
3707
3708 (define_insn "extend<mode>di2"
3709   [(set (match_operand:DI 0 "register_operand" "=r")
3710         (sign_extend:DI
3711          (match_operand:SWI12 1 "nonimmediate_operand" "<r>m")))]
3712   "TARGET_64BIT"
3713   "movs{<imodesuffix>q|x}\t{%1, %0|%0, %1}"
3714   [(set_attr "type" "imovx")
3715    (set_attr "mode" "DI")])
3716
3717 (define_insn "extendhisi2"
3718   [(set (match_operand:SI 0 "register_operand" "=*a,r")
3719         (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "*0,rm")))]
3720   ""
3721 {
3722   switch (get_attr_prefix_0f (insn))
3723     {
3724     case 0:
3725       return "{cwtl|cwde}";
3726     default:
3727       return "movs{wl|x}\t{%1, %0|%0, %1}";
3728     }
3729 }
3730   [(set_attr "type" "imovx")
3731    (set_attr "mode" "SI")
3732    (set (attr "prefix_0f")
3733      ;; movsx is short decodable while cwtl is vector decoded.
3734      (if_then_else (and (eq_attr "cpu" "!k6")
3735                         (eq_attr "alternative" "0"))
3736         (const_string "0")
3737         (const_string "1")))
3738    (set (attr "modrm")
3739      (if_then_else (eq_attr "prefix_0f" "0")
3740         (const_string "0")
3741         (const_string "1")))])
3742
3743 (define_insn "*extendhisi2_zext"
3744   [(set (match_operand:DI 0 "register_operand" "=*a,r")
3745         (zero_extend:DI
3746          (sign_extend:SI
3747           (match_operand:HI 1 "nonimmediate_operand" "*0,rm"))))]
3748   "TARGET_64BIT"
3749 {
3750   switch (get_attr_prefix_0f (insn))
3751     {
3752     case 0:
3753       return "{cwtl|cwde}";
3754     default:
3755       return "movs{wl|x}\t{%1, %k0|%k0, %1}";
3756     }
3757 }
3758   [(set_attr "type" "imovx")
3759    (set_attr "mode" "SI")
3760    (set (attr "prefix_0f")
3761      ;; movsx is short decodable while cwtl is vector decoded.
3762      (if_then_else (and (eq_attr "cpu" "!k6")
3763                         (eq_attr "alternative" "0"))
3764         (const_string "0")
3765         (const_string "1")))
3766    (set (attr "modrm")
3767      (if_then_else (eq_attr "prefix_0f" "0")
3768         (const_string "0")
3769         (const_string "1")))])
3770
3771 (define_insn "extendqisi2"
3772   [(set (match_operand:SI 0 "register_operand" "=r")
3773         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3774   ""
3775   "movs{bl|x}\t{%1, %0|%0, %1}"
3776    [(set_attr "type" "imovx")
3777     (set_attr "mode" "SI")])
3778
3779 (define_insn "*extendqisi2_zext"
3780   [(set (match_operand:DI 0 "register_operand" "=r")
3781         (zero_extend:DI
3782           (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm"))))]
3783   "TARGET_64BIT"
3784   "movs{bl|x}\t{%1, %k0|%k0, %1}"
3785    [(set_attr "type" "imovx")
3786     (set_attr "mode" "SI")])
3787
3788 (define_insn "extendqihi2"
3789   [(set (match_operand:HI 0 "register_operand" "=*a,r")
3790         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "*0,qm")))]
3791   ""
3792 {
3793   switch (get_attr_prefix_0f (insn))
3794     {
3795     case 0:
3796       return "{cbtw|cbw}";
3797     default:
3798       return "movs{bw|x}\t{%1, %0|%0, %1}";
3799     }
3800 }
3801   [(set_attr "type" "imovx")
3802    (set_attr "mode" "HI")
3803    (set (attr "prefix_0f")
3804      ;; movsx is short decodable while cwtl is vector decoded.
3805      (if_then_else (and (eq_attr "cpu" "!k6")
3806                         (eq_attr "alternative" "0"))
3807         (const_string "0")
3808         (const_string "1")))
3809    (set (attr "modrm")
3810      (if_then_else (eq_attr "prefix_0f" "0")
3811         (const_string "0")
3812         (const_string "1")))])
3813 \f
3814 ;; Conversions between float and double.
3815
3816 ;; These are all no-ops in the model used for the 80387.
3817 ;; So just emit moves.
3818
3819 ;; %%% Kill these when call knows how to work out a DFmode push earlier.
3820 (define_split
3821   [(set (match_operand:DF 0 "push_operand" "")
3822         (float_extend:DF (match_operand:SF 1 "fp_register_operand" "")))]
3823   "reload_completed"
3824   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -8)))
3825    (set (mem:DF (reg:P SP_REG)) (float_extend:DF (match_dup 1)))])
3826
3827 (define_split
3828   [(set (match_operand:XF 0 "push_operand" "")
3829         (float_extend:XF (match_operand:MODEF 1 "fp_register_operand" "")))]
3830   "reload_completed"
3831   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
3832    (set (mem:XF (reg:P SP_REG)) (float_extend:XF (match_dup 1)))]
3833   "operands[2] = GEN_INT (-GET_MODE_SIZE (XFmode));")
3834
3835 (define_expand "extendsfdf2"
3836   [(set (match_operand:DF 0 "nonimmediate_operand" "")
3837         (float_extend:DF (match_operand:SF 1 "general_operand" "")))]
3838   "TARGET_80387 || (TARGET_SSE2 && TARGET_SSE_MATH)"
3839 {
3840   /* ??? Needed for compress_float_constant since all fp constants
3841      are TARGET_LEGITIMATE_CONSTANT_P.  */
3842   if (GET_CODE (operands[1]) == CONST_DOUBLE)
3843     {
3844       if ((!TARGET_SSE2 || TARGET_MIX_SSE_I387)
3845           && standard_80387_constant_p (operands[1]) > 0)
3846         {
3847           operands[1] = simplify_const_unary_operation
3848             (FLOAT_EXTEND, DFmode, operands[1], SFmode);
3849           emit_move_insn_1 (operands[0], operands[1]);
3850           DONE;
3851         }
3852       operands[1] = validize_mem (force_const_mem (SFmode, operands[1]));
3853     }
3854 })
3855
3856 /* For converting SF(xmm2) to DF(xmm1), use the following code instead of
3857    cvtss2sd:
3858       unpcklps xmm2,xmm2   ; packed conversion might crash on signaling NaNs
3859       cvtps2pd xmm2,xmm1
3860    We do the conversion post reload to avoid producing of 128bit spills
3861    that might lead to ICE on 32bit target.  The sequence unlikely combine
3862    anyway.  */
3863 (define_split
3864   [(set (match_operand:DF 0 "register_operand" "")
3865         (float_extend:DF
3866           (match_operand:SF 1 "nonimmediate_operand" "")))]
3867   "TARGET_USE_VECTOR_FP_CONVERTS
3868    && optimize_insn_for_speed_p ()
3869    && reload_completed && SSE_REG_P (operands[0])"
3870    [(set (match_dup 2)
3871          (float_extend:V2DF
3872            (vec_select:V2SF
3873              (match_dup 3)
3874              (parallel [(const_int 0) (const_int 1)]))))]
3875 {
3876   operands[2] = simplify_gen_subreg (V2DFmode, operands[0], DFmode, 0);
3877   operands[3] = simplify_gen_subreg (V4SFmode, operands[0], DFmode, 0);
3878   /* Use movss for loading from memory, unpcklps reg, reg for registers.
3879      Try to avoid move when unpacking can be done in source.  */
3880   if (REG_P (operands[1]))
3881     {
3882       /* If it is unsafe to overwrite upper half of source, we need
3883          to move to destination and unpack there.  */
3884       if ((ORIGINAL_REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
3885            || PSEUDO_REGNO_BYTES (ORIGINAL_REGNO (operands[1])) > 4)
3886           && true_regnum (operands[0]) != true_regnum (operands[1]))
3887         {
3888           rtx tmp = gen_rtx_REG (SFmode, true_regnum (operands[0]));
3889           emit_move_insn (tmp, operands[1]);
3890         }
3891       else
3892         operands[3] = simplify_gen_subreg (V4SFmode, operands[1], SFmode, 0);
3893       emit_insn (gen_vec_interleave_lowv4sf (operands[3], operands[3],
3894                                              operands[3]));
3895     }
3896   else
3897     emit_insn (gen_vec_setv4sf_0 (operands[3],
3898                                   CONST0_RTX (V4SFmode), operands[1]));
3899 })
3900
3901 (define_insn "*extendsfdf2_mixed"
3902   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,m,x")
3903         (float_extend:DF
3904           (match_operand:SF 1 "nonimmediate_operand" "fm,f,xm")))]
3905   "TARGET_SSE2 && TARGET_MIX_SSE_I387"
3906 {
3907   switch (which_alternative)
3908     {
3909     case 0:
3910     case 1:
3911       return output_387_reg_move (insn, operands);
3912
3913     case 2:
3914       return "%vcvtss2sd\t{%1, %d0|%d0, %1}";
3915
3916     default:
3917       gcc_unreachable ();
3918     }
3919 }
3920   [(set_attr "type" "fmov,fmov,ssecvt")
3921    (set_attr "prefix" "orig,orig,maybe_vex")
3922    (set_attr "mode" "SF,XF,DF")])
3923
3924 (define_insn "*extendsfdf2_sse"
3925   [(set (match_operand:DF 0 "nonimmediate_operand" "=x")
3926         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "xm")))]
3927   "TARGET_SSE2 && TARGET_SSE_MATH"
3928   "%vcvtss2sd\t{%1, %d0|%d0, %1}"
3929   [(set_attr "type" "ssecvt")
3930    (set_attr "prefix" "maybe_vex")
3931    (set_attr "mode" "DF")])
3932
3933 (define_insn "*extendsfdf2_i387"
3934   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,m")
3935         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "fm,f")))]
3936   "TARGET_80387"
3937   "* return output_387_reg_move (insn, operands);"
3938   [(set_attr "type" "fmov")
3939    (set_attr "mode" "SF,XF")])
3940
3941 (define_expand "extend<mode>xf2"
3942   [(set (matc