OSDN Git Service

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