OSDN Git Service

Add -mlzcnt.
[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 \f
955 ;; Scheduling descriptions
956
957 (include "pentium.md")
958 (include "ppro.md")
959 (include "k6.md")
960 (include "athlon.md")
961 (include "bdver1.md")
962 (include "geode.md")
963 (include "atom.md")
964 (include "core2.md")
965
966 \f
967 ;; Operand and operator predicates and constraints
968
969 (include "predicates.md")
970 (include "constraints.md")
971
972 \f
973 ;; Compare and branch/compare and store instructions.
974
975 (define_expand "cbranch<mode>4"
976   [(set (reg:CC FLAGS_REG)
977         (compare:CC (match_operand:SDWIM 1 "nonimmediate_operand" "")
978                     (match_operand:SDWIM 2 "<general_operand>" "")))
979    (set (pc) (if_then_else
980                (match_operator 0 "ordered_comparison_operator"
981                 [(reg:CC FLAGS_REG) (const_int 0)])
982                (label_ref (match_operand 3 "" ""))
983                (pc)))]
984   ""
985 {
986   if (MEM_P (operands[1]) && MEM_P (operands[2]))
987     operands[1] = force_reg (<MODE>mode, operands[1]);
988   ix86_expand_branch (GET_CODE (operands[0]),
989                       operands[1], operands[2], operands[3]);
990   DONE;
991 })
992
993 (define_expand "cstore<mode>4"
994   [(set (reg:CC FLAGS_REG)
995         (compare:CC (match_operand:SWIM 2 "nonimmediate_operand" "")
996                     (match_operand:SWIM 3 "<general_operand>" "")))
997    (set (match_operand:QI 0 "register_operand" "")
998         (match_operator 1 "ordered_comparison_operator"
999           [(reg:CC FLAGS_REG) (const_int 0)]))]
1000   ""
1001 {
1002   if (MEM_P (operands[2]) && MEM_P (operands[3]))
1003     operands[2] = force_reg (<MODE>mode, operands[2]);
1004   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1005                      operands[2], operands[3]);
1006   DONE;
1007 })
1008
1009 (define_expand "cmp<mode>_1"
1010   [(set (reg:CC FLAGS_REG)
1011         (compare:CC (match_operand:SWI48 0 "nonimmediate_operand" "")
1012                     (match_operand:SWI48 1 "<general_operand>" "")))])
1013
1014 (define_insn "*cmp<mode>_ccno_1"
1015   [(set (reg FLAGS_REG)
1016         (compare (match_operand:SWI 0 "nonimmediate_operand" "<r>,?m<r>")
1017                  (match_operand:SWI 1 "const0_operand" "")))]
1018   "ix86_match_ccmode (insn, CCNOmode)"
1019   "@
1020    test{<imodesuffix>}\t%0, %0
1021    cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
1022   [(set_attr "type" "test,icmp")
1023    (set_attr "length_immediate" "0,1")
1024    (set_attr "mode" "<MODE>")])
1025
1026 (define_insn "*cmp<mode>_1"
1027   [(set (reg FLAGS_REG)
1028         (compare (match_operand:SWI 0 "nonimmediate_operand" "<r>m,<r>")
1029                  (match_operand:SWI 1 "<general_operand>" "<r><i>,<r>m")))]
1030   "ix86_match_ccmode (insn, CCmode)"
1031   "cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
1032   [(set_attr "type" "icmp")
1033    (set_attr "mode" "<MODE>")])
1034
1035 (define_insn "*cmp<mode>_minus_1"
1036   [(set (reg FLAGS_REG)
1037         (compare
1038           (minus:SWI (match_operand:SWI 0 "nonimmediate_operand" "<r>m,<r>")
1039                      (match_operand:SWI 1 "<general_operand>" "<r><i>,<r>m"))
1040           (const_int 0)))]
1041   "ix86_match_ccmode (insn, CCGOCmode)"
1042   "cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
1043   [(set_attr "type" "icmp")
1044    (set_attr "mode" "<MODE>")])
1045
1046 (define_insn "*cmpqi_ext_1"
1047   [(set (reg FLAGS_REG)
1048         (compare
1049           (match_operand:QI 0 "general_operand" "Qm")
1050           (subreg:QI
1051             (zero_extract:SI
1052               (match_operand 1 "ext_register_operand" "Q")
1053               (const_int 8)
1054               (const_int 8)) 0)))]
1055   "!TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1056   "cmp{b}\t{%h1, %0|%0, %h1}"
1057   [(set_attr "type" "icmp")
1058    (set_attr "mode" "QI")])
1059
1060 (define_insn "*cmpqi_ext_1_rex64"
1061   [(set (reg FLAGS_REG)
1062         (compare
1063           (match_operand:QI 0 "register_operand" "Q")
1064           (subreg:QI
1065             (zero_extract:SI
1066               (match_operand 1 "ext_register_operand" "Q")
1067               (const_int 8)
1068               (const_int 8)) 0)))]
1069   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1070   "cmp{b}\t{%h1, %0|%0, %h1}"
1071   [(set_attr "type" "icmp")
1072    (set_attr "mode" "QI")])
1073
1074 (define_insn "*cmpqi_ext_2"
1075   [(set (reg FLAGS_REG)
1076         (compare
1077           (subreg:QI
1078             (zero_extract:SI
1079               (match_operand 0 "ext_register_operand" "Q")
1080               (const_int 8)
1081               (const_int 8)) 0)
1082           (match_operand:QI 1 "const0_operand" "")))]
1083   "ix86_match_ccmode (insn, CCNOmode)"
1084   "test{b}\t%h0, %h0"
1085   [(set_attr "type" "test")
1086    (set_attr "length_immediate" "0")
1087    (set_attr "mode" "QI")])
1088
1089 (define_expand "cmpqi_ext_3"
1090   [(set (reg:CC FLAGS_REG)
1091         (compare:CC
1092           (subreg:QI
1093             (zero_extract:SI
1094               (match_operand 0 "ext_register_operand" "")
1095               (const_int 8)
1096               (const_int 8)) 0)
1097           (match_operand:QI 1 "immediate_operand" "")))])
1098
1099 (define_insn "*cmpqi_ext_3_insn"
1100   [(set (reg FLAGS_REG)
1101         (compare
1102           (subreg:QI
1103             (zero_extract:SI
1104               (match_operand 0 "ext_register_operand" "Q")
1105               (const_int 8)
1106               (const_int 8)) 0)
1107           (match_operand:QI 1 "general_operand" "Qmn")))]
1108   "!TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1109   "cmp{b}\t{%1, %h0|%h0, %1}"
1110   [(set_attr "type" "icmp")
1111    (set_attr "modrm" "1")
1112    (set_attr "mode" "QI")])
1113
1114 (define_insn "*cmpqi_ext_3_insn_rex64"
1115   [(set (reg FLAGS_REG)
1116         (compare
1117           (subreg:QI
1118             (zero_extract:SI
1119               (match_operand 0 "ext_register_operand" "Q")
1120               (const_int 8)
1121               (const_int 8)) 0)
1122           (match_operand:QI 1 "nonmemory_operand" "Qn")))]
1123   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1124   "cmp{b}\t{%1, %h0|%h0, %1}"
1125   [(set_attr "type" "icmp")
1126    (set_attr "modrm" "1")
1127    (set_attr "mode" "QI")])
1128
1129 (define_insn "*cmpqi_ext_4"
1130   [(set (reg FLAGS_REG)
1131         (compare
1132           (subreg:QI
1133             (zero_extract:SI
1134               (match_operand 0 "ext_register_operand" "Q")
1135               (const_int 8)
1136               (const_int 8)) 0)
1137           (subreg:QI
1138             (zero_extract:SI
1139               (match_operand 1 "ext_register_operand" "Q")
1140               (const_int 8)
1141               (const_int 8)) 0)))]
1142   "ix86_match_ccmode (insn, CCmode)"
1143   "cmp{b}\t{%h1, %h0|%h0, %h1}"
1144   [(set_attr "type" "icmp")
1145    (set_attr "mode" "QI")])
1146
1147 ;; These implement float point compares.
1148 ;; %%% See if we can get away with VOIDmode operands on the actual insns,
1149 ;; which would allow mix and match FP modes on the compares.  Which is what
1150 ;; the old patterns did, but with many more of them.
1151
1152 (define_expand "cbranchxf4"
1153   [(set (reg:CC FLAGS_REG)
1154         (compare:CC (match_operand:XF 1 "nonmemory_operand" "")
1155                     (match_operand:XF 2 "nonmemory_operand" "")))
1156    (set (pc) (if_then_else
1157               (match_operator 0 "ix86_fp_comparison_operator"
1158                [(reg:CC FLAGS_REG)
1159                 (const_int 0)])
1160               (label_ref (match_operand 3 "" ""))
1161               (pc)))]
1162   "TARGET_80387"
1163 {
1164   ix86_expand_branch (GET_CODE (operands[0]),
1165                       operands[1], operands[2], operands[3]);
1166   DONE;
1167 })
1168
1169 (define_expand "cstorexf4"
1170   [(set (reg:CC FLAGS_REG)
1171         (compare:CC (match_operand:XF 2 "nonmemory_operand" "")
1172                     (match_operand:XF 3 "nonmemory_operand" "")))
1173    (set (match_operand:QI 0 "register_operand" "")
1174               (match_operator 1 "ix86_fp_comparison_operator"
1175                [(reg:CC FLAGS_REG)
1176                 (const_int 0)]))]
1177   "TARGET_80387"
1178 {
1179   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1180                      operands[2], operands[3]);
1181   DONE;
1182 })
1183
1184 (define_expand "cbranch<mode>4"
1185   [(set (reg:CC FLAGS_REG)
1186         (compare:CC (match_operand:MODEF 1 "cmp_fp_expander_operand" "")
1187                     (match_operand:MODEF 2 "cmp_fp_expander_operand" "")))
1188    (set (pc) (if_then_else
1189               (match_operator 0 "ix86_fp_comparison_operator"
1190                [(reg:CC FLAGS_REG)
1191                 (const_int 0)])
1192               (label_ref (match_operand 3 "" ""))
1193               (pc)))]
1194   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
1195 {
1196   ix86_expand_branch (GET_CODE (operands[0]),
1197                       operands[1], operands[2], operands[3]);
1198   DONE;
1199 })
1200
1201 (define_expand "cstore<mode>4"
1202   [(set (reg:CC FLAGS_REG)
1203         (compare:CC (match_operand:MODEF 2 "cmp_fp_expander_operand" "")
1204                     (match_operand:MODEF 3 "cmp_fp_expander_operand" "")))
1205    (set (match_operand:QI 0 "register_operand" "")
1206               (match_operator 1 "ix86_fp_comparison_operator"
1207                [(reg:CC FLAGS_REG)
1208                 (const_int 0)]))]
1209   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
1210 {
1211   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1212                      operands[2], operands[3]);
1213   DONE;
1214 })
1215
1216 (define_expand "cbranchcc4"
1217   [(set (pc) (if_then_else
1218               (match_operator 0 "comparison_operator"
1219                [(match_operand 1 "flags_reg_operand" "")
1220                 (match_operand 2 "const0_operand" "")])
1221               (label_ref (match_operand 3 "" ""))
1222               (pc)))]
1223   ""
1224 {
1225   ix86_expand_branch (GET_CODE (operands[0]),
1226                       operands[1], operands[2], operands[3]);
1227   DONE;
1228 })
1229
1230 (define_expand "cstorecc4"
1231   [(set (match_operand:QI 0 "register_operand" "")
1232               (match_operator 1 "comparison_operator"
1233                [(match_operand 2 "flags_reg_operand" "")
1234                 (match_operand 3 "const0_operand" "")]))]
1235   ""
1236 {
1237   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1238                      operands[2], operands[3]);
1239   DONE;
1240 })
1241
1242
1243 ;; FP compares, step 1:
1244 ;; Set the FP condition codes.
1245 ;;
1246 ;; CCFPmode     compare with exceptions
1247 ;; CCFPUmode    compare with no exceptions
1248
1249 ;; We may not use "#" to split and emit these, since the REG_DEAD notes
1250 ;; used to manage the reg stack popping would not be preserved.
1251
1252 (define_insn "*cmpfp_0"
1253   [(set (match_operand:HI 0 "register_operand" "=a")
1254         (unspec:HI
1255           [(compare:CCFP
1256              (match_operand 1 "register_operand" "f")
1257              (match_operand 2 "const0_operand" ""))]
1258         UNSPEC_FNSTSW))]
1259   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1260    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1261   "* return output_fp_compare (insn, operands, false, false);"
1262   [(set_attr "type" "multi")
1263    (set_attr "unit" "i387")
1264    (set (attr "mode")
1265      (cond [(match_operand:SF 1 "" "")
1266               (const_string "SF")
1267             (match_operand:DF 1 "" "")
1268               (const_string "DF")
1269            ]
1270            (const_string "XF")))])
1271
1272 (define_insn_and_split "*cmpfp_0_cc"
1273   [(set (reg:CCFP FLAGS_REG)
1274         (compare:CCFP
1275           (match_operand 1 "register_operand" "f")
1276           (match_operand 2 "const0_operand" "")))
1277    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1278   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1279    && TARGET_SAHF && !TARGET_CMOVE
1280    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1281   "#"
1282   "&& reload_completed"
1283   [(set (match_dup 0)
1284         (unspec:HI
1285           [(compare:CCFP (match_dup 1)(match_dup 2))]
1286         UNSPEC_FNSTSW))
1287    (set (reg:CC FLAGS_REG)
1288         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1289   ""
1290   [(set_attr "type" "multi")
1291    (set_attr "unit" "i387")
1292    (set (attr "mode")
1293      (cond [(match_operand:SF 1 "" "")
1294               (const_string "SF")
1295             (match_operand:DF 1 "" "")
1296               (const_string "DF")
1297            ]
1298            (const_string "XF")))])
1299
1300 (define_insn "*cmpfp_xf"
1301   [(set (match_operand:HI 0 "register_operand" "=a")
1302         (unspec:HI
1303           [(compare:CCFP
1304              (match_operand:XF 1 "register_operand" "f")
1305              (match_operand:XF 2 "register_operand" "f"))]
1306           UNSPEC_FNSTSW))]
1307   "TARGET_80387"
1308   "* return output_fp_compare (insn, operands, false, false);"
1309   [(set_attr "type" "multi")
1310    (set_attr "unit" "i387")
1311    (set_attr "mode" "XF")])
1312
1313 (define_insn_and_split "*cmpfp_xf_cc"
1314   [(set (reg:CCFP FLAGS_REG)
1315         (compare:CCFP
1316           (match_operand:XF 1 "register_operand" "f")
1317           (match_operand:XF 2 "register_operand" "f")))
1318    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1319   "TARGET_80387
1320    && TARGET_SAHF && !TARGET_CMOVE"
1321   "#"
1322   "&& reload_completed"
1323   [(set (match_dup 0)
1324         (unspec:HI
1325           [(compare:CCFP (match_dup 1)(match_dup 2))]
1326         UNSPEC_FNSTSW))
1327    (set (reg:CC FLAGS_REG)
1328         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1329   ""
1330   [(set_attr "type" "multi")
1331    (set_attr "unit" "i387")
1332    (set_attr "mode" "XF")])
1333
1334 (define_insn "*cmpfp_<mode>"
1335   [(set (match_operand:HI 0 "register_operand" "=a")
1336         (unspec:HI
1337           [(compare:CCFP
1338              (match_operand:MODEF 1 "register_operand" "f")
1339              (match_operand:MODEF 2 "nonimmediate_operand" "fm"))]
1340           UNSPEC_FNSTSW))]
1341   "TARGET_80387"
1342   "* return output_fp_compare (insn, operands, false, false);"
1343   [(set_attr "type" "multi")
1344    (set_attr "unit" "i387")
1345    (set_attr "mode" "<MODE>")])
1346
1347 (define_insn_and_split "*cmpfp_<mode>_cc"
1348   [(set (reg:CCFP FLAGS_REG)
1349         (compare:CCFP
1350           (match_operand:MODEF 1 "register_operand" "f")
1351           (match_operand:MODEF 2 "nonimmediate_operand" "fm")))
1352    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1353   "TARGET_80387
1354    && TARGET_SAHF && !TARGET_CMOVE"
1355   "#"
1356   "&& reload_completed"
1357   [(set (match_dup 0)
1358         (unspec:HI
1359           [(compare:CCFP (match_dup 1)(match_dup 2))]
1360         UNSPEC_FNSTSW))
1361    (set (reg:CC FLAGS_REG)
1362         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1363   ""
1364   [(set_attr "type" "multi")
1365    (set_attr "unit" "i387")
1366    (set_attr "mode" "<MODE>")])
1367
1368 (define_insn "*cmpfp_u"
1369   [(set (match_operand:HI 0 "register_operand" "=a")
1370         (unspec:HI
1371           [(compare:CCFPU
1372              (match_operand 1 "register_operand" "f")
1373              (match_operand 2 "register_operand" "f"))]
1374           UNSPEC_FNSTSW))]
1375   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1376    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1377   "* return output_fp_compare (insn, operands, false, true);"
1378   [(set_attr "type" "multi")
1379    (set_attr "unit" "i387")
1380    (set (attr "mode")
1381      (cond [(match_operand:SF 1 "" "")
1382               (const_string "SF")
1383             (match_operand:DF 1 "" "")
1384               (const_string "DF")
1385            ]
1386            (const_string "XF")))])
1387
1388 (define_insn_and_split "*cmpfp_u_cc"
1389   [(set (reg:CCFPU FLAGS_REG)
1390         (compare:CCFPU
1391           (match_operand 1 "register_operand" "f")
1392           (match_operand 2 "register_operand" "f")))
1393    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1394   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1395    && TARGET_SAHF && !TARGET_CMOVE
1396    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1397   "#"
1398   "&& reload_completed"
1399   [(set (match_dup 0)
1400         (unspec:HI
1401           [(compare:CCFPU (match_dup 1)(match_dup 2))]
1402         UNSPEC_FNSTSW))
1403    (set (reg:CC FLAGS_REG)
1404         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1405   ""
1406   [(set_attr "type" "multi")
1407    (set_attr "unit" "i387")
1408    (set (attr "mode")
1409      (cond [(match_operand:SF 1 "" "")
1410               (const_string "SF")
1411             (match_operand:DF 1 "" "")
1412               (const_string "DF")
1413            ]
1414            (const_string "XF")))])
1415
1416 (define_insn "*cmpfp_<mode>"
1417   [(set (match_operand:HI 0 "register_operand" "=a")
1418         (unspec:HI
1419           [(compare:CCFP
1420              (match_operand 1 "register_operand" "f")
1421              (match_operator 3 "float_operator"
1422                [(match_operand:SWI24 2 "memory_operand" "m")]))]
1423           UNSPEC_FNSTSW))]
1424   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1425    && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))
1426    && (GET_MODE (operands [3]) == GET_MODE (operands[1]))"
1427   "* return output_fp_compare (insn, operands, false, false);"
1428   [(set_attr "type" "multi")
1429    (set_attr "unit" "i387")
1430    (set_attr "fp_int_src" "true")
1431    (set_attr "mode" "<MODE>")])
1432
1433 (define_insn_and_split "*cmpfp_<mode>_cc"
1434   [(set (reg:CCFP FLAGS_REG)
1435         (compare:CCFP
1436           (match_operand 1 "register_operand" "f")
1437           (match_operator 3 "float_operator"
1438             [(match_operand:SWI24 2 "memory_operand" "m")])))
1439    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1440   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1441    && TARGET_SAHF && !TARGET_CMOVE
1442    && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))
1443    && (GET_MODE (operands [3]) == GET_MODE (operands[1]))"
1444   "#"
1445   "&& reload_completed"
1446   [(set (match_dup 0)
1447         (unspec:HI
1448           [(compare:CCFP
1449              (match_dup 1)
1450              (match_op_dup 3 [(match_dup 2)]))]
1451         UNSPEC_FNSTSW))
1452    (set (reg:CC FLAGS_REG)
1453         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1454   ""
1455   [(set_attr "type" "multi")
1456    (set_attr "unit" "i387")
1457    (set_attr "fp_int_src" "true")
1458    (set_attr "mode" "<MODE>")])
1459
1460 ;; FP compares, step 2
1461 ;; Move the fpsw to ax.
1462
1463 (define_insn "x86_fnstsw_1"
1464   [(set (match_operand:HI 0 "register_operand" "=a")
1465         (unspec:HI [(reg:CCFP FPSR_REG)] UNSPEC_FNSTSW))]
1466   "TARGET_80387"
1467   "fnstsw\t%0"
1468   [(set (attr "length") (symbol_ref "ix86_attr_length_address_default (insn) + 2"))
1469    (set_attr "mode" "SI")
1470    (set_attr "unit" "i387")])
1471
1472 ;; FP compares, step 3
1473 ;; Get ax into flags, general case.
1474
1475 (define_insn "x86_sahf_1"
1476   [(set (reg:CC FLAGS_REG)
1477         (unspec:CC [(match_operand:HI 0 "register_operand" "a")]
1478                    UNSPEC_SAHF))]
1479   "TARGET_SAHF"
1480 {
1481 #ifndef HAVE_AS_IX86_SAHF
1482   if (TARGET_64BIT)
1483     return ASM_BYTE "0x9e";
1484   else
1485 #endif
1486   return "sahf";
1487 }
1488   [(set_attr "length" "1")
1489    (set_attr "athlon_decode" "vector")
1490    (set_attr "amdfam10_decode" "direct")
1491    (set_attr "bdver1_decode" "direct")
1492    (set_attr "mode" "SI")])
1493
1494 ;; Pentium Pro can do steps 1 through 3 in one go.
1495 ;; comi*, ucomi*, fcomi*, ficomi*,fucomi* (i387 instructions set condition codes)
1496 (define_insn "*cmpfp_i_mixed"
1497   [(set (reg:CCFP FLAGS_REG)
1498         (compare:CCFP (match_operand 0 "register_operand" "f,x")
1499                       (match_operand 1 "nonimmediate_operand" "f,xm")))]
1500   "TARGET_MIX_SSE_I387
1501    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1502    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1503   "* return output_fp_compare (insn, operands, true, false);"
1504   [(set_attr "type" "fcmp,ssecomi")
1505    (set_attr "prefix" "orig,maybe_vex")
1506    (set (attr "mode")
1507      (if_then_else (match_operand:SF 1 "" "")
1508         (const_string "SF")
1509         (const_string "DF")))
1510    (set (attr "prefix_rep")
1511         (if_then_else (eq_attr "type" "ssecomi")
1512                       (const_string "0")
1513                       (const_string "*")))
1514    (set (attr "prefix_data16")
1515         (cond [(eq_attr "type" "fcmp")
1516                  (const_string "*")
1517                (eq_attr "mode" "DF")
1518                  (const_string "1")
1519               ]
1520               (const_string "0")))
1521    (set_attr "athlon_decode" "vector")
1522    (set_attr "amdfam10_decode" "direct")
1523    (set_attr "bdver1_decode" "double")])
1524
1525 (define_insn "*cmpfp_i_sse"
1526   [(set (reg:CCFP FLAGS_REG)
1527         (compare:CCFP (match_operand 0 "register_operand" "x")
1528                       (match_operand 1 "nonimmediate_operand" "xm")))]
1529   "TARGET_SSE_MATH
1530    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1531    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1532   "* return output_fp_compare (insn, operands, true, false);"
1533   [(set_attr "type" "ssecomi")
1534    (set_attr "prefix" "maybe_vex")
1535    (set (attr "mode")
1536      (if_then_else (match_operand:SF 1 "" "")
1537         (const_string "SF")
1538         (const_string "DF")))
1539    (set_attr "prefix_rep" "0")
1540    (set (attr "prefix_data16")
1541         (if_then_else (eq_attr "mode" "DF")
1542                       (const_string "1")
1543                       (const_string "0")))
1544    (set_attr "athlon_decode" "vector")
1545    (set_attr "amdfam10_decode" "direct")
1546    (set_attr "bdver1_decode" "double")])
1547
1548 (define_insn "*cmpfp_i_i387"
1549   [(set (reg:CCFP FLAGS_REG)
1550         (compare:CCFP (match_operand 0 "register_operand" "f")
1551                       (match_operand 1 "register_operand" "f")))]
1552   "X87_FLOAT_MODE_P (GET_MODE (operands[0]))
1553    && TARGET_CMOVE
1554    && !(SSE_FLOAT_MODE_P (GET_MODE (operands[0])) && TARGET_SSE_MATH)
1555    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1556   "* return output_fp_compare (insn, operands, true, false);"
1557   [(set_attr "type" "fcmp")
1558    (set (attr "mode")
1559      (cond [(match_operand:SF 1 "" "")
1560               (const_string "SF")
1561             (match_operand:DF 1 "" "")
1562               (const_string "DF")
1563            ]
1564            (const_string "XF")))
1565    (set_attr "athlon_decode" "vector")
1566    (set_attr "amdfam10_decode" "direct")
1567    (set_attr "bdver1_decode" "double")])
1568
1569 (define_insn "*cmpfp_iu_mixed"
1570   [(set (reg:CCFPU FLAGS_REG)
1571         (compare:CCFPU (match_operand 0 "register_operand" "f,x")
1572                        (match_operand 1 "nonimmediate_operand" "f,xm")))]
1573   "TARGET_MIX_SSE_I387
1574    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1575    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1576   "* return output_fp_compare (insn, operands, true, true);"
1577   [(set_attr "type" "fcmp,ssecomi")
1578    (set_attr "prefix" "orig,maybe_vex")
1579    (set (attr "mode")
1580      (if_then_else (match_operand:SF 1 "" "")
1581         (const_string "SF")
1582         (const_string "DF")))
1583    (set (attr "prefix_rep")
1584         (if_then_else (eq_attr "type" "ssecomi")
1585                       (const_string "0")
1586                       (const_string "*")))
1587    (set (attr "prefix_data16")
1588         (cond [(eq_attr "type" "fcmp")
1589                  (const_string "*")
1590                (eq_attr "mode" "DF")
1591                  (const_string "1")
1592               ]
1593               (const_string "0")))
1594    (set_attr "athlon_decode" "vector")
1595    (set_attr "amdfam10_decode" "direct")
1596    (set_attr "bdver1_decode" "double")])
1597
1598 (define_insn "*cmpfp_iu_sse"
1599   [(set (reg:CCFPU FLAGS_REG)
1600         (compare:CCFPU (match_operand 0 "register_operand" "x")
1601                        (match_operand 1 "nonimmediate_operand" "xm")))]
1602   "TARGET_SSE_MATH
1603    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1604    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1605   "* return output_fp_compare (insn, operands, true, true);"
1606   [(set_attr "type" "ssecomi")
1607    (set_attr "prefix" "maybe_vex")
1608    (set (attr "mode")
1609      (if_then_else (match_operand:SF 1 "" "")
1610         (const_string "SF")
1611         (const_string "DF")))
1612    (set_attr "prefix_rep" "0")
1613    (set (attr "prefix_data16")
1614         (if_then_else (eq_attr "mode" "DF")
1615                       (const_string "1")
1616                       (const_string "0")))
1617    (set_attr "athlon_decode" "vector")
1618    (set_attr "amdfam10_decode" "direct")
1619    (set_attr "bdver1_decode" "double")])
1620
1621 (define_insn "*cmpfp_iu_387"
1622   [(set (reg:CCFPU FLAGS_REG)
1623         (compare:CCFPU (match_operand 0 "register_operand" "f")
1624                        (match_operand 1 "register_operand" "f")))]
1625   "X87_FLOAT_MODE_P (GET_MODE (operands[0]))
1626    && TARGET_CMOVE
1627    && !(SSE_FLOAT_MODE_P (GET_MODE (operands[0])) && TARGET_SSE_MATH)
1628    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1629   "* return output_fp_compare (insn, operands, true, true);"
1630   [(set_attr "type" "fcmp")
1631    (set (attr "mode")
1632      (cond [(match_operand:SF 1 "" "")
1633               (const_string "SF")
1634             (match_operand:DF 1 "" "")
1635               (const_string "DF")
1636            ]
1637            (const_string "XF")))
1638    (set_attr "athlon_decode" "vector")
1639    (set_attr "amdfam10_decode" "direct")
1640    (set_attr "bdver1_decode" "direct")])
1641 \f
1642 ;; Push/pop instructions.
1643
1644 (define_insn "*push<mode>2"
1645   [(set (match_operand:DWI 0 "push_operand" "=<")
1646         (match_operand:DWI 1 "general_no_elim_operand" "riF*m"))]
1647   ""
1648   "#")
1649
1650 (define_split
1651   [(set (match_operand:TI 0 "push_operand" "")
1652         (match_operand:TI 1 "general_operand" ""))]
1653   "TARGET_64BIT && reload_completed
1654    && !SSE_REG_P (operands[1])"
1655   [(const_int 0)]
1656   "ix86_split_long_move (operands); DONE;")
1657
1658 (define_insn "*pushdi2_rex64"
1659   [(set (match_operand:DI 0 "push_operand" "=<,!<")
1660         (match_operand:DI 1 "general_no_elim_operand" "re*m,n"))]
1661   "TARGET_64BIT"
1662   "@
1663    push{q}\t%1
1664    #"
1665   [(set_attr "type" "push,multi")
1666    (set_attr "mode" "DI")])
1667
1668 ;; Convert impossible pushes of immediate to existing instructions.
1669 ;; First try to get scratch register and go through it.  In case this
1670 ;; fails, push sign extended lower part first and then overwrite
1671 ;; upper part by 32bit move.
1672 (define_peephole2
1673   [(match_scratch:DI 2 "r")
1674    (set (match_operand:DI 0 "push_operand" "")
1675         (match_operand:DI 1 "immediate_operand" ""))]
1676   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
1677    && !x86_64_immediate_operand (operands[1], DImode)"
1678   [(set (match_dup 2) (match_dup 1))
1679    (set (match_dup 0) (match_dup 2))])
1680
1681 ;; We need to define this as both peepholer and splitter for case
1682 ;; peephole2 pass is not run.
1683 ;; "&& 1" is needed to keep it from matching the previous pattern.
1684 (define_peephole2
1685   [(set (match_operand:DI 0 "push_operand" "")
1686         (match_operand:DI 1 "immediate_operand" ""))]
1687   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
1688    && !x86_64_immediate_operand (operands[1], DImode) && 1"
1689   [(set (match_dup 0) (match_dup 1))
1690    (set (match_dup 2) (match_dup 3))]
1691 {
1692   split_double_mode (DImode, &operands[1], 1, &operands[2], &operands[3]);
1693
1694   operands[1] = gen_lowpart (DImode, operands[2]);
1695   operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (DImode, stack_pointer_rtx,
1696                                                    GEN_INT (4)));
1697 })
1698
1699 (define_split
1700   [(set (match_operand:DI 0 "push_operand" "")
1701         (match_operand:DI 1 "immediate_operand" ""))]
1702   "TARGET_64BIT && ((optimize > 0 && flag_peephole2)
1703                     ? epilogue_completed : reload_completed)
1704    && !symbolic_operand (operands[1], DImode)
1705    && !x86_64_immediate_operand (operands[1], DImode)"
1706   [(set (match_dup 0) (match_dup 1))
1707    (set (match_dup 2) (match_dup 3))]
1708 {
1709   split_double_mode (DImode, &operands[1], 1, &operands[2], &operands[3]);
1710
1711   operands[1] = gen_lowpart (DImode, operands[2]);
1712   operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (DImode, stack_pointer_rtx,
1713                                                    GEN_INT (4)));
1714 })
1715
1716 (define_split
1717   [(set (match_operand:DI 0 "push_operand" "")
1718         (match_operand:DI 1 "general_operand" ""))]
1719   "!TARGET_64BIT && reload_completed
1720    && !(MMX_REG_P (operands[1]) || SSE_REG_P (operands[1]))"
1721   [(const_int 0)]
1722   "ix86_split_long_move (operands); DONE;")
1723
1724 (define_insn "*pushsi2"
1725   [(set (match_operand:SI 0 "push_operand" "=<")
1726         (match_operand:SI 1 "general_no_elim_operand" "ri*m"))]
1727   "!TARGET_64BIT"
1728   "push{l}\t%1"
1729   [(set_attr "type" "push")
1730    (set_attr "mode" "SI")])
1731
1732 ;; emit_push_insn when it calls move_by_pieces requires an insn to
1733 ;; "push a byte/word".  But actually we use pushl, which has the effect
1734 ;; of rounding the amount pushed up to a word.
1735
1736 ;; For TARGET_64BIT we always round up to 8 bytes.
1737 (define_insn "*push<mode>2_rex64"
1738   [(set (match_operand:SWI124 0 "push_operand" "=X")
1739         (match_operand:SWI124 1 "nonmemory_no_elim_operand" "r<i>"))]
1740   "TARGET_64BIT"
1741   "push{q}\t%q1"
1742   [(set_attr "type" "push")
1743    (set_attr "mode" "DI")])
1744
1745 (define_insn "*push<mode>2"
1746   [(set (match_operand:SWI12 0 "push_operand" "=X")
1747         (match_operand:SWI12 1 "nonmemory_no_elim_operand" "rn"))]
1748   "!TARGET_64BIT"
1749   "push{l}\t%k1"
1750   [(set_attr "type" "push")
1751    (set_attr "mode" "SI")])
1752
1753 (define_insn "*push<mode>2_prologue"
1754   [(set (match_operand:P 0 "push_operand" "=<")
1755         (match_operand:P 1 "general_no_elim_operand" "r<i>*m"))
1756    (clobber (mem:BLK (scratch)))]
1757   ""
1758   "push{<imodesuffix>}\t%1"
1759   [(set_attr "type" "push")
1760    (set_attr "mode" "<MODE>")])
1761
1762 (define_insn "*pop<mode>1"
1763   [(set (match_operand:P 0 "nonimmediate_operand" "=r*m")
1764         (match_operand:P 1 "pop_operand" ">"))]
1765   ""
1766   "pop{<imodesuffix>}\t%0"
1767   [(set_attr "type" "pop")
1768    (set_attr "mode" "<MODE>")])
1769
1770 (define_insn "*pop<mode>1_epilogue"
1771   [(set (match_operand:P 0 "nonimmediate_operand" "=r*m")
1772         (match_operand:P 1 "pop_operand" ">"))
1773    (clobber (mem:BLK (scratch)))]
1774   ""
1775   "pop{<imodesuffix>}\t%0"
1776   [(set_attr "type" "pop")
1777    (set_attr "mode" "<MODE>")])
1778 \f
1779 ;; Move instructions.
1780
1781 (define_expand "movoi"
1782   [(set (match_operand:OI 0 "nonimmediate_operand" "")
1783         (match_operand:OI 1 "general_operand" ""))]
1784   "TARGET_AVX"
1785   "ix86_expand_move (OImode, operands); DONE;")
1786
1787 (define_expand "movti"
1788   [(set (match_operand:TI 0 "nonimmediate_operand" "")
1789         (match_operand:TI 1 "nonimmediate_operand" ""))]
1790   "TARGET_64BIT || TARGET_SSE"
1791 {
1792   if (TARGET_64BIT)
1793     ix86_expand_move (TImode, operands);
1794   else if (push_operand (operands[0], TImode))
1795     ix86_expand_push (TImode, operands[1]);
1796   else
1797     ix86_expand_vector_move (TImode, operands);
1798   DONE;
1799 })
1800
1801 ;; This expands to what emit_move_complex would generate if we didn't
1802 ;; have a movti pattern.  Having this avoids problems with reload on
1803 ;; 32-bit targets when SSE is present, but doesn't seem to be harmful
1804 ;; to have around all the time.
1805 (define_expand "movcdi"
1806   [(set (match_operand:CDI 0 "nonimmediate_operand" "")
1807         (match_operand:CDI 1 "general_operand" ""))]
1808   ""
1809 {
1810   if (push_operand (operands[0], CDImode))
1811     emit_move_complex_push (CDImode, operands[0], operands[1]);
1812   else
1813     emit_move_complex_parts (operands[0], operands[1]);
1814   DONE;
1815 })
1816
1817 (define_expand "mov<mode>"
1818   [(set (match_operand:SWI1248x 0 "nonimmediate_operand" "")
1819         (match_operand:SWI1248x 1 "general_operand" ""))]
1820   ""
1821   "ix86_expand_move (<MODE>mode, operands); DONE;")
1822
1823 (define_insn "*mov<mode>_xor"
1824   [(set (match_operand:SWI48 0 "register_operand" "=r")
1825         (match_operand:SWI48 1 "const0_operand" ""))
1826    (clobber (reg:CC FLAGS_REG))]
1827   "reload_completed"
1828   "xor{l}\t%k0, %k0"
1829   [(set_attr "type" "alu1")
1830    (set_attr "mode" "SI")
1831    (set_attr "length_immediate" "0")])
1832
1833 (define_insn "*mov<mode>_or"
1834   [(set (match_operand:SWI48 0 "register_operand" "=r")
1835         (match_operand:SWI48 1 "const_int_operand" ""))
1836    (clobber (reg:CC FLAGS_REG))]
1837   "reload_completed
1838    && operands[1] == constm1_rtx"
1839   "or{<imodesuffix>}\t{%1, %0|%0, %1}"
1840   [(set_attr "type" "alu1")
1841    (set_attr "mode" "<MODE>")
1842    (set_attr "length_immediate" "1")])
1843
1844 (define_insn "*movoi_internal_avx"
1845   [(set (match_operand:OI 0 "nonimmediate_operand" "=x,x,m")
1846         (match_operand:OI 1 "vector_move_operand" "C,xm,x"))]
1847   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1848 {
1849   switch (which_alternative)
1850     {
1851     case 0:
1852       return standard_sse_constant_opcode (insn, operands[1]);
1853     case 1:
1854     case 2:
1855       if (misaligned_operand (operands[0], OImode)
1856           || misaligned_operand (operands[1], OImode))
1857         return "vmovdqu\t{%1, %0|%0, %1}";
1858       else
1859         return "vmovdqa\t{%1, %0|%0, %1}";
1860     default:
1861       gcc_unreachable ();
1862     }
1863 }
1864   [(set_attr "type" "sselog1,ssemov,ssemov")
1865    (set_attr "prefix" "vex")
1866    (set_attr "mode" "OI")])
1867
1868 (define_insn "*movti_internal_rex64"
1869   [(set (match_operand:TI 0 "nonimmediate_operand" "=!r,o,x,x,xm")
1870         (match_operand:TI 1 "general_operand" "riFo,riF,C,xm,x"))]
1871   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1872 {
1873   switch (which_alternative)
1874     {
1875     case 0:
1876     case 1:
1877       return "#";
1878     case 2:
1879       return standard_sse_constant_opcode (insn, operands[1]);
1880     case 3:
1881     case 4:
1882       /* TDmode values are passed as TImode on the stack.  Moving them
1883          to stack may result in unaligned memory access.  */
1884       if (misaligned_operand (operands[0], TImode)
1885           || misaligned_operand (operands[1], TImode))
1886         {
1887           if (get_attr_mode (insn) == MODE_V4SF)
1888             return "%vmovups\t{%1, %0|%0, %1}";
1889           else
1890             return "%vmovdqu\t{%1, %0|%0, %1}";
1891         }
1892       else
1893         {
1894           if (get_attr_mode (insn) == MODE_V4SF)
1895             return "%vmovaps\t{%1, %0|%0, %1}";
1896           else
1897             return "%vmovdqa\t{%1, %0|%0, %1}";
1898         }
1899     default:
1900       gcc_unreachable ();
1901     }
1902 }
1903   [(set_attr "type" "*,*,sselog1,ssemov,ssemov")
1904    (set_attr "prefix" "*,*,maybe_vex,maybe_vex,maybe_vex")
1905    (set (attr "mode")
1906         (cond [(eq_attr "alternative" "2,3")
1907                  (if_then_else
1908                    (ne (symbol_ref "optimize_function_for_size_p (cfun)")
1909                        (const_int 0))
1910                    (const_string "V4SF")
1911                    (const_string "TI"))
1912                (eq_attr "alternative" "4")
1913                  (if_then_else
1914                    (ior (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
1915                             (const_int 0))
1916                         (ne (symbol_ref "optimize_function_for_size_p (cfun)")
1917                             (const_int 0)))
1918                    (const_string "V4SF")
1919                    (const_string "TI"))]
1920                (const_string "DI")))])
1921
1922 (define_split
1923   [(set (match_operand:TI 0 "nonimmediate_operand" "")
1924         (match_operand:TI 1 "general_operand" ""))]
1925   "reload_completed
1926    && !SSE_REG_P (operands[0]) && !SSE_REG_P (operands[1])"
1927   [(const_int 0)]
1928   "ix86_split_long_move (operands); DONE;")
1929
1930 (define_insn "*movti_internal_sse"
1931   [(set (match_operand:TI 0 "nonimmediate_operand" "=x,x,m")
1932         (match_operand:TI 1 "vector_move_operand" "C,xm,x"))]
1933   "TARGET_SSE && !TARGET_64BIT
1934    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1935 {
1936   switch (which_alternative)
1937     {
1938     case 0:
1939       return standard_sse_constant_opcode (insn, operands[1]);
1940     case 1:
1941     case 2:
1942       /* TDmode values are passed as TImode on the stack.  Moving them
1943          to stack may result in unaligned memory access.  */
1944       if (misaligned_operand (operands[0], TImode)
1945           || misaligned_operand (operands[1], TImode))
1946         {
1947           if (get_attr_mode (insn) == MODE_V4SF)
1948             return "%vmovups\t{%1, %0|%0, %1}";
1949           else
1950             return "%vmovdqu\t{%1, %0|%0, %1}";
1951         }
1952       else
1953         {
1954           if (get_attr_mode (insn) == MODE_V4SF)
1955             return "%vmovaps\t{%1, %0|%0, %1}";
1956           else
1957             return "%vmovdqa\t{%1, %0|%0, %1}";
1958         }
1959     default:
1960       gcc_unreachable ();
1961     }
1962 }
1963   [(set_attr "type" "sselog1,ssemov,ssemov")
1964    (set_attr "prefix" "maybe_vex")
1965    (set (attr "mode")
1966         (cond [(ior (eq (symbol_ref "TARGET_SSE2") (const_int 0))
1967                     (ne (symbol_ref "optimize_function_for_size_p (cfun)")
1968                         (const_int 0)))
1969                  (const_string "V4SF")
1970                (and (eq_attr "alternative" "2")
1971                     (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
1972                         (const_int 0)))
1973                  (const_string "V4SF")]
1974               (const_string "TI")))])
1975
1976 (define_insn "*movdi_internal_rex64"
1977   [(set (match_operand:DI 0 "nonimmediate_operand"
1978           "=r,r  ,r,m ,!m,*y,m*y,?*y,?r ,?*Ym,*x,m ,*x,*x,?r ,?*Yi,?*x,?*Ym")
1979         (match_operand:DI 1 "general_operand"
1980           "Z ,rem,i,re,n ,C ,*y ,m  ,*Ym,r   ,C ,*x,*x,m ,*Yi,r   ,*Ym,*x"))]
1981   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1982 {
1983   switch (get_attr_type (insn))
1984     {
1985     case TYPE_SSECVT:
1986       if (SSE_REG_P (operands[0]))
1987         return "movq2dq\t{%1, %0|%0, %1}";
1988       else
1989         return "movdq2q\t{%1, %0|%0, %1}";
1990
1991     case TYPE_SSEMOV:
1992       if (get_attr_mode (insn) == MODE_TI)
1993         return "%vmovdqa\t{%1, %0|%0, %1}";
1994       /* Handle broken assemblers that require movd instead of movq.  */
1995       if (GENERAL_REG_P (operands[0]) || GENERAL_REG_P (operands[1]))
1996         return "%vmovd\t{%1, %0|%0, %1}";
1997       else
1998         return "%vmovq\t{%1, %0|%0, %1}";
1999
2000     case TYPE_MMXMOV:
2001       /* Handle broken assemblers that require movd instead of movq.  */
2002       if (GENERAL_REG_P (operands[0]) || GENERAL_REG_P (operands[1]))
2003         return "movd\t{%1, %0|%0, %1}";
2004       else
2005         return "movq\t{%1, %0|%0, %1}";
2006
2007     case TYPE_SSELOG1:
2008       return standard_sse_constant_opcode (insn, operands[1]);
2009
2010     case TYPE_MMX:
2011       return "pxor\t%0, %0";
2012
2013     case TYPE_MULTI:
2014       return "#";
2015
2016     case TYPE_LEA:
2017       return "lea{q}\t{%a1, %0|%0, %a1}";
2018
2019     default:
2020       gcc_assert (!flag_pic || LEGITIMATE_PIC_OPERAND_P (operands[1]));
2021       if (get_attr_mode (insn) == MODE_SI)
2022         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2023       else if (which_alternative == 2)
2024         return "movabs{q}\t{%1, %0|%0, %1}";
2025       else
2026         return "mov{q}\t{%1, %0|%0, %1}";
2027     }
2028 }
2029   [(set (attr "type")
2030      (cond [(eq_attr "alternative" "4")
2031               (const_string "multi")
2032             (eq_attr "alternative" "5")
2033               (const_string "mmx")
2034             (eq_attr "alternative" "6,7,8,9")
2035               (const_string "mmxmov")
2036             (eq_attr "alternative" "10")
2037               (const_string "sselog1")
2038             (eq_attr "alternative" "11,12,13,14,15")
2039               (const_string "ssemov")
2040             (eq_attr "alternative" "16,17")
2041               (const_string "ssecvt")
2042             (match_operand 1 "pic_32bit_operand" "")
2043               (const_string "lea")
2044            ]
2045            (const_string "imov")))
2046    (set (attr "modrm")
2047      (if_then_else
2048        (and (eq_attr "alternative" "2") (eq_attr "type" "imov"))
2049          (const_string "0")
2050          (const_string "*")))
2051    (set (attr "length_immediate")
2052      (if_then_else
2053        (and (eq_attr "alternative" "2") (eq_attr "type" "imov"))
2054          (const_string "8")
2055          (const_string "*")))
2056    (set (attr "prefix_rex")
2057      (if_then_else (eq_attr "alternative" "8,9")
2058        (const_string "1")
2059        (const_string "*")))
2060    (set (attr "prefix_data16")
2061      (if_then_else (eq_attr "alternative" "11")
2062        (const_string "1")
2063        (const_string "*")))
2064    (set (attr "prefix")
2065      (if_then_else (eq_attr "alternative" "10,11,12,13,14,15")
2066        (const_string "maybe_vex")
2067        (const_string "orig")))
2068    (set_attr "mode" "SI,DI,DI,DI,SI,DI,DI,DI,DI,DI,TI,DI,TI,DI,DI,DI,DI,DI")])
2069
2070 ;; Convert impossible stores of immediate to existing instructions.
2071 ;; First try to get scratch register and go through it.  In case this
2072 ;; fails, move by 32bit parts.
2073 (define_peephole2
2074   [(match_scratch:DI 2 "r")
2075    (set (match_operand:DI 0 "memory_operand" "")
2076         (match_operand:DI 1 "immediate_operand" ""))]
2077   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2078    && !x86_64_immediate_operand (operands[1], DImode)"
2079   [(set (match_dup 2) (match_dup 1))
2080    (set (match_dup 0) (match_dup 2))])
2081
2082 ;; We need to define this as both peepholer and splitter for case
2083 ;; peephole2 pass is not run.
2084 ;; "&& 1" is needed to keep it from matching the previous pattern.
2085 (define_peephole2
2086   [(set (match_operand:DI 0 "memory_operand" "")
2087         (match_operand:DI 1 "immediate_operand" ""))]
2088   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2089    && !x86_64_immediate_operand (operands[1], DImode) && 1"
2090   [(set (match_dup 2) (match_dup 3))
2091    (set (match_dup 4) (match_dup 5))]
2092   "split_double_mode (DImode, &operands[0], 2, &operands[2], &operands[4]);")
2093
2094 (define_split
2095   [(set (match_operand:DI 0 "memory_operand" "")
2096         (match_operand:DI 1 "immediate_operand" ""))]
2097   "TARGET_64BIT && ((optimize > 0 && flag_peephole2)
2098                     ? epilogue_completed : reload_completed)
2099    && !symbolic_operand (operands[1], DImode)
2100    && !x86_64_immediate_operand (operands[1], DImode)"
2101   [(set (match_dup 2) (match_dup 3))
2102    (set (match_dup 4) (match_dup 5))]
2103   "split_double_mode (DImode, &operands[0], 2, &operands[2], &operands[4]);")
2104
2105 (define_insn "*movdi_internal"
2106   [(set (match_operand:DI 0 "nonimmediate_operand"
2107           "=r  ,o  ,*y,m*y,*y,*Y2,m  ,*Y2,*Y2,*x,m ,*x,*x,?*Y2,?*Ym")
2108         (match_operand:DI 1 "general_operand"
2109           "riFo,riF,C ,*y ,m ,C  ,*Y2,*Y2,m  ,C ,*x,*x,m ,*Ym ,*Y2"))]
2110   "!TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2111 {
2112   switch (get_attr_type (insn))
2113     {
2114     case TYPE_SSECVT:
2115       if (SSE_REG_P (operands[0]))
2116         return "movq2dq\t{%1, %0|%0, %1}";
2117       else
2118         return "movdq2q\t{%1, %0|%0, %1}";
2119
2120     case TYPE_SSEMOV:
2121       switch (get_attr_mode (insn))
2122         {
2123         case MODE_TI:
2124           return "%vmovdqa\t{%1, %0|%0, %1}";
2125         case MODE_DI:
2126            return "%vmovq\t{%1, %0|%0, %1}";
2127         case MODE_V4SF:
2128           return "movaps\t{%1, %0|%0, %1}";
2129         case MODE_V2SF:
2130           return "movlps\t{%1, %0|%0, %1}";
2131         default:
2132           gcc_unreachable ();
2133         }
2134
2135     case TYPE_MMXMOV:
2136       return "movq\t{%1, %0|%0, %1}";
2137
2138     case TYPE_SSELOG1:
2139       return standard_sse_constant_opcode (insn, operands[1]);
2140
2141     case TYPE_MMX:
2142       return "pxor\t%0, %0";
2143
2144     case TYPE_MULTI:
2145       return "#";
2146
2147     default:
2148       gcc_unreachable ();
2149     }
2150 }
2151   [(set (attr "isa")
2152      (if_then_else (eq_attr "alternative" "9,10,11,12")
2153        (const_string "noavx")
2154        (const_string "*")))
2155    (set (attr "type")
2156      (cond [(eq_attr "alternative" "0,1")
2157               (const_string "multi")
2158             (eq_attr "alternative" "2")
2159               (const_string "mmx")
2160             (eq_attr "alternative" "3,4")
2161               (const_string "mmxmov")
2162             (eq_attr "alternative" "5,9")
2163               (const_string "sselog1")
2164             (eq_attr "alternative" "13,14")
2165               (const_string "ssecvt")
2166            ]
2167            (const_string "ssemov")))
2168    (set (attr "prefix")
2169      (if_then_else (eq_attr "alternative" "5,6,7,8")
2170        (const_string "maybe_vex")
2171        (const_string "orig")))
2172    (set_attr "mode" "DI,DI,DI,DI,DI,TI,DI,TI,DI,V4SF,V2SF,V4SF,V2SF,DI,DI")])
2173
2174 (define_split
2175   [(set (match_operand:DI 0 "nonimmediate_operand" "")
2176         (match_operand:DI 1 "general_operand" ""))]
2177   "!TARGET_64BIT && reload_completed
2178    && !(MMX_REG_P (operands[0]) || SSE_REG_P (operands[0]))
2179    && !(MMX_REG_P (operands[1]) || SSE_REG_P (operands[1]))"
2180   [(const_int 0)]
2181   "ix86_split_long_move (operands); DONE;")
2182
2183 (define_insn "*movsi_internal"
2184   [(set (match_operand:SI 0 "nonimmediate_operand"
2185                         "=r,m ,*y,*y,?rm,?*y,*x,*x,?r ,m ,?*Yi,*x")
2186         (match_operand:SI 1 "general_operand"
2187                         "g ,re,C ,*y,*y ,rm ,C ,*x,*Yi,*x,r   ,m "))]
2188   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2189 {
2190   switch (get_attr_type (insn))
2191     {
2192     case TYPE_SSELOG1:
2193       return standard_sse_constant_opcode (insn, operands[1]);
2194
2195     case TYPE_SSEMOV:
2196       switch (get_attr_mode (insn))
2197         {
2198         case MODE_TI:
2199           return "%vmovdqa\t{%1, %0|%0, %1}";
2200         case MODE_V4SF:
2201           return "%vmovaps\t{%1, %0|%0, %1}";
2202         case MODE_SI:
2203           return "%vmovd\t{%1, %0|%0, %1}";
2204         case MODE_SF:
2205           return "%vmovss\t{%1, %0|%0, %1}";
2206         default:
2207           gcc_unreachable ();
2208         }
2209
2210     case TYPE_MMX:
2211       return "pxor\t%0, %0";
2212
2213     case TYPE_MMXMOV:
2214       if (get_attr_mode (insn) == MODE_DI)
2215         return "movq\t{%1, %0|%0, %1}";
2216       return "movd\t{%1, %0|%0, %1}";
2217
2218     case TYPE_LEA:
2219       return "lea{l}\t{%a1, %0|%0, %a1}";
2220
2221     default:
2222       gcc_assert (!flag_pic || LEGITIMATE_PIC_OPERAND_P (operands[1]));
2223       return "mov{l}\t{%1, %0|%0, %1}";
2224     }
2225 }
2226   [(set (attr "type")
2227      (cond [(eq_attr "alternative" "2")
2228               (const_string "mmx")
2229             (eq_attr "alternative" "3,4,5")
2230               (const_string "mmxmov")
2231             (eq_attr "alternative" "6")
2232               (const_string "sselog1")
2233             (eq_attr "alternative" "7,8,9,10,11")
2234               (const_string "ssemov")
2235             (match_operand 1 "pic_32bit_operand" "")
2236               (const_string "lea")
2237            ]
2238            (const_string "imov")))
2239    (set (attr "prefix")
2240      (if_then_else (eq_attr "alternative" "0,1,2,3,4,5")
2241        (const_string "orig")
2242        (const_string "maybe_vex")))
2243    (set (attr "prefix_data16")
2244      (if_then_else (and (eq_attr "type" "ssemov") (eq_attr "mode" "SI"))
2245        (const_string "1")
2246        (const_string "*")))
2247    (set (attr "mode")
2248      (cond [(eq_attr "alternative" "2,3")
2249               (const_string "DI")
2250             (eq_attr "alternative" "6,7")
2251               (if_then_else
2252                 (eq (symbol_ref "TARGET_SSE2") (const_int 0))
2253                 (const_string "V4SF")
2254                 (const_string "TI"))
2255             (and (eq_attr "alternative" "8,9,10,11")
2256                  (eq (symbol_ref "TARGET_SSE2") (const_int 0)))
2257               (const_string "SF")
2258            ]
2259            (const_string "SI")))])
2260
2261 (define_insn "*movhi_internal"
2262   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,r,m")
2263         (match_operand:HI 1 "general_operand" "r,rn,rm,rn"))]
2264   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2265 {
2266   switch (get_attr_type (insn))
2267     {
2268     case TYPE_IMOVX:
2269       /* movzwl is faster than movw on p2 due to partial word stalls,
2270          though not as fast as an aligned movl.  */
2271       return "movz{wl|x}\t{%1, %k0|%k0, %1}";
2272     default:
2273       if (get_attr_mode (insn) == MODE_SI)
2274         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2275       else
2276         return "mov{w}\t{%1, %0|%0, %1}";
2277     }
2278 }
2279   [(set (attr "type")
2280      (cond [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
2281                 (const_int 0))
2282               (const_string "imov")
2283             (and (eq_attr "alternative" "0")
2284                  (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2285                           (const_int 0))
2286                       (eq (symbol_ref "TARGET_HIMODE_MATH")
2287                           (const_int 0))))
2288               (const_string "imov")
2289             (and (eq_attr "alternative" "1,2")
2290                  (match_operand:HI 1 "aligned_operand" ""))
2291               (const_string "imov")
2292             (and (ne (symbol_ref "TARGET_MOVX")
2293                      (const_int 0))
2294                  (eq_attr "alternative" "0,2"))
2295               (const_string "imovx")
2296            ]
2297            (const_string "imov")))
2298     (set (attr "mode")
2299       (cond [(eq_attr "type" "imovx")
2300                (const_string "SI")
2301              (and (eq_attr "alternative" "1,2")
2302                   (match_operand:HI 1 "aligned_operand" ""))
2303                (const_string "SI")
2304              (and (eq_attr "alternative" "0")
2305                   (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2306                            (const_int 0))
2307                        (eq (symbol_ref "TARGET_HIMODE_MATH")
2308                            (const_int 0))))
2309                (const_string "SI")
2310             ]
2311             (const_string "HI")))])
2312
2313 ;; Situation is quite tricky about when to choose full sized (SImode) move
2314 ;; over QImode moves.  For Q_REG -> Q_REG move we use full size only for
2315 ;; partial register dependency machines (such as AMD Athlon), where QImode
2316 ;; moves issue extra dependency and for partial register stalls machines
2317 ;; that don't use QImode patterns (and QImode move cause stall on the next
2318 ;; instruction).
2319 ;;
2320 ;; For loads of Q_REG to NONQ_REG we use full sized moves except for partial
2321 ;; register stall machines with, where we use QImode instructions, since
2322 ;; partial register stall can be caused there.  Then we use movzx.
2323 (define_insn "*movqi_internal"
2324   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,q ,q ,r,r ,?r,m")
2325         (match_operand:QI 1 "general_operand"      " q,qn,qm,q,rn,qm,qn"))]
2326   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2327 {
2328   switch (get_attr_type (insn))
2329     {
2330     case TYPE_IMOVX:
2331       gcc_assert (ANY_QI_REG_P (operands[1]) || MEM_P (operands[1]));
2332       return "movz{bl|x}\t{%1, %k0|%k0, %1}";
2333     default:
2334       if (get_attr_mode (insn) == MODE_SI)
2335         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2336       else
2337         return "mov{b}\t{%1, %0|%0, %1}";
2338     }
2339 }
2340   [(set (attr "type")
2341      (cond [(and (eq_attr "alternative" "5")
2342                  (not (match_operand:QI 1 "aligned_operand" "")))
2343               (const_string "imovx")
2344             (ne (symbol_ref "optimize_function_for_size_p (cfun)")
2345                 (const_int 0))
2346               (const_string "imov")
2347             (and (eq_attr "alternative" "3")
2348                  (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2349                           (const_int 0))
2350                       (eq (symbol_ref "TARGET_QIMODE_MATH")
2351                           (const_int 0))))
2352               (const_string "imov")
2353             (eq_attr "alternative" "3,5")
2354               (const_string "imovx")
2355             (and (ne (symbol_ref "TARGET_MOVX")
2356                      (const_int 0))
2357                  (eq_attr "alternative" "2"))
2358               (const_string "imovx")
2359            ]
2360            (const_string "imov")))
2361    (set (attr "mode")
2362       (cond [(eq_attr "alternative" "3,4,5")
2363                (const_string "SI")
2364              (eq_attr "alternative" "6")
2365                (const_string "QI")
2366              (eq_attr "type" "imovx")
2367                (const_string "SI")
2368              (and (eq_attr "type" "imov")
2369                   (and (eq_attr "alternative" "0,1")
2370                        (and (ne (symbol_ref "TARGET_PARTIAL_REG_DEPENDENCY")
2371                                 (const_int 0))
2372                             (and (eq (symbol_ref "optimize_function_for_size_p (cfun)")
2373                                      (const_int 0))
2374                                  (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2375                                      (const_int 0))))))
2376                (const_string "SI")
2377              ;; Avoid partial register stalls when not using QImode arithmetic
2378              (and (eq_attr "type" "imov")
2379                   (and (eq_attr "alternative" "0,1")
2380                        (and (ne (symbol_ref "TARGET_PARTIAL_REG_STALL")
2381                                 (const_int 0))
2382                             (eq (symbol_ref "TARGET_QIMODE_MATH")
2383                                 (const_int 0)))))
2384                (const_string "SI")
2385            ]
2386            (const_string "QI")))])
2387
2388 ;; Stores and loads of ax to arbitrary constant address.
2389 ;; We fake an second form of instruction to force reload to load address
2390 ;; into register when rax is not available
2391 (define_insn "*movabs<mode>_1"
2392   [(set (mem:SWI1248x (match_operand:DI 0 "x86_64_movabs_operand" "i,r"))
2393         (match_operand:SWI1248x 1 "nonmemory_operand" "a,er"))]
2394   "TARGET_64BIT && ix86_check_movabs (insn, 0)"
2395   "@
2396    movabs{<imodesuffix>}\t{%1, %P0|%P0, %1}
2397    mov{<imodesuffix>}\t{%1, %a0|%a0, %1}"
2398   [(set_attr "type" "imov")
2399    (set_attr "modrm" "0,*")
2400    (set_attr "length_address" "8,0")
2401    (set_attr "length_immediate" "0,*")
2402    (set_attr "memory" "store")
2403    (set_attr "mode" "<MODE>")])
2404
2405 (define_insn "*movabs<mode>_2"
2406   [(set (match_operand:SWI1248x 0 "register_operand" "=a,r")
2407         (mem:SWI1248x (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
2408   "TARGET_64BIT && ix86_check_movabs (insn, 1)"
2409   "@
2410    movabs{<imodesuffix>}\t{%P1, %0|%0, %P1}
2411    mov{<imodesuffix>}\t{%a1, %0|%0, %a1}"
2412   [(set_attr "type" "imov")
2413    (set_attr "modrm" "0,*")
2414    (set_attr "length_address" "8,0")
2415    (set_attr "length_immediate" "0")
2416    (set_attr "memory" "load")
2417    (set_attr "mode" "<MODE>")])
2418
2419 (define_insn "*swap<mode>"
2420   [(set (match_operand:SWI48 0 "register_operand" "+r")
2421         (match_operand:SWI48 1 "register_operand" "+r"))
2422    (set (match_dup 1)
2423         (match_dup 0))]
2424   ""
2425   "xchg{<imodesuffix>}\t%1, %0"
2426   [(set_attr "type" "imov")
2427    (set_attr "mode" "<MODE>")
2428    (set_attr "pent_pair" "np")
2429    (set_attr "athlon_decode" "vector")
2430    (set_attr "amdfam10_decode" "double")
2431    (set_attr "bdver1_decode" "double")])
2432
2433 (define_insn "*swap<mode>_1"
2434   [(set (match_operand:SWI12 0 "register_operand" "+r")
2435         (match_operand:SWI12 1 "register_operand" "+r"))
2436    (set (match_dup 1)
2437         (match_dup 0))]
2438   "!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)"
2439   "xchg{l}\t%k1, %k0"
2440   [(set_attr "type" "imov")
2441    (set_attr "mode" "SI")
2442    (set_attr "pent_pair" "np")
2443    (set_attr "athlon_decode" "vector")
2444    (set_attr "amdfam10_decode" "double")
2445    (set_attr "bdver1_decode" "double")])
2446
2447 ;; Not added amdfam10_decode since TARGET_PARTIAL_REG_STALL
2448 ;; is disabled for AMDFAM10
2449 (define_insn "*swap<mode>_2"
2450   [(set (match_operand:SWI12 0 "register_operand" "+<r>")
2451         (match_operand:SWI12 1 "register_operand" "+<r>"))
2452    (set (match_dup 1)
2453         (match_dup 0))]
2454   "TARGET_PARTIAL_REG_STALL"
2455   "xchg{<imodesuffix>}\t%1, %0"
2456   [(set_attr "type" "imov")
2457    (set_attr "mode" "<MODE>")
2458    (set_attr "pent_pair" "np")
2459    (set_attr "athlon_decode" "vector")])
2460
2461 (define_expand "movstrict<mode>"
2462   [(set (strict_low_part (match_operand:SWI12 0 "nonimmediate_operand" ""))
2463         (match_operand:SWI12 1 "general_operand" ""))]
2464   ""
2465 {
2466   if (TARGET_PARTIAL_REG_STALL && optimize_function_for_speed_p (cfun))
2467     FAIL;
2468   if (GET_CODE (operands[0]) == SUBREG
2469       && GET_MODE_CLASS (GET_MODE (SUBREG_REG (operands[0]))) != MODE_INT)
2470     FAIL;
2471   /* Don't generate memory->memory moves, go through a register */
2472   if (MEM_P (operands[0]) && MEM_P (operands[1]))
2473     operands[1] = force_reg (<MODE>mode, operands[1]);
2474 })
2475
2476 (define_insn "*movstrict<mode>_1"
2477   [(set (strict_low_part
2478           (match_operand:SWI12 0 "nonimmediate_operand" "+<r>m,<r>"))
2479         (match_operand:SWI12 1 "general_operand" "<r>n,m"))]
2480   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
2481    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2482   "mov{<imodesuffix>}\t{%1, %0|%0, %1}"
2483   [(set_attr "type" "imov")
2484    (set_attr "mode" "<MODE>")])
2485
2486 (define_insn "*movstrict<mode>_xor"
2487   [(set (strict_low_part (match_operand:SWI12 0 "register_operand" "+<r>"))
2488         (match_operand:SWI12 1 "const0_operand" ""))
2489    (clobber (reg:CC FLAGS_REG))]
2490   "reload_completed"
2491   "xor{<imodesuffix>}\t%0, %0"
2492   [(set_attr "type" "alu1")
2493    (set_attr "mode" "<MODE>")
2494    (set_attr "length_immediate" "0")])
2495
2496 (define_insn "*mov<mode>_extv_1"
2497   [(set (match_operand:SWI24 0 "register_operand" "=R")
2498         (sign_extract:SWI24 (match_operand 1 "ext_register_operand" "Q")
2499                             (const_int 8)
2500                             (const_int 8)))]
2501   ""
2502   "movs{bl|x}\t{%h1, %k0|%k0, %h1}"
2503   [(set_attr "type" "imovx")
2504    (set_attr "mode" "SI")])
2505
2506 (define_insn "*movqi_extv_1_rex64"
2507   [(set (match_operand:QI 0 "register_operand" "=Q,?R")
2508         (sign_extract:QI (match_operand 1 "ext_register_operand" "Q,Q")
2509                          (const_int 8)
2510                          (const_int 8)))]
2511   "TARGET_64BIT"
2512 {
2513   switch (get_attr_type (insn))
2514     {
2515     case TYPE_IMOVX:
2516       return "movs{bl|x}\t{%h1, %k0|%k0, %h1}";
2517     default:
2518       return "mov{b}\t{%h1, %0|%0, %h1}";
2519     }
2520 }
2521   [(set (attr "type")
2522      (if_then_else (ior (not (match_operand:QI 0 "QIreg_operand" ""))
2523                         (ne (symbol_ref "TARGET_MOVX")
2524                             (const_int 0)))
2525         (const_string "imovx")
2526         (const_string "imov")))
2527    (set (attr "mode")
2528      (if_then_else (eq_attr "type" "imovx")
2529         (const_string "SI")
2530         (const_string "QI")))])
2531
2532 (define_insn "*movqi_extv_1"
2533   [(set (match_operand:QI 0 "nonimmediate_operand" "=Qm,?r")
2534         (sign_extract:QI (match_operand 1 "ext_register_operand" "Q,Q")
2535                          (const_int 8)
2536                          (const_int 8)))]
2537   "!TARGET_64BIT"
2538 {
2539   switch (get_attr_type (insn))
2540     {
2541     case TYPE_IMOVX:
2542       return "movs{bl|x}\t{%h1, %k0|%k0, %h1}";
2543     default:
2544       return "mov{b}\t{%h1, %0|%0, %h1}";
2545     }
2546 }
2547   [(set (attr "type")
2548      (if_then_else (and (match_operand:QI 0 "register_operand" "")
2549                         (ior (not (match_operand:QI 0 "QIreg_operand" ""))
2550                              (ne (symbol_ref "TARGET_MOVX")
2551                                  (const_int 0))))
2552         (const_string "imovx")
2553         (const_string "imov")))
2554    (set (attr "mode")
2555      (if_then_else (eq_attr "type" "imovx")
2556         (const_string "SI")
2557         (const_string "QI")))])
2558
2559 (define_insn "*mov<mode>_extzv_1"
2560   [(set (match_operand:SWI48 0 "register_operand" "=R")
2561         (zero_extract:SWI48 (match_operand 1 "ext_register_operand" "Q")
2562                             (const_int 8)
2563                             (const_int 8)))]
2564   ""
2565   "movz{bl|x}\t{%h1, %k0|%k0, %h1}"
2566   [(set_attr "type" "imovx")
2567    (set_attr "mode" "SI")])
2568
2569 (define_insn "*movqi_extzv_2_rex64"
2570   [(set (match_operand:QI 0 "register_operand" "=Q,?R")
2571         (subreg:QI
2572           (zero_extract:SI (match_operand 1 "ext_register_operand" "Q,Q")
2573                            (const_int 8)
2574                            (const_int 8)) 0))]
2575   "TARGET_64BIT"
2576 {
2577   switch (get_attr_type (insn))
2578     {
2579     case TYPE_IMOVX:
2580       return "movz{bl|x}\t{%h1, %k0|%k0, %h1}";
2581     default:
2582       return "mov{b}\t{%h1, %0|%0, %h1}";
2583     }
2584 }
2585   [(set (attr "type")
2586      (if_then_else (ior (not (match_operand:QI 0 "QIreg_operand" ""))
2587                         (ne (symbol_ref "TARGET_MOVX")
2588                             (const_int 0)))
2589         (const_string "imovx")
2590         (const_string "imov")))
2591    (set (attr "mode")
2592      (if_then_else (eq_attr "type" "imovx")
2593         (const_string "SI")
2594         (const_string "QI")))])
2595
2596 (define_insn "*movqi_extzv_2"
2597   [(set (match_operand:QI 0 "nonimmediate_operand" "=Qm,?R")
2598         (subreg:QI
2599           (zero_extract:SI (match_operand 1 "ext_register_operand" "Q,Q")
2600                            (const_int 8)
2601                            (const_int 8)) 0))]
2602   "!TARGET_64BIT"
2603 {
2604   switch (get_attr_type (insn))
2605     {
2606     case TYPE_IMOVX:
2607       return "movz{bl|x}\t{%h1, %k0|%k0, %h1}";
2608     default:
2609       return "mov{b}\t{%h1, %0|%0, %h1}";
2610     }
2611 }
2612   [(set (attr "type")
2613      (if_then_else (and (match_operand:QI 0 "register_operand" "")
2614                         (ior (not (match_operand:QI 0 "QIreg_operand" ""))
2615                              (ne (symbol_ref "TARGET_MOVX")
2616                                  (const_int 0))))
2617         (const_string "imovx")
2618         (const_string "imov")))
2619    (set (attr "mode")
2620      (if_then_else (eq_attr "type" "imovx")
2621         (const_string "SI")
2622         (const_string "QI")))])
2623
2624 (define_expand "mov<mode>_insv_1"
2625   [(set (zero_extract:SWI48 (match_operand 0 "ext_register_operand" "")
2626                             (const_int 8)
2627                             (const_int 8))
2628         (match_operand:SWI48 1 "nonmemory_operand" ""))])
2629
2630 (define_insn "*mov<mode>_insv_1_rex64"
2631   [(set (zero_extract:SWI48x (match_operand 0 "ext_register_operand" "+Q")
2632                              (const_int 8)
2633                              (const_int 8))
2634         (match_operand:SWI48x 1 "nonmemory_operand" "Qn"))]
2635   "TARGET_64BIT"
2636   "mov{b}\t{%b1, %h0|%h0, %b1}"
2637   [(set_attr "type" "imov")
2638    (set_attr "mode" "QI")])
2639
2640 (define_insn "*movsi_insv_1"
2641   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
2642                          (const_int 8)
2643                          (const_int 8))
2644         (match_operand:SI 1 "general_operand" "Qmn"))]
2645   "!TARGET_64BIT"
2646   "mov{b}\t{%b1, %h0|%h0, %b1}"
2647   [(set_attr "type" "imov")
2648    (set_attr "mode" "QI")])
2649
2650 (define_insn "*movqi_insv_2"
2651   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
2652                          (const_int 8)
2653                          (const_int 8))
2654         (lshiftrt:SI (match_operand:SI 1 "register_operand" "Q")
2655                      (const_int 8)))]
2656   ""
2657   "mov{b}\t{%h1, %h0|%h0, %h1}"
2658   [(set_attr "type" "imov")
2659    (set_attr "mode" "QI")])
2660 \f
2661 ;; Floating point push instructions.
2662
2663 (define_insn "*pushtf"
2664   [(set (match_operand:TF 0 "push_operand" "=<,<,<")
2665         (match_operand:TF 1 "general_no_elim_operand" "x,Fo,*r"))]
2666   "TARGET_SSE2"
2667 {
2668   /* This insn should be already split before reg-stack.  */
2669   gcc_unreachable ();
2670 }
2671   [(set_attr "type" "multi")
2672    (set_attr "unit" "sse,*,*")
2673    (set_attr "mode" "TF,SI,SI")])
2674
2675 ;; %%% Kill this when call knows how to work this out.
2676 (define_split
2677   [(set (match_operand:TF 0 "push_operand" "")
2678         (match_operand:TF 1 "sse_reg_operand" ""))]
2679   "TARGET_SSE2 && reload_completed"
2680   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -16)))
2681    (set (mem:TF (reg:P SP_REG)) (match_dup 1))])
2682
2683 (define_insn "*pushxf"
2684   [(set (match_operand:XF 0 "push_operand" "=<,<")
2685         (match_operand:XF 1 "general_no_elim_operand" "f,ro"))]
2686   "optimize_function_for_speed_p (cfun)"
2687 {
2688   /* This insn should be already split before reg-stack.  */
2689   gcc_unreachable ();
2690 }
2691   [(set_attr "type" "multi")
2692    (set_attr "unit" "i387,*")
2693    (set_attr "mode" "XF,SI")])
2694
2695 ;; Size of pushxf is 3 (for sub) + 2 (for fstp) + memory operand size.
2696 ;; Size of pushxf using integer instructions is 3+3*memory operand size
2697 ;; Pushing using integer instructions is longer except for constants
2698 ;; and direct memory references (assuming that any given constant is pushed
2699 ;; only once, but this ought to be handled elsewhere).
2700
2701 (define_insn "*pushxf_nointeger"
2702   [(set (match_operand:XF 0 "push_operand" "=X,X")
2703         (match_operand:XF 1 "general_no_elim_operand" "f,*rFo"))]
2704   "optimize_function_for_size_p (cfun)"
2705 {
2706   /* This insn should be already split before reg-stack.  */
2707   gcc_unreachable ();
2708 }
2709   [(set_attr "type" "multi")
2710    (set_attr "unit" "i387,*")
2711    (set_attr "mode" "XF,SI")])
2712
2713 ;; %%% Kill this when call knows how to work this out.
2714 (define_split
2715   [(set (match_operand:XF 0 "push_operand" "")
2716         (match_operand:XF 1 "fp_register_operand" ""))]
2717   "reload_completed"
2718   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
2719    (set (mem:XF (reg:P SP_REG)) (match_dup 1))]
2720   "operands[2] = GEN_INT (-GET_MODE_SIZE (XFmode));")
2721
2722 ;; Size of pushdf is 3 (for sub) + 2 (for fstp) + memory operand size.
2723 ;; Size of pushdf using integer instructions is 2+2*memory operand size
2724 ;; On the average, pushdf using integers can be still shorter.
2725
2726 (define_insn "*pushdf"
2727   [(set (match_operand:DF 0 "push_operand" "=<,<,<")
2728         (match_operand:DF 1 "general_no_elim_operand" "f,Yd*rFo,Y2"))]
2729   ""
2730 {
2731   /* This insn should be already split before reg-stack.  */
2732   gcc_unreachable ();
2733 }
2734   [(set_attr "type" "multi")
2735    (set_attr "unit" "i387,*,*")
2736    (set_attr "mode" "DF,SI,DF")])
2737
2738 ;; %%% Kill this when call knows how to work this out.
2739 (define_split
2740   [(set (match_operand:DF 0 "push_operand" "")
2741         (match_operand:DF 1 "any_fp_register_operand" ""))]
2742   "reload_completed"
2743   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -8)))
2744    (set (mem:DF (reg:P SP_REG)) (match_dup 1))])
2745
2746 (define_insn "*pushsf_rex64"
2747   [(set (match_operand:SF 0 "push_operand" "=X,X,X")
2748         (match_operand:SF 1 "nonmemory_no_elim_operand" "f,rF,x"))]
2749   "TARGET_64BIT"
2750 {
2751   /* Anything else should be already split before reg-stack.  */
2752   gcc_assert (which_alternative == 1);
2753   return "push{q}\t%q1";
2754 }
2755   [(set_attr "type" "multi,push,multi")
2756    (set_attr "unit" "i387,*,*")
2757    (set_attr "mode" "SF,DI,SF")])
2758
2759 (define_insn "*pushsf"
2760   [(set (match_operand:SF 0 "push_operand" "=<,<,<")
2761         (match_operand:SF 1 "general_no_elim_operand" "f,rFm,x"))]
2762   "!TARGET_64BIT"
2763 {
2764   /* Anything else should be already split before reg-stack.  */
2765   gcc_assert (which_alternative == 1);
2766   return "push{l}\t%1";
2767 }
2768   [(set_attr "type" "multi,push,multi")
2769    (set_attr "unit" "i387,*,*")
2770    (set_attr "mode" "SF,SI,SF")])
2771
2772 ;; %%% Kill this when call knows how to work this out.
2773 (define_split
2774   [(set (match_operand:SF 0 "push_operand" "")
2775         (match_operand:SF 1 "any_fp_register_operand" ""))]
2776   "reload_completed"
2777   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
2778    (set (mem:SF (reg:P SP_REG)) (match_dup 1))]
2779   "operands[2] = GEN_INT (-GET_MODE_SIZE (<P:MODE>mode));")
2780
2781 (define_split
2782   [(set (match_operand:SF 0 "push_operand" "")
2783         (match_operand:SF 1 "memory_operand" ""))]
2784   "reload_completed
2785    && (operands[2] = find_constant_src (insn))"
2786   [(set (match_dup 0) (match_dup 2))])
2787
2788 (define_split
2789   [(set (match_operand 0 "push_operand" "")
2790         (match_operand 1 "general_operand" ""))]
2791   "reload_completed
2792    && (GET_MODE (operands[0]) == TFmode
2793        || GET_MODE (operands[0]) == XFmode
2794        || GET_MODE (operands[0]) == DFmode)
2795    && !ANY_FP_REG_P (operands[1])"
2796   [(const_int 0)]
2797   "ix86_split_long_move (operands); DONE;")
2798 \f
2799 ;; Floating point move instructions.
2800
2801 (define_expand "movtf"
2802   [(set (match_operand:TF 0 "nonimmediate_operand" "")
2803         (match_operand:TF 1 "nonimmediate_operand" ""))]
2804   "TARGET_SSE2"
2805 {
2806   ix86_expand_move (TFmode, operands);
2807   DONE;
2808 })
2809
2810 (define_expand "mov<mode>"
2811   [(set (match_operand:X87MODEF 0 "nonimmediate_operand" "")
2812         (match_operand:X87MODEF 1 "general_operand" ""))]
2813   ""
2814   "ix86_expand_move (<MODE>mode, operands); DONE;")
2815
2816 (define_insn "*movtf_internal"
2817   [(set (match_operand:TF 0 "nonimmediate_operand" "=x,m,x,?*r ,!o")
2818         (match_operand:TF 1 "general_operand"      "xm,x,C,*roF,F*r"))]
2819   "TARGET_SSE2
2820    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
2821    && (!can_create_pseudo_p ()
2822        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
2823        || GET_CODE (operands[1]) != CONST_DOUBLE
2824        || (optimize_function_for_size_p (cfun)
2825            && standard_sse_constant_p (operands[1])
2826            && !memory_operand (operands[0], TFmode))
2827        || (!TARGET_MEMORY_MISMATCH_STALL
2828            && memory_operand (operands[0], TFmode)))"
2829 {
2830   switch (which_alternative)
2831     {
2832     case 0:
2833     case 1:
2834       /* Handle misaligned load/store since we
2835          don't have movmisaligntf pattern. */
2836       if (misaligned_operand (operands[0], TFmode)
2837           || misaligned_operand (operands[1], TFmode))
2838         {
2839           if (get_attr_mode (insn) == MODE_V4SF)
2840             return "%vmovups\t{%1, %0|%0, %1}";
2841           else
2842             return "%vmovdqu\t{%1, %0|%0, %1}";
2843         }
2844       else
2845         {
2846           if (get_attr_mode (insn) == MODE_V4SF)
2847             return "%vmovaps\t{%1, %0|%0, %1}";
2848           else
2849             return "%vmovdqa\t{%1, %0|%0, %1}";
2850         }
2851
2852     case 2:
2853       return standard_sse_constant_opcode (insn, operands[1]);
2854
2855     case 3:
2856     case 4:
2857         return "#";
2858
2859     default:
2860       gcc_unreachable ();
2861     }
2862 }
2863   [(set_attr "type" "ssemov,ssemov,sselog1,*,*")
2864    (set_attr "prefix" "maybe_vex,maybe_vex,maybe_vex,*,*")
2865    (set (attr "mode")
2866         (cond [(eq_attr "alternative" "0,2")
2867                  (if_then_else
2868                    (ne (symbol_ref "optimize_function_for_size_p (cfun)")
2869                        (const_int 0))
2870                    (const_string "V4SF")
2871                    (const_string "TI"))
2872                (eq_attr "alternative" "1")
2873                  (if_then_else
2874                    (ior (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
2875                             (const_int 0))
2876                         (ne (symbol_ref "optimize_function_for_size_p (cfun)")
2877                             (const_int 0)))
2878                    (const_string "V4SF")
2879                    (const_string "TI"))]
2880                (const_string "DI")))])
2881
2882 ;; Possible store forwarding (partial memory) stall in alternative 4.
2883 (define_insn "*movxf_internal"
2884   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m,f,?Yx*r ,!o")
2885         (match_operand:XF 1 "general_operand"      "fm,f,G,Yx*roF,FYx*r"))]
2886   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
2887    && (!can_create_pseudo_p ()
2888        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
2889        || GET_CODE (operands[1]) != CONST_DOUBLE
2890        || (optimize_function_for_size_p (cfun)
2891            && standard_80387_constant_p (operands[1]) > 0
2892            && !memory_operand (operands[0], XFmode))
2893        || (!TARGET_MEMORY_MISMATCH_STALL
2894            && memory_operand (operands[0], XFmode)))"
2895 {
2896   switch (which_alternative)
2897     {
2898     case 0:
2899     case 1:
2900       return output_387_reg_move (insn, operands);
2901
2902     case 2:
2903       return standard_80387_constant_opcode (operands[1]);
2904
2905     case 3:
2906     case 4:
2907       return "#";
2908
2909     default:
2910       gcc_unreachable ();
2911     }
2912 }
2913   [(set_attr "type" "fmov,fmov,fmov,multi,multi")
2914    (set_attr "mode" "XF,XF,XF,SI,SI")])
2915
2916 (define_insn "*movdf_internal_rex64"
2917   [(set (match_operand:DF 0 "nonimmediate_operand"
2918                 "=f,m,f,?r,?m,?r,!m,Y2*x,Y2*x,Y2*x,m   ,Yi,r ")
2919         (match_operand:DF 1 "general_operand"
2920                 "fm,f,G,rm,r ,F ,F ,C   ,Y2*x,m   ,Y2*x,r ,Yi"))]
2921   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))
2922    && (!can_create_pseudo_p ()
2923        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
2924        || GET_CODE (operands[1]) != CONST_DOUBLE
2925        || (optimize_function_for_size_p (cfun)
2926            && ((!(TARGET_SSE2 && TARGET_SSE_MATH)
2927                 && standard_80387_constant_p (operands[1]) > 0)
2928                || (TARGET_SSE2 && TARGET_SSE_MATH
2929                    && standard_sse_constant_p (operands[1]))))
2930        || memory_operand (operands[0], DFmode))"
2931 {
2932   switch (which_alternative)
2933     {
2934     case 0:
2935     case 1:
2936       return output_387_reg_move (insn, operands);
2937
2938     case 2:
2939       return standard_80387_constant_opcode (operands[1]);
2940
2941     case 3:
2942     case 4:
2943       return "mov{q}\t{%1, %0|%0, %1}";
2944
2945     case 5:
2946       return "movabs{q}\t{%1, %0|%0, %1}";
2947
2948     case 6:
2949       return "#";
2950
2951     case 7:
2952       return standard_sse_constant_opcode (insn, operands[1]);
2953
2954     case 8:
2955     case 9:
2956     case 10:
2957       switch (get_attr_mode (insn))
2958         {
2959         case MODE_V2DF:
2960           if (!TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
2961             return "%vmovapd\t{%1, %0|%0, %1}";
2962         case MODE_V4SF:
2963           return "%vmovaps\t{%1, %0|%0, %1}";
2964
2965         case MODE_DI:
2966           return "%vmovq\t{%1, %0|%0, %1}";
2967         case MODE_DF:
2968           if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
2969             return "vmovsd\t{%1, %0, %0|%0, %0, %1}";
2970           return "%vmovsd\t{%1, %0|%0, %1}";
2971         case MODE_V1DF:
2972           return "%vmovlpd\t{%1, %d0|%d0, %1}";
2973         case MODE_V2SF:
2974           return "%vmovlps\t{%1, %d0|%d0, %1}";
2975         default:
2976           gcc_unreachable ();
2977         }
2978
2979     case 11:
2980     case 12:
2981       /* Handle broken assemblers that require movd instead of movq.  */
2982       return "%vmovd\t{%1, %0|%0, %1}";
2983
2984     default:
2985       gcc_unreachable();
2986     }
2987 }
2988   [(set_attr "type" "fmov,fmov,fmov,imov,imov,imov,multi,sselog1,ssemov,ssemov,ssemov,ssemov,ssemov")
2989    (set (attr "modrm")
2990      (if_then_else
2991        (and (eq_attr "alternative" "5") (eq_attr "type" "imov"))
2992          (const_string "0")
2993          (const_string "*")))
2994    (set (attr "length_immediate")
2995      (if_then_else
2996        (and (eq_attr "alternative" "5") (eq_attr "type" "imov"))
2997          (const_string "8")
2998          (const_string "*")))
2999    (set (attr "prefix")
3000      (if_then_else (eq_attr "alternative" "0,1,2,3,4,5,6")
3001        (const_string "orig")
3002        (const_string "maybe_vex")))
3003    (set (attr "prefix_data16")
3004      (if_then_else (eq_attr "mode" "V1DF")
3005        (const_string "1")
3006        (const_string "*")))
3007    (set (attr "mode")
3008         (cond [(eq_attr "alternative" "0,1,2")
3009                  (const_string "DF")
3010                (eq_attr "alternative" "3,4,5,6,11,12")
3011                  (const_string "DI")
3012
3013                /* xorps is one byte shorter.  */
3014                (eq_attr "alternative" "7")
3015                  (cond [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3016                             (const_int 0))
3017                           (const_string "V4SF")
3018                         (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
3019                             (const_int 0))
3020                           (const_string "TI")
3021                        ]
3022                        (const_string "V2DF"))
3023
3024                /* For architectures resolving dependencies on
3025                   whole SSE registers use APD move to break dependency
3026                   chains, otherwise use short move to avoid extra work.
3027
3028                   movaps encodes one byte shorter.  */
3029                (eq_attr "alternative" "8")
3030                  (cond
3031                    [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3032                         (const_int 0))
3033                       (const_string "V4SF")
3034                     (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3035                         (const_int 0))
3036                       (const_string "V2DF")
3037                    ]
3038                    (const_string "DF"))
3039                /* For architectures resolving dependencies on register
3040                   parts we may avoid extra work to zero out upper part
3041                   of register.  */
3042                (eq_attr "alternative" "9")
3043                  (if_then_else
3044                    (ne (symbol_ref "TARGET_SSE_SPLIT_REGS")
3045                        (const_int 0))
3046                    (const_string "V1DF")
3047                    (const_string "DF"))
3048               ]
3049               (const_string "DF")))])
3050
3051 ;; Possible store forwarding (partial memory) stall in alternative 4.
3052 (define_insn "*movdf_internal"
3053   [(set (match_operand:DF 0 "nonimmediate_operand"
3054                 "=f,m,f,?Yd*r ,!o   ,Y2*x,Y2*x,Y2*x,m  ")
3055         (match_operand:DF 1 "general_operand"
3056                 "fm,f,G,Yd*roF,FYd*r,C   ,Y2*x,m   ,Y2*x"))]
3057   "!TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))
3058    && (!can_create_pseudo_p ()
3059        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3060        || GET_CODE (operands[1]) != CONST_DOUBLE
3061        || (optimize_function_for_size_p (cfun)
3062            && ((!(TARGET_SSE2 && TARGET_SSE_MATH)
3063                 && standard_80387_constant_p (operands[1]) > 0)
3064                || (TARGET_SSE2 && TARGET_SSE_MATH
3065                    && standard_sse_constant_p (operands[1])))
3066            && !memory_operand (operands[0], DFmode))
3067        || (!TARGET_MEMORY_MISMATCH_STALL
3068            && memory_operand (operands[0], DFmode)))"
3069 {
3070   switch (which_alternative)
3071     {
3072     case 0:
3073     case 1:
3074       return output_387_reg_move (insn, operands);
3075
3076     case 2:
3077       return standard_80387_constant_opcode (operands[1]);
3078
3079     case 3:
3080     case 4:
3081       return "#";
3082
3083     case 5:
3084       return standard_sse_constant_opcode (insn, operands[1]);
3085
3086     case 6:
3087     case 7:
3088     case 8:
3089       switch (get_attr_mode (insn))
3090         {
3091         case MODE_V2DF:
3092           if (!TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
3093             return "%vmovapd\t{%1, %0|%0, %1}";
3094         case MODE_V4SF:
3095           return "%vmovaps\t{%1, %0|%0, %1}";
3096
3097         case MODE_DI:
3098           return "%vmovq\t{%1, %0|%0, %1}";
3099         case MODE_DF:
3100           if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
3101             return "vmovsd\t{%1, %0, %0|%0, %0, %1}";
3102           return "%vmovsd\t{%1, %0|%0, %1}";
3103         case MODE_V1DF:
3104           return "%vmovlpd\t{%1, %d0|%d0, %1}";
3105         case MODE_V2SF:
3106           return "%vmovlps\t{%1, %d0|%d0, %1}";
3107         default:
3108           gcc_unreachable ();
3109         }
3110
3111     default:
3112       gcc_unreachable ();
3113     }
3114 }
3115   [(set_attr "type" "fmov,fmov,fmov,multi,multi,sselog1,ssemov,ssemov,ssemov")
3116    (set (attr "prefix")
3117      (if_then_else (eq_attr "alternative" "0,1,2,3,4")
3118        (const_string "orig")
3119        (const_string "maybe_vex")))
3120    (set (attr "prefix_data16")
3121      (if_then_else (eq_attr "mode" "V1DF")
3122        (const_string "1")
3123        (const_string "*")))
3124    (set (attr "mode")
3125         (cond [(eq_attr "alternative" "0,1,2")
3126                  (const_string "DF")
3127                (eq_attr "alternative" "3,4")
3128                  (const_string "SI")
3129
3130                /* For SSE1, we have many fewer alternatives.  */
3131                (eq (symbol_ref "TARGET_SSE2") (const_int 0))
3132                  (if_then_else
3133                    (eq_attr "alternative" "5,6")
3134                    (const_string "V4SF")
3135                    (const_string "V2SF"))
3136
3137                /* xorps is one byte shorter.  */
3138                (eq_attr "alternative" "5")
3139                  (cond [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3140                             (const_int 0))
3141                           (const_string "V4SF")
3142                         (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
3143                             (const_int 0))
3144                           (const_string "TI")
3145                        ]
3146                        (const_string "V2DF"))
3147
3148                /* For architectures resolving dependencies on
3149                   whole SSE registers use APD move to break dependency
3150                   chains, otherwise use short move to avoid extra work.
3151
3152                   movaps encodes one byte shorter.  */
3153                (eq_attr "alternative" "6")
3154                  (cond
3155                    [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3156                         (const_int 0))
3157                       (const_string "V4SF")
3158                     (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3159                         (const_int 0))
3160                       (const_string "V2DF")
3161                    ]
3162                    (const_string "DF"))
3163                /* For architectures resolving dependencies on register
3164                   parts we may avoid extra work to zero out upper part
3165                   of register.  */
3166                (eq_attr "alternative" "7")
3167                  (if_then_else
3168                    (ne (symbol_ref "TARGET_SSE_SPLIT_REGS")
3169                        (const_int 0))
3170                    (const_string "V1DF")
3171                    (const_string "DF"))
3172               ]
3173               (const_string "DF")))])
3174
3175 (define_insn "*movsf_internal"
3176   [(set (match_operand:SF 0 "nonimmediate_operand"
3177           "=f,m,f,?r ,?m,x,x,x,m,!*y,!m,!*y,?Yi,?r,!*Ym,!r")
3178         (match_operand:SF 1 "general_operand"
3179           "fm,f,G,rmF,Fr,C,x,m,x,m  ,*y,*y ,r  ,Yi,r   ,*Ym"))]
3180   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
3181    && (!can_create_pseudo_p ()
3182        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3183        || GET_CODE (operands[1]) != CONST_DOUBLE
3184        || (optimize_function_for_size_p (cfun)
3185            && ((!TARGET_SSE_MATH
3186                 && standard_80387_constant_p (operands[1]) > 0)
3187                || (TARGET_SSE_MATH
3188                    && standard_sse_constant_p (operands[1]))))
3189        || memory_operand (operands[0], SFmode))"
3190 {
3191   switch (which_alternative)
3192     {
3193     case 0:
3194     case 1:
3195       return output_387_reg_move (insn, operands);
3196
3197     case 2:
3198       return standard_80387_constant_opcode (operands[1]);
3199
3200     case 3:
3201     case 4:
3202       return "mov{l}\t{%1, %0|%0, %1}";
3203
3204     case 5:
3205       return standard_sse_constant_opcode (insn, operands[1]);
3206
3207     case 6:
3208       if (get_attr_mode (insn) == MODE_V4SF)
3209         return "%vmovaps\t{%1, %0|%0, %1}";
3210       if (TARGET_AVX)
3211         return "vmovss\t{%1, %0, %0|%0, %0, %1}";
3212
3213     case 7:
3214     case 8:
3215       return "%vmovss\t{%1, %0|%0, %1}";
3216
3217     case 9:
3218     case 10:
3219     case 14:
3220     case 15:
3221       return "movd\t{%1, %0|%0, %1}";
3222
3223     case 11:
3224       return "movq\t{%1, %0|%0, %1}";
3225
3226     case 12:
3227     case 13:
3228       return "%vmovd\t{%1, %0|%0, %1}";
3229
3230     default:
3231       gcc_unreachable ();
3232     }
3233 }
3234   [(set_attr "type" "fmov,fmov,fmov,imov,imov,sselog1,ssemov,ssemov,ssemov,mmxmov,mmxmov,mmxmov,ssemov,ssemov,mmxmov,mmxmov")
3235    (set (attr "prefix")
3236      (if_then_else (eq_attr "alternative" "5,6,7,8,12,13")
3237        (const_string "maybe_vex")
3238        (const_string "orig")))
3239    (set (attr "mode")
3240         (cond [(eq_attr "alternative" "3,4,9,10")
3241                  (const_string "SI")
3242                (eq_attr "alternative" "5")
3243                  (if_then_else
3244                    (and (and (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
3245                                  (const_int 0))
3246                              (ne (symbol_ref "TARGET_SSE2")
3247                                  (const_int 0)))
3248                         (eq (symbol_ref "optimize_function_for_size_p (cfun)")
3249                             (const_int 0)))
3250                    (const_string "TI")
3251                    (const_string "V4SF"))
3252                /* For architectures resolving dependencies on
3253                   whole SSE registers use APS move to break dependency
3254                   chains, otherwise use short move to avoid extra work.
3255
3256                   Do the same for architectures resolving dependencies on
3257                   the parts.  While in DF mode it is better to always handle
3258                   just register parts, the SF mode is different due to lack
3259                   of instructions to load just part of the register.  It is
3260                   better to maintain the whole registers in single format
3261                   to avoid problems on using packed logical operations.  */
3262                (eq_attr "alternative" "6")
3263                  (if_then_else
3264                    (ior (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3265                             (const_int 0))
3266                         (ne (symbol_ref "TARGET_SSE_SPLIT_REGS")
3267                             (const_int 0)))
3268                    (const_string "V4SF")
3269                    (const_string "SF"))
3270                (eq_attr "alternative" "11")
3271                  (const_string "DI")]
3272                (const_string "SF")))])
3273
3274 (define_split
3275   [(set (match_operand 0 "any_fp_register_operand" "")
3276         (match_operand 1 "memory_operand" ""))]
3277   "reload_completed
3278    && (GET_MODE (operands[0]) == TFmode
3279        || GET_MODE (operands[0]) == XFmode
3280        || GET_MODE (operands[0]) == DFmode
3281        || GET_MODE (operands[0]) == SFmode)
3282    && (operands[2] = find_constant_src (insn))"
3283   [(set (match_dup 0) (match_dup 2))]
3284 {
3285   rtx c = operands[2];
3286   int r = REGNO (operands[0]);
3287
3288   if ((SSE_REGNO_P (r) && !standard_sse_constant_p (c))
3289       || (FP_REGNO_P (r) && standard_80387_constant_p (c) < 1))
3290     FAIL;
3291 })
3292
3293 (define_split
3294   [(set (match_operand 0 "any_fp_register_operand" "")
3295         (float_extend (match_operand 1 "memory_operand" "")))]
3296   "reload_completed
3297    && (GET_MODE (operands[0]) == TFmode
3298        || GET_MODE (operands[0]) == XFmode
3299        || GET_MODE (operands[0]) == DFmode)
3300    && (operands[2] = find_constant_src (insn))"
3301   [(set (match_dup 0) (match_dup 2))]
3302 {
3303   rtx c = operands[2];
3304   int r = REGNO (operands[0]);
3305
3306   if ((SSE_REGNO_P (r) && !standard_sse_constant_p (c))
3307       || (FP_REGNO_P (r) && standard_80387_constant_p (c) < 1))
3308     FAIL;
3309 })
3310
3311 ;; Split the load of -0.0 or -1.0 into fldz;fchs or fld1;fchs sequence
3312 (define_split
3313   [(set (match_operand:X87MODEF 0 "fp_register_operand" "")
3314         (match_operand:X87MODEF 1 "immediate_operand" ""))]
3315   "reload_completed
3316    && (standard_80387_constant_p (operands[1]) == 8
3317        || standard_80387_constant_p (operands[1]) == 9)"
3318   [(set (match_dup 0)(match_dup 1))
3319    (set (match_dup 0)
3320         (neg:X87MODEF (match_dup 0)))]
3321 {
3322   REAL_VALUE_TYPE r;
3323
3324   REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
3325   if (real_isnegzero (&r))
3326     operands[1] = CONST0_RTX (<MODE>mode);
3327   else
3328     operands[1] = CONST1_RTX (<MODE>mode);
3329 })
3330
3331 (define_split
3332   [(set (match_operand 0 "nonimmediate_operand" "")
3333         (match_operand 1 "general_operand" ""))]
3334   "reload_completed
3335    && (GET_MODE (operands[0]) == TFmode
3336        || GET_MODE (operands[0]) == XFmode
3337        || GET_MODE (operands[0]) == DFmode)
3338    && !(ANY_FP_REG_P (operands[0]) || ANY_FP_REG_P (operands[1]))"
3339   [(const_int 0)]
3340   "ix86_split_long_move (operands); DONE;")
3341
3342 (define_insn "swapxf"
3343   [(set (match_operand:XF 0 "register_operand" "+f")
3344         (match_operand:XF 1 "register_operand" "+f"))
3345    (set (match_dup 1)
3346         (match_dup 0))]
3347   "TARGET_80387"
3348 {
3349   if (STACK_TOP_P (operands[0]))
3350     return "fxch\t%1";
3351   else
3352     return "fxch\t%0";
3353 }
3354   [(set_attr "type" "fxch")
3355    (set_attr "mode" "XF")])
3356
3357 (define_insn "*swap<mode>"
3358   [(set (match_operand:MODEF 0 "fp_register_operand" "+f")
3359         (match_operand:MODEF 1 "fp_register_operand" "+f"))
3360    (set (match_dup 1)
3361         (match_dup 0))]
3362   "TARGET_80387 || reload_completed"
3363 {
3364   if (STACK_TOP_P (operands[0]))
3365     return "fxch\t%1";
3366   else
3367     return "fxch\t%0";
3368 }
3369   [(set_attr "type" "fxch")
3370    (set_attr "mode" "<MODE>")])
3371 \f
3372 ;; Zero extension instructions
3373
3374 (define_expand "zero_extendsidi2"
3375   [(set (match_operand:DI 0 "nonimmediate_operand" "")
3376         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))]
3377   ""
3378 {
3379   if (!TARGET_64BIT)
3380     {
3381       emit_insn (gen_zero_extendsidi2_1 (operands[0], operands[1]));
3382       DONE;
3383     }
3384 })
3385
3386 (define_insn "*zero_extendsidi2_rex64"
3387   [(set (match_operand:DI 0 "nonimmediate_operand"  "=r,o,?*Ym,?*y,?*Yi,*Y2")
3388         (zero_extend:DI
3389          (match_operand:SI 1 "nonimmediate_operand" "rm,0,r   ,m  ,r   ,m")))]
3390   "TARGET_64BIT"
3391   "@
3392    mov\t{%k1, %k0|%k0, %k1}
3393    #
3394    movd\t{%1, %0|%0, %1}
3395    movd\t{%1, %0|%0, %1}
3396    %vmovd\t{%1, %0|%0, %1}
3397    %vmovd\t{%1, %0|%0, %1}"
3398   [(set_attr "type" "imovx,imov,mmxmov,mmxmov,ssemov,ssemov")
3399    (set_attr "prefix" "orig,*,orig,orig,maybe_vex,maybe_vex")
3400    (set_attr "prefix_0f" "0,*,*,*,*,*")
3401    (set_attr "mode" "SI,DI,DI,DI,TI,TI")])
3402
3403 (define_split
3404   [(set (match_operand:DI 0 "memory_operand" "")
3405         (zero_extend:DI (match_dup 0)))]
3406   "TARGET_64BIT"
3407   [(set (match_dup 4) (const_int 0))]
3408   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3409
3410 ;; %%% Kill me once multi-word ops are sane.
3411 (define_insn "zero_extendsidi2_1"
3412   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,?r,?o,?*Ym,?*y,?*Yi,*Y2")
3413         (zero_extend:DI
3414          (match_operand:SI 1 "nonimmediate_operand" "0,rm,r ,r   ,m  ,r   ,m")))
3415    (clobber (reg:CC FLAGS_REG))]
3416   "!TARGET_64BIT"
3417   "@
3418    #
3419    #
3420    #
3421    movd\t{%1, %0|%0, %1}
3422    movd\t{%1, %0|%0, %1}
3423    %vmovd\t{%1, %0|%0, %1}
3424    %vmovd\t{%1, %0|%0, %1}"
3425   [(set_attr "type" "multi,multi,multi,mmxmov,mmxmov,ssemov,ssemov")
3426    (set_attr "prefix" "*,*,*,orig,orig,maybe_vex,maybe_vex")
3427    (set_attr "mode" "SI,SI,SI,DI,DI,TI,TI")])
3428
3429 (define_split
3430   [(set (match_operand:DI 0 "register_operand" "")
3431         (zero_extend:DI (match_operand:SI 1 "register_operand" "")))
3432    (clobber (reg:CC FLAGS_REG))]
3433   "!TARGET_64BIT && reload_completed
3434    && true_regnum (operands[0]) == true_regnum (operands[1])"
3435   [(set (match_dup 4) (const_int 0))]
3436   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3437
3438 (define_split
3439   [(set (match_operand:DI 0 "nonimmediate_operand" "")
3440         (zero_extend:DI (match_operand:SI 1 "general_operand" "")))
3441    (clobber (reg:CC FLAGS_REG))]
3442   "!TARGET_64BIT && reload_completed
3443    && !(MMX_REG_P (operands[0]) || SSE_REG_P (operands[0]))"
3444   [(set (match_dup 3) (match_dup 1))
3445    (set (match_dup 4) (const_int 0))]
3446   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3447
3448 (define_insn "zero_extend<mode>di2"
3449   [(set (match_operand:DI 0 "register_operand" "=r")
3450         (zero_extend:DI
3451          (match_operand:SWI12 1 "nonimmediate_operand" "<r>m")))]
3452   "TARGET_64BIT"
3453   "movz{<imodesuffix>l|x}\t{%1, %k0|%k0, %1}"
3454   [(set_attr "type" "imovx")
3455    (set_attr "mode" "SI")])
3456
3457 (define_expand "zero_extendhisi2"
3458   [(set (match_operand:SI 0 "register_operand" "")
3459         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "")))]
3460   ""
3461 {
3462   if (TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))
3463     {
3464       operands[1] = force_reg (HImode, operands[1]);
3465       emit_insn (gen_zero_extendhisi2_and (operands[0], operands[1]));
3466       DONE;
3467     }
3468 })
3469
3470 (define_insn_and_split "zero_extendhisi2_and"
3471   [(set (match_operand:SI 0 "register_operand" "=r")
3472         (zero_extend:SI (match_operand:HI 1 "register_operand" "0")))
3473    (clobber (reg:CC FLAGS_REG))]
3474   "TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
3475   "#"
3476   "&& reload_completed"
3477   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (const_int 65535)))
3478               (clobber (reg:CC FLAGS_REG))])]
3479   ""
3480   [(set_attr "type" "alu1")
3481    (set_attr "mode" "SI")])
3482
3483 (define_insn "*zero_extendhisi2_movzwl"
3484   [(set (match_operand:SI 0 "register_operand" "=r")
3485         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "rm")))]
3486   "!TARGET_ZERO_EXTEND_WITH_AND
3487    || optimize_function_for_size_p (cfun)"
3488   "movz{wl|x}\t{%1, %0|%0, %1}"
3489   [(set_attr "type" "imovx")
3490    (set_attr "mode" "SI")])
3491
3492 (define_expand "zero_extendqi<mode>2"
3493   [(parallel
3494     [(set (match_operand:SWI24 0 "register_operand" "")
3495           (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "")))
3496      (clobber (reg:CC FLAGS_REG))])])
3497
3498 (define_insn "*zero_extendqi<mode>2_and"
3499   [(set (match_operand:SWI24 0 "register_operand" "=r,?&q")
3500         (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "0,qm")))
3501    (clobber (reg:CC FLAGS_REG))]
3502   "TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
3503   "#"
3504   [(set_attr "type" "alu1")
3505    (set_attr "mode" "<MODE>")])
3506
3507 ;; When source and destination does not overlap, clear destination
3508 ;; first and then do the movb
3509 (define_split
3510   [(set (match_operand:SWI24 0 "register_operand" "")
3511         (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "")))
3512    (clobber (reg:CC FLAGS_REG))]
3513   "reload_completed
3514    && (TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))
3515    && ANY_QI_REG_P (operands[0])
3516    && (ANY_QI_REG_P (operands[1]) || MEM_P (operands[1]))
3517    && !reg_overlap_mentioned_p (operands[0], operands[1])"
3518   [(set (strict_low_part (match_dup 2)) (match_dup 1))]
3519 {
3520   operands[2] = gen_lowpart (QImode, operands[0]);
3521   ix86_expand_clear (operands[0]);
3522 })
3523
3524 (define_insn "*zero_extendqi<mode>2_movzbl_and"
3525   [(set (match_operand:SWI24 0 "register_operand" "=r,r")
3526         (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "qm,0")))
3527    (clobber (reg:CC FLAGS_REG))]
3528   "!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun)"
3529   "#"
3530   [(set_attr "type" "imovx,alu1")
3531    (set_attr "mode" "<MODE>")])
3532
3533 ;; For the movzbl case strip only the clobber
3534 (define_split
3535   [(set (match_operand:SWI24 0 "register_operand" "")
3536         (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "")))
3537    (clobber (reg:CC FLAGS_REG))]
3538   "reload_completed
3539    && (!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun))
3540    && (!REG_P (operands[1]) || ANY_QI_REG_P (operands[1]))"
3541   [(set (match_dup 0)
3542         (zero_extend:SWI24 (match_dup 1)))])
3543
3544 ; zero extend to SImode to avoid partial register stalls
3545 (define_insn "*zero_extendqi<mode>2_movzbl"
3546   [(set (match_operand:SWI24 0 "register_operand" "=r")
3547         (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3548   "reload_completed
3549    && (!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun))"
3550   "movz{bl|x}\t{%1, %k0|%k0, %1}"
3551   [(set_attr "type" "imovx")
3552    (set_attr "mode" "SI")])
3553
3554 ;; Rest is handled by single and.
3555 (define_split
3556   [(set (match_operand:SWI24 0 "register_operand" "")
3557         (zero_extend:SWI24 (match_operand:QI 1 "register_operand" "")))
3558    (clobber (reg:CC FLAGS_REG))]
3559   "reload_completed
3560    && true_regnum (operands[0]) == true_regnum (operands[1])"
3561   [(parallel [(set (match_dup 0) (and:SWI24 (match_dup 0) (const_int 255)))
3562               (clobber (reg:CC FLAGS_REG))])])
3563 \f
3564 ;; Sign extension instructions
3565
3566 (define_expand "extendsidi2"
3567   [(set (match_operand:DI 0 "register_operand" "")
3568         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))]
3569   ""
3570 {
3571   if (!TARGET_64BIT)
3572     {
3573       emit_insn (gen_extendsidi2_1 (operands[0], operands[1]));
3574       DONE;
3575     }
3576 })
3577
3578 (define_insn "*extendsidi2_rex64"
3579   [(set (match_operand:DI 0 "register_operand" "=*a,r")
3580         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "*0,rm")))]
3581   "TARGET_64BIT"
3582   "@
3583    {cltq|cdqe}
3584    movs{lq|x}\t{%1, %0|%0, %1}"
3585   [(set_attr "type" "imovx")
3586    (set_attr "mode" "DI")
3587    (set_attr "prefix_0f" "0")
3588    (set_attr "modrm" "0,1")])
3589
3590 (define_insn "extendsidi2_1"
3591   [(set (match_operand:DI 0 "nonimmediate_operand" "=*A,r,?r,?*o")
3592         (sign_extend:DI (match_operand:SI 1 "register_operand" "0,0,r,r")))
3593    (clobber (reg:CC FLAGS_REG))
3594    (clobber (match_scratch:SI 2 "=X,X,X,&r"))]
3595   "!TARGET_64BIT"
3596   "#")
3597
3598 ;; Extend to memory case when source register does die.
3599 (define_split
3600   [(set (match_operand:DI 0 "memory_operand" "")
3601         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3602    (clobber (reg:CC FLAGS_REG))
3603    (clobber (match_operand:SI 2 "register_operand" ""))]
3604   "(reload_completed
3605     && dead_or_set_p (insn, operands[1])
3606     && !reg_mentioned_p (operands[1], operands[0]))"
3607   [(set (match_dup 3) (match_dup 1))
3608    (parallel [(set (match_dup 1) (ashiftrt:SI (match_dup 1) (const_int 31)))
3609               (clobber (reg:CC FLAGS_REG))])
3610    (set (match_dup 4) (match_dup 1))]
3611   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3612
3613 ;; Extend to memory case when source register does not die.
3614 (define_split
3615   [(set (match_operand:DI 0 "memory_operand" "")
3616         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3617    (clobber (reg:CC FLAGS_REG))
3618    (clobber (match_operand:SI 2 "register_operand" ""))]
3619   "reload_completed"
3620   [(const_int 0)]
3621 {
3622   split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);
3623
3624   emit_move_insn (operands[3], operands[1]);
3625
3626   /* Generate a cltd if possible and doing so it profitable.  */
3627   if ((optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
3628       && true_regnum (operands[1]) == AX_REG
3629       && true_regnum (operands[2]) == DX_REG)
3630     {
3631       emit_insn (gen_ashrsi3_cvt (operands[2], operands[1], GEN_INT (31)));
3632     }
3633   else
3634     {
3635       emit_move_insn (operands[2], operands[1]);
3636       emit_insn (gen_ashrsi3_cvt (operands[2], operands[2], GEN_INT (31)));
3637     }
3638   emit_move_insn (operands[4], operands[2]);
3639   DONE;
3640 })
3641
3642 ;; Extend to register case.  Optimize case where source and destination
3643 ;; registers match and cases where we can use cltd.
3644 (define_split
3645   [(set (match_operand:DI 0 "register_operand" "")
3646         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3647    (clobber (reg:CC FLAGS_REG))
3648    (clobber (match_scratch:SI 2 ""))]
3649   "reload_completed"
3650   [(const_int 0)]
3651 {
3652   split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);
3653
3654   if (true_regnum (operands[3]) != true_regnum (operands[1]))
3655     emit_move_insn (operands[3], operands[1]);
3656
3657   /* Generate a cltd if possible and doing so it profitable.  */
3658   if ((optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
3659       && true_regnum (operands[3]) == AX_REG
3660       && true_regnum (operands[4]) == DX_REG)
3661     {
3662       emit_insn (gen_ashrsi3_cvt (operands[4], operands[3], GEN_INT (31)));
3663       DONE;
3664     }
3665
3666   if (true_regnum (operands[4]) != true_regnum (operands[1]))
3667     emit_move_insn (operands[4], operands[1]);
3668
3669   emit_insn (gen_ashrsi3_cvt (operands[4], operands[4], GEN_INT (31)));
3670   DONE;
3671 })
3672
3673 (define_insn "extend<mode>di2"
3674   [(set (match_operand:DI 0 "register_operand" "=r")
3675         (sign_extend:DI
3676          (match_operand:SWI12 1 "nonimmediate_operand" "<r>m")))]
3677   "TARGET_64BIT"
3678   "movs{<imodesuffix>q|x}\t{%1, %0|%0, %1}"
3679   [(set_attr "type" "imovx")
3680    (set_attr "mode" "DI")])
3681
3682 (define_insn "extendhisi2"
3683   [(set (match_operand:SI 0 "register_operand" "=*a,r")
3684         (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "*0,rm")))]
3685   ""
3686 {
3687   switch (get_attr_prefix_0f (insn))
3688     {
3689     case 0:
3690       return "{cwtl|cwde}";
3691     default:
3692       return "movs{wl|x}\t{%1, %0|%0, %1}";
3693     }
3694 }
3695   [(set_attr "type" "imovx")
3696    (set_attr "mode" "SI")
3697    (set (attr "prefix_0f")
3698      ;; movsx is short decodable while cwtl is vector decoded.
3699      (if_then_else (and (eq_attr "cpu" "!k6")
3700                         (eq_attr "alternative" "0"))
3701         (const_string "0")
3702         (const_string "1")))
3703    (set (attr "modrm")
3704      (if_then_else (eq_attr "prefix_0f" "0")
3705         (const_string "0")
3706         (const_string "1")))])
3707
3708 (define_insn "*extendhisi2_zext"
3709   [(set (match_operand:DI 0 "register_operand" "=*a,r")
3710         (zero_extend:DI
3711          (sign_extend:SI
3712           (match_operand:HI 1 "nonimmediate_operand" "*0,rm"))))]
3713   "TARGET_64BIT"
3714 {
3715   switch (get_attr_prefix_0f (insn))
3716     {
3717     case 0:
3718       return "{cwtl|cwde}";
3719     default:
3720       return "movs{wl|x}\t{%1, %k0|%k0, %1}";
3721     }
3722 }
3723   [(set_attr "type" "imovx")
3724    (set_attr "mode" "SI")
3725    (set (attr "prefix_0f")
3726      ;; movsx is short decodable while cwtl is vector decoded.
3727      (if_then_else (and (eq_attr "cpu" "!k6")
3728                         (eq_attr "alternative" "0"))
3729         (const_string "0")
3730         (const_string "1")))
3731    (set (attr "modrm")
3732      (if_then_else (eq_attr "prefix_0f" "0")
3733         (const_string "0")
3734         (const_string "1")))])
3735
3736 (define_insn "extendqisi2"
3737   [(set (match_operand:SI 0 "register_operand" "=r")
3738         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3739   ""
3740   "movs{bl|x}\t{%1, %0|%0, %1}"
3741    [(set_attr "type" "imovx")
3742     (set_attr "mode" "SI")])
3743
3744 (define_insn "*extendqisi2_zext"
3745   [(set (match_operand:DI 0 "register_operand" "=r")
3746         (zero_extend:DI
3747           (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm"))))]
3748   "TARGET_64BIT"
3749   "movs{bl|x}\t{%1, %k0|%k0, %1}"
3750    [(set_attr "type" "imovx")
3751     (set_attr "mode" "SI")])
3752
3753 (define_insn "extendqihi2"
3754   [(set (match_operand:HI 0 "register_operand" "=*a,r")
3755         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "*0,qm")))]
3756   ""
3757 {
3758   switch (get_attr_prefix_0f (insn))
3759     {
3760     case 0:
3761       return "{cbtw|cbw}";
3762     default:
3763       return "movs{bw|x}\t{%1, %0|%0, %1}";
3764     }
3765 }
3766   [(set_attr "type" "imovx")
3767    (set_attr "mode" "HI")
3768    (set (attr "prefix_0f")
3769      ;; movsx is short decodable while cwtl is vector decoded.
3770      (if_then_else (and (eq_attr "cpu" "!k6")
3771                         (eq_attr "alternative" "0"))
3772         (const_string "0")
3773         (const_string "1")))
3774    (set (attr "modrm")
3775      (if_then_else (eq_attr "prefix_0f" "0")
3776         (const_string "0")
3777         (const_string "1")))])
3778 \f
3779 ;; Conversions between float and double.
3780
3781 ;; These are all no-ops in the model used for the 80387.
3782 ;; So just emit moves.
3783
3784 ;; %%% Kill these when call knows how to work out a DFmode push earlier.
3785 (define_split
3786   [(set (match_operand:DF 0 "push_operand" "")
3787         (float_extend:DF (match_operand:SF 1 "fp_register_operand" "")))]
3788   "reload_completed"
3789   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -8)))
3790    (set (mem:DF (reg:P SP_REG)) (float_extend:DF (match_dup 1)))])
3791
3792 (define_split
3793   [(set (match_operand:XF 0 "push_operand" "")
3794         (float_extend:XF (match_operand:MODEF 1 "fp_register_operand" "")))]
3795   "reload_completed"
3796   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
3797    (set (mem:XF (reg:P SP_REG)) (float_extend:XF (match_dup 1)))]
3798   "operands[2] = GEN_INT (-GET_MODE_SIZE (XFmode));")
3799
3800 (define_expand "extendsfdf2"
3801   [(set (match_operand:DF 0 "nonimmediate_operand" "")
3802         (float_extend:DF (match_operand:SF 1 "general_operand" "")))]
3803   "TARGET_80387 || (TARGET_SSE2 && TARGET_SSE_MATH)"
3804 {
3805   /* ??? Needed for compress_float_constant since all fp constants
3806      are TARGET_LEGITIMATE_CONSTANT_P.  */
3807   if (GET_CODE (operands[1]) == CONST_DOUBLE)
3808     {
3809       if ((!TARGET_SSE2 || TARGET_MIX_SSE_I387)
3810           && standard_80387_constant_p (operands[1]) > 0)
3811         {
3812           operands[1] = simplify_const_unary_operation
3813             (FLOAT_EXTEND, DFmode, operands[1], SFmode);
3814           emit_move_insn_1 (operands[0], operands[1]);
3815           DONE;
3816         }
3817       operands[1] = validize_mem (force_const_mem (SFmode, operands[1]));
3818     }
3819 })
3820
3821 /* For converting SF(xmm2) to DF(xmm1), use the following code instead of
3822    cvtss2sd:
3823       unpcklps xmm2,xmm2   ; packed conversion might crash on signaling NaNs
3824       cvtps2pd xmm2,xmm1
3825    We do the conversion post reload to avoid producing of 128bit spills
3826    that might lead to ICE on 32bit target.  The sequence unlikely combine
3827    anyway.  */
3828 (define_split
3829   [(set (match_operand:DF 0 "register_operand" "")
3830         (float_extend:DF
3831           (match_operand:SF 1 "nonimmediate_operand" "")))]
3832   "TARGET_USE_VECTOR_FP_CONVERTS
3833    && optimize_insn_for_speed_p ()
3834    && reload_completed && SSE_REG_P (operands[0])"
3835    [(set (match_dup 2)
3836          (float_extend:V2DF
3837            (vec_select:V2SF
3838              (match_dup 3)
3839              (parallel [(const_int 0) (const_int 1)]))))]
3840 {
3841   operands[2] = simplify_gen_subreg (V2DFmode, operands[0], DFmode, 0);
3842   operands[3] = simplify_gen_subreg (V4SFmode, operands[0], DFmode, 0);
3843   /* Use movss for loading from memory, unpcklps reg, reg for registers.
3844      Try to avoid move when unpacking can be done in source.  */
3845   if (REG_P (operands[1]))
3846     {
3847       /* If it is unsafe to overwrite upper half of source, we need
3848          to move to destination and unpack there.  */
3849       if ((ORIGINAL_REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
3850            || PSEUDO_REGNO_BYTES (ORIGINAL_REGNO (operands[1])) > 4)
3851           && true_regnum (operands[0]) != true_regnum (operands[1]))
3852         {
3853           rtx tmp = gen_rtx_REG (SFmode, true_regnum (operands[0]));
3854           emit_move_insn (tmp, operands[1]);
3855         }
3856       else
3857         operands[3] = simplify_gen_subreg (V4SFmode, operands[1], SFmode, 0);
3858       emit_insn (gen_vec_interleave_lowv4sf (operands[3], operands[3],
3859                                              operands[3]));
3860     }
3861   else
3862     emit_insn (gen_vec_setv4sf_0 (operands[3],
3863                                   CONST0_RTX (V4SFmode), operands[1]));
3864 })
3865
3866 (define_insn "*extendsfdf2_mixed"
3867   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,m,x")
3868         (float_extend:DF
3869           (match_operand:SF 1 "nonimmediate_operand" "fm,f,xm")))]
3870   "TARGET_SSE2 && TARGET_MIX_SSE_I387"
3871 {
3872   switch (which_alternative)
3873     {
3874     case 0:
3875     case 1:
3876       return output_387_reg_move (insn, operands);
3877
3878     case 2:
3879       return "%vcvtss2sd\t{%1, %d0|%d0, %1}";
3880
3881     default:
3882       gcc_unreachable ();
3883     }
3884 }
3885   [(set_attr "type" "fmov,fmov,ssecvt")
3886    (set_attr "prefix" "orig,orig,maybe_vex")
3887    (set_attr "mode" "SF,XF,DF")])
3888
3889 (define_insn "*extendsfdf2_sse"
3890   [(set (match_operand:DF 0 "nonimmediate_operand" "=x")
3891         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "xm")))]
3892   "TARGET_SSE2 && TARGET_SSE_MATH"
3893   "%vcvtss2sd\t{%1, %d0|%d0, %1}"
3894   [(set_attr "type" "ssecvt")
3895    (set_attr "prefix" "maybe_vex")
3896    (set_attr "mode" "DF")])
3897
3898 (define_insn "*extendsfdf2_i387"
3899   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,m")
3900         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "fm,f")))]
3901   "TARGET_80387"
3902   "* return output_387_reg_move (insn, operands);"
3903   [(set_attr "type" "fmov")
3904    (set_attr "mode" "SF,XF")])
3905
3906 (define_expand "extend<mode>xf2"
3907   [(set (match_operand:XF 0 "nonimmediate_operand" "")
3908         (float_extend:XF (match_operand:MODEF 1 "general_operand" "")))]
3909   "TARGET_80387"
3910 {
3911   /* ??? Needed for compress_float_constant since all fp constants
3912      are TARGET_LEGITIMATE_CONSTANT_P.  */
3913   if (GET_CODE (operands[1]) == CONST_DOUBLE)
3914     {
3915       if (standard_80387_constant_p (operands[1]) > 0)
3916         {
3917           operands[1] = simplify_const_unary_operation
3918             (FLOAT_EXTEND, XFmode, operands[1], <MODE>mode);
3919           emit_move_insn_1 (operands[0], operands[1]);
3920           DONE;