OSDN Git Service

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