OSDN Git Service

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