OSDN Git Service

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