OSDN Git Service

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