OSDN Git Service

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