OSDN Git Service

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