OSDN Git Service

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