OSDN Git Service

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