OSDN Git Service

b0c4c83f825dec467a459e51622e1c0f2f8a4faa
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / i386.md
1 ;; GCC machine description for IA-32 and x86-64.
2 ;; Copyright (C) 1988, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 ;; Free Software Foundation, Inc.
5 ;; Mostly by William Schelter.
6 ;; x86_64 support added by Jan Hubicka
7 ;;
8 ;; This file is part of GCC.
9 ;;
10 ;; GCC is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
13 ;; any later version.
14 ;;
15 ;; GCC is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19 ;;
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GCC; see the file COPYING3.  If not see
22 ;; <http://www.gnu.org/licenses/>.  */
23 ;;
24 ;; The original PO technology requires these to be ordered by speed,
25 ;; so that assigner will pick the fastest.
26 ;;
27 ;; See file "rtl.def" for documentation on define_insn, match_*, et. al.
28 ;;
29 ;; The special asm out single letter directives following a '%' are:
30 ;; L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
31 ;; C -- print opcode suffix for set/cmov insn.
32 ;; c -- like C, but print reversed condition
33 ;; F,f -- likewise, but for floating-point.
34 ;; O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
35 ;;      otherwise nothing
36 ;; R -- print the prefix for register names.
37 ;; z -- print the opcode suffix for the size of the current operand.
38 ;; Z -- likewise, with special suffixes for x87 instructions.
39 ;; * -- print a star (in certain assembler syntax)
40 ;; A -- print an absolute memory reference.
41 ;; w -- print the operand as if it's a "word" (HImode) even if it isn't.
42 ;; s -- print a shift double count, followed by the assemblers argument
43 ;;      delimiter.
44 ;; b -- print the QImode name of the register for the indicated operand.
45 ;;      %b0 would print %al if operands[0] is reg 0.
46 ;; w --  likewise, print the HImode name of the register.
47 ;; k --  likewise, print the SImode name of the register.
48 ;; q --  likewise, print the DImode name of the register.
49 ;; x --  likewise, print the V4SFmode name of the register.
50 ;; t --  likewise, print the V8SFmode name of the register.
51 ;; h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
52 ;; y -- print "st(0)" instead of "st" as a register.
53 ;; d -- print duplicated register operand for AVX instruction.
54 ;; D -- print condition for SSE cmp instruction.
55 ;; P -- if PIC, print an @PLT suffix.
56 ;; X -- don't print any sort of PIC '@' suffix for a symbol.
57 ;; & -- print some in-use local-dynamic symbol name.
58 ;; H -- print a memory address offset by 8; used for sse high-parts
59 ;; Y -- print condition for XOP pcom* instruction.
60 ;; + -- print a branch hint as 'cs' or 'ds' prefix
61 ;; ; -- print a semicolon (after prefixes due to bug in older gas).
62 ;; @ -- print a segment register of thread base pointer load
63
64 ;; UNSPEC usage:
65
66 (define_c_enum "unspec" [
67   ;; Relocation specifiers
68   UNSPEC_GOT
69   UNSPEC_GOTOFF
70   UNSPEC_GOTPCREL
71   UNSPEC_GOTTPOFF
72   UNSPEC_TPOFF
73   UNSPEC_NTPOFF
74   UNSPEC_DTPOFF
75   UNSPEC_GOTNTPOFF
76   UNSPEC_INDNTPOFF
77   UNSPEC_PLTOFF
78   UNSPEC_MACHOPIC_OFFSET
79   UNSPEC_PCREL
80
81   ;; Prologue support
82   UNSPEC_STACK_ALLOC
83   UNSPEC_SET_GOT
84   UNSPEC_REG_SAVE
85   UNSPEC_DEF_CFA
86   UNSPEC_SET_RIP
87   UNSPEC_SET_GOT_OFFSET
88   UNSPEC_MEMORY_BLOCKAGE
89   UNSPEC_STACK_CHECK
90
91   ;; TLS support
92   UNSPEC_TP
93   UNSPEC_TLS_GD
94   UNSPEC_TLS_LD_BASE
95   UNSPEC_TLSDESC
96   UNSPEC_TLS_IE_SUN
97
98   ;; Other random patterns
99   UNSPEC_SCAS
100   UNSPEC_FNSTSW
101   UNSPEC_SAHF
102   UNSPEC_PARITY
103   UNSPEC_FSTCW
104   UNSPEC_ADD_CARRY
105   UNSPEC_FLDCW
106   UNSPEC_REP
107   UNSPEC_LD_MPIC        ; load_macho_picbase
108   UNSPEC_TRUNC_NOOP
109   UNSPEC_DIV_ALREADY_SPLIT
110   UNSPEC_CALL_NEEDS_VZEROUPPER
111
112   ;; For SSE/MMX support:
113   UNSPEC_FIX_NOTRUNC
114   UNSPEC_MASKMOV
115   UNSPEC_MOVMSK
116   UNSPEC_MOVNT
117   UNSPEC_MOVU
118   UNSPEC_RCP
119   UNSPEC_RSQRT
120   UNSPEC_SFENCE
121   UNSPEC_PFRCP
122   UNSPEC_PFRCPIT1
123   UNSPEC_PFRCPIT2
124   UNSPEC_PFRSQRT
125   UNSPEC_PFRSQIT1
126   UNSPEC_MFENCE
127   UNSPEC_LFENCE
128   UNSPEC_PSADBW
129   UNSPEC_LDDQU
130   UNSPEC_MS_TO_SYSV_CALL
131
132   ;; Generic math support
133   UNSPEC_COPYSIGN
134   UNSPEC_IEEE_MIN       ; not commutative
135   UNSPEC_IEEE_MAX       ; not commutative
136
137   ;; x87 Floating point
138   UNSPEC_SIN
139   UNSPEC_COS
140   UNSPEC_FPATAN
141   UNSPEC_FYL2X
142   UNSPEC_FYL2XP1
143   UNSPEC_FRNDINT
144   UNSPEC_FIST
145   UNSPEC_F2XM1
146   UNSPEC_TAN
147   UNSPEC_FXAM
148
149   ;; x87 Rounding
150   UNSPEC_FRNDINT_FLOOR
151   UNSPEC_FRNDINT_CEIL
152   UNSPEC_FRNDINT_TRUNC
153   UNSPEC_FRNDINT_MASK_PM
154   UNSPEC_FIST_FLOOR
155   UNSPEC_FIST_CEIL
156
157   ;; x87 Double output FP
158   UNSPEC_SINCOS_COS
159   UNSPEC_SINCOS_SIN
160   UNSPEC_XTRACT_FRACT
161   UNSPEC_XTRACT_EXP
162   UNSPEC_FSCALE_FRACT
163   UNSPEC_FSCALE_EXP
164   UNSPEC_FPREM_F
165   UNSPEC_FPREM_U
166   UNSPEC_FPREM1_F
167   UNSPEC_FPREM1_U
168
169   UNSPEC_C2_FLAG
170   UNSPEC_FXAM_MEM
171
172   ;; SSP patterns
173   UNSPEC_SP_SET
174   UNSPEC_SP_TEST
175   UNSPEC_SP_TLS_SET
176   UNSPEC_SP_TLS_TEST
177
178   ;; SSSE3
179   UNSPEC_PSHUFB
180   UNSPEC_PSIGN
181   UNSPEC_PALIGNR
182
183   ;; For SSE4A support
184   UNSPEC_EXTRQI
185   UNSPEC_EXTRQ
186   UNSPEC_INSERTQI
187   UNSPEC_INSERTQ
188
189   ;; For SSE4.1 support
190   UNSPEC_BLENDV
191   UNSPEC_INSERTPS
192   UNSPEC_DP
193   UNSPEC_MOVNTDQA
194   UNSPEC_MPSADBW
195   UNSPEC_PHMINPOSUW
196   UNSPEC_PTEST
197   UNSPEC_ROUND
198
199   ;; For SSE4.2 support
200   UNSPEC_CRC32
201   UNSPEC_PCMPESTR
202   UNSPEC_PCMPISTR
203
204   ;; For FMA4 support
205   UNSPEC_FMADDSUB
206   UNSPEC_XOP_UNSIGNED_CMP
207   UNSPEC_XOP_TRUEFALSE
208   UNSPEC_XOP_PERMUTE
209   UNSPEC_FRCZ
210
211   ;; For AES support
212   UNSPEC_AESENC
213   UNSPEC_AESENCLAST
214   UNSPEC_AESDEC
215   UNSPEC_AESDECLAST
216   UNSPEC_AESIMC
217   UNSPEC_AESKEYGENASSIST
218
219   ;; For PCLMUL support
220   UNSPEC_PCLMUL
221
222   ;; For AVX support
223   UNSPEC_PCMP
224   UNSPEC_VPERMIL
225   UNSPEC_VPERMIL2
226   UNSPEC_VPERMIL2F128
227   UNSPEC_CAST
228   UNSPEC_VTESTP
229   UNSPEC_VCVTPH2PS
230   UNSPEC_VCVTPS2PH
231
232   ;; For BMI support
233   UNSPEC_BEXTR
234
235   ;; For RDRAND support
236   UNSPEC_RDRAND
237 ])
238
239 (define_c_enum "unspecv" [
240   UNSPECV_BLOCKAGE
241   UNSPECV_STACK_PROBE
242   UNSPECV_PROBE_STACK_RANGE
243   UNSPECV_EMMS
244   UNSPECV_LDMXCSR
245   UNSPECV_STMXCSR
246   UNSPECV_FEMMS
247   UNSPECV_CLFLUSH
248   UNSPECV_ALIGN
249   UNSPECV_MONITOR
250   UNSPECV_MWAIT
251   UNSPECV_CMPXCHG
252   UNSPECV_XCHG
253   UNSPECV_LOCK
254   UNSPECV_PROLOGUE_USE
255   UNSPECV_CLD
256   UNSPECV_NOPS
257   UNSPECV_VZEROALL
258   UNSPECV_VZEROUPPER
259   UNSPECV_RDTSC
260   UNSPECV_RDTSCP
261   UNSPECV_RDPMC
262   UNSPECV_LLWP_INTRINSIC
263   UNSPECV_SLWP_INTRINSIC
264   UNSPECV_LWPVAL_INTRINSIC
265   UNSPECV_LWPINS_INTRINSIC
266   UNSPECV_RDFSBASE
267   UNSPECV_RDGSBASE
268   UNSPECV_WRFSBASE
269   UNSPECV_WRGSBASE
270   UNSPECV_SPLIT_STACK_RETURN
271 ])
272
273 ;; Constants to represent rounding modes in the ROUND instruction
274 (define_constants
275   [(ROUND_FLOOR                 0x1)
276    (ROUND_CEIL                  0x2)
277    (ROUND_TRUNC                 0x3)
278    (ROUND_MXCSR                 0x4)
279    (ROUND_NO_EXC                0x8)
280   ])
281
282 ;; Constants to represent pcomtrue/pcomfalse variants
283 (define_constants
284   [(PCOM_FALSE                  0)
285    (PCOM_TRUE                   1)
286    (COM_FALSE_S                 2)
287    (COM_FALSE_P                 3)
288    (COM_TRUE_S                  4)
289    (COM_TRUE_P                  5)
290   ])
291
292 ;; Constants used in the XOP pperm instruction
293 (define_constants
294   [(PPERM_SRC                   0x00)   /* copy source */
295    (PPERM_INVERT                0x20)   /* invert source */
296    (PPERM_REVERSE               0x40)   /* bit reverse source */
297    (PPERM_REV_INV               0x60)   /* bit reverse & invert src */
298    (PPERM_ZERO                  0x80)   /* all 0's */
299    (PPERM_ONES                  0xa0)   /* all 1's */
300    (PPERM_SIGN                  0xc0)   /* propagate sign bit */
301    (PPERM_INV_SIGN              0xe0)   /* invert & propagate sign */
302    (PPERM_SRC1                  0x00)   /* use first source byte */
303    (PPERM_SRC2                  0x10)   /* use second source byte */
304    ])
305
306 ;; Registers by name.
307 (define_constants
308   [(AX_REG                       0)
309    (DX_REG                       1)
310    (CX_REG                       2)
311    (BX_REG                       3)
312    (SI_REG                       4)
313    (DI_REG                       5)
314    (BP_REG                       6)
315    (SP_REG                       7)
316    (ST0_REG                      8)
317    (ST1_REG                      9)
318    (ST2_REG                     10)
319    (ST3_REG                     11)
320    (ST4_REG                     12)
321    (ST5_REG                     13)
322    (ST6_REG                     14)
323    (ST7_REG                     15)
324    (FLAGS_REG                   17)
325    (FPSR_REG                    18)
326    (FPCR_REG                    19)
327    (XMM0_REG                    21)
328    (XMM1_REG                    22)
329    (XMM2_REG                    23)
330    (XMM3_REG                    24)
331    (XMM4_REG                    25)
332    (XMM5_REG                    26)
333    (XMM6_REG                    27)
334    (XMM7_REG                    28)
335    (MM0_REG                     29)
336    (MM1_REG                     30)
337    (MM2_REG                     31)
338    (MM3_REG                     32)
339    (MM4_REG                     33)
340    (MM5_REG                     34)
341    (MM6_REG                     35)
342    (MM7_REG                     36)
343    (R8_REG                      37)
344    (R9_REG                      38)
345    (R10_REG                     39)
346    (R11_REG                     40)
347    (R12_REG                     41)
348    (R13_REG                     42)
349    (XMM8_REG                    45)
350    (XMM9_REG                    46)
351    (XMM10_REG                   47)
352    (XMM11_REG                   48)
353    (XMM12_REG                   49)
354    (XMM13_REG                   50)
355    (XMM14_REG                   51)
356    (XMM15_REG                   52)
357   ])
358
359 ;; Insns whose names begin with "x86_" are emitted by gen_FOO calls
360 ;; from i386.c.
361
362 ;; In C guard expressions, put expressions which may be compile-time
363 ;; constants first.  This allows for better optimization.  For
364 ;; example, write "TARGET_64BIT && reload_completed", not
365 ;; "reload_completed && TARGET_64BIT".
366
367 \f
368 ;; Processor type.
369 (define_attr "cpu" "none,pentium,pentiumpro,geode,k6,athlon,k8,core2,corei7,
370                     atom,generic64,amdfam10,bdver1,btver1"
371   (const (symbol_ref "ix86_schedule")))
372
373 ;; A basic instruction type.  Refinements due to arguments to be
374 ;; provided in other attributes.
375 (define_attr "type"
376   "other,multi,
377    alu,alu1,negnot,imov,imovx,lea,
378    incdec,ishift,ishift1,rotate,rotate1,imul,idiv,
379    icmp,test,ibr,setcc,icmov,
380    push,pop,call,callv,leave,
381    str,bitmanip,
382    fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,fxch,fistp,fisttp,frndint,
383    sselog,sselog1,sseiadd,sseiadd1,sseishft,sseishft1,sseimul,
384    sse,ssemov,sseadd,ssemul,ssecmp,ssecomi,ssecvt,ssecvt1,sseicvt,ssediv,sseins,
385    ssemuladd,sse4arg,lwp,
386    mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft"
387   (const_string "other"))
388
389 ;; Main data type used by the insn
390 (define_attr "mode"
391   "unknown,none,QI,HI,SI,DI,TI,OI,SF,DF,XF,TF,V8SF,V4DF,V4SF,V2DF,V2SF,V1DF"
392   (const_string "unknown"))
393
394 ;; The CPU unit operations uses.
395 (define_attr "unit" "integer,i387,sse,mmx,unknown"
396   (cond [(eq_attr "type" "fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,fxch,fistp,fisttp,frndint")
397            (const_string "i387")
398          (eq_attr "type" "sselog,sselog1,sseiadd,sseiadd1,sseishft,sseishft1,sseimul,
399                           sse,ssemov,sseadd,ssemul,ssecmp,ssecomi,ssecvt,
400                           ssecvt1,sseicvt,ssediv,sseins,ssemuladd,sse4arg")
401            (const_string "sse")
402          (eq_attr "type" "mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft")
403            (const_string "mmx")
404          (eq_attr "type" "other")
405            (const_string "unknown")]
406          (const_string "integer")))
407
408 ;; The (bounding maximum) length of an instruction immediate.
409 (define_attr "length_immediate" ""
410   (cond [(eq_attr "type" "incdec,setcc,icmov,str,lea,other,multi,idiv,leave,
411                           bitmanip")
412            (const_int 0)
413          (eq_attr "unit" "i387,sse,mmx")
414            (const_int 0)
415          (eq_attr "type" "alu,alu1,negnot,imovx,ishift,rotate,ishift1,rotate1,
416                           imul,icmp,push,pop")
417            (symbol_ref "ix86_attr_length_immediate_default(insn,1)")
418          (eq_attr "type" "imov,test")
419            (symbol_ref "ix86_attr_length_immediate_default(insn,0)")
420          (eq_attr "type" "call")
421            (if_then_else (match_operand 0 "constant_call_address_operand" "")
422              (const_int 4)
423              (const_int 0))
424          (eq_attr "type" "callv")
425            (if_then_else (match_operand 1 "constant_call_address_operand" "")
426              (const_int 4)
427              (const_int 0))
428          ;; We don't know the size before shorten_branches.  Expect
429          ;; the instruction to fit for better scheduling.
430          (eq_attr "type" "ibr")
431            (const_int 1)
432          ]
433          (symbol_ref "/* Update immediate_length and other attributes! */
434                       gcc_unreachable (),1")))
435
436 ;; The (bounding maximum) length of an instruction address.
437 (define_attr "length_address" ""
438   (cond [(eq_attr "type" "str,other,multi,fxch")
439            (const_int 0)
440          (and (eq_attr "type" "call")
441               (match_operand 0 "constant_call_address_operand" ""))
442              (const_int 0)
443          (and (eq_attr "type" "callv")
444               (match_operand 1 "constant_call_address_operand" ""))
445              (const_int 0)
446          ]
447          (symbol_ref "ix86_attr_length_address_default (insn)")))
448
449 ;; Set when length prefix is used.
450 (define_attr "prefix_data16" ""
451   (cond [(eq_attr "type" "ssemuladd,sse4arg,sseiadd1,ssecvt1")
452            (const_int 0)
453          (eq_attr "mode" "HI")
454            (const_int 1)
455          (and (eq_attr "unit" "sse") (eq_attr "mode" "V2DF,TI"))
456            (const_int 1)
457         ]
458         (const_int 0)))
459
460 ;; Set when string REP prefix is used.
461 (define_attr "prefix_rep" ""
462   (cond [(eq_attr "type" "ssemuladd,sse4arg,sseiadd1,ssecvt1")
463            (const_int 0)
464          (and (eq_attr "unit" "sse") (eq_attr "mode" "SF,DF"))
465            (const_int 1)
466         ]
467         (const_int 0)))
468
469 ;; Set when 0f opcode prefix is used.
470 (define_attr "prefix_0f" ""
471   (if_then_else
472     (ior (eq_attr "type" "imovx,setcc,icmov,bitmanip")
473          (eq_attr "unit" "sse,mmx"))
474     (const_int 1)
475     (const_int 0)))
476
477 ;; Set when REX opcode prefix is used.
478 (define_attr "prefix_rex" ""
479   (cond [(eq (symbol_ref "TARGET_64BIT") (const_int 0))
480            (const_int 0)
481          (and (eq_attr "mode" "DI")
482               (and (eq_attr "type" "!push,pop,call,callv,leave,ibr")
483                    (eq_attr "unit" "!mmx")))
484            (const_int 1)
485          (and (eq_attr "mode" "QI")
486               (ne (symbol_ref "x86_extended_QIreg_mentioned_p (insn)")
487                   (const_int 0)))
488            (const_int 1)
489          (ne (symbol_ref "x86_extended_reg_mentioned_p (insn)")
490              (const_int 0))
491            (const_int 1)
492          (and (eq_attr "type" "imovx")
493               (match_operand:QI 1 "ext_QIreg_operand" ""))
494            (const_int 1)
495         ]
496         (const_int 0)))
497
498 ;; There are also additional prefixes in 3DNOW, SSSE3.
499 ;; ssemuladd,sse4arg default to 0f24/0f25 and DREX byte,
500 ;; sseiadd1,ssecvt1 to 0f7a with no DREX byte.
501 ;; 3DNOW has 0f0f prefix, SSSE3 and SSE4_{1,2} 0f38/0f3a.
502 (define_attr "prefix_extra" ""
503   (cond [(eq_attr "type" "ssemuladd,sse4arg")
504            (const_int 2)
505          (eq_attr "type" "sseiadd1,ssecvt1")
506            (const_int 1)
507         ]
508         (const_int 0)))
509
510 ;; Prefix used: original, VEX or maybe VEX.
511 (define_attr "prefix" "orig,vex,maybe_vex"
512   (if_then_else (eq_attr "mode" "OI,V8SF,V4DF")
513     (const_string "vex")
514     (const_string "orig")))
515
516 ;; VEX W bit is used.
517 (define_attr "prefix_vex_w" "" (const_int 0))
518
519 ;; The length of VEX prefix
520 ;; Only instructions with 0f prefix can have 2 byte VEX prefix,
521 ;; 0f38/0f3a prefixes can't.  In i386.md 0f3[8a] is
522 ;; still prefix_0f 1, with prefix_extra 1.
523 (define_attr "length_vex" ""
524   (if_then_else (and (eq_attr "prefix_0f" "1")
525                      (eq_attr "prefix_extra" "0"))
526     (if_then_else (eq_attr "prefix_vex_w" "1")
527       (symbol_ref "ix86_attr_length_vex_default (insn, 1, 1)")
528       (symbol_ref "ix86_attr_length_vex_default (insn, 1, 0)"))
529     (if_then_else (eq_attr "prefix_vex_w" "1")
530       (symbol_ref "ix86_attr_length_vex_default (insn, 0, 1)")
531       (symbol_ref "ix86_attr_length_vex_default (insn, 0, 0)"))))
532
533 ;; Set when modrm byte is used.
534 (define_attr "modrm" ""
535   (cond [(eq_attr "type" "str,leave")
536            (const_int 0)
537          (eq_attr "unit" "i387")
538            (const_int 0)
539          (and (eq_attr "type" "incdec")
540               (and (eq (symbol_ref "TARGET_64BIT") (const_int 0))
541                    (ior (match_operand:SI 1 "register_operand" "")
542                         (match_operand:HI 1 "register_operand" ""))))
543            (const_int 0)
544          (and (eq_attr "type" "push")
545               (not (match_operand 1 "memory_operand" "")))
546            (const_int 0)
547          (and (eq_attr "type" "pop")
548               (not (match_operand 0 "memory_operand" "")))
549            (const_int 0)
550          (and (eq_attr "type" "imov")
551               (and (not (eq_attr "mode" "DI"))
552                    (ior (and (match_operand 0 "register_operand" "")
553                              (match_operand 1 "immediate_operand" ""))
554                         (ior (and (match_operand 0 "ax_reg_operand" "")
555                                   (match_operand 1 "memory_displacement_only_operand" ""))
556                              (and (match_operand 0 "memory_displacement_only_operand" "")
557                                   (match_operand 1 "ax_reg_operand" ""))))))
558            (const_int 0)
559          (and (eq_attr "type" "call")
560               (match_operand 0 "constant_call_address_operand" ""))
561              (const_int 0)
562          (and (eq_attr "type" "callv")
563               (match_operand 1 "constant_call_address_operand" ""))
564              (const_int 0)
565          (and (eq_attr "type" "alu,alu1,icmp,test")
566               (match_operand 0 "ax_reg_operand" ""))
567              (symbol_ref "(get_attr_length_immediate (insn) <= (get_attr_mode (insn) != MODE_QI))")
568          ]
569          (const_int 1)))
570
571 ;; The (bounding maximum) length of an instruction in bytes.
572 ;; ??? fistp and frndint are in fact fldcw/{fistp,frndint}/fldcw sequences.
573 ;; Later we may want to split them and compute proper length as for
574 ;; other insns.
575 (define_attr "length" ""
576   (cond [(eq_attr "type" "other,multi,fistp,frndint")
577            (const_int 16)
578          (eq_attr "type" "fcmp")
579            (const_int 4)
580          (eq_attr "unit" "i387")
581            (plus (const_int 2)
582                  (plus (attr "prefix_data16")
583                        (attr "length_address")))
584          (ior (eq_attr "prefix" "vex")
585               (and (eq_attr "prefix" "maybe_vex")
586                     (ne (symbol_ref "TARGET_AVX") (const_int 0))))
587            (plus (attr "length_vex")
588                  (plus (attr "length_immediate")
589                        (plus (attr "modrm")
590                              (attr "length_address"))))]
591          (plus (plus (attr "modrm")
592                      (plus (attr "prefix_0f")
593                            (plus (attr "prefix_rex")
594                                  (plus (attr "prefix_extra")
595                                        (const_int 1)))))
596                (plus (attr "prefix_rep")
597                      (plus (attr "prefix_data16")
598                            (plus (attr "length_immediate")
599                                  (attr "length_address")))))))
600
601 ;; The `memory' attribute is `none' if no memory is referenced, `load' or
602 ;; `store' if there is a simple memory reference therein, or `unknown'
603 ;; if the instruction is complex.
604
605 (define_attr "memory" "none,load,store,both,unknown"
606   (cond [(eq_attr "type" "other,multi,str,lwp")
607            (const_string "unknown")
608          (eq_attr "type" "lea,fcmov,fpspc")
609            (const_string "none")
610          (eq_attr "type" "fistp,leave")
611            (const_string "both")
612          (eq_attr "type" "frndint")
613            (const_string "load")
614          (eq_attr "type" "push")
615            (if_then_else (match_operand 1 "memory_operand" "")
616              (const_string "both")
617              (const_string "store"))
618          (eq_attr "type" "pop")
619            (if_then_else (match_operand 0 "memory_operand" "")
620              (const_string "both")
621              (const_string "load"))
622          (eq_attr "type" "setcc")
623            (if_then_else (match_operand 0 "memory_operand" "")
624              (const_string "store")
625              (const_string "none"))
626          (eq_attr "type" "icmp,test,ssecmp,ssecomi,mmxcmp,fcmp")
627            (if_then_else (ior (match_operand 0 "memory_operand" "")
628                               (match_operand 1 "memory_operand" ""))
629              (const_string "load")
630              (const_string "none"))
631          (eq_attr "type" "ibr")
632            (if_then_else (match_operand 0 "memory_operand" "")
633              (const_string "load")
634              (const_string "none"))
635          (eq_attr "type" "call")
636            (if_then_else (match_operand 0 "constant_call_address_operand" "")
637              (const_string "none")
638              (const_string "load"))
639          (eq_attr "type" "callv")
640            (if_then_else (match_operand 1 "constant_call_address_operand" "")
641              (const_string "none")
642              (const_string "load"))
643          (and (eq_attr "type" "alu1,negnot,ishift1,sselog1")
644               (match_operand 1 "memory_operand" ""))
645            (const_string "both")
646          (and (match_operand 0 "memory_operand" "")
647               (match_operand 1 "memory_operand" ""))
648            (const_string "both")
649          (match_operand 0 "memory_operand" "")
650            (const_string "store")
651          (match_operand 1 "memory_operand" "")
652            (const_string "load")
653          (and (eq_attr "type"
654                  "!alu1,negnot,ishift1,
655                    imov,imovx,icmp,test,bitmanip,
656                    fmov,fcmp,fsgn,
657                    sse,ssemov,ssecmp,ssecomi,ssecvt,ssecvt1,sseicvt,sselog1,
658                    sseiadd1,mmx,mmxmov,mmxcmp,mmxcvt")
659               (match_operand 2 "memory_operand" ""))
660            (const_string "load")
661          (and (eq_attr "type" "icmov,ssemuladd,sse4arg")
662               (match_operand 3 "memory_operand" ""))
663            (const_string "load")
664         ]
665         (const_string "none")))
666
667 ;; Indicates if an instruction has both an immediate and a displacement.
668
669 (define_attr "imm_disp" "false,true,unknown"
670   (cond [(eq_attr "type" "other,multi")
671            (const_string "unknown")
672          (and (eq_attr "type" "icmp,test,imov,alu1,ishift1,rotate1")
673               (and (match_operand 0 "memory_displacement_operand" "")
674                    (match_operand 1 "immediate_operand" "")))
675            (const_string "true")
676          (and (eq_attr "type" "alu,ishift,rotate,imul,idiv")
677               (and (match_operand 0 "memory_displacement_operand" "")
678                    (match_operand 2 "immediate_operand" "")))
679            (const_string "true")
680         ]
681         (const_string "false")))
682
683 ;; Indicates if an FP operation has an integer source.
684
685 (define_attr "fp_int_src" "false,true"
686   (const_string "false"))
687
688 ;; Defines rounding mode of an FP operation.
689
690 (define_attr "i387_cw" "trunc,floor,ceil,mask_pm,uninitialized,any"
691   (const_string "any"))
692
693 ;; Define attribute to classify add/sub insns that consumes carry flag (CF)
694 (define_attr "use_carry" "0,1" (const_string "0"))
695
696 ;; Define attribute to indicate unaligned ssemov insns
697 (define_attr "movu" "0,1" (const_string "0"))
698
699 ;; Used to control the "enabled" attribute on a per-instruction basis.
700 (define_attr "isa" "base,noavx,avx"
701   (const_string "base"))
702
703 (define_attr "enabled" ""
704   (cond [(eq_attr "isa" "noavx") (symbol_ref "!TARGET_AVX")
705          (eq_attr "isa" "avx") (symbol_ref "TARGET_AVX")
706         ]
707         (const_int 1)))
708
709 ;; Describe a user's asm statement.
710 (define_asm_attributes
711   [(set_attr "length" "128")
712    (set_attr "type" "multi")])
713
714 (define_code_iterator plusminus [plus minus])
715
716 (define_code_iterator sat_plusminus [ss_plus us_plus ss_minus us_minus])
717
718 ;; Base name for define_insn
719 (define_code_attr plusminus_insn
720   [(plus "add") (ss_plus "ssadd") (us_plus "usadd")
721    (minus "sub") (ss_minus "sssub") (us_minus "ussub")])
722
723 ;; Base name for insn mnemonic.
724 (define_code_attr plusminus_mnemonic
725   [(plus "add") (ss_plus "adds") (us_plus "addus")
726    (minus "sub") (ss_minus "subs") (us_minus "subus")])
727 (define_code_attr plusminus_carry_mnemonic
728   [(plus "adc") (minus "sbb")])
729
730 ;; Mark commutative operators as such in constraints.
731 (define_code_attr comm [(plus "%") (ss_plus "%") (us_plus "%")
732                         (minus "") (ss_minus "") (us_minus "")])
733
734 ;; Mapping of signed max and min
735 (define_code_iterator smaxmin [smax smin])
736
737 ;; Mapping of unsigned max and min
738 (define_code_iterator umaxmin [umax umin])
739
740 ;; Base name for integer and FP insn mnemonic
741 (define_code_attr maxmin_int [(smax "maxs") (smin "mins")
742                               (umax "maxu") (umin "minu")])
743 (define_code_attr maxmin_float [(smax "max") (smin "min")])
744
745 ;; Mapping of logic operators
746 (define_code_iterator any_logic [and ior xor])
747 (define_code_iterator any_or [ior xor])
748
749 ;; Base name for insn mnemonic.
750 (define_code_attr logic [(and "and") (ior "or") (xor "xor")])
751
752 ;; Mapping of shift-right operators
753 (define_code_iterator any_shiftrt [lshiftrt ashiftrt])
754
755 ;; Base name for define_insn
756 (define_code_attr shiftrt_insn [(lshiftrt "lshr") (ashiftrt "ashr")])
757
758 ;; Base name for insn mnemonic.
759 (define_code_attr shiftrt [(lshiftrt "shr") (ashiftrt "sar")])
760
761 ;; Mapping of rotate operators
762 (define_code_iterator any_rotate [rotate rotatert])
763
764 ;; Base name for define_insn
765 (define_code_attr rotate_insn [(rotate "rotl") (rotatert "rotr")])
766
767 ;; Base name for insn mnemonic.
768 (define_code_attr rotate [(rotate "rol") (rotatert "ror")])
769
770 ;; Mapping of abs neg operators
771 (define_code_iterator absneg [abs neg])
772
773 ;; Base name for x87 insn mnemonic.
774 (define_code_attr absneg_mnemonic [(abs "abs") (neg "chs")])
775
776 ;; Used in signed and unsigned widening multiplications.
777 (define_code_iterator any_extend [sign_extend zero_extend])
778
779 ;; Various insn prefixes for signed and unsigned operations.
780 (define_code_attr u [(sign_extend "") (zero_extend "u")
781                      (div "") (udiv "u")])
782 (define_code_attr s [(sign_extend "s") (zero_extend "u")])
783
784 ;; Used in signed and unsigned divisions.
785 (define_code_iterator any_div [div udiv])
786
787 ;; Instruction prefix for signed and unsigned operations.
788 (define_code_attr sgnprefix [(sign_extend "i") (zero_extend "")
789                              (div "i") (udiv "")])
790
791 ;; 64bit single word integer modes.
792 (define_mode_iterator SWI1248x [QI HI SI DI])
793
794 ;; 64bit single word integer modes without QImode and HImode.
795 (define_mode_iterator SWI48x [SI DI])
796
797 ;; Single word integer modes.
798 (define_mode_iterator SWI [QI HI SI (DI "TARGET_64BIT")])
799
800 ;; Single word integer modes without SImode and DImode.
801 (define_mode_iterator SWI12 [QI HI])
802
803 ;; Single word integer modes without DImode.
804 (define_mode_iterator SWI124 [QI HI SI])
805
806 ;; Single word integer modes without QImode and DImode.
807 (define_mode_iterator SWI24 [HI SI])
808
809 ;; Single word integer modes without QImode.
810 (define_mode_iterator SWI248 [HI SI (DI "TARGET_64BIT")])
811
812 ;; Single word integer modes without QImode and HImode.
813 (define_mode_iterator SWI48 [SI (DI "TARGET_64BIT")])
814
815 ;; All math-dependant single and double word integer modes.
816 (define_mode_iterator SDWIM [(QI "TARGET_QIMODE_MATH")
817                              (HI "TARGET_HIMODE_MATH")
818                              SI DI (TI "TARGET_64BIT")])
819
820 ;; Math-dependant single word integer modes.
821 (define_mode_iterator SWIM [(QI "TARGET_QIMODE_MATH")
822                             (HI "TARGET_HIMODE_MATH")
823                             SI (DI "TARGET_64BIT")])
824
825 ;; Math-dependant single word integer modes without DImode.
826 (define_mode_iterator SWIM124 [(QI "TARGET_QIMODE_MATH")
827                                (HI "TARGET_HIMODE_MATH")
828                                SI])
829
830 ;; Math-dependant single word integer modes without QImode.
831 (define_mode_iterator SWIM248 [(HI "TARGET_HIMODE_MATH")
832                                SI (DI "TARGET_64BIT")])
833
834 ;; Double word integer modes.
835 (define_mode_iterator DWI [(DI "!TARGET_64BIT")
836                            (TI "TARGET_64BIT")])
837
838 ;; Double word integer modes as mode attribute.
839 (define_mode_attr DWI [(SI "DI") (DI "TI")])
840 (define_mode_attr dwi [(SI "di") (DI "ti")])
841
842 ;; Half mode for double word integer modes.
843 (define_mode_iterator DWIH [(SI "!TARGET_64BIT")
844                             (DI "TARGET_64BIT")])
845
846 ;; Instruction suffix for integer modes.
847 (define_mode_attr imodesuffix [(QI "b") (HI "w") (SI "l") (DI "q")])
848
849 ;; Pointer size prefix for integer modes (Intel asm dialect)
850 (define_mode_attr iptrsize [(QI "BYTE")
851                             (HI "WORD")
852                             (SI "DWORD")
853                             (DI "QWORD")])
854
855 ;; Register class for integer modes.
856 (define_mode_attr r [(QI "q") (HI "r") (SI "r") (DI "r")])
857
858 ;; Immediate operand constraint for integer modes.
859 (define_mode_attr i [(QI "n") (HI "n") (SI "i") (DI "e")])
860
861 ;; General operand constraint for word modes.
862 (define_mode_attr g [(QI "qmn") (HI "rmn") (SI "g") (DI "rme")])
863
864 ;; Immediate operand constraint for double integer modes.
865 (define_mode_attr di [(SI "iF") (DI "e")])
866
867 ;; Immediate operand constraint for shifts.
868 (define_mode_attr S [(QI "I") (HI "I") (SI "I") (DI "J") (TI "O")])
869
870 ;; General operand predicate for integer modes.
871 (define_mode_attr general_operand
872         [(QI "general_operand")
873          (HI "general_operand")
874          (SI "general_operand")
875          (DI "x86_64_general_operand")
876          (TI "x86_64_general_operand")])
877
878 ;; General sign/zero extend operand predicate for integer modes.
879 (define_mode_attr general_szext_operand
880         [(QI "general_operand")
881          (HI "general_operand")
882          (SI "general_operand")
883          (DI "x86_64_szext_general_operand")])
884
885 ;; Immediate operand predicate for integer modes.
886 (define_mode_attr immediate_operand
887         [(QI "immediate_operand")
888          (HI "immediate_operand")
889          (SI "immediate_operand")
890          (DI "x86_64_immediate_operand")])
891
892 ;; Nonmemory operand predicate for integer modes.
893 (define_mode_attr nonmemory_operand
894         [(QI "nonmemory_operand")
895          (HI "nonmemory_operand")
896          (SI "nonmemory_operand")
897          (DI "x86_64_nonmemory_operand")])
898
899 ;; Operand predicate for shifts.
900 (define_mode_attr shift_operand
901         [(QI "nonimmediate_operand")
902          (HI "nonimmediate_operand")
903          (SI "nonimmediate_operand")
904          (DI "shiftdi_operand")
905          (TI "register_operand")])
906
907 ;; Operand predicate for shift argument.
908 (define_mode_attr shift_immediate_operand
909         [(QI "const_1_to_31_operand")
910          (HI "const_1_to_31_operand")
911          (SI "const_1_to_31_operand")
912          (DI "const_1_to_63_operand")])
913
914 ;; Input operand predicate for arithmetic left shifts.
915 (define_mode_attr ashl_input_operand
916         [(QI "nonimmediate_operand")
917          (HI "nonimmediate_operand")
918          (SI "nonimmediate_operand")
919          (DI "ashldi_input_operand")
920          (TI "reg_or_pm1_operand")])
921
922 ;; SSE and x87 SFmode and DFmode floating point modes
923 (define_mode_iterator MODEF [SF DF])
924
925 ;; All x87 floating point modes
926 (define_mode_iterator X87MODEF [SF DF XF])
927
928 ;; All integer modes handled by x87 fisttp operator.
929 (define_mode_iterator X87MODEI [HI SI DI])
930
931 ;; All integer modes handled by integer x87 operators.
932 (define_mode_iterator X87MODEI12 [HI SI])
933
934 ;; All integer modes handled by SSE cvtts?2si* operators.
935 (define_mode_iterator SSEMODEI24 [SI DI])
936
937 ;; SSE instruction suffix for various modes
938 (define_mode_attr ssemodesuffix
939   [(SF "ss") (DF "sd")
940    (V8SF "ps") (V4DF "pd")
941    (V4SF "ps") (V2DF "pd")
942    (V16QI "b") (V8HI "w") (V4SI "d") (V2DI "q")
943    (V8SI "si")])
944
945 ;; SSE vector suffix for floating point modes
946 (define_mode_attr ssevecmodesuffix [(SF "ps") (DF "pd")])
947
948 ;; SSE vector mode corresponding to a scalar mode
949 (define_mode_attr ssevecmode
950   [(QI "V16QI") (HI "V8HI") (SI "V4SI") (DI "V2DI") (SF "V4SF") (DF "V2DF")])
951
952 ;; Instruction suffix for REX 64bit operators.
953 (define_mode_attr rex64suffix [(SI "") (DI "{q}")])
954
955 ;; This mode iterator allows :P to be used for patterns that operate on
956 ;; pointer-sized quantities.  Exactly one of the two alternatives will match.
957 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
958 \f
959 ;; Scheduling descriptions
960
961 (include "pentium.md")
962 (include "ppro.md")
963 (include "k6.md")
964 (include "athlon.md")
965 (include "bdver1.md")
966 (include "geode.md")
967 (include "atom.md")
968 (include "core2.md")
969
970 \f
971 ;; Operand and operator predicates and constraints
972
973 (include "predicates.md")
974 (include "constraints.md")
975
976 \f
977 ;; Compare and branch/compare and store instructions.
978
979 (define_expand "cbranch<mode>4"
980   [(set (reg:CC FLAGS_REG)
981         (compare:CC (match_operand:SDWIM 1 "nonimmediate_operand" "")
982                     (match_operand:SDWIM 2 "<general_operand>" "")))
983    (set (pc) (if_then_else
984                (match_operator 0 "ordered_comparison_operator"
985                 [(reg:CC FLAGS_REG) (const_int 0)])
986                (label_ref (match_operand 3 "" ""))
987                (pc)))]
988   ""
989 {
990   if (MEM_P (operands[1]) && MEM_P (operands[2]))
991     operands[1] = force_reg (<MODE>mode, operands[1]);
992   ix86_expand_branch (GET_CODE (operands[0]),
993                       operands[1], operands[2], operands[3]);
994   DONE;
995 })
996
997 (define_expand "cstore<mode>4"
998   [(set (reg:CC FLAGS_REG)
999         (compare:CC (match_operand:SWIM 2 "nonimmediate_operand" "")
1000                     (match_operand:SWIM 3 "<general_operand>" "")))
1001    (set (match_operand:QI 0 "register_operand" "")
1002         (match_operator 1 "ordered_comparison_operator"
1003           [(reg:CC FLAGS_REG) (const_int 0)]))]
1004   ""
1005 {
1006   if (MEM_P (operands[2]) && MEM_P (operands[3]))
1007     operands[2] = force_reg (<MODE>mode, operands[2]);
1008   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1009                      operands[2], operands[3]);
1010   DONE;
1011 })
1012
1013 (define_expand "cmp<mode>_1"
1014   [(set (reg:CC FLAGS_REG)
1015         (compare:CC (match_operand:SWI48 0 "nonimmediate_operand" "")
1016                     (match_operand:SWI48 1 "<general_operand>" "")))])
1017
1018 (define_insn "*cmp<mode>_ccno_1"
1019   [(set (reg FLAGS_REG)
1020         (compare (match_operand:SWI 0 "nonimmediate_operand" "<r>,?m<r>")
1021                  (match_operand:SWI 1 "const0_operand" "")))]
1022   "ix86_match_ccmode (insn, CCNOmode)"
1023   "@
1024    test{<imodesuffix>}\t%0, %0
1025    cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
1026   [(set_attr "type" "test,icmp")
1027    (set_attr "length_immediate" "0,1")
1028    (set_attr "mode" "<MODE>")])
1029
1030 (define_insn "*cmp<mode>_1"
1031   [(set (reg FLAGS_REG)
1032         (compare (match_operand:SWI 0 "nonimmediate_operand" "<r>m,<r>")
1033                  (match_operand:SWI 1 "<general_operand>" "<r><i>,<r>m")))]
1034   "ix86_match_ccmode (insn, CCmode)"
1035   "cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
1036   [(set_attr "type" "icmp")
1037    (set_attr "mode" "<MODE>")])
1038
1039 (define_insn "*cmp<mode>_minus_1"
1040   [(set (reg FLAGS_REG)
1041         (compare
1042           (minus:SWI (match_operand:SWI 0 "nonimmediate_operand" "<r>m,<r>")
1043                      (match_operand:SWI 1 "<general_operand>" "<r><i>,<r>m"))
1044           (const_int 0)))]
1045   "ix86_match_ccmode (insn, CCGOCmode)"
1046   "cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
1047   [(set_attr "type" "icmp")
1048    (set_attr "mode" "<MODE>")])
1049
1050 (define_insn "*cmpqi_ext_1"
1051   [(set (reg FLAGS_REG)
1052         (compare
1053           (match_operand:QI 0 "general_operand" "Qm")
1054           (subreg:QI
1055             (zero_extract:SI
1056               (match_operand 1 "ext_register_operand" "Q")
1057               (const_int 8)
1058               (const_int 8)) 0)))]
1059   "!TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1060   "cmp{b}\t{%h1, %0|%0, %h1}"
1061   [(set_attr "type" "icmp")
1062    (set_attr "mode" "QI")])
1063
1064 (define_insn "*cmpqi_ext_1_rex64"
1065   [(set (reg FLAGS_REG)
1066         (compare
1067           (match_operand:QI 0 "register_operand" "Q")
1068           (subreg:QI
1069             (zero_extract:SI
1070               (match_operand 1 "ext_register_operand" "Q")
1071               (const_int 8)
1072               (const_int 8)) 0)))]
1073   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1074   "cmp{b}\t{%h1, %0|%0, %h1}"
1075   [(set_attr "type" "icmp")
1076    (set_attr "mode" "QI")])
1077
1078 (define_insn "*cmpqi_ext_2"
1079   [(set (reg FLAGS_REG)
1080         (compare
1081           (subreg:QI
1082             (zero_extract:SI
1083               (match_operand 0 "ext_register_operand" "Q")
1084               (const_int 8)
1085               (const_int 8)) 0)
1086           (match_operand:QI 1 "const0_operand" "")))]
1087   "ix86_match_ccmode (insn, CCNOmode)"
1088   "test{b}\t%h0, %h0"
1089   [(set_attr "type" "test")
1090    (set_attr "length_immediate" "0")
1091    (set_attr "mode" "QI")])
1092
1093 (define_expand "cmpqi_ext_3"
1094   [(set (reg:CC FLAGS_REG)
1095         (compare:CC
1096           (subreg:QI
1097             (zero_extract:SI
1098               (match_operand 0 "ext_register_operand" "")
1099               (const_int 8)
1100               (const_int 8)) 0)
1101           (match_operand:QI 1 "immediate_operand" "")))])
1102
1103 (define_insn "*cmpqi_ext_3_insn"
1104   [(set (reg FLAGS_REG)
1105         (compare
1106           (subreg:QI
1107             (zero_extract:SI
1108               (match_operand 0 "ext_register_operand" "Q")
1109               (const_int 8)
1110               (const_int 8)) 0)
1111           (match_operand:QI 1 "general_operand" "Qmn")))]
1112   "!TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1113   "cmp{b}\t{%1, %h0|%h0, %1}"
1114   [(set_attr "type" "icmp")
1115    (set_attr "modrm" "1")
1116    (set_attr "mode" "QI")])
1117
1118 (define_insn "*cmpqi_ext_3_insn_rex64"
1119   [(set (reg FLAGS_REG)
1120         (compare
1121           (subreg:QI
1122             (zero_extract:SI
1123               (match_operand 0 "ext_register_operand" "Q")
1124               (const_int 8)
1125               (const_int 8)) 0)
1126           (match_operand:QI 1 "nonmemory_operand" "Qn")))]
1127   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)"
1128   "cmp{b}\t{%1, %h0|%h0, %1}"
1129   [(set_attr "type" "icmp")
1130    (set_attr "modrm" "1")
1131    (set_attr "mode" "QI")])
1132
1133 (define_insn "*cmpqi_ext_4"
1134   [(set (reg FLAGS_REG)
1135         (compare
1136           (subreg:QI
1137             (zero_extract:SI
1138               (match_operand 0 "ext_register_operand" "Q")
1139               (const_int 8)
1140               (const_int 8)) 0)
1141           (subreg:QI
1142             (zero_extract:SI
1143               (match_operand 1 "ext_register_operand" "Q")
1144               (const_int 8)
1145               (const_int 8)) 0)))]
1146   "ix86_match_ccmode (insn, CCmode)"
1147   "cmp{b}\t{%h1, %h0|%h0, %h1}"
1148   [(set_attr "type" "icmp")
1149    (set_attr "mode" "QI")])
1150
1151 ;; These implement float point compares.
1152 ;; %%% See if we can get away with VOIDmode operands on the actual insns,
1153 ;; which would allow mix and match FP modes on the compares.  Which is what
1154 ;; the old patterns did, but with many more of them.
1155
1156 (define_expand "cbranchxf4"
1157   [(set (reg:CC FLAGS_REG)
1158         (compare:CC (match_operand:XF 1 "nonmemory_operand" "")
1159                     (match_operand:XF 2 "nonmemory_operand" "")))
1160    (set (pc) (if_then_else
1161               (match_operator 0 "ix86_fp_comparison_operator"
1162                [(reg:CC FLAGS_REG)
1163                 (const_int 0)])
1164               (label_ref (match_operand 3 "" ""))
1165               (pc)))]
1166   "TARGET_80387"
1167 {
1168   ix86_expand_branch (GET_CODE (operands[0]),
1169                       operands[1], operands[2], operands[3]);
1170   DONE;
1171 })
1172
1173 (define_expand "cstorexf4"
1174   [(set (reg:CC FLAGS_REG)
1175         (compare:CC (match_operand:XF 2 "nonmemory_operand" "")
1176                     (match_operand:XF 3 "nonmemory_operand" "")))
1177    (set (match_operand:QI 0 "register_operand" "")
1178               (match_operator 1 "ix86_fp_comparison_operator"
1179                [(reg:CC FLAGS_REG)
1180                 (const_int 0)]))]
1181   "TARGET_80387"
1182 {
1183   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1184                      operands[2], operands[3]);
1185   DONE;
1186 })
1187
1188 (define_expand "cbranch<mode>4"
1189   [(set (reg:CC FLAGS_REG)
1190         (compare:CC (match_operand:MODEF 1 "cmp_fp_expander_operand" "")
1191                     (match_operand:MODEF 2 "cmp_fp_expander_operand" "")))
1192    (set (pc) (if_then_else
1193               (match_operator 0 "ix86_fp_comparison_operator"
1194                [(reg:CC FLAGS_REG)
1195                 (const_int 0)])
1196               (label_ref (match_operand 3 "" ""))
1197               (pc)))]
1198   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
1199 {
1200   ix86_expand_branch (GET_CODE (operands[0]),
1201                       operands[1], operands[2], operands[3]);
1202   DONE;
1203 })
1204
1205 (define_expand "cstore<mode>4"
1206   [(set (reg:CC FLAGS_REG)
1207         (compare:CC (match_operand:MODEF 2 "cmp_fp_expander_operand" "")
1208                     (match_operand:MODEF 3 "cmp_fp_expander_operand" "")))
1209    (set (match_operand:QI 0 "register_operand" "")
1210               (match_operator 1 "ix86_fp_comparison_operator"
1211                [(reg:CC FLAGS_REG)
1212                 (const_int 0)]))]
1213   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
1214 {
1215   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1216                      operands[2], operands[3]);
1217   DONE;
1218 })
1219
1220 (define_expand "cbranchcc4"
1221   [(set (pc) (if_then_else
1222               (match_operator 0 "comparison_operator"
1223                [(match_operand 1 "flags_reg_operand" "")
1224                 (match_operand 2 "const0_operand" "")])
1225               (label_ref (match_operand 3 "" ""))
1226               (pc)))]
1227   ""
1228 {
1229   ix86_expand_branch (GET_CODE (operands[0]),
1230                       operands[1], operands[2], operands[3]);
1231   DONE;
1232 })
1233
1234 (define_expand "cstorecc4"
1235   [(set (match_operand:QI 0 "register_operand" "")
1236               (match_operator 1 "comparison_operator"
1237                [(match_operand 2 "flags_reg_operand" "")
1238                 (match_operand 3 "const0_operand" "")]))]
1239   ""
1240 {
1241   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1242                      operands[2], operands[3]);
1243   DONE;
1244 })
1245
1246
1247 ;; FP compares, step 1:
1248 ;; Set the FP condition codes.
1249 ;;
1250 ;; CCFPmode     compare with exceptions
1251 ;; CCFPUmode    compare with no exceptions
1252
1253 ;; We may not use "#" to split and emit these, since the REG_DEAD notes
1254 ;; used to manage the reg stack popping would not be preserved.
1255
1256 (define_insn "*cmpfp_0"
1257   [(set (match_operand:HI 0 "register_operand" "=a")
1258         (unspec:HI
1259           [(compare:CCFP
1260              (match_operand 1 "register_operand" "f")
1261              (match_operand 2 "const0_operand" ""))]
1262         UNSPEC_FNSTSW))]
1263   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1264    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1265   "* return output_fp_compare (insn, operands, 0, 0);"
1266   [(set_attr "type" "multi")
1267    (set_attr "unit" "i387")
1268    (set (attr "mode")
1269      (cond [(match_operand:SF 1 "" "")
1270               (const_string "SF")
1271             (match_operand:DF 1 "" "")
1272               (const_string "DF")
1273            ]
1274            (const_string "XF")))])
1275
1276 (define_insn_and_split "*cmpfp_0_cc"
1277   [(set (reg:CCFP FLAGS_REG)
1278         (compare:CCFP
1279           (match_operand 1 "register_operand" "f")
1280           (match_operand 2 "const0_operand" "")))
1281    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1282   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1283    && TARGET_SAHF && !TARGET_CMOVE
1284    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1285   "#"
1286   "&& reload_completed"
1287   [(set (match_dup 0)
1288         (unspec:HI
1289           [(compare:CCFP (match_dup 1)(match_dup 2))]
1290         UNSPEC_FNSTSW))
1291    (set (reg:CC FLAGS_REG)
1292         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1293   ""
1294   [(set_attr "type" "multi")
1295    (set_attr "unit" "i387")
1296    (set (attr "mode")
1297      (cond [(match_operand:SF 1 "" "")
1298               (const_string "SF")
1299             (match_operand:DF 1 "" "")
1300               (const_string "DF")
1301            ]
1302            (const_string "XF")))])
1303
1304 (define_insn "*cmpfp_xf"
1305   [(set (match_operand:HI 0 "register_operand" "=a")
1306         (unspec:HI
1307           [(compare:CCFP
1308              (match_operand:XF 1 "register_operand" "f")
1309              (match_operand:XF 2 "register_operand" "f"))]
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" "XF")])
1316
1317 (define_insn_and_split "*cmpfp_xf_cc"
1318   [(set (reg:CCFP FLAGS_REG)
1319         (compare:CCFP
1320           (match_operand:XF 1 "register_operand" "f")
1321           (match_operand:XF 2 "register_operand" "f")))
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" "XF")])
1337
1338 (define_insn "*cmpfp_<mode>"
1339   [(set (match_operand:HI 0 "register_operand" "=a")
1340         (unspec:HI
1341           [(compare:CCFP
1342              (match_operand:MODEF 1 "register_operand" "f")
1343              (match_operand:MODEF 2 "nonimmediate_operand" "fm"))]
1344           UNSPEC_FNSTSW))]
1345   "TARGET_80387"
1346   "* return output_fp_compare (insn, operands, 0, 0);"
1347   [(set_attr "type" "multi")
1348    (set_attr "unit" "i387")
1349    (set_attr "mode" "<MODE>")])
1350
1351 (define_insn_and_split "*cmpfp_<mode>_cc"
1352   [(set (reg:CCFP FLAGS_REG)
1353         (compare:CCFP
1354           (match_operand:MODEF 1 "register_operand" "f")
1355           (match_operand:MODEF 2 "nonimmediate_operand" "fm")))
1356    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1357   "TARGET_80387
1358    && TARGET_SAHF && !TARGET_CMOVE"
1359   "#"
1360   "&& reload_completed"
1361   [(set (match_dup 0)
1362         (unspec:HI
1363           [(compare:CCFP (match_dup 1)(match_dup 2))]
1364         UNSPEC_FNSTSW))
1365    (set (reg:CC FLAGS_REG)
1366         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1367   ""
1368   [(set_attr "type" "multi")
1369    (set_attr "unit" "i387")
1370    (set_attr "mode" "<MODE>")])
1371
1372 (define_insn "*cmpfp_u"
1373   [(set (match_operand:HI 0 "register_operand" "=a")
1374         (unspec:HI
1375           [(compare:CCFPU
1376              (match_operand 1 "register_operand" "f")
1377              (match_operand 2 "register_operand" "f"))]
1378           UNSPEC_FNSTSW))]
1379   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1380    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1381   "* return output_fp_compare (insn, operands, 0, 1);"
1382   [(set_attr "type" "multi")
1383    (set_attr "unit" "i387")
1384    (set (attr "mode")
1385      (cond [(match_operand:SF 1 "" "")
1386               (const_string "SF")
1387             (match_operand:DF 1 "" "")
1388               (const_string "DF")
1389            ]
1390            (const_string "XF")))])
1391
1392 (define_insn_and_split "*cmpfp_u_cc"
1393   [(set (reg:CCFPU FLAGS_REG)
1394         (compare:CCFPU
1395           (match_operand 1 "register_operand" "f")
1396           (match_operand 2 "register_operand" "f")))
1397    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1398   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1399    && TARGET_SAHF && !TARGET_CMOVE
1400    && GET_MODE (operands[1]) == GET_MODE (operands[2])"
1401   "#"
1402   "&& reload_completed"
1403   [(set (match_dup 0)
1404         (unspec:HI
1405           [(compare:CCFPU (match_dup 1)(match_dup 2))]
1406         UNSPEC_FNSTSW))
1407    (set (reg:CC FLAGS_REG)
1408         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1409   ""
1410   [(set_attr "type" "multi")
1411    (set_attr "unit" "i387")
1412    (set (attr "mode")
1413      (cond [(match_operand:SF 1 "" "")
1414               (const_string "SF")
1415             (match_operand:DF 1 "" "")
1416               (const_string "DF")
1417            ]
1418            (const_string "XF")))])
1419
1420 (define_insn "*cmpfp_<mode>"
1421   [(set (match_operand:HI 0 "register_operand" "=a")
1422         (unspec:HI
1423           [(compare:CCFP
1424              (match_operand 1 "register_operand" "f")
1425              (match_operator 3 "float_operator"
1426                [(match_operand:X87MODEI12 2 "memory_operand" "m")]))]
1427           UNSPEC_FNSTSW))]
1428   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1429    && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))
1430    && (GET_MODE (operands [3]) == GET_MODE (operands[1]))"
1431   "* return output_fp_compare (insn, operands, 0, 0);"
1432   [(set_attr "type" "multi")
1433    (set_attr "unit" "i387")
1434    (set_attr "fp_int_src" "true")
1435    (set_attr "mode" "<MODE>")])
1436
1437 (define_insn_and_split "*cmpfp_<mode>_cc"
1438   [(set (reg:CCFP FLAGS_REG)
1439         (compare:CCFP
1440           (match_operand 1 "register_operand" "f")
1441           (match_operator 3 "float_operator"
1442             [(match_operand:X87MODEI12 2 "memory_operand" "m")])))
1443    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1444   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
1445    && TARGET_SAHF && !TARGET_CMOVE
1446    && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))
1447    && (GET_MODE (operands [3]) == GET_MODE (operands[1]))"
1448   "#"
1449   "&& reload_completed"
1450   [(set (match_dup 0)
1451         (unspec:HI
1452           [(compare:CCFP
1453              (match_dup 1)
1454              (match_op_dup 3 [(match_dup 2)]))]
1455         UNSPEC_FNSTSW))
1456    (set (reg:CC FLAGS_REG)
1457         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1458   ""
1459   [(set_attr "type" "multi")
1460    (set_attr "unit" "i387")
1461    (set_attr "fp_int_src" "true")
1462    (set_attr "mode" "<MODE>")])
1463
1464 ;; FP compares, step 2
1465 ;; Move the fpsw to ax.
1466
1467 (define_insn "x86_fnstsw_1"
1468   [(set (match_operand:HI 0 "register_operand" "=a")
1469         (unspec:HI [(reg:CCFP FPSR_REG)] UNSPEC_FNSTSW))]
1470   "TARGET_80387"
1471   "fnstsw\t%0"
1472   [(set (attr "length") (symbol_ref "ix86_attr_length_address_default (insn) + 2"))
1473    (set_attr "mode" "SI")
1474    (set_attr "unit" "i387")])
1475
1476 ;; FP compares, step 3
1477 ;; Get ax into flags, general case.
1478
1479 (define_insn "x86_sahf_1"
1480   [(set (reg:CC FLAGS_REG)
1481         (unspec:CC [(match_operand:HI 0 "register_operand" "a")]
1482                    UNSPEC_SAHF))]
1483   "TARGET_SAHF"
1484 {
1485 #ifndef HAVE_AS_IX86_SAHF
1486   if (TARGET_64BIT)
1487     return ASM_BYTE "0x9e";
1488   else
1489 #endif
1490   return "sahf";
1491 }
1492   [(set_attr "length" "1")
1493    (set_attr "athlon_decode" "vector")
1494    (set_attr "amdfam10_decode" "direct")
1495    (set_attr "bdver1_decode" "direct")
1496    (set_attr "mode" "SI")])
1497
1498 ;; Pentium Pro can do steps 1 through 3 in one go.
1499 ;; comi*, ucomi*, fcomi*, ficomi*,fucomi* (i387 instructions set condition codes)
1500 (define_insn "*cmpfp_i_mixed"
1501   [(set (reg:CCFP FLAGS_REG)
1502         (compare:CCFP (match_operand 0 "register_operand" "f,x")
1503                       (match_operand 1 "nonimmediate_operand" "f,xm")))]
1504   "TARGET_MIX_SSE_I387
1505    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1506    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1507   "* return output_fp_compare (insn, operands, 1, 0);"
1508   [(set_attr "type" "fcmp,ssecomi")
1509    (set_attr "prefix" "orig,maybe_vex")
1510    (set (attr "mode")
1511      (if_then_else (match_operand:SF 1 "" "")
1512         (const_string "SF")
1513         (const_string "DF")))
1514    (set (attr "prefix_rep")
1515         (if_then_else (eq_attr "type" "ssecomi")
1516                       (const_string "0")
1517                       (const_string "*")))
1518    (set (attr "prefix_data16")
1519         (cond [(eq_attr "type" "fcmp")
1520                  (const_string "*")
1521                (eq_attr "mode" "DF")
1522                  (const_string "1")
1523               ]
1524               (const_string "0")))
1525    (set_attr "athlon_decode" "vector")
1526    (set_attr "amdfam10_decode" "direct")
1527    (set_attr "bdver1_decode" "double")])
1528
1529 (define_insn "*cmpfp_i_sse"
1530   [(set (reg:CCFP FLAGS_REG)
1531         (compare:CCFP (match_operand 0 "register_operand" "x")
1532                       (match_operand 1 "nonimmediate_operand" "xm")))]
1533   "TARGET_SSE_MATH
1534    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1535    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1536   "* return output_fp_compare (insn, operands, 1, 0);"
1537   [(set_attr "type" "ssecomi")
1538    (set_attr "prefix" "maybe_vex")
1539    (set (attr "mode")
1540      (if_then_else (match_operand:SF 1 "" "")
1541         (const_string "SF")
1542         (const_string "DF")))
1543    (set_attr "prefix_rep" "0")
1544    (set (attr "prefix_data16")
1545         (if_then_else (eq_attr "mode" "DF")
1546                       (const_string "1")
1547                       (const_string "0")))
1548    (set_attr "athlon_decode" "vector")
1549    (set_attr "amdfam10_decode" "direct")
1550    (set_attr "bdver1_decode" "double")])
1551
1552 (define_insn "*cmpfp_i_i387"
1553   [(set (reg:CCFP FLAGS_REG)
1554         (compare:CCFP (match_operand 0 "register_operand" "f")
1555                       (match_operand 1 "register_operand" "f")))]
1556   "X87_FLOAT_MODE_P (GET_MODE (operands[0]))
1557    && TARGET_CMOVE
1558    && !(SSE_FLOAT_MODE_P (GET_MODE (operands[0])) && TARGET_SSE_MATH)
1559    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1560   "* return output_fp_compare (insn, operands, 1, 0);"
1561   [(set_attr "type" "fcmp")
1562    (set (attr "mode")
1563      (cond [(match_operand:SF 1 "" "")
1564               (const_string "SF")
1565             (match_operand:DF 1 "" "")
1566               (const_string "DF")
1567            ]
1568            (const_string "XF")))
1569    (set_attr "athlon_decode" "vector")
1570    (set_attr "amdfam10_decode" "direct")
1571    (set_attr "bdver1_decode" "double")])
1572
1573 (define_insn "*cmpfp_iu_mixed"
1574   [(set (reg:CCFPU FLAGS_REG)
1575         (compare:CCFPU (match_operand 0 "register_operand" "f,x")
1576                        (match_operand 1 "nonimmediate_operand" "f,xm")))]
1577   "TARGET_MIX_SSE_I387
1578    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1579    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1580   "* return output_fp_compare (insn, operands, 1, 1);"
1581   [(set_attr "type" "fcmp,ssecomi")
1582    (set_attr "prefix" "orig,maybe_vex")
1583    (set (attr "mode")
1584      (if_then_else (match_operand:SF 1 "" "")
1585         (const_string "SF")
1586         (const_string "DF")))
1587    (set (attr "prefix_rep")
1588         (if_then_else (eq_attr "type" "ssecomi")
1589                       (const_string "0")
1590                       (const_string "*")))
1591    (set (attr "prefix_data16")
1592         (cond [(eq_attr "type" "fcmp")
1593                  (const_string "*")
1594                (eq_attr "mode" "DF")
1595                  (const_string "1")
1596               ]
1597               (const_string "0")))
1598    (set_attr "athlon_decode" "vector")
1599    (set_attr "amdfam10_decode" "direct")
1600    (set_attr "bdver1_decode" "double")])
1601
1602 (define_insn "*cmpfp_iu_sse"
1603   [(set (reg:CCFPU FLAGS_REG)
1604         (compare:CCFPU (match_operand 0 "register_operand" "x")
1605                        (match_operand 1 "nonimmediate_operand" "xm")))]
1606   "TARGET_SSE_MATH
1607    && SSE_FLOAT_MODE_P (GET_MODE (operands[0]))
1608    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1609   "* return output_fp_compare (insn, operands, 1, 1);"
1610   [(set_attr "type" "ssecomi")
1611    (set_attr "prefix" "maybe_vex")
1612    (set (attr "mode")
1613      (if_then_else (match_operand:SF 1 "" "")
1614         (const_string "SF")
1615         (const_string "DF")))
1616    (set_attr "prefix_rep" "0")
1617    (set (attr "prefix_data16")
1618         (if_then_else (eq_attr "mode" "DF")
1619                       (const_string "1")
1620                       (const_string "0")))
1621    (set_attr "athlon_decode" "vector")
1622    (set_attr "amdfam10_decode" "direct")
1623    (set_attr "bdver1_decode" "double")])
1624
1625 (define_insn "*cmpfp_iu_387"
1626   [(set (reg:CCFPU FLAGS_REG)
1627         (compare:CCFPU (match_operand 0 "register_operand" "f")
1628                        (match_operand 1 "register_operand" "f")))]
1629   "X87_FLOAT_MODE_P (GET_MODE (operands[0]))
1630    && TARGET_CMOVE
1631    && !(SSE_FLOAT_MODE_P (GET_MODE (operands[0])) && TARGET_SSE_MATH)
1632    && GET_MODE (operands[0]) == GET_MODE (operands[1])"
1633   "* return output_fp_compare (insn, operands, 1, 1);"
1634   [(set_attr "type" "fcmp")
1635    (set (attr "mode")
1636      (cond [(match_operand:SF 1 "" "")
1637               (const_string "SF")
1638             (match_operand:DF 1 "" "")
1639               (const_string "DF")
1640            ]
1641            (const_string "XF")))
1642    (set_attr "athlon_decode" "vector")
1643    (set_attr "amdfam10_decode" "direct")
1644    (set_attr "bdver1_decode" "direct")])
1645 \f
1646 ;; Push/pop instructions.
1647
1648 (define_insn "*push<mode>2"
1649   [(set (match_operand:DWI 0 "push_operand" "=<")
1650         (match_operand:DWI 1 "general_no_elim_operand" "riF*m"))]
1651   ""
1652   "#")
1653
1654 (define_split
1655   [(set (match_operand:TI 0 "push_operand" "")
1656         (match_operand:TI 1 "general_operand" ""))]
1657   "TARGET_64BIT && reload_completed
1658    && !SSE_REG_P (operands[1])"
1659   [(const_int 0)]
1660   "ix86_split_long_move (operands); DONE;")
1661
1662 (define_insn "*pushdi2_rex64"
1663   [(set (match_operand:DI 0 "push_operand" "=<,!<")
1664         (match_operand:DI 1 "general_no_elim_operand" "re*m,n"))]
1665   "TARGET_64BIT"
1666   "@
1667    push{q}\t%1
1668    #"
1669   [(set_attr "type" "push,multi")
1670    (set_attr "mode" "DI")])
1671
1672 ;; Convert impossible pushes of immediate to existing instructions.
1673 ;; First try to get scratch register and go through it.  In case this
1674 ;; fails, push sign extended lower part first and then overwrite
1675 ;; upper part by 32bit move.
1676 (define_peephole2
1677   [(match_scratch:DI 2 "r")
1678    (set (match_operand:DI 0 "push_operand" "")
1679         (match_operand:DI 1 "immediate_operand" ""))]
1680   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
1681    && !x86_64_immediate_operand (operands[1], DImode)"
1682   [(set (match_dup 2) (match_dup 1))
1683    (set (match_dup 0) (match_dup 2))])
1684
1685 ;; We need to define this as both peepholer and splitter for case
1686 ;; peephole2 pass is not run.
1687 ;; "&& 1" is needed to keep it from matching the previous pattern.
1688 (define_peephole2
1689   [(set (match_operand:DI 0 "push_operand" "")
1690         (match_operand:DI 1 "immediate_operand" ""))]
1691   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
1692    && !x86_64_immediate_operand (operands[1], DImode) && 1"
1693   [(set (match_dup 0) (match_dup 1))
1694    (set (match_dup 2) (match_dup 3))]
1695 {
1696   split_double_mode (DImode, &operands[1], 1, &operands[2], &operands[3]);
1697
1698   operands[1] = gen_lowpart (DImode, operands[2]);
1699   operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (DImode, stack_pointer_rtx,
1700                                                    GEN_INT (4)));
1701 })
1702
1703 (define_split
1704   [(set (match_operand:DI 0 "push_operand" "")
1705         (match_operand:DI 1 "immediate_operand" ""))]
1706   "TARGET_64BIT && ((optimize > 0 && flag_peephole2)
1707                     ? epilogue_completed : reload_completed)
1708    && !symbolic_operand (operands[1], DImode)
1709    && !x86_64_immediate_operand (operands[1], DImode)"
1710   [(set (match_dup 0) (match_dup 1))
1711    (set (match_dup 2) (match_dup 3))]
1712 {
1713   split_double_mode (DImode, &operands[1], 1, &operands[2], &operands[3]);
1714
1715   operands[1] = gen_lowpart (DImode, operands[2]);
1716   operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (DImode, stack_pointer_rtx,
1717                                                    GEN_INT (4)));
1718 })
1719
1720 (define_split
1721   [(set (match_operand:DI 0 "push_operand" "")
1722         (match_operand:DI 1 "general_operand" ""))]
1723   "!TARGET_64BIT && reload_completed
1724    && !(MMX_REG_P (operands[1]) || SSE_REG_P (operands[1]))"
1725   [(const_int 0)]
1726   "ix86_split_long_move (operands); DONE;")
1727
1728 (define_insn "*pushsi2"
1729   [(set (match_operand:SI 0 "push_operand" "=<")
1730         (match_operand:SI 1 "general_no_elim_operand" "ri*m"))]
1731   "!TARGET_64BIT"
1732   "push{l}\t%1"
1733   [(set_attr "type" "push")
1734    (set_attr "mode" "SI")])
1735
1736 ;; emit_push_insn when it calls move_by_pieces requires an insn to
1737 ;; "push a byte/word".  But actually we use pushl, which has the effect
1738 ;; of rounding the amount pushed up to a word.
1739
1740 ;; For TARGET_64BIT we always round up to 8 bytes.
1741 (define_insn "*push<mode>2_rex64"
1742   [(set (match_operand:SWI124 0 "push_operand" "=X")
1743         (match_operand:SWI124 1 "nonmemory_no_elim_operand" "r<i>"))]
1744   "TARGET_64BIT"
1745   "push{q}\t%q1"
1746   [(set_attr "type" "push")
1747    (set_attr "mode" "DI")])
1748
1749 (define_insn "*push<mode>2"
1750   [(set (match_operand:SWI12 0 "push_operand" "=X")
1751         (match_operand:SWI12 1 "nonmemory_no_elim_operand" "rn"))]
1752   "!TARGET_64BIT"
1753   "push{l}\t%k1"
1754   [(set_attr "type" "push")
1755    (set_attr "mode" "SI")])
1756
1757 (define_insn "*push<mode>2_prologue"
1758   [(set (match_operand:P 0 "push_operand" "=<")
1759         (match_operand:P 1 "general_no_elim_operand" "r<i>*m"))
1760    (clobber (mem:BLK (scratch)))]
1761   ""
1762   "push{<imodesuffix>}\t%1"
1763   [(set_attr "type" "push")
1764    (set_attr "mode" "<MODE>")])
1765
1766 (define_insn "*pop<mode>1"
1767   [(set (match_operand:P 0 "nonimmediate_operand" "=r*m")
1768         (match_operand:P 1 "pop_operand" ">"))]
1769   ""
1770   "pop{<imodesuffix>}\t%0"
1771   [(set_attr "type" "pop")
1772    (set_attr "mode" "<MODE>")])
1773
1774 (define_insn "*pop<mode>1_epilogue"
1775   [(set (match_operand:P 0 "nonimmediate_operand" "=r*m")
1776         (match_operand:P 1 "pop_operand" ">"))
1777    (clobber (mem:BLK (scratch)))]
1778   ""
1779   "pop{<imodesuffix>}\t%0"
1780   [(set_attr "type" "pop")
1781    (set_attr "mode" "<MODE>")])
1782 \f
1783 ;; Move instructions.
1784
1785 (define_expand "movoi"
1786   [(set (match_operand:OI 0 "nonimmediate_operand" "")
1787         (match_operand:OI 1 "general_operand" ""))]
1788   "TARGET_AVX"
1789   "ix86_expand_move (OImode, operands); DONE;")
1790
1791 (define_expand "movti"
1792   [(set (match_operand:TI 0 "nonimmediate_operand" "")
1793         (match_operand:TI 1 "nonimmediate_operand" ""))]
1794   "TARGET_64BIT || TARGET_SSE"
1795 {
1796   if (TARGET_64BIT)
1797     ix86_expand_move (TImode, operands);
1798   else if (push_operand (operands[0], TImode))
1799     ix86_expand_push (TImode, operands[1]);
1800   else
1801     ix86_expand_vector_move (TImode, operands);
1802   DONE;
1803 })
1804
1805 ;; This expands to what emit_move_complex would generate if we didn't
1806 ;; have a movti pattern.  Having this avoids problems with reload on
1807 ;; 32-bit targets when SSE is present, but doesn't seem to be harmful
1808 ;; to have around all the time.
1809 (define_expand "movcdi"
1810   [(set (match_operand:CDI 0 "nonimmediate_operand" "")
1811         (match_operand:CDI 1 "general_operand" ""))]
1812   ""
1813 {
1814   if (push_operand (operands[0], CDImode))
1815     emit_move_complex_push (CDImode, operands[0], operands[1]);
1816   else
1817     emit_move_complex_parts (operands[0], operands[1]);
1818   DONE;
1819 })
1820
1821 (define_expand "mov<mode>"
1822   [(set (match_operand:SWI1248x 0 "nonimmediate_operand" "")
1823         (match_operand:SWI1248x 1 "general_operand" ""))]
1824   ""
1825   "ix86_expand_move (<MODE>mode, operands); DONE;")
1826
1827 (define_insn "*mov<mode>_xor"
1828   [(set (match_operand:SWI48 0 "register_operand" "=r")
1829         (match_operand:SWI48 1 "const0_operand" ""))
1830    (clobber (reg:CC FLAGS_REG))]
1831   "reload_completed"
1832   "xor{l}\t%k0, %k0"
1833   [(set_attr "type" "alu1")
1834    (set_attr "mode" "SI")
1835    (set_attr "length_immediate" "0")])
1836
1837 (define_insn "*mov<mode>_or"
1838   [(set (match_operand:SWI48 0 "register_operand" "=r")
1839         (match_operand:SWI48 1 "const_int_operand" ""))
1840    (clobber (reg:CC FLAGS_REG))]
1841   "reload_completed
1842    && operands[1] == constm1_rtx"
1843   "or{<imodesuffix>}\t{%1, %0|%0, %1}"
1844   [(set_attr "type" "alu1")
1845    (set_attr "mode" "<MODE>")
1846    (set_attr "length_immediate" "1")])
1847
1848 (define_insn "*movoi_internal_avx"
1849   [(set (match_operand:OI 0 "nonimmediate_operand" "=x,x,m")
1850         (match_operand:OI 1 "vector_move_operand" "C,xm,x"))]
1851   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1852 {
1853   switch (which_alternative)
1854     {
1855     case 0:
1856       return "vxorps\t%0, %0, %0";
1857     case 1:
1858     case 2:
1859       if (misaligned_operand (operands[0], OImode)
1860           || misaligned_operand (operands[1], OImode))
1861         return "vmovdqu\t{%1, %0|%0, %1}";
1862       else
1863         return "vmovdqa\t{%1, %0|%0, %1}";
1864     default:
1865       gcc_unreachable ();
1866     }
1867 }
1868   [(set_attr "type" "sselog1,ssemov,ssemov")
1869    (set_attr "prefix" "vex")
1870    (set_attr "mode" "OI")])
1871
1872 (define_insn "*movti_internal_rex64"
1873   [(set (match_operand:TI 0 "nonimmediate_operand" "=!r,o,x,x,xm")
1874         (match_operand:TI 1 "general_operand" "riFo,riF,C,xm,x"))]
1875   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1876 {
1877   switch (which_alternative)
1878     {
1879     case 0:
1880     case 1:
1881       return "#";
1882     case 2:
1883       if (get_attr_mode (insn) == MODE_V4SF)
1884         return "%vxorps\t%0, %d0";
1885       else
1886         return "%vpxor\t%0, %d0";
1887     case 3:
1888     case 4:
1889       /* TDmode values are passed as TImode on the stack.  Moving them
1890          to stack may result in unaligned memory access.  */
1891       if (misaligned_operand (operands[0], TImode)
1892           || misaligned_operand (operands[1], TImode))
1893         {
1894           if (get_attr_mode (insn) == MODE_V4SF)
1895             return "%vmovups\t{%1, %0|%0, %1}";
1896           else
1897             return "%vmovdqu\t{%1, %0|%0, %1}";
1898         }
1899       else
1900         {
1901           if (get_attr_mode (insn) == MODE_V4SF)
1902             return "%vmovaps\t{%1, %0|%0, %1}";
1903           else
1904             return "%vmovdqa\t{%1, %0|%0, %1}";
1905         }
1906     default:
1907       gcc_unreachable ();
1908     }
1909 }
1910   [(set_attr "type" "*,*,sselog1,ssemov,ssemov")
1911    (set_attr "prefix" "*,*,maybe_vex,maybe_vex,maybe_vex")
1912    (set (attr "mode")
1913         (cond [(eq_attr "alternative" "2,3")
1914                  (if_then_else
1915                    (ne (symbol_ref "optimize_function_for_size_p (cfun)")
1916                        (const_int 0))
1917                    (const_string "V4SF")
1918                    (const_string "TI"))
1919                (eq_attr "alternative" "4")
1920                  (if_then_else
1921                    (ior (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
1922                             (const_int 0))
1923                         (ne (symbol_ref "optimize_function_for_size_p (cfun)")
1924                             (const_int 0)))
1925                    (const_string "V4SF")
1926                    (const_string "TI"))]
1927                (const_string "DI")))])
1928
1929 (define_split
1930   [(set (match_operand:TI 0 "nonimmediate_operand" "")
1931         (match_operand:TI 1 "general_operand" ""))]
1932   "reload_completed
1933    && !SSE_REG_P (operands[0]) && !SSE_REG_P (operands[1])"
1934   [(const_int 0)]
1935   "ix86_split_long_move (operands); DONE;")
1936
1937 (define_insn "*movti_internal_sse"
1938   [(set (match_operand:TI 0 "nonimmediate_operand" "=x,x,m")
1939         (match_operand:TI 1 "vector_move_operand" "C,xm,x"))]
1940   "TARGET_SSE && !TARGET_64BIT
1941    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1942 {
1943   switch (which_alternative)
1944     {
1945     case 0:
1946       if (get_attr_mode (insn) == MODE_V4SF)
1947         return "%vxorps\t%0, %d0";
1948       else
1949         return "%vpxor\t%0, %d0";
1950     case 1:
1951     case 2:
1952       /* TDmode values are passed as TImode on the stack.  Moving them
1953          to stack may result in unaligned memory access.  */
1954       if (misaligned_operand (operands[0], TImode)
1955           || misaligned_operand (operands[1], TImode))
1956         {
1957           if (get_attr_mode (insn) == MODE_V4SF)
1958             return "%vmovups\t{%1, %0|%0, %1}";
1959           else
1960             return "%vmovdqu\t{%1, %0|%0, %1}";
1961         }
1962       else
1963         {
1964           if (get_attr_mode (insn) == MODE_V4SF)
1965             return "%vmovaps\t{%1, %0|%0, %1}";
1966           else
1967             return "%vmovdqa\t{%1, %0|%0, %1}";
1968         }
1969     default:
1970       gcc_unreachable ();
1971     }
1972 }
1973   [(set_attr "type" "sselog1,ssemov,ssemov")
1974    (set_attr "prefix" "maybe_vex")
1975    (set (attr "mode")
1976         (cond [(ior (eq (symbol_ref "TARGET_SSE2") (const_int 0))
1977                     (ne (symbol_ref "optimize_function_for_size_p (cfun)")
1978                         (const_int 0)))
1979                  (const_string "V4SF")
1980                (and (eq_attr "alternative" "2")
1981                     (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
1982                         (const_int 0)))
1983                  (const_string "V4SF")]
1984               (const_string "TI")))])
1985
1986 (define_insn "*movdi_internal_rex64"
1987   [(set (match_operand:DI 0 "nonimmediate_operand"
1988           "=r,r  ,r,m ,!m,*y,*y,?r ,m ,?*Ym,?*y,*x,*x,?r ,m,?*Yi,*x,?*x,?*Ym")
1989         (match_operand:DI 1 "general_operand"
1990           "Z ,rem,i,re,n ,C ,*y,*Ym,*y,r   ,m  ,C ,*x,*Yi,*x,r  ,m ,*Ym,*x"))]
1991   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1992 {
1993   switch (get_attr_type (insn))
1994     {
1995     case TYPE_SSECVT:
1996       if (SSE_REG_P (operands[0]))
1997         return "movq2dq\t{%1, %0|%0, %1}";
1998       else
1999         return "movdq2q\t{%1, %0|%0, %1}";
2000
2001     case TYPE_SSEMOV:
2002       if (get_attr_mode (insn) == MODE_TI)
2003         return "%vmovdqa\t{%1, %0|%0, %1}";
2004       /* Handle broken assemblers that require movd instead of movq.  */
2005       if (GENERAL_REG_P (operands[0]) || GENERAL_REG_P (operands[1]))
2006         return "%vmovd\t{%1, %0|%0, %1}";
2007       else
2008         return "%vmovq\t{%1, %0|%0, %1}";
2009
2010     case TYPE_MMXMOV:
2011       /* Handle broken assemblers that require movd instead of movq.  */
2012       if (GENERAL_REG_P (operands[0]) || GENERAL_REG_P (operands[1]))
2013         return "movd\t{%1, %0|%0, %1}";
2014       else
2015         return "movq\t{%1, %0|%0, %1}";
2016
2017     case TYPE_SSELOG1:
2018       return "%vpxor\t%0, %d0";
2019
2020     case TYPE_MMX:
2021       return "pxor\t%0, %0";
2022
2023     case TYPE_MULTI:
2024       return "#";
2025
2026     case TYPE_LEA:
2027       return "lea{q}\t{%a1, %0|%0, %a1}";
2028
2029     default:
2030       gcc_assert (!flag_pic || LEGITIMATE_PIC_OPERAND_P (operands[1]));
2031       if (get_attr_mode (insn) == MODE_SI)
2032         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2033       else if (which_alternative == 2)
2034         return "movabs{q}\t{%1, %0|%0, %1}";
2035       else
2036         return "mov{q}\t{%1, %0|%0, %1}";
2037     }
2038 }
2039   [(set (attr "type")
2040      (cond [(eq_attr "alternative" "5")
2041               (const_string "mmx")
2042             (eq_attr "alternative" "6,7,8,9,10")
2043               (const_string "mmxmov")
2044             (eq_attr "alternative" "11")
2045               (const_string "sselog1")
2046             (eq_attr "alternative" "12,13,14,15,16")
2047               (const_string "ssemov")
2048             (eq_attr "alternative" "17,18")
2049               (const_string "ssecvt")
2050             (eq_attr "alternative" "4")
2051               (const_string "multi")
2052             (match_operand:DI 1 "pic_32bit_operand" "")
2053               (const_string "lea")
2054            ]
2055            (const_string "imov")))
2056    (set (attr "modrm")
2057      (if_then_else
2058        (and (eq_attr "alternative" "2") (eq_attr "type" "imov"))
2059          (const_string "0")
2060          (const_string "*")))
2061    (set (attr "length_immediate")
2062      (if_then_else
2063        (and (eq_attr "alternative" "2") (eq_attr "type" "imov"))
2064          (const_string "8")
2065          (const_string "*")))
2066    (set_attr "prefix_rex" "*,*,*,*,*,*,*,1,*,1,*,*,*,*,*,*,*,*,*")
2067    (set_attr "prefix_data16" "*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,1,*,*,*")
2068    (set (attr "prefix")
2069      (if_then_else (eq_attr "alternative" "11,12,13,14,15,16")
2070        (const_string "maybe_vex")
2071        (const_string "orig")))
2072    (set_attr "mode" "SI,DI,DI,DI,SI,DI,DI,DI,DI,DI,DI,TI,TI,DI,DI,DI,DI,DI,DI")])
2073
2074 ;; Convert impossible stores of immediate to existing instructions.
2075 ;; First try to get scratch register and go through it.  In case this
2076 ;; fails, move by 32bit parts.
2077 (define_peephole2
2078   [(match_scratch:DI 2 "r")
2079    (set (match_operand:DI 0 "memory_operand" "")
2080         (match_operand:DI 1 "immediate_operand" ""))]
2081   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2082    && !x86_64_immediate_operand (operands[1], DImode)"
2083   [(set (match_dup 2) (match_dup 1))
2084    (set (match_dup 0) (match_dup 2))])
2085
2086 ;; We need to define this as both peepholer and splitter for case
2087 ;; peephole2 pass is not run.
2088 ;; "&& 1" is needed to keep it from matching the previous pattern.
2089 (define_peephole2
2090   [(set (match_operand:DI 0 "memory_operand" "")
2091         (match_operand:DI 1 "immediate_operand" ""))]
2092   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
2093    && !x86_64_immediate_operand (operands[1], DImode) && 1"
2094   [(set (match_dup 2) (match_dup 3))
2095    (set (match_dup 4) (match_dup 5))]
2096   "split_double_mode (DImode, &operands[0], 2, &operands[2], &operands[4]);")
2097
2098 (define_split
2099   [(set (match_operand:DI 0 "memory_operand" "")
2100         (match_operand:DI 1 "immediate_operand" ""))]
2101   "TARGET_64BIT && ((optimize > 0 && flag_peephole2)
2102                     ? epilogue_completed : reload_completed)
2103    && !symbolic_operand (operands[1], DImode)
2104    && !x86_64_immediate_operand (operands[1], DImode)"
2105   [(set (match_dup 2) (match_dup 3))
2106    (set (match_dup 4) (match_dup 5))]
2107   "split_double_mode (DImode, &operands[0], 2, &operands[2], &operands[4]);")
2108
2109 (define_insn "*movdi_internal"
2110   [(set (match_operand:DI 0 "nonimmediate_operand"
2111                         "=r  ,o  ,*y,m*y,*y,*Y2,m  ,*Y2,*Y2,*x,m ,*x,*x")
2112         (match_operand:DI 1 "general_operand"
2113                         "riFo,riF,C ,*y ,m ,C  ,*Y2,*Y2,m  ,C ,*x,*x,m "))]
2114   "!TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2115   "@
2116    #
2117    #
2118    pxor\t%0, %0
2119    movq\t{%1, %0|%0, %1}
2120    movq\t{%1, %0|%0, %1}
2121    %vpxor\t%0, %d0
2122    %vmovq\t{%1, %0|%0, %1}
2123    %vmovdqa\t{%1, %0|%0, %1}
2124    %vmovq\t{%1, %0|%0, %1}
2125    xorps\t%0, %0
2126    movlps\t{%1, %0|%0, %1}
2127    movaps\t{%1, %0|%0, %1}
2128    movlps\t{%1, %0|%0, %1}"
2129   [(set (attr "isa")
2130      (if_then_else (eq_attr "alternative" "9,10,11,12")
2131        (const_string "noavx")
2132        (const_string "base")))
2133    (set_attr "type" "*,*,mmx,mmxmov,mmxmov,sselog1,ssemov,ssemov,ssemov,sselog1,ssemov,ssemov,ssemov")
2134    (set (attr "prefix")
2135      (if_then_else (eq_attr "alternative" "5,6,7,8")
2136        (const_string "maybe_vex")
2137        (const_string "orig")))
2138    (set_attr "mode" "DI,DI,DI,DI,DI,TI,DI,TI,DI,V4SF,V2SF,V4SF,V2SF")])
2139
2140 (define_split
2141   [(set (match_operand:DI 0 "nonimmediate_operand" "")
2142         (match_operand:DI 1 "general_operand" ""))]
2143   "!TARGET_64BIT && reload_completed
2144    && !(MMX_REG_P (operands[0]) || SSE_REG_P (operands[0]))
2145    && !(MMX_REG_P (operands[1]) || SSE_REG_P (operands[1]))"
2146   [(const_int 0)]
2147   "ix86_split_long_move (operands); DONE;")
2148
2149 (define_insn "*movsi_internal"
2150   [(set (match_operand:SI 0 "nonimmediate_operand"
2151                         "=r,m ,*y,*y,?rm,?*y,*x,*x,?r ,m ,?*Yi,*x")
2152         (match_operand:SI 1 "general_operand"
2153                         "g ,ri,C ,*y,*y ,rm ,C ,*x,*Yi,*x,r   ,m "))]
2154   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2155 {
2156   switch (get_attr_type (insn))
2157     {
2158     case TYPE_SSELOG1:
2159       if (get_attr_mode (insn) == MODE_TI)
2160         return "%vpxor\t%0, %d0";
2161       return "%vxorps\t%0, %d0";
2162
2163     case TYPE_SSEMOV:
2164       switch (get_attr_mode (insn))
2165         {
2166         case MODE_TI:
2167           return "%vmovdqa\t{%1, %0|%0, %1}";
2168         case MODE_V4SF:
2169           return "%vmovaps\t{%1, %0|%0, %1}";
2170         case MODE_SI:
2171           return "%vmovd\t{%1, %0|%0, %1}";
2172         case MODE_SF:
2173           return "%vmovss\t{%1, %0|%0, %1}";
2174         default:
2175           gcc_unreachable ();
2176         }
2177
2178     case TYPE_MMX:
2179       return "pxor\t%0, %0";
2180
2181     case TYPE_MMXMOV:
2182       if (get_attr_mode (insn) == MODE_DI)
2183         return "movq\t{%1, %0|%0, %1}";
2184       return "movd\t{%1, %0|%0, %1}";
2185
2186     case TYPE_LEA:
2187       return "lea{l}\t{%a1, %0|%0, %a1}";
2188
2189     default:
2190       gcc_assert (!flag_pic || LEGITIMATE_PIC_OPERAND_P (operands[1]));
2191       return "mov{l}\t{%1, %0|%0, %1}";
2192     }
2193 }
2194   [(set (attr "type")
2195      (cond [(eq_attr "alternative" "2")
2196               (const_string "mmx")
2197             (eq_attr "alternative" "3,4,5")
2198               (const_string "mmxmov")
2199             (eq_attr "alternative" "6")
2200               (const_string "sselog1")
2201             (eq_attr "alternative" "7,8,9,10,11")
2202               (const_string "ssemov")
2203             (match_operand:DI 1 "pic_32bit_operand" "")
2204               (const_string "lea")
2205            ]
2206            (const_string "imov")))
2207    (set (attr "prefix")
2208      (if_then_else (eq_attr "alternative" "0,1,2,3,4,5")
2209        (const_string "orig")
2210        (const_string "maybe_vex")))
2211    (set (attr "prefix_data16")
2212      (if_then_else (and (eq_attr "type" "ssemov") (eq_attr "mode" "SI"))
2213        (const_string "1")
2214        (const_string "*")))
2215    (set (attr "mode")
2216      (cond [(eq_attr "alternative" "2,3")
2217               (const_string "DI")
2218             (eq_attr "alternative" "6,7")
2219               (if_then_else
2220                 (eq (symbol_ref "TARGET_SSE2") (const_int 0))
2221                 (const_string "V4SF")
2222                 (const_string "TI"))
2223             (and (eq_attr "alternative" "8,9,10,11")
2224                  (eq (symbol_ref "TARGET_SSE2") (const_int 0)))
2225               (const_string "SF")
2226            ]
2227            (const_string "SI")))])
2228
2229 (define_insn "*movhi_internal"
2230   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,r,m")
2231         (match_operand:HI 1 "general_operand" "r,rn,rm,rn"))]
2232   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2233 {
2234   switch (get_attr_type (insn))
2235     {
2236     case TYPE_IMOVX:
2237       /* movzwl is faster than movw on p2 due to partial word stalls,
2238          though not as fast as an aligned movl.  */
2239       return "movz{wl|x}\t{%1, %k0|%k0, %1}";
2240     default:
2241       if (get_attr_mode (insn) == MODE_SI)
2242         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2243       else
2244         return "mov{w}\t{%1, %0|%0, %1}";
2245     }
2246 }
2247   [(set (attr "type")
2248      (cond [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
2249                 (const_int 0))
2250               (const_string "imov")
2251             (and (eq_attr "alternative" "0")
2252                  (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2253                           (const_int 0))
2254                       (eq (symbol_ref "TARGET_HIMODE_MATH")
2255                           (const_int 0))))
2256               (const_string "imov")
2257             (and (eq_attr "alternative" "1,2")
2258                  (match_operand:HI 1 "aligned_operand" ""))
2259               (const_string "imov")
2260             (and (ne (symbol_ref "TARGET_MOVX")
2261                      (const_int 0))
2262                  (eq_attr "alternative" "0,2"))
2263               (const_string "imovx")
2264            ]
2265            (const_string "imov")))
2266     (set (attr "mode")
2267       (cond [(eq_attr "type" "imovx")
2268                (const_string "SI")
2269              (and (eq_attr "alternative" "1,2")
2270                   (match_operand:HI 1 "aligned_operand" ""))
2271                (const_string "SI")
2272              (and (eq_attr "alternative" "0")
2273                   (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2274                            (const_int 0))
2275                        (eq (symbol_ref "TARGET_HIMODE_MATH")
2276                            (const_int 0))))
2277                (const_string "SI")
2278             ]
2279             (const_string "HI")))])
2280
2281 ;; Situation is quite tricky about when to choose full sized (SImode) move
2282 ;; over QImode moves.  For Q_REG -> Q_REG move we use full size only for
2283 ;; partial register dependency machines (such as AMD Athlon), where QImode
2284 ;; moves issue extra dependency and for partial register stalls machines
2285 ;; that don't use QImode patterns (and QImode move cause stall on the next
2286 ;; instruction).
2287 ;;
2288 ;; For loads of Q_REG to NONQ_REG we use full sized moves except for partial
2289 ;; register stall machines with, where we use QImode instructions, since
2290 ;; partial register stall can be caused there.  Then we use movzx.
2291 (define_insn "*movqi_internal"
2292   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,q ,q ,r,r ,?r,m")
2293         (match_operand:QI 1 "general_operand"      " q,qn,qm,q,rn,qm,qn"))]
2294   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2295 {
2296   switch (get_attr_type (insn))
2297     {
2298     case TYPE_IMOVX:
2299       gcc_assert (ANY_QI_REG_P (operands[1]) || MEM_P (operands[1]));
2300       return "movz{bl|x}\t{%1, %k0|%k0, %1}";
2301     default:
2302       if (get_attr_mode (insn) == MODE_SI)
2303         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2304       else
2305         return "mov{b}\t{%1, %0|%0, %1}";
2306     }
2307 }
2308   [(set (attr "type")
2309      (cond [(and (eq_attr "alternative" "5")
2310                  (not (match_operand:QI 1 "aligned_operand" "")))
2311               (const_string "imovx")
2312             (ne (symbol_ref "optimize_function_for_size_p (cfun)")
2313                 (const_int 0))
2314               (const_string "imov")
2315             (and (eq_attr "alternative" "3")
2316                  (ior (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2317                           (const_int 0))
2318                       (eq (symbol_ref "TARGET_QIMODE_MATH")
2319                           (const_int 0))))
2320               (const_string "imov")
2321             (eq_attr "alternative" "3,5")
2322               (const_string "imovx")
2323             (and (ne (symbol_ref "TARGET_MOVX")
2324                      (const_int 0))
2325                  (eq_attr "alternative" "2"))
2326               (const_string "imovx")
2327            ]
2328            (const_string "imov")))
2329    (set (attr "mode")
2330       (cond [(eq_attr "alternative" "3,4,5")
2331                (const_string "SI")
2332              (eq_attr "alternative" "6")
2333                (const_string "QI")
2334              (eq_attr "type" "imovx")
2335                (const_string "SI")
2336              (and (eq_attr "type" "imov")
2337                   (and (eq_attr "alternative" "0,1")
2338                        (and (ne (symbol_ref "TARGET_PARTIAL_REG_DEPENDENCY")
2339                                 (const_int 0))
2340                             (and (eq (symbol_ref "optimize_function_for_size_p (cfun)")
2341                                      (const_int 0))
2342                                  (eq (symbol_ref "TARGET_PARTIAL_REG_STALL")
2343                                      (const_int 0))))))
2344                (const_string "SI")
2345              ;; Avoid partial register stalls when not using QImode arithmetic
2346              (and (eq_attr "type" "imov")
2347                   (and (eq_attr "alternative" "0,1")
2348                        (and (ne (symbol_ref "TARGET_PARTIAL_REG_STALL")
2349                                 (const_int 0))
2350                             (eq (symbol_ref "TARGET_QIMODE_MATH")
2351                                 (const_int 0)))))
2352                (const_string "SI")
2353            ]
2354            (const_string "QI")))])
2355
2356 ;; Stores and loads of ax to arbitrary constant address.
2357 ;; We fake an second form of instruction to force reload to load address
2358 ;; into register when rax is not available
2359 (define_insn "*movabs<mode>_1"
2360   [(set (mem:SWI1248x (match_operand:DI 0 "x86_64_movabs_operand" "i,r"))
2361         (match_operand:SWI1248x 1 "nonmemory_operand" "a,er"))]
2362   "TARGET_64BIT && ix86_check_movabs (insn, 0)"
2363   "@
2364    movabs{<imodesuffix>}\t{%1, %P0|%P0, %1}
2365    mov{<imodesuffix>}\t{%1, %a0|%a0, %1}"
2366   [(set_attr "type" "imov")
2367    (set_attr "modrm" "0,*")
2368    (set_attr "length_address" "8,0")
2369    (set_attr "length_immediate" "0,*")
2370    (set_attr "memory" "store")
2371    (set_attr "mode" "<MODE>")])
2372
2373 (define_insn "*movabs<mode>_2"
2374   [(set (match_operand:SWI1248x 0 "register_operand" "=a,r")
2375         (mem:SWI1248x (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
2376   "TARGET_64BIT && ix86_check_movabs (insn, 1)"
2377   "@
2378    movabs{<imodesuffix>}\t{%P1, %0|%0, %P1}
2379    mov{<imodesuffix>}\t{%a1, %0|%0, %a1}"
2380   [(set_attr "type" "imov")
2381    (set_attr "modrm" "0,*")
2382    (set_attr "length_address" "8,0")
2383    (set_attr "length_immediate" "0")
2384    (set_attr "memory" "load")
2385    (set_attr "mode" "<MODE>")])
2386
2387 (define_insn "*swap<mode>"
2388   [(set (match_operand:SWI48 0 "register_operand" "+r")
2389         (match_operand:SWI48 1 "register_operand" "+r"))
2390    (set (match_dup 1)
2391         (match_dup 0))]
2392   ""
2393   "xchg{<imodesuffix>}\t%1, %0"
2394   [(set_attr "type" "imov")
2395    (set_attr "mode" "<MODE>")
2396    (set_attr "pent_pair" "np")
2397    (set_attr "athlon_decode" "vector")
2398    (set_attr "amdfam10_decode" "double")
2399    (set_attr "bdver1_decode" "double")])
2400
2401 (define_insn "*swap<mode>_1"
2402   [(set (match_operand:SWI12 0 "register_operand" "+r")
2403         (match_operand:SWI12 1 "register_operand" "+r"))
2404    (set (match_dup 1)
2405         (match_dup 0))]
2406   "!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)"
2407   "xchg{l}\t%k1, %k0"
2408   [(set_attr "type" "imov")
2409    (set_attr "mode" "SI")
2410    (set_attr "pent_pair" "np")
2411    (set_attr "athlon_decode" "vector")
2412    (set_attr "amdfam10_decode" "double")
2413    (set_attr "bdver1_decode" "double")])
2414
2415 ;; Not added amdfam10_decode since TARGET_PARTIAL_REG_STALL
2416 ;; is disabled for AMDFAM10
2417 (define_insn "*swap<mode>_2"
2418   [(set (match_operand:SWI12 0 "register_operand" "+<r>")
2419         (match_operand:SWI12 1 "register_operand" "+<r>"))
2420    (set (match_dup 1)
2421         (match_dup 0))]
2422   "TARGET_PARTIAL_REG_STALL"
2423   "xchg{<imodesuffix>}\t%1, %0"
2424   [(set_attr "type" "imov")
2425    (set_attr "mode" "<MODE>")
2426    (set_attr "pent_pair" "np")
2427    (set_attr "athlon_decode" "vector")])
2428
2429 (define_expand "movstrict<mode>"
2430   [(set (strict_low_part (match_operand:SWI12 0 "nonimmediate_operand" ""))
2431         (match_operand:SWI12 1 "general_operand" ""))]
2432   ""
2433 {
2434   if (TARGET_PARTIAL_REG_STALL && optimize_function_for_speed_p (cfun))
2435     FAIL;
2436   if (GET_CODE (operands[0]) == SUBREG
2437       && GET_MODE_CLASS (GET_MODE (SUBREG_REG (operands[0]))) != MODE_INT)
2438     FAIL;
2439   /* Don't generate memory->memory moves, go through a register */
2440   if (MEM_P (operands[0]) && MEM_P (operands[1]))
2441     operands[1] = force_reg (<MODE>mode, operands[1]);
2442 })
2443
2444 (define_insn "*movstrict<mode>_1"
2445   [(set (strict_low_part
2446           (match_operand:SWI12 0 "nonimmediate_operand" "+<r>m,<r>"))
2447         (match_operand:SWI12 1 "general_operand" "<r>n,m"))]
2448   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
2449    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2450   "mov{<imodesuffix>}\t{%1, %0|%0, %1}"
2451   [(set_attr "type" "imov")
2452    (set_attr "mode" "<MODE>")])
2453
2454 (define_insn "*movstrict<mode>_xor"
2455   [(set (strict_low_part (match_operand:SWI12 0 "register_operand" "+<r>"))
2456         (match_operand:SWI12 1 "const0_operand" ""))
2457    (clobber (reg:CC FLAGS_REG))]
2458   "reload_completed"
2459   "xor{<imodesuffix>}\t%0, %0"
2460   [(set_attr "type" "alu1")
2461    (set_attr "mode" "<MODE>")
2462    (set_attr "length_immediate" "0")])
2463
2464 (define_insn "*mov<mode>_extv_1"
2465   [(set (match_operand:SWI24 0 "register_operand" "=R")
2466         (sign_extract:SWI24 (match_operand 1 "ext_register_operand" "Q")
2467                             (const_int 8)
2468                             (const_int 8)))]
2469   ""
2470   "movs{bl|x}\t{%h1, %k0|%k0, %h1}"
2471   [(set_attr "type" "imovx")
2472    (set_attr "mode" "SI")])
2473
2474 (define_insn "*movqi_extv_1_rex64"
2475   [(set (match_operand:QI 0 "register_operand" "=Q,?R")
2476         (sign_extract:QI (match_operand 1 "ext_register_operand" "Q,Q")
2477                          (const_int 8)
2478                          (const_int 8)))]
2479   "TARGET_64BIT"
2480 {
2481   switch (get_attr_type (insn))
2482     {
2483     case TYPE_IMOVX:
2484       return "movs{bl|x}\t{%h1, %k0|%k0, %h1}";
2485     default:
2486       return "mov{b}\t{%h1, %0|%0, %h1}";
2487     }
2488 }
2489   [(set (attr "type")
2490      (if_then_else (and (match_operand:QI 0 "register_operand" "")
2491                         (ior (not (match_operand:QI 0 "q_regs_operand" ""))
2492                              (ne (symbol_ref "TARGET_MOVX")
2493                                  (const_int 0))))
2494         (const_string "imovx")
2495         (const_string "imov")))
2496    (set (attr "mode")
2497      (if_then_else (eq_attr "type" "imovx")
2498         (const_string "SI")
2499         (const_string "QI")))])
2500
2501 (define_insn "*movqi_extv_1"
2502   [(set (match_operand:QI 0 "nonimmediate_operand" "=Qm,?r")
2503         (sign_extract:QI (match_operand 1 "ext_register_operand" "Q,Q")
2504                          (const_int 8)
2505                          (const_int 8)))]
2506   "!TARGET_64BIT"
2507 {
2508   switch (get_attr_type (insn))
2509     {
2510     case TYPE_IMOVX:
2511       return "movs{bl|x}\t{%h1, %k0|%k0, %h1}";
2512     default:
2513       return "mov{b}\t{%h1, %0|%0, %h1}";
2514     }
2515 }
2516   [(set (attr "type")
2517      (if_then_else (and (match_operand:QI 0 "register_operand" "")
2518                         (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 "*mov<mode>_extzv_1"
2529   [(set (match_operand:SWI48 0 "register_operand" "=R")
2530         (zero_extract:SWI48 (match_operand 1 "ext_register_operand" "Q")
2531                             (const_int 8)
2532                             (const_int 8)))]
2533   ""
2534   "movz{bl|x}\t{%h1, %k0|%k0, %h1}"
2535   [(set_attr "type" "imovx")
2536    (set_attr "mode" "SI")])
2537
2538 (define_insn "*movqi_extzv_2_rex64"
2539   [(set (match_operand:QI 0 "register_operand" "=Q,?R")
2540         (subreg:QI
2541           (zero_extract:SI (match_operand 1 "ext_register_operand" "Q,Q")
2542                            (const_int 8)
2543                            (const_int 8)) 0))]
2544   "TARGET_64BIT"
2545 {
2546   switch (get_attr_type (insn))
2547     {
2548     case TYPE_IMOVX:
2549       return "movz{bl|x}\t{%h1, %k0|%k0, %h1}";
2550     default:
2551       return "mov{b}\t{%h1, %0|%0, %h1}";
2552     }
2553 }
2554   [(set (attr "type")
2555      (if_then_else (ior (not (match_operand:QI 0 "q_regs_operand" ""))
2556                         (ne (symbol_ref "TARGET_MOVX")
2557                             (const_int 0)))
2558         (const_string "imovx")
2559         (const_string "imov")))
2560    (set (attr "mode")
2561      (if_then_else (eq_attr "type" "imovx")
2562         (const_string "SI")
2563         (const_string "QI")))])
2564
2565 (define_insn "*movqi_extzv_2"
2566   [(set (match_operand:QI 0 "nonimmediate_operand" "=Qm,?R")
2567         (subreg:QI
2568           (zero_extract:SI (match_operand 1 "ext_register_operand" "Q,Q")
2569                            (const_int 8)
2570                            (const_int 8)) 0))]
2571   "!TARGET_64BIT"
2572 {
2573   switch (get_attr_type (insn))
2574     {
2575     case TYPE_IMOVX:
2576       return "movz{bl|x}\t{%h1, %k0|%k0, %h1}";
2577     default:
2578       return "mov{b}\t{%h1, %0|%0, %h1}";
2579     }
2580 }
2581   [(set (attr "type")
2582      (if_then_else (and (match_operand:QI 0 "register_operand" "")
2583                         (ior (not (match_operand:QI 0 "q_regs_operand" ""))
2584                              (ne (symbol_ref "TARGET_MOVX")
2585                                  (const_int 0))))
2586         (const_string "imovx")
2587         (const_string "imov")))
2588    (set (attr "mode")
2589      (if_then_else (eq_attr "type" "imovx")
2590         (const_string "SI")
2591         (const_string "QI")))])
2592
2593 (define_expand "mov<mode>_insv_1"
2594   [(set (zero_extract:SWI48 (match_operand 0 "ext_register_operand" "")
2595                             (const_int 8)
2596                             (const_int 8))
2597         (match_operand:SWI48 1 "nonmemory_operand" ""))])
2598
2599 (define_insn "*mov<mode>_insv_1_rex64"
2600   [(set (zero_extract:SWI48x (match_operand 0 "ext_register_operand" "+Q")
2601                              (const_int 8)
2602                              (const_int 8))
2603         (match_operand:SWI48x 1 "nonmemory_operand" "Qn"))]
2604   "TARGET_64BIT"
2605   "mov{b}\t{%b1, %h0|%h0, %b1}"
2606   [(set_attr "type" "imov")
2607    (set_attr "mode" "QI")])
2608
2609 (define_insn "*movsi_insv_1"
2610   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
2611                          (const_int 8)
2612                          (const_int 8))
2613         (match_operand:SI 1 "general_operand" "Qmn"))]
2614   "!TARGET_64BIT"
2615   "mov{b}\t{%b1, %h0|%h0, %b1}"
2616   [(set_attr "type" "imov")
2617    (set_attr "mode" "QI")])
2618
2619 (define_insn "*movqi_insv_2"
2620   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
2621                          (const_int 8)
2622                          (const_int 8))
2623         (lshiftrt:SI (match_operand:SI 1 "register_operand" "Q")
2624                      (const_int 8)))]
2625   ""
2626   "mov{b}\t{%h1, %h0|%h0, %h1}"
2627   [(set_attr "type" "imov")
2628    (set_attr "mode" "QI")])
2629 \f
2630 ;; Floating point push instructions.
2631
2632 (define_insn "*pushtf"
2633   [(set (match_operand:TF 0 "push_operand" "=<,<,<")
2634         (match_operand:TF 1 "general_no_elim_operand" "x,Fo,*r"))]
2635   "TARGET_SSE2"
2636 {
2637   /* This insn should be already split before reg-stack.  */
2638   gcc_unreachable ();
2639 }
2640   [(set_attr "type" "multi")
2641    (set_attr "unit" "sse,*,*")
2642    (set_attr "mode" "TF,SI,SI")])
2643
2644 (define_split
2645   [(set (match_operand:TF 0 "push_operand" "")
2646         (match_operand:TF 1 "sse_reg_operand" ""))]
2647   "TARGET_SSE2 && reload_completed"
2648   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -16)))
2649    (set (mem:TF (reg:P SP_REG)) (match_dup 1))])
2650
2651 (define_split
2652   [(set (match_operand:TF 0 "push_operand" "")
2653         (match_operand:TF 1 "general_operand" ""))]
2654   "TARGET_SSE2 && reload_completed
2655    && !SSE_REG_P (operands[1])"
2656   [(const_int 0)]
2657   "ix86_split_long_move (operands); DONE;")
2658
2659 (define_insn "*pushxf"
2660   [(set (match_operand:XF 0 "push_operand" "=<,<")
2661         (match_operand:XF 1 "general_no_elim_operand" "f,ro"))]
2662   "optimize_function_for_speed_p (cfun)"
2663 {
2664   /* This insn should be already split before reg-stack.  */
2665   gcc_unreachable ();
2666 }
2667   [(set_attr "type" "multi")
2668    (set_attr "unit" "i387,*")
2669    (set_attr "mode" "XF,SI")])
2670
2671 ;; Size of pushxf is 3 (for sub) + 2 (for fstp) + memory operand size.
2672 ;; Size of pushxf using integer instructions is 3+3*memory operand size
2673 ;; Pushing using integer instructions is longer except for constants
2674 ;; and direct memory references (assuming that any given constant is pushed
2675 ;; only once, but this ought to be handled elsewhere).
2676
2677 (define_insn "*pushxf_nointeger"
2678   [(set (match_operand:XF 0 "push_operand" "=X,X,X")
2679         (match_operand:XF 1 "general_no_elim_operand" "f,Fo,*r"))]
2680   "optimize_function_for_size_p (cfun)"
2681 {
2682   /* This insn should be already split before reg-stack.  */
2683   gcc_unreachable ();
2684 }
2685   [(set_attr "type" "multi")
2686    (set_attr "unit" "i387,*,*")
2687    (set_attr "mode" "XF,SI,SI")])
2688
2689 (define_split
2690   [(set (match_operand:XF 0 "push_operand" "")
2691         (match_operand:XF 1 "fp_register_operand" ""))]
2692   "reload_completed"
2693   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
2694    (set (mem:XF (reg:P SP_REG)) (match_dup 1))]
2695   "operands[2] = GEN_INT (-GET_MODE_SIZE (XFmode));")
2696
2697 (define_split
2698   [(set (match_operand:XF 0 "push_operand" "")
2699         (match_operand:XF 1 "general_operand" ""))]
2700   "reload_completed
2701    && !FP_REG_P (operands[1])"
2702   [(const_int 0)]
2703   "ix86_split_long_move (operands); DONE;")
2704
2705 (define_insn "*pushdf"
2706   [(set (match_operand:DF 0 "push_operand" "=<,<,<")
2707         (match_operand:DF 1 "general_no_elim_operand" "f,rFo,Y2"))]
2708   "TARGET_64BIT || TARGET_INTEGER_DFMODE_MOVES"
2709 {
2710   /* This insn should be already split before reg-stack.  */
2711   gcc_unreachable ();
2712 }
2713   [(set_attr "type" "multi")
2714    (set_attr "unit" "i387,*,*")
2715    (set_attr "mode" "DF,SI,DF")])
2716
2717 ;; Size of pushdf is 3 (for sub) + 2 (for fstp) + memory operand size.
2718 ;; Size of pushdf using integer instructions is 2+2*memory operand size
2719 ;; On the average, pushdf using integers can be still shorter.  Allow this
2720 ;; pattern for optimize_size too.
2721
2722 (define_insn "*pushdf_nointeger"
2723   [(set (match_operand:DF 0 "push_operand" "=<,<,<,<")
2724         (match_operand:DF 1 "general_no_elim_operand" "f,Fo,*r,Y2"))]
2725   "!(TARGET_64BIT || TARGET_INTEGER_DFMODE_MOVES)"
2726 {
2727   /* This insn should be already split before reg-stack.  */
2728   gcc_unreachable ();
2729 }
2730   [(set_attr "type" "multi")
2731    (set_attr "unit" "i387,*,*,*")
2732    (set_attr "mode" "DF,SI,SI,DF")])
2733
2734 ;; %%% Kill this when call knows how to work this out.
2735 (define_split
2736   [(set (match_operand:DF 0 "push_operand" "")
2737         (match_operand:DF 1 "any_fp_register_operand" ""))]
2738   "reload_completed"
2739   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -8)))
2740    (set (mem:DF (reg:P SP_REG)) (match_dup 1))])
2741
2742 (define_split
2743   [(set (match_operand:DF 0 "push_operand" "")
2744         (match_operand:DF 1 "general_operand" ""))]
2745   "reload_completed
2746    && !ANY_FP_REG_P (operands[1])"
2747   [(const_int 0)]
2748   "ix86_split_long_move (operands); DONE;")
2749
2750 (define_insn "*pushsf_rex64"
2751   [(set (match_operand:SF 0 "push_operand" "=X,X,X")
2752         (match_operand:SF 1 "nonmemory_no_elim_operand" "f,rF,x"))]
2753   "TARGET_64BIT"
2754 {
2755   /* Anything else should be already split before reg-stack.  */
2756   gcc_assert (which_alternative == 1);
2757   return "push{q}\t%q1";
2758 }
2759   [(set_attr "type" "multi,push,multi")
2760    (set_attr "unit" "i387,*,*")
2761    (set_attr "mode" "SF,DI,SF")])
2762
2763 (define_insn "*pushsf"
2764   [(set (match_operand:SF 0 "push_operand" "=<,<,<")
2765         (match_operand:SF 1 "general_no_elim_operand" "f,rFm,x"))]
2766   "!TARGET_64BIT"
2767 {
2768   /* Anything else should be already split before reg-stack.  */
2769   gcc_assert (which_alternative == 1);
2770   return "push{l}\t%1";
2771 }
2772   [(set_attr "type" "multi,push,multi")
2773    (set_attr "unit" "i387,*,*")
2774    (set_attr "mode" "SF,SI,SF")])
2775
2776 (define_split
2777   [(set (match_operand:SF 0 "push_operand" "")
2778         (match_operand:SF 1 "memory_operand" ""))]
2779   "reload_completed
2780    && MEM_P (operands[1])
2781    && (operands[2] = find_constant_src (insn))"
2782   [(set (match_dup 0)
2783         (match_dup 2))])
2784
2785 ;; %%% Kill this when call knows how to work this out.
2786 (define_split
2787   [(set (match_operand:SF 0 "push_operand" "")
2788         (match_operand:SF 1 "any_fp_register_operand" ""))]
2789   "reload_completed"
2790   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
2791    (set (mem:SF (reg:P SP_REG)) (match_dup 1))]
2792   "operands[2] = GEN_INT (-GET_MODE_SIZE (<MODE>mode));")
2793 \f
2794 ;; Floating point move instructions.
2795
2796 (define_expand "movtf"
2797   [(set (match_operand:TF 0 "nonimmediate_operand" "")
2798         (match_operand:TF 1 "nonimmediate_operand" ""))]
2799   "TARGET_SSE2"
2800 {
2801   ix86_expand_move (TFmode, operands);
2802   DONE;
2803 })
2804
2805 (define_expand "mov<mode>"
2806   [(set (match_operand:X87MODEF 0 "nonimmediate_operand" "")
2807         (match_operand:X87MODEF 1 "general_operand" ""))]
2808   ""
2809   "ix86_expand_move (<MODE>mode, operands); DONE;")
2810
2811 (define_insn "*movtf_internal"
2812   [(set (match_operand:TF 0 "nonimmediate_operand" "=x,m,x,?r,?o")
2813         (match_operand:TF 1 "general_operand" "xm,x,C,roF,Fr"))]
2814   "TARGET_SSE2
2815    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2816 {
2817   switch (which_alternative)
2818     {
2819     case 0:
2820     case 1:
2821       if (get_attr_mode (insn) == MODE_V4SF)
2822         return "%vmovaps\t{%1, %0|%0, %1}";
2823       else
2824         return "%vmovdqa\t{%1, %0|%0, %1}";
2825     case 2:
2826       if (get_attr_mode (insn) == MODE_V4SF)
2827         return "%vxorps\t%0, %d0";
2828       else
2829         return "%vpxor\t%0, %d0";
2830     case 3:
2831     case 4:
2832         return "#";
2833     default:
2834       gcc_unreachable ();
2835     }
2836 }
2837   [(set_attr "type" "ssemov,ssemov,sselog1,*,*")
2838    (set_attr "prefix" "maybe_vex,maybe_vex,maybe_vex,*,*")
2839    (set (attr "mode")
2840         (cond [(eq_attr "alternative" "0,2")
2841                  (if_then_else
2842                    (ne (symbol_ref "optimize_function_for_size_p (cfun)")
2843                        (const_int 0))
2844                    (const_string "V4SF")
2845                    (const_string "TI"))
2846                (eq_attr "alternative" "1")
2847                  (if_then_else
2848                    (ior (ne (symbol_ref "TARGET_SSE_TYPELESS_STORES")
2849                             (const_int 0))
2850                         (ne (symbol_ref "optimize_function_for_size_p (cfun)")
2851                             (const_int 0)))
2852                    (const_string "V4SF")
2853                    (const_string "TI"))]
2854                (const_string "DI")))])
2855
2856 (define_split
2857   [(set (match_operand:TF 0 "nonimmediate_operand" "")
2858         (match_operand:TF 1 "general_operand" ""))]
2859   "reload_completed
2860    && !(SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]))"
2861   [(const_int 0)]
2862   "ix86_split_long_move (operands); DONE;")
2863
2864 (define_insn "*movxf_internal"
2865   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m,f,r,o")
2866         (match_operand:XF 1 "general_operand" "fm,f,G,roF,Fr"))]
2867   "optimize_function_for_speed_p (cfun)
2868    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
2869    && (!can_create_pseudo_p ()
2870        || GET_CODE (operands[1]) != CONST_DOUBLE
2871        || memory_operand (operands[0], XFmode))"
2872 {
2873   switch (which_alternative)
2874     {
2875     case 0:
2876     case 1:
2877       return output_387_reg_move (insn, operands);
2878
2879     case 2:
2880       return standard_80387_constant_opcode (operands[1]);
2881
2882     case 3: case 4:
2883       return "#";
2884
2885     default:
2886       gcc_unreachable ();
2887     }
2888 }
2889   [(set_attr "type" "fmov,fmov,fmov,multi,multi")
2890    (set_attr "mode" "XF,XF,XF,SI,SI")])
2891
2892 ;; Do not use integer registers when optimizing for size
2893 (define_insn "*movxf_internal_nointeger"
2894   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m,f,*r,o")
2895         (match_operand:XF 1 "general_operand" "fm,f,G,*roF,F*r"))]
2896   "optimize_function_for_size_p (cfun)
2897    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
2898    && (!can_create_pseudo_p ()
2899        || standard_80387_constant_p (operands[1])
2900        || GET_CODE (operands[1]) != CONST_DOUBLE
2901        || memory_operand (operands[0], XFmode))"
2902 {
2903   switch (which_alternative)
2904     {
2905     case 0:
2906     case 1:
2907       return output_387_reg_move (insn, operands);
2908
2909     case 2:
2910       return standard_80387_constant_opcode (operands[1]);
2911
2912     case 3: case 4:
2913       return "#";
2914     default:
2915       gcc_unreachable ();
2916     }
2917 }
2918   [(set_attr "type" "fmov,fmov,fmov,multi,multi")
2919    (set_attr "mode" "XF,XF,XF,SI,SI")])
2920
2921 (define_split
2922   [(set (match_operand:XF 0 "nonimmediate_operand" "")
2923         (match_operand:XF 1 "general_operand" ""))]
2924   "reload_completed
2925    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
2926    && ! (FP_REG_P (operands[0]) ||
2927          (GET_CODE (operands[0]) == SUBREG
2928           && FP_REG_P (SUBREG_REG (operands[0]))))
2929    && ! (FP_REG_P (operands[1]) ||
2930          (GET_CODE (operands[1]) == SUBREG
2931           && FP_REG_P (SUBREG_REG (operands[1]))))"
2932   [(const_int 0)]
2933   "ix86_split_long_move (operands); DONE;")
2934
2935 (define_insn "*movdf_internal_rex64"
2936   [(set (match_operand:DF 0 "nonimmediate_operand"
2937                 "=f,m,f,r ,m,!r,!m,Y2*x,Y2*x,Y2*x,m   ,Yi,r ")
2938         (match_operand:DF 1 "general_operand"
2939                 "fm,f,G,rm,r,F ,F ,C   ,Y2*x,m   ,Y2*x,r ,Yi"))]
2940   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))
2941    && (!can_create_pseudo_p ()
2942        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
2943        || (!(TARGET_SSE2 && TARGET_SSE_MATH)
2944            && optimize_function_for_size_p (cfun)
2945            && standard_80387_constant_p (operands[1]))
2946        || GET_CODE (operands[1]) != CONST_DOUBLE
2947        || memory_operand (operands[0], DFmode))"
2948 {
2949   switch (which_alternative)
2950     {
2951     case 0:
2952     case 1:
2953       return output_387_reg_move (insn, operands);
2954
2955     case 2:
2956       return standard_80387_constant_opcode (operands[1]);
2957
2958     case 3:
2959     case 4:
2960       return "mov{q}\t{%1, %0|%0, %1}";
2961
2962     case 5:
2963       return "movabs{q}\t{%1, %0|%0, %1}";
2964
2965     case 6:
2966       return "#";
2967
2968     case 7:
2969       switch (get_attr_mode (insn))
2970         {
2971         case MODE_V4SF:
2972           return "%vxorps\t%0, %d0";
2973         case MODE_V2DF:
2974           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
2975             return "%vxorps\t%0, %d0";
2976           else
2977             return "%vxorpd\t%0, %d0";
2978         case MODE_TI:
2979           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
2980             return "%vxorps\t%0, %d0";
2981           else
2982             return "%vpxor\t%0, %d0";
2983         default:
2984           gcc_unreachable ();
2985         }
2986     case 8:
2987     case 9:
2988     case 10:
2989       switch (get_attr_mode (insn))
2990         {
2991         case MODE_V4SF:
2992           return "%vmovaps\t{%1, %0|%0, %1}";
2993         case MODE_V2DF:
2994           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
2995             return "%vmovaps\t{%1, %0|%0, %1}";
2996           else
2997             return "%vmovapd\t{%1, %0|%0, %1}";
2998         case MODE_TI:
2999           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
3000             return "%vmovaps\t{%1, %0|%0, %1}";
3001           else
3002             return "%vmovdqa\t{%1, %0|%0, %1}";
3003         case MODE_DI:
3004           return "%vmovq\t{%1, %0|%0, %1}";
3005         case MODE_DF:
3006           if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
3007             return "vmovsd\t{%1, %0, %0|%0, %0, %1}";
3008           else
3009             return "%vmovsd\t{%1, %0|%0, %1}";
3010         case MODE_V1DF:
3011           return "%vmovlpd\t{%1, %d0|%d0, %1}";
3012         case MODE_V2SF:
3013           return "%vmovlps\t{%1, %d0|%d0, %1}";
3014         default:
3015           gcc_unreachable ();
3016         }
3017
3018     case 11:
3019     case 12:
3020       /* Handle broken assemblers that require movd instead of movq.  */
3021       return "%vmovd\t{%1, %0|%0, %1}";
3022
3023     default:
3024       gcc_unreachable();
3025     }
3026 }
3027   [(set_attr "type" "fmov,fmov,fmov,imov,imov,imov,multi,sselog1,ssemov,ssemov,ssemov,ssemov,ssemov")
3028    (set (attr "modrm")
3029      (if_then_else
3030        (and (eq_attr "alternative" "5") (eq_attr "type" "imov"))
3031          (const_string "0")
3032          (const_string "*")))
3033    (set (attr "length_immediate")
3034      (if_then_else
3035        (and (eq_attr "alternative" "5") (eq_attr "type" "imov"))
3036          (const_string "8")
3037          (const_string "*")))
3038    (set (attr "prefix")
3039      (if_then_else (eq_attr "alternative" "0,1,2,3,4,5,6")
3040        (const_string "orig")
3041        (const_string "maybe_vex")))
3042    (set (attr "prefix_data16")
3043      (if_then_else (eq_attr "mode" "V1DF")
3044        (const_string "1")
3045        (const_string "*")))
3046    (set (attr "mode")
3047         (cond [(eq_attr "alternative" "0,1,2")
3048                  (const_string "DF")
3049                (eq_attr "alternative" "3,4,5,6,11,12")
3050                  (const_string "DI")
3051
3052                /* For SSE1, we have many fewer alternatives.  */
3053                (eq (symbol_ref "TARGET_SSE2") (const_int 0))
3054                  (cond [(eq_attr "alternative" "7,8")
3055                           (const_string "V4SF")
3056                        ]
3057                    (const_string "V2SF"))
3058
3059                /* xorps is one byte shorter.  */
3060                (eq_attr "alternative" "7")
3061                  (cond [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3062                             (const_int 0))
3063                           (const_string "V4SF")
3064                         (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
3065                             (const_int 0))
3066                           (const_string "TI")
3067                        ]
3068                        (const_string "V2DF"))
3069
3070                /* For architectures resolving dependencies on
3071                   whole SSE registers use APD move to break dependency
3072                   chains, otherwise use short move to avoid extra work.
3073
3074                   movaps encodes one byte shorter.  */
3075                (eq_attr "alternative" "8")
3076                  (cond
3077                    [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3078                         (const_int 0))
3079                       (const_string "V4SF")
3080                     (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3081                         (const_int 0))
3082                       (const_string "V2DF")
3083                    ]
3084                    (const_string "DF"))
3085                /* For architectures resolving dependencies on register
3086                   parts we may avoid extra work to zero out upper part
3087                   of register.  */
3088                (eq_attr "alternative" "9")
3089                  (if_then_else
3090                    (ne (symbol_ref "TARGET_SSE_SPLIT_REGS")
3091                        (const_int 0))
3092                    (const_string "V1DF")
3093                    (const_string "DF"))
3094               ]
3095               (const_string "DF")))])
3096
3097 (define_insn "*movdf_internal"
3098   [(set (match_operand:DF 0 "nonimmediate_operand"
3099                 "=f,m,f,r  ,o ,Y2*x,Y2*x,Y2*x,m   ")
3100         (match_operand:DF 1 "general_operand"
3101                 "fm,f,G,roF,Fr,C   ,Y2*x,m   ,Y2*x"))]
3102   "!TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))
3103    && optimize_function_for_speed_p (cfun)
3104    && TARGET_INTEGER_DFMODE_MOVES
3105    && (!can_create_pseudo_p ()
3106        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3107        || (!(TARGET_SSE2 && TARGET_SSE_MATH)
3108            && optimize_function_for_size_p (cfun)
3109            && standard_80387_constant_p (operands[1]))
3110        || GET_CODE (operands[1]) != CONST_DOUBLE
3111        || memory_operand (operands[0], DFmode))"
3112 {
3113   switch (which_alternative)
3114     {
3115     case 0:
3116     case 1:
3117       return output_387_reg_move (insn, operands);
3118
3119     case 2:
3120       return standard_80387_constant_opcode (operands[1]);
3121
3122     case 3:
3123     case 4:
3124       return "#";
3125
3126     case 5:
3127       switch (get_attr_mode (insn))
3128         {
3129         case MODE_V4SF:
3130           return "%vxorps\t%0, %d0";
3131         case MODE_V2DF:
3132           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
3133             return "%vxorps\t%0, %d0";
3134           else
3135             return "%vxorpd\t%0, %d0";
3136         case MODE_TI:
3137           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
3138             return "%vxorps\t%0, %d0";
3139           else
3140             return "%vpxor\t%0, %d0";
3141         default:
3142           gcc_unreachable ();
3143         }
3144     case 6:
3145     case 7:
3146     case 8:
3147       switch (get_attr_mode (insn))
3148         {
3149         case MODE_V4SF:
3150           return "%vmovaps\t{%1, %0|%0, %1}";
3151         case MODE_V2DF:
3152           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
3153             return "%vmovaps\t{%1, %0|%0, %1}";
3154           else
3155             return "%vmovapd\t{%1, %0|%0, %1}";
3156         case MODE_TI:
3157           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
3158             return "%vmovaps\t{%1, %0|%0, %1}";
3159           else
3160             return "%vmovdqa\t{%1, %0|%0, %1}";
3161         case MODE_DI:
3162           return "%vmovq\t{%1, %0|%0, %1}";
3163         case MODE_DF:
3164           if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
3165             return "vmovsd\t{%1, %0, %0|%0, %0, %1}";
3166           else
3167             return "%vmovsd\t{%1, %0|%0, %1}";
3168         case MODE_V1DF:
3169           if (TARGET_AVX && REG_P (operands[0]))
3170             return "vmovlpd\t{%1, %0, %0|%0, %0, %1}";
3171           else
3172             return "%vmovlpd\t{%1, %0|%0, %1}";
3173         case MODE_V2SF:
3174           if (TARGET_AVX && REG_P (operands[0]))
3175             return "vmovlps\t{%1, %0, %0|%0, %0, %1}";
3176           else
3177             return "%vmovlps\t{%1, %0|%0, %1}";
3178         default:
3179           gcc_unreachable ();
3180         }
3181
3182     default:
3183       gcc_unreachable ();
3184     }
3185 }
3186   [(set_attr "type" "fmov,fmov,fmov,multi,multi,sselog1,ssemov,ssemov,ssemov")
3187    (set (attr "prefix")
3188      (if_then_else (eq_attr "alternative" "0,1,2,3,4")
3189        (const_string "orig")
3190        (const_string "maybe_vex")))
3191    (set (attr "prefix_data16")
3192      (if_then_else (eq_attr "mode" "V1DF")
3193        (const_string "1")
3194        (const_string "*")))
3195    (set (attr "mode")
3196         (cond [(eq_attr "alternative" "0,1,2")
3197                  (const_string "DF")
3198                (eq_attr "alternative" "3,4")
3199                  (const_string "SI")
3200
3201                /* For SSE1, we have many fewer alternatives.  */
3202                (eq (symbol_ref "TARGET_SSE2") (const_int 0))
3203                  (cond [(eq_attr "alternative" "5,6")
3204                           (const_string "V4SF")
3205                        ]
3206                    (const_string "V2SF"))
3207
3208                /* xorps is one byte shorter.  */
3209                (eq_attr "alternative" "5")
3210                  (cond [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3211                             (const_int 0))
3212                           (const_string "V4SF")
3213                         (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
3214                             (const_int 0))
3215                           (const_string "TI")
3216                        ]
3217                        (const_string "V2DF"))
3218
3219                /* For architectures resolving dependencies on
3220                   whole SSE registers use APD move to break dependency
3221                   chains, otherwise use short move to avoid extra work.
3222
3223                   movaps encodes one byte shorter.  */
3224                (eq_attr "alternative" "6")
3225                  (cond
3226                    [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3227                         (const_int 0))
3228                       (const_string "V4SF")
3229                     (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3230                         (const_int 0))
3231                       (const_string "V2DF")
3232                    ]
3233                    (const_string "DF"))
3234                /* For architectures resolving dependencies on register
3235                   parts we may avoid extra work to zero out upper part
3236                   of register.  */
3237                (eq_attr "alternative" "7")
3238                  (if_then_else
3239                    (ne (symbol_ref "TARGET_SSE_SPLIT_REGS")
3240                        (const_int 0))
3241                    (const_string "V1DF")
3242                    (const_string "DF"))
3243               ]
3244               (const_string "DF")))])
3245
3246 ;; Moving is usually shorter when only FP registers are used. This separate
3247 ;; movdf pattern avoids the use of integer registers for FP operations
3248 ;; when optimizing for size.
3249
3250 (define_insn "*movdf_internal_nointeger"
3251   [(set (match_operand:DF 0 "nonimmediate_operand"
3252                         "=f,m,f,*r  ,o  ,Y2*x,Y2*x,Y2*x ,m  ")
3253         (match_operand:DF 1 "general_operand"
3254                         "fm,f,G,*roF,F*r,C   ,Y2*x,mY2*x,Y2*x"))]
3255   "!TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))
3256    && (optimize_function_for_size_p (cfun)
3257        || !TARGET_INTEGER_DFMODE_MOVES)
3258    && (!can_create_pseudo_p ()
3259        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3260        || (!(TARGET_SSE2 && TARGET_SSE_MATH)
3261            && optimize_function_for_size_p (cfun)
3262            && !memory_operand (operands[0], DFmode)
3263            && standard_80387_constant_p (operands[1]))
3264        || GET_CODE (operands[1]) != CONST_DOUBLE
3265        || ((optimize_function_for_size_p (cfun)
3266             || !TARGET_MEMORY_MISMATCH_STALL)
3267            && memory_operand (operands[0], DFmode)))"
3268 {
3269   switch (which_alternative)
3270     {
3271     case 0:
3272     case 1:
3273       return output_387_reg_move (insn, operands);
3274
3275     case 2:
3276       return standard_80387_constant_opcode (operands[1]);
3277
3278     case 3:
3279     case 4:
3280       return "#";
3281
3282     case 5:
3283       switch (get_attr_mode (insn))
3284         {
3285         case MODE_V4SF:
3286           return "%vxorps\t%0, %d0";
3287         case MODE_V2DF:
3288           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
3289             return "%vxorps\t%0, %d0";
3290           else
3291             return "%vxorpd\t%0, %d0";
3292         case MODE_TI:
3293           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
3294             return "%vxorps\t%0, %d0";
3295           else
3296             return "%vpxor\t%0, %d0";
3297         default:
3298           gcc_unreachable ();
3299         }
3300     case 6:
3301     case 7:
3302     case 8:
3303       switch (get_attr_mode (insn))
3304         {
3305         case MODE_V4SF:
3306           return "%vmovaps\t{%1, %0|%0, %1}";
3307         case MODE_V2DF:
3308           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
3309             return "%vmovaps\t{%1, %0|%0, %1}";
3310           else
3311             return "%vmovapd\t{%1, %0|%0, %1}";
3312         case MODE_TI:
3313           if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
3314             return "%vmovaps\t{%1, %0|%0, %1}";
3315           else
3316             return "%vmovdqa\t{%1, %0|%0, %1}";
3317         case MODE_DI:
3318           return "%vmovq\t{%1, %0|%0, %1}";
3319         case MODE_DF:
3320           if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
3321             return "vmovsd\t{%1, %0, %0|%0, %0, %1}";
3322           else
3323             return "%vmovsd\t{%1, %0|%0, %1}";
3324         case MODE_V1DF:
3325           if (TARGET_AVX && REG_P (operands[0]))
3326             return "vmovlpd\t{%1, %0, %0|%0, %0, %1}";
3327           else
3328             return "%vmovlpd\t{%1, %0|%0, %1}";
3329         case MODE_V2SF:
3330           if (TARGET_AVX && REG_P (operands[0]))
3331             return "vmovlps\t{%1, %0, %0|%0, %0, %1}";
3332           else
3333             return "%vmovlps\t{%1, %0|%0, %1}";
3334         default:
3335           gcc_unreachable ();
3336         }
3337
3338     default:
3339       gcc_unreachable ();
3340     }
3341 }
3342   [(set_attr "type" "fmov,fmov,fmov,multi,multi,sselog1,ssemov,ssemov,ssemov")
3343    (set (attr "prefix")
3344      (if_then_else (eq_attr "alternative" "0,1,2,3,4")
3345        (const_string "orig")
3346        (const_string "maybe_vex")))
3347    (set (attr "prefix_data16")
3348      (if_then_else (eq_attr "mode" "V1DF")
3349        (const_string "1")
3350        (const_string "*")))
3351    (set (attr "mode")
3352         (cond [(eq_attr "alternative" "0,1,2")
3353                  (const_string "DF")
3354                (eq_attr "alternative" "3,4")
3355                  (const_string "SI")
3356
3357                /* For SSE1, we have many fewer alternatives.  */
3358                (eq (symbol_ref "TARGET_SSE2") (const_int 0))
3359                  (cond [(eq_attr "alternative" "5,6")
3360                           (const_string "V4SF")
3361                        ]
3362                    (const_string "V2SF"))
3363
3364                /* xorps is one byte shorter.  */
3365                (eq_attr "alternative" "5")
3366                  (cond [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3367                             (const_int 0))
3368                           (const_string "V4SF")
3369                         (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
3370                             (const_int 0))
3371                           (const_string "TI")
3372                        ]
3373                        (const_string "V2DF"))
3374
3375                /* For architectures resolving dependencies on
3376                   whole SSE registers use APD move to break dependency
3377                   chains, otherwise use short move to avoid extra work.
3378
3379                   movaps encodes one byte shorter.  */
3380                (eq_attr "alternative" "6")
3381                  (cond
3382                    [(ne (symbol_ref "optimize_function_for_size_p (cfun)")
3383                         (const_int 0))
3384                       (const_string "V4SF")
3385                     (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3386                         (const_int 0))
3387                       (const_string "V2DF")
3388                    ]
3389                    (const_string "DF"))
3390                /* For architectures resolving dependencies on register
3391                   parts we may avoid extra work to zero out upper part
3392                   of register.  */
3393                (eq_attr "alternative" "7")
3394                  (if_then_else
3395                    (ne (symbol_ref "TARGET_SSE_SPLIT_REGS")
3396                        (const_int 0))
3397                    (const_string "V1DF")
3398                    (const_string "DF"))
3399               ]
3400               (const_string "DF")))])
3401
3402 (define_split
3403   [(set (match_operand:DF 0 "nonimmediate_operand" "")
3404         (match_operand:DF 1 "general_operand" ""))]
3405   "reload_completed
3406    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
3407    && ! (ANY_FP_REG_P (operands[0]) ||
3408          (GET_CODE (operands[0]) == SUBREG
3409           && ANY_FP_REG_P (SUBREG_REG (operands[0]))))
3410    && ! (ANY_FP_REG_P (operands[1]) ||
3411          (GET_CODE (operands[1]) == SUBREG
3412           && ANY_FP_REG_P (SUBREG_REG (operands[1]))))"
3413   [(const_int 0)]
3414   "ix86_split_long_move (operands); DONE;")
3415
3416 (define_insn "*movsf_internal"
3417   [(set (match_operand:SF 0 "nonimmediate_operand"
3418           "=f,m,f,r  ,m ,x,x,x ,m,!*y,!m,!*y,?Yi,?r,!*Ym,!r")
3419         (match_operand:SF 1 "general_operand"
3420           "fm,f,G,rmF,Fr,C,x,xm,x,m  ,*y,*y ,r  ,Yi,r   ,*Ym"))]
3421   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
3422    && (!can_create_pseudo_p ()
3423        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3424        || (!TARGET_SSE_MATH && optimize_function_for_size_p (cfun)
3425            && standard_80387_constant_p (operands[1]))
3426        || GET_CODE (operands[1]) != CONST_DOUBLE
3427        || memory_operand (operands[0], SFmode))"
3428 {
3429   switch (which_alternative)
3430     {
3431     case 0:
3432     case 1:
3433       return output_387_reg_move (insn, operands);
3434
3435     case 2:
3436       return standard_80387_constant_opcode (operands[1]);
3437
3438     case 3:
3439     case 4:
3440       return "mov{l}\t{%1, %0|%0, %1}";
3441     case 5:
3442       if (get_attr_mode (insn) == MODE_TI)
3443         return "%vpxor\t%0, %d0";
3444       else
3445         return "%vxorps\t%0, %d0";
3446     case 6:
3447       if (get_attr_mode (insn) == MODE_V4SF)
3448         return "%vmovaps\t{%1, %0|%0, %1}";
3449       else
3450         return "%vmovss\t{%1, %d0|%d0, %1}";
3451     case 7:
3452       if (TARGET_AVX && REG_P (operands[1]))
3453         return "vmovss\t{%1, %0, %0|%0, %0, %1}";
3454       else
3455         return "%vmovss\t{%1, %0|%0, %1}";
3456     case 8:
3457       return "%vmovss\t{%1, %0|%0, %1}";
3458
3459     case 9: case 10: case 14: case 15:
3460       return "movd\t{%1, %0|%0, %1}";
3461
3462     case 11:
3463       return "movq\t{%1, %0|%0, %1}";
3464
3465     case 12: case 13:
3466       return "%vmovd\t{%1, %0|%0, %1}";
3467
3468     default:
3469       gcc_unreachable ();
3470     }
3471 }
3472   [(set_attr "type" "fmov,fmov,fmov,imov,imov,sselog1,ssemov,ssemov,ssemov,mmxmov,mmxmov,mmxmov,ssemov,ssemov,mmxmov,mmxmov")
3473    (set (attr "prefix")
3474      (if_then_else (eq_attr "alternative" "5,6,7,8,12,13")
3475        (const_string "maybe_vex")
3476        (const_string "orig")))
3477    (set (attr "mode")
3478         (cond [(eq_attr "alternative" "3,4,9,10")
3479                  (const_string "SI")
3480                (eq_attr "alternative" "5")
3481                  (if_then_else
3482                    (and (and (ne (symbol_ref "TARGET_SSE_LOAD0_BY_PXOR")
3483                                  (const_int 0))
3484                              (ne (symbol_ref "TARGET_SSE2")
3485                                  (const_int 0)))
3486                         (eq (symbol_ref "optimize_function_for_size_p (cfun)")
3487                             (const_int 0)))
3488                    (const_string "TI")
3489                    (const_string "V4SF"))
3490                /* For architectures resolving dependencies on
3491                   whole SSE registers use APS move to break dependency
3492                   chains, otherwise use short move to avoid extra work.
3493
3494                   Do the same for architectures resolving dependencies on
3495                   the parts.  While in DF mode it is better to always handle
3496                   just register parts, the SF mode is different due to lack
3497                   of instructions to load just part of the register.  It is
3498                   better to maintain the whole registers in single format
3499                   to avoid problems on using packed logical operations.  */
3500                (eq_attr "alternative" "6")
3501                  (if_then_else
3502                    (ior (ne (symbol_ref "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3503                             (const_int 0))
3504                         (ne (symbol_ref "TARGET_SSE_SPLIT_REGS")
3505                             (const_int 0)))
3506                    (const_string "V4SF")
3507                    (const_string "SF"))
3508                (eq_attr "alternative" "11")
3509                  (const_string "DI")]
3510                (const_string "SF")))])
3511
3512 (define_split
3513   [(set (match_operand 0 "register_operand" "")
3514         (match_operand 1 "memory_operand" ""))]
3515   "reload_completed
3516    && MEM_P (operands[1])
3517    && (GET_MODE (operands[0]) == TFmode
3518        || GET_MODE (operands[0]) == XFmode
3519        || GET_MODE (operands[0]) == DFmode
3520        || GET_MODE (operands[0]) == SFmode)
3521    && (operands[2] = find_constant_src (insn))"
3522   [(set (match_dup 0) (match_dup 2))]
3523 {
3524   rtx c = operands[2];
3525   rtx r = operands[0];
3526
3527   if (GET_CODE (r) == SUBREG)
3528     r = SUBREG_REG (r);
3529
3530   if (SSE_REG_P (r))
3531     {
3532       if (!standard_sse_constant_p (c))
3533         FAIL;
3534     }
3535   else if (FP_REG_P (r))
3536     {
3537       if (!standard_80387_constant_p (c))
3538         FAIL;
3539     }
3540   else if (MMX_REG_P (r))
3541     FAIL;
3542 })
3543
3544 (define_split
3545   [(set (match_operand 0 "register_operand" "")
3546         (float_extend (match_operand 1 "memory_operand" "")))]
3547   "reload_completed
3548    && MEM_P (operands[1])
3549    && (GET_MODE (operands[0]) == TFmode
3550        || GET_MODE (operands[0]) == XFmode
3551        || GET_MODE (operands[0]) == DFmode
3552        || GET_MODE (operands[0]) == SFmode)
3553    && (operands[2] = find_constant_src (insn))"
3554   [(set (match_dup 0) (match_dup 2))]
3555 {
3556   rtx c = operands[2];
3557   rtx r = operands[0];
3558
3559   if (GET_CODE (r) == SUBREG)
3560     r = SUBREG_REG (r);
3561
3562   if (SSE_REG_P (r))
3563     {
3564       if (!standard_sse_constant_p (c))
3565         FAIL;
3566     }
3567   else if (FP_REG_P (r))
3568     {
3569       if (!standard_80387_constant_p (c))
3570         FAIL;
3571     }
3572   else if (MMX_REG_P (r))
3573     FAIL;
3574 })
3575
3576 ;; Split the load of -0.0 or -1.0 into fldz;fchs or fld1;fchs sequence
3577 (define_split
3578   [(set (match_operand:X87MODEF 0 "register_operand" "")
3579         (match_operand:X87MODEF 1 "immediate_operand" ""))]
3580   "reload_completed && FP_REGNO_P (REGNO (operands[0]))
3581    && (standard_80387_constant_p (operands[1]) == 8
3582        || standard_80387_constant_p (operands[1]) == 9)"
3583   [(set (match_dup 0)(match_dup 1))
3584    (set (match_dup 0)
3585         (neg:X87MODEF (match_dup 0)))]
3586 {
3587   REAL_VALUE_TYPE r;
3588
3589   REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
3590   if (real_isnegzero (&r))
3591     operands[1] = CONST0_RTX (<MODE>mode);
3592   else
3593     operands[1] = CONST1_RTX (<MODE>mode);
3594 })
3595
3596 (define_insn "swapxf"
3597   [(set (match_operand:XF 0 "register_operand" "+f")
3598         (match_operand:XF 1 "register_operand" "+f"))
3599    (set (match_dup 1)
3600         (match_dup 0))]
3601   "TARGET_80387"
3602 {
3603   if (STACK_TOP_P (operands[0]))
3604     return "fxch\t%1";
3605   else
3606     return "fxch\t%0";
3607 }
3608   [(set_attr "type" "fxch")
3609    (set_attr "mode" "XF")])
3610
3611 (define_insn "*swap<mode>"
3612   [(set (match_operand:MODEF 0 "fp_register_operand" "+f")
3613         (match_operand:MODEF 1 "fp_register_operand" "+f"))
3614    (set (match_dup 1)
3615         (match_dup 0))]
3616   "TARGET_80387 || reload_completed"
3617 {
3618   if (STACK_TOP_P (operands[0]))
3619     return "fxch\t%1";
3620   else
3621     return "fxch\t%0";
3622 }
3623   [(set_attr "type" "fxch")
3624    (set_attr "mode" "<MODE>")])
3625 \f
3626 ;; Zero extension instructions
3627
3628 (define_expand "zero_extendsidi2"
3629   [(set (match_operand:DI 0 "nonimmediate_operand" "")
3630         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "")))]
3631   ""
3632 {
3633   if (!TARGET_64BIT)
3634     {
3635       emit_insn (gen_zero_extendsidi2_1 (operands[0], operands[1]));
3636       DONE;
3637     }
3638 })
3639
3640 (define_insn "*zero_extendsidi2_rex64"
3641   [(set (match_operand:DI 0 "nonimmediate_operand"  "=r,o,?*Ym,?*y,?*Yi,*Y2")
3642         (zero_extend:DI
3643          (match_operand:SI 1 "nonimmediate_operand" "rm,0,r   ,m  ,r   ,m")))]
3644   "TARGET_64BIT"
3645   "@
3646    mov\t{%k1, %k0|%k0, %k1}
3647    #
3648    movd\t{%1, %0|%0, %1}
3649    movd\t{%1, %0|%0, %1}
3650    %vmovd\t{%1, %0|%0, %1}
3651    %vmovd\t{%1, %0|%0, %1}"
3652   [(set_attr "type" "imovx,imov,mmxmov,mmxmov,ssemov,ssemov")
3653    (set_attr "prefix" "orig,*,orig,orig,maybe_vex,maybe_vex")
3654    (set_attr "prefix_0f" "0,*,*,*,*,*")
3655    (set_attr "mode" "SI,DI,DI,DI,TI,TI")])
3656
3657 (define_split
3658   [(set (match_operand:DI 0 "memory_operand" "")
3659         (zero_extend:DI (match_dup 0)))]
3660   "TARGET_64BIT"
3661   [(set (match_dup 4) (const_int 0))]
3662   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3663
3664 ;; %%% Kill me once multi-word ops are sane.
3665 (define_insn "zero_extendsidi2_1"
3666   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,?r,?o,?*Ym,?*y,?*Yi,*Y2")
3667         (zero_extend:DI
3668          (match_operand:SI 1 "nonimmediate_operand" "0,rm,r ,r   ,m  ,r   ,m")))
3669    (clobber (reg:CC FLAGS_REG))]
3670   "!TARGET_64BIT"
3671   "@
3672    #
3673    #
3674    #
3675    movd\t{%1, %0|%0, %1}
3676    movd\t{%1, %0|%0, %1}
3677    %vmovd\t{%1, %0|%0, %1}
3678    %vmovd\t{%1, %0|%0, %1}"
3679   [(set_attr "type" "multi,multi,multi,mmxmov,mmxmov,ssemov,ssemov")
3680    (set_attr "prefix" "*,*,*,orig,orig,maybe_vex,maybe_vex")
3681    (set_attr "mode" "SI,SI,SI,DI,DI,TI,TI")])
3682
3683 (define_split
3684   [(set (match_operand:DI 0 "register_operand" "")
3685         (zero_extend:DI (match_operand:SI 1 "register_operand" "")))
3686    (clobber (reg:CC FLAGS_REG))]
3687   "!TARGET_64BIT && reload_completed
3688    && true_regnum (operands[0]) == true_regnum (operands[1])"
3689   [(set (match_dup 4) (const_int 0))]
3690   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3691
3692 (define_split
3693   [(set (match_operand:DI 0 "nonimmediate_operand" "")
3694         (zero_extend:DI (match_operand:SI 1 "general_operand" "")))
3695    (clobber (reg:CC FLAGS_REG))]
3696   "!TARGET_64BIT && reload_completed
3697    && !(MMX_REG_P (operands[0]) || SSE_REG_P (operands[0]))"
3698   [(set (match_dup 3) (match_dup 1))
3699    (set (match_dup 4) (const_int 0))]
3700   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3701
3702 (define_insn "zero_extend<mode>di2"
3703   [(set (match_operand:DI 0 "register_operand" "=r")
3704         (zero_extend:DI
3705          (match_operand:SWI12 1 "nonimmediate_operand" "<r>m")))]
3706   "TARGET_64BIT"
3707   "movz{<imodesuffix>l|x}\t{%1, %k0|%k0, %1}"
3708   [(set_attr "type" "imovx")
3709    (set_attr "mode" "SI")])
3710
3711 (define_expand "zero_extendhisi2"
3712   [(set (match_operand:SI 0 "register_operand" "")
3713         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "")))]
3714   ""
3715 {
3716   if (TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))
3717     {
3718       operands[1] = force_reg (HImode, operands[1]);
3719       emit_insn (gen_zero_extendhisi2_and (operands[0], operands[1]));
3720       DONE;
3721     }
3722 })
3723
3724 (define_insn_and_split "zero_extendhisi2_and"
3725   [(set (match_operand:SI 0 "register_operand" "=r")
3726         (zero_extend:SI (match_operand:HI 1 "register_operand" "0")))
3727    (clobber (reg:CC FLAGS_REG))]
3728   "TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
3729   "#"
3730   "&& reload_completed"
3731   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (const_int 65535)))
3732               (clobber (reg:CC FLAGS_REG))])]
3733   ""
3734   [(set_attr "type" "alu1")
3735    (set_attr "mode" "SI")])
3736
3737 (define_insn "*zero_extendhisi2_movzwl"
3738   [(set (match_operand:SI 0 "register_operand" "=r")
3739         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "rm")))]
3740   "!TARGET_ZERO_EXTEND_WITH_AND
3741    || optimize_function_for_size_p (cfun)"
3742   "movz{wl|x}\t{%1, %0|%0, %1}"
3743   [(set_attr "type" "imovx")
3744    (set_attr "mode" "SI")])
3745
3746 (define_expand "zero_extendqi<mode>2"
3747   [(parallel
3748     [(set (match_operand:SWI24 0 "register_operand" "")
3749           (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "")))
3750      (clobber (reg:CC FLAGS_REG))])])
3751
3752 (define_insn "*zero_extendqi<mode>2_and"
3753   [(set (match_operand:SWI24 0 "register_operand" "=r,?&q")
3754         (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "0,qm")))
3755    (clobber (reg:CC FLAGS_REG))]
3756   "TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
3757   "#"
3758   [(set_attr "type" "alu1")
3759    (set_attr "mode" "<MODE>")])
3760
3761 ;; When source and destination does not overlap, clear destination
3762 ;; first and then do the movb
3763 (define_split
3764   [(set (match_operand:SWI24 0 "register_operand" "")
3765         (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "")))
3766    (clobber (reg:CC FLAGS_REG))]
3767   "reload_completed
3768    && (TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))
3769    && ANY_QI_REG_P (operands[0])
3770    && (ANY_QI_REG_P (operands[1]) || MEM_P (operands[1]))
3771    && !reg_overlap_mentioned_p (operands[0], operands[1])"
3772   [(set (strict_low_part (match_dup 2)) (match_dup 1))]
3773 {
3774   operands[2] = gen_lowpart (QImode, operands[0]);
3775   ix86_expand_clear (operands[0]);
3776 })
3777
3778 (define_insn "*zero_extendqi<mode>2_movzbl_and"
3779   [(set (match_operand:SWI24 0 "register_operand" "=r,r")
3780         (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "qm,0")))
3781    (clobber (reg:CC FLAGS_REG))]
3782   "!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun)"
3783   "#"
3784   [(set_attr "type" "imovx,alu1")
3785    (set_attr "mode" "<MODE>")])
3786
3787 ;; For the movzbl case strip only the clobber
3788 (define_split
3789   [(set (match_operand:SWI24 0 "register_operand" "")
3790         (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "")))
3791    (clobber (reg:CC FLAGS_REG))]
3792   "reload_completed
3793    && (!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun))
3794    && (!REG_P (operands[1]) || ANY_QI_REG_P (operands[1]))"
3795   [(set (match_dup 0)
3796         (zero_extend:SWI24 (match_dup 1)))])
3797
3798 ; zero extend to SImode to avoid partial register stalls
3799 (define_insn "*zero_extendqi<mode>2_movzbl"
3800   [(set (match_operand:SWI24 0 "register_operand" "=r")
3801         (zero_extend:SWI24 (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3802   "reload_completed
3803    && (!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun))"
3804   "movz{bl|x}\t{%1, %k0|%k0, %1}"
3805   [(set_attr "type" "imovx")
3806    (set_attr "mode" "SI")])
3807
3808 ;; Rest is handled by single and.
3809 (define_split
3810   [(set (match_operand:SWI24 0 "register_operand" "")
3811         (zero_extend:SWI24 (match_operand:QI 1 "register_operand" "")))
3812    (clobber (reg:CC FLAGS_REG))]
3813   "reload_completed
3814    && true_regnum (operands[0]) == true_regnum (operands[1])"
3815   [(parallel [(set (match_dup 0) (and:SWI24 (match_dup 0) (const_int 255)))
3816               (clobber (reg:CC FLAGS_REG))])])
3817 \f
3818 ;; Sign extension instructions
3819
3820 (define_expand "extendsidi2"
3821   [(set (match_operand:DI 0 "register_operand" "")
3822         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))]
3823   ""
3824 {
3825   if (!TARGET_64BIT)
3826     {
3827       emit_insn (gen_extendsidi2_1 (operands[0], operands[1]));
3828       DONE;
3829     }
3830 })
3831
3832 (define_insn "*extendsidi2_rex64"
3833   [(set (match_operand:DI 0 "register_operand" "=*a,r")
3834         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "*0,rm")))]
3835   "TARGET_64BIT"
3836   "@
3837    {cltq|cdqe}
3838    movs{lq|x}\t{%1, %0|%0, %1}"
3839   [(set_attr "type" "imovx")
3840    (set_attr "mode" "DI")
3841    (set_attr "prefix_0f" "0")
3842    (set_attr "modrm" "0,1")])
3843
3844 (define_insn "extendsidi2_1"
3845   [(set (match_operand:DI 0 "nonimmediate_operand" "=*A,r,?r,?*o")
3846         (sign_extend:DI (match_operand:SI 1 "register_operand" "0,0,r,r")))
3847    (clobber (reg:CC FLAGS_REG))
3848    (clobber (match_scratch:SI 2 "=X,X,X,&r"))]
3849   "!TARGET_64BIT"
3850   "#")
3851
3852 ;; Extend to memory case when source register does die.
3853 (define_split
3854   [(set (match_operand:DI 0 "memory_operand" "")
3855         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3856    (clobber (reg:CC FLAGS_REG))
3857    (clobber (match_operand:SI 2 "register_operand" ""))]
3858   "(reload_completed
3859     && dead_or_set_p (insn, operands[1])
3860     && !reg_mentioned_p (operands[1], operands[0]))"
3861   [(set (match_dup 3) (match_dup 1))
3862    (parallel [(set (match_dup 1) (ashiftrt:SI (match_dup 1) (const_int 31)))
3863               (clobber (reg:CC FLAGS_REG))])
3864    (set (match_dup 4) (match_dup 1))]
3865   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3866
3867 ;; Extend to memory case when source register does not die.
3868 (define_split
3869   [(set (match_operand:DI 0 "memory_operand" "")
3870         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3871    (clobber (reg:CC FLAGS_REG))
3872    (clobber (match_operand:SI 2 "register_operand" ""))]
3873   "reload_completed"
3874   [(const_int 0)]
3875 {
3876   split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);
3877
3878   emit_move_insn (operands[3], operands[1]);
3879
3880   /* Generate a cltd if possible and doing so it profitable.  */
3881   if ((optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
3882       && true_regnum (operands[1]) == AX_REG
3883       && true_regnum (operands[2]) == DX_REG)
3884     {
3885       emit_insn (gen_ashrsi3_cvt (operands[2], operands[1], GEN_INT (31)));
3886     }
3887   else
3888     {
3889       emit_move_insn (operands[2], operands[1]);
3890       emit_insn (gen_ashrsi3_cvt (operands[2], operands[2], GEN_INT (31)));
3891     }
3892   emit_move_insn (operands[4], operands[2]);
3893   DONE;
3894 })
3895
3896 ;; Extend to register case.  Optimize case where source and destination
3897 ;; registers match and cases where we can use cltd.
3898 (define_split
3899   [(set (match_operand:DI 0 "register_operand" "")
3900         (sign_extend:DI (match_operand:SI 1 "register_operand" "")))
3901    (clobber (reg:CC FLAGS_REG))
3902    (clobber (match_scratch:SI 2 ""))]
3903   "reload_completed"
3904   [(const_int 0)]
3905 {
3906   split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);
3907
3908   if (true_regnum (operands[3]) != true_regnum (operands[1]))
3909     emit_move_insn (operands[3], operands[1]);
3910
3911   /* Generate a cltd if possible and doing so it profitable.  */
3912   if ((optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
3913       && true_regnum (operands[3]) == AX_REG
3914       && true_regnum (operands[4]) == DX_REG)
3915     {
3916       emit_insn (gen_ashrsi3_cvt (operands[4], operands[3], GEN_INT (31)));
3917       DONE;
3918     }
3919
3920   if (true_regnum (operands[4]) != true_regnum (operands[1]))
3921     emit_move_insn (operands[4], operands[1]);
3922
3923   emit_insn (gen_ashrsi3_cvt (operands[4], operands[4], GEN_INT (31)));
3924   DONE;
3925 })
3926
3927 (define_insn "extend<mode>di2"
3928   [(set (match_operand:DI 0 "register_operand" "=r")
3929         (sign_extend:DI
3930          (match_operand:SWI12 1 "nonimmediate_operand" "<r>m")))]
3931   "TARGET_64BIT"
3932   "movs{<imodesuffix>q|x}\t{%1, %0|%0, %1}"
3933   [(set_attr "type" "imovx")
3934    (set_attr "mode" "DI")])
3935
3936 (define_insn "extendhisi2"
3937   [(set (match_operand:SI 0 "register_operand" "=*a,r")
3938         (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "*0,rm")))]
3939   ""
3940 {
3941   switch (get_attr_prefix_0f (insn))
3942     {
3943     case 0:
3944       return "{cwtl|cwde}";
3945     default:
3946       return "movs{wl|x}\t{%1, %0|%0, %1}";
3947     }
3948 }
3949   [(set_attr "type" "imovx")
3950    (set_attr "mode" "SI")
3951    (set (attr "prefix_0f")
3952      ;; movsx is short decodable while cwtl is vector decoded.
3953      (if_then_else (and (eq_attr "cpu" "!k6")
3954                         (eq_attr "alternative" "0"))
3955         (const_string "0")
3956         (const_string "1")))
3957    (set (attr "modrm")
3958      (if_then_else (eq_attr "prefix_0f" "0")
3959         (const_string "0")
3960         (const_string "1")))])
3961
3962 (define_insn "*extendhisi2_zext"
3963   [(set (match_operand:DI 0 "register_operand" "=*a,r")
3964         (zero_extend:DI
3965          (sign_extend:SI
3966           (match_operand:HI 1 "nonimmediate_operand" "*0,rm"))))]
3967   "TARGET_64BIT"
3968 {
3969   switch (get_attr_prefix_0f (insn))
3970     {
3971     case 0:
3972       return "{cwtl|cwde}";
3973     default:
3974       return "movs{wl|x}\t{%1, %k0|%k0, %1}";
3975     }
3976 }
3977   [(set_attr "type" "imovx")
3978    (set_attr "mode" "SI")
3979    (set (attr "prefix_0f")
3980      ;; movsx is short decodable while cwtl is vector decoded.
3981      (if_then_else (and (eq_attr "cpu" "!k6")
3982                         (eq_attr "alternative" "0"))
3983         (const_string "0")
3984         (const_string "1")))
3985    (set (attr "modrm")
3986      (if_then_else (eq_attr "prefix_0f" "0")
3987         (const_string "0")
3988         (const_string "1")))])
3989
3990 (define_insn "extendqisi2"
3991   [(set (match_operand:SI 0 "register_operand" "=r")
3992         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3993   ""
3994   "movs{bl|x}\t{%1, %0|%0, %1}"
3995    [(set_attr "type" "imovx")
3996     (set_attr "mode" "SI")])
3997
3998 (define_insn "*extendqisi2_zext"
3999   [(set (match_operand:DI 0 "register_operand" "=r")
4000         (zero_extend:DI
4001           (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm"))))]
4002   "TARGET_64BIT"
4003   "movs{bl|x}\t{%1, %k0|%k0, %1}"
4004    [(set_attr "type" "imovx")
4005     (set_attr "mode" "SI")])
4006
4007 (define_insn "extendqihi2"
4008   [(set (match_operand:HI 0 "register_operand" "=*a,r")
4009         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "*0,qm")))]
4010   ""
4011 {
4012   switch (get_attr_prefix_0f (insn))
4013     {
4014     case 0:
4015       return "{cbtw|cbw}";
4016     default:
4017       return "movs{bw|x}\t{%1, %0|%0, %1}";
4018     }
4019 }
4020   [(set_attr "type" "imovx")
4021    (set_attr "mode" "HI")
4022    (set (attr "prefix_0f")
4023      ;; movsx is short decodable while cwtl is vector decoded.
4024      (if_then_else (and (eq_attr "cpu" "!k6")
4025                         (eq_attr "alternative" "0"))
4026         (const_string "0")
4027         (const_string "1")))
4028    (set (attr "modrm")
4029      (if_then_else (eq_attr "prefix_0f" "0")
4030         (const_string "0")
4031         (const_string "1")))])
4032 \f
4033 ;; Conversions between float and double.
4034
4035 ;; These are all no-ops in the model used for the 80387.
4036 ;; So just emit moves.
4037
4038 ;; %%% Kill these when call knows how to work out a DFmode push earlier.
4039 (define_split
4040   [(set (match_operand:DF 0 "push_operand" "")
4041         (float_extend:DF (match_operand:SF 1 "fp_register_operand" "")))]
4042   "reload_completed"
4043   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -8)))
4044    (set (mem:DF (reg:P SP_REG)) (float_extend:DF (match_dup 1)))])
4045
4046 (define_split
4047   [(set (match_operand:XF 0 "push_operand" "")
4048         (float_extend:XF (match_operand:MODEF 1 "fp_register_operand" "")))]
4049   "reload_completed"
4050   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
4051    (set (mem:XF (reg:P SP_REG)) (float_extend:XF (match_dup 1)))]
4052   "operands[2] = GEN_INT (-GET_MODE_SIZE (XFmode));")
4053
4054 (define_expand "extendsfdf2"
4055   [(set (match_operand:DF 0 "nonimmediate_operand" "")
4056         (float_extend:DF (match_operand:SF 1 "general_operand" "")))]
4057   "TARGET_80387 || (TARGET_SSE2 && TARGET_SSE_MATH)"
4058 {
4059   /* ??? Needed for compress_float_constant since all fp constants
4060      are TARGET_LEGITIMATE_CONSTANT_P.  */
4061   if (GET_CODE (operands[1]) == CONST_DOUBLE)
4062     {
4063       if ((!TARGET_SSE2 || TARGET_MIX_SSE_I387)
4064           && standard_80387_constant_p (operands[1]) > 0)
4065         {
4066           operands[1] = simplify_const_unary_operation
4067             (FLOAT_EXTEND, DFmode, operands[1], SFmode);
4068           emit_move_insn_1 (operands[0], operands[1]);
4069           DONE;
4070         }
4071       operands[1] = validize_mem (force_const_mem (SFmode, operands[1]));
4072     }
4073 })
4074
4075 /* For converting SF(xmm2) to DF(xmm1), use the following code instead of
4076    cvtss2sd:
4077       unpcklps xmm2,xmm2   ; packed conversion might crash on signaling NaNs
4078       cvtps2pd xmm2,xmm1
4079    We do the conversion post reload to avoid producing of 128bit spills
4080    that might lead to ICE on 32bit target.  The sequence unlikely combine
4081    anyway.  */
4082 (define_split
4083   [(set (match_operand:DF 0 "register_operand" "")
4084         (float_extend:DF
4085           (match_operand:SF 1 "nonimmediate_operand" "")))]
4086   "TARGET_USE_VECTOR_FP_CONVERTS
4087    && optimize_insn_for_speed_p ()
4088    && reload_completed && SSE_REG_P (operands[0])"
4089    [(set (match_dup 2)
4090          (float_extend:V2DF
4091            (vec_select:V2SF
4092              (match_dup 3)
4093              (parallel [(const_int 0) (const_int 1)]))))]
4094 {
4095   operands[2] = simplify_gen_subreg (V2DFmode, operands[0], DFmode, 0);
4096   operands[3] = simplify_gen_subreg (V4SFmode, operands[0], DFmode, 0);
4097   /* Use movss for loading from memory, unpcklps reg, reg for registers.
4098      Try to avoid move when unpacking can be done in source.  */
4099   if (REG_P (operands[1]))
4100     {
4101       /* If it is unsafe to overwrite upper half of source, we need
4102          to move to destination and unpack there.  */
4103       if ((ORIGINAL_REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
4104            || PSEUDO_REGNO_BYTES (ORIGINAL_REGNO (operands[1])) > 4)
4105           && true_regnum (operands[0]) != true_regnum (operands[1]))
4106         {
4107           rtx tmp = gen_rtx_REG (SFmode, true_regnum (operands[0]));
4108           emit_move_insn (tmp, operands[1]);
4109         }
4110       else
4111         operands[3] = simplify_gen_subreg (V4SFmode, operands[1], SFmode, 0);
4112       emit_insn (gen_vec_interleave_lowv4sf (operands[3], operands[3],
4113                                              operands[3]));
4114     }
4115   else
4116     emit_insn (gen_vec_setv4sf_0 (operands[3],
4117                                   CONST0_RTX (V4SFmode), operands[1]));
4118 })
4119
4120 (define_insn "*extendsfdf2_mixed"
4121   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,m,x")
4122         (float_extend:DF
4123           (match_operand:SF 1 "nonimmediate_operand" "fm,f,xm")))]
4124   "TARGET_SSE2 && TARGET_MIX_SSE_I387"
4125 {
4126   switch (which_alternative)
4127     {
4128     case 0:
4129     case 1:
4130       return output_387_reg_move (insn, operands);
4131
4132     case 2:
4133       return "%vcvtss2sd\t{%1, %d0|%d0, %1}";
4134
4135     default:
4136       gcc_unreachable ();
4137     }
4138 }
4139   [(set_attr "type" "fmov,fmov,ssecvt")
4140    (set_attr "prefix" "orig,orig,maybe_vex")
4141    (set_attr "mode" "SF,XF,DF")])
4142
4143 (define_insn "*extendsfdf2_sse"
4144   [(set (match_operand:DF 0 "nonimmediate_operand" "=x")
4145         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "xm")))]
4146   "TARGET_SSE2 && TARGET_SSE_MATH"
4147   "%vcvtss2sd\t{%1, %d0|%d0, %1}"
4148   [(set_attr "type" "ssecvt")
4149    (set_attr "prefix" "maybe_vex")
4150    (set_attr "mode" "DF")])
4151
4152 (define_insn "*extendsfdf2_i387"
4153   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,m")
4154         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "fm,f")))]
4155   "TARGET_80387"
4156   "* return output_387_reg_move (insn, operands);"
4157   [(set_attr "type" "fmov")
4158    (set_attr "mode" "SF,XF")])
4159
4160 (define_expand "extend<mode>xf2"
4161   [(set (match_operand:XF 0 "nonimmediate_operand" "")
4162         (float_extend:XF (match_operand:MODEF 1 "general_operand" "")))]
4163   "TARGET_80387"
4164 {
4165   /* ??? Needed for compress_float_constant since all fp constants
4166      are TARGET_LEGITIMATE_CONSTANT_P.  */
4167   if (GET_CODE (operands[1]) == CONST_DOUBLE)
4168     {
4169       if (standard_80387_constant_p (operands[1]) > 0)
4170         {
4171           operands[1] = simplify_const_unary_operation
4172             (FLOAT_EXTEND, XFmode, operands[1], <MODE>mode);
4173           emit_move_insn_1 (operands[0], operands[1]);
4174           DONE;
4175         }
4176       operands[1] = validize_mem (force_const_mem (<MODE>mode, operands[1]));
4177     }
4178 })
4179
4180 (define_insn "*extend<mode>xf2_i387"
4181   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m")
4182         (float_extend:XF
4183           (match_operand:MODEF 1 "nonimmediate_operand" "fm,f")))]
4184   "TARGET_80387"
4185   "* return output_387_reg_move (insn, operands);"
4186   [(set_attr "type" "fmov")
4187    (set_attr "mode" "<MODE>,XF")])
4188
4189 ;; %%% This seems bad bad news.
4190 ;; This cannot output into an f-reg because there is no way to be sure
4191 ;; of truncating in that case.  Otherwise this is just like a simple move
4192 ;; insn.  So we pretend we can output to a reg in order to get better
4193 ;; register preferencing, but we really use a stack slot.
4194
4195 ;; Conversion from DFmode to SFmode.
4196
4197 (define_expand "truncdfsf2"
4198   [(set (match_operand:SF 0 "nonimmediate_operand" "")
4199         (float_truncate:SF
4200           (match_operand:DF 1 "nonimmediate_operand" "")))]
4201   "TARGET_80387 || (TARGET_SSE2 && TARGET_SSE_MATH)"
4202 {
4203   if (TARGET_SSE2 && TARGET_SSE_MATH && !TARGET_MIX_SSE_I387)
4204     ;
4205   else if (flag_unsafe_math_optimizations)
4206     ;
4207   else
4208     {
4209       enum ix86_stack_slot slot = (virtuals_instantiated
4210                                    ? SLOT_TEMP
4211                                    : SLOT_VIRTUAL);
4212       rtx temp = assign_386_stack_local (SFmode, slot);
4213       emit_insn (gen_truncdfsf2_with_temp (operands[0], operands[1], temp));
4214       DONE;
4215     }
4216 })
4217
4218 /* For converting DF(xmm2) to SF(xmm1), use the following code instead of
4219    cvtsd2ss:
4220       unpcklpd xmm2,xmm2   ; packed conversion might crash on signaling NaNs
4221       cvtpd2ps xmm2,xmm1
4222    We do the conversion post reload to avoid producing of 128bit spills
4223    that might lead to ICE on 32bit target.  The sequence unlikely combine
4224    anyway.  */
4225 (define_split
4226   [(set (match_operand:SF 0 "register_operand" "")
4227         (float_truncate:SF
4228           (match_operand:DF 1 "nonimmediate_operand" "")))]
4229   "TARGET_USE_VECTOR_FP_CONVERTS
4230    && optimize_insn_for_speed_p ()
4231    && reload_completed && SSE_REG_P (operands[0])"
4232    [(set (match_dup 2)
4233          (vec_concat:V4SF
4234            (float_truncate:V2SF
4235              (match_dup 4))
4236            (match_dup 3)))]
4237 {
4238   operands[2] = simplify_gen_subreg (V4SFmode, operands[0], SFmode, 0);
4239   operands[3] = CONST0_RTX (V2SFmode);
4240   operands[4] = simplify_gen_subreg (V2DFmode, operands[0], SFmode, 0);
4241   /* Use movsd for loading from memory, unpcklpd for registers.
4242      Try to avoid move when unpacking can be done in source, or SSE3
4243      movddup is available.  */
4244   if (REG_P (operands[1]))
4245     {
4246       if (!TARGET_SSE3
4247           && true_regnum (operands[0]) != true_regnum (operands[1])
4248           && (ORIGINAL_REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
4249               || PSEUDO_REGNO_BYTES (ORIGINAL_REGNO (operands[1])) > 8))
4250         {
4251           rtx tmp = simplify_gen_subreg (DFmode, operands[0], SFmode, 0);
4252           emit_move_insn (tmp, operands[1]);
4253           operands[1] = tmp;
4254         }
4255       else if (!TARGET_SSE3)
4256         operands[4] = simplify_gen_subreg (V2DFmode, operands[1], DFmode, 0);
4257       emit_insn (gen_vec_dupv2df (operands[4], operands[1]));
4258     }
4259   else
4260     emit_insn (gen_sse2_loadlpd (operands[4],
4261                                  CONST0_RTX (V2DFmode), operands[1]));
4262 })
4263
4264 (define_expand "truncdfsf2_with_temp"
4265   [(parallel [(set (match_operand:SF 0 "" "")
4266                    (float_truncate:SF (match_operand:DF 1 "" "")))
4267               (clobber (match_operand:SF 2 "" ""))])])
4268
4269 (define_insn "*truncdfsf_fast_mixed"
4270   [(set (match_operand:SF 0 "nonimmediate_operand"   "=fm,x")
4271         (float_truncate:SF
4272           (match_operand:DF 1 "nonimmediate_operand" "f  ,xm")))]
4273   "TARGET_SSE2 && TARGET_MIX_SSE_I387 && flag_unsafe_math_optimizations"
4274 {
4275   switch (which_alternative)
4276     {
4277     case 0:
4278       return output_387_reg_move (insn, operands);
4279     case 1:
4280       return "%vcvtsd2ss\t{%1, %d0|%d0, %1}";
4281     default:
4282       gcc_unreachable ();
4283     }
4284 }
4285   [(set_attr "type" "fmov,ssecvt")
4286    (set_attr "prefix" "orig,maybe_vex")
4287    (set_attr "mode" "SF")])
4288
4289 ;; Yes, this one doesn't depend on flag_unsafe_math_optimizations,
4290 ;; because nothing we do here is unsafe.
4291 (define_insn "*truncdfsf_fast_sse"
4292   [(set (match_operand:SF 0 "nonimmediate_operand"   "=x")
4293         (float_truncate:SF
4294           (match_operand:DF 1 "nonimmediate_operand" "xm")))]
4295   "TARGET_SSE2 && TARGET_SSE_MATH"
4296   "%vcvtsd2ss\t{%1, %d0|%d0, %1}"
4297   [(set_attr "type" "ssecvt")
4298    (set_attr "prefix" "maybe_vex")
4299    (set_attr "mode" "SF")])
4300
4301 (define_insn "*truncdfsf_fast_i387"
4302   [(set (match_operand:SF 0 "nonimmediate_operand"   "=fm")
4303         (float_truncate:SF
4304           (match_operand:DF 1 "nonimmediate_operand" "f")))]
4305   "TARGET_80387 && flag_unsafe_math_optimizations"
4306   "* return output_387_reg_move (insn, operands);"
4307   [(set_attr "type" "fmov")
4308    (set_attr "mode" "SF")])
4309
4310 (define_insn "*truncdfsf_mixed"
4311   [(set (match_operand:SF 0 "nonimmediate_operand"   "=m,Y2 ,?f,?x,?*r")
4312         (float_truncate:SF
4313           (match_operand:DF 1 "nonimmediate_operand" "f ,Y2m,f ,f ,f")))
4314    (clobber (match_operand:SF 2 "memory_operand"     "=X,X  ,m ,m ,m"))]
4315   "TARGET_MIX_SSE_I387"
4316 {
4317   switch (which_alternative)
4318     {
4319     case 0:
4320       return output_387_reg_move (insn, operands);
4321     case 1:
4322       return "%vcvtsd2ss\t{%1, %d0|%d0, %1}";
4323
4324     default:
4325       return "#";
4326     }
4327 }
4328   [(set_attr "type" "fmov,ssecvt,multi,multi,multi")
4329    (set_attr "unit" "*,*,i387,i387,i387")
4330    (set_attr "prefix" "orig,maybe_vex,orig,orig,orig")
4331    (set_attr "mode" "SF")])
4332
4333 (define_insn "*truncdfsf_i387"
4334   [(set (match_operand:SF 0 "nonimmediate_operand"   "=m,?f,?x,?*r")
4335         (float_truncate:SF
4336           (match_operand:DF 1 "nonimmediate_operand" "f ,f ,f ,f")))
4337    (clobber (match_operand:SF 2 "memory_operand"     "=X,m ,m ,m"))]
4338   "TARGET_80387"
4339 {
4340   switch (which_alternative)
4341     {
4342     case 0:
4343       return output_387_reg_move (insn, operands);
4344
4345     default:
4346       return "#";
4347     }
4348 }
4349   [(set_attr "type" "fmov,multi,multi,multi")
4350    (set_attr "unit" "*,i387,i387,i387")
4351    (set_attr "mode" "SF")])
4352
4353 (define_insn "*truncdfsf2_i387_1"
4354   [(set (match_operand:SF 0 "memory_operand" "=m")
4355         (float_truncate:SF
4356           (match_operand:DF 1 "register_operand" "f")))]
4357   "TARGET_80387
4358    && !(TARGET_SSE2 && TARGET_SSE_MATH)
4359    && !TARGET_MIX_SSE_I387"
4360   "* return output_387_reg_move (insn, operands);"
4361   [(set_attr "type" "fmov")
4362    (set_attr "mode" "SF")])
4363
4364 (define_split
4365   [(set (match_operand:SF 0 "register_operand" "")
4366         (float_truncate:SF
4367          (match_operand:DF 1 "fp_register_operand" "")))
4368    (clobber (match_operand 2 "" ""))]
4369   "reload_completed"
4370   [(set (match_dup 2) (match_dup 1))
4371    (set (match_dup 0) (match_dup 2))]
4372   "operands[1] = gen_rtx_REG (SFmode, true_regnum (operands[1]));")
4373
4374 ;; Conversion from XFmode to {SF,DF}mode
4375
4376 (define_expand "truncxf<mode>2"
4377   [(parallel [(set (match_operand:MODEF 0 "nonimmediate_operand" "")
4378                    (float_truncate:MODEF
4379                      (match_operand:XF 1 "register_operand" "")))
4380               (clobber (match_dup 2))])]
4381   "TARGET_80387"
4382 {
4383   if (flag_unsafe_math_optimizations)
4384     {
4385       rtx reg = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (<MODE>mode);
4386       emit_insn (gen_truncxf<mode>2_i387_noop (reg, operands[1]));
4387       if (reg != operands[0])
4388         emit_move_insn (operands[0], reg);
4389       DONE;
4390     }
4391   else
4392     {
4393       enum ix86_stack_slot slot = (virtuals_instantiated
4394                                    ? SLOT_TEMP
4395                                    : SLOT_VIRTUAL);
4396       operands[2] = assign_386_stack_local (<MODE>mode, slot);
4397     }
4398 })
4399
4400 (define_insn "*truncxfsf2_mixed"
4401   [(set (match_operand:SF 0 "nonimmediate_operand" "=m,?f,?x,?*r")
4402         (float_truncate:SF
4403           (match_operand:XF 1 "register_operand"   "f ,f ,f ,f")))
4404    (clobber (match_operand:SF 2 "memory_operand"   "=X,m ,m ,m"))]
4405   "TARGET_80387"
4406 {
4407   gcc_assert (!which_alternative);
4408   return output_387_reg_move (insn, operands);
4409 }
4410   [(set_attr "type" "fmov,multi,multi,multi")
4411    (set_attr "unit" "*,i387,i387,i387")
4412    (set_attr "mode" "SF")])
4413
4414 (define_insn "*truncxfdf2_mixed"
4415   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,?f,?Y2,?*r")
4416         (float_truncate:DF
4417           (match_operand:XF 1 "register_operand"   "f ,f ,f  ,f")))
4418    (clobber (match_operand:DF 2 "memory_operand"   "=X,m ,m  ,m"))]
4419   "TARGET_80387"
4420 {
4421   gcc_assert (!which_alternative);
4422   return output_387_reg_move (insn, operands);
4423 }
4424   [(set_attr "type" "fmov,multi,multi,multi")
4425    (set_attr "unit" "*,i387,i387,i387")
4426    (set_attr "mode" "DF")])
4427
4428 (define_insn "truncxf<mode>2_i387_noop"
4429   [(set (match_operand:MODEF 0 "register_operand" "=f")
4430         (float_truncate:MODEF
4431           (match_operand:XF 1 "register_operand" "f")))]
4432   "TARGET_80387 && flag_unsafe_math_optimizations"
4433   "* return output_387_reg_move (insn, operands);"
4434   [(set_attr "type" "fmov")
4435    (set_attr "mode" "<MODE>")])
4436
4437 (define_insn "*truncxf<mode>2_i387"
4438   [(set (match_operand:MODEF 0 "memory_operand" "=m")
4439         (float_truncate:MODEF
4440           (match_operand:XF 1 "register_operand" "f")))]
4441   "TARGET_80387"
4442   "* return output_387_reg_move (insn, operands);"
4443   [(set_attr "type" "fmov")
4444    (set_attr "mode" "<MODE>")])
4445
4446 (define_split
4447   [(set (match_operand:MODEF 0 "register_operand" "")
4448         (float_truncate:MODEF
4449           (match_operand:XF 1 "register_operand" "")))
4450    (clobber (match_operand:MODEF 2 "memory_operand" ""))]
4451   "TARGET_80387 && reload_completed"
4452   [(set (match_dup 2) (float_truncate:MODEF (match_dup 1)))
4453    (set (match_dup 0) (match_dup 2))])
4454
4455 (define_split
4456   [(set (match_operand:MODEF 0 "memory_operand" "")
4457         (float_truncate:MODEF
4458           (match_operand:XF 1 "register_operand" "")))
4459    (clobber (match_operand:MODEF 2 "memory_operand" ""))]
4460   "TARGET_80387"
4461   [(set (match_dup 0) (float_truncate:MODEF (match_dup 1)))])
4462 \f
4463 ;; Signed conversion to DImode.
4464
4465 (define_expand "fix_truncxfdi2"
4466   [(parallel [(set (match_operand:DI 0 "nonimmediate_operand" "")
4467                    (fix:DI (match_operand:XF 1 "register_operand" "")))
4468               (clobber (reg:CC FLAGS_REG))])]
4469   "TARGET_80387"
4470 {
4471   if (TARGET_FISTTP)
4472    {
4473      emit_insn (gen_fix_truncdi_fisttp_i387_1 (operands[0], operands[1]));
4474      DONE;
4475    }
4476 })
4477
4478 (define_expand "fix_trunc<mode>di2"
4479   [(parallel [(set (match_operand:DI 0 "nonimmediate_operand" "")
4480                    (fix:DI (match_operand:MODEF 1 "register_operand" "")))
4481               (clobber (reg:CC FLAGS_REG))])]
4482   "TARGET_80387 || (TARGET_64BIT && SSE_FLOAT_MODE_P (<MODE>mode))"
4483 {
4484   if (TARGET_FISTTP
4485       && !(TARGET_64BIT && SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))
4486    {
4487      emit_insn (gen_fix_truncdi_fisttp_i387_1 (operands[0], operands[1]));
4488      DONE;
4489    }
4490   if (TARGET_64BIT && SSE_FLOAT_MODE_P (<MODE>mode))
4491    {
4492      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (DImode);
4493      emit_insn (gen_fix_trunc<mode>di_sse (out, operands[1]));
4494      if (out != operands[0])
4495         emit_move_insn (operands[0], out);
4496      DONE;
4497    }
4498 })
4499
4500 ;; Signed conversion to SImode.
4501
4502 (define_expand "fix_truncxfsi2"
4503   [(parallel [(set (match_operand:SI 0 "nonimmediate_operand" "")
4504                    (fix:SI (match_operand:XF 1 "register_operand" "")))
4505               (clobber (reg:CC FLAGS_REG))])]
4506   "TARGET_80387"
4507 {
4508   if (TARGET_FISTTP)
4509    {
4510      emit_insn (gen_fix_truncsi_fisttp_i387_1 (operands[0], operands[1]));
4511      DONE;
4512    }
4513 })
4514
4515 (define_expand "fix_trunc<mode>si2"
4516   [(parallel [(set (match_operand:SI 0 "nonimmediate_operand" "")
4517                    (fix:SI (match_operand:MODEF 1 "register_operand" "")))
4518               (clobber (reg:CC FLAGS_REG))])]
4519   "TARGET_80387 || SSE_FLOAT_MODE_P (<MODE>mode)"
4520 {
4521   if (TARGET_FISTTP
4522       && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))
4523    {
4524      emit_insn (gen_fix_truncsi_fisttp_i387_1 (operands[0], operands[1]));
4525      DONE;
4526    }
4527   if (SSE_FLOAT_MODE_P (<MODE>mode))
4528    {
4529      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (SImode);
4530      emit_insn (gen_fix_trunc<mode>si_sse (out, operands[1]));
4531      if (out != operands[0])
4532         emit_move_insn (operands[0], out);
4533      DONE;
4534    }
4535 })
4536
4537 ;; Signed conversion to HImode.
4538
4539 (define_expand "fix_trunc<mode>hi2"
4540   [(parallel [(set (match_operand:HI 0 "nonimmediate_operand" "")
4541                    (fix:HI (match_operand:X87MODEF 1 "register_operand" "")))
4542               (clobber (reg:CC FLAGS_REG))])]
4543   "TARGET_80387
4544    && !(SSE_FLOAT_MODE_P (<MODE>mode) && (!TARGET_FISTTP || TARGET_SSE_MATH))"
4545 {
4546   if (TARGET_FISTTP)
4547    {
4548      emit_insn (gen_fix_trunchi_fisttp_i387_1 (operands[0], operands[1]));
4549      DONE;
4550    }
4551 })
4552
4553 ;; Unsigned conversion to SImode.
4554
4555 (define_expand "fixuns_trunc<mode>si2"
4556   [(parallel
4557     [(set (match_operand:SI 0 "register_operand" "")
4558           (unsigned_fix:SI
4559             (match_operand:MODEF 1 "nonimmediate_operand" "")))
4560      (use (match_dup 2))
4561      (clobber (match_scratch:<ssevecmode> 3 ""))
4562      (clobber (match_scratch:<ssevecmode> 4 ""))])]
4563   "!TARGET_64BIT && TARGET_SSE2 && TARGET_SSE_MATH"
4564 {
4565   enum machine_mode mode = <MODE>mode;
4566   enum machine_mode vecmode = <ssevecmode>mode;
4567   REAL_VALUE_TYPE TWO31r;
4568   rtx two31;
4569
4570   if (optimize_insn_for_size_p ())
4571     FAIL;
4572
4573   real_ldexp (&TWO31r, &dconst1, 31);
4574   two31 = const_double_from_real_value (TWO31r, mode);
4575   two31 = ix86_build_const_vector (vecmode, true, two31);
4576   operands[2] = force_reg (vecmode, two31);
4577 })
4578
4579 (define_insn_and_split "*fixuns_trunc<mode>_1"
4580   [(set (match_operand:SI 0 "register_operand" "=&x,&x")
4581         (unsigned_fix:SI
4582           (match_operand:MODEF 3 "nonimmediate_operand" "xm,xm")))
4583    (use (match_operand:<ssevecmode> 4  "nonimmediate_operand" "m,x"))
4584    (clobber (match_scratch:<ssevecmode> 1 "=x,&x"))
4585    (clobber (match_scratch:<ssevecmode> 2 "=x,x"))]
4586   "!TARGET_64BIT && TARGET_SSE2 && TARGET_SSE_MATH
4587    && optimize_function_for_speed_p (cfun)"
4588   "#"
4589   "&& reload_completed"
4590   [(const_int 0)]
4591 {
4592   ix86_split_convert_uns_si_sse (operands);
4593   DONE;
4594 })
4595
4596 ;; Unsigned conversion to HImode.
4597 ;; Without these patterns, we'll try the unsigned SI conversion which
4598 ;; is complex for SSE, rather than the signed SI conversion, which isn't.
4599
4600 (define_expand "fixuns_trunc<mode>hi2"
4601   [(set (match_dup 2)
4602         (fix:SI (match_operand:MODEF 1 "nonimmediate_operand" "")))
4603    (set (match_operand:HI 0 "nonimmediate_operand" "")
4604         (subreg:HI (match_dup 2) 0))]
4605   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
4606   "operands[2] = gen_reg_rtx (SImode);")
4607
4608 ;; When SSE is available, it is always faster to use it!
4609 (define_insn "fix_trunc<mode>di_sse"
4610   [(set (match_operand:DI 0 "register_operand" "=r,r")
4611         (fix:DI (match_operand:MODEF 1 "nonimmediate_operand" "x,m")))]
4612   "TARGET_64BIT && SSE_FLOAT_MODE_P (<MODE>mode)
4613    && (!TARGET_FISTTP || TARGET_SSE_MATH)"
4614   "%vcvtt<ssemodesuffix>2si{q}\t{%1, %0|%0, %1}"
4615   [(set_attr "type" "sseicvt")
4616    (set_attr "prefix" "maybe_vex")
4617    (set_attr "prefix_rex" "1")
4618    (set_attr "mode" "<MODE>")
4619    (set_attr "athlon_decode" "double,vector")
4620    (set_attr "amdfam10_decode" "double,double")
4621    (set_attr "bdver1_decode" "double,double")])
4622
4623 (define_insn "fix_trunc<mode>si_sse"
4624   [(set (match_operand:SI 0 "register_operand" "=r,r")
4625         (fix:SI (match_operand:MODEF 1 "nonimmediate_operand" "x,m")))]
4626   "SSE_FLOAT_MODE_P (<MODE>mode)
4627    && (!TARGET_FISTTP || TARGET_SSE_MATH)"
4628   "%vcvtt<ssemodesuffix>2si\t{%1, %0|%0, %1}"
4629   [(set_attr "type" "sseicvt")
4630    (set_attr "prefix" "maybe_vex")
4631    (set_attr "mode" "<MODE>")
4632    (set_attr "athlon_decode" "double,vector")
4633    (set_attr "amdfam10_decode" "double,double")
4634    (set_attr "bdver1_decode" "double,double")])
4635
4636 ;; Shorten x87->SSE reload sequences of fix_trunc?f?i_sse patterns.
4637 (define_peephole2
4638   [(set (match_operand:MODEF 0 "register_operand" "")
4639         (match_operand:MODEF 1 "memory_operand" ""))
4640    (set (match_operand:SSEMODEI24 2 "register_operand" "")
4641         (fix:SSEMODEI24 (match_dup 0)))]
4642   "TARGET_SHORTEN_X87_SSE
4643    && !(TARGET_AVOID_VECTOR_DECODE && optimize_insn_for_speed_p ())
4644    && peep2_reg_dead_p (2, operands[0])"
4645   [(set (match_dup 2) (fix:SSEMODEI24 (match_dup 1)))])
4646
4647 ;; Avoid vector decoded forms of the instruction.
4648 (define_peephole2
4649   [(match_scratch:DF 2 "Y2")
4650    (set (match_operand:SSEMODEI24 0 "register_operand" "")
4651         (fix:SSEMODEI24 (match_operand:DF 1 "memory_operand" "")))]
4652   "TARGET_AVOID_VECTOR_DECODE && optimize_insn_for_speed_p ()"
4653   [(set (match_dup 2) (match_dup 1))
4654    (set (match_dup 0) (fix:SSEMODEI24 (match_dup 2)))])
4655
4656 (define_peephole2
4657   [(match_scratch:SF 2 "x")
4658    (set (match_operand:SSEMODEI24 0 "register_operand" "")
4659         (fix:SSEMODEI24 (match_operand:SF 1 "memory_operand" "")))]
4660   "TARGET_AVOID_VECTOR_DECODE && optimize_insn_for_speed_p ()"
4661   [(set (match_dup 2) (match_dup 1))
4662    (set (match_dup 0) (fix:SSEMODEI24 (match_dup 2)))])
4663
4664 (define_insn_and_split "fix_trunc<mode>_fisttp_i387_1"
4665   [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "")
4666         (fix:X87MODEI (match_operand 1 "register_operand" "")))]
4667   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4668    && TARGET_FISTTP
4669    && !((SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
4670          && (TARGET_64BIT || <MODE>mode != DImode))
4671         && TARGET_SSE_MATH)
4672    && can_create_pseudo_p ()"
4673   "#"
4674   "&& 1"
4675   [(const_int 0)]
4676 {
4677   if (memory_operand (operands[0], VOIDmode))
4678     emit_insn (gen_fix_trunc<mode>_i387_fisttp (operands[0], operands[1]));
4679   else
4680     {
4681       operands[2] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
4682       emit_insn (gen_fix_trunc<mode>_i387_fisttp_with_temp (operands[0],
4683                                                             operands[1],
4684                                                             operands[2]));
4685     }
4686   DONE;
4687 }
4688   [(set_attr "type" "fisttp")
4689    (set_attr "mode" "<MODE>")])
4690
4691 (define_insn "fix_trunc<mode>_i387_fisttp"
4692   [(set (match_operand:X87MODEI 0 "memory_operand" "=m")
4693         (fix:X87MODEI (match_operand 1 "register_operand" "f")))
4694    (clobber (match_scratch:XF 2 "=&1f"))]
4695   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4696    && TARGET_FISTTP
4697    && !((SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
4698          && (TARGET_64BIT || <MODE>mode != DImode))
4699         && TARGET_SSE_MATH)"
4700   "* return output_fix_trunc (insn, operands, 1);"
4701   [(set_attr "type" "fisttp")
4702    (set_attr "mode" "<MODE>")])
4703
4704 (define_insn "fix_trunc<mode>_i387_fisttp_with_temp"
4705   [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "=m,?r")
4706         (fix:X87MODEI (match_operand 1 "register_operand" "f,f")))
4707    (clobber (match_operand:X87MODEI 2 "memory_operand" "=X,m"))
4708    (clobber (match_scratch:XF 3 "=&1f,&1f"))]
4709   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4710    && TARGET_FISTTP
4711    && !((SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
4712         && (TARGET_64BIT || <MODE>mode != DImode))
4713         && TARGET_SSE_MATH)"
4714   "#"
4715   [(set_attr "type" "fisttp")
4716    (set_attr "mode" "<MODE>")])
4717
4718 (define_split
4719   [(set (match_operand:X87MODEI 0 "register_operand" "")
4720         (fix:X87MODEI (match_operand 1 "register_operand" "")))
4721    (clobber (match_operand:X87MODEI 2 "memory_operand" ""))
4722    (clobber (match_scratch 3 ""))]
4723   "reload_completed"
4724   [(parallel [(set (match_dup 2) (fix:X87MODEI (match_dup 1)))
4725               (clobber (match_dup 3))])
4726    (set (match_dup 0) (match_dup 2))])
4727
4728 (define_split
4729   [(set (match_operand:X87MODEI 0 "memory_operand" "")
4730         (fix:X87MODEI (match_operand 1 "register_operand" "")))
4731    (clobber (match_operand:X87MODEI 2 "memory_operand" ""))
4732    (clobber (match_scratch 3 ""))]
4733   "reload_completed"
4734   [(parallel [(set (match_dup 0) (fix:X87MODEI (match_dup 1)))
4735               (clobber (match_dup 3))])])
4736
4737 ;; See the comments in i386.h near OPTIMIZE_MODE_SWITCHING for the description
4738 ;; of the machinery. Please note the clobber of FLAGS_REG. In i387 control
4739 ;; word calculation (inserted by LCM in mode switching pass) a FLAGS_REG
4740 ;; clobbering insns can be used. Look at emit_i387_cw_initialization ()
4741 ;; function in i386.c.
4742 (define_insn_and_split "*fix_trunc<mode>_i387_1"
4743   [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "")
4744         (fix:X87MODEI (match_operand 1 "register_operand" "")))
4745    (clobber (reg:CC FLAGS_REG))]
4746   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4747    && !TARGET_FISTTP
4748    && !(SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
4749          && (TARGET_64BIT || <MODE>mode != DImode))
4750    && can_create_pseudo_p ()"
4751   "#"
4752   "&& 1"
4753   [(const_int 0)]
4754 {
4755   ix86_optimize_mode_switching[I387_TRUNC] = 1;
4756
4757   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
4758   operands[3] = assign_386_stack_local (HImode, SLOT_CW_TRUNC);
4759   if (memory_operand (operands[0], VOIDmode))
4760     emit_insn (gen_fix_trunc<mode>_i387 (operands[0], operands[1],
4761                                          operands[2], operands[3]));
4762   else
4763     {
4764       operands[4] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
4765       emit_insn (gen_fix_trunc<mode>_i387_with_temp (operands[0], operands[1],
4766                                                      operands[2], operands[3],
4767                                                      operands[4]));
4768     }
4769   DONE;
4770 }
4771   [(set_attr "type" "fistp")
4772    (set_attr "i387_cw" "trunc")
4773    (set_attr "mode" "<MODE>")])
4774
4775 (define_insn "fix_truncdi_i387"
4776   [(set (match_operand:DI 0 "memory_operand" "=m")
4777         (fix:DI (match_operand 1 "register_operand" "f")))
4778    (use (match_operand:HI 2 "memory_operand" "m"))
4779    (use (match_operand:HI 3 "memory_operand" "m"))
4780    (clobber (match_scratch:XF 4 "=&1f"))]
4781   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4782    && !TARGET_FISTTP
4783    && !(TARGET_64BIT && SSE_FLOAT_MODE_P (GET_MODE (operands[1])))"
4784   "* return output_fix_trunc (insn, operands, 0);"
4785   [(set_attr "type" "fistp")
4786    (set_attr "i387_cw" "trunc")
4787    (set_attr "mode" "DI")])
4788
4789 (define_insn "fix_truncdi_i387_with_temp"
4790   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
4791         (fix:DI (match_operand 1 "register_operand" "f,f")))
4792    (use (match_operand:HI 2 "memory_operand" "m,m"))
4793    (use (match_operand:HI 3 "memory_operand" "m,m"))
4794    (clobber (match_operand:DI 4 "memory_operand" "=X,m"))
4795    (clobber (match_scratch:XF 5 "=&1f,&1f"))]
4796   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4797    && !TARGET_FISTTP
4798    && !(TARGET_64BIT && SSE_FLOAT_MODE_P (GET_MODE (operands[1])))"
4799   "#"
4800   [(set_attr "type" "fistp")
4801    (set_attr "i387_cw" "trunc")
4802    (set_attr "mode" "DI")])
4803
4804 (define_split
4805   [(set (match_operand:DI 0 "register_operand" "")
4806         (fix:DI (match_operand 1 "register_operand" "")))
4807    (use (match_operand:HI 2 "memory_operand" ""))
4808    (use (match_operand:HI 3 "memory_operand" ""))
4809    (clobber (match_operand:DI 4 "memory_operand" ""))
4810    (clobber (match_scratch 5 ""))]
4811   "reload_completed"
4812   [(parallel [(set (match_dup 4) (fix:DI (match_dup 1)))
4813               (use (match_dup 2))
4814               (use (match_dup 3))
4815               (clobber (match_dup 5))])
4816    (set (match_dup 0) (match_dup 4))])
4817
4818 (define_split
4819   [(set (match_operand:DI 0 "memory_operand" "")
4820         (fix:DI (match_operand 1 "register_operand" "")))
4821    (use (match_operand:HI 2 "memory_operand" ""))
4822    (use (match_operand:HI 3 "memory_operand" ""))
4823    (clobber (match_operand:DI 4 "memory_operand" ""))
4824    (clobber (match_scratch 5 ""))]
4825   "reload_completed"
4826   [(parallel [(set (match_dup 0) (fix:DI (match_dup 1)))
4827               (use (match_dup 2))
4828               (use (match_dup 3))
4829               (clobber (match_dup 5))])])
4830
4831 (define_insn "fix_trunc<mode>_i387"
4832   [(set (match_operand:X87MODEI12 0 "memory_operand" "=m")
4833         (fix:X87MODEI12 (match_operand 1 "register_operand" "f")))
4834    (use (match_operand:HI 2 "memory_operand" "m"))
4835    (use (match_operand:HI 3 "memory_operand" "m"))]
4836   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4837    && !TARGET_FISTTP
4838    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4839   "* return output_fix_trunc (insn, operands, 0);"
4840   [(set_attr "type" "fistp")
4841    (set_attr "i387_cw" "trunc")
4842    (set_attr "mode" "<MODE>")])
4843
4844 (define_insn "fix_trunc<mode>_i387_with_temp"
4845   [(set (match_operand:X87MODEI12 0 "nonimmediate_operand" "=m,?r")
4846         (fix:X87MODEI12 (match_operand 1 "register_operand" "f,f")))
4847    (use (match_operand:HI 2 "memory_operand" "m,m"))
4848    (use (match_operand:HI 3 "memory_operand" "m,m"))
4849    (clobber (match_operand:X87MODEI12 4 "memory_operand" "=X,m"))]
4850   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4851    && !TARGET_FISTTP
4852    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4853   "#"
4854   [(set_attr "type" "fistp")
4855    (set_attr "i387_cw" "trunc")
4856    (set_attr "mode" "<MODE>")])
4857
4858 (define_split
4859   [(set (match_operand:X87MODEI12 0 "register_operand" "")
4860         (fix:X87MODEI12 (match_operand 1 "register_operand" "")))
4861    (use (match_operand:HI 2 "memory_operand" ""))
4862    (use (match_operand:HI 3 "memory_operand" ""))
4863    (clobber (match_operand:X87MODEI12 4 "memory_operand" ""))]
4864   "reload_completed"
4865   [(parallel [(set (match_dup 4) (fix:X87MODEI12 (match_dup 1)))
4866               (use (match_dup 2))
4867               (use (match_dup 3))])
4868    (set (match_dup 0) (match_dup 4))])
4869
4870 (define_split
4871   [(set (match_operand:X87MODEI12 0 "memory_operand" "")
4872         (fix:X87MODEI12 (match_operand 1 "register_operand" "")))
4873    (use (match_operand:HI 2 "memory_operand" ""))
4874    (use (match_operand:HI 3 "memory_operand" ""))
4875    (clobber (match_operand:X87MODEI12 4 "memory_operand" ""))]
4876   "reload_completed"
4877   [(parallel [(set (match_dup 0) (fix:X87MODEI12 (match_dup 1)))
4878               (use (match_dup 2))
4879               (use (match_dup 3))])])
4880
4881 (define_insn "x86_fnstcw_1"
4882   [(set (match_operand:HI 0 "memory_operand" "=m")
4883         (unspec:HI [(reg:HI FPCR_REG)] UNSPEC_FSTCW))]
4884   "TARGET_80387"
4885   "fnstcw\t%0"
4886   [(set (attr "length")
4887         (symbol_ref "ix86_attr_length_address_default (insn) + 2"))
4888    (set_attr "mode" "HI")
4889    (set_attr "unit" "i387")
4890    (set_attr "bdver1_decode" "vector")])
4891
4892 (define_insn "x86_fldcw_1"
4893   [(set (reg:HI FPCR_REG)
4894         (unspec:HI [(match_operand:HI 0 "memory_operand" "m")] UNSPEC_FLDCW))]
4895   "TARGET_80387"
4896   "fldcw\t%0"
4897   [(set (attr "length")
4898         (symbol_ref "ix86_attr_length_address_default (insn) + 2"))
4899    (set_attr "mode" "HI")
4900    (set_attr "unit" "i387")
4901    (set_attr "athlon_decode" "vector")
4902    (set_attr "amdfam10_decode" "vector")
4903    (set_attr "bdver1_decode" "vector")])
4904 \f
4905 ;; Conversion between fixed point and floating point.
4906
4907 ;; Even though we only accept memory inputs, the backend _really_
4908 ;; wants to be able to do this between registers.
4909
4910 (define_expand "floathi<mode>2"
4911   [(set (match_operand:X87MODEF 0 "register_operand" "")
4912         (float:X87MODEF (match_operand:HI 1 "nonimmediate_operand" "")))]
4913   "TARGET_80387
4914    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
4915        || TARGET_MIX_SSE_I387)")
4916
4917 ;; Pre-reload splitter to add memory clobber to the pattern.
4918 (define_insn_and_split "*floathi<mode>2_1"
4919   [(set (match_operand:X87MODEF 0 "register_operand" "")
4920         (float:X87MODEF (match_operand:HI 1 "register_operand" "")))]
4921   "TARGET_80387
4922    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
4923        || TARGET_MIX_SSE_I387)
4924    && can_create_pseudo_p ()"
4925   "#"
4926   "&& 1"
4927   [(parallel [(set (match_dup 0)
4928               (float:X87MODEF (match_dup 1)))
4929    (clobber (match_dup 2))])]
4930   "operands[2] = assign_386_stack_local (HImode, SLOT_TEMP);")
4931
4932 (define_insn "*floathi<mode>2_i387_with_temp"
4933   [(set (match_operand:X87MODEF 0 "register_operand" "=f,f")
4934         (float:X87MODEF (match_operand:HI 1 "nonimmediate_operand" "m,?r")))
4935   (clobber (match_operand:HI 2 "memory_operand" "=m,m"))]
4936   "TARGET_80387
4937    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
4938        || TARGET_MIX_SSE_I387)"
4939   "#"
4940   [(set_attr "type" "fmov,multi")
4941    (set_attr "mode" "<MODE>")
4942    (set_attr "unit" "*,i387")
4943    (set_attr "fp_int_src" "true")])
4944
4945 (define_insn "*floathi<mode>2_i387"
4946   [(set (match_operand:X87MODEF 0 "register_operand" "=f")
4947         (float:X87MODEF (match_operand:HI 1 "memory_operand" "m")))]
4948   "TARGET_80387
4949    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
4950        || TARGET_MIX_SSE_I387)"
4951   "fild%Z1\t%1"
4952   [(set_attr "type" "fmov")
4953    (set_attr "mode" "<MODE>")
4954    (set_attr "fp_int_src" "true")])
4955
4956 (define_split
4957   [(set (match_operand:X87MODEF 0 "register_operand" "")
4958         (float:X87MODEF (match_operand:HI 1 "register_operand" "")))
4959    (clobber (match_operand:HI 2 "memory_operand" ""))]
4960   "TARGET_80387
4961    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
4962        || TARGET_MIX_SSE_I387)
4963    && reload_completed"
4964   [(set (match_dup 2) (match_dup 1))
4965    (set (match_dup 0) (float:X87MODEF (match_dup 2)))])
4966
4967 (define_split
4968   [(set (match_operand:X87MODEF 0 "register_operand" "")
4969         (float:X87MODEF (match_operand:HI 1 "memory_operand" "")))
4970    (clobber (match_operand:HI 2 "memory_operand" ""))]
4971    "TARGET_80387
4972     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
4973         || TARGET_MIX_SSE_I387)
4974     && reload_completed"
4975   [(set (match_dup 0) (float:X87MODEF (match_dup 1)))])
4976
4977 (define_expand "float<SSEMODEI24:mode><X87MODEF:mode>2"
4978   [(set (match_operand:X87MODEF 0 "register_operand" "")
4979         (float:X87MODEF
4980           (match_operand:SSEMODEI24 1 "nonimmediate_operand" "")))]
4981   "TARGET_80387
4982    || ((<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
4983        && SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH)"
4984 {
4985   if (!((<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
4986         && SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH)
4987       && !X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, <SSEMODEI24:MODE>mode))
4988     {
4989       rtx reg = gen_reg_rtx (XFmode);
4990       rtx (*insn)(rtx, rtx);
4991
4992       emit_insn (gen_float<SSEMODEI24:mode>xf2 (reg, operands[1]));
4993
4994       if (<X87MODEF:MODE>mode == SFmode)
4995         insn = gen_truncxfsf2;
4996       else if (<X87MODEF:MODE>mode == DFmode)
4997         insn = gen_truncxfdf2;
4998       else
4999         gcc_unreachable ();
5000
5001       emit_insn (insn (operands[0], reg));
5002       DONE;
5003     }
5004 })
5005
5006 ;; Pre-reload splitter to add memory clobber to the pattern.
5007 (define_insn_and_split "*float<SSEMODEI24:mode><X87MODEF:mode>2_1"
5008   [(set (match_operand:X87MODEF 0 "register_operand" "")
5009         (float:X87MODEF (match_operand:SSEMODEI24 1 "register_operand" "")))]
5010   "((TARGET_80387
5011      && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, <SSEMODEI24:MODE>mode)
5012      && (!((<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5013            && SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH)
5014          || TARGET_MIX_SSE_I387))
5015     || ((<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5016         && SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH
5017         && ((<SSEMODEI24:MODE>mode == SImode
5018              && TARGET_SSE2 && TARGET_USE_VECTOR_CONVERTS
5019              && optimize_function_for_speed_p (cfun)
5020              && flag_trapping_math)
5021             || !(TARGET_INTER_UNIT_CONVERSIONS
5022                  || optimize_function_for_size_p (cfun)))))
5023    && can_create_pseudo_p ()"
5024   "#"
5025   "&& 1"
5026   [(parallel [(set (match_dup 0) (float:X87MODEF (match_dup 1)))
5027               (clobber (match_dup 2))])]
5028 {
5029   operands[2] = assign_386_stack_local (<SSEMODEI24:MODE>mode, SLOT_TEMP);
5030
5031   /* Avoid store forwarding (partial memory) stall penalty
5032      by passing DImode value through XMM registers.  */
5033   if (<SSEMODEI24:MODE>mode == DImode && !TARGET_64BIT
5034       && TARGET_80387 && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES
5035       && optimize_function_for_speed_p (cfun))
5036     {
5037       emit_insn (gen_floatdi<X87MODEF:mode>2_i387_with_xmm (operands[0],
5038                                                             operands[1],
5039                                                             operands[2]));
5040       DONE;
5041     }
5042 })
5043
5044 (define_insn "*floatsi<mode>2_vector_mixed_with_temp"
5045   [(set (match_operand:MODEF 0 "register_operand" "=f,f,x,x,x")
5046         (float:MODEF
5047           (match_operand:SI 1 "nonimmediate_operand" "m,?r,r,m,!x")))
5048    (clobber (match_operand:SI 2 "memory_operand" "=X,m,m,X,m"))]
5049   "TARGET_SSE2 && TARGET_MIX_SSE_I387
5050    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)"
5051   "#"
5052   [(set_attr "type" "fmov,multi,sseicvt,sseicvt,sseicvt")
5053    (set_attr "mode" "<MODE>,<MODE>,<MODE>,<MODE>,<ssevecmode>")
5054    (set_attr "unit" "*,i387,*,*,*")
5055    (set_attr "athlon_decode" "*,*,double,direct,double")
5056    (set_attr "amdfam10_decode" "*,*,vector,double,double")
5057    (set_attr "bdver1_decode" "*,*,double,direct,double")
5058    (set_attr "fp_int_src" "true")])
5059
5060 (define_insn "*floatsi<mode>2_vector_mixed"
5061   [(set (match_operand:MODEF 0 "register_operand" "=f,x")
5062         (float:MODEF (match_operand:SI 1 "memory_operand" "m,m")))]
5063   "TARGET_SSE2 && TARGET_MIX_SSE_I387
5064    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)"
5065   "@
5066    fild%Z1\t%1
5067    #"
5068   [(set_attr "type" "fmov,sseicvt")
5069    (set_attr "mode" "<MODE>,<ssevecmode>")
5070    (set_attr "unit" "i387,*")
5071    (set_attr "athlon_decode" "*,direct")
5072    (set_attr "amdfam10_decode" "*,double")
5073    (set_attr "bdver1_decode" "*,direct")
5074    (set_attr "fp_int_src" "true")])
5075
5076 (define_insn "*float<SSEMODEI24:mode><MODEF:mode>2_mixed_with_temp"
5077   [(set (match_operand:MODEF 0 "register_operand" "=f,f,x,x")
5078         (float:MODEF
5079           (match_operand:SSEMODEI24 1 "nonimmediate_operand" "m,?r,r,m")))
5080   (clobber (match_operand:SSEMODEI24 2 "memory_operand" "=X,m,m,X"))]
5081   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5082    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_MIX_SSE_I387"
5083   "#"
5084   [(set_attr "type" "fmov,multi,sseicvt,sseicvt")
5085    (set_attr "mode" "<MODEF:MODE>")
5086    (set_attr "unit" "*,i387,*,*")
5087    (set_attr "athlon_decode" "*,*,double,direct")
5088    (set_attr "amdfam10_decode" "*,*,vector,double")
5089    (set_attr "bdver1_decode" "*,*,double,direct")
5090    (set_attr "fp_int_src" "true")])
5091
5092 (define_split
5093   [(set (match_operand:MODEF 0 "register_operand" "")
5094         (float:MODEF (match_operand:SSEMODEI24 1 "register_operand" "")))
5095    (clobber (match_operand:SSEMODEI24 2 "memory_operand" ""))]
5096   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5097    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_MIX_SSE_I387
5098    && TARGET_INTER_UNIT_CONVERSIONS
5099    && reload_completed
5100    && (SSE_REG_P (operands[0])
5101        || (GET_CODE (operands[0]) == SUBREG
5102            && SSE_REG_P (operands[0])))"
5103   [(set (match_dup 0) (float:MODEF (match_dup 1)))])
5104
5105 (define_split
5106   [(set (match_operand:MODEF 0 "register_operand" "")
5107         (float:MODEF (match_operand:SSEMODEI24 1 "register_operand" "")))
5108    (clobber (match_operand:SSEMODEI24 2 "memory_operand" ""))]
5109   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5110    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_MIX_SSE_I387
5111    && !(TARGET_INTER_UNIT_CONVERSIONS || optimize_function_for_size_p (cfun))
5112    && reload_completed
5113    && (SSE_REG_P (operands[0])
5114        || (GET_CODE (operands[0]) == SUBREG
5115            && SSE_REG_P (operands[0])))"
5116   [(set (match_dup 2) (match_dup 1))
5117    (set (match_dup 0) (float:MODEF (match_dup 2)))])
5118
5119 (define_insn "*float<SSEMODEI24:mode><MODEF:mode>2_mixed_interunit"
5120   [(set (match_operand:MODEF 0 "register_operand" "=f,x,x")
5121         (float:MODEF
5122           (match_operand:SSEMODEI24 1 "nonimmediate_operand" "m,r,m")))]
5123   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5124    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_MIX_SSE_I387
5125    && (TARGET_INTER_UNIT_CONVERSIONS || optimize_function_for_size_p (cfun))"
5126   "@
5127    fild%Z1\t%1
5128    %vcvtsi2<MODEF:ssemodesuffix><SSEMODEI24:rex64suffix>\t{%1, %d0|%d0, %1}
5129    %vcvtsi2<MODEF:ssemodesuffix><SSEMODEI24:rex64suffix>\t{%1, %d0|%d0, %1}"
5130   [(set_attr "type" "fmov,sseicvt,sseicvt")
5131    (set_attr "prefix" "orig,maybe_vex,maybe_vex")
5132    (set_attr "mode" "<MODEF:MODE>")
5133    (set (attr "prefix_rex")
5134      (if_then_else
5135        (and (eq_attr "prefix" "maybe_vex")
5136             (ne (symbol_ref "<SSEMODEI24:MODE>mode == DImode") (const_int 0)))
5137        (const_string "1")
5138        (const_string "*")))
5139    (set_attr "unit" "i387,*,*")
5140    (set_attr "athlon_decode" "*,double,direct")
5141    (set_attr "amdfam10_decode" "*,vector,double")
5142    (set_attr "bdver1_decode" "*,double,direct")
5143    (set_attr "fp_int_src" "true")])
5144
5145 (define_insn "*float<SSEMODEI24:mode><MODEF:mode>2_mixed_nointerunit"
5146   [(set (match_operand:MODEF 0 "register_operand" "=f,x")
5147         (float:MODEF
5148           (match_operand:SSEMODEI24 1 "memory_operand" "m,m")))]
5149   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5150    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_MIX_SSE_I387
5151    && !(TARGET_INTER_UNIT_CONVERSIONS || optimize_function_for_size_p (cfun))"
5152   "@
5153    fild%Z1\t%1
5154    %vcvtsi2<MODEF:ssemodesuffix><SSEMODEI24:rex64suffix>\t{%1, %d0|%d0, %1}"
5155   [(set_attr "type" "fmov,sseicvt")
5156    (set_attr "prefix" "orig,maybe_vex")
5157    (set_attr "mode" "<MODEF:MODE>")
5158    (set (attr "prefix_rex")
5159      (if_then_else
5160        (and (eq_attr "prefix" "maybe_vex")
5161             (ne (symbol_ref "<SSEMODEI24:MODE>mode == DImode") (const_int 0)))
5162        (const_string "1")
5163        (const_string "*")))
5164    (set_attr "athlon_decode" "*,direct")
5165    (set_attr "amdfam10_decode" "*,double")
5166    (set_attr "bdver1_decode" "*,direct")
5167    (set_attr "fp_int_src" "true")])
5168
5169 (define_insn "*floatsi<mode>2_vector_sse_with_temp"
5170   [(set (match_operand:MODEF 0 "register_operand" "=x,x,x")
5171         (float:MODEF
5172           (match_operand:SI 1 "nonimmediate_operand" "r,m,!x")))
5173    (clobber (match_operand:SI 2 "memory_operand" "=m,X,m"))]
5174   "TARGET_SSE2 && TARGET_SSE_MATH
5175    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)"
5176   "#"
5177   [(set_attr "type" "sseicvt")
5178    (set_attr "mode" "<MODE>,<MODE>,<ssevecmode>")
5179    (set_attr "athlon_decode" "double,direct,double")
5180    (set_attr "amdfam10_decode" "vector,double,double")
5181    (set_attr "bdver1_decode" "double,direct,double")
5182    (set_attr "fp_int_src" "true")])
5183
5184 (define_insn "*floatsi<mode>2_vector_sse"
5185   [(set (match_operand:MODEF 0 "register_operand" "=x")
5186         (float:MODEF (match_operand:SI 1 "memory_operand" "m")))]
5187   "TARGET_SSE2 && TARGET_SSE_MATH
5188    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)"
5189   "#"
5190   [(set_attr "type" "sseicvt")
5191    (set_attr "mode" "<MODE>")
5192    (set_attr "athlon_decode" "direct")
5193    (set_attr "amdfam10_decode" "double")
5194    (set_attr "bdver1_decode" "direct")
5195    (set_attr "fp_int_src" "true")])
5196
5197 (define_split
5198   [(set (match_operand:MODEF 0 "register_operand" "")
5199         (float:MODEF (match_operand:SI 1 "register_operand" "")))
5200    (clobber (match_operand:SI 2 "memory_operand" ""))]
5201   "TARGET_SSE2 && TARGET_SSE_MATH
5202    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)
5203    && reload_completed
5204    && (SSE_REG_P (operands[0])
5205        || (GET_CODE (operands[0]) == SUBREG
5206            && SSE_REG_P (operands[0])))"
5207   [(const_int 0)]
5208 {
5209   rtx op1 = operands[1];
5210
5211   operands[3] = simplify_gen_subreg (<ssevecmode>mode, operands[0],
5212                                      <MODE>mode, 0);
5213   if (GET_CODE (op1) == SUBREG)
5214     op1 = SUBREG_REG (op1);
5215
5216   if (GENERAL_REG_P (op1) && TARGET_INTER_UNIT_MOVES)
5217     {
5218       operands[4] = simplify_gen_subreg (V4SImode, operands[0], <MODE>mode, 0);
5219       emit_insn (gen_sse2_loadld (operands[4],
5220                                   CONST0_RTX (V4SImode), operands[1]));
5221     }
5222   /* We can ignore possible trapping value in the
5223      high part of SSE register for non-trapping math. */
5224   else if (SSE_REG_P (op1) && !flag_trapping_math)
5225     operands[4] = simplify_gen_subreg (V4SImode, operands[1], SImode, 0);
5226   else
5227     {
5228       operands[4] = simplify_gen_subreg (V4SImode, operands[0], <MODE>mode, 0);
5229       emit_move_insn (operands[2], operands[1]);
5230       emit_insn (gen_sse2_loadld (operands[4],
5231                                   CONST0_RTX (V4SImode), operands[2]));
5232     }
5233   emit_insn
5234     (gen_sse2_cvtdq2<ssevecmodesuffix> (operands[3], operands[4]));
5235   DONE;
5236 })
5237
5238 (define_split
5239   [(set (match_operand:MODEF 0 "register_operand" "")
5240         (float:MODEF (match_operand:SI 1 "memory_operand" "")))
5241    (clobber (match_operand:SI 2 "memory_operand" ""))]
5242   "TARGET_SSE2 && TARGET_SSE_MATH
5243    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)
5244    && reload_completed
5245    && (SSE_REG_P (operands[0])
5246        || (GET_CODE (operands[0]) == SUBREG
5247            && SSE_REG_P (operands[0])))"
5248   [(const_int 0)]
5249 {
5250   operands[3] = simplify_gen_subreg (<ssevecmode>mode, operands[0],
5251                                      <MODE>mode, 0);
5252   operands[4] = simplify_gen_subreg (V4SImode, operands[0], <MODE>mode, 0);
5253
5254   emit_insn (gen_sse2_loadld (operands[4],
5255                               CONST0_RTX (V4SImode), operands[1]));
5256   emit_insn
5257     (gen_sse2_cvtdq2<ssevecmodesuffix> (operands[3], operands[4]));
5258   DONE;
5259 })
5260
5261 (define_split
5262   [(set (match_operand:MODEF 0 "register_operand" "")
5263         (float:MODEF (match_operand:SI 1 "register_operand" "")))]
5264   "TARGET_SSE2 && TARGET_SSE_MATH
5265    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)
5266    && reload_completed
5267    && (SSE_REG_P (operands[0])
5268        || (GET_CODE (operands[0]) == SUBREG
5269            && SSE_REG_P (operands[0])))"
5270   [(const_int 0)]
5271 {
5272   rtx op1 = operands[1];
5273
5274   operands[3] = simplify_gen_subreg (<ssevecmode>mode, operands[0],
5275                                      <MODE>mode, 0);
5276   if (GET_CODE (op1) == SUBREG)
5277     op1 = SUBREG_REG (op1);
5278
5279   if (GENERAL_REG_P (op1) && TARGET_INTER_UNIT_MOVES)
5280     {
5281       operands[4] = simplify_gen_subreg (V4SImode, operands[0], <MODE>mode, 0);
5282       emit_insn (gen_sse2_loadld (operands[4],
5283                                   CONST0_RTX (V4SImode), operands[1]));
5284     }
5285   /* We can ignore possible trapping value in the
5286      high part of SSE register for non-trapping math. */
5287   else if (SSE_REG_P (op1) && !flag_trapping_math)
5288     operands[4] = simplify_gen_subreg (V4SImode, operands[1], SImode, 0);
5289   else
5290     gcc_unreachable ();
5291   emit_insn
5292     (gen_sse2_cvtdq2<ssevecmodesuffix> (operands[3], operands[4]));
5293   DONE;
5294 })
5295
5296 (define_split
5297   [(set (match_operand:MODEF 0 "register_operand" "")
5298         (float:MODEF (match_operand:SI 1 "memory_operand" "")))]
5299   "TARGET_SSE2 && TARGET_SSE_MATH
5300    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)
5301    && reload_completed
5302    && (SSE_REG_P (operands[0])
5303        || (GET_CODE (operands[0]) == SUBREG
5304            && SSE_REG_P (operands[0])))"
5305   [(const_int 0)]
5306 {
5307   operands[3] = simplify_gen_subreg (<ssevecmode>mode, operands[0],
5308                                      <MODE>mode, 0);
5309   operands[4] = simplify_gen_subreg (V4SImode, operands[0], <MODE>mode, 0);
5310
5311   emit_insn (gen_sse2_loadld (operands[4],
5312                               CONST0_RTX (V4SImode), operands[1]));
5313   emit_insn
5314     (gen_sse2_cvtdq2<ssevecmodesuffix> (operands[3], operands[4]));
5315   DONE;
5316 })
5317
5318 (define_insn "*float<SSEMODEI24:mode><MODEF:mode>2_sse_with_temp"
5319   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
5320         (float:MODEF
5321           (match_operand:SSEMODEI24 1 "nonimmediate_operand" "r,m")))
5322   (clobber (match_operand:SSEMODEI24 2 "memory_operand" "=m,X"))]
5323   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5324    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH"
5325   "#"
5326   [(set_attr "type" "sseicvt")
5327    (set_attr "mode" "<MODEF:MODE>")
5328    (set_attr "athlon_decode" "double,direct")
5329    (set_attr "amdfam10_decode" "vector,double")
5330    (set_attr "bdver1_decode" "double,direct")
5331    (set_attr "fp_int_src" "true")])
5332
5333 (define_insn "*float<SSEMODEI24:mode><MODEF:mode>2_sse_interunit"
5334   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
5335         (float:MODEF
5336           (match_operand:SSEMODEI24 1 "nonimmediate_operand" "r,m")))]
5337   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5338    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
5339    && (TARGET_INTER_UNIT_CONVERSIONS || optimize_function_for_size_p (cfun))"
5340   "%vcvtsi2<MODEF:ssemodesuffix><SSEMODEI24:rex64suffix>\t{%1, %d0|%d0, %1}"
5341   [(set_attr "type" "sseicvt")
5342    (set_attr "prefix" "maybe_vex")
5343    (set_attr "mode" "<MODEF:MODE>")
5344    (set (attr "prefix_rex")
5345      (if_then_else
5346        (and (eq_attr "prefix" "maybe_vex")
5347             (ne (symbol_ref "<SSEMODEI24:MODE>mode == DImode") (const_int 0)))
5348        (const_string "1")
5349        (const_string "*")))
5350    (set_attr "athlon_decode" "double,direct")
5351    (set_attr "amdfam10_decode" "vector,double")
5352    (set_attr "bdver1_decode" "double,direct")
5353    (set_attr "fp_int_src" "true")])
5354
5355 (define_split
5356   [(set (match_operand:MODEF 0 "register_operand" "")
5357         (float:MODEF (match_operand:SSEMODEI24 1 "nonimmediate_operand" "")))
5358    (clobber (match_operand:SSEMODEI24 2 "memory_operand" ""))]
5359   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5360    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
5361    && (TARGET_INTER_UNIT_CONVERSIONS || optimize_function_for_size_p (cfun))
5362    && reload_completed
5363    && (SSE_REG_P (operands[0])
5364        || (GET_CODE (operands[0]) == SUBREG
5365            && SSE_REG_P (operands[0])))"
5366   [(set (match_dup 0) (float:MODEF (match_dup 1)))])
5367
5368 (define_insn "*float<SSEMODEI24:mode><MODEF:mode>2_sse_nointerunit"
5369   [(set (match_operand:MODEF 0 "register_operand" "=x")
5370         (float:MODEF
5371           (match_operand:SSEMODEI24 1 "memory_operand" "m")))]
5372   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5373    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
5374    && !(TARGET_INTER_UNIT_CONVERSIONS || optimize_function_for_size_p (cfun))"
5375   "%vcvtsi2<MODEF:ssemodesuffix><SSEMODEI24:rex64suffix>\t{%1, %d0|%d0, %1}"
5376   [(set_attr "type" "sseicvt")
5377    (set_attr "prefix" "maybe_vex")
5378    (set_attr "mode" "<MODEF:MODE>")
5379    (set (attr "prefix_rex")
5380      (if_then_else
5381        (and (eq_attr "prefix" "maybe_vex")
5382             (ne (symbol_ref "<SSEMODEI24:MODE>mode == DImode") (const_int 0)))
5383        (const_string "1")
5384        (const_string "*")))
5385    (set_attr "athlon_decode" "direct")
5386    (set_attr "amdfam10_decode" "double")
5387    (set_attr "bdver1_decode" "direct")
5388    (set_attr "fp_int_src" "true")])
5389
5390 (define_split
5391   [(set (match_operand:MODEF 0 "register_operand" "")
5392         (float:MODEF (match_operand:SSEMODEI24 1 "register_operand" "")))
5393    (clobber (match_operand:SSEMODEI24 2 "memory_operand" ""))]
5394   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5395    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
5396    && !(TARGET_INTER_UNIT_CONVERSIONS || optimize_function_for_size_p (cfun))
5397    && reload_completed
5398    && (SSE_REG_P (operands[0])
5399        || (GET_CODE (operands[0]) == SUBREG
5400            && SSE_REG_P (operands[0])))"
5401   [(set (match_dup 2) (match_dup 1))
5402    (set (match_dup 0) (float:MODEF (match_dup 2)))])
5403
5404 (define_split
5405   [(set (match_operand:MODEF 0 "register_operand" "")
5406         (float:MODEF (match_operand:SSEMODEI24 1 "memory_operand" "")))
5407    (clobber (match_operand:SSEMODEI24 2 "memory_operand" ""))]
5408   "(<SSEMODEI24:MODE>mode != DImode || TARGET_64BIT)
5409    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
5410    && reload_completed
5411    && (SSE_REG_P (operands[0])
5412        || (GET_CODE (operands[0]) == SUBREG
5413            && SSE_REG_P (operands[0])))"
5414   [(set (match_dup 0) (float:MODEF (match_dup 1)))])
5415
5416 (define_insn "*float<SSEMODEI24:mode><X87MODEF:mode>2_i387_with_temp"
5417   [(set (match_operand:X87MODEF 0 "register_operand" "=f,f")
5418         (float:X87MODEF
5419           (match_operand:SSEMODEI24 1 "nonimmediate_operand" "m,?r")))
5420   (clobber (match_operand:SSEMODEI24 2 "memory_operand" "=X,m"))]
5421   "TARGET_80387
5422    && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, <SSEMODEI24:MODE>mode)"
5423   "@
5424    fild%Z1\t%1
5425    #"
5426   [(set_attr "type" "fmov,multi")
5427    (set_attr "mode" "<X87MODEF:MODE>")
5428    (set_attr "unit" "*,i387")
5429    (set_attr "fp_int_src" "true")])
5430
5431 (define_insn "*float<SSEMODEI24:mode><X87MODEF:mode>2_i387"
5432   [(set (match_operand:X87MODEF 0 "register_operand" "=f")
5433         (float:X87MODEF
5434           (match_operand:SSEMODEI24 1 "memory_operand" "m")))]
5435   "TARGET_80387
5436    && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, <SSEMODEI24:MODE>mode)"
5437   "fild%Z1\t%1"
5438   [(set_attr "type" "fmov")
5439    (set_attr "mode" "<X87MODEF:MODE>")
5440    (set_attr "fp_int_src" "true")])
5441
5442 (define_split
5443   [(set (match_operand:X87MODEF 0 "register_operand" "")
5444         (float:X87MODEF (match_operand:SSEMODEI24 1 "register_operand" "")))
5445    (clobber (match_operand:SSEMODEI24 2 "memory_operand" ""))]
5446   "TARGET_80387
5447    && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, <SSEMODEI24:MODE>mode)
5448    && reload_completed
5449    && FP_REG_P (operands[0])"
5450   [(set (match_dup 2) (match_dup 1))
5451    (set (match_dup 0) (float:X87MODEF (match_dup 2)))])
5452
5453 (define_split
5454   [(set (match_operand:X87MODEF 0 "register_operand" "")
5455         (float:X87MODEF (match_operand:SSEMODEI24 1 "memory_operand" "")))
5456    (clobber (match_operand:SSEMODEI24 2 "memory_operand" ""))]
5457   "TARGET_80387
5458    && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, <SSEMODEI24:MODE>mode)
5459    && reload_completed
5460    && FP_REG_P (operands[0])"
5461   [(set (match_dup 0) (float:X87MODEF (match_dup 1)))])
5462
5463 ;; Avoid store forwarding (partial memory) stall penalty
5464 ;; by passing DImode value through XMM registers.  */
5465
5466 (define_insn "floatdi<X87MODEF:mode>2_i387_with_xmm"
5467   [(set (match_operand:X87MODEF 0 "register_operand" "=f,f")
5468         (float:X87MODEF
5469           (match_operand:DI 1 "nonimmediate_operand" "m,?r")))
5470    (clobber (match_scratch:V4SI 3 "=X,x"))
5471    (clobber (match_scratch:V4SI 4 "=X,x"))
5472    (clobber (match_operand:DI 2 "memory_operand" "=X,m"))]
5473   "TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5474    && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES
5475    && !TARGET_64BIT && optimize_function_for_speed_p (cfun)"
5476   "#"
5477   [(set_attr "type" "multi")
5478    (set_attr "mode" "<X87MODEF:MODE>")
5479    (set_attr "unit" "i387")
5480    (set_attr "fp_int_src" "true")])
5481
5482 (define_split
5483   [(set (match_operand:X87MODEF 0 "register_operand" "")
5484         (float:X87MODEF (match_operand:DI 1 "register_operand" "")))
5485    (clobber (match_scratch:V4SI 3 ""))
5486    (clobber (match_scratch:V4SI 4 ""))
5487    (clobber (match_operand:DI 2 "memory_operand" ""))]
5488   "TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5489    && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES
5490    && !TARGET_64BIT && optimize_function_for_speed_p (cfun)
5491    && reload_completed
5492    && FP_REG_P (operands[0])"
5493   [(set (match_dup 2) (match_dup 3))
5494    (set (match_dup 0) (float:X87MODEF (match_dup 2)))]
5495 {
5496   /* The DImode arrived in a pair of integral registers (e.g. %edx:%eax).
5497      Assemble the 64-bit DImode value in an xmm register.  */
5498   emit_insn (gen_sse2_loadld (operands[3], CONST0_RTX (V4SImode),
5499                               gen_rtx_SUBREG (SImode, operands[1], 0)));
5500   emit_insn (gen_sse2_loadld (operands[4], CONST0_RTX (V4SImode),
5501                               gen_rtx_SUBREG (SImode, operands[1], 4)));
5502   emit_insn (gen_vec_interleave_lowv4si (operands[3], operands[3],
5503                                          operands[4]));
5504
5505   operands[3] = gen_rtx_REG (DImode, REGNO (operands[3]));
5506 })
5507
5508 (define_split
5509   [(set (match_operand:X87MODEF 0 "register_operand" "")
5510         (float:X87MODEF (match_operand:DI 1 "memory_operand" "")))
5511    (clobber (match_scratch:V4SI 3 ""))
5512    (clobber (match_scratch:V4SI 4 ""))
5513    (clobber (match_operand:DI 2 "memory_operand" ""))]
5514   "TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5515    && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES
5516    && !TARGET_64BIT && optimize_function_for_speed_p (cfun)
5517    && reload_completed
5518    && FP_REG_P (operands[0])"
5519   [(set (match_dup 0) (float:X87MODEF (match_dup 1)))])
5520
5521 ;; Avoid store forwarding (partial memory) stall penalty by extending
5522 ;; SImode value to DImode through XMM register instead of pushing two
5523 ;; SImode values to stack. Note that even !TARGET_INTER_UNIT_MOVES
5524 ;; targets benefit from this optimization. Also note that fild
5525 ;; loads from memory only.
5526
5527 (define_insn "*floatunssi<mode>2_1"
5528   [(set (match_operand:X87MODEF 0 "register_operand" "=f,f")
5529         (unsigned_float:X87MODEF
5530           (match_operand:SI 1 "nonimmediate_operand" "x,m")))
5531    (clobber (match_operand:DI 2 "memory_operand" "=m,m"))
5532    (clobber (match_scratch:SI 3 "=X,x"))]
5533   "!TARGET_64BIT
5534    && TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5535    && TARGET_SSE"
5536   "#"
5537   [(set_attr "type" "multi")
5538    (set_attr "mode" "<MODE>")])
5539
5540 (define_split
5541   [(set (match_operand:X87MODEF 0 "register_operand" "")
5542         (unsigned_float:X87MODEF
5543           (match_operand:SI 1 "register_operand" "")))
5544    (clobber (match_operand:DI 2 "memory_operand" ""))
5545    (clobber (match_scratch:SI 3 ""))]
5546   "!TARGET_64BIT
5547    && TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5548    && TARGET_SSE
5549    && reload_completed"
5550   [(set (match_dup 2) (match_dup 1))
5551    (set (match_dup 0)
5552         (float:X87MODEF (match_dup 2)))]
5553   "operands[1] = simplify_gen_subreg (DImode, operands[1], SImode, 0);")
5554
5555 (define_split
5556   [(set (match_operand:X87MODEF 0 "register_operand" "")
5557         (unsigned_float:X87MODEF
5558           (match_operand:SI 1 "memory_operand" "")))
5559    (clobber (match_operand:DI 2 "memory_operand" ""))
5560    (clobber (match_scratch:SI 3 ""))]
5561   "!TARGET_64BIT
5562    && TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5563    && TARGET_SSE
5564    && reload_completed"
5565   [(set (match_dup 2) (match_dup 3))
5566    (set (match_dup 0)
5567         (float:X87MODEF (match_dup 2)))]
5568 {
5569   emit_move_insn (operands[3], operands[1]);
5570   operands[3] = simplify_gen_subreg (DImode, operands[3], SImode, 0);
5571 })
5572
5573 (define_expand "floatunssi<mode>2"
5574   [(parallel
5575      [(set (match_operand:X87MODEF 0 "register_operand" "")
5576            (unsigned_float:X87MODEF
5577              (match_operand:SI 1 "nonimmediate_operand" "")))
5578       (clobber (match_dup 2))
5579       (clobber (match_scratch:SI 3 ""))])]
5580   "!TARGET_64BIT
5581    && ((TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5582         && TARGET_SSE)
5583        || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))"
5584 {
5585   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
5586     {
5587       ix86_expand_convert_uns_si<mode>_sse (operands[0], operands[1]);
5588       DONE;
5589     }
5590   else
5591     {
5592       enum ix86_stack_slot slot = (virtuals_instantiated
5593                                    ? SLOT_TEMP
5594                                    : SLOT_VIRTUAL);
5595       operands[2] = assign_386_stack_local (DImode, slot);
5596     }
5597 })
5598
5599 (define_expand "floatunsdisf2"
5600   [(use (match_operand:SF 0 "register_operand" ""))
5601    (use (match_operand:DI 1 "nonimmediate_operand" ""))]
5602   "TARGET_64BIT && TARGET_SSE_MATH"
5603   "x86_emit_floatuns (operands); DONE;")
5604
5605 (define_expand "floatunsdidf2"
5606   [(use (match_operand:DF 0 "register_operand" ""))
5607    (use (match_operand:DI 1 "nonimmediate_operand" ""))]
5608   "(TARGET_64BIT || TARGET_KEEPS_VECTOR_ALIGNED_STACK)
5609    && TARGET_SSE2 && TARGET_SSE_MATH"
5610 {
5611   if (TARGET_64BIT)
5612     x86_emit_floatuns (operands);
5613   else
5614     ix86_expand_convert_uns_didf_sse (operands[0], operands[1]);
5615   DONE;
5616 })
5617 \f
5618 ;; Add instructions
5619
5620 (define_expand "add<mode>3"
5621   [(set (match_operand:SDWIM 0 "nonimmediate_operand" "")
5622         (plus:SDWIM (match_operand:SDWIM 1 "nonimmediate_operand" "")
5623                     (match_operand:SDWIM 2 "<general_operand>" "")))]
5624   ""
5625   "ix86_expand_binary_operator (PLUS, <MODE>mode, operands); DONE;")
5626
5627 (define_insn_and_split "*add<dwi>3_doubleword"
5628   [(set (match_operand:<DWI> 0 "nonimmediate_operand" "=r,o")
5629         (plus:<DWI>
5630           (match_operand:<DWI> 1 "nonimmediate_operand" "%0,0")
5631           (match_operand:<DWI> 2 "<general_operand>" "ro<di>,r<di>")))
5632    (clobber (reg:CC FLAGS_REG))]
5633   "ix86_binary_operator_ok (PLUS, <DWI>mode, operands)"
5634   "#"
5635   "reload_completed"
5636   [(parallel [(set (reg:CC FLAGS_REG)
5637                    (unspec:CC [(match_dup 1) (match_dup 2)]
5638                               UNSPEC_ADD_CARRY))
5639               (set (match_dup 0)
5640                    (plus:DWIH (match_dup 1) (match_dup 2)))])
5641    (parallel [(set (match_dup 3)
5642                    (plus:DWIH
5643                      (match_dup 4)
5644                      (plus:DWIH
5645                        (ltu:DWIH (reg:CC FLAGS_REG) (const_int 0))
5646                        (match_dup 5))))
5647               (clobber (reg:CC FLAGS_REG))])]
5648   "split_double_mode (<DWI>mode, &operands[0], 3, &operands[0], &operands[3]);")
5649
5650 (define_insn "*add<mode>3_cc"
5651   [(set (reg:CC FLAGS_REG)
5652         (unspec:CC
5653           [(match_operand:SWI48 1 "nonimmediate_operand" "%0,0")
5654            (match_operand:SWI48 2 "<general_operand>" "r<i>,rm")]
5655           UNSPEC_ADD_CARRY))
5656    (set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,r")
5657         (plus:SWI48 (match_dup 1) (match_dup 2)))]
5658   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
5659   "add{<imodesuffix>}\t{%2, %0|%0, %2}"
5660   [(set_attr "type" "alu")
5661    (set_attr "mode" "<MODE>")])
5662
5663 (define_insn "addqi3_cc"
5664   [(set (reg:CC FLAGS_REG)
5665         (unspec:CC
5666           [(match_operand:QI 1 "nonimmediate_operand" "%0,0")
5667            (match_operand:QI 2 "general_operand" "qn,qm")]
5668           UNSPEC_ADD_CARRY))
5669    (set (match_operand:QI 0 "nonimmediate_operand" "=qm,q")
5670         (plus:QI (match_dup 1) (match_dup 2)))]
5671   "ix86_binary_operator_ok (PLUS, QImode, operands)"
5672   "add{b}\t{%2, %0|%0, %2}"
5673   [(set_attr "type" "alu")
5674    (set_attr "mode" "QI")])
5675
5676 (define_insn "*lea_1"
5677   [(set (match_operand:P 0 "register_operand" "=r")
5678         (match_operand:P 1 "no_seg_address_operand" "p"))]
5679   ""
5680   "lea{<imodesuffix>}\t{%a1, %0|%0, %a1}"
5681   [(set_attr "type" "lea")
5682    (set_attr "mode" "<MODE>")])
5683
5684 (define_insn "*lea_2"
5685   [(set (match_operand:SI 0 "register_operand" "=r")
5686         (subreg:SI (match_operand:DI 1 "no_seg_address_operand" "p") 0))]
5687   "TARGET_64BIT"
5688   "lea{l}\t{%a1, %0|%0, %a1}"
5689   [(set_attr "type" "lea")
5690    (set_attr "mode" "SI")])
5691
5692 (define_insn "*lea_2_zext"
5693   [(set (match_operand:DI 0 "register_operand" "=r")
5694         (zero_extend:DI
5695           (subreg:SI (match_operand:DI 1 "no_seg_address_operand" "p") 0)))]
5696   "TARGET_64BIT"
5697   "lea{l}\t{%a1, %k0|%k0, %a1}"
5698   [(set_attr "type" "lea")
5699    (set_attr "mode" "SI")])
5700
5701 (define_insn "*add<mode>_1"
5702   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=r,rm,r,r")
5703         (plus:SWI48
5704           (match_operand:SWI48 1 "nonimmediate_operand" "%0,0,r,r")
5705           (match_operand:SWI48 2 "<general_operand>" "<g>,r<i>,0,l<i>")))
5706    (clobber (reg:CC FLAGS_REG))]
5707   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
5708 {
5709   switch (get_attr_type (insn))
5710     {
5711     case TYPE_LEA:
5712       return "#";
5713
5714     case TYPE_INCDEC:
5715       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5716       if (operands[2] == const1_rtx)
5717         return "inc{<imodesuffix>}\t%0";
5718       else
5719         {
5720           gcc_assert (operands[2] == constm1_rtx);
5721           return "dec{<imodesuffix>}\t%0";
5722         }
5723
5724     default:
5725       /* For most processors, ADD is faster than LEA.  This alternative
5726          was added to use ADD as much as possible.  */
5727       if (which_alternative == 2)
5728         {
5729           rtx tmp;
5730           tmp = operands[1], operands[1] = operands[2], operands[2] = tmp;
5731         }
5732         
5733       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5734       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
5735         return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
5736
5737       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
5738     }
5739 }
5740   [(set (attr "type")
5741      (cond [(eq_attr "alternative" "3")
5742               (const_string "lea")
5743             (match_operand:SWI48 2 "incdec_operand" "")
5744               (const_string "incdec")
5745            ]
5746            (const_string "alu")))
5747    (set (attr "length_immediate")
5748       (if_then_else
5749         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
5750         (const_string "1")
5751         (const_string "*")))
5752    (set_attr "mode" "<MODE>")])
5753
5754 ;; It may seem that nonimmediate operand is proper one for operand 1.
5755 ;; The addsi_1 pattern allows nonimmediate operand at that place and
5756 ;; we take care in ix86_binary_operator_ok to not allow two memory
5757 ;; operands so proper swapping will be done in reload.  This allow
5758 ;; patterns constructed from addsi_1 to match.
5759
5760 (define_insn "*addsi_1_zext"
5761   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
5762         (zero_extend:DI
5763           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0,r,r")
5764                    (match_operand:SI 2 "general_operand" "g,0,li"))))
5765    (clobber (reg:CC FLAGS_REG))]
5766   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, SImode, operands)"
5767 {
5768   switch (get_attr_type (insn))
5769     {
5770     case TYPE_LEA:
5771       return "#";
5772
5773     case TYPE_INCDEC:
5774       if (operands[2] == const1_rtx)
5775         return "inc{l}\t%k0";
5776       else
5777         {
5778           gcc_assert (operands[2] == constm1_rtx);
5779           return "dec{l}\t%k0";
5780         }
5781
5782     default:
5783       /* For most processors, ADD is faster than LEA.  This alternative
5784          was added to use ADD as much as possible.  */
5785       if (which_alternative == 1)
5786         {
5787           rtx tmp;
5788           tmp = operands[1], operands[1] = operands[2], operands[2] = tmp;
5789         }
5790
5791       if (x86_maybe_negate_const_int (&operands[2], SImode))
5792         return "sub{l}\t{%2, %k0|%k0, %2}";
5793
5794       return "add{l}\t{%2, %k0|%k0, %2}";
5795     }
5796 }
5797   [(set (attr "type")
5798      (cond [(eq_attr "alternative" "2")
5799               (const_string "lea")
5800             (match_operand:SI 2 "incdec_operand" "")
5801               (const_string "incdec")
5802            ]
5803            (const_string "alu")))
5804    (set (attr "length_immediate")
5805       (if_then_else
5806         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
5807         (const_string "1")
5808         (const_string "*")))
5809    (set_attr "mode" "SI")])
5810
5811 (define_insn "*addhi_1"
5812   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
5813         (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0")
5814                  (match_operand:HI 2 "general_operand" "rn,rm")))
5815    (clobber (reg:CC FLAGS_REG))]
5816   "TARGET_PARTIAL_REG_STALL
5817    && ix86_binary_operator_ok (PLUS, HImode, operands)"
5818 {
5819   switch (get_attr_type (insn))
5820     {
5821     case TYPE_INCDEC:
5822       if (operands[2] == const1_rtx)
5823         return "inc{w}\t%0";
5824       else
5825         {
5826           gcc_assert (operands[2] == constm1_rtx);
5827           return "dec{w}\t%0";
5828         }
5829
5830     default:
5831       if (x86_maybe_negate_const_int (&operands[2], HImode))
5832         return "sub{w}\t{%2, %0|%0, %2}";
5833
5834       return "add{w}\t{%2, %0|%0, %2}";
5835     }
5836 }
5837   [(set (attr "type")
5838      (if_then_else (match_operand:HI 2 "incdec_operand" "")
5839         (const_string "incdec")
5840         (const_string "alu")))
5841    (set (attr "length_immediate")
5842       (if_then_else
5843         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
5844         (const_string "1")
5845         (const_string "*")))
5846    (set_attr "mode" "HI")])
5847
5848 (define_insn "*addhi_1_lea"
5849   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,rm,r,r")
5850         (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,r,r")
5851                  (match_operand:HI 2 "general_operand" "rmn,rn,0,ln")))
5852    (clobber (reg:CC FLAGS_REG))]
5853   "!TARGET_PARTIAL_REG_STALL
5854    && ix86_binary_operator_ok (PLUS, HImode, operands)"
5855 {
5856   switch (get_attr_type (insn))
5857     {
5858     case TYPE_LEA:
5859       return "#";
5860
5861     case TYPE_INCDEC:
5862       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5863       if (operands[2] == const1_rtx)
5864         return "inc{w}\t%0";
5865       else
5866         {
5867           gcc_assert (operands[2] == constm1_rtx);
5868           return "dec{w}\t%0";
5869         }
5870
5871     default:
5872       /* For most processors, ADD is faster than LEA.  This alternative
5873          was added to use ADD as much as possible.  */
5874       if (which_alternative == 2)
5875         {
5876           rtx tmp;
5877           tmp = operands[1], operands[1] = operands[2], operands[2] = tmp;
5878         }
5879
5880       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5881       if (x86_maybe_negate_const_int (&operands[2], HImode))
5882         return "sub{w}\t{%2, %0|%0, %2}";
5883
5884       return "add{w}\t{%2, %0|%0, %2}";
5885     }
5886 }
5887   [(set (attr "type")
5888      (cond [(eq_attr "alternative" "3")
5889               (const_string "lea")
5890             (match_operand:HI 2 "incdec_operand" "")
5891               (const_string "incdec")
5892            ]
5893            (const_string "alu")))
5894    (set (attr "length_immediate")
5895       (if_then_else
5896         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
5897         (const_string "1")
5898         (const_string "*")))
5899    (set_attr "mode" "HI,HI,HI,SI")])
5900
5901 ;; %%% Potential partial reg stall on alternative 2.  What to do?
5902 (define_insn "*addqi_1"
5903   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q,r")
5904         (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
5905                  (match_operand:QI 2 "general_operand" "qn,qmn,rn")))
5906    (clobber (reg:CC FLAGS_REG))]
5907   "TARGET_PARTIAL_REG_STALL
5908    && ix86_binary_operator_ok (PLUS, QImode, operands)"
5909 {
5910   int widen = (which_alternative == 2);
5911   switch (get_attr_type (insn))
5912     {
5913     case TYPE_INCDEC:
5914       if (operands[2] == const1_rtx)
5915         return widen ? "inc{l}\t%k0" : "inc{b}\t%0";
5916       else
5917         {
5918           gcc_assert (operands[2] == constm1_rtx);
5919           return widen ? "dec{l}\t%k0" : "dec{b}\t%0";
5920         }
5921
5922     default:
5923       if (x86_maybe_negate_const_int (&operands[2], QImode))
5924         {
5925           if (widen)
5926             return "sub{l}\t{%2, %k0|%k0, %2}";
5927           else
5928             return "sub{b}\t{%2, %0|%0, %2}";
5929         }
5930       if (widen)
5931         return "add{l}\t{%k2, %k0|%k0, %k2}";
5932       else
5933         return "add{b}\t{%2, %0|%0, %2}";
5934     }
5935 }
5936   [(set (attr "type")
5937      (if_then_else (match_operand:QI 2 "incdec_operand" "")
5938         (const_string "incdec")
5939         (const_string "alu")))
5940    (set (attr "length_immediate")
5941       (if_then_else
5942         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
5943         (const_string "1")
5944         (const_string "*")))
5945    (set_attr "mode" "QI,QI,SI")])
5946
5947 ;; %%% Potential partial reg stall on alternatives 3 and 4.  What to do?
5948 (define_insn "*addqi_1_lea"
5949   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,qm,q,r,r,r")
5950         (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,q,0,r,r")
5951                  (match_operand:QI 2 "general_operand" "qmn,qn,0,rn,0,ln")))
5952    (clobber (reg:CC FLAGS_REG))]
5953   "!TARGET_PARTIAL_REG_STALL
5954    && ix86_binary_operator_ok (PLUS, QImode, operands)"
5955 {
5956   int widen = (which_alternative == 3 || which_alternative == 4);
5957
5958   switch (get_attr_type (insn))
5959     {
5960     case TYPE_LEA:
5961       return "#";
5962
5963     case TYPE_INCDEC:
5964       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5965       if (operands[2] == const1_rtx)
5966         return widen ? "inc{l}\t%k0" : "inc{b}\t%0";
5967       else
5968         {
5969           gcc_assert (operands[2] == constm1_rtx);
5970           return widen ? "dec{l}\t%k0" : "dec{b}\t%0";
5971         }
5972
5973     default:
5974       /* For most processors, ADD is faster than LEA.  These alternatives
5975          were added to use ADD as much as possible.  */
5976       if (which_alternative == 2 || which_alternative == 4)
5977         {
5978           rtx tmp;
5979           tmp = operands[1], operands[1] = operands[2], operands[2] = tmp;
5980         }
5981
5982       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5983       if (x86_maybe_negate_const_int (&operands[2], QImode))
5984         {
5985           if (widen)
5986             return "sub{l}\t{%2, %k0|%k0, %2}";
5987           else
5988             return "sub{b}\t{%2, %0|%0, %2}";
5989         }
5990       if (widen)
5991         return "add{l}\t{%k2, %k0|%k0, %k2}";
5992       else
5993         return "add{b}\t{%2, %0|%0, %2}";
5994     }
5995 }
5996   [(set (attr "type")
5997      (cond [(eq_attr "alternative" "5")
5998               (const_string "lea")
5999             (match_operand:QI 2 "incdec_operand" "")
6000               (const_string "incdec")
6001            ]
6002            (const_string "alu")))
6003    (set (attr "length_immediate")
6004       (if_then_else
6005         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6006         (const_string "1")
6007         (const_string "*")))
6008    (set_attr "mode" "QI,QI,QI,SI,SI,SI")])
6009
6010 (define_insn "*addqi_1_slp"
6011   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
6012         (plus:QI (match_dup 0)
6013                  (match_operand:QI 1 "general_operand" "qn,qnm")))
6014    (clobber (reg:CC FLAGS_REG))]
6015   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
6016    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
6017 {
6018   switch (get_attr_type (insn))
6019     {
6020     case TYPE_INCDEC:
6021       if (operands[1] == const1_rtx)
6022         return "inc{b}\t%0";
6023       else
6024         {
6025           gcc_assert (operands[1] == constm1_rtx);
6026           return "dec{b}\t%0";
6027         }
6028
6029     default:
6030       if (x86_maybe_negate_const_int (&operands[1], QImode))
6031         return "sub{b}\t{%1, %0|%0, %1}";
6032
6033       return "add{b}\t{%1, %0|%0, %1}";
6034     }
6035 }
6036   [(set (attr "type")
6037      (if_then_else (match_operand:QI 1 "incdec_operand" "")
6038         (const_string "incdec")
6039         (const_string "alu1")))
6040    (set (attr "memory")
6041      (if_then_else (match_operand 1 "memory_operand" "")
6042         (const_string "load")
6043         (const_string "none")))
6044    (set_attr "mode" "QI")])
6045
6046 ;; Convert lea to the lea pattern to avoid flags dependency.
6047 (define_split
6048   [(set (match_operand 0 "register_operand" "")
6049         (plus (match_operand 1 "register_operand" "")
6050               (match_operand 2 "nonmemory_operand" "")))
6051    (clobber (reg:CC FLAGS_REG))]
6052   "reload_completed && ix86_lea_for_add_ok (insn, operands)" 
6053   [(const_int 0)]
6054 {
6055   rtx pat;
6056   enum machine_mode mode = GET_MODE (operands[0]);
6057
6058   /* In -fPIC mode the constructs like (const (unspec [symbol_ref]))
6059      may confuse gen_lowpart.  */
6060   if (mode != Pmode)
6061     {
6062       operands[1] = gen_lowpart (Pmode, operands[1]);
6063       operands[2] = gen_lowpart (Pmode, operands[2]);
6064     }
6065
6066   pat = gen_rtx_PLUS (Pmode, operands[1], operands[2]);
6067
6068   if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (SImode))
6069     operands[0] = gen_lowpart (SImode, operands[0]);
6070
6071   if (TARGET_64BIT && mode != Pmode)
6072     pat = gen_rtx_SUBREG (SImode, pat, 0);
6073
6074   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
6075   DONE;
6076 })
6077
6078 ;; Convert lea to the lea pattern to avoid flags dependency.
6079 ;; ??? This pattern handles immediate operands that do not satisfy immediate
6080 ;; operand predicate (TARGET_LEGITIMATE_CONSTANT_P) in the previous pattern.
6081 (define_split
6082   [(set (match_operand:DI 0 "register_operand" "")
6083         (plus:DI (match_operand:DI 1 "register_operand" "")
6084                  (match_operand:DI 2 "x86_64_immediate_operand" "")))
6085    (clobber (reg:CC FLAGS_REG))]
6086   "TARGET_64BIT && reload_completed 
6087    && true_regnum (operands[0]) != true_regnum (operands[1])"
6088   [(set (match_dup 0)
6089         (plus:DI (match_dup 1) (match_dup 2)))])
6090
6091 ;; Convert lea to the lea pattern to avoid flags dependency.
6092 (define_split
6093   [(set (match_operand:DI 0 "register_operand" "")
6094         (zero_extend:DI
6095           (plus:SI (match_operand:SI 1 "register_operand" "")
6096                    (match_operand:SI 2 "nonmemory_operand" ""))))
6097    (clobber (reg:CC FLAGS_REG))]
6098   "TARGET_64BIT && reload_completed
6099    && ix86_lea_for_add_ok (insn, operands)"
6100   [(set (match_dup 0)
6101         (zero_extend:DI (subreg:SI (plus:DI (match_dup 1) (match_dup 2)) 0)))]
6102 {
6103   operands[1] = gen_lowpart (DImode, operands[1]);
6104   operands[2] = gen_lowpart (DImode, operands[2]);
6105 })
6106
6107 (define_insn "*add<mode>_2"
6108   [(set (reg FLAGS_REG)
6109         (compare
6110           (plus:SWI
6111             (match_operand:SWI 1 "nonimmediate_operand" "%0,0")
6112             (match_operand:SWI 2 "<general_operand>" "<g>,<r><i>"))
6113           (const_int 0)))
6114    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>,<r>m")
6115         (plus:SWI (match_dup 1) (match_dup 2)))]
6116   "ix86_match_ccmode (insn, CCGOCmode)
6117    && ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
6118 {
6119   switch (get_attr_type (insn))
6120     {
6121     case TYPE_INCDEC:
6122       if (operands[2] == const1_rtx)
6123         return "inc{<imodesuffix>}\t%0";
6124       else
6125         {
6126           gcc_assert (operands[2] == constm1_rtx);
6127           return "dec{<imodesuffix>}\t%0";
6128         }
6129
6130     default:
6131       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
6132         return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
6133
6134       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
6135     }
6136 }
6137   [(set (attr "type")
6138      (if_then_else (match_operand:SWI 2 "incdec_operand" "")
6139         (const_string "incdec")
6140         (const_string "alu")))
6141    (set (attr "length_immediate")
6142       (if_then_else
6143         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6144         (const_string "1")
6145         (const_string "*")))
6146    (set_attr "mode" "<MODE>")])
6147
6148 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
6149 (define_insn "*addsi_2_zext"
6150   [(set (reg FLAGS_REG)
6151         (compare
6152           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
6153                    (match_operand:SI 2 "general_operand" "g"))
6154           (const_int 0)))
6155    (set (match_operand:DI 0 "register_operand" "=r")
6156         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))]
6157   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
6158    && ix86_binary_operator_ok (PLUS, SImode, operands)"
6159 {
6160   switch (get_attr_type (insn))
6161     {
6162     case TYPE_INCDEC:
6163       if (operands[2] == const1_rtx)
6164         return "inc{l}\t%k0";
6165       else
6166         {
6167           gcc_assert (operands[2] == constm1_rtx);
6168           return "dec{l}\t%k0";
6169         }
6170
6171     default:
6172       if (x86_maybe_negate_const_int (&operands[2], SImode))
6173         return "sub{l}\t{%2, %k0|%k0, %2}";
6174
6175       return "add{l}\t{%2, %k0|%k0, %2}";
6176     }
6177 }
6178   [(set (attr "type")
6179      (if_then_else (match_operand:SI 2 "incdec_operand" "")
6180         (const_string "incdec")
6181         (const_string "alu")))
6182    (set (attr "length_immediate")
6183       (if_then_else
6184         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6185         (const_string "1")
6186         (const_string "*")))
6187    (set_attr "mode" "SI")])
6188
6189 (define_insn "*add<mode>_3"
6190   [(set (reg FLAGS_REG)
6191         (compare
6192           (neg:SWI (match_operand:SWI 2 "<general_operand>" "<g>"))
6193           (match_operand:SWI 1 "nonimmediate_operand" "%0")))
6194    (clobber (match_scratch:SWI 0 "=<r>"))]
6195   "ix86_match_ccmode (insn, CCZmode)
6196    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6197 {
6198   switch (get_attr_type (insn))
6199     {
6200     case TYPE_INCDEC:
6201       if (operands[2] == const1_rtx)
6202         return "inc{<imodesuffix>}\t%0";
6203       else
6204         {
6205           gcc_assert (operands[2] == constm1_rtx);
6206           return "dec{<imodesuffix>}\t%0";
6207         }
6208
6209     default:
6210       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
6211         return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
6212
6213       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
6214     }
6215 }
6216   [(set (attr "type")
6217      (if_then_else (match_operand:SWI 2 "incdec_operand" "")
6218         (const_string "incdec")
6219         (const_string "alu")))
6220    (set (attr "length_immediate")
6221       (if_then_else
6222         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6223         (const_string "1")
6224         (const_string "*")))
6225    (set_attr "mode" "<MODE>")])
6226
6227 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
6228 (define_insn "*addsi_3_zext"
6229   [(set (reg FLAGS_REG)
6230         (compare
6231           (neg:SI (match_operand:SI 2 "general_operand" "g"))
6232           (match_operand:SI 1 "nonimmediate_operand" "%0")))
6233    (set (match_operand:DI 0 "register_operand" "=r")
6234         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))]
6235   "TARGET_64BIT && ix86_match_ccmode (insn, CCZmode)
6236    && ix86_binary_operator_ok (PLUS, SImode, operands)"
6237 {
6238   switch (get_attr_type (insn))
6239     {
6240     case TYPE_INCDEC:
6241       if (operands[2] == const1_rtx)
6242         return "inc{l}\t%k0";
6243       else
6244         {
6245           gcc_assert (operands[2] == constm1_rtx);
6246           return "dec{l}\t%k0";
6247         }
6248
6249     default:
6250       if (x86_maybe_negate_const_int (&operands[2], SImode))
6251         return "sub{l}\t{%2, %k0|%k0, %2}";
6252
6253       return "add{l}\t{%2, %k0|%k0, %2}";
6254     }
6255 }
6256   [(set (attr "type")
6257      (if_then_else (match_operand:SI 2 "incdec_operand" "")
6258         (const_string "incdec")
6259         (const_string "alu")))
6260    (set (attr "length_immediate")
6261       (if_then_else
6262         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6263         (const_string "1")
6264         (const_string "*")))
6265    (set_attr "mode" "SI")])
6266
6267 ; For comparisons against 1, -1 and 128, we may generate better code
6268 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
6269 ; is matched then.  We can't accept general immediate, because for
6270 ; case of overflows,  the result is messed up.
6271 ; Also carry flag is reversed compared to cmp, so this conversion is valid
6272 ; only for comparisons not depending on it.
6273
6274 (define_insn "*adddi_4"
6275   [(set (reg FLAGS_REG)
6276         (compare
6277           (match_operand:DI 1 "nonimmediate_operand" "0")
6278           (match_operand:DI 2 "x86_64_immediate_operand" "e")))
6279    (clobber (match_scratch:DI 0 "=rm"))]
6280   "TARGET_64BIT
6281    && ix86_match_ccmode (insn, CCGCmode)"
6282 {
6283   switch (get_attr_type (insn))
6284     {
6285     case TYPE_INCDEC:
6286       if (operands[2] == constm1_rtx)
6287         return "inc{q}\t%0";
6288       else
6289         {
6290           gcc_assert (operands[2] == const1_rtx);
6291           return "dec{q}\t%0";
6292         }
6293
6294     default:
6295       if (x86_maybe_negate_const_int (&operands[2], DImode))
6296         return "add{q}\t{%2, %0|%0, %2}";
6297
6298       return "sub{q}\t{%2, %0|%0, %2}";
6299     }
6300 }
6301   [(set (attr "type")
6302      (if_then_else (match_operand:DI 2 "incdec_operand" "")
6303         (const_string "incdec")
6304         (const_string "alu")))
6305    (set (attr "length_immediate")
6306       (if_then_else
6307         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6308         (const_string "1")
6309         (const_string "*")))
6310    (set_attr "mode" "DI")])
6311
6312 ; For comparisons against 1, -1 and 128, we may generate better code
6313 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
6314 ; is matched then.  We can't accept general immediate, because for
6315 ; case of overflows,  the result is messed up.
6316 ; Also carry flag is reversed compared to cmp, so this conversion is valid
6317 ; only for comparisons not depending on it.
6318
6319 (define_insn "*add<mode>_4"
6320   [(set (reg FLAGS_REG)
6321         (compare
6322           (match_operand:SWI124 1 "nonimmediate_operand" "0")
6323           (match_operand:SWI124 2 "const_int_operand" "n")))
6324    (clobber (match_scratch:SWI124 0 "=<r>m"))]
6325   "ix86_match_ccmode (insn, CCGCmode)"
6326 {
6327   switch (get_attr_type (insn))
6328     {
6329     case TYPE_INCDEC:
6330       if (operands[2] == constm1_rtx)
6331         return "inc{<imodesuffix>}\t%0";
6332       else
6333         {
6334           gcc_assert (operands[2] == const1_rtx);
6335           return "dec{<imodesuffix>}\t%0";
6336         }
6337
6338     default:
6339       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
6340         return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
6341
6342       return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
6343     }
6344 }
6345   [(set (attr "type")
6346      (if_then_else (match_operand:<MODE> 2 "incdec_operand" "")
6347         (const_string "incdec")
6348         (const_string "alu")))
6349    (set (attr "length_immediate")
6350       (if_then_else
6351         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6352         (const_string "1")
6353         (const_string "*")))
6354    (set_attr "mode" "<MODE>")])
6355
6356 (define_insn "*add<mode>_5"
6357   [(set (reg FLAGS_REG)
6358         (compare
6359           (plus:SWI
6360             (match_operand:SWI 1 "nonimmediate_operand" "%0")
6361             (match_operand:SWI 2 "<general_operand>" "<g>"))
6362           (const_int 0)))
6363    (clobber (match_scratch:SWI 0 "=<r>"))]
6364   "ix86_match_ccmode (insn, CCGOCmode)
6365    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6366 {
6367   switch (get_attr_type (insn))
6368     {
6369     case TYPE_INCDEC:
6370       if (operands[2] == const1_rtx)
6371         return "inc{<imodesuffix>}\t%0";
6372       else
6373         {
6374           gcc_assert (operands[2] == constm1_rtx);
6375           return "dec{<imodesuffix>}\t%0";
6376         }
6377
6378     default:
6379       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
6380         return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
6381
6382       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
6383     }
6384 }
6385   [(set (attr "type")
6386      (if_then_else (match_operand:SWI 2 "incdec_operand" "")
6387         (const_string "incdec")
6388         (const_string "alu")))
6389    (set (attr "length_immediate")
6390       (if_then_else
6391         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand" ""))
6392         (const_string "1")
6393         (const_string "*")))
6394    (set_attr "mode" "<MODE>")])
6395
6396 (define_insn "*addqi_ext_1_rex64"
6397   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
6398                          (const_int 8)
6399                          (const_int 8))
6400         (plus:SI
6401           (zero_extract:SI
6402             (match_operand 1 "ext_register_operand" "0")
6403             (const_int 8)
6404             (const_int 8))
6405           (match_operand:QI 2 "nonmemory_operand" "Qn")))
6406    (clobber (reg:CC FLAGS_REG))]
6407   "TARGET_64BIT"
6408 {
6409   switch (get_attr_type (insn))
6410     {
6411     case TYPE_INCDEC:
6412       if (operands[2] == const1_rtx)
6413         return "inc{b}\t%h0";
6414       else
6415         {
6416           gcc_assert (operands[2] == constm1_rtx);
6417           return "dec{b}\t%h0";
6418         }
6419
6420     default:
6421       return "add{b}\t{%2, %h0|%h0, %2}";
6422     }
6423 }
6424   [(set (attr "type")
6425      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6426         (const_string "incdec")
6427         (const_string "alu")))
6428    (set_attr "modrm" "1")
6429    (set_attr "mode" "QI")])
6430
6431 (define_insn "addqi_ext_1"
6432   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
6433                          (const_int 8)
6434                          (const_int 8))
6435         (plus:SI
6436           (zero_extract:SI
6437             (match_operand 1 "ext_register_operand" "0")
6438             (const_int 8)
6439             (const_int 8))
6440           (match_operand:QI 2 "general_operand" "Qmn")))
6441    (clobber (reg:CC FLAGS_REG))]
6442   "!TARGET_64BIT"
6443 {
6444   switch (get_attr_type (insn))
6445     {
6446     case TYPE_INCDEC:
6447       if (operands[2] == const1_rtx)
6448         return "inc{b}\t%h0";
6449       else
6450         {
6451           gcc_assert (operands[2] == constm1_rtx);
6452           return "dec{b}\t%h0";
6453         }
6454
6455     default:
6456       return "add{b}\t{%2, %h0|%h0, %2}";
6457     }
6458 }
6459   [(set (attr "type")
6460      (if_then_else (match_operand:QI 2 "incdec_operand" "")
6461         (const_string "incdec")
6462         (const_string "alu")))
6463    (set_attr "modrm" "1")
6464    (set_attr "mode" "QI")])
6465
6466 (define_insn "*addqi_ext_2"
6467   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
6468                          (const_int 8)
6469                          (const_int 8))
6470         (plus:SI
6471           (zero_extract:SI
6472             (match_operand 1 "ext_register_operand" "%0")
6473             (const_int 8)
6474             (const_int 8))
6475           (zero_extract:SI
6476             (match_operand 2 "ext_register_operand" "Q")
6477             (const_int 8)
6478             (const_int 8))))
6479    (clobber (reg:CC FLAGS_REG))]
6480   ""
6481   "add{b}\t{%h2, %h0|%h0, %h2}"
6482   [(set_attr "type" "alu")
6483    (set_attr "mode" "QI")])
6484
6485 ;; The lea patterns for non-Pmodes needs to be matched by
6486 ;; several insns converted to real lea by splitters.
6487
6488 (define_insn_and_split "*lea_general_1"
6489   [(set (match_operand 0 "register_operand" "=r")
6490         (plus (plus (match_operand 1 "index_register_operand" "l")
6491                     (match_operand 2 "register_operand" "r"))
6492               (match_operand 3 "immediate_operand" "i")))]
6493   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode
6494     || (TARGET_64BIT && GET_MODE (operands[0]) == SImode))
6495    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
6496    && GET_MODE (operands[0]) == GET_MODE (operands[1])
6497    && GET_MODE (operands[0]) == GET_MODE (operands[2])
6498    && (GET_MODE (operands[0]) == GET_MODE (operands[3])
6499        || GET_MODE (operands[3]) == VOIDmode)"
6500   "#"
6501   "&& reload_completed"
6502   [(const_int 0)]
6503 {
6504   rtx pat;
6505   operands[0] = gen_lowpart (SImode, operands[0]);
6506   operands[1] = gen_lowpart (Pmode, operands[1]);
6507   operands[2] = gen_lowpart (Pmode, operands[2]);
6508   operands[3] = gen_lowpart (Pmode, operands[3]);
6509   pat = gen_rtx_PLUS (Pmode, gen_rtx_PLUS (Pmode, operands[1], operands[2]),
6510                       operands[3]);
6511   if (Pmode != SImode)
6512     pat = gen_rtx_SUBREG (SImode, pat, 0);
6513   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
6514   DONE;
6515 }
6516   [(set_attr "type" "lea")
6517    (set_attr "mode" "SI")])
6518
6519 (define_insn_and_split "*lea_general_1_zext"
6520   [(set (match_operand:DI 0 "register_operand" "=r")
6521         (zero_extend:DI
6522           (plus:SI (plus:SI
6523                      (match_operand:SI 1 "index_register_operand" "l")
6524                      (match_operand:SI 2 "register_operand" "r"))
6525                    (match_operand:SI 3 "immediate_operand" "i"))))]
6526   "TARGET_64BIT"
6527   "#"
6528   "&& reload_completed"
6529   [(set (match_dup 0)
6530         (zero_extend:DI (subreg:SI (plus:DI (plus:DI (match_dup 1)
6531                                                      (match_dup 2))
6532                                             (match_dup 3)) 0)))]
6533 {
6534   operands[1] = gen_lowpart (Pmode, operands[1]);
6535   operands[2] = gen_lowpart (Pmode, operands[2]);
6536   operands[3] = gen_lowpart (Pmode, operands[3]);
6537 }
6538   [(set_attr "type" "lea")
6539    (set_attr "mode" "SI")])
6540
6541 (define_insn_and_split "*lea_general_2"
6542   [(set (match_operand 0 "register_operand" "=r")
6543         (plus (mult (match_operand 1 "index_register_operand" "l")
6544                     (match_operand 2 "const248_operand" "i"))
6545               (match_operand 3 "nonmemory_operand" "ri")))]
6546   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode
6547     || (TARGET_64BIT && GET_MODE (operands[0]) == SImode))
6548    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
6549    && GET_MODE (operands[0]) == GET_MODE (operands[1])
6550    && (GET_MODE (operands[0]) == GET_MODE (operands[3])
6551        || GET_MODE (operands[3]) == VOIDmode)"
6552   "#"
6553   "&& reload_completed"
6554   [(const_int 0)]
6555 {
6556   rtx pat;
6557   operands[0] = gen_lowpart (SImode, operands[0]);
6558   operands[1] = gen_lowpart (Pmode, operands[1]);
6559   operands[3] = gen_lowpart (Pmode, operands[3]);
6560   pat = gen_rtx_PLUS (Pmode, gen_rtx_MULT (Pmode, operands[1], operands[2]),
6561                       operands[3]);
6562   if (Pmode != SImode)
6563     pat = gen_rtx_SUBREG (SImode, pat, 0);
6564   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
6565   DONE;
6566 }
6567   [(set_attr "type" "lea")
6568    (set_attr "mode" "SI")])
6569
6570 (define_insn_and_split "*lea_general_2_zext"
6571   [(set (match_operand:DI 0 "register_operand" "=r")
6572         (zero_extend:DI
6573           (plus:SI (mult:SI
6574                      (match_operand:SI 1 "index_register_operand" "l")
6575                      (match_operand:SI 2 "const248_operand" "n"))
6576                    (match_operand:SI 3 "nonmemory_operand" "ri"))))]
6577   "TARGET_64BIT"
6578   "#"
6579   "&& reload_completed"
6580   [(set (match_dup 0)
6581         (zero_extend:DI (subreg:SI (plus:DI (mult:DI (match_dup 1)
6582                                                      (match_dup 2))
6583                                             (match_dup 3)) 0)))]
6584 {
6585   operands[1] = gen_lowpart (Pmode, operands[1]);
6586   operands[3] = gen_lowpart (Pmode, operands[3]);
6587 }
6588   [(set_attr "type" "lea")
6589    (set_attr "mode" "SI")])
6590
6591 (define_insn_and_split "*lea_general_3"
6592   [(set (match_operand 0 "register_operand" "=r")
6593         (plus (plus (mult (match_operand 1 "index_register_operand" "l")
6594                           (match_operand 2 "const248_operand" "i"))
6595                     (match_operand 3 "register_operand" "r"))
6596               (match_operand 4 "immediate_operand" "i")))]
6597   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode
6598     || (TARGET_64BIT && GET_MODE (operands[0]) == SImode))
6599    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
6600    && GET_MODE (operands[0]) == GET_MODE (operands[1])
6601    && GET_MODE (operands[0]) == GET_MODE (operands[3])"
6602   "#"
6603   "&& reload_completed"
6604   [(const_int 0)]
6605 {
6606   rtx pat;
6607   operands[0] = gen_lowpart (SImode, operands[0]);
6608   operands[1] = gen_lowpart (Pmode, operands[1]);
6609   operands[3] = gen_lowpart (Pmode, operands[3]);
6610   operands[4] = gen_lowpart (Pmode, operands[4]);
6611   pat = gen_rtx_PLUS (Pmode,
6612                       gen_rtx_PLUS (Pmode, gen_rtx_MULT (Pmode, operands[1],
6613                                                          operands[2]),
6614                                     operands[3]),
6615                       operands[4]);
6616   if (Pmode != SImode)
6617     pat = gen_rtx_SUBREG (SImode, pat, 0);
6618   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
6619   DONE;
6620 }
6621   [(set_attr "type" "lea")
6622    (set_attr "mode" "SI")])
6623
6624 (define_insn_and_split "*lea_general_3_zext"
6625   [(set (match_operand:DI 0 "register_operand" "=r")
6626         (zero_extend:DI
6627           (plus:SI (plus:SI
6628                      (mult:SI
6629                        (match_operand:SI 1 "index_register_operand" "l")
6630                        (match_operand:SI 2 "const248_operand" "n"))
6631                      (match_operand:SI 3 "register_operand" "r"))
6632                    (match_operand:SI 4 "immediate_operand" "i"))))]
6633   "TARGET_64BIT"
6634   "#"
6635   "&& reload_completed"
6636   [(set (match_dup 0)
6637         (zero_extend:DI (subreg:SI (plus:DI (plus:DI (mult:DI (match_dup 1)
6638                                                               (match_dup 2))
6639                                                      (match_dup 3))
6640                                             (match_dup 4)) 0)))]
6641 {
6642   operands[1] = gen_lowpart (Pmode, operands[1]);
6643   operands[3] = gen_lowpart (Pmode, operands[3]);
6644   operands[4] = gen_lowpart (Pmode, operands[4]);
6645 }
6646   [(set_attr "type" "lea")
6647    (set_attr "mode" "SI")])
6648 \f
6649 ;; Subtract instructions
6650
6651 (define_expand "sub<mode>3"
6652   [(set (match_operand:SDWIM 0 "nonimmediate_operand" "")
6653         (minus:SDWIM (match_operand:SDWIM 1 "nonimmediate_operand" "")
6654                      (match_operand:SDWIM 2 "<general_operand>" "")))]
6655   ""
6656   "ix86_expand_binary_operator (MINUS, <MODE>mode, operands); DONE;")
6657
6658 (define_insn_and_split "*sub<dwi>3_doubleword"
6659   [(set (match_operand:<DWI> 0 "nonimmediate_operand" "=r,o")
6660         (minus:<DWI>
6661           (match_operand:<DWI> 1 "nonimmediate_operand" "0,0")
6662           (match_operand:<DWI> 2 "<general_operand>" "ro<di>,r<di>")))
6663    (clobber (reg:CC FLAGS_REG))]
6664   "ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
6665   "#"
6666   "reload_completed"
6667   [(parallel [(set (reg:CC FLAGS_REG)
6668                    (compare:CC (match_dup 1) (match_dup 2)))
6669               (set (match_dup 0)
6670                    (minus:DWIH (match_dup 1) (match_dup 2)))])
6671    (parallel [(set (match_dup 3)
6672                    (minus:DWIH
6673                      (match_dup 4)
6674                      (plus:DWIH
6675                        (ltu:DWIH (reg:CC FLAGS_REG) (const_int 0))
6676                        (match_dup 5))))
6677               (clobber (reg:CC FLAGS_REG))])]
6678   "split_double_mode (<DWI>mode, &operands[0], 3, &operands[0], &operands[3]);")
6679
6680 (define_insn "*sub<mode>_1"
6681   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6682         (minus:SWI
6683           (match_operand:SWI 1 "nonimmediate_operand" "0,0")
6684           (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m")))
6685    (clobber (reg:CC FLAGS_REG))]
6686   "ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
6687   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
6688   [(set_attr "type" "alu")
6689    (set_attr "mode" "<MODE>")])
6690
6691 (define_insn "*subsi_1_zext"
6692   [(set (match_operand:DI 0 "register_operand" "=r")
6693         (zero_extend:DI
6694           (minus:SI (match_operand:SI 1 "register_operand" "0")
6695                     (match_operand:SI 2 "general_operand" "g"))))
6696    (clobber (reg:CC FLAGS_REG))]
6697   "TARGET_64BIT && ix86_binary_operator_ok (MINUS, SImode, operands)"
6698   "sub{l}\t{%2, %k0|%k0, %2}"
6699   [(set_attr "type" "alu")
6700    (set_attr "mode" "SI")])
6701
6702 (define_insn "*subqi_1_slp"
6703   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
6704         (minus:QI (match_dup 0)
6705                   (match_operand:QI 1 "general_operand" "qn,qm")))
6706    (clobber (reg:CC FLAGS_REG))]
6707   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
6708    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
6709   "sub{b}\t{%1, %0|%0, %1}"
6710   [(set_attr "type" "alu1")
6711    (set_attr "mode" "QI")])
6712
6713 (define_insn "*sub<mode>_2"
6714   [(set (reg FLAGS_REG)
6715         (compare
6716           (minus:SWI
6717             (match_operand:SWI 1 "nonimmediate_operand" "0,0")
6718             (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m"))
6719           (const_int 0)))
6720    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6721         (minus:SWI (match_dup 1) (match_dup 2)))]
6722   "ix86_match_ccmode (insn, CCGOCmode)
6723    && ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
6724   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
6725   [(set_attr "type" "alu")
6726    (set_attr "mode" "<MODE>")])
6727
6728 (define_insn "*subsi_2_zext"
6729   [(set (reg FLAGS_REG)
6730         (compare
6731           (minus:SI (match_operand:SI 1 "register_operand" "0")
6732                     (match_operand:SI 2 "general_operand" "g"))
6733           (const_int 0)))
6734    (set (match_operand:DI 0 "register_operand" "=r")
6735         (zero_extend:DI
6736           (minus:SI (match_dup 1)
6737                     (match_dup 2))))]
6738   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
6739    && ix86_binary_operator_ok (MINUS, SImode, operands)"
6740   "sub{l}\t{%2, %k0|%k0, %2}"
6741   [(set_attr "type" "alu")
6742    (set_attr "mode" "SI")])
6743
6744 (define_insn "*sub<mode>_3"
6745   [(set (reg FLAGS_REG)
6746         (compare (match_operand:SWI 1 "nonimmediate_operand" "0,0")
6747                  (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m")))
6748    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6749         (minus:SWI (match_dup 1) (match_dup 2)))]
6750   "ix86_match_ccmode (insn, CCmode)
6751    && ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
6752   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
6753   [(set_attr "type" "alu")
6754    (set_attr "mode" "<MODE>")])
6755
6756 (define_insn "*subsi_3_zext"
6757   [(set (reg FLAGS_REG)
6758         (compare (match_operand:SI 1 "register_operand" "0")
6759                  (match_operand:SI 2 "general_operand" "g")))
6760    (set (match_operand:DI 0 "register_operand" "=r")
6761         (zero_extend:DI
6762           (minus:SI (match_dup 1)
6763                     (match_dup 2))))]
6764   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)
6765    && ix86_binary_operator_ok (MINUS, SImode, operands)"
6766   "sub{l}\t{%2, %1|%1, %2}"
6767   [(set_attr "type" "alu")
6768    (set_attr "mode" "SI")])
6769 \f
6770 ;; Add with carry and subtract with borrow
6771
6772 (define_expand "<plusminus_insn><mode>3_carry"
6773   [(parallel
6774     [(set (match_operand:SWI 0 "nonimmediate_operand" "")
6775           (plusminus:SWI
6776             (match_operand:SWI 1 "nonimmediate_operand" "")
6777             (plus:SWI (match_operator:SWI 4 "ix86_carry_flag_operator"
6778                        [(match_operand 3 "flags_reg_operand" "")
6779                         (const_int 0)])
6780                       (match_operand:SWI 2 "<general_operand>" ""))))
6781      (clobber (reg:CC FLAGS_REG))])]
6782   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)")
6783
6784 (define_insn "*<plusminus_insn><mode>3_carry"
6785   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6786         (plusminus:SWI
6787           (match_operand:SWI 1 "nonimmediate_operand" "<comm>0,0")
6788           (plus:SWI
6789             (match_operator 3 "ix86_carry_flag_operator"
6790              [(reg FLAGS_REG) (const_int 0)])
6791             (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m"))))
6792    (clobber (reg:CC FLAGS_REG))]
6793   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
6794   "<plusminus_carry_mnemonic>{<imodesuffix>}\t{%2, %0|%0, %2}"
6795   [(set_attr "type" "alu")
6796    (set_attr "use_carry" "1")
6797    (set_attr "pent_pair" "pu")
6798    (set_attr "mode" "<MODE>")])
6799
6800 (define_insn "*addsi3_carry_zext"
6801   [(set (match_operand:DI 0 "register_operand" "=r")
6802         (zero_extend:DI
6803           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
6804                    (plus:SI (match_operator 3 "ix86_carry_flag_operator"
6805                              [(reg FLAGS_REG) (const_int 0)])
6806                             (match_operand:SI 2 "general_operand" "g")))))
6807    (clobber (reg:CC FLAGS_REG))]
6808   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, SImode, operands)"
6809   "adc{l}\t{%2, %k0|%k0, %2}"
6810   [(set_attr "type" "alu")
6811    (set_attr "use_carry" "1")
6812    (set_attr "pent_pair" "pu")
6813    (set_attr "mode" "SI")])
6814
6815 (define_insn "*subsi3_carry_zext"
6816   [(set (match_operand:DI 0 "register_operand" "=r")
6817         (zero_extend:DI
6818           (minus:SI (match_operand:SI 1 "register_operand" "0")
6819                     (plus:SI (match_operator 3 "ix86_carry_flag_operator"
6820                               [(reg FLAGS_REG) (const_int 0)])
6821                              (match_operand:SI 2 "general_operand" "g")))))
6822    (clobber (reg:CC FLAGS_REG))]
6823   "TARGET_64BIT && ix86_binary_operator_ok (MINUS, SImode, operands)"
6824   "sbb{l}\t{%2, %k0|%k0, %2}"
6825   [(set_attr "type" "alu")
6826    (set_attr "pent_pair" "pu")
6827    (set_attr "mode" "SI")])
6828 \f
6829 ;; Overflow setting add and subtract instructions
6830
6831 (define_insn "*add<mode>3_cconly_overflow"
6832   [(set (reg:CCC FLAGS_REG)
6833         (compare:CCC
6834           (plus:SWI
6835             (match_operand:SWI 1 "nonimmediate_operand" "%0")
6836             (match_operand:SWI 2 "<general_operand>" "<g>"))
6837           (match_dup 1)))
6838    (clobber (match_scratch:SWI 0 "=<r>"))]
6839   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
6840   "add{<imodesuffix>}\t{%2, %0|%0, %2}"
6841   [(set_attr "type" "alu")
6842    (set_attr "mode" "<MODE>")])
6843
6844 (define_insn "*sub<mode>3_cconly_overflow"
6845   [(set (reg:CCC FLAGS_REG)
6846         (compare:CCC
6847           (minus:SWI
6848             (match_operand:SWI 0 "nonimmediate_operand" "<r>m,<r>")
6849             (match_operand:SWI 1 "<general_operand>" "<r><i>,<r>m"))
6850           (match_dup 0)))]
6851   ""
6852   "cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
6853   [(set_attr "type" "icmp")
6854    (set_attr "mode" "<MODE>")])
6855
6856 (define_insn "*<plusminus_insn><mode>3_cc_overflow"
6857   [(set (reg:CCC FLAGS_REG)
6858         (compare:CCC
6859             (plusminus:SWI
6860                 (match_operand:SWI 1 "nonimmediate_operand" "<comm>0,0")
6861                 (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m"))
6862             (match_dup 1)))
6863    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6864         (plusminus:SWI (match_dup 1) (match_dup 2)))]
6865   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
6866   "<plusminus_mnemonic>{<imodesuffix>}\t{%2, %0|%0, %2}"
6867   [(set_attr "type" "alu")
6868    (set_attr "mode" "<MODE>")])
6869
6870 (define_insn "*<plusminus_insn>si3_zext_cc_overflow"
6871   [(set (reg:CCC FLAGS_REG)
6872         (compare:CCC
6873           (plusminus:SI
6874             (match_operand:SI 1 "nonimmediate_operand" "<comm>0")
6875             (match_operand:SI 2 "general_operand" "g"))
6876           (match_dup 1)))
6877    (set (match_operand:DI 0 "register_operand" "=r")
6878         (zero_extend:DI (plusminus:SI (match_dup 1) (match_dup 2))))]
6879   "TARGET_64BIT && ix86_binary_operator_ok (<CODE>, SImode, operands)"
6880   "<plusminus_mnemonic>{l}\t{%2, %k0|%k0, %2}"
6881   [(set_attr "type" "alu")
6882    (set_attr "mode" "SI")])
6883
6884 ;; The patterns that match these are at the end of this file.
6885
6886 (define_expand "<plusminus_insn>xf3"
6887   [(set (match_operand:XF 0 "register_operand" "")
6888         (plusminus:XF
6889           (match_operand:XF 1 "register_operand" "")
6890           (match_operand:XF 2 "register_operand" "")))]
6891   "TARGET_80387")
6892
6893 (define_expand "<plusminus_insn><mode>3"
6894   [(set (match_operand:MODEF 0 "register_operand" "")
6895         (plusminus:MODEF
6896           (match_operand:MODEF 1 "register_operand" "")
6897           (match_operand:MODEF 2 "nonimmediate_operand" "")))]
6898   "(TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode))
6899     || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)")
6900 \f
6901 ;; Multiply instructions
6902
6903 (define_expand "mul<mode>3"
6904   [(parallel [(set (match_operand:SWIM248 0 "register_operand" "")
6905                    (mult:SWIM248
6906                      (match_operand:SWIM248 1 "register_operand" "")
6907                      (match_operand:SWIM248 2 "<general_operand>" "")))
6908               (clobber (reg:CC FLAGS_REG))])])
6909
6910 (define_expand "mulqi3"
6911   [(parallel [(set (match_operand:QI 0 "register_operand" "")
6912                    (mult:QI
6913                      (match_operand:QI 1 "register_operand" "")
6914                      (match_operand:QI 2 "nonimmediate_operand" "")))
6915               (clobber (reg:CC FLAGS_REG))])]
6916   "TARGET_QIMODE_MATH")
6917
6918 ;; On AMDFAM10
6919 ;; IMUL reg32/64, reg32/64, imm8        Direct
6920 ;; IMUL reg32/64, mem32/64, imm8        VectorPath
6921 ;; IMUL reg32/64, reg32/64, imm32       Direct
6922 ;; IMUL reg32/64, mem32/64, imm32       VectorPath
6923 ;; IMUL reg32/64, reg32/64              Direct
6924 ;; IMUL reg32/64, mem32/64              Direct
6925 ;;
6926 ;; On BDVER1, all above IMULs use DirectPath
6927
6928 (define_insn "*mul<mode>3_1"
6929   [(set (match_operand:SWI48 0 "register_operand" "=r,r,r")
6930         (mult:SWI48
6931           (match_operand:SWI48 1 "nonimmediate_operand" "%rm,rm,0")
6932           (match_operand:SWI48 2 "<general_operand>" "K,<i>,mr")))
6933    (clobber (reg:CC FLAGS_REG))]
6934   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
6935   "@
6936    imul{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}
6937    imul{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}
6938    imul{<imodesuffix>}\t{%2, %0|%0, %2}"
6939   [(set_attr "type" "imul")
6940    (set_attr "prefix_0f" "0,0,1")
6941    (set (attr "athlon_decode")
6942         (cond [(eq_attr "cpu" "athlon")
6943                   (const_string "vector")
6944                (eq_attr "alternative" "1")
6945                   (const_string "vector")
6946                (and (eq_attr "alternative" "2")
6947                     (match_operand 1 "memory_operand" ""))
6948                   (const_string "vector")]
6949               (const_string "direct")))
6950    (set (attr "amdfam10_decode")
6951         (cond [(and (eq_attr "alternative" "0,1")
6952                     (match_operand 1 "memory_operand" ""))
6953                   (const_string "vector")]
6954               (const_string "direct")))
6955    (set_attr "bdver1_decode" "direct")
6956    (set_attr "mode" "<MODE>")])
6957
6958 (define_insn "*mulsi3_1_zext"
6959   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
6960         (zero_extend:DI
6961           (mult:SI (match_operand:SI 1 "nonimmediate_operand" "%rm,rm,0")
6962                    (match_operand:SI 2 "general_operand" "K,i,mr"))))
6963    (clobber (reg:CC FLAGS_REG))]
6964   "TARGET_64BIT
6965    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6966   "@
6967    imul{l}\t{%2, %1, %k0|%k0, %1, %2}
6968    imul{l}\t{%2, %1, %k0|%k0, %1, %2}
6969    imul{l}\t{%2, %k0|%k0, %2}"
6970   [(set_attr "type" "imul")
6971    (set_attr "prefix_0f" "0,0,1")
6972    (set (attr "athlon_decode")
6973         (cond [(eq_attr "cpu" "athlon")
6974                   (const_string "vector")
6975                (eq_attr "alternative" "1")
6976                   (const_string "vector")
6977                (and (eq_attr "alternative" "2")
6978                     (match_operand 1 "memory_operand" ""))
6979                   (const_string "vector")]
6980               (const_string "direct")))
6981    (set (attr "amdfam10_decode")
6982         (cond [(and (eq_attr "alternative" "0,1")
6983                     (match_operand 1 "memory_operand" ""))
6984                   (const_string "vector")]
6985               (const_string "direct")))
6986    (set_attr "bdver1_decode" "direct")
6987    (set_attr "mode" "SI")])
6988
6989 ;; On AMDFAM10
6990 ;; IMUL reg16, reg16, imm8      VectorPath
6991 ;; IMUL reg16, mem16, imm8      VectorPath
6992 ;; IMUL reg16, reg16, imm16     VectorPath
6993 ;; IMUL reg16, mem16, imm16     VectorPath
6994 ;; IMUL reg16, reg16            Direct
6995 ;; IMUL reg16, mem16            Direct
6996 ;;
6997 ;; On BDVER1, all HI MULs use DoublePath
6998
6999 (define_insn "*mulhi3_1"
7000   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
7001         (mult:HI (match_operand:HI 1 "nonimmediate_operand" "%rm,rm,0")
7002                  (match_operand:HI 2 "general_operand" "K,n,mr")))
7003    (clobber (reg:CC FLAGS_REG))]
7004   "TARGET_HIMODE_MATH
7005    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
7006   "@
7007    imul{w}\t{%2, %1, %0|%0, %1, %2}
7008    imul{w}\t{%2, %1, %0|%0, %1, %2}
7009    imul{w}\t{%2, %0|%0, %2}"
7010   [(set_attr "type" "imul")
7011    (set_attr "prefix_0f" "0,0,1")
7012    (set (attr "athlon_decode")
7013         (cond [(eq_attr "cpu" "athlon")
7014                   (const_string "vector")
7015                (eq_attr "alternative" "1,2")
7016                   (const_string "vector")]
7017               (const_string "direct")))
7018    (set (attr "amdfam10_decode")
7019         (cond [(eq_attr "alternative" "0,1")
7020                   (const_string "vector")]
7021               (const_string "direct")))
7022    (set_attr "bdver1_decode" "double")
7023    (set_attr "mode" "HI")])
7024
7025 ;;On AMDFAM10 and BDVER1
7026 ;; MUL reg8     Direct
7027 ;; MUL mem8     Direct
7028
7029 (define_insn "*mulqi3_1"
7030   [(set (match_operand:QI 0 "register_operand" "=a")
7031         (mult:QI (match_operand:QI 1 "nonimmediate_operand" "%0")
7032                  (match_operand:QI 2 "nonimmediate_operand" "qm")))
7033    (clobber (reg:CC FLAGS_REG))]
7034   "TARGET_QIMODE_MATH
7035    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
7036   "mul{b}\t%2"
7037   [(set_attr "type" "imul")
7038    (set_attr "length_immediate" "0")
7039    (set (attr "athlon_decode")
7040      (if_then_else (eq_attr "cpu" "athlon")
7041         (const_string "vector")
7042         (const_string "direct")))
7043    (set_attr "amdfam10_decode" "direct")
7044    (set_attr "bdver1_decode" "direct")
7045    (set_attr "mode" "QI")])
7046
7047 (define_expand "<u>mul<mode><dwi>3"
7048   [(parallel [(set (match_operand:<DWI> 0 "register_operand" "")
7049                    (mult:<DWI>
7050                      (any_extend:<DWI>
7051                        (match_operand:DWIH 1 "nonimmediate_operand" ""))
7052                      (any_extend:<DWI>
7053                        (match_operand:DWIH 2 "register_operand" ""))))
7054               (clobber (reg:CC FLAGS_REG))])])
7055
7056 (define_expand "<u>mulqihi3"
7057   [(parallel [(set (match_operand:HI 0 "register_operand" "")
7058                    (mult:HI
7059                      (any_extend:HI
7060                        (match_operand:QI 1 "nonimmediate_operand" ""))
7061                      (any_extend:HI
7062                        (match_operand:QI 2 "register_operand" ""))))
7063               (clobber (reg:CC FLAGS_REG))])]
7064   "TARGET_QIMODE_MATH")
7065
7066 (define_insn "*<u>mul<mode><dwi>3_1"
7067   [(set (match_operand:<DWI> 0 "register_operand" "=A")
7068         (mult:<DWI>
7069           (any_extend:<DWI>
7070             (match_operand:DWIH 1 "nonimmediate_operand" "%0"))
7071           (any_extend:<DWI>
7072             (match_operand:DWIH 2 "nonimmediate_operand" "rm"))))
7073    (clobber (reg:CC FLAGS_REG))]
7074   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
7075   "<sgnprefix>mul{<imodesuffix>}\t%2"
7076   [(set_attr "type" "imul")
7077    (set_attr "length_immediate" "0")
7078    (set (attr "athlon_decode")
7079      (if_then_else (eq_attr "cpu" "athlon")
7080         (const_string "vector")
7081         (const_string "double")))
7082    (set_attr "amdfam10_decode" "double")
7083    (set_attr "bdver1_decode" "direct")
7084    (set_attr "mode" "<MODE>")])
7085
7086 (define_insn "*<u>mulqihi3_1"
7087   [(set (match_operand:HI 0 "register_operand" "=a")
7088         (mult:HI
7089           (any_extend:HI
7090             (match_operand:QI 1 "nonimmediate_operand" "%0"))
7091           (any_extend:HI
7092             (match_operand:QI 2 "nonimmediate_operand" "qm"))))
7093    (clobber (reg:CC FLAGS_REG))]
7094   "TARGET_QIMODE_MATH
7095    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
7096   "<sgnprefix>mul{b}\t%2"
7097   [(set_attr "type" "imul")
7098    (set_attr "length_immediate" "0")
7099    (set (attr "athlon_decode")
7100      (if_then_else (eq_attr "cpu" "athlon")
7101         (const_string "vector")
7102         (const_string "direct")))
7103    (set_attr "amdfam10_decode" "direct")
7104    (set_attr "bdver1_decode" "direct")
7105    (set_attr "mode" "QI")])
7106
7107 (define_expand "<s>mul<mode>3_highpart"
7108   [(parallel [(set (match_operand:SWI48 0 "register_operand" "")
7109                    (truncate:SWI48
7110                      (lshiftrt:<DWI>
7111                        (mult:<DWI>
7112                          (any_extend:<DWI>
7113                            (match_operand:SWI48 1 "nonimmediate_operand" ""))
7114                          (any_extend:<DWI>
7115                            (match_operand:SWI48 2 "register_operand" "")))
7116                        (match_dup 4))))
7117               (clobber (match_scratch:SWI48 3 ""))
7118               (clobber (reg:CC FLAGS_REG))])]
7119   ""
7120   "operands[4] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));")
7121
7122 (define_insn "*<s>muldi3_highpart_1"
7123   [(set (match_operand:DI 0 "register_operand" "=d")
7124         (truncate:DI
7125           (lshiftrt:TI
7126             (mult:TI
7127               (any_extend:TI
7128                 (match_operand:DI 1 "nonimmediate_operand" "%a"))
7129               (any_extend:TI
7130                 (match_operand:DI 2 "nonimmediate_operand" "rm")))
7131             (const_int 64))))
7132    (clobber (match_scratch:DI 3 "=1"))
7133    (clobber (reg:CC FLAGS_REG))]
7134   "TARGET_64BIT
7135    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
7136   "<sgnprefix>mul{q}\t%2"
7137   [(set_attr "type" "imul")
7138    (set_attr "length_immediate" "0")
7139    (set (attr "athlon_decode")
7140      (if_then_else (eq_attr "cpu" "athlon")
7141         (const_string "vector")
7142         (const_string "double")))
7143    (set_attr "amdfam10_decode" "double")
7144    (set_attr "bdver1_decode" "direct")
7145    (set_attr "mode" "DI")])
7146
7147 (define_insn "*<s>mulsi3_highpart_1"
7148   [(set (match_operand:SI 0 "register_operand" "=d")
7149         (truncate:SI
7150           (lshiftrt:DI
7151             (mult:DI
7152               (any_extend:DI
7153                 (match_operand:SI 1 "nonimmediate_operand" "%a"))
7154               (any_extend:DI
7155                 (match_operand:SI 2 "nonimmediate_operand" "rm")))
7156             (const_int 32))))
7157    (clobber (match_scratch:SI 3 "=1"))
7158    (clobber (reg:CC FLAGS_REG))]
7159   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
7160   "<sgnprefix>mul{l}\t%2"
7161   [(set_attr "type" "imul")
7162    (set_attr "length_immediate" "0")
7163    (set (attr "athlon_decode")
7164      (if_then_else (eq_attr "cpu" "athlon")
7165         (const_string "vector")
7166         (const_string "double")))
7167    (set_attr "amdfam10_decode" "double")
7168    (set_attr "bdver1_decode" "direct")
7169    (set_attr "mode" "SI")])
7170
7171 (define_insn "*<s>mulsi3_highpart_zext"
7172   [(set (match_operand:DI 0 "register_operand" "=d")
7173         (zero_extend:DI (truncate:SI
7174           (lshiftrt:DI
7175             (mult:DI (any_extend:DI
7176                        (match_operand:SI 1 "nonimmediate_operand" "%a"))
7177                      (any_extend:DI
7178                        (match_operand:SI 2 "nonimmediate_operand" "rm")))
7179             (const_int 32)))))
7180    (clobber (match_scratch:SI 3 "=1"))
7181    (clobber (reg:CC FLAGS_REG))]
7182   "TARGET_64BIT
7183    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
7184   "<sgnprefix>mul{l}\t%2"
7185   [(set_attr "type" "imul")
7186    (set_attr "length_immediate" "0")
7187    (set (attr "athlon_decode")
7188      (if_then_else (eq_attr "cpu" "athlon")
7189         (const_string "vector")
7190         (const_string "double")))
7191    (set_attr "amdfam10_decode" "double")
7192    (set_attr "bdver1_decode" "direct")
7193    (set_attr "mode" "SI")])
7194
7195 ;; The patterns that match these are at the end of this file.
7196
7197 (define_expand "mulxf3"
7198   [(set (match_operand:XF 0 "register_operand" "")
7199         (mult:XF (match_operand:XF 1 "register_operand" "")
7200                  (match_operand:XF 2 "register_operand" "")))]
7201   "TARGET_80387")
7202
7203 (define_expand "mul<mode>3"
7204   [(set (match_operand:MODEF 0 "register_operand" "")
7205         (mult:MODEF (match_operand:MODEF 1 "register_operand" "")
7206                     (match_operand:MODEF 2 "nonimmediate_operand" "")))]
7207   "(TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode))
7208     || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)")
7209 \f
7210 ;; Divide instructions
7211
7212 ;; The patterns that match these are at the end of this file.
7213
7214 (define_expand "divxf3"
7215   [(set (match_operand:XF 0 "register_operand" "")
7216         (div:XF (match_operand:XF 1 "register_operand" "")
7217                 (match_operand:XF 2 "register_operand" "")))]
7218   "TARGET_80387")
7219
7220 (define_expand "divdf3"
7221   [(set (match_operand:DF 0 "register_operand" "")
7222         (div:DF (match_operand:DF 1 "register_operand" "")
7223                 (match_operand:DF 2 "nonimmediate_operand" "")))]
7224    "(TARGET_80387 && X87_ENABLE_ARITH (DFmode))
7225     || (TARGET_SSE2 && TARGET_SSE_MATH)")
7226
7227 (define_expand "divsf3"
7228   [(set (match_operand:SF 0 "register_operand" "")
7229         (div:SF (match_operand:SF 1 "register_operand" "")
7230                 (match_operand:SF 2 "nonimmediate_operand" "")))]
7231   "(TARGET_80387 && X87_ENABLE_ARITH (SFmode))
7232     || TARGET_SSE_MATH"
7233 {
7234   if (TARGET_SSE_MATH && TARGET_RECIP && optimize_insn_for_speed_p ()
7235       && flag_finite_math_only && !flag_trapping_math
7236       && flag_unsafe_math_optimizations)
7237     {
7238       ix86_emit_swdivsf (operands[0], operands[1],
7239                          operands[2], SFmode);
7240       DONE;
7241     }
7242 })
7243 \f
7244 ;; Divmod instructions.
7245
7246 (define_expand "divmod<mode>4"
7247   [(parallel [(set (match_operand:SWIM248 0 "register_operand" "")
7248                    (div:SWIM248
7249                      (match_operand:SWIM248 1 "register_operand" "")
7250                      (match_operand:SWIM248 2 "nonimmediate_operand" "")))
7251               (set (match_operand:SWIM248 3 "register_operand" "")
7252                    (mod:SWIM248 (match_dup 1) (match_dup 2)))
7253               (clobber (reg:CC FLAGS_REG))])])
7254
7255 ;; Split with 8bit unsigned divide:
7256 ;;      if (dividend an divisor are in [0-255])
7257 ;;         use 8bit unsigned integer divide
7258 ;;       else
7259 ;;         use original integer divide
7260 (define_split
7261   [(set (match_operand:SWI48 0 "register_operand" "")
7262         (div:SWI48 (match_operand:SWI48 2 "register_operand" "")
7263                     (match_operand:SWI48 3 "nonimmediate_operand" "")))
7264    (set (match_operand:SWI48 1 "register_operand" "")
7265         (mod:SWI48 (match_dup 2) (match_dup 3)))
7266    (clobber (reg:CC FLAGS_REG))]
7267   "TARGET_USE_8BIT_IDIV
7268    && TARGET_QIMODE_MATH
7269    && can_create_pseudo_p ()
7270    && !optimize_insn_for_size_p ()"
7271   [(const_int 0)]
7272   "ix86_split_idivmod (<MODE>mode, operands, true); DONE;")
7273
7274 (define_insn_and_split "divmod<mode>4_1"
7275   [(set (match_operand:SWI48 0 "register_operand" "=a")
7276         (div:SWI48 (match_operand:SWI48 2 "register_operand" "0")
7277                    (match_operand:SWI48 3 "nonimmediate_operand" "rm")))
7278    (set (match_operand:SWI48 1 "register_operand" "=&d")
7279         (mod:SWI48 (match_dup 2) (match_dup 3)))
7280    (unspec [(const_int 0)] UNSPEC_DIV_ALREADY_SPLIT)
7281    (clobber (reg:CC FLAGS_REG))]
7282   ""
7283   "#"
7284   "reload_completed"
7285   [(parallel [(set (match_dup 1)
7286                    (ashiftrt:SWI48 (match_dup 4) (match_dup 5)))
7287               (clobber (reg:CC FLAGS_REG))])
7288    (parallel [(set (match_dup 0)
7289                    (div:SWI48 (match_dup 2) (match_dup 3)))
7290               (set (match_dup 1)
7291                    (mod:SWI48 (match_dup 2) (match_dup 3)))
7292               (use (match_dup 1))
7293               (clobber (reg:CC FLAGS_REG))])]
7294 {
7295   operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1);
7296
7297   if (optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
7298     operands[4] = operands[2];
7299   else
7300     {
7301       /* Avoid use of cltd in favor of a mov+shift.  */
7302       emit_move_insn (operands[1], operands[2]);
7303       operands[4] = operands[1];
7304     }
7305 }
7306   [(set_attr "type" "multi")
7307    (set_attr "mode" "<MODE>")])
7308
7309 (define_insn_and_split "*divmod<mode>4"
7310   [(set (match_operand:SWIM248 0 "register_operand" "=a")
7311         (div:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
7312                     (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
7313    (set (match_operand:SWIM248 1 "register_operand" "=&d")
7314         (mod:SWIM248 (match_dup 2) (match_dup 3)))
7315    (clobber (reg:CC FLAGS_REG))]
7316   ""
7317   "#"
7318   "reload_completed"
7319   [(parallel [(set (match_dup 1)
7320                    (ashiftrt:SWIM248 (match_dup 4) (match_dup 5)))
7321               (clobber (reg:CC FLAGS_REG))])
7322    (parallel [(set (match_dup 0)
7323                    (div:SWIM248 (match_dup 2) (match_dup 3)))
7324               (set (match_dup 1)
7325                    (mod:SWIM248 (match_dup 2) (match_dup 3)))
7326               (use (match_dup 1))
7327               (clobber (reg:CC FLAGS_REG))])]
7328 {
7329   operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1);
7330
7331   if (<MODE>mode != HImode
7332       && (optimize_function_for_size_p (cfun) || TARGET_USE_CLTD))
7333     operands[4] = operands[2];
7334   else
7335     {
7336       /* Avoid use of cltd in favor of a mov+shift.  */
7337       emit_move_insn (operands[1], operands[2]);
7338       operands[4] = operands[1];
7339     }
7340 }
7341   [(set_attr "type" "multi")
7342    (set_attr "mode" "<MODE>")])
7343
7344 (define_insn "*divmod<mode>4_noext"
7345   [(set (match_operand:SWIM248 0 "register_operand" "=a")
7346         (div:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
7347                     (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
7348    (set (match_operand:SWIM248 1 "register_operand" "=d")
7349         (mod:SWIM248 (match_dup 2) (match_dup 3)))
7350    (use (match_operand:SWIM248 4 "register_operand" "1"))
7351    (clobber (reg:CC FLAGS_REG))]
7352   ""
7353   "idiv{<imodesuffix>}\t%3"
7354   [(set_attr "type" "idiv")
7355    (set_attr "mode" "<MODE>")])
7356
7357 (define_expand "divmodqi4"
7358   [(parallel [(set (match_operand:QI 0 "register_operand" "")
7359                    (div:QI
7360                      (match_operand:QI 1 "register_operand" "")
7361                      (match_operand:QI 2 "nonimmediate_operand" "")))
7362               (set (match_operand:QI 3 "register_operand" "")
7363                    (mod:QI (match_dup 1) (match_dup 2)))
7364               (clobber (reg:CC FLAGS_REG))])]
7365   "TARGET_QIMODE_MATH"
7366 {
7367   rtx div, mod, insn;
7368   rtx tmp0, tmp1;
7369   
7370   tmp0 = gen_reg_rtx (HImode);
7371   tmp1 = gen_reg_rtx (HImode);
7372
7373   /* Extend operands[1] to HImode.  Generate 8bit divide.  Result is
7374      in AX.  */
7375   emit_insn (gen_extendqihi2 (tmp1, operands[1]));
7376   emit_insn (gen_divmodhiqi3 (tmp0, tmp1, operands[2]));
7377
7378   /* Extract remainder from AH.  */
7379   tmp1 = gen_rtx_SIGN_EXTRACT (QImode, tmp0, GEN_INT (8), GEN_INT (8));
7380   insn = emit_move_insn (operands[3], tmp1);
7381
7382   mod = gen_rtx_MOD (QImode, operands[1], operands[2]);
7383   set_unique_reg_note (insn, REG_EQUAL, mod);
7384
7385   /* Extract quotient from AL.  */
7386   insn = emit_move_insn (operands[0], gen_lowpart (QImode, tmp0));
7387
7388   div = gen_rtx_DIV (QImode, operands[1], operands[2]);
7389   set_unique_reg_note (insn, REG_EQUAL, div);
7390
7391   DONE;
7392 })
7393
7394 ;; Divide AX by r/m8, with result stored in
7395 ;; AL <- Quotient
7396 ;; AH <- Remainder
7397 ;; Change div/mod to HImode and extend the second argument to HImode
7398 ;; so that mode of div/mod matches with mode of arguments.  Otherwise
7399 ;; combine may fail.
7400 (define_insn "divmodhiqi3"
7401   [(set (match_operand:HI 0 "register_operand" "=a")
7402         (ior:HI
7403           (ashift:HI
7404             (zero_extend:HI
7405               (truncate:QI
7406                 (mod:HI (match_operand:HI 1 "register_operand" "0")
7407                         (sign_extend:HI
7408                           (match_operand:QI 2 "nonimmediate_operand" "qm")))))
7409             (const_int 8))
7410           (zero_extend:HI
7411             (truncate:QI
7412               (div:HI (match_dup 1) (sign_extend:HI (match_dup 2)))))))
7413    (clobber (reg:CC FLAGS_REG))]
7414   "TARGET_QIMODE_MATH"
7415   "idiv{b}\t%2"
7416   [(set_attr "type" "idiv")
7417    (set_attr "mode" "QI")])
7418
7419 (define_expand "udivmod<mode>4"
7420   [(parallel [(set (match_operand:SWIM248 0 "register_operand" "")
7421                    (udiv:SWIM248
7422                      (match_operand:SWIM248 1 "register_operand" "")
7423                      (match_operand:SWIM248 2 "nonimmediate_operand" "")))
7424               (set (match_operand:SWIM248 3 "register_operand" "")
7425                    (umod:SWIM248 (match_dup 1) (match_dup 2)))
7426               (clobber (reg:CC FLAGS_REG))])])
7427
7428 ;; Split with 8bit unsigned divide:
7429 ;;      if (dividend an divisor are in [0-255])
7430 ;;         use 8bit unsigned integer divide
7431 ;;       else
7432 ;;         use original integer divide
7433 (define_split
7434   [(set (match_operand:SWI48 0 "register_operand" "")
7435         (udiv:SWI48 (match_operand:SWI48 2 "register_operand" "")
7436                     (match_operand:SWI48 3 "nonimmediate_operand" "")))
7437    (set (match_operand:SWI48 1 "register_operand" "")
7438         (umod:SWI48 (match_dup 2) (match_dup 3)))
7439    (clobber (reg:CC FLAGS_REG))]
7440   "TARGET_USE_8BIT_IDIV
7441    && TARGET_QIMODE_MATH
7442    && can_create_pseudo_p ()
7443    && !optimize_insn_for_size_p ()"
7444   [(const_int 0)]
7445   "ix86_split_idivmod (<MODE>mode, operands, false); DONE;")
7446
7447 (define_insn_and_split "udivmod<mode>4_1"
7448   [(set (match_operand:SWI48 0 "register_operand" "=a")
7449         (udiv:SWI48 (match_operand:SWI48 2 "register_operand" "0")
7450                     (match_operand:SWI48 3 "nonimmediate_operand" "rm")))
7451    (set (match_operand:SWI48 1 "register_operand" "=&d")
7452         (umod:SWI48 (match_dup 2) (match_dup 3)))
7453    (unspec [(const_int 0)] UNSPEC_DIV_ALREADY_SPLIT)
7454    (clobber (reg:CC FLAGS_REG))]
7455   ""
7456   "#"
7457   "reload_completed"
7458   [(set (match_dup 1) (const_int 0))
7459    (parallel [(set (match_dup 0)
7460                    (udiv:SWI48 (match_dup 2) (match_dup 3)))
7461               (set (match_dup 1)
7462                    (umod:SWI48 (match_dup 2) (match_dup 3)))
7463               (use (match_dup 1))
7464               (clobber (reg:CC FLAGS_REG))])]
7465   ""
7466   [(set_attr "type" "multi")
7467    (set_attr "mode" "<MODE>")])
7468
7469 (define_insn_and_split "*udivmod<mode>4"
7470   [(set (match_operand:SWIM248 0 "register_operand" "=a")
7471         (udiv:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
7472                       (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
7473    (set (match_operand:SWIM248 1 "register_operand" "=&d")
7474         (umod:SWIM248 (match_dup 2) (match_dup 3)))
7475    (clobber (reg:CC FLAGS_REG))]
7476   ""
7477   "#"
7478   "reload_completed"
7479   [(set (match_dup 1) (const_int 0))
7480    (parallel [(set (match_dup 0)
7481                    (udiv:SWIM248 (match_dup 2) (match_dup 3)))
7482               (set (match_dup 1)
7483                    (umod:SWIM248 (match_dup 2) (match_dup 3)))
7484               (use (match_dup 1))
7485               (clobber (reg:CC FLAGS_REG))])]
7486   ""
7487   [(set_attr "type" "multi")
7488    (set_attr "mode" "<MODE>")])
7489
7490 (define_insn "*udivmod<mode>4_noext"
7491   [(set (match_operand:SWIM248 0 "register_operand" "=a")
7492         (udiv:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
7493                       (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
7494    (set (match_operand:SWIM248 1 "register_operand" "=d")
7495         (umod:SWIM248 (match_dup 2) (match_dup 3)))
7496    (use (match_operand:SWIM248 4 "register_operand" "1"))
7497    (clobber (reg:CC FLAGS_REG))]
7498   ""
7499   "div{<imodesuffix>}\t%3"
7500   [(set_attr "type" "idiv")
7501    (set_attr "mode" "<MODE>")])
7502
7503 (define_expand "udivmodqi4"
7504   [(parallel [(set (match_operand:QI 0 "register_operand" "")
7505                    (udiv:QI
7506                      (match_operand:QI 1 "register_operand" "")
7507                      (match_operand:QI 2 "nonimmediate_operand" "")))
7508               (set (match_operand:QI 3 "register_operand" "")
7509                    (umod:QI (match_dup 1) (match_dup 2)))
7510               (clobber (reg:CC FLAGS_REG))])]
7511   "TARGET_QIMODE_MATH"
7512 {
7513   rtx div, mod, insn;
7514   rtx tmp0, tmp1;
7515   
7516   tmp0 = gen_reg_rtx (HImode);
7517   tmp1 = gen_reg_rtx (HImode);
7518
7519   /* Extend operands[1] to HImode.  Generate 8bit divide.  Result is
7520      in AX.  */
7521   emit_insn (gen_zero_extendqihi2 (tmp1, operands[1]));
7522   emit_insn (gen_udivmodhiqi3 (tmp0, tmp1, operands[2]));
7523
7524   /* Extract remainder from AH.  */
7525   tmp1 = gen_rtx_ZERO_EXTRACT (SImode, tmp0, GEN_INT (8), GEN_INT (8));
7526   tmp1 = simplify_gen_subreg (QImode, tmp1, SImode, 0);
7527   insn = emit_move_insn (operands[3], tmp1);
7528
7529   mod = gen_rtx_UMOD (QImode, operands[1], operands[2]);
7530   set_unique_reg_note (insn, REG_EQUAL, mod);
7531
7532   /* Extract quotient from AL.  */
7533   insn = emit_move_insn (operands[0], gen_lowpart (QImode, tmp0));
7534
7535   div = gen_rtx_UDIV (QImode, operands[1], operands[2]);
7536   set_unique_reg_note (insn, REG_EQUAL, div);
7537
7538   DONE;
7539 })
7540
7541 (define_insn "udivmodhiqi3"
7542   [(set (match_operand:HI 0 "register_operand" "=a")
7543         (ior:HI
7544           (ashift:HI
7545             (zero_extend:HI
7546               (truncate:QI
7547                 (mod:HI (match_operand:HI 1 "register_operand" "0")
7548                         (zero_extend:HI
7549                           (match_operand:QI 2 "nonimmediate_operand" "qm")))))
7550             (const_int 8))
7551           (zero_extend:HI
7552             (truncate:QI
7553               (div:HI (match_dup 1) (zero_extend:HI (match_dup 2)))))))
7554    (clobber (reg:CC FLAGS_REG))]
7555   "TARGET_QIMODE_MATH"
7556   "div{b}\t%2"
7557   [(set_attr "type" "idiv")
7558    (set_attr "mode" "QI")])
7559
7560 ;; We cannot use div/idiv for double division, because it causes
7561 ;; "division by zero" on the overflow and that's not what we expect
7562 ;; from truncate.  Because true (non truncating) double division is
7563 ;; never generated, we can't create this insn anyway.
7564 ;
7565 ;(define_insn ""
7566 ;  [(set (match_operand:SI 0 "register_operand" "=a")
7567 ;       (truncate:SI
7568 ;         (udiv:DI (match_operand:DI 1 "register_operand" "A")
7569 ;                  (zero_extend:DI
7570 ;                    (match_operand:SI 2 "nonimmediate_operand" "rm")))))
7571 ;   (set (match_operand:SI 3 "register_operand" "=d")
7572 ;       (truncate:SI
7573 ;         (umod:DI (match_dup 1) (zero_extend:DI (match_dup 2)))))
7574 ;   (clobber (reg:CC FLAGS_REG))]
7575 ;  ""
7576 ;  "div{l}\t{%2, %0|%0, %2}"
7577 ;  [(set_attr "type" "idiv")])
7578 \f
7579 ;;- Logical AND instructions
7580
7581 ;; On Pentium, "test imm, reg" is pairable only with eax, ax, and al.
7582 ;; Note that this excludes ah.
7583
7584 (define_expand "testsi_ccno_1"
7585   [(set (reg:CCNO FLAGS_REG)
7586         (compare:CCNO
7587           (and:SI (match_operand:SI 0 "nonimmediate_operand" "")
7588                   (match_operand:SI 1 "nonmemory_operand" ""))
7589           (const_int 0)))])
7590
7591 (define_expand "testqi_ccz_1"
7592   [(set (reg:CCZ FLAGS_REG)
7593         (compare:CCZ (and:QI (match_operand:QI 0 "nonimmediate_operand" "")
7594                              (match_operand:QI 1 "nonmemory_operand" ""))
7595                  (const_int 0)))])
7596
7597 (define_expand "testdi_ccno_1"
7598   [(set (reg:CCNO FLAGS_REG)
7599         (compare:CCNO
7600           (and:DI (match_operand:DI 0 "nonimmediate_operand" "")
7601                   (match_operand:DI 1 "x86_64_szext_general_operand" ""))
7602           (const_int 0)))]
7603   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))")
7604
7605 (define_insn "*testdi_1"
7606   [(set (reg FLAGS_REG)
7607         (compare
7608          (and:DI
7609           (match_operand:DI 0 "nonimmediate_operand" "%!*a,r,!*a,r,rm")
7610           (match_operand:DI 1 "x86_64_szext_general_operand" "Z,Z,e,e,re"))
7611          (const_int 0)))]
7612   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
7613    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7614   "@
7615    test{l}\t{%k1, %k0|%k0, %k1}
7616    test{l}\t{%k1, %k0|%k0, %k1}
7617    test{q}\t{%1, %0|%0, %1}
7618    test{q}\t{%1, %0|%0, %1}
7619    test{q}\t{%1, %0|%0, %1}"
7620   [(set_attr "type" "test")
7621    (set_attr "modrm" "0,1,0,1,1")
7622    (set_attr "mode" "SI,SI,DI,DI,DI")])
7623
7624 (define_insn "*testqi_1_maybe_si"
7625   [(set (reg FLAGS_REG)
7626         (compare
7627           (and:QI
7628             (match_operand:QI 0 "nonimmediate_operand" "%!*a,q,qm,r")
7629             (match_operand:QI 1 "general_operand" "n,n,qn,n"))
7630           (const_int 0)))]
7631    "!(MEM_P (operands[0]) && MEM_P (operands[1]))
7632     && ix86_match_ccmode (insn,
7633                          CONST_INT_P (operands[1])
7634                          && INTVAL (operands[1]) >= 0 ? CCNOmode : CCZmode)"
7635 {
7636   if (which_alternative == 3)
7637     {
7638       if (CONST_INT_P (operands[1]) && INTVAL (operands[1]) < 0)
7639         operands[1] = GEN_INT (INTVAL (operands[1]) & 0xff);
7640       return "test{l}\t{%1, %k0|%k0, %1}";
7641     }
7642   return "test{b}\t{%1, %0|%0, %1}";
7643 }
7644   [(set_attr "type" "test")
7645    (set_attr "modrm" "0,1,1,1")
7646    (set_attr "mode" "QI,QI,QI,SI")
7647    (set_attr "pent_pair" "uv,np,uv,np")])
7648
7649 (define_insn "*test<mode>_1"
7650   [(set (reg FLAGS_REG)
7651         (compare
7652          (and:SWI124
7653           (match_operand:SWI124 0 "nonimmediate_operand" "%!*a,<r>,<r>m")
7654           (match_operand:SWI124 1 "general_operand" "<i>,<i>,<r><i>"))
7655          (const_int 0)))]
7656   "ix86_match_ccmode (insn, CCNOmode)
7657    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7658   "test{<imodesuffix>}\t{%1, %0|%0, %1}"
7659   [(set_attr "type" "test")
7660    (set_attr "modrm" "0,1,1")
7661    (set_attr "mode" "<MODE>")
7662    (set_attr "pent_pair" "uv,np,uv")])
7663
7664 (define_expand "testqi_ext_ccno_0"
7665   [(set (reg:CCNO FLAGS_REG)
7666         (compare:CCNO
7667           (and:SI
7668             (zero_extract:SI
7669               (match_operand 0 "ext_register_operand" "")
7670               (const_int 8)
7671               (const_int 8))
7672             (match_operand 1 "const_int_operand" ""))
7673           (const_int 0)))])
7674
7675 (define_insn "*testqi_ext_0"
7676   [(set (reg FLAGS_REG)
7677         (compare
7678           (and:SI
7679             (zero_extract:SI
7680               (match_operand 0 "ext_register_operand" "Q")
7681               (const_int 8)
7682               (const_int 8))
7683             (match_operand 1 "const_int_operand" "n"))
7684           (const_int 0)))]
7685   "ix86_match_ccmode (insn, CCNOmode)"
7686   "test{b}\t{%1, %h0|%h0, %1}"
7687   [(set_attr "type" "test")
7688    (set_attr "mode" "QI")
7689    (set_attr "length_immediate" "1")
7690    (set_attr "modrm" "1")
7691    (set_attr "pent_pair" "np")])
7692
7693 (define_insn "*testqi_ext_1_rex64"
7694   [(set (reg FLAGS_REG)
7695         (compare
7696           (and:SI
7697             (zero_extract:SI
7698               (match_operand 0 "ext_register_operand" "Q")
7699               (const_int 8)
7700               (const_int 8))
7701             (zero_extend:SI
7702               (match_operand:QI 1 "register_operand" "Q")))
7703           (const_int 0)))]
7704   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
7705   "test{b}\t{%1, %h0|%h0, %1}"
7706   [(set_attr "type" "test")
7707    (set_attr "mode" "QI")])
7708
7709 (define_insn "*testqi_ext_1"
7710   [(set (reg FLAGS_REG)
7711         (compare
7712           (and:SI
7713             (zero_extract:SI
7714               (match_operand 0 "ext_register_operand" "Q")
7715               (const_int 8)
7716               (const_int 8))
7717             (zero_extend:SI
7718               (match_operand:QI 1 "general_operand" "Qm")))
7719           (const_int 0)))]
7720   "!TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
7721   "test{b}\t{%1, %h0|%h0, %1}"
7722   [(set_attr "type" "test")
7723    (set_attr "mode" "QI")])
7724
7725 (define_insn "*testqi_ext_2"
7726   [(set (reg FLAGS_REG)
7727         (compare
7728           (and:SI
7729             (zero_extract:SI
7730               (match_operand 0 "ext_register_operand" "Q")
7731               (const_int 8)
7732               (const_int 8))
7733             (zero_extract:SI
7734               (match_operand 1 "ext_register_operand" "Q")
7735               (const_int 8)
7736               (const_int 8)))
7737           (const_int 0)))]
7738   "ix86_match_ccmode (insn, CCNOmode)"
7739   "test{b}\t{%h1, %h0|%h0, %h1}"
7740   [(set_attr "type" "test")
7741    (set_attr "mode" "QI")])
7742
7743 (define_insn "*testqi_ext_3_rex64"
7744   [(set (reg FLAGS_REG)
7745         (compare (zero_extract:DI
7746                    (match_operand 0 "nonimmediate_operand" "rm")
7747                    (match_operand:DI 1 "const_int_operand" "")
7748                    (match_operand:DI 2 "const_int_operand" ""))
7749                  (const_int 0)))]
7750   "TARGET_64BIT
7751    && ix86_match_ccmode (insn, CCNOmode)
7752    && INTVAL (operands[1]) > 0
7753    && INTVAL (operands[2]) >= 0
7754    /* Ensure that resulting mask is zero or sign extended operand.  */
7755    && (INTVAL (operands[1]) + INTVAL (operands[2]) <= 32
7756        || (INTVAL (operands[1]) + INTVAL (operands[2]) == 64
7757            && INTVAL (operands[1]) > 32))
7758    && (GET_MODE (operands[0]) == SImode
7759        || GET_MODE (operands[0]) == DImode
7760        || GET_MODE (operands[0]) == HImode
7761        || GET_MODE (operands[0]) == QImode)"
7762   "#")
7763
7764 ;; Combine likes to form bit extractions for some tests.  Humor it.
7765 (define_insn "*testqi_ext_3"
7766   [(set (reg FLAGS_REG)
7767         (compare (zero_extract:SI
7768                    (match_operand 0 "nonimmediate_operand" "rm")
7769                    (match_operand:SI 1 "const_int_operand" "")
7770                    (match_operand:SI 2 "const_int_operand" ""))
7771                  (const_int 0)))]
7772   "ix86_match_ccmode (insn, CCNOmode)
7773    && INTVAL (operands[1]) > 0
7774    && INTVAL (operands[2]) >= 0
7775    && INTVAL (operands[1]) + INTVAL (operands[2]) <= 32
7776    && (GET_MODE (operands[0]) == SImode
7777        || (TARGET_64BIT && GET_MODE (operands[0]) == DImode)
7778        || GET_MODE (operands[0]) == HImode
7779        || GET_MODE (operands[0]) == QImode)"
7780   "#")
7781
7782 (define_split
7783   [(set (match_operand 0 "flags_reg_operand" "")
7784         (match_operator 1 "compare_operator"
7785           [(zero_extract
7786              (match_operand 2 "nonimmediate_operand" "")
7787              (match_operand 3 "const_int_operand" "")
7788              (match_operand 4 "const_int_operand" ""))
7789            (const_int 0)]))]
7790   "ix86_match_ccmode (insn, CCNOmode)"
7791   [(set (match_dup 0) (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
7792 {
7793   rtx val = operands[2];
7794   HOST_WIDE_INT len = INTVAL (operands[3]);
7795   HOST_WIDE_INT pos = INTVAL (operands[4]);
7796   HOST_WIDE_INT mask;
7797   enum machine_mode mode, submode;
7798
7799   mode = GET_MODE (val);
7800   if (MEM_P (val))
7801     {
7802       /* ??? Combine likes to put non-volatile mem extractions in QImode
7803          no matter the size of the test.  So find a mode that works.  */
7804       if (! MEM_VOLATILE_P (val))
7805         {
7806           mode = smallest_mode_for_size (pos + len, MODE_INT);
7807           val = adjust_address (val, mode, 0);
7808         }
7809     }
7810   else if (GET_CODE (val) == SUBREG
7811            && (submode = GET_MODE (SUBREG_REG (val)),
7812                GET_MODE_BITSIZE (mode) > GET_MODE_BITSIZE (submode))
7813            && pos + len <= GET_MODE_BITSIZE (submode)
7814            && GET_MODE_CLASS (submode) == MODE_INT)
7815     {
7816       /* Narrow a paradoxical subreg to prevent partial register stalls.  */
7817       mode = submode;
7818       val = SUBREG_REG (val);
7819     }
7820   else if (mode == HImode && pos + len <= 8)
7821     {
7822       /* Small HImode tests can be converted to QImode.  */
7823       mode = QImode;
7824       val = gen_lowpart (QImode, val);
7825     }
7826
7827   if (len == HOST_BITS_PER_WIDE_INT)
7828     mask = -1;
7829   else
7830     mask = ((HOST_WIDE_INT)1 << len) - 1;
7831   mask <<= pos;
7832
7833   operands[2] = gen_rtx_AND (mode, val, gen_int_mode (mask, mode));
7834 })
7835
7836 ;; Convert HImode/SImode test instructions with immediate to QImode ones.
7837 ;; i386 does not allow to encode test with 8bit sign extended immediate, so
7838 ;; this is relatively important trick.
7839 ;; Do the conversion only post-reload to avoid limiting of the register class
7840 ;; to QI regs.
7841 (define_split
7842   [(set (match_operand 0 "flags_reg_operand" "")
7843         (match_operator 1 "compare_operator"
7844           [(and (match_operand 2 "register_operand" "")
7845                 (match_operand 3 "const_int_operand" ""))
7846            (const_int 0)]))]
7847    "reload_completed
7848     && QI_REG_P (operands[2])
7849     && GET_MODE (operands[2]) != QImode
7850     && ((ix86_match_ccmode (insn, CCZmode)
7851          && !(INTVAL (operands[3]) & ~(255 << 8)))
7852         || (ix86_match_ccmode (insn, CCNOmode)
7853             && !(INTVAL (operands[3]) & ~(127 << 8))))"
7854   [(set (match_dup 0)
7855         (match_op_dup 1
7856           [(and:SI (zero_extract:SI (match_dup 2) (const_int 8) (const_int 8))
7857                    (match_dup 3))
7858            (const_int 0)]))]
7859   "operands[2] = gen_lowpart (SImode, operands[2]);
7860    operands[3] = gen_int_mode (INTVAL (operands[3]) >> 8, SImode);")
7861
7862 (define_split
7863   [(set (match_operand 0 "flags_reg_operand" "")
7864         (match_operator 1 "compare_operator"
7865           [(and (match_operand 2 "nonimmediate_operand" "")
7866                 (match_operand 3 "const_int_operand" ""))
7867            (const_int 0)]))]
7868    "reload_completed
7869     && GET_MODE (operands[2]) != QImode
7870     && (!REG_P (operands[2]) || ANY_QI_REG_P (operands[2]))
7871     && ((ix86_match_ccmode (insn, CCZmode)
7872          && !(INTVAL (operands[3]) & ~255))
7873         || (ix86_match_ccmode (insn, CCNOmode)
7874             && !(INTVAL (operands[3]) & ~127)))"
7875   [(set (match_dup 0)
7876         (match_op_dup 1 [(and:QI (match_dup 2) (match_dup 3))
7877                          (const_int 0)]))]
7878   "operands[2] = gen_lowpart (QImode, operands[2]);
7879    operands[3] = gen_lowpart (QImode, operands[3]);")
7880
7881 ;; %%% This used to optimize known byte-wide and operations to memory,
7882 ;; and sometimes to QImode registers.  If this is considered useful,
7883 ;; it should be done with splitters.
7884
7885 (define_expand "and<mode>3"
7886   [(set (match_operand:SWIM 0 "nonimmediate_operand" "")
7887         (and:SWIM (match_operand:SWIM 1 "nonimmediate_operand" "")
7888                   (match_operand:SWIM 2 "<general_szext_operand>" "")))]
7889   ""
7890   "ix86_expand_binary_operator (AND, <MODE>mode, operands); DONE;")
7891
7892 (define_insn "*anddi_1"
7893   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,rm,r,r")
7894         (and:DI
7895          (match_operand:DI 1 "nonimmediate_operand" "%0,0,0,qm")
7896          (match_operand:DI 2 "x86_64_szext_general_operand" "Z,re,rm,L")))
7897    (clobber (reg:CC FLAGS_REG))]
7898   "TARGET_64BIT && ix86_binary_operator_ok (AND, DImode, operands)"
7899 {
7900   switch (get_attr_type (insn))
7901     {
7902     case TYPE_IMOVX:
7903       {
7904         enum machine_mode mode;
7905
7906         gcc_assert (CONST_INT_P (operands[2]));
7907         if (INTVAL (operands[2]) == 0xff)
7908           mode = QImode;
7909         else
7910           {
7911             gcc_assert (INTVAL (operands[2]) == 0xffff);
7912             mode = HImode;
7913           }
7914
7915         operands[1] = gen_lowpart (mode, operands[1]);
7916         if (mode == QImode)
7917           return "movz{bl|x}\t{%1, %k0|%k0, %1}";
7918         else
7919           return "movz{wl|x}\t{%1, %k0|%k0, %1}";
7920       }
7921
7922     default:
7923       gcc_assert (rtx_equal_p (operands[0], operands[1]));
7924       if (get_attr_mode (insn) == MODE_SI)
7925         return "and{l}\t{%k2, %k0|%k0, %k2}";
7926       else
7927         return "and{q}\t{%2, %0|%0, %2}";
7928     }
7929 }
7930   [(set_attr "type" "alu,alu,alu,imovx")
7931    (set_attr "length_immediate" "*,*,*,0")
7932    (set (attr "prefix_rex")
7933      (if_then_else
7934        (and (eq_attr "type" "imovx")
7935             (and (ne (symbol_ref "INTVAL (operands[2]) == 0xff") (const_int 0))
7936                  (match_operand 1 "ext_QIreg_operand" "")))
7937        (const_string "1")
7938        (const_string "*")))
7939    (set_attr "mode" "SI,DI,DI,SI")])
7940
7941 (define_insn "*andsi_1"
7942   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r,r")
7943         (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,qm")
7944                 (match_operand:SI 2 "general_operand" "ri,rm,L")))
7945    (clobber (reg:CC FLAGS_REG))]
7946   "ix86_binary_operator_ok (AND, SImode, operands)"
7947 {
7948   switch (get_attr_type (insn))
7949     {
7950     case TYPE_IMOVX:
7951       {
7952         enum machine_mode mode;
7953
7954         gcc_assert (CONST_INT_P (operands[2]));
7955         if (INTVAL (operands[2]) == 0xff)
7956           mode = QImode;
7957         else
7958           {
7959             gcc_assert (INTVAL (operands[2]) == 0xffff);
7960             mode = HImode;
7961           }
7962
7963         operands[1] = gen_lowpart (mode, operands[1]);
7964         if (mode == QImode)
7965           return "movz{bl|x}\t{%1, %0|%0, %1}";
7966         else
7967           return "movz{wl|x}\t{%1, %0|%0, %1}";
7968       }
7969
7970     default:
7971       gcc_assert (rtx_equal_p (operands[0], operands[1]));
7972       return "and{l}\t{%2, %0|%0, %2}";
7973     }
7974 }
7975   [(set_attr "type" "alu,alu,imovx")
7976    (set (attr "prefix_rex")
7977      (if_then_else
7978        (and (eq_attr "type" "imovx")
7979             (and (ne (symbol_ref "INTVAL (operands[2]) == 0xff") (const_int 0))
7980                  (match_operand 1 "ext_QIreg_operand" "")))
7981        (const_string "1")
7982        (const_string "*")))
7983    (set_attr "length_immediate" "*,*,0")
7984    (set_attr "mode" "SI")])
7985
7986 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
7987 (define_insn "*andsi_1_zext"
7988   [(set (match_operand:DI 0 "register_operand" "=r")
7989         (zero_extend:DI
7990           (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
7991                   (match_operand:SI 2 "general_operand" "g"))))
7992    (clobber (reg:CC FLAGS_REG))]
7993   "TARGET_64BIT && ix86_binary_operator_ok (AND, SImode, operands)"
7994   "and{l}\t{%2, %k0|%k0, %2}"
7995   [(set_attr "type" "alu")
7996    (set_attr "mode" "SI")])
7997
7998 (define_insn "*andhi_1"
7999   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r,r")
8000         (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,qm")
8001                 (match_operand:HI 2 "general_operand" "rn,rm,L")))
8002    (clobber (reg:CC FLAGS_REG))]
8003   "ix86_binary_operator_ok (AND, HImode, operands)"
8004 {
8005   switch (get_attr_type (insn))
8006     {
8007     case TYPE_IMOVX:
8008       gcc_assert (CONST_INT_P (operands[2]));
8009       gcc_assert (INTVAL (operands[2]) == 0xff);
8010       return "movz{bl|x}\t{%b1, %k0|%k0, %b1}";
8011
8012     default:
8013       gcc_assert (rtx_equal_p (operands[0], operands[1]));
8014
8015       return "and{w}\t{%2, %0|%0, %2}";
8016     }
8017 }
8018   [(set_attr "type" "alu,alu,imovx")
8019    (set_attr "length_immediate" "*,*,0")
8020    (set (attr "prefix_rex")
8021      (if_then_else
8022        (and (eq_attr "type" "imovx")
8023             (match_operand 1 "ext_QIreg_operand" ""))
8024        (const_string "1")
8025        (const_string "*")))
8026    (set_attr "mode" "HI,HI,SI")])
8027
8028 ;; %%% Potential partial reg stall on alternative 2.  What to do?
8029 (define_insn "*andqi_1"
8030   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q,r")
8031         (and:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
8032                 (match_operand:QI 2 "general_operand" "qn,qmn,rn")))
8033    (clobber (reg:CC FLAGS_REG))]
8034   "ix86_binary_operator_ok (AND, QImode, operands)"
8035   "@
8036    and{b}\t{%2, %0|%0, %2}
8037    and{b}\t{%2, %0|%0, %2}
8038    and{l}\t{%k2, %k0|%k0, %k2}"
8039   [(set_attr "type" "alu")
8040    (set_attr "mode" "QI,QI,SI")])
8041
8042 (define_insn "*andqi_1_slp"
8043   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
8044         (and:QI (match_dup 0)
8045                 (match_operand:QI 1 "general_operand" "qn,qmn")))
8046    (clobber (reg:CC FLAGS_REG))]
8047   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8048    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8049   "and{b}\t{%1, %0|%0, %1}"
8050   [(set_attr "type" "alu1")
8051    (set_attr "mode" "QI")])
8052
8053 (define_split
8054   [(set (match_operand 0 "register_operand" "")
8055         (and (match_dup 0)
8056              (const_int -65536)))
8057    (clobber (reg:CC FLAGS_REG))]
8058   "(TARGET_FAST_PREFIX && !TARGET_PARTIAL_REG_STALL)
8059     || optimize_function_for_size_p (cfun)"
8060   [(set (strict_low_part (match_dup 1)) (const_int 0))]
8061   "operands[1] = gen_lowpart (HImode, operands[0]);")
8062
8063 (define_split
8064   [(set (match_operand 0 "ext_register_operand" "")
8065         (and (match_dup 0)
8066              (const_int -256)))
8067    (clobber (reg:CC FLAGS_REG))]
8068   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8069    && reload_completed"
8070   [(set (strict_low_part (match_dup 1)) (const_int 0))]
8071   "operands[1] = gen_lowpart (QImode, operands[0]);")
8072
8073 (define_split
8074   [(set (match_operand 0 "ext_register_operand" "")
8075         (and (match_dup 0)
8076              (const_int -65281)))
8077    (clobber (reg:CC FLAGS_REG))]
8078   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8079    && reload_completed"
8080   [(parallel [(set (zero_extract:SI (match_dup 0)
8081                                     (const_int 8)
8082                                     (const_int 8))
8083                    (xor:SI
8084                      (zero_extract:SI (match_dup 0)
8085                                       (const_int 8)
8086                                       (const_int 8))
8087                      (zero_extract:SI (match_dup 0)
8088                                       (const_int 8)
8089                                       (const_int 8))))
8090               (clobber (reg:CC FLAGS_REG))])]
8091   "operands[0] = gen_lowpart (SImode, operands[0]);")
8092
8093 (define_insn "*anddi_2"
8094   [(set (reg FLAGS_REG)
8095         (compare
8096          (and:DI
8097           (match_operand:DI 1 "nonimmediate_operand" "%0,0,0")
8098           (match_operand:DI 2 "x86_64_szext_general_operand" "Z,rem,re"))
8099          (const_int 0)))
8100    (set (match_operand:DI 0 "nonimmediate_operand" "=r,r,rm")
8101         (and:DI (match_dup 1) (match_dup 2)))]
8102   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8103    && ix86_binary_operator_ok (AND, DImode, operands)"
8104   "@
8105    and{l}\t{%k2, %k0|%k0, %k2}
8106    and{q}\t{%2, %0|%0, %2}
8107    and{q}\t{%2, %0|%0, %2}"
8108   [(set_attr "type" "alu")
8109    (set_attr "mode" "SI,DI,DI")])
8110
8111 (define_insn "*andqi_2_maybe_si"
8112   [(set (reg FLAGS_REG)
8113         (compare (and:QI
8114                   (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
8115                   (match_operand:QI 2 "general_operand" "qmn,qn,n"))
8116                  (const_int 0)))
8117    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm,*r")
8118         (and:QI (match_dup 1) (match_dup 2)))]
8119   "ix86_binary_operator_ok (AND, QImode, operands)
8120    && ix86_match_ccmode (insn,
8121                          CONST_INT_P (operands[2])
8122                          && INTVAL (operands[2]) >= 0 ? CCNOmode : CCZmode)"
8123 {
8124   if (which_alternative == 2)
8125     {
8126       if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) < 0)
8127         operands[2] = GEN_INT (INTVAL (operands[2]) & 0xff);
8128       return "and{l}\t{%2, %k0|%k0, %2}";
8129     }
8130   return "and{b}\t{%2, %0|%0, %2}";
8131 }
8132   [(set_attr "type" "alu")
8133    (set_attr "mode" "QI,QI,SI")])
8134
8135 (define_insn "*and<mode>_2"
8136   [(set (reg FLAGS_REG)
8137         (compare (and:SWI124
8138                   (match_operand:SWI124 1 "nonimmediate_operand" "%0,0")
8139                   (match_operand:SWI124 2 "general_operand" "<g>,<r><i>"))
8140                  (const_int 0)))
8141    (set (match_operand:SWI124 0 "nonimmediate_operand" "=<r>,<r>m")
8142         (and:SWI124 (match_dup 1) (match_dup 2)))]
8143   "ix86_match_ccmode (insn, CCNOmode)
8144    && ix86_binary_operator_ok (AND, <MODE>mode, operands)"
8145   "and{<imodesuffix>}\t{%2, %0|%0, %2}"
8146   [(set_attr "type" "alu")
8147    (set_attr "mode" "<MODE>")])
8148
8149 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8150 (define_insn "*andsi_2_zext"
8151   [(set (reg FLAGS_REG)
8152         (compare (and:SI
8153                   (match_operand:SI 1 "nonimmediate_operand" "%0")
8154                   (match_operand:SI 2 "general_operand" "g"))
8155                  (const_int 0)))
8156    (set (match_operand:DI 0 "register_operand" "=r")
8157         (zero_extend:DI (and:SI (match_dup 1) (match_dup 2))))]
8158   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8159    && ix86_binary_operator_ok (AND, SImode, operands)"
8160   "and{l}\t{%2, %k0|%k0, %2}"
8161   [(set_attr "type" "alu")
8162    (set_attr "mode" "SI")])
8163
8164 (define_insn "*andqi_2_slp"
8165   [(set (reg FLAGS_REG)
8166         (compare (and:QI
8167                    (match_operand:QI 0 "nonimmediate_operand" "+q,qm")
8168                    (match_operand:QI 1 "nonimmediate_operand" "qmn,qn"))
8169                  (const_int 0)))
8170    (set (strict_low_part (match_dup 0))
8171         (and:QI (match_dup 0) (match_dup 1)))]
8172   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8173    && ix86_match_ccmode (insn, CCNOmode)
8174    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8175   "and{b}\t{%1, %0|%0, %1}"
8176   [(set_attr "type" "alu1")
8177    (set_attr "mode" "QI")])
8178
8179 ;; ??? A bug in recog prevents it from recognizing a const_int as an
8180 ;; operand to zero_extend in andqi_ext_1.  It was checking explicitly
8181 ;; for a QImode operand, which of course failed.
8182 (define_insn "andqi_ext_0"
8183   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8184                          (const_int 8)
8185                          (const_int 8))
8186         (and:SI
8187           (zero_extract:SI
8188             (match_operand 1 "ext_register_operand" "0")
8189             (const_int 8)
8190             (const_int 8))
8191           (match_operand 2 "const_int_operand" "n")))
8192    (clobber (reg:CC FLAGS_REG))]
8193   ""
8194   "and{b}\t{%2, %h0|%h0, %2}"
8195   [(set_attr "type" "alu")
8196    (set_attr "length_immediate" "1")
8197    (set_attr "modrm" "1")
8198    (set_attr "mode" "QI")])
8199
8200 ;; Generated by peephole translating test to and.  This shows up
8201 ;; often in fp comparisons.
8202 (define_insn "*andqi_ext_0_cc"
8203   [(set (reg FLAGS_REG)
8204         (compare
8205           (and:SI
8206             (zero_extract:SI
8207               (match_operand 1 "ext_register_operand" "0")
8208               (const_int 8)
8209               (const_int 8))
8210             (match_operand 2 "const_int_operand" "n"))
8211           (const_int 0)))
8212    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8213                          (const_int 8)
8214                          (const_int 8))
8215         (and:SI
8216           (zero_extract:SI
8217             (match_dup 1)
8218             (const_int 8)
8219             (const_int 8))
8220           (match_dup 2)))]
8221   "ix86_match_ccmode (insn, CCNOmode)"
8222   "and{b}\t{%2, %h0|%h0, %2}"
8223   [(set_attr "type" "alu")
8224    (set_attr "length_immediate" "1")
8225    (set_attr "modrm" "1")
8226    (set_attr "mode" "QI")])
8227
8228 (define_insn "*andqi_ext_1_rex64"
8229   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8230                          (const_int 8)
8231                          (const_int 8))
8232         (and:SI
8233           (zero_extract:SI
8234             (match_operand 1 "ext_register_operand" "0")
8235             (const_int 8)
8236             (const_int 8))
8237           (zero_extend:SI
8238             (match_operand 2 "ext_register_operand" "Q"))))
8239    (clobber (reg:CC FLAGS_REG))]
8240   "TARGET_64BIT"
8241   "and{b}\t{%2, %h0|%h0, %2}"
8242   [(set_attr "type" "alu")
8243    (set_attr "length_immediate" "0")
8244    (set_attr "mode" "QI")])
8245
8246 (define_insn "*andqi_ext_1"
8247   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8248                          (const_int 8)
8249                          (const_int 8))
8250         (and:SI
8251           (zero_extract:SI
8252             (match_operand 1 "ext_register_operand" "0")
8253             (const_int 8)
8254             (const_int 8))
8255           (zero_extend:SI
8256             (match_operand:QI 2 "general_operand" "Qm"))))
8257    (clobber (reg:CC FLAGS_REG))]
8258   "!TARGET_64BIT"
8259   "and{b}\t{%2, %h0|%h0, %2}"
8260   [(set_attr "type" "alu")
8261    (set_attr "length_immediate" "0")
8262    (set_attr "mode" "QI")])
8263
8264 (define_insn "*andqi_ext_2"
8265   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8266                          (const_int 8)
8267                          (const_int 8))
8268         (and:SI
8269           (zero_extract:SI
8270             (match_operand 1 "ext_register_operand" "%0")
8271             (const_int 8)
8272             (const_int 8))
8273           (zero_extract:SI
8274             (match_operand 2 "ext_register_operand" "Q")
8275             (const_int 8)
8276             (const_int 8))))
8277    (clobber (reg:CC FLAGS_REG))]
8278   ""
8279   "and{b}\t{%h2, %h0|%h0, %h2}"
8280   [(set_attr "type" "alu")
8281    (set_attr "length_immediate" "0")
8282    (set_attr "mode" "QI")])
8283
8284 ;; Convert wide AND instructions with immediate operand to shorter QImode
8285 ;; equivalents when possible.
8286 ;; Don't do the splitting with memory operands, since it introduces risk
8287 ;; of memory mismatch stalls.  We may want to do the splitting for optimizing
8288 ;; for size, but that can (should?) be handled by generic code instead.
8289 (define_split
8290   [(set (match_operand 0 "register_operand" "")
8291         (and (match_operand 1 "register_operand" "")
8292              (match_operand 2 "const_int_operand" "")))
8293    (clobber (reg:CC FLAGS_REG))]
8294    "reload_completed
8295     && QI_REG_P (operands[0])
8296     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8297     && !(~INTVAL (operands[2]) & ~(255 << 8))
8298     && GET_MODE (operands[0]) != QImode"
8299   [(parallel [(set (zero_extract:SI (match_dup 0) (const_int 8) (const_int 8))
8300                    (and:SI (zero_extract:SI (match_dup 1)
8301                                             (const_int 8) (const_int 8))
8302                            (match_dup 2)))
8303               (clobber (reg:CC FLAGS_REG))])]
8304   "operands[0] = gen_lowpart (SImode, operands[0]);
8305    operands[1] = gen_lowpart (SImode, operands[1]);
8306    operands[2] = gen_int_mode ((INTVAL (operands[2]) >> 8) & 0xff, SImode);")
8307
8308 ;; Since AND can be encoded with sign extended immediate, this is only
8309 ;; profitable when 7th bit is not set.
8310 (define_split
8311   [(set (match_operand 0 "register_operand" "")
8312         (and (match_operand 1 "general_operand" "")
8313              (match_operand 2 "const_int_operand" "")))
8314    (clobber (reg:CC FLAGS_REG))]
8315    "reload_completed
8316     && ANY_QI_REG_P (operands[0])
8317     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8318     && !(~INTVAL (operands[2]) & ~255)
8319     && !(INTVAL (operands[2]) & 128)
8320     && GET_MODE (operands[0]) != QImode"
8321   [(parallel [(set (strict_low_part (match_dup 0))
8322                    (and:QI (match_dup 1)
8323                            (match_dup 2)))
8324               (clobber (reg:CC FLAGS_REG))])]
8325   "operands[0] = gen_lowpart (QImode, operands[0]);
8326    operands[1] = gen_lowpart (QImode, operands[1]);
8327    operands[2] = gen_lowpart (QImode, operands[2]);")
8328 \f
8329 ;; Logical inclusive and exclusive OR instructions
8330
8331 ;; %%% This used to optimize known byte-wide and operations to memory.
8332 ;; If this is considered useful, it should be done with splitters.
8333
8334 (define_expand "<code><mode>3"
8335   [(set (match_operand:SWIM 0 "nonimmediate_operand" "")
8336         (any_or:SWIM (match_operand:SWIM 1 "nonimmediate_operand" "")
8337                      (match_operand:SWIM 2 "<general_operand>" "")))]
8338   ""
8339   "ix86_expand_binary_operator (<CODE>, <MODE>mode, operands); DONE;")
8340
8341 (define_insn "*<code><mode>_1"
8342   [(set (match_operand:SWI248 0 "nonimmediate_operand" "=r,rm")
8343         (any_or:SWI248
8344          (match_operand:SWI248 1 "nonimmediate_operand" "%0,0")
8345          (match_operand:SWI248 2 "<general_operand>" "<g>,r<i>")))
8346    (clobber (reg:CC FLAGS_REG))]
8347   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
8348   "<logic>{<imodesuffix>}\t{%2, %0|%0, %2}"
8349   [(set_attr "type" "alu")
8350    (set_attr "mode" "<MODE>")])
8351
8352 ;; %%% Potential partial reg stall on alternative 2.  What to do?
8353 (define_insn "*<code>qi_1"
8354   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,m,r")
8355         (any_or:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
8356                    (match_operand:QI 2 "general_operand" "qmn,qn,rn")))
8357    (clobber (reg:CC FLAGS_REG))]
8358   "ix86_binary_operator_ok (<CODE>, QImode, operands)"
8359   "@
8360    <logic>{b}\t{%2, %0|%0, %2}
8361    <logic>{b}\t{%2, %0|%0, %2}
8362    <logic>{l}\t{%k2, %k0|%k0, %k2}"
8363   [(set_attr "type" "alu")
8364    (set_attr "mode" "QI,QI,SI")])
8365
8366 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8367 (define_insn "*<code>si_1_zext"
8368   [(set (match_operand:DI 0 "register_operand" "=r")
8369         (zero_extend:DI
8370          (any_or:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8371                     (match_operand:SI 2 "general_operand" "g"))))
8372    (clobber (reg:CC FLAGS_REG))]
8373   "TARGET_64BIT && ix86_binary_operator_ok (<CODE>, SImode, operands)"
8374   "<logic>{l}\t{%2, %k0|%k0, %2}"
8375   [(set_attr "type" "alu")
8376    (set_attr "mode" "SI")])
8377
8378 (define_insn "*<code>si_1_zext_imm"
8379   [(set (match_operand:DI 0 "register_operand" "=r")
8380         (any_or:DI
8381          (zero_extend:DI (match_operand:SI 1 "register_operand" "%0"))
8382          (match_operand:DI 2 "x86_64_zext_immediate_operand" "Z")))
8383    (clobber (reg:CC FLAGS_REG))]
8384   "TARGET_64BIT && ix86_binary_operator_ok (<CODE>, SImode, operands)"
8385   "<logic>{l}\t{%2, %k0|%k0, %2}"
8386   [(set_attr "type" "alu")
8387    (set_attr "mode" "SI")])
8388
8389 (define_insn "*<code>qi_1_slp"
8390   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+q,m"))
8391         (any_or:QI (match_dup 0)
8392                    (match_operand:QI 1 "general_operand" "qmn,qn")))
8393    (clobber (reg:CC FLAGS_REG))]
8394   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8395    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8396   "<logic>{b}\t{%1, %0|%0, %1}"
8397   [(set_attr "type" "alu1")
8398    (set_attr "mode" "QI")])
8399
8400 (define_insn "*<code><mode>_2"
8401   [(set (reg FLAGS_REG)
8402         (compare (any_or:SWI
8403                   (match_operand:SWI 1 "nonimmediate_operand" "%0,0")
8404                   (match_operand:SWI 2 "<general_operand>" "<g>,<r><i>"))
8405                  (const_int 0)))
8406    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>,<r>m")
8407         (any_or:SWI (match_dup 1) (match_dup 2)))]
8408   "ix86_match_ccmode (insn, CCNOmode)
8409    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
8410   "<logic>{<imodesuffix>}\t{%2, %0|%0, %2}"
8411   [(set_attr "type" "alu")
8412    (set_attr "mode" "<MODE>")])
8413
8414 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8415 ;; ??? Special case for immediate operand is missing - it is tricky.
8416 (define_insn "*<code>si_2_zext"
8417   [(set (reg FLAGS_REG)
8418         (compare (any_or:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8419                             (match_operand:SI 2 "general_operand" "g"))
8420                  (const_int 0)))
8421    (set (match_operand:DI 0 "register_operand" "=r")
8422         (zero_extend:DI (any_or:SI (match_dup 1) (match_dup 2))))]
8423   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8424    && ix86_binary_operator_ok (<CODE>, SImode, operands)"
8425   "<logic>{l}\t{%2, %k0|%k0, %2}"
8426   [(set_attr "type" "alu")
8427    (set_attr "mode" "SI")])
8428
8429 (define_insn "*<code>si_2_zext_imm"
8430   [(set (reg FLAGS_REG)
8431         (compare (any_or:SI
8432                   (match_operand:SI 1 "nonimmediate_operand" "%0")
8433                   (match_operand:SI 2 "x86_64_zext_immediate_operand" "Z"))
8434                  (const_int 0)))
8435    (set (match_operand:DI 0 "register_operand" "=r")
8436         (any_or:DI (zero_extend:DI (match_dup 1)) (match_dup 2)))]
8437   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8438    && ix86_binary_operator_ok (<CODE>, SImode, operands)"
8439   "<logic>{l}\t{%2, %k0|%k0, %2}"
8440   [(set_attr "type" "alu")
8441    (set_attr "mode" "SI")])
8442
8443 (define_insn "*<code>qi_2_slp"
8444   [(set (reg FLAGS_REG)
8445         (compare (any_or:QI (match_operand:QI 0 "nonimmediate_operand" "+q,qm")
8446                             (match_operand:QI 1 "general_operand" "qmn,qn"))
8447                  (const_int 0)))
8448    (set (strict_low_part (match_dup 0))
8449         (any_or:QI (match_dup 0) (match_dup 1)))]
8450   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8451    && ix86_match_ccmode (insn, CCNOmode)
8452    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8453   "<logic>{b}\t{%1, %0|%0, %1}"
8454   [(set_attr "type" "alu1")
8455    (set_attr "mode" "QI")])
8456
8457 (define_insn "*<code><mode>_3"
8458   [(set (reg FLAGS_REG)
8459         (compare (any_or:SWI
8460                   (match_operand:SWI 1 "nonimmediate_operand" "%0")
8461                   (match_operand:SWI 2 "<general_operand>" "<g>"))
8462                  (const_int 0)))
8463    (clobber (match_scratch:SWI 0 "=<r>"))]
8464   "ix86_match_ccmode (insn, CCNOmode)
8465    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
8466   "<logic>{<imodesuffix>}\t{%2, %0|%0, %2}"
8467   [(set_attr "type" "alu")
8468    (set_attr "mode" "<MODE>")])
8469
8470 (define_insn "*<code>qi_ext_0"
8471   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8472                          (const_int 8)
8473                          (const_int 8))
8474         (any_or:SI
8475           (zero_extract:SI
8476             (match_operand 1 "ext_register_operand" "0")
8477             (const_int 8)
8478             (const_int 8))
8479           (match_operand 2 "const_int_operand" "n")))
8480    (clobber (reg:CC FLAGS_REG))]
8481   "!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)"
8482   "<logic>{b}\t{%2, %h0|%h0, %2}"
8483   [(set_attr "type" "alu")
8484    (set_attr "length_immediate" "1")
8485    (set_attr "modrm" "1")
8486    (set_attr "mode" "QI")])
8487
8488 (define_insn "*<code>qi_ext_1_rex64"
8489   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8490                          (const_int 8)
8491                          (const_int 8))
8492         (any_or:SI
8493           (zero_extract:SI
8494             (match_operand 1 "ext_register_operand" "0")
8495             (const_int 8)
8496             (const_int 8))
8497           (zero_extend:SI
8498             (match_operand 2 "ext_register_operand" "Q"))))
8499    (clobber (reg:CC FLAGS_REG))]
8500   "TARGET_64BIT
8501    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))"
8502   "<logic>{b}\t{%2, %h0|%h0, %2}"
8503   [(set_attr "type" "alu")
8504    (set_attr "length_immediate" "0")
8505    (set_attr "mode" "QI")])
8506
8507 (define_insn "*<code>qi_ext_1"
8508   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8509                          (const_int 8)
8510                          (const_int 8))
8511         (any_or:SI
8512           (zero_extract:SI
8513             (match_operand 1 "ext_register_operand" "0")
8514             (const_int 8)
8515             (const_int 8))
8516           (zero_extend:SI
8517             (match_operand:QI 2 "general_operand" "Qm"))))
8518    (clobber (reg:CC FLAGS_REG))]
8519   "!TARGET_64BIT
8520    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))"
8521   "<logic>{b}\t{%2, %h0|%h0, %2}"
8522   [(set_attr "type" "alu")
8523    (set_attr "length_immediate" "0")
8524    (set_attr "mode" "QI")])
8525
8526 (define_insn "*<code>qi_ext_2"
8527   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8528                          (const_int 8)
8529                          (const_int 8))
8530         (any_or:SI
8531           (zero_extract:SI (match_operand 1 "ext_register_operand" "0")
8532                            (const_int 8)
8533                            (const_int 8))
8534           (zero_extract:SI (match_operand 2 "ext_register_operand" "Q")
8535                            (const_int 8)
8536                            (const_int 8))))
8537    (clobber (reg:CC FLAGS_REG))]
8538   "!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)"
8539   "<logic>{b}\t{%h2, %h0|%h0, %h2}"
8540   [(set_attr "type" "alu")
8541    (set_attr "length_immediate" "0")
8542    (set_attr "mode" "QI")])
8543
8544 (define_split
8545   [(set (match_operand 0 "register_operand" "")
8546         (any_or (match_operand 1 "register_operand" "")
8547                 (match_operand 2 "const_int_operand" "")))
8548    (clobber (reg:CC FLAGS_REG))]
8549    "reload_completed
8550     && QI_REG_P (operands[0])
8551     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8552     && !(INTVAL (operands[2]) & ~(255 << 8))
8553     && GET_MODE (operands[0]) != QImode"
8554   [(parallel [(set (zero_extract:SI (match_dup 0) (const_int 8) (const_int 8))
8555                    (any_or:SI (zero_extract:SI (match_dup 1)
8556                                                (const_int 8) (const_int 8))
8557                               (match_dup 2)))
8558               (clobber (reg:CC FLAGS_REG))])]
8559   "operands[0] = gen_lowpart (SImode, operands[0]);
8560    operands[1] = gen_lowpart (SImode, operands[1]);
8561    operands[2] = gen_int_mode ((INTVAL (operands[2]) >> 8) & 0xff, SImode);")
8562
8563 ;; Since OR can be encoded with sign extended immediate, this is only
8564 ;; profitable when 7th bit is set.
8565 (define_split
8566   [(set (match_operand 0 "register_operand" "")
8567         (any_or (match_operand 1 "general_operand" "")
8568                 (match_operand 2 "const_int_operand" "")))
8569    (clobber (reg:CC FLAGS_REG))]
8570    "reload_completed
8571     && ANY_QI_REG_P (operands[0])
8572     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8573     && !(INTVAL (operands[2]) & ~255)
8574     && (INTVAL (operands[2]) & 128)
8575     && GET_MODE (operands[0]) != QImode"
8576   [(parallel [(set (strict_low_part (match_dup 0))
8577                    (any_or:QI (match_dup 1)
8578                               (match_dup 2)))
8579               (clobber (reg:CC FLAGS_REG))])]
8580   "operands[0] = gen_lowpart (QImode, operands[0]);
8581    operands[1] = gen_lowpart (QImode, operands[1]);
8582    operands[2] = gen_lowpart (QImode, operands[2]);")
8583
8584 (define_expand "xorqi_cc_ext_1"
8585   [(parallel [
8586      (set (reg:CCNO FLAGS_REG)
8587           (compare:CCNO
8588             (xor:SI
8589               (zero_extract:SI
8590                 (match_operand 1 "ext_register_operand" "")
8591                 (const_int 8)
8592                 (const_int 8))
8593               (match_operand:QI 2 "general_operand" ""))
8594             (const_int 0)))
8595      (set (zero_extract:SI (match_operand 0 "ext_register_operand" "")
8596                            (const_int 8)
8597                            (const_int 8))
8598           (xor:SI
8599             (zero_extract:SI
8600              (match_dup 1)
8601              (const_int 8)
8602              (const_int 8))
8603             (match_dup 2)))])])
8604
8605 (define_insn "*xorqi_cc_ext_1_rex64"
8606   [(set (reg FLAGS_REG)
8607         (compare
8608           (xor:SI
8609             (zero_extract:SI
8610               (match_operand 1 "ext_register_operand" "0")
8611               (const_int 8)
8612               (const_int 8))
8613             (match_operand:QI 2 "nonmemory_operand" "Qn"))
8614           (const_int 0)))
8615    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8616                          (const_int 8)
8617                          (const_int 8))
8618         (xor:SI
8619           (zero_extract:SI
8620            (match_dup 1)
8621            (const_int 8)
8622            (const_int 8))
8623           (match_dup 2)))]
8624   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
8625   "xor{b}\t{%2, %h0|%h0, %2}"
8626   [(set_attr "type" "alu")
8627    (set_attr "modrm" "1")
8628    (set_attr "mode" "QI")])
8629
8630 (define_insn "*xorqi_cc_ext_1"
8631   [(set (reg FLAGS_REG)
8632         (compare
8633           (xor:SI
8634             (zero_extract:SI
8635               (match_operand 1 "ext_register_operand" "0")
8636               (const_int 8)
8637               (const_int 8))
8638             (match_operand:QI 2 "general_operand" "qmn"))
8639           (const_int 0)))
8640    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=q")
8641                          (const_int 8)
8642                          (const_int 8))
8643         (xor:SI
8644           (zero_extract:SI
8645            (match_dup 1)
8646            (const_int 8)
8647            (const_int 8))
8648           (match_dup 2)))]
8649   "!TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)"
8650   "xor{b}\t{%2, %h0|%h0, %2}"
8651   [(set_attr "type" "alu")
8652    (set_attr "modrm" "1")
8653    (set_attr "mode" "QI")])
8654 \f
8655 ;; Negation instructions
8656
8657 (define_expand "neg<mode>2"
8658   [(set (match_operand:SDWIM 0 "nonimmediate_operand" "")
8659         (neg:SDWIM (match_operand:SDWIM 1 "nonimmediate_operand" "")))]
8660   ""
8661   "ix86_expand_unary_operator (NEG, <MODE>mode, operands); DONE;")
8662
8663 (define_insn_and_split "*neg<dwi>2_doubleword"
8664   [(set (match_operand:<DWI> 0 "nonimmediate_operand" "=ro")
8665         (neg:<DWI> (match_operand:<DWI> 1 "nonimmediate_operand" "0")))
8666    (clobber (reg:CC FLAGS_REG))]
8667   "ix86_unary_operator_ok (NEG, <DWI>mode, operands)"
8668   "#"
8669   "reload_completed"
8670   [(parallel
8671     [(set (reg:CCZ FLAGS_REG)
8672           (compare:CCZ (neg:DWIH (match_dup 1)) (const_int 0)))
8673      (set (match_dup 0) (neg:DWIH (match_dup 1)))])
8674    (parallel
8675     [(set (match_dup 2)
8676           (plus:DWIH (match_dup 3)
8677                      (plus:DWIH (ltu:DWIH (reg:CC FLAGS_REG) (const_int 0))
8678                                 (const_int 0))))
8679      (clobber (reg:CC FLAGS_REG))])
8680    (parallel
8681     [(set (match_dup 2)
8682           (neg:DWIH (match_dup 2)))
8683      (clobber (reg:CC FLAGS_REG))])]
8684   "split_double_mode (<DWI>mode, &operands[0], 2, &operands[0], &operands[2]);")
8685
8686 (define_insn "*neg<mode>2_1"
8687   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
8688         (neg:SWI (match_operand:SWI 1 "nonimmediate_operand" "0")))
8689    (clobber (reg:CC FLAGS_REG))]
8690   "ix86_unary_operator_ok (NEG, <MODE>mode, operands)"
8691   "neg{<imodesuffix>}\t%0"
8692   [(set_attr "type" "negnot")
8693    (set_attr "mode" "<MODE>")])
8694
8695 ;; Combine is quite creative about this pattern.
8696 (define_insn "*negsi2_1_zext"
8697   [(set (match_operand:DI 0 "register_operand" "=r")
8698         (lshiftrt:DI
8699           (neg:DI (ashift:DI (match_operand:DI 1 "register_operand" "0")
8700                              (const_int 32)))
8701         (const_int 32)))
8702    (clobber (reg:CC FLAGS_REG))]
8703   "TARGET_64BIT && ix86_unary_operator_ok (NEG, SImode, operands)"
8704   "neg{l}\t%k0"
8705   [(set_attr "type" "negnot")
8706    (set_attr "mode" "SI")])
8707
8708 ;; The problem with neg is that it does not perform (compare x 0),
8709 ;; it really performs (compare 0 x), which leaves us with the zero
8710 ;; flag being the only useful item.
8711
8712 (define_insn "*neg<mode>2_cmpz"
8713   [(set (reg:CCZ FLAGS_REG)
8714         (compare:CCZ
8715           (neg:SWI (match_operand:SWI 1 "nonimmediate_operand" "0"))
8716                    (const_int 0)))
8717    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
8718         (neg:SWI (match_dup 1)))]
8719   "ix86_unary_operator_ok (NEG, <MODE>mode, operands)"
8720   "neg{<imodesuffix>}\t%0"
8721   [(set_attr "type" "negnot")
8722    (set_attr "mode" "<MODE>")])
8723
8724 (define_insn "*negsi2_cmpz_zext"
8725   [(set (reg:CCZ FLAGS_REG)
8726         (compare:CCZ
8727           (lshiftrt:DI
8728             (neg:DI (ashift:DI
8729                       (match_operand:DI 1 "register_operand" "0")
8730                       (const_int 32)))
8731             (const_int 32))
8732           (const_int 0)))
8733    (set (match_operand:DI 0 "register_operand" "=r")
8734         (lshiftrt:DI (neg:DI (ashift:DI (match_dup 1)
8735                                         (const_int 32)))
8736                      (const_int 32)))]
8737   "TARGET_64BIT && ix86_unary_operator_ok (NEG, SImode, operands)"
8738   "neg{l}\t%k0"
8739   [(set_attr "type" "negnot")
8740    (set_attr "mode" "SI")])
8741
8742 ;; Changing of sign for FP values is doable using integer unit too.
8743
8744 (define_expand "<code><mode>2"
8745   [(set (match_operand:X87MODEF 0 "register_operand" "")
8746         (absneg:X87MODEF (match_operand:X87MODEF 1 "register_operand" "")))]
8747   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
8748   "ix86_expand_fp_absneg_operator (<CODE>, <MODE>mode, operands); DONE;")
8749
8750 (define_insn "*absneg<mode>2_mixed"
8751   [(set (match_operand:MODEF 0 "register_operand" "=x,x,f,!r")
8752         (match_operator:MODEF 3 "absneg_operator"
8753           [(match_operand:MODEF 1 "register_operand" "0,x,0,0")]))
8754    (use (match_operand:<ssevecmode> 2 "nonimmediate_operand" "xm,0,X,X"))
8755    (clobber (reg:CC FLAGS_REG))]
8756   "TARGET_MIX_SSE_I387 && SSE_FLOAT_MODE_P (<MODE>mode)"
8757   "#")
8758
8759 (define_insn "*absneg<mode>2_sse"
8760   [(set (match_operand:MODEF 0 "register_operand" "=x,x,!r")
8761         (match_operator:MODEF 3 "absneg_operator"
8762           [(match_operand:MODEF 1 "register_operand" "0 ,x,0")]))
8763    (use (match_operand:<ssevecmode> 2 "register_operand" "xm,0,X"))
8764    (clobber (reg:CC FLAGS_REG))]
8765   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
8766   "#")
8767
8768 (define_insn "*absneg<mode>2_i387"
8769   [(set (match_operand:X87MODEF 0 "register_operand" "=f,!r")
8770         (match_operator:X87MODEF 3 "absneg_operator"
8771           [(match_operand:X87MODEF 1 "register_operand" "0,0")]))
8772    (use (match_operand 2 "" ""))
8773    (clobber (reg:CC FLAGS_REG))]
8774   "TARGET_80387 && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
8775   "#")
8776
8777 (define_expand "<code>tf2"
8778   [(set (match_operand:TF 0 "register_operand" "")
8779         (absneg:TF (match_operand:TF 1 "register_operand" "")))]
8780   "TARGET_SSE2"
8781   "ix86_expand_fp_absneg_operator (<CODE>, TFmode, operands); DONE;")
8782
8783 (define_insn "*absnegtf2_sse"
8784   [(set (match_operand:TF 0 "register_operand" "=x,x")
8785         (match_operator:TF 3 "absneg_operator"
8786           [(match_operand:TF 1 "register_operand" "0,x")]))
8787    (use (match_operand:TF 2 "nonimmediate_operand" "xm,0"))
8788    (clobber (reg:CC FLAGS_REG))]
8789   "TARGET_SSE2"
8790   "#")
8791
8792 ;; Splitters for fp abs and neg.
8793
8794 (define_split
8795   [(set (match_operand 0 "fp_register_operand" "")
8796         (match_operator 1 "absneg_operator" [(match_dup 0)]))
8797    (use (match_operand 2 "" ""))
8798    (clobber (reg:CC FLAGS_REG))]
8799   "reload_completed"
8800   [(set (match_dup 0) (match_op_dup 1 [(match_dup 0)]))])
8801
8802 (define_split
8803   [(set (match_operand 0 "register_operand" "")
8804         (match_operator 3 "absneg_operator"
8805           [(match_operand 1 "register_operand" "")]))
8806    (use (match_operand 2 "nonimmediate_operand" ""))
8807    (clobber (reg:CC FLAGS_REG))]
8808   "reload_completed && SSE_REG_P (operands[0])"
8809   [(set (match_dup 0) (match_dup 3))]
8810 {
8811   enum machine_mode mode = GET_MODE (operands[0]);
8812   enum machine_mode vmode = GET_MODE (operands[2]);
8813   rtx tmp;
8814
8815   operands[0] = simplify_gen_subreg (vmode, operands[0], mode, 0);
8816   operands[1] = simplify_gen_subreg (vmode, operands[1], mode, 0);
8817   if (operands_match_p (operands[0], operands[2]))
8818     {
8819       tmp = operands[1];
8820       operands[1] = operands[2];
8821       operands[2] = tmp;
8822     }
8823   if (GET_CODE (operands[3]) == ABS)
8824     tmp = gen_rtx_AND (vmode, operands[1], operands[2]);
8825   else
8826     tmp = gen_rtx_XOR (vmode, operands[1], operands[2]);
8827   operands[3] = tmp;
8828 })
8829
8830 (define_split
8831   [(set (match_operand:SF 0 "register_operand" "")
8832         (match_operator:SF 1 "absneg_operator" [(match_dup 0)]))
8833    (use (match_operand:V4SF 2 "" ""))
8834    (clobber (reg:CC FLAGS_REG))]
8835   "reload_completed"
8836   [(parallel [(set (match_dup 0) (match_dup 1))
8837               (clobber (reg:CC FLAGS_REG))])]
8838 {
8839   rtx tmp;
8840   operands[0] = gen_lowpart (SImode, operands[0]);
8841   if (GET_CODE (operands[1]) == ABS)
8842     {
8843       tmp = gen_int_mode (0x7fffffff, SImode);
8844       tmp = gen_rtx_AND (SImode, operands[0], tmp);
8845     }
8846   else
8847     {
8848       tmp = gen_int_mode (0x80000000, SImode);
8849       tmp = gen_rtx_XOR (SImode, operands[0], tmp);
8850     }
8851   operands[1] = tmp;
8852 })
8853
8854 (define_split
8855   [(set (match_operand:DF 0 "register_operand" "")
8856         (match_operator:DF 1 "absneg_operator" [(match_dup 0)]))
8857    (use (match_operand 2 "" ""))
8858    (clobber (reg:CC FLAGS_REG))]
8859   "reload_completed"
8860   [(parallel [(set (match_dup 0) (match_dup 1))
8861               (clobber (reg:CC FLAGS_REG))])]
8862 {
8863   rtx tmp;
8864   if (TARGET_64BIT)
8865     {
8866       tmp = gen_lowpart (DImode, operands[0]);
8867       tmp = gen_rtx_ZERO_EXTRACT (DImode, tmp, const1_rtx, GEN_INT (63));
8868       operands[0] = tmp;
8869
8870       if (GET_CODE (operands[1]) == ABS)
8871         tmp = const0_rtx;
8872       else
8873         tmp = gen_rtx_NOT (DImode, tmp);
8874     }
8875   else
8876     {
8877       operands[0] = gen_highpart (SImode, operands[0]);
8878       if (GET_CODE (operands[1]) == ABS)
8879         {
8880           tmp = gen_int_mode (0x7fffffff, SImode);
8881           tmp = gen_rtx_AND (SImode, operands[0], tmp);
8882         }
8883       else
8884         {
8885           tmp = gen_int_mode (0x80000000, SImode);
8886           tmp = gen_rtx_XOR (SImode, operands[0], tmp);
8887         }
8888     }
8889   operands[1] = tmp;
8890 })
8891
8892 (define_split
8893   [(set (match_operand:XF 0 "register_operand" "")
8894         (match_operator:XF 1 "absneg_operator" [(match_dup 0)]))
8895    (use (match_operand 2 "" ""))
8896    (clobber (reg:CC FLAGS_REG))]
8897   "reload_completed"
8898   [(parallel [(set (match_dup 0) (match_dup 1))
8899               (clobber (reg:CC FLAGS_REG))])]
8900 {
8901   rtx tmp;
8902   operands[0] = gen_rtx_REG (SImode,
8903                              true_regnum (operands[0])
8904                              + (TARGET_64BIT ? 1 : 2));
8905   if (GET_CODE (operands[1]) == ABS)
8906     {
8907       tmp = GEN_INT (0x7fff);
8908       tmp = gen_rtx_AND (SImode, operands[0], tmp);
8909     }
8910   else
8911     {
8912       tmp = GEN_INT (0x8000);
8913       tmp = gen_rtx_XOR (SImode, operands[0], tmp);
8914     }
8915   operands[1] = tmp;
8916 })
8917
8918 ;; Conditionalize these after reload. If they match before reload, we
8919 ;; lose the clobber and ability to use integer instructions.
8920
8921 (define_insn "*<code><mode>2_1"
8922   [(set (match_operand:X87MODEF 0 "register_operand" "=f")
8923         (absneg:X87MODEF (match_operand:X87MODEF 1 "register_operand" "0")))]
8924   "TARGET_80387
8925    && (reload_completed
8926        || !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))"
8927   "f<absneg_mnemonic>"
8928   [(set_attr "type" "fsgn")
8929    (set_attr "mode" "<MODE>")])
8930
8931 (define_insn "*<code>extendsfdf2"
8932   [(set (match_operand:DF 0 "register_operand" "=f")
8933         (absneg:DF (float_extend:DF
8934                      (match_operand:SF 1 "register_operand" "0"))))]
8935   "TARGET_80387 && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387)"
8936   "f<absneg_mnemonic>"
8937   [(set_attr "type" "fsgn")
8938    (set_attr "mode" "DF")])
8939
8940 (define_insn "*<code>extendsfxf2"
8941   [(set (match_operand:XF 0 "register_operand" "=f")
8942         (absneg:XF (float_extend:XF
8943                      (match_operand:SF 1 "register_operand" "0"))))]
8944   "TARGET_80387"
8945   "f<absneg_mnemonic>"
8946   [(set_attr "type" "fsgn")
8947    (set_attr "mode" "XF")])
8948
8949 (define_insn "*<code>extenddfxf2"
8950   [(set (match_operand:XF 0 "register_operand" "=f")
8951         (absneg:XF (float_extend:XF
8952                      (match_operand:DF 1 "register_operand" "0"))))]
8953   "TARGET_80387"
8954   "f<absneg_mnemonic>"
8955   [(set_attr "type" "fsgn")
8956    (set_attr "mode" "XF")])
8957
8958 ;; Copysign instructions
8959
8960 (define_mode_iterator CSGNMODE [SF DF TF])
8961 (define_mode_attr CSGNVMODE [(SF "V4SF") (DF "V2DF") (TF "TF")])
8962
8963 (define_expand "copysign<mode>3"
8964   [(match_operand:CSGNMODE 0 "register_operand" "")
8965    (match_operand:CSGNMODE 1 "nonmemory_operand" "")
8966    (match_operand:CSGNMODE 2 "register_operand" "")]
8967   "(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
8968    || (TARGET_SSE2 && (<MODE>mode == TFmode))"
8969   "ix86_expand_copysign (operands); DONE;")
8970
8971 (define_insn_and_split "copysign<mode>3_const"
8972   [(set (match_operand:CSGNMODE 0 "register_operand" "=x")
8973         (unspec:CSGNMODE
8974           [(match_operand:<CSGNVMODE> 1 "vector_move_operand" "xmC")
8975            (match_operand:CSGNMODE 2 "register_operand" "0")
8976            (match_operand:<CSGNVMODE> 3 "nonimmediate_operand" "xm")]
8977           UNSPEC_COPYSIGN))]
8978   "(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
8979    || (TARGET_SSE2 && (<MODE>mode == TFmode))"
8980   "#"
8981   "&& reload_completed"
8982   [(const_int 0)]
8983   "ix86_split_copysign_const (operands); DONE;")
8984
8985 (define_insn "copysign<mode>3_var"
8986   [(set (match_operand:CSGNMODE 0 "register_operand" "=x,x,x,x,x")
8987         (unspec:CSGNMODE
8988           [(match_operand:CSGNMODE 2 "register_operand" "x,0,0,x,x")
8989            (match_operand:CSGNMODE 3 "register_operand" "1,1,x,1,x")
8990            (match_operand:<CSGNVMODE> 4 "nonimmediate_operand" "X,xm,xm,0,0")
8991            (match_operand:<CSGNVMODE> 5 "nonimmediate_operand" "0,xm,1,xm,1")]
8992           UNSPEC_COPYSIGN))
8993    (clobber (match_scratch:<CSGNVMODE> 1 "=x,x,x,x,x"))]
8994   "(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
8995    || (TARGET_SSE2 && (<MODE>mode == TFmode))"
8996   "#")
8997
8998 (define_split
8999   [(set (match_operand:CSGNMODE 0 "register_operand" "")
9000         (unspec:CSGNMODE
9001           [(match_operand:CSGNMODE 2 "register_operand" "")
9002            (match_operand:CSGNMODE 3 "register_operand" "")
9003            (match_operand:<CSGNVMODE> 4 "" "")
9004            (match_operand:<CSGNVMODE> 5 "" "")]
9005           UNSPEC_COPYSIGN))
9006    (clobber (match_scratch:<CSGNVMODE> 1 ""))]
9007   "((SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
9008     || (TARGET_SSE2 && (<MODE>mode == TFmode)))
9009    && reload_completed"
9010   [(const_int 0)]
9011   "ix86_split_copysign_var (operands); DONE;")
9012 \f
9013 ;; One complement instructions
9014
9015 (define_expand "one_cmpl<mode>2"
9016   [(set (match_operand:SWIM 0 "nonimmediate_operand" "")
9017         (not:SWIM (match_operand:SWIM 1 "nonimmediate_operand" "")))]
9018   ""
9019   "ix86_expand_unary_operator (NOT, <MODE>mode, operands); DONE;")
9020
9021 (define_insn "*one_cmpl<mode>2_1"
9022   [(set (match_operand:SWI248 0 "nonimmediate_operand" "=rm")
9023         (not:SWI248 (match_operand:SWI248 1 "nonimmediate_operand" "0")))]
9024   "ix86_unary_operator_ok (NOT, <MODE>mode, operands)"
9025   "not{<imodesuffix>}\t%0"
9026   [(set_attr "type" "negnot")
9027    (set_attr "mode" "<MODE>")])
9028
9029 ;; %%% Potential partial reg stall on alternative 1.  What to do?
9030 (define_insn "*one_cmplqi2_1"
9031   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r")
9032         (not:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")))]
9033   "ix86_unary_operator_ok (NOT, QImode, operands)"
9034   "@
9035    not{b}\t%0
9036    not{l}\t%k0"
9037   [(set_attr "type" "negnot")
9038    (set_attr "mode" "QI,SI")])
9039
9040 ;; ??? Currently never generated - xor is used instead.
9041 (define_insn "*one_cmplsi2_1_zext"
9042   [(set (match_operand:DI 0 "register_operand" "=r")
9043         (zero_extend:DI
9044           (not:SI (match_operand:SI 1 "register_operand" "0"))))]
9045   "TARGET_64BIT && ix86_unary_operator_ok (NOT, SImode, operands)"
9046   "not{l}\t%k0"
9047   [(set_attr "type" "negnot")
9048    (set_attr "mode" "SI")])
9049
9050 (define_insn "*one_cmpl<mode>2_2"
9051   [(set (reg FLAGS_REG)
9052         (compare (not:SWI (match_operand:SWI 1 "nonimmediate_operand" "0"))
9053                  (const_int 0)))
9054    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
9055         (not:SWI (match_dup 1)))]
9056   "ix86_match_ccmode (insn, CCNOmode)
9057    && ix86_unary_operator_ok (NOT, <MODE>mode, operands)"
9058   "#"
9059   [(set_attr "type" "alu1")
9060    (set_attr "mode" "<MODE>")])
9061
9062 (define_split
9063   [(set (match_operand 0 "flags_reg_operand" "")
9064         (match_operator 2 "compare_operator"
9065           [(not:SWI (match_operand:SWI 3 "nonimmediate_operand" ""))
9066            (const_int 0)]))
9067    (set (match_operand:SWI 1 "nonimmediate_operand" "")
9068         (not:SWI (match_dup 3)))]
9069   "ix86_match_ccmode (insn, CCNOmode)"
9070   [(parallel [(set (match_dup 0)
9071                    (match_op_dup 2 [(xor:SWI (match_dup 3) (const_int -1))
9072                                     (const_int 0)]))
9073               (set (match_dup 1)
9074                    (xor:SWI (match_dup 3) (const_int -1)))])])
9075
9076 ;; ??? Currently never generated - xor is used instead.
9077 (define_insn "*one_cmplsi2_2_zext"
9078   [(set (reg FLAGS_REG)
9079         (compare (not:SI (match_operand:SI 1 "register_operand" "0"))
9080                  (const_int 0)))
9081    (set (match_operand:DI 0 "register_operand" "=r")
9082         (zero_extend:DI (not:SI (match_dup 1))))]
9083   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
9084    && ix86_unary_operator_ok (NOT, SImode, operands)"
9085   "#"
9086   [(set_attr "type" "alu1")
9087    (set_attr "mode" "SI")])
9088
9089 (define_split
9090   [(set (match_operand 0 "flags_reg_operand" "")
9091         (match_operator 2 "compare_operator"
9092           [(not:SI (match_operand:SI 3 "register_operand" ""))
9093            (const_int 0)]))
9094    (set (match_operand:DI 1 "register_operand" "")
9095         (zero_extend:DI (not:SI (match_dup 3))))]
9096   "ix86_match_ccmode (insn, CCNOmode)"
9097   [(parallel [(set (match_dup 0)
9098                    (match_op_dup 2 [(xor:SI (match_dup 3) (const_int -1))
9099                                     (const_int 0)]))
9100               (set (match_dup 1)
9101                    (zero_extend:DI (xor:SI (match_dup 3) (const_int -1))))])])
9102 \f
9103 ;; Shift instructions
9104
9105 ;; DImode shifts are implemented using the i386 "shift double" opcode,
9106 ;; which is written as "sh[lr]d[lw] imm,reg,reg/mem".  If the shift count
9107 ;; is variable, then the count is in %cl and the "imm" operand is dropped
9108 ;; from the assembler input.
9109 ;;
9110 ;; This instruction shifts the target reg/mem as usual, but instead of
9111 ;; shifting in zeros, bits are shifted in from reg operand.  If the insn
9112 ;; is a left shift double, bits are taken from the high order bits of
9113 ;; reg, else if the insn is a shift right double, bits are taken from the
9114 ;; low order bits of reg.  So if %eax is "1234" and %edx is "5678",
9115 ;; "shldl $8,%edx,%eax" leaves %edx unchanged and sets %eax to "2345".
9116 ;;
9117 ;; Since sh[lr]d does not change the `reg' operand, that is done
9118 ;; separately, making all shifts emit pairs of shift double and normal
9119 ;; shift.  Since sh[lr]d does not shift more than 31 bits, and we wish to
9120 ;; support a 63 bit shift, each shift where the count is in a reg expands
9121 ;; to a pair of shifts, a branch, a shift by 32 and a label.
9122 ;;
9123 ;; If the shift count is a constant, we need never emit more than one
9124 ;; shift pair, instead using moves and sign extension for counts greater
9125 ;; than 31.
9126
9127 (define_expand "ashl<mode>3"
9128   [(set (match_operand:SDWIM 0 "<shift_operand>" "")
9129         (ashift:SDWIM (match_operand:SDWIM 1 "<ashl_input_operand>" "")
9130                       (match_operand:QI 2 "nonmemory_operand" "")))]
9131   ""
9132   "ix86_expand_binary_operator (ASHIFT, <MODE>mode, operands); DONE;")
9133
9134 (define_insn "*ashl<mode>3_doubleword"
9135   [(set (match_operand:DWI 0 "register_operand" "=&r,r")
9136         (ashift:DWI (match_operand:DWI 1 "reg_or_pm1_operand" "n,0")
9137                     (match_operand:QI 2 "nonmemory_operand" "<S>c,<S>c")))
9138    (clobber (reg:CC FLAGS_REG))]
9139   ""
9140   "#"
9141   [(set_attr "type" "multi")])
9142
9143 (define_split
9144   [(set (match_operand:DWI 0 "register_operand" "")
9145         (ashift:DWI (match_operand:DWI 1 "nonmemory_operand" "")
9146                     (match_operand:QI 2 "nonmemory_operand" "")))
9147    (clobber (reg:CC FLAGS_REG))]
9148   "(optimize && flag_peephole2) ? epilogue_completed : reload_completed"
9149   [(const_int 0)]
9150   "ix86_split_ashl (operands, NULL_RTX, <MODE>mode); DONE;")
9151
9152 ;; By default we don't ask for a scratch register, because when DWImode
9153 ;; values are manipulated, registers are already at a premium.  But if
9154 ;; we have one handy, we won't turn it away.
9155
9156 (define_peephole2
9157   [(match_scratch:DWIH 3 "r")
9158    (parallel [(set (match_operand:<DWI> 0 "register_operand" "")
9159                    (ashift:<DWI>
9160                      (match_operand:<DWI> 1 "nonmemory_operand" "")
9161                      (match_operand:QI 2 "nonmemory_operand" "")))
9162               (clobber (reg:CC FLAGS_REG))])
9163    (match_dup 3)]
9164   "TARGET_CMOVE"
9165   [(const_int 0)]
9166   "ix86_split_ashl (operands, operands[3], <DWI>mode); DONE;")
9167
9168 (define_insn "x86_64_shld"
9169   [(set (match_operand:DI 0 "nonimmediate_operand" "+r*m")
9170         (ior:DI (ashift:DI (match_dup 0)
9171                   (match_operand:QI 2 "nonmemory_operand" "Jc"))
9172                 (lshiftrt:DI (match_operand:DI 1 "register_operand" "r")
9173                   (minus:QI (const_int 64) (match_dup 2)))))
9174    (clobber (reg:CC FLAGS_REG))]
9175   "TARGET_64BIT"
9176   "shld{q}\t{%s2%1, %0|%0, %1, %2}"
9177   [(set_attr "type" "ishift")
9178    (set_attr "prefix_0f" "1")
9179    (set_attr "mode" "DI")
9180    (set_attr "athlon_decode" "vector")
9181    (set_attr "amdfam10_decode" "vector")
9182    (set_attr "bdver1_decode" "vector")])
9183
9184 (define_insn "x86_shld"
9185   [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m")
9186         (ior:SI (ashift:SI (match_dup 0)
9187                   (match_operand:QI 2 "nonmemory_operand" "Ic"))
9188                 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
9189                   (minus:QI (const_int 32) (match_dup 2)))))
9190    (clobber (reg:CC FLAGS_REG))]
9191   ""
9192   "shld{l}\t{%s2%1, %0|%0, %1, %2}"
9193   [(set_attr "type" "ishift")
9194    (set_attr "prefix_0f" "1")
9195    (set_attr "mode" "SI")
9196    (set_attr "pent_pair" "np")
9197    (set_attr "athlon_decode" "vector")
9198    (set_attr "amdfam10_decode" "vector")
9199    (set_attr "bdver1_decode" "vector")])
9200
9201 (define_expand "x86_shift<mode>_adj_1"
9202   [(set (reg:CCZ FLAGS_REG)
9203         (compare:CCZ (and:QI (match_operand:QI 2 "register_operand" "")
9204                              (match_dup 4))
9205                      (const_int 0)))
9206    (set (match_operand:SWI48 0 "register_operand" "")
9207         (if_then_else:SWI48 (ne (reg:CCZ FLAGS_REG) (const_int 0))
9208                             (match_operand:SWI48 1 "register_operand" "")
9209                             (match_dup 0)))
9210    (set (match_dup 1)
9211         (if_then_else:SWI48 (ne (reg:CCZ FLAGS_REG) (const_int 0))
9212                             (match_operand:SWI48 3 "register_operand" "r")
9213                             (match_dup 1)))]
9214   "TARGET_CMOVE"
9215   "operands[4] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));")
9216
9217 (define_expand "x86_shift<mode>_adj_2"
9218   [(use (match_operand:SWI48 0 "register_operand" ""))
9219    (use (match_operand:SWI48 1 "register_operand" ""))
9220    (use (match_operand:QI 2 "register_operand" ""))]
9221   ""
9222 {
9223   rtx label = gen_label_rtx ();
9224   rtx tmp;
9225
9226   emit_insn (gen_testqi_ccz_1 (operands[2],
9227                                GEN_INT (GET_MODE_BITSIZE (<MODE>mode))));
9228
9229   tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
9230   tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
9231   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
9232                               gen_rtx_LABEL_REF (VOIDmode, label),
9233                               pc_rtx);
9234   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
9235   JUMP_LABEL (tmp) = label;
9236
9237   emit_move_insn (operands[0], operands[1]);
9238   ix86_expand_clear (operands[1]);
9239
9240   emit_label (label);
9241   LABEL_NUSES (label) = 1;
9242
9243   DONE;
9244 })
9245
9246 ;; Avoid useless masking of count operand.
9247 (define_insn_and_split "*ashl<mode>3_mask"
9248   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm")
9249         (ashift:SWI48
9250           (match_operand:SWI48 1 "nonimmediate_operand" "0")
9251           (subreg:QI
9252             (and:SI
9253               (match_operand:SI 2 "nonimmediate_operand" "c")
9254               (match_operand:SI 3 "const_int_operand" "n")) 0)))
9255    (clobber (reg:CC FLAGS_REG))]
9256   "ix86_binary_operator_ok (ASHIFT, <MODE>mode, operands)
9257    && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode)-1))
9258       == GET_MODE_BITSIZE (<MODE>mode)-1"
9259   "#"
9260   "&& 1"
9261   [(parallel [(set (match_dup 0)
9262                    (ashift:SWI48 (match_dup 1) (match_dup 2)))
9263               (clobber (reg:CC FLAGS_REG))])]
9264 {
9265   if (can_create_pseudo_p ())
9266     operands [2] = force_reg (SImode, operands[2]);
9267
9268   operands[2] = simplify_gen_subreg (QImode, operands[2], SImode, 0);
9269 }
9270   [(set_attr "type" "ishift")
9271    (set_attr "mode" "<MODE>")])
9272
9273 (define_insn "*ashl<mode>3_1"
9274   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,r")
9275         (ashift:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "0,l")
9276                       (match_operand:QI 2 "nonmemory_operand" "c<S>,M")))
9277    (clobber (reg:CC FLAGS_REG))]
9278   "ix86_binary_operator_ok (ASHIFT, <MODE>mode, operands)"
9279 {
9280   switch (get_attr_type (insn))
9281     {
9282     case TYPE_LEA:
9283       return "#";
9284
9285     case TYPE_ALU:
9286       gcc_assert (operands[2] == const1_rtx);
9287       gcc_assert (rtx_equal_p (operands[0], operands[1]));
9288       return "add{<imodesuffix>}\t%0, %0";
9289
9290     default:
9291       if (operands[2] == const1_rtx
9292           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9293         return "sal{<imodesuffix>}\t%0";
9294       else
9295         return "sal{<imodesuffix>}\t{%2, %0|%0, %2}";
9296     }
9297 }
9298   [(set (attr "type")
9299      (cond [(eq_attr "alternative" "1")
9300               (const_string "lea")
9301             (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
9302                           (const_int 0))
9303                       (match_operand 0 "register_operand" ""))
9304                  (match_operand 2 "const1_operand" ""))
9305               (const_string "alu")
9306            ]
9307            (const_string "ishift")))
9308    (set (attr "length_immediate")
9309      (if_then_else
9310        (ior (eq_attr "type" "alu")
9311             (and (eq_attr "type" "ishift")
9312                  (and (match_operand 2 "const1_operand" "")
9313                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
9314                           (const_int 0)))))
9315        (const_string "0")
9316        (const_string "*")))
9317    (set_attr "mode" "<MODE>")])
9318
9319 (define_insn "*ashlsi3_1_zext"
9320   [(set (match_operand:DI 0 "register_operand" "=r,r")
9321         (zero_extend:DI
9322           (ashift:SI (match_operand:SI 1 "register_operand" "0,l")
9323                      (match_operand:QI 2 "nonmemory_operand" "cI,M"))))
9324    (clobber (reg:CC FLAGS_REG))]
9325   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
9326 {
9327   switch (get_attr_type (insn))
9328     {
9329     case TYPE_LEA:
9330       return "#";
9331
9332     case TYPE_ALU:
9333       gcc_assert (operands[2] == const1_rtx);
9334       return "add{l}\t%k0, %k0";
9335
9336     default:
9337       if (operands[2] == const1_rtx
9338           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9339         return "sal{l}\t%k0";
9340       else
9341         return "sal{l}\t{%2, %k0|%k0, %2}";
9342     }
9343 }
9344   [(set (attr "type")
9345      (cond [(eq_attr "alternative" "1")
9346               (const_string "lea")
9347             (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
9348                      (const_int 0))
9349                  (match_operand 2 "const1_operand" ""))
9350               (const_string "alu")
9351            ]
9352            (const_string "ishift")))
9353    (set (attr "length_immediate")
9354      (if_then_else
9355        (ior (eq_attr "type" "alu")
9356             (and (eq_attr "type" "ishift")
9357                  (and (match_operand 2 "const1_operand" "")
9358                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
9359                           (const_int 0)))))
9360        (const_string "0")
9361        (const_string "*")))
9362    (set_attr "mode" "SI")])
9363
9364 (define_insn "*ashlhi3_1"
9365   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
9366         (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0")
9367                    (match_operand:QI 2 "nonmemory_operand" "cI")))
9368    (clobber (reg:CC FLAGS_REG))]
9369   "TARGET_PARTIAL_REG_STALL
9370    && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
9371 {
9372   switch (get_attr_type (insn))
9373     {
9374     case TYPE_ALU:
9375       gcc_assert (operands[2] == const1_rtx);
9376       return "add{w}\t%0, %0";
9377
9378     default:
9379       if (operands[2] == const1_rtx
9380           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9381         return "sal{w}\t%0";
9382       else
9383         return "sal{w}\t{%2, %0|%0, %2}";
9384     }
9385 }
9386   [(set (attr "type")
9387      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
9388                           (const_int 0))
9389                       (match_operand 0 "register_operand" ""))
9390                  (match_operand 2 "const1_operand" ""))
9391               (const_string "alu")
9392            ]
9393            (const_string "ishift")))
9394    (set (attr "length_immediate")
9395      (if_then_else
9396        (ior (eq_attr "type" "alu")
9397             (and (eq_attr "type" "ishift")
9398                  (and (match_operand 2 "const1_operand" "")
9399                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
9400                           (const_int 0)))))
9401        (const_string "0")
9402        (const_string "*")))
9403    (set_attr "mode" "HI")])
9404
9405 (define_insn "*ashlhi3_1_lea"
9406   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r")
9407         (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0,l")
9408                    (match_operand:QI 2 "nonmemory_operand" "cI,M")))
9409    (clobber (reg:CC FLAGS_REG))]
9410   "!TARGET_PARTIAL_REG_STALL
9411    && ix86_binary_operator_ok (ASHIFT, HImode, operands)"
9412 {
9413   switch (get_attr_type (insn))
9414     {
9415     case TYPE_LEA:
9416       return "#";
9417
9418     case TYPE_ALU:
9419       gcc_assert (operands[2] == const1_rtx);
9420       return "add{w}\t%0, %0";
9421
9422     default:
9423       if (operands[2] == const1_rtx
9424           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9425         return "sal{w}\t%0";
9426       else
9427         return "sal{w}\t{%2, %0|%0, %2}";
9428     }
9429 }
9430   [(set (attr "type")
9431      (cond [(eq_attr "alternative" "1")
9432               (const_string "lea")
9433             (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
9434                           (const_int 0))
9435                       (match_operand 0 "register_operand" ""))
9436                  (match_operand 2 "const1_operand" ""))
9437               (const_string "alu")
9438            ]
9439            (const_string "ishift")))
9440    (set (attr "length_immediate")
9441      (if_then_else
9442        (ior (eq_attr "type" "alu")
9443             (and (eq_attr "type" "ishift")
9444                  (and (match_operand 2 "const1_operand" "")
9445                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
9446                           (const_int 0)))))
9447        (const_string "0")
9448        (const_string "*")))
9449    (set_attr "mode" "HI,SI")])
9450
9451 (define_insn "*ashlqi3_1"
9452   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r")
9453         (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0,0")
9454                    (match_operand:QI 2 "nonmemory_operand" "cI,cI")))
9455    (clobber (reg:CC FLAGS_REG))]
9456   "TARGET_PARTIAL_REG_STALL
9457    && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
9458 {
9459   switch (get_attr_type (insn))
9460     {
9461     case TYPE_ALU:
9462       gcc_assert (operands[2] == const1_rtx);
9463       if (REG_P (operands[1]) && !ANY_QI_REG_P (operands[1]))
9464         return "add{l}\t%k0, %k0";
9465       else
9466         return "add{b}\t%0, %0";
9467
9468     default:
9469       if (operands[2] == const1_rtx
9470           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9471         {
9472           if (get_attr_mode (insn) == MODE_SI)
9473             return "sal{l}\t%k0";
9474           else
9475             return "sal{b}\t%0";
9476         }
9477       else
9478         {
9479           if (get_attr_mode (insn) == MODE_SI)
9480             return "sal{l}\t{%2, %k0|%k0, %2}";
9481           else
9482             return "sal{b}\t{%2, %0|%0, %2}";
9483         }
9484     }
9485 }
9486   [(set (attr "type")
9487      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
9488                           (const_int 0))
9489                       (match_operand 0 "register_operand" ""))
9490                  (match_operand 2 "const1_operand" ""))
9491               (const_string "alu")
9492            ]
9493            (const_string "ishift")))
9494    (set (attr "length_immediate")
9495      (if_then_else
9496        (ior (eq_attr "type" "alu")
9497             (and (eq_attr "type" "ishift")
9498                  (and (match_operand 2 "const1_operand" "")
9499                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
9500                           (const_int 0)))))
9501        (const_string "0")
9502        (const_string "*")))
9503    (set_attr "mode" "QI,SI")])
9504
9505 ;; %%% Potential partial reg stall on alternative 2.  What to do?
9506 (define_insn "*ashlqi3_1_lea"
9507   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r,r")
9508         (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0,0,l")
9509                    (match_operand:QI 2 "nonmemory_operand" "cI,cI,M")))
9510    (clobber (reg:CC FLAGS_REG))]
9511   "!TARGET_PARTIAL_REG_STALL
9512    && ix86_binary_operator_ok (ASHIFT, QImode, operands)"
9513 {
9514   switch (get_attr_type (insn))
9515     {
9516     case TYPE_LEA:
9517       return "#";
9518
9519     case TYPE_ALU:
9520       gcc_assert (operands[2] == const1_rtx);
9521       if (REG_P (operands[1]) && !ANY_QI_REG_P (operands[1]))
9522         return "add{l}\t%k0, %k0";
9523       else
9524         return "add{b}\t%0, %0";
9525
9526     default:
9527       if (operands[2] == const1_rtx
9528           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9529         {
9530           if (get_attr_mode (insn) == MODE_SI)
9531             return "sal{l}\t%k0";
9532           else
9533             return "sal{b}\t%0";
9534         }
9535       else
9536         {
9537           if (get_attr_mode (insn) == MODE_SI)
9538             return "sal{l}\t{%2, %k0|%k0, %2}";
9539           else
9540             return "sal{b}\t{%2, %0|%0, %2}";
9541         }
9542     }
9543 }
9544   [(set (attr "type")
9545      (cond [(eq_attr "alternative" "2")
9546               (const_string "lea")
9547             (and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
9548                           (const_int 0))
9549                       (match_operand 0 "register_operand" ""))
9550                  (match_operand 2 "const1_operand" ""))
9551               (const_string "alu")
9552            ]
9553            (const_string "ishift")))
9554    (set (attr "length_immediate")
9555      (if_then_else
9556        (ior (eq_attr "type" "alu")
9557             (and (eq_attr "type" "ishift")
9558                  (and (match_operand 2 "const1_operand" "")
9559                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
9560                           (const_int 0)))))
9561        (const_string "0")
9562        (const_string "*")))
9563    (set_attr "mode" "QI,SI,SI")])
9564
9565 (define_insn "*ashlqi3_1_slp"
9566   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
9567         (ashift:QI (match_dup 0)
9568                    (match_operand:QI 1 "nonmemory_operand" "cI")))
9569    (clobber (reg:CC FLAGS_REG))]
9570   "(optimize_function_for_size_p (cfun)
9571     || !TARGET_PARTIAL_FLAG_REG_STALL
9572     || (operands[1] == const1_rtx
9573         && (TARGET_SHIFT1
9574             || (TARGET_DOUBLE_WITH_ADD && REG_P (operands[0])))))"
9575 {
9576   switch (get_attr_type (insn))
9577     {
9578     case TYPE_ALU:
9579       gcc_assert (operands[1] == const1_rtx);
9580       return "add{b}\t%0, %0";
9581
9582     default:
9583       if (operands[1] == const1_rtx
9584           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9585         return "sal{b}\t%0";
9586       else
9587         return "sal{b}\t{%1, %0|%0, %1}";
9588     }
9589 }
9590   [(set (attr "type")
9591      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
9592                           (const_int 0))
9593                       (match_operand 0 "register_operand" ""))
9594                  (match_operand 1 "const1_operand" ""))
9595               (const_string "alu")
9596            ]
9597            (const_string "ishift1")))
9598    (set (attr "length_immediate")
9599      (if_then_else
9600        (ior (eq_attr "type" "alu")
9601             (and (eq_attr "type" "ishift1")
9602                  (and (match_operand 1 "const1_operand" "")
9603                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
9604                           (const_int 0)))))
9605        (const_string "0")
9606        (const_string "*")))
9607    (set_attr "mode" "QI")])
9608
9609 ;; Convert lea to the lea pattern to avoid flags dependency.
9610 (define_split
9611   [(set (match_operand 0 "register_operand" "")
9612         (ashift (match_operand 1 "index_register_operand" "")
9613                 (match_operand:QI 2 "const_int_operand" "")))
9614    (clobber (reg:CC FLAGS_REG))]
9615   "reload_completed
9616    && true_regnum (operands[0]) != true_regnum (operands[1])"
9617   [(const_int 0)]
9618 {
9619   rtx pat;
9620   enum machine_mode mode = GET_MODE (operands[0]);
9621
9622   if (mode != Pmode)
9623     operands[1] = gen_lowpart (Pmode, operands[1]);
9624   operands[2] = gen_int_mode (1 << INTVAL (operands[2]), Pmode);
9625
9626   pat = gen_rtx_MULT (Pmode, operands[1], operands[2]);
9627
9628   if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (SImode))
9629     operands[0] = gen_lowpart (SImode, operands[0]);
9630
9631   if (TARGET_64BIT && mode != Pmode)
9632     pat = gen_rtx_SUBREG (SImode, pat, 0);
9633
9634   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
9635   DONE;
9636 })
9637
9638 ;; Convert lea to the lea pattern to avoid flags dependency.
9639 (define_split
9640   [(set (match_operand:DI 0 "register_operand" "")
9641         (zero_extend:DI
9642           (ashift:SI (match_operand:SI 1 "index_register_operand" "")
9643                      (match_operand:QI 2 "const_int_operand" ""))))
9644    (clobber (reg:CC FLAGS_REG))]
9645   "TARGET_64BIT && reload_completed
9646    && true_regnum (operands[0]) != true_regnum (operands[1])"
9647   [(set (match_dup 0)
9648         (zero_extend:DI (subreg:SI (mult:DI (match_dup 1) (match_dup 2)) 0)))]
9649 {
9650   operands[1] = gen_lowpart (DImode, operands[1]);
9651   operands[2] = gen_int_mode (1 << INTVAL (operands[2]), DImode);
9652 })
9653
9654 ;; This pattern can't accept a variable shift count, since shifts by
9655 ;; zero don't affect the flags.  We assume that shifts by constant
9656 ;; zero are optimized away.
9657 (define_insn "*ashl<mode>3_cmp"
9658   [(set (reg FLAGS_REG)
9659         (compare
9660           (ashift:SWI (match_operand:SWI 1 "nonimmediate_operand" "0")
9661                       (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
9662           (const_int 0)))
9663    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
9664         (ashift:SWI (match_dup 1) (match_dup 2)))]
9665   "(optimize_function_for_size_p (cfun)
9666     || !TARGET_PARTIAL_FLAG_REG_STALL
9667     || (operands[2] == const1_rtx
9668         && (TARGET_SHIFT1
9669             || (TARGET_DOUBLE_WITH_ADD && REG_P (operands[0])))))
9670    && ix86_match_ccmode (insn, CCGOCmode)
9671    && ix86_binary_operator_ok (ASHIFT, <MODE>mode, operands)"
9672 {
9673   switch (get_attr_type (insn))
9674     {
9675     case TYPE_ALU:
9676       gcc_assert (operands[2] == const1_rtx);
9677       return "add{<imodesuffix>}\t%0, %0";
9678
9679     default:
9680       if (operands[2] == const1_rtx
9681           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9682         return "sal{<imodesuffix>}\t%0";
9683       else
9684         return "sal{<imodesuffix>}\t{%2, %0|%0, %2}";
9685     }
9686 }
9687   [(set (attr "type")
9688      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
9689                           (const_int 0))
9690                       (match_operand 0 "register_operand" ""))
9691                  (match_operand 2 "const1_operand" ""))
9692               (const_string "alu")
9693            ]
9694            (const_string "ishift")))
9695    (set (attr "length_immediate")
9696      (if_then_else
9697        (ior (eq_attr "type" "alu")
9698             (and (eq_attr "type" "ishift")
9699                  (and (match_operand 2 "const1_operand" "")
9700                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
9701                           (const_int 0)))))
9702        (const_string "0")
9703        (const_string "*")))
9704    (set_attr "mode" "<MODE>")])
9705
9706 (define_insn "*ashlsi3_cmp_zext"
9707   [(set (reg FLAGS_REG)
9708         (compare
9709           (ashift:SI (match_operand:SI 1 "register_operand" "0")
9710                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
9711           (const_int 0)))
9712    (set (match_operand:DI 0 "register_operand" "=r")
9713         (zero_extend:DI (ashift:SI (match_dup 1) (match_dup 2))))]
9714   "TARGET_64BIT
9715    && (optimize_function_for_size_p (cfun)
9716        || !TARGET_PARTIAL_FLAG_REG_STALL
9717        || (operands[2] == const1_rtx
9718            && (TARGET_SHIFT1
9719                || TARGET_DOUBLE_WITH_ADD)))
9720    && ix86_match_ccmode (insn, CCGOCmode)
9721    && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
9722 {
9723   switch (get_attr_type (insn))
9724     {
9725     case TYPE_ALU:
9726       gcc_assert (operands[2] == const1_rtx);
9727       return "add{l}\t%k0, %k0";
9728
9729     default:
9730       if (operands[2] == const1_rtx
9731           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9732         return "sal{l}\t%k0";
9733       else
9734         return "sal{l}\t{%2, %k0|%k0, %2}";
9735     }
9736 }
9737   [(set (attr "type")
9738      (cond [(and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
9739                      (const_int 0))
9740                  (match_operand 2 "const1_operand" ""))
9741               (const_string "alu")
9742            ]
9743            (const_string "ishift")))
9744    (set (attr "length_immediate")
9745      (if_then_else
9746        (ior (eq_attr "type" "alu")
9747             (and (eq_attr "type" "ishift")
9748                  (and (match_operand 2 "const1_operand" "")
9749                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
9750                           (const_int 0)))))
9751        (const_string "0")
9752        (const_string "*")))
9753    (set_attr "mode" "SI")])
9754
9755 (define_insn "*ashl<mode>3_cconly"
9756   [(set (reg FLAGS_REG)
9757         (compare
9758           (ashift:SWI (match_operand:SWI 1 "register_operand" "0")
9759                       (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
9760           (const_int 0)))
9761    (clobber (match_scratch:SWI 0 "=<r>"))]
9762   "(optimize_function_for_size_p (cfun)
9763     || !TARGET_PARTIAL_FLAG_REG_STALL
9764     || (operands[2] == const1_rtx
9765         && (TARGET_SHIFT1
9766             || TARGET_DOUBLE_WITH_ADD)))
9767    && ix86_match_ccmode (insn, CCGOCmode)"
9768 {
9769   switch (get_attr_type (insn))
9770     {
9771     case TYPE_ALU:
9772       gcc_assert (operands[2] == const1_rtx);
9773       return "add{<imodesuffix>}\t%0, %0";
9774
9775     default:
9776       if (operands[2] == const1_rtx
9777           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9778         return "sal{<imodesuffix>}\t%0";
9779       else
9780         return "sal{<imodesuffix>}\t{%2, %0|%0, %2}";
9781     }
9782 }
9783   [(set (attr "type")
9784      (cond [(and (and (ne (symbol_ref "TARGET_DOUBLE_WITH_ADD")
9785                           (const_int 0))
9786                       (match_operand 0 "register_operand" ""))
9787                  (match_operand 2 "const1_operand" ""))
9788               (const_string "alu")
9789            ]
9790            (const_string "ishift")))
9791    (set (attr "length_immediate")
9792      (if_then_else
9793        (ior (eq_attr "type" "alu")
9794             (and (eq_attr "type" "ishift")
9795                  (and (match_operand 2 "const1_operand" "")
9796                       (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
9797                           (const_int 0)))))
9798        (const_string "0")
9799        (const_string "*")))
9800    (set_attr "mode" "<MODE>")])
9801
9802 ;; See comment above `ashl<mode>3' about how this works.
9803
9804 (define_expand "<shiftrt_insn><mode>3"
9805   [(set (match_operand:SDWIM 0 "<shift_operand>" "")
9806         (any_shiftrt:SDWIM (match_operand:SDWIM 1 "<shift_operand>" "")
9807                            (match_operand:QI 2 "nonmemory_operand" "")))]
9808   ""
9809   "ix86_expand_binary_operator (<CODE>, <MODE>mode, operands); DONE;")
9810
9811 ;; Avoid useless masking of count operand.
9812 (define_insn_and_split "*<shiftrt_insn><mode>3_mask"
9813   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm")
9814         (any_shiftrt:SWI48
9815           (match_operand:SWI48 1 "nonimmediate_operand" "0")
9816           (subreg:QI
9817             (and:SI
9818               (match_operand:SI 2 "nonimmediate_operand" "c")
9819               (match_operand:SI 3 "const_int_operand" "n")) 0)))
9820    (clobber (reg:CC FLAGS_REG))]
9821   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)
9822    && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode)-1))
9823       == GET_MODE_BITSIZE (<MODE>mode)-1"
9824   "#"
9825   "&& 1"
9826   [(parallel [(set (match_dup 0)
9827                    (any_shiftrt:SWI48 (match_dup 1) (match_dup 2)))
9828               (clobber (reg:CC FLAGS_REG))])]
9829 {
9830   if (can_create_pseudo_p ())
9831     operands [2] = force_reg (SImode, operands[2]);
9832
9833   operands[2] = simplify_gen_subreg (QImode, operands[2], SImode, 0);
9834 }
9835   [(set_attr "type" "ishift")
9836    (set_attr "mode" "<MODE>")])
9837
9838 (define_insn_and_split "*<shiftrt_insn><mode>3_doubleword"
9839   [(set (match_operand:DWI 0 "register_operand" "=r")
9840         (any_shiftrt:DWI (match_operand:DWI 1 "register_operand" "0")
9841                          (match_operand:QI 2 "nonmemory_operand" "<S>c")))
9842    (clobber (reg:CC FLAGS_REG))]
9843   ""
9844   "#"
9845   "(optimize && flag_peephole2) ? epilogue_completed : reload_completed"
9846   [(const_int 0)]
9847   "ix86_split_<shiftrt_insn> (operands, NULL_RTX, <MODE>mode); DONE;"
9848   [(set_attr "type" "multi")])
9849
9850 ;; By default we don't ask for a scratch register, because when DWImode
9851 ;; values are manipulated, registers are already at a premium.  But if
9852 ;; we have one handy, we won't turn it away.
9853
9854 (define_peephole2
9855   [(match_scratch:DWIH 3 "r")
9856    (parallel [(set (match_operand:<DWI> 0 "register_operand" "")
9857                    (any_shiftrt:<DWI>
9858                      (match_operand:<DWI> 1 "register_operand" "")
9859                      (match_operand:QI 2 "nonmemory_operand" "")))
9860               (clobber (reg:CC FLAGS_REG))])
9861    (match_dup 3)]
9862   "TARGET_CMOVE"
9863   [(const_int 0)]
9864   "ix86_split_<shiftrt_insn> (operands, operands[3], <DWI>mode); DONE;")
9865
9866 (define_insn "x86_64_shrd"
9867   [(set (match_operand:DI 0 "nonimmediate_operand" "+r*m")
9868         (ior:DI (ashiftrt:DI (match_dup 0)
9869                   (match_operand:QI 2 "nonmemory_operand" "Jc"))
9870                 (ashift:DI (match_operand:DI 1 "register_operand" "r")
9871                   (minus:QI (const_int 64) (match_dup 2)))))
9872    (clobber (reg:CC FLAGS_REG))]
9873   "TARGET_64BIT"
9874   "shrd{q}\t{%s2%1, %0|%0, %1, %2}"
9875   [(set_attr "type" "ishift")
9876    (set_attr "prefix_0f" "1")
9877    (set_attr "mode" "DI")
9878    (set_attr "athlon_decode" "vector")
9879    (set_attr "amdfam10_decode" "vector")
9880    (set_attr "bdver1_decode" "vector")])
9881
9882 (define_insn "x86_shrd"
9883   [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m")
9884         (ior:SI (ashiftrt:SI (match_dup 0)
9885                   (match_operand:QI 2 "nonmemory_operand" "Ic"))
9886                 (ashift:SI (match_operand:SI 1 "register_operand" "r")
9887                   (minus:QI (const_int 32) (match_dup 2)))))
9888    (clobber (reg:CC FLAGS_REG))]
9889   ""
9890   "shrd{l}\t{%s2%1, %0|%0, %1, %2}"
9891   [(set_attr "type" "ishift")
9892    (set_attr "prefix_0f" "1")
9893    (set_attr "mode" "SI")
9894    (set_attr "pent_pair" "np")
9895    (set_attr "athlon_decode" "vector")
9896    (set_attr "amdfam10_decode" "vector")
9897    (set_attr "bdver1_decode" "vector")])
9898
9899 (define_insn "ashrdi3_cvt"
9900   [(set (match_operand:DI 0 "nonimmediate_operand" "=*d,rm")
9901         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "*a,0")
9902                      (match_operand:QI 2 "const_int_operand" "")))
9903    (clobber (reg:CC FLAGS_REG))]
9904   "TARGET_64BIT && INTVAL (operands[2]) == 63
9905    && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
9906    && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
9907   "@
9908    {cqto|cqo}
9909    sar{q}\t{%2, %0|%0, %2}"
9910   [(set_attr "type" "imovx,ishift")
9911    (set_attr "prefix_0f" "0,*")
9912    (set_attr "length_immediate" "0,*")
9913    (set_attr "modrm" "0,1")
9914    (set_attr "mode" "DI")])
9915
9916 (define_insn "ashrsi3_cvt"
9917   [(set (match_operand:SI 0 "nonimmediate_operand" "=*d,rm")
9918         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "*a,0")
9919                      (match_operand:QI 2 "const_int_operand" "")))
9920    (clobber (reg:CC FLAGS_REG))]
9921   "INTVAL (operands[2]) == 31
9922    && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
9923    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
9924   "@
9925    {cltd|cdq}
9926    sar{l}\t{%2, %0|%0, %2}"
9927   [(set_attr "type" "imovx,ishift")
9928    (set_attr "prefix_0f" "0,*")
9929    (set_attr "length_immediate" "0,*")
9930    (set_attr "modrm" "0,1")
9931    (set_attr "mode" "SI")])
9932
9933 (define_insn "*ashrsi3_cvt_zext"
9934   [(set (match_operand:DI 0 "register_operand" "=*d,r")
9935         (zero_extend:DI
9936           (ashiftrt:SI (match_operand:SI 1 "register_operand" "*a,0")
9937                        (match_operand:QI 2 "const_int_operand" ""))))
9938    (clobber (reg:CC FLAGS_REG))]
9939   "TARGET_64BIT && INTVAL (operands[2]) == 31
9940    && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
9941    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
9942   "@
9943    {cltd|cdq}
9944    sar{l}\t{%2, %k0|%k0, %2}"
9945   [(set_attr "type" "imovx,ishift")
9946    (set_attr "prefix_0f" "0,*")
9947    (set_attr "length_immediate" "0,*")
9948    (set_attr "modrm" "0,1")
9949    (set_attr "mode" "SI")])
9950
9951 (define_expand "x86_shift<mode>_adj_3"
9952   [(use (match_operand:SWI48 0 "register_operand" ""))
9953    (use (match_operand:SWI48 1 "register_operand" ""))
9954    (use (match_operand:QI 2 "register_operand" ""))]
9955   ""
9956 {
9957   rtx label = gen_label_rtx ();
9958   rtx tmp;
9959
9960   emit_insn (gen_testqi_ccz_1 (operands[2],
9961                                GEN_INT (GET_MODE_BITSIZE (<MODE>mode))));
9962
9963   tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
9964   tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
9965   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
9966                               gen_rtx_LABEL_REF (VOIDmode, label),
9967                               pc_rtx);
9968   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
9969   JUMP_LABEL (tmp) = label;
9970
9971   emit_move_insn (operands[0], operands[1]);
9972   emit_insn (gen_ashr<mode>3_cvt (operands[1], operands[1],
9973                                   GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1)));
9974   emit_label (label);
9975   LABEL_NUSES (label) = 1;
9976
9977   DONE;
9978 })
9979
9980 (define_insn "*<shiftrt_insn><mode>3_1"
9981   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
9982         (any_shiftrt:SWI (match_operand:SWI 1 "nonimmediate_operand" "0")
9983                          (match_operand:QI 2 "nonmemory_operand" "c<S>")))
9984    (clobber (reg:CC FLAGS_REG))]
9985   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
9986 {
9987   if (operands[2] == const1_rtx
9988       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9989     return "<shiftrt>{<imodesuffix>}\t%0";
9990   else
9991     return "<shiftrt>{<imodesuffix>}\t{%2, %0|%0, %2}";
9992 }
9993   [(set_attr "type" "ishift")
9994    (set (attr "length_immediate")
9995      (if_then_else
9996        (and (match_operand 2 "const1_operand" "")
9997             (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
9998                 (const_int 0)))
9999        (const_string "0")
10000        (const_string "*")))
10001    (set_attr "mode" "<MODE>")])
10002
10003 (define_insn "*<shiftrt_insn>si3_1_zext"
10004   [(set (match_operand:DI 0 "register_operand" "=r")
10005         (zero_extend:DI
10006           (any_shiftrt:SI (match_operand:SI 1 "register_operand" "0")
10007                           (match_operand:QI 2 "nonmemory_operand" "cI"))))
10008    (clobber (reg:CC FLAGS_REG))]
10009   "TARGET_64BIT && ix86_binary_operator_ok (<CODE>, SImode, operands)"
10010 {
10011   if (operands[2] == const1_rtx
10012       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10013     return "<shiftrt>{l}\t%k0";
10014   else
10015     return "<shiftrt>{l}\t{%2, %k0|%k0, %2}";
10016 }
10017   [(set_attr "type" "ishift")
10018    (set (attr "length_immediate")
10019      (if_then_else
10020        (and (match_operand 2 "const1_operand" "")
10021             (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
10022                 (const_int 0)))
10023        (const_string "0")
10024        (const_string "*")))
10025    (set_attr "mode" "SI")])
10026
10027 (define_insn "*<shiftrt_insn>qi3_1_slp"
10028   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
10029         (any_shiftrt:QI (match_dup 0)
10030                         (match_operand:QI 1 "nonmemory_operand" "cI")))
10031    (clobber (reg:CC FLAGS_REG))]
10032   "(optimize_function_for_size_p (cfun)
10033     || !TARGET_PARTIAL_REG_STALL
10034     || (operands[1] == const1_rtx
10035         && TARGET_SHIFT1))"
10036 {
10037   if (operands[1] == const1_rtx
10038       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10039     return "<shiftrt>{b}\t%0";
10040   else
10041     return "<shiftrt>{b}\t{%1, %0|%0, %1}";
10042 }
10043   [(set_attr "type" "ishift1")
10044    (set (attr "length_immediate")
10045      (if_then_else
10046        (and (match_operand 1 "const1_operand" "")
10047             (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
10048                 (const_int 0)))
10049        (const_string "0")
10050        (const_string "*")))
10051    (set_attr "mode" "QI")])
10052
10053 ;; This pattern can't accept a variable shift count, since shifts by
10054 ;; zero don't affect the flags.  We assume that shifts by constant
10055 ;; zero are optimized away.
10056 (define_insn "*<shiftrt_insn><mode>3_cmp"
10057   [(set (reg FLAGS_REG)
10058         (compare
10059           (any_shiftrt:SWI
10060             (match_operand:SWI 1 "nonimmediate_operand" "0")
10061             (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
10062           (const_int 0)))
10063    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
10064         (any_shiftrt:SWI (match_dup 1) (match_dup 2)))]
10065   "(optimize_function_for_size_p (cfun)
10066     || !TARGET_PARTIAL_FLAG_REG_STALL
10067     || (operands[2] == const1_rtx
10068         && TARGET_SHIFT1))
10069    && ix86_match_ccmode (insn, CCGOCmode)
10070    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10071 {
10072   if (operands[2] == const1_rtx
10073       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10074     return "<shiftrt>{<imodesuffix>}\t%0";
10075   else
10076     return "<shiftrt>{<imodesuffix>}\t{%2, %0|%0, %2}";
10077 }
10078   [(set_attr "type" "ishift")
10079    (set (attr "length_immediate")
10080      (if_then_else
10081        (and (match_operand 2 "const1_operand" "")
10082             (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
10083                 (const_int 0)))
10084        (const_string "0")
10085        (const_string "*")))
10086    (set_attr "mode" "<MODE>")])
10087
10088 (define_insn "*<shiftrt_insn>si3_cmp_zext"
10089   [(set (reg FLAGS_REG)
10090         (compare
10091           (any_shiftrt:SI (match_operand:SI 1 "register_operand" "0")
10092                           (match_operand:QI 2 "const_1_to_31_operand" "I"))
10093           (const_int 0)))
10094    (set (match_operand:DI 0 "register_operand" "=r")
10095         (zero_extend:DI (any_shiftrt:SI (match_dup 1) (match_dup 2))))]
10096   "TARGET_64BIT
10097    && (optimize_function_for_size_p (cfun)
10098        || !TARGET_PARTIAL_FLAG_REG_STALL
10099        || (operands[2] == const1_rtx
10100            && TARGET_SHIFT1))
10101    && ix86_match_ccmode (insn, CCGOCmode)
10102    && ix86_binary_operator_ok (<CODE>, SImode, operands)"
10103 {
10104   if (operands[2] == const1_rtx
10105       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10106     return "<shiftrt>{l}\t%k0";
10107   else
10108     return "<shiftrt>{l}\t{%2, %k0|%k0, %2}";
10109 }
10110   [(set_attr "type" "ishift")
10111    (set (attr "length_immediate")
10112      (if_then_else
10113        (and (match_operand 2 "const1_operand" "")
10114             (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
10115                 (const_int 0)))
10116        (const_string "0")
10117        (const_string "*")))
10118    (set_attr "mode" "SI")])
10119
10120 (define_insn "*<shiftrt_insn><mode>3_cconly"
10121   [(set (reg FLAGS_REG)
10122         (compare
10123           (any_shiftrt:SWI
10124             (match_operand:SWI 1 "register_operand" "0")
10125             (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
10126           (const_int 0)))
10127    (clobber (match_scratch:SWI 0 "=<r>"))]
10128   "(optimize_function_for_size_p (cfun)
10129     || !TARGET_PARTIAL_FLAG_REG_STALL
10130     || (operands[2] == const1_rtx
10131         && TARGET_SHIFT1))
10132    && ix86_match_ccmode (insn, CCGOCmode)"
10133 {
10134   if (operands[2] == const1_rtx
10135       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10136     return "<shiftrt>{<imodesuffix>}\t%0";
10137   else
10138     return "<shiftrt>{<imodesuffix>}\t{%2, %0|%0, %2}";
10139 }
10140   [(set_attr "type" "ishift")
10141    (set (attr "length_immediate")
10142      (if_then_else
10143        (and (match_operand 2 "const1_operand" "")
10144             (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
10145                 (const_int 0)))
10146        (const_string "0")
10147        (const_string "*")))
10148    (set_attr "mode" "<MODE>")])
10149 \f
10150 ;; Rotate instructions
10151
10152 (define_expand "<rotate_insn>ti3"
10153   [(set (match_operand:TI 0 "register_operand" "")
10154         (any_rotate:TI (match_operand:TI 1 "register_operand" "")
10155                        (match_operand:QI 2 "nonmemory_operand" "")))]
10156   "TARGET_64BIT"
10157 {
10158   if (const_1_to_63_operand (operands[2], VOIDmode))
10159     emit_insn (gen_ix86_<rotate_insn>ti3_doubleword
10160                 (operands[0], operands[1], operands[2]));
10161   else
10162     FAIL;
10163
10164   DONE;
10165 })
10166
10167 (define_expand "<rotate_insn>di3"
10168   [(set (match_operand:DI 0 "shiftdi_operand" "")
10169         (any_rotate:DI (match_operand:DI 1 "shiftdi_operand" "")
10170                        (match_operand:QI 2 "nonmemory_operand" "")))]
10171  ""
10172 {
10173   if (TARGET_64BIT)
10174     ix86_expand_binary_operator (<CODE>, DImode, operands);
10175   else if (const_1_to_31_operand (operands[2], VOIDmode))
10176     emit_insn (gen_ix86_<rotate_insn>di3_doubleword
10177                 (operands[0], operands[1], operands[2]));
10178   else
10179     FAIL;
10180
10181   DONE;
10182 })
10183
10184 (define_expand "<rotate_insn><mode>3"
10185   [(set (match_operand:SWIM124 0 "nonimmediate_operand" "")
10186         (any_rotate:SWIM124 (match_operand:SWIM124 1 "nonimmediate_operand" "")
10187                             (match_operand:QI 2 "nonmemory_operand" "")))]
10188   ""
10189   "ix86_expand_binary_operator (<CODE>, <MODE>mode, operands); DONE;")
10190
10191 ;; Avoid useless masking of count operand.
10192 (define_insn_and_split "*<rotate_insn><mode>3_mask"
10193   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm")
10194         (any_rotate:SWI48
10195           (match_operand:SWI48 1 "nonimmediate_operand" "0")
10196           (subreg:QI
10197             (and:SI
10198               (match_operand:SI 2 "nonimmediate_operand" "c")
10199               (match_operand:SI 3 "const_int_operand" "n")) 0)))
10200    (clobber (reg:CC FLAGS_REG))]
10201   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)
10202    && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode)-1))
10203       == GET_MODE_BITSIZE (<MODE>mode)-1"
10204   "#"
10205   "&& 1"
10206   [(parallel [(set (match_dup 0)
10207                    (any_rotate:SWI48 (match_dup 1) (match_dup 2)))
10208               (clobber (reg:CC FLAGS_REG))])]
10209 {
10210   if (can_create_pseudo_p ())
10211     operands [2] = force_reg (SImode, operands[2]);
10212
10213   operands[2] = simplify_gen_subreg (QImode, operands[2], SImode, 0);
10214 }
10215   [(set_attr "type" "rotate")
10216    (set_attr "mode" "<MODE>")])
10217
10218 ;; Implement rotation using two double-precision
10219 ;; shift instructions and a scratch register.
10220
10221 (define_insn_and_split "ix86_rotl<dwi>3_doubleword"
10222  [(set (match_operand:<DWI> 0 "register_operand" "=r")
10223        (rotate:<DWI> (match_operand:<DWI> 1 "register_operand" "0")
10224                      (match_operand:QI 2 "<shift_immediate_operand>" "<S>")))
10225   (clobber (reg:CC FLAGS_REG))
10226   (clobber (match_scratch:DWIH 3 "=&r"))]
10227  ""
10228  "#"
10229  "reload_completed"
10230  [(set (match_dup 3) (match_dup 4))
10231   (parallel
10232    [(set (match_dup 4)
10233          (ior:DWIH (ashift:DWIH (match_dup 4) (match_dup 2))
10234                    (lshiftrt:DWIH (match_dup 5)
10235                                   (minus:QI (match_dup 6) (match_dup 2)))))
10236     (clobber (reg:CC FLAGS_REG))])
10237   (parallel
10238    [(set (match_dup 5)
10239          (ior:DWIH (ashift:DWIH (match_dup 5) (match_dup 2))
10240                    (lshiftrt:DWIH (match_dup 3)
10241                                   (minus:QI (match_dup 6) (match_dup 2)))))
10242     (clobber (reg:CC FLAGS_REG))])]
10243 {
10244   operands[6] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
10245
10246   split_double_mode (<DWI>mode, &operands[0], 1, &operands[4], &operands[5]);
10247 })
10248
10249 (define_insn_and_split "ix86_rotr<dwi>3_doubleword"
10250  [(set (match_operand:<DWI> 0 "register_operand" "=r")
10251        (rotatert:<DWI> (match_operand:<DWI> 1 "register_operand" "0")
10252                        (match_operand:QI 2 "<shift_immediate_operand>" "<S>")))
10253   (clobber (reg:CC FLAGS_REG))
10254   (clobber (match_scratch:DWIH 3 "=&r"))]
10255  ""
10256  "#"
10257  "reload_completed"
10258  [(set (match_dup 3) (match_dup 4))
10259   (parallel
10260    [(set (match_dup 4)
10261          (ior:DWIH (ashiftrt:DWIH (match_dup 4) (match_dup 2))
10262                    (ashift:DWIH (match_dup 5)
10263                                 (minus:QI (match_dup 6) (match_dup 2)))))
10264     (clobber (reg:CC FLAGS_REG))])
10265   (parallel
10266    [(set (match_dup 5)
10267          (ior:DWIH (ashiftrt:DWIH (match_dup 5) (match_dup 2))
10268                    (ashift:DWIH (match_dup 3)
10269                                 (minus:QI (match_dup 6) (match_dup 2)))))
10270     (clobber (reg:CC FLAGS_REG))])]
10271 {
10272   operands[6] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
10273
10274   split_double_mode (<DWI>mode, &operands[0], 1, &operands[4], &operands[5]);
10275 })
10276
10277 (define_insn "*<rotate_insn><mode>3_1"
10278   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
10279         (any_rotate:SWI (match_operand:SWI 1 "nonimmediate_operand" "0")
10280                         (match_operand:QI 2 "nonmemory_operand" "c<S>")))
10281    (clobber (reg:CC FLAGS_REG))]
10282   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10283 {
10284   if (operands[2] == const1_rtx
10285       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10286     return "<rotate>{<imodesuffix>}\t%0";
10287   else
10288     return "<rotate>{<imodesuffix>}\t{%2, %0|%0, %2}";
10289 }
10290   [(set_attr "type" "rotate")
10291    (set (attr "length_immediate")
10292      (if_then_else
10293        (and (match_operand 2 "const1_operand" "")
10294             (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
10295                 (const_int 0)))
10296        (const_string "0")
10297        (const_string "*")))
10298    (set_attr "mode" "<MODE>")])
10299
10300 (define_insn "*<rotate_insn>si3_1_zext"
10301   [(set (match_operand:DI 0 "register_operand" "=r")
10302         (zero_extend:DI
10303           (any_rotate:SI (match_operand:SI 1 "register_operand" "0")
10304                          (match_operand:QI 2 "nonmemory_operand" "cI"))))
10305    (clobber (reg:CC FLAGS_REG))]
10306   "TARGET_64BIT && ix86_binary_operator_ok (<CODE>, SImode, operands)"
10307 {
10308     if (operands[2] == const1_rtx
10309         && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10310     return "<rotate>{l}\t%k0";
10311   else
10312     return "<rotate>{l}\t{%2, %k0|%k0, %2}";
10313 }
10314   [(set_attr "type" "rotate")
10315    (set (attr "length_immediate")
10316      (if_then_else
10317        (and (match_operand 2 "const1_operand" "")
10318             (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
10319                 (const_int 0)))
10320        (const_string "0")
10321        (const_string "*")))
10322    (set_attr "mode" "SI")])
10323
10324 (define_insn "*<rotate_insn>qi3_1_slp"
10325   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
10326         (any_rotate:QI (match_dup 0)
10327                        (match_operand:QI 1 "nonmemory_operand" "cI")))
10328    (clobber (reg:CC FLAGS_REG))]
10329   "(optimize_function_for_size_p (cfun)
10330     || !TARGET_PARTIAL_REG_STALL
10331     || (operands[1] == const1_rtx
10332         && TARGET_SHIFT1))"
10333 {
10334   if (operands[1] == const1_rtx
10335       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10336     return "<rotate>{b}\t%0";
10337   else
10338     return "<rotate>{b}\t{%1, %0|%0, %1}";
10339 }
10340   [(set_attr "type" "rotate1")
10341    (set (attr "length_immediate")
10342      (if_then_else
10343        (and (match_operand 1 "const1_operand" "")
10344             (ne (symbol_ref "TARGET_SHIFT1 || optimize_function_for_size_p (cfun)")
10345                 (const_int 0)))
10346        (const_string "0")
10347        (const_string "*")))
10348    (set_attr "mode" "QI")])
10349
10350 (define_split
10351  [(set (match_operand:HI 0 "register_operand" "")
10352        (any_rotate:HI (match_dup 0) (const_int 8)))
10353   (clobber (reg:CC FLAGS_REG))]
10354  "reload_completed
10355   && (TARGET_USE_XCHGB || optimize_function_for_size_p (cfun))"
10356  [(parallel [(set (strict_low_part (match_dup 0))
10357                   (bswap:HI (match_dup 0)))
10358              (clobber (reg:CC FLAGS_REG))])])
10359 \f
10360 ;; Bit set / bit test instructions
10361
10362 (define_expand "extv"
10363   [(set (match_operand:SI 0 "register_operand" "")
10364         (sign_extract:SI (match_operand:SI 1 "register_operand" "")
10365                          (match_operand:SI 2 "const8_operand" "")
10366                          (match_operand:SI 3 "const8_operand" "")))]
10367   ""
10368 {
10369   /* Handle extractions from %ah et al.  */
10370   if (INTVAL (operands[2]) != 8 || INTVAL (operands[3]) != 8)
10371     FAIL;
10372
10373   /* From mips.md: extract_bit_field doesn't verify that our source
10374      matches the predicate, so check it again here.  */
10375   if (! ext_register_operand (operands[1], VOIDmode))
10376     FAIL;
10377 })
10378
10379 (define_expand "extzv"
10380   [(set (match_operand:SI 0 "register_operand" "")
10381         (zero_extract:SI (match_operand 1 "ext_register_operand" "")
10382                          (match_operand:SI 2 "const8_operand" "")
10383                          (match_operand:SI 3 "const8_operand" "")))]
10384   ""
10385 {
10386   /* Handle extractions from %ah et al.  */
10387   if (INTVAL (operands[2]) != 8 || INTVAL (operands[3]) != 8)
10388     FAIL;
10389
10390   /* From mips.md: extract_bit_field doesn't verify that our source
10391      matches the predicate, so check it again here.  */
10392   if (! ext_register_operand (operands[1], VOIDmode))
10393     FAIL;
10394 })
10395
10396 (define_expand "insv"
10397   [(set (zero_extract (match_operand 0 "register_operand" "")
10398                       (match_operand 1 "const_int_operand" "")
10399                       (match_operand 2 "const_int_operand" ""))
10400         (match_operand 3 "register_operand" ""))]
10401   ""
10402 {
10403   rtx (*gen_mov_insv_1) (rtx, rtx);
10404
10405   if (ix86_expand_pinsr (operands))
10406     DONE;
10407
10408   /* Handle insertions to %ah et al.  */
10409   if (INTVAL (operands[1]) != 8 || INTVAL (operands[2]) != 8)
10410     FAIL;
10411
10412   /* From mips.md: insert_bit_field doesn't verify that our source
10413      matches the predicate, so check it again here.  */
10414   if (! ext_register_operand (operands[0], VOIDmode))
10415     FAIL;
10416
10417   gen_mov_insv_1 = (TARGET_64BIT
10418                     ? gen_movdi_insv_1 : gen_movsi_insv_1);
10419
10420   emit_insn (gen_mov_insv_1 (operands[0], operands[3]));
10421   DONE;
10422 })
10423
10424 ;; %%% bts, btr, btc, bt.
10425 ;; In general these instructions are *slow* when applied to memory,
10426 ;; since they enforce atomic operation.  When applied to registers,
10427 ;; it depends on the cpu implementation.  They're never faster than
10428 ;; the corresponding and/ior/xor operations, so with 32-bit there's
10429 ;; no point.  But in 64-bit, we can't hold the relevant immediates
10430 ;; within the instruction itself, so operating on bits in the high
10431 ;; 32-bits of a register becomes easier.
10432 ;;
10433 ;; These are slow on Nocona, but fast on Athlon64.  We do require the use
10434 ;; of btrq and btcq for corner cases of post-reload expansion of absdf and
10435 ;; negdf respectively, so they can never be disabled entirely.
10436
10437 (define_insn "*btsq"
10438   [(set (zero_extract:DI (match_operand:DI 0 "register_operand" "+r")
10439                          (const_int 1)
10440                          (match_operand:DI 1 "const_0_to_63_operand" ""))
10441         (const_int 1))
10442    (clobber (reg:CC FLAGS_REG))]
10443   "TARGET_64BIT && (TARGET_USE_BT || reload_completed)"
10444   "bts{q}\t{%1, %0|%0, %1}"
10445   [(set_attr "type" "alu1")
10446    (set_attr "prefix_0f" "1")
10447    (set_attr "mode" "DI")])
10448
10449 (define_insn "*btrq"
10450   [(set (zero_extract:DI (match_operand:DI 0 "register_operand" "+r")
10451                          (const_int 1)
10452                          (match_operand:DI 1 "const_0_to_63_operand" ""))
10453         (const_int 0))
10454    (clobber (reg:CC FLAGS_REG))]
10455   "TARGET_64BIT && (TARGET_USE_BT || reload_completed)"
10456   "btr{q}\t{%1, %0|%0, %1}"
10457   [(set_attr "type" "alu1")
10458    (set_attr "prefix_0f" "1")
10459    (set_attr "mode" "DI")])
10460
10461 (define_insn "*btcq"
10462   [(set (zero_extract:DI (match_operand:DI 0 "register_operand" "+r")
10463                          (const_int 1)
10464                          (match_operand:DI 1 "const_0_to_63_operand" ""))
10465         (not:DI (zero_extract:DI (match_dup 0) (const_int 1) (match_dup 1))))
10466    (clobber (reg:CC FLAGS_REG))]
10467   "TARGET_64BIT && (TARGET_USE_BT || reload_completed)"
10468   "btc{q}\t{%1, %0|%0, %1}"
10469   [(set_attr "type" "alu1")
10470    (set_attr "prefix_0f" "1")
10471    (set_attr "mode" "DI")])
10472
10473 ;; Allow Nocona to avoid these instructions if a register is available.
10474
10475 (define_peephole2
10476   [(match_scratch:DI 2 "r")
10477    (parallel [(set (zero_extract:DI
10478                      (match_operand:DI 0 "register_operand" "")
10479                      (const_int 1)
10480                      (match_operand:DI 1 "const_0_to_63_operand" ""))
10481                    (const_int 1))
10482               (clobber (reg:CC FLAGS_REG))])]
10483   "TARGET_64BIT && !TARGET_USE_BT"
10484   [(const_int 0)]
10485 {
10486   HOST_WIDE_INT i = INTVAL (operands[1]), hi, lo;
10487   rtx op1;
10488
10489   if (HOST_BITS_PER_WIDE_INT >= 64)
10490     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10491   else if (i < HOST_BITS_PER_WIDE_INT)
10492     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10493   else
10494     lo = 0, hi = (HOST_WIDE_INT)1 << (i - HOST_BITS_PER_WIDE_INT);
10495
10496   op1 = immed_double_const (lo, hi, DImode);
10497   if (i >= 31)
10498     {
10499       emit_move_insn (operands[2], op1);
10500       op1 = operands[2];
10501     }
10502
10503   emit_insn (gen_iordi3 (operands[0], operands[0], op1));
10504   DONE;
10505 })
10506
10507 (define_peephole2
10508   [(match_scratch:DI 2 "r")
10509    (parallel [(set (zero_extract:DI
10510                      (match_operand:DI 0 "register_operand" "")
10511                      (const_int 1)
10512                      (match_operand:DI 1 "const_0_to_63_operand" ""))
10513                    (const_int 0))
10514               (clobber (reg:CC FLAGS_REG))])]
10515   "TARGET_64BIT && !TARGET_USE_BT"
10516   [(const_int 0)]
10517 {
10518   HOST_WIDE_INT i = INTVAL (operands[1]), hi, lo;
10519   rtx op1;
10520
10521   if (HOST_BITS_PER_WIDE_INT >= 64)
10522     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10523   else if (i < HOST_BITS_PER_WIDE_INT)
10524     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10525   else
10526     lo = 0, hi = (HOST_WIDE_INT)1 << (i - HOST_BITS_PER_WIDE_INT);
10527
10528   op1 = immed_double_const (~lo, ~hi, DImode);
10529   if (i >= 32)
10530     {
10531       emit_move_insn (operands[2], op1);
10532       op1 = operands[2];
10533     }
10534
10535   emit_insn (gen_anddi3 (operands[0], operands[0], op1));
10536   DONE;
10537 })
10538
10539 (define_peephole2
10540   [(match_scratch:DI 2 "r")
10541    (parallel [(set (zero_extract:DI
10542                      (match_operand:DI 0 "register_operand" "")
10543                      (const_int 1)
10544                      (match_operand:DI 1 "const_0_to_63_operand" ""))
10545               (not:DI (zero_extract:DI
10546                         (match_dup 0) (const_int 1) (match_dup 1))))
10547               (clobber (reg:CC FLAGS_REG))])]
10548   "TARGET_64BIT && !TARGET_USE_BT"
10549   [(const_int 0)]
10550 {
10551   HOST_WIDE_INT i = INTVAL (operands[1]), hi, lo;
10552   rtx op1;
10553
10554   if (HOST_BITS_PER_WIDE_INT >= 64)
10555     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10556   else if (i < HOST_BITS_PER_WIDE_INT)
10557     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10558   else
10559     lo = 0, hi = (HOST_WIDE_INT)1 << (i - HOST_BITS_PER_WIDE_INT);
10560
10561   op1 = immed_double_const (lo, hi, DImode);
10562   if (i >= 31)
10563     {
10564       emit_move_insn (operands[2], op1);
10565       op1 = operands[2];
10566     }
10567
10568   emit_insn (gen_xordi3 (operands[0], operands[0], op1));
10569   DONE;
10570 })
10571
10572 (define_insn "*bt<mode>"
10573   [(set (reg:CCC FLAGS_REG)
10574         (compare:CCC
10575           (zero_extract:SWI48
10576             (match_operand:SWI48 0 "register_operand" "r")
10577             (const_int 1)
10578             (match_operand:SWI48 1 "nonmemory_operand" "rN"))
10579           (const_int 0)))]
10580   "TARGET_USE_BT || optimize_function_for_size_p (cfun)"
10581   "bt{<imodesuffix>}\t{%1, %0|%0, %1}"
10582   [(set_attr "type" "alu1")
10583    (set_attr "prefix_0f" "1")
10584    (set_attr "mode" "<MODE>")])
10585 \f
10586 ;; Store-flag instructions.
10587
10588 ;; For all sCOND expanders, also expand the compare or test insn that
10589 ;; generates cc0.  Generate an equality comparison if `seq' or `sne'.
10590
10591 (define_insn_and_split "*setcc_di_1"
10592   [(set (match_operand:DI 0 "register_operand" "=q")
10593         (match_operator:DI 1 "ix86_comparison_operator"
10594           [(reg FLAGS_REG) (const_int 0)]))]
10595   "TARGET_64BIT && !TARGET_PARTIAL_REG_STALL"
10596   "#"
10597   "&& reload_completed"
10598   [(set (match_dup 2) (match_dup 1))
10599    (set (match_dup 0) (zero_extend:DI (match_dup 2)))]
10600 {
10601   PUT_MODE (operands[1], QImode);
10602   operands[2] = gen_lowpart (QImode, operands[0]);
10603 })
10604
10605 (define_insn_and_split "*setcc_si_1_and"
10606   [(set (match_operand:SI 0 "register_operand" "=q")
10607         (match_operator:SI 1 "ix86_comparison_operator"
10608           [(reg FLAGS_REG) (const_int 0)]))
10609    (clobber (reg:CC FLAGS_REG))]
10610   "!TARGET_PARTIAL_REG_STALL
10611    && TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
10612   "#"
10613   "&& reload_completed"
10614   [(set (match_dup 2) (match_dup 1))
10615    (parallel [(set (match_dup 0) (zero_extend:SI (match_dup 2)))
10616               (clobber (reg:CC FLAGS_REG))])]
10617 {
10618   PUT_MODE (operands[1], QImode);
10619   operands[2] = gen_lowpart (QImode, operands[0]);
10620 })
10621
10622 (define_insn_and_split "*setcc_si_1_movzbl"
10623   [(set (match_operand:SI 0 "register_operand" "=q")
10624         (match_operator:SI 1 "ix86_comparison_operator"
10625           [(reg FLAGS_REG) (const_int 0)]))]
10626   "!TARGET_PARTIAL_REG_STALL
10627    && (!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun))"
10628   "#"
10629   "&& reload_completed"
10630   [(set (match_dup 2) (match_dup 1))
10631    (set (match_dup 0) (zero_extend:SI (match_dup 2)))]
10632 {
10633   PUT_MODE (operands[1], QImode);
10634   operands[2] = gen_lowpart (QImode, operands[0]);
10635 })
10636
10637 (define_insn "*setcc_qi"
10638   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
10639         (match_operator:QI 1 "ix86_comparison_operator"
10640           [(reg FLAGS_REG) (const_int 0)]))]
10641   ""
10642   "set%C1\t%0"
10643   [(set_attr "type" "setcc")
10644    (set_attr "mode" "QI")])
10645
10646 (define_insn "*setcc_qi_slp"
10647   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
10648         (match_operator:QI 1 "ix86_comparison_operator"
10649           [(reg FLAGS_REG) (const_int 0)]))]
10650   ""
10651   "set%C1\t%0"
10652   [(set_attr "type" "setcc")
10653    (set_attr "mode" "QI")])
10654
10655 ;; In general it is not safe to assume too much about CCmode registers,
10656 ;; so simplify-rtx stops when it sees a second one.  Under certain
10657 ;; conditions this is safe on x86, so help combine not create
10658 ;;
10659 ;;      seta    %al
10660 ;;      testb   %al, %al
10661 ;;      sete    %al
10662
10663 (define_split
10664   [(set (match_operand:QI 0 "nonimmediate_operand" "")
10665         (ne:QI (match_operator 1 "ix86_comparison_operator"
10666                  [(reg FLAGS_REG) (const_int 0)])
10667             (const_int 0)))]
10668   ""
10669   [(set (match_dup 0) (match_dup 1))]
10670   "PUT_MODE (operands[1], QImode);")
10671
10672 (define_split
10673   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" ""))
10674         (ne:QI (match_operator 1 "ix86_comparison_operator"
10675                  [(reg FLAGS_REG) (const_int 0)])
10676             (const_int 0)))]
10677   ""
10678   [(set (match_dup 0) (match_dup 1))]
10679   "PUT_MODE (operands[1], QImode);")
10680
10681 (define_split
10682   [(set (match_operand:QI 0 "nonimmediate_operand" "")
10683         (eq:QI (match_operator 1 "ix86_comparison_operator"
10684                  [(reg FLAGS_REG) (const_int 0)])
10685             (const_int 0)))]
10686   ""
10687   [(set (match_dup 0) (match_dup 1))]
10688 {
10689   rtx new_op1 = copy_rtx (operands[1]);
10690   operands[1] = new_op1;
10691   PUT_MODE (new_op1, QImode);
10692   PUT_CODE (new_op1, ix86_reverse_condition (GET_CODE (new_op1),
10693                                              GET_MODE (XEXP (new_op1, 0))));
10694
10695   /* Make sure that (a) the CCmode we have for the flags is strong
10696      enough for the reversed compare or (b) we have a valid FP compare.  */
10697   if (! ix86_comparison_operator (new_op1, VOIDmode))
10698     FAIL;
10699 })
10700
10701 (define_split
10702   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" ""))
10703         (eq:QI (match_operator 1 "ix86_comparison_operator"
10704                  [(reg FLAGS_REG) (const_int 0)])
10705             (const_int 0)))]
10706   ""
10707   [(set (match_dup 0) (match_dup 1))]
10708 {
10709   rtx new_op1 = copy_rtx (operands[1]);
10710   operands[1] = new_op1;
10711   PUT_MODE (new_op1, QImode);
10712   PUT_CODE (new_op1, ix86_reverse_condition (GET_CODE (new_op1),
10713                                              GET_MODE (XEXP (new_op1, 0))));
10714
10715   /* Make sure that (a) the CCmode we have for the flags is strong
10716      enough for the reversed compare or (b) we have a valid FP compare.  */
10717   if (! ix86_comparison_operator (new_op1, VOIDmode))
10718     FAIL;
10719 })
10720
10721 ;; The SSE store flag instructions saves 0 or 0xffffffff to the result.
10722 ;; subsequent logical operations are used to imitate conditional moves.
10723 ;; 0xffffffff is NaN, but not in normalized form, so we can't represent
10724 ;; it directly.
10725
10726 (define_insn "setcc_<mode>_sse"
10727   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
10728         (match_operator:MODEF 3 "sse_comparison_operator"
10729           [(match_operand:MODEF 1 "register_operand" "0,x")
10730            (match_operand:MODEF 2 "nonimmediate_operand" "xm,xm")]))]
10731   "SSE_FLOAT_MODE_P (<MODE>mode)"
10732   "@
10733    cmp%D3<ssemodesuffix>\t{%2, %0|%0, %2}
10734    vcmp%D3<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
10735   [(set_attr "isa" "noavx,avx")
10736    (set_attr "type" "ssecmp")
10737    (set_attr "length_immediate" "1")
10738    (set_attr "prefix" "orig,vex")
10739    (set_attr "mode" "<MODE>")])
10740 \f
10741 ;; Basic conditional jump instructions.
10742 ;; We ignore the overflow flag for signed branch instructions.
10743
10744 (define_insn "*jcc_1"
10745   [(set (pc)
10746         (if_then_else (match_operator 1 "ix86_comparison_operator"
10747                                       [(reg FLAGS_REG) (const_int 0)])
10748                       (label_ref (match_operand 0 "" ""))
10749                       (pc)))]
10750   ""
10751   "%+j%C1\t%l0"
10752   [(set_attr "type" "ibr")
10753    (set_attr "modrm" "0")
10754    (set (attr "length")
10755            (if_then_else (and (ge (minus (match_dup 0) (pc))
10756                                   (const_int -126))
10757                               (lt (minus (match_dup 0) (pc))
10758                                   (const_int 128)))
10759              (const_int 2)
10760              (const_int 6)))])
10761
10762 (define_insn "*jcc_2"
10763   [(set (pc)
10764         (if_then_else (match_operator 1 "ix86_comparison_operator"
10765                                       [(reg FLAGS_REG) (const_int 0)])
10766                       (pc)
10767                       (label_ref (match_operand 0 "" ""))))]
10768   ""
10769   "%+j%c1\t%l0"
10770   [(set_attr "type" "ibr")
10771    (set_attr "modrm" "0")
10772    (set (attr "length")
10773            (if_then_else (and (ge (minus (match_dup 0) (pc))
10774                                   (const_int -126))
10775                               (lt (minus (match_dup 0) (pc))
10776                                   (const_int 128)))
10777              (const_int 2)
10778              (const_int 6)))])
10779
10780 ;; In general it is not safe to assume too much about CCmode registers,
10781 ;; so simplify-rtx stops when it sees a second one.  Under certain
10782 ;; conditions this is safe on x86, so help combine not create
10783 ;;
10784 ;;      seta    %al
10785 ;;      testb   %al, %al
10786 ;;      je      Lfoo
10787
10788 (define_split
10789   [(set (pc)
10790         (if_then_else (ne (match_operator 0 "ix86_comparison_operator"
10791                                       [(reg FLAGS_REG) (const_int 0)])
10792                           (const_int 0))
10793                       (label_ref (match_operand 1 "" ""))
10794                       (pc)))]
10795   ""
10796   [(set (pc)
10797         (if_then_else (match_dup 0)
10798                       (label_ref (match_dup 1))
10799                       (pc)))]
10800   "PUT_MODE (operands[0], VOIDmode);")
10801
10802 (define_split
10803   [(set (pc)
10804         (if_then_else (eq (match_operator 0 "ix86_comparison_operator"
10805                                       [(reg FLAGS_REG) (const_int 0)])
10806                           (const_int 0))
10807                       (label_ref (match_operand 1 "" ""))
10808                       (pc)))]
10809   ""
10810   [(set (pc)
10811         (if_then_else (match_dup 0)
10812                       (label_ref (match_dup 1))
10813                       (pc)))]
10814 {
10815   rtx new_op0 = copy_rtx (operands[0]);
10816   operands[0] = new_op0;
10817   PUT_MODE (new_op0, VOIDmode);
10818   PUT_CODE (new_op0, ix86_reverse_condition (GET_CODE (new_op0),
10819                                              GET_MODE (XEXP (new_op0, 0))));
10820
10821   /* Make sure that (a) the CCmode we have for the flags is strong
10822      enough for the reversed compare or (b) we have a valid FP compare.  */
10823   if (! ix86_comparison_operator (new_op0, VOIDmode))
10824     FAIL;
10825 })
10826
10827 ;; zero_extend in SImode is correct also for DImode, since this is what combine
10828 ;; pass generates from shift insn with QImode operand.  Actually, the mode
10829 ;; of operand 2 (bit offset operand) doesn't matter since bt insn takes
10830 ;; appropriate modulo of the bit offset value.
10831
10832 (define_insn_and_split "*jcc_bt<mode>"
10833   [(set (pc)
10834         (if_then_else (match_operator 0 "bt_comparison_operator"
10835                         [(zero_extract:SWI48
10836                            (match_operand:SWI48 1 "register_operand" "r")
10837                            (const_int 1)
10838                            (zero_extend:SI
10839                              (match_operand:QI 2 "register_operand" "r")))
10840                          (const_int 0)])
10841                       (label_ref (match_operand 3 "" ""))
10842                       (pc)))
10843    (clobber (reg:CC FLAGS_REG))]
10844   "TARGET_USE_BT || optimize_function_for_size_p (cfun)"
10845   "#"
10846   "&& 1"
10847   [(set (reg:CCC FLAGS_REG)
10848         (compare:CCC
10849           (zero_extract:SWI48
10850             (match_dup 1)
10851             (const_int 1)
10852             (match_dup 2))
10853           (const_int 0)))
10854    (set (pc)
10855         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
10856                       (label_ref (match_dup 3))
10857                       (pc)))]
10858 {
10859   operands[2] = simplify_gen_subreg (<MODE>mode, operands[2], QImode, 0);
10860
10861   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
10862 })
10863
10864 ;; Avoid useless masking of bit offset operand.  "and" in SImode is correct
10865 ;; also for DImode, this is what combine produces.
10866 (define_insn_and_split "*jcc_bt<mode>_mask"
10867   [(set (pc)
10868         (if_then_else (match_operator 0 "bt_comparison_operator"
10869                         [(zero_extract:SWI48
10870                            (match_operand:SWI48 1 "register_operand" "r")
10871                            (const_int 1)
10872                            (and:SI
10873                              (match_operand:SI 2 "register_operand" "r")
10874                              (match_operand:SI 3 "const_int_operand" "n")))])
10875                       (label_ref (match_operand 4 "" ""))
10876                       (pc)))
10877    (clobber (reg:CC FLAGS_REG))]
10878   "(TARGET_USE_BT || optimize_function_for_size_p (cfun))
10879    && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode)-1))
10880       == GET_MODE_BITSIZE (<MODE>mode)-1"
10881   "#"
10882   "&& 1"
10883   [(set (reg:CCC FLAGS_REG)
10884         (compare:CCC
10885           (zero_extract:SWI48
10886             (match_dup 1)
10887             (const_int 1)
10888             (match_dup 2))
10889           (const_int 0)))
10890    (set (pc)
10891         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
10892                       (label_ref (match_dup 4))
10893                       (pc)))]
10894 {
10895   operands[2] = simplify_gen_subreg (<MODE>mode, operands[2], SImode, 0);
10896
10897   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
10898 })
10899
10900 (define_insn_and_split "*jcc_btsi_1"
10901   [(set (pc)
10902         (if_then_else (match_operator 0 "bt_comparison_operator"
10903                         [(and:SI
10904                            (lshiftrt:SI
10905                              (match_operand:SI 1 "register_operand" "r")
10906                              (match_operand:QI 2 "register_operand" "r"))
10907                            (const_int 1))
10908                          (const_int 0)])
10909                       (label_ref (match_operand 3 "" ""))
10910                       (pc)))
10911    (clobber (reg:CC FLAGS_REG))]
10912   "TARGET_USE_BT || optimize_function_for_size_p (cfun)"
10913   "#"
10914   "&& 1"
10915   [(set (reg:CCC FLAGS_REG)
10916         (compare:CCC
10917           (zero_extract:SI
10918             (match_dup 1)
10919             (const_int 1)
10920             (match_dup 2))
10921           (const_int 0)))
10922    (set (pc)
10923         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
10924                       (label_ref (match_dup 3))
10925                       (pc)))]
10926 {
10927   operands[2] = simplify_gen_subreg (SImode, operands[2], QImode, 0);
10928
10929   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
10930 })
10931
10932 ;; avoid useless masking of bit offset operand
10933 (define_insn_and_split "*jcc_btsi_mask_1"
10934   [(set (pc)
10935         (if_then_else
10936           (match_operator 0 "bt_comparison_operator"
10937             [(and:SI
10938                (lshiftrt:SI
10939                  (match_operand:SI 1 "register_operand" "r")
10940                  (subreg:QI
10941                    (and:SI
10942                      (match_operand:SI 2 "register_operand" "r")
10943                      (match_operand:SI 3 "const_int_operand" "n")) 0))
10944                (const_int 1))
10945              (const_int 0)])
10946           (label_ref (match_operand 4 "" ""))
10947           (pc)))
10948    (clobber (reg:CC FLAGS_REG))]
10949   "(TARGET_USE_BT || optimize_function_for_size_p (cfun))
10950    && (INTVAL (operands[3]) & 0x1f) == 0x1f"
10951   "#"
10952   "&& 1"
10953   [(set (reg:CCC FLAGS_REG)
10954         (compare:CCC
10955           (zero_extract:SI
10956             (match_dup 1)
10957             (const_int 1)
10958             (match_dup 2))
10959           (const_int 0)))
10960    (set (pc)
10961         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
10962                       (label_ref (match_dup 4))
10963                       (pc)))]
10964   "PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));")
10965
10966 ;; Define combination compare-and-branch fp compare instructions to help
10967 ;; combine.
10968
10969 (define_insn "*fp_jcc_1_387"
10970   [(set (pc)
10971         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
10972                         [(match_operand 1 "register_operand" "f")
10973                          (match_operand 2 "nonimmediate_operand" "fm")])
10974           (label_ref (match_operand 3 "" ""))
10975           (pc)))
10976    (clobber (reg:CCFP FPSR_REG))
10977    (clobber (reg:CCFP FLAGS_REG))
10978    (clobber (match_scratch:HI 4 "=a"))]
10979   "TARGET_80387
10980    && (GET_MODE (operands[1]) == SFmode || GET_MODE (operands[1]) == DFmode)
10981    && GET_MODE (operands[1]) == GET_MODE (operands[2])
10982    && SELECT_CC_MODE (GET_CODE (operands[0]),
10983                       operands[1], operands[2]) == CCFPmode
10984    && !TARGET_CMOVE"
10985   "#")
10986
10987 (define_insn "*fp_jcc_1r_387"
10988   [(set (pc)
10989         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
10990                         [(match_operand 1 "register_operand" "f")
10991                          (match_operand 2 "nonimmediate_operand" "fm")])
10992           (pc)
10993           (label_ref (match_operand 3 "" ""))))
10994    (clobber (reg:CCFP FPSR_REG))
10995    (clobber (reg:CCFP FLAGS_REG))
10996    (clobber (match_scratch:HI 4 "=a"))]
10997   "TARGET_80387
10998    && (GET_MODE (operands[1]) == SFmode || GET_MODE (operands[1]) == DFmode)
10999    && GET_MODE (operands[1]) == GET_MODE (operands[2])
11000    && SELECT_CC_MODE (GET_CODE (operands[0]),
11001                       operands[1], operands[2]) == CCFPmode
11002    && !TARGET_CMOVE"
11003   "#")
11004
11005 (define_insn "*fp_jcc_2_387"
11006   [(set (pc)
11007         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
11008                         [(match_operand 1 "register_operand" "f")
11009                          (match_operand 2 "register_operand" "f")])
11010           (label_ref (match_operand 3 "" ""))
11011           (pc)))
11012    (clobber (reg:CCFP FPSR_REG))
11013    (clobber (reg:CCFP FLAGS_REG))
11014    (clobber (match_scratch:HI 4 "=a"))]
11015   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
11016    && GET_MODE (operands[1]) == GET_MODE (operands[2])
11017    && !TARGET_CMOVE"
11018   "#")
11019
11020 (define_insn "*fp_jcc_2r_387"
11021   [(set (pc)
11022         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
11023                         [(match_operand 1 "register_operand" "f")
11024                          (match_operand 2 "register_operand" "f")])
11025           (pc)
11026           (label_ref (match_operand 3 "" ""))))
11027    (clobber (reg:CCFP FPSR_REG))
11028    (clobber (reg:CCFP FLAGS_REG))
11029    (clobber (match_scratch:HI 4 "=a"))]
11030   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
11031    && GET_MODE (operands[1]) == GET_MODE (operands[2])
11032    && !TARGET_CMOVE"
11033   "#")
11034
11035 (define_insn "*fp_jcc_3_387"
11036   [(set (pc)
11037         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
11038                         [(match_operand 1 "register_operand" "f")
11039                          (match_operand 2 "const0_operand" "")])
11040           (label_ref (match_operand 3 "" ""))
11041           (pc)))
11042    (clobber (reg:CCFP FPSR_REG))
11043    (clobber (reg:CCFP FLAGS_REG))
11044    (clobber (match_scratch:HI 4 "=a"))]
11045   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
11046    && GET_MODE (operands[1]) == GET_MODE (operands[2])
11047    && SELECT_CC_MODE (GET_CODE (operands[0]),
11048                       operands[1], operands[2]) == CCFPmode
11049    && !TARGET_CMOVE"
11050   "#")
11051
11052 (define_split
11053   [(set (pc)
11054         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
11055                         [(match_operand 1 "register_operand" "")
11056                          (match_operand 2 "nonimmediate_operand" "")])
11057           (match_operand 3 "" "")
11058           (match_operand 4 "" "")))
11059    (clobber (reg:CCFP FPSR_REG))
11060    (clobber (reg:CCFP FLAGS_REG))]
11061   "reload_completed"
11062   [(const_int 0)]
11063 {
11064   ix86_split_fp_branch (GET_CODE (operands[0]), operands[1], operands[2],
11065                         operands[3], operands[4], NULL_RTX, NULL_RTX);
11066   DONE;
11067 })
11068
11069 (define_split
11070   [(set (pc)
11071         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
11072                         [(match_operand 1 "register_operand" "")
11073                          (match_operand 2 "general_operand" "")])
11074           (match_operand 3 "" "")
11075           (match_operand 4 "" "")))
11076    (clobber (reg:CCFP FPSR_REG))
11077    (clobber (reg:CCFP FLAGS_REG))
11078    (clobber (match_scratch:HI 5 "=a"))]
11079   "reload_completed"
11080   [(const_int 0)]
11081 {
11082   ix86_split_fp_branch (GET_CODE (operands[0]), operands[1], operands[2],
11083                         operands[3], operands[4], operands[5], NULL_RTX);
11084   DONE;
11085 })
11086
11087 ;; The order of operands in *fp_jcc_4_387 is forced by combine in
11088 ;; simplify_comparison () function. Float operator is treated as RTX_OBJ
11089 ;; with a precedence over other operators and is always put in the first
11090 ;; place. Swap condition and operands to match ficom instruction.
11091
11092 (define_insn "*fp_jcc_4_<mode>_387"
11093   [(set (pc)
11094         (if_then_else
11095           (match_operator 0 "ix86_swapped_fp_comparison_operator"
11096             [(match_operator 1 "float_operator"
11097               [(match_operand:X87MODEI12 2 "nonimmediate_operand" "m,?r")])
11098              (match_operand 3 "register_operand" "f,f")])
11099           (label_ref (match_operand 4 "" ""))
11100           (pc)))
11101    (clobber (reg:CCFP FPSR_REG))
11102    (clobber (reg:CCFP FLAGS_REG))
11103    (clobber (match_scratch:HI 5 "=a,a"))]
11104   "X87_FLOAT_MODE_P (GET_MODE (operands[3]))
11105    && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))
11106    && GET_MODE (operands[1]) == GET_MODE (operands[3])
11107    && ix86_fp_compare_mode (swap_condition (GET_CODE (operands[0]))) == CCFPmode
11108    && !TARGET_CMOVE"
11109   "#")
11110
11111 (define_split
11112   [(set (pc)
11113         (if_then_else
11114           (match_operator 0 "ix86_swapped_fp_comparison_operator"
11115             [(match_operator 1 "float_operator"
11116               [(match_operand:X87MODEI12 2 "memory_operand" "")])
11117              (match_operand 3 "register_operand" "")])
11118           (match_operand 4 "" "")
11119           (match_operand 5 "" "")))
11120    (clobber (reg:CCFP FPSR_REG))
11121    (clobber (reg:CCFP FLAGS_REG))
11122    (clobber (match_scratch:HI 6 "=a"))]
11123   "reload_completed"
11124   [(const_int 0)]
11125 {
11126   operands[7] = gen_rtx_FLOAT (GET_MODE (operands[1]), operands[2]);
11127
11128   ix86_split_fp_branch (swap_condition (GET_CODE (operands[0])),
11129                         operands[3], operands[7],
11130                         operands[4], operands[5], operands[6], NULL_RTX);
11131   DONE;
11132 })
11133
11134 ;; %%% Kill this when reload knows how to do it.
11135 (define_split
11136   [(set (pc)
11137         (if_then_else
11138           (match_operator 0 "ix86_swapped_fp_comparison_operator"
11139             [(match_operator 1 "float_operator"
11140               [(match_operand:X87MODEI12 2 "register_operand" "")])
11141              (match_operand 3 "register_operand" "")])
11142           (match_operand 4 "" "")
11143           (match_operand 5 "" "")))
11144    (clobber (reg:CCFP FPSR_REG))
11145    (clobber (reg:CCFP FLAGS_REG))
11146    (clobber (match_scratch:HI 6 "=a"))]
11147   "reload_completed"
11148   [(const_int 0)]
11149 {
11150   operands[7] = ix86_force_to_memory (GET_MODE (operands[2]), operands[2]);
11151   operands[7] = gen_rtx_FLOAT (GET_MODE (operands[1]), operands[7]);
11152
11153   ix86_split_fp_branch (swap_condition (GET_CODE (operands[0])),
11154                         operands[3], operands[7],
11155                         operands[4], operands[5], operands[6], operands[2]);
11156   DONE;
11157 })
11158 \f
11159 ;; Unconditional and other jump instructions
11160
11161 (define_insn "jump"
11162   [(set (pc)
11163         (label_ref (match_operand 0 "" "")))]
11164   ""
11165   "jmp\t%l0"
11166   [(set_attr "type" "ibr")
11167    (set (attr "length")
11168            (if_then_else (and (ge (minus (match_dup 0) (pc))
11169                                   (const_int -126))
11170                               (lt (minus (match_dup 0) (pc))
11171                                   (const_int 128)))
11172              (const_int 2)
11173              (const_int 5)))
11174    (set_attr "modrm" "0")])
11175
11176 (define_expand "indirect_jump"
11177   [(set (pc) (match_operand 0 "nonimmediate_operand" ""))]
11178   ""
11179   "")
11180
11181 (define_insn "*indirect_jump"
11182   [(set (pc) (match_operand:P 0 "nonimmediate_operand" "rm"))]
11183   ""
11184   "jmp\t%A0"
11185   [(set_attr "type" "ibr")
11186    (set_attr "length_immediate" "0")])
11187
11188 (define_expand "tablejump"
11189   [(parallel [(set (pc) (match_operand 0 "nonimmediate_operand" ""))
11190               (use (label_ref (match_operand 1 "" "")))])]
11191   ""
11192 {
11193   /* In PIC mode, the table entries are stored GOT (32-bit) or PC (64-bit)
11194      relative.  Convert the relative address to an absolute address.  */
11195   if (flag_pic)
11196     {
11197       rtx op0, op1;
11198       enum rtx_code code;
11199
11200       /* We can't use @GOTOFF for text labels on VxWorks;
11201          see gotoff_operand.  */
11202       if (TARGET_64BIT || TARGET_VXWORKS_RTP)
11203         {
11204           code = PLUS;
11205           op0 = operands[0];
11206           op1 = gen_rtx_LABEL_REF (Pmode, operands[1]);
11207         }
11208       else if (TARGET_MACHO || HAVE_AS_GOTOFF_IN_DATA)
11209         {
11210           code = PLUS;
11211           op0 = operands[0];
11212           op1 = pic_offset_table_rtx;
11213         }
11214       else
11215         {
11216           code = MINUS;
11217           op0 = pic_offset_table_rtx;
11218           op1 = operands[0];
11219         }
11220
11221       operands[0] = expand_simple_binop (Pmode, code, op0, op1, NULL_RTX, 0,
11222                                          OPTAB_DIRECT);
11223     }
11224 })
11225
11226 (define_insn "*tablejump_1"
11227   [(set (pc) (match_operand:P 0 "nonimmediate_operand" "rm"))
11228    (use (label_ref (match_operand 1 "" "")))]
11229   ""
11230   "jmp\t%A0"
11231   [(set_attr "type" "ibr")
11232    (set_attr "length_immediate" "0")])
11233 \f
11234 ;; Convert setcc + movzbl to xor + setcc if operands don't overlap.
11235
11236 (define_peephole2
11237   [(set (reg FLAGS_REG) (match_operand 0 "" ""))
11238    (set (match_operand:QI 1 "register_operand" "")
11239         (match_operator:QI 2 "ix86_comparison_operator"
11240           [(reg FLAGS_REG) (const_int 0)]))
11241    (set (match_operand 3 "q_regs_operand" "")
11242         (zero_extend (match_dup 1)))]
11243   "(peep2_reg_dead_p (3, operands[1])
11244     || operands_match_p (operands[1], operands[3]))
11245    && ! reg_overlap_mentioned_p (operands[3], operands[0])"
11246   [(set (match_dup 4) (match_dup 0))
11247    (set (strict_low_part (match_dup 5))
11248         (match_dup 2))]
11249 {
11250   operands[4] = gen_rtx_REG (GET_MODE (operands[0]), FLAGS_REG);
11251   operands[5] = gen_lowpart (QImode, operands[3]);
11252   ix86_expand_clear (operands[3]);
11253 })
11254
11255 ;; Similar, but match zero_extendhisi2_and, which adds a clobber.
11256
11257 (define_peephole2
11258   [(set (reg FLAGS_REG) (match_operand 0 "" ""))
11259    (set (match_operand:QI 1 "register_operand" "")
11260         (match_operator:QI 2 "ix86_comparison_operator"
11261           [(reg FLAGS_REG) (const_int 0)]))
11262    (parallel [(set (match_operand 3 "q_regs_operand" "")
11263                    (zero_extend (match_dup 1)))
11264               (clobber (reg:CC FLAGS_REG))])]
11265   "(peep2_reg_dead_p (3, operands[1])
11266     || operands_match_p (operands[1], operands[3]))
11267    && ! reg_overlap_mentioned_p (operands[3], operands[0])"
11268   [(set (match_dup 4) (match_dup 0))
11269    (set (strict_low_part (match_dup 5))
11270         (match_dup 2))]
11271 {
11272   operands[4] = gen_rtx_REG (GET_MODE (operands[0]), FLAGS_REG);
11273   operands[5] = gen_lowpart (QImode, operands[3]);
11274   ix86_expand_clear (operands[3]);
11275 })
11276 \f
11277 ;; Call instructions.
11278
11279 ;; The predicates normally associated with named expanders are not properly
11280 ;; checked for calls.  This is a bug in the generic code, but it isn't that
11281 ;; easy to fix.  Ignore it for now and be prepared to fix things up.
11282
11283 ;; P6 processors will jump to the address after the decrement when %esp
11284 ;; is used as a call operand, so they will execute return address as a code.
11285 ;; See Pentium Pro errata 70, Pentium 2 errata A33 and Pentium 3 errata E17.
11286  
11287 ;; Call subroutine returning no value.
11288
11289 (define_expand "call_pop"
11290   [(parallel [(call (match_operand:QI 0 "" "")
11291                     (match_operand:SI 1 "" ""))
11292               (set (reg:SI SP_REG)
11293                    (plus:SI (reg:SI SP_REG)
11294                             (match_operand:SI 3 "" "")))])]
11295   "!TARGET_64BIT"
11296 {
11297   ix86_expand_call (NULL, operands[0], operands[1],
11298                     operands[2], operands[3], 0);
11299   DONE;
11300 })
11301
11302 (define_insn_and_split "*call_pop_0_vzeroupper"
11303   [(parallel
11304     [(call (mem:QI (match_operand:SI 0 "constant_call_address_operand" ""))
11305            (match_operand:SI 1 "" ""))
11306      (set (reg:SI SP_REG)
11307           (plus:SI (reg:SI SP_REG)
11308                    (match_operand:SI 2 "immediate_operand" "")))])
11309    (unspec [(match_operand 3 "const_int_operand" "")]
11310            UNSPEC_CALL_NEEDS_VZEROUPPER)]
11311   "TARGET_VZEROUPPER && !TARGET_64BIT"
11312   "#"
11313   "&& reload_completed"
11314   [(const_int 0)]
11315   "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
11316   [(set_attr "type" "call")])
11317
11318 (define_insn "*call_pop_0"
11319   [(call (mem:QI (match_operand:SI 0 "constant_call_address_operand" ""))
11320          (match_operand:SI 1 "" ""))
11321    (set (reg:SI SP_REG)
11322         (plus:SI (reg:SI SP_REG)
11323                  (match_operand:SI 2 "immediate_operand" "")))]
11324   "!TARGET_64BIT"
11325 {
11326   if (SIBLING_CALL_P (insn))
11327     return "jmp\t%P0";
11328   else
11329     return "call\t%P0";
11330 }
11331   [(set_attr "type" "call")])
11332
11333 (define_insn_and_split "*call_pop_1_vzeroupper"
11334   [(parallel
11335     [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "lsm"))
11336            (match_operand:SI 1 "" ""))
11337      (set (reg:SI SP_REG)
11338           (plus:SI (reg:SI SP_REG)
11339                    (match_operand:SI 2 "immediate_operand" "i")))])
11340    (unspec [(match_operand 3 "const_int_operand" "")]
11341            UNSPEC_CALL_NEEDS_VZEROUPPER)]
11342   "TARGET_VZEROUPPER && !TARGET_64BIT && !SIBLING_CALL_P (insn)"
11343   "#"
11344   "&& reload_completed"
11345   [(const_int 0)]
11346   "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
11347   [(set_attr "type" "call")])
11348
11349 (define_insn "*call_pop_1"
11350   [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "lsm"))
11351          (match_operand:SI 1 "" ""))
11352    (set (reg:SI SP_REG)
11353         (plus:SI (reg:SI SP_REG)
11354                  (match_operand:SI 2 "immediate_operand" "i")))]
11355   "!TARGET_64BIT && !SIBLING_CALL_P (insn)"
11356 {
11357   if (constant_call_address_operand (operands[0], Pmode))
11358     return "call\t%P0";
11359   return "call\t%A0";
11360 }
11361   [(set_attr "type" "call")])
11362
11363 (define_insn_and_split "*sibcall_pop_1_vzeroupper"
11364  [(parallel
11365    [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "s,U"))
11366            (match_operand:SI 1 "" ""))
11367      (set (reg:SI SP_REG)
11368           (plus:SI (reg:SI SP_REG)
11369                    (match_operand:SI 2 "immediate_operand" "i,i")))])
11370    (unspec [(match_operand 3 "const_int_operand" "")]
11371            UNSPEC_CALL_NEEDS_VZEROUPPER)]
11372   "TARGET_VZEROUPPER && !TARGET_64BIT && SIBLING_CALL_P (insn)"
11373   "#"
11374   "&& reload_completed"
11375   [(const_int 0)]
11376   "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
11377   [(set_attr "type" "call")])
11378
11379 (define_insn "*sibcall_pop_1"
11380   [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "s,U"))
11381          (match_operand:SI 1 "" ""))
11382    (set (reg:SI SP_REG)
11383         (plus:SI (reg:SI SP_REG)
11384                  (match_operand:SI 2 "immediate_operand" "i,i")))]
11385   "!TARGET_64BIT && SIBLING_CALL_P (insn)"
11386   "@
11387    jmp\t%P0
11388    jmp\t%A0"
11389   [(set_attr "type" "call")])
11390
11391 (define_expand "call"
11392   [(call (match_operand:QI 0 "" "")
11393          (match_operand 1 "" ""))
11394    (use (match_operand 2 "" ""))]
11395   ""
11396 {
11397   ix86_expand_call (NULL, operands[0], operands[1], operands[2], NULL, 0);
11398   DONE;
11399 })
11400
11401 (define_expand "sibcall"
11402   [(call (match_operand:QI 0 "" "")
11403          (match_operand 1 "" ""))
11404    (use (match_operand 2 "" ""))]
11405   ""
11406 {
11407   ix86_expand_call (NULL, operands[0], operands[1], operands[2], NULL, 1);
11408   DONE;
11409 })
11410
11411 (define_insn_and_split "*call_0_vzeroupper"
11412   [(call (mem:QI (match_operand 0 "constant_call_address_operand" ""))
11413          (match_operand 1 "" ""))
11414    (unspec [(match_operand 2 "const_int_operand" "")]
11415            UNSPEC_CALL_NEEDS_VZEROUPPER)]
11416   "TARGET_VZEROUPPER"
11417   "#"
11418   "&& reload_completed"
11419   [(const_int 0)]
11420   "ix86_split_call_vzeroupper (curr_insn, operands[2]); DONE;"
11421   [(set_attr "type" "call")])
11422
11423 (define_insn "*call_0"
11424   [(call (mem:QI (match_operand 0 "constant_call_address_operand" ""))
11425          (match_operand 1 "" ""))]
11426   ""
11427   { return ix86_output_call_insn (insn, operands[0], 0); }
11428   [(set_attr "type" "call")])
11429
11430 (define_insn_and_split "*call_1_vzeroupper"
11431   [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "lsm"))
11432          (match_operand 1 "" ""))
11433    (unspec [(match_operand 2 "const_int_operand" "")]
11434            UNSPEC_CALL_NEEDS_VZEROUPPER)]
11435   "TARGET_VZEROUPPER && !TARGET_64BIT && !SIBLING_CALL_P (insn)"
11436   "#"
11437   "&& reload_completed"
11438   [(const_int 0)]
11439   "ix86_split_call_vzeroupper (curr_insn, operands[2]); DONE;"
11440   [(set_attr "type" "call")])
11441
11442 (define_insn "*call_1"
11443   [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "lsm"))
11444          (match_operand 1 "" ""))]
11445   "!TARGET_64BIT && !SIBLING_CALL_P (insn)"
11446   { return ix86_output_call_insn (insn, operands[0], 0); }
11447   [(set_attr "type" "call")])
11448
11449 (define_insn_and_split "*sibcall_1_vzeroupper"
11450   [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "s,U"))
11451          (match_operand 1 "" ""))
11452    (unspec [(match_operand 2 "const_int_operand" "")]
11453            UNSPEC_CALL_NEEDS_VZEROUPPER)]
11454   "TARGET_VZEROUPPER && !TARGET_64BIT && SIBLING_CALL_P (insn)"
11455   "#"
11456   "&& reload_completed"
11457   [(const_int 0)]
11458   "ix86_split_call_vzeroupper (curr_insn, operands[2]); DONE;"
11459   [(set_attr "type" "call")])
11460
11461 (define_insn "*sibcall_1"
11462   [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "s,U"))
11463          (match_operand 1 "" ""))]
11464   "!TARGET_64BIT && SIBLING_CALL_P (insn)"
11465   { return ix86_output_call_insn (insn, operands[0], 0); }
11466   [(set_attr "type" "call")])
11467
11468 (define_insn_and_split "*call_1_rex64_vzeroupper"
11469   [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rsm"))
11470          (match_operand 1 "" ""))
11471    (unspec [(match_operand 2 "const_int_operand" "")]
11472            UNSPEC_CALL_NEEDS_VZEROUPPER)]
11473   "TARGET_VZEROUPPER && TARGET_64BIT && !SIBLING_CALL_P (insn)
11474    && ix86_cmodel != CM_LARGE && ix86_cmodel != CM_LARGE_PIC"
11475   "#"
11476   "&& reload_completed"
11477   [(const_int 0)]
11478   "ix86_split_call_vzeroupper (curr_insn, operands[2]); DONE;"
11479   [(set_attr "type" "call")])
11480
11481 (define_insn "*call_1_rex64"
11482   [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rsm"))
11483          (match_operand 1 "" ""))]
11484   "TARGET_64BIT && !SIBLING_CALL_P (insn)
11485    && ix86_cmodel != CM_LARGE && ix86_cmodel != CM_LARGE_PIC"
11486   { return ix86_output_call_insn (insn, operands[0], 0); }
11487   [(set_attr "type" "call")])
11488
11489 (define_insn_and_split "*call_1_rex64_ms_sysv_vzeroupper"
11490   [(parallel
11491     [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rsm"))
11492            (match_operand 1 "" ""))
11493      (unspec [(const_int 0)] UNSPEC_MS_TO_SYSV_CALL)
11494      (clobber (reg:TI XMM6_REG))
11495      (clobber (reg:TI XMM7_REG))
11496      (clobber (reg:TI XMM8_REG))
11497      (clobber (reg:TI XMM9_REG))
11498      (clobber (reg:TI XMM10_REG))
11499      (clobber (reg:TI XMM11_REG))
11500      (clobber (reg:TI XMM12_REG))
11501      (clobber (reg:TI XMM13_REG))
11502      (clobber (reg:TI XMM14_REG))
11503      (clobber (reg:TI XMM15_REG))
11504      (clobber (reg:DI SI_REG))
11505      (clobber (reg:DI DI_REG))])
11506    (unspec [(match_operand 2 "const_int_operand" "")]
11507            UNSPEC_CALL_NEEDS_VZEROUPPER)]
11508   "TARGET_VZEROUPPER && TARGET_64BIT && !SIBLING_CALL_P (insn)"
11509   "#"
11510   "&& reload_completed"
11511   [(const_int 0)]
11512   "ix86_split_call_vzeroupper (curr_insn, operands[2]); DONE;"
11513   [(set_attr "type" "call")])
11514
11515 (define_insn "*call_1_rex64_ms_sysv"
11516   [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rsm"))
11517          (match_operand 1 "" ""))
11518    (unspec [(const_int 0)] UNSPEC_MS_TO_SYSV_CALL)
11519    (clobber (reg:TI XMM6_REG))
11520    (clobber (reg:TI XMM7_REG))
11521    (clobber (reg:TI XMM8_REG))
11522    (clobber (reg:TI XMM9_REG))
11523    (clobber (reg:TI XMM10_REG))
11524    (clobber (reg:TI XMM11_REG))
11525    (clobber (reg:TI XMM12_REG))
11526    (clobber (reg:TI XMM13_REG))
11527    (clobber (reg:TI XMM14_REG))
11528    (clobber (reg:TI XMM15_REG))
11529    (clobber (reg:DI SI_REG))
11530    (clobber (reg:DI DI_REG))]
11531   "TARGET_64BIT && !SIBLING_CALL_P (insn)"
11532   { return ix86_output_call_insn (insn, operands[0], 0); }
11533   [(set_attr "type" "call")])
11534
11535 (define_insn_and_split "*call_1_rex64_large_vzeroupper"
11536   [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rm"))
11537          (match_operand 1 "" ""))
11538    (unspec [(match_operand 2 "const_int_operand" "")]
11539            UNSPEC_CALL_NEEDS_VZEROUPPER)]
11540   "TARGET_VZEROUPPER && TARGET_64BIT && !SIBLING_CALL_P (insn)"
11541   "#"
11542   "&& reload_completed"
11543   [(const_int 0)]
11544   "ix86_split_call_vzeroupper (curr_insn, operands[2]); DONE;"
11545   [(set_attr "type" "call")])
11546
11547 (define_insn "*call_1_rex64_large"
11548   [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rm"))
11549          (match_operand 1 "" ""))]
11550   "TARGET_64BIT && !SIBLING_CALL_P (insn)"
11551   { return ix86_output_call_insn (insn, operands[0], 0); }
11552   [(set_attr "type" "call")])
11553
11554 (define_insn_and_split "*sibcall_1_rex64_vzeroupper"
11555   [(call (mem:QI (match_operand:DI 0 "sibcall_insn_operand" "s,U"))
11556          (match_operand 1 "" ""))
11557    (unspec [(match_operand 2 "const_int_operand" "")]
11558            UNSPEC_CALL_NEEDS_VZEROUPPER)]
11559   "TARGET_VZEROUPPER && TARGET_64BIT && SIBLING_CALL_P (insn)"
11560   "#"
11561   "&& reload_completed"
11562   [(const_int 0)]
11563   "ix86_split_call_vzeroupper (curr_insn, operands[2]); DONE;"
11564   [(set_attr "type" "call")])
11565
11566 (define_insn "*sibcall_1_rex64"
11567   [(call (mem:QI (match_operand:DI 0 "sibcall_insn_operand" "s,U"))
11568          (match_operand 1 "" ""))]
11569   "TARGET_64BIT && SIBLING_CALL_P (insn)"
11570   { return ix86_output_call_insn (insn, operands[0], 0); }
11571   [(set_attr "type" "call")])
11572
11573 ;; Call subroutine, returning value in operand 0
11574 (define_expand "call_value_pop"
11575   [(parallel [(set (match_operand 0 "" "")
11576                    (call (match_operand:QI 1 "" "")
11577                          (match_operand:SI 2 "" "")))
11578               (set (reg:SI SP_REG)
11579                    (plus:SI (reg:SI SP_REG)
11580                             (match_operand:SI 4 "" "")))])]
11581   "!TARGET_64BIT"
11582 {
11583   ix86_expand_call (operands[0], operands[1], operands[2],
11584                     operands[3], operands[4], 0);
11585   DONE;
11586 })
11587
11588 (define_expand "call_value"
11589   [(set (match_operand 0 "" "")
11590         (call (match_operand:QI 1 "" "")
11591               (match_operand:SI 2 "" "")))
11592    (use (match_operand:SI 3 "" ""))]
11593   ;; Operand 3 is not used on the i386.
11594   ""
11595 {
11596   ix86_expand_call (operands[0], operands[1], operands[2],
11597                     operands[3], NULL, 0);
11598   DONE;
11599 })
11600
11601 (define_expand "sibcall_value"
11602   [(set (match_operand 0 "" "")
11603         (call (match_operand:QI 1 "" "")
11604               (match_operand:SI 2 "" "")))
11605    (use (match_operand:SI 3 "" ""))]
11606   ;; Operand 3 is not used on the i386.
11607   ""
11608 {
11609   ix86_expand_call (operands[0], operands[1], operands[2],
11610                     operands[3], NULL, 1);
11611   DONE;
11612 })
11613
11614 ;; Call subroutine returning any type.
11615
11616 (define_expand "untyped_call"
11617   [(parallel [(call (match_operand 0 "" "")
11618                     (const_int 0))
11619               (match_operand 1 "" "")
11620               (match_operand 2 "" "")])]
11621   ""
11622 {
11623   int i;
11624
11625   /* In order to give reg-stack an easier job in validating two
11626      coprocessor registers as containing a possible return value,
11627      simply pretend the untyped call returns a complex long double
11628      value. 
11629
11630      We can't use SSE_REGPARM_MAX here since callee is unprototyped
11631      and should have the default ABI.  */
11632
11633   ix86_expand_call ((TARGET_FLOAT_RETURNS_IN_80387
11634                      ? gen_rtx_REG (XCmode, FIRST_FLOAT_REG) : NULL),
11635                     operands[0], const0_rtx,
11636                     GEN_INT ((TARGET_64BIT
11637                               ? (ix86_abi == SYSV_ABI
11638                                  ? X86_64_SSE_REGPARM_MAX
11639                                  : X86_64_MS_SSE_REGPARM_MAX)
11640                               : X86_32_SSE_REGPARM_MAX)
11641                              - 1),
11642                     NULL, 0);
11643
11644   for (i = 0; i < XVECLEN (operands[2], 0); i++)
11645     {
11646       rtx set = XVECEXP (operands[2], 0, i);
11647       emit_move_insn (SET_DEST (set), SET_SRC (set));
11648     }
11649
11650   /* The optimizer does not know that the call sets the function value
11651      registers we stored in the result block.  We avoid problems by
11652      claiming that all hard registers are used and clobbered at this
11653      point.  */
11654   emit_insn (gen_blockage ());
11655
11656   DONE;
11657 })
11658 \f
11659 ;; Prologue and epilogue instructions
11660
11661 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
11662 ;; all of memory.  This blocks insns from being moved across this point.
11663
11664 (define_insn "blockage"
11665   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
11666   ""
11667   ""
11668   [(set_attr "length" "0")])
11669
11670 ;; Do not schedule instructions accessing memory across this point.
11671
11672 (define_expand "memory_blockage"
11673   [(set (match_dup 0)
11674         (unspec:BLK [(match_dup 0)] UNSPEC_MEMORY_BLOCKAGE))]
11675   ""
11676 {
11677   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
11678   MEM_VOLATILE_P (operands[0]) = 1;
11679 })
11680
11681 (define_insn "*memory_blockage"
11682   [(set (match_operand:BLK 0 "" "")
11683         (unspec:BLK [(match_dup 0)] UNSPEC_MEMORY_BLOCKAGE))]
11684   ""
11685   ""
11686   [(set_attr "length" "0")])
11687
11688 ;; As USE insns aren't meaningful after reload, this is used instead
11689 ;; to prevent deleting instructions setting registers for PIC code
11690 (define_insn "prologue_use"
11691   [(unspec_volatile [(match_operand 0 "" "")] UNSPECV_PROLOGUE_USE)]
11692   ""
11693   ""
11694   [(set_attr "length" "0")])
11695
11696 ;; Insn emitted into the body of a function to return from a function.
11697 ;; This is only done if the function's epilogue is known to be simple.
11698 ;; See comments for ix86_can_use_return_insn_p in i386.c.
11699
11700 (define_expand "return"
11701   [(return)]
11702   "ix86_can_use_return_insn_p ()"
11703 {
11704   if (crtl->args.pops_args)
11705     {
11706       rtx popc = GEN_INT (crtl->args.pops_args);
11707       emit_jump_insn (gen_return_pop_internal (popc));
11708       DONE;
11709     }
11710 })
11711
11712 (define_insn "return_internal"
11713   [(return)]
11714   "reload_completed"
11715   "ret"
11716   [(set_attr "length" "1")
11717    (set_attr "atom_unit" "jeu")
11718    (set_attr "length_immediate" "0")
11719    (set_attr "modrm" "0")])
11720
11721 ;; Used by x86_machine_dependent_reorg to avoid penalty on single byte RET
11722 ;; instruction Athlon and K8 have.
11723
11724 (define_insn "return_internal_long"
11725   [(return)
11726    (unspec [(const_int 0)] UNSPEC_REP)]
11727   "reload_completed"
11728   "rep\;ret"
11729   [(set_attr "length" "2")
11730    (set_attr "atom_unit" "jeu")
11731    (set_attr "length_immediate" "0")
11732    (set_attr "prefix_rep" "1")
11733    (set_attr "modrm" "0")])
11734
11735 (define_insn "return_pop_internal"
11736   [(return)
11737    (use (match_operand:SI 0 "const_int_operand" ""))]
11738   "reload_completed"
11739   "ret\t%0"
11740   [(set_attr "length" "3")
11741    (set_attr "atom_unit" "jeu")
11742    (set_attr "length_immediate" "2")
11743    (set_attr "modrm" "0")])
11744
11745 (define_insn "return_indirect_internal"
11746   [(return)
11747    (use (match_operand:SI 0 "register_operand" "r"))]
11748   "reload_completed"
11749   "jmp\t%A0"
11750   [(set_attr "type" "ibr")
11751    (set_attr "length_immediate" "0")])
11752
11753 (define_insn "nop"
11754   [(const_int 0)]
11755   ""
11756   "nop"
11757   [(set_attr "length" "1")
11758    (set_attr "length_immediate" "0")
11759    (set_attr "modrm" "0")])
11760
11761 ;; Generate nops.  Operand 0 is the number of nops, up to 8.
11762 (define_insn "nops"
11763   [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
11764                     UNSPECV_NOPS)]
11765   "reload_completed"
11766 {
11767   int num = INTVAL (operands[0]);
11768
11769   gcc_assert (num >= 1 && num <= 8);
11770
11771   while (num--)
11772     fputs ("\tnop\n", asm_out_file);
11773
11774   return "";
11775 }
11776   [(set (attr "length") (symbol_ref "INTVAL (operands[0])"))
11777    (set_attr "length_immediate" "0")
11778    (set_attr "modrm" "0")])
11779
11780 ;; Pad to 16-byte boundary, max skip in op0.  Used to avoid
11781 ;; branch prediction penalty for the third jump in a 16-byte
11782 ;; block on K8.
11783
11784 (define_insn "pad"
11785   [(unspec_volatile [(match_operand 0 "" "")] UNSPECV_ALIGN)]
11786   ""
11787 {
11788 #ifdef ASM_OUTPUT_MAX_SKIP_PAD
11789   ASM_OUTPUT_MAX_SKIP_PAD (asm_out_file, 4, (int)INTVAL (operands[0]));
11790 #else
11791   /* It is tempting to use ASM_OUTPUT_ALIGN here, but we don't want to do that.
11792      The align insn is used to avoid 3 jump instructions in the row to improve
11793      branch prediction and the benefits hardly outweigh the cost of extra 8
11794      nops on the average inserted by full alignment pseudo operation.  */
11795 #endif
11796   return "";
11797 }
11798   [(set_attr "length" "16")])
11799
11800 (define_expand "prologue"
11801   [(const_int 0)]
11802   ""
11803   "ix86_expand_prologue (); DONE;")
11804
11805 (define_insn "set_got"
11806   [(set (match_operand:SI 0 "register_operand" "=r")
11807         (unspec:SI [(const_int 0)] UNSPEC_SET_GOT))
11808    (clobber (reg:CC FLAGS_REG))]
11809   "!TARGET_64BIT"
11810   "* return output_set_got (operands[0], NULL_RTX);"
11811   [(set_attr "type" "multi")
11812    (set_attr "length" "12")])
11813
11814 (define_insn "set_got_labelled"
11815   [(set (match_operand:SI 0 "register_operand" "=r")
11816         (unspec:SI [(label_ref (match_operand 1 "" ""))]
11817          UNSPEC_SET_GOT))
11818    (clobber (reg:CC FLAGS_REG))]
11819   "!TARGET_64BIT"
11820   "* return output_set_got (operands[0], operands[1]);"
11821   [(set_attr "type" "multi")
11822    (set_attr "length" "12")])
11823
11824 (define_insn "set_got_rex64"
11825   [(set (match_operand:DI 0 "register_operand" "=r")
11826         (unspec:DI [(const_int 0)] UNSPEC_SET_GOT))]
11827   "TARGET_64BIT"
11828   "lea{q}\t{_GLOBAL_OFFSET_TABLE_(%%rip), %0|%0, _GLOBAL_OFFSET_TABLE_[rip]}"
11829   [(set_attr "type" "lea")
11830    (set_attr "length_address" "4")
11831    (set_attr "mode" "DI")])
11832
11833 (define_insn "set_rip_rex64"
11834   [(set (match_operand:DI 0 "register_operand" "=r")
11835         (unspec:DI [(label_ref (match_operand 1 "" ""))] UNSPEC_SET_RIP))]
11836   "TARGET_64BIT"
11837   "lea{q}\t{%l1(%%rip), %0|%0, %l1[rip]}"
11838   [(set_attr "type" "lea")
11839    (set_attr "length_address" "4")
11840    (set_attr "mode" "DI")])
11841
11842 (define_insn "set_got_offset_rex64"
11843   [(set (match_operand:DI 0 "register_operand" "=r")
11844         (unspec:DI
11845           [(label_ref (match_operand 1 "" ""))]
11846           UNSPEC_SET_GOT_OFFSET))]
11847   "TARGET_64BIT"
11848   "movabs{q}\t{$_GLOBAL_OFFSET_TABLE_-%l1, %0|%0, OFFSET FLAT:_GLOBAL_OFFSET_TABLE_-%l1}"
11849   [(set_attr "type" "imov")
11850    (set_attr "length_immediate" "0")
11851    (set_attr "length_address" "8")
11852    (set_attr "mode" "DI")])
11853
11854 (define_expand "epilogue"
11855   [(const_int 0)]
11856   ""
11857   "ix86_expand_epilogue (1); DONE;")
11858
11859 (define_expand "sibcall_epilogue"
11860   [(const_int 0)]
11861   ""
11862   "ix86_expand_epilogue (0); DONE;")
11863
11864 (define_expand "eh_return"
11865   [(use (match_operand 0 "register_operand" ""))]
11866   ""
11867 {
11868   rtx tmp, sa = EH_RETURN_STACKADJ_RTX, ra = operands[0];
11869
11870   /* Tricky bit: we write the address of the handler to which we will
11871      be returning into someone else's stack frame, one word below the
11872      stack address we wish to restore.  */
11873   tmp = gen_rtx_PLUS (Pmode, arg_pointer_rtx, sa);
11874   tmp = plus_constant (tmp, -UNITS_PER_WORD);
11875   tmp = gen_rtx_MEM (Pmode, tmp);
11876   emit_move_insn (tmp, ra);
11877
11878   emit_jump_insn (gen_eh_return_internal ());
11879   emit_barrier ();
11880   DONE;
11881 })
11882
11883 (define_insn_and_split "eh_return_internal"
11884   [(eh_return)]
11885   ""
11886   "#"
11887   "epilogue_completed"
11888   [(const_int 0)]
11889   "ix86_expand_epilogue (2); DONE;")
11890
11891 (define_insn "leave"
11892   [(set (reg:SI SP_REG) (plus:SI (reg:SI BP_REG) (const_int 4)))
11893    (set (reg:SI BP_REG) (mem:SI (reg:SI BP_REG)))
11894    (clobber (mem:BLK (scratch)))]
11895   "!TARGET_64BIT"
11896   "leave"
11897   [(set_attr "type" "leave")])
11898
11899 (define_insn "leave_rex64"
11900   [(set (reg:DI SP_REG) (plus:DI (reg:DI BP_REG) (const_int 8)))
11901    (set (reg:DI BP_REG) (mem:DI (reg:DI BP_REG)))
11902    (clobber (mem:BLK (scratch)))]
11903   "TARGET_64BIT"
11904   "leave"
11905   [(set_attr "type" "leave")])
11906 \f
11907 ;; Handle -fsplit-stack.
11908
11909 (define_expand "split_stack_prologue"
11910   [(const_int 0)]
11911   ""
11912 {
11913   ix86_expand_split_stack_prologue ();
11914   DONE;
11915 })
11916
11917 ;; In order to support the call/return predictor, we use a return
11918 ;; instruction which the middle-end doesn't see.
11919 (define_insn "split_stack_return"
11920   [(unspec_volatile [(match_operand:SI 0 "const_int_operand" "")]
11921                      UNSPECV_SPLIT_STACK_RETURN)]
11922   ""
11923 {
11924   if (operands[0] == const0_rtx)
11925     return "ret";
11926   else
11927     return "ret\t%0";
11928 }
11929   [(set_attr "atom_unit" "jeu")
11930    (set_attr "modrm" "0")
11931    (set (attr "length")
11932         (if_then_else (match_operand:SI 0 "const0_operand" "")
11933                       (const_int 1)
11934                       (const_int 3)))
11935    (set (attr "length_immediate")
11936         (if_then_else (match_operand:SI 0 "const0_operand" "")
11937                       (const_int 0)
11938                       (const_int 2)))])
11939
11940 ;; If there are operand 0 bytes available on the stack, jump to
11941 ;; operand 1.
11942
11943 (define_expand "split_stack_space_check"
11944   [(set (pc) (if_then_else
11945               (ltu (minus (reg SP_REG)
11946                           (match_operand 0 "register_operand" ""))
11947                    (unspec [(const_int 0)] UNSPEC_STACK_CHECK))
11948               (label_ref (match_operand 1 "" ""))
11949               (pc)))]
11950   ""
11951 {
11952   rtx reg, size, limit;
11953
11954   reg = gen_reg_rtx (Pmode);
11955   size = force_reg (Pmode, operands[0]);
11956   emit_insn (gen_sub3_insn (reg, stack_pointer_rtx, size));
11957   limit = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
11958                           UNSPEC_STACK_CHECK);
11959   limit = gen_rtx_MEM (Pmode, gen_rtx_CONST (Pmode, limit));
11960   ix86_expand_branch (GEU, reg, limit, operands[1]);
11961
11962   DONE;
11963 })
11964 \f
11965 ;; Bit manipulation instructions.
11966
11967 (define_expand "ffs<mode>2"
11968   [(set (match_dup 2) (const_int -1))
11969    (parallel [(set (reg:CCZ FLAGS_REG)
11970                    (compare:CCZ
11971                      (match_operand:SWI48 1 "nonimmediate_operand" "")
11972                      (const_int 0)))
11973               (set (match_operand:SWI48 0 "register_operand" "")
11974                    (ctz:SWI48 (match_dup 1)))])
11975    (set (match_dup 0) (if_then_else:SWI48
11976                         (eq (reg:CCZ FLAGS_REG) (const_int 0))
11977                         (match_dup 2)
11978                         (match_dup 0)))
11979    (parallel [(set (match_dup 0) (plus:SWI48 (match_dup 0) (const_int 1)))
11980               (clobber (reg:CC FLAGS_REG))])]
11981   ""
11982 {
11983   if (<MODE>mode == SImode && !TARGET_CMOVE)
11984     {
11985       emit_insn (gen_ffssi2_no_cmove (operands[0], operands [1]));
11986       DONE;
11987     }
11988   operands[2] = gen_reg_rtx (<MODE>mode);
11989 })
11990
11991 (define_insn_and_split "ffssi2_no_cmove"
11992   [(set (match_operand:SI 0 "register_operand" "=r")
11993         (ffs:SI (match_operand:SI 1 "nonimmediate_operand" "rm")))
11994    (clobber (match_scratch:SI 2 "=&q"))
11995    (clobber (reg:CC FLAGS_REG))]
11996   "!TARGET_CMOVE"
11997   "#"
11998   "&& reload_completed"
11999   [(parallel [(set (reg:CCZ FLAGS_REG)
12000                    (compare:CCZ (match_dup 1) (const_int 0)))
12001               (set (match_dup 0) (ctz:SI (match_dup 1)))])
12002    (set (strict_low_part (match_dup 3))
12003         (eq:QI (reg:CCZ FLAGS_REG) (const_int 0)))
12004    (parallel [(set (match_dup 2) (neg:SI (match_dup 2)))
12005               (clobber (reg:CC FLAGS_REG))])
12006    (parallel [(set (match_dup 0) (ior:SI (match_dup 0) (match_dup 2)))
12007               (clobber (reg:CC FLAGS_REG))])
12008    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 1)))
12009               (clobber (reg:CC FLAGS_REG))])]
12010 {
12011   operands[3] = gen_lowpart (QImode, operands[2]);
12012   ix86_expand_clear (operands[2]);
12013 })
12014
12015 (define_insn "*ffs<mode>_1"
12016   [(set (reg:CCZ FLAGS_REG)
12017         (compare:CCZ (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12018                      (const_int 0)))
12019    (set (match_operand:SWI48 0 "register_operand" "=r")
12020         (ctz:SWI48 (match_dup 1)))]
12021   ""
12022   "bsf{<imodesuffix>}\t{%1, %0|%0, %1}"
12023   [(set_attr "type" "alu1")
12024    (set_attr "prefix_0f" "1")
12025    (set_attr "mode" "<MODE>")])
12026
12027 (define_insn "ctz<mode>2"
12028   [(set (match_operand:SWI248 0 "register_operand" "=r")
12029         (ctz:SWI248 (match_operand:SWI248 1 "nonimmediate_operand" "rm")))
12030    (clobber (reg:CC FLAGS_REG))]
12031   ""
12032 {
12033   if (TARGET_BMI)
12034     return "tzcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
12035   else
12036     return "bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
12037 }
12038   [(set_attr "type" "alu1")
12039    (set_attr "prefix_0f" "1")
12040    (set (attr "prefix_rep") (symbol_ref "TARGET_BMI"))
12041    (set_attr "mode" "<MODE>")])
12042
12043 (define_expand "clz<mode>2"
12044   [(parallel
12045      [(set (match_operand:SWI248 0 "register_operand" "")
12046            (minus:SWI248
12047              (match_dup 2)
12048              (clz:SWI248 (match_operand:SWI248 1 "nonimmediate_operand" ""))))
12049       (clobber (reg:CC FLAGS_REG))])
12050    (parallel
12051      [(set (match_dup 0) (xor:SWI248 (match_dup 0) (match_dup 2)))
12052       (clobber (reg:CC FLAGS_REG))])]
12053   ""
12054 {
12055   if (TARGET_ABM)
12056     {
12057       emit_insn (gen_clz<mode>2_abm (operands[0], operands[1]));
12058       DONE;
12059     }
12060   operands[2] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1);
12061 })
12062
12063 (define_insn "clz<mode>2_abm"
12064   [(set (match_operand:SWI248 0 "register_operand" "=r")
12065         (clz:SWI248 (match_operand:SWI248 1 "nonimmediate_operand" "rm")))
12066    (clobber (reg:CC FLAGS_REG))]
12067   "TARGET_ABM || TARGET_BMI"
12068   "lzcnt{<imodesuffix>}\t{%1, %0|%0, %1}"
12069   [(set_attr "prefix_rep" "1")
12070    (set_attr "type" "bitmanip")
12071    (set_attr "mode" "<MODE>")])
12072
12073 ;; BMI instructions.
12074 (define_insn "*bmi_andn_<mode>"
12075   [(set (match_operand:SWI48 0 "register_operand" "=r")
12076         (and:SWI48
12077           (not:SWI48
12078             (match_operand:SWI48 1 "register_operand" "r"))
12079             (match_operand:SWI48 2 "nonimmediate_operand" "rm")))
12080    (clobber (reg:CC FLAGS_REG))]
12081   "TARGET_BMI"
12082   "andn\t{%2, %1, %0|%0, %1, %2}"
12083   [(set_attr "type" "bitmanip")
12084    (set_attr "mode" "<MODE>")])
12085
12086 (define_insn "bmi_bextr_<mode>"
12087   [(set (match_operand:SWI48 0 "register_operand" "=r")
12088         (unspec:SWI48 [(match_operand:SWI48 1 "nonimmediate_operand" "rm")
12089                        (match_operand:SWI48 2 "register_operand" "r")]
12090                        UNSPEC_BEXTR))
12091    (clobber (reg:CC FLAGS_REG))]
12092   "TARGET_BMI"
12093   "bextr\t{%2, %1, %0|%0, %1, %2}"
12094   [(set_attr "type" "bitmanip")
12095    (set_attr "mode" "<MODE>")])
12096
12097 (define_insn "*bmi_blsi_<mode>"
12098   [(set (match_operand:SWI48 0 "register_operand" "=r")
12099         (and:SWI48
12100           (neg:SWI48
12101             (match_operand:SWI48 1 "nonimmediate_operand" "rm"))
12102           (match_dup 1)))
12103    (clobber (reg:CC FLAGS_REG))]
12104   "TARGET_BMI"
12105   "blsi\t{%1, %0|%0, %1}"
12106   [(set_attr "type" "bitmanip")
12107    (set_attr "mode" "<MODE>")])
12108
12109 (define_insn "*bmi_blsmsk_<mode>"
12110   [(set (match_operand:SWI48 0 "register_operand" "=r")
12111         (xor:SWI48
12112           (plus:SWI48
12113             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12114             (const_int -1))
12115           (match_dup 1)))
12116    (clobber (reg:CC FLAGS_REG))]
12117   "TARGET_BMI"
12118   "blsmsk\t{%1, %0|%0, %1}"
12119   [(set_attr "type" "bitmanip")
12120    (set_attr "mode" "<MODE>")])
12121
12122 (define_insn "*bmi_blsr_<mode>"
12123   [(set (match_operand:SWI48 0 "register_operand" "=r")
12124         (and:SWI48
12125           (plus:SWI48
12126             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12127             (const_int -1))
12128           (match_dup 1)))
12129    (clobber (reg:CC FLAGS_REG))]
12130    "TARGET_BMI"
12131    "blsr\t{%1, %0|%0, %1}"
12132   [(set_attr "type" "bitmanip")
12133    (set_attr "mode" "<MODE>")])
12134
12135 ;; TBM instructions.
12136 (define_insn "tbm_bextri_<mode>"
12137   [(set (match_operand:SWI48 0 "register_operand" "=r")
12138         (zero_extract:SWI48
12139           (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12140           (match_operand:SWI48 2 "const_0_to_255_operand" "n")
12141           (match_operand:SWI48 3 "const_0_to_255_operand" "n")))
12142    (clobber (reg:CC FLAGS_REG))]
12143    "TARGET_TBM"
12144 {
12145   operands[2] = GEN_INT (INTVAL (operands[2]) << 8 | INTVAL (operands[3]));
12146   return "bextr\t{%2, %1, %0|%0, %1, %2}";
12147 }
12148   [(set_attr "type" "bitmanip")
12149    (set_attr "mode" "<MODE>")])
12150
12151 (define_insn "*tbm_blcfill_<mode>"
12152   [(set (match_operand:SWI48 0 "register_operand" "=r")
12153         (and:SWI48
12154           (plus:SWI48
12155             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12156             (const_int 1))
12157           (match_dup 1)))
12158    (clobber (reg:CC FLAGS_REG))]
12159    "TARGET_TBM"
12160    "blcfill\t{%1, %0|%0, %1}"
12161   [(set_attr "type" "bitmanip")
12162    (set_attr "mode" "<MODE>")])
12163
12164 (define_insn "*tbm_blci_<mode>"
12165   [(set (match_operand:SWI48 0 "register_operand" "=r")
12166         (ior:SWI48
12167           (not:SWI48
12168             (plus:SWI48
12169               (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12170               (const_int 1)))
12171           (match_dup 1)))
12172    (clobber (reg:CC FLAGS_REG))]
12173    "TARGET_TBM"
12174    "blci\t{%1, %0|%0, %1}"
12175   [(set_attr "type" "bitmanip")
12176    (set_attr "mode" "<MODE>")])
12177
12178 (define_insn "*tbm_blcic_<mode>"
12179   [(set (match_operand:SWI48 0 "register_operand" "=r")
12180         (and:SWI48
12181           (plus:SWI48
12182             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12183             (const_int 1))
12184           (not:SWI48
12185             (match_dup 1))))
12186    (clobber (reg:CC FLAGS_REG))]
12187    "TARGET_TBM"
12188    "blcic\t{%1, %0|%0, %1}"
12189   [(set_attr "type" "bitmanip")
12190    (set_attr "mode" "<MODE>")])
12191
12192 (define_insn "*tbm_blcmsk_<mode>"
12193   [(set (match_operand:SWI48 0 "register_operand" "=r")
12194         (xor:SWI48
12195           (plus:SWI48
12196             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12197             (const_int 1))
12198           (match_dup 1)))
12199    (clobber (reg:CC FLAGS_REG))]
12200    "TARGET_TBM"
12201    "blcmsk\t{%1, %0|%0, %1}"
12202   [(set_attr "type" "bitmanip")
12203    (set_attr "mode" "<MODE>")])
12204
12205 (define_insn "*tbm_blcs_<mode>"
12206   [(set (match_operand:SWI48 0 "register_operand" "=r")
12207         (ior:SWI48
12208           (plus:SWI48
12209             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12210             (const_int 1))
12211           (match_dup 1)))
12212    (clobber (reg:CC FLAGS_REG))]
12213    "TARGET_TBM"
12214    "blcs\t{%1, %0|%0, %1}"
12215   [(set_attr "type" "bitmanip")
12216    (set_attr "mode" "<MODE>")])
12217
12218 (define_insn "*tbm_blsfill_<mode>"
12219   [(set (match_operand:SWI48 0 "register_operand" "=r")
12220         (ior:SWI48
12221           (plus:SWI48
12222             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12223             (const_int -1))
12224           (match_dup 1)))
12225    (clobber (reg:CC FLAGS_REG))]
12226    "TARGET_TBM"
12227    "blsfill\t{%1, %0|%0, %1}"
12228   [(set_attr "type" "bitmanip")
12229    (set_attr "mode" "<MODE>")])
12230
12231 (define_insn "*tbm_blsic_<mode>"
12232   [(set (match_operand:SWI48 0 "register_operand" "=r")
12233         (ior:SWI48
12234           (plus:SWI48
12235             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12236             (const_int -1))
12237           (not:SWI48
12238             (match_dup 1))))
12239    (clobber (reg:CC FLAGS_REG))]
12240    "TARGET_TBM"
12241    "blsic\t{%1, %0|%0, %1}"
12242   [(set_attr "type" "bitmanip")
12243    (set_attr "mode" "<MODE>")])
12244
12245 (define_insn "*tbm_t1mskc_<mode>"
12246   [(set (match_operand:SWI48 0 "register_operand" "=r")
12247         (ior:SWI48
12248           (plus:SWI48
12249             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12250             (const_int 1))
12251           (not:SWI48
12252             (match_dup 1))))
12253    (clobber (reg:CC FLAGS_REG))]
12254    "TARGET_TBM"
12255    "t1mskc\t{%1, %0|%0, %1}"
12256   [(set_attr "type" "bitmanip")
12257    (set_attr "mode" "<MODE>")])
12258
12259 (define_insn "*tbm_tzmsk_<mode>"
12260   [(set (match_operand:SWI48 0 "register_operand" "=r")
12261         (and:SWI48
12262           (plus:SWI48
12263             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12264             (const_int -1))
12265           (not:SWI48
12266             (match_dup 1))))
12267    (clobber (reg:CC FLAGS_REG))]
12268    "TARGET_TBM"
12269    "tzmsk\t{%1, %0|%0, %1}"
12270   [(set_attr "type" "bitmanip")
12271    (set_attr "mode" "<MODE>")])
12272
12273 (define_insn "bsr_rex64"
12274   [(set (match_operand:DI 0 "register_operand" "=r")
12275         (minus:DI (const_int 63)
12276                   (clz:DI (match_operand:DI 1 "nonimmediate_operand" "rm"))))
12277    (clobber (reg:CC FLAGS_REG))]
12278   "TARGET_64BIT"
12279   "bsr{q}\t{%1, %0|%0, %1}"
12280   [(set_attr "type" "alu1")
12281    (set_attr "prefix_0f" "1")
12282    (set_attr "mode" "DI")])
12283
12284 (define_insn "bsr"
12285   [(set (match_operand:SI 0 "register_operand" "=r")
12286         (minus:SI (const_int 31)
12287                   (clz:SI (match_operand:SI 1 "nonimmediate_operand" "rm"))))
12288    (clobber (reg:CC FLAGS_REG))]
12289   ""
12290   "bsr{l}\t{%1, %0|%0, %1}"
12291   [(set_attr "type" "alu1")
12292    (set_attr "prefix_0f" "1")
12293    (set_attr "mode" "SI")])
12294
12295 (define_insn "*bsrhi"
12296   [(set (match_operand:HI 0 "register_operand" "=r")
12297         (minus:HI (const_int 15)
12298                   (clz:HI (match_operand:HI 1 "nonimmediate_operand" "rm"))))
12299    (clobber (reg:CC FLAGS_REG))]
12300   ""
12301   "bsr{w}\t{%1, %0|%0, %1}"
12302   [(set_attr "type" "alu1")
12303    (set_attr "prefix_0f" "1")
12304    (set_attr "mode" "HI")])
12305
12306 (define_insn "popcount<mode>2"
12307   [(set (match_operand:SWI248 0 "register_operand" "=r")
12308         (popcount:SWI248
12309           (match_operand:SWI248 1 "nonimmediate_operand" "rm")))
12310    (clobber (reg:CC FLAGS_REG))]
12311   "TARGET_POPCNT"
12312 {
12313 #if TARGET_MACHO
12314   return "popcnt\t{%1, %0|%0, %1}";
12315 #else
12316   return "popcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
12317 #endif
12318 }
12319   [(set_attr "prefix_rep" "1")
12320    (set_attr "type" "bitmanip")
12321    (set_attr "mode" "<MODE>")])
12322
12323 (define_insn "*popcount<mode>2_cmp"
12324   [(set (reg FLAGS_REG)
12325         (compare
12326           (popcount:SWI248
12327             (match_operand:SWI248 1 "nonimmediate_operand" "rm"))
12328           (const_int 0)))
12329    (set (match_operand:SWI248 0 "register_operand" "=r")
12330         (popcount:SWI248 (match_dup 1)))]
12331   "TARGET_POPCNT && ix86_match_ccmode (insn, CCZmode)"
12332 {
12333 #if TARGET_MACHO
12334   return "popcnt\t{%1, %0|%0, %1}";
12335 #else
12336   return "popcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
12337 #endif
12338 }
12339   [(set_attr "prefix_rep" "1")
12340    (set_attr "type" "bitmanip")
12341    (set_attr "mode" "<MODE>")])
12342
12343 (define_insn "*popcountsi2_cmp_zext"
12344   [(set (reg FLAGS_REG)
12345         (compare
12346           (popcount:SI (match_operand:SI 1 "nonimmediate_operand" "rm"))
12347           (const_int 0)))
12348    (set (match_operand:DI 0 "register_operand" "=r")
12349         (zero_extend:DI(popcount:SI (match_dup 1))))]
12350   "TARGET_64BIT && TARGET_POPCNT && ix86_match_ccmode (insn, CCZmode)"
12351 {
12352 #if TARGET_MACHO
12353   return "popcnt\t{%1, %0|%0, %1}";
12354 #else
12355   return "popcnt{l}\t{%1, %0|%0, %1}";
12356 #endif
12357 }
12358   [(set_attr "prefix_rep" "1")
12359    (set_attr "type" "bitmanip")
12360    (set_attr "mode" "SI")])
12361
12362 (define_expand "bswap<mode>2"
12363   [(set (match_operand:SWI48 0 "register_operand" "")
12364         (bswap:SWI48 (match_operand:SWI48 1 "register_operand" "")))]
12365   ""
12366 {
12367   if (<MODE>mode == SImode && !(TARGET_BSWAP || TARGET_MOVBE))
12368     {
12369       rtx x = operands[0];
12370
12371       emit_move_insn (x, operands[1]);
12372       emit_insn (gen_bswaphi_lowpart (gen_lowpart (HImode, x)));
12373       emit_insn (gen_rotlsi3 (x, x, GEN_INT (16)));
12374       emit_insn (gen_bswaphi_lowpart (gen_lowpart (HImode, x)));
12375       DONE;
12376     }
12377 })
12378
12379 (define_insn "*bswap<mode>2_movbe"
12380   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=r,r,m")
12381         (bswap:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "0,m,r")))]
12382   "TARGET_MOVBE
12383    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
12384   "@
12385     bswap\t%0
12386     movbe\t{%1, %0|%0, %1}
12387     movbe\t{%1, %0|%0, %1}"
12388   [(set_attr "type" "bitmanip,imov,imov")
12389    (set_attr "modrm" "0,1,1")
12390    (set_attr "prefix_0f" "*,1,1")
12391    (set_attr "prefix_extra" "*,1,1")
12392    (set_attr "mode" "<MODE>")])
12393
12394 (define_insn "*bswap<mode>2_1"
12395   [(set (match_operand:SWI48 0 "register_operand" "=r")
12396         (bswap:SWI48 (match_operand:SWI48 1 "register_operand" "0")))]
12397   "TARGET_BSWAP"
12398   "bswap\t%0"
12399   [(set_attr "type" "bitmanip")
12400    (set_attr "modrm" "0")
12401    (set_attr "mode" "<MODE>")])
12402
12403 (define_insn "*bswaphi_lowpart_1"
12404   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+Q,r"))
12405         (bswap:HI (match_dup 0)))
12406    (clobber (reg:CC FLAGS_REG))]
12407   "TARGET_USE_XCHGB || optimize_function_for_size_p (cfun)"
12408   "@
12409     xchg{b}\t{%h0, %b0|%b0, %h0}
12410     rol{w}\t{$8, %0|%0, 8}"
12411   [(set_attr "length" "2,4")
12412    (set_attr "mode" "QI,HI")])
12413
12414 (define_insn "bswaphi_lowpart"
12415   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+r"))
12416         (bswap:HI (match_dup 0)))
12417    (clobber (reg:CC FLAGS_REG))]
12418   ""
12419   "rol{w}\t{$8, %0|%0, 8}"
12420   [(set_attr "length" "4")
12421    (set_attr "mode" "HI")])
12422
12423 (define_expand "paritydi2"
12424   [(set (match_operand:DI 0 "register_operand" "")
12425         (parity:DI (match_operand:DI 1 "register_operand" "")))]
12426   "! TARGET_POPCNT"
12427 {
12428   rtx scratch = gen_reg_rtx (QImode);
12429   rtx cond;
12430
12431   emit_insn (gen_paritydi2_cmp (NULL_RTX, NULL_RTX,
12432                                 NULL_RTX, operands[1]));
12433
12434   cond = gen_rtx_fmt_ee (ORDERED, QImode,
12435                          gen_rtx_REG (CCmode, FLAGS_REG),
12436                          const0_rtx);
12437   emit_insn (gen_rtx_SET (VOIDmode, scratch, cond));
12438
12439   if (TARGET_64BIT)
12440     emit_insn (gen_zero_extendqidi2 (operands[0], scratch));
12441   else
12442     {
12443       rtx tmp = gen_reg_rtx (SImode);
12444
12445       emit_insn (gen_zero_extendqisi2 (tmp, scratch));
12446       emit_insn (gen_zero_extendsidi2 (operands[0], tmp));
12447     }
12448   DONE;
12449 })
12450
12451 (define_expand "paritysi2"
12452   [(set (match_operand:SI 0 "register_operand" "")
12453         (parity:SI (match_operand:SI 1 "register_operand" "")))]
12454   "! TARGET_POPCNT"
12455 {
12456   rtx scratch = gen_reg_rtx (QImode);
12457   rtx cond;
12458
12459   emit_insn (gen_paritysi2_cmp (NULL_RTX, NULL_RTX, operands[1]));
12460
12461   cond = gen_rtx_fmt_ee (ORDERED, QImode,
12462                          gen_rtx_REG (CCmode, FLAGS_REG),
12463                          const0_rtx);
12464   emit_insn (gen_rtx_SET (VOIDmode, scratch, cond));
12465
12466   emit_insn (gen_zero_extendqisi2 (operands[0], scratch));
12467   DONE;
12468 })
12469
12470 (define_insn_and_split "paritydi2_cmp"
12471   [(set (reg:CC FLAGS_REG)
12472         (unspec:CC [(match_operand:DI 3 "register_operand" "0")]
12473                    UNSPEC_PARITY))
12474    (clobber (match_scratch:DI 0 "=r"))
12475    (clobber (match_scratch:SI 1 "=&r"))
12476    (clobber (match_scratch:HI 2 "=Q"))]
12477   "! TARGET_POPCNT"
12478   "#"
12479   "&& reload_completed"
12480   [(parallel
12481      [(set (match_dup 1)
12482            (xor:SI (match_dup 1) (match_dup 4)))
12483       (clobber (reg:CC FLAGS_REG))])
12484    (parallel
12485      [(set (reg:CC FLAGS_REG)
12486            (unspec:CC [(match_dup 1)] UNSPEC_PARITY))
12487       (clobber (match_dup 1))
12488       (clobber (match_dup 2))])]
12489 {
12490   operands[4] = gen_lowpart (SImode, operands[3]);
12491
12492   if (TARGET_64BIT)
12493     {
12494       emit_move_insn (operands[1], gen_lowpart (SImode, operands[3]));
12495       emit_insn (gen_lshrdi3 (operands[3], operands[3], GEN_INT (32)));
12496     }
12497   else
12498     operands[1] = gen_highpart (SImode, operands[3]);
12499 })
12500
12501 (define_insn_and_split "paritysi2_cmp"
12502   [(set (reg:CC FLAGS_REG)
12503         (unspec:CC [(match_operand:SI 2 "register_operand" "0")]
12504                    UNSPEC_PARITY))
12505    (clobber (match_scratch:SI 0 "=r"))
12506    (clobber (match_scratch:HI 1 "=&Q"))]
12507   "! TARGET_POPCNT"
12508   "#"
12509   "&& reload_completed"
12510   [(parallel
12511      [(set (match_dup 1)
12512            (xor:HI (match_dup 1) (match_dup 3)))
12513       (clobber (reg:CC FLAGS_REG))])
12514    (parallel
12515      [(set (reg:CC FLAGS_REG)
12516            (unspec:CC [(match_dup 1)] UNSPEC_PARITY))
12517       (clobber (match_dup 1))])]
12518 {
12519   operands[3] = gen_lowpart (HImode, operands[2]);
12520
12521   emit_move_insn (operands[1], gen_lowpart (HImode, operands[2]));
12522   emit_insn (gen_lshrsi3 (operands[2], operands[2], GEN_INT (16)));
12523 })
12524
12525 (define_insn "*parityhi2_cmp"
12526   [(set (reg:CC FLAGS_REG)
12527         (unspec:CC [(match_operand:HI 1 "register_operand" "0")]
12528                    UNSPEC_PARITY))
12529    (clobber (match_scratch:HI 0 "=Q"))]
12530   "! TARGET_POPCNT"
12531   "xor{b}\t{%h0, %b0|%b0, %h0}"
12532   [(set_attr "length" "2")
12533    (set_attr "mode" "HI")])
12534 \f
12535 ;; Thread-local storage patterns for ELF.
12536 ;;
12537 ;; Note that these code sequences must appear exactly as shown
12538 ;; in order to allow linker relaxation.
12539
12540 (define_insn "*tls_global_dynamic_32_gnu"
12541   [(set (match_operand:SI 0 "register_operand" "=a")
12542         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
12543                     (match_operand:SI 2 "tls_symbolic_operand" "")
12544                     (match_operand:SI 3 "call_insn_operand" "")]
12545                     UNSPEC_TLS_GD))
12546    (clobber (match_scratch:SI 4 "=d"))
12547    (clobber (match_scratch:SI 5 "=c"))
12548    (clobber (reg:CC FLAGS_REG))]
12549   "!TARGET_64BIT && TARGET_GNU_TLS"
12550   "lea{l}\t{%a2@tlsgd(,%1,1), %0|%0, %a2@tlsgd[%1*1]}\;call\t%P3"
12551   [(set_attr "type" "multi")
12552    (set_attr "length" "12")])
12553
12554 (define_expand "tls_global_dynamic_32"
12555   [(parallel [(set (match_operand:SI 0 "register_operand" "")
12556                    (unspec:SI
12557                     [(match_operand:SI 2 "register_operand" "")
12558                      (match_operand:SI 1 "tls_symbolic_operand" "")
12559                      (match_operand:SI 3 "call_insn_operand" "")]
12560                     UNSPEC_TLS_GD))
12561               (clobber (match_scratch:SI 4 ""))
12562               (clobber (match_scratch:SI 5 ""))
12563               (clobber (reg:CC FLAGS_REG))])])
12564
12565 (define_insn "*tls_global_dynamic_64"
12566   [(set (match_operand:DI 0 "register_operand" "=a")
12567         (call:DI (mem:QI (match_operand:DI 2 "call_insn_operand" ""))
12568                  (match_operand:DI 3 "" "")))
12569    (unspec:DI [(match_operand:DI 1 "tls_symbolic_operand" "")]
12570               UNSPEC_TLS_GD)]
12571   "TARGET_64BIT"
12572   { return ASM_BYTE "0x66\n\tlea{q}\t{%a1@tlsgd(%%rip), %%rdi|rdi, %a1@tlsgd[rip]}\n" ASM_SHORT "0x6666\n\trex64\n\tcall\t%P2"; }
12573   [(set_attr "type" "multi")
12574    (set_attr "length" "16")])
12575
12576 (define_expand "tls_global_dynamic_64"
12577   [(parallel [(set (match_operand:DI 0 "register_operand" "")
12578                    (call:DI
12579                      (mem:QI (match_operand:DI 2 "call_insn_operand" ""))
12580                      (const_int 0)))
12581               (unspec:DI [(match_operand:DI 1 "tls_symbolic_operand" "")]
12582                          UNSPEC_TLS_GD)])])
12583
12584 (define_insn "*tls_local_dynamic_base_32_gnu"
12585   [(set (match_operand:SI 0 "register_operand" "=a")
12586         (unspec:SI [(match_operand:SI 1 "register_operand" "b")
12587                     (match_operand:SI 2 "call_insn_operand" "")]
12588                    UNSPEC_TLS_LD_BASE))
12589    (clobber (match_scratch:SI 3 "=d"))
12590    (clobber (match_scratch:SI 4 "=c"))
12591    (clobber (reg:CC FLAGS_REG))]
12592   "!TARGET_64BIT && TARGET_GNU_TLS"
12593   "lea{l}\t{%&@tlsldm(%1), %0|%0, %&@tlsldm[%1]}\;call\t%P2"
12594   [(set_attr "type" "multi")
12595    (set_attr "length" "11")])
12596
12597 (define_expand "tls_local_dynamic_base_32"
12598   [(parallel [(set (match_operand:SI 0 "register_operand" "")
12599                    (unspec:SI [(match_operand:SI 1 "register_operand" "")
12600                                (match_operand:SI 2 "call_insn_operand" "")]
12601                               UNSPEC_TLS_LD_BASE))
12602               (clobber (match_scratch:SI 3 ""))
12603               (clobber (match_scratch:SI 4 ""))
12604               (clobber (reg:CC FLAGS_REG))])])
12605
12606 (define_insn "*tls_local_dynamic_base_64"
12607   [(set (match_operand:DI 0 "register_operand" "=a")
12608         (call:DI (mem:QI (match_operand:DI 1 "call_insn_operand" ""))
12609                  (match_operand:DI 2 "" "")))
12610    (unspec:DI [(const_int 0)] UNSPEC_TLS_LD_BASE)]
12611   "TARGET_64BIT"
12612   "lea{q}\t{%&@tlsld(%%rip), %%rdi|rdi, %&@tlsld[rip]}\;call\t%P1"
12613   [(set_attr "type" "multi")
12614    (set_attr "length" "12")])
12615
12616 (define_expand "tls_local_dynamic_base_64"
12617   [(parallel [(set (match_operand:DI 0 "register_operand" "")
12618                    (call:DI
12619                      (mem:QI (match_operand:DI 1 "call_insn_operand" ""))
12620                      (const_int 0)))
12621               (unspec:DI [(const_int 0)] UNSPEC_TLS_LD_BASE)])])
12622
12623 ;; Local dynamic of a single variable is a lose.  Show combine how
12624 ;; to convert that back to global dynamic.
12625
12626 (define_insn_and_split "*tls_local_dynamic_32_once"
12627   [(set (match_operand:SI 0 "register_operand" "=a")
12628         (plus:SI (unspec:SI [(match_operand:SI 1 "register_operand" "b")
12629                              (match_operand:SI 2 "call_insn_operand" "")]
12630                             UNSPEC_TLS_LD_BASE)
12631                  (const:SI (unspec:SI
12632                             [(match_operand:SI 3 "tls_symbolic_operand" "")]
12633                             UNSPEC_DTPOFF))))
12634    (clobber (match_scratch:SI 4 "=d"))
12635    (clobber (match_scratch:SI 5 "=c"))
12636    (clobber (reg:CC FLAGS_REG))]
12637   ""
12638   "#"
12639   ""
12640   [(parallel [(set (match_dup 0)
12641                    (unspec:SI [(match_dup 1) (match_dup 3) (match_dup 2)]
12642                               UNSPEC_TLS_GD))
12643               (clobber (match_dup 4))
12644               (clobber (match_dup 5))
12645               (clobber (reg:CC FLAGS_REG))])])
12646
12647 ;; Segment register for the thread base ptr load
12648 (define_mode_attr tp_seg [(SI "gs") (DI "fs")])
12649
12650 ;; Load and add the thread base pointer from %gs:0.
12651 (define_insn "*load_tp_<mode>"
12652   [(set (match_operand:P 0 "register_operand" "=r")
12653         (unspec:P [(const_int 0)] UNSPEC_TP))]
12654   ""
12655   "mov{<imodesuffix>}\t{%%<tp_seg>:0, %0|%0, <iptrsize> PTR <tp_seg>:0}"
12656   [(set_attr "type" "imov")
12657    (set_attr "modrm" "0")
12658    (set_attr "length" "7")
12659    (set_attr "memory" "load")
12660    (set_attr "imm_disp" "false")])
12661
12662 (define_insn "*add_tp_<mode>"
12663   [(set (match_operand:P 0 "register_operand" "=r")
12664         (plus:P (unspec:P [(const_int 0)] UNSPEC_TP)
12665                 (match_operand:P 1 "register_operand" "0")))
12666    (clobber (reg:CC FLAGS_REG))]
12667   ""
12668   "add{<imodesuffix>}\t{%%<tp_seg>:0, %0|%0, <iptrsize> PTR <tp_seg>:0}"
12669   [(set_attr "type" "alu")
12670    (set_attr "modrm" "0")
12671    (set_attr "length" "7")
12672    (set_attr "memory" "load")
12673    (set_attr "imm_disp" "false")])
12674
12675 ;; The Sun linker took the AMD64 TLS spec literally and can only handle
12676 ;; %rax as destination of the initial executable code sequence.
12677 (define_insn "tls_initial_exec_64_sun"
12678   [(set (match_operand:DI 0 "register_operand" "=a")
12679         (unspec:DI
12680          [(match_operand:DI 1 "tls_symbolic_operand" "")]
12681          UNSPEC_TLS_IE_SUN))
12682    (clobber (reg:CC FLAGS_REG))]
12683   "TARGET_64BIT && TARGET_SUN_TLS"
12684   "mov{q}\t{%%fs:0, %0|%0, QWORD PTR fs:0}\n\tadd{q}\t{%a1@gottpoff(%%rip), %0|%0, %a1@gottpoff[rip]}"
12685   [(set_attr "type" "multi")])
12686
12687 ;; GNU2 TLS patterns can be split.
12688
12689 (define_expand "tls_dynamic_gnu2_32"
12690   [(set (match_dup 3)
12691         (plus:SI (match_operand:SI 2 "register_operand" "")
12692                  (const:SI
12693                   (unspec:SI [(match_operand:SI 1 "tls_symbolic_operand" "")]
12694                              UNSPEC_TLSDESC))))
12695    (parallel
12696     [(set (match_operand:SI 0 "register_operand" "")
12697           (unspec:SI [(match_dup 1) (match_dup 3)
12698                       (match_dup 2) (reg:SI SP_REG)]
12699                       UNSPEC_TLSDESC))
12700      (clobber (reg:CC FLAGS_REG))])]
12701   "!TARGET_64BIT && TARGET_GNU2_TLS"
12702 {
12703   operands[3] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
12704   ix86_tls_descriptor_calls_expanded_in_cfun = true;
12705 })
12706
12707 (define_insn "*tls_dynamic_lea_32"
12708   [(set (match_operand:SI 0 "register_operand" "=r")
12709         (plus:SI (match_operand:SI 1 "register_operand" "b")
12710                  (const:SI
12711                   (unspec:SI [(match_operand:SI 2 "tls_symbolic_operand" "")]
12712                               UNSPEC_TLSDESC))))]
12713   "!TARGET_64BIT && TARGET_GNU2_TLS"
12714   "lea{l}\t{%a2@TLSDESC(%1), %0|%0, %a2@TLSDESC[%1]}"
12715   [(set_attr "type" "lea")
12716    (set_attr "mode" "SI")
12717    (set_attr "length" "6")
12718    (set_attr "length_address" "4")])
12719
12720 (define_insn "*tls_dynamic_call_32"
12721   [(set (match_operand:SI 0 "register_operand" "=a")
12722         (unspec:SI [(match_operand:SI 1 "tls_symbolic_operand" "")
12723                     (match_operand:SI 2 "register_operand" "0")
12724                     ;; we have to make sure %ebx still points to the GOT
12725                     (match_operand:SI 3 "register_operand" "b")
12726                     (reg:SI SP_REG)]
12727                    UNSPEC_TLSDESC))
12728    (clobber (reg:CC FLAGS_REG))]
12729   "!TARGET_64BIT && TARGET_GNU2_TLS"
12730   "call\t{*%a1@TLSCALL(%2)|[DWORD PTR [%2+%a1@TLSCALL]]}"
12731   [(set_attr "type" "call")
12732    (set_attr "length" "2")
12733    (set_attr "length_address" "0")])
12734
12735 (define_insn_and_split "*tls_dynamic_gnu2_combine_32"
12736   [(set (match_operand:SI 0 "register_operand" "=&a")
12737         (plus:SI
12738          (unspec:SI [(match_operand:SI 3 "tls_modbase_operand" "")
12739                      (match_operand:SI 4 "" "")
12740                      (match_operand:SI 2 "register_operand" "b")
12741                      (reg:SI SP_REG)]
12742                     UNSPEC_TLSDESC)
12743          (const:SI (unspec:SI
12744                     [(match_operand:SI 1 "tls_symbolic_operand" "")]
12745                     UNSPEC_DTPOFF))))
12746    (clobber (reg:CC FLAGS_REG))]
12747   "!TARGET_64BIT && TARGET_GNU2_TLS"
12748   "#"
12749   ""
12750   [(set (match_dup 0) (match_dup 5))]
12751 {
12752   operands[5] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
12753   emit_insn (gen_tls_dynamic_gnu2_32 (operands[5], operands[1], operands[2]));
12754 })
12755
12756 (define_expand "tls_dynamic_gnu2_64"
12757   [(set (match_dup 2)
12758         (unspec:DI [(match_operand:DI 1 "tls_symbolic_operand" "")]
12759                    UNSPEC_TLSDESC))
12760    (parallel
12761     [(set (match_operand:DI 0 "register_operand" "")
12762           (unspec:DI [(match_dup 1) (match_dup 2) (reg:DI SP_REG)]
12763                      UNSPEC_TLSDESC))
12764      (clobber (reg:CC FLAGS_REG))])]
12765   "TARGET_64BIT && TARGET_GNU2_TLS"
12766 {
12767   operands[2] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
12768   ix86_tls_descriptor_calls_expanded_in_cfun = true;
12769 })
12770
12771 (define_insn "*tls_dynamic_lea_64"
12772   [(set (match_operand:DI 0 "register_operand" "=r")
12773         (unspec:DI [(match_operand:DI 1 "tls_symbolic_operand" "")]
12774                    UNSPEC_TLSDESC))]
12775   "TARGET_64BIT && TARGET_GNU2_TLS"
12776   "lea{q}\t{%a1@TLSDESC(%%rip), %0|%0, %a1@TLSDESC[rip]}"
12777   [(set_attr "type" "lea")
12778    (set_attr "mode" "DI")
12779    (set_attr "length" "7")
12780    (set_attr "length_address" "4")])
12781
12782 (define_insn "*tls_dynamic_call_64"
12783   [(set (match_operand:DI 0 "register_operand" "=a")
12784         (unspec:DI [(match_operand:DI 1 "tls_symbolic_operand" "")
12785                     (match_operand:DI 2 "register_operand" "0")
12786                     (reg:DI SP_REG)]
12787                    UNSPEC_TLSDESC))
12788    (clobber (reg:CC FLAGS_REG))]
12789   "TARGET_64BIT && TARGET_GNU2_TLS"
12790   "call\t{*%a1@TLSCALL(%2)|[QWORD PTR [%2+%a1@TLSCALL]]}"
12791   [(set_attr "type" "call")
12792    (set_attr "length" "2")
12793    (set_attr "length_address" "0")])
12794
12795 (define_insn_and_split "*tls_dynamic_gnu2_combine_64"
12796   [(set (match_operand:DI 0 "register_operand" "=&a")
12797         (plus:DI
12798          (unspec:DI [(match_operand:DI 2 "tls_modbase_operand" "")
12799                      (match_operand:DI 3 "" "")
12800                      (reg:DI SP_REG)]
12801                     UNSPEC_TLSDESC)
12802          (const:DI (unspec:DI
12803                     [(match_operand:DI 1 "tls_symbolic_operand" "")]
12804                     UNSPEC_DTPOFF))))
12805    (clobber (reg:CC FLAGS_REG))]
12806   "TARGET_64BIT && TARGET_GNU2_TLS"
12807   "#"
12808   ""
12809   [(set (match_dup 0) (match_dup 4))]
12810 {
12811   operands[4] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
12812   emit_insn (gen_tls_dynamic_gnu2_64 (operands[4], operands[1]));
12813 })
12814 \f
12815 ;; These patterns match the binary 387 instructions for addM3, subM3,
12816 ;; mulM3 and divM3.  There are three patterns for each of DFmode and
12817 ;; SFmode.  The first is the normal insn, the second the same insn but
12818 ;; with one operand a conversion, and the third the same insn but with
12819 ;; the other operand a conversion.  The conversion may be SFmode or
12820 ;; SImode if the target mode DFmode, but only SImode if the target mode
12821 ;; is SFmode.
12822
12823 ;; Gcc is slightly more smart about handling normal two address instructions
12824 ;; so use special patterns for add and mull.
12825
12826 (define_insn "*fop_<mode>_comm_mixed"
12827   [(set (match_operand:MODEF 0 "register_operand" "=f,x,x")
12828         (match_operator:MODEF 3 "binary_fp_operator"
12829           [(match_operand:MODEF 1 "nonimmediate_operand" "%0,0,x")
12830            (match_operand:MODEF 2 "nonimmediate_operand" "fm,xm,xm")]))]
12831   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_MIX_SSE_I387
12832    && COMMUTATIVE_ARITH_P (operands[3])
12833    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
12834   "* return output_387_binary_op (insn, operands);"
12835   [(set (attr "type")
12836         (if_then_else (eq_attr "alternative" "1,2")
12837            (if_then_else (match_operand:MODEF 3 "mult_operator" "")
12838               (const_string "ssemul")
12839               (const_string "sseadd"))
12840            (if_then_else (match_operand:MODEF 3 "mult_operator" "")
12841               (const_string "fmul")
12842               (const_string "fop"))))
12843    (set_attr "isa" "base,noavx,avx")
12844    (set_attr "prefix" "orig,orig,vex")
12845    (set_attr "mode" "<MODE>")])
12846
12847 (define_insn "*fop_<mode>_comm_sse"
12848   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
12849         (match_operator:MODEF 3 "binary_fp_operator"
12850           [(match_operand:MODEF 1 "nonimmediate_operand" "%0,x")
12851            (match_operand:MODEF 2 "nonimmediate_operand" "xm,xm")]))]
12852   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
12853    && COMMUTATIVE_ARITH_P (operands[3])
12854    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
12855   "* return output_387_binary_op (insn, operands);"
12856   [(set (attr "type")
12857         (if_then_else (match_operand:MODEF 3 "mult_operator" "")
12858            (const_string "ssemul")
12859            (const_string "sseadd")))
12860    (set_attr "isa" "noavx,avx")
12861    (set_attr "prefix" "orig,vex")
12862    (set_attr "mode" "<MODE>")])
12863
12864 (define_insn "*fop_<mode>_comm_i387"
12865   [(set (match_operand:MODEF 0 "register_operand" "=f")
12866         (match_operator:MODEF 3 "binary_fp_operator"
12867           [(match_operand:MODEF 1 "nonimmediate_operand" "%0")
12868            (match_operand:MODEF 2 "nonimmediate_operand" "fm")]))]
12869   "TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode)
12870    && COMMUTATIVE_ARITH_P (operands[3])
12871    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
12872   "* return output_387_binary_op (insn, operands);"
12873   [(set (attr "type")
12874         (if_then_else (match_operand:MODEF 3 "mult_operator" "")
12875            (const_string "fmul")
12876            (const_string "fop")))
12877    (set_attr "mode" "<MODE>")])
12878
12879 (define_insn "*fop_<mode>_1_mixed"
12880   [(set (match_operand:MODEF 0 "register_operand" "=f,f,x,x")
12881         (match_operator:MODEF 3 "binary_fp_operator"
12882           [(match_operand:MODEF 1 "nonimmediate_operand" "0,fm,0,x")
12883            (match_operand:MODEF 2 "nonimmediate_operand" "fm,0,xm,xm")]))]
12884   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_MIX_SSE_I387
12885    && !COMMUTATIVE_ARITH_P (operands[3])
12886    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
12887   "* return output_387_binary_op (insn, operands);"
12888   [(set (attr "type")
12889         (cond [(and (eq_attr "alternative" "2,3")
12890                     (match_operand:MODEF 3 "mult_operator" ""))
12891                  (const_string "ssemul")
12892                (and (eq_attr "alternative" "2,3")
12893                     (match_operand:MODEF 3 "div_operator" ""))
12894                  (const_string "ssediv")
12895                (eq_attr "alternative" "2,3")
12896                  (const_string "sseadd")
12897                (match_operand:MODEF 3 "mult_operator" "")
12898                  (const_string "fmul")
12899                (match_operand:MODEF 3 "div_operator" "")
12900                  (const_string "fdiv")
12901               ]
12902               (const_string "fop")))
12903    (set_attr "isa" "base,base,noavx,avx")
12904    (set_attr "prefix" "orig,orig,orig,vex")
12905    (set_attr "mode" "<MODE>")])
12906
12907 (define_insn "*rcpsf2_sse"
12908   [(set (match_operand:SF 0 "register_operand" "=x")
12909         (unspec:SF [(match_operand:SF 1 "nonimmediate_operand" "xm")]
12910                    UNSPEC_RCP))]
12911   "TARGET_SSE_MATH"
12912   "%vrcpss\t{%1, %d0|%d0, %1}"
12913   [(set_attr "type" "sse")
12914    (set_attr "atom_sse_attr" "rcp")
12915    (set_attr "prefix" "maybe_vex")
12916    (set_attr "mode" "SF")])
12917
12918 (define_insn "*fop_<mode>_1_sse"
12919   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
12920         (match_operator:MODEF 3 "binary_fp_operator"
12921           [(match_operand:MODEF 1 "register_operand" "0,x")
12922            (match_operand:MODEF 2 "nonimmediate_operand" "xm,xm")]))]
12923   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
12924    && !COMMUTATIVE_ARITH_P (operands[3])"
12925   "* return output_387_binary_op (insn, operands);"
12926   [(set (attr "type")
12927         (cond [(match_operand:MODEF 3 "mult_operator" "")
12928                  (const_string "ssemul")
12929                (match_operand:MODEF 3 "div_operator" "")
12930                  (const_string "ssediv")
12931               ]
12932               (const_string "sseadd")))
12933    (set_attr "isa" "noavx,avx")
12934    (set_attr "prefix" "orig,vex")
12935    (set_attr "mode" "<MODE>")])
12936
12937 ;; This pattern is not fully shadowed by the pattern above.
12938 (define_insn "*fop_<mode>_1_i387"
12939   [(set (match_operand:MODEF 0 "register_operand" "=f,f")
12940         (match_operator:MODEF 3 "binary_fp_operator"
12941           [(match_operand:MODEF 1 "nonimmediate_operand" "0,fm")
12942            (match_operand:MODEF 2 "nonimmediate_operand" "fm,0")]))]
12943   "TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode)
12944    && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
12945    && !COMMUTATIVE_ARITH_P (operands[3])
12946    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
12947   "* return output_387_binary_op (insn, operands);"
12948   [(set (attr "type")
12949         (cond [(match_operand:MODEF 3 "mult_operator" "")
12950                  (const_string "fmul")
12951                (match_operand:MODEF 3 "div_operator" "")
12952                  (const_string "fdiv")
12953               ]
12954               (const_string "fop")))
12955    (set_attr "mode" "<MODE>")])
12956
12957 ;; ??? Add SSE splitters for these!
12958 (define_insn "*fop_<MODEF:mode>_2_i387"
12959   [(set (match_operand:MODEF 0 "register_operand" "=f,f")
12960         (match_operator:MODEF 3 "binary_fp_operator"
12961           [(float:MODEF
12962              (match_operand:X87MODEI12 1 "nonimmediate_operand" "m,?r"))
12963            (match_operand:MODEF 2 "register_operand" "0,0")]))]
12964   "TARGET_80387 && X87_ENABLE_FLOAT (<MODEF:MODE>mode, <X87MODEI12:MODE>mode)
12965    && !(SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH)
12966    && (TARGET_USE_<X87MODEI12:MODE>MODE_FIOP || optimize_function_for_size_p (cfun))"
12967   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
12968   [(set (attr "type")
12969         (cond [(match_operand:MODEF 3 "mult_operator" "")
12970                  (const_string "fmul")
12971                (match_operand:MODEF 3 "div_operator" "")
12972                  (const_string "fdiv")
12973               ]
12974               (const_string "fop")))
12975    (set_attr "fp_int_src" "true")
12976    (set_attr "mode" "<X87MODEI12:MODE>")])
12977
12978 (define_insn "*fop_<MODEF:mode>_3_i387"
12979   [(set (match_operand:MODEF 0 "register_operand" "=f,f")
12980         (match_operator:MODEF 3 "binary_fp_operator"
12981           [(match_operand:MODEF 1 "register_operand" "0,0")
12982            (float:MODEF
12983              (match_operand:X87MODEI12 2 "nonimmediate_operand" "m,?r"))]))]
12984   "TARGET_80387 && X87_ENABLE_FLOAT (<MODEF:MODE>mode, <X87MODEI12:MODE>mode)
12985    && !(SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH)
12986    && (TARGET_USE_<X87MODEI12:MODE>MODE_FIOP || optimize_function_for_size_p (cfun))"
12987   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
12988   [(set (attr "type")
12989         (cond [(match_operand:MODEF 3 "mult_operator" "")
12990                  (const_string "fmul")
12991                (match_operand:MODEF 3 "div_operator" "")
12992                  (const_string "fdiv")
12993               ]
12994               (const_string "fop")))
12995    (set_attr "fp_int_src" "true")
12996    (set_attr "mode" "<MODE>")])
12997
12998 (define_insn "*fop_df_4_i387"
12999   [(set (match_operand:DF 0 "register_operand" "=f,f")
13000         (match_operator:DF 3 "binary_fp_operator"
13001            [(float_extend:DF
13002              (match_operand:SF 1 "nonimmediate_operand" "fm,0"))
13003             (match_operand:DF 2 "register_operand" "0,f")]))]
13004   "TARGET_80387 && X87_ENABLE_ARITH (DFmode)
13005    && !(TARGET_SSE2 && TARGET_SSE_MATH)
13006    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
13007   "* return output_387_binary_op (insn, operands);"
13008   [(set (attr "type")
13009         (cond [(match_operand:DF 3 "mult_operator" "")
13010                  (const_string "fmul")
13011                (match_operand:DF 3 "div_operator" "")
13012                  (const_string "fdiv")
13013               ]
13014               (const_string "fop")))
13015    (set_attr "mode" "SF")])
13016
13017 (define_insn "*fop_df_5_i387"
13018   [(set (match_operand:DF 0 "register_operand" "=f,f")
13019         (match_operator:DF 3 "binary_fp_operator"
13020           [(match_operand:DF 1 "register_operand" "0,f")
13021            (float_extend:DF
13022             (match_operand:SF 2 "nonimmediate_operand" "fm,0"))]))]
13023   "TARGET_80387 && X87_ENABLE_ARITH (DFmode)
13024    && !(TARGET_SSE2 && TARGET_SSE_MATH)"
13025   "* return output_387_binary_op (insn, operands);"
13026   [(set (attr "type")
13027         (cond [(match_operand:DF 3 "mult_operator" "")
13028                  (const_string "fmul")
13029                (match_operand:DF 3 "div_operator" "")
13030                  (const_string "fdiv")
13031               ]
13032               (const_string "fop")))
13033    (set_attr "mode" "SF")])
13034
13035 (define_insn "*fop_df_6_i387"
13036   [(set (match_operand:DF 0 "register_operand" "=f,f")
13037         (match_operator:DF 3 "binary_fp_operator"
13038           [(float_extend:DF
13039             (match_operand:SF 1 "register_operand" "0,f"))
13040            (float_extend:DF
13041             (match_operand:SF 2 "nonimmediate_operand" "fm,0"))]))]
13042   "TARGET_80387 && X87_ENABLE_ARITH (DFmode)
13043    && !(TARGET_SSE2 && TARGET_SSE_MATH)"
13044   "* return output_387_binary_op (insn, operands);"
13045   [(set (attr "type")
13046         (cond [(match_operand:DF 3 "mult_operator" "")
13047                  (const_string "fmul")
13048                (match_operand:DF 3 "div_operator" "")
13049                  (const_string "fdiv")
13050               ]
13051               (const_string "fop")))
13052    (set_attr "mode" "SF")])
13053
13054 (define_insn "*fop_xf_comm_i387"
13055   [(set (match_operand:XF 0 "register_operand" "=f")
13056         (match_operator:XF 3 "binary_fp_operator"
13057                         [(match_operand:XF 1 "register_operand" "%0")
13058                          (match_operand:XF 2 "register_operand" "f")]))]
13059   "TARGET_80387
13060    && COMMUTATIVE_ARITH_P (operands[3])"
13061   "* return output_387_binary_op (insn, operands);"
13062   [(set (attr "type")
13063         (if_then_else (match_operand:XF 3 "mult_operator" "")
13064            (const_string "fmul")
13065            (const_string "fop")))
13066    (set_attr "mode" "XF")])
13067
13068 (define_insn "*fop_xf_1_i387"
13069   [(set (match_operand:XF 0 "register_operand" "=f,f")
13070         (match_operator:XF 3 "binary_fp_operator"
13071                         [(match_operand:XF 1 "register_operand" "0,f")
13072                          (match_operand:XF 2 "register_operand" "f,0")]))]
13073   "TARGET_80387
13074    && !COMMUTATIVE_ARITH_P (operands[3])"
13075   "* return output_387_binary_op (insn, operands);"
13076   [(set (attr "type")
13077         (cond [(match_operand:XF 3 "mult_operator" "")
13078                  (const_string "fmul")
13079                (match_operand:XF 3 "div_operator" "")
13080                  (const_string "fdiv")
13081               ]
13082               (const_string "fop")))
13083    (set_attr "mode" "XF")])
13084
13085 (define_insn "*fop_xf_2_i387"
13086   [(set (match_operand:XF 0 "register_operand" "=f,f")
13087         (match_operator:XF 3 "binary_fp_operator"
13088           [(float:XF
13089              (match_operand:X87MODEI12 1 "nonimmediate_operand" "m,?r"))
13090            (match_operand:XF 2 "register_operand" "0,0")]))]
13091   "TARGET_80387 && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))"
13092   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
13093   [(set (attr "type")
13094         (cond [(match_operand:XF 3 "mult_operator" "")
13095                  (const_string "fmul")
13096                (match_operand:XF 3 "div_operator" "")
13097                  (const_string "fdiv")
13098               ]
13099               (const_string "fop")))
13100    (set_attr "fp_int_src" "true")
13101    (set_attr "mode" "<MODE>")])
13102
13103 (define_insn "*fop_xf_3_i387"
13104   [(set (match_operand:XF 0 "register_operand" "=f,f")
13105         (match_operator:XF 3 "binary_fp_operator"
13106           [(match_operand:XF 1 "register_operand" "0,0")
13107            (float:XF
13108              (match_operand:X87MODEI12 2 "nonimmediate_operand" "m,?r"))]))]
13109   "TARGET_80387 && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))"
13110   "* return which_alternative ? \"#\" : output_387_binary_op (insn, operands);"
13111   [(set (attr "type")
13112         (cond [(match_operand:XF 3 "mult_operator" "")
13113                  (const_string "fmul")
13114                (match_operand:XF 3 "div_operator" "")
13115                  (const_string "fdiv")
13116               ]
13117               (const_string "fop")))
13118    (set_attr "fp_int_src" "true")
13119    (set_attr "mode" "<MODE>")])
13120
13121 (define_insn "*fop_xf_4_i387"
13122   [(set (match_operand:XF 0 "register_operand" "=f,f")
13123         (match_operator:XF 3 "binary_fp_operator"
13124            [(float_extend:XF
13125               (match_operand:MODEF 1 "nonimmediate_operand" "fm,0"))
13126             (match_operand:XF 2 "register_operand" "0,f")]))]
13127   "TARGET_80387"
13128   "* return output_387_binary_op (insn, operands);"
13129   [(set (attr "type")
13130         (cond [(match_operand:XF 3 "mult_operator" "")
13131                  (const_string "fmul")
13132                (match_operand:XF 3 "div_operator" "")
13133                  (const_string "fdiv")
13134               ]
13135               (const_string "fop")))
13136    (set_attr "mode" "<MODE>")])
13137
13138 (define_insn "*fop_xf_5_i387"
13139   [(set (match_operand:XF 0 "register_operand" "=f,f")
13140         (match_operator:XF 3 "binary_fp_operator"
13141           [(match_operand:XF 1 "register_operand" "0,f")
13142            (float_extend:XF
13143              (match_operand:MODEF 2 "nonimmediate_operand" "fm,0"))]))]
13144   "TARGET_80387"
13145   "* return output_387_binary_op (insn, operands);"
13146   [(set (attr "type")
13147         (cond [(match_operand:XF 3 "mult_operator" "")
13148                  (const_string "fmul")
13149                (match_operand:XF 3 "div_operator" "")
13150                  (const_string "fdiv")
13151               ]
13152               (const_string "fop")))
13153    (set_attr "mode" "<MODE>")])
13154
13155 (define_insn "*fop_xf_6_i387"
13156   [(set (match_operand:XF 0 "register_operand" "=f,f")
13157         (match_operator:XF 3 "binary_fp_operator"
13158           [(float_extend:XF
13159              (match_operand:MODEF 1 "register_operand" "0,f"))
13160            (float_extend:XF
13161              (match_operand:MODEF 2 "nonimmediate_operand" "fm,0"))]))]
13162   "TARGET_80387"
13163   "* return output_387_binary_op (insn, operands);"
13164   [(set (attr "type")
13165         (cond [(match_operand:XF 3 "mult_operator" "")
13166                  (const_string "fmul")
13167                (match_operand:XF 3 "div_operator" "")
13168                  (const_string "fdiv")
13169               ]
13170               (const_string "fop")))
13171    (set_attr "mode" "<MODE>")])
13172
13173 (define_split
13174   [(set (match_operand 0 "register_operand" "")
13175         (match_operator 3 "binary_fp_operator"
13176            [(float (match_operand:X87MODEI12 1 "register_operand" ""))
13177             (match_operand 2 "register_operand" "")]))]
13178   "reload_completed
13179    && X87_FLOAT_MODE_P (GET_MODE (operands[0]))
13180    && X87_ENABLE_FLOAT (GET_MODE (operands[0]), GET_MODE (operands[1]))"
13181   [(const_int 0)]
13182 {
13183   operands[4] = ix86_force_to_memory (GET_MODE (operands[1]), operands[1]);
13184   operands[4] = gen_rtx_FLOAT (GET_MODE (operands[0]), operands[4]);
13185   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
13186                           gen_rtx_fmt_ee (GET_CODE (operands[3]),
13187                                           GET_MODE (operands[3]),
13188                                           operands[4],
13189                                           operands[2])));
13190   ix86_free_from_memory (GET_MODE (operands[1]));
13191   DONE;
13192 })
13193
13194 (define_split
13195   [(set (match_operand 0 "register_operand" "")
13196         (match_operator 3 "binary_fp_operator"
13197            [(match_operand 1 "register_operand" "")
13198             (float (match_operand:X87MODEI12 2 "register_operand" ""))]))]
13199   "reload_completed
13200    && X87_FLOAT_MODE_P (GET_MODE (operands[0]))
13201    && X87_ENABLE_FLOAT (GET_MODE (operands[0]), GET_MODE (operands[2]))"
13202   [(const_int 0)]
13203 {
13204   operands[4] = ix86_force_to_memory (GET_MODE (operands[2]), operands[2]);
13205   operands[4] = gen_rtx_FLOAT (GET_MODE (operands[0]), operands[4]);
13206   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
13207                           gen_rtx_fmt_ee (GET_CODE (operands[3]),
13208                                           GET_MODE (operands[3]),
13209                                           operands[1],
13210                                           operands[4])));
13211   ix86_free_from_memory (GET_MODE (operands[2]));
13212   DONE;
13213 })
13214 \f
13215 ;; FPU special functions.
13216
13217 ;; This pattern implements a no-op XFmode truncation for
13218 ;; all fancy i386 XFmode math functions.
13219
13220 (define_insn "truncxf<mode>2_i387_noop_unspec"
13221   [(set (match_operand:MODEF 0 "register_operand" "=f")
13222         (unspec:MODEF [(match_operand:XF 1 "register_operand" "f")]
13223         UNSPEC_TRUNC_NOOP))]
13224   "TARGET_USE_FANCY_MATH_387"
13225   "* return output_387_reg_move (insn, operands);"
13226   [(set_attr "type" "fmov")
13227    (set_attr "mode" "<MODE>")])
13228
13229 (define_insn "sqrtxf2"
13230   [(set (match_operand:XF 0 "register_operand" "=f")
13231         (sqrt:XF (match_operand:XF 1 "register_operand" "0")))]
13232   "TARGET_USE_FANCY_MATH_387"
13233   "fsqrt"
13234   [(set_attr "type" "fpspc")
13235    (set_attr "mode" "XF")
13236    (set_attr "athlon_decode" "direct")
13237    (set_attr "amdfam10_decode" "direct")
13238    (set_attr "bdver1_decode" "direct")])
13239
13240 (define_insn "sqrt_extend<mode>xf2_i387"
13241   [(set (match_operand:XF 0 "register_operand" "=f")
13242         (sqrt:XF
13243           (float_extend:XF
13244             (match_operand:MODEF 1 "register_operand" "0"))))]
13245   "TARGET_USE_FANCY_MATH_387"
13246   "fsqrt"
13247   [(set_attr "type" "fpspc")
13248    (set_attr "mode" "XF")
13249    (set_attr "athlon_decode" "direct")
13250    (set_attr "amdfam10_decode" "direct")
13251    (set_attr "bdver1_decode" "direct")])
13252
13253 (define_insn "*rsqrtsf2_sse"
13254   [(set (match_operand:SF 0 "register_operand" "=x")
13255         (unspec:SF [(match_operand:SF 1 "nonimmediate_operand" "xm")]
13256                    UNSPEC_RSQRT))]
13257   "TARGET_SSE_MATH"
13258   "%vrsqrtss\t{%1, %d0|%d0, %1}"
13259   [(set_attr "type" "sse")
13260    (set_attr "atom_sse_attr" "rcp")
13261    (set_attr "prefix" "maybe_vex")
13262    (set_attr "mode" "SF")])
13263
13264 (define_expand "rsqrtsf2"
13265   [(set (match_operand:SF 0 "register_operand" "")
13266         (unspec:SF [(match_operand:SF 1 "nonimmediate_operand" "")]
13267                    UNSPEC_RSQRT))]
13268   "TARGET_SSE_MATH"
13269 {
13270   ix86_emit_swsqrtsf (operands[0], operands[1], SFmode, 1);
13271   DONE;
13272 })
13273
13274 (define_insn "*sqrt<mode>2_sse"
13275   [(set (match_operand:MODEF 0 "register_operand" "=x")
13276         (sqrt:MODEF
13277           (match_operand:MODEF 1 "nonimmediate_operand" "xm")))]
13278   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
13279   "%vsqrt<ssemodesuffix>\t{%1, %d0|%d0, %1}"
13280   [(set_attr "type" "sse")
13281    (set_attr "atom_sse_attr" "sqrt")
13282    (set_attr "prefix" "maybe_vex")
13283    (set_attr "mode" "<MODE>")
13284    (set_attr "athlon_decode" "*")
13285    (set_attr "amdfam10_decode" "*")
13286    (set_attr "bdver1_decode" "*")])
13287
13288 (define_expand "sqrt<mode>2"
13289   [(set (match_operand:MODEF 0 "register_operand" "")
13290         (sqrt:MODEF
13291           (match_operand:MODEF 1 "nonimmediate_operand" "")))]
13292   "(TARGET_USE_FANCY_MATH_387 && X87_ENABLE_ARITH (<MODE>mode))
13293    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
13294 {
13295   if (<MODE>mode == SFmode
13296       && TARGET_SSE_MATH && TARGET_RECIP && !optimize_function_for_size_p (cfun)
13297       && flag_finite_math_only && !flag_trapping_math
13298       && flag_unsafe_math_optimizations)
13299     {
13300       ix86_emit_swsqrtsf (operands[0], operands[1], SFmode, 0);
13301       DONE;
13302     }
13303
13304   if (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))
13305     {
13306       rtx op0 = gen_reg_rtx (XFmode);
13307       rtx op1 = force_reg (<MODE>mode, operands[1]);
13308
13309       emit_insn (gen_sqrt_extend<mode>xf2_i387 (op0, op1));
13310       emit_insn (gen_truncxf<mode>2_i387_noop_unspec (operands[0], op0));
13311       DONE;
13312    }
13313 })
13314
13315 (define_insn "fpremxf4_i387"
13316   [(set (match_operand:XF 0 "register_operand" "=f")
13317         (unspec:XF [(match_operand:XF 2 "register_operand" "0")
13318                     (match_operand:XF 3 "register_operand" "1")]
13319                    UNSPEC_FPREM_F))
13320    (set (match_operand:XF 1 "register_operand" "=u")
13321         (unspec:XF [(match_dup 2) (match_dup 3)]
13322                    UNSPEC_FPREM_U))
13323    (set (reg:CCFP FPSR_REG)
13324         (unspec:CCFP [(match_dup 2) (match_dup 3)]
13325                      UNSPEC_C2_FLAG))]
13326   "TARGET_USE_FANCY_MATH_387"
13327   "fprem"
13328   [(set_attr "type" "fpspc")
13329    (set_attr "mode" "XF")])
13330
13331 (define_expand "fmodxf3"
13332   [(use (match_operand:XF 0 "register_operand" ""))
13333    (use (match_operand:XF 1 "general_operand" ""))
13334    (use (match_operand:XF 2 "general_operand" ""))]
13335   "TARGET_USE_FANCY_MATH_387"
13336 {
13337   rtx label = gen_label_rtx ();
13338
13339   rtx op1 = gen_reg_rtx (XFmode);
13340   rtx op2 = gen_reg_rtx (XFmode);
13341
13342   emit_move_insn (op2, operands[2]);
13343   emit_move_insn (op1, operands[1]);
13344
13345   emit_label (label);
13346   emit_insn (gen_fpremxf4_i387 (op1, op2, op1, op2));
13347   ix86_emit_fp_unordered_jump (label);
13348   LABEL_NUSES (label) = 1;
13349
13350   emit_move_insn (operands[0], op1);
13351   DONE;
13352 })
13353
13354 (define_expand "fmod<mode>3"
13355   [(use (match_operand:MODEF 0 "register_operand" ""))
13356    (use (match_operand:MODEF 1 "general_operand" ""))
13357    (use (match_operand:MODEF 2 "general_operand" ""))]
13358   "TARGET_USE_FANCY_MATH_387"
13359 {
13360   rtx (*gen_truncxf) (rtx, rtx);
13361
13362   rtx label = gen_label_rtx ();
13363
13364   rtx op1 = gen_reg_rtx (XFmode);
13365   rtx op2 = gen_reg_rtx (XFmode);
13366
13367   emit_insn (gen_extend<mode>xf2 (op2, operands[2]));
13368   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
13369
13370   emit_label (label);
13371   emit_insn (gen_fpremxf4_i387 (op1, op2, op1, op2));
13372   ix86_emit_fp_unordered_jump (label);
13373   LABEL_NUSES (label) = 1;
13374
13375   /* Truncate the result properly for strict SSE math.  */
13376   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
13377       && !TARGET_MIX_SSE_I387)
13378     gen_truncxf = gen_truncxf<mode>2;
13379   else
13380     gen_truncxf = gen_truncxf<mode>2_i387_noop_unspec;
13381
13382   emit_insn (gen_truncxf (operands[0], op1));
13383   DONE;
13384 })
13385
13386 (define_insn "fprem1xf4_i387"
13387   [(set (match_operand:XF 0 "register_operand" "=f")
13388         (unspec:XF [(match_operand:XF 2 "register_operand" "0")
13389                     (match_operand:XF 3 "register_operand" "1")]
13390                    UNSPEC_FPREM1_F))
13391    (set (match_operand:XF 1 "register_operand" "=u")
13392         (unspec:XF [(match_dup 2) (match_dup 3)]
13393                    UNSPEC_FPREM1_U))
13394    (set (reg:CCFP FPSR_REG)
13395         (unspec:CCFP [(match_dup 2) (match_dup 3)]
13396                      UNSPEC_C2_FLAG))]
13397   "TARGET_USE_FANCY_MATH_387"
13398   "fprem1"
13399   [(set_attr "type" "fpspc")
13400    (set_attr "mode" "XF")])
13401
13402 (define_expand "remainderxf3"
13403   [(use (match_operand:XF 0 "register_operand" ""))
13404    (use (match_operand:XF 1 "general_operand" ""))
13405    (use (match_operand:XF 2 "general_operand" ""))]
13406   "TARGET_USE_FANCY_MATH_387"
13407 {
13408   rtx label = gen_label_rtx ();
13409
13410   rtx op1 = gen_reg_rtx (XFmode);
13411   rtx op2 = gen_reg_rtx (XFmode);
13412
13413   emit_move_insn (op2, operands[2]);
13414   emit_move_insn (op1, operands[1]);
13415
13416   emit_label (label);
13417   emit_insn (gen_fprem1xf4_i387 (op1, op2, op1, op2));
13418   ix86_emit_fp_unordered_jump (label);
13419   LABEL_NUSES (label) = 1;
13420
13421   emit_move_insn (operands[0], op1);
13422   DONE;
13423 })
13424
13425 (define_expand "remainder<mode>3"
13426   [(use (match_operand:MODEF 0 "register_operand" ""))
13427    (use (match_operand:MODEF 1 "general_operand" ""))
13428    (use (match_operand:MODEF 2 "general_operand" ""))]
13429   "TARGET_USE_FANCY_MATH_387"
13430 {
13431   rtx (*gen_truncxf) (rtx, rtx);
13432
13433   rtx label = gen_label_rtx ();
13434
13435   rtx op1 = gen_reg_rtx (XFmode);
13436   rtx op2 = gen_reg_rtx (XFmode);
13437
13438   emit_insn (gen_extend<mode>xf2 (op2, operands[2]));
13439   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
13440
13441   emit_label (label);
13442
13443   emit_insn (gen_fprem1xf4_i387 (op1, op2, op1, op2));
13444   ix86_emit_fp_unordered_jump (label);
13445   LABEL_NUSES (label) = 1;
13446
13447   /* Truncate the result properly for strict SSE math.  */
13448   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
13449       && !TARGET_MIX_SSE_I387)
13450     gen_truncxf = gen_truncxf<mode>2;
13451   else
13452     gen_truncxf = gen_truncxf<mode>2_i387_noop_unspec;
13453
13454   emit_insn (gen_truncxf (operands[0], op1));
13455   DONE;
13456 })
13457
13458 (define_insn "*sinxf2_i387"
13459   [(set (match_operand:XF 0 "register_operand" "=f")
13460         (unspec:XF [(match_operand:XF 1 "register_operand" "0")] UNSPEC_SIN))]
13461   "TARGET_USE_FANCY_MATH_387
13462    && flag_unsafe_math_optimizations"
13463   "fsin"
13464   [(set_attr "type" "fpspc")
13465    (set_attr "mode" "XF")])
13466
13467 (define_insn "*sin_extend<mode>xf2_i387"
13468   [(set (match_operand:XF 0 "register_operand" "=f")
13469         (unspec:XF [(float_extend:XF
13470                       (match_operand:MODEF 1 "register_operand" "0"))]
13471                    UNSPEC_SIN))]
13472   "TARGET_USE_FANCY_MATH_387
13473    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13474        || TARGET_MIX_SSE_I387)
13475    && flag_unsafe_math_optimizations"
13476   "fsin"
13477   [(set_attr "type" "fpspc")
13478    (set_attr "mode" "XF")])
13479
13480 (define_insn "*cosxf2_i387"
13481   [(set (match_operand:XF 0 "register_operand" "=f")
13482         (unspec:XF [(match_operand:XF 1 "register_operand" "0")] UNSPEC_COS))]
13483   "TARGET_USE_FANCY_MATH_387
13484    && flag_unsafe_math_optimizations"
13485   "fcos"
13486   [(set_attr "type" "fpspc")
13487    (set_attr "mode" "XF")])
13488
13489 (define_insn "*cos_extend<mode>xf2_i387"
13490   [(set (match_operand:XF 0 "register_operand" "=f")
13491         (unspec:XF [(float_extend:XF
13492                       (match_operand:MODEF 1 "register_operand" "0"))]
13493                    UNSPEC_COS))]
13494   "TARGET_USE_FANCY_MATH_387
13495    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13496        || TARGET_MIX_SSE_I387)
13497    && flag_unsafe_math_optimizations"
13498   "fcos"
13499   [(set_attr "type" "fpspc")
13500    (set_attr "mode" "XF")])
13501
13502 ;; When sincos pattern is defined, sin and cos builtin functions will be
13503 ;; expanded to sincos pattern with one of its outputs left unused.
13504 ;; CSE pass will figure out if two sincos patterns can be combined,
13505 ;; otherwise sincos pattern will be split back to sin or cos pattern,
13506 ;; depending on the unused output.
13507
13508 (define_insn "sincosxf3"
13509   [(set (match_operand:XF 0 "register_operand" "=f")
13510         (unspec:XF [(match_operand:XF 2 "register_operand" "0")]
13511                    UNSPEC_SINCOS_COS))
13512    (set (match_operand:XF 1 "register_operand" "=u")
13513         (unspec:XF [(match_dup 2)] UNSPEC_SINCOS_SIN))]
13514   "TARGET_USE_FANCY_MATH_387
13515    && flag_unsafe_math_optimizations"
13516   "fsincos"
13517   [(set_attr "type" "fpspc")
13518    (set_attr "mode" "XF")])
13519
13520 (define_split
13521   [(set (match_operand:XF 0 "register_operand" "")
13522         (unspec:XF [(match_operand:XF 2 "register_operand" "")]
13523                    UNSPEC_SINCOS_COS))
13524    (set (match_operand:XF 1 "register_operand" "")
13525         (unspec:XF [(match_dup 2)] UNSPEC_SINCOS_SIN))]
13526   "find_regno_note (insn, REG_UNUSED, REGNO (operands[0]))
13527    && can_create_pseudo_p ()"
13528   [(set (match_dup 1) (unspec:XF [(match_dup 2)] UNSPEC_SIN))])
13529
13530 (define_split
13531   [(set (match_operand:XF 0 "register_operand" "")
13532         (unspec:XF [(match_operand:XF 2 "register_operand" "")]
13533                    UNSPEC_SINCOS_COS))
13534    (set (match_operand:XF 1 "register_operand" "")
13535         (unspec:XF [(match_dup 2)] UNSPEC_SINCOS_SIN))]
13536   "find_regno_note (insn, REG_UNUSED, REGNO (operands[1]))
13537    && can_create_pseudo_p ()"
13538   [(set (match_dup 0) (unspec:XF [(match_dup 2)] UNSPEC_COS))])
13539
13540 (define_insn "sincos_extend<mode>xf3_i387"
13541   [(set (match_operand:XF 0 "register_operand" "=f")
13542         (unspec:XF [(float_extend:XF
13543                       (match_operand:MODEF 2 "register_operand" "0"))]
13544                    UNSPEC_SINCOS_COS))
13545    (set (match_operand:XF 1 "register_operand" "=u")
13546         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SINCOS_SIN))]
13547   "TARGET_USE_FANCY_MATH_387
13548    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13549        || TARGET_MIX_SSE_I387)
13550    && flag_unsafe_math_optimizations"
13551   "fsincos"
13552   [(set_attr "type" "fpspc")
13553    (set_attr "mode" "XF")])
13554
13555 (define_split
13556   [(set (match_operand:XF 0 "register_operand" "")
13557         (unspec:XF [(float_extend:XF
13558                       (match_operand:MODEF 2 "register_operand" ""))]
13559                    UNSPEC_SINCOS_COS))
13560    (set (match_operand:XF 1 "register_operand" "")
13561         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SINCOS_SIN))]
13562   "find_regno_note (insn, REG_UNUSED, REGNO (operands[0]))
13563    && can_create_pseudo_p ()"
13564   [(set (match_dup 1)
13565         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SIN))])
13566
13567 (define_split
13568   [(set (match_operand:XF 0 "register_operand" "")
13569         (unspec:XF [(float_extend:XF
13570                       (match_operand:MODEF 2 "register_operand" ""))]
13571                    UNSPEC_SINCOS_COS))
13572    (set (match_operand:XF 1 "register_operand" "")
13573         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SINCOS_SIN))]
13574   "find_regno_note (insn, REG_UNUSED, REGNO (operands[1]))
13575    && can_create_pseudo_p ()"
13576   [(set (match_dup 0)
13577         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_COS))])
13578
13579 (define_expand "sincos<mode>3"
13580   [(use (match_operand:MODEF 0 "register_operand" ""))
13581    (use (match_operand:MODEF 1 "register_operand" ""))
13582    (use (match_operand:MODEF 2 "register_operand" ""))]
13583   "TARGET_USE_FANCY_MATH_387
13584    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13585        || TARGET_MIX_SSE_I387)
13586    && flag_unsafe_math_optimizations"
13587 {
13588   rtx op0 = gen_reg_rtx (XFmode);
13589   rtx op1 = gen_reg_rtx (XFmode);
13590
13591   emit_insn (gen_sincos_extend<mode>xf3_i387 (op0, op1, operands[2]));
13592   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
13593   emit_insn (gen_truncxf<mode>2_i387_noop (operands[1], op1));
13594   DONE;
13595 })
13596
13597 (define_insn "fptanxf4_i387"
13598   [(set (match_operand:XF 0 "register_operand" "=f")
13599         (match_operand:XF 3 "const_double_operand" "F"))
13600    (set (match_operand:XF 1 "register_operand" "=u")
13601         (unspec:XF [(match_operand:XF 2 "register_operand" "0")]
13602                    UNSPEC_TAN))]
13603   "TARGET_USE_FANCY_MATH_387
13604    && flag_unsafe_math_optimizations
13605    && standard_80387_constant_p (operands[3]) == 2"
13606   "fptan"
13607   [(set_attr "type" "fpspc")
13608    (set_attr "mode" "XF")])
13609
13610 (define_insn "fptan_extend<mode>xf4_i387"
13611   [(set (match_operand:MODEF 0 "register_operand" "=f")
13612         (match_operand:MODEF 3 "const_double_operand" "F"))
13613    (set (match_operand:XF 1 "register_operand" "=u")
13614         (unspec:XF [(float_extend:XF
13615                       (match_operand:MODEF 2 "register_operand" "0"))]
13616                    UNSPEC_TAN))]
13617   "TARGET_USE_FANCY_MATH_387
13618    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13619        || TARGET_MIX_SSE_I387)
13620    && flag_unsafe_math_optimizations
13621    && standard_80387_constant_p (operands[3]) == 2"
13622   "fptan"
13623   [(set_attr "type" "fpspc")
13624    (set_attr "mode" "XF")])
13625
13626 (define_expand "tanxf2"
13627   [(use (match_operand:XF 0 "register_operand" ""))
13628    (use (match_operand:XF 1 "register_operand" ""))]
13629   "TARGET_USE_FANCY_MATH_387
13630    && flag_unsafe_math_optimizations"
13631 {
13632   rtx one = gen_reg_rtx (XFmode);
13633   rtx op2 = CONST1_RTX (XFmode); /* fld1 */
13634
13635   emit_insn (gen_fptanxf4_i387 (one, operands[0], operands[1], op2));
13636   DONE;
13637 })
13638
13639 (define_expand "tan<mode>2"
13640   [(use (match_operand:MODEF 0 "register_operand" ""))
13641    (use (match_operand:MODEF 1 "register_operand" ""))]
13642   "TARGET_USE_FANCY_MATH_387
13643    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13644        || TARGET_MIX_SSE_I387)
13645    && flag_unsafe_math_optimizations"
13646 {
13647   rtx op0 = gen_reg_rtx (XFmode);
13648
13649   rtx one = gen_reg_rtx (<MODE>mode);
13650   rtx op2 = CONST1_RTX (<MODE>mode); /* fld1 */
13651
13652   emit_insn (gen_fptan_extend<mode>xf4_i387 (one, op0,
13653                                              operands[1], op2));
13654   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
13655   DONE;
13656 })
13657
13658 (define_insn "*fpatanxf3_i387"
13659   [(set (match_operand:XF 0 "register_operand" "=f")
13660         (unspec:XF [(match_operand:XF 1 "register_operand" "0")
13661                     (match_operand:XF 2 "register_operand" "u")]
13662                    UNSPEC_FPATAN))
13663    (clobber (match_scratch:XF 3 "=2"))]
13664   "TARGET_USE_FANCY_MATH_387
13665    && flag_unsafe_math_optimizations"
13666   "fpatan"
13667   [(set_attr "type" "fpspc")
13668    (set_attr "mode" "XF")])
13669
13670 (define_insn "fpatan_extend<mode>xf3_i387"
13671   [(set (match_operand:XF 0 "register_operand" "=f")
13672         (unspec:XF [(float_extend:XF
13673                       (match_operand:MODEF 1 "register_operand" "0"))
13674                     (float_extend:XF
13675                       (match_operand:MODEF 2 "register_operand" "u"))]
13676                    UNSPEC_FPATAN))
13677    (clobber (match_scratch:XF 3 "=2"))]
13678   "TARGET_USE_FANCY_MATH_387
13679    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13680        || TARGET_MIX_SSE_I387)
13681    && flag_unsafe_math_optimizations"
13682   "fpatan"
13683   [(set_attr "type" "fpspc")
13684    (set_attr "mode" "XF")])
13685
13686 (define_expand "atan2xf3"
13687   [(parallel [(set (match_operand:XF 0 "register_operand" "")
13688                    (unspec:XF [(match_operand:XF 2 "register_operand" "")
13689                                (match_operand:XF 1 "register_operand" "")]
13690                               UNSPEC_FPATAN))
13691               (clobber (match_scratch:XF 3 ""))])]
13692   "TARGET_USE_FANCY_MATH_387
13693    && flag_unsafe_math_optimizations")
13694
13695 (define_expand "atan2<mode>3"
13696   [(use (match_operand:MODEF 0 "register_operand" ""))
13697    (use (match_operand:MODEF 1 "register_operand" ""))
13698    (use (match_operand:MODEF 2 "register_operand" ""))]
13699   "TARGET_USE_FANCY_MATH_387
13700    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13701        || TARGET_MIX_SSE_I387)
13702    && flag_unsafe_math_optimizations"
13703 {
13704   rtx op0 = gen_reg_rtx (XFmode);
13705
13706   emit_insn (gen_fpatan_extend<mode>xf3_i387 (op0, operands[2], operands[1]));
13707   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
13708   DONE;
13709 })
13710
13711 (define_expand "atanxf2"
13712   [(parallel [(set (match_operand:XF 0 "register_operand" "")
13713                    (unspec:XF [(match_dup 2)
13714                                (match_operand:XF 1 "register_operand" "")]
13715                               UNSPEC_FPATAN))
13716               (clobber (match_scratch:XF 3 ""))])]
13717   "TARGET_USE_FANCY_MATH_387
13718    && flag_unsafe_math_optimizations"
13719 {
13720   operands[2] = gen_reg_rtx (XFmode);
13721   emit_move_insn (operands[2], CONST1_RTX (XFmode));  /* fld1 */
13722 })
13723
13724 (define_expand "atan<mode>2"
13725   [(use (match_operand:MODEF 0 "register_operand" ""))
13726    (use (match_operand:MODEF 1 "register_operand" ""))]
13727   "TARGET_USE_FANCY_MATH_387
13728    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13729        || TARGET_MIX_SSE_I387)
13730    && flag_unsafe_math_optimizations"
13731 {
13732   rtx op0 = gen_reg_rtx (XFmode);
13733
13734   rtx op2 = gen_reg_rtx (<MODE>mode);
13735   emit_move_insn (op2, CONST1_RTX (<MODE>mode));  /* fld1 */
13736
13737   emit_insn (gen_fpatan_extend<mode>xf3_i387 (op0, op2, operands[1]));
13738   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
13739   DONE;
13740 })
13741
13742 (define_expand "asinxf2"
13743   [(set (match_dup 2)
13744         (mult:XF (match_operand:XF 1 "register_operand" "")
13745                  (match_dup 1)))
13746    (set (match_dup 4) (minus:XF (match_dup 3) (match_dup 2)))
13747    (set (match_dup 5) (sqrt:XF (match_dup 4)))
13748    (parallel [(set (match_operand:XF 0 "register_operand" "")
13749                    (unspec:XF [(match_dup 5) (match_dup 1)]
13750                               UNSPEC_FPATAN))
13751               (clobber (match_scratch:XF 6 ""))])]
13752   "TARGET_USE_FANCY_MATH_387
13753    && flag_unsafe_math_optimizations"
13754 {
13755   int i;
13756
13757   if (optimize_insn_for_size_p ())
13758     FAIL;
13759
13760   for (i = 2; i < 6; i++)
13761     operands[i] = gen_reg_rtx (XFmode);
13762
13763   emit_move_insn (operands[3], CONST1_RTX (XFmode));  /* fld1 */
13764 })
13765
13766 (define_expand "asin<mode>2"
13767   [(use (match_operand:MODEF 0 "register_operand" ""))
13768    (use (match_operand:MODEF 1 "general_operand" ""))]
13769  "TARGET_USE_FANCY_MATH_387
13770    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13771        || TARGET_MIX_SSE_I387)
13772    && flag_unsafe_math_optimizations"
13773 {
13774   rtx op0 = gen_reg_rtx (XFmode);
13775   rtx op1 = gen_reg_rtx (XFmode);
13776
13777   if (optimize_insn_for_size_p ())
13778     FAIL;
13779
13780   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
13781   emit_insn (gen_asinxf2 (op0, op1));
13782   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
13783   DONE;
13784 })
13785
13786 (define_expand "acosxf2"
13787   [(set (match_dup 2)
13788         (mult:XF (match_operand:XF 1 "register_operand" "")
13789                  (match_dup 1)))
13790    (set (match_dup 4) (minus:XF (match_dup 3) (match_dup 2)))
13791    (set (match_dup 5) (sqrt:XF (match_dup 4)))
13792    (parallel [(set (match_operand:XF 0 "register_operand" "")
13793                    (unspec:XF [(match_dup 1) (match_dup 5)]
13794                               UNSPEC_FPATAN))
13795               (clobber (match_scratch:XF 6 ""))])]
13796   "TARGET_USE_FANCY_MATH_387
13797    && flag_unsafe_math_optimizations"
13798 {
13799   int i;
13800
13801   if (optimize_insn_for_size_p ())
13802     FAIL;
13803
13804   for (i = 2; i < 6; i++)
13805     operands[i] = gen_reg_rtx (XFmode);
13806
13807   emit_move_insn (operands[3], CONST1_RTX (XFmode));  /* fld1 */
13808 })
13809
13810 (define_expand "acos<mode>2"
13811   [(use (match_operand:MODEF 0 "register_operand" ""))
13812    (use (match_operand:MODEF 1 "general_operand" ""))]
13813  "TARGET_USE_FANCY_MATH_387
13814    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13815        || TARGET_MIX_SSE_I387)
13816    && flag_unsafe_math_optimizations"
13817 {
13818   rtx op0 = gen_reg_rtx (XFmode);
13819   rtx op1 = gen_reg_rtx (XFmode);
13820
13821   if (optimize_insn_for_size_p ())
13822     FAIL;
13823
13824   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
13825   emit_insn (gen_acosxf2 (op0, op1));
13826   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
13827   DONE;
13828 })
13829
13830 (define_insn "fyl2xxf3_i387"
13831   [(set (match_operand:XF 0 "register_operand" "=f")
13832         (unspec:XF [(match_operand:XF 1 "register_operand" "0")
13833                     (match_operand:XF 2 "register_operand" "u")]
13834                    UNSPEC_FYL2X))
13835    (clobber (match_scratch:XF 3 "=2"))]
13836   "TARGET_USE_FANCY_MATH_387
13837    && flag_unsafe_math_optimizations"
13838   "fyl2x"
13839   [(set_attr "type" "fpspc")
13840    (set_attr "mode" "XF")])
13841
13842 (define_insn "fyl2x_extend<mode>xf3_i387"
13843   [(set (match_operand:XF 0 "register_operand" "=f")
13844         (unspec:XF [(float_extend:XF
13845                       (match_operand:MODEF 1 "register_operand" "0"))
13846                     (match_operand:XF 2 "register_operand" "u")]
13847                    UNSPEC_FYL2X))
13848    (clobber (match_scratch:XF 3 "=2"))]
13849   "TARGET_USE_FANCY_MATH_387
13850    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13851        || TARGET_MIX_SSE_I387)
13852    && flag_unsafe_math_optimizations"
13853   "fyl2x"
13854   [(set_attr "type" "fpspc")
13855    (set_attr "mode" "XF")])
13856
13857 (define_expand "logxf2"
13858   [(parallel [(set (match_operand:XF 0 "register_operand" "")
13859                    (unspec:XF [(match_operand:XF 1 "register_operand" "")
13860                                (match_dup 2)] UNSPEC_FYL2X))
13861               (clobber (match_scratch:XF 3 ""))])]
13862   "TARGET_USE_FANCY_MATH_387
13863    && flag_unsafe_math_optimizations"
13864 {
13865   operands[2] = gen_reg_rtx (XFmode);
13866   emit_move_insn (operands[2], standard_80387_constant_rtx (4)); /* fldln2 */
13867 })
13868
13869 (define_expand "log<mode>2"
13870   [(use (match_operand:MODEF 0 "register_operand" ""))
13871    (use (match_operand:MODEF 1 "register_operand" ""))]
13872   "TARGET_USE_FANCY_MATH_387
13873    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13874        || TARGET_MIX_SSE_I387)
13875    && flag_unsafe_math_optimizations"
13876 {
13877   rtx op0 = gen_reg_rtx (XFmode);
13878
13879   rtx op2 = gen_reg_rtx (XFmode);
13880   emit_move_insn (op2, standard_80387_constant_rtx (4)); /* fldln2 */
13881
13882   emit_insn (gen_fyl2x_extend<mode>xf3_i387 (op0, operands[1], op2));
13883   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
13884   DONE;
13885 })
13886
13887 (define_expand "log10xf2"
13888   [(parallel [(set (match_operand:XF 0 "register_operand" "")
13889                    (unspec:XF [(match_operand:XF 1 "register_operand" "")
13890                                (match_dup 2)] UNSPEC_FYL2X))
13891               (clobber (match_scratch:XF 3 ""))])]
13892   "TARGET_USE_FANCY_MATH_387
13893    && flag_unsafe_math_optimizations"
13894 {
13895   operands[2] = gen_reg_rtx (XFmode);
13896   emit_move_insn (operands[2], standard_80387_constant_rtx (3)); /* fldlg2 */
13897 })
13898
13899 (define_expand "log10<mode>2"
13900   [(use (match_operand:MODEF 0 "register_operand" ""))
13901    (use (match_operand:MODEF 1 "register_operand" ""))]
13902   "TARGET_USE_FANCY_MATH_387
13903    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13904        || TARGET_MIX_SSE_I387)
13905    && flag_unsafe_math_optimizations"
13906 {
13907   rtx op0 = gen_reg_rtx (XFmode);
13908
13909   rtx op2 = gen_reg_rtx (XFmode);
13910   emit_move_insn (op2, standard_80387_constant_rtx (3)); /* fldlg2 */
13911
13912   emit_insn (gen_fyl2x_extend<mode>xf3_i387 (op0, operands[1], op2));
13913   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
13914   DONE;
13915 })
13916
13917 (define_expand "log2xf2"
13918   [(parallel [(set (match_operand:XF 0 "register_operand" "")
13919                    (unspec:XF [(match_operand:XF 1 "register_operand" "")
13920                                (match_dup 2)] UNSPEC_FYL2X))
13921               (clobber (match_scratch:XF 3 ""))])]
13922   "TARGET_USE_FANCY_MATH_387
13923    && flag_unsafe_math_optimizations"
13924 {
13925   operands[2] = gen_reg_rtx (XFmode);
13926   emit_move_insn (operands[2], CONST1_RTX (XFmode)); /* fld1 */
13927 })
13928
13929 (define_expand "log2<mode>2"
13930   [(use (match_operand:MODEF 0 "register_operand" ""))
13931    (use (match_operand:MODEF 1 "register_operand" ""))]
13932   "TARGET_USE_FANCY_MATH_387
13933    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13934        || TARGET_MIX_SSE_I387)
13935    && flag_unsafe_math_optimizations"
13936 {
13937   rtx op0 = gen_reg_rtx (XFmode);
13938
13939   rtx op2 = gen_reg_rtx (XFmode);
13940   emit_move_insn (op2, CONST1_RTX (XFmode)); /* fld1 */
13941
13942   emit_insn (gen_fyl2x_extend<mode>xf3_i387 (op0, operands[1], op2));
13943   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
13944   DONE;
13945 })
13946
13947 (define_insn "fyl2xp1xf3_i387"
13948   [(set (match_operand:XF 0 "register_operand" "=f")
13949         (unspec:XF [(match_operand:XF 1 "register_operand" "0")
13950                     (match_operand:XF 2 "register_operand" "u")]
13951                    UNSPEC_FYL2XP1))
13952    (clobber (match_scratch:XF 3 "=2"))]
13953   "TARGET_USE_FANCY_MATH_387
13954    && flag_unsafe_math_optimizations"
13955   "fyl2xp1"
13956   [(set_attr "type" "fpspc")
13957    (set_attr "mode" "XF")])
13958
13959 (define_insn "fyl2xp1_extend<mode>xf3_i387"
13960   [(set (match_operand:XF 0 "register_operand" "=f")
13961         (unspec:XF [(float_extend:XF
13962                       (match_operand:MODEF 1 "register_operand" "0"))
13963                     (match_operand:XF 2 "register_operand" "u")]
13964                    UNSPEC_FYL2XP1))
13965    (clobber (match_scratch:XF 3 "=2"))]
13966   "TARGET_USE_FANCY_MATH_387
13967    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13968        || TARGET_MIX_SSE_I387)
13969    && flag_unsafe_math_optimizations"
13970   "fyl2xp1"
13971   [(set_attr "type" "fpspc")
13972    (set_attr "mode" "XF")])
13973
13974 (define_expand "log1pxf2"
13975   [(use (match_operand:XF 0 "register_operand" ""))
13976    (use (match_operand:XF 1 "register_operand" ""))]
13977   "TARGET_USE_FANCY_MATH_387
13978    && flag_unsafe_math_optimizations"
13979 {
13980   if (optimize_insn_for_size_p ())
13981     FAIL;
13982
13983   ix86_emit_i387_log1p (operands[0], operands[1]);
13984   DONE;
13985 })
13986
13987 (define_expand "log1p<mode>2"
13988   [(use (match_operand:MODEF 0 "register_operand" ""))
13989    (use (match_operand:MODEF 1 "register_operand" ""))]
13990   "TARGET_USE_FANCY_MATH_387
13991    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13992        || TARGET_MIX_SSE_I387)
13993    && flag_unsafe_math_optimizations"
13994 {
13995   rtx op0;
13996
13997   if (optimize_insn_for_size_p ())
13998     FAIL;
13999
14000   op0 = gen_reg_rtx (XFmode);
14001
14002   operands[1] = gen_rtx_FLOAT_EXTEND (XFmode, operands[1]);
14003
14004   ix86_emit_i387_log1p (op0, operands[1]);
14005   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14006   DONE;
14007 })
14008
14009 (define_insn "fxtractxf3_i387"
14010   [(set (match_operand:XF 0 "register_operand" "=f")
14011         (unspec:XF [(match_operand:XF 2 "register_operand" "0")]
14012                    UNSPEC_XTRACT_FRACT))
14013    (set (match_operand:XF 1 "register_operand" "=u")
14014         (unspec:XF [(match_dup 2)] UNSPEC_XTRACT_EXP))]
14015   "TARGET_USE_FANCY_MATH_387
14016    && flag_unsafe_math_optimizations"
14017   "fxtract"
14018   [(set_attr "type" "fpspc")
14019    (set_attr "mode" "XF")])
14020
14021 (define_insn "fxtract_extend<mode>xf3_i387"
14022   [(set (match_operand:XF 0 "register_operand" "=f")
14023         (unspec:XF [(float_extend:XF
14024                       (match_operand:MODEF 2 "register_operand" "0"))]
14025                    UNSPEC_XTRACT_FRACT))
14026    (set (match_operand:XF 1 "register_operand" "=u")
14027         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_XTRACT_EXP))]
14028   "TARGET_USE_FANCY_MATH_387
14029    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14030        || TARGET_MIX_SSE_I387)
14031    && flag_unsafe_math_optimizations"
14032   "fxtract"
14033   [(set_attr "type" "fpspc")
14034    (set_attr "mode" "XF")])
14035
14036 (define_expand "logbxf2"
14037   [(parallel [(set (match_dup 2)
14038                    (unspec:XF [(match_operand:XF 1 "register_operand" "")]
14039                               UNSPEC_XTRACT_FRACT))
14040               (set (match_operand:XF 0 "register_operand" "")
14041                    (unspec:XF [(match_dup 1)] UNSPEC_XTRACT_EXP))])]
14042   "TARGET_USE_FANCY_MATH_387
14043    && flag_unsafe_math_optimizations"
14044   "operands[2] = gen_reg_rtx (XFmode);")
14045
14046 (define_expand "logb<mode>2"
14047   [(use (match_operand:MODEF 0 "register_operand" ""))
14048    (use (match_operand:MODEF 1 "register_operand" ""))]
14049   "TARGET_USE_FANCY_MATH_387
14050    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14051        || TARGET_MIX_SSE_I387)
14052    && flag_unsafe_math_optimizations"
14053 {
14054   rtx op0 = gen_reg_rtx (XFmode);
14055   rtx op1 = gen_reg_rtx (XFmode);
14056
14057   emit_insn (gen_fxtract_extend<mode>xf3_i387 (op0, op1, operands[1]));
14058   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op1));
14059   DONE;
14060 })
14061
14062 (define_expand "ilogbxf2"
14063   [(use (match_operand:SI 0 "register_operand" ""))
14064    (use (match_operand:XF 1 "register_operand" ""))]
14065   "TARGET_USE_FANCY_MATH_387
14066    && flag_unsafe_math_optimizations"
14067 {
14068   rtx op0, op1;
14069
14070   if (optimize_insn_for_size_p ())
14071     FAIL;
14072
14073   op0 = gen_reg_rtx (XFmode);
14074   op1 = gen_reg_rtx (XFmode);
14075
14076   emit_insn (gen_fxtractxf3_i387 (op0, op1, operands[1]));
14077   emit_insn (gen_fix_truncxfsi2 (operands[0], op1));
14078   DONE;
14079 })
14080
14081 (define_expand "ilogb<mode>2"
14082   [(use (match_operand:SI 0 "register_operand" ""))
14083    (use (match_operand:MODEF 1 "register_operand" ""))]
14084   "TARGET_USE_FANCY_MATH_387
14085    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14086        || TARGET_MIX_SSE_I387)
14087    && flag_unsafe_math_optimizations"
14088 {
14089   rtx op0, op1;
14090
14091   if (optimize_insn_for_size_p ())
14092     FAIL;
14093
14094   op0 = gen_reg_rtx (XFmode);
14095   op1 = gen_reg_rtx (XFmode);
14096
14097   emit_insn (gen_fxtract_extend<mode>xf3_i387 (op0, op1, operands[1]));
14098   emit_insn (gen_fix_truncxfsi2 (operands[0], op1));
14099   DONE;
14100 })
14101
14102 (define_insn "*f2xm1xf2_i387"
14103   [(set (match_operand:XF 0 "register_operand" "=f")
14104         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
14105                    UNSPEC_F2XM1))]
14106   "TARGET_USE_FANCY_MATH_387
14107    && flag_unsafe_math_optimizations"
14108   "f2xm1"
14109   [(set_attr "type" "fpspc")
14110    (set_attr "mode" "XF")])
14111
14112 (define_insn "*fscalexf4_i387"
14113   [(set (match_operand:XF 0 "register_operand" "=f")
14114         (unspec:XF [(match_operand:XF 2 "register_operand" "0")
14115                     (match_operand:XF 3 "register_operand" "1")]
14116                    UNSPEC_FSCALE_FRACT))
14117    (set (match_operand:XF 1 "register_operand" "=u")
14118         (unspec:XF [(match_dup 2) (match_dup 3)]
14119                    UNSPEC_FSCALE_EXP))]
14120   "TARGET_USE_FANCY_MATH_387
14121    && flag_unsafe_math_optimizations"
14122   "fscale"
14123   [(set_attr "type" "fpspc")
14124    (set_attr "mode" "XF")])
14125
14126 (define_expand "expNcorexf3"
14127   [(set (match_dup 3) (mult:XF (match_operand:XF 1 "register_operand" "")
14128                                (match_operand:XF 2 "register_operand" "")))
14129    (set (match_dup 4) (unspec:XF [(match_dup 3)] UNSPEC_FRNDINT))
14130    (set (match_dup 5) (minus:XF (match_dup 3) (match_dup 4)))
14131    (set (match_dup 6) (unspec:XF [(match_dup 5)] UNSPEC_F2XM1))
14132    (set (match_dup 8) (plus:XF (match_dup 6) (match_dup 7)))
14133    (parallel [(set (match_operand:XF 0 "register_operand" "")
14134                    (unspec:XF [(match_dup 8) (match_dup 4)]
14135                               UNSPEC_FSCALE_FRACT))
14136               (set (match_dup 9)
14137                    (unspec:XF [(match_dup 8) (match_dup 4)]
14138                               UNSPEC_FSCALE_EXP))])]
14139   "TARGET_USE_FANCY_MATH_387
14140    && flag_unsafe_math_optimizations"
14141 {
14142   int i;
14143
14144   if (optimize_insn_for_size_p ())
14145     FAIL;
14146
14147   for (i = 3; i < 10; i++)
14148     operands[i] = gen_reg_rtx (XFmode);
14149
14150   emit_move_insn (operands[7], CONST1_RTX (XFmode));  /* fld1 */
14151 })
14152
14153 (define_expand "expxf2"
14154   [(use (match_operand:XF 0 "register_operand" ""))
14155    (use (match_operand:XF 1 "register_operand" ""))]
14156   "TARGET_USE_FANCY_MATH_387
14157    && flag_unsafe_math_optimizations"
14158 {
14159   rtx op2;
14160
14161   if (optimize_insn_for_size_p ())
14162     FAIL;
14163
14164   op2 = gen_reg_rtx (XFmode);
14165   emit_move_insn (op2, standard_80387_constant_rtx (5)); /* fldl2e */
14166
14167   emit_insn (gen_expNcorexf3 (operands[0], operands[1], op2));
14168   DONE;
14169 })
14170
14171 (define_expand "exp<mode>2"
14172   [(use (match_operand:MODEF 0 "register_operand" ""))
14173    (use (match_operand:MODEF 1 "general_operand" ""))]
14174  "TARGET_USE_FANCY_MATH_387
14175    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14176        || TARGET_MIX_SSE_I387)
14177    && flag_unsafe_math_optimizations"
14178 {
14179   rtx op0, op1;
14180
14181   if (optimize_insn_for_size_p ())
14182     FAIL;
14183
14184   op0 = gen_reg_rtx (XFmode);
14185   op1 = gen_reg_rtx (XFmode);
14186
14187   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14188   emit_insn (gen_expxf2 (op0, op1));
14189   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14190   DONE;
14191 })
14192
14193 (define_expand "exp10xf2"
14194   [(use (match_operand:XF 0 "register_operand" ""))
14195    (use (match_operand:XF 1 "register_operand" ""))]
14196   "TARGET_USE_FANCY_MATH_387
14197    && flag_unsafe_math_optimizations"
14198 {
14199   rtx op2;
14200
14201   if (optimize_insn_for_size_p ())
14202     FAIL;
14203
14204   op2 = gen_reg_rtx (XFmode);
14205   emit_move_insn (op2, standard_80387_constant_rtx (6)); /* fldl2t */
14206
14207   emit_insn (gen_expNcorexf3 (operands[0], operands[1], op2));
14208   DONE;
14209 })
14210
14211 (define_expand "exp10<mode>2"
14212   [(use (match_operand:MODEF 0 "register_operand" ""))
14213    (use (match_operand:MODEF 1 "general_operand" ""))]
14214  "TARGET_USE_FANCY_MATH_387
14215    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14216        || TARGET_MIX_SSE_I387)
14217    && flag_unsafe_math_optimizations"
14218 {
14219   rtx op0, op1;
14220
14221   if (optimize_insn_for_size_p ())
14222     FAIL;
14223
14224   op0 = gen_reg_rtx (XFmode);
14225   op1 = gen_reg_rtx (XFmode);
14226
14227   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14228   emit_insn (gen_exp10xf2 (op0, op1));
14229   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14230   DONE;
14231 })
14232
14233 (define_expand "exp2xf2"
14234   [(use (match_operand:XF 0 "register_operand" ""))
14235    (use (match_operand:XF 1 "register_operand" ""))]
14236   "TARGET_USE_FANCY_MATH_387
14237    && flag_unsafe_math_optimizations"
14238 {
14239   rtx op2;
14240
14241   if (optimize_insn_for_size_p ())
14242     FAIL;
14243
14244   op2 = gen_reg_rtx (XFmode);
14245   emit_move_insn (op2, CONST1_RTX (XFmode));  /* fld1 */
14246
14247   emit_insn (gen_expNcorexf3 (operands[0], operands[1], op2));
14248   DONE;
14249 })
14250
14251 (define_expand "exp2<mode>2"
14252   [(use (match_operand:MODEF 0 "register_operand" ""))
14253    (use (match_operand:MODEF 1 "general_operand" ""))]
14254  "TARGET_USE_FANCY_MATH_387
14255    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14256        || TARGET_MIX_SSE_I387)
14257    && flag_unsafe_math_optimizations"
14258 {
14259   rtx op0, op1;
14260
14261   if (optimize_insn_for_size_p ())
14262     FAIL;
14263
14264   op0 = gen_reg_rtx (XFmode);
14265   op1 = gen_reg_rtx (XFmode);
14266
14267   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14268   emit_insn (gen_exp2xf2 (op0, op1));
14269   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14270   DONE;
14271 })
14272
14273 (define_expand "expm1xf2"
14274   [(set (match_dup 3) (mult:XF (match_operand:XF 1 "register_operand" "")
14275                                (match_dup 2)))
14276    (set (match_dup 4) (unspec:XF [(match_dup 3)] UNSPEC_FRNDINT))
14277    (set (match_dup 5) (minus:XF (match_dup 3) (match_dup 4)))
14278    (set (match_dup 9) (float_extend:XF (match_dup 13)))
14279    (set (match_dup 6) (unspec:XF [(match_dup 5)] UNSPEC_F2XM1))
14280    (parallel [(set (match_dup 7)
14281                    (unspec:XF [(match_dup 6) (match_dup 4)]
14282                               UNSPEC_FSCALE_FRACT))
14283               (set (match_dup 8)
14284                    (unspec:XF [(match_dup 6) (match_dup 4)]
14285                               UNSPEC_FSCALE_EXP))])
14286    (parallel [(set (match_dup 10)
14287                    (unspec:XF [(match_dup 9) (match_dup 8)]
14288                               UNSPEC_FSCALE_FRACT))
14289               (set (match_dup 11)
14290                    (unspec:XF [(match_dup 9) (match_dup 8)]
14291                               UNSPEC_FSCALE_EXP))])
14292    (set (match_dup 12) (minus:XF (match_dup 10)
14293                                  (float_extend:XF (match_dup 13))))
14294    (set (match_operand:XF 0 "register_operand" "")
14295         (plus:XF (match_dup 12) (match_dup 7)))]
14296   "TARGET_USE_FANCY_MATH_387
14297    && flag_unsafe_math_optimizations"
14298 {
14299   int i;
14300
14301   if (optimize_insn_for_size_p ())
14302     FAIL;
14303
14304   for (i = 2; i < 13; i++)
14305     operands[i] = gen_reg_rtx (XFmode);
14306
14307   operands[13]
14308     = validize_mem (force_const_mem (SFmode, CONST1_RTX (SFmode))); /* fld1 */
14309
14310   emit_move_insn (operands[2], standard_80387_constant_rtx (5)); /* fldl2e */
14311 })
14312
14313 (define_expand "expm1<mode>2"
14314   [(use (match_operand:MODEF 0 "register_operand" ""))
14315    (use (match_operand:MODEF 1 "general_operand" ""))]
14316  "TARGET_USE_FANCY_MATH_387
14317    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14318        || TARGET_MIX_SSE_I387)
14319    && flag_unsafe_math_optimizations"
14320 {
14321   rtx op0, op1;
14322
14323   if (optimize_insn_for_size_p ())
14324     FAIL;
14325
14326   op0 = gen_reg_rtx (XFmode);
14327   op1 = gen_reg_rtx (XFmode);
14328
14329   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14330   emit_insn (gen_expm1xf2 (op0, op1));
14331   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14332   DONE;
14333 })
14334
14335 (define_expand "ldexpxf3"
14336   [(set (match_dup 3)
14337         (float:XF (match_operand:SI 2 "register_operand" "")))
14338    (parallel [(set (match_operand:XF 0 " register_operand" "")
14339                    (unspec:XF [(match_operand:XF 1 "register_operand" "")
14340                                (match_dup 3)]
14341                               UNSPEC_FSCALE_FRACT))
14342               (set (match_dup 4)
14343                    (unspec:XF [(match_dup 1) (match_dup 3)]
14344                               UNSPEC_FSCALE_EXP))])]
14345   "TARGET_USE_FANCY_MATH_387
14346    && flag_unsafe_math_optimizations"
14347 {
14348   if (optimize_insn_for_size_p ())
14349     FAIL;
14350
14351   operands[3] = gen_reg_rtx (XFmode);
14352   operands[4] = gen_reg_rtx (XFmode);
14353 })
14354
14355 (define_expand "ldexp<mode>3"
14356   [(use (match_operand:MODEF 0 "register_operand" ""))
14357    (use (match_operand:MODEF 1 "general_operand" ""))
14358    (use (match_operand:SI 2 "register_operand" ""))]
14359  "TARGET_USE_FANCY_MATH_387
14360    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14361        || TARGET_MIX_SSE_I387)
14362    && flag_unsafe_math_optimizations"
14363 {
14364   rtx op0, op1;
14365
14366   if (optimize_insn_for_size_p ())
14367     FAIL;
14368
14369   op0 = gen_reg_rtx (XFmode);
14370   op1 = gen_reg_rtx (XFmode);
14371
14372   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14373   emit_insn (gen_ldexpxf3 (op0, op1, operands[2]));
14374   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14375   DONE;
14376 })
14377
14378 (define_expand "scalbxf3"
14379   [(parallel [(set (match_operand:XF 0 " register_operand" "")
14380                    (unspec:XF [(match_operand:XF 1 "register_operand" "")
14381                                (match_operand:XF 2 "register_operand" "")]
14382                               UNSPEC_FSCALE_FRACT))
14383               (set (match_dup 3)
14384                    (unspec:XF [(match_dup 1) (match_dup 2)]
14385                               UNSPEC_FSCALE_EXP))])]
14386   "TARGET_USE_FANCY_MATH_387
14387    && flag_unsafe_math_optimizations"
14388 {
14389   if (optimize_insn_for_size_p ())
14390     FAIL;
14391
14392   operands[3] = gen_reg_rtx (XFmode);
14393 })
14394
14395 (define_expand "scalb<mode>3"
14396   [(use (match_operand:MODEF 0 "register_operand" ""))
14397    (use (match_operand:MODEF 1 "general_operand" ""))
14398    (use (match_operand:MODEF 2 "general_operand" ""))]
14399  "TARGET_USE_FANCY_MATH_387
14400    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14401        || TARGET_MIX_SSE_I387)
14402    && flag_unsafe_math_optimizations"
14403 {
14404   rtx op0, op1, op2;
14405
14406   if (optimize_insn_for_size_p ())
14407     FAIL;
14408
14409   op0 = gen_reg_rtx (XFmode);
14410   op1 = gen_reg_rtx (XFmode);
14411   op2 = gen_reg_rtx (XFmode);
14412
14413   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14414   emit_insn (gen_extend<mode>xf2 (op2, operands[2]));
14415   emit_insn (gen_scalbxf3 (op0, op1, op2));
14416   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14417   DONE;
14418 })
14419
14420 (define_expand "significandxf2"
14421   [(parallel [(set (match_operand:XF 0 "register_operand" "")
14422                    (unspec:XF [(match_operand:XF 1 "register_operand" "")]
14423                               UNSPEC_XTRACT_FRACT))
14424               (set (match_dup 2)
14425                    (unspec:XF [(match_dup 1)] UNSPEC_XTRACT_EXP))])]
14426   "TARGET_USE_FANCY_MATH_387
14427    && flag_unsafe_math_optimizations"
14428   "operands[2] = gen_reg_rtx (XFmode);")
14429
14430 (define_expand "significand<mode>2"
14431   [(use (match_operand:MODEF 0 "register_operand" ""))
14432    (use (match_operand:MODEF 1 "register_operand" ""))]
14433   "TARGET_USE_FANCY_MATH_387
14434    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14435        || TARGET_MIX_SSE_I387)
14436    && flag_unsafe_math_optimizations"
14437 {
14438   rtx op0 = gen_reg_rtx (XFmode);
14439   rtx op1 = gen_reg_rtx (XFmode);
14440
14441   emit_insn (gen_fxtract_extend<mode>xf3_i387 (op0, op1, operands[1]));
14442   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14443   DONE;
14444 })
14445 \f
14446
14447 (define_insn "sse4_1_round<mode>2"
14448   [(set (match_operand:MODEF 0 "register_operand" "=x")
14449         (unspec:MODEF [(match_operand:MODEF 1 "register_operand" "x")
14450                        (match_operand:SI 2 "const_0_to_15_operand" "n")]
14451                       UNSPEC_ROUND))]
14452   "TARGET_ROUND"
14453   "%vround<ssemodesuffix>\t{%2, %1, %d0|%d0, %1, %2}"
14454   [(set_attr "type" "ssecvt")
14455    (set_attr "prefix_extra" "1")
14456    (set_attr "prefix" "maybe_vex")
14457    (set_attr "mode" "<MODE>")])
14458
14459 (define_insn "rintxf2"
14460   [(set (match_operand:XF 0 "register_operand" "=f")
14461         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
14462                    UNSPEC_FRNDINT))]
14463   "TARGET_USE_FANCY_MATH_387
14464    && flag_unsafe_math_optimizations"
14465   "frndint"
14466   [(set_attr "type" "fpspc")
14467    (set_attr "mode" "XF")])
14468
14469 (define_expand "rint<mode>2"
14470   [(use (match_operand:MODEF 0 "register_operand" ""))
14471    (use (match_operand:MODEF 1 "register_operand" ""))]
14472   "(TARGET_USE_FANCY_MATH_387
14473     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14474         || TARGET_MIX_SSE_I387)
14475     && flag_unsafe_math_optimizations)
14476    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
14477        && !flag_trapping_math)"
14478 {
14479   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
14480       && !flag_trapping_math)
14481     {
14482       if (!TARGET_ROUND && optimize_insn_for_size_p ())
14483         FAIL;
14484       if (TARGET_ROUND)
14485         emit_insn (gen_sse4_1_round<mode>2
14486                    (operands[0], operands[1], GEN_INT (ROUND_MXCSR)));
14487       else
14488         ix86_expand_rint (operand0, operand1);
14489     }
14490   else
14491     {
14492       rtx op0 = gen_reg_rtx (XFmode);
14493       rtx op1 = gen_reg_rtx (XFmode);
14494
14495       emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14496       emit_insn (gen_rintxf2 (op0, op1));
14497
14498       emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14499     }
14500   DONE;
14501 })
14502
14503 (define_expand "round<mode>2"
14504   [(match_operand:MODEF 0 "register_operand" "")
14505    (match_operand:MODEF 1 "nonimmediate_operand" "")]
14506   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
14507    && !flag_trapping_math && !flag_rounding_math"
14508 {
14509   if (optimize_insn_for_size_p ())
14510     FAIL;
14511   if (TARGET_64BIT || (<MODE>mode != DFmode))
14512     ix86_expand_round (operand0, operand1);
14513   else
14514     ix86_expand_rounddf_32 (operand0, operand1);
14515   DONE;
14516 })
14517
14518 (define_insn_and_split "*fistdi2_1"
14519   [(set (match_operand:DI 0 "nonimmediate_operand" "")
14520         (unspec:DI [(match_operand:XF 1 "register_operand" "")]
14521                    UNSPEC_FIST))]
14522   "TARGET_USE_FANCY_MATH_387
14523    && can_create_pseudo_p ()"
14524   "#"
14525   "&& 1"
14526   [(const_int 0)]
14527 {
14528   if (memory_operand (operands[0], VOIDmode))
14529     emit_insn (gen_fistdi2 (operands[0], operands[1]));
14530   else
14531     {
14532       operands[2] = assign_386_stack_local (DImode, SLOT_TEMP);
14533       emit_insn (gen_fistdi2_with_temp (operands[0], operands[1],
14534                                          operands[2]));
14535     }
14536   DONE;
14537 }
14538   [(set_attr "type" "fpspc")
14539    (set_attr "mode" "DI")])
14540
14541 (define_insn "fistdi2"
14542   [(set (match_operand:DI 0 "memory_operand" "=m")
14543         (unspec:DI [(match_operand:XF 1 "register_operand" "f")]
14544                    UNSPEC_FIST))
14545    (clobber (match_scratch:XF 2 "=&1f"))]
14546   "TARGET_USE_FANCY_MATH_387"
14547   "* return output_fix_trunc (insn, operands, 0);"
14548   [(set_attr "type" "fpspc")
14549    (set_attr "mode" "DI")])
14550
14551 (define_insn "fistdi2_with_temp"
14552   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
14553         (unspec:DI [(match_operand:XF 1 "register_operand" "f,f")]
14554                    UNSPEC_FIST))
14555    (clobber (match_operand:DI 2 "memory_operand" "=X,m"))
14556    (clobber (match_scratch:XF 3 "=&1f,&1f"))]
14557   "TARGET_USE_FANCY_MATH_387"
14558   "#"
14559   [(set_attr "type" "fpspc")
14560    (set_attr "mode" "DI")])
14561
14562 (define_split
14563   [(set (match_operand:DI 0 "register_operand" "")
14564         (unspec:DI [(match_operand:XF 1 "register_operand" "")]
14565                    UNSPEC_FIST))
14566    (clobber (match_operand:DI 2 "memory_operand" ""))
14567    (clobber (match_scratch 3 ""))]
14568   "reload_completed"
14569   [(parallel [(set (match_dup 2) (unspec:DI [(match_dup 1)] UNSPEC_FIST))
14570               (clobber (match_dup 3))])
14571    (set (match_dup 0) (match_dup 2))])
14572
14573 (define_split
14574   [(set (match_operand:DI 0 "memory_operand" "")
14575         (unspec:DI [(match_operand:XF 1 "register_operand" "")]
14576                    UNSPEC_FIST))
14577    (clobber (match_operand:DI 2 "memory_operand" ""))
14578    (clobber (match_scratch 3 ""))]
14579   "reload_completed"
14580   [(parallel [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_FIST))
14581               (clobber (match_dup 3))])])
14582
14583 (define_insn_and_split "*fist<mode>2_1"
14584   [(set (match_operand:X87MODEI12 0 "register_operand" "")
14585         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "")]
14586                            UNSPEC_FIST))]
14587   "TARGET_USE_FANCY_MATH_387
14588    && can_create_pseudo_p ()"
14589   "#"
14590   "&& 1"
14591   [(const_int 0)]
14592 {
14593   operands[2] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
14594   emit_insn (gen_fist<mode>2_with_temp (operands[0], operands[1],
14595                                         operands[2]));
14596   DONE;
14597 }
14598   [(set_attr "type" "fpspc")
14599    (set_attr "mode" "<MODE>")])
14600
14601 (define_insn "fist<mode>2"
14602   [(set (match_operand:X87MODEI12 0 "memory_operand" "=m")
14603         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "f")]
14604                            UNSPEC_FIST))]
14605   "TARGET_USE_FANCY_MATH_387"
14606   "* return output_fix_trunc (insn, operands, 0);"
14607   [(set_attr "type" "fpspc")
14608    (set_attr "mode" "<MODE>")])
14609
14610 (define_insn "fist<mode>2_with_temp"
14611   [(set (match_operand:X87MODEI12 0 "register_operand" "=r")
14612         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "f")]
14613                            UNSPEC_FIST))
14614    (clobber (match_operand:X87MODEI12 2 "memory_operand" "=m"))]
14615   "TARGET_USE_FANCY_MATH_387"
14616   "#"
14617   [(set_attr "type" "fpspc")
14618    (set_attr "mode" "<MODE>")])
14619
14620 (define_split
14621   [(set (match_operand:X87MODEI12 0 "register_operand" "")
14622         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "")]
14623                            UNSPEC_FIST))
14624    (clobber (match_operand:X87MODEI12 2 "memory_operand" ""))]
14625   "reload_completed"
14626   [(set (match_dup 2) (unspec:X87MODEI12 [(match_dup 1)] UNSPEC_FIST))
14627    (set (match_dup 0) (match_dup 2))])
14628
14629 (define_split
14630   [(set (match_operand:X87MODEI12 0 "memory_operand" "")
14631         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "")]
14632                            UNSPEC_FIST))
14633    (clobber (match_operand:X87MODEI12 2 "memory_operand" ""))]
14634   "reload_completed"
14635   [(set (match_dup 0) (unspec:X87MODEI12 [(match_dup 1)] UNSPEC_FIST))])
14636
14637 (define_expand "lrintxf<mode>2"
14638   [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "")
14639      (unspec:X87MODEI [(match_operand:XF 1 "register_operand" "")]
14640                       UNSPEC_FIST))]
14641   "TARGET_USE_FANCY_MATH_387")
14642
14643 (define_expand "lrint<MODEF:mode><SSEMODEI24:mode>2"
14644   [(set (match_operand:SSEMODEI24 0 "nonimmediate_operand" "")
14645      (unspec:SSEMODEI24 [(match_operand:MODEF 1 "register_operand" "")]
14646                         UNSPEC_FIX_NOTRUNC))]
14647   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
14648    && ((<SSEMODEI24:MODE>mode != DImode) || TARGET_64BIT)")
14649
14650 (define_expand "lround<MODEF:mode><SSEMODEI24:mode>2"
14651   [(match_operand:SSEMODEI24 0 "nonimmediate_operand" "")
14652    (match_operand:MODEF 1 "register_operand" "")]
14653   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
14654    && ((<SSEMODEI24:MODE>mode != DImode) || TARGET_64BIT)
14655    && !flag_trapping_math && !flag_rounding_math"
14656 {
14657   if (optimize_insn_for_size_p ())
14658     FAIL;
14659   ix86_expand_lround (operand0, operand1);
14660   DONE;
14661 })
14662
14663 ;; Rounding mode control word calculation could clobber FLAGS_REG.
14664 (define_insn_and_split "frndintxf2_floor"
14665   [(set (match_operand:XF 0 "register_operand" "")
14666         (unspec:XF [(match_operand:XF 1 "register_operand" "")]
14667          UNSPEC_FRNDINT_FLOOR))
14668    (clobber (reg:CC FLAGS_REG))]
14669   "TARGET_USE_FANCY_MATH_387
14670    && flag_unsafe_math_optimizations
14671    && can_create_pseudo_p ()"
14672   "#"
14673   "&& 1"
14674   [(const_int 0)]
14675 {
14676   ix86_optimize_mode_switching[I387_FLOOR] = 1;
14677
14678   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
14679   operands[3] = assign_386_stack_local (HImode, SLOT_CW_FLOOR);
14680
14681   emit_insn (gen_frndintxf2_floor_i387 (operands[0], operands[1],
14682                                         operands[2], operands[3]));
14683   DONE;
14684 }
14685   [(set_attr "type" "frndint")
14686    (set_attr "i387_cw" "floor")
14687    (set_attr "mode" "XF")])
14688
14689 (define_insn "frndintxf2_floor_i387"
14690   [(set (match_operand:XF 0 "register_operand" "=f")
14691         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
14692          UNSPEC_FRNDINT_FLOOR))
14693    (use (match_operand:HI 2 "memory_operand" "m"))
14694    (use (match_operand:HI 3 "memory_operand" "m"))]
14695   "TARGET_USE_FANCY_MATH_387
14696    && flag_unsafe_math_optimizations"
14697   "fldcw\t%3\n\tfrndint\n\tfldcw\t%2"
14698   [(set_attr "type" "frndint")
14699    (set_attr "i387_cw" "floor")
14700    (set_attr "mode" "XF")])
14701
14702 (define_expand "floorxf2"
14703   [(use (match_operand:XF 0 "register_operand" ""))
14704    (use (match_operand:XF 1 "register_operand" ""))]
14705   "TARGET_USE_FANCY_MATH_387
14706    && flag_unsafe_math_optimizations"
14707 {
14708   if (optimize_insn_for_size_p ())
14709     FAIL;
14710   emit_insn (gen_frndintxf2_floor (operands[0], operands[1]));
14711   DONE;
14712 })
14713
14714 (define_expand "floor<mode>2"
14715   [(use (match_operand:MODEF 0 "register_operand" ""))
14716    (use (match_operand:MODEF 1 "register_operand" ""))]
14717   "(TARGET_USE_FANCY_MATH_387
14718     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14719         || TARGET_MIX_SSE_I387)
14720     && flag_unsafe_math_optimizations)
14721    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
14722        && !flag_trapping_math)"
14723 {
14724   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
14725       && !flag_trapping_math
14726       && (TARGET_ROUND || optimize_insn_for_speed_p ()))
14727     {
14728       if (!TARGET_ROUND && optimize_insn_for_size_p ())
14729         FAIL;
14730       if (TARGET_ROUND)
14731         emit_insn (gen_sse4_1_round<mode>2
14732                    (operands[0], operands[1], GEN_INT (ROUND_FLOOR)));
14733       else if (TARGET_64BIT || (<MODE>mode != DFmode))
14734         ix86_expand_floorceil (operand0, operand1, true);
14735       else
14736         ix86_expand_floorceildf_32 (operand0, operand1, true);
14737     }
14738   else
14739     {
14740       rtx op0, op1;
14741
14742       if (optimize_insn_for_size_p ())
14743         FAIL;
14744
14745       op0 = gen_reg_rtx (XFmode);
14746       op1 = gen_reg_rtx (XFmode);
14747       emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14748       emit_insn (gen_frndintxf2_floor (op0, op1));
14749
14750       emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14751     }
14752   DONE;
14753 })
14754
14755 (define_insn_and_split "*fist<mode>2_floor_1"
14756   [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "")
14757         (unspec:X87MODEI [(match_operand:XF 1 "register_operand" "")]
14758          UNSPEC_FIST_FLOOR))
14759    (clobber (reg:CC FLAGS_REG))]
14760   "TARGET_USE_FANCY_MATH_387
14761    && flag_unsafe_math_optimizations
14762    && can_create_pseudo_p ()"
14763   "#"
14764   "&& 1"
14765   [(const_int 0)]
14766 {
14767   ix86_optimize_mode_switching[I387_FLOOR] = 1;
14768
14769   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
14770   operands[3] = assign_386_stack_local (HImode, SLOT_CW_FLOOR);
14771   if (memory_operand (operands[0], VOIDmode))
14772     emit_insn (gen_fist<mode>2_floor (operands[0], operands[1],
14773                                       operands[2], operands[3]));
14774   else
14775     {
14776       operands[4] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
14777       emit_insn (gen_fist<mode>2_floor_with_temp (operands[0], operands[1],
14778                                                   operands[2], operands[3],
14779                                                   operands[4]));
14780     }
14781   DONE;
14782 }
14783   [(set_attr "type" "fistp")
14784    (set_attr "i387_cw" "floor")
14785    (set_attr "mode" "<MODE>")])
14786
14787 (define_insn "fistdi2_floor"
14788   [(set (match_operand:DI 0 "memory_operand" "=m")
14789         (unspec:DI [(match_operand:XF 1 "register_operand" "f")]
14790          UNSPEC_FIST_FLOOR))
14791    (use (match_operand:HI 2 "memory_operand" "m"))
14792    (use (match_operand:HI 3 "memory_operand" "m"))
14793    (clobber (match_scratch:XF 4 "=&1f"))]
14794   "TARGET_USE_FANCY_MATH_387
14795    && flag_unsafe_math_optimizations"
14796   "* return output_fix_trunc (insn, operands, 0);"
14797   [(set_attr "type" "fistp")
14798    (set_attr "i387_cw" "floor")
14799    (set_attr "mode" "DI")])
14800
14801 (define_insn "fistdi2_floor_with_temp"
14802   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
14803         (unspec:DI [(match_operand:XF 1 "register_operand" "f,f")]
14804          UNSPEC_FIST_FLOOR))
14805    (use (match_operand:HI 2 "memory_operand" "m,m"))
14806    (use (match_operand:HI 3 "memory_operand" "m,m"))
14807    (clobber (match_operand:DI 4 "memory_operand" "=X,m"))
14808    (clobber (match_scratch:XF 5 "=&1f,&1f"))]
14809   "TARGET_USE_FANCY_MATH_387
14810    && flag_unsafe_math_optimizations"
14811   "#"
14812   [(set_attr "type" "fistp")
14813    (set_attr "i387_cw" "floor")
14814    (set_attr "mode" "DI")])
14815
14816 (define_split
14817   [(set (match_operand:DI 0 "register_operand" "")
14818         (unspec:DI [(match_operand:XF 1 "register_operand" "")]
14819          UNSPEC_FIST_FLOOR))
14820    (use (match_operand:HI 2 "memory_operand" ""))
14821    (use (match_operand:HI 3 "memory_operand" ""))
14822    (clobber (match_operand:DI 4 "memory_operand" ""))
14823    (clobber (match_scratch 5 ""))]
14824   "reload_completed"
14825   [(parallel [(set (match_dup 4) (unspec:DI [(match_dup 1)] UNSPEC_FIST_FLOOR))
14826               (use (match_dup 2))
14827               (use (match_dup 3))
14828               (clobber (match_dup 5))])
14829    (set (match_dup 0) (match_dup 4))])
14830
14831 (define_split
14832   [(set (match_operand:DI 0 "memory_operand" "")
14833         (unspec:DI [(match_operand:XF 1 "register_operand" "")]
14834          UNSPEC_FIST_FLOOR))
14835    (use (match_operand:HI 2 "memory_operand" ""))
14836    (use (match_operand:HI 3 "memory_operand" ""))
14837    (clobber (match_operand:DI 4 "memory_operand" ""))
14838    (clobber (match_scratch 5 ""))]
14839   "reload_completed"
14840   [(parallel [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_FIST_FLOOR))
14841               (use (match_dup 2))
14842               (use (match_dup 3))
14843               (clobber (match_dup 5))])])
14844
14845 (define_insn "fist<mode>2_floor"
14846   [(set (match_operand:X87MODEI12 0 "memory_operand" "=m")
14847         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "f")]
14848          UNSPEC_FIST_FLOOR))
14849    (use (match_operand:HI 2 "memory_operand" "m"))
14850    (use (match_operand:HI 3 "memory_operand" "m"))]
14851   "TARGET_USE_FANCY_MATH_387
14852    && flag_unsafe_math_optimizations"
14853   "* return output_fix_trunc (insn, operands, 0);"
14854   [(set_attr "type" "fistp")
14855    (set_attr "i387_cw" "floor")
14856    (set_attr "mode" "<MODE>")])
14857
14858 (define_insn "fist<mode>2_floor_with_temp"
14859   [(set (match_operand:X87MODEI12 0 "nonimmediate_operand" "=m,?r")
14860         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "f,f")]
14861          UNSPEC_FIST_FLOOR))
14862    (use (match_operand:HI 2 "memory_operand" "m,m"))
14863    (use (match_operand:HI 3 "memory_operand" "m,m"))
14864    (clobber (match_operand:X87MODEI12 4 "memory_operand" "=X,m"))]
14865   "TARGET_USE_FANCY_MATH_387
14866    && flag_unsafe_math_optimizations"
14867   "#"
14868   [(set_attr "type" "fistp")
14869    (set_attr "i387_cw" "floor")
14870    (set_attr "mode" "<MODE>")])
14871
14872 (define_split
14873   [(set (match_operand:X87MODEI12 0 "register_operand" "")
14874         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "")]
14875          UNSPEC_FIST_FLOOR))
14876    (use (match_operand:HI 2 "memory_operand" ""))
14877    (use (match_operand:HI 3 "memory_operand" ""))
14878    (clobber (match_operand:X87MODEI12 4 "memory_operand" ""))]
14879   "reload_completed"
14880   [(parallel [(set (match_dup 4) (unspec:X87MODEI12 [(match_dup 1)]
14881                                   UNSPEC_FIST_FLOOR))
14882               (use (match_dup 2))
14883               (use (match_dup 3))])
14884    (set (match_dup 0) (match_dup 4))])
14885
14886 (define_split
14887   [(set (match_operand:X87MODEI12 0 "memory_operand" "")
14888         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "")]
14889          UNSPEC_FIST_FLOOR))
14890    (use (match_operand:HI 2 "memory_operand" ""))
14891    (use (match_operand:HI 3 "memory_operand" ""))
14892    (clobber (match_operand:X87MODEI12 4 "memory_operand" ""))]
14893   "reload_completed"
14894   [(parallel [(set (match_dup 0) (unspec:X87MODEI12 [(match_dup 1)]
14895                                   UNSPEC_FIST_FLOOR))
14896               (use (match_dup 2))
14897               (use (match_dup 3))])])
14898
14899 (define_expand "lfloorxf<mode>2"
14900   [(parallel [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "")
14901                    (unspec:X87MODEI [(match_operand:XF 1 "register_operand" "")]
14902                     UNSPEC_FIST_FLOOR))
14903               (clobber (reg:CC FLAGS_REG))])]
14904   "TARGET_USE_FANCY_MATH_387
14905    && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387)
14906    && flag_unsafe_math_optimizations")
14907
14908 (define_expand "lfloor<MODEF:mode><SWI48:mode>2"
14909   [(match_operand:SWI48 0 "nonimmediate_operand" "")
14910    (match_operand:MODEF 1 "register_operand" "")]
14911   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
14912    && !flag_trapping_math"
14913 {
14914   if (TARGET_64BIT && optimize_insn_for_size_p ())
14915     FAIL;
14916   ix86_expand_lfloorceil (operand0, operand1, true);
14917   DONE;
14918 })
14919
14920 ;; Rounding mode control word calculation could clobber FLAGS_REG.
14921 (define_insn_and_split "frndintxf2_ceil"
14922   [(set (match_operand:XF 0 "register_operand" "")
14923         (unspec:XF [(match_operand:XF 1 "register_operand" "")]
14924          UNSPEC_FRNDINT_CEIL))
14925    (clobber (reg:CC FLAGS_REG))]
14926   "TARGET_USE_FANCY_MATH_387
14927    && flag_unsafe_math_optimizations
14928    && can_create_pseudo_p ()"
14929   "#"
14930   "&& 1"
14931   [(const_int 0)]
14932 {
14933   ix86_optimize_mode_switching[I387_CEIL] = 1;
14934
14935   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
14936   operands[3] = assign_386_stack_local (HImode, SLOT_CW_CEIL);
14937
14938   emit_insn (gen_frndintxf2_ceil_i387 (operands[0], operands[1],
14939                                        operands[2], operands[3]));
14940   DONE;
14941 }
14942   [(set_attr "type" "frndint")
14943    (set_attr "i387_cw" "ceil")
14944    (set_attr "mode" "XF")])
14945
14946 (define_insn "frndintxf2_ceil_i387"
14947   [(set (match_operand:XF 0 "register_operand" "=f")
14948         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
14949          UNSPEC_FRNDINT_CEIL))
14950    (use (match_operand:HI 2 "memory_operand" "m"))
14951    (use (match_operand:HI 3 "memory_operand" "m"))]
14952   "TARGET_USE_FANCY_MATH_387
14953    && flag_unsafe_math_optimizations"
14954   "fldcw\t%3\n\tfrndint\n\tfldcw\t%2"
14955   [(set_attr "type" "frndint")
14956    (set_attr "i387_cw" "ceil")
14957    (set_attr "mode" "XF")])
14958
14959 (define_expand "ceilxf2"
14960   [(use (match_operand:XF 0 "register_operand" ""))
14961    (use (match_operand:XF 1 "register_operand" ""))]
14962   "TARGET_USE_FANCY_MATH_387
14963    && flag_unsafe_math_optimizations"
14964 {
14965   if (optimize_insn_for_size_p ())
14966     FAIL;
14967   emit_insn (gen_frndintxf2_ceil (operands[0], operands[1]));
14968   DONE;
14969 })
14970
14971 (define_expand "ceil<mode>2"
14972   [(use (match_operand:MODEF 0 "register_operand" ""))
14973    (use (match_operand:MODEF 1 "register_operand" ""))]
14974   "(TARGET_USE_FANCY_MATH_387
14975     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14976         || TARGET_MIX_SSE_I387)
14977     && flag_unsafe_math_optimizations)
14978    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
14979        && !flag_trapping_math)"
14980 {
14981   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
14982       && !flag_trapping_math
14983       && (TARGET_ROUND || optimize_insn_for_speed_p ()))
14984     {
14985       if (TARGET_ROUND)
14986         emit_insn (gen_sse4_1_round<mode>2
14987                    (operands[0], operands[1], GEN_INT (ROUND_CEIL)));
14988       else if (optimize_insn_for_size_p ())
14989         FAIL;
14990       else if (TARGET_64BIT || (<MODE>mode != DFmode))
14991         ix86_expand_floorceil (operand0, operand1, false);
14992       else
14993         ix86_expand_floorceildf_32 (operand0, operand1, false);
14994     }
14995   else
14996     {
14997       rtx op0, op1;
14998
14999       if (optimize_insn_for_size_p ())
15000         FAIL;
15001
15002       op0 = gen_reg_rtx (XFmode);
15003       op1 = gen_reg_rtx (XFmode);
15004       emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15005       emit_insn (gen_frndintxf2_ceil (op0, op1));
15006
15007       emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15008     }
15009   DONE;
15010 })
15011
15012 (define_insn_and_split "*fist<mode>2_ceil_1"
15013   [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "")
15014         (unspec:X87MODEI [(match_operand:XF 1 "register_operand" "")]
15015          UNSPEC_FIST_CEIL))
15016    (clobber (reg:CC FLAGS_REG))]
15017   "TARGET_USE_FANCY_MATH_387
15018    && flag_unsafe_math_optimizations
15019    && can_create_pseudo_p ()"
15020   "#"
15021   "&& 1"
15022   [(const_int 0)]
15023 {
15024   ix86_optimize_mode_switching[I387_CEIL] = 1;
15025
15026   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
15027   operands[3] = assign_386_stack_local (HImode, SLOT_CW_CEIL);
15028   if (memory_operand (operands[0], VOIDmode))
15029     emit_insn (gen_fist<mode>2_ceil (operands[0], operands[1],
15030                                      operands[2], operands[3]));
15031   else
15032     {
15033       operands[4] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
15034       emit_insn (gen_fist<mode>2_ceil_with_temp (operands[0], operands[1],
15035                                                  operands[2], operands[3],
15036                                                  operands[4]));
15037     }
15038   DONE;
15039 }
15040   [(set_attr "type" "fistp")
15041    (set_attr "i387_cw" "ceil")
15042    (set_attr "mode" "<MODE>")])
15043
15044 (define_insn "fistdi2_ceil"
15045   [(set (match_operand:DI 0 "memory_operand" "=m")
15046         (unspec:DI [(match_operand:XF 1 "register_operand" "f")]
15047          UNSPEC_FIST_CEIL))
15048    (use (match_operand:HI 2 "memory_operand" "m"))
15049    (use (match_operand:HI 3 "memory_operand" "m"))
15050    (clobber (match_scratch:XF 4 "=&1f"))]
15051   "TARGET_USE_FANCY_MATH_387
15052    && flag_unsafe_math_optimizations"
15053   "* return output_fix_trunc (insn, operands, 0);"
15054   [(set_attr "type" "fistp")
15055    (set_attr "i387_cw" "ceil")
15056    (set_attr "mode" "DI")])
15057
15058 (define_insn "fistdi2_ceil_with_temp"
15059   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
15060         (unspec:DI [(match_operand:XF 1 "register_operand" "f,f")]
15061          UNSPEC_FIST_CEIL))
15062    (use (match_operand:HI 2 "memory_operand" "m,m"))
15063    (use (match_operand:HI 3 "memory_operand" "m,m"))
15064    (clobber (match_operand:DI 4 "memory_operand" "=X,m"))
15065    (clobber (match_scratch:XF 5 "=&1f,&1f"))]
15066   "TARGET_USE_FANCY_MATH_387
15067    && flag_unsafe_math_optimizations"
15068   "#"
15069   [(set_attr "type" "fistp")
15070    (set_attr "i387_cw" "ceil")
15071    (set_attr "mode" "DI")])
15072
15073 (define_split
15074   [(set (match_operand:DI 0 "register_operand" "")
15075         (unspec:DI [(match_operand:XF 1 "register_operand" "")]
15076          UNSPEC_FIST_CEIL))
15077    (use (match_operand:HI 2 "memory_operand" ""))
15078    (use (match_operand:HI 3 "memory_operand" ""))
15079    (clobber (match_operand:DI 4 "memory_operand" ""))
15080    (clobber (match_scratch 5 ""))]
15081   "reload_completed"
15082   [(parallel [(set (match_dup 4) (unspec:DI [(match_dup 1)] UNSPEC_FIST_CEIL))
15083               (use (match_dup 2))
15084               (use (match_dup 3))
15085               (clobber (match_dup 5))])
15086    (set (match_dup 0) (match_dup 4))])
15087
15088 (define_split
15089   [(set (match_operand:DI 0 "memory_operand" "")
15090         (unspec:DI [(match_operand:XF 1 "register_operand" "")]
15091          UNSPEC_FIST_CEIL))
15092    (use (match_operand:HI 2 "memory_operand" ""))
15093    (use (match_operand:HI 3 "memory_operand" ""))
15094    (clobber (match_operand:DI 4 "memory_operand" ""))
15095    (clobber (match_scratch 5 ""))]
15096   "reload_completed"
15097   [(parallel [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_FIST_CEIL))
15098               (use (match_dup 2))
15099               (use (match_dup 3))
15100               (clobber (match_dup 5))])])
15101
15102 (define_insn "fist<mode>2_ceil"
15103   [(set (match_operand:X87MODEI12 0 "memory_operand" "=m")
15104         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "f")]
15105          UNSPEC_FIST_CEIL))
15106    (use (match_operand:HI 2 "memory_operand" "m"))
15107    (use (match_operand:HI 3 "memory_operand" "m"))]
15108   "TARGET_USE_FANCY_MATH_387
15109    && flag_unsafe_math_optimizations"
15110   "* return output_fix_trunc (insn, operands, 0);"
15111   [(set_attr "type" "fistp")
15112    (set_attr "i387_cw" "ceil")
15113    (set_attr "mode" "<MODE>")])
15114
15115 (define_insn "fist<mode>2_ceil_with_temp"
15116   [(set (match_operand:X87MODEI12 0 "nonimmediate_operand" "=m,?r")
15117         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "f,f")]
15118          UNSPEC_FIST_CEIL))
15119    (use (match_operand:HI 2 "memory_operand" "m,m"))
15120    (use (match_operand:HI 3 "memory_operand" "m,m"))
15121    (clobber (match_operand:X87MODEI12 4 "memory_operand" "=X,m"))]
15122   "TARGET_USE_FANCY_MATH_387
15123    && flag_unsafe_math_optimizations"
15124   "#"
15125   [(set_attr "type" "fistp")
15126    (set_attr "i387_cw" "ceil")
15127    (set_attr "mode" "<MODE>")])
15128
15129 (define_split
15130   [(set (match_operand:X87MODEI12 0 "register_operand" "")
15131         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "")]
15132          UNSPEC_FIST_CEIL))
15133    (use (match_operand:HI 2 "memory_operand" ""))
15134    (use (match_operand:HI 3 "memory_operand" ""))
15135    (clobber (match_operand:X87MODEI12 4 "memory_operand" ""))]
15136   "reload_completed"
15137   [(parallel [(set (match_dup 4) (unspec:X87MODEI12 [(match_dup 1)]
15138                                   UNSPEC_FIST_CEIL))
15139               (use (match_dup 2))
15140               (use (match_dup 3))])
15141    (set (match_dup 0) (match_dup 4))])
15142
15143 (define_split
15144   [(set (match_operand:X87MODEI12 0 "memory_operand" "")
15145         (unspec:X87MODEI12 [(match_operand:XF 1 "register_operand" "")]
15146          UNSPEC_FIST_CEIL))
15147    (use (match_operand:HI 2 "memory_operand" ""))
15148    (use (match_operand:HI 3 "memory_operand" ""))
15149    (clobber (match_operand:X87MODEI12 4 "memory_operand" ""))]
15150   "reload_completed"
15151   [(parallel [(set (match_dup 0) (unspec:X87MODEI12 [(match_dup 1)]
15152                                   UNSPEC_FIST_CEIL))
15153               (use (match_dup 2))
15154               (use (match_dup 3))])])
15155
15156 (define_expand "lceilxf<mode>2"
15157   [(parallel [(set (match_operand:X87MODEI 0 "nonimmediate_operand" "")
15158                    (unspec:X87MODEI [(match_operand:XF 1 "register_operand" "")]
15159                     UNSPEC_FIST_CEIL))
15160               (clobber (reg:CC FLAGS_REG))])]
15161   "TARGET_USE_FANCY_MATH_387
15162    && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387)
15163    && flag_unsafe_math_optimizations")
15164
15165 (define_expand "lceil<MODEF:mode><SWI48:mode>2"
15166   [(match_operand:SWI48 0 "nonimmediate_operand" "")
15167    (match_operand:MODEF 1 "register_operand" "")]
15168   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
15169    && !flag_trapping_math"
15170 {
15171   ix86_expand_lfloorceil (operand0, operand1, false);
15172   DONE;
15173 })
15174
15175 ;; Rounding mode control word calculation could clobber FLAGS_REG.
15176 (define_insn_and_split "frndintxf2_trunc"
15177   [(set (match_operand:XF 0 "register_operand" "")
15178         (unspec:XF [(match_operand:XF 1 "register_operand" "")]
15179          UNSPEC_FRNDINT_TRUNC))
15180    (clobber (reg:CC FLAGS_REG))]
15181   "TARGET_USE_FANCY_MATH_387
15182    && flag_unsafe_math_optimizations
15183    && can_create_pseudo_p ()"
15184   "#"
15185   "&& 1"
15186   [(const_int 0)]
15187 {
15188   ix86_optimize_mode_switching[I387_TRUNC] = 1;
15189
15190   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
15191   operands[3] = assign_386_stack_local (HImode, SLOT_CW_TRUNC);
15192
15193   emit_insn (gen_frndintxf2_trunc_i387 (operands[0], operands[1],
15194                                         operands[2], operands[3]));
15195   DONE;
15196 }
15197   [(set_attr "type" "frndint")
15198    (set_attr "i387_cw" "trunc")
15199    (set_attr "mode" "XF")])
15200
15201 (define_insn "frndintxf2_trunc_i387"
15202   [(set (match_operand:XF 0 "register_operand" "=f")
15203         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
15204          UNSPEC_FRNDINT_TRUNC))
15205    (use (match_operand:HI 2 "memory_operand" "m"))
15206    (use (match_operand:HI 3 "memory_operand" "m"))]
15207   "TARGET_USE_FANCY_MATH_387
15208    && flag_unsafe_math_optimizations"
15209   "fldcw\t%3\n\tfrndint\n\tfldcw\t%2"
15210   [(set_attr "type" "frndint")
15211    (set_attr "i387_cw" "trunc")
15212    (set_attr "mode" "XF")])
15213
15214 (define_expand "btruncxf2"
15215   [(use (match_operand:XF 0 "register_operand" ""))
15216    (use (match_operand:XF 1 "register_operand" ""))]
15217   "TARGET_USE_FANCY_MATH_387
15218    && flag_unsafe_math_optimizations"
15219 {
15220   if (optimize_insn_for_size_p ())
15221     FAIL;
15222   emit_insn (gen_frndintxf2_trunc (operands[0], operands[1]));
15223   DONE;
15224 })
15225
15226 (define_expand "btrunc<mode>2"
15227   [(use (match_operand:MODEF 0 "register_operand" ""))
15228    (use (match_operand:MODEF 1 "register_operand" ""))]
15229   "(TARGET_USE_FANCY_MATH_387
15230     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15231         || TARGET_MIX_SSE_I387)
15232     && flag_unsafe_math_optimizations)
15233    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15234        && !flag_trapping_math)"
15235 {
15236   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15237       && !flag_trapping_math
15238       && (TARGET_ROUND || optimize_insn_for_speed_p ()))
15239     {
15240       if (TARGET_ROUND)
15241         emit_insn (gen_sse4_1_round<mode>2
15242                    (operands[0], operands[1], GEN_INT (ROUND_TRUNC)));
15243       else if (optimize_insn_for_size_p ())
15244         FAIL;
15245       else if (TARGET_64BIT || (<MODE>mode != DFmode))
15246         ix86_expand_trunc (operand0, operand1);
15247       else
15248         ix86_expand_truncdf_32 (operand0, operand1);
15249     }
15250   else
15251     {
15252       rtx op0, op1;
15253
15254       if (optimize_insn_for_size_p ())
15255         FAIL;
15256
15257       op0 = gen_reg_rtx (XFmode);
15258       op1 = gen_reg_rtx (XFmode);
15259       emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15260       emit_insn (gen_frndintxf2_trunc (op0, op1));
15261
15262       emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15263     }
15264   DONE;
15265 })
15266
15267 ;; Rounding mode control word calculation could clobber FLAGS_REG.
15268 (define_insn_and_split "frndintxf2_mask_pm"
15269   [(set (match_operand:XF 0 "register_operand" "")
15270         (unspec:XF [(match_operand:XF 1 "register_operand" "")]
15271          UNSPEC_FRNDINT_MASK_PM))
15272    (clobber (reg:CC FLAGS_REG))]
15273   "TARGET_USE_FANCY_MATH_387
15274    && flag_unsafe_math_optimizations
15275    && can_create_pseudo_p ()"
15276   "#"
15277   "&& 1"
15278   [(const_int 0)]
15279 {
15280   ix86_optimize_mode_switching[I387_MASK_PM] = 1;
15281
15282   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
15283   operands[3] = assign_386_stack_local (HImode, SLOT_CW_MASK_PM);
15284
15285   emit_insn (gen_frndintxf2_mask_pm_i387 (operands[0], operands[1],
15286                                           operands[2], operands[3]));
15287   DONE;
15288 }
15289   [(set_attr "type" "frndint")
15290    (set_attr "i387_cw" "mask_pm")
15291    (set_attr "mode" "XF")])
15292
15293 (define_insn "frndintxf2_mask_pm_i387"
15294   [(set (match_operand:XF 0 "register_operand" "=f")
15295         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
15296          UNSPEC_FRNDINT_MASK_PM))
15297    (use (match_operand:HI 2 "memory_operand" "m"))
15298    (use (match_operand:HI 3 "memory_operand" "m"))]
15299   "TARGET_USE_FANCY_MATH_387
15300    && flag_unsafe_math_optimizations"
15301   "fldcw\t%3\n\tfrndint\n\tfclex\n\tfldcw\t%2"
15302   [(set_attr "type" "frndint")
15303    (set_attr "i387_cw" "mask_pm")
15304    (set_attr "mode" "XF")])
15305
15306 (define_expand "nearbyintxf2"
15307   [(use (match_operand:XF 0 "register_operand" ""))
15308    (use (match_operand:XF 1 "register_operand" ""))]
15309   "TARGET_USE_FANCY_MATH_387
15310    && flag_unsafe_math_optimizations"
15311 {
15312   emit_insn (gen_frndintxf2_mask_pm (operands[0], operands[1]));
15313   DONE;
15314 })
15315
15316 (define_expand "nearbyint<mode>2"
15317   [(use (match_operand:MODEF 0 "register_operand" ""))
15318    (use (match_operand:MODEF 1 "register_operand" ""))]
15319   "TARGET_USE_FANCY_MATH_387
15320    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15321        || TARGET_MIX_SSE_I387)
15322    && flag_unsafe_math_optimizations"
15323 {
15324   rtx op0 = gen_reg_rtx (XFmode);
15325   rtx op1 = gen_reg_rtx (XFmode);
15326
15327   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15328   emit_insn (gen_frndintxf2_mask_pm (op0, op1));
15329
15330   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15331   DONE;
15332 })
15333
15334 (define_insn "fxam<mode>2_i387"
15335   [(set (match_operand:HI 0 "register_operand" "=a")
15336         (unspec:HI
15337           [(match_operand:X87MODEF 1 "register_operand" "f")]
15338           UNSPEC_FXAM))]
15339   "TARGET_USE_FANCY_MATH_387"
15340   "fxam\n\tfnstsw\t%0"
15341   [(set_attr "type" "multi")
15342    (set_attr "length" "4")
15343    (set_attr "unit" "i387")
15344    (set_attr "mode" "<MODE>")])
15345
15346 (define_insn_and_split "fxam<mode>2_i387_with_temp"
15347   [(set (match_operand:HI 0 "register_operand" "")
15348         (unspec:HI
15349           [(match_operand:MODEF 1 "memory_operand" "")]
15350           UNSPEC_FXAM_MEM))]
15351   "TARGET_USE_FANCY_MATH_387
15352    && can_create_pseudo_p ()"
15353   "#"
15354   "&& 1"
15355   [(set (match_dup 2)(match_dup 1))
15356    (set (match_dup 0)
15357         (unspec:HI [(match_dup 2)] UNSPEC_FXAM))]
15358 {
15359   operands[2] = gen_reg_rtx (<MODE>mode);
15360
15361   MEM_VOLATILE_P (operands[1]) = 1;
15362 }
15363   [(set_attr "type" "multi")
15364    (set_attr "unit" "i387")
15365    (set_attr "mode" "<MODE>")])
15366
15367 (define_expand "isinfxf2"
15368   [(use (match_operand:SI 0 "register_operand" ""))
15369    (use (match_operand:XF 1 "register_operand" ""))]
15370   "TARGET_USE_FANCY_MATH_387
15371    && TARGET_C99_FUNCTIONS"
15372 {
15373   rtx mask = GEN_INT (0x45);
15374   rtx val = GEN_INT (0x05);
15375
15376   rtx cond;
15377
15378   rtx scratch = gen_reg_rtx (HImode);
15379   rtx res = gen_reg_rtx (QImode);
15380
15381   emit_insn (gen_fxamxf2_i387 (scratch, operands[1]));
15382
15383   emit_insn (gen_andqi_ext_0 (scratch, scratch, mask));
15384   emit_insn (gen_cmpqi_ext_3 (scratch, val));
15385   cond = gen_rtx_fmt_ee (EQ, QImode,
15386                          gen_rtx_REG (CCmode, FLAGS_REG),
15387                          const0_rtx);
15388   emit_insn (gen_rtx_SET (VOIDmode, res, cond));
15389   emit_insn (gen_zero_extendqisi2 (operands[0], res));
15390   DONE;
15391 })
15392
15393 (define_expand "isinf<mode>2"
15394   [(use (match_operand:SI 0 "register_operand" ""))
15395    (use (match_operand:MODEF 1 "nonimmediate_operand" ""))]
15396   "TARGET_USE_FANCY_MATH_387
15397    && TARGET_C99_FUNCTIONS
15398    && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
15399 {
15400   rtx mask = GEN_INT (0x45);
15401   rtx val = GEN_INT (0x05);
15402
15403   rtx cond;
15404
15405   rtx scratch = gen_reg_rtx (HImode);
15406   rtx res = gen_reg_rtx (QImode);
15407
15408   /* Remove excess precision by forcing value through memory. */
15409   if (memory_operand (operands[1], VOIDmode))
15410     emit_insn (gen_fxam<mode>2_i387_with_temp (scratch, operands[1]));
15411   else
15412     {
15413       enum ix86_stack_slot slot = (virtuals_instantiated
15414                                    ? SLOT_TEMP
15415                                    : SLOT_VIRTUAL);
15416       rtx temp = assign_386_stack_local (<MODE>mode, slot);
15417
15418       emit_move_insn (temp, operands[1]);
15419       emit_insn (gen_fxam<mode>2_i387_with_temp (scratch, temp));
15420     }
15421
15422   emit_insn (gen_andqi_ext_0 (scratch, scratch, mask));
15423   emit_insn (gen_cmpqi_ext_3 (scratch, val));
15424   cond = gen_rtx_fmt_ee (EQ, QImode,
15425                          gen_rtx_REG (CCmode, FLAGS_REG),
15426                          const0_rtx);
15427   emit_insn (gen_rtx_SET (VOIDmode, res, cond));
15428   emit_insn (gen_zero_extendqisi2 (operands[0], res));
15429   DONE;
15430 })
15431
15432 (define_expand "signbitxf2"
15433   [(use (match_operand:SI 0 "register_operand" ""))
15434    (use (match_operand:XF 1 "register_operand" ""))]
15435   "TARGET_USE_FANCY_MATH_387"
15436 {
15437   rtx scratch = gen_reg_rtx (HImode);
15438
15439   emit_insn (gen_fxamxf2_i387 (scratch, operands[1]));
15440   emit_insn (gen_andsi3 (operands[0],
15441              gen_lowpart (SImode, scratch), GEN_INT (0x200)));
15442   DONE;
15443 })
15444
15445 (define_insn "movmsk_df"
15446   [(set (match_operand:SI 0 "register_operand" "=r")
15447         (unspec:SI
15448           [(match_operand:DF 1 "register_operand" "x")]
15449           UNSPEC_MOVMSK))]
15450   "SSE_FLOAT_MODE_P (DFmode) && TARGET_SSE_MATH"
15451   "%vmovmskpd\t{%1, %0|%0, %1}"
15452   [(set_attr "type" "ssemov")
15453    (set_attr "prefix" "maybe_vex")
15454    (set_attr "mode" "DF")])
15455
15456 ;; Use movmskpd in SSE mode to avoid store forwarding stall
15457 ;; for 32bit targets and movq+shrq sequence for 64bit targets.
15458 (define_expand "signbitdf2"
15459   [(use (match_operand:SI 0 "register_operand" ""))
15460    (use (match_operand:DF 1 "register_operand" ""))]
15461   "TARGET_USE_FANCY_MATH_387
15462    || (SSE_FLOAT_MODE_P (DFmode) && TARGET_SSE_MATH)"
15463 {
15464   if (SSE_FLOAT_MODE_P (DFmode) && TARGET_SSE_MATH)
15465     {
15466       emit_insn (gen_movmsk_df (operands[0], operands[1]));
15467       emit_insn (gen_andsi3 (operands[0], operands[0], const1_rtx));
15468     }
15469   else
15470     {
15471       rtx scratch = gen_reg_rtx (HImode);
15472
15473       emit_insn (gen_fxamdf2_i387 (scratch, operands[1]));
15474       emit_insn (gen_andsi3 (operands[0],
15475                  gen_lowpart (SImode, scratch), GEN_INT (0x200)));
15476     }
15477   DONE;
15478 })
15479
15480 (define_expand "signbitsf2"
15481   [(use (match_operand:SI 0 "register_operand" ""))
15482    (use (match_operand:SF 1 "register_operand" ""))]
15483   "TARGET_USE_FANCY_MATH_387
15484    && !(SSE_FLOAT_MODE_P (SFmode) && TARGET_SSE_MATH)"
15485 {
15486   rtx scratch = gen_reg_rtx (HImode);
15487
15488   emit_insn (gen_fxamsf2_i387 (scratch, operands[1]));
15489   emit_insn (gen_andsi3 (operands[0],
15490              gen_lowpart (SImode, scratch), GEN_INT (0x200)));
15491   DONE;
15492 })
15493 \f
15494 ;; Block operation instructions
15495
15496 (define_insn "cld"
15497   [(unspec_volatile [(const_int 0)] UNSPECV_CLD)]
15498   ""
15499   "cld"
15500   [(set_attr "length" "1")
15501    (set_attr "length_immediate" "0")
15502    (set_attr "modrm" "0")])
15503
15504 (define_expand "movmem<mode>"
15505   [(use (match_operand:BLK 0 "memory_operand" ""))
15506    (use (match_operand:BLK 1 "memory_operand" ""))
15507    (use (match_operand:SWI48 2 "nonmemory_operand" ""))
15508    (use (match_operand:SWI48 3 "const_int_operand" ""))
15509    (use (match_operand:SI 4 "const_int_operand" ""))
15510    (use (match_operand:SI 5 "const_int_operand" ""))]
15511   ""
15512 {
15513  if (ix86_expand_movmem (operands[0], operands[1], operands[2], operands[3],
15514                          operands[4], operands[5]))
15515    DONE;
15516  else
15517    FAIL;
15518 })
15519
15520 ;; Most CPUs don't like single string operations
15521 ;; Handle this case here to simplify previous expander.
15522
15523 (define_expand "strmov"
15524   [(set (match_dup 4) (match_operand 3 "memory_operand" ""))
15525    (set (match_operand 1 "memory_operand" "") (match_dup 4))
15526    (parallel [(set (match_operand 0 "register_operand" "") (match_dup 5))
15527               (clobber (reg:CC FLAGS_REG))])
15528    (parallel [(set (match_operand 2 "register_operand" "") (match_dup 6))
15529               (clobber (reg:CC FLAGS_REG))])]
15530   ""
15531 {
15532   rtx adjust = GEN_INT (GET_MODE_SIZE (GET_MODE (operands[1])));
15533
15534   /* If .md ever supports :P for Pmode, these can be directly
15535      in the pattern above.  */
15536   operands[5] = gen_rtx_PLUS (Pmode, operands[0], adjust);
15537   operands[6] = gen_rtx_PLUS (Pmode, operands[2], adjust);
15538
15539   /* Can't use this if the user has appropriated esi or edi.  */
15540   if ((TARGET_SINGLE_STRINGOP || optimize_insn_for_size_p ())
15541       && !(fixed_regs[SI_REG] || fixed_regs[DI_REG]))
15542     {
15543       emit_insn (gen_strmov_singleop (operands[0], operands[1],
15544                                       operands[2], operands[3],
15545                                       operands[5], operands[6]));
15546       DONE;
15547     }
15548
15549   operands[4] = gen_reg_rtx (GET_MODE (operands[1]));
15550 })
15551
15552 (define_expand "strmov_singleop"
15553   [(parallel [(set (match_operand 1 "memory_operand" "")
15554                    (match_operand 3 "memory_operand" ""))
15555               (set (match_operand 0 "register_operand" "")
15556                    (match_operand 4 "" ""))
15557               (set (match_operand 2 "register_operand" "")
15558                    (match_operand 5 "" ""))])]
15559   ""
15560   "ix86_current_function_needs_cld = 1;")
15561
15562 (define_insn "*strmovdi_rex_1"
15563   [(set (mem:DI (match_operand:DI 2 "register_operand" "0"))
15564         (mem:DI (match_operand:DI 3 "register_operand" "1")))
15565    (set (match_operand:DI 0 "register_operand" "=D")
15566         (plus:DI (match_dup 2)
15567                  (const_int 8)))
15568    (set (match_operand:DI 1 "register_operand" "=S")
15569         (plus:DI (match_dup 3)
15570                  (const_int 8)))]
15571   "TARGET_64BIT"
15572   "movsq"
15573   [(set_attr "type" "str")
15574    (set_attr "memory" "both")
15575    (set_attr "mode" "DI")])
15576
15577 (define_insn "*strmovsi_1"
15578   [(set (mem:SI (match_operand:P 2 "register_operand" "0"))
15579         (mem:SI (match_operand:P 3 "register_operand" "1")))
15580    (set (match_operand:P 0 "register_operand" "=D")
15581         (plus:P (match_dup 2)
15582                 (const_int 4)))
15583    (set (match_operand:P 1 "register_operand" "=S")
15584         (plus:P (match_dup 3)
15585                 (const_int 4)))]
15586   ""
15587   "movs{l|d}"
15588   [(set_attr "type" "str")
15589    (set_attr "memory" "both")
15590    (set_attr "mode" "SI")])
15591
15592 (define_insn "*strmovhi_1"
15593   [(set (mem:HI (match_operand:P 2 "register_operand" "0"))
15594         (mem:HI (match_operand:P 3 "register_operand" "1")))
15595    (set (match_operand:P 0 "register_operand" "=D")
15596         (plus:P (match_dup 2)
15597                 (const_int 2)))
15598    (set (match_operand:P 1 "register_operand" "=S")
15599         (plus:P (match_dup 3)
15600                 (const_int 2)))]
15601   ""
15602   "movsw"
15603   [(set_attr "type" "str")
15604    (set_attr "memory" "both")
15605    (set_attr "mode" "HI")])
15606
15607 (define_insn "*strmovqi_1"
15608   [(set (mem:QI (match_operand:P 2 "register_operand" "0"))
15609         (mem:QI (match_operand:P 3 "register_operand" "1")))
15610    (set (match_operand:P 0 "register_operand" "=D")
15611         (plus:P (match_dup 2)
15612                 (const_int 1)))
15613    (set (match_operand:P 1 "register_operand" "=S")
15614         (plus:P (match_dup 3)
15615                 (const_int 1)))]
15616   ""
15617   "movsb"
15618   [(set_attr "type" "str")
15619    (set_attr "memory" "both")
15620    (set (attr "prefix_rex")
15621         (if_then_else
15622           (ne (symbol_ref "<P:MODE>mode == DImode") (const_int 0))
15623           (const_string "0")
15624           (const_string "*")))
15625    (set_attr "mode" "QI")])
15626
15627 (define_expand "rep_mov"
15628   [(parallel [(set (match_operand 4 "register_operand" "") (const_int 0))
15629               (set (match_operand 0 "register_operand" "")
15630                    (match_operand 5 "" ""))
15631               (set (match_operand 2 "register_operand" "")
15632                    (match_operand 6 "" ""))
15633               (set (match_operand 1 "memory_operand" "")
15634                    (match_operand 3 "memory_operand" ""))
15635               (use (match_dup 4))])]
15636   ""
15637   "ix86_current_function_needs_cld = 1;")
15638
15639 (define_insn "*rep_movdi_rex64"
15640   [(set (match_operand:DI 2 "register_operand" "=c") (const_int 0))
15641    (set (match_operand:DI 0 "register_operand" "=D")
15642         (plus:DI (ashift:DI (match_operand:DI 5 "register_operand" "2")
15643                             (const_int 3))
15644                  (match_operand:DI 3 "register_operand" "0")))
15645    (set (match_operand:DI 1 "register_operand" "=S")
15646         (plus:DI (ashift:DI (match_dup 5) (const_int 3))
15647                  (match_operand:DI 4 "register_operand" "1")))
15648    (set (mem:BLK (match_dup 3))
15649         (mem:BLK (match_dup 4)))
15650    (use (match_dup 5))]
15651   "TARGET_64BIT"
15652   "rep{%;} movsq"
15653   [(set_attr "type" "str")
15654    (set_attr "prefix_rep" "1")
15655    (set_attr "memory" "both")
15656    (set_attr "mode" "DI")])
15657
15658 (define_insn "*rep_movsi"
15659   [(set (match_operand:P 2 "register_operand" "=c") (const_int 0))
15660    (set (match_operand:P 0 "register_operand" "=D")
15661         (plus:P (ashift:P (match_operand:P 5 "register_operand" "2")
15662                           (const_int 2))
15663                  (match_operand:P 3 "register_operand" "0")))
15664    (set (match_operand:P 1 "register_operand" "=S")
15665         (plus:P (ashift:P (match_dup 5) (const_int 2))
15666                 (match_operand:P 4 "register_operand" "1")))
15667    (set (mem:BLK (match_dup 3))
15668         (mem:BLK (match_dup 4)))
15669    (use (match_dup 5))]
15670   ""
15671   "rep{%;} movs{l|d}"
15672   [(set_attr "type" "str")
15673    (set_attr "prefix_rep" "1")
15674    (set_attr "memory" "both")
15675    (set_attr "mode" "SI")])
15676
15677 (define_insn "*rep_movqi"
15678   [(set (match_operand:P 2 "register_operand" "=c") (const_int 0))
15679    (set (match_operand:P 0 "register_operand" "=D")
15680         (plus:P (match_operand:P 3 "register_operand" "0")
15681                 (match_operand:P 5 "register_operand" "2")))
15682    (set (match_operand:P 1 "register_operand" "=S")
15683         (plus:P (match_operand:P 4 "register_operand" "1") (match_dup 5)))
15684    (set (mem:BLK (match_dup 3))
15685         (mem:BLK (match_dup 4)))
15686    (use (match_dup 5))]
15687   ""
15688   "rep{%;} movsb"
15689   [(set_attr "type" "str")
15690    (set_attr "prefix_rep" "1")
15691    (set_attr "memory" "both")
15692    (set_attr "mode" "QI")])
15693
15694 (define_expand "setmem<mode>"
15695    [(use (match_operand:BLK 0 "memory_operand" ""))
15696     (use (match_operand:SWI48 1 "nonmemory_operand" ""))
15697     (use (match_operand:QI 2 "nonmemory_operand" ""))
15698     (use (match_operand 3 "const_int_operand" ""))
15699     (use (match_operand:SI 4 "const_int_operand" ""))
15700     (use (match_operand:SI 5 "const_int_operand" ""))]
15701   ""
15702 {
15703  if (ix86_expand_setmem (operands[0], operands[1],
15704                          operands[2], operands[3],
15705                          operands[4], operands[5]))
15706    DONE;
15707  else
15708    FAIL;
15709 })
15710
15711 ;; Most CPUs don't like single string operations
15712 ;; Handle this case here to simplify previous expander.
15713
15714 (define_expand "strset"
15715   [(set (match_operand 1 "memory_operand" "")
15716         (match_operand 2 "register_operand" ""))
15717    (parallel [(set (match_operand 0 "register_operand" "")
15718                    (match_dup 3))
15719               (clobber (reg:CC FLAGS_REG))])]
15720   ""
15721 {
15722   if (GET_MODE (operands[1]) != GET_MODE (operands[2]))
15723     operands[1] = adjust_address_nv (operands[1], GET_MODE (operands[2]), 0);
15724
15725   /* If .md ever supports :P for Pmode, this can be directly
15726      in the pattern above.  */
15727   operands[3] = gen_rtx_PLUS (Pmode, operands[0],
15728                               GEN_INT (GET_MODE_SIZE (GET_MODE
15729                                                       (operands[2]))));
15730   if (TARGET_SINGLE_STRINGOP || optimize_insn_for_size_p ())
15731     {
15732       emit_insn (gen_strset_singleop (operands[0], operands[1], operands[2],
15733                                       operands[3]));
15734       DONE;
15735     }
15736 })
15737
15738 (define_expand "strset_singleop"
15739   [(parallel [(set (match_operand 1 "memory_operand" "")
15740                    (match_operand 2 "register_operand" ""))
15741               (set (match_operand 0 "register_operand" "")
15742                    (match_operand 3 "" ""))])]
15743   ""
15744   "ix86_current_function_needs_cld = 1;")
15745
15746 (define_insn "*strsetdi_rex_1"
15747   [(set (mem:DI (match_operand:DI 1 "register_operand" "0"))
15748         (match_operand:DI 2 "register_operand" "a"))
15749    (set (match_operand:DI 0 "register_operand" "=D")
15750         (plus:DI (match_dup 1)
15751                  (const_int 8)))]
15752   "TARGET_64BIT"
15753   "stosq"
15754   [(set_attr "type" "str")
15755    (set_attr "memory" "store")
15756    (set_attr "mode" "DI")])
15757
15758 (define_insn "*strsetsi_1"
15759   [(set (mem:SI (match_operand:P 1 "register_operand" "0"))
15760         (match_operand:SI 2 "register_operand" "a"))
15761    (set (match_operand:P 0 "register_operand" "=D")
15762         (plus:P (match_dup 1)
15763                 (const_int 4)))]
15764   ""
15765   "stos{l|d}"
15766   [(set_attr "type" "str")
15767    (set_attr "memory" "store")
15768    (set_attr "mode" "SI")])
15769
15770 (define_insn "*strsethi_1"
15771   [(set (mem:HI (match_operand:P 1 "register_operand" "0"))
15772         (match_operand:HI 2 "register_operand" "a"))
15773    (set (match_operand:P 0 "register_operand" "=D")
15774         (plus:P (match_dup 1)
15775                 (const_int 2)))]
15776   ""
15777   "stosw"
15778   [(set_attr "type" "str")
15779    (set_attr "memory" "store")
15780    (set_attr "mode" "HI")])
15781
15782 (define_insn "*strsetqi_1"
15783   [(set (mem:QI (match_operand:P 1 "register_operand" "0"))
15784         (match_operand:QI 2 "register_operand" "a"))
15785    (set (match_operand:P 0 "register_operand" "=D")
15786         (plus:P (match_dup 1)
15787                 (const_int 1)))]
15788   ""
15789   "stosb"
15790   [(set_attr "type" "str")
15791    (set_attr "memory" "store")
15792    (set (attr "prefix_rex")
15793         (if_then_else
15794           (ne (symbol_ref "<P:MODE>mode == DImode") (const_int 0))
15795           (const_string "0")
15796           (const_string "*")))
15797    (set_attr "mode" "QI")])
15798
15799 (define_expand "rep_stos"
15800   [(parallel [(set (match_operand 1 "register_operand" "") (const_int 0))
15801               (set (match_operand 0 "register_operand" "")
15802                    (match_operand 4 "" ""))
15803               (set (match_operand 2 "memory_operand" "") (const_int 0))
15804               (use (match_operand 3 "register_operand" ""))
15805               (use (match_dup 1))])]
15806   ""
15807   "ix86_current_function_needs_cld = 1;")
15808
15809 (define_insn "*rep_stosdi_rex64"
15810   [(set (match_operand:DI 1 "register_operand" "=c") (const_int 0))
15811    (set (match_operand:DI 0 "register_operand" "=D")
15812         (plus:DI (ashift:DI (match_operand:DI 4 "register_operand" "1")
15813                             (const_int 3))
15814                  (match_operand:DI 3 "register_operand" "0")))
15815    (set (mem:BLK (match_dup 3))
15816         (const_int 0))
15817    (use (match_operand:DI 2 "register_operand" "a"))
15818    (use (match_dup 4))]
15819   "TARGET_64BIT"
15820   "rep{%;} stosq"
15821   [(set_attr "type" "str")
15822    (set_attr "prefix_rep" "1")
15823    (set_attr "memory" "store")
15824    (set_attr "mode" "DI")])
15825
15826 (define_insn "*rep_stossi"
15827   [(set (match_operand:P 1 "register_operand" "=c") (const_int 0))
15828    (set (match_operand:P 0 "register_operand" "=D")
15829         (plus:P (ashift:P (match_operand:P 4 "register_operand" "1")
15830                           (const_int 2))
15831                  (match_operand:P 3 "register_operand" "0")))
15832    (set (mem:BLK (match_dup 3))
15833         (const_int 0))
15834    (use (match_operand:SI 2 "register_operand" "a"))
15835    (use (match_dup 4))]
15836   ""
15837   "rep{%;} stos{l|d}"
15838   [(set_attr "type" "str")
15839    (set_attr "prefix_rep" "1")
15840    (set_attr "memory" "store")
15841    (set_attr "mode" "SI")])
15842
15843 (define_insn "*rep_stosqi"
15844   [(set (match_operand:P 1 "register_operand" "=c") (const_int 0))
15845    (set (match_operand:P 0 "register_operand" "=D")
15846         (plus:P (match_operand:P 3 "register_operand" "0")
15847                 (match_operand:P 4 "register_operand" "1")))
15848    (set (mem:BLK (match_dup 3))
15849         (const_int 0))
15850    (use (match_operand:QI 2 "register_operand" "a"))
15851    (use (match_dup 4))]
15852   ""
15853   "rep{%;} stosb"
15854   [(set_attr "type" "str")
15855    (set_attr "prefix_rep" "1")
15856    (set_attr "memory" "store")
15857    (set (attr "prefix_rex")
15858         (if_then_else
15859           (ne (symbol_ref "<P:MODE>mode == DImode") (const_int 0))
15860           (const_string "0")
15861           (const_string "*")))
15862    (set_attr "mode" "QI")])
15863
15864 (define_expand "cmpstrnsi"
15865   [(set (match_operand:SI 0 "register_operand" "")
15866         (compare:SI (match_operand:BLK 1 "general_operand" "")
15867                     (match_operand:BLK 2 "general_operand" "")))
15868    (use (match_operand 3 "general_operand" ""))
15869    (use (match_operand 4 "immediate_operand" ""))]
15870   ""
15871 {
15872   rtx addr1, addr2, out, outlow, count, countreg, align;
15873
15874   if (optimize_insn_for_size_p () && !TARGET_INLINE_ALL_STRINGOPS)
15875     FAIL;
15876
15877   /* Can't use this if the user has appropriated esi or edi.  */
15878   if (fixed_regs[SI_REG] || fixed_regs[DI_REG])
15879     FAIL;
15880
15881   out = operands[0];
15882   if (!REG_P (out))
15883     out = gen_reg_rtx (SImode);
15884
15885   addr1 = copy_to_mode_reg (Pmode, XEXP (operands[1], 0));
15886   addr2 = copy_to_mode_reg (Pmode, XEXP (operands[2], 0));
15887   if (addr1 != XEXP (operands[1], 0))
15888     operands[1] = replace_equiv_address_nv (operands[1], addr1);
15889   if (addr2 != XEXP (operands[2], 0))
15890     operands[2] = replace_equiv_address_nv (operands[2], addr2);
15891
15892   count = operands[3];
15893   countreg = ix86_zero_extend_to_Pmode (count);
15894
15895   /* %%% Iff we are testing strict equality, we can use known alignment
15896      to good advantage.  This may be possible with combine, particularly
15897      once cc0 is dead.  */
15898   align = operands[4];
15899
15900   if (CONST_INT_P (count))
15901     {
15902       if (INTVAL (count) == 0)
15903         {
15904           emit_move_insn (operands[0], const0_rtx);
15905           DONE;
15906         }
15907       emit_insn (gen_cmpstrnqi_nz_1 (addr1, addr2, countreg, align,
15908                                      operands[1], operands[2]));
15909     }
15910   else
15911     {
15912       rtx (*gen_cmp) (rtx, rtx);
15913
15914       gen_cmp = (TARGET_64BIT
15915                  ? gen_cmpdi_1 : gen_cmpsi_1);
15916
15917       emit_insn (gen_cmp (countreg, countreg));
15918       emit_insn (gen_cmpstrnqi_1 (addr1, addr2, countreg, align,
15919                                   operands[1], operands[2]));
15920     }
15921
15922   outlow = gen_lowpart (QImode, out);
15923   emit_insn (gen_cmpintqi (outlow));
15924   emit_move_insn (out, gen_rtx_SIGN_EXTEND (SImode, outlow));
15925
15926   if (operands[0] != out)
15927     emit_move_insn (operands[0], out);
15928
15929   DONE;
15930 })
15931
15932 ;; Produce a tri-state integer (-1, 0, 1) from condition codes.
15933
15934 (define_expand "cmpintqi"
15935   [(set (match_dup 1)
15936         (gtu:QI (reg:CC FLAGS_REG) (const_int 0)))
15937    (set (match_dup 2)
15938         (ltu:QI (reg:CC FLAGS_REG) (const_int 0)))
15939    (parallel [(set (match_operand:QI 0 "register_operand" "")
15940                    (minus:QI (match_dup 1)
15941                              (match_dup 2)))
15942               (clobber (reg:CC FLAGS_REG))])]
15943   ""
15944 {
15945   operands[1] = gen_reg_rtx (QImode);
15946   operands[2] = gen_reg_rtx (QImode);
15947 })
15948
15949 ;; memcmp recognizers.  The `cmpsb' opcode does nothing if the count is
15950 ;; zero.  Emit extra code to make sure that a zero-length compare is EQ.
15951
15952 (define_expand "cmpstrnqi_nz_1"
15953   [(parallel [(set (reg:CC FLAGS_REG)
15954                    (compare:CC (match_operand 4 "memory_operand" "")
15955                                (match_operand 5 "memory_operand" "")))
15956               (use (match_operand 2 "register_operand" ""))
15957               (use (match_operand:SI 3 "immediate_operand" ""))
15958               (clobber (match_operand 0 "register_operand" ""))
15959               (clobber (match_operand 1 "register_operand" ""))
15960               (clobber (match_dup 2))])]
15961   ""
15962   "ix86_current_function_needs_cld = 1;")
15963
15964 (define_insn "*cmpstrnqi_nz_1"
15965   [(set (reg:CC FLAGS_REG)
15966         (compare:CC (mem:BLK (match_operand:P 4 "register_operand" "0"))
15967                     (mem:BLK (match_operand:P 5 "register_operand" "1"))))
15968    (use (match_operand:P 6 "register_operand" "2"))
15969    (use (match_operand:SI 3 "immediate_operand" "i"))
15970    (clobber (match_operand:P 0 "register_operand" "=S"))
15971    (clobber (match_operand:P 1 "register_operand" "=D"))
15972    (clobber (match_operand:P 2 "register_operand" "=c"))]
15973   ""
15974   "repz{%;} cmpsb"
15975   [(set_attr "type" "str")
15976    (set_attr "mode" "QI")
15977    (set (attr "prefix_rex")
15978         (if_then_else
15979           (ne (symbol_ref "<P:MODE>mode == DImode") (const_int 0))
15980           (const_string "0")
15981           (const_string "*")))
15982    (set_attr "prefix_rep" "1")])
15983
15984 ;; The same, but the count is not known to not be zero.
15985
15986 (define_expand "cmpstrnqi_1"
15987   [(parallel [(set (reg:CC FLAGS_REG)
15988                 (if_then_else:CC (ne (match_operand 2 "register_operand" "")
15989                                      (const_int 0))
15990                   (compare:CC (match_operand 4 "memory_operand" "")
15991                               (match_operand 5 "memory_operand" ""))
15992                   (const_int 0)))
15993               (use (match_operand:SI 3 "immediate_operand" ""))
15994               (use (reg:CC FLAGS_REG))
15995               (clobber (match_operand 0 "register_operand" ""))
15996               (clobber (match_operand 1 "register_operand" ""))
15997               (clobber (match_dup 2))])]
15998   ""
15999   "ix86_current_function_needs_cld = 1;")
16000
16001 (define_insn "*cmpstrnqi_1"
16002   [(set (reg:CC FLAGS_REG)
16003         (if_then_else:CC (ne (match_operand:P 6 "register_operand" "2")
16004                              (const_int 0))
16005           (compare:CC (mem:BLK (match_operand:P 4 "register_operand" "0"))
16006                       (mem:BLK (match_operand:P 5 "register_operand" "1")))
16007           (const_int 0)))
16008    (use (match_operand:SI 3 "immediate_operand" "i"))
16009    (use (reg:CC FLAGS_REG))
16010    (clobber (match_operand:P 0 "register_operand" "=S"))
16011    (clobber (match_operand:P 1 "register_operand" "=D"))
16012    (clobber (match_operand:P 2 "register_operand" "=c"))]
16013   ""
16014   "repz{%;} cmpsb"
16015   [(set_attr "type" "str")
16016    (set_attr "mode" "QI")
16017    (set (attr "prefix_rex")
16018         (if_then_else
16019           (ne (symbol_ref "<P:MODE>mode == DImode") (const_int 0))
16020           (const_string "0")
16021           (const_string "*")))
16022    (set_attr "prefix_rep" "1")])
16023
16024 (define_expand "strlen<mode>"
16025   [(set (match_operand:SWI48x 0 "register_operand" "")
16026         (unspec:SWI48x [(match_operand:BLK 1 "general_operand" "")
16027                         (match_operand:QI 2 "immediate_operand" "")
16028                         (match_operand 3 "immediate_operand" "")]
16029                        UNSPEC_SCAS))]
16030   ""
16031 {
16032  if (ix86_expand_strlen (operands[0], operands[1], operands[2], operands[3]))
16033    DONE;
16034  else
16035    FAIL;
16036 })
16037
16038 (define_expand "strlenqi_1"
16039   [(parallel [(set (match_operand 0 "register_operand" "")
16040                    (match_operand 2 "" ""))
16041               (clobber (match_operand 1 "register_operand" ""))
16042               (clobber (reg:CC FLAGS_REG))])]
16043   ""
16044   "ix86_current_function_needs_cld = 1;")
16045
16046 (define_insn "*strlenqi_1"
16047   [(set (match_operand:P 0 "register_operand" "=&c")
16048         (unspec:P [(mem:BLK (match_operand:P 5 "register_operand" "1"))
16049                    (match_operand:QI 2 "register_operand" "a")
16050                    (match_operand:P 3 "immediate_operand" "i")
16051                    (match_operand:P 4 "register_operand" "0")] UNSPEC_SCAS))
16052    (clobber (match_operand:P 1 "register_operand" "=D"))
16053    (clobber (reg:CC FLAGS_REG))]
16054   ""
16055   "repnz{%;} scasb"
16056   [(set_attr "type" "str")
16057    (set_attr "mode" "QI")
16058    (set (attr "prefix_rex")
16059         (if_then_else
16060           (ne (symbol_ref "<P:MODE>mode == DImode") (const_int 0))
16061           (const_string "0")
16062           (const_string "*")))
16063    (set_attr "prefix_rep" "1")])
16064
16065 ;; Peephole optimizations to clean up after cmpstrn*.  This should be
16066 ;; handled in combine, but it is not currently up to the task.
16067 ;; When used for their truth value, the cmpstrn* expanders generate
16068 ;; code like this:
16069 ;;
16070 ;;   repz cmpsb
16071 ;;   seta       %al
16072 ;;   setb       %dl
16073 ;;   cmpb       %al, %dl
16074 ;;   jcc        label
16075 ;;
16076 ;; The intermediate three instructions are unnecessary.
16077
16078 ;; This one handles cmpstrn*_nz_1...
16079 (define_peephole2
16080   [(parallel[
16081      (set (reg:CC FLAGS_REG)
16082           (compare:CC (mem:BLK (match_operand 4 "register_operand" ""))
16083                       (mem:BLK (match_operand 5 "register_operand" ""))))
16084      (use (match_operand 6 "register_operand" ""))
16085      (use (match_operand:SI 3 "immediate_operand" ""))
16086      (clobber (match_operand 0 "register_operand" ""))
16087      (clobber (match_operand 1 "register_operand" ""))
16088      (clobber (match_operand 2 "register_operand" ""))])
16089    (set (match_operand:QI 7 "register_operand" "")
16090         (gtu:QI (reg:CC FLAGS_REG) (const_int 0)))
16091    (set (match_operand:QI 8 "register_operand" "")
16092         (ltu:QI (reg:CC FLAGS_REG) (const_int 0)))
16093    (set (reg FLAGS_REG)
16094         (compare (match_dup 7) (match_dup 8)))
16095   ]
16096   "peep2_reg_dead_p (4, operands[7]) && peep2_reg_dead_p (4, operands[8])"
16097   [(parallel[
16098      (set (reg:CC FLAGS_REG)
16099           (compare:CC (mem:BLK (match_dup 4))
16100                       (mem:BLK (match_dup 5))))
16101      (use (match_dup 6))
16102      (use (match_dup 3))
16103      (clobber (match_dup 0))
16104      (clobber (match_dup 1))
16105      (clobber (match_dup 2))])])
16106
16107 ;; ...and this one handles cmpstrn*_1.
16108 (define_peephole2
16109   [(parallel[
16110      (set (reg:CC FLAGS_REG)
16111           (if_then_else:CC (ne (match_operand 6 "register_operand" "")
16112                                (const_int 0))
16113             (compare:CC (mem:BLK (match_operand 4 "register_operand" ""))
16114                         (mem:BLK (match_operand 5 "register_operand" "")))
16115             (const_int 0)))
16116      (use (match_operand:SI 3 "immediate_operand" ""))
16117      (use (reg:CC FLAGS_REG))
16118      (clobber (match_operand 0 "register_operand" ""))
16119      (clobber (match_operand 1 "register_operand" ""))
16120      (clobber (match_operand 2 "register_operand" ""))])
16121    (set (match_operand:QI 7 "register_operand" "")
16122         (gtu:QI (reg:CC FLAGS_REG) (const_int 0)))
16123    (set (match_operand:QI 8 "register_operand" "")
16124         (ltu:QI (reg:CC FLAGS_REG) (const_int 0)))
16125    (set (reg FLAGS_REG)
16126         (compare (match_dup 7) (match_dup 8)))
16127   ]
16128   "peep2_reg_dead_p (4, operands[7]) && peep2_reg_dead_p (4, operands[8])"
16129   [(parallel[
16130      (set (reg:CC FLAGS_REG)
16131           (if_then_else:CC (ne (match_dup 6)
16132                                (const_int 0))
16133             (compare:CC (mem:BLK (match_dup 4))
16134                         (mem:BLK (match_dup 5)))
16135             (const_int 0)))
16136      (use (match_dup 3))
16137      (use (reg:CC FLAGS_REG))
16138      (clobber (match_dup 0))
16139      (clobber (match_dup 1))
16140      (clobber (match_dup 2))])])
16141 \f
16142 ;; Conditional move instructions.
16143
16144 (define_expand "mov<mode>cc"
16145   [(set (match_operand:SWIM 0 "register_operand" "")
16146         (if_then_else:SWIM (match_operand 1 "ordered_comparison_operator" "")
16147                            (match_operand:SWIM 2 "general_operand" "")
16148                            (match_operand:SWIM 3 "general_operand" "")))]
16149   ""
16150   "if (ix86_expand_int_movcc (operands)) DONE; else FAIL;")
16151
16152 ;; Data flow gets confused by our desire for `sbbl reg,reg', and clearing
16153 ;; the register first winds up with `sbbl $0,reg', which is also weird.
16154 ;; So just document what we're doing explicitly.
16155
16156 (define_expand "x86_mov<mode>cc_0_m1"
16157   [(parallel
16158     [(set (match_operand:SWI48 0 "register_operand" "")
16159           (if_then_else:SWI48
16160             (match_operator:SWI48 2 "ix86_carry_flag_operator"
16161              [(match_operand 1 "flags_reg_operand" "")
16162               (const_int 0)])
16163             (const_int -1)
16164             (const_int 0)))
16165      (clobber (reg:CC FLAGS_REG))])])
16166
16167 (define_insn "*x86_mov<mode>cc_0_m1"
16168   [(set (match_operand:SWI48 0 "register_operand" "=r")
16169         (if_then_else:SWI48 (match_operator 1 "ix86_carry_flag_operator"
16170                              [(reg FLAGS_REG) (const_int 0)])
16171           (const_int -1)
16172           (const_int 0)))
16173    (clobber (reg:CC FLAGS_REG))]
16174   ""
16175   "sbb{<imodesuffix>}\t%0, %0"
16176   ; Since we don't have the proper number of operands for an alu insn,
16177   ; fill in all the blanks.
16178   [(set_attr "type" "alu")
16179    (set_attr "use_carry" "1")
16180    (set_attr "pent_pair" "pu")
16181    (set_attr "memory" "none")
16182    (set_attr "imm_disp" "false")
16183    (set_attr "mode" "<MODE>")
16184    (set_attr "length_immediate" "0")])
16185
16186 (define_insn "*x86_mov<mode>cc_0_m1_se"
16187   [(set (match_operand:SWI48 0 "register_operand" "=r")
16188         (sign_extract:SWI48 (match_operator 1 "ix86_carry_flag_operator"
16189                              [(reg FLAGS_REG) (const_int 0)])
16190                             (const_int 1)
16191                             (const_int 0)))
16192    (clobber (reg:CC FLAGS_REG))]
16193   ""
16194   "sbb{<imodesuffix>}\t%0, %0"
16195   [(set_attr "type" "alu")
16196    (set_attr "use_carry" "1")
16197    (set_attr "pent_pair" "pu")
16198    (set_attr "memory" "none")
16199    (set_attr "imm_disp" "false")
16200    (set_attr "mode" "<MODE>")
16201    (set_attr "length_immediate" "0")])
16202
16203 (define_insn "*x86_mov<mode>cc_0_m1_neg"
16204   [(set (match_operand:SWI48 0 "register_operand" "=r")
16205         (neg:SWI48 (match_operator 1 "ix86_carry_flag_operator"
16206                     [(reg FLAGS_REG) (const_int 0)])))]
16207   ""
16208   "sbb{<imodesuffix>}\t%0, %0"
16209   [(set_attr "type" "alu")
16210    (set_attr "use_carry" "1")
16211    (set_attr "pent_pair" "pu")
16212    (set_attr "memory" "none")
16213    (set_attr "imm_disp" "false")
16214    (set_attr "mode" "<MODE>")
16215    (set_attr "length_immediate" "0")])
16216
16217 (define_insn "*mov<mode>cc_noc"
16218   [(set (match_operand:SWI248 0 "register_operand" "=r,r")
16219         (if_then_else:SWI248 (match_operator 1 "ix86_comparison_operator"
16220                                [(reg FLAGS_REG) (const_int 0)])
16221           (match_operand:SWI248 2 "nonimmediate_operand" "rm,0")
16222           (match_operand:SWI248 3 "nonimmediate_operand" "0,rm")))]
16223   "TARGET_CMOVE && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
16224   "@
16225    cmov%O2%C1\t{%2, %0|%0, %2}
16226    cmov%O2%c1\t{%3, %0|%0, %3}"
16227   [(set_attr "type" "icmov")
16228    (set_attr "mode" "<MODE>")])
16229
16230 (define_insn_and_split "*movqicc_noc"
16231   [(set (match_operand:QI 0 "register_operand" "=r,r")
16232         (if_then_else:QI (match_operator 1 "ix86_comparison_operator"
16233                            [(match_operand 4 "flags_reg_operand" "")
16234                             (const_int 0)])
16235                       (match_operand:QI 2 "register_operand" "r,0")
16236                       (match_operand:QI 3 "register_operand" "0,r")))]
16237   "TARGET_CMOVE && !TARGET_PARTIAL_REG_STALL"
16238   "#"
16239   "&& reload_completed"
16240   [(set (match_dup 0)
16241         (if_then_else:SI (match_op_dup 1 [(match_dup 4) (const_int 0)])
16242                       (match_dup 2)
16243                       (match_dup 3)))]
16244   "operands[0] = gen_lowpart (SImode, operands[0]);
16245    operands[2] = gen_lowpart (SImode, operands[2]);
16246    operands[3] = gen_lowpart (SImode, operands[3]);"
16247   [(set_attr "type" "icmov")
16248    (set_attr "mode" "SI")])
16249
16250 (define_expand "mov<mode>cc"
16251   [(set (match_operand:X87MODEF 0 "register_operand" "")
16252         (if_then_else:X87MODEF
16253           (match_operand 1 "ix86_fp_comparison_operator" "")
16254           (match_operand:X87MODEF 2 "register_operand" "")
16255           (match_operand:X87MODEF 3 "register_operand" "")))]
16256   "(TARGET_80387 && TARGET_CMOVE)
16257    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
16258   "if (ix86_expand_fp_movcc (operands)) DONE; else FAIL;")
16259
16260 (define_insn "*movxfcc_1"
16261   [(set (match_operand:XF 0 "register_operand" "=f,f")
16262         (if_then_else:XF (match_operator 1 "fcmov_comparison_operator"
16263                                 [(reg FLAGS_REG) (const_int 0)])
16264                       (match_operand:XF 2 "register_operand" "f,0")
16265                       (match_operand:XF 3 "register_operand" "0,f")))]
16266   "TARGET_80387 && TARGET_CMOVE"
16267   "@
16268    fcmov%F1\t{%2, %0|%0, %2}
16269    fcmov%f1\t{%3, %0|%0, %3}"
16270   [(set_attr "type" "fcmov")
16271    (set_attr "mode" "XF")])
16272
16273 (define_insn "*movdfcc_1_rex64"
16274   [(set (match_operand:DF 0 "register_operand" "=f,f,r,r")
16275         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator"
16276                                 [(reg FLAGS_REG) (const_int 0)])
16277                       (match_operand:DF 2 "nonimmediate_operand" "f,0,rm,0")
16278                       (match_operand:DF 3 "nonimmediate_operand" "0,f,0,rm")))]
16279   "TARGET_64BIT && TARGET_80387 && TARGET_CMOVE
16280    && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
16281   "@
16282    fcmov%F1\t{%2, %0|%0, %2}
16283    fcmov%f1\t{%3, %0|%0, %3}
16284    cmov%O2%C1\t{%2, %0|%0, %2}
16285    cmov%O2%c1\t{%3, %0|%0, %3}"
16286   [(set_attr "type" "fcmov,fcmov,icmov,icmov")
16287    (set_attr "mode" "DF,DF,DI,DI")])
16288
16289 (define_insn "*movdfcc_1"
16290   [(set (match_operand:DF 0 "register_operand" "=f,f,&r,&r")
16291         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator"
16292                                 [(reg FLAGS_REG) (const_int 0)])
16293                       (match_operand:DF 2 "nonimmediate_operand" "f,0,rm,0")
16294                       (match_operand:DF 3 "nonimmediate_operand" "0,f,0,rm")))]
16295   "!TARGET_64BIT && TARGET_80387 && TARGET_CMOVE
16296    && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
16297   "@
16298    fcmov%F1\t{%2, %0|%0, %2}
16299    fcmov%f1\t{%3, %0|%0, %3}
16300    #
16301    #"
16302   [(set_attr "type" "fcmov,fcmov,multi,multi")
16303    (set_attr "mode" "DF,DF,DI,DI")])
16304
16305 (define_split
16306   [(set (match_operand:DF 0 "register_and_not_any_fp_reg_operand" "")
16307         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator"
16308                                 [(match_operand 4 "flags_reg_operand" "")
16309                                  (const_int 0)])
16310                       (match_operand:DF 2 "nonimmediate_operand" "")
16311                       (match_operand:DF 3 "nonimmediate_operand" "")))]
16312   "!TARGET_64BIT && reload_completed"
16313   [(set (match_dup 2)
16314         (if_then_else:SI (match_op_dup 1 [(match_dup 4) (const_int 0)])
16315                       (match_dup 5)
16316                       (match_dup 6)))
16317    (set (match_dup 3)
16318         (if_then_else:SI (match_op_dup 1 [(match_dup 4) (const_int 0)])
16319                       (match_dup 7)
16320                       (match_dup 8)))]
16321 {
16322   split_double_mode (DImode, &operands[2], 2, &operands[5], &operands[7]);
16323   split_double_mode (DImode, &operands[0], 1, &operands[2], &operands[3]);
16324 })
16325
16326 (define_insn "*movsfcc_1_387"
16327   [(set (match_operand:SF 0 "register_operand" "=f,f,r,r")
16328         (if_then_else:SF (match_operator 1 "fcmov_comparison_operator"
16329                                 [(reg FLAGS_REG) (const_int 0)])
16330                       (match_operand:SF 2 "nonimmediate_operand" "f,0,rm,0")
16331                       (match_operand:SF 3 "nonimmediate_operand" "0,f,0,rm")))]
16332   "TARGET_80387 && TARGET_CMOVE
16333    && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
16334   "@
16335    fcmov%F1\t{%2, %0|%0, %2}
16336    fcmov%f1\t{%3, %0|%0, %3}
16337    cmov%O2%C1\t{%2, %0|%0, %2}
16338    cmov%O2%c1\t{%3, %0|%0, %3}"
16339   [(set_attr "type" "fcmov,fcmov,icmov,icmov")
16340    (set_attr "mode" "SF,SF,SI,SI")])
16341
16342 ;; All moves in XOP pcmov instructions are 128 bits and hence we restrict
16343 ;; the scalar versions to have only XMM registers as operands.
16344
16345 ;; XOP conditional move
16346 (define_insn "*xop_pcmov_<mode>"
16347   [(set (match_operand:MODEF 0 "register_operand" "=x")
16348         (if_then_else:MODEF
16349           (match_operand:MODEF 1 "register_operand" "x")
16350           (match_operand:MODEF 2 "register_operand" "x")
16351           (match_operand:MODEF 3 "register_operand" "x")))]
16352   "TARGET_XOP"
16353   "vpcmov\t{%1, %3, %2, %0|%0, %2, %3, %1}"
16354   [(set_attr "type" "sse4arg")])
16355
16356 ;; These versions of the min/max patterns are intentionally ignorant of
16357 ;; their behavior wrt -0.0 and NaN (via the commutative operand mark).
16358 ;; Since both the tree-level MAX_EXPR and the rtl-level SMAX operator
16359 ;; are undefined in this condition, we're certain this is correct.
16360
16361 (define_insn "<code><mode>3"
16362   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
16363         (smaxmin:MODEF
16364           (match_operand:MODEF 1 "nonimmediate_operand" "%0,x")
16365           (match_operand:MODEF 2 "nonimmediate_operand" "xm,xm")))]
16366   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
16367   "@
16368    <maxmin_float><ssemodesuffix>\t{%2, %0|%0, %2}
16369    v<maxmin_float><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
16370   [(set_attr "isa" "noavx,avx")
16371    (set_attr "prefix" "orig,vex")
16372    (set_attr "type" "sseadd")
16373    (set_attr "mode" "<MODE>")])
16374
16375 ;; These versions of the min/max patterns implement exactly the operations
16376 ;;   min = (op1 < op2 ? op1 : op2)
16377 ;;   max = (!(op1 < op2) ? op1 : op2)
16378 ;; Their operands are not commutative, and thus they may be used in the
16379 ;; presence of -0.0 and NaN.
16380
16381 (define_insn "*ieee_smin<mode>3"
16382   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
16383         (unspec:MODEF
16384           [(match_operand:MODEF 1 "register_operand" "0,x")
16385            (match_operand:MODEF 2 "nonimmediate_operand" "xm,xm")]
16386          UNSPEC_IEEE_MIN))]
16387   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
16388   "@
16389    min<ssemodesuffix>\t{%2, %0|%0, %2}
16390    vmin<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
16391   [(set_attr "isa" "noavx,avx")
16392    (set_attr "prefix" "orig,vex")
16393    (set_attr "type" "sseadd")
16394    (set_attr "mode" "<MODE>")])
16395
16396 (define_insn "*ieee_smax<mode>3"
16397   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
16398         (unspec:MODEF
16399           [(match_operand:MODEF 1 "register_operand" "0,x")
16400            (match_operand:MODEF 2 "nonimmediate_operand" "xm,xm")]
16401          UNSPEC_IEEE_MAX))]
16402   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
16403   "@
16404    max<ssemodesuffix>\t{%2, %0|%0, %2}
16405    vmax<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
16406   [(set_attr "isa" "noavx,avx")
16407    (set_attr "prefix" "orig,vex")
16408    (set_attr "type" "sseadd")
16409    (set_attr "mode" "<MODE>")])
16410
16411 ;; Make two stack loads independent:
16412 ;;   fld aa              fld aa
16413 ;;   fld %st(0)     ->   fld bb
16414 ;;   fmul bb             fmul %st(1), %st
16415 ;;
16416 ;; Actually we only match the last two instructions for simplicity.
16417 (define_peephole2
16418   [(set (match_operand 0 "fp_register_operand" "")
16419         (match_operand 1 "fp_register_operand" ""))
16420    (set (match_dup 0)
16421         (match_operator 2 "binary_fp_operator"
16422            [(match_dup 0)
16423             (match_operand 3 "memory_operand" "")]))]
16424   "REGNO (operands[0]) != REGNO (operands[1])"
16425   [(set (match_dup 0) (match_dup 3))
16426    (set (match_dup 0) (match_dup 4))]
16427
16428   ;; The % modifier is not operational anymore in peephole2's, so we have to
16429   ;; swap the operands manually in the case of addition and multiplication.
16430   "if (COMMUTATIVE_ARITH_P (operands[2]))
16431      operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[2]),
16432                                    GET_MODE (operands[2]),
16433                                    operands[0], operands[1]);
16434    else
16435      operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[2]),
16436                                    GET_MODE (operands[2]),
16437                                    operands[1], operands[0]);")
16438
16439 ;; Conditional addition patterns
16440 (define_expand "add<mode>cc"
16441   [(match_operand:SWI 0 "register_operand" "")
16442    (match_operand 1 "ordered_comparison_operator" "")
16443    (match_operand:SWI 2 "register_operand" "")
16444    (match_operand:SWI 3 "const_int_operand" "")]
16445   ""
16446   "if (ix86_expand_int_addcc (operands)) DONE; else FAIL;")
16447 \f
16448 ;; Misc patterns (?)
16449
16450 ;; This pattern exists to put a dependency on all ebp-based memory accesses.
16451 ;; Otherwise there will be nothing to keep
16452 ;;
16453 ;; [(set (reg ebp) (reg esp))]
16454 ;; [(set (reg esp) (plus (reg esp) (const_int -160000)))
16455 ;;  (clobber (eflags)]
16456 ;; [(set (mem (plus (reg ebp) (const_int -160000))) (const_int 0))]
16457 ;;
16458 ;; in proper program order.
16459
16460 (define_insn "pro_epilogue_adjust_stack_<mode>_add"
16461   [(set (match_operand:P 0 "register_operand" "=r,r")
16462         (plus:P (match_operand:P 1 "register_operand" "0,r")
16463                 (match_operand:P 2 "<nonmemory_operand>" "r<i>,l<i>")))
16464    (clobber (reg:CC FLAGS_REG))
16465    (clobber (mem:BLK (scratch)))]
16466   ""
16467 {
16468   switch (get_attr_type (insn))
16469     {
16470     case TYPE_IMOV:
16471       return "mov{<imodesuffix>}\t{%1, %0|%0, %1}";
16472
16473     case TYPE_ALU:
16474       gcc_assert (rtx_equal_p (operands[0], operands[1]));
16475       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
16476         return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
16477
16478       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
16479
16480     default:
16481       operands[2] = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
16482       return "lea{<imodesuffix>}\t{%a2, %0|%0, %a2}";
16483     }
16484 }
16485   [(set (attr "type")
16486         (cond [(and (eq_attr "alternative" "0")
16487                     (eq (symbol_ref "TARGET_OPT_AGU") (const_int 0)))
16488                  (const_string "alu")
16489                (match_operand:<MODE> 2 "const0_operand" "")
16490                  (const_string "imov")
16491               ]
16492               (const_string "lea")))
16493    (set (attr "length_immediate")
16494         (cond [(eq_attr "type" "imov")
16495                  (const_string "0")
16496                (and (eq_attr "type" "alu")
16497                     (match_operand 2 "const128_operand" ""))
16498                  (const_string "1")
16499               ]
16500               (const_string "*")))
16501    (set_attr "mode" "<MODE>")])
16502
16503 (define_insn "pro_epilogue_adjust_stack_<mode>_sub"
16504   [(set (match_operand:P 0 "register_operand" "=r")
16505         (minus:P (match_operand:P 1 "register_operand" "0")
16506                  (match_operand:P 2 "register_operand" "r")))
16507    (clobber (reg:CC FLAGS_REG))
16508    (clobber (mem:BLK (scratch)))]
16509   ""
16510   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
16511   [(set_attr "type" "alu")
16512    (set_attr "mode" "<MODE>")])
16513
16514 (define_insn "allocate_stack_worker_probe_<mode>"
16515   [(set (match_operand:P 0 "register_operand" "=a")
16516         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")]
16517                             UNSPECV_STACK_PROBE))
16518    (clobber (reg:CC FLAGS_REG))]
16519   "ix86_target_stack_probe ()"
16520   "call\t___chkstk_ms"
16521   [(set_attr "type" "multi")
16522    (set_attr "length" "5")])
16523
16524 (define_expand "allocate_stack"
16525   [(match_operand 0 "register_operand" "")
16526    (match_operand 1 "general_operand" "")]
16527   "ix86_target_stack_probe ()"
16528 {
16529   rtx x;
16530
16531 #ifndef CHECK_STACK_LIMIT
16532 #define CHECK_STACK_LIMIT 0
16533 #endif
16534
16535   if (CHECK_STACK_LIMIT && CONST_INT_P (operands[1])
16536       && INTVAL (operands[1]) < CHECK_STACK_LIMIT)
16537     {
16538       x = expand_simple_binop (Pmode, MINUS, stack_pointer_rtx, operands[1],
16539                                stack_pointer_rtx, 0, OPTAB_DIRECT);
16540       if (x != stack_pointer_rtx)
16541         emit_move_insn (stack_pointer_rtx, x);
16542     }
16543   else
16544     {
16545       x = copy_to_mode_reg (Pmode, operands[1]);
16546       if (TARGET_64BIT)
16547         emit_insn (gen_allocate_stack_worker_probe_di (x, x));
16548       else
16549         emit_insn (gen_allocate_stack_worker_probe_si (x, x));
16550       x = expand_simple_binop (Pmode, MINUS, stack_pointer_rtx, x,
16551                                stack_pointer_rtx, 0, OPTAB_DIRECT);
16552       if (x != stack_pointer_rtx)
16553         emit_move_insn (stack_pointer_rtx, x);
16554     }
16555
16556   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
16557   DONE;
16558 })
16559
16560 ;; Use IOR for stack probes, this is shorter.
16561 (define_expand "probe_stack"
16562   [(match_operand 0 "memory_operand" "")]
16563   ""
16564 {
16565   rtx (*gen_ior3) (rtx, rtx, rtx);
16566
16567   gen_ior3 = (GET_MODE (operands[0]) == DImode
16568               ? gen_iordi3 : gen_iorsi3);
16569
16570   emit_insn (gen_ior3 (operands[0], operands[0], const0_rtx));
16571   DONE;
16572 })
16573
16574 (define_insn "adjust_stack_and_probe<mode>"
16575   [(set (match_operand:P 0 "register_operand" "=r")
16576         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")]
16577                             UNSPECV_PROBE_STACK_RANGE))
16578    (set (reg:P SP_REG)
16579         (minus:P (reg:P SP_REG) (match_operand:P 2 "const_int_operand" "n")))
16580    (clobber (reg:CC FLAGS_REG))
16581    (clobber (mem:BLK (scratch)))]
16582   ""
16583   "* return output_adjust_stack_and_probe (operands[0]);"
16584   [(set_attr "type" "multi")])
16585
16586 (define_insn "probe_stack_range<mode>"
16587   [(set (match_operand:P 0 "register_operand" "=r")
16588         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
16589                             (match_operand:P 2 "const_int_operand" "n")]
16590                             UNSPECV_PROBE_STACK_RANGE))
16591    (clobber (reg:CC FLAGS_REG))]
16592   ""
16593   "* return output_probe_stack_range (operands[0], operands[2]);"
16594   [(set_attr "type" "multi")])
16595
16596 (define_expand "builtin_setjmp_receiver"
16597   [(label_ref (match_operand 0 "" ""))]
16598   "!TARGET_64BIT && flag_pic"
16599 {
16600 #if TARGET_MACHO
16601   if (TARGET_MACHO)
16602     {
16603       rtx xops[3];
16604       rtx picreg = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
16605       rtx label_rtx = gen_label_rtx ();
16606       emit_insn (gen_set_got_labelled (pic_offset_table_rtx, label_rtx));
16607       xops[0] = xops[1] = picreg;
16608       xops[2] = machopic_gen_offset (gen_rtx_LABEL_REF (SImode, label_rtx));
16609       ix86_expand_binary_operator (MINUS, SImode, xops);
16610     }
16611   else
16612 #endif
16613     emit_insn (gen_set_got (pic_offset_table_rtx));
16614   DONE;
16615 })
16616 \f
16617 ;; Avoid redundant prefixes by splitting HImode arithmetic to SImode.
16618
16619 (define_split
16620   [(set (match_operand 0 "register_operand" "")
16621         (match_operator 3 "promotable_binary_operator"
16622            [(match_operand 1 "register_operand" "")
16623             (match_operand 2 "aligned_operand" "")]))
16624    (clobber (reg:CC FLAGS_REG))]
16625   "! TARGET_PARTIAL_REG_STALL && reload_completed
16626    && ((GET_MODE (operands[0]) == HImode
16627         && ((optimize_function_for_speed_p (cfun) && !TARGET_FAST_PREFIX)
16628             /* ??? next two lines just !satisfies_constraint_K (...) */
16629             || !CONST_INT_P (operands[2])
16630             || satisfies_constraint_K (operands[2])))
16631        || (GET_MODE (operands[0]) == QImode
16632            && (TARGET_PROMOTE_QImode || optimize_function_for_size_p (cfun))))"
16633   [(parallel [(set (match_dup 0)
16634                    (match_op_dup 3 [(match_dup 1) (match_dup 2)]))
16635               (clobber (reg:CC FLAGS_REG))])]
16636   "operands[0] = gen_lowpart (SImode, operands[0]);
16637    operands[1] = gen_lowpart (SImode, operands[1]);
16638    if (GET_CODE (operands[3]) != ASHIFT)
16639      operands[2] = gen_lowpart (SImode, operands[2]);
16640    PUT_MODE (operands[3], SImode);")
16641
16642 ; Promote the QImode tests, as i386 has encoding of the AND
16643 ; instruction with 32-bit sign-extended immediate and thus the
16644 ; instruction size is unchanged, except in the %eax case for
16645 ; which it is increased by one byte, hence the ! optimize_size.
16646 (define_split
16647   [(set (match_operand 0 "flags_reg_operand" "")
16648         (match_operator 2 "compare_operator"
16649           [(and (match_operand 3 "aligned_operand" "")
16650                 (match_operand 4 "const_int_operand" ""))
16651            (const_int 0)]))
16652    (set (match_operand 1 "register_operand" "")
16653         (and (match_dup 3) (match_dup 4)))]
16654   "! TARGET_PARTIAL_REG_STALL && reload_completed
16655    && optimize_insn_for_speed_p ()
16656    && ((GET_MODE (operands[1]) == HImode && ! TARGET_FAST_PREFIX)
16657        || (GET_MODE (operands[1]) == QImode && TARGET_PROMOTE_QImode))
16658    /* Ensure that the operand will remain sign-extended immediate.  */
16659    && ix86_match_ccmode (insn, INTVAL (operands[4]) >= 0 ? CCNOmode : CCZmode)"
16660   [(parallel [(set (match_dup 0)
16661                    (match_op_dup 2 [(and:SI (match_dup 3) (match_dup 4))
16662                                     (const_int 0)]))
16663               (set (match_dup 1)
16664                    (and:SI (match_dup 3) (match_dup 4)))])]
16665 {
16666   operands[4]
16667     = gen_int_mode (INTVAL (operands[4])
16668                     & GET_MODE_MASK (GET_MODE (operands[1])), SImode);
16669   operands[1] = gen_lowpart (SImode, operands[1]);
16670   operands[3] = gen_lowpart (SImode, operands[3]);
16671 })
16672
16673 ; Don't promote the QImode tests, as i386 doesn't have encoding of
16674 ; the TEST instruction with 32-bit sign-extended immediate and thus
16675 ; the instruction size would at least double, which is not what we
16676 ; want even with ! optimize_size.
16677 (define_split
16678   [(set (match_operand 0 "flags_reg_operand" "")
16679         (match_operator 1 "compare_operator"
16680           [(and (match_operand:HI 2 "aligned_operand" "")
16681                 (match_operand:HI 3 "const_int_operand" ""))
16682            (const_int 0)]))]
16683   "! TARGET_PARTIAL_REG_STALL && reload_completed
16684    && ! TARGET_FAST_PREFIX
16685    && optimize_insn_for_speed_p ()
16686    /* Ensure that the operand will remain sign-extended immediate.  */
16687    && ix86_match_ccmode (insn, INTVAL (operands[3]) >= 0 ? CCNOmode : CCZmode)"
16688   [(set (match_dup 0)
16689         (match_op_dup 1 [(and:SI (match_dup 2) (match_dup 3))
16690                          (const_int 0)]))]
16691 {
16692   operands[3]
16693     = gen_int_mode (INTVAL (operands[3])
16694                     & GET_MODE_MASK (GET_MODE (operands[2])), SImode);
16695   operands[2] = gen_lowpart (SImode, operands[2]);
16696 })
16697
16698 (define_split
16699   [(set (match_operand 0 "register_operand" "")
16700         (neg (match_operand 1 "register_operand" "")))
16701    (clobber (reg:CC FLAGS_REG))]
16702   "! TARGET_PARTIAL_REG_STALL && reload_completed
16703    && (GET_MODE (operands[0]) == HImode
16704        || (GET_MODE (operands[0]) == QImode
16705            && (TARGET_PROMOTE_QImode
16706                || optimize_insn_for_size_p ())))"
16707   [(parallel [(set (match_dup 0)
16708                    (neg:SI (match_dup 1)))
16709               (clobber (reg:CC FLAGS_REG))])]
16710   "operands[0] = gen_lowpart (SImode, operands[0]);
16711    operands[1] = gen_lowpart (SImode, operands[1]);")
16712
16713 (define_split
16714   [(set (match_operand 0 "register_operand" "")
16715         (not (match_operand 1 "register_operand" "")))]
16716   "! TARGET_PARTIAL_REG_STALL && reload_completed
16717    && (GET_MODE (operands[0]) == HImode
16718        || (GET_MODE (operands[0]) == QImode
16719            && (TARGET_PROMOTE_QImode
16720                || optimize_insn_for_size_p ())))"
16721   [(set (match_dup 0)
16722         (not:SI (match_dup 1)))]
16723   "operands[0] = gen_lowpart (SImode, operands[0]);
16724    operands[1] = gen_lowpart (SImode, operands[1]);")
16725
16726 (define_split
16727   [(set (match_operand 0 "register_operand" "")
16728         (if_then_else (match_operator 1 "ordered_comparison_operator"
16729                                 [(reg FLAGS_REG) (const_int 0)])
16730                       (match_operand 2 "register_operand" "")
16731                       (match_operand 3 "register_operand" "")))]
16732   "! TARGET_PARTIAL_REG_STALL && TARGET_CMOVE
16733    && (GET_MODE (operands[0]) == HImode
16734        || (GET_MODE (operands[0]) == QImode
16735            && (TARGET_PROMOTE_QImode
16736                || optimize_insn_for_size_p ())))"
16737   [(set (match_dup 0)
16738         (if_then_else:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
16739   "operands[0] = gen_lowpart (SImode, operands[0]);
16740    operands[2] = gen_lowpart (SImode, operands[2]);
16741    operands[3] = gen_lowpart (SImode, operands[3]);")
16742 \f
16743 ;; RTL Peephole optimizations, run before sched2.  These primarily look to
16744 ;; transform a complex memory operation into two memory to register operations.
16745
16746 ;; Don't push memory operands
16747 (define_peephole2
16748   [(set (match_operand:SWI 0 "push_operand" "")
16749         (match_operand:SWI 1 "memory_operand" ""))
16750    (match_scratch:SWI 2 "<r>")]
16751   "optimize_insn_for_speed_p () && !TARGET_PUSH_MEMORY
16752    && !RTX_FRAME_RELATED_P (peep2_next_insn (0))"
16753   [(set (match_dup 2) (match_dup 1))
16754    (set (match_dup 0) (match_dup 2))])
16755
16756 ;; We need to handle SFmode only, because DFmode and XFmode are split to
16757 ;; SImode pushes.
16758 (define_peephole2
16759   [(set (match_operand:SF 0 "push_operand" "")
16760         (match_operand:SF 1 "memory_operand" ""))
16761    (match_scratch:SF 2 "r")]
16762   "optimize_insn_for_speed_p () && !TARGET_PUSH_MEMORY
16763    && !RTX_FRAME_RELATED_P (peep2_next_insn (0))"
16764   [(set (match_dup 2) (match_dup 1))
16765    (set (match_dup 0) (match_dup 2))])
16766
16767 ;; Don't move an immediate directly to memory when the instruction
16768 ;; gets too big.
16769 (define_peephole2
16770   [(match_scratch:SWI124 1 "<r>")
16771    (set (match_operand:SWI124 0 "memory_operand" "")
16772         (const_int 0))]
16773   "optimize_insn_for_speed_p ()
16774    && !TARGET_USE_MOV0
16775    && TARGET_SPLIT_LONG_MOVES
16776    && get_attr_length (insn) >= ix86_cur_cost ()->large_insn
16777    && peep2_regno_dead_p (0, FLAGS_REG)"
16778   [(parallel [(set (match_dup 2) (const_int 0))
16779               (clobber (reg:CC FLAGS_REG))])
16780    (set (match_dup 0) (match_dup 1))]
16781   "operands[2] = gen_lowpart (SImode, operands[1]);")
16782
16783 (define_peephole2
16784   [(match_scratch:SWI124 2 "<r>")
16785    (set (match_operand:SWI124 0 "memory_operand" "")
16786         (match_operand:SWI124 1 "immediate_operand" ""))]
16787   "optimize_insn_for_speed_p ()
16788    && TARGET_SPLIT_LONG_MOVES
16789    && get_attr_length (insn) >= ix86_cur_cost ()->large_insn"
16790   [(set (match_dup 2) (match_dup 1))
16791    (set (match_dup 0) (match_dup 2))])
16792
16793 ;; Don't compare memory with zero, load and use a test instead.
16794 (define_peephole2
16795   [(set (match_operand 0 "flags_reg_operand" "")
16796         (match_operator 1 "compare_operator"
16797           [(match_operand:SI 2 "memory_operand" "")
16798            (const_int 0)]))
16799    (match_scratch:SI 3 "r")]
16800   "optimize_insn_for_speed_p () && ix86_match_ccmode (insn, CCNOmode)"
16801   [(set (match_dup 3) (match_dup 2))
16802    (set (match_dup 0) (match_op_dup 1 [(match_dup 3) (const_int 0)]))])
16803
16804 ;; NOT is not pairable on Pentium, while XOR is, but one byte longer.
16805 ;; Don't split NOTs with a displacement operand, because resulting XOR
16806 ;; will not be pairable anyway.
16807 ;;
16808 ;; On AMD K6, NOT is vector decoded with memory operand that cannot be
16809 ;; represented using a modRM byte.  The XOR replacement is long decoded,
16810 ;; so this split helps here as well.
16811 ;;
16812 ;; Note: Can't do this as a regular split because we can't get proper
16813 ;; lifetime information then.
16814
16815 (define_peephole2
16816   [(set (match_operand:SWI124 0 "nonimmediate_operand" "")
16817         (not:SWI124 (match_operand:SWI124 1 "nonimmediate_operand" "")))]
16818   "optimize_insn_for_speed_p ()
16819    && ((TARGET_NOT_UNPAIRABLE
16820         && (!MEM_P (operands[0])
16821             || !memory_displacement_operand (operands[0], <MODE>mode)))
16822        || (TARGET_NOT_VECTORMODE
16823            && long_memory_operand (operands[0], <MODE>mode)))
16824    && peep2_regno_dead_p (0, FLAGS_REG)"
16825   [(parallel [(set (match_dup 0)
16826                    (xor:SWI124 (match_dup 1) (const_int -1)))
16827               (clobber (reg:CC FLAGS_REG))])])
16828
16829 ;; Non pairable "test imm, reg" instructions can be translated to
16830 ;; "and imm, reg" if reg dies.  The "and" form is also shorter (one
16831 ;; byte opcode instead of two, have a short form for byte operands),
16832 ;; so do it for other CPUs as well.  Given that the value was dead,
16833 ;; this should not create any new dependencies.  Pass on the sub-word
16834 ;; versions if we're concerned about partial register stalls.
16835
16836 (define_peephole2
16837   [(set (match_operand 0 "flags_reg_operand" "")
16838         (match_operator 1 "compare_operator"
16839           [(and:SI (match_operand:SI 2 "register_operand" "")
16840                    (match_operand:SI 3 "immediate_operand" ""))
16841            (const_int 0)]))]
16842   "ix86_match_ccmode (insn, CCNOmode)
16843    && (true_regnum (operands[2]) != AX_REG
16844        || satisfies_constraint_K (operands[3]))
16845    && peep2_reg_dead_p (1, operands[2])"
16846   [(parallel
16847      [(set (match_dup 0)
16848            (match_op_dup 1 [(and:SI (match_dup 2) (match_dup 3))
16849                             (const_int 0)]))
16850       (set (match_dup 2)
16851            (and:SI (match_dup 2) (match_dup 3)))])])
16852
16853 ;; We don't need to handle HImode case, because it will be promoted to SImode
16854 ;; on ! TARGET_PARTIAL_REG_STALL
16855
16856 (define_peephole2
16857   [(set (match_operand 0 "flags_reg_operand" "")
16858         (match_operator 1 "compare_operator"
16859           [(and:QI (match_operand:QI 2 "register_operand" "")
16860                    (match_operand:QI 3 "immediate_operand" ""))
16861            (const_int 0)]))]
16862   "! TARGET_PARTIAL_REG_STALL
16863    && ix86_match_ccmode (insn, CCNOmode)
16864    && true_regnum (operands[2]) != AX_REG
16865    && peep2_reg_dead_p (1, operands[2])"
16866   [(parallel
16867      [(set (match_dup 0)
16868            (match_op_dup 1 [(and:QI (match_dup 2) (match_dup 3))
16869                             (const_int 0)]))
16870       (set (match_dup 2)
16871            (and:QI (match_dup 2) (match_dup 3)))])])
16872
16873 (define_peephole2
16874   [(set (match_operand 0 "flags_reg_operand" "")
16875         (match_operator 1 "compare_operator"
16876           [(and:SI
16877              (zero_extract:SI
16878                (match_operand 2 "ext_register_operand" "")
16879                (const_int 8)
16880                (const_int 8))
16881              (match_operand 3 "const_int_operand" ""))
16882            (const_int 0)]))]
16883   "! TARGET_PARTIAL_REG_STALL
16884    && ix86_match_ccmode (insn, CCNOmode)
16885    && true_regnum (operands[2]) != AX_REG
16886    && peep2_reg_dead_p (1, operands[2])"
16887   [(parallel [(set (match_dup 0)
16888                    (match_op_dup 1
16889                      [(and:SI
16890                         (zero_extract:SI
16891                           (match_dup 2)
16892                           (const_int 8)
16893                           (const_int 8))
16894                         (match_dup 3))
16895                       (const_int 0)]))
16896               (set (zero_extract:SI (match_dup 2)
16897                                     (const_int 8)
16898                                     (const_int 8))
16899                    (and:SI
16900                      (zero_extract:SI
16901                        (match_dup 2)
16902                        (const_int 8)
16903                        (const_int 8))
16904                      (match_dup 3)))])])
16905
16906 ;; Don't do logical operations with memory inputs.
16907 (define_peephole2
16908   [(match_scratch:SI 2 "r")
16909    (parallel [(set (match_operand:SI 0 "register_operand" "")
16910                    (match_operator:SI 3 "arith_or_logical_operator"
16911                      [(match_dup 0)
16912                       (match_operand:SI 1 "memory_operand" "")]))
16913               (clobber (reg:CC FLAGS_REG))])]
16914   "optimize_insn_for_speed_p () && ! TARGET_READ_MODIFY"
16915   [(set (match_dup 2) (match_dup 1))
16916    (parallel [(set (match_dup 0)
16917                    (match_op_dup 3 [(match_dup 0) (match_dup 2)]))
16918               (clobber (reg:CC FLAGS_REG))])])
16919
16920 (define_peephole2
16921   [(match_scratch:SI 2 "r")
16922    (parallel [(set (match_operand:SI 0 "register_operand" "")
16923                    (match_operator:SI 3 "arith_or_logical_operator"
16924                      [(match_operand:SI 1 "memory_operand" "")
16925                       (match_dup 0)]))
16926               (clobber (reg:CC FLAGS_REG))])]
16927   "optimize_insn_for_speed_p () && ! TARGET_READ_MODIFY"
16928   [(set (match_dup 2) (match_dup 1))
16929    (parallel [(set (match_dup 0)
16930                    (match_op_dup 3 [(match_dup 2) (match_dup 0)]))
16931               (clobber (reg:CC FLAGS_REG))])])
16932
16933 ;; Prefer Load+RegOp to Mov+MemOp.  Watch out for cases when the memory address
16934 ;; refers to the destination of the load!
16935
16936 (define_peephole2
16937   [(set (match_operand:SI 0 "register_operand" "")
16938         (match_operand:SI 1 "register_operand" ""))
16939    (parallel [(set (match_dup 0)
16940                    (match_operator:SI 3 "commutative_operator"
16941                      [(match_dup 0)
16942                       (match_operand:SI 2 "memory_operand" "")]))
16943               (clobber (reg:CC FLAGS_REG))])]
16944   "REGNO (operands[0]) != REGNO (operands[1])
16945    && GENERAL_REGNO_P (REGNO (operands[0]))
16946    && GENERAL_REGNO_P (REGNO (operands[1]))"
16947   [(set (match_dup 0) (match_dup 4))
16948    (parallel [(set (match_dup 0)
16949                    (match_op_dup 3 [(match_dup 0) (match_dup 1)]))
16950               (clobber (reg:CC FLAGS_REG))])]
16951   "operands[4] = replace_rtx (operands[2], operands[0], operands[1]);")
16952
16953 (define_peephole2
16954   [(set (match_operand 0 "register_operand" "")
16955         (match_operand 1 "register_operand" ""))
16956    (set (match_dup 0)
16957                    (match_operator 3 "commutative_operator"
16958                      [(match_dup 0)
16959                       (match_operand 2 "memory_operand" "")]))]
16960   "REGNO (operands[0]) != REGNO (operands[1])
16961    && ((MMX_REG_P (operands[0]) && MMX_REG_P (operands[1])) 
16962        || (SSE_REG_P (operands[0]) && SSE_REG_P (operands[1])))"
16963   [(set (match_dup 0) (match_dup 2))
16964    (set (match_dup 0)
16965         (match_op_dup 3 [(match_dup 0) (match_dup 1)]))])
16966
16967 ; Don't do logical operations with memory outputs
16968 ;
16969 ; These two don't make sense for PPro/PII -- we're expanding a 4-uop
16970 ; instruction into two 1-uop insns plus a 2-uop insn.  That last has
16971 ; the same decoder scheduling characteristics as the original.
16972
16973 (define_peephole2
16974   [(match_scratch:SI 2 "r")
16975    (parallel [(set (match_operand:SI 0 "memory_operand" "")
16976                    (match_operator:SI 3 "arith_or_logical_operator"
16977                      [(match_dup 0)
16978                       (match_operand:SI 1 "nonmemory_operand" "")]))
16979               (clobber (reg:CC FLAGS_REG))])]
16980   "optimize_insn_for_speed_p () && ! TARGET_READ_MODIFY_WRITE
16981    /* Do not split stack checking probes.  */
16982    && GET_CODE (operands[3]) != IOR && operands[1] != const0_rtx"
16983   [(set (match_dup 2) (match_dup 0))
16984    (parallel [(set (match_dup 2)
16985                    (match_op_dup 3 [(match_dup 2) (match_dup 1)]))
16986               (clobber (reg:CC FLAGS_REG))])
16987    (set (match_dup 0) (match_dup 2))])
16988
16989 (define_peephole2
16990   [(match_scratch:SI 2 "r")
16991    (parallel [(set (match_operand:SI 0 "memory_operand" "")
16992                    (match_operator:SI 3 "arith_or_logical_operator"
16993                      [(match_operand:SI 1 "nonmemory_operand" "")
16994                       (match_dup 0)]))
16995               (clobber (reg:CC FLAGS_REG))])]
16996   "optimize_insn_for_speed_p () && ! TARGET_READ_MODIFY_WRITE
16997    /* Do not split stack checking probes.  */
16998    && GET_CODE (operands[3]) != IOR && operands[1] != const0_rtx"
16999   [(set (match_dup 2) (match_dup 0))
17000    (parallel [(set (match_dup 2)
17001                    (match_op_dup 3 [(match_dup 1) (match_dup 2)]))
17002               (clobber (reg:CC FLAGS_REG))])
17003    (set (match_dup 0) (match_dup 2))])
17004
17005 ;; Attempt to always use XOR for zeroing registers.
17006 (define_peephole2
17007   [(set (match_operand 0 "register_operand" "")
17008         (match_operand 1 "const0_operand" ""))]
17009   "GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
17010    && (! TARGET_USE_MOV0 || optimize_insn_for_size_p ())
17011    && GENERAL_REG_P (operands[0])
17012    && peep2_regno_dead_p (0, FLAGS_REG)"
17013   [(parallel [(set (match_dup 0) (const_int 0))
17014               (clobber (reg:CC FLAGS_REG))])]
17015   "operands[0] = gen_lowpart (word_mode, operands[0]);")
17016
17017 (define_peephole2
17018   [(set (strict_low_part (match_operand 0 "register_operand" ""))
17019         (const_int 0))]
17020   "(GET_MODE (operands[0]) == QImode
17021     || GET_MODE (operands[0]) == HImode)
17022    && (! TARGET_USE_MOV0 || optimize_insn_for_size_p ())
17023    && peep2_regno_dead_p (0, FLAGS_REG)"
17024   [(parallel [(set (strict_low_part (match_dup 0)) (const_int 0))
17025               (clobber (reg:CC FLAGS_REG))])])
17026
17027 ;; For HI, SI and DI modes, or $-1,reg is smaller than mov $-1,reg.
17028 (define_peephole2
17029   [(set (match_operand:SWI248 0 "register_operand" "")
17030         (const_int -1))]
17031   "(optimize_insn_for_size_p () || TARGET_MOVE_M1_VIA_OR)
17032    && peep2_regno_dead_p (0, FLAGS_REG)"
17033   [(parallel [(set (match_dup 0) (const_int -1))
17034               (clobber (reg:CC FLAGS_REG))])]
17035 {
17036   if (GET_MODE_SIZE (<MODE>mode) < GET_MODE_SIZE (SImode))
17037     operands[0] = gen_lowpart (SImode, operands[0]);
17038 })
17039
17040 ;; Attempt to convert simple lea to add/shift.
17041 ;; These can be created by move expanders.
17042
17043 (define_peephole2
17044   [(set (match_operand:SWI48 0 "register_operand" "")
17045         (plus:SWI48 (match_dup 0)
17046                     (match_operand:SWI48 1 "<nonmemory_operand>" "")))]
17047   "peep2_regno_dead_p (0, FLAGS_REG)"
17048   [(parallel [(set (match_dup 0) (plus:SWI48 (match_dup 0) (match_dup 1)))
17049               (clobber (reg:CC FLAGS_REG))])])
17050
17051 (define_peephole2
17052   [(set (match_operand:SI 0 "register_operand" "")
17053         (subreg:SI (plus:DI (match_operand:DI 1 "register_operand" "")
17054                             (match_operand:DI 2 "nonmemory_operand" "")) 0))]
17055   "TARGET_64BIT
17056    && peep2_regno_dead_p (0, FLAGS_REG)
17057    && REGNO (operands[0]) == REGNO (operands[1])"
17058   [(parallel [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))
17059               (clobber (reg:CC FLAGS_REG))])]
17060   "operands[2] = gen_lowpart (SImode, operands[2]);")
17061
17062 (define_peephole2
17063   [(set (match_operand:SWI48 0 "register_operand" "")
17064         (mult:SWI48 (match_dup 0)
17065                     (match_operand:SWI48 1 "const_int_operand" "")))]
17066   "exact_log2 (INTVAL (operands[1])) >= 0
17067    && peep2_regno_dead_p (0, FLAGS_REG)"
17068   [(parallel [(set (match_dup 0) (ashift:SWI48 (match_dup 0) (match_dup 2)))
17069               (clobber (reg:CC FLAGS_REG))])]
17070   "operands[2] = GEN_INT (exact_log2 (INTVAL (operands[1])));")
17071
17072 (define_peephole2
17073   [(set (match_operand:SI 0 "register_operand" "")
17074         (subreg:SI (mult:DI (match_operand:DI 1 "register_operand" "")
17075                    (match_operand:DI 2 "const_int_operand" "")) 0))]
17076   "TARGET_64BIT
17077    && exact_log2 (INTVAL (operands[2])) >= 0
17078    && REGNO (operands[0]) == REGNO (operands[1])
17079    && peep2_regno_dead_p (0, FLAGS_REG)"
17080   [(parallel [(set (match_dup 0) (ashift:SI (match_dup 0) (match_dup 2)))
17081               (clobber (reg:CC FLAGS_REG))])]
17082   "operands[2] = GEN_INT (exact_log2 (INTVAL (operands[2])));")
17083
17084 ;; The ESP adjustments can be done by the push and pop instructions.  Resulting
17085 ;; code is shorter, since push is only 1 byte, while add imm, %esp is 3 bytes.
17086 ;; On many CPUs it is also faster, since special hardware to avoid esp
17087 ;; dependencies is present.
17088
17089 ;; While some of these conversions may be done using splitters, we use
17090 ;; peepholes in order to allow combine_stack_adjustments pass to see
17091 ;; nonobfuscated RTL.
17092
17093 ;; Convert prologue esp subtractions to push.
17094 ;; We need register to push.  In order to keep verify_flow_info happy we have
17095 ;; two choices
17096 ;; - use scratch and clobber it in order to avoid dependencies
17097 ;; - use already live register
17098 ;; We can't use the second way right now, since there is no reliable way how to
17099 ;; verify that given register is live.  First choice will also most likely in
17100 ;; fewer dependencies.  On the place of esp adjustments it is very likely that
17101 ;; call clobbered registers are dead.  We may want to use base pointer as an
17102 ;; alternative when no register is available later.
17103
17104 (define_peephole2
17105   [(match_scratch:P 1 "r")
17106    (parallel [(set (reg:P SP_REG)
17107                    (plus:P (reg:P SP_REG)
17108                            (match_operand:P 0 "const_int_operand" "")))
17109               (clobber (reg:CC FLAGS_REG))
17110               (clobber (mem:BLK (scratch)))])]
17111   "(TARGET_SINGLE_PUSH || optimize_insn_for_size_p ())
17112    && INTVAL (operands[0]) == -GET_MODE_SIZE (Pmode)"
17113   [(clobber (match_dup 1))
17114    (parallel [(set (mem:P (pre_dec:P (reg:P SP_REG))) (match_dup 1))
17115               (clobber (mem:BLK (scratch)))])])
17116
17117 (define_peephole2
17118   [(match_scratch:P 1 "r")
17119    (parallel [(set (reg:P SP_REG)
17120                    (plus:P (reg:P SP_REG)
17121                            (match_operand:P 0 "const_int_operand" "")))
17122               (clobber (reg:CC FLAGS_REG))
17123               (clobber (mem:BLK (scratch)))])]
17124   "(TARGET_DOUBLE_PUSH || optimize_insn_for_size_p ())
17125    && INTVAL (operands[0]) == -2*GET_MODE_SIZE (Pmode)"
17126   [(clobber (match_dup 1))
17127    (set (mem:P (pre_dec:P (reg:P SP_REG))) (match_dup 1))
17128    (parallel [(set (mem:P (pre_dec:P (reg:P SP_REG))) (match_dup 1))
17129               (clobber (mem:BLK (scratch)))])])
17130
17131 ;; Convert esp subtractions to push.
17132 (define_peephole2
17133   [(match_scratch:P 1 "r")
17134    (parallel [(set (reg:P SP_REG)
17135                    (plus:P (reg:P SP_REG)
17136                            (match_operand:P 0 "const_int_operand" "")))
17137               (clobber (reg:CC FLAGS_REG))])]
17138   "(TARGET_SINGLE_PUSH || optimize_insn_for_size_p ())
17139    && INTVAL (operands[0]) == -GET_MODE_SIZE (Pmode)"
17140   [(clobber (match_dup 1))
17141    (set (mem:P (pre_dec:P (reg:P SP_REG))) (match_dup 1))])
17142
17143 (define_peephole2
17144   [(match_scratch:P 1 "r")
17145    (parallel [(set (reg:P SP_REG)
17146                    (plus:P (reg:P SP_REG)
17147                            (match_operand:P 0 "const_int_operand" "")))
17148               (clobber (reg:CC FLAGS_REG))])]
17149   "(TARGET_DOUBLE_PUSH || optimize_insn_for_size_p ())
17150    && INTVAL (operands[0]) == -2*GET_MODE_SIZE (Pmode)"
17151   [(clobber (match_dup 1))
17152    (set (mem:P (pre_dec:P (reg:P SP_REG))) (match_dup 1))
17153    (set (mem:P (pre_dec:P (reg:P SP_REG))) (match_dup 1))])
17154
17155 ;; Convert epilogue deallocator to pop.
17156 (define_peephole2
17157   [(match_scratch:P 1 "r")
17158    (parallel [(set (reg:P SP_REG)
17159                    (plus:P (reg:P SP_REG)
17160                            (match_operand:P 0 "const_int_operand" "")))
17161               (clobber (reg:CC FLAGS_REG))
17162               (clobber (mem:BLK (scratch)))])]
17163   "(TARGET_SINGLE_POP || optimize_insn_for_size_p ())
17164    && INTVAL (operands[0]) == GET_MODE_SIZE (Pmode)"
17165   [(parallel [(set (match_dup 1) (mem:P (post_inc:P (reg:P SP_REG))))
17166               (clobber (mem:BLK (scratch)))])])
17167
17168 ;; Two pops case is tricky, since pop causes dependency
17169 ;; on destination register.  We use two registers if available.
17170 (define_peephole2
17171   [(match_scratch:P 1 "r")
17172    (match_scratch:P 2 "r")
17173    (parallel [(set (reg:P SP_REG)
17174                    (plus:P (reg:P SP_REG)
17175                            (match_operand:P 0 "const_int_operand" "")))
17176               (clobber (reg:CC FLAGS_REG))
17177               (clobber (mem:BLK (scratch)))])]
17178   "(TARGET_DOUBLE_POP || optimize_insn_for_size_p ())
17179    && INTVAL (operands[0]) == 2*GET_MODE_SIZE (Pmode)"
17180   [(parallel [(set (match_dup 1) (mem:P (post_inc:P (reg:P SP_REG))))
17181               (clobber (mem:BLK (scratch)))])
17182    (set (match_dup 2) (mem:P (post_inc:P (reg:P SP_REG))))])
17183
17184 (define_peephole2
17185   [(match_scratch:P 1 "r")
17186    (parallel [(set (reg:P SP_REG)
17187                    (plus:P (reg:P SP_REG)
17188                            (match_operand:P 0 "const_int_operand" "")))
17189               (clobber (reg:CC FLAGS_REG))
17190               (clobber (mem:BLK (scratch)))])]
17191   "optimize_insn_for_size_p ()
17192    && INTVAL (operands[0]) == 2*GET_MODE_SIZE (Pmode)"
17193   [(parallel [(set (match_dup 1) (mem:P (post_inc:P (reg:P SP_REG))))
17194               (clobber (mem:BLK (scratch)))])
17195    (set (match_dup 1) (mem:P (post_inc:P (reg:P SP_REG))))])
17196
17197 ;; Convert esp additions to pop.
17198 (define_peephole2
17199   [(match_scratch:P 1 "r")
17200    (parallel [(set (reg:P SP_REG)
17201                    (plus:P (reg:P SP_REG)
17202                            (match_operand:P 0 "const_int_operand" "")))
17203               (clobber (reg:CC FLAGS_REG))])]
17204   "INTVAL (operands[0]) == GET_MODE_SIZE (Pmode)"
17205   [(set (match_dup 1) (mem:P (post_inc:P (reg:P SP_REG))))])
17206
17207 ;; Two pops case is tricky, since pop causes dependency
17208 ;; on destination register.  We use two registers if available.
17209 (define_peephole2
17210   [(match_scratch:P 1 "r")
17211    (match_scratch:P 2 "r")
17212    (parallel [(set (reg:P SP_REG)
17213                    (plus:P (reg:P SP_REG)
17214                            (match_operand:P 0 "const_int_operand" "")))
17215               (clobber (reg:CC FLAGS_REG))])]
17216   "INTVAL (operands[0]) == 2*GET_MODE_SIZE (Pmode)"
17217   [(set (match_dup 1) (mem:P (post_inc:P (reg:P SP_REG))))
17218    (set (match_dup 2) (mem:P (post_inc:P (reg:P SP_REG))))])
17219
17220 (define_peephole2
17221   [(match_scratch:P 1 "r")
17222    (parallel [(set (reg:P SP_REG)
17223                    (plus:P (reg:P SP_REG)
17224                            (match_operand:P 0 "const_int_operand" "")))
17225               (clobber (reg:CC FLAGS_REG))])]
17226   "optimize_insn_for_size_p ()
17227    && INTVAL (operands[0]) == 2*GET_MODE_SIZE (Pmode)"
17228   [(set (match_dup 1) (mem:P (post_inc:P (reg:P SP_REG))))
17229    (set (match_dup 1) (mem:P (post_inc:P (reg:P SP_REG))))])
17230 \f
17231 ;; Convert compares with 1 to shorter inc/dec operations when CF is not
17232 ;; required and register dies.  Similarly for 128 to -128.
17233 (define_peephole2
17234   [(set (match_operand 0 "flags_reg_operand" "")
17235         (match_operator 1 "compare_operator"
17236           [(match_operand 2 "register_operand" "")
17237            (match_operand 3 "const_int_operand" "")]))]
17238   "(((!TARGET_FUSE_CMP_AND_BRANCH || optimize_insn_for_size_p ())
17239      && incdec_operand (operands[3], GET_MODE (operands[3])))
17240     || (!TARGET_FUSE_CMP_AND_BRANCH
17241         && INTVAL (operands[3]) == 128))
17242    && ix86_match_ccmode (insn, CCGCmode)
17243    && peep2_reg_dead_p (1, operands[2])"
17244   [(parallel [(set (match_dup 0)
17245                    (match_op_dup 1 [(match_dup 2) (match_dup 3)]))
17246               (clobber (match_dup 2))])])
17247 \f
17248 ;; Convert imul by three, five and nine into lea
17249 (define_peephole2
17250   [(parallel
17251     [(set (match_operand:SWI48 0 "register_operand" "")
17252           (mult:SWI48 (match_operand:SWI48 1 "register_operand" "")
17253                       (match_operand:SWI48 2 "const_int_operand" "")))
17254      (clobber (reg:CC FLAGS_REG))])]
17255   "INTVAL (operands[2]) == 3
17256    || INTVAL (operands[2]) == 5
17257    || INTVAL (operands[2]) == 9"
17258   [(set (match_dup 0)
17259         (plus:SWI48 (mult:SWI48 (match_dup 1) (match_dup 2))
17260                     (match_dup 1)))]
17261   "operands[2] = GEN_INT (INTVAL (operands[2]) - 1);")
17262
17263 (define_peephole2
17264   [(parallel
17265     [(set (match_operand:SWI48 0 "register_operand" "")
17266           (mult:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "")
17267                       (match_operand:SWI48 2 "const_int_operand" "")))
17268      (clobber (reg:CC FLAGS_REG))])]
17269   "optimize_insn_for_speed_p ()
17270    && (INTVAL (operands[2]) == 3
17271        || INTVAL (operands[2]) == 5
17272        || INTVAL (operands[2]) == 9)"
17273   [(set (match_dup 0) (match_dup 1))
17274    (set (match_dup 0)
17275         (plus:SWI48 (mult:SWI48 (match_dup 0) (match_dup 2))
17276                     (match_dup 0)))]
17277   "operands[2] = GEN_INT (INTVAL (operands[2]) - 1);")
17278
17279 ;; imul $32bit_imm, mem, reg is vector decoded, while
17280 ;; imul $32bit_imm, reg, reg is direct decoded.
17281 (define_peephole2
17282   [(match_scratch:SWI48 3 "r")
17283    (parallel [(set (match_operand:SWI48 0 "register_operand" "")
17284                    (mult:SWI48 (match_operand:SWI48 1 "memory_operand" "")
17285                                (match_operand:SWI48 2 "immediate_operand" "")))
17286               (clobber (reg:CC FLAGS_REG))])]
17287   "TARGET_SLOW_IMUL_IMM32_MEM && optimize_insn_for_speed_p ()
17288    && !satisfies_constraint_K (operands[2])"
17289   [(set (match_dup 3) (match_dup 1))
17290    (parallel [(set (match_dup 0) (mult:SWI48 (match_dup 3) (match_dup 2)))
17291               (clobber (reg:CC FLAGS_REG))])])
17292
17293 (define_peephole2
17294   [(match_scratch:SI 3 "r")
17295    (parallel [(set (match_operand:DI 0 "register_operand" "")
17296                    (zero_extend:DI
17297                      (mult:SI (match_operand:SI 1 "memory_operand" "")
17298                               (match_operand:SI 2 "immediate_operand" ""))))
17299               (clobber (reg:CC FLAGS_REG))])]
17300   "TARGET_64BIT
17301    && TARGET_SLOW_IMUL_IMM32_MEM && optimize_insn_for_speed_p ()
17302    && !satisfies_constraint_K (operands[2])"
17303   [(set (match_dup 3) (match_dup 1))
17304    (parallel [(set (match_dup 0)
17305                    (zero_extend:DI (mult:SI (match_dup 3) (match_dup 2))))
17306               (clobber (reg:CC FLAGS_REG))])])
17307
17308 ;; imul $8/16bit_imm, regmem, reg is vector decoded.
17309 ;; Convert it into imul reg, reg
17310 ;; It would be better to force assembler to encode instruction using long
17311 ;; immediate, but there is apparently no way to do so.
17312 (define_peephole2
17313   [(parallel [(set (match_operand:SWI248 0 "register_operand" "")
17314                    (mult:SWI248
17315                     (match_operand:SWI248 1 "nonimmediate_operand" "")
17316                     (match_operand:SWI248 2 "const_int_operand" "")))
17317               (clobber (reg:CC FLAGS_REG))])
17318    (match_scratch:SWI248 3 "r")]
17319   "TARGET_SLOW_IMUL_IMM8 && optimize_insn_for_speed_p ()
17320    && satisfies_constraint_K (operands[2])"
17321   [(set (match_dup 3) (match_dup 2))
17322    (parallel [(set (match_dup 0) (mult:SWI248 (match_dup 0) (match_dup 3)))
17323               (clobber (reg:CC FLAGS_REG))])]
17324 {
17325   if (!rtx_equal_p (operands[0], operands[1]))
17326     emit_move_insn (operands[0], operands[1]);
17327 })
17328
17329 ;; After splitting up read-modify operations, array accesses with memory
17330 ;; operands might end up in form:
17331 ;;  sall    $2, %eax
17332 ;;  movl    4(%esp), %edx
17333 ;;  addl    %edx, %eax
17334 ;; instead of pre-splitting:
17335 ;;  sall    $2, %eax
17336 ;;  addl    4(%esp), %eax
17337 ;; Turn it into:
17338 ;;  movl    4(%esp), %edx
17339 ;;  leal    (%edx,%eax,4), %eax
17340
17341 (define_peephole2
17342   [(match_scratch:P 5 "r")
17343    (parallel [(set (match_operand 0 "register_operand" "")
17344                    (ashift (match_operand 1 "register_operand" "")
17345                            (match_operand 2 "const_int_operand" "")))
17346                (clobber (reg:CC FLAGS_REG))])
17347    (parallel [(set (match_operand 3 "register_operand" "")
17348                    (plus (match_dup 0)
17349                          (match_operand 4 "x86_64_general_operand" "")))
17350                    (clobber (reg:CC FLAGS_REG))])]
17351   "IN_RANGE (INTVAL (operands[2]), 1, 3)
17352    /* Validate MODE for lea.  */
17353    && ((!TARGET_PARTIAL_REG_STALL
17354         && (GET_MODE (operands[0]) == QImode
17355             || GET_MODE (operands[0]) == HImode))
17356        || GET_MODE (operands[0]) == SImode
17357        || (TARGET_64BIT && GET_MODE (operands[0]) == DImode))
17358    && (rtx_equal_p (operands[0], operands[3])
17359        || peep2_reg_dead_p (2, operands[0]))
17360    /* We reorder load and the shift.  */
17361    && !reg_overlap_mentioned_p (operands[0], operands[4])"
17362   [(set (match_dup 5) (match_dup 4))
17363    (set (match_dup 0) (match_dup 1))]
17364 {
17365   enum machine_mode op1mode = GET_MODE (operands[1]);
17366   enum machine_mode mode = op1mode == DImode ? DImode : SImode;
17367   int scale = 1 << INTVAL (operands[2]);
17368   rtx index = gen_lowpart (Pmode, operands[1]);
17369   rtx base = gen_lowpart (Pmode, operands[5]);
17370   rtx dest = gen_lowpart (mode, operands[3]);
17371
17372   operands[1] = gen_rtx_PLUS (Pmode, base,
17373                               gen_rtx_MULT (Pmode, index, GEN_INT (scale)));
17374   operands[5] = base;
17375   if (mode != Pmode)
17376     operands[1] = gen_rtx_SUBREG (mode, operands[1], 0);
17377   if (op1mode != Pmode)
17378     operands[5] = gen_rtx_SUBREG (op1mode, operands[5], 0);
17379   operands[0] = dest;
17380 })
17381 \f
17382 ;; Call-value patterns last so that the wildcard operand does not
17383 ;; disrupt insn-recog's switch tables.
17384
17385 (define_insn_and_split "*call_value_pop_0_vzeroupper"
17386   [(parallel
17387     [(set (match_operand 0 "" "")
17388           (call (mem:QI (match_operand:SI 1 "constant_call_address_operand" ""))
17389                 (match_operand:SI 2 "" "")))
17390      (set (reg:SI SP_REG)
17391           (plus:SI (reg:SI SP_REG)
17392                    (match_operand:SI 3 "immediate_operand" "")))])
17393    (unspec [(match_operand 4 "const_int_operand" "")]
17394            UNSPEC_CALL_NEEDS_VZEROUPPER)]
17395   "TARGET_VZEROUPPER && !TARGET_64BIT"
17396   "#"
17397   "&& reload_completed"
17398   [(const_int 0)]
17399   "ix86_split_call_vzeroupper (curr_insn, operands[4]); DONE;"
17400   [(set_attr "type" "callv")])
17401
17402 (define_insn "*call_value_pop_0"
17403   [(set (match_operand 0 "" "")
17404         (call (mem:QI (match_operand:SI 1 "constant_call_address_operand" ""))
17405               (match_operand:SI 2 "" "")))
17406    (set (reg:SI SP_REG)
17407         (plus:SI (reg:SI SP_REG)
17408                  (match_operand:SI 3 "immediate_operand" "")))]
17409   "!TARGET_64BIT"
17410   { return ix86_output_call_insn (insn, operands[1], 1); }
17411   [(set_attr "type" "callv")])
17412
17413 (define_insn_and_split "*call_value_pop_1_vzeroupper"
17414   [(parallel
17415     [(set (match_operand 0 "" "")
17416           (call (mem:QI (match_operand:SI 1 "call_insn_operand" "lsm"))
17417                 (match_operand:SI 2 "" "")))
17418      (set (reg:SI SP_REG)
17419           (plus:SI (reg:SI SP_REG)
17420                    (match_operand:SI 3 "immediate_operand" "i")))])
17421    (unspec [(match_operand 4 "const_int_operand" "")]
17422            UNSPEC_CALL_NEEDS_VZEROUPPER)]
17423   "TARGET_VZEROUPPER && !TARGET_64BIT && !SIBLING_CALL_P (insn)"
17424   "#"
17425   "&& reload_completed"
17426   [(const_int 0)]
17427   "ix86_split_call_vzeroupper (curr_insn, operands[4]); DONE;"
17428   [(set_attr "type" "callv")])
17429
17430 (define_insn "*call_value_pop_1"
17431   [(set (match_operand 0 "" "")
17432         (call (mem:QI (match_operand:SI 1 "call_insn_operand" "lsm"))
17433               (match_operand:SI 2 "" "")))
17434    (set (reg:SI SP_REG)
17435         (plus:SI (reg:SI SP_REG)
17436                  (match_operand:SI 3 "immediate_operand" "i")))]
17437   "!TARGET_64BIT && !SIBLING_CALL_P (insn)"
17438   { return ix86_output_call_insn (insn, operands[1], 1); }
17439   [(set_attr "type" "callv")])
17440
17441 (define_insn_and_split "*sibcall_value_pop_1_vzeroupper"
17442  [(parallel
17443    [(set (match_operand 0 "" "")
17444           (call (mem:QI (match_operand:SI 1 "sibcall_insn_operand" "s,U"))
17445                 (match_operand:SI 2 "" "")))
17446      (set (reg:SI SP_REG)
17447           (plus:SI (reg:SI SP_REG)
17448                    (match_operand:SI 3 "immediate_operand" "i,i")))])
17449    (unspec [(match_operand 4 "const_int_operand" "")]
17450            UNSPEC_CALL_NEEDS_VZEROUPPER)]
17451   "TARGET_VZEROUPPER && !TARGET_64BIT && SIBLING_CALL_P (insn)"
17452   "#"
17453   "&& reload_completed"
17454   [(const_int 0)]
17455   "ix86_split_call_vzeroupper (curr_insn, operands[4]); DONE;"
17456   [(set_attr "type" "callv")])
17457
17458 (define_insn "*sibcall_value_pop_1"
17459   [(set (match_operand 0 "" "")
17460         (call (mem:QI (match_operand:SI 1 "sibcall_insn_operand" "s,U"))
17461               (match_operand:SI 2 "" "")))
17462    (set (reg:SI SP_REG)
17463         (plus:SI (reg:SI SP_REG)
17464                  (match_operand:SI 3 "immediate_operand" "i,i")))]
17465   "!TARGET_64BIT && SIBLING_CALL_P (insn)"
17466   { return ix86_output_call_insn (insn, operands[1], 1); }
17467   [(set_attr "type" "callv")])
17468
17469 (define_insn_and_split "*call_value_0_vzeroupper"
17470   [(set (match_operand 0 "" "")
17471         (call (mem:QI (match_operand:SI 1 "constant_call_address_operand" ""))
17472               (match_operand:SI 2 "" "")))
17473    (unspec [(match_operand 3 "const_int_operand" "")]
17474            UNSPEC_CALL_NEEDS_VZEROUPPER)]
17475   "TARGET_VZEROUPPER && !TARGET_64BIT"
17476   "#"
17477   "&& reload_completed"
17478   [(const_int 0)]
17479   "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
17480   [(set_attr "type" "callv")])
17481
17482 (define_insn "*call_value_0"
17483   [(set (match_operand 0 "" "")
17484         (call (mem:QI (match_operand:SI 1 "constant_call_address_operand" ""))
17485               (match_operand:SI 2 "" "")))]
17486   "!TARGET_64BIT"
17487   { return ix86_output_call_insn (insn, operands[1], 1); }
17488   [(set_attr "type" "callv")])
17489
17490 (define_insn_and_split "*call_value_0_rex64_vzeroupper"
17491   [(set (match_operand 0 "" "")
17492         (call (mem:QI (match_operand:DI 1 "constant_call_address_operand" ""))
17493               (match_operand:DI 2 "const_int_operand" "")))
17494    (unspec [(match_operand 3 "const_int_operand" "")]
17495            UNSPEC_CALL_NEEDS_VZEROUPPER)]
17496   "TARGET_VZEROUPPER && TARGET_64BIT"
17497   "#"
17498   "&& reload_completed"
17499   [(const_int 0)]
17500   "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
17501   [(set_attr "type" "callv")])
17502
17503 (define_insn "*call_value_0_rex64"
17504   [(set (match_operand 0 "" "")
17505         (call (mem:QI (match_operand:DI 1 "constant_call_address_operand" ""))
17506               (match_operand:DI 2 "const_int_operand" "")))]
17507   "TARGET_64BIT"
17508   { return ix86_output_call_insn (insn, operands[1], 1); }
17509   [(set_attr "type" "callv")])
17510
17511 (define_insn_and_split "*call_value_0_rex64_ms_sysv_vzeroupper"
17512   [(parallel
17513     [(set (match_operand 0 "" "")
17514           (call (mem:QI (match_operand:DI 1 "constant_call_address_operand" ""))
17515                 (match_operand:DI 2 "const_int_operand" "")))
17516      (unspec [(const_int 0)] UNSPEC_MS_TO_SYSV_CALL)
17517      (clobber (reg:TI XMM6_REG))
17518      (clobber (reg:TI XMM7_REG))
17519      (clobber (reg:TI XMM8_REG))
17520      (clobber (reg:TI XMM9_REG))
17521      (clobber (reg:TI XMM10_REG))
17522      (clobber (reg:TI XMM11_REG))
17523      (clobber (reg:TI XMM12_REG))
17524      (clobber (reg:TI XMM13_REG))
17525      (clobber (reg:TI XMM14_REG))
17526      (clobber (reg:TI XMM15_REG))
17527      (clobber (reg:DI SI_REG))
17528      (clobber (reg:DI DI_REG))])
17529    (unspec [(match_operand 3 "const_int_operand" "")]
17530            UNSPEC_CALL_NEEDS_VZEROUPPER)]
17531   "TARGET_VZEROUPPER && TARGET_64BIT && !SIBLING_CALL_P (insn)"
17532   "#"
17533   "&& reload_completed"
17534   [(const_int 0)]
17535   "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
17536   [(set_attr "type" "callv")])
17537
17538 (define_insn "*call_value_0_rex64_ms_sysv"
17539   [(set (match_operand 0 "" "")
17540         (call (mem:QI (match_operand:DI 1 "constant_call_address_operand" ""))
17541               (match_operand:DI 2 "const_int_operand" "")))
17542    (unspec [(const_int 0)] UNSPEC_MS_TO_SYSV_CALL)
17543    (clobber (reg:TI XMM6_REG))
17544    (clobber (reg:TI XMM7_REG))
17545    (clobber (reg:TI XMM8_REG))
17546    (clobber (reg:TI XMM9_REG))
17547    (clobber (reg:TI XMM10_REG))
17548    (clobber (reg:TI XMM11_REG))
17549    (clobber (reg:TI XMM12_REG))
17550    (clobber (reg:TI XMM13_REG))
17551    (clobber (reg:TI XMM14_REG))
17552    (clobber (reg:TI XMM15_REG))
17553    (clobber (reg:DI SI_REG))
17554    (clobber (reg:DI DI_REG))]
17555   "TARGET_64BIT && !SIBLING_CALL_P (insn)"
17556   { return ix86_output_call_insn (insn, operands[1], 1); }
17557   [(set_attr "type" "callv")])
17558
17559 (define_insn_and_split "*call_value_1_vzeroupper"
17560   [(set (match_operand 0 "" "")
17561         (call (mem:QI (match_operand:SI 1 "call_insn_operand" "lsm"))
17562               (match_operand:SI 2 "" "")))
17563    (unspec [(match_operand 3 "const_int_operand" "")]
17564            UNSPEC_CALL_NEEDS_VZEROUPPER)]
17565   "TARGET_VZEROUPPER && !TARGET_64BIT && !SIBLING_CALL_P (insn)"
17566   "#"
17567   "&& reload_completed"
17568   [(const_int 0)]
17569   "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
17570   [(set_attr "type" "callv")])
17571
17572 (define_insn "*call_value_1"
17573   [(set (match_operand 0 "" "")
17574         (call (mem:QI (match_operand:SI 1 "call_insn_operand" "lsm"))
17575               (match_operand:SI 2 "" "")))]
17576   "!TARGET_64BIT && !SIBLING_CALL_P (insn)"
17577   { return ix86_output_call_insn (insn, operands[1], 1); }
17578   [(set_attr "type" "callv")])
17579
17580 (define_insn_and_split "*sibcall_value_1_vzeroupper"
17581   [(set (match_operand 0 "" "")
17582         (call (mem:QI (match_operand:SI 1 "sibcall_insn_operand" "s,U"))
17583               (match_operand:SI 2 "" "")))
17584    (unspec [(match_operand 3 "const_int_operand" "")]
17585            UNSPEC_CALL_NEEDS_VZEROUPPER)]
17586   "TARGET_VZEROUPPER && !TARGET_64BIT && SIBLING_CALL_P (insn)"
17587   "#"
17588   "&& reload_completed"
17589   [(const_int 0)]
17590   "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
17591   [(set_attr "type" "callv")])
17592
17593 (define_insn "*sibcall_value_1"
17594   [(set (match_operand 0 "" "")
17595         (call (mem:QI (match_operand:SI 1 "sibcall_insn_operand" "s,U"))
17596               (match_operand:SI 2 "" "")))]
17597   "!TARGET_64BIT && SIBLING_CALL_P (insn)"
17598   { return ix86_output_call_insn (insn, operands[1], 1); }
17599   [(set_attr "type" "callv")])
17600
17601 (define_insn_and_split "*call_value_1_rex64_vzeroupper"
17602   [(set (match_operand 0 "" "")
17603         (call (mem:QI (match_operand:DI 1 "call_insn_operand" "rsm"))
17604               (match_operand:DI 2 "" "")))
17605    (unspec [(match_operand 3 "const_int_operand" "")]
17606            UNSPEC_CALL_NEEDS_VZEROUPPER)]
17607   "TARGET_VZEROUPPER && TARGET_64BIT && !SIBLING_CALL_P (insn)
17608    && ix86_cmodel != CM_LARGE && ix86_cmodel != CM_LARGE_PIC"
17609   "#"
17610   "&& reload_completed"
17611   [(const_int 0)]
17612   "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
17613   [(set_attr "type" "callv")])
17614
17615 (define_insn "*call_value_1_rex64"
17616   [(set (match_operand 0 "" "")
17617         (call (mem:QI (match_operand:DI 1 "call_insn_operand" "rsm"))
17618               (match_operand:DI 2 "" "")))]
17619   "TARGET_64BIT && !SIBLING_CALL_P (insn)
17620    && ix86_cmodel != CM_LARGE && ix86_cmodel != CM_LARGE_PIC"
17621   { return ix86_output_call_insn (insn, operands[1], 1); }
17622   [(set_attr "type" "callv")])
17623
17624 (define_insn_and_split "*call_value_1_rex64_ms_sysv_vzeroupper"
17625   [(parallel
17626     [(set (match_operand 0 "" "")
17627           (call (mem:QI (match_operand:DI 1 "call_insn_operand" "rsm"))
17628                 (match_operand:DI 2 "" "")))
17629      (unspec [(const_int 0)] UNSPEC_MS_TO_SYSV_CALL)
17630      (clobber (reg:TI XMM6_REG))
17631      (clobber (reg:TI XMM7_REG))
17632      (clobber (reg:TI XMM8_REG))
17633      (clobber (reg:TI XMM9_REG))
17634      (clobber (reg:TI XMM10_REG))
17635      (clobber (reg:TI XMM11_REG))
17636      (clobber (reg:TI XMM12_REG))
17637      (clobber (reg:TI XMM13_REG))
17638      (clobber (reg:TI XMM14_REG))
17639      (clobber (reg:TI XMM15_REG))
17640      (clobber (reg:DI SI_REG))
17641      (clobber (reg:DI DI_REG))])
17642    (unspec [(match_operand 3 "const_int_operand" "")]
17643            UNSPEC_CALL_NEEDS_VZEROUPPER)]
17644   "TARGET_VZEROUPPER && TARGET_64BIT && !SIBLING_CALL_P (insn)"
17645   "#"
17646   "&& reload_completed"
17647   [(const_int 0)]
17648   "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
17649   [(set_attr "type" "callv")])
17650
17651 (define_insn "*call_value_1_rex64_ms_sysv"
17652   [(set (match_operand 0 "" "")
17653         (call (mem:QI (match_operand:DI 1 "call_insn_operand" "rsm"))
17654               (match_operand:DI 2 "" "")))
17655    (unspec [(const_int 0)] UNSPEC_MS_TO_SYSV_CALL)
17656    (clobber (reg:TI XMM6_REG))
17657    (clobber (reg:TI XMM7_REG))
17658    (clobber (reg:TI XMM8_REG))
17659    (clobber (reg:TI XMM9_REG))
17660    (clobber (reg:TI XMM10_REG))
17661    (clobber (reg:TI XMM11_REG))
17662    (clobber (reg:TI XMM12_REG))
17663    (clobber (reg:TI XMM13_REG))
17664    (clobber (reg:TI XMM14_REG))
17665    (clobber (reg:TI XMM15_REG))
17666    (clobber (reg:DI SI_REG))
17667    (clobber (reg:DI DI_REG))]
17668   "TARGET_64BIT && !SIBLING_CALL_P (insn)"
17669   { return ix86_output_call_insn (insn, operands[1], 1); }
17670   [(set_attr "type" "callv")])
17671
17672 (define_insn_and_split "*call_value_1_rex64_large_vzeroupper"
17673   [(set (match_operand 0 "" "")
17674         (call (mem:QI (match_operand:DI 1 "call_insn_operand" "rm"))
17675               (match_operand:DI 2 "" "")))
17676    (unspec [(match_operand 3 "const_int_operand" "")]
17677            UNSPEC_CALL_NEEDS_VZEROUPPER)]
17678   "TARGET_VZEROUPPER && TARGET_64BIT && !SIBLING_CALL_P (insn)"
17679   "#"
17680   "&& reload_completed"
17681   [(const_int 0)]
17682   "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
17683   [(set_attr "type" "callv")])
17684
17685 (define_insn "*call_value_1_rex64_large"
17686   [(set (match_operand 0 "" "")
17687         (call (mem:QI (match_operand:DI 1 "call_insn_operand" "rm"))
17688               (match_operand:DI 2 "" "")))]
17689   "TARGET_64BIT && !SIBLING_CALL_P (insn)"
17690   { return ix86_output_call_insn (insn, operands[1], 1); }
17691   [(set_attr "type" "callv")])
17692
17693 (define_insn_and_split "*sibcall_value_1_rex64_vzeroupper"
17694   [(set (match_operand 0 "" "")
17695         (call (mem:QI (match_operand:DI 1 "sibcall_insn_operand" "s,U"))
17696               (match_operand:DI 2 "" "")))
17697    (unspec [(match_operand 3 "const_int_operand" "")]
17698            UNSPEC_CALL_NEEDS_VZEROUPPER)]
17699   "TARGET_VZEROUPPER && TARGET_64BIT && SIBLING_CALL_P (insn)"
17700   "#"
17701   "&& reload_completed"
17702   [(const_int 0)]
17703   "ix86_split_call_vzeroupper (curr_insn, operands[3]); DONE;"
17704   [(set_attr "type" "callv")])
17705
17706 (define_insn "*sibcall_value_1_rex64"
17707   [(set (match_operand 0 "" "")
17708         (call (mem:QI (match_operand:DI 1 "sibcall_insn_operand" "s,U"))
17709               (match_operand:DI 2 "" "")))]
17710   "TARGET_64BIT && SIBLING_CALL_P (insn)"
17711   { return ix86_output_call_insn (insn, operands[1], 1); }
17712   [(set_attr "type" "callv")])
17713 \f
17714 ;; We used to use "int $5", in honor of #BR which maps to interrupt vector 5.
17715 ;; That, however, is usually mapped by the OS to SIGSEGV, which is often
17716 ;; caught for use by garbage collectors and the like.  Using an insn that
17717 ;; maps to SIGILL makes it more likely the program will rightfully die.
17718 ;; Keeping with tradition, "6" is in honor of #UD.
17719 (define_insn "trap"
17720   [(trap_if (const_int 1) (const_int 6))]
17721   ""
17722   { return ASM_SHORT "0x0b0f"; }
17723   [(set_attr "length" "2")])
17724
17725 (define_expand "prefetch"
17726   [(prefetch (match_operand 0 "address_operand" "")
17727              (match_operand:SI 1 "const_int_operand" "")
17728              (match_operand:SI 2 "const_int_operand" ""))]
17729   "TARGET_PREFETCH_SSE || TARGET_3DNOW"
17730 {
17731   int rw = INTVAL (operands[1]);
17732   int locality = INTVAL (operands[2]);
17733
17734   gcc_assert (rw == 0 || rw == 1);
17735   gcc_assert (locality >= 0 && locality <= 3);
17736   gcc_assert (GET_MODE (operands[0]) == Pmode
17737               || GET_MODE (operands[0]) == VOIDmode);
17738
17739   /* Use 3dNOW prefetch in case we are asking for write prefetch not
17740      supported by SSE counterpart or the SSE prefetch is not available
17741      (K6 machines).  Otherwise use SSE prefetch as it allows specifying
17742      of locality.  */
17743   if (TARGET_3DNOW && (!TARGET_PREFETCH_SSE || rw))
17744     operands[2] = GEN_INT (3);
17745   else
17746     operands[1] = const0_rtx;
17747 })
17748
17749 (define_insn "*prefetch_sse_<mode>"
17750   [(prefetch (match_operand:P 0 "address_operand" "p")
17751              (const_int 0)
17752              (match_operand:SI 1 "const_int_operand" ""))]
17753   "TARGET_PREFETCH_SSE"
17754 {
17755   static const char * const patterns[4] = {
17756    "prefetchnta\t%a0", "prefetcht2\t%a0", "prefetcht1\t%a0", "prefetcht0\t%a0"
17757   };
17758
17759   int locality = INTVAL (operands[1]);
17760   gcc_assert (locality >= 0 && locality <= 3);
17761
17762   return patterns[locality];
17763 }
17764   [(set_attr "type" "sse")
17765    (set_attr "atom_sse_attr" "prefetch")
17766    (set (attr "length_address")
17767         (symbol_ref "memory_address_length (operands[0])"))
17768    (set_attr "memory" "none")])
17769
17770 (define_insn "*prefetch_3dnow_<mode>"
17771   [(prefetch (match_operand:P 0 "address_operand" "p")
17772              (match_operand:SI 1 "const_int_operand" "n")
17773              (const_int 3))]
17774   "TARGET_3DNOW"
17775 {
17776   if (INTVAL (operands[1]) == 0)
17777     return "prefetch\t%a0";
17778   else
17779     return "prefetchw\t%a0";
17780 }
17781   [(set_attr "type" "mmx")
17782    (set (attr "length_address")
17783         (symbol_ref "memory_address_length (operands[0])"))
17784    (set_attr "memory" "none")])
17785
17786 (define_expand "stack_protect_set"
17787   [(match_operand 0 "memory_operand" "")
17788    (match_operand 1 "memory_operand" "")]
17789   ""
17790 {
17791   rtx (*insn)(rtx, rtx);
17792
17793 #ifdef TARGET_THREAD_SSP_OFFSET
17794   operands[1] = GEN_INT (TARGET_THREAD_SSP_OFFSET);
17795   insn = (TARGET_64BIT
17796           ? gen_stack_tls_protect_set_di
17797           : gen_stack_tls_protect_set_si);
17798 #else
17799   insn = (TARGET_64BIT
17800           ? gen_stack_protect_set_di
17801           : gen_stack_protect_set_si);
17802 #endif
17803
17804   emit_insn (insn (operands[0], operands[1]));
17805   DONE;
17806 })
17807
17808 (define_insn "stack_protect_set_<mode>"
17809   [(set (match_operand:P 0 "memory_operand" "=m")
17810         (unspec:P [(match_operand:P 1 "memory_operand" "m")] UNSPEC_SP_SET))
17811    (set (match_scratch:P 2 "=&r") (const_int 0))
17812    (clobber (reg:CC FLAGS_REG))]
17813   ""
17814   "mov{<imodesuffix>}\t{%1, %2|%2, %1}\;mov{<imodesuffix>}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2"
17815   [(set_attr "type" "multi")])
17816
17817 (define_insn "stack_tls_protect_set_<mode>"
17818   [(set (match_operand:P 0 "memory_operand" "=m")
17819         (unspec:P [(match_operand:P 1 "const_int_operand" "i")]
17820                   UNSPEC_SP_TLS_SET))
17821    (set (match_scratch:P 2 "=&r") (const_int 0))
17822    (clobber (reg:CC FLAGS_REG))]
17823   ""
17824   "mov{<imodesuffix>}\t{%@:%P1, %2|%2, <iptrsize> PTR %@:%P1}\;mov{<imodesuffix>}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2"
17825   [(set_attr "type" "multi")])
17826
17827 (define_expand "stack_protect_test"
17828   [(match_operand 0 "memory_operand" "")
17829    (match_operand 1 "memory_operand" "")
17830    (match_operand 2 "" "")]
17831   ""
17832 {
17833   rtx flags = gen_rtx_REG (CCZmode, FLAGS_REG);
17834
17835   rtx (*insn)(rtx, rtx, rtx);
17836
17837 #ifdef TARGET_THREAD_SSP_OFFSET
17838   operands[1] = GEN_INT (TARGET_THREAD_SSP_OFFSET);
17839   insn = (TARGET_64BIT
17840           ? gen_stack_tls_protect_test_di
17841           : gen_stack_tls_protect_test_si);
17842 #else
17843   insn = (TARGET_64BIT
17844           ? gen_stack_protect_test_di
17845           : gen_stack_protect_test_si);
17846 #endif
17847
17848   emit_insn (insn (flags, operands[0], operands[1]));
17849
17850   emit_jump_insn (gen_cbranchcc4 (gen_rtx_EQ (VOIDmode, flags, const0_rtx),
17851                                   flags, const0_rtx, operands[2]));
17852   DONE;
17853 })
17854
17855 (define_insn "stack_protect_test_<mode>"
17856   [(set (match_operand:CCZ 0 "flags_reg_operand" "")
17857         (unspec:CCZ [(match_operand:P 1 "memory_operand" "m")
17858                      (match_operand:P 2 "memory_operand" "m")]
17859                     UNSPEC_SP_TEST))
17860    (clobber (match_scratch:P 3 "=&r"))]
17861   ""
17862   "mov{<imodesuffix>}\t{%1, %3|%3, %1}\;xor{<imodesuffix>}\t{%2, %3|%3, %2}"
17863   [(set_attr "type" "multi")])
17864
17865 (define_insn "stack_tls_protect_test_<mode>"
17866   [(set (match_operand:CCZ 0 "flags_reg_operand" "")
17867         (unspec:CCZ [(match_operand:P 1 "memory_operand" "m")
17868                      (match_operand:P 2 "const_int_operand" "i")]
17869                     UNSPEC_SP_TLS_TEST))
17870    (clobber (match_scratch:P 3 "=r"))]
17871   ""
17872   "mov{<imodesuffix>}\t{%1, %3|%3, %1}\;xor{<imodesuffix>}\t{%@:%P2, %3|%3, <iptrsize> PTR %@:%P2}"
17873   [(set_attr "type" "multi")])
17874
17875 (define_insn "sse4_2_crc32<mode>"
17876   [(set (match_operand:SI 0 "register_operand" "=r")
17877         (unspec:SI
17878           [(match_operand:SI 1 "register_operand" "0")
17879            (match_operand:SWI124 2 "nonimmediate_operand" "<r>m")]
17880           UNSPEC_CRC32))]
17881   "TARGET_SSE4_2 || TARGET_CRC32"
17882   "crc32{<imodesuffix>}\t{%2, %0|%0, %2}"
17883   [(set_attr "type" "sselog1")
17884    (set_attr "prefix_rep" "1")
17885    (set_attr "prefix_extra" "1")
17886    (set (attr "prefix_data16")
17887      (if_then_else (match_operand:HI 2 "" "")
17888        (const_string "1")
17889        (const_string "*")))
17890    (set (attr "prefix_rex")
17891      (if_then_else (match_operand:QI 2 "ext_QIreg_operand" "")
17892        (const_string "1")
17893        (const_string "*")))
17894    (set_attr "mode" "SI")])
17895
17896 (define_insn "sse4_2_crc32di"
17897   [(set (match_operand:DI 0 "register_operand" "=r")
17898         (unspec:DI
17899           [(match_operand:DI 1 "register_operand" "0")
17900            (match_operand:DI 2 "nonimmediate_operand" "rm")]
17901           UNSPEC_CRC32))]
17902   "TARGET_64BIT && (TARGET_SSE4_2 || TARGET_CRC32)"
17903   "crc32{q}\t{%2, %0|%0, %2}"
17904   [(set_attr "type" "sselog1")
17905    (set_attr "prefix_rep" "1")
17906    (set_attr "prefix_extra" "1")
17907    (set_attr "mode" "DI")])
17908
17909 (define_expand "rdpmc"
17910   [(match_operand:DI 0 "register_operand" "")
17911    (match_operand:SI 1 "register_operand" "")]
17912   ""
17913 {
17914   rtx reg = gen_reg_rtx (DImode);
17915   rtx si;
17916
17917   /* Force operand 1 into ECX.  */
17918   rtx ecx = gen_rtx_REG (SImode, CX_REG);
17919   emit_insn (gen_rtx_SET (VOIDmode, ecx, operands[1]));
17920   si = gen_rtx_UNSPEC_VOLATILE (DImode, gen_rtvec (1, ecx),
17921                                 UNSPECV_RDPMC);
17922
17923   if (TARGET_64BIT)
17924     {
17925       rtvec vec = rtvec_alloc (2);
17926       rtx load = gen_rtx_PARALLEL (VOIDmode, vec);
17927       rtx upper = gen_reg_rtx (DImode);
17928       rtx di = gen_rtx_UNSPEC_VOLATILE (DImode,
17929                                         gen_rtvec (1, const0_rtx),
17930                                         UNSPECV_RDPMC);
17931       RTVEC_ELT (vec, 0) = gen_rtx_SET (VOIDmode, reg, si);
17932       RTVEC_ELT (vec, 1) = gen_rtx_SET (VOIDmode, upper, di);
17933       emit_insn (load);
17934       upper = expand_simple_binop (DImode, ASHIFT, upper, GEN_INT (32),
17935                                    NULL, 1, OPTAB_DIRECT);
17936       reg = expand_simple_binop (DImode, IOR, reg, upper, reg, 1,
17937                                  OPTAB_DIRECT);
17938     }
17939   else
17940     emit_insn (gen_rtx_SET (VOIDmode, reg, si));
17941   emit_insn (gen_rtx_SET (VOIDmode, operands[0], reg));
17942   DONE;
17943 })
17944
17945 (define_insn "*rdpmc"
17946   [(set (match_operand:DI 0 "register_operand" "=A")
17947         (unspec_volatile:DI [(match_operand:SI 1 "register_operand" "c")]
17948                             UNSPECV_RDPMC))]
17949   "!TARGET_64BIT"
17950   "rdpmc"
17951   [(set_attr "type" "other")
17952    (set_attr "length" "2")])
17953
17954 (define_insn "*rdpmc_rex64"
17955   [(set (match_operand:DI 0 "register_operand" "=a")
17956         (unspec_volatile:DI [(match_operand:SI 2 "register_operand" "c")]
17957                             UNSPECV_RDPMC))
17958   (set (match_operand:DI 1 "register_operand" "=d")
17959        (unspec_volatile:DI [(const_int 0)] UNSPECV_RDPMC))]
17960   "TARGET_64BIT"
17961   "rdpmc"
17962   [(set_attr "type" "other")
17963    (set_attr "length" "2")])
17964
17965 (define_expand "rdtsc"
17966   [(set (match_operand:DI 0 "register_operand" "")
17967         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSC))]
17968   ""
17969 {
17970   if (TARGET_64BIT)
17971     {
17972       rtvec vec = rtvec_alloc (2);
17973       rtx load = gen_rtx_PARALLEL (VOIDmode, vec);
17974       rtx upper = gen_reg_rtx (DImode);
17975       rtx lower = gen_reg_rtx (DImode);
17976       rtx src = gen_rtx_UNSPEC_VOLATILE (DImode,
17977                                          gen_rtvec (1, const0_rtx),
17978                                          UNSPECV_RDTSC);
17979       RTVEC_ELT (vec, 0) = gen_rtx_SET (VOIDmode, lower, src);
17980       RTVEC_ELT (vec, 1) = gen_rtx_SET (VOIDmode, upper, src);
17981       emit_insn (load);
17982       upper = expand_simple_binop (DImode, ASHIFT, upper, GEN_INT (32),
17983                                    NULL, 1, OPTAB_DIRECT);
17984       lower = expand_simple_binop (DImode, IOR, lower, upper, lower, 1,
17985                                    OPTAB_DIRECT);
17986       emit_insn (gen_rtx_SET (VOIDmode, operands[0], lower));
17987       DONE;
17988     }
17989 })
17990
17991 (define_insn "*rdtsc"
17992   [(set (match_operand:DI 0 "register_operand" "=A")
17993         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSC))]
17994   "!TARGET_64BIT"
17995   "rdtsc"
17996   [(set_attr "type" "other")
17997    (set_attr "length" "2")])
17998
17999 (define_insn "*rdtsc_rex64"
18000   [(set (match_operand:DI 0 "register_operand" "=a")
18001         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSC))
18002    (set (match_operand:DI 1 "register_operand" "=d")
18003         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSC))]
18004   "TARGET_64BIT"
18005   "rdtsc"
18006   [(set_attr "type" "other")
18007    (set_attr "length" "2")])
18008
18009 (define_expand "rdtscp"
18010   [(match_operand:DI 0 "register_operand" "")
18011    (match_operand:SI 1 "memory_operand" "")]
18012   ""
18013 {
18014   rtx di = gen_rtx_UNSPEC_VOLATILE (DImode,
18015                                     gen_rtvec (1, const0_rtx),
18016                                     UNSPECV_RDTSCP);
18017   rtx si = gen_rtx_UNSPEC_VOLATILE (SImode,
18018                                     gen_rtvec (1, const0_rtx),
18019                                     UNSPECV_RDTSCP);
18020   rtx reg = gen_reg_rtx (DImode);
18021   rtx tmp = gen_reg_rtx (SImode);
18022
18023   if (TARGET_64BIT)
18024     {
18025       rtvec vec = rtvec_alloc (3);
18026       rtx load = gen_rtx_PARALLEL (VOIDmode, vec);
18027       rtx upper = gen_reg_rtx (DImode);
18028       RTVEC_ELT (vec, 0) = gen_rtx_SET (VOIDmode, reg, di);
18029       RTVEC_ELT (vec, 1) = gen_rtx_SET (VOIDmode, upper, di);
18030       RTVEC_ELT (vec, 2) = gen_rtx_SET (VOIDmode, tmp, si);
18031       emit_insn (load);
18032       upper = expand_simple_binop (DImode, ASHIFT, upper, GEN_INT (32),
18033                                    NULL, 1, OPTAB_DIRECT);
18034       reg = expand_simple_binop (DImode, IOR, reg, upper, reg, 1,
18035                                  OPTAB_DIRECT);
18036     }
18037   else
18038     {
18039       rtvec vec = rtvec_alloc (2);
18040       rtx load = gen_rtx_PARALLEL (VOIDmode, vec);
18041       RTVEC_ELT (vec, 0) = gen_rtx_SET (VOIDmode, reg, di);
18042       RTVEC_ELT (vec, 1) = gen_rtx_SET (VOIDmode, tmp, si);
18043       emit_insn (load);
18044     }
18045   emit_insn (gen_rtx_SET (VOIDmode, operands[0], reg));
18046   emit_insn (gen_rtx_SET (VOIDmode, operands[1], tmp));
18047   DONE;
18048 })
18049
18050 (define_insn "*rdtscp"
18051   [(set (match_operand:DI 0 "register_operand" "=A")
18052         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSCP))
18053    (set (match_operand:SI 1 "register_operand" "=c")
18054         (unspec_volatile:SI [(const_int 0)] UNSPECV_RDTSCP))]
18055   "!TARGET_64BIT"
18056   "rdtscp"
18057   [(set_attr "type" "other")
18058    (set_attr "length" "3")])
18059
18060 (define_insn "*rdtscp_rex64"
18061   [(set (match_operand:DI 0 "register_operand" "=a")
18062         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSCP))
18063    (set (match_operand:DI 1 "register_operand" "=d")
18064         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSCP))
18065    (set (match_operand:SI 2 "register_operand" "=c")
18066         (unspec_volatile:SI [(const_int 0)] UNSPECV_RDTSCP))]
18067   "TARGET_64BIT"
18068   "rdtscp"
18069   [(set_attr "type" "other")
18070    (set_attr "length" "3")])
18071
18072 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18073 ;;
18074 ;; LWP instructions
18075 ;;
18076 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18077
18078 (define_expand "lwp_llwpcb"
18079   [(unspec_volatile [(match_operand 0 "register_operand" "r")]
18080                     UNSPECV_LLWP_INTRINSIC)]
18081   "TARGET_LWP")
18082
18083 (define_insn "*lwp_llwpcb<mode>1"
18084   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
18085                     UNSPECV_LLWP_INTRINSIC)]
18086   "TARGET_LWP"
18087   "llwpcb\t%0"
18088   [(set_attr "type" "lwp")
18089    (set_attr "mode" "<MODE>")
18090    (set_attr "length" "5")])
18091
18092 (define_expand "lwp_slwpcb"
18093   [(set (match_operand 0 "register_operand" "=r")
18094         (unspec_volatile [(const_int 0)] UNSPECV_SLWP_INTRINSIC))]
18095   "TARGET_LWP"
18096 {
18097   rtx (*insn)(rtx);
18098
18099   insn = (TARGET_64BIT
18100           ? gen_lwp_slwpcbdi
18101           : gen_lwp_slwpcbsi);
18102
18103   emit_insn (insn (operands[0]));
18104   DONE;
18105 })
18106
18107 (define_insn "lwp_slwpcb<mode>"
18108   [(set (match_operand:P 0 "register_operand" "=r")
18109         (unspec_volatile:P [(const_int 0)] UNSPECV_SLWP_INTRINSIC))]
18110   "TARGET_LWP"
18111   "slwpcb\t%0"
18112   [(set_attr "type" "lwp")
18113    (set_attr "mode" "<MODE>")
18114    (set_attr "length" "5")])
18115
18116 (define_expand "lwp_lwpval<mode>3"
18117   [(unspec_volatile [(match_operand:SWI48 1 "register_operand" "r")
18118                      (match_operand:SI 2 "nonimmediate_operand" "rm")
18119                      (match_operand:SI 3 "const_int_operand" "i")]
18120                     UNSPECV_LWPVAL_INTRINSIC)]
18121   "TARGET_LWP"
18122   "/* Avoid unused variable warning.  */
18123    (void) operand0;")
18124
18125 (define_insn "*lwp_lwpval<mode>3_1"
18126   [(unspec_volatile [(match_operand:SWI48 0 "register_operand" "r")
18127                      (match_operand:SI 1 "nonimmediate_operand" "rm")
18128                      (match_operand:SI 2 "const_int_operand" "i")]
18129                     UNSPECV_LWPVAL_INTRINSIC)]
18130   "TARGET_LWP"
18131   "lwpval\t{%2, %1, %0|%0, %1, %2}"
18132   [(set_attr "type" "lwp")
18133    (set_attr "mode" "<MODE>")
18134    (set (attr "length")
18135         (symbol_ref "ix86_attr_length_address_default (insn) + 9"))])
18136
18137 (define_expand "lwp_lwpins<mode>3"
18138   [(set (reg:CCC FLAGS_REG)
18139         (unspec_volatile:CCC [(match_operand:SWI48 1 "register_operand" "r")
18140                               (match_operand:SI 2 "nonimmediate_operand" "rm")
18141                               (match_operand:SI 3 "const_int_operand" "i")]
18142                              UNSPECV_LWPINS_INTRINSIC))
18143    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
18144         (eq:QI (reg:CCC FLAGS_REG) (const_int 0)))]
18145   "TARGET_LWP")
18146
18147 (define_insn "*lwp_lwpins<mode>3_1"
18148   [(set (reg:CCC FLAGS_REG)
18149         (unspec_volatile:CCC [(match_operand:SWI48 0 "register_operand" "r")
18150                               (match_operand:SI 1 "nonimmediate_operand" "rm")
18151                               (match_operand:SI 2 "const_int_operand" "i")]
18152                              UNSPECV_LWPINS_INTRINSIC))]
18153   "TARGET_LWP"
18154   "lwpins\t{%2, %1, %0|%0, %1, %2}"
18155   [(set_attr "type" "lwp")
18156    (set_attr "mode" "<MODE>")
18157    (set (attr "length")
18158         (symbol_ref "ix86_attr_length_address_default (insn) + 9"))])
18159
18160 (define_insn "rdfsbase<mode>"
18161   [(set (match_operand:SWI48 0 "register_operand" "=r")
18162         (unspec_volatile:SWI48 [(const_int 0)] UNSPECV_RDFSBASE))]
18163   "TARGET_64BIT && TARGET_FSGSBASE"
18164   "rdfsbase %0"
18165   [(set_attr "type" "other")
18166    (set_attr "prefix_extra" "2")])
18167
18168 (define_insn "rdgsbase<mode>"
18169   [(set (match_operand:SWI48 0 "register_operand" "=r")
18170         (unspec_volatile:SWI48 [(const_int 0)] UNSPECV_RDGSBASE))]
18171   "TARGET_64BIT && TARGET_FSGSBASE"
18172   "rdgsbase %0"
18173   [(set_attr "type" "other")
18174    (set_attr "prefix_extra" "2")])
18175
18176 (define_insn "wrfsbase<mode>"
18177   [(unspec_volatile [(match_operand:SWI48 0 "register_operand" "r")]
18178                     UNSPECV_WRFSBASE)]
18179   "TARGET_64BIT && TARGET_FSGSBASE"
18180   "wrfsbase %0"
18181   [(set_attr "type" "other")
18182    (set_attr "prefix_extra" "2")])
18183
18184 (define_insn "wrgsbase<mode>"
18185   [(unspec_volatile [(match_operand:SWI48 0 "register_operand" "r")]
18186                     UNSPECV_WRGSBASE)]
18187   "TARGET_64BIT && TARGET_FSGSBASE"
18188   "wrgsbase %0"
18189   [(set_attr "type" "other")
18190    (set_attr "prefix_extra" "2")])
18191
18192 (define_insn "rdrand<mode>_1"
18193   [(set (match_operand:SWI248 0 "register_operand" "=r")
18194         (unspec:SWI248 [(const_int 0)] UNSPEC_RDRAND))
18195    (set (reg:CCC FLAGS_REG)
18196         (unspec:CCC [(const_int 0)] UNSPEC_RDRAND))]
18197   "TARGET_RDRND"
18198   "rdrand\t%0"
18199   [(set_attr "type" "other")
18200    (set_attr "prefix_extra" "1")])
18201
18202 (include "mmx.md")
18203 (include "sse.md")
18204 (include "sync.md")