OSDN Git Service

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