OSDN Git Service

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