OSDN Git Service

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