Import pre-release gcc-5.0 to new vendor branch
[dragonfly.git] / contrib / gcc-5.0 / gcc / config / i386 / i386.md
1 ;; GCC machine description for IA-32 and x86-64.
2 ;; Copyright (C) 1988-2015 Free Software Foundation, Inc.
3 ;; Mostly by William Schelter.
4 ;; x86_64 support added by Jan Hubicka
5 ;;
6 ;; This file is part of GCC.
7 ;;
8 ;; GCC is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 3, or (at your option)
11 ;; any later version.
12 ;;
13 ;; GCC is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ;; GNU General Public License for more details.
17 ;;
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING3.  If not see
20 ;; <http://www.gnu.org/licenses/>.  */
21 ;;
22 ;; The original PO technology requires these to be ordered by speed,
23 ;; so that assigner will pick the fastest.
24 ;;
25 ;; See file "rtl.def" for documentation on define_insn, match_*, et. al.
26 ;;
27 ;; The special asm out single letter directives following a '%' are:
28 ;; L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
29 ;; C -- print opcode suffix for set/cmov insn.
30 ;; c -- like C, but print reversed condition
31 ;; F,f -- likewise, but for floating-point.
32 ;; O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
33 ;;      otherwise nothing
34 ;; R -- print the prefix for register names.
35 ;; z -- print the opcode suffix for the size of the current operand.
36 ;; Z -- likewise, with special suffixes for x87 instructions.
37 ;; * -- print a star (in certain assembler syntax)
38 ;; A -- print an absolute memory reference.
39 ;; E -- print address with DImode register names if TARGET_64BIT.
40 ;; w -- print the operand as if it's a "word" (HImode) even if it isn't.
41 ;; s -- print a shift double count, followed by the assemblers argument
42 ;;      delimiter.
43 ;; b -- print the QImode name of the register for the indicated operand.
44 ;;      %b0 would print %al if operands[0] is reg 0.
45 ;; w --  likewise, print the HImode name of the register.
46 ;; k --  likewise, print the SImode name of the register.
47 ;; q --  likewise, print the DImode name of the register.
48 ;; x --  likewise, print the V4SFmode name of the register.
49 ;; t --  likewise, print the V8SFmode name of the register.
50 ;; h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
51 ;; y -- print "st(0)" instead of "st" as a register.
52 ;; d -- print duplicated register operand for AVX instruction.
53 ;; D -- print condition for SSE cmp instruction.
54 ;; P -- if PIC, print an @PLT suffix.
55 ;; p -- print raw symbol name.
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 ;; K -- print HLE lock prefix
60 ;; Y -- print condition for XOP pcom* instruction.
61 ;; + -- print a branch hint as 'cs' or 'ds' prefix
62 ;; ; -- print a semicolon (after prefixes due to bug in older gas).
63 ;; ~ -- print "i" if TARGET_AVX2, "f" otherwise.
64 ;; @ -- print a segment register of thread base pointer load
65 ;; ^ -- print addr32 prefix if TARGET_64BIT and Pmode != word_mode
66 ;; ! -- print MPX prefix for jxx/call/ret instructions if required.
67
68 (define_c_enum "unspec" [
69   ;; Relocation specifiers
70   UNSPEC_GOT
71   UNSPEC_GOTOFF
72   UNSPEC_GOTPCREL
73   UNSPEC_GOTTPOFF
74   UNSPEC_TPOFF
75   UNSPEC_NTPOFF
76   UNSPEC_DTPOFF
77   UNSPEC_GOTNTPOFF
78   UNSPEC_INDNTPOFF
79   UNSPEC_PLTOFF
80   UNSPEC_MACHOPIC_OFFSET
81   UNSPEC_PCREL
82   UNSPEC_SIZEOF
83
84   ;; Prologue support
85   UNSPEC_STACK_ALLOC
86   UNSPEC_SET_GOT
87   UNSPEC_SET_RIP
88   UNSPEC_SET_GOT_OFFSET
89   UNSPEC_MEMORY_BLOCKAGE
90   UNSPEC_STACK_CHECK
91
92   ;; TLS support
93   UNSPEC_TP
94   UNSPEC_TLS_GD
95   UNSPEC_TLS_LD_BASE
96   UNSPEC_TLSDESC
97   UNSPEC_TLS_IE_SUN
98
99   ;; Other random patterns
100   UNSPEC_SCAS
101   UNSPEC_FNSTSW
102   UNSPEC_SAHF
103   UNSPEC_PARITY
104   UNSPEC_FSTCW
105   UNSPEC_ADD_CARRY
106   UNSPEC_FLDCW
107   UNSPEC_REP
108   UNSPEC_LD_MPIC        ; load_macho_picbase
109   UNSPEC_TRUNC_NOOP
110   UNSPEC_DIV_ALREADY_SPLIT
111   UNSPEC_PAUSE
112   UNSPEC_LEA_ADDR
113   UNSPEC_XBEGIN_ABORT
114   UNSPEC_STOS
115   UNSPEC_PEEPSIB
116   UNSPEC_INSN_FALSE_DEP
117
118   ;; For SSE/MMX support:
119   UNSPEC_FIX_NOTRUNC
120   UNSPEC_MASKMOV
121   UNSPEC_MOVMSK
122   UNSPEC_RCP
123   UNSPEC_RSQRT
124   UNSPEC_PSADBW
125
126   ;; Generic math support
127   UNSPEC_COPYSIGN
128   UNSPEC_IEEE_MIN       ; not commutative
129   UNSPEC_IEEE_MAX       ; not commutative
130
131   ;; x87 Floating point
132   UNSPEC_SIN
133   UNSPEC_COS
134   UNSPEC_FPATAN
135   UNSPEC_FYL2X
136   UNSPEC_FYL2XP1
137   UNSPEC_FRNDINT
138   UNSPEC_FIST
139   UNSPEC_F2XM1
140   UNSPEC_TAN
141   UNSPEC_FXAM
142
143   ;; x87 Rounding
144   UNSPEC_FRNDINT_FLOOR
145   UNSPEC_FRNDINT_CEIL
146   UNSPEC_FRNDINT_TRUNC
147   UNSPEC_FRNDINT_MASK_PM
148   UNSPEC_FIST_FLOOR
149   UNSPEC_FIST_CEIL
150
151   ;; x87 Double output FP
152   UNSPEC_SINCOS_COS
153   UNSPEC_SINCOS_SIN
154   UNSPEC_XTRACT_FRACT
155   UNSPEC_XTRACT_EXP
156   UNSPEC_FSCALE_FRACT
157   UNSPEC_FSCALE_EXP
158   UNSPEC_FPREM_F
159   UNSPEC_FPREM_U
160   UNSPEC_FPREM1_F
161   UNSPEC_FPREM1_U
162
163   UNSPEC_C2_FLAG
164   UNSPEC_FXAM_MEM
165
166   ;; SSP patterns
167   UNSPEC_SP_SET
168   UNSPEC_SP_TEST
169   UNSPEC_SP_TLS_SET
170   UNSPEC_SP_TLS_TEST
171
172   ;; For ROUND support
173   UNSPEC_ROUND
174
175   ;; For CRC32 support
176   UNSPEC_CRC32
177
178   ;; For BMI support
179   UNSPEC_BEXTR
180
181   ;; For BMI2 support
182   UNSPEC_PDEP
183   UNSPEC_PEXT
184
185   ;; For AVX512F support
186   UNSPEC_KMOV
187
188   UNSPEC_BNDMK
189   UNSPEC_BNDMK_ADDR
190   UNSPEC_BNDSTX
191   UNSPEC_BNDLDX
192   UNSPEC_BNDLDX_ADDR
193   UNSPEC_BNDCL
194   UNSPEC_BNDCU
195   UNSPEC_BNDCN
196   UNSPEC_MPX_FENCE
197 ])
198
199 (define_c_enum "unspecv" [
200   UNSPECV_BLOCKAGE
201   UNSPECV_STACK_PROBE
202   UNSPECV_PROBE_STACK_RANGE
203   UNSPECV_ALIGN
204   UNSPECV_PROLOGUE_USE
205   UNSPECV_SPLIT_STACK_RETURN
206   UNSPECV_CLD
207   UNSPECV_NOPS
208   UNSPECV_RDTSC
209   UNSPECV_RDTSCP
210   UNSPECV_RDPMC
211   UNSPECV_LLWP_INTRINSIC
212   UNSPECV_SLWP_INTRINSIC
213   UNSPECV_LWPVAL_INTRINSIC
214   UNSPECV_LWPINS_INTRINSIC
215   UNSPECV_RDFSBASE
216   UNSPECV_RDGSBASE
217   UNSPECV_WRFSBASE
218   UNSPECV_WRGSBASE
219   UNSPECV_FXSAVE
220   UNSPECV_FXRSTOR
221   UNSPECV_FXSAVE64
222   UNSPECV_FXRSTOR64
223   UNSPECV_XSAVE
224   UNSPECV_XRSTOR
225   UNSPECV_XSAVE64
226   UNSPECV_XRSTOR64
227   UNSPECV_XSAVEOPT
228   UNSPECV_XSAVEOPT64
229   UNSPECV_XSAVES
230   UNSPECV_XRSTORS
231   UNSPECV_XSAVES64
232   UNSPECV_XRSTORS64
233   UNSPECV_XSAVEC
234   UNSPECV_XSAVEC64
235
236   ;; For atomic compound assignments.
237   UNSPECV_FNSTENV
238   UNSPECV_FLDENV
239   UNSPECV_FNSTSW
240   UNSPECV_FNCLEX
241
242   ;; For RDRAND support
243   UNSPECV_RDRAND
244
245   ;; For RDSEED support
246   UNSPECV_RDSEED
247
248   ;; For RTM support
249   UNSPECV_XBEGIN
250   UNSPECV_XEND
251   UNSPECV_XABORT
252   UNSPECV_XTEST
253
254   UNSPECV_NLGR
255
256   ;; For CLWB support
257   UNSPECV_CLWB
258
259   ;; For PCOMMIT support
260   UNSPECV_PCOMMIT
261
262   ;; For CLFLUSHOPT support
263   UNSPECV_CLFLUSHOPT
264 ])
265
266 ;; Constants to represent rounding modes in the ROUND instruction
267 (define_constants
268   [(ROUND_FLOOR                 0x1)
269    (ROUND_CEIL                  0x2)
270    (ROUND_TRUNC                 0x3)
271    (ROUND_MXCSR                 0x4)
272    (ROUND_NO_EXC                0x8)
273   ])
274
275 ;; Constants to represent AVX512F embeded rounding
276 (define_constants
277   [(ROUND_NEAREST_INT                   0)
278    (ROUND_NEG_INF                       1)
279    (ROUND_POS_INF                       2)
280    (ROUND_ZERO                          3)
281    (NO_ROUND                            4)
282    (ROUND_SAE                           8)
283   ])
284
285 ;; Constants to represent pcomtrue/pcomfalse variants
286 (define_constants
287   [(PCOM_FALSE                  0)
288    (PCOM_TRUE                   1)
289    (COM_FALSE_S                 2)
290    (COM_FALSE_P                 3)
291    (COM_TRUE_S                  4)
292    (COM_TRUE_P                  5)
293   ])
294
295 ;; Constants used in the XOP pperm instruction
296 (define_constants
297   [(PPERM_SRC                   0x00)   /* copy source */
298    (PPERM_INVERT                0x20)   /* invert source */
299    (PPERM_REVERSE               0x40)   /* bit reverse source */
300    (PPERM_REV_INV               0x60)   /* bit reverse & invert src */
301    (PPERM_ZERO                  0x80)   /* all 0's */
302    (PPERM_ONES                  0xa0)   /* all 1's */
303    (PPERM_SIGN                  0xc0)   /* propagate sign bit */
304    (PPERM_INV_SIGN              0xe0)   /* invert & propagate sign */
305    (PPERM_SRC1                  0x00)   /* use first source byte */
306    (PPERM_SRC2                  0x10)   /* use second source byte */
307    ])
308
309 ;; Registers by name.
310 (define_constants
311   [(AX_REG                       0)
312    (DX_REG                       1)
313    (CX_REG                       2)
314    (BX_REG                       3)
315    (SI_REG                       4)
316    (DI_REG                       5)
317    (BP_REG                       6)
318    (SP_REG                       7)
319    (ST0_REG                      8)
320    (ST1_REG                      9)
321    (ST2_REG                     10)
322    (ST3_REG                     11)
323    (ST4_REG                     12)
324    (ST5_REG                     13)
325    (ST6_REG                     14)
326    (ST7_REG                     15)
327    (FLAGS_REG                   17)
328    (FPSR_REG                    18)
329    (FPCR_REG                    19)
330    (XMM0_REG                    21)
331    (XMM1_REG                    22)
332    (XMM2_REG                    23)
333    (XMM3_REG                    24)
334    (XMM4_REG                    25)
335    (XMM5_REG                    26)
336    (XMM6_REG                    27)
337    (XMM7_REG                    28)
338    (MM0_REG                     29)
339    (MM1_REG                     30)
340    (MM2_REG                     31)
341    (MM3_REG                     32)
342    (MM4_REG                     33)
343    (MM5_REG                     34)
344    (MM6_REG                     35)
345    (MM7_REG                     36)
346    (R8_REG                      37)
347    (R9_REG                      38)
348    (R10_REG                     39)
349    (R11_REG                     40)
350    (R12_REG                     41)
351    (R13_REG                     42)
352    (R14_REG                     43)
353    (R15_REG                     44)
354    (XMM8_REG                    45)
355    (XMM9_REG                    46)
356    (XMM10_REG                   47)
357    (XMM11_REG                   48)
358    (XMM12_REG                   49)
359    (XMM13_REG                   50)
360    (XMM14_REG                   51)
361    (XMM15_REG                   52)
362    (XMM16_REG                   53)
363    (XMM17_REG                   54)
364    (XMM18_REG                   55)
365    (XMM19_REG                   56)
366    (XMM20_REG                   57)
367    (XMM21_REG                   58)
368    (XMM22_REG                   59)
369    (XMM23_REG                   60)
370    (XMM24_REG                   61)
371    (XMM25_REG                   62)
372    (XMM26_REG                   63)
373    (XMM27_REG                   64)
374    (XMM28_REG                   65)
375    (XMM29_REG                   66)
376    (XMM30_REG                   67)
377    (XMM31_REG                   68)
378    (MASK0_REG                   69)
379    (MASK1_REG                   70)
380    (MASK2_REG                   71)
381    (MASK3_REG                   72)
382    (MASK4_REG                   73)
383    (MASK5_REG                   74)
384    (MASK6_REG                   75)
385    (MASK7_REG                   76)
386    (BND0_REG                    77)
387    (BND1_REG                    78)
388   ])
389
390 ;; Insns whose names begin with "x86_" are emitted by gen_FOO calls
391 ;; from i386.c.
392
393 ;; In C guard expressions, put expressions which may be compile-time
394 ;; constants first.  This allows for better optimization.  For
395 ;; example, write "TARGET_64BIT && reload_completed", not
396 ;; "reload_completed && TARGET_64BIT".
397
398 \f
399 ;; Processor type.
400 (define_attr "cpu" "none,pentium,pentiumpro,geode,k6,athlon,k8,core2,nehalem,
401                     atom,slm,generic,amdfam10,bdver1,bdver2,bdver3,bdver4,
402                     btver2,knl"
403   (const (symbol_ref "ix86_schedule")))
404
405 ;; A basic instruction type.  Refinements due to arguments to be
406 ;; provided in other attributes.
407 (define_attr "type"
408   "other,multi,
409    alu,alu1,negnot,imov,imovx,lea,
410    incdec,ishift,ishiftx,ishift1,rotate,rotatex,rotate1,
411    imul,imulx,idiv,icmp,test,ibr,setcc,icmov,
412    push,pop,call,callv,leave,
413    str,bitmanip,
414    fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,
415    fxch,fistp,fisttp,frndint,
416    sse,ssemov,sseadd,sseadd1,sseiadd,sseiadd1,
417    ssemul,sseimul,ssediv,sselog,sselog1,
418    sseishft,sseishft1,ssecmp,ssecomi,
419    ssecvt,ssecvt1,sseicvt,sseins,
420    sseshuf,sseshuf1,ssemuladd,sse4arg,
421    lwp,mskmov,msklog,
422    mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft,
423    mpxmov,mpxmk,mpxchk,mpxld,mpxst"
424   (const_string "other"))
425
426 ;; Main data type used by the insn
427 (define_attr "mode"
428   "unknown,none,QI,HI,SI,DI,TI,OI,XI,SF,DF,XF,TF,V16SF,V8SF,V4DF,V4SF,
429   V2DF,V2SF,V1DF,V8DF"
430   (const_string "unknown"))
431
432 ;; The CPU unit operations uses.
433 (define_attr "unit" "integer,i387,sse,mmx,unknown"
434   (cond [(eq_attr "type" "fmov,fop,fsgn,fmul,fdiv,fpspc,fcmov,fcmp,
435                           fxch,fistp,fisttp,frndint")
436            (const_string "i387")
437          (eq_attr "type" "sse,ssemov,sseadd,sseadd1,sseiadd,sseiadd1,
438                           ssemul,sseimul,ssediv,sselog,sselog1,
439                           sseishft,sseishft1,ssecmp,ssecomi,
440                           ssecvt,ssecvt1,sseicvt,sseins,
441                           sseshuf,sseshuf1,ssemuladd,sse4arg,mskmov")
442            (const_string "sse")
443          (eq_attr "type" "mmx,mmxmov,mmxadd,mmxmul,mmxcmp,mmxcvt,mmxshft")
444            (const_string "mmx")
445          (eq_attr "type" "other")
446            (const_string "unknown")]
447          (const_string "integer")))
448
449 ;; The minimum required alignment of vector mode memory operands of the SSE
450 ;; (non-VEX/EVEX) instruction in bits, if it is different from
451 ;; GET_MODE_ALIGNMENT of the operand, otherwise 0.  If an instruction has
452 ;; multiple alternatives, this should be conservative maximum of those minimum
453 ;; required alignments.
454 (define_attr "ssememalign" "" (const_int 0))
455
456 ;; The (bounding maximum) length of an instruction immediate.
457 (define_attr "length_immediate" ""
458   (cond [(eq_attr "type" "incdec,setcc,icmov,str,lea,other,multi,idiv,leave,
459                           bitmanip,imulx,msklog,mskmov,mpxmk,mpxmov,mpxchk,
460                           mpxld,mpxst")
461            (const_int 0)
462          (eq_attr "unit" "i387,sse,mmx")
463            (const_int 0)
464          (eq_attr "type" "alu,alu1,negnot,imovx,ishift,ishiftx,ishift1,
465                           rotate,rotatex,rotate1,imul,icmp,push,pop")
466            (symbol_ref "ix86_attr_length_immediate_default (insn, true)")
467          (eq_attr "type" "imov,test")
468            (symbol_ref "ix86_attr_length_immediate_default (insn, false)")
469          (eq_attr "type" "call")
470            (if_then_else (match_operand 0 "constant_call_address_operand")
471              (const_int 4)
472              (const_int 0))
473          (eq_attr "type" "callv")
474            (if_then_else (match_operand 1 "constant_call_address_operand")
475              (const_int 4)
476              (const_int 0))
477          ;; We don't know the size before shorten_branches.  Expect
478          ;; the instruction to fit for better scheduling.
479          (eq_attr "type" "ibr")
480            (const_int 1)
481          ]
482          (symbol_ref "/* Update immediate_length and other attributes! */
483                       gcc_unreachable (),1")))
484
485 ;; The (bounding maximum) length of an instruction address.
486 (define_attr "length_address" ""
487   (cond [(eq_attr "type" "str,other,multi,fxch")
488            (const_int 0)
489          (and (eq_attr "type" "call")
490               (match_operand 0 "constant_call_address_operand"))
491              (const_int 0)
492          (and (eq_attr "type" "callv")
493               (match_operand 1 "constant_call_address_operand"))
494              (const_int 0)
495          ]
496          (symbol_ref "ix86_attr_length_address_default (insn)")))
497
498 ;; Set when length prefix is used.
499 (define_attr "prefix_data16" ""
500   (cond [(eq_attr "type" "ssemuladd,sse4arg,sseiadd1,ssecvt1")
501            (const_int 0)
502          (eq_attr "mode" "HI")
503            (const_int 1)
504          (and (eq_attr "unit" "sse") (eq_attr "mode" "V2DF,TI"))
505            (const_int 1)
506         ]
507         (const_int 0)))
508
509 ;; Set when string REP prefix is used.
510 (define_attr "prefix_rep" ""
511   (cond [(eq_attr "type" "ssemuladd,sse4arg,sseiadd1,ssecvt1")
512            (const_int 0)
513          (and (eq_attr "unit" "sse") (eq_attr "mode" "SF,DF"))
514            (const_int 1)
515          (and (eq_attr "type" "ibr,call,callv")
516               (match_test "ix86_bnd_prefixed_insn_p (insn)"))
517            (const_int 1)
518         ]
519         (const_int 0)))
520
521 ;; Set when 0f opcode prefix is used.
522 (define_attr "prefix_0f" ""
523   (if_then_else
524     (ior (eq_attr "type" "imovx,setcc,icmov,bitmanip,msklog,mskmov,
525                           mpxmk,mpxmov,mpxchk,mpxld,mpxst")
526          (eq_attr "unit" "sse,mmx"))
527     (const_int 1)
528     (const_int 0)))
529
530 ;; Set when REX opcode prefix is used.
531 (define_attr "prefix_rex" ""
532   (cond [(not (match_test "TARGET_64BIT"))
533            (const_int 0)
534          (and (eq_attr "mode" "DI")
535               (and (eq_attr "type" "!push,pop,call,callv,leave,ibr")
536                    (eq_attr "unit" "!mmx")))
537            (const_int 1)
538          (and (eq_attr "mode" "QI")
539               (match_test "x86_extended_QIreg_mentioned_p (insn)"))
540            (const_int 1)
541          (match_test "x86_extended_reg_mentioned_p (insn)")
542            (const_int 1)
543          (and (eq_attr "type" "imovx")
544               (match_operand:QI 1 "ext_QIreg_operand"))
545            (const_int 1)
546         ]
547         (const_int 0)))
548
549 ;; There are also additional prefixes in 3DNOW, SSSE3.
550 ;; ssemuladd,sse4arg default to 0f24/0f25 and DREX byte,
551 ;; sseiadd1,ssecvt1 to 0f7a with no DREX byte.
552 ;; 3DNOW has 0f0f prefix, SSSE3 and SSE4_{1,2} 0f38/0f3a.
553 (define_attr "prefix_extra" ""
554   (cond [(eq_attr "type" "ssemuladd,sse4arg")
555            (const_int 2)
556          (eq_attr "type" "sseiadd1,ssecvt1")
557            (const_int 1)
558         ]
559         (const_int 0)))
560
561 ;; Prefix used: original, VEX or maybe VEX.
562 (define_attr "prefix" "orig,vex,maybe_vex,evex,maybe_evex"
563   (cond [(eq_attr "mode" "OI,V8SF,V4DF")
564            (const_string "vex")
565          (eq_attr "mode" "XI,V16SF,V8DF")
566            (const_string "evex")
567         ]
568         (const_string "orig")))
569
570 ;; VEX W bit is used.
571 (define_attr "prefix_vex_w" "" (const_int 0))
572
573 ;; The length of VEX prefix
574 ;; Only instructions with 0f prefix can have 2 byte VEX prefix,
575 ;; 0f38/0f3a prefixes can't.  In i386.md 0f3[8a] is
576 ;; still prefix_0f 1, with prefix_extra 1.
577 (define_attr "length_vex" ""
578   (if_then_else (and (eq_attr "prefix_0f" "1")
579                      (eq_attr "prefix_extra" "0"))
580     (if_then_else (eq_attr "prefix_vex_w" "1")
581       (symbol_ref "ix86_attr_length_vex_default (insn, true, true)")
582       (symbol_ref "ix86_attr_length_vex_default (insn, true, false)"))
583     (if_then_else (eq_attr "prefix_vex_w" "1")
584       (symbol_ref "ix86_attr_length_vex_default (insn, false, true)")
585       (symbol_ref "ix86_attr_length_vex_default (insn, false, false)"))))
586
587 ;; 4-bytes evex prefix and 1 byte opcode.
588 (define_attr "length_evex" "" (const_int 5))
589
590 ;; Set when modrm byte is used.
591 (define_attr "modrm" ""
592   (cond [(eq_attr "type" "str,leave")
593            (const_int 0)
594          (eq_attr "unit" "i387")
595            (const_int 0)
596          (and (eq_attr "type" "incdec")
597               (and (not (match_test "TARGET_64BIT"))
598                    (ior (match_operand:SI 1 "register_operand")
599                         (match_operand:HI 1 "register_operand"))))
600            (const_int 0)
601          (and (eq_attr "type" "push")
602               (not (match_operand 1 "memory_operand")))
603            (const_int 0)
604          (and (eq_attr "type" "pop")
605               (not (match_operand 0 "memory_operand")))
606            (const_int 0)
607          (and (eq_attr "type" "imov")
608               (and (not (eq_attr "mode" "DI"))
609                    (ior (and (match_operand 0 "register_operand")
610                              (match_operand 1 "immediate_operand"))
611                         (ior (and (match_operand 0 "ax_reg_operand")
612                                   (match_operand 1 "memory_displacement_only_operand"))
613                              (and (match_operand 0 "memory_displacement_only_operand")
614                                   (match_operand 1 "ax_reg_operand"))))))
615            (const_int 0)
616          (and (eq_attr "type" "call")
617               (match_operand 0 "constant_call_address_operand"))
618              (const_int 0)
619          (and (eq_attr "type" "callv")
620               (match_operand 1 "constant_call_address_operand"))
621              (const_int 0)
622          (and (eq_attr "type" "alu,alu1,icmp,test")
623               (match_operand 0 "ax_reg_operand"))
624              (symbol_ref "(get_attr_length_immediate (insn) <= (get_attr_mode (insn) != MODE_QI))")
625          ]
626          (const_int 1)))
627
628 ;; When this attribute is set, calculate total insn length from
629 ;; length_nobnd attribute, prefixed with eventual bnd prefix byte
630 (define_attr "length_nobnd" "" (const_int 0))
631
632 ;; The (bounding maximum) length of an instruction in bytes.
633 ;; ??? fistp and frndint are in fact fldcw/{fistp,frndint}/fldcw sequences.
634 ;; Later we may want to split them and compute proper length as for
635 ;; other insns.
636 (define_attr "length" ""
637   (cond [(eq_attr "length_nobnd" "!0")
638            (plus (symbol_ref ("ix86_bnd_prefixed_insn_p (insn)"))
639                  (attr "length_nobnd"))
640          (eq_attr "type" "other,multi,fistp,frndint")
641            (const_int 16)
642          (eq_attr "type" "fcmp")
643            (const_int 4)
644          (eq_attr "unit" "i387")
645            (plus (const_int 2)
646                  (plus (attr "prefix_data16")
647                        (attr "length_address")))
648          (ior (eq_attr "prefix" "evex")
649               (and (ior (eq_attr "prefix" "maybe_evex")
650                         (eq_attr "prefix" "maybe_vex"))
651                    (match_test "TARGET_AVX512F")))
652            (plus (attr "length_evex")
653                  (plus (attr "length_immediate")
654                        (plus (attr "modrm")
655                              (attr "length_address"))))
656          (ior (eq_attr "prefix" "vex")
657               (and (ior (eq_attr "prefix" "maybe_vex")
658                         (eq_attr "prefix" "maybe_evex"))
659                    (match_test "TARGET_AVX")))
660            (plus (attr "length_vex")
661                  (plus (attr "length_immediate")
662                        (plus (attr "modrm")
663                              (attr "length_address"))))]
664          (plus (plus (attr "modrm")
665                      (plus (attr "prefix_0f")
666                            (plus (attr "prefix_rex")
667                                  (plus (attr "prefix_extra")
668                                        (const_int 1)))))
669                (plus (attr "prefix_rep")
670                      (plus (attr "prefix_data16")
671                            (plus (attr "length_immediate")
672                                  (attr "length_address")))))))
673
674 ;; The `memory' attribute is `none' if no memory is referenced, `load' or
675 ;; `store' if there is a simple memory reference therein, or `unknown'
676 ;; if the instruction is complex.
677
678 (define_attr "memory" "none,load,store,both,unknown"
679   (cond [(eq_attr "type" "other,multi,str,lwp")
680            (const_string "unknown")
681          (eq_attr "type" "lea,fcmov,fpspc,mpxmk,mpxchk")
682            (const_string "none")
683          (eq_attr "type" "fistp,leave")
684            (const_string "both")
685          (eq_attr "type" "frndint")
686            (const_string "load")
687          (eq_attr "type" "mpxld")
688            (const_string "load")
689          (eq_attr "type" "mpxst")
690            (const_string "store")
691          (eq_attr "type" "push")
692            (if_then_else (match_operand 1 "memory_operand")
693              (const_string "both")
694              (const_string "store"))
695          (eq_attr "type" "pop")
696            (if_then_else (match_operand 0 "memory_operand")
697              (const_string "both")
698              (const_string "load"))
699          (eq_attr "type" "setcc")
700            (if_then_else (match_operand 0 "memory_operand")
701              (const_string "store")
702              (const_string "none"))
703          (eq_attr "type" "icmp,test,ssecmp,ssecomi,mmxcmp,fcmp")
704            (if_then_else (ior (match_operand 0 "memory_operand")
705                               (match_operand 1 "memory_operand"))
706              (const_string "load")
707              (const_string "none"))
708          (eq_attr "type" "ibr")
709            (if_then_else (match_operand 0 "memory_operand")
710              (const_string "load")
711              (const_string "none"))
712          (eq_attr "type" "call")
713            (if_then_else (match_operand 0 "constant_call_address_operand")
714              (const_string "none")
715              (const_string "load"))
716          (eq_attr "type" "callv")
717            (if_then_else (match_operand 1 "constant_call_address_operand")
718              (const_string "none")
719              (const_string "load"))
720          (and (eq_attr "type" "alu1,negnot,ishift1,sselog1,sseshuf1")
721               (match_operand 1 "memory_operand"))
722            (const_string "both")
723          (and (match_operand 0 "memory_operand")
724               (match_operand 1 "memory_operand"))
725            (const_string "both")
726          (match_operand 0 "memory_operand")
727            (const_string "store")
728          (match_operand 1 "memory_operand")
729            (const_string "load")
730          (and (eq_attr "type"
731                  "!alu1,negnot,ishift1,
732                    imov,imovx,icmp,test,bitmanip,
733                    fmov,fcmp,fsgn,
734                    sse,ssemov,ssecmp,ssecomi,ssecvt,ssecvt1,sseicvt,
735                    sselog1,sseshuf1,sseadd1,sseiadd1,sseishft1,
736                    mmx,mmxmov,mmxcmp,mmxcvt,mskmov,msklog,mpxmov")
737               (match_operand 2 "memory_operand"))
738            (const_string "load")
739          (and (eq_attr "type" "icmov,ssemuladd,sse4arg")
740               (match_operand 3 "memory_operand"))
741            (const_string "load")
742         ]
743         (const_string "none")))
744
745 ;; Indicates if an instruction has both an immediate and a displacement.
746
747 (define_attr "imm_disp" "false,true,unknown"
748   (cond [(eq_attr "type" "other,multi")
749            (const_string "unknown")
750          (and (eq_attr "type" "icmp,test,imov,alu1,ishift1,rotate1")
751               (and (match_operand 0 "memory_displacement_operand")
752                    (match_operand 1 "immediate_operand")))
753            (const_string "true")
754          (and (eq_attr "type" "alu,ishift,ishiftx,rotate,rotatex,imul,idiv")
755               (and (match_operand 0 "memory_displacement_operand")
756                    (match_operand 2 "immediate_operand")))
757            (const_string "true")
758         ]
759         (const_string "false")))
760
761 ;; Indicates if an FP operation has an integer source.
762
763 (define_attr "fp_int_src" "false,true"
764   (const_string "false"))
765
766 ;; Defines rounding mode of an FP operation.
767
768 (define_attr "i387_cw" "trunc,floor,ceil,mask_pm,uninitialized,any"
769   (const_string "any"))
770
771 ;; Define attribute to classify add/sub insns that consumes carry flag (CF)
772 (define_attr "use_carry" "0,1" (const_string "0"))
773
774 ;; Define attribute to indicate unaligned ssemov insns
775 (define_attr "movu" "0,1" (const_string "0"))
776
777 ;; Used to control the "enabled" attribute on a per-instruction basis.
778 (define_attr "isa" "base,x64,x64_sse4,x64_sse4_noavx,x64_avx,nox64,
779                     sse2,sse2_noavx,sse3,sse4,sse4_noavx,avx,noavx,
780                     avx2,noavx2,bmi,bmi2,fma4,fma,avx512f,noavx512f,
781                     fma_avx512f,avx512bw,noavx512bw,avx512dq,noavx512dq"
782   (const_string "base"))
783
784 (define_attr "enabled" ""
785   (cond [(eq_attr "isa" "x64") (symbol_ref "TARGET_64BIT")
786          (eq_attr "isa" "x64_sse4")
787            (symbol_ref "TARGET_64BIT && TARGET_SSE4_1")
788          (eq_attr "isa" "x64_sse4_noavx")
789            (symbol_ref "TARGET_64BIT && TARGET_SSE4_1 && !TARGET_AVX")
790          (eq_attr "isa" "x64_avx")
791            (symbol_ref "TARGET_64BIT && TARGET_AVX")
792          (eq_attr "isa" "nox64") (symbol_ref "!TARGET_64BIT")
793          (eq_attr "isa" "sse2") (symbol_ref "TARGET_SSE2")
794          (eq_attr "isa" "sse2_noavx")
795            (symbol_ref "TARGET_SSE2 && !TARGET_AVX")
796          (eq_attr "isa" "sse3") (symbol_ref "TARGET_SSE3")
797          (eq_attr "isa" "sse4") (symbol_ref "TARGET_SSE4_1")
798          (eq_attr "isa" "sse4_noavx")
799            (symbol_ref "TARGET_SSE4_1 && !TARGET_AVX")
800          (eq_attr "isa" "avx") (symbol_ref "TARGET_AVX")
801          (eq_attr "isa" "noavx") (symbol_ref "!TARGET_AVX")
802          (eq_attr "isa" "avx2") (symbol_ref "TARGET_AVX2")
803          (eq_attr "isa" "noavx2") (symbol_ref "!TARGET_AVX2")
804          (eq_attr "isa" "bmi") (symbol_ref "TARGET_BMI")
805          (eq_attr "isa" "bmi2") (symbol_ref "TARGET_BMI2")
806          (eq_attr "isa" "fma4") (symbol_ref "TARGET_FMA4")
807          (eq_attr "isa" "fma") (symbol_ref "TARGET_FMA")
808          (eq_attr "isa" "avx512f") (symbol_ref "TARGET_AVX512F")
809          (eq_attr "isa" "noavx512f") (symbol_ref "!TARGET_AVX512F")
810          (eq_attr "isa" "fma_avx512f")
811            (symbol_ref "TARGET_FMA || TARGET_AVX512F")
812          (eq_attr "isa" "avx512bw") (symbol_ref "TARGET_AVX512BW")
813          (eq_attr "isa" "noavx512bw") (symbol_ref "!TARGET_AVX512BW")
814          (eq_attr "isa" "avx512dq") (symbol_ref "TARGET_AVX512DQ")
815          (eq_attr "isa" "noavx512dq") (symbol_ref "!TARGET_AVX512DQ")
816         ]
817         (const_int 1)))
818
819 (define_attr "preferred_for_size" "" (const_int 1))
820 (define_attr "preferred_for_speed" "" (const_int 1))
821
822 ;; Describe a user's asm statement.
823 (define_asm_attributes
824   [(set_attr "length" "128")
825    (set_attr "type" "multi")])
826
827 (define_code_iterator plusminus [plus minus])
828
829 (define_code_iterator sat_plusminus [ss_plus us_plus ss_minus us_minus])
830
831 (define_code_iterator multdiv [mult div])
832
833 ;; Base name for define_insn
834 (define_code_attr plusminus_insn
835   [(plus "add") (ss_plus "ssadd") (us_plus "usadd")
836    (minus "sub") (ss_minus "sssub") (us_minus "ussub")])
837
838 ;; Base name for insn mnemonic.
839 (define_code_attr plusminus_mnemonic
840   [(plus "add") (ss_plus "adds") (us_plus "addus")
841    (minus "sub") (ss_minus "subs") (us_minus "subus")])
842 (define_code_attr plusminus_carry_mnemonic
843   [(plus "adc") (minus "sbb")])
844 (define_code_attr multdiv_mnemonic
845   [(mult "mul") (div "div")])
846
847 ;; Mark commutative operators as such in constraints.
848 (define_code_attr comm [(plus "%") (ss_plus "%") (us_plus "%")
849                         (minus "") (ss_minus "") (us_minus "")])
850
851 ;; Mapping of max and min
852 (define_code_iterator maxmin [smax smin umax umin])
853
854 ;; Mapping of signed max and min
855 (define_code_iterator smaxmin [smax smin])
856
857 ;; Mapping of unsigned max and min
858 (define_code_iterator umaxmin [umax umin])
859
860 ;; Base name for integer and FP insn mnemonic
861 (define_code_attr maxmin_int [(smax "maxs") (smin "mins")
862                               (umax "maxu") (umin "minu")])
863 (define_code_attr maxmin_float [(smax "max") (smin "min")])
864
865 ;; Mapping of logic operators
866 (define_code_iterator any_logic [and ior xor])
867 (define_code_iterator any_or [ior xor])
868 (define_code_iterator fpint_logic [and xor])
869
870 ;; Base name for insn mnemonic.
871 (define_code_attr logic [(and "and") (ior "or") (xor "xor")])
872
873 ;; Mapping of logic-shift operators
874 (define_code_iterator any_lshift [ashift lshiftrt])
875
876 ;; Mapping of shift-right operators
877 (define_code_iterator any_shiftrt [lshiftrt ashiftrt])
878
879 ;; Mapping of all shift operators
880 (define_code_iterator any_shift [ashift lshiftrt ashiftrt])
881
882 ;; Base name for define_insn
883 (define_code_attr shift_insn
884   [(ashift "ashl") (lshiftrt "lshr") (ashiftrt "ashr")])
885
886 ;; Base name for insn mnemonic.
887 (define_code_attr shift [(ashift "sll") (lshiftrt "shr") (ashiftrt "sar")])
888 (define_code_attr vshift [(ashift "sll") (lshiftrt "srl") (ashiftrt "sra")])
889
890 ;; Mapping of rotate operators
891 (define_code_iterator any_rotate [rotate rotatert])
892
893 ;; Base name for define_insn
894 (define_code_attr rotate_insn [(rotate "rotl") (rotatert "rotr")])
895
896 ;; Base name for insn mnemonic.
897 (define_code_attr rotate [(rotate "rol") (rotatert "ror")])
898
899 ;; Mapping of abs neg operators
900 (define_code_iterator absneg [abs neg])
901
902 ;; Base name for x87 insn mnemonic.
903 (define_code_attr absneg_mnemonic [(abs "abs") (neg "chs")])
904
905 ;; Used in signed and unsigned widening multiplications.
906 (define_code_iterator any_extend [sign_extend zero_extend])
907
908 ;; Prefix for insn menmonic.
909 (define_code_attr sgnprefix [(sign_extend "i") (zero_extend "")])
910
911 ;; Prefix for define_insn
912 (define_code_attr u [(sign_extend "") (zero_extend "u")])
913 (define_code_attr s [(sign_extend "s") (zero_extend "u")])
914 (define_code_attr u_bool [(sign_extend "false") (zero_extend "true")])
915
916 ;; Used in signed and unsigned truncations.
917 (define_code_iterator any_truncate [ss_truncate truncate us_truncate])
918 ;; Instruction suffix for truncations.
919 (define_code_attr trunsuffix [(ss_truncate "s") (truncate "") (us_truncate "us")])
920
921 ;; Used in signed and unsigned fix.
922 (define_code_iterator any_fix [fix unsigned_fix])
923 (define_code_attr fixsuffix [(fix "") (unsigned_fix "u")])
924
925 ;; Used in signed and unsigned float.
926 (define_code_iterator any_float [float unsigned_float])
927 (define_code_attr floatsuffix [(float "") (unsigned_float "u")])
928
929 ;; All integer modes.
930 (define_mode_iterator SWI1248x [QI HI SI DI])
931
932 ;; All integer modes with AVX512BW.
933 (define_mode_iterator SWI1248_AVX512BW
934   [QI HI (SI "TARGET_AVX512BW") (DI "TARGET_AVX512BW")])
935
936 ;; All integer modes without QImode.
937 (define_mode_iterator SWI248x [HI SI DI])
938
939 ;; All integer modes without QImode and HImode.
940 (define_mode_iterator SWI48x [SI DI])
941
942 ;; All integer modes without SImode and DImode.
943 (define_mode_iterator SWI12 [QI HI])
944
945 ;; All integer modes without DImode.
946 (define_mode_iterator SWI124 [QI HI SI])
947
948 ;; All integer modes without QImode and DImode.
949 (define_mode_iterator SWI24 [HI SI])
950
951 ;; Single word integer modes.
952 (define_mode_iterator SWI [QI HI SI (DI "TARGET_64BIT")])
953
954 ;; Single word integer modes without QImode.
955 (define_mode_iterator SWI248 [HI SI (DI "TARGET_64BIT")])
956
957 ;; Single word integer modes without QImode and HImode.
958 (define_mode_iterator SWI48 [SI (DI "TARGET_64BIT")])
959
960 ;; All math-dependant single and double word integer modes.
961 (define_mode_iterator SDWIM [(QI "TARGET_QIMODE_MATH")
962                              (HI "TARGET_HIMODE_MATH")
963                              SI DI (TI "TARGET_64BIT")])
964
965 ;; Math-dependant single word integer modes.
966 (define_mode_iterator SWIM [(QI "TARGET_QIMODE_MATH")
967                             (HI "TARGET_HIMODE_MATH")
968                             SI (DI "TARGET_64BIT")])
969
970 ;; Math-dependant integer modes without DImode.
971 (define_mode_iterator SWIM124 [(QI "TARGET_QIMODE_MATH")
972                                (HI "TARGET_HIMODE_MATH")
973                                SI])
974
975 ;; Math-dependant single word integer modes without QImode.
976 (define_mode_iterator SWIM248 [(HI "TARGET_HIMODE_MATH")
977                                SI (DI "TARGET_64BIT")])
978
979 ;; Double word integer modes.
980 (define_mode_iterator DWI [(DI "!TARGET_64BIT")
981                            (TI "TARGET_64BIT")])
982
983 ;; GET_MODE_SIZE for selected modes.  As GET_MODE_SIZE is not
984 ;; compile time constant, it is faster to use <MODE_SIZE> than
985 ;; GET_MODE_SIZE (<MODE>mode).  For XFmode which depends on
986 ;; command line options just use GET_MODE_SIZE macro.
987 (define_mode_attr MODE_SIZE [(QI "1") (HI "2") (SI "4") (DI "8") (TI "16")
988                              (SF "4") (DF "8") (XF "GET_MODE_SIZE (XFmode)")
989                              (V16QI "16") (V32QI "32") (V64QI "64")
990                              (V8HI "16") (V16HI "32") (V32HI "64")
991                              (V4SI "16") (V8SI "32") (V16SI "64")
992                              (V2DI "16") (V4DI "32") (V8DI "64")
993                              (V1TI "16") (V2TI "32") (V4TI "64")
994                              (V2DF "16") (V4DF "32") (V8DF "64")
995                              (V4SF "16") (V8SF "32") (V16SF "64")])
996
997 ;; Double word integer modes as mode attribute.
998 (define_mode_attr DWI [(QI "HI") (HI "SI") (SI "DI") (DI "TI")])
999 (define_mode_attr dwi [(QI "hi") (HI "si") (SI "di") (DI "ti")])
1000
1001 ;; Half mode for double word integer modes.
1002 (define_mode_iterator DWIH [(SI "!TARGET_64BIT")
1003                             (DI "TARGET_64BIT")])
1004
1005 ;; Bound modes.
1006 (define_mode_iterator BND [(BND32 "!TARGET_LP64")
1007                            (BND64 "TARGET_LP64")])
1008
1009 ;; Pointer mode corresponding to bound mode.
1010 (define_mode_attr bnd_ptr [(BND32 "SI") (BND64 "DI")])
1011
1012 ;; MPX check types
1013 (define_int_iterator BNDCHECK [UNSPEC_BNDCL UNSPEC_BNDCU UNSPEC_BNDCN])
1014
1015 ;; Check name
1016 (define_int_attr bndcheck [(UNSPEC_BNDCL "cl")
1017                            (UNSPEC_BNDCU "cu")
1018                            (UNSPEC_BNDCN "cn")])
1019
1020 ;; Instruction suffix for integer modes.
1021 (define_mode_attr imodesuffix [(QI "b") (HI "w") (SI "l") (DI "q")])
1022
1023 ;; Instruction suffix for masks.
1024 (define_mode_attr mskmodesuffix [(QI "b") (HI "w") (SI "d") (DI "q")])
1025
1026 ;; Pointer size prefix for integer modes (Intel asm dialect)
1027 (define_mode_attr iptrsize [(QI "BYTE")
1028                             (HI "WORD")
1029                             (SI "DWORD")
1030                             (DI "QWORD")])
1031
1032 ;; Register class for integer modes.
1033 (define_mode_attr r [(QI "q") (HI "r") (SI "r") (DI "r")])
1034
1035 ;; Immediate operand constraint for integer modes.
1036 (define_mode_attr i [(QI "n") (HI "n") (SI "e") (DI "e")])
1037
1038 ;; General operand constraint for word modes.
1039 (define_mode_attr g [(QI "qmn") (HI "rmn") (SI "rme") (DI "rme")])
1040
1041 ;; Immediate operand constraint for double integer modes.
1042 (define_mode_attr di [(SI "nF") (DI "e")])
1043
1044 ;; Immediate operand constraint for shifts.
1045 (define_mode_attr S [(QI "I") (HI "I") (SI "I") (DI "J") (TI "O")])
1046
1047 ;; General operand predicate for integer modes.
1048 (define_mode_attr general_operand
1049         [(QI "general_operand")
1050          (HI "general_operand")
1051          (SI "x86_64_general_operand")
1052          (DI "x86_64_general_operand")
1053          (TI "x86_64_general_operand")])
1054
1055 ;; General sign extend operand predicate for integer modes,
1056 ;; which disallows VOIDmode operands and thus it is suitable
1057 ;; for use inside sign_extend.
1058 (define_mode_attr general_sext_operand
1059         [(QI "sext_operand")
1060          (HI "sext_operand")
1061          (SI "x86_64_sext_operand")
1062          (DI "x86_64_sext_operand")])
1063
1064 ;; General sign/zero extend operand predicate for integer modes.
1065 (define_mode_attr general_szext_operand
1066         [(QI "general_operand")
1067          (HI "general_operand")
1068          (SI "x86_64_szext_general_operand")
1069          (DI "x86_64_szext_general_operand")])
1070
1071 ;; Immediate operand predicate for integer modes.
1072 (define_mode_attr immediate_operand
1073         [(QI "immediate_operand")
1074          (HI "immediate_operand")
1075          (SI "x86_64_immediate_operand")
1076          (DI "x86_64_immediate_operand")])
1077
1078 ;; Nonmemory operand predicate for integer modes.
1079 (define_mode_attr nonmemory_operand
1080         [(QI "nonmemory_operand")
1081          (HI "nonmemory_operand")
1082          (SI "x86_64_nonmemory_operand")
1083          (DI "x86_64_nonmemory_operand")])
1084
1085 ;; Operand predicate for shifts.
1086 (define_mode_attr shift_operand
1087         [(QI "nonimmediate_operand")
1088          (HI "nonimmediate_operand")
1089          (SI "nonimmediate_operand")
1090          (DI "shiftdi_operand")
1091          (TI "register_operand")])
1092
1093 ;; Operand predicate for shift argument.
1094 (define_mode_attr shift_immediate_operand
1095         [(QI "const_1_to_31_operand")
1096          (HI "const_1_to_31_operand")
1097          (SI "const_1_to_31_operand")
1098          (DI "const_1_to_63_operand")])
1099
1100 ;; Input operand predicate for arithmetic left shifts.
1101 (define_mode_attr ashl_input_operand
1102         [(QI "nonimmediate_operand")
1103          (HI "nonimmediate_operand")
1104          (SI "nonimmediate_operand")
1105          (DI "ashldi_input_operand")
1106          (TI "reg_or_pm1_operand")])
1107
1108 ;; SSE and x87 SFmode and DFmode floating point modes
1109 (define_mode_iterator MODEF [SF DF])
1110
1111 ;; All x87 floating point modes
1112 (define_mode_iterator X87MODEF [SF DF XF])
1113
1114 ;; SSE instruction suffix for various modes
1115 (define_mode_attr ssemodesuffix
1116   [(SF "ss") (DF "sd")
1117    (V16SF "ps") (V8DF "pd")
1118    (V8SF "ps") (V4DF "pd")
1119    (V4SF "ps") (V2DF "pd")
1120    (V16QI "b") (V8HI "w") (V4SI "d") (V2DI "q")
1121    (V32QI "b") (V16HI "w") (V8SI "d") (V4DI "q")
1122    (V64QI "b") (V32HI "w") (V16SI "d") (V8DI "q")])
1123
1124 ;; SSE vector suffix for floating point modes
1125 (define_mode_attr ssevecmodesuffix [(SF "ps") (DF "pd")])
1126
1127 ;; SSE vector mode corresponding to a scalar mode
1128 (define_mode_attr ssevecmode
1129   [(QI "V16QI") (HI "V8HI") (SI "V4SI") (DI "V2DI") (SF "V4SF") (DF "V2DF")])
1130 (define_mode_attr ssevecmodelower
1131   [(QI "v16qi") (HI "v8hi") (SI "v4si") (DI "v2di") (SF "v4sf") (DF "v2df")])
1132
1133 ;; Instruction suffix for REX 64bit operators.
1134 (define_mode_attr rex64suffix [(SI "") (DI "{q}")])
1135
1136 ;; This mode iterator allows :P to be used for patterns that operate on
1137 ;; pointer-sized quantities.  Exactly one of the two alternatives will match.
1138 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
1139
1140 ;; This mode iterator allows :W to be used for patterns that operate on
1141 ;; word_mode sized quantities.
1142 (define_mode_iterator W
1143   [(SI "word_mode == SImode") (DI "word_mode == DImode")])
1144
1145 ;; This mode iterator allows :PTR to be used for patterns that operate on
1146 ;; ptr_mode sized quantities.
1147 (define_mode_iterator PTR
1148   [(SI "ptr_mode == SImode") (DI "ptr_mode == DImode")])
1149 \f
1150 ;; Scheduling descriptions
1151
1152 (include "pentium.md")
1153 (include "ppro.md")
1154 (include "k6.md")
1155 (include "athlon.md")
1156 (include "bdver1.md")
1157 (include "bdver3.md")
1158 (include "btver2.md")
1159 (include "geode.md")
1160 (include "atom.md")
1161 (include "slm.md")
1162 (include "core2.md")
1163
1164 \f
1165 ;; Operand and operator predicates and constraints
1166
1167 (include "predicates.md")
1168 (include "constraints.md")
1169
1170 \f
1171 ;; Compare and branch/compare and store instructions.
1172
1173 (define_expand "cbranch<mode>4"
1174   [(set (reg:CC FLAGS_REG)
1175         (compare:CC (match_operand:SDWIM 1 "nonimmediate_operand")
1176                     (match_operand:SDWIM 2 "<general_operand>")))
1177    (set (pc) (if_then_else
1178                (match_operator 0 "ordered_comparison_operator"
1179                 [(reg:CC FLAGS_REG) (const_int 0)])
1180                (label_ref (match_operand 3))
1181                (pc)))]
1182   ""
1183 {
1184   if (MEM_P (operands[1]) && MEM_P (operands[2]))
1185     operands[1] = force_reg (<MODE>mode, operands[1]);
1186   ix86_expand_branch (GET_CODE (operands[0]),
1187                       operands[1], operands[2], operands[3]);
1188   DONE;
1189 })
1190
1191 (define_expand "cstore<mode>4"
1192   [(set (reg:CC FLAGS_REG)
1193         (compare:CC (match_operand:SWIM 2 "nonimmediate_operand")
1194                     (match_operand:SWIM 3 "<general_operand>")))
1195    (set (match_operand:QI 0 "register_operand")
1196         (match_operator 1 "ordered_comparison_operator"
1197           [(reg:CC FLAGS_REG) (const_int 0)]))]
1198   ""
1199 {
1200   if (MEM_P (operands[2]) && MEM_P (operands[3]))
1201     operands[2] = force_reg (<MODE>mode, operands[2]);
1202   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1203                      operands[2], operands[3]);
1204   DONE;
1205 })
1206
1207 (define_expand "cmp<mode>_1"
1208   [(set (reg:CC FLAGS_REG)
1209         (compare:CC (match_operand:SWI48 0 "nonimmediate_operand")
1210                     (match_operand:SWI48 1 "<general_operand>")))])
1211
1212 (define_insn "*cmp<mode>_ccno_1"
1213   [(set (reg FLAGS_REG)
1214         (compare (match_operand:SWI 0 "nonimmediate_operand" "<r>,?m<r>")
1215                  (match_operand:SWI 1 "const0_operand")))]
1216   "ix86_match_ccmode (insn, CCNOmode)"
1217   "@
1218    test{<imodesuffix>}\t%0, %0
1219    cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
1220   [(set_attr "type" "test,icmp")
1221    (set_attr "length_immediate" "0,1")
1222    (set_attr "mode" "<MODE>")])
1223
1224 (define_insn "*cmp<mode>_1"
1225   [(set (reg FLAGS_REG)
1226         (compare (match_operand:SWI 0 "nonimmediate_operand" "<r>m,<r>")
1227                  (match_operand:SWI 1 "<general_operand>" "<r><i>,<r>m")))]
1228   "ix86_match_ccmode (insn, CCmode)"
1229   "cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
1230   [(set_attr "type" "icmp")
1231    (set_attr "mode" "<MODE>")])
1232
1233 (define_insn "*cmp<mode>_minus_1"
1234   [(set (reg FLAGS_REG)
1235         (compare
1236           (minus:SWI (match_operand:SWI 0 "nonimmediate_operand" "<r>m,<r>")
1237                      (match_operand:SWI 1 "<general_operand>" "<r><i>,<r>m"))
1238           (const_int 0)))]
1239   "ix86_match_ccmode (insn, CCGOCmode)"
1240   "cmp{<imodesuffix>}\t{%1, %0|%0, %1}"
1241   [(set_attr "type" "icmp")
1242    (set_attr "mode" "<MODE>")])
1243
1244 (define_insn "*cmpqi_ext_1"
1245   [(set (reg FLAGS_REG)
1246         (compare
1247           (match_operand:QI 0 "nonimmediate_x64nomem_operand" "Q,m")
1248           (subreg:QI
1249             (zero_extract:SI
1250               (match_operand 1 "ext_register_operand" "Q,Q")
1251               (const_int 8)
1252               (const_int 8)) 0)))]
1253   "ix86_match_ccmode (insn, CCmode)"
1254   "cmp{b}\t{%h1, %0|%0, %h1}"
1255   [(set_attr "isa" "*,nox64")
1256    (set_attr "type" "icmp")
1257    (set_attr "mode" "QI")])
1258
1259 (define_insn "*cmpqi_ext_2"
1260   [(set (reg FLAGS_REG)
1261         (compare
1262           (subreg:QI
1263             (zero_extract:SI
1264               (match_operand 0 "ext_register_operand" "Q")
1265               (const_int 8)
1266               (const_int 8)) 0)
1267           (match_operand:QI 1 "const0_operand")))]
1268   "ix86_match_ccmode (insn, CCNOmode)"
1269   "test{b}\t%h0, %h0"
1270   [(set_attr "type" "test")
1271    (set_attr "length_immediate" "0")
1272    (set_attr "mode" "QI")])
1273
1274 (define_expand "cmpqi_ext_3"
1275   [(set (reg:CC FLAGS_REG)
1276         (compare:CC
1277           (subreg:QI
1278             (zero_extract:SI
1279               (match_operand 0 "ext_register_operand")
1280               (const_int 8)
1281               (const_int 8)) 0)
1282           (match_operand:QI 1 "const_int_operand")))])
1283
1284 (define_insn "*cmpqi_ext_3"
1285   [(set (reg FLAGS_REG)
1286         (compare
1287           (subreg:QI
1288             (zero_extract:SI
1289               (match_operand 0 "ext_register_operand" "Q,Q")
1290               (const_int 8)
1291               (const_int 8)) 0)
1292           (match_operand:QI 1 "general_x64nomem_operand" "Qn,m")))]
1293   "ix86_match_ccmode (insn, CCmode)"
1294   "cmp{b}\t{%1, %h0|%h0, %1}"
1295   [(set_attr "isa" "*,nox64")
1296    (set_attr "type" "icmp")
1297    (set_attr "modrm" "1")
1298    (set_attr "mode" "QI")])
1299
1300 (define_insn "*cmpqi_ext_4"
1301   [(set (reg FLAGS_REG)
1302         (compare
1303           (subreg:QI
1304             (zero_extract:SI
1305               (match_operand 0 "ext_register_operand" "Q")
1306               (const_int 8)
1307               (const_int 8)) 0)
1308           (subreg:QI
1309             (zero_extract:SI
1310               (match_operand 1 "ext_register_operand" "Q")
1311               (const_int 8)
1312               (const_int 8)) 0)))]
1313   "ix86_match_ccmode (insn, CCmode)"
1314   "cmp{b}\t{%h1, %h0|%h0, %h1}"
1315   [(set_attr "type" "icmp")
1316    (set_attr "mode" "QI")])
1317
1318 ;; These implement float point compares.
1319 ;; %%% See if we can get away with VOIDmode operands on the actual insns,
1320 ;; which would allow mix and match FP modes on the compares.  Which is what
1321 ;; the old patterns did, but with many more of them.
1322
1323 (define_expand "cbranchxf4"
1324   [(set (reg:CC FLAGS_REG)
1325         (compare:CC (match_operand:XF 1 "nonmemory_operand")
1326                     (match_operand:XF 2 "nonmemory_operand")))
1327    (set (pc) (if_then_else
1328               (match_operator 0 "ix86_fp_comparison_operator"
1329                [(reg:CC FLAGS_REG)
1330                 (const_int 0)])
1331               (label_ref (match_operand 3))
1332               (pc)))]
1333   "TARGET_80387"
1334 {
1335   ix86_expand_branch (GET_CODE (operands[0]),
1336                       operands[1], operands[2], operands[3]);
1337   DONE;
1338 })
1339
1340 (define_expand "cstorexf4"
1341   [(set (reg:CC FLAGS_REG)
1342         (compare:CC (match_operand:XF 2 "nonmemory_operand")
1343                     (match_operand:XF 3 "nonmemory_operand")))
1344    (set (match_operand:QI 0 "register_operand")
1345               (match_operator 1 "ix86_fp_comparison_operator"
1346                [(reg:CC FLAGS_REG)
1347                 (const_int 0)]))]
1348   "TARGET_80387"
1349 {
1350   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1351                      operands[2], operands[3]);
1352   DONE;
1353 })
1354
1355 (define_expand "cbranch<mode>4"
1356   [(set (reg:CC FLAGS_REG)
1357         (compare:CC (match_operand:MODEF 1 "cmp_fp_expander_operand")
1358                     (match_operand:MODEF 2 "cmp_fp_expander_operand")))
1359    (set (pc) (if_then_else
1360               (match_operator 0 "ix86_fp_comparison_operator"
1361                [(reg:CC FLAGS_REG)
1362                 (const_int 0)])
1363               (label_ref (match_operand 3))
1364               (pc)))]
1365   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
1366 {
1367   ix86_expand_branch (GET_CODE (operands[0]),
1368                       operands[1], operands[2], operands[3]);
1369   DONE;
1370 })
1371
1372 (define_expand "cstore<mode>4"
1373   [(set (reg:CC FLAGS_REG)
1374         (compare:CC (match_operand:MODEF 2 "cmp_fp_expander_operand")
1375                     (match_operand:MODEF 3 "cmp_fp_expander_operand")))
1376    (set (match_operand:QI 0 "register_operand")
1377               (match_operator 1 "ix86_fp_comparison_operator"
1378                [(reg:CC FLAGS_REG)
1379                 (const_int 0)]))]
1380   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
1381 {
1382   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1383                      operands[2], operands[3]);
1384   DONE;
1385 })
1386
1387 (define_expand "cbranchcc4"
1388   [(set (pc) (if_then_else
1389               (match_operator 0 "comparison_operator"
1390                [(match_operand 1 "flags_reg_operand")
1391                 (match_operand 2 "const0_operand")])
1392               (label_ref (match_operand 3))
1393               (pc)))]
1394   ""
1395 {
1396   ix86_expand_branch (GET_CODE (operands[0]),
1397                       operands[1], operands[2], operands[3]);
1398   DONE;
1399 })
1400
1401 (define_expand "cstorecc4"
1402   [(set (match_operand:QI 0 "register_operand")
1403               (match_operator 1 "comparison_operator"
1404                [(match_operand 2 "flags_reg_operand")
1405                 (match_operand 3 "const0_operand")]))]
1406   ""
1407 {
1408   ix86_expand_setcc (operands[0], GET_CODE (operands[1]),
1409                      operands[2], operands[3]);
1410   DONE;
1411 })
1412
1413
1414 ;; FP compares, step 1:
1415 ;; Set the FP condition codes.
1416 ;;
1417 ;; CCFPmode     compare with exceptions
1418 ;; CCFPUmode    compare with no exceptions
1419
1420 ;; We may not use "#" to split and emit these, since the REG_DEAD notes
1421 ;; used to manage the reg stack popping would not be preserved.
1422
1423 (define_insn "*cmp<mode>_0_i387"
1424   [(set (match_operand:HI 0 "register_operand" "=a")
1425         (unspec:HI
1426           [(compare:CCFP
1427              (match_operand:X87MODEF 1 "register_operand" "f")
1428              (match_operand:X87MODEF 2 "const0_operand"))]
1429         UNSPEC_FNSTSW))]
1430   "TARGET_80387"
1431   "* return output_fp_compare (insn, operands, false, false);"
1432   [(set_attr "type" "multi")
1433    (set_attr "unit" "i387")
1434    (set_attr "mode" "<MODE>")])
1435
1436 (define_insn_and_split "*cmp<mode>_0_cc_i387"
1437   [(set (reg:CCFP FLAGS_REG)
1438         (compare:CCFP
1439           (match_operand:X87MODEF 1 "register_operand" "f")
1440           (match_operand:X87MODEF 2 "const0_operand")))
1441    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1442   "TARGET_80387 && TARGET_SAHF && !TARGET_CMOVE"
1443   "#"
1444   "&& reload_completed"
1445   [(set (match_dup 0)
1446         (unspec:HI
1447           [(compare:CCFP (match_dup 1)(match_dup 2))]
1448         UNSPEC_FNSTSW))
1449    (set (reg:CC FLAGS_REG)
1450         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1451   ""
1452   [(set_attr "type" "multi")
1453    (set_attr "unit" "i387")
1454    (set_attr "mode" "<MODE>")])
1455
1456 (define_insn "*cmpxf_i387"
1457   [(set (match_operand:HI 0 "register_operand" "=a")
1458         (unspec:HI
1459           [(compare:CCFP
1460              (match_operand:XF 1 "register_operand" "f")
1461              (match_operand:XF 2 "register_operand" "f"))]
1462           UNSPEC_FNSTSW))]
1463   "TARGET_80387"
1464   "* return output_fp_compare (insn, operands, false, false);"
1465   [(set_attr "type" "multi")
1466    (set_attr "unit" "i387")
1467    (set_attr "mode" "XF")])
1468
1469 (define_insn_and_split "*cmpxf_cc_i387"
1470   [(set (reg:CCFP FLAGS_REG)
1471         (compare:CCFP
1472           (match_operand:XF 1 "register_operand" "f")
1473           (match_operand:XF 2 "register_operand" "f")))
1474    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1475   "TARGET_80387 && TARGET_SAHF && !TARGET_CMOVE"
1476   "#"
1477   "&& reload_completed"
1478   [(set (match_dup 0)
1479         (unspec:HI
1480           [(compare:CCFP (match_dup 1)(match_dup 2))]
1481         UNSPEC_FNSTSW))
1482    (set (reg:CC FLAGS_REG)
1483         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1484   ""
1485   [(set_attr "type" "multi")
1486    (set_attr "unit" "i387")
1487    (set_attr "mode" "XF")])
1488
1489 (define_insn "*cmp<mode>_i387"
1490   [(set (match_operand:HI 0 "register_operand" "=a")
1491         (unspec:HI
1492           [(compare:CCFP
1493              (match_operand:MODEF 1 "register_operand" "f")
1494              (match_operand:MODEF 2 "nonimmediate_operand" "fm"))]
1495           UNSPEC_FNSTSW))]
1496   "TARGET_80387"
1497   "* return output_fp_compare (insn, operands, false, false);"
1498   [(set_attr "type" "multi")
1499    (set_attr "unit" "i387")
1500    (set_attr "mode" "<MODE>")])
1501
1502 (define_insn_and_split "*cmp<mode>_cc_i387"
1503   [(set (reg:CCFP FLAGS_REG)
1504         (compare:CCFP
1505           (match_operand:MODEF 1 "register_operand" "f")
1506           (match_operand:MODEF 2 "nonimmediate_operand" "fm")))
1507    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1508   "TARGET_80387 && TARGET_SAHF && !TARGET_CMOVE"
1509   "#"
1510   "&& reload_completed"
1511   [(set (match_dup 0)
1512         (unspec:HI
1513           [(compare:CCFP (match_dup 1)(match_dup 2))]
1514         UNSPEC_FNSTSW))
1515    (set (reg:CC FLAGS_REG)
1516         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1517   ""
1518   [(set_attr "type" "multi")
1519    (set_attr "unit" "i387")
1520    (set_attr "mode" "<MODE>")])
1521
1522 (define_insn "*cmpu<mode>_i387"
1523   [(set (match_operand:HI 0 "register_operand" "=a")
1524         (unspec:HI
1525           [(compare:CCFPU
1526              (match_operand:X87MODEF 1 "register_operand" "f")
1527              (match_operand:X87MODEF 2 "register_operand" "f"))]
1528           UNSPEC_FNSTSW))]
1529   "TARGET_80387"
1530   "* return output_fp_compare (insn, operands, false, true);"
1531   [(set_attr "type" "multi")
1532    (set_attr "unit" "i387")
1533    (set_attr "mode" "<MODE>")])
1534
1535 (define_insn_and_split "*cmpu<mode>_cc_i387"
1536   [(set (reg:CCFPU FLAGS_REG)
1537         (compare:CCFPU
1538           (match_operand:X87MODEF 1 "register_operand" "f")
1539           (match_operand:X87MODEF 2 "register_operand" "f")))
1540    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1541   "TARGET_80387 && TARGET_SAHF && !TARGET_CMOVE"
1542   "#"
1543   "&& reload_completed"
1544   [(set (match_dup 0)
1545         (unspec:HI
1546           [(compare:CCFPU (match_dup 1)(match_dup 2))]
1547         UNSPEC_FNSTSW))
1548    (set (reg:CC FLAGS_REG)
1549         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1550   ""
1551   [(set_attr "type" "multi")
1552    (set_attr "unit" "i387")
1553    (set_attr "mode" "<MODE>")])
1554
1555 (define_insn "*cmp<X87MODEF:mode>_<SWI24:mode>_i387"
1556   [(set (match_operand:HI 0 "register_operand" "=a")
1557         (unspec:HI
1558           [(compare:CCFP
1559              (match_operand:X87MODEF 1 "register_operand" "f")
1560              (match_operator:X87MODEF 3 "float_operator"
1561                [(match_operand:SWI24 2 "memory_operand" "m")]))]
1562           UNSPEC_FNSTSW))]
1563   "TARGET_80387
1564    && (TARGET_USE_<SWI24:MODE>MODE_FIOP
1565        || optimize_function_for_size_p (cfun))"
1566   "* return output_fp_compare (insn, operands, false, false);"
1567   [(set_attr "type" "multi")
1568    (set_attr "unit" "i387")
1569    (set_attr "fp_int_src" "true")
1570    (set_attr "mode" "<SWI24:MODE>")])
1571
1572 (define_insn_and_split "*cmp<X87MODEF:mode>_<SWI24:mode>_cc_i387"
1573   [(set (reg:CCFP FLAGS_REG)
1574         (compare:CCFP
1575           (match_operand:X87MODEF 1 "register_operand" "f")
1576           (match_operator:X87MODEF 3 "float_operator"
1577             [(match_operand:SWI24 2 "memory_operand" "m")])))
1578    (clobber (match_operand:HI 0 "register_operand" "=a"))]
1579   "TARGET_80387 && TARGET_SAHF && !TARGET_CMOVE
1580    && (TARGET_USE_<SWI24:MODE>MODE_FIOP
1581        || optimize_function_for_size_p (cfun))"
1582   "#"
1583   "&& reload_completed"
1584   [(set (match_dup 0)
1585         (unspec:HI
1586           [(compare:CCFP
1587              (match_dup 1)
1588              (match_op_dup 3 [(match_dup 2)]))]
1589         UNSPEC_FNSTSW))
1590    (set (reg:CC FLAGS_REG)
1591         (unspec:CC [(match_dup 0)] UNSPEC_SAHF))]
1592   ""
1593   [(set_attr "type" "multi")
1594    (set_attr "unit" "i387")
1595    (set_attr "fp_int_src" "true")
1596    (set_attr "mode" "<SWI24:MODE>")])
1597
1598 ;; FP compares, step 2
1599 ;; Move the fpsw to ax.
1600
1601 (define_insn "x86_fnstsw_1"
1602   [(set (match_operand:HI 0 "register_operand" "=a")
1603         (unspec:HI [(reg:CCFP FPSR_REG)] UNSPEC_FNSTSW))]
1604   "TARGET_80387"
1605   "fnstsw\t%0"
1606   [(set_attr "length" "2")
1607    (set_attr "mode" "SI")
1608    (set_attr "unit" "i387")])
1609
1610 ;; FP compares, step 3
1611 ;; Get ax into flags, general case.
1612
1613 (define_insn "x86_sahf_1"
1614   [(set (reg:CC FLAGS_REG)
1615         (unspec:CC [(match_operand:HI 0 "register_operand" "a")]
1616                    UNSPEC_SAHF))]
1617   "TARGET_SAHF"
1618 {
1619 #ifndef HAVE_AS_IX86_SAHF
1620   if (TARGET_64BIT)
1621     return ASM_BYTE "0x9e";
1622   else
1623 #endif
1624   return "sahf";
1625 }
1626   [(set_attr "length" "1")
1627    (set_attr "athlon_decode" "vector")
1628    (set_attr "amdfam10_decode" "direct")
1629    (set_attr "bdver1_decode" "direct")
1630    (set_attr "mode" "SI")])
1631
1632 ;; Pentium Pro can do steps 1 through 3 in one go.
1633 ;; comi*, ucomi*, fcomi*, ficomi*, fucomi*
1634 ;; (these i387 instructions set flags directly)
1635
1636 (define_mode_iterator FPCMP [CCFP CCFPU])
1637 (define_mode_attr unord [(CCFP "") (CCFPU "u")])
1638
1639 (define_insn "*cmpi<FPCMP:unord><MODEF:mode>_mixed"
1640   [(set (reg:FPCMP FLAGS_REG)
1641         (compare:FPCMP
1642           (match_operand:MODEF 0 "register_operand" "f,x")
1643           (match_operand:MODEF 1 "nonimmediate_operand" "f,xm")))]
1644   "TARGET_MIX_SSE_I387
1645    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode)"
1646   "* return output_fp_compare (insn, operands, true,
1647                                <FPCMP:MODE>mode == CCFPUmode);"
1648   [(set_attr "type" "fcmp,ssecomi")
1649    (set_attr "prefix" "orig,maybe_vex")
1650    (set_attr "mode" "<MODEF:MODE>")
1651    (set (attr "prefix_rep")
1652         (if_then_else (eq_attr "type" "ssecomi")
1653                       (const_string "0")
1654                       (const_string "*")))
1655    (set (attr "prefix_data16")
1656         (cond [(eq_attr "type" "fcmp")
1657                  (const_string "*")
1658                (eq_attr "mode" "DF")
1659                  (const_string "1")
1660               ]
1661               (const_string "0")))
1662    (set_attr "athlon_decode" "vector")
1663    (set_attr "amdfam10_decode" "direct")
1664    (set_attr "bdver1_decode" "double")])
1665
1666 (define_insn "*cmpi<FPCMP:unord><MODEF:mode>_sse"
1667   [(set (reg:FPCMP FLAGS_REG)
1668         (compare:FPCMP
1669           (match_operand:MODEF 0 "register_operand" "x")
1670           (match_operand:MODEF 1 "nonimmediate_operand" "xm")))]
1671   "TARGET_SSE_MATH
1672    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode)"
1673   "* return output_fp_compare (insn, operands, true,
1674                                <FPCMP:MODE>mode == CCFPUmode);"
1675   [(set_attr "type" "ssecomi")
1676    (set_attr "prefix" "maybe_vex")
1677    (set_attr "mode" "<MODEF:MODE>")
1678    (set_attr "prefix_rep" "0")
1679    (set (attr "prefix_data16")
1680         (if_then_else (eq_attr "mode" "DF")
1681                       (const_string "1")
1682                       (const_string "0")))
1683    (set_attr "athlon_decode" "vector")
1684    (set_attr "amdfam10_decode" "direct")
1685    (set_attr "bdver1_decode" "double")])
1686
1687 (define_insn "*cmpi<FPCMP:unord><X87MODEF:mode>_i387"
1688   [(set (reg:FPCMP FLAGS_REG)
1689         (compare:FPCMP
1690           (match_operand:X87MODEF 0 "register_operand" "f")
1691           (match_operand:X87MODEF 1 "register_operand" "f")))]
1692   "TARGET_80387 && TARGET_CMOVE
1693    && !(SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH)"
1694   "* return output_fp_compare (insn, operands, true,
1695                                <FPCMP:MODE>mode == CCFPUmode);"
1696   [(set_attr "type" "fcmp")
1697    (set_attr "mode" "<X87MODEF:MODE>")
1698    (set_attr "athlon_decode" "vector")
1699    (set_attr "amdfam10_decode" "direct")
1700    (set_attr "bdver1_decode" "double")])
1701 \f
1702 ;; Push/pop instructions.
1703
1704 (define_insn "*push<mode>2"
1705   [(set (match_operand:DWI 0 "push_operand" "=<")
1706         (match_operand:DWI 1 "general_no_elim_operand" "riF*o"))]
1707   ""
1708   "#"
1709   [(set_attr "type" "multi")
1710    (set_attr "mode" "<MODE>")])
1711
1712 (define_split
1713   [(set (match_operand:TI 0 "push_operand")
1714         (match_operand:TI 1 "general_operand"))]
1715   "TARGET_64BIT && reload_completed
1716    && !SSE_REG_P (operands[1])"
1717   [(const_int 0)]
1718   "ix86_split_long_move (operands); DONE;")
1719
1720 (define_insn "*pushdi2_rex64"
1721   [(set (match_operand:DI 0 "push_operand" "=<,!<")
1722         (match_operand:DI 1 "general_no_elim_operand" "re*m,n"))]
1723   "TARGET_64BIT"
1724   "@
1725    push{q}\t%1
1726    #"
1727   [(set_attr "type" "push,multi")
1728    (set_attr "mode" "DI")])
1729
1730 ;; Convert impossible pushes of immediate to existing instructions.
1731 ;; First try to get scratch register and go through it.  In case this
1732 ;; fails, push sign extended lower part first and then overwrite
1733 ;; upper part by 32bit move.
1734 (define_peephole2
1735   [(match_scratch:DI 2 "r")
1736    (set (match_operand:DI 0 "push_operand")
1737         (match_operand:DI 1 "immediate_operand"))]
1738   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
1739    && !x86_64_immediate_operand (operands[1], DImode)"
1740   [(set (match_dup 2) (match_dup 1))
1741    (set (match_dup 0) (match_dup 2))])
1742
1743 ;; We need to define this as both peepholer and splitter for case
1744 ;; peephole2 pass is not run.
1745 ;; "&& 1" is needed to keep it from matching the previous pattern.
1746 (define_peephole2
1747   [(set (match_operand:DI 0 "push_operand")
1748         (match_operand:DI 1 "immediate_operand"))]
1749   "TARGET_64BIT && !symbolic_operand (operands[1], DImode)
1750    && !x86_64_immediate_operand (operands[1], DImode) && 1"
1751   [(set (match_dup 0) (match_dup 1))
1752    (set (match_dup 2) (match_dup 3))]
1753 {
1754   split_double_mode (DImode, &operands[1], 1, &operands[2], &operands[3]);
1755
1756   operands[1] = gen_lowpart (DImode, operands[2]);
1757   operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (Pmode, stack_pointer_rtx,
1758                                                    GEN_INT (4)));
1759 })
1760
1761 (define_split
1762   [(set (match_operand:DI 0 "push_operand")
1763         (match_operand:DI 1 "immediate_operand"))]
1764   "TARGET_64BIT && ((optimize > 0 && flag_peephole2)
1765                     ? epilogue_completed : reload_completed)
1766    && !symbolic_operand (operands[1], DImode)
1767    && !x86_64_immediate_operand (operands[1], DImode)"
1768   [(set (match_dup 0) (match_dup 1))
1769    (set (match_dup 2) (match_dup 3))]
1770 {
1771   split_double_mode (DImode, &operands[1], 1, &operands[2], &operands[3]);
1772
1773   operands[1] = gen_lowpart (DImode, operands[2]);
1774   operands[2] = gen_rtx_MEM (SImode, gen_rtx_PLUS (Pmode, stack_pointer_rtx,
1775                                                    GEN_INT (4)));
1776 })
1777
1778 (define_split
1779   [(set (match_operand:DI 0 "push_operand")
1780         (match_operand:DI 1 "general_operand"))]
1781   "!TARGET_64BIT && reload_completed
1782    && !(MMX_REG_P (operands[1]) || SSE_REG_P (operands[1]))"
1783   [(const_int 0)]
1784   "ix86_split_long_move (operands); DONE;")
1785
1786 (define_insn "*pushsi2"
1787   [(set (match_operand:SI 0 "push_operand" "=<")
1788         (match_operand:SI 1 "general_no_elim_operand" "ri*m"))]
1789   "!TARGET_64BIT"
1790   "push{l}\t%1"
1791   [(set_attr "type" "push")
1792    (set_attr "mode" "SI")])
1793
1794 ;; emit_push_insn when it calls move_by_pieces requires an insn to
1795 ;; "push a byte/word".  But actually we use pushl, which has the effect
1796 ;; of rounding the amount pushed up to a word.
1797
1798 ;; For TARGET_64BIT we always round up to 8 bytes.
1799 (define_insn "*push<mode>2_rex64"
1800   [(set (match_operand:SWI124 0 "push_operand" "=X")
1801         (match_operand:SWI124 1 "nonmemory_no_elim_operand" "r<i>"))]
1802   "TARGET_64BIT"
1803   "push{q}\t%q1"
1804   [(set_attr "type" "push")
1805    (set_attr "mode" "DI")])
1806
1807 (define_insn "*push<mode>2"
1808   [(set (match_operand:SWI12 0 "push_operand" "=X")
1809         (match_operand:SWI12 1 "nonmemory_no_elim_operand" "rn"))]
1810   "!TARGET_64BIT"
1811   "push{l}\t%k1"
1812   [(set_attr "type" "push")
1813    (set_attr "mode" "SI")])
1814
1815 (define_insn "*push<mode>2_prologue"
1816   [(set (match_operand:W 0 "push_operand" "=<")
1817         (match_operand:W 1 "general_no_elim_operand" "r<i>*m"))
1818    (clobber (mem:BLK (scratch)))]
1819   ""
1820   "push{<imodesuffix>}\t%1"
1821   [(set_attr "type" "push")
1822    (set_attr "mode" "<MODE>")])
1823
1824 (define_insn "*pop<mode>1"
1825   [(set (match_operand:W 0 "nonimmediate_operand" "=r*m")
1826         (match_operand:W 1 "pop_operand" ">"))]
1827   ""
1828   "pop{<imodesuffix>}\t%0"
1829   [(set_attr "type" "pop")
1830    (set_attr "mode" "<MODE>")])
1831
1832 (define_insn "*pop<mode>1_epilogue"
1833   [(set (match_operand:W 0 "nonimmediate_operand" "=r*m")
1834         (match_operand:W 1 "pop_operand" ">"))
1835    (clobber (mem:BLK (scratch)))]
1836   ""
1837   "pop{<imodesuffix>}\t%0"
1838   [(set_attr "type" "pop")
1839    (set_attr "mode" "<MODE>")])
1840
1841 (define_insn "*pushfl<mode>2"
1842   [(set (match_operand:W 0 "push_operand" "=<")
1843         (match_operand:W 1 "flags_reg_operand"))]
1844   ""
1845   "pushf{<imodesuffix>}"
1846   [(set_attr "type" "push")
1847    (set_attr "mode" "<MODE>")])
1848
1849 (define_insn "*popfl<mode>1"
1850   [(set (match_operand:W 0 "flags_reg_operand")
1851         (match_operand:W 1 "pop_operand" ">"))]
1852   ""
1853   "popf{<imodesuffix>}"
1854   [(set_attr "type" "pop")
1855    (set_attr "mode" "<MODE>")])
1856
1857 \f
1858 ;; Move instructions.
1859
1860 (define_expand "movxi"
1861   [(set (match_operand:XI 0 "nonimmediate_operand")
1862         (match_operand:XI 1 "general_operand"))]
1863   "TARGET_AVX512F"
1864   "ix86_expand_move (XImode, operands); DONE;")
1865
1866 ;; Reload patterns to support multi-word load/store
1867 ;; with non-offsetable address.
1868 (define_expand "reload_noff_store"
1869   [(parallel [(match_operand 0 "memory_operand" "=m")
1870               (match_operand 1 "register_operand" "r")
1871               (match_operand:DI 2 "register_operand" "=&r")])]
1872   "TARGET_64BIT"
1873 {
1874   rtx mem = operands[0];
1875   rtx addr = XEXP (mem, 0);
1876
1877   emit_move_insn (operands[2], addr);
1878   mem = replace_equiv_address_nv (mem, operands[2]);
1879
1880   emit_insn (gen_rtx_SET (VOIDmode, mem, operands[1]));
1881   DONE;
1882 })
1883
1884 (define_expand "reload_noff_load"
1885   [(parallel [(match_operand 0 "register_operand" "=r")
1886               (match_operand 1 "memory_operand" "m")
1887               (match_operand:DI 2 "register_operand" "=r")])]
1888   "TARGET_64BIT"
1889 {
1890   rtx mem = operands[1];
1891   rtx addr = XEXP (mem, 0);
1892
1893   emit_move_insn (operands[2], addr);
1894   mem = replace_equiv_address_nv (mem, operands[2]);
1895
1896   emit_insn (gen_rtx_SET (VOIDmode, operands[0], mem));
1897   DONE;
1898 })
1899
1900 (define_expand "movoi"
1901   [(set (match_operand:OI 0 "nonimmediate_operand")
1902         (match_operand:OI 1 "general_operand"))]
1903   "TARGET_AVX"
1904   "ix86_expand_move (OImode, operands); DONE;")
1905
1906 (define_expand "movti"
1907   [(set (match_operand:TI 0 "nonimmediate_operand")
1908         (match_operand:TI 1 "nonimmediate_operand"))]
1909   "TARGET_64BIT || TARGET_SSE"
1910 {
1911   if (TARGET_64BIT)
1912     ix86_expand_move (TImode, operands);
1913   else
1914     ix86_expand_vector_move (TImode, operands);
1915   DONE;
1916 })
1917
1918 ;; This expands to what emit_move_complex would generate if we didn't
1919 ;; have a movti pattern.  Having this avoids problems with reload on
1920 ;; 32-bit targets when SSE is present, but doesn't seem to be harmful
1921 ;; to have around all the time.
1922 (define_expand "movcdi"
1923   [(set (match_operand:CDI 0 "nonimmediate_operand")
1924         (match_operand:CDI 1 "general_operand"))]
1925   ""
1926 {
1927   if (push_operand (operands[0], CDImode))
1928     emit_move_complex_push (CDImode, operands[0], operands[1]);
1929   else
1930     emit_move_complex_parts (operands[0], operands[1]);
1931   DONE;
1932 })
1933
1934 (define_expand "mov<mode>"
1935   [(set (match_operand:SWI1248x 0 "nonimmediate_operand")
1936         (match_operand:SWI1248x 1 "general_operand"))]
1937   ""
1938   "ix86_expand_move (<MODE>mode, operands); DONE;")
1939
1940 (define_insn "*mov<mode>_xor"
1941   [(set (match_operand:SWI48 0 "register_operand" "=r")
1942         (match_operand:SWI48 1 "const0_operand"))
1943    (clobber (reg:CC FLAGS_REG))]
1944   "reload_completed"
1945   "xor{l}\t%k0, %k0"
1946   [(set_attr "type" "alu1")
1947    (set_attr "mode" "SI")
1948    (set_attr "length_immediate" "0")])
1949
1950 (define_insn "*mov<mode>_or"
1951   [(set (match_operand:SWI48 0 "register_operand" "=r")
1952         (match_operand:SWI48 1 "const_int_operand"))
1953    (clobber (reg:CC FLAGS_REG))]
1954   "reload_completed
1955    && operands[1] == constm1_rtx"
1956   "or{<imodesuffix>}\t{%1, %0|%0, %1}"
1957   [(set_attr "type" "alu1")
1958    (set_attr "mode" "<MODE>")
1959    (set_attr "length_immediate" "1")])
1960
1961 (define_insn "*movxi_internal_avx512f"
1962   [(set (match_operand:XI 0 "nonimmediate_operand" "=x,x ,m")
1963         (match_operand:XI 1 "vector_move_operand"  "C ,xm,x"))]
1964   "TARGET_AVX512F && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1965 {
1966   switch (which_alternative)
1967     {
1968     case 0:
1969       return standard_sse_constant_opcode (insn, operands[1]);
1970     case 1:
1971     case 2:
1972       if (misaligned_operand (operands[0], XImode)
1973           || misaligned_operand (operands[1], XImode))
1974         return "vmovdqu32\t{%1, %0|%0, %1}";
1975       else
1976         return "vmovdqa32\t{%1, %0|%0, %1}";
1977     default:
1978       gcc_unreachable ();
1979     }
1980 }
1981   [(set_attr "type" "sselog1,ssemov,ssemov")
1982    (set_attr "prefix" "evex")
1983    (set_attr "mode" "XI")])
1984
1985 (define_insn "*movoi_internal_avx"
1986   [(set (match_operand:OI 0 "nonimmediate_operand" "=v,v ,m")
1987         (match_operand:OI 1 "vector_move_operand"  "C ,vm,v"))]
1988   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
1989 {
1990   switch (get_attr_type (insn))
1991     {
1992     case TYPE_SSELOG1:
1993       return standard_sse_constant_opcode (insn, operands[1]);
1994
1995     case TYPE_SSEMOV:
1996       if (misaligned_operand (operands[0], OImode)
1997           || misaligned_operand (operands[1], OImode))
1998         {
1999           if (get_attr_mode (insn) == MODE_V8SF)
2000             return "vmovups\t{%1, %0|%0, %1}";
2001           else if (get_attr_mode (insn) == MODE_XI)
2002             return "vmovdqu32\t{%1, %0|%0, %1}";
2003           else
2004             return "vmovdqu\t{%1, %0|%0, %1}";
2005         }
2006       else
2007         {
2008           if (get_attr_mode (insn) == MODE_V8SF)
2009             return "vmovaps\t{%1, %0|%0, %1}";
2010           else if (get_attr_mode (insn) == MODE_XI)
2011             return "vmovdqa32\t{%1, %0|%0, %1}";
2012           else
2013             return "vmovdqa\t{%1, %0|%0, %1}";
2014         }
2015
2016     default:
2017       gcc_unreachable ();
2018     }
2019 }
2020   [(set_attr "type" "sselog1,ssemov,ssemov")
2021    (set_attr "prefix" "vex")
2022    (set (attr "mode")
2023         (cond [(ior (match_operand 0 "ext_sse_reg_operand")
2024                     (match_operand 1 "ext_sse_reg_operand"))
2025                  (const_string "XI")
2026                (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
2027                  (const_string "V8SF")
2028                (and (eq_attr "alternative" "2")
2029                     (match_test "TARGET_SSE_TYPELESS_STORES"))
2030                  (const_string "V8SF")
2031               ]
2032               (const_string "OI")))])
2033
2034 (define_insn "*movti_internal"
2035   [(set (match_operand:TI 0 "nonimmediate_operand" "=!r ,o ,v,v ,m")
2036         (match_operand:TI 1 "general_operand"      "riFo,re,C,vm,v"))]
2037   "(TARGET_64BIT || TARGET_SSE)
2038    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2039 {
2040   switch (get_attr_type (insn))
2041     {
2042     case TYPE_MULTI:
2043       return "#";
2044
2045     case TYPE_SSELOG1:
2046       return standard_sse_constant_opcode (insn, operands[1]);
2047
2048     case TYPE_SSEMOV:
2049       /* TDmode values are passed as TImode on the stack.  Moving them
2050          to stack may result in unaligned memory access.  */
2051       if (misaligned_operand (operands[0], TImode)
2052           || misaligned_operand (operands[1], TImode))
2053         {
2054           if (get_attr_mode (insn) == MODE_V4SF)
2055             return "%vmovups\t{%1, %0|%0, %1}";
2056           else if (get_attr_mode (insn) == MODE_XI)
2057             return "vmovdqu32\t{%1, %0|%0, %1}";
2058           else
2059             return "%vmovdqu\t{%1, %0|%0, %1}";
2060         }
2061       else
2062         {
2063           if (get_attr_mode (insn) == MODE_V4SF)
2064             return "%vmovaps\t{%1, %0|%0, %1}";
2065           else if (get_attr_mode (insn) == MODE_XI)
2066             return "vmovdqa32\t{%1, %0|%0, %1}";
2067           else
2068             return "%vmovdqa\t{%1, %0|%0, %1}";
2069         }
2070
2071     default:
2072       gcc_unreachable ();
2073     }
2074 }
2075   [(set_attr "isa" "x64,x64,*,*,*")
2076    (set_attr "type" "multi,multi,sselog1,ssemov,ssemov")
2077    (set (attr "prefix")
2078      (if_then_else (eq_attr "type" "sselog1,ssemov")
2079        (const_string "maybe_vex")
2080        (const_string "orig")))
2081    (set (attr "mode")
2082         (cond [(ior (match_operand 0 "ext_sse_reg_operand")
2083                     (match_operand 1 "ext_sse_reg_operand"))
2084                  (const_string "XI")
2085                (eq_attr "alternative" "0,1")
2086                  (const_string "DI")
2087                (ior (not (match_test "TARGET_SSE2"))
2088                     (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
2089                  (const_string "V4SF")
2090                (and (eq_attr "alternative" "4")
2091                     (match_test "TARGET_SSE_TYPELESS_STORES"))
2092                  (const_string "V4SF")
2093                (match_test "TARGET_AVX")
2094                  (const_string "TI")
2095                (match_test "optimize_function_for_size_p (cfun)")
2096                  (const_string "V4SF")
2097                ]
2098                (const_string "TI")))])
2099
2100 (define_split
2101   [(set (match_operand:TI 0 "nonimmediate_operand")
2102         (match_operand:TI 1 "general_operand"))]
2103   "reload_completed
2104    && !SSE_REG_P (operands[0]) && !SSE_REG_P (operands[1])"
2105   [(const_int 0)]
2106   "ix86_split_long_move (operands); DONE;")
2107
2108 (define_insn "*movdi_internal"
2109   [(set (match_operand:DI 0 "nonimmediate_operand"
2110     "=r  ,o  ,r,r  ,r,m ,*y,*y,?*y,?m,?r ,?*Ym,*v,*v,*v,m ,?r ,?r,?*Yi,?*Ym,?*Yi,*k,*k ,*r ,*m")
2111         (match_operand:DI 1 "general_operand"
2112     "riFo,riF,Z,rem,i,re,C ,*y,m  ,*y,*Yn,r   ,C ,*v,m ,*v,*Yj,*v,r   ,*Yj ,*Yn ,*r ,*km,*k,*k"))]
2113   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2114 {
2115   switch (get_attr_type (insn))
2116     {
2117     case TYPE_MSKMOV:
2118       return "kmovq\t{%1, %0|%0, %1}";
2119
2120     case TYPE_MULTI:
2121       return "#";
2122
2123     case TYPE_MMX:
2124       return "pxor\t%0, %0";
2125
2126     case TYPE_MMXMOV:
2127       /* Handle broken assemblers that require movd instead of movq.  */
2128       if (!HAVE_AS_IX86_INTERUNIT_MOVQ
2129           && (GENERAL_REG_P (operands[0]) || GENERAL_REG_P (operands[1])))
2130         return "movd\t{%1, %0|%0, %1}";
2131       return "movq\t{%1, %0|%0, %1}";
2132
2133     case TYPE_SSELOG1:
2134       if (GENERAL_REG_P (operands[0]))
2135         return "%vpextrq\t{$0, %1, %0|%0, %1, 0}";
2136
2137       return standard_sse_constant_opcode (insn, operands[1]);
2138
2139     case TYPE_SSEMOV:
2140       switch (get_attr_mode (insn))
2141         {
2142         case MODE_DI:
2143           /* Handle broken assemblers that require movd instead of movq.  */
2144           if (!HAVE_AS_IX86_INTERUNIT_MOVQ
2145               && (GENERAL_REG_P (operands[0]) || GENERAL_REG_P (operands[1])))
2146             return "%vmovd\t{%1, %0|%0, %1}";
2147           return "%vmovq\t{%1, %0|%0, %1}";
2148         case MODE_TI:
2149           return "%vmovdqa\t{%1, %0|%0, %1}";
2150         case MODE_XI:
2151           return "vmovdqa64\t{%g1, %g0|%g0, %g1}";
2152
2153         case MODE_V2SF:
2154           gcc_assert (!TARGET_AVX);
2155           return "movlps\t{%1, %0|%0, %1}";
2156         case MODE_V4SF:
2157           return "%vmovaps\t{%1, %0|%0, %1}";
2158
2159         default:
2160           gcc_unreachable ();
2161         }
2162
2163     case TYPE_SSECVT:
2164       if (SSE_REG_P (operands[0]))
2165         return "movq2dq\t{%1, %0|%0, %1}";
2166       else
2167         return "movdq2q\t{%1, %0|%0, %1}";
2168
2169     case TYPE_LEA:
2170       return "lea{q}\t{%E1, %0|%0, %E1}";
2171
2172     case TYPE_IMOV:
2173       gcc_assert (!flag_pic || LEGITIMATE_PIC_OPERAND_P (operands[1]));
2174       if (get_attr_mode (insn) == MODE_SI)
2175         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2176       else if (which_alternative == 4)
2177         return "movabs{q}\t{%1, %0|%0, %1}";
2178       else if (ix86_use_lea_for_mov (insn, operands))
2179         return "lea{q}\t{%E1, %0|%0, %E1}";
2180       else
2181         return "mov{q}\t{%1, %0|%0, %1}";
2182
2183     default:
2184       gcc_unreachable ();
2185     }
2186 }
2187   [(set (attr "isa")
2188      (cond [(eq_attr "alternative" "0,1")
2189               (const_string "nox64")
2190             (eq_attr "alternative" "2,3,4,5,10,11,16,18,21,23")
2191               (const_string "x64")
2192             (eq_attr "alternative" "17")
2193               (const_string "x64_sse4")
2194            ]
2195            (const_string "*")))
2196    (set (attr "type")
2197      (cond [(eq_attr "alternative" "0,1")
2198               (const_string "multi")
2199             (eq_attr "alternative" "6")
2200               (const_string "mmx")
2201             (eq_attr "alternative" "7,8,9,10,11")
2202               (const_string "mmxmov")
2203             (eq_attr "alternative" "12,17")
2204               (const_string "sselog1")
2205             (eq_attr "alternative" "13,14,15,16,18")
2206               (const_string "ssemov")
2207             (eq_attr "alternative" "19,20")
2208               (const_string "ssecvt")
2209             (eq_attr "alternative" "21,22,23,24")
2210               (const_string "mskmov")
2211             (and (match_operand 0 "register_operand")
2212                  (match_operand 1 "pic_32bit_operand"))
2213               (const_string "lea")
2214            ]
2215            (const_string "imov")))
2216    (set (attr "modrm")
2217      (if_then_else
2218        (and (eq_attr "alternative" "4") (eq_attr "type" "imov"))
2219          (const_string "0")
2220          (const_string "*")))
2221    (set (attr "length_immediate")
2222      (cond [(and (eq_attr "alternative" "4") (eq_attr "type" "imov"))
2223               (const_string "8")
2224             (eq_attr "alternative" "17")
2225               (const_string "1")
2226            ]
2227            (const_string "*")))
2228    (set (attr "prefix_rex")
2229      (if_then_else (eq_attr "alternative" "10,11,16,17,18")
2230        (const_string "1")
2231        (const_string "*")))
2232    (set (attr "prefix_extra")
2233      (if_then_else (eq_attr "alternative" "17")
2234        (const_string "1")
2235        (const_string "*")))
2236    (set (attr "prefix")
2237      (if_then_else (eq_attr "type" "sselog1,ssemov")
2238        (const_string "maybe_vex")
2239        (const_string "orig")))
2240    (set (attr "prefix_data16")
2241      (if_then_else (and (eq_attr "type" "ssemov") (eq_attr "mode" "DI"))
2242        (const_string "1")
2243        (const_string "*")))
2244    (set (attr "mode")
2245      (cond [(eq_attr "alternative" "2")
2246               (const_string "SI")
2247             (eq_attr "alternative" "12,13")
2248               (cond [(ior (match_operand 0 "ext_sse_reg_operand")
2249                           (match_operand 1 "ext_sse_reg_operand"))
2250                        (const_string "XI")
2251                      (ior (not (match_test "TARGET_SSE2"))
2252                           (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
2253                        (const_string "V4SF")
2254                      (match_test "TARGET_AVX")
2255                        (const_string "TI")
2256                      (match_test "optimize_function_for_size_p (cfun)")
2257                        (const_string "V4SF")
2258                     ]
2259                     (const_string "TI"))
2260
2261             (and (eq_attr "alternative" "14,15")
2262                  (not (match_test "TARGET_SSE2")))
2263               (const_string "V2SF")
2264             (eq_attr "alternative" "17")
2265               (const_string "TI")
2266            ]
2267            (const_string "DI")))])
2268
2269 (define_split
2270   [(set (match_operand:DI 0 "nonimmediate_operand")
2271         (match_operand:DI 1 "general_operand"))]
2272   "!TARGET_64BIT && reload_completed
2273    && !(MMX_REG_P (operands[0])
2274         || SSE_REG_P (operands[0])
2275         || MASK_REG_P (operands[0]))
2276    && !(MMX_REG_P (operands[1])
2277         || SSE_REG_P (operands[1])
2278         || MASK_REG_P (operands[1]))"
2279   [(const_int 0)]
2280   "ix86_split_long_move (operands); DONE;")
2281
2282 (define_insn "*movsi_internal"
2283   [(set (match_operand:SI 0 "nonimmediate_operand"
2284                         "=r,m ,*y,*y,?rm,?*y,*v,*v,*v,m ,?r ,?r,?*Yi,*k  ,*rm")
2285         (match_operand:SI 1 "general_operand"
2286                         "g ,re,C ,*y,*y ,rm ,C ,*v,m ,*v,*Yj,*v,r   ,*krm,*k"))]
2287   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2288 {
2289   switch (get_attr_type (insn))
2290     {
2291     case TYPE_SSELOG1:
2292       if (GENERAL_REG_P (operands[0]))
2293         return "%vpextrd\t{$0, %1, %0|%0, %1, 0}";
2294
2295       return standard_sse_constant_opcode (insn, operands[1]);
2296
2297     case TYPE_MSKMOV:
2298       return "kmovd\t{%1, %0|%0, %1}";
2299
2300     case TYPE_SSEMOV:
2301       switch (get_attr_mode (insn))
2302         {
2303         case MODE_SI:
2304           return "%vmovd\t{%1, %0|%0, %1}";
2305         case MODE_TI:
2306           return "%vmovdqa\t{%1, %0|%0, %1}";
2307         case MODE_XI:
2308           return "vmovdqa32\t{%g1, %g0|%g0, %g1}";
2309
2310         case MODE_V4SF:
2311           return "%vmovaps\t{%1, %0|%0, %1}";
2312
2313         case MODE_SF:
2314           gcc_assert (!TARGET_AVX);
2315           return "movss\t{%1, %0|%0, %1}";
2316
2317         default:
2318           gcc_unreachable ();
2319         }
2320
2321     case TYPE_MMX:
2322       return "pxor\t%0, %0";
2323
2324     case TYPE_MMXMOV:
2325       switch (get_attr_mode (insn))
2326         {
2327         case MODE_DI:
2328           return "movq\t{%1, %0|%0, %1}";
2329         case MODE_SI:
2330           return "movd\t{%1, %0|%0, %1}";
2331
2332         default:
2333           gcc_unreachable ();
2334         }
2335
2336     case TYPE_LEA:
2337       return "lea{l}\t{%E1, %0|%0, %E1}";
2338
2339     case TYPE_IMOV:
2340       gcc_assert (!flag_pic || LEGITIMATE_PIC_OPERAND_P (operands[1]));
2341       if (ix86_use_lea_for_mov (insn, operands))
2342         return "lea{l}\t{%E1, %0|%0, %E1}";
2343       else
2344         return "mov{l}\t{%1, %0|%0, %1}";
2345
2346     default:
2347       gcc_unreachable ();
2348     }
2349 }
2350   [(set (attr "isa")
2351      (if_then_else (eq_attr "alternative" "11")
2352        (const_string "sse4")
2353        (const_string "*")))
2354    (set (attr "type")
2355      (cond [(eq_attr "alternative" "2")
2356               (const_string "mmx")
2357             (eq_attr "alternative" "3,4,5")
2358               (const_string "mmxmov")
2359             (eq_attr "alternative" "6,11")
2360               (const_string "sselog1")
2361             (eq_attr "alternative" "7,8,9,10,12")
2362               (const_string "ssemov")
2363             (eq_attr "alternative" "13,14")
2364               (const_string "mskmov")
2365             (and (match_operand 0 "register_operand")
2366                  (match_operand 1 "pic_32bit_operand"))
2367               (const_string "lea")
2368            ]
2369            (const_string "imov")))
2370    (set (attr "length_immediate")
2371      (if_then_else (eq_attr "alternative" "11")
2372        (const_string "1")
2373        (const_string "*")))
2374    (set (attr "prefix_extra")
2375      (if_then_else (eq_attr "alternative" "11")
2376        (const_string "1")
2377        (const_string "*")))
2378    (set (attr "prefix")
2379      (if_then_else (eq_attr "type" "sselog1,ssemov")
2380        (const_string "maybe_vex")
2381        (const_string "orig")))
2382    (set (attr "prefix_data16")
2383      (if_then_else (and (eq_attr "type" "ssemov") (eq_attr "mode" "SI"))
2384        (const_string "1")
2385        (const_string "*")))
2386    (set (attr "mode")
2387      (cond [(eq_attr "alternative" "2,3")
2388               (const_string "DI")
2389             (eq_attr "alternative" "6,7")
2390               (cond [(ior (match_operand 0 "ext_sse_reg_operand")
2391                           (match_operand 1 "ext_sse_reg_operand"))
2392                        (const_string "XI")
2393                      (ior (not (match_test "TARGET_SSE2"))
2394                           (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
2395                        (const_string "V4SF")
2396                      (match_test "TARGET_AVX")
2397                        (const_string "TI")
2398                      (match_test "optimize_function_for_size_p (cfun)")
2399                        (const_string "V4SF")
2400                     ]
2401                     (const_string "TI"))
2402
2403             (and (eq_attr "alternative" "8,9")
2404                  (not (match_test "TARGET_SSE2")))
2405               (const_string "SF")
2406             (eq_attr "alternative" "11")
2407               (const_string "TI")
2408            ]
2409            (const_string "SI")))])
2410
2411 (define_insn "kmovw"
2412   [(set (match_operand:HI 0 "nonimmediate_operand" "=k,k")
2413         (unspec:HI
2414           [(match_operand:HI 1 "nonimmediate_operand" "rm,k")]
2415           UNSPEC_KMOV))]
2416   "!(MEM_P (operands[0]) && MEM_P (operands[1])) && TARGET_AVX512F"
2417   "@
2418    kmovw\t{%k1, %0|%0, %k1}
2419    kmovw\t{%1, %0|%0, %1}";
2420   [(set_attr "mode" "HI")
2421    (set_attr "type" "mskmov")
2422    (set_attr "prefix" "vex")])
2423
2424
2425 (define_insn "*movhi_internal"
2426   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r ,r ,m ,k,k,rm")
2427         (match_operand:HI 1 "general_operand"      "r ,rn,rm,rn,rm,k,k"))]
2428   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2429 {
2430   switch (get_attr_type (insn))
2431     {
2432     case TYPE_IMOVX:
2433       /* movzwl is faster than movw on p2 due to partial word stalls,
2434          though not as fast as an aligned movl.  */
2435       return "movz{wl|x}\t{%1, %k0|%k0, %1}";
2436
2437     case TYPE_MSKMOV:
2438       switch (which_alternative)
2439         {
2440         case 4: return "kmovw\t{%k1, %0|%0, %k1}";
2441         case 5: return "kmovw\t{%1, %0|%0, %1}";
2442         case 6: return "kmovw\t{%1, %k0|%k0, %1}";
2443         default: gcc_unreachable ();
2444         }
2445
2446     default:
2447       if (get_attr_mode (insn) == MODE_SI)
2448         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2449       else
2450         return "mov{w}\t{%1, %0|%0, %1}";
2451     }
2452 }
2453   [(set (attr "type")
2454      (cond [(eq_attr "alternative" "4,5,6")
2455               (const_string "mskmov")
2456             (match_test "optimize_function_for_size_p (cfun)")
2457               (const_string "imov")
2458             (and (eq_attr "alternative" "0")
2459                  (ior (not (match_test "TARGET_PARTIAL_REG_STALL"))
2460                       (not (match_test "TARGET_HIMODE_MATH"))))
2461               (const_string "imov")
2462             (and (eq_attr "alternative" "1,2")
2463                  (match_operand:HI 1 "aligned_operand"))
2464               (const_string "imov")
2465             (and (match_test "TARGET_MOVX")
2466                  (eq_attr "alternative" "0,2"))
2467               (const_string "imovx")
2468            ]
2469            (const_string "imov")))
2470     (set (attr "prefix")
2471       (if_then_else (eq_attr "alternative" "4,5,6")
2472         (const_string "vex")
2473         (const_string "orig")))
2474     (set (attr "mode")
2475       (cond [(eq_attr "type" "imovx")
2476                (const_string "SI")
2477              (and (eq_attr "alternative" "1,2")
2478                   (match_operand:HI 1 "aligned_operand"))
2479                (const_string "SI")
2480              (and (eq_attr "alternative" "0")
2481                   (ior (not (match_test "TARGET_PARTIAL_REG_STALL"))
2482                        (not (match_test "TARGET_HIMODE_MATH"))))
2483                (const_string "SI")
2484             ]
2485             (const_string "HI")))])
2486
2487 ;; Situation is quite tricky about when to choose full sized (SImode) move
2488 ;; over QImode moves.  For Q_REG -> Q_REG move we use full size only for
2489 ;; partial register dependency machines (such as AMD Athlon), where QImode
2490 ;; moves issue extra dependency and for partial register stalls machines
2491 ;; that don't use QImode patterns (and QImode move cause stall on the next
2492 ;; instruction).
2493 ;;
2494 ;; For loads of Q_REG to NONQ_REG we use full sized moves except for partial
2495 ;; register stall machines with, where we use QImode instructions, since
2496 ;; partial register stall can be caused there.  Then we use movzx.
2497
2498 (define_insn "*movqi_internal"
2499   [(set (match_operand:QI 0 "nonimmediate_operand"
2500                         "=q,q ,q ,r,r ,?r,m ,k,k,r ,m,k")
2501         (match_operand:QI 1 "general_operand"
2502                         "q ,qn,qm,q,rn,qm,qn,r ,k,k,k,m"))]
2503   "!(MEM_P (operands[0]) && MEM_P (operands[1]))"
2504 {
2505   switch (get_attr_type (insn))
2506     {
2507     case TYPE_IMOVX:
2508       gcc_assert (ANY_QI_REG_P (operands[1]) || MEM_P (operands[1]));
2509       return "movz{bl|x}\t{%1, %k0|%k0, %1}";
2510
2511     case TYPE_MSKMOV:
2512       switch (which_alternative)
2513         {
2514         case 7: return TARGET_AVX512DQ ? "kmovb\t{%k1, %0|%0, %k1}"
2515                                        : "kmovw\t{%k1, %0|%0, %k1}";
2516         case 8: return TARGET_AVX512DQ ? "kmovb\t{%1, %0|%0, %1}"
2517                                        : "kmovw\t{%1, %0|%0, %1}";
2518         case 9: return TARGET_AVX512DQ ? "kmovb\t{%1, %k0|%k0, %1}"
2519                                        : "kmovw\t{%1, %k0|%k0, %1}";
2520         case 10:
2521         case 11:
2522           gcc_assert (TARGET_AVX512DQ);
2523           return "kmovb\t{%1, %0|%0, %1}";
2524         default: gcc_unreachable ();
2525         }
2526
2527     default:
2528       if (get_attr_mode (insn) == MODE_SI)
2529         return "mov{l}\t{%k1, %k0|%k0, %k1}";
2530       else
2531         return "mov{b}\t{%1, %0|%0, %1}";
2532     }
2533 }
2534   [(set_attr "isa" "*,*,*,*,*,*,*,*,*,*,avx512dq,avx512dq")
2535    (set (attr "type")
2536      (cond [(eq_attr "alternative" "3,5")
2537               (const_string "imovx")
2538             (eq_attr "alternative" "7,8,9,10,11")
2539               (const_string "mskmov")
2540             (and (eq_attr "alternative" "5")
2541                  (not (match_operand:QI 1 "aligned_operand")))
2542               (const_string "imovx")
2543             (match_test "optimize_function_for_size_p (cfun)")
2544               (const_string "imov")
2545             (and (eq_attr "alternative" "3")
2546                  (ior (not (match_test "TARGET_PARTIAL_REG_STALL"))
2547                       (not (match_test "TARGET_QIMODE_MATH"))))
2548               (const_string "imov")
2549             (and (match_test "TARGET_MOVX")
2550                  (eq_attr "alternative" "2"))
2551               (const_string "imovx")
2552            ]
2553            (const_string "imov")))
2554    (set (attr "prefix")
2555      (if_then_else (eq_attr "alternative" "7,8,9")
2556        (const_string "vex")
2557        (const_string "orig")))
2558    (set (attr "mode")
2559       (cond [(eq_attr "alternative" "3,4,5")
2560                (const_string "SI")
2561              (eq_attr "alternative" "6")
2562                (const_string "QI")
2563              (eq_attr "type" "imovx")
2564                (const_string "SI")
2565              (and (eq_attr "type" "imov")
2566                   (and (eq_attr "alternative" "0,1")
2567                        (and (match_test "TARGET_PARTIAL_REG_DEPENDENCY")
2568                             (and (not (match_test "optimize_function_for_size_p (cfun)"))
2569                                  (not (match_test "TARGET_PARTIAL_REG_STALL"))))))
2570                (const_string "SI")
2571              ;; Avoid partial register stalls when not using QImode arithmetic
2572              (and (eq_attr "type" "imov")
2573                   (and (eq_attr "alternative" "0,1")
2574                        (and (match_test "TARGET_PARTIAL_REG_STALL")
2575                             (not (match_test "TARGET_QIMODE_MATH")))))
2576                (const_string "SI")
2577            ]
2578            (const_string "QI")))])
2579
2580 ;; Stores and loads of ax to arbitrary constant address.
2581 ;; We fake an second form of instruction to force reload to load address
2582 ;; into register when rax is not available
2583 (define_insn "*movabs<mode>_1"
2584   [(set (mem:SWI1248x (match_operand:DI 0 "x86_64_movabs_operand" "i,r"))
2585         (match_operand:SWI1248x 1 "nonmemory_operand" "a,r<i>"))]
2586   "TARGET_LP64 && ix86_check_movabs (insn, 0)"
2587   "@
2588    movabs{<imodesuffix>}\t{%1, %P0|[%P0], %1}
2589    mov{<imodesuffix>}\t{%1, %a0|<iptrsize> PTR %a0, %1}"
2590   [(set_attr "type" "imov")
2591    (set_attr "modrm" "0,*")
2592    (set_attr "length_address" "8,0")
2593    (set_attr "length_immediate" "0,*")
2594    (set_attr "memory" "store")
2595    (set_attr "mode" "<MODE>")])
2596
2597 (define_insn "*movabs<mode>_2"
2598   [(set (match_operand:SWI1248x 0 "register_operand" "=a,r")
2599         (mem:SWI1248x (match_operand:DI 1 "x86_64_movabs_operand" "i,r")))]
2600   "TARGET_LP64 && ix86_check_movabs (insn, 1)"
2601   "@
2602    movabs{<imodesuffix>}\t{%P1, %0|%0, [%P1]}
2603    mov{<imodesuffix>}\t{%a1, %0|%0, <iptrsize> PTR %a1}"
2604   [(set_attr "type" "imov")
2605    (set_attr "modrm" "0,*")
2606    (set_attr "length_address" "8,0")
2607    (set_attr "length_immediate" "0")
2608    (set_attr "memory" "load")
2609    (set_attr "mode" "<MODE>")])
2610
2611 (define_insn "*swap<mode>"
2612   [(set (match_operand:SWI48 0 "register_operand" "+r")
2613         (match_operand:SWI48 1 "register_operand" "+r"))
2614    (set (match_dup 1)
2615         (match_dup 0))]
2616   ""
2617   "xchg{<imodesuffix>}\t%1, %0"
2618   [(set_attr "type" "imov")
2619    (set_attr "mode" "<MODE>")
2620    (set_attr "pent_pair" "np")
2621    (set_attr "athlon_decode" "vector")
2622    (set_attr "amdfam10_decode" "double")
2623    (set_attr "bdver1_decode" "double")])
2624
2625 (define_insn "*swap<mode>_1"
2626   [(set (match_operand:SWI12 0 "register_operand" "+r")
2627         (match_operand:SWI12 1 "register_operand" "+r"))
2628    (set (match_dup 1)
2629         (match_dup 0))]
2630   "!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)"
2631   "xchg{l}\t%k1, %k0"
2632   [(set_attr "type" "imov")
2633    (set_attr "mode" "SI")
2634    (set_attr "pent_pair" "np")
2635    (set_attr "athlon_decode" "vector")
2636    (set_attr "amdfam10_decode" "double")
2637    (set_attr "bdver1_decode" "double")])
2638
2639 ;; Not added amdfam10_decode since TARGET_PARTIAL_REG_STALL
2640 ;; is disabled for AMDFAM10
2641 (define_insn "*swap<mode>_2"
2642   [(set (match_operand:SWI12 0 "register_operand" "+<r>")
2643         (match_operand:SWI12 1 "register_operand" "+<r>"))
2644    (set (match_dup 1)
2645         (match_dup 0))]
2646   "TARGET_PARTIAL_REG_STALL"
2647   "xchg{<imodesuffix>}\t%1, %0"
2648   [(set_attr "type" "imov")
2649    (set_attr "mode" "<MODE>")
2650    (set_attr "pent_pair" "np")
2651    (set_attr "athlon_decode" "vector")])
2652
2653 (define_expand "movstrict<mode>"
2654   [(set (strict_low_part (match_operand:SWI12 0 "nonimmediate_operand"))
2655         (match_operand:SWI12 1 "general_operand"))]
2656   ""
2657 {
2658   if (TARGET_PARTIAL_REG_STALL && optimize_function_for_speed_p (cfun))
2659     FAIL;
2660   if (GET_CODE (operands[0]) == SUBREG
2661       && GET_MODE_CLASS (GET_MODE (SUBREG_REG (operands[0]))) != MODE_INT)
2662     FAIL;
2663   /* Don't generate memory->memory moves, go through a register */
2664   if (MEM_P (operands[0]) && MEM_P (operands[1]))
2665     operands[1] = force_reg (<MODE>mode, operands[1]);
2666 })
2667
2668 (define_insn "*movstrict<mode>_1"
2669   [(set (strict_low_part
2670           (match_operand:SWI12 0 "nonimmediate_operand" "+<r>m,<r>"))
2671         (match_operand:SWI12 1 "general_operand" "<r>n,m"))]
2672   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
2673    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
2674   "mov{<imodesuffix>}\t{%1, %0|%0, %1}"
2675   [(set_attr "type" "imov")
2676    (set_attr "mode" "<MODE>")])
2677
2678 (define_insn "*movstrict<mode>_xor"
2679   [(set (strict_low_part (match_operand:SWI12 0 "register_operand" "+<r>"))
2680         (match_operand:SWI12 1 "const0_operand"))
2681    (clobber (reg:CC FLAGS_REG))]
2682   "reload_completed"
2683   "xor{<imodesuffix>}\t%0, %0"
2684   [(set_attr "type" "alu1")
2685    (set_attr "mode" "<MODE>")
2686    (set_attr "length_immediate" "0")])
2687
2688 (define_insn "*mov<mode>_extv_1"
2689   [(set (match_operand:SWI24 0 "register_operand" "=R")
2690         (sign_extract:SWI24 (match_operand 1 "ext_register_operand" "Q")
2691                             (const_int 8)
2692                             (const_int 8)))]
2693   ""
2694   "movs{bl|x}\t{%h1, %k0|%k0, %h1}"
2695   [(set_attr "type" "imovx")
2696    (set_attr "mode" "SI")])
2697
2698 (define_insn "*movqi_extv_1"
2699   [(set (match_operand:QI 0 "nonimmediate_x64nomem_operand" "=Q,?R,m")
2700         (sign_extract:QI (match_operand 1 "ext_register_operand" "Q,Q,Q")
2701                          (const_int 8)
2702                          (const_int 8)))]
2703   ""
2704 {
2705   switch (get_attr_type (insn))
2706     {
2707     case TYPE_IMOVX:
2708       return "movs{bl|x}\t{%h1, %k0|%k0, %h1}";
2709     default:
2710       return "mov{b}\t{%h1, %0|%0, %h1}";
2711     }
2712 }
2713   [(set_attr "isa" "*,*,nox64")
2714    (set (attr "type")
2715      (if_then_else (and (match_operand:QI 0 "register_operand")
2716                         (ior (not (match_operand:QI 0 "QIreg_operand"))
2717                              (match_test "TARGET_MOVX")))
2718         (const_string "imovx")
2719         (const_string "imov")))
2720    (set (attr "mode")
2721      (if_then_else (eq_attr "type" "imovx")
2722         (const_string "SI")
2723         (const_string "QI")))])
2724
2725 (define_insn "*mov<mode>_extzv_1"
2726   [(set (match_operand:SWI48 0 "register_operand" "=R")
2727         (zero_extract:SWI48 (match_operand 1 "ext_register_operand" "Q")
2728                             (const_int 8)
2729                             (const_int 8)))]
2730   ""
2731   "movz{bl|x}\t{%h1, %k0|%k0, %h1}"
2732   [(set_attr "type" "imovx")
2733    (set_attr "mode" "SI")])
2734
2735 (define_insn "*movqi_extzv_2"
2736   [(set (match_operand:QI 0 "nonimmediate_x64nomem_operand" "=Q,?R,m")
2737         (subreg:QI
2738           (zero_extract:SI (match_operand 1 "ext_register_operand" "Q,Q,Q")
2739                            (const_int 8)
2740                            (const_int 8)) 0))]
2741   ""
2742 {
2743   switch (get_attr_type (insn))
2744     {
2745     case TYPE_IMOVX:
2746       return "movz{bl|x}\t{%h1, %k0|%k0, %h1}";
2747     default:
2748       return "mov{b}\t{%h1, %0|%0, %h1}";
2749     }
2750 }
2751   [(set_attr "isa" "*,*,nox64")
2752    (set (attr "type")
2753      (if_then_else (and (match_operand:QI 0 "register_operand")
2754                         (ior (not (match_operand:QI 0 "QIreg_operand"))
2755                              (match_test "TARGET_MOVX")))
2756         (const_string "imovx")
2757         (const_string "imov")))
2758    (set (attr "mode")
2759      (if_then_else (eq_attr "type" "imovx")
2760         (const_string "SI")
2761         (const_string "QI")))])
2762
2763 (define_insn "mov<mode>_insv_1"
2764   [(set (zero_extract:SWI48 (match_operand 0 "ext_register_operand" "+Q,Q")
2765                              (const_int 8)
2766                              (const_int 8))
2767         (match_operand:SWI48 1 "general_x64nomem_operand" "Qn,m"))]
2768   ""
2769 {
2770   if (CONST_INT_P (operands[1]))
2771     operands[1] = simplify_gen_subreg (QImode, operands[1], <MODE>mode, 0);
2772   return "mov{b}\t{%b1, %h0|%h0, %b1}";
2773 }
2774   [(set_attr "isa" "*,nox64")
2775    (set_attr "type" "imov")
2776    (set_attr "mode" "QI")])
2777
2778 (define_insn "*movqi_insv_2"
2779   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "+Q")
2780                          (const_int 8)
2781                          (const_int 8))
2782         (lshiftrt:SI (match_operand:SI 1 "register_operand" "Q")
2783                      (const_int 8)))]
2784   ""
2785   "mov{b}\t{%h1, %h0|%h0, %h1}"
2786   [(set_attr "type" "imov")
2787    (set_attr "mode" "QI")])
2788 \f
2789 ;; Floating point push instructions.
2790
2791 (define_insn "*pushtf"
2792   [(set (match_operand:TF 0 "push_operand" "=<,<")
2793         (match_operand:TF 1 "general_no_elim_operand" "x,*roF"))]
2794   "TARGET_64BIT || TARGET_SSE"
2795 {
2796   /* This insn should be already split before reg-stack.  */
2797   gcc_unreachable ();
2798 }
2799   [(set_attr "isa" "*,x64")
2800    (set_attr "type" "multi")
2801    (set_attr "unit" "sse,*")
2802    (set_attr "mode" "TF,DI")])
2803
2804 ;; %%% Kill this when call knows how to work this out.
2805 (define_split
2806   [(set (match_operand:TF 0 "push_operand")
2807         (match_operand:TF 1 "sse_reg_operand"))]
2808   "TARGET_SSE && reload_completed"
2809   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -16)))
2810    (set (match_dup 0) (match_dup 1))]
2811 {
2812   /* Preserve memory attributes. */
2813   operands[0] = replace_equiv_address (operands[0], stack_pointer_rtx);
2814 })
2815
2816 (define_insn "*pushxf"
2817   [(set (match_operand:XF 0 "push_operand" "=<,<,<,<")
2818         (match_operand:XF 1 "general_no_elim_operand" "f,r,*r,oF"))]
2819   ""
2820 {
2821   /* This insn should be already split before reg-stack.  */
2822   gcc_unreachable ();
2823 }
2824   [(set_attr "type" "multi")
2825    (set_attr "unit" "i387,*,*,*")
2826    (set (attr "mode")
2827         (cond [(eq_attr "alternative" "1,2,3")
2828                  (if_then_else (match_test "TARGET_64BIT")
2829                    (const_string "DI")
2830                    (const_string "SI"))
2831               ]
2832               (const_string "XF")))
2833    (set (attr "preferred_for_size")
2834      (cond [(eq_attr "alternative" "1")
2835               (symbol_ref "false")]
2836            (symbol_ref "true")))])
2837
2838 ;; %%% Kill this when call knows how to work this out.
2839 (define_split
2840   [(set (match_operand:XF 0 "push_operand")
2841         (match_operand:XF 1 "fp_register_operand"))]
2842   "reload_completed"
2843   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
2844    (set (match_dup 0) (match_dup 1))]
2845 {
2846   operands[2] = GEN_INT (-GET_MODE_SIZE (XFmode));
2847   /* Preserve memory attributes. */
2848   operands[0] = replace_equiv_address (operands[0], stack_pointer_rtx);
2849 })
2850
2851 (define_insn "*pushdf"
2852   [(set (match_operand:DF 0 "push_operand" "=<,<,<,<,<,<")
2853         (match_operand:DF 1 "general_no_elim_operand" "f,r,*r,oF,rmF,x"))]
2854   ""
2855 {
2856   /* This insn should be already split before reg-stack.  */
2857   gcc_unreachable ();
2858 }
2859   [(set_attr "isa" "*,nox64,nox64,nox64,x64,sse2")
2860    (set_attr "type" "multi")
2861    (set_attr "unit" "i387,*,*,*,*,sse")
2862    (set_attr "mode" "DF,SI,SI,SI,DI,DF")
2863    (set (attr "preferred_for_size")
2864      (cond [(eq_attr "alternative" "1")
2865               (symbol_ref "false")]
2866            (symbol_ref "true")))
2867    (set (attr "preferred_for_speed")
2868      (cond [(eq_attr "alternative" "1")
2869               (symbol_ref "TARGET_INTEGER_DFMODE_MOVES")]
2870            (symbol_ref "true")))])
2871    
2872 ;; %%% Kill this when call knows how to work this out.
2873 (define_split
2874   [(set (match_operand:DF 0 "push_operand")
2875         (match_operand:DF 1 "any_fp_register_operand"))]
2876   "reload_completed"
2877   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -8)))
2878    (set (match_dup 0) (match_dup 1))]
2879 {
2880   /* Preserve memory attributes. */
2881   operands[0] = replace_equiv_address (operands[0], stack_pointer_rtx);
2882 })
2883
2884 (define_insn "*pushsf_rex64"
2885   [(set (match_operand:SF 0 "push_operand" "=X,X,X")
2886         (match_operand:SF 1 "nonmemory_no_elim_operand" "f,rF,x"))]
2887   "TARGET_64BIT"
2888 {
2889   /* Anything else should be already split before reg-stack.  */
2890   gcc_assert (which_alternative == 1);
2891   return "push{q}\t%q1";
2892 }
2893   [(set_attr "type" "multi,push,multi")
2894    (set_attr "unit" "i387,*,*")
2895    (set_attr "mode" "SF,DI,SF")])
2896
2897 (define_insn "*pushsf"
2898   [(set (match_operand:SF 0 "push_operand" "=<,<,<")
2899         (match_operand:SF 1 "general_no_elim_operand" "f,rmF,x"))]
2900   "!TARGET_64BIT"
2901 {
2902   /* Anything else should be already split before reg-stack.  */
2903   gcc_assert (which_alternative == 1);
2904   return "push{l}\t%1";
2905 }
2906   [(set_attr "type" "multi,push,multi")
2907    (set_attr "unit" "i387,*,*")
2908    (set_attr "mode" "SF,SI,SF")])
2909
2910 ;; %%% Kill this when call knows how to work this out.
2911 (define_split
2912   [(set (match_operand:SF 0 "push_operand")
2913         (match_operand:SF 1 "any_fp_register_operand"))]
2914   "reload_completed"
2915   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
2916    (set (match_dup 0) (match_dup 1))]
2917 {
2918   rtx op = XEXP (operands[0], 0);
2919   if (GET_CODE (op) == PRE_DEC)
2920     {
2921       gcc_assert (!TARGET_64BIT);
2922       op = GEN_INT (-4);
2923     }
2924   else
2925     {
2926       op = XEXP (XEXP (op, 1), 1);
2927       gcc_assert (CONST_INT_P (op));
2928     }
2929   operands[2] = op;
2930   /* Preserve memory attributes. */
2931   operands[0] = replace_equiv_address (operands[0], stack_pointer_rtx);
2932 })
2933
2934 (define_split
2935   [(set (match_operand:SF 0 "push_operand")
2936         (match_operand:SF 1 "memory_operand"))]
2937   "reload_completed
2938    && (operands[2] = find_constant_src (insn))"
2939   [(set (match_dup 0) (match_dup 2))])
2940
2941 (define_split
2942   [(set (match_operand 0 "push_operand")
2943         (match_operand 1 "general_operand"))]
2944   "reload_completed
2945    && (GET_MODE (operands[0]) == TFmode
2946        || GET_MODE (operands[0]) == XFmode
2947        || GET_MODE (operands[0]) == DFmode)
2948    && !ANY_FP_REG_P (operands[1])"
2949   [(const_int 0)]
2950   "ix86_split_long_move (operands); DONE;")
2951 \f
2952 ;; Floating point move instructions.
2953
2954 (define_expand "movtf"
2955   [(set (match_operand:TF 0 "nonimmediate_operand")
2956         (match_operand:TF 1 "nonimmediate_operand"))]
2957   "TARGET_64BIT || TARGET_SSE"
2958   "ix86_expand_move (TFmode, operands); DONE;")
2959
2960 (define_expand "mov<mode>"
2961   [(set (match_operand:X87MODEF 0 "nonimmediate_operand")
2962         (match_operand:X87MODEF 1 "general_operand"))]
2963   ""
2964   "ix86_expand_move (<MODE>mode, operands); DONE;")
2965
2966 (define_insn "*movtf_internal"
2967   [(set (match_operand:TF 0 "nonimmediate_operand" "=x,x ,m,?*r ,!o")
2968         (match_operand:TF 1 "general_operand"      "C ,xm,x,*roF,*rC"))]
2969   "(TARGET_64BIT || TARGET_SSE)
2970    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
2971    && (!can_create_pseudo_p ()
2972        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
2973        || GET_CODE (operands[1]) != CONST_DOUBLE
2974        || (optimize_function_for_size_p (cfun)
2975            && standard_sse_constant_p (operands[1])
2976            && !memory_operand (operands[0], TFmode))
2977        || (!TARGET_MEMORY_MISMATCH_STALL
2978            && memory_operand (operands[0], TFmode)))"
2979 {
2980   switch (get_attr_type (insn))
2981     {
2982     case TYPE_SSELOG1:
2983       return standard_sse_constant_opcode (insn, operands[1]);
2984
2985     case TYPE_SSEMOV:
2986       /* Handle misaligned load/store since we
2987          don't have movmisaligntf pattern. */
2988       if (misaligned_operand (operands[0], TFmode)
2989           || misaligned_operand (operands[1], TFmode))
2990         {
2991           if (get_attr_mode (insn) == MODE_V4SF)
2992             return "%vmovups\t{%1, %0|%0, %1}";
2993           else
2994             return "%vmovdqu\t{%1, %0|%0, %1}";
2995         }
2996       else
2997         {
2998           if (get_attr_mode (insn) == MODE_V4SF)
2999             return "%vmovaps\t{%1, %0|%0, %1}";
3000           else
3001             return "%vmovdqa\t{%1, %0|%0, %1}";
3002         }
3003
3004     case TYPE_MULTI:
3005         return "#";
3006
3007     default:
3008       gcc_unreachable ();
3009     }
3010 }
3011   [(set_attr "isa" "*,*,*,x64,x64")
3012    (set_attr "type" "sselog1,ssemov,ssemov,multi,multi")
3013    (set (attr "prefix")
3014      (if_then_else (eq_attr "type" "sselog1,ssemov")
3015        (const_string "maybe_vex")
3016        (const_string "orig")))
3017    (set (attr "mode")
3018         (cond [(eq_attr "alternative" "3,4")
3019                  (const_string "DI")
3020                (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
3021                  (const_string "V4SF")
3022                (and (eq_attr "alternative" "2")
3023                     (match_test "TARGET_SSE_TYPELESS_STORES"))
3024                  (const_string "V4SF")
3025                (match_test "TARGET_AVX")
3026                  (const_string "TI")
3027                (ior (not (match_test "TARGET_SSE2"))
3028                     (match_test "optimize_function_for_size_p (cfun)"))
3029                  (const_string "V4SF")
3030                ]
3031                (const_string "TI")))])
3032
3033 ;; Possible store forwarding (partial memory) stall
3034 ;; in alternatives 4, 6, 7 and 8.
3035 (define_insn "*movxf_internal"
3036   [(set (match_operand:XF 0 "nonimmediate_operand"
3037          "=f,m,f,?r ,!o,?*r ,!o,!o,!o")
3038         (match_operand:XF 1 "general_operand"
3039          "fm,f,G,roF,r , *roF,*r,F ,C"))]
3040   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
3041    && (!can_create_pseudo_p ()
3042        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3043        || GET_CODE (operands[1]) != CONST_DOUBLE
3044        || (optimize_function_for_size_p (cfun)
3045            && standard_80387_constant_p (operands[1]) > 0
3046            && !memory_operand (operands[0], XFmode))
3047        || (!TARGET_MEMORY_MISMATCH_STALL
3048            && memory_operand (operands[0], XFmode)))"
3049 {
3050   switch (get_attr_type (insn))
3051     {
3052     case TYPE_FMOV:
3053       if (which_alternative == 2)
3054         return standard_80387_constant_opcode (operands[1]);
3055       return output_387_reg_move (insn, operands);
3056
3057     case TYPE_MULTI:
3058       return "#";
3059
3060     default:
3061       gcc_unreachable ();
3062     }
3063 }
3064   [(set (attr "isa")
3065         (cond [(eq_attr "alternative" "7")
3066                  (const_string "nox64")
3067                (eq_attr "alternative" "8")
3068                  (const_string "x64")
3069               ]
3070               (const_string "*")))
3071    (set (attr "type")
3072         (cond [(eq_attr "alternative" "3,4,5,6,7,8")
3073                  (const_string "multi")
3074               ]
3075               (const_string "fmov")))
3076    (set (attr "mode")
3077         (cond [(eq_attr "alternative" "3,4,5,6,7,8")
3078                  (if_then_else (match_test "TARGET_64BIT")
3079                    (const_string "DI")
3080                    (const_string "SI"))
3081               ]
3082               (const_string "XF")))
3083    (set (attr "preferred_for_size")
3084      (cond [(eq_attr "alternative" "3,4")
3085               (symbol_ref "false")]
3086            (symbol_ref "true")))])
3087    
3088 ;; Possible store forwarding (partial memory) stall in alternatives 4, 6 and 7.
3089 (define_insn "*movdf_internal"
3090   [(set (match_operand:DF 0 "nonimmediate_operand"
3091     "=Yf*f,m   ,Yf*f,?r ,!o,?*r ,!o,!o,?r,?m,?r,?r,v,v,v,m,*x,*x,*x,m ,r ,Yi")
3092         (match_operand:DF 1 "general_operand"
3093     "Yf*fm,Yf*f,G   ,roF,r ,*roF,*r,F ,rm,rC,C ,F ,C,v,m,v,C ,*x,m ,*x,Yj,r"))]
3094   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
3095    && (!can_create_pseudo_p ()
3096        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3097        || GET_CODE (operands[1]) != CONST_DOUBLE
3098        || (optimize_function_for_size_p (cfun)
3099            && ((!(TARGET_SSE2 && TARGET_SSE_MATH)
3100                 && standard_80387_constant_p (operands[1]) > 0)
3101                || (TARGET_SSE2 && TARGET_SSE_MATH
3102                    && standard_sse_constant_p (operands[1])))
3103            && !memory_operand (operands[0], DFmode))
3104        || ((TARGET_64BIT || !TARGET_MEMORY_MISMATCH_STALL)
3105            && memory_operand (operands[0], DFmode)))"
3106 {
3107   switch (get_attr_type (insn))
3108     {
3109     case TYPE_FMOV:
3110       if (which_alternative == 2)
3111         return standard_80387_constant_opcode (operands[1]);
3112       return output_387_reg_move (insn, operands);
3113
3114     case TYPE_MULTI:
3115       return "#";
3116
3117     case TYPE_IMOV:
3118       if (get_attr_mode (insn) == MODE_SI)
3119         return "mov{l}\t{%1, %k0|%k0, %1}";
3120       else if (which_alternative == 11)
3121         return "movabs{q}\t{%1, %0|%0, %1}";
3122       else
3123         return "mov{q}\t{%1, %0|%0, %1}";
3124
3125     case TYPE_SSELOG1:
3126       return standard_sse_constant_opcode (insn, operands[1]);
3127
3128     case TYPE_SSEMOV:
3129       switch (get_attr_mode (insn))
3130         {
3131         case MODE_DF:
3132           if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
3133             return "vmovsd\t{%1, %0, %0|%0, %0, %1}";
3134           return "%vmovsd\t{%1, %0|%0, %1}";
3135
3136         case MODE_V4SF:
3137           return "%vmovaps\t{%1, %0|%0, %1}";
3138         case MODE_V8DF:
3139           return "vmovapd\t{%g1, %g0|%g0, %g1}";
3140         case MODE_V2DF:
3141           return "%vmovapd\t{%1, %0|%0, %1}";
3142
3143         case MODE_V2SF:
3144           gcc_assert (!TARGET_AVX);
3145           return "movlps\t{%1, %0|%0, %1}";
3146         case MODE_V1DF:
3147           gcc_assert (!TARGET_AVX);
3148           return "movlpd\t{%1, %0|%0, %1}";
3149
3150         case MODE_DI:
3151           /* Handle broken assemblers that require movd instead of movq.  */
3152           if (!HAVE_AS_IX86_INTERUNIT_MOVQ
3153               && (GENERAL_REG_P (operands[0]) || GENERAL_REG_P (operands[1])))
3154             return "%vmovd\t{%1, %0|%0, %1}";
3155           return "%vmovq\t{%1, %0|%0, %1}";
3156
3157         default:
3158           gcc_unreachable ();
3159         }
3160
3161     default:
3162       gcc_unreachable ();
3163     }
3164 }
3165   [(set (attr "isa")
3166         (cond [(eq_attr "alternative" "3,4,5,6,7")
3167                  (const_string "nox64")
3168                (eq_attr "alternative" "8,9,10,11,20,21")
3169                  (const_string "x64")
3170                (eq_attr "alternative" "12,13,14,15")
3171                  (const_string "sse2")
3172               ]
3173               (const_string "*")))
3174    (set (attr "type")
3175         (cond [(eq_attr "alternative" "0,1,2")
3176                  (const_string "fmov")
3177                (eq_attr "alternative" "3,4,5,6,7")
3178                  (const_string "multi")
3179                (eq_attr "alternative" "8,9,10,11")
3180                  (const_string "imov")
3181                (eq_attr "alternative" "12,16")
3182                  (const_string "sselog1")
3183               ]
3184               (const_string "ssemov")))
3185    (set (attr "modrm")
3186      (if_then_else (eq_attr "alternative" "11")
3187        (const_string "0")
3188        (const_string "*")))
3189    (set (attr "length_immediate")
3190      (if_then_else (eq_attr "alternative" "11")
3191        (const_string "8")
3192        (const_string "*")))
3193    (set (attr "prefix")
3194      (if_then_else (eq_attr "type" "sselog1,ssemov")
3195        (const_string "maybe_vex")
3196        (const_string "orig")))
3197    (set (attr "prefix_data16")
3198      (if_then_else
3199        (ior (and (eq_attr "type" "ssemov") (eq_attr "mode" "DI"))
3200             (eq_attr "mode" "V1DF"))
3201        (const_string "1")
3202        (const_string "*")))
3203    (set (attr "mode")
3204         (cond [(eq_attr "alternative" "3,4,5,6,7,10")
3205                  (const_string "SI")
3206                (eq_attr "alternative" "8,9,11,20,21")
3207                  (const_string "DI")
3208
3209                /* xorps is one byte shorter for non-AVX targets.  */
3210                (eq_attr "alternative" "12,16")
3211                  (cond [(not (match_test "TARGET_SSE2"))
3212                           (const_string "V4SF")
3213                         (match_test "TARGET_AVX512F")
3214                           (const_string "XI")
3215                         (match_test "TARGET_AVX")
3216                           (const_string "V2DF")
3217                         (match_test "optimize_function_for_size_p (cfun)")
3218                           (const_string "V4SF")
3219                         (match_test "TARGET_SSE_LOAD0_BY_PXOR")
3220                           (const_string "TI")
3221                        ]
3222                        (const_string "V2DF"))
3223
3224                /* For architectures resolving dependencies on
3225                   whole SSE registers use movapd to break dependency
3226                   chains, otherwise use short move to avoid extra work.  */
3227
3228                /* movaps is one byte shorter for non-AVX targets.  */
3229                (eq_attr "alternative" "13,17")
3230                  (cond [(ior (match_operand 0 "ext_sse_reg_operand")
3231                              (match_operand 1 "ext_sse_reg_operand"))
3232                           (const_string "V8DF")
3233                         (ior (not (match_test "TARGET_SSE2"))
3234                              (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
3235                           (const_string "V4SF")
3236                         (match_test "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3237                           (const_string "V2DF")
3238                         (match_test "TARGET_AVX")
3239                           (const_string "DF")
3240                         (match_test "optimize_function_for_size_p (cfun)")
3241                           (const_string "V4SF")
3242                        ]
3243                        (const_string "DF"))
3244
3245                /* For architectures resolving dependencies on register
3246                   parts we may avoid extra work to zero out upper part
3247                   of register.  */
3248                (eq_attr "alternative" "14,18")
3249                  (cond [(not (match_test "TARGET_SSE2"))
3250                           (const_string "V2SF")
3251                         (match_test "TARGET_AVX")
3252                           (const_string "DF")
3253                         (match_test "TARGET_SSE_SPLIT_REGS")
3254                           (const_string "V1DF")
3255                        ]
3256                        (const_string "DF"))
3257
3258                (and (eq_attr "alternative" "15,19")
3259                     (not (match_test "TARGET_SSE2")))
3260                  (const_string "V2SF")
3261               ]
3262               (const_string "DF")))
3263    (set (attr "preferred_for_size")
3264      (cond [(eq_attr "alternative" "3,4")
3265               (symbol_ref "false")]
3266            (symbol_ref "true")))
3267    (set (attr "preferred_for_speed")
3268      (cond [(eq_attr "alternative" "3,4")
3269               (symbol_ref "TARGET_INTEGER_DFMODE_MOVES")]
3270            (symbol_ref "true")))])
3271
3272 (define_insn "*movsf_internal"
3273   [(set (match_operand:SF 0 "nonimmediate_operand"
3274           "=Yf*f,m   ,Yf*f,?r ,?m,v,v,v,m,?r,?Yi,!*y,!*y,!m,!r ,!*Ym")
3275         (match_operand:SF 1 "general_operand"
3276           "Yf*fm,Yf*f,G   ,rmF,rF,C,v,m,v,Yj,r  ,*y ,m  ,*y,*Yn,r"))]
3277   "!(MEM_P (operands[0]) && MEM_P (operands[1]))
3278    && (!can_create_pseudo_p ()
3279        || (ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_LARGE)
3280        || GET_CODE (operands[1]) != CONST_DOUBLE
3281        || (optimize_function_for_size_p (cfun)
3282            && ((!TARGET_SSE_MATH
3283                 && standard_80387_constant_p (operands[1]) > 0)
3284                || (TARGET_SSE_MATH
3285                    && standard_sse_constant_p (operands[1]))))
3286        || memory_operand (operands[0], SFmode))"
3287 {
3288   switch (get_attr_type (insn))
3289     {
3290     case TYPE_FMOV:
3291       if (which_alternative == 2)
3292         return standard_80387_constant_opcode (operands[1]);
3293       return output_387_reg_move (insn, operands);
3294
3295     case TYPE_IMOV:
3296       return "mov{l}\t{%1, %0|%0, %1}";
3297
3298     case TYPE_SSELOG1:
3299       return standard_sse_constant_opcode (insn, operands[1]);
3300
3301     case TYPE_SSEMOV:
3302       switch (get_attr_mode (insn))
3303         {
3304         case MODE_SF:
3305           if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
3306             return "vmovss\t{%1, %0, %0|%0, %0, %1}";
3307           return "%vmovss\t{%1, %0|%0, %1}";
3308
3309         case MODE_V16SF:
3310           return "vmovaps\t{%g1, %g0|%g0, %g1}";
3311         case MODE_V4SF:
3312           return "%vmovaps\t{%1, %0|%0, %1}";
3313
3314         case MODE_SI:
3315           return "%vmovd\t{%1, %0|%0, %1}";
3316
3317         default:
3318           gcc_unreachable ();
3319         }
3320
3321     case TYPE_MMXMOV:
3322       switch (get_attr_mode (insn))
3323         {
3324         case MODE_DI:
3325           return "movq\t{%1, %0|%0, %1}";
3326         case MODE_SI:
3327           return "movd\t{%1, %0|%0, %1}";
3328
3329         default:
3330           gcc_unreachable ();
3331         }
3332
3333     default:
3334       gcc_unreachable ();
3335     }
3336 }
3337   [(set (attr "type")
3338         (cond [(eq_attr "alternative" "0,1,2")
3339                  (const_string "fmov")
3340                (eq_attr "alternative" "3,4")
3341                  (const_string "imov")
3342                (eq_attr "alternative" "5")
3343                  (const_string "sselog1")
3344                (eq_attr "alternative" "11,12,13,14,15")
3345                  (const_string "mmxmov")
3346               ]
3347               (const_string "ssemov")))
3348    (set (attr "prefix")
3349      (if_then_else (eq_attr "type" "sselog1,ssemov")
3350        (const_string "maybe_vex")
3351        (const_string "orig")))
3352    (set (attr "prefix_data16")
3353      (if_then_else (and (eq_attr "type" "ssemov") (eq_attr "mode" "SI"))
3354        (const_string "1")
3355        (const_string "*")))
3356    (set (attr "mode")
3357         (cond [(eq_attr "alternative" "3,4,9,10,12,13,14,15")
3358                  (const_string "SI")
3359                (eq_attr "alternative" "11")
3360                  (const_string "DI")
3361                (eq_attr "alternative" "5")
3362                  (cond [(not (match_test "TARGET_SSE2"))
3363                           (const_string "V4SF")
3364                         (match_test "TARGET_AVX512F")
3365                           (const_string "V16SF")
3366                         (match_test "TARGET_AVX")
3367                           (const_string "V4SF")
3368                         (match_test "optimize_function_for_size_p (cfun)")
3369                           (const_string "V4SF")
3370                         (match_test "TARGET_SSE_LOAD0_BY_PXOR")
3371                           (const_string "TI")
3372                        ]
3373                        (const_string "V4SF"))
3374
3375                /* For architectures resolving dependencies on
3376                   whole SSE registers use APS move to break dependency
3377                   chains, otherwise use short move to avoid extra work.
3378
3379                   Do the same for architectures resolving dependencies on
3380                   the parts.  While in DF mode it is better to always handle
3381                   just register parts, the SF mode is different due to lack
3382                   of instructions to load just part of the register.  It is
3383                   better to maintain the whole registers in single format
3384                   to avoid problems on using packed logical operations.  */
3385                (eq_attr "alternative" "6")
3386                  (cond [(ior  (match_operand 0 "ext_sse_reg_operand")
3387                               (match_operand 1 "ext_sse_reg_operand"))
3388                           (const_string "V16SF")
3389                         (ior (match_test "TARGET_SSE_PARTIAL_REG_DEPENDENCY")
3390                              (match_test "TARGET_SSE_SPLIT_REGS"))
3391                           (const_string "V4SF")
3392                        ]
3393                        (const_string "SF"))
3394               ]
3395               (const_string "SF")))])
3396
3397 (define_split
3398   [(set (match_operand 0 "any_fp_register_operand")
3399         (match_operand 1 "memory_operand"))]
3400   "reload_completed
3401    && (GET_MODE (operands[0]) == TFmode
3402        || GET_MODE (operands[0]) == XFmode
3403        || GET_MODE (operands[0]) == DFmode
3404        || GET_MODE (operands[0]) == SFmode)
3405    && (operands[2] = find_constant_src (insn))"
3406   [(set (match_dup 0) (match_dup 2))]
3407 {
3408   rtx c = operands[2];
3409   int r = REGNO (operands[0]);
3410
3411   if ((SSE_REGNO_P (r) && !standard_sse_constant_p (c))
3412       || (STACK_REGNO_P (r) && standard_80387_constant_p (c) < 1))
3413     FAIL;
3414 })
3415
3416 (define_split
3417   [(set (match_operand 0 "any_fp_register_operand")
3418         (float_extend (match_operand 1 "memory_operand")))]
3419   "reload_completed
3420    && (GET_MODE (operands[0]) == TFmode
3421        || GET_MODE (operands[0]) == XFmode
3422        || GET_MODE (operands[0]) == DFmode)
3423    && (operands[2] = find_constant_src (insn))"
3424   [(set (match_dup 0) (match_dup 2))]
3425 {
3426   rtx c = operands[2];
3427   int r = REGNO (operands[0]);
3428
3429   if ((SSE_REGNO_P (r) && !standard_sse_constant_p (c))
3430       || (STACK_REGNO_P (r) && standard_80387_constant_p (c) < 1))
3431     FAIL;
3432 })
3433
3434 ;; Split the load of -0.0 or -1.0 into fldz;fchs or fld1;fchs sequence
3435 (define_split
3436   [(set (match_operand:X87MODEF 0 "fp_register_operand")
3437         (match_operand:X87MODEF 1 "immediate_operand"))]
3438   "reload_completed
3439    && (standard_80387_constant_p (operands[1]) == 8
3440        || standard_80387_constant_p (operands[1]) == 9)"
3441   [(set (match_dup 0)(match_dup 1))
3442    (set (match_dup 0)
3443         (neg:X87MODEF (match_dup 0)))]
3444 {
3445   REAL_VALUE_TYPE r;
3446
3447   REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
3448   if (real_isnegzero (&r))
3449     operands[1] = CONST0_RTX (<MODE>mode);
3450   else
3451     operands[1] = CONST1_RTX (<MODE>mode);
3452 })
3453
3454 (define_split
3455   [(set (match_operand 0 "nonimmediate_operand")
3456         (match_operand 1 "general_operand"))]
3457   "reload_completed
3458    && (GET_MODE (operands[0]) == TFmode
3459        || GET_MODE (operands[0]) == XFmode
3460        || GET_MODE (operands[0]) == DFmode)
3461    && !(ANY_FP_REG_P (operands[0]) || ANY_FP_REG_P (operands[1]))"
3462   [(const_int 0)]
3463   "ix86_split_long_move (operands); DONE;")
3464
3465 (define_insn "swapxf"
3466   [(set (match_operand:XF 0 "register_operand" "+f")
3467         (match_operand:XF 1 "register_operand" "+f"))
3468    (set (match_dup 1)
3469         (match_dup 0))]
3470   "TARGET_80387"
3471 {
3472   if (STACK_TOP_P (operands[0]))
3473     return "fxch\t%1";
3474   else
3475     return "fxch\t%0";
3476 }
3477   [(set_attr "type" "fxch")
3478    (set_attr "mode" "XF")])
3479
3480 (define_insn "*swap<mode>"
3481   [(set (match_operand:MODEF 0 "fp_register_operand" "+f")
3482         (match_operand:MODEF 1 "fp_register_operand" "+f"))
3483    (set (match_dup 1)
3484         (match_dup 0))]
3485   "TARGET_80387 || reload_completed"
3486 {
3487   if (STACK_TOP_P (operands[0]))
3488     return "fxch\t%1";
3489   else
3490     return "fxch\t%0";
3491 }
3492   [(set_attr "type" "fxch")
3493    (set_attr "mode" "<MODE>")])
3494 \f
3495 ;; Zero extension instructions
3496
3497 (define_expand "zero_extendsidi2"
3498   [(set (match_operand:DI 0 "nonimmediate_operand")
3499         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))])
3500
3501 (define_insn "*zero_extendsidi2"
3502   [(set (match_operand:DI 0 "nonimmediate_operand"
3503                         "=r,?r,?o,r   ,o,?*Ym,?!*y,?r ,?r,?*Yi,?*x")
3504         (zero_extend:DI
3505          (match_operand:SI 1 "x86_64_zext_operand"
3506                         "0 ,rm,r ,rmWz,0,r   ,m   ,*Yj,*x,r   ,m")))]
3507   ""
3508 {
3509   switch (get_attr_type (insn))
3510     {
3511     case TYPE_IMOVX:
3512       if (ix86_use_lea_for_mov (insn, operands))
3513         return "lea{l}\t{%E1, %k0|%k0, %E1}";
3514       else
3515         return "mov{l}\t{%1, %k0|%k0, %1}";
3516
3517     case TYPE_MULTI:
3518       return "#";
3519
3520     case TYPE_MMXMOV:
3521       return "movd\t{%1, %0|%0, %1}";
3522
3523     case TYPE_SSELOG1:
3524       return "%vpextrd\t{$0, %1, %k0|%k0, %1, 0}";
3525
3526     case TYPE_SSEMOV:
3527       if (GENERAL_REG_P (operands[0]))
3528         return "%vmovd\t{%1, %k0|%k0, %1}";
3529
3530       return "%vmovd\t{%1, %0|%0, %1}";
3531
3532     default:
3533       gcc_unreachable ();
3534     }
3535 }
3536   [(set (attr "isa")
3537      (cond [(eq_attr "alternative" "0,1,2")
3538               (const_string "nox64")
3539             (eq_attr "alternative" "3,7")
3540               (const_string "x64")
3541             (eq_attr "alternative" "8")
3542               (const_string "x64_sse4")
3543             (eq_attr "alternative" "10")
3544               (const_string "sse2")
3545            ]
3546            (const_string "*")))
3547    (set (attr "type")
3548      (cond [(eq_attr "alternative" "0,1,2,4")
3549               (const_string "multi")
3550             (eq_attr "alternative" "5,6")
3551               (const_string "mmxmov")
3552             (eq_attr "alternative" "7,9,10")
3553               (const_string "ssemov")
3554             (eq_attr "alternative" "8")
3555               (const_string "sselog1")
3556            ]
3557            (const_string "imovx")))
3558    (set (attr "prefix_extra")
3559      (if_then_else (eq_attr "alternative" "8")
3560        (const_string "1")
3561        (const_string "*")))
3562    (set (attr "length_immediate")
3563      (if_then_else (eq_attr "alternative" "8")
3564        (const_string "1")
3565        (const_string "*")))
3566    (set (attr "prefix")
3567      (if_then_else (eq_attr "type" "ssemov,sselog1")
3568        (const_string "maybe_vex")
3569        (const_string "orig")))
3570    (set (attr "prefix_0f")
3571      (if_then_else (eq_attr "type" "imovx")
3572        (const_string "0")
3573        (const_string "*")))
3574    (set (attr "mode")
3575      (cond [(eq_attr "alternative" "5,6")
3576               (const_string "DI")
3577             (eq_attr "alternative" "7,8,9")
3578               (const_string "TI")
3579            ]
3580            (const_string "SI")))])
3581
3582 (define_split
3583   [(set (match_operand:DI 0 "memory_operand")
3584         (zero_extend:DI (match_operand:SI 1 "memory_operand")))]
3585   "reload_completed"
3586   [(set (match_dup 4) (const_int 0))]
3587   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3588
3589 (define_split
3590   [(set (match_operand:DI 0 "register_operand")
3591         (zero_extend:DI (match_operand:SI 1 "register_operand")))]
3592   "!TARGET_64BIT && reload_completed
3593    && !(MMX_REG_P (operands[0]) || SSE_REG_P (operands[0]))
3594    && true_regnum (operands[0]) == true_regnum (operands[1])"
3595   [(set (match_dup 4) (const_int 0))]
3596   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3597
3598 (define_split
3599   [(set (match_operand:DI 0 "nonimmediate_operand")
3600         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))]
3601   "!TARGET_64BIT && reload_completed
3602    && !(MEM_P (operands[0]) && MEM_P (operands[1]))
3603    && !(MMX_REG_P (operands[0]) || SSE_REG_P (operands[0]))"
3604   [(set (match_dup 3) (match_dup 1))
3605    (set (match_dup 4) (const_int 0))]
3606   "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")
3607
3608 (define_insn "zero_extend<mode>di2"
3609   [(set (match_operand:DI 0 "register_operand" "=r")
3610         (zero_extend:DI
3611          (match_operand:SWI12 1 "nonimmediate_operand" "<r>m")))]
3612   "TARGET_64BIT"
3613   "movz{<imodesuffix>l|x}\t{%1, %k0|%k0, %1}"
3614   [(set_attr "type" "imovx")
3615    (set_attr "mode" "SI")])
3616
3617 (define_expand "zero_extend<mode>si2"
3618   [(set (match_operand:SI 0 "register_operand")
3619         (zero_extend:SI (match_operand:SWI12 1 "nonimmediate_operand")))]
3620   ""
3621 {
3622   if (TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))
3623     {
3624       operands[1] = force_reg (<MODE>mode, operands[1]);
3625       emit_insn (gen_zero_extend<mode>si2_and (operands[0], operands[1]));
3626       DONE;
3627     }
3628 })
3629
3630 (define_insn_and_split "zero_extend<mode>si2_and"
3631   [(set (match_operand:SI 0 "register_operand" "=r,?&<r>")
3632         (zero_extend:SI
3633           (match_operand:SWI12 1 "nonimmediate_operand" "0,<r>m")))
3634    (clobber (reg:CC FLAGS_REG))]
3635   "TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
3636   "#"
3637   "&& reload_completed"
3638   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (match_dup 2)))
3639               (clobber (reg:CC FLAGS_REG))])]
3640 {
3641   if (true_regnum (operands[0]) != true_regnum (operands[1]))
3642     {
3643       ix86_expand_clear (operands[0]);
3644
3645       gcc_assert (!TARGET_PARTIAL_REG_STALL);
3646       emit_insn (gen_movstrict<mode>
3647                   (gen_lowpart (<MODE>mode, operands[0]), operands[1]));
3648       DONE;
3649     }
3650
3651   operands[2] = GEN_INT (GET_MODE_MASK (<MODE>mode));
3652 }
3653   [(set_attr "type" "alu1")
3654    (set_attr "mode" "SI")])
3655
3656 (define_insn "*zero_extend<mode>si2"
3657   [(set (match_operand:SI 0 "register_operand" "=r")
3658         (zero_extend:SI
3659           (match_operand:SWI12 1 "nonimmediate_operand" "<r>m")))]
3660   "!(TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))"
3661   "movz{<imodesuffix>l|x}\t{%1, %0|%0, %1}"
3662   [(set_attr "type" "imovx")
3663    (set_attr "mode" "SI")])
3664
3665 (define_expand "zero_extendqihi2"
3666   [(set (match_operand:HI 0 "register_operand")
3667         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3668   ""
3669 {
3670   if (TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))
3671     {
3672       operands[1] = force_reg (QImode, operands[1]);
3673       emit_insn (gen_zero_extendqihi2_and (operands[0], operands[1]));
3674       DONE;
3675     }
3676 })
3677
3678 (define_insn_and_split "zero_extendqihi2_and"
3679   [(set (match_operand:HI 0 "register_operand" "=r,?&q")
3680         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,qm")))
3681    (clobber (reg:CC FLAGS_REG))]
3682   "TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
3683   "#"
3684   "&& reload_completed"
3685   [(parallel [(set (match_dup 0) (and:SI (match_dup 0) (const_int 255)))
3686               (clobber (reg:CC FLAGS_REG))])]
3687 {
3688   if (true_regnum (operands[0]) != true_regnum (operands[1]))
3689     {
3690       ix86_expand_clear (operands[0]);
3691
3692       gcc_assert (!TARGET_PARTIAL_REG_STALL);
3693       emit_insn (gen_movstrictqi
3694                   (gen_lowpart (QImode, operands[0]), operands[1]));
3695       DONE;
3696     }
3697
3698   operands[0] = gen_lowpart (SImode, operands[0]);
3699 }
3700   [(set_attr "type" "alu1")
3701    (set_attr "mode" "SI")])
3702
3703 ; zero extend to SImode to avoid partial register stalls
3704 (define_insn "*zero_extendqihi2"
3705   [(set (match_operand:HI 0 "register_operand" "=r")
3706         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3707   "!(TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))"
3708   "movz{bl|x}\t{%1, %k0|%k0, %1}"
3709   [(set_attr "type" "imovx")
3710    (set_attr "mode" "SI")])
3711 \f
3712 ;; Sign extension instructions
3713
3714 (define_expand "extendsidi2"
3715   [(set (match_operand:DI 0 "register_operand")
3716         (sign_extend:DI (match_operand:SI 1 "register_operand")))]
3717   ""
3718 {
3719   if (!TARGET_64BIT)
3720     {
3721       emit_insn (gen_extendsidi2_1 (operands[0], operands[1]));
3722       DONE;
3723     }
3724 })
3725
3726 (define_insn "*extendsidi2_rex64"
3727   [(set (match_operand:DI 0 "register_operand" "=*a,r")
3728         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "*0,rm")))]
3729   "TARGET_64BIT"
3730   "@
3731    {cltq|cdqe}
3732    movs{lq|x}\t{%1, %0|%0, %1}"
3733   [(set_attr "type" "imovx")
3734    (set_attr "mode" "DI")
3735    (set_attr "prefix_0f" "0")
3736    (set_attr "modrm" "0,1")])
3737
3738 (define_insn "extendsidi2_1"
3739   [(set (match_operand:DI 0 "nonimmediate_operand" "=*A,r,?r,?*o")
3740         (sign_extend:DI (match_operand:SI 1 "register_operand" "0,0,r,r")))
3741    (clobber (reg:CC FLAGS_REG))
3742    (clobber (match_scratch:SI 2 "=X,X,X,&r"))]
3743   "!TARGET_64BIT"
3744   "#")
3745
3746 ;; Split the memory case.  If the source register doesn't die, it will stay
3747 ;; this way, if it does die, following peephole2s take care of it.
3748 (define_split
3749   [(set (match_operand:DI 0 "memory_operand")
3750         (sign_extend:DI (match_operand:SI 1 "register_operand")))
3751    (clobber (reg:CC FLAGS_REG))
3752    (clobber (match_operand:SI 2 "register_operand"))]
3753   "reload_completed"
3754   [(const_int 0)]
3755 {
3756   split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);
3757
3758   emit_move_insn (operands[3], operands[1]);
3759
3760   /* Generate a cltd if possible and doing so it profitable.  */
3761   if ((optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
3762       && true_regnum (operands[1]) == AX_REG
3763       && true_regnum (operands[2]) == DX_REG)
3764     {
3765       emit_insn (gen_ashrsi3_cvt (operands[2], operands[1], GEN_INT (31)));
3766     }
3767   else
3768     {
3769       emit_move_insn (operands[2], operands[1]);
3770       emit_insn (gen_ashrsi3_cvt (operands[2], operands[2], GEN_INT (31)));
3771     }
3772   emit_move_insn (operands[4], operands[2]);
3773   DONE;
3774 })
3775
3776 ;; Peepholes for the case where the source register does die, after
3777 ;; being split with the above splitter.
3778 (define_peephole2
3779   [(set (match_operand:SI 0 "memory_operand")
3780         (match_operand:SI 1 "register_operand"))
3781    (set (match_operand:SI 2 "register_operand") (match_dup 1))
3782    (parallel [(set (match_dup 2)
3783                    (ashiftrt:SI (match_dup 2) (const_int 31)))
3784                (clobber (reg:CC FLAGS_REG))])
3785    (set (match_operand:SI 3 "memory_operand") (match_dup 2))]
3786   "REGNO (operands[1]) != REGNO (operands[2])
3787    && peep2_reg_dead_p (2, operands[1])
3788    && peep2_reg_dead_p (4, operands[2])
3789    && !reg_mentioned_p (operands[2], operands[3])"
3790   [(set (match_dup 0) (match_dup 1))
3791    (parallel [(set (match_dup 1) (ashiftrt:SI (match_dup 1) (const_int 31)))
3792               (clobber (reg:CC FLAGS_REG))])
3793    (set (match_dup 3) (match_dup 1))])
3794
3795 (define_peephole2
3796   [(set (match_operand:SI 0 "memory_operand")
3797         (match_operand:SI 1 "register_operand"))
3798    (parallel [(set (match_operand:SI 2 "register_operand")
3799                    (ashiftrt:SI (match_dup 1) (const_int 31)))
3800                (clobber (reg:CC FLAGS_REG))])
3801    (set (match_operand:SI 3 "memory_operand") (match_dup 2))]
3802   "/* cltd is shorter than sarl $31, %eax */
3803    !optimize_function_for_size_p (cfun)
3804    && true_regnum (operands[1]) == AX_REG
3805    && true_regnum (operands[2]) == DX_REG
3806    && peep2_reg_dead_p (2, operands[1])
3807    && peep2_reg_dead_p (3, operands[2])
3808    && !reg_mentioned_p (operands[2], operands[3])"
3809   [(set (match_dup 0) (match_dup 1))
3810    (parallel [(set (match_dup 1) (ashiftrt:SI (match_dup 1) (const_int 31)))
3811               (clobber (reg:CC FLAGS_REG))])
3812    (set (match_dup 3) (match_dup 1))])
3813
3814 ;; Extend to register case.  Optimize case where source and destination
3815 ;; registers match and cases where we can use cltd.
3816 (define_split
3817   [(set (match_operand:DI 0 "register_operand")
3818         (sign_extend:DI (match_operand:SI 1 "register_operand")))
3819    (clobber (reg:CC FLAGS_REG))
3820    (clobber (match_scratch:SI 2))]
3821   "reload_completed"
3822   [(const_int 0)]
3823 {
3824   split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);
3825
3826   if (true_regnum (operands[3]) != true_regnum (operands[1]))
3827     emit_move_insn (operands[3], operands[1]);
3828
3829   /* Generate a cltd if possible and doing so it profitable.  */
3830   if ((optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
3831       && true_regnum (operands[3]) == AX_REG
3832       && true_regnum (operands[4]) == DX_REG)
3833     {
3834       emit_insn (gen_ashrsi3_cvt (operands[4], operands[3], GEN_INT (31)));
3835       DONE;
3836     }
3837
3838   if (true_regnum (operands[4]) != true_regnum (operands[1]))
3839     emit_move_insn (operands[4], operands[1]);
3840
3841   emit_insn (gen_ashrsi3_cvt (operands[4], operands[4], GEN_INT (31)));
3842   DONE;
3843 })
3844
3845 (define_insn "extend<mode>di2"
3846   [(set (match_operand:DI 0 "register_operand" "=r")
3847         (sign_extend:DI
3848          (match_operand:SWI12 1 "nonimmediate_operand" "<r>m")))]
3849   "TARGET_64BIT"
3850   "movs{<imodesuffix>q|x}\t{%1, %0|%0, %1}"
3851   [(set_attr "type" "imovx")
3852    (set_attr "mode" "DI")])
3853
3854 (define_insn "extendhisi2"
3855   [(set (match_operand:SI 0 "register_operand" "=*a,r")
3856         (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "*0,rm")))]
3857   ""
3858 {
3859   switch (get_attr_prefix_0f (insn))
3860     {
3861     case 0:
3862       return "{cwtl|cwde}";
3863     default:
3864       return "movs{wl|x}\t{%1, %0|%0, %1}";
3865     }
3866 }
3867   [(set_attr "type" "imovx")
3868    (set_attr "mode" "SI")
3869    (set (attr "prefix_0f")
3870      ;; movsx is short decodable while cwtl is vector decoded.
3871      (if_then_else (and (eq_attr "cpu" "!k6")
3872                         (eq_attr "alternative" "0"))
3873         (const_string "0")
3874         (const_string "1")))
3875    (set (attr "modrm")
3876      (if_then_else (eq_attr "prefix_0f" "0")
3877         (const_string "0")
3878         (const_string "1")))])
3879
3880 (define_insn "*extendhisi2_zext"
3881   [(set (match_operand:DI 0 "register_operand" "=*a,r")
3882         (zero_extend:DI
3883          (sign_extend:SI
3884           (match_operand:HI 1 "nonimmediate_operand" "*0,rm"))))]
3885   "TARGET_64BIT"
3886 {
3887   switch (get_attr_prefix_0f (insn))
3888     {
3889     case 0:
3890       return "{cwtl|cwde}";
3891     default:
3892       return "movs{wl|x}\t{%1, %k0|%k0, %1}";
3893     }
3894 }
3895   [(set_attr "type" "imovx")
3896    (set_attr "mode" "SI")
3897    (set (attr "prefix_0f")
3898      ;; movsx is short decodable while cwtl is vector decoded.
3899      (if_then_else (and (eq_attr "cpu" "!k6")
3900                         (eq_attr "alternative" "0"))
3901         (const_string "0")
3902         (const_string "1")))
3903    (set (attr "modrm")
3904      (if_then_else (eq_attr "prefix_0f" "0")
3905         (const_string "0")
3906         (const_string "1")))])
3907
3908 (define_insn "extendqisi2"
3909   [(set (match_operand:SI 0 "register_operand" "=r")
3910         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm")))]
3911   ""
3912   "movs{bl|x}\t{%1, %0|%0, %1}"
3913    [(set_attr "type" "imovx")
3914     (set_attr "mode" "SI")])
3915
3916 (define_insn "*extendqisi2_zext"
3917   [(set (match_operand:DI 0 "register_operand" "=r")
3918         (zero_extend:DI
3919           (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm"))))]
3920   "TARGET_64BIT"
3921   "movs{bl|x}\t{%1, %k0|%k0, %1}"
3922    [(set_attr "type" "imovx")
3923     (set_attr "mode" "SI")])
3924
3925 (define_insn "extendqihi2"
3926   [(set (match_operand:HI 0 "register_operand" "=*a,r")
3927         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "*0,qm")))]
3928   ""
3929 {
3930   switch (get_attr_prefix_0f (insn))
3931     {
3932     case 0:
3933       return "{cbtw|cbw}";
3934     default:
3935       return "movs{bw|x}\t{%1, %0|%0, %1}";
3936     }
3937 }
3938   [(set_attr "type" "imovx")
3939    (set_attr "mode" "HI")
3940    (set (attr "prefix_0f")
3941      ;; movsx is short decodable while cwtl is vector decoded.
3942      (if_then_else (and (eq_attr "cpu" "!k6")
3943                         (eq_attr "alternative" "0"))
3944         (const_string "0")
3945         (const_string "1")))
3946    (set (attr "modrm")
3947      (if_then_else (eq_attr "prefix_0f" "0")
3948         (const_string "0")
3949         (const_string "1")))])
3950 \f
3951 ;; Conversions between float and double.
3952
3953 ;; These are all no-ops in the model used for the 80387.
3954 ;; So just emit moves.
3955
3956 ;; %%% Kill these when call knows how to work out a DFmode push earlier.
3957 (define_split
3958   [(set (match_operand:DF 0 "push_operand")
3959         (float_extend:DF (match_operand:SF 1 "fp_register_operand")))]
3960   "reload_completed"
3961   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (const_int -8)))
3962    (set (mem:DF (reg:P SP_REG)) (float_extend:DF (match_dup 1)))])
3963
3964 (define_split
3965   [(set (match_operand:XF 0 "push_operand")
3966         (float_extend:XF (match_operand:MODEF 1 "fp_register_operand")))]
3967   "reload_completed"
3968   [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
3969    (set (mem:XF (reg:P SP_REG)) (float_extend:XF (match_dup 1)))]
3970   "operands[2] = GEN_INT (-GET_MODE_SIZE (XFmode));")
3971
3972 (define_expand "extendsfdf2"
3973   [(set (match_operand:DF 0 "nonimmediate_operand")
3974         (float_extend:DF (match_operand:SF 1 "general_operand")))]
3975   "TARGET_80387 || (TARGET_SSE2 && TARGET_SSE_MATH)"
3976 {
3977   /* ??? Needed for compress_float_constant since all fp constants
3978      are TARGET_LEGITIMATE_CONSTANT_P.  */
3979   if (GET_CODE (operands[1]) == CONST_DOUBLE)
3980     {
3981       if ((!TARGET_SSE2 || TARGET_MIX_SSE_I387)
3982           && standard_80387_constant_p (operands[1]) > 0)
3983         {
3984           operands[1] = simplify_const_unary_operation
3985             (FLOAT_EXTEND, DFmode, operands[1], SFmode);
3986           emit_move_insn_1 (operands[0], operands[1]);
3987           DONE;
3988         }
3989       operands[1] = validize_mem (force_const_mem (SFmode, operands[1]));
3990     }
3991 })
3992
3993 /* For converting SF(xmm2) to DF(xmm1), use the following code instead of
3994    cvtss2sd:
3995       unpcklps xmm2,xmm2   ; packed conversion might crash on signaling NaNs
3996       cvtps2pd xmm2,xmm1
3997    We do the conversion post reload to avoid producing of 128bit spills
3998    that might lead to ICE on 32bit target.  The sequence unlikely combine
3999    anyway.  */
4000 (define_split
4001   [(set (match_operand:DF 0 "register_operand")
4002         (float_extend:DF
4003           (match_operand:SF 1 "nonimmediate_operand")))]
4004   "TARGET_USE_VECTOR_FP_CONVERTS
4005    && optimize_insn_for_speed_p ()
4006    && reload_completed && SSE_REG_P (operands[0])"
4007    [(set (match_dup 2)
4008          (float_extend:V2DF
4009            (vec_select:V2SF
4010              (match_dup 3)
4011              (parallel [(const_int 0) (const_int 1)]))))]
4012 {
4013   operands[2] = simplify_gen_subreg (V2DFmode, operands[0], DFmode, 0);
4014   operands[3] = simplify_gen_subreg (V4SFmode, operands[0], DFmode, 0);
4015   /* Use movss for loading from memory, unpcklps reg, reg for registers.
4016      Try to avoid move when unpacking can be done in source.  */
4017   if (REG_P (operands[1]))
4018     {
4019       /* If it is unsafe to overwrite upper half of source, we need
4020          to move to destination and unpack there.  */
4021       if ((ORIGINAL_REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
4022            || PSEUDO_REGNO_BYTES (ORIGINAL_REGNO (operands[1])) > 4)
4023           && true_regnum (operands[0]) != true_regnum (operands[1]))
4024         {
4025           rtx tmp = gen_rtx_REG (SFmode, true_regnum (operands[0]));
4026           emit_move_insn (tmp, operands[1]);
4027         }
4028       else
4029         operands[3] = simplify_gen_subreg (V4SFmode, operands[1], SFmode, 0);
4030       emit_insn (gen_vec_interleave_lowv4sf (operands[3], operands[3],
4031                                              operands[3]));
4032     }
4033   else
4034     emit_insn (gen_vec_setv4sf_0 (operands[3],
4035                                   CONST0_RTX (V4SFmode), operands[1]));
4036 })
4037
4038 ;; It's more profitable to split and then extend in the same register.
4039 (define_peephole2
4040   [(set (match_operand:DF 0 "register_operand")
4041         (float_extend:DF
4042           (match_operand:SF 1 "memory_operand")))]
4043   "TARGET_SPLIT_MEM_OPND_FOR_FP_CONVERTS
4044    && optimize_insn_for_speed_p ()
4045    && SSE_REG_P (operands[0])"
4046   [(set (match_dup 2) (match_dup 1))
4047    (set (match_dup 0) (float_extend:DF (match_dup 2)))]
4048   "operands[2] = gen_rtx_REG (SFmode, REGNO (operands[0]));")
4049
4050 (define_insn "*extendsfdf2_mixed"
4051   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,m,x")
4052         (float_extend:DF
4053           (match_operand:SF 1 "nonimmediate_operand" "fm,f,xm")))]
4054   "TARGET_SSE2 && TARGET_MIX_SSE_I387"
4055 {
4056   switch (which_alternative)
4057     {
4058     case 0:
4059     case 1:
4060       return output_387_reg_move (insn, operands);
4061
4062     case 2:
4063       return "%vcvtss2sd\t{%1, %d0|%d0, %1}";
4064
4065     default:
4066       gcc_unreachable ();
4067     }
4068 }
4069   [(set_attr "type" "fmov,fmov,ssecvt")
4070    (set_attr "prefix" "orig,orig,maybe_vex")
4071    (set_attr "mode" "SF,XF,DF")])
4072
4073 (define_insn "*extendsfdf2_sse"
4074   [(set (match_operand:DF 0 "nonimmediate_operand" "=x")
4075         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "xm")))]
4076   "TARGET_SSE2 && TARGET_SSE_MATH"
4077   "%vcvtss2sd\t{%1, %d0|%d0, %1}"
4078   [(set_attr "type" "ssecvt")
4079    (set_attr "prefix" "maybe_vex")
4080    (set_attr "mode" "DF")])
4081
4082 (define_insn "*extendsfdf2_i387"
4083   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,m")
4084         (float_extend:DF (match_operand:SF 1 "nonimmediate_operand" "fm,f")))]
4085   "TARGET_80387"
4086   "* return output_387_reg_move (insn, operands);"
4087   [(set_attr "type" "fmov")
4088    (set_attr "mode" "SF,XF")])
4089
4090 (define_expand "extend<mode>xf2"
4091   [(set (match_operand:XF 0 "nonimmediate_operand")
4092         (float_extend:XF (match_operand:MODEF 1 "general_operand")))]
4093   "TARGET_80387"
4094 {
4095   /* ??? Needed for compress_float_constant since all fp constants
4096      are TARGET_LEGITIMATE_CONSTANT_P.  */
4097   if (GET_CODE (operands[1]) == CONST_DOUBLE)
4098     {
4099       if (standard_80387_constant_p (operands[1]) > 0)
4100         {
4101           operands[1] = simplify_const_unary_operation
4102             (FLOAT_EXTEND, XFmode, operands[1], <MODE>mode);
4103           emit_move_insn_1 (operands[0], operands[1]);
4104           DONE;
4105         }
4106       operands[1] = validize_mem (force_const_mem (<MODE>mode, operands[1]));
4107     }
4108 })
4109
4110 (define_insn "*extend<mode>xf2_i387"
4111   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m")
4112         (float_extend:XF
4113           (match_operand:MODEF 1 "nonimmediate_operand" "fm,f")))]
4114   "TARGET_80387"
4115   "* return output_387_reg_move (insn, operands);"
4116   [(set_attr "type" "fmov")
4117    (set_attr "mode" "<MODE>,XF")])
4118
4119 ;; %%% This seems bad bad news.
4120 ;; This cannot output into an f-reg because there is no way to be sure
4121 ;; of truncating in that case.  Otherwise this is just like a simple move
4122 ;; insn.  So we pretend we can output to a reg in order to get better
4123 ;; register preferencing, but we really use a stack slot.
4124
4125 ;; Conversion from DFmode to SFmode.
4126
4127 (define_expand "truncdfsf2"
4128   [(set (match_operand:SF 0 "nonimmediate_operand")
4129         (float_truncate:SF
4130           (match_operand:DF 1 "nonimmediate_operand")))]
4131   "TARGET_80387 || (TARGET_SSE2 && TARGET_SSE_MATH)"
4132 {
4133   if (TARGET_SSE2 && TARGET_SSE_MATH && !TARGET_MIX_SSE_I387)
4134     ;
4135   else if (flag_unsafe_math_optimizations)
4136     ;
4137   else
4138     {
4139       rtx temp = assign_386_stack_local (SFmode, SLOT_TEMP);
4140       emit_insn (gen_truncdfsf2_with_temp (operands[0], operands[1], temp));
4141       DONE;
4142     }
4143 })
4144
4145 /* For converting DF(xmm2) to SF(xmm1), use the following code instead of
4146    cvtsd2ss:
4147       unpcklpd xmm2,xmm2   ; packed conversion might crash on signaling NaNs
4148       cvtpd2ps xmm2,xmm1
4149    We do the conversion post reload to avoid producing of 128bit spills
4150    that might lead to ICE on 32bit target.  The sequence unlikely combine
4151    anyway.  */
4152 (define_split
4153   [(set (match_operand:SF 0 "register_operand")
4154         (float_truncate:SF
4155           (match_operand:DF 1 "nonimmediate_operand")))]
4156   "TARGET_USE_VECTOR_FP_CONVERTS
4157    && optimize_insn_for_speed_p ()
4158    && reload_completed && SSE_REG_P (operands[0])"
4159    [(set (match_dup 2)
4160          (vec_concat:V4SF
4161            (float_truncate:V2SF
4162              (match_dup 4))
4163            (match_dup 3)))]
4164 {
4165   operands[2] = simplify_gen_subreg (V4SFmode, operands[0], SFmode, 0);
4166   operands[3] = CONST0_RTX (V2SFmode);
4167   operands[4] = simplify_gen_subreg (V2DFmode, operands[0], SFmode, 0);
4168   /* Use movsd for loading from memory, unpcklpd for registers.
4169      Try to avoid move when unpacking can be done in source, or SSE3
4170      movddup is available.  */
4171   if (REG_P (operands[1]))
4172     {
4173       if (!TARGET_SSE3
4174           && true_regnum (operands[0]) != true_regnum (operands[1])
4175           && (ORIGINAL_REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
4176               || PSEUDO_REGNO_BYTES (ORIGINAL_REGNO (operands[1])) > 8))
4177         {
4178           rtx tmp = simplify_gen_subreg (DFmode, operands[0], SFmode, 0);
4179           emit_move_insn (tmp, operands[1]);
4180           operands[1] = tmp;
4181         }
4182       else if (!TARGET_SSE3)
4183         operands[4] = simplify_gen_subreg (V2DFmode, operands[1], DFmode, 0);
4184       emit_insn (gen_vec_dupv2df (operands[4], operands[1]));
4185     }
4186   else
4187     emit_insn (gen_sse2_loadlpd (operands[4],
4188                                  CONST0_RTX (V2DFmode), operands[1]));
4189 })
4190
4191 ;; It's more profitable to split and then extend in the same register.
4192 (define_peephole2
4193   [(set (match_operand:SF 0 "register_operand")
4194         (float_truncate:SF
4195           (match_operand:DF 1 "memory_operand")))]
4196   "TARGET_SPLIT_MEM_OPND_FOR_FP_CONVERTS
4197    && optimize_insn_for_speed_p ()
4198    && SSE_REG_P (operands[0])"
4199   [(set (match_dup 2) (match_dup 1))
4200    (set (match_dup 0) (float_truncate:SF (match_dup 2)))]
4201   "operands[2] = gen_rtx_REG (DFmode, REGNO (operands[0]));")
4202
4203 (define_expand "truncdfsf2_with_temp"
4204   [(parallel [(set (match_operand:SF 0)
4205                    (float_truncate:SF (match_operand:DF 1)))
4206               (clobber (match_operand:SF 2))])])
4207
4208 (define_insn "*truncdfsf_fast_mixed"
4209   [(set (match_operand:SF 0 "nonimmediate_operand"   "=fm,x")
4210         (float_truncate:SF
4211           (match_operand:DF 1 "nonimmediate_operand" "f  ,xm")))]
4212   "TARGET_SSE2 && TARGET_MIX_SSE_I387 && flag_unsafe_math_optimizations"
4213 {
4214   switch (which_alternative)
4215     {
4216     case 0:
4217       return output_387_reg_move (insn, operands);
4218     case 1:
4219       return "%vcvtsd2ss\t{%1, %d0|%d0, %1}";
4220     default:
4221       gcc_unreachable ();
4222     }
4223 }
4224   [(set_attr "type" "fmov,ssecvt")
4225    (set_attr "prefix" "orig,maybe_vex")
4226    (set_attr "mode" "SF")])
4227
4228 ;; Yes, this one doesn't depend on flag_unsafe_math_optimizations,
4229 ;; because nothing we do here is unsafe.
4230 (define_insn "*truncdfsf_fast_sse"
4231   [(set (match_operand:SF 0 "nonimmediate_operand"   "=x")
4232         (float_truncate:SF
4233           (match_operand:DF 1 "nonimmediate_operand" "xm")))]
4234   "TARGET_SSE2 && TARGET_SSE_MATH"
4235   "%vcvtsd2ss\t{%1, %d0|%d0, %1}"
4236   [(set_attr "type" "ssecvt")
4237    (set_attr "prefix" "maybe_vex")
4238    (set_attr "mode" "SF")])
4239
4240 (define_insn "*truncdfsf_fast_i387"
4241   [(set (match_operand:SF 0 "nonimmediate_operand"   "=fm")
4242         (float_truncate:SF
4243           (match_operand:DF 1 "nonimmediate_operand" "f")))]
4244   "TARGET_80387 && flag_unsafe_math_optimizations"
4245   "* return output_387_reg_move (insn, operands);"
4246   [(set_attr "type" "fmov")
4247    (set_attr "mode" "SF")])
4248
4249 (define_insn "*truncdfsf_mixed"
4250   [(set (match_operand:SF 0 "nonimmediate_operand"   "=m,x ,?f,?x,?*r")
4251         (float_truncate:SF
4252           (match_operand:DF 1 "nonimmediate_operand" "f ,xm,f ,f ,f")))
4253    (clobber (match_operand:SF 2 "memory_operand"     "=X,X ,m ,m ,m"))]
4254   "TARGET_MIX_SSE_I387"
4255 {
4256   switch (which_alternative)
4257     {
4258     case 0:
4259       return output_387_reg_move (insn, operands);
4260     case 1:
4261       return "%vcvtsd2ss\t{%1, %d0|%d0, %1}";
4262
4263     default:
4264       return "#";
4265     }
4266 }
4267   [(set_attr "isa" "*,sse2,*,*,*")
4268    (set_attr "type" "fmov,ssecvt,multi,multi,multi")
4269    (set_attr "unit" "*,*,i387,i387,i387")
4270    (set_attr "prefix" "orig,maybe_vex,orig,orig,orig")
4271    (set_attr "mode" "SF")])
4272
4273 (define_insn "*truncdfsf_i387"
4274   [(set (match_operand:SF 0 "nonimmediate_operand"   "=m,?f,?x,?*r")
4275         (float_truncate:SF
4276           (match_operand:DF 1 "nonimmediate_operand" "f ,f ,f ,f")))
4277    (clobber (match_operand:SF 2 "memory_operand"     "=X,m ,m ,m"))]
4278   "TARGET_80387"
4279 {
4280   switch (which_alternative)
4281     {
4282     case 0:
4283       return output_387_reg_move (insn, operands);
4284
4285     default:
4286       return "#";
4287     }
4288 }
4289   [(set_attr "type" "fmov,multi,multi,multi")
4290    (set_attr "unit" "*,i387,i387,i387")
4291    (set_attr "mode" "SF")])
4292
4293 (define_insn "*truncdfsf2_i387_1"
4294   [(set (match_operand:SF 0 "memory_operand" "=m")
4295         (float_truncate:SF
4296           (match_operand:DF 1 "register_operand" "f")))]
4297   "TARGET_80387
4298    && !(TARGET_SSE2 && TARGET_SSE_MATH)
4299    && !TARGET_MIX_SSE_I387"
4300   "* return output_387_reg_move (insn, operands);"
4301   [(set_attr "type" "fmov")
4302    (set_attr "mode" "SF")])
4303
4304 (define_split
4305   [(set (match_operand:SF 0 "register_operand")
4306         (float_truncate:SF
4307          (match_operand:DF 1 "fp_register_operand")))
4308    (clobber (match_operand 2))]
4309   "reload_completed"
4310   [(set (match_dup 2) (match_dup 1))
4311    (set (match_dup 0) (match_dup 2))]
4312   "operands[1] = gen_rtx_REG (SFmode, true_regnum (operands[1]));")
4313
4314 ;; Conversion from XFmode to {SF,DF}mode
4315
4316 (define_expand "truncxf<mode>2"
4317   [(parallel [(set (match_operand:MODEF 0 "nonimmediate_operand")
4318                    (float_truncate:MODEF
4319                      (match_operand:XF 1 "register_operand")))
4320               (clobber (match_dup 2))])]
4321   "TARGET_80387"
4322 {
4323   if (flag_unsafe_math_optimizations)
4324     {
4325       rtx reg = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (<MODE>mode);
4326       emit_insn (gen_truncxf<mode>2_i387_noop (reg, operands[1]));
4327       if (reg != operands[0])
4328         emit_move_insn (operands[0], reg);
4329       DONE;
4330     }
4331   else
4332     operands[2] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
4333 })
4334
4335 (define_insn "*truncxfsf2_mixed"
4336   [(set (match_operand:SF 0 "nonimmediate_operand" "=m,?f,?x,?*r")
4337         (float_truncate:SF
4338           (match_operand:XF 1 "register_operand"   "f ,f ,f ,f")))
4339    (clobber (match_operand:SF 2 "memory_operand"   "=X,m ,m ,m"))]
4340   "TARGET_80387"
4341 {
4342   gcc_assert (!which_alternative);
4343   return output_387_reg_move (insn, operands);
4344 }
4345   [(set_attr "type" "fmov,multi,multi,multi")
4346    (set_attr "unit" "*,i387,i387,i387")
4347    (set_attr "mode" "SF")])
4348
4349 (define_insn "*truncxfdf2_mixed"
4350   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,?f,?x,?*r")
4351         (float_truncate:DF
4352           (match_operand:XF 1 "register_operand"   "f ,f ,f  ,f")))
4353    (clobber (match_operand:DF 2 "memory_operand"   "=X,m ,m  ,m"))]
4354   "TARGET_80387"
4355 {
4356   gcc_assert (!which_alternative);
4357   return output_387_reg_move (insn, operands);
4358 }
4359   [(set_attr "isa" "*,*,sse2,*")
4360    (set_attr "type" "fmov,multi,multi,multi")
4361    (set_attr "unit" "*,i387,i387,i387")
4362    (set_attr "mode" "DF")])
4363
4364 (define_insn "truncxf<mode>2_i387_noop"
4365   [(set (match_operand:MODEF 0 "register_operand" "=f")
4366         (float_truncate:MODEF
4367           (match_operand:XF 1 "register_operand" "f")))]
4368   "TARGET_80387 && flag_unsafe_math_optimizations"
4369   "* return output_387_reg_move (insn, operands);"
4370   [(set_attr "type" "fmov")
4371    (set_attr "mode" "<MODE>")])
4372
4373 (define_insn "*truncxf<mode>2_i387"
4374   [(set (match_operand:MODEF 0 "memory_operand" "=m")
4375         (float_truncate:MODEF
4376           (match_operand:XF 1 "register_operand" "f")))]
4377   "TARGET_80387"
4378   "* return output_387_reg_move (insn, operands);"
4379   [(set_attr "type" "fmov")
4380    (set_attr "mode" "<MODE>")])
4381
4382 (define_split
4383   [(set (match_operand:MODEF 0 "register_operand")
4384         (float_truncate:MODEF
4385           (match_operand:XF 1 "register_operand")))
4386    (clobber (match_operand:MODEF 2 "memory_operand"))]
4387   "TARGET_80387 && reload_completed"
4388   [(set (match_dup 2) (float_truncate:MODEF (match_dup 1)))
4389    (set (match_dup 0) (match_dup 2))])
4390
4391 (define_split
4392   [(set (match_operand:MODEF 0 "memory_operand")
4393         (float_truncate:MODEF
4394           (match_operand:XF 1 "register_operand")))
4395    (clobber (match_operand:MODEF 2 "memory_operand"))]
4396   "TARGET_80387"
4397   [(set (match_dup 0) (float_truncate:MODEF (match_dup 1)))])
4398 \f
4399 ;; Signed conversion to DImode.
4400
4401 (define_expand "fix_truncxfdi2"
4402   [(parallel [(set (match_operand:DI 0 "nonimmediate_operand")
4403                    (fix:DI (match_operand:XF 1 "register_operand")))
4404               (clobber (reg:CC FLAGS_REG))])]
4405   "TARGET_80387"
4406 {
4407   if (TARGET_FISTTP)
4408    {
4409      emit_insn (gen_fix_truncdi_fisttp_i387_1 (operands[0], operands[1]));
4410      DONE;
4411    }
4412 })
4413
4414 (define_expand "fix_trunc<mode>di2"
4415   [(parallel [(set (match_operand:DI 0 "nonimmediate_operand")
4416                    (fix:DI (match_operand:MODEF 1 "register_operand")))
4417               (clobber (reg:CC FLAGS_REG))])]
4418   "TARGET_80387 || (TARGET_64BIT && SSE_FLOAT_MODE_P (<MODE>mode))"
4419 {
4420   if (TARGET_FISTTP
4421       && !(TARGET_64BIT && SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))
4422    {
4423      emit_insn (gen_fix_truncdi_fisttp_i387_1 (operands[0], operands[1]));
4424      DONE;
4425    }
4426   if (TARGET_64BIT && SSE_FLOAT_MODE_P (<MODE>mode))
4427    {
4428      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (DImode);
4429      emit_insn (gen_fix_trunc<mode>di_sse (out, operands[1]));
4430      if (out != operands[0])
4431         emit_move_insn (operands[0], out);
4432      DONE;
4433    }
4434 })
4435
4436 ;; Signed conversion to SImode.
4437
4438 (define_expand "fix_truncxfsi2"
4439   [(parallel [(set (match_operand:SI 0 "nonimmediate_operand")
4440                    (fix:SI (match_operand:XF 1 "register_operand")))
4441               (clobber (reg:CC FLAGS_REG))])]
4442   "TARGET_80387"
4443 {
4444   if (TARGET_FISTTP)
4445    {
4446      emit_insn (gen_fix_truncsi_fisttp_i387_1 (operands[0], operands[1]));
4447      DONE;
4448    }
4449 })
4450
4451 (define_expand "fix_trunc<mode>si2"
4452   [(parallel [(set (match_operand:SI 0 "nonimmediate_operand")
4453                    (fix:SI (match_operand:MODEF 1 "register_operand")))
4454               (clobber (reg:CC FLAGS_REG))])]
4455   "TARGET_80387 || SSE_FLOAT_MODE_P (<MODE>mode)"
4456 {
4457   if (TARGET_FISTTP
4458       && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))
4459    {
4460      emit_insn (gen_fix_truncsi_fisttp_i387_1 (operands[0], operands[1]));
4461      DONE;
4462    }
4463   if (SSE_FLOAT_MODE_P (<MODE>mode))
4464    {
4465      rtx out = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (SImode);
4466      emit_insn (gen_fix_trunc<mode>si_sse (out, operands[1]));
4467      if (out != operands[0])
4468         emit_move_insn (operands[0], out);
4469      DONE;
4470    }
4471 })
4472
4473 ;; Signed conversion to HImode.
4474
4475 (define_expand "fix_trunc<mode>hi2"
4476   [(parallel [(set (match_operand:HI 0 "nonimmediate_operand")
4477                    (fix:HI (match_operand:X87MODEF 1 "register_operand")))
4478               (clobber (reg:CC FLAGS_REG))])]
4479   "TARGET_80387
4480    && !(SSE_FLOAT_MODE_P (<MODE>mode) && (!TARGET_FISTTP || TARGET_SSE_MATH))"
4481 {
4482   if (TARGET_FISTTP)
4483    {
4484      emit_insn (gen_fix_trunchi_fisttp_i387_1 (operands[0], operands[1]));
4485      DONE;
4486    }
4487 })
4488
4489 ;; Unsigned conversion to SImode.
4490
4491 (define_expand "fixuns_trunc<mode>si2"
4492   [(parallel
4493     [(set (match_operand:SI 0 "register_operand")
4494           (unsigned_fix:SI
4495             (match_operand:MODEF 1 "nonimmediate_operand")))
4496      (use (match_dup 2))
4497      (clobber (match_scratch:<ssevecmode> 3))
4498      (clobber (match_scratch:<ssevecmode> 4))])]
4499   "!TARGET_64BIT && TARGET_SSE2 && TARGET_SSE_MATH"
4500 {
4501   machine_mode mode = <MODE>mode;
4502   machine_mode vecmode = <ssevecmode>mode;
4503   REAL_VALUE_TYPE TWO31r;
4504   rtx two31;
4505
4506   if (optimize_insn_for_size_p ())
4507     FAIL;
4508
4509   real_ldexp (&TWO31r, &dconst1, 31);
4510   two31 = const_double_from_real_value (TWO31r, mode);
4511   two31 = ix86_build_const_vector (vecmode, true, two31);
4512   operands[2] = force_reg (vecmode, two31);
4513 })
4514
4515 (define_insn_and_split "*fixuns_trunc<mode>_1"
4516   [(set (match_operand:SI 0 "register_operand" "=&x,&x")
4517         (unsigned_fix:SI
4518           (match_operand:MODEF 3 "nonimmediate_operand" "xm,xm")))
4519    (use (match_operand:<ssevecmode> 4  "nonimmediate_operand" "m,x"))
4520    (clobber (match_scratch:<ssevecmode> 1 "=x,&x"))
4521    (clobber (match_scratch:<ssevecmode> 2 "=x,x"))]
4522   "!TARGET_64BIT && TARGET_SSE2 && TARGET_SSE_MATH
4523    && optimize_function_for_speed_p (cfun)"
4524   "#"
4525   "&& reload_completed"
4526   [(const_int 0)]
4527 {
4528   ix86_split_convert_uns_si_sse (operands);
4529   DONE;
4530 })
4531
4532 ;; Unsigned conversion to HImode.
4533 ;; Without these patterns, we'll try the unsigned SI conversion which
4534 ;; is complex for SSE, rather than the signed SI conversion, which isn't.
4535
4536 (define_expand "fixuns_trunc<mode>hi2"
4537   [(set (match_dup 2)
4538         (fix:SI (match_operand:MODEF 1 "nonimmediate_operand")))
4539    (set (match_operand:HI 0 "nonimmediate_operand")
4540         (subreg:HI (match_dup 2) 0))]
4541   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
4542   "operands[2] = gen_reg_rtx (SImode);")
4543
4544 ;; When SSE is available, it is always faster to use it!
4545 (define_insn "fix_trunc<MODEF:mode><SWI48:mode>_sse"
4546   [(set (match_operand:SWI48 0 "register_operand" "=r,r")
4547         (fix:SWI48 (match_operand:MODEF 1 "nonimmediate_operand" "x,m")))]
4548   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode)
4549    && (!TARGET_FISTTP || TARGET_SSE_MATH)"
4550   "%vcvtt<MODEF:ssemodesuffix>2si<SWI48:rex64suffix>\t{%1, %0|%0, %1}"
4551   [(set_attr "type" "sseicvt")
4552    (set_attr "prefix" "maybe_vex")
4553    (set (attr "prefix_rex")
4554         (if_then_else
4555           (match_test "<SWI48:MODE>mode == DImode")
4556           (const_string "1")
4557           (const_string "*")))
4558    (set_attr "mode" "<MODEF:MODE>")
4559    (set_attr "athlon_decode" "double,vector")
4560    (set_attr "amdfam10_decode" "double,double")
4561    (set_attr "bdver1_decode" "double,double")])
4562
4563 ;; Avoid vector decoded forms of the instruction.
4564 (define_peephole2
4565   [(match_scratch:MODEF 2 "x")
4566    (set (match_operand:SWI48 0 "register_operand")
4567         (fix:SWI48 (match_operand:MODEF 1 "memory_operand")))]
4568   "TARGET_AVOID_VECTOR_DECODE
4569    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode)
4570    && optimize_insn_for_speed_p ()"
4571   [(set (match_dup 2) (match_dup 1))
4572    (set (match_dup 0) (fix:SWI48 (match_dup 2)))])
4573
4574 (define_insn_and_split "fix_trunc<mode>_fisttp_i387_1"
4575   [(set (match_operand:SWI248x 0 "nonimmediate_operand")
4576         (fix:SWI248x (match_operand 1 "register_operand")))]
4577   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4578    && TARGET_FISTTP
4579    && !((SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
4580          && (TARGET_64BIT || <MODE>mode != DImode))
4581         && TARGET_SSE_MATH)
4582    && can_create_pseudo_p ()"
4583   "#"
4584   "&& 1"
4585   [(const_int 0)]
4586 {
4587   if (memory_operand (operands[0], VOIDmode))
4588     emit_insn (gen_fix_trunc<mode>_i387_fisttp (operands[0], operands[1]));
4589   else
4590     {
4591       operands[2] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
4592       emit_insn (gen_fix_trunc<mode>_i387_fisttp_with_temp (operands[0],
4593                                                             operands[1],
4594                                                             operands[2]));
4595     }
4596   DONE;
4597 }
4598   [(set_attr "type" "fisttp")
4599    (set_attr "mode" "<MODE>")])
4600
4601 (define_insn "fix_trunc<mode>_i387_fisttp"
4602   [(set (match_operand:SWI248x 0 "memory_operand" "=m")
4603         (fix:SWI248x (match_operand 1 "register_operand" "f")))
4604    (clobber (match_scratch:XF 2 "=&1f"))]
4605   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4606    && TARGET_FISTTP
4607    && !((SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
4608          && (TARGET_64BIT || <MODE>mode != DImode))
4609         && TARGET_SSE_MATH)"
4610   "* return output_fix_trunc (insn, operands, true);"
4611   [(set_attr "type" "fisttp")
4612    (set_attr "mode" "<MODE>")])
4613
4614 (define_insn "fix_trunc<mode>_i387_fisttp_with_temp"
4615   [(set (match_operand:SWI248x 0 "nonimmediate_operand" "=m,?r")
4616         (fix:SWI248x (match_operand 1 "register_operand" "f,f")))
4617    (clobber (match_operand:SWI248x 2 "memory_operand" "=X,m"))
4618    (clobber (match_scratch:XF 3 "=&1f,&1f"))]
4619   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4620    && TARGET_FISTTP
4621    && !((SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
4622         && (TARGET_64BIT || <MODE>mode != DImode))
4623         && TARGET_SSE_MATH)"
4624   "#"
4625   [(set_attr "type" "fisttp")
4626    (set_attr "mode" "<MODE>")])
4627
4628 (define_split
4629   [(set (match_operand:SWI248x 0 "register_operand")
4630         (fix:SWI248x (match_operand 1 "register_operand")))
4631    (clobber (match_operand:SWI248x 2 "memory_operand"))
4632    (clobber (match_scratch 3))]
4633   "reload_completed"
4634   [(parallel [(set (match_dup 2) (fix:SWI248x (match_dup 1)))
4635               (clobber (match_dup 3))])
4636    (set (match_dup 0) (match_dup 2))])
4637
4638 (define_split
4639   [(set (match_operand:SWI248x 0 "memory_operand")
4640         (fix:SWI248x (match_operand 1 "register_operand")))
4641    (clobber (match_operand:SWI248x 2 "memory_operand"))
4642    (clobber (match_scratch 3))]
4643   "reload_completed"
4644   [(parallel [(set (match_dup 0) (fix:SWI248x (match_dup 1)))
4645               (clobber (match_dup 3))])])
4646
4647 ;; See the comments in i386.h near OPTIMIZE_MODE_SWITCHING for the description
4648 ;; of the machinery. Please note the clobber of FLAGS_REG. In i387 control
4649 ;; word calculation (inserted by LCM in mode switching pass) a FLAGS_REG
4650 ;; clobbering insns can be used. Look at emit_i387_cw_initialization ()
4651 ;; function in i386.c.
4652 (define_insn_and_split "*fix_trunc<mode>_i387_1"
4653   [(set (match_operand:SWI248x 0 "nonimmediate_operand")
4654         (fix:SWI248x (match_operand 1 "register_operand")))
4655    (clobber (reg:CC FLAGS_REG))]
4656   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4657    && !TARGET_FISTTP
4658    && !(SSE_FLOAT_MODE_P (GET_MODE (operands[1]))
4659          && (TARGET_64BIT || <MODE>mode != DImode))
4660    && can_create_pseudo_p ()"
4661   "#"
4662   "&& 1"
4663   [(const_int 0)]
4664 {
4665   ix86_optimize_mode_switching[I387_TRUNC] = 1;
4666
4667   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
4668   operands[3] = assign_386_stack_local (HImode, SLOT_CW_TRUNC);
4669   if (memory_operand (operands[0], VOIDmode))
4670     emit_insn (gen_fix_trunc<mode>_i387 (operands[0], operands[1],
4671                                          operands[2], operands[3]));
4672   else
4673     {
4674       operands[4] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
4675       emit_insn (gen_fix_trunc<mode>_i387_with_temp (operands[0], operands[1],
4676                                                      operands[2], operands[3],
4677                                                      operands[4]));
4678     }
4679   DONE;
4680 }
4681   [(set_attr "type" "fistp")
4682    (set_attr "i387_cw" "trunc")
4683    (set_attr "mode" "<MODE>")])
4684
4685 (define_insn "fix_truncdi_i387"
4686   [(set (match_operand:DI 0 "memory_operand" "=m")
4687         (fix:DI (match_operand 1 "register_operand" "f")))
4688    (use (match_operand:HI 2 "memory_operand" "m"))
4689    (use (match_operand:HI 3 "memory_operand" "m"))
4690    (clobber (match_scratch:XF 4 "=&1f"))]
4691   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4692    && !TARGET_FISTTP
4693    && !(TARGET_64BIT && SSE_FLOAT_MODE_P (GET_MODE (operands[1])))"
4694   "* return output_fix_trunc (insn, operands, false);"
4695   [(set_attr "type" "fistp")
4696    (set_attr "i387_cw" "trunc")
4697    (set_attr "mode" "DI")])
4698
4699 (define_insn "fix_truncdi_i387_with_temp"
4700   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
4701         (fix:DI (match_operand 1 "register_operand" "f,f")))
4702    (use (match_operand:HI 2 "memory_operand" "m,m"))
4703    (use (match_operand:HI 3 "memory_operand" "m,m"))
4704    (clobber (match_operand:DI 4 "memory_operand" "=X,m"))
4705    (clobber (match_scratch:XF 5 "=&1f,&1f"))]
4706   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4707    && !TARGET_FISTTP
4708    && !(TARGET_64BIT && SSE_FLOAT_MODE_P (GET_MODE (operands[1])))"
4709   "#"
4710   [(set_attr "type" "fistp")
4711    (set_attr "i387_cw" "trunc")
4712    (set_attr "mode" "DI")])
4713
4714 (define_split
4715   [(set (match_operand:DI 0 "register_operand")
4716         (fix:DI (match_operand 1 "register_operand")))
4717    (use (match_operand:HI 2 "memory_operand"))
4718    (use (match_operand:HI 3 "memory_operand"))
4719    (clobber (match_operand:DI 4 "memory_operand"))
4720    (clobber (match_scratch 5))]
4721   "reload_completed"
4722   [(parallel [(set (match_dup 4) (fix:DI (match_dup 1)))
4723               (use (match_dup 2))
4724               (use (match_dup 3))
4725               (clobber (match_dup 5))])
4726    (set (match_dup 0) (match_dup 4))])
4727
4728 (define_split
4729   [(set (match_operand:DI 0 "memory_operand")
4730         (fix:DI (match_operand 1 "register_operand")))
4731    (use (match_operand:HI 2 "memory_operand"))
4732    (use (match_operand:HI 3 "memory_operand"))
4733    (clobber (match_operand:DI 4 "memory_operand"))
4734    (clobber (match_scratch 5))]
4735   "reload_completed"
4736   [(parallel [(set (match_dup 0) (fix:DI (match_dup 1)))
4737               (use (match_dup 2))
4738               (use (match_dup 3))
4739               (clobber (match_dup 5))])])
4740
4741 (define_insn "fix_trunc<mode>_i387"
4742   [(set (match_operand:SWI24 0 "memory_operand" "=m")
4743         (fix:SWI24 (match_operand 1 "register_operand" "f")))
4744    (use (match_operand:HI 2 "memory_operand" "m"))
4745    (use (match_operand:HI 3 "memory_operand" "m"))]
4746   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4747    && !TARGET_FISTTP
4748    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4749   "* return output_fix_trunc (insn, operands, false);"
4750   [(set_attr "type" "fistp")
4751    (set_attr "i387_cw" "trunc")
4752    (set_attr "mode" "<MODE>")])
4753
4754 (define_insn "fix_trunc<mode>_i387_with_temp"
4755   [(set (match_operand:SWI24 0 "nonimmediate_operand" "=m,?r")
4756         (fix:SWI24 (match_operand 1 "register_operand" "f,f")))
4757    (use (match_operand:HI 2 "memory_operand" "m,m"))
4758    (use (match_operand:HI 3 "memory_operand" "m,m"))
4759    (clobber (match_operand:SWI24 4 "memory_operand" "=X,m"))]
4760   "X87_FLOAT_MODE_P (GET_MODE (operands[1]))
4761    && !TARGET_FISTTP
4762    && !SSE_FLOAT_MODE_P (GET_MODE (operands[1]))"
4763   "#"
4764   [(set_attr "type" "fistp")
4765    (set_attr "i387_cw" "trunc")
4766    (set_attr "mode" "<MODE>")])
4767
4768 (define_split
4769   [(set (match_operand:SWI24 0 "register_operand")
4770         (fix:SWI24 (match_operand 1 "register_operand")))
4771    (use (match_operand:HI 2 "memory_operand"))
4772    (use (match_operand:HI 3 "memory_operand"))
4773    (clobber (match_operand:SWI24 4 "memory_operand"))]
4774   "reload_completed"
4775   [(parallel [(set (match_dup 4) (fix:SWI24 (match_dup 1)))
4776               (use (match_dup 2))
4777               (use (match_dup 3))])
4778    (set (match_dup 0) (match_dup 4))])
4779
4780 (define_split
4781   [(set (match_operand:SWI24 0 "memory_operand")
4782         (fix:SWI24 (match_operand 1 "register_operand")))
4783    (use (match_operand:HI 2 "memory_operand"))
4784    (use (match_operand:HI 3 "memory_operand"))
4785    (clobber (match_operand:SWI24 4 "memory_operand"))]
4786   "reload_completed"
4787   [(parallel [(set (match_dup 0) (fix:SWI24 (match_dup 1)))
4788               (use (match_dup 2))
4789               (use (match_dup 3))])])
4790
4791 (define_insn "x86_fnstcw_1"
4792   [(set (match_operand:HI 0 "memory_operand" "=m")
4793         (unspec:HI [(reg:HI FPCR_REG)] UNSPEC_FSTCW))]
4794   "TARGET_80387"
4795   "fnstcw\t%0"
4796   [(set (attr "length")
4797         (symbol_ref "ix86_attr_length_address_default (insn) + 2"))
4798    (set_attr "mode" "HI")
4799    (set_attr "unit" "i387")
4800    (set_attr "bdver1_decode" "vector")])
4801
4802 (define_insn "x86_fldcw_1"
4803   [(set (reg:HI FPCR_REG)
4804         (unspec:HI [(match_operand:HI 0 "memory_operand" "m")] UNSPEC_FLDCW))]
4805   "TARGET_80387"
4806   "fldcw\t%0"
4807   [(set (attr "length")
4808         (symbol_ref "ix86_attr_length_address_default (insn) + 2"))
4809    (set_attr "mode" "HI")
4810    (set_attr "unit" "i387")
4811    (set_attr "athlon_decode" "vector")
4812    (set_attr "amdfam10_decode" "vector")
4813    (set_attr "bdver1_decode" "vector")])
4814 \f
4815 ;; Conversion between fixed point and floating point.
4816
4817 ;; Even though we only accept memory inputs, the backend _really_
4818 ;; wants to be able to do this between registers.  Thankfully, LRA
4819 ;; will fix this up for us during register allocation.
4820
4821 (define_insn "floathi<mode>2"
4822   [(set (match_operand:X87MODEF 0 "register_operand" "=f")
4823         (float:X87MODEF (match_operand:HI 1 "nonimmediate_operand" "m")))]
4824   "TARGET_80387
4825    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
4826        || TARGET_MIX_SSE_I387)"
4827   "fild%Z1\t%1"
4828   [(set_attr "type" "fmov")
4829    (set_attr "mode" "<MODE>")
4830    (set_attr "fp_int_src" "true")])
4831
4832 (define_insn "float<SWI48x:mode>xf2"
4833   [(set (match_operand:XF 0 "register_operand" "=f")
4834         (float:XF (match_operand:SWI48x 1 "nonimmediate_operand" "m")))]
4835   "TARGET_80387"
4836   "fild%Z1\t%1"
4837   [(set_attr "type" "fmov")
4838    (set_attr "mode" "XF")
4839    (set_attr "fp_int_src" "true")])
4840
4841 (define_expand "float<SWI48:mode><MODEF:mode>2"
4842   [(set (match_operand:MODEF 0 "register_operand")
4843         (float:MODEF (match_operand:SWI48 1 "nonimmediate_operand")))]
4844   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH)"
4845 {
4846   if (!(SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH)
4847       && !X87_ENABLE_FLOAT (<MODEF:MODE>mode, <SWI48:MODE>mode))
4848     {
4849       rtx reg = gen_reg_rtx (XFmode);
4850       rtx (*insn)(rtx, rtx);
4851
4852       emit_insn (gen_float<SWI48:mode>xf2 (reg, operands[1]));
4853
4854       if (<MODEF:MODE>mode == SFmode)
4855         insn = gen_truncxfsf2;
4856       else if (<MODEF:MODE>mode == DFmode)
4857         insn = gen_truncxfdf2;
4858       else
4859         gcc_unreachable ();
4860
4861       emit_insn (insn (operands[0], reg));
4862       DONE;
4863     }
4864 })
4865
4866 (define_insn "*float<SWI48:mode><MODEF:mode>2_sse"
4867   [(set (match_operand:MODEF 0 "register_operand" "=f,x,x")
4868         (float:MODEF
4869           (match_operand:SWI48 1 "nonimmediate_operand" "m,r,m")))]
4870   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH"
4871   "@
4872    fild%Z1\t%1
4873    %vcvtsi2<MODEF:ssemodesuffix><SWI48:rex64suffix>\t{%1, %d0|%d0, %1}
4874    %vcvtsi2<MODEF:ssemodesuffix><SWI48:rex64suffix>\t{%1, %d0|%d0, %1}"
4875   [(set_attr "type" "fmov,sseicvt,sseicvt")
4876    (set_attr "prefix" "orig,maybe_vex,maybe_vex")
4877    (set_attr "mode" "<MODEF:MODE>")
4878    (set (attr "prefix_rex")
4879      (if_then_else
4880        (and (eq_attr "prefix" "maybe_vex")
4881             (match_test "<SWI48:MODE>mode == DImode"))
4882        (const_string "1")
4883        (const_string "*")))
4884    (set_attr "unit" "i387,*,*")
4885    (set_attr "athlon_decode" "*,double,direct")
4886    (set_attr "amdfam10_decode" "*,vector,double")
4887    (set_attr "bdver1_decode" "*,double,direct")
4888    (set_attr "fp_int_src" "true")
4889    (set (attr "enabled")
4890      (cond [(eq_attr "alternative" "0")
4891               (symbol_ref "TARGET_MIX_SSE_I387
4892                            && X87_ENABLE_FLOAT (<MODEF:MODE>mode,
4893                                                 <SWI48:MODE>mode)")
4894            ]
4895            (symbol_ref "true")))
4896    (set (attr "preferred_for_speed")
4897      (cond [(eq_attr "alternative" "1")
4898               (symbol_ref "TARGET_INTER_UNIT_CONVERSIONS")]
4899            (symbol_ref "true")))])
4900
4901 (define_insn "*float<SWI48x:mode><MODEF:mode>2_i387"
4902   [(set (match_operand:MODEF 0 "register_operand" "=f")
4903         (float:MODEF (match_operand:SWI48x 1 "nonimmediate_operand" "m")))]
4904   "TARGET_80387 && X87_ENABLE_FLOAT (<MODEF:MODE>mode, <SWI48x:MODE>mode)"
4905   "fild%Z1\t%1"
4906   [(set_attr "type" "fmov")
4907    (set_attr "mode" "<MODEF:MODE>")
4908    (set_attr "fp_int_src" "true")])
4909
4910 ;; Try TARGET_USE_VECTOR_CONVERTS, but not so hard as to require extra memory
4911 ;; slots when !TARGET_INTER_UNIT_MOVES_TO_VEC disables the general_regs
4912 ;; alternative in sse2_loadld.
4913 (define_split
4914   [(set (match_operand:MODEF 0 "register_operand")
4915         (float:MODEF (match_operand:SI 1 "nonimmediate_operand")))]
4916   "TARGET_SSE2 && TARGET_SSE_MATH
4917    && TARGET_USE_VECTOR_CONVERTS && optimize_function_for_speed_p (cfun)
4918    && reload_completed && SSE_REG_P (operands[0])
4919    && (MEM_P (operands[1]) || TARGET_INTER_UNIT_MOVES_TO_VEC)"
4920   [(const_int 0)]
4921 {
4922   operands[3] = simplify_gen_subreg (<ssevecmode>mode, operands[0],
4923                                      <MODE>mode, 0);
4924   operands[4] = simplify_gen_subreg (V4SImode, operands[0], <MODE>mode, 0);
4925
4926   emit_insn (gen_sse2_loadld (operands[4],
4927                               CONST0_RTX (V4SImode), operands[1]));
4928
4929   if (<ssevecmode>mode == V4SFmode)
4930     emit_insn (gen_floatv4siv4sf2 (operands[3], operands[4]));
4931   else
4932     emit_insn (gen_sse2_cvtdq2pd (operands[3], operands[4]));
4933   DONE;
4934 })
4935
4936 ;; Avoid partial SSE register dependency stalls
4937 (define_split
4938   [(set (match_operand:MODEF 0 "register_operand")
4939         (float:MODEF (match_operand:SWI48 1 "nonimmediate_operand")))]
4940   "TARGET_SSE2 && TARGET_SSE_MATH
4941    && TARGET_SSE_PARTIAL_REG_DEPENDENCY
4942    && optimize_function_for_speed_p (cfun)
4943    && reload_completed && SSE_REG_P (operands[0])"
4944   [(const_int 0)]
4945 {
4946   const machine_mode vmode = <MODEF:ssevecmode>mode;
4947   const machine_mode mode = <MODEF:MODE>mode;
4948   rtx t, op0 = simplify_gen_subreg (vmode, operands[0], mode, 0);
4949
4950   emit_move_insn (op0, CONST0_RTX (vmode));
4951
4952   t = gen_rtx_FLOAT (mode, operands[1]);
4953   t = gen_rtx_VEC_DUPLICATE (vmode, t);
4954   t = gen_rtx_VEC_MERGE (vmode, t, op0, const1_rtx);
4955   emit_insn (gen_rtx_SET (VOIDmode, op0, t));
4956   DONE;
4957 })
4958
4959 ;; Break partial reg stall for cvtsd2ss.
4960
4961 (define_peephole2
4962   [(set (match_operand:SF 0 "register_operand")
4963         (float_truncate:SF
4964           (match_operand:DF 1 "nonimmediate_operand")))]
4965   "TARGET_SSE2 && TARGET_SSE_MATH
4966    && TARGET_SSE_PARTIAL_REG_DEPENDENCY
4967    && optimize_function_for_speed_p (cfun)
4968    && SSE_REG_P (operands[0])
4969    && (!SSE_REG_P (operands[1])
4970        || REGNO (operands[0]) != REGNO (operands[1]))"
4971   [(set (match_dup 0)
4972         (vec_merge:V4SF
4973           (vec_duplicate:V4SF
4974             (float_truncate:V2SF
4975               (match_dup 1)))
4976           (match_dup 0)
4977           (const_int 1)))]
4978 {
4979   operands[0] = simplify_gen_subreg (V4SFmode, operands[0],
4980                                      SFmode, 0);
4981   operands[1] = simplify_gen_subreg (V2DFmode, operands[1],
4982                                      DFmode, 0);
4983   emit_move_insn (operands[0], CONST0_RTX (V4SFmode));
4984 })
4985
4986 ;; Break partial reg stall for cvtss2sd.
4987
4988 (define_peephole2
4989   [(set (match_operand:DF 0 "register_operand")
4990         (float_extend:DF
4991           (match_operand:SF 1 "nonimmediate_operand")))]
4992   "TARGET_SSE2 && TARGET_SSE_MATH
4993    && TARGET_SSE_PARTIAL_REG_DEPENDENCY
4994    && optimize_function_for_speed_p (cfun)
4995    && SSE_REG_P (operands[0])
4996    && (!SSE_REG_P (operands[1])
4997        || REGNO (operands[0]) != REGNO (operands[1]))"
4998   [(set (match_dup 0)
4999         (vec_merge:V2DF
5000           (float_extend:V2DF
5001             (vec_select:V2SF
5002               (match_dup 1)
5003               (parallel [(const_int 0) (const_int 1)])))
5004           (match_dup 0)
5005           (const_int 1)))]
5006 {
5007   operands[0] = simplify_gen_subreg (V2DFmode, operands[0],
5008                                      DFmode, 0);
5009   operands[1] = simplify_gen_subreg (V4SFmode, operands[1],
5010                                      SFmode, 0);
5011   emit_move_insn (operands[0], CONST0_RTX (V2DFmode));
5012 })
5013
5014 ;; Avoid store forwarding (partial memory) stall penalty
5015 ;; by passing DImode value through XMM registers.  */
5016
5017 (define_insn "floatdi<X87MODEF:mode>2_i387_with_xmm"
5018   [(set (match_operand:X87MODEF 0 "register_operand" "=f,f")
5019         (float:X87MODEF
5020           (match_operand:DI 1 "nonimmediate_operand" "m,?r")))
5021    (clobber (match_scratch:V4SI 3 "=X,x"))
5022    (clobber (match_scratch:V4SI 4 "=X,x"))
5023    (clobber (match_operand:DI 2 "memory_operand" "=X,m"))]
5024   "TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5025    && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_TO_VEC
5026    && !TARGET_64BIT && optimize_function_for_speed_p (cfun)"
5027   "#"
5028   [(set_attr "type" "multi")
5029    (set_attr "mode" "<X87MODEF:MODE>")
5030    (set_attr "unit" "i387")
5031    (set_attr "fp_int_src" "true")])
5032
5033 (define_split
5034   [(set (match_operand:X87MODEF 0 "fp_register_operand")
5035         (float:X87MODEF (match_operand:DI 1 "register_operand")))
5036    (clobber (match_scratch:V4SI 3))
5037    (clobber (match_scratch:V4SI 4))
5038    (clobber (match_operand:DI 2 "memory_operand"))]
5039   "TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5040    && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_TO_VEC
5041    && !TARGET_64BIT && optimize_function_for_speed_p (cfun)
5042    && reload_completed"
5043   [(set (match_dup 2) (match_dup 3))
5044    (set (match_dup 0) (float:X87MODEF (match_dup 2)))]
5045 {
5046   /* The DImode arrived in a pair of integral registers (e.g. %edx:%eax).
5047      Assemble the 64-bit DImode value in an xmm register.  */
5048   emit_insn (gen_sse2_loadld (operands[3], CONST0_RTX (V4SImode),
5049                               gen_rtx_SUBREG (SImode, operands[1], 0)));
5050   emit_insn (gen_sse2_loadld (operands[4], CONST0_RTX (V4SImode),
5051                               gen_rtx_SUBREG (SImode, operands[1], 4)));
5052   emit_insn (gen_vec_interleave_lowv4si (operands[3], operands[3],
5053                                          operands[4]));
5054
5055   operands[3] = gen_rtx_REG (DImode, REGNO (operands[3]));
5056 })
5057
5058 (define_split
5059   [(set (match_operand:X87MODEF 0 "fp_register_operand")
5060         (float:X87MODEF (match_operand:DI 1 "memory_operand")))
5061    (clobber (match_scratch:V4SI 3))
5062    (clobber (match_scratch:V4SI 4))
5063    (clobber (match_operand:DI 2 "memory_operand"))]
5064   "TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5065    && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_TO_VEC
5066    && !TARGET_64BIT && optimize_function_for_speed_p (cfun)
5067    && reload_completed"
5068   [(set (match_dup 0) (float:X87MODEF (match_dup 1)))])
5069
5070 (define_expand "floatuns<SWI12:mode><MODEF:mode>2"
5071   [(set (match_operand:MODEF 0 "register_operand")
5072         (unsigned_float:MODEF
5073           (match_operand:SWI12 1 "nonimmediate_operand")))]
5074   "!TARGET_64BIT
5075    && SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH"
5076 {
5077   operands[1] = convert_to_mode (SImode, operands[1], 1);
5078   emit_insn (gen_floatsi<MODEF:mode>2 (operands[0], operands[1]));
5079   DONE;
5080 })
5081
5082 ;; Avoid store forwarding (partial memory) stall penalty by extending
5083 ;; SImode value to DImode through XMM register instead of pushing two
5084 ;; SImode values to stack. Also note that fild loads from memory only.
5085
5086 (define_insn_and_split "*floatunssi<mode>2_i387_with_xmm"
5087   [(set (match_operand:X87MODEF 0 "register_operand" "=f")
5088         (unsigned_float:X87MODEF
5089           (match_operand:SI 1 "nonimmediate_operand" "rm")))
5090    (clobber (match_scratch:DI 3 "=x"))
5091    (clobber (match_operand:DI 2 "memory_operand" "=m"))]
5092   "!TARGET_64BIT
5093    && TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5094    && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_TO_VEC"
5095   "#"
5096   "&& reload_completed"
5097   [(set (match_dup 3) (zero_extend:DI (match_dup 1)))
5098    (set (match_dup 2) (match_dup 3))
5099    (set (match_dup 0)
5100         (float:X87MODEF (match_dup 2)))]
5101   ""
5102   [(set_attr "type" "multi")
5103    (set_attr "mode" "<MODE>")])
5104
5105 (define_expand "floatunssi<mode>2"
5106   [(parallel
5107      [(set (match_operand:X87MODEF 0 "register_operand")
5108            (unsigned_float:X87MODEF
5109              (match_operand:SI 1 "nonimmediate_operand")))
5110       (clobber (match_scratch:DI 3))
5111       (clobber (match_dup 2))])]
5112   "!TARGET_64BIT
5113    && ((TARGET_80387 && X87_ENABLE_FLOAT (<X87MODEF:MODE>mode, DImode)
5114         && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_TO_VEC)
5115        || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))"
5116 {
5117   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
5118     {
5119       ix86_expand_convert_uns_si<mode>_sse (operands[0], operands[1]);
5120       DONE;
5121     }
5122   else
5123     operands[2] = assign_386_stack_local (DImode, SLOT_TEMP);
5124 })
5125
5126 (define_expand "floatunsdisf2"
5127   [(use (match_operand:SF 0 "register_operand"))
5128    (use (match_operand:DI 1 "nonimmediate_operand"))]
5129   "TARGET_64BIT && TARGET_SSE_MATH"
5130   "x86_emit_floatuns (operands); DONE;")
5131
5132 (define_expand "floatunsdidf2"
5133   [(use (match_operand:DF 0 "register_operand"))
5134    (use (match_operand:DI 1 "nonimmediate_operand"))]
5135   "(TARGET_64BIT || TARGET_KEEPS_VECTOR_ALIGNED_STACK)
5136    && TARGET_SSE2 && TARGET_SSE_MATH"
5137 {
5138   if (TARGET_64BIT)
5139     x86_emit_floatuns (operands);
5140   else
5141     ix86_expand_convert_uns_didf_sse (operands[0], operands[1]);
5142   DONE;
5143 })
5144 \f
5145 ;; Load effective address instructions
5146
5147 (define_insn_and_split "*lea<mode>"
5148   [(set (match_operand:SWI48 0 "register_operand" "=r")
5149         (match_operand:SWI48 1 "address_no_seg_operand" "Ts"))]
5150   ""
5151 {
5152   if (SImode_address_operand (operands[1], VOIDmode))
5153     {
5154       gcc_assert (TARGET_64BIT);
5155       return "lea{l}\t{%E1, %k0|%k0, %E1}";
5156     }
5157   else 
5158     return "lea{<imodesuffix>}\t{%E1, %0|%0, %E1}";
5159 }
5160   "reload_completed && ix86_avoid_lea_for_addr (insn, operands)"
5161   [(const_int 0)]
5162 {
5163   machine_mode mode = <MODE>mode;
5164   rtx pat;
5165
5166   /* ix86_avoid_lea_for_addr re-recognizes insn and may
5167      change operands[] array behind our back.  */
5168   pat = PATTERN (curr_insn);
5169
5170   operands[0] = SET_DEST (pat);
5171   operands[1] = SET_SRC (pat);
5172
5173   /* Emit all operations in SImode for zero-extended addresses.  */
5174   if (SImode_address_operand (operands[1], VOIDmode))
5175     mode = SImode;
5176
5177   ix86_split_lea_for_addr (curr_insn, operands, mode);
5178
5179   /* Zero-extend return register to DImode for zero-extended addresses.  */
5180   if (mode != <MODE>mode)
5181     emit_insn (gen_zero_extendsidi2
5182                (operands[0], gen_lowpart (mode, operands[0])));
5183
5184   DONE;
5185 }
5186   [(set_attr "type" "lea")
5187    (set (attr "mode")
5188      (if_then_else
5189        (match_operand 1 "SImode_address_operand")
5190        (const_string "SI")
5191        (const_string "<MODE>")))])
5192 \f
5193 ;; Add instructions
5194
5195 (define_expand "add<mode>3"
5196   [(set (match_operand:SDWIM 0 "nonimmediate_operand")
5197         (plus:SDWIM (match_operand:SDWIM 1 "nonimmediate_operand")
5198                     (match_operand:SDWIM 2 "<general_operand>")))]
5199   ""
5200   "ix86_expand_binary_operator (PLUS, <MODE>mode, operands); DONE;")
5201
5202 (define_insn_and_split "*add<dwi>3_doubleword"
5203   [(set (match_operand:<DWI> 0 "nonimmediate_operand" "=r,o")
5204         (plus:<DWI>
5205           (match_operand:<DWI> 1 "nonimmediate_operand" "%0,0")
5206           (match_operand:<DWI> 2 "<general_operand>" "ro<di>,r<di>")))
5207    (clobber (reg:CC FLAGS_REG))]
5208   "ix86_binary_operator_ok (PLUS, <DWI>mode, operands)"
5209   "#"
5210   "reload_completed"
5211   [(parallel [(set (reg:CC FLAGS_REG)
5212                    (unspec:CC [(match_dup 1) (match_dup 2)]
5213                               UNSPEC_ADD_CARRY))
5214               (set (match_dup 0)
5215                    (plus:DWIH (match_dup 1) (match_dup 2)))])
5216    (parallel [(set (match_dup 3)
5217                    (plus:DWIH
5218                      (match_dup 4)
5219                      (plus:DWIH
5220                        (ltu:DWIH (reg:CC FLAGS_REG) (const_int 0))
5221                        (match_dup 5))))
5222               (clobber (reg:CC FLAGS_REG))])]
5223   "split_double_mode (<DWI>mode, &operands[0], 3, &operands[0], &operands[3]);")
5224
5225 (define_insn "*add<mode>3_cc"
5226   [(set (reg:CC FLAGS_REG)
5227         (unspec:CC
5228           [(match_operand:SWI48 1 "nonimmediate_operand" "%0,0")
5229            (match_operand:SWI48 2 "<general_operand>" "r<i>,rm")]
5230           UNSPEC_ADD_CARRY))
5231    (set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,r")
5232         (plus:SWI48 (match_dup 1) (match_dup 2)))]
5233   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
5234   "add{<imodesuffix>}\t{%2, %0|%0, %2}"
5235   [(set_attr "type" "alu")
5236    (set_attr "mode" "<MODE>")])
5237
5238 (define_insn "addqi3_cc"
5239   [(set (reg:CC FLAGS_REG)
5240         (unspec:CC
5241           [(match_operand:QI 1 "nonimmediate_operand" "%0,0")
5242            (match_operand:QI 2 "general_operand" "qn,qm")]
5243           UNSPEC_ADD_CARRY))
5244    (set (match_operand:QI 0 "nonimmediate_operand" "=qm,q")
5245         (plus:QI (match_dup 1) (match_dup 2)))]
5246   "ix86_binary_operator_ok (PLUS, QImode, operands)"
5247   "add{b}\t{%2, %0|%0, %2}"
5248   [(set_attr "type" "alu")
5249    (set_attr "mode" "QI")])
5250
5251 (define_insn "*add<mode>_1"
5252   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=r,rm,r,r")
5253         (plus:SWI48
5254           (match_operand:SWI48 1 "nonimmediate_operand" "%0,0,r,r")
5255           (match_operand:SWI48 2 "x86_64_general_operand" "rme,re,0,le")))
5256    (clobber (reg:CC FLAGS_REG))]
5257   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
5258 {
5259   switch (get_attr_type (insn))
5260     {
5261     case TYPE_LEA:
5262       return "#";
5263
5264     case TYPE_INCDEC:
5265       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5266       if (operands[2] == const1_rtx)
5267         return "inc{<imodesuffix>}\t%0";
5268       else
5269         {
5270           gcc_assert (operands[2] == constm1_rtx);
5271           return "dec{<imodesuffix>}\t%0";
5272         }
5273
5274     default:
5275       /* For most processors, ADD is faster than LEA.  This alternative
5276          was added to use ADD as much as possible.  */
5277       if (which_alternative == 2)
5278         std::swap (operands[1], operands[2]);
5279         
5280       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5281       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
5282         return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
5283
5284       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
5285     }
5286 }
5287   [(set (attr "type")
5288      (cond [(eq_attr "alternative" "3")
5289               (const_string "lea")
5290             (match_operand:SWI48 2 "incdec_operand")
5291               (const_string "incdec")
5292            ]
5293            (const_string "alu")))
5294    (set (attr "length_immediate")
5295       (if_then_else
5296         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5297         (const_string "1")
5298         (const_string "*")))
5299    (set_attr "mode" "<MODE>")])
5300
5301 ;; It may seem that nonimmediate operand is proper one for operand 1.
5302 ;; The addsi_1 pattern allows nonimmediate operand at that place and
5303 ;; we take care in ix86_binary_operator_ok to not allow two memory
5304 ;; operands so proper swapping will be done in reload.  This allow
5305 ;; patterns constructed from addsi_1 to match.
5306
5307 (define_insn "addsi_1_zext"
5308   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
5309         (zero_extend:DI
5310           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0,r,r")
5311                    (match_operand:SI 2 "x86_64_general_operand" "rme,0,le"))))
5312    (clobber (reg:CC FLAGS_REG))]
5313   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, SImode, operands)"
5314 {
5315   switch (get_attr_type (insn))
5316     {
5317     case TYPE_LEA:
5318       return "#";
5319
5320     case TYPE_INCDEC:
5321       if (operands[2] == const1_rtx)
5322         return "inc{l}\t%k0";
5323       else
5324         {
5325           gcc_assert (operands[2] == constm1_rtx);
5326           return "dec{l}\t%k0";
5327         }
5328
5329     default:
5330       /* For most processors, ADD is faster than LEA.  This alternative
5331          was added to use ADD as much as possible.  */
5332       if (which_alternative == 1)
5333         std::swap (operands[1], operands[2]);
5334
5335       if (x86_maybe_negate_const_int (&operands[2], SImode))
5336         return "sub{l}\t{%2, %k0|%k0, %2}";
5337
5338       return "add{l}\t{%2, %k0|%k0, %2}";
5339     }
5340 }
5341   [(set (attr "type")
5342      (cond [(eq_attr "alternative" "2")
5343               (const_string "lea")
5344             (match_operand:SI 2 "incdec_operand")
5345               (const_string "incdec")
5346            ]
5347            (const_string "alu")))
5348    (set (attr "length_immediate")
5349       (if_then_else
5350         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5351         (const_string "1")
5352         (const_string "*")))
5353    (set_attr "mode" "SI")])
5354
5355 (define_insn "*addhi_1"
5356   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r,r,Yp")
5357         (plus:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,r,Yp")
5358                  (match_operand:HI 2 "general_operand" "rn,rm,0,ln")))
5359    (clobber (reg:CC FLAGS_REG))]
5360   "ix86_binary_operator_ok (PLUS, HImode, operands)"
5361 {
5362   switch (get_attr_type (insn))
5363     {
5364     case TYPE_LEA:
5365       return "#";
5366
5367     case TYPE_INCDEC:
5368       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5369       if (operands[2] == const1_rtx)
5370         return "inc{w}\t%0";
5371       else
5372         {
5373           gcc_assert (operands[2] == constm1_rtx);
5374           return "dec{w}\t%0";
5375         }
5376
5377     default:
5378       /* For most processors, ADD is faster than LEA.  This alternative
5379          was added to use ADD as much as possible.  */
5380       if (which_alternative == 2)
5381         std::swap (operands[1], operands[2]);
5382
5383       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5384       if (x86_maybe_negate_const_int (&operands[2], HImode))
5385         return "sub{w}\t{%2, %0|%0, %2}";
5386
5387       return "add{w}\t{%2, %0|%0, %2}";
5388     }
5389 }
5390   [(set (attr "type")
5391      (cond [(eq_attr "alternative" "3")
5392               (const_string "lea")
5393             (match_operand:HI 2 "incdec_operand")
5394               (const_string "incdec")
5395            ]
5396            (const_string "alu")))
5397    (set (attr "length_immediate")
5398       (if_then_else
5399         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5400         (const_string "1")
5401         (const_string "*")))
5402    (set_attr "mode" "HI,HI,HI,SI")])
5403
5404 ;; %%% Potential partial reg stall on alternatives 3 and 4.  What to do?
5405 (define_insn "*addqi_1"
5406   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q,q,r,r,Yp")
5407         (plus:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,q,0,r,Yp")
5408                  (match_operand:QI 2 "general_operand" "qn,qm,0,rn,0,ln")))
5409    (clobber (reg:CC FLAGS_REG))]
5410   "ix86_binary_operator_ok (PLUS, QImode, operands)"
5411 {
5412   bool widen = (which_alternative == 3 || which_alternative == 4);
5413
5414   switch (get_attr_type (insn))
5415     {
5416     case TYPE_LEA:
5417       return "#";
5418
5419     case TYPE_INCDEC:
5420       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5421       if (operands[2] == const1_rtx)
5422         return widen ? "inc{l}\t%k0" : "inc{b}\t%0";
5423       else
5424         {
5425           gcc_assert (operands[2] == constm1_rtx);
5426           return widen ? "dec{l}\t%k0" : "dec{b}\t%0";
5427         }
5428
5429     default:
5430       /* For most processors, ADD is faster than LEA.  These alternatives
5431          were added to use ADD as much as possible.  */
5432       if (which_alternative == 2 || which_alternative == 4)
5433         std::swap (operands[1], operands[2]);
5434
5435       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5436       if (x86_maybe_negate_const_int (&operands[2], QImode))
5437         {
5438           if (widen)
5439             return "sub{l}\t{%2, %k0|%k0, %2}";
5440           else
5441             return "sub{b}\t{%2, %0|%0, %2}";
5442         }
5443       if (widen)
5444         return "add{l}\t{%k2, %k0|%k0, %k2}";
5445       else
5446         return "add{b}\t{%2, %0|%0, %2}";
5447     }
5448 }
5449   [(set (attr "type")
5450      (cond [(eq_attr "alternative" "5")
5451               (const_string "lea")
5452             (match_operand:QI 2 "incdec_operand")
5453               (const_string "incdec")
5454            ]
5455            (const_string "alu")))
5456    (set (attr "length_immediate")
5457       (if_then_else
5458         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5459         (const_string "1")
5460         (const_string "*")))
5461    (set_attr "mode" "QI,QI,QI,SI,SI,SI")])
5462
5463 (define_insn "*addqi_1_slp"
5464   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
5465         (plus:QI (match_dup 0)
5466                  (match_operand:QI 1 "general_operand" "qn,qm")))
5467    (clobber (reg:CC FLAGS_REG))]
5468   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
5469    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
5470 {
5471   switch (get_attr_type (insn))
5472     {
5473     case TYPE_INCDEC:
5474       if (operands[1] == const1_rtx)
5475         return "inc{b}\t%0";
5476       else
5477         {
5478           gcc_assert (operands[1] == constm1_rtx);
5479           return "dec{b}\t%0";
5480         }
5481
5482     default:
5483       if (x86_maybe_negate_const_int (&operands[1], QImode))
5484         return "sub{b}\t{%1, %0|%0, %1}";
5485
5486       return "add{b}\t{%1, %0|%0, %1}";
5487     }
5488 }
5489   [(set (attr "type")
5490      (if_then_else (match_operand:QI 1 "incdec_operand")
5491         (const_string "incdec")
5492         (const_string "alu1")))
5493    (set (attr "memory")
5494      (if_then_else (match_operand 1 "memory_operand")
5495         (const_string "load")
5496         (const_string "none")))
5497    (set_attr "mode" "QI")])
5498
5499 ;; Split non destructive adds if we cannot use lea.
5500 (define_split
5501   [(set (match_operand:SWI48 0 "register_operand")
5502         (plus:SWI48 (match_operand:SWI48 1 "register_operand")
5503                     (match_operand:SWI48 2 "x86_64_nonmemory_operand")))
5504    (clobber (reg:CC FLAGS_REG))]
5505   "reload_completed && ix86_avoid_lea_for_add (insn, operands)"
5506   [(set (match_dup 0) (match_dup 1))
5507    (parallel [(set (match_dup 0) (plus:SWI48 (match_dup 0) (match_dup 2)))
5508               (clobber (reg:CC FLAGS_REG))])])
5509
5510 ;; Convert add to the lea pattern to avoid flags dependency.
5511 (define_split
5512   [(set (match_operand:SWI 0 "register_operand")
5513         (plus:SWI (match_operand:SWI 1 "register_operand")
5514                   (match_operand:SWI 2 "<nonmemory_operand>")))
5515    (clobber (reg:CC FLAGS_REG))]
5516   "reload_completed && ix86_lea_for_add_ok (insn, operands)" 
5517   [(const_int 0)]
5518 {
5519   machine_mode mode = <MODE>mode;
5520   rtx pat;
5521
5522   if (<MODE_SIZE> < GET_MODE_SIZE (SImode))
5523     { 
5524       mode = SImode; 
5525       operands[0] = gen_lowpart (mode, operands[0]);
5526       operands[1] = gen_lowpart (mode, operands[1]);
5527       operands[2] = gen_lowpart (mode, operands[2]);
5528     }
5529
5530   pat = gen_rtx_PLUS (mode, operands[1], operands[2]);
5531
5532   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
5533   DONE;
5534 })
5535
5536 ;; Split non destructive adds if we cannot use lea.
5537 (define_split
5538   [(set (match_operand:DI 0 "register_operand")
5539         (zero_extend:DI
5540           (plus:SI (match_operand:SI 1 "register_operand")
5541                    (match_operand:SI 2 "x86_64_nonmemory_operand"))))
5542    (clobber (reg:CC FLAGS_REG))]
5543   "TARGET_64BIT
5544    && reload_completed && ix86_avoid_lea_for_add (insn, operands)"
5545   [(set (match_dup 3) (match_dup 1))
5546    (parallel [(set (match_dup 0)
5547                    (zero_extend:DI (plus:SI (match_dup 3) (match_dup 2))))
5548               (clobber (reg:CC FLAGS_REG))])]
5549   "operands[3] = gen_lowpart (SImode, operands[0]);")
5550
5551 ;; Convert add to the lea pattern to avoid flags dependency.
5552 (define_split
5553   [(set (match_operand:DI 0 "register_operand")
5554         (zero_extend:DI
5555           (plus:SI (match_operand:SI 1 "register_operand")
5556                    (match_operand:SI 2 "x86_64_nonmemory_operand"))))
5557    (clobber (reg:CC FLAGS_REG))]
5558   "TARGET_64BIT && reload_completed && ix86_lea_for_add_ok (insn, operands)"
5559   [(set (match_dup 0)
5560         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))])
5561
5562 (define_insn "*add<mode>_2"
5563   [(set (reg FLAGS_REG)
5564         (compare
5565           (plus:SWI
5566             (match_operand:SWI 1 "nonimmediate_operand" "%0,0,<r>")
5567             (match_operand:SWI 2 "<general_operand>" "<g>,<r><i>,0"))
5568           (const_int 0)))
5569    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>,<r>m,<r>")
5570         (plus:SWI (match_dup 1) (match_dup 2)))]
5571   "ix86_match_ccmode (insn, CCGOCmode)
5572    && ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
5573 {
5574   switch (get_attr_type (insn))
5575     {
5576     case TYPE_INCDEC:
5577       if (operands[2] == const1_rtx)
5578         return "inc{<imodesuffix>}\t%0";
5579       else
5580         {
5581           gcc_assert (operands[2] == constm1_rtx);
5582           return "dec{<imodesuffix>}\t%0";
5583         }
5584
5585     default:
5586       if (which_alternative == 2)
5587         std::swap (operands[1], operands[2]);
5588         
5589       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5590       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
5591         return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
5592
5593       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
5594     }
5595 }
5596   [(set (attr "type")
5597      (if_then_else (match_operand:SWI 2 "incdec_operand")
5598         (const_string "incdec")
5599         (const_string "alu")))
5600    (set (attr "length_immediate")
5601       (if_then_else
5602         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5603         (const_string "1")
5604         (const_string "*")))
5605    (set_attr "mode" "<MODE>")])
5606
5607 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
5608 (define_insn "*addsi_2_zext"
5609   [(set (reg FLAGS_REG)
5610         (compare
5611           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0,r")
5612                    (match_operand:SI 2 "x86_64_general_operand" "rme,0"))
5613           (const_int 0)))
5614    (set (match_operand:DI 0 "register_operand" "=r,r")
5615         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))]
5616   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
5617    && ix86_binary_operator_ok (PLUS, SImode, operands)"
5618 {
5619   switch (get_attr_type (insn))
5620     {
5621     case TYPE_INCDEC:
5622       if (operands[2] == const1_rtx)
5623         return "inc{l}\t%k0";
5624       else
5625         {
5626           gcc_assert (operands[2] == constm1_rtx);
5627           return "dec{l}\t%k0";
5628         }
5629
5630     default:
5631       if (which_alternative == 1)
5632         std::swap (operands[1], operands[2]);
5633
5634       if (x86_maybe_negate_const_int (&operands[2], SImode))
5635         return "sub{l}\t{%2, %k0|%k0, %2}";
5636
5637       return "add{l}\t{%2, %k0|%k0, %2}";
5638     }
5639 }
5640   [(set (attr "type")
5641      (if_then_else (match_operand:SI 2 "incdec_operand")
5642         (const_string "incdec")
5643         (const_string "alu")))
5644    (set (attr "length_immediate")
5645       (if_then_else
5646         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5647         (const_string "1")
5648         (const_string "*")))
5649    (set_attr "mode" "SI")])
5650
5651 (define_insn "*add<mode>_3"
5652   [(set (reg FLAGS_REG)
5653         (compare
5654           (neg:SWI (match_operand:SWI 2 "<general_operand>" "<g>,0"))
5655           (match_operand:SWI 1 "nonimmediate_operand" "%0,<r>")))
5656    (clobber (match_scratch:SWI 0 "=<r>,<r>"))]
5657   "ix86_match_ccmode (insn, CCZmode)
5658    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
5659 {
5660   switch (get_attr_type (insn))
5661     {
5662     case TYPE_INCDEC:
5663       if (operands[2] == const1_rtx)
5664         return "inc{<imodesuffix>}\t%0";
5665       else
5666         {
5667           gcc_assert (operands[2] == constm1_rtx);
5668           return "dec{<imodesuffix>}\t%0";
5669         }
5670
5671     default:
5672       if (which_alternative == 1)
5673         std::swap (operands[1], operands[2]);
5674
5675       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5676       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
5677         return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
5678
5679       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
5680     }
5681 }
5682   [(set (attr "type")
5683      (if_then_else (match_operand:SWI 2 "incdec_operand")
5684         (const_string "incdec")
5685         (const_string "alu")))
5686    (set (attr "length_immediate")
5687       (if_then_else
5688         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5689         (const_string "1")
5690         (const_string "*")))
5691    (set_attr "mode" "<MODE>")])
5692
5693 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
5694 (define_insn "*addsi_3_zext"
5695   [(set (reg FLAGS_REG)
5696         (compare
5697           (neg:SI (match_operand:SI 2 "x86_64_general_operand" "rme,0"))
5698           (match_operand:SI 1 "nonimmediate_operand" "%0,r")))
5699    (set (match_operand:DI 0 "register_operand" "=r,r")
5700         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))]
5701   "TARGET_64BIT && ix86_match_ccmode (insn, CCZmode)
5702    && ix86_binary_operator_ok (PLUS, SImode, operands)"
5703 {
5704   switch (get_attr_type (insn))
5705     {
5706     case TYPE_INCDEC:
5707       if (operands[2] == const1_rtx)
5708         return "inc{l}\t%k0";
5709       else
5710         {
5711           gcc_assert (operands[2] == constm1_rtx);
5712           return "dec{l}\t%k0";
5713         }
5714
5715     default:
5716       if (which_alternative == 1)
5717         std::swap (operands[1], operands[2]);
5718
5719       if (x86_maybe_negate_const_int (&operands[2], SImode))
5720         return "sub{l}\t{%2, %k0|%k0, %2}";
5721
5722       return "add{l}\t{%2, %k0|%k0, %2}";
5723     }
5724 }
5725   [(set (attr "type")
5726      (if_then_else (match_operand:SI 2 "incdec_operand")
5727         (const_string "incdec")
5728         (const_string "alu")))
5729    (set (attr "length_immediate")
5730       (if_then_else
5731         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5732         (const_string "1")
5733         (const_string "*")))
5734    (set_attr "mode" "SI")])
5735
5736 ; For comparisons against 1, -1 and 128, we may generate better code
5737 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
5738 ; is matched then.  We can't accept general immediate, because for
5739 ; case of overflows,  the result is messed up.
5740 ; Also carry flag is reversed compared to cmp, so this conversion is valid
5741 ; only for comparisons not depending on it.
5742
5743 (define_insn "*adddi_4"
5744   [(set (reg FLAGS_REG)
5745         (compare
5746           (match_operand:DI 1 "nonimmediate_operand" "0")
5747           (match_operand:DI 2 "x86_64_immediate_operand" "e")))
5748    (clobber (match_scratch:DI 0 "=rm"))]
5749   "TARGET_64BIT
5750    && ix86_match_ccmode (insn, CCGCmode)"
5751 {
5752   switch (get_attr_type (insn))
5753     {
5754     case TYPE_INCDEC:
5755       if (operands[2] == constm1_rtx)
5756         return "inc{q}\t%0";
5757       else
5758         {
5759           gcc_assert (operands[2] == const1_rtx);
5760           return "dec{q}\t%0";
5761         }
5762
5763     default:
5764       if (x86_maybe_negate_const_int (&operands[2], DImode))
5765         return "add{q}\t{%2, %0|%0, %2}";
5766
5767       return "sub{q}\t{%2, %0|%0, %2}";
5768     }
5769 }
5770   [(set (attr "type")
5771      (if_then_else (match_operand:DI 2 "incdec_operand")
5772         (const_string "incdec")
5773         (const_string "alu")))
5774    (set (attr "length_immediate")
5775       (if_then_else
5776         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5777         (const_string "1")
5778         (const_string "*")))
5779    (set_attr "mode" "DI")])
5780
5781 ; For comparisons against 1, -1 and 128, we may generate better code
5782 ; by converting cmp to add, inc or dec as done by peephole2.  This pattern
5783 ; is matched then.  We can't accept general immediate, because for
5784 ; case of overflows,  the result is messed up.
5785 ; Also carry flag is reversed compared to cmp, so this conversion is valid
5786 ; only for comparisons not depending on it.
5787
5788 (define_insn "*add<mode>_4"
5789   [(set (reg FLAGS_REG)
5790         (compare
5791           (match_operand:SWI124 1 "nonimmediate_operand" "0")
5792           (match_operand:SWI124 2 "const_int_operand" "n")))
5793    (clobber (match_scratch:SWI124 0 "=<r>m"))]
5794   "ix86_match_ccmode (insn, CCGCmode)"
5795 {
5796   switch (get_attr_type (insn))
5797     {
5798     case TYPE_INCDEC:
5799       if (operands[2] == constm1_rtx)
5800         return "inc{<imodesuffix>}\t%0";
5801       else
5802         {
5803           gcc_assert (operands[2] == const1_rtx);
5804           return "dec{<imodesuffix>}\t%0";
5805         }
5806
5807     default:
5808       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
5809         return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
5810
5811       return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
5812     }
5813 }
5814   [(set (attr "type")
5815      (if_then_else (match_operand:<MODE> 2 "incdec_operand")
5816         (const_string "incdec")
5817         (const_string "alu")))
5818    (set (attr "length_immediate")
5819       (if_then_else
5820         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5821         (const_string "1")
5822         (const_string "*")))
5823    (set_attr "mode" "<MODE>")])
5824
5825 (define_insn "*add<mode>_5"
5826   [(set (reg FLAGS_REG)
5827         (compare
5828           (plus:SWI
5829             (match_operand:SWI 1 "nonimmediate_operand" "%0,<r>")
5830             (match_operand:SWI 2 "<general_operand>" "<g>,0"))
5831           (const_int 0)))
5832    (clobber (match_scratch:SWI 0 "=<r>,<r>"))]
5833   "ix86_match_ccmode (insn, CCGOCmode)
5834    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
5835 {
5836   switch (get_attr_type (insn))
5837     {
5838     case TYPE_INCDEC:
5839       if (operands[2] == const1_rtx)
5840         return "inc{<imodesuffix>}\t%0";
5841       else
5842         {
5843           gcc_assert (operands[2] == constm1_rtx);
5844           return "dec{<imodesuffix>}\t%0";
5845         }
5846
5847     default:
5848       if (which_alternative == 1)
5849         std::swap (operands[1], operands[2]);
5850
5851       gcc_assert (rtx_equal_p (operands[0], operands[1]));
5852       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
5853         return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
5854
5855       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
5856     }
5857 }
5858   [(set (attr "type")
5859      (if_then_else (match_operand:SWI 2 "incdec_operand")
5860         (const_string "incdec")
5861         (const_string "alu")))
5862    (set (attr "length_immediate")
5863       (if_then_else
5864         (and (eq_attr "type" "alu") (match_operand 2 "const128_operand"))
5865         (const_string "1")
5866         (const_string "*")))
5867    (set_attr "mode" "<MODE>")])
5868
5869 (define_insn "addqi_ext_1"
5870   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q,Q")
5871                          (const_int 8)
5872                          (const_int 8))
5873         (plus:SI
5874           (zero_extract:SI
5875             (match_operand 1 "ext_register_operand" "0,0")
5876             (const_int 8)
5877             (const_int 8))
5878           (match_operand:QI 2 "general_x64nomem_operand" "Qn,m")))
5879    (clobber (reg:CC FLAGS_REG))]
5880   ""
5881 {
5882   switch (get_attr_type (insn))
5883     {
5884     case TYPE_INCDEC:
5885       if (operands[2] == const1_rtx)
5886         return "inc{b}\t%h0";
5887       else
5888         {
5889           gcc_assert (operands[2] == constm1_rtx);
5890           return "dec{b}\t%h0";
5891         }
5892
5893     default:
5894       return "add{b}\t{%2, %h0|%h0, %2}";
5895     }
5896 }
5897   [(set_attr "isa" "*,nox64")
5898    (set (attr "type")
5899      (if_then_else (match_operand:QI 2 "incdec_operand")
5900         (const_string "incdec")
5901         (const_string "alu")))
5902    (set_attr "modrm" "1")
5903    (set_attr "mode" "QI")])
5904
5905 (define_insn "*addqi_ext_2"
5906   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
5907                          (const_int 8)
5908                          (const_int 8))
5909         (plus:SI
5910           (zero_extract:SI
5911             (match_operand 1 "ext_register_operand" "%0")
5912             (const_int 8)
5913             (const_int 8))
5914           (zero_extract:SI
5915             (match_operand 2 "ext_register_operand" "Q")
5916             (const_int 8)
5917             (const_int 8))))
5918    (clobber (reg:CC FLAGS_REG))]
5919   ""
5920   "add{b}\t{%h2, %h0|%h0, %h2}"
5921   [(set_attr "type" "alu")
5922    (set_attr "mode" "QI")])
5923
5924 ;; Add with jump on overflow.
5925 (define_expand "addv<mode>4"
5926   [(parallel [(set (reg:CCO FLAGS_REG)
5927                    (eq:CCO (plus:<DWI>
5928                               (sign_extend:<DWI>
5929                                  (match_operand:SWI 1 "nonimmediate_operand"))
5930                               (match_dup 4))
5931                            (sign_extend:<DWI>
5932                               (plus:SWI (match_dup 1)
5933                                         (match_operand:SWI 2
5934                                            "<general_operand>")))))
5935               (set (match_operand:SWI 0 "register_operand")
5936                    (plus:SWI (match_dup 1) (match_dup 2)))])
5937    (set (pc) (if_then_else
5938                (eq (reg:CCO FLAGS_REG) (const_int 0))
5939                (label_ref (match_operand 3))
5940                (pc)))]
5941   ""
5942 {
5943   ix86_fixup_binary_operands_no_copy (PLUS, <MODE>mode, operands);
5944   if (CONST_INT_P (operands[2]))
5945     operands[4] = operands[2];
5946   else
5947     operands[4] = gen_rtx_SIGN_EXTEND (<DWI>mode, operands[2]);
5948 })
5949
5950 (define_insn "*addv<mode>4"
5951   [(set (reg:CCO FLAGS_REG)
5952         (eq:CCO (plus:<DWI>
5953                    (sign_extend:<DWI>
5954                       (match_operand:SWI 1 "nonimmediate_operand" "%0,0"))
5955                    (sign_extend:<DWI>
5956                       (match_operand:SWI 2 "<general_sext_operand>"
5957                                            "<r>mWe,<r>We")))
5958                 (sign_extend:<DWI>
5959                    (plus:SWI (match_dup 1) (match_dup 2)))))
5960    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>,<r>m")
5961         (plus:SWI (match_dup 1) (match_dup 2)))]
5962   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
5963   "add{<imodesuffix>}\t{%2, %0|%0, %2}"
5964   [(set_attr "type" "alu")
5965    (set_attr "mode" "<MODE>")])
5966
5967 (define_insn "*addv<mode>4_1"
5968   [(set (reg:CCO FLAGS_REG)
5969         (eq:CCO (plus:<DWI>
5970                    (sign_extend:<DWI>
5971                       (match_operand:SWI 1 "nonimmediate_operand" "0"))
5972                    (match_operand:<DWI> 3 "const_int_operand" "i"))
5973                 (sign_extend:<DWI>
5974                    (plus:SWI (match_dup 1)
5975                              (match_operand:SWI 2 "x86_64_immediate_operand"
5976                                                   "<i>")))))
5977    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
5978         (plus:SWI (match_dup 1) (match_dup 2)))]
5979   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)
5980    && CONST_INT_P (operands[2])
5981    && INTVAL (operands[2]) == INTVAL (operands[3])"
5982   "add{<imodesuffix>}\t{%2, %0|%0, %2}"
5983   [(set_attr "type" "alu")
5984    (set_attr "mode" "<MODE>")
5985    (set (attr "length_immediate")
5986         (cond [(match_test "IN_RANGE (INTVAL (operands[2]), -128, 127)")
5987                   (const_string "1")
5988                (match_test "<MODE_SIZE> == 8")
5989                   (const_string "4")]
5990               (const_string "<MODE_SIZE>")))])
5991
5992 ;; The lea patterns for modes less than 32 bits need to be matched by
5993 ;; several insns converted to real lea by splitters.
5994
5995 (define_insn_and_split "*lea_general_1"
5996   [(set (match_operand 0 "register_operand" "=r")
5997         (plus (plus (match_operand 1 "index_register_operand" "l")
5998                     (match_operand 2 "register_operand" "r"))
5999               (match_operand 3 "immediate_operand" "i")))]
6000   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode)
6001    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
6002    && GET_MODE (operands[0]) == GET_MODE (operands[1])
6003    && GET_MODE (operands[0]) == GET_MODE (operands[2])
6004    && (GET_MODE (operands[0]) == GET_MODE (operands[3])
6005        || GET_MODE (operands[3]) == VOIDmode)"
6006   "#"
6007   "&& reload_completed"
6008   [(const_int 0)]
6009 {
6010   machine_mode mode = SImode;
6011   rtx pat;
6012
6013   operands[0] = gen_lowpart (mode, operands[0]);
6014   operands[1] = gen_lowpart (mode, operands[1]);
6015   operands[2] = gen_lowpart (mode, operands[2]);
6016   operands[3] = gen_lowpart (mode, operands[3]);
6017
6018   pat = gen_rtx_PLUS (mode, gen_rtx_PLUS (mode, operands[1], operands[2]),
6019                       operands[3]);
6020
6021   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
6022   DONE;
6023 }
6024   [(set_attr "type" "lea")
6025    (set_attr "mode" "SI")])
6026
6027 (define_insn_and_split "*lea_general_2"
6028   [(set (match_operand 0 "register_operand" "=r")
6029         (plus (mult (match_operand 1 "index_register_operand" "l")
6030                     (match_operand 2 "const248_operand" "n"))
6031               (match_operand 3 "nonmemory_operand" "ri")))]
6032   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode)
6033    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
6034    && GET_MODE (operands[0]) == GET_MODE (operands[1])
6035    && (GET_MODE (operands[0]) == GET_MODE (operands[3])
6036        || GET_MODE (operands[3]) == VOIDmode)"
6037   "#"
6038   "&& reload_completed"
6039   [(const_int 0)]
6040 {
6041   machine_mode mode = SImode;
6042   rtx pat;
6043
6044   operands[0] = gen_lowpart (mode, operands[0]);
6045   operands[1] = gen_lowpart (mode, operands[1]);
6046   operands[3] = gen_lowpart (mode, operands[3]);
6047
6048   pat = gen_rtx_PLUS (mode, gen_rtx_MULT (mode, operands[1], operands[2]),
6049                       operands[3]);
6050
6051   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
6052   DONE;
6053 }
6054   [(set_attr "type" "lea")
6055    (set_attr "mode" "SI")])
6056
6057 (define_insn_and_split "*lea_general_3"
6058   [(set (match_operand 0 "register_operand" "=r")
6059         (plus (plus (mult (match_operand 1 "index_register_operand" "l")
6060                           (match_operand 2 "const248_operand" "n"))
6061                     (match_operand 3 "register_operand" "r"))
6062               (match_operand 4 "immediate_operand" "i")))]
6063   "(GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode)
6064    && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
6065    && GET_MODE (operands[0]) == GET_MODE (operands[1])
6066    && GET_MODE (operands[0]) == GET_MODE (operands[3])"
6067   "#"
6068   "&& reload_completed"
6069   [(const_int 0)]
6070 {
6071   machine_mode mode = SImode;
6072   rtx pat;
6073
6074   operands[0] = gen_lowpart (mode, operands[0]);
6075   operands[1] = gen_lowpart (mode, operands[1]);
6076   operands[3] = gen_lowpart (mode, operands[3]);
6077   operands[4] = gen_lowpart (mode, operands[4]);
6078
6079   pat = gen_rtx_PLUS (mode,
6080                       gen_rtx_PLUS (mode,
6081                                     gen_rtx_MULT (mode, operands[1],
6082                                                         operands[2]),
6083                                     operands[3]),
6084                       operands[4]);
6085
6086   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
6087   DONE;
6088 }
6089   [(set_attr "type" "lea")
6090    (set_attr "mode" "SI")])
6091
6092 (define_insn_and_split "*lea_general_4"
6093   [(set (match_operand 0 "register_operand" "=r")
6094         (any_or (ashift
6095                   (match_operand 1 "index_register_operand" "l")
6096                   (match_operand 2 "const_int_operand" "n"))
6097                 (match_operand 3 "const_int_operand" "n")))]
6098   "(((GET_MODE (operands[0]) == QImode || GET_MODE (operands[0]) == HImode)
6099       && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)))
6100     || GET_MODE (operands[0]) == SImode
6101     || (TARGET_64BIT && GET_MODE (operands[0]) == DImode))
6102    && GET_MODE (operands[0]) == GET_MODE (operands[1])
6103    && ((unsigned HOST_WIDE_INT) INTVAL (operands[2])) - 1 < 3
6104    && ((unsigned HOST_WIDE_INT) INTVAL (operands[3])
6105        < ((unsigned HOST_WIDE_INT) 1 << INTVAL (operands[2])))"
6106   "#"
6107   "&& reload_completed"
6108   [(const_int 0)]
6109 {
6110   machine_mode mode = GET_MODE (operands[0]);
6111   rtx pat;
6112
6113   if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (SImode))
6114     { 
6115       mode = SImode; 
6116       operands[0] = gen_lowpart (mode, operands[0]);
6117       operands[1] = gen_lowpart (mode, operands[1]);
6118     }
6119
6120   operands[2] = GEN_INT (1 << INTVAL (operands[2]));
6121
6122   pat = plus_constant (mode, gen_rtx_MULT (mode, operands[1], operands[2]),
6123                        INTVAL (operands[3]));
6124
6125   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
6126   DONE;
6127 }
6128   [(set_attr "type" "lea")
6129    (set (attr "mode")
6130       (if_then_else (match_operand:DI 0)
6131         (const_string "DI")
6132         (const_string "SI")))])
6133 \f
6134 ;; Subtract instructions
6135
6136 (define_expand "sub<mode>3"
6137   [(set (match_operand:SDWIM 0 "nonimmediate_operand")
6138         (minus:SDWIM (match_operand:SDWIM 1 "nonimmediate_operand")
6139                      (match_operand:SDWIM 2 "<general_operand>")))]
6140   ""
6141   "ix86_expand_binary_operator (MINUS, <MODE>mode, operands); DONE;")
6142
6143 (define_insn_and_split "*sub<dwi>3_doubleword"
6144   [(set (match_operand:<DWI> 0 "nonimmediate_operand" "=r,o")
6145         (minus:<DWI>
6146           (match_operand:<DWI> 1 "nonimmediate_operand" "0,0")
6147           (match_operand:<DWI> 2 "<general_operand>" "ro<di>,r<di>")))
6148    (clobber (reg:CC FLAGS_REG))]
6149   "ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
6150   "#"
6151   "reload_completed"
6152   [(parallel [(set (reg:CC FLAGS_REG)
6153                    (compare:CC (match_dup 1) (match_dup 2)))
6154               (set (match_dup 0)
6155                    (minus:DWIH (match_dup 1) (match_dup 2)))])
6156    (parallel [(set (match_dup 3)
6157                    (minus:DWIH
6158                      (match_dup 4)
6159                      (plus:DWIH
6160                        (ltu:DWIH (reg:CC FLAGS_REG) (const_int 0))
6161                        (match_dup 5))))
6162               (clobber (reg:CC FLAGS_REG))])]
6163   "split_double_mode (<DWI>mode, &operands[0], 3, &operands[0], &operands[3]);")
6164
6165 (define_insn "*sub<mode>_1"
6166   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6167         (minus:SWI
6168           (match_operand:SWI 1 "nonimmediate_operand" "0,0")
6169           (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m")))
6170    (clobber (reg:CC FLAGS_REG))]
6171   "ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
6172   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
6173   [(set_attr "type" "alu")
6174    (set_attr "mode" "<MODE>")])
6175
6176 (define_insn "*subsi_1_zext"
6177   [(set (match_operand:DI 0 "register_operand" "=r")
6178         (zero_extend:DI
6179           (minus:SI (match_operand:SI 1 "register_operand" "0")
6180                     (match_operand:SI 2 "x86_64_general_operand" "rme"))))
6181    (clobber (reg:CC FLAGS_REG))]
6182   "TARGET_64BIT && ix86_binary_operator_ok (MINUS, SImode, operands)"
6183   "sub{l}\t{%2, %k0|%k0, %2}"
6184   [(set_attr "type" "alu")
6185    (set_attr "mode" "SI")])
6186
6187 (define_insn "*subqi_1_slp"
6188   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
6189         (minus:QI (match_dup 0)
6190                   (match_operand:QI 1 "general_operand" "qn,qm")))
6191    (clobber (reg:CC FLAGS_REG))]
6192   "(! TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
6193    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
6194   "sub{b}\t{%1, %0|%0, %1}"
6195   [(set_attr "type" "alu1")
6196    (set_attr "mode" "QI")])
6197
6198 (define_insn "*sub<mode>_2"
6199   [(set (reg FLAGS_REG)
6200         (compare
6201           (minus:SWI
6202             (match_operand:SWI 1 "nonimmediate_operand" "0,0")
6203             (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m"))
6204           (const_int 0)))
6205    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6206         (minus:SWI (match_dup 1) (match_dup 2)))]
6207   "ix86_match_ccmode (insn, CCGOCmode)
6208    && ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
6209   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
6210   [(set_attr "type" "alu")
6211    (set_attr "mode" "<MODE>")])
6212
6213 (define_insn "*subsi_2_zext"
6214   [(set (reg FLAGS_REG)
6215         (compare
6216           (minus:SI (match_operand:SI 1 "register_operand" "0")
6217                     (match_operand:SI 2 "x86_64_general_operand" "rme"))
6218           (const_int 0)))
6219    (set (match_operand:DI 0 "register_operand" "=r")
6220         (zero_extend:DI
6221           (minus:SI (match_dup 1)
6222                     (match_dup 2))))]
6223   "TARGET_64BIT && ix86_match_ccmode (insn, CCGOCmode)
6224    && ix86_binary_operator_ok (MINUS, SImode, operands)"
6225   "sub{l}\t{%2, %k0|%k0, %2}"
6226   [(set_attr "type" "alu")
6227    (set_attr "mode" "SI")])
6228
6229 ;; Subtract with jump on overflow.
6230 (define_expand "subv<mode>4"
6231   [(parallel [(set (reg:CCO FLAGS_REG)
6232                    (eq:CCO (minus:<DWI>
6233                               (sign_extend:<DWI>
6234                                  (match_operand:SWI 1 "nonimmediate_operand"))
6235                               (match_dup 4))
6236                            (sign_extend:<DWI>
6237                               (minus:SWI (match_dup 1)
6238                                          (match_operand:SWI 2
6239                                             "<general_operand>")))))
6240               (set (match_operand:SWI 0 "register_operand")
6241                    (minus:SWI (match_dup 1) (match_dup 2)))])
6242    (set (pc) (if_then_else
6243                (eq (reg:CCO FLAGS_REG) (const_int 0))
6244                (label_ref (match_operand 3))
6245                (pc)))]
6246   ""
6247 {
6248   ix86_fixup_binary_operands_no_copy (MINUS, <MODE>mode, operands);
6249   if (CONST_INT_P (operands[2]))
6250     operands[4] = operands[2];
6251   else
6252     operands[4] = gen_rtx_SIGN_EXTEND (<DWI>mode, operands[2]);
6253 })
6254
6255 (define_insn "*subv<mode>4"
6256   [(set (reg:CCO FLAGS_REG)
6257         (eq:CCO (minus:<DWI>
6258                    (sign_extend:<DWI>
6259                       (match_operand:SWI 1 "nonimmediate_operand" "0,0"))
6260                    (sign_extend:<DWI>
6261                       (match_operand:SWI 2 "<general_sext_operand>"
6262                                            "<r>We,<r>m")))
6263                 (sign_extend:<DWI>
6264                    (minus:SWI (match_dup 1) (match_dup 2)))))
6265    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6266         (minus:SWI (match_dup 1) (match_dup 2)))]
6267   "ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
6268   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
6269   [(set_attr "type" "alu")
6270    (set_attr "mode" "<MODE>")])
6271
6272 (define_insn "*subv<mode>4_1"
6273   [(set (reg:CCO FLAGS_REG)
6274         (eq:CCO (minus:<DWI>
6275                    (sign_extend:<DWI>
6276                       (match_operand:SWI 1 "nonimmediate_operand" "0"))
6277                    (match_operand:<DWI> 3 "const_int_operand" "i"))
6278                 (sign_extend:<DWI>
6279                    (minus:SWI (match_dup 1)
6280                               (match_operand:SWI 2 "x86_64_immediate_operand"
6281                                                    "<i>")))))
6282    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
6283         (minus:SWI (match_dup 1) (match_dup 2)))]
6284   "ix86_binary_operator_ok (MINUS, <MODE>mode, operands)
6285    && CONST_INT_P (operands[2])
6286    && INTVAL (operands[2]) == INTVAL (operands[3])"
6287   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
6288   [(set_attr "type" "alu")
6289    (set_attr "mode" "<MODE>")
6290    (set (attr "length_immediate")
6291         (cond [(match_test "IN_RANGE (INTVAL (operands[2]), -128, 127)")
6292                   (const_string "1")
6293                (match_test "<MODE_SIZE> == 8")
6294                   (const_string "4")]
6295               (const_string "<MODE_SIZE>")))])
6296
6297 (define_insn "*sub<mode>_3"
6298   [(set (reg FLAGS_REG)
6299         (compare (match_operand:SWI 1 "nonimmediate_operand" "0,0")
6300                  (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m")))
6301    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6302         (minus:SWI (match_dup 1) (match_dup 2)))]
6303   "ix86_match_ccmode (insn, CCmode)
6304    && ix86_binary_operator_ok (MINUS, <MODE>mode, operands)"
6305   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
6306   [(set_attr "type" "alu")
6307    (set_attr "mode" "<MODE>")])
6308
6309 (define_insn "*subsi_3_zext"
6310   [(set (reg FLAGS_REG)
6311         (compare (match_operand:SI 1 "register_operand" "0")
6312                  (match_operand:SI 2 "x86_64_general_operand" "rme")))
6313    (set (match_operand:DI 0 "register_operand" "=r")
6314         (zero_extend:DI
6315           (minus:SI (match_dup 1)
6316                     (match_dup 2))))]
6317   "TARGET_64BIT && ix86_match_ccmode (insn, CCmode)
6318    && ix86_binary_operator_ok (MINUS, SImode, operands)"
6319   "sub{l}\t{%2, %1|%1, %2}"
6320   [(set_attr "type" "alu")
6321    (set_attr "mode" "SI")])
6322 \f
6323 ;; Add with carry and subtract with borrow
6324
6325 (define_expand "<plusminus_insn><mode>3_carry"
6326   [(parallel
6327     [(set (match_operand:SWI 0 "nonimmediate_operand")
6328           (plusminus:SWI
6329             (match_operand:SWI 1 "nonimmediate_operand")
6330             (plus:SWI (match_operator:SWI 4 "ix86_carry_flag_operator"
6331                        [(match_operand 3 "flags_reg_operand")
6332                         (const_int 0)])
6333                       (match_operand:SWI 2 "<general_operand>"))))
6334      (clobber (reg:CC FLAGS_REG))])]
6335   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)")
6336
6337 (define_insn "*<plusminus_insn><mode>3_carry"
6338   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6339         (plusminus:SWI
6340           (match_operand:SWI 1 "nonimmediate_operand" "<comm>0,0")
6341           (plus:SWI
6342             (match_operator 3 "ix86_carry_flag_operator"
6343              [(reg FLAGS_REG) (const_int 0)])
6344             (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m"))))
6345    (clobber (reg:CC FLAGS_REG))]
6346   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
6347   "<plusminus_carry_mnemonic>{<imodesuffix>}\t{%2, %0|%0, %2}"
6348   [(set_attr "type" "alu")
6349    (set_attr "use_carry" "1")
6350    (set_attr "pent_pair" "pu")
6351    (set_attr "mode" "<MODE>")])
6352
6353 (define_insn "*addsi3_carry_zext"
6354   [(set (match_operand:DI 0 "register_operand" "=r")
6355         (zero_extend:DI
6356           (plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
6357                    (plus:SI (match_operator 3 "ix86_carry_flag_operator"
6358                              [(reg FLAGS_REG) (const_int 0)])
6359                             (match_operand:SI 2 "x86_64_general_operand" "rme")))))
6360    (clobber (reg:CC FLAGS_REG))]
6361   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, SImode, operands)"
6362   "adc{l}\t{%2, %k0|%k0, %2}"
6363   [(set_attr "type" "alu")
6364    (set_attr "use_carry" "1")
6365    (set_attr "pent_pair" "pu")
6366    (set_attr "mode" "SI")])
6367
6368 (define_insn "*subsi3_carry_zext"
6369   [(set (match_operand:DI 0 "register_operand" "=r")
6370         (zero_extend:DI
6371           (minus:SI (match_operand:SI 1 "register_operand" "0")
6372                     (plus:SI (match_operator 3 "ix86_carry_flag_operator"
6373                               [(reg FLAGS_REG) (const_int 0)])
6374                              (match_operand:SI 2 "x86_64_general_operand" "rme")))))
6375    (clobber (reg:CC FLAGS_REG))]
6376   "TARGET_64BIT && ix86_binary_operator_ok (MINUS, SImode, operands)"
6377   "sbb{l}\t{%2, %k0|%k0, %2}"
6378   [(set_attr "type" "alu")
6379    (set_attr "pent_pair" "pu")
6380    (set_attr "mode" "SI")])
6381 \f
6382 ;; ADCX instruction
6383
6384 (define_insn "adcx<mode>3"
6385   [(set (reg:CCC FLAGS_REG)
6386         (compare:CCC
6387           (plus:SWI48
6388             (match_operand:SWI48 1 "nonimmediate_operand" "%0")
6389             (plus:SWI48
6390               (match_operator 4 "ix86_carry_flag_operator"
6391                [(match_operand 3 "flags_reg_operand") (const_int 0)])
6392               (match_operand:SWI48 2 "nonimmediate_operand" "rm")))
6393           (const_int 0)))
6394    (set (match_operand:SWI48 0 "register_operand" "=r")
6395         (plus:SWI48 (match_dup 1)
6396                     (plus:SWI48 (match_op_dup 4
6397                                  [(match_dup 3) (const_int 0)])
6398                                 (match_dup 2))))]
6399   "TARGET_ADX && ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
6400   "adcx\t{%2, %0|%0, %2}"
6401   [(set_attr "type" "alu")
6402    (set_attr "use_carry" "1")
6403    (set_attr "mode" "<MODE>")])
6404 \f
6405 ;; Overflow setting add instructions
6406
6407 (define_insn "*add<mode>3_cconly_overflow"
6408   [(set (reg:CCC FLAGS_REG)
6409         (compare:CCC
6410           (plus:SWI
6411             (match_operand:SWI 1 "nonimmediate_operand" "%0")
6412             (match_operand:SWI 2 "<general_operand>" "<g>"))
6413           (match_dup 1)))
6414    (clobber (match_scratch:SWI 0 "=<r>"))]
6415   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
6416   "add{<imodesuffix>}\t{%2, %0|%0, %2}"
6417   [(set_attr "type" "alu")
6418    (set_attr "mode" "<MODE>")])
6419
6420 (define_insn "*add<mode>3_cc_overflow"
6421   [(set (reg:CCC FLAGS_REG)
6422         (compare:CCC
6423             (plus:SWI
6424                 (match_operand:SWI 1 "nonimmediate_operand" "%0,0")
6425                 (match_operand:SWI 2 "<general_operand>" "<r><i>,<r>m"))
6426             (match_dup 1)))
6427    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m,<r>")
6428         (plus:SWI (match_dup 1) (match_dup 2)))]
6429   "ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
6430   "add{<imodesuffix>}\t{%2, %0|%0, %2}"
6431   [(set_attr "type" "alu")
6432    (set_attr "mode" "<MODE>")])
6433
6434 (define_insn "*addsi3_zext_cc_overflow"
6435   [(set (reg:CCC FLAGS_REG)
6436         (compare:CCC
6437           (plus:SI
6438             (match_operand:SI 1 "nonimmediate_operand" "%0")
6439             (match_operand:SI 2 "x86_64_general_operand" "rme"))
6440           (match_dup 1)))
6441    (set (match_operand:DI 0 "register_operand" "=r")
6442         (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))]
6443   "TARGET_64BIT && ix86_binary_operator_ok (PLUS, SImode, operands)"
6444   "add{l}\t{%2, %k0|%k0, %2}"
6445   [(set_attr "type" "alu")
6446    (set_attr "mode" "SI")])
6447
6448 ;; The patterns that match these are at the end of this file.
6449
6450 (define_expand "<plusminus_insn>xf3"
6451   [(set (match_operand:XF 0 "register_operand")
6452         (plusminus:XF
6453           (match_operand:XF 1 "register_operand")
6454           (match_operand:XF 2 "register_operand")))]
6455   "TARGET_80387")
6456
6457 (define_expand "<plusminus_insn><mode>3"
6458   [(set (match_operand:MODEF 0 "register_operand")
6459         (plusminus:MODEF
6460           (match_operand:MODEF 1 "register_operand")
6461           (match_operand:MODEF 2 "nonimmediate_operand")))]
6462   "(TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode))
6463     || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)")
6464 \f
6465 ;; Multiply instructions
6466
6467 (define_expand "mul<mode>3"
6468   [(parallel [(set (match_operand:SWIM248 0 "register_operand")
6469                    (mult:SWIM248
6470                      (match_operand:SWIM248 1 "register_operand")
6471                      (match_operand:SWIM248 2 "<general_operand>")))
6472               (clobber (reg:CC FLAGS_REG))])])
6473
6474 (define_expand "mulqi3"
6475   [(parallel [(set (match_operand:QI 0 "register_operand")
6476                    (mult:QI
6477                      (match_operand:QI 1 "register_operand")
6478                      (match_operand:QI 2 "nonimmediate_operand")))
6479               (clobber (reg:CC FLAGS_REG))])]
6480   "TARGET_QIMODE_MATH")
6481
6482 ;; On AMDFAM10
6483 ;; IMUL reg32/64, reg32/64, imm8        Direct
6484 ;; IMUL reg32/64, mem32/64, imm8        VectorPath
6485 ;; IMUL reg32/64, reg32/64, imm32       Direct
6486 ;; IMUL reg32/64, mem32/64, imm32       VectorPath
6487 ;; IMUL reg32/64, reg32/64              Direct
6488 ;; IMUL reg32/64, mem32/64              Direct
6489 ;;
6490 ;; On BDVER1, all above IMULs use DirectPath
6491
6492 (define_insn "*mul<mode>3_1"
6493   [(set (match_operand:SWI48 0 "register_operand" "=r,r,r")
6494         (mult:SWI48
6495           (match_operand:SWI48 1 "nonimmediate_operand" "%rm,rm,0")
6496           (match_operand:SWI48 2 "<general_operand>" "K,<i>,mr")))
6497    (clobber (reg:CC FLAGS_REG))]
6498   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
6499   "@
6500    imul{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}
6501    imul{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}
6502    imul{<imodesuffix>}\t{%2, %0|%0, %2}"
6503   [(set_attr "type" "imul")
6504    (set_attr "prefix_0f" "0,0,1")
6505    (set (attr "athlon_decode")
6506         (cond [(eq_attr "cpu" "athlon")
6507                   (const_string "vector")
6508                (eq_attr "alternative" "1")
6509                   (const_string "vector")
6510                (and (eq_attr "alternative" "2")
6511                     (match_operand 1 "memory_operand"))
6512                   (const_string "vector")]
6513               (const_string "direct")))
6514    (set (attr "amdfam10_decode")
6515         (cond [(and (eq_attr "alternative" "0,1")
6516                     (match_operand 1 "memory_operand"))
6517                   (const_string "vector")]
6518               (const_string "direct")))
6519    (set_attr "bdver1_decode" "direct")
6520    (set_attr "mode" "<MODE>")])
6521
6522 (define_insn "*mulsi3_1_zext"
6523   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
6524         (zero_extend:DI
6525           (mult:SI (match_operand:SI 1 "nonimmediate_operand" "%rm,rm,0")
6526                    (match_operand:SI 2 "x86_64_general_operand" "K,e,mr"))))
6527    (clobber (reg:CC FLAGS_REG))]
6528   "TARGET_64BIT
6529    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6530   "@
6531    imul{l}\t{%2, %1, %k0|%k0, %1, %2}
6532    imul{l}\t{%2, %1, %k0|%k0, %1, %2}
6533    imul{l}\t{%2, %k0|%k0, %2}"
6534   [(set_attr "type" "imul")
6535    (set_attr "prefix_0f" "0,0,1")
6536    (set (attr "athlon_decode")
6537         (cond [(eq_attr "cpu" "athlon")
6538                   (const_string "vector")
6539                (eq_attr "alternative" "1")
6540                   (const_string "vector")
6541                (and (eq_attr "alternative" "2")
6542                     (match_operand 1 "memory_operand"))
6543                   (const_string "vector")]
6544               (const_string "direct")))
6545    (set (attr "amdfam10_decode")
6546         (cond [(and (eq_attr "alternative" "0,1")
6547                     (match_operand 1 "memory_operand"))
6548                   (const_string "vector")]
6549               (const_string "direct")))
6550    (set_attr "bdver1_decode" "direct")
6551    (set_attr "mode" "SI")])
6552
6553 ;; On AMDFAM10
6554 ;; IMUL reg16, reg16, imm8      VectorPath
6555 ;; IMUL reg16, mem16, imm8      VectorPath
6556 ;; IMUL reg16, reg16, imm16     VectorPath
6557 ;; IMUL reg16, mem16, imm16     VectorPath
6558 ;; IMUL reg16, reg16            Direct
6559 ;; IMUL reg16, mem16            Direct
6560 ;;
6561 ;; On BDVER1, all HI MULs use DoublePath
6562
6563 (define_insn "*mulhi3_1"
6564   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
6565         (mult:HI (match_operand:HI 1 "nonimmediate_operand" "%rm,rm,0")
6566                  (match_operand:HI 2 "general_operand" "K,n,mr")))
6567    (clobber (reg:CC FLAGS_REG))]
6568   "TARGET_HIMODE_MATH
6569    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6570   "@
6571    imul{w}\t{%2, %1, %0|%0, %1, %2}
6572    imul{w}\t{%2, %1, %0|%0, %1, %2}
6573    imul{w}\t{%2, %0|%0, %2}"
6574   [(set_attr "type" "imul")
6575    (set_attr "prefix_0f" "0,0,1")
6576    (set (attr "athlon_decode")
6577         (cond [(eq_attr "cpu" "athlon")
6578                   (const_string "vector")
6579                (eq_attr "alternative" "1,2")
6580                   (const_string "vector")]
6581               (const_string "direct")))
6582    (set (attr "amdfam10_decode")
6583         (cond [(eq_attr "alternative" "0,1")
6584                   (const_string "vector")]
6585               (const_string "direct")))
6586    (set_attr "bdver1_decode" "double")
6587    (set_attr "mode" "HI")])
6588
6589 ;;On AMDFAM10 and BDVER1
6590 ;; MUL reg8     Direct
6591 ;; MUL mem8     Direct
6592
6593 (define_insn "*mulqi3_1"
6594   [(set (match_operand:QI 0 "register_operand" "=a")
6595         (mult:QI (match_operand:QI 1 "nonimmediate_operand" "%0")
6596                  (match_operand:QI 2 "nonimmediate_operand" "qm")))
6597    (clobber (reg:CC FLAGS_REG))]
6598   "TARGET_QIMODE_MATH
6599    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6600   "mul{b}\t%2"
6601   [(set_attr "type" "imul")
6602    (set_attr "length_immediate" "0")
6603    (set (attr "athlon_decode")
6604      (if_then_else (eq_attr "cpu" "athlon")
6605         (const_string "vector")
6606         (const_string "direct")))
6607    (set_attr "amdfam10_decode" "direct")
6608    (set_attr "bdver1_decode" "direct")
6609    (set_attr "mode" "QI")])
6610
6611 ;; Multiply with jump on overflow.
6612 (define_expand "mulv<mode>4"
6613   [(parallel [(set (reg:CCO FLAGS_REG)
6614                    (eq:CCO (mult:<DWI>
6615                               (sign_extend:<DWI>
6616                                  (match_operand:SWI48 1 "register_operand"))
6617                               (match_dup 4))
6618                            (sign_extend:<DWI>
6619                               (mult:SWI48 (match_dup 1)
6620                                           (match_operand:SWI48 2
6621                                              "<general_operand>")))))
6622               (set (match_operand:SWI48 0 "register_operand")
6623                    (mult:SWI48 (match_dup 1) (match_dup 2)))])
6624    (set (pc) (if_then_else
6625                (eq (reg:CCO FLAGS_REG) (const_int 0))
6626                (label_ref (match_operand 3))
6627                (pc)))]
6628   ""
6629 {
6630   if (CONST_INT_P (operands[2]))
6631     operands[4] = operands[2];
6632   else
6633     operands[4] = gen_rtx_SIGN_EXTEND (<DWI>mode, operands[2]);
6634 })
6635
6636 (define_insn "*mulv<mode>4"
6637   [(set (reg:CCO FLAGS_REG)
6638         (eq:CCO (mult:<DWI>
6639                    (sign_extend:<DWI>
6640                       (match_operand:SWI48 1 "nonimmediate_operand" "%rm,0"))
6641                    (sign_extend:<DWI>
6642                       (match_operand:SWI48 2 "<general_sext_operand>"
6643                                              "We,mr")))
6644                 (sign_extend:<DWI>
6645                    (mult:SWI48 (match_dup 1) (match_dup 2)))))
6646    (set (match_operand:SWI48 0 "register_operand" "=r,r")
6647         (mult:SWI48 (match_dup 1) (match_dup 2)))]
6648   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
6649   "@
6650    imul{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}
6651    imul{<imodesuffix>}\t{%2, %0|%0, %2}"
6652   [(set_attr "type" "imul")
6653    (set_attr "prefix_0f" "0,1")
6654    (set (attr "athlon_decode")
6655         (cond [(eq_attr "cpu" "athlon")
6656                   (const_string "vector")
6657                (eq_attr "alternative" "0")
6658                   (const_string "vector")
6659                (and (eq_attr "alternative" "1")
6660                     (match_operand 1 "memory_operand"))
6661                   (const_string "vector")]
6662               (const_string "direct")))
6663    (set (attr "amdfam10_decode")
6664         (cond [(and (eq_attr "alternative" "1")
6665                     (match_operand 1 "memory_operand"))
6666                   (const_string "vector")]
6667               (const_string "direct")))
6668    (set_attr "bdver1_decode" "direct")
6669    (set_attr "mode" "<MODE>")])
6670
6671 (define_insn "*mulv<mode>4_1"
6672   [(set (reg:CCO FLAGS_REG)
6673         (eq:CCO (mult:<DWI>
6674                    (sign_extend:<DWI>
6675                       (match_operand:SWI48 1 "nonimmediate_operand" "rm,rm"))
6676                    (match_operand:<DWI> 3 "const_int_operand" "K,i"))
6677                 (sign_extend:<DWI>
6678                    (mult:SWI48 (match_dup 1)
6679                                (match_operand:SWI 2 "x86_64_immediate_operand"
6680                                                     "K,<i>")))))
6681    (set (match_operand:SWI48 0 "register_operand" "=r,r")
6682         (mult:SWI48 (match_dup 1) (match_dup 2)))]
6683   "!(MEM_P (operands[1]) && MEM_P (operands[2]))
6684    && CONST_INT_P (operands[2])
6685    && INTVAL (operands[2]) == INTVAL (operands[3])"
6686   "@
6687    imul{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}
6688    imul{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}"
6689   [(set_attr "type" "imul")
6690    (set (attr "athlon_decode")
6691         (cond [(eq_attr "cpu" "athlon")
6692                   (const_string "vector")
6693                (eq_attr "alternative" "1")
6694                   (const_string "vector")]
6695               (const_string "direct")))
6696    (set (attr "amdfam10_decode")
6697         (cond [(match_operand 1 "memory_operand")
6698                   (const_string "vector")]
6699               (const_string "direct")))
6700    (set_attr "bdver1_decode" "direct")
6701    (set_attr "mode" "<MODE>")
6702    (set (attr "length_immediate")
6703         (cond [(match_test "IN_RANGE (INTVAL (operands[2]), -128, 127)")
6704                   (const_string "1")
6705                (match_test "<MODE_SIZE> == 8")
6706                   (const_string "4")]
6707               (const_string "<MODE_SIZE>")))])
6708
6709 (define_expand "umulv<mode>4"
6710   [(parallel [(set (reg:CCO FLAGS_REG)
6711                    (eq:CCO (mult:<DWI>
6712                               (zero_extend:<DWI>
6713                                  (match_operand:SWI48 1
6714                                                       "nonimmediate_operand"))
6715                               (zero_extend:<DWI>
6716                                  (match_operand:SWI48 2
6717                                                       "nonimmediate_operand")))
6718                            (zero_extend:<DWI>
6719                               (mult:SWI48 (match_dup 1) (match_dup 2)))))
6720               (set (match_operand:SWI48 0 "register_operand")
6721                    (mult:SWI48 (match_dup 1) (match_dup 2)))
6722               (clobber (match_scratch:SWI48 4))])
6723    (set (pc) (if_then_else
6724                (eq (reg:CCO FLAGS_REG) (const_int 0))
6725                (label_ref (match_operand 3))
6726                (pc)))]
6727   ""
6728 {
6729   if (MEM_P (operands[1]) && MEM_P (operands[2]))
6730     operands[1] = force_reg (<MODE>mode, operands[1]);
6731 })
6732
6733 (define_insn "*umulv<mode>4"
6734   [(set (reg:CCO FLAGS_REG)
6735         (eq:CCO (mult:<DWI>
6736                    (zero_extend:<DWI>
6737                       (match_operand:SWI48 1 "nonimmediate_operand" "%0"))
6738                    (zero_extend:<DWI>
6739                       (match_operand:SWI48 2 "nonimmediate_operand" "rm")))
6740                 (zero_extend:<DWI>
6741                    (mult:SWI48 (match_dup 1) (match_dup 2)))))
6742    (set (match_operand:SWI48 0 "register_operand" "=a")
6743         (mult:SWI48 (match_dup 1) (match_dup 2)))
6744    (clobber (match_scratch:SWI48 3 "=d"))]
6745   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
6746   "mul{<imodesuffix>}\t%2"
6747   [(set_attr "type" "imul")
6748    (set_attr "length_immediate" "0")
6749    (set (attr "athlon_decode")
6750      (if_then_else (eq_attr "cpu" "athlon")
6751        (const_string "vector")
6752        (const_string "double")))
6753    (set_attr "amdfam10_decode" "double")
6754    (set_attr "bdver1_decode" "direct")
6755    (set_attr "mode" "<MODE>")])
6756
6757 (define_expand "<u>mulvqi4"
6758   [(parallel [(set (reg:CCO FLAGS_REG)
6759                    (eq:CCO (mult:HI
6760                               (any_extend:HI
6761                                  (match_operand:QI 1 "nonimmediate_operand"))
6762                               (any_extend:HI
6763                                  (match_operand:QI 2 "nonimmediate_operand")))
6764                            (any_extend:HI
6765                               (mult:QI (match_dup 1) (match_dup 2)))))
6766               (set (match_operand:QI 0 "register_operand")
6767                    (mult:QI (match_dup 1) (match_dup 2)))])
6768    (set (pc) (if_then_else
6769                (eq (reg:CCO FLAGS_REG) (const_int 0))
6770                (label_ref (match_operand 3))
6771                (pc)))]
6772   "TARGET_QIMODE_MATH"
6773 {
6774   if (MEM_P (operands[1]) && MEM_P (operands[2]))
6775     operands[1] = force_reg (QImode, operands[1]);
6776 })
6777
6778 (define_insn "*<u>mulvqi4"
6779   [(set (reg:CCO FLAGS_REG)
6780         (eq:CCO (mult:HI
6781                    (any_extend:HI
6782                       (match_operand:QI 1 "nonimmediate_operand" "%0"))
6783                    (any_extend:HI
6784                       (match_operand:QI 2 "nonimmediate_operand" "qm")))
6785                 (any_extend:HI
6786                    (mult:QI (match_dup 1) (match_dup 2)))))
6787    (set (match_operand:QI 0 "register_operand" "=a")
6788         (mult:QI (match_dup 1) (match_dup 2)))]
6789   "TARGET_QIMODE_MATH
6790    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6791   "<sgnprefix>mul{b}\t%2"
6792   [(set_attr "type" "imul")
6793    (set_attr "length_immediate" "0")
6794    (set (attr "athlon_decode")
6795      (if_then_else (eq_attr "cpu" "athlon")
6796         (const_string "vector")
6797         (const_string "direct")))
6798    (set_attr "amdfam10_decode" "direct")
6799    (set_attr "bdver1_decode" "direct")
6800    (set_attr "mode" "QI")])
6801
6802 (define_expand "<u>mul<mode><dwi>3"
6803   [(parallel [(set (match_operand:<DWI> 0 "register_operand")
6804                    (mult:<DWI>
6805                      (any_extend:<DWI>
6806                        (match_operand:DWIH 1 "nonimmediate_operand"))
6807                      (any_extend:<DWI>
6808                        (match_operand:DWIH 2 "register_operand"))))
6809               (clobber (reg:CC FLAGS_REG))])])
6810
6811 (define_expand "<u>mulqihi3"
6812   [(parallel [(set (match_operand:HI 0 "register_operand")
6813                    (mult:HI
6814                      (any_extend:HI
6815                        (match_operand:QI 1 "nonimmediate_operand"))
6816                      (any_extend:HI
6817                        (match_operand:QI 2 "register_operand"))))
6818               (clobber (reg:CC FLAGS_REG))])]
6819   "TARGET_QIMODE_MATH")
6820
6821 (define_insn "*bmi2_umulditi3_1"
6822   [(set (match_operand:DI 0 "register_operand" "=r")
6823         (mult:DI
6824           (match_operand:DI 2 "nonimmediate_operand" "%d")
6825           (match_operand:DI 3 "nonimmediate_operand" "rm")))
6826    (set (match_operand:DI 1 "register_operand" "=r")
6827         (truncate:DI
6828           (lshiftrt:TI
6829             (mult:TI (zero_extend:TI (match_dup 2))
6830                      (zero_extend:TI (match_dup 3)))
6831             (const_int 64))))]
6832   "TARGET_64BIT && TARGET_BMI2
6833    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6834   "mulx\t{%3, %0, %1|%1, %0, %3}"
6835   [(set_attr "type" "imulx")
6836    (set_attr "prefix" "vex")
6837    (set_attr "mode" "DI")])
6838
6839 (define_insn "*bmi2_umulsidi3_1"
6840   [(set (match_operand:SI 0 "register_operand" "=r")
6841         (mult:SI
6842           (match_operand:SI 2 "nonimmediate_operand" "%d")
6843           (match_operand:SI 3 "nonimmediate_operand" "rm")))
6844    (set (match_operand:SI 1 "register_operand" "=r")
6845         (truncate:SI
6846           (lshiftrt:DI
6847             (mult:DI (zero_extend:DI (match_dup 2))
6848                      (zero_extend:DI (match_dup 3)))
6849             (const_int 32))))]
6850   "!TARGET_64BIT && TARGET_BMI2
6851    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6852   "mulx\t{%3, %0, %1|%1, %0, %3}"
6853   [(set_attr "type" "imulx")
6854    (set_attr "prefix" "vex")
6855    (set_attr "mode" "SI")])
6856
6857 (define_insn "*umul<mode><dwi>3_1"
6858   [(set (match_operand:<DWI> 0 "register_operand" "=r,A")
6859         (mult:<DWI>
6860           (zero_extend:<DWI>
6861             (match_operand:DWIH 1 "nonimmediate_operand" "%d,0"))
6862           (zero_extend:<DWI>
6863             (match_operand:DWIH 2 "nonimmediate_operand" "rm,rm"))))
6864    (clobber (reg:CC FLAGS_REG))]
6865   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
6866   "@
6867    #
6868    mul{<imodesuffix>}\t%2"
6869   [(set_attr "isa" "bmi2,*")
6870    (set_attr "type" "imulx,imul")
6871    (set_attr "length_immediate" "*,0")
6872    (set (attr "athlon_decode")
6873         (cond [(eq_attr "alternative" "1")
6874                  (if_then_else (eq_attr "cpu" "athlon")
6875                    (const_string "vector")
6876                    (const_string "double"))]
6877               (const_string "*")))
6878    (set_attr "amdfam10_decode" "*,double")
6879    (set_attr "bdver1_decode" "*,direct")
6880    (set_attr "prefix" "vex,orig")
6881    (set_attr "mode" "<MODE>")])
6882
6883 ;; Convert mul to the mulx pattern to avoid flags dependency.
6884 (define_split
6885  [(set (match_operand:<DWI> 0 "register_operand")
6886        (mult:<DWI>
6887          (zero_extend:<DWI>
6888            (match_operand:DWIH 1 "register_operand"))
6889          (zero_extend:<DWI>
6890            (match_operand:DWIH 2 "nonimmediate_operand"))))
6891   (clobber (reg:CC FLAGS_REG))]
6892  "TARGET_BMI2 && reload_completed
6893   && true_regnum (operands[1]) == DX_REG"
6894   [(parallel [(set (match_dup 3)
6895                    (mult:DWIH (match_dup 1) (match_dup 2)))
6896               (set (match_dup 4)
6897                    (truncate:DWIH
6898                      (lshiftrt:<DWI>
6899                        (mult:<DWI> (zero_extend:<DWI> (match_dup 1))
6900                                    (zero_extend:<DWI> (match_dup 2)))
6901                        (match_dup 5))))])]
6902 {
6903   split_double_mode (<DWI>mode, &operands[0], 1, &operands[3], &operands[4]);
6904
6905   operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
6906 })
6907
6908 (define_insn "*mul<mode><dwi>3_1"
6909   [(set (match_operand:<DWI> 0 "register_operand" "=A")
6910         (mult:<DWI>
6911           (sign_extend:<DWI>
6912             (match_operand:DWIH 1 "nonimmediate_operand" "%0"))
6913           (sign_extend:<DWI>
6914             (match_operand:DWIH 2 "nonimmediate_operand" "rm"))))
6915    (clobber (reg:CC FLAGS_REG))]
6916   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
6917   "imul{<imodesuffix>}\t%2"
6918   [(set_attr "type" "imul")
6919    (set_attr "length_immediate" "0")
6920    (set (attr "athlon_decode")
6921      (if_then_else (eq_attr "cpu" "athlon")
6922         (const_string "vector")
6923         (const_string "double")))
6924    (set_attr "amdfam10_decode" "double")
6925    (set_attr "bdver1_decode" "direct")
6926    (set_attr "mode" "<MODE>")])
6927
6928 (define_insn "*<u>mulqihi3_1"
6929   [(set (match_operand:HI 0 "register_operand" "=a")
6930         (mult:HI
6931           (any_extend:HI
6932             (match_operand:QI 1 "nonimmediate_operand" "%0"))
6933           (any_extend:HI
6934             (match_operand:QI 2 "nonimmediate_operand" "qm"))))
6935    (clobber (reg:CC FLAGS_REG))]
6936   "TARGET_QIMODE_MATH
6937    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6938   "<sgnprefix>mul{b}\t%2"
6939   [(set_attr "type" "imul")
6940    (set_attr "length_immediate" "0")
6941    (set (attr "athlon_decode")
6942      (if_then_else (eq_attr "cpu" "athlon")
6943         (const_string "vector")
6944         (const_string "direct")))
6945    (set_attr "amdfam10_decode" "direct")
6946    (set_attr "bdver1_decode" "direct")
6947    (set_attr "mode" "QI")])
6948
6949 (define_expand "<s>mul<mode>3_highpart"
6950   [(parallel [(set (match_operand:SWI48 0 "register_operand")
6951                    (truncate:SWI48
6952                      (lshiftrt:<DWI>
6953                        (mult:<DWI>
6954                          (any_extend:<DWI>
6955                            (match_operand:SWI48 1 "nonimmediate_operand"))
6956                          (any_extend:<DWI>
6957                            (match_operand:SWI48 2 "register_operand")))
6958                        (match_dup 4))))
6959               (clobber (match_scratch:SWI48 3))
6960               (clobber (reg:CC FLAGS_REG))])]
6961   ""
6962   "operands[4] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));")
6963
6964 (define_insn "*<s>muldi3_highpart_1"
6965   [(set (match_operand:DI 0 "register_operand" "=d")
6966         (truncate:DI
6967           (lshiftrt:TI
6968             (mult:TI
6969               (any_extend:TI
6970                 (match_operand:DI 1 "nonimmediate_operand" "%a"))
6971               (any_extend:TI
6972                 (match_operand:DI 2 "nonimmediate_operand" "rm")))
6973             (const_int 64))))
6974    (clobber (match_scratch:DI 3 "=1"))
6975    (clobber (reg:CC FLAGS_REG))]
6976   "TARGET_64BIT
6977    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
6978   "<sgnprefix>mul{q}\t%2"
6979   [(set_attr "type" "imul")
6980    (set_attr "length_immediate" "0")
6981    (set (attr "athlon_decode")
6982      (if_then_else (eq_attr "cpu" "athlon")
6983         (const_string "vector")
6984         (const_string "double")))
6985    (set_attr "amdfam10_decode" "double")
6986    (set_attr "bdver1_decode" "direct")
6987    (set_attr "mode" "DI")])
6988
6989 (define_insn "*<s>mulsi3_highpart_1"
6990   [(set (match_operand:SI 0 "register_operand" "=d")
6991         (truncate:SI
6992           (lshiftrt:DI
6993             (mult:DI
6994               (any_extend:DI
6995                 (match_operand:SI 1 "nonimmediate_operand" "%a"))
6996               (any_extend:DI
6997                 (match_operand:SI 2 "nonimmediate_operand" "rm")))
6998             (const_int 32))))
6999    (clobber (match_scratch:SI 3 "=1"))
7000    (clobber (reg:CC FLAGS_REG))]
7001   "!(MEM_P (operands[1]) && MEM_P (operands[2]))"
7002   "<sgnprefix>mul{l}\t%2"
7003   [(set_attr "type" "imul")
7004    (set_attr "length_immediate" "0")
7005    (set (attr "athlon_decode")
7006      (if_then_else (eq_attr "cpu" "athlon")
7007         (const_string "vector")
7008         (const_string "double")))
7009    (set_attr "amdfam10_decode" "double")
7010    (set_attr "bdver1_decode" "direct")
7011    (set_attr "mode" "SI")])
7012
7013 (define_insn "*<s>mulsi3_highpart_zext"
7014   [(set (match_operand:DI 0 "register_operand" "=d")
7015         (zero_extend:DI (truncate:SI
7016           (lshiftrt:DI
7017             (mult:DI (any_extend:DI
7018                        (match_operand:SI 1 "nonimmediate_operand" "%a"))
7019                      (any_extend:DI
7020                        (match_operand:SI 2 "nonimmediate_operand" "rm")))
7021             (const_int 32)))))
7022    (clobber (match_scratch:SI 3 "=1"))
7023    (clobber (reg:CC FLAGS_REG))]
7024   "TARGET_64BIT
7025    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
7026   "<sgnprefix>mul{l}\t%2"
7027   [(set_attr "type" "imul")
7028    (set_attr "length_immediate" "0")
7029    (set (attr "athlon_decode")
7030      (if_then_else (eq_attr "cpu" "athlon")
7031         (const_string "vector")
7032         (const_string "double")))
7033    (set_attr "amdfam10_decode" "double")
7034    (set_attr "bdver1_decode" "direct")
7035    (set_attr "mode" "SI")])
7036
7037 ;; The patterns that match these are at the end of this file.
7038
7039 (define_expand "mulxf3"
7040   [(set (match_operand:XF 0 "register_operand")
7041         (mult:XF (match_operand:XF 1 "register_operand")
7042                  (match_operand:XF 2 "register_operand")))]
7043   "TARGET_80387")
7044
7045 (define_expand "mul<mode>3"
7046   [(set (match_operand:MODEF 0 "register_operand")
7047         (mult:MODEF (match_operand:MODEF 1 "register_operand")
7048                     (match_operand:MODEF 2 "nonimmediate_operand")))]
7049   "(TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode))
7050     || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)")
7051 \f
7052 ;; Divide instructions
7053
7054 ;; The patterns that match these are at the end of this file.
7055
7056 (define_expand "divxf3"
7057   [(set (match_operand:XF 0 "register_operand")
7058         (div:XF (match_operand:XF 1 "register_operand")
7059                 (match_operand:XF 2 "register_operand")))]
7060   "TARGET_80387")
7061
7062 (define_expand "divdf3"
7063   [(set (match_operand:DF 0 "register_operand")
7064         (div:DF (match_operand:DF 1 "register_operand")
7065                 (match_operand:DF 2 "nonimmediate_operand")))]
7066    "(TARGET_80387 && X87_ENABLE_ARITH (DFmode))
7067     || (TARGET_SSE2 && TARGET_SSE_MATH)")
7068
7069 (define_expand "divsf3"
7070   [(set (match_operand:SF 0 "register_operand")
7071         (div:SF (match_operand:SF 1 "register_operand")
7072                 (match_operand:SF 2 "nonimmediate_operand")))]
7073   "(TARGET_80387 && X87_ENABLE_ARITH (SFmode))
7074     || TARGET_SSE_MATH"
7075 {
7076   if (TARGET_SSE_MATH
7077       && TARGET_RECIP_DIV
7078       && optimize_insn_for_speed_p ()
7079       && flag_finite_math_only && !flag_trapping_math
7080       && flag_unsafe_math_optimizations)
7081     {
7082       ix86_emit_swdivsf (operands[0], operands[1],
7083                          operands[2], SFmode);
7084       DONE;
7085     }
7086 })
7087 \f
7088 ;; Divmod instructions.
7089
7090 (define_expand "divmod<mode>4"
7091   [(parallel [(set (match_operand:SWIM248 0 "register_operand")
7092                    (div:SWIM248
7093                      (match_operand:SWIM248 1 "register_operand")
7094                      (match_operand:SWIM248 2 "nonimmediate_operand")))
7095               (set (match_operand:SWIM248 3 "register_operand")
7096                    (mod:SWIM248 (match_dup 1) (match_dup 2)))
7097               (clobber (reg:CC FLAGS_REG))])])
7098
7099 ;; Split with 8bit unsigned divide:
7100 ;;      if (dividend an divisor are in [0-255])
7101 ;;         use 8bit unsigned integer divide
7102 ;;       else
7103 ;;         use original integer divide
7104 (define_split
7105   [(set (match_operand:SWI48 0 "register_operand")
7106         (div:SWI48 (match_operand:SWI48 2 "register_operand")
7107                     (match_operand:SWI48 3 "nonimmediate_operand")))
7108    (set (match_operand:SWI48 1 "register_operand")
7109         (mod:SWI48 (match_dup 2) (match_dup 3)))
7110    (clobber (reg:CC FLAGS_REG))]
7111   "TARGET_USE_8BIT_IDIV
7112    && TARGET_QIMODE_MATH
7113    && can_create_pseudo_p ()
7114    && !optimize_insn_for_size_p ()"
7115   [(const_int 0)]
7116   "ix86_split_idivmod (<MODE>mode, operands, true); DONE;")
7117
7118 (define_insn_and_split "divmod<mode>4_1"
7119   [(set (match_operand:SWI48 0 "register_operand" "=a")
7120         (div:SWI48 (match_operand:SWI48 2 "register_operand" "0")
7121                    (match_operand:SWI48 3 "nonimmediate_operand" "rm")))
7122    (set (match_operand:SWI48 1 "register_operand" "=&d")
7123         (mod:SWI48 (match_dup 2) (match_dup 3)))
7124    (unspec [(const_int 0)] UNSPEC_DIV_ALREADY_SPLIT)
7125    (clobber (reg:CC FLAGS_REG))]
7126   ""
7127   "#"
7128   "reload_completed"
7129   [(parallel [(set (match_dup 1)
7130                    (ashiftrt:SWI48 (match_dup 4) (match_dup 5)))
7131               (clobber (reg:CC FLAGS_REG))])
7132    (parallel [(set (match_dup 0)
7133                    (div:SWI48 (match_dup 2) (match_dup 3)))
7134               (set (match_dup 1)
7135                    (mod:SWI48 (match_dup 2) (match_dup 3)))
7136               (use (match_dup 1))
7137               (clobber (reg:CC FLAGS_REG))])]
7138 {
7139   operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1);
7140
7141   if (optimize_function_for_size_p (cfun) || TARGET_USE_CLTD)
7142     operands[4] = operands[2];
7143   else
7144     {
7145       /* Avoid use of cltd in favor of a mov+shift.  */
7146       emit_move_insn (operands[1], operands[2]);
7147       operands[4] = operands[1];
7148     }
7149 }
7150   [(set_attr "type" "multi")
7151    (set_attr "mode" "<MODE>")])
7152
7153 (define_insn_and_split "*divmod<mode>4"
7154   [(set (match_operand:SWIM248 0 "register_operand" "=a")
7155         (div:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
7156                     (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
7157    (set (match_operand:SWIM248 1 "register_operand" "=&d")
7158         (mod:SWIM248 (match_dup 2) (match_dup 3)))
7159    (clobber (reg:CC FLAGS_REG))]
7160   ""
7161   "#"
7162   "reload_completed"
7163   [(parallel [(set (match_dup 1)
7164                    (ashiftrt:SWIM248 (match_dup 4) (match_dup 5)))
7165               (clobber (reg:CC FLAGS_REG))])
7166    (parallel [(set (match_dup 0)
7167                    (div:SWIM248 (match_dup 2) (match_dup 3)))
7168               (set (match_dup 1)
7169                    (mod:SWIM248 (match_dup 2) (match_dup 3)))
7170               (use (match_dup 1))
7171               (clobber (reg:CC FLAGS_REG))])]
7172 {
7173   operands[5] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1);
7174
7175   if (<MODE>mode != HImode
7176       && (optimize_function_for_size_p (cfun) || TARGET_USE_CLTD))
7177     operands[4] = operands[2];
7178   else
7179     {
7180       /* Avoid use of cltd in favor of a mov+shift.  */
7181       emit_move_insn (operands[1], operands[2]);
7182       operands[4] = operands[1];
7183     }
7184 }
7185   [(set_attr "type" "multi")
7186    (set_attr "mode" "<MODE>")])
7187
7188 (define_insn "*divmod<mode>4_noext"
7189   [(set (match_operand:SWIM248 0 "register_operand" "=a")
7190         (div:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
7191                     (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
7192    (set (match_operand:SWIM248 1 "register_operand" "=d")
7193         (mod:SWIM248 (match_dup 2) (match_dup 3)))
7194    (use (match_operand:SWIM248 4 "register_operand" "1"))
7195    (clobber (reg:CC FLAGS_REG))]
7196   ""
7197   "idiv{<imodesuffix>}\t%3"
7198   [(set_attr "type" "idiv")
7199    (set_attr "mode" "<MODE>")])
7200
7201 (define_expand "divmodqi4"
7202   [(parallel [(set (match_operand:QI 0 "register_operand")
7203                    (div:QI
7204                      (match_operand:QI 1 "register_operand")
7205                      (match_operand:QI 2 "nonimmediate_operand")))
7206               (set (match_operand:QI 3 "register_operand")
7207                    (mod:QI (match_dup 1) (match_dup 2)))
7208               (clobber (reg:CC FLAGS_REG))])]
7209   "TARGET_QIMODE_MATH"
7210 {
7211   rtx div, mod, insn;
7212   rtx tmp0, tmp1;
7213   
7214   tmp0 = gen_reg_rtx (HImode);
7215   tmp1 = gen_reg_rtx (HImode);
7216
7217   /* Extend operands[1] to HImode.  Generate 8bit divide.  Result is
7218      in AX.  */
7219   emit_insn (gen_extendqihi2 (tmp1, operands[1]));
7220   emit_insn (gen_divmodhiqi3 (tmp0, tmp1, operands[2]));
7221
7222   /* Extract remainder from AH.  */
7223   tmp1 = gen_rtx_SIGN_EXTRACT (QImode, tmp0, GEN_INT (8), GEN_INT (8));
7224   insn = emit_move_insn (operands[3], tmp1);
7225
7226   mod = gen_rtx_MOD (QImode, operands[1], operands[2]);
7227   set_unique_reg_note (insn, REG_EQUAL, mod);
7228
7229   /* Extract quotient from AL.  */
7230   insn = emit_move_insn (operands[0], gen_lowpart (QImode, tmp0));
7231
7232   div = gen_rtx_DIV (QImode, operands[1], operands[2]);
7233   set_unique_reg_note (insn, REG_EQUAL, div);
7234
7235   DONE;
7236 })
7237
7238 ;; Divide AX by r/m8, with result stored in
7239 ;; AL <- Quotient
7240 ;; AH <- Remainder
7241 ;; Change div/mod to HImode and extend the second argument to HImode
7242 ;; so that mode of div/mod matches with mode of arguments.  Otherwise
7243 ;; combine may fail.
7244 (define_insn "divmodhiqi3"
7245   [(set (match_operand:HI 0 "register_operand" "=a")
7246         (ior:HI
7247           (ashift:HI
7248             (zero_extend:HI
7249               (truncate:QI
7250                 (mod:HI (match_operand:HI 1 "register_operand" "0")
7251                         (sign_extend:HI
7252                           (match_operand:QI 2 "nonimmediate_operand" "qm")))))
7253             (const_int 8))
7254           (zero_extend:HI
7255             (truncate:QI
7256               (div:HI (match_dup 1) (sign_extend:HI (match_dup 2)))))))
7257    (clobber (reg:CC FLAGS_REG))]
7258   "TARGET_QIMODE_MATH"
7259   "idiv{b}\t%2"
7260   [(set_attr "type" "idiv")
7261    (set_attr "mode" "QI")])
7262
7263 (define_expand "udivmod<mode>4"
7264   [(parallel [(set (match_operand:SWIM248 0 "register_operand")
7265                    (udiv:SWIM248
7266                      (match_operand:SWIM248 1 "register_operand")
7267                      (match_operand:SWIM248 2 "nonimmediate_operand")))
7268               (set (match_operand:SWIM248 3 "register_operand")
7269                    (umod:SWIM248 (match_dup 1) (match_dup 2)))
7270               (clobber (reg:CC FLAGS_REG))])])
7271
7272 ;; Split with 8bit unsigned divide:
7273 ;;      if (dividend an divisor are in [0-255])
7274 ;;         use 8bit unsigned integer divide
7275 ;;       else
7276 ;;         use original integer divide
7277 (define_split
7278   [(set (match_operand:SWI48 0 "register_operand")
7279         (udiv:SWI48 (match_operand:SWI48 2 "register_operand")
7280                     (match_operand:SWI48 3 "nonimmediate_operand")))
7281    (set (match_operand:SWI48 1 "register_operand")
7282         (umod:SWI48 (match_dup 2) (match_dup 3)))
7283    (clobber (reg:CC FLAGS_REG))]
7284   "TARGET_USE_8BIT_IDIV
7285    && TARGET_QIMODE_MATH
7286    && can_create_pseudo_p ()
7287    && !optimize_insn_for_size_p ()"
7288   [(const_int 0)]
7289   "ix86_split_idivmod (<MODE>mode, operands, false); DONE;")
7290
7291 (define_insn_and_split "udivmod<mode>4_1"
7292   [(set (match_operand:SWI48 0 "register_operand" "=a")
7293         (udiv:SWI48 (match_operand:SWI48 2 "register_operand" "0")
7294                     (match_operand:SWI48 3 "nonimmediate_operand" "rm")))
7295    (set (match_operand:SWI48 1 "register_operand" "=&d")
7296         (umod:SWI48 (match_dup 2) (match_dup 3)))
7297    (unspec [(const_int 0)] UNSPEC_DIV_ALREADY_SPLIT)
7298    (clobber (reg:CC FLAGS_REG))]
7299   ""
7300   "#"
7301   "reload_completed"
7302   [(set (match_dup 1) (const_int 0))
7303    (parallel [(set (match_dup 0)
7304                    (udiv:SWI48 (match_dup 2) (match_dup 3)))
7305               (set (match_dup 1)
7306                    (umod:SWI48 (match_dup 2) (match_dup 3)))
7307               (use (match_dup 1))
7308               (clobber (reg:CC FLAGS_REG))])]
7309   ""
7310   [(set_attr "type" "multi")
7311    (set_attr "mode" "<MODE>")])
7312
7313 (define_insn_and_split "*udivmod<mode>4"
7314   [(set (match_operand:SWIM248 0 "register_operand" "=a")
7315         (udiv:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
7316                       (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
7317    (set (match_operand:SWIM248 1 "register_operand" "=&d")
7318         (umod:SWIM248 (match_dup 2) (match_dup 3)))
7319    (clobber (reg:CC FLAGS_REG))]
7320   ""
7321   "#"
7322   "reload_completed"
7323   [(set (match_dup 1) (const_int 0))
7324    (parallel [(set (match_dup 0)
7325                    (udiv:SWIM248 (match_dup 2) (match_dup 3)))
7326               (set (match_dup 1)
7327                    (umod:SWIM248 (match_dup 2) (match_dup 3)))
7328               (use (match_dup 1))
7329               (clobber (reg:CC FLAGS_REG))])]
7330   ""
7331   [(set_attr "type" "multi")
7332    (set_attr "mode" "<MODE>")])
7333
7334 (define_insn "*udivmod<mode>4_noext"
7335   [(set (match_operand:SWIM248 0 "register_operand" "=a")
7336         (udiv:SWIM248 (match_operand:SWIM248 2 "register_operand" "0")
7337                       (match_operand:SWIM248 3 "nonimmediate_operand" "rm")))
7338    (set (match_operand:SWIM248 1 "register_operand" "=d")
7339         (umod:SWIM248 (match_dup 2) (match_dup 3)))
7340    (use (match_operand:SWIM248 4 "register_operand" "1"))
7341    (clobber (reg:CC FLAGS_REG))]
7342   ""
7343   "div{<imodesuffix>}\t%3"
7344   [(set_attr "type" "idiv")
7345    (set_attr "mode" "<MODE>")])
7346
7347 (define_expand "udivmodqi4"
7348   [(parallel [(set (match_operand:QI 0 "register_operand")
7349                    (udiv:QI
7350                      (match_operand:QI 1 "register_operand")
7351                      (match_operand:QI 2 "nonimmediate_operand")))
7352               (set (match_operand:QI 3 "register_operand")
7353                    (umod:QI (match_dup 1) (match_dup 2)))
7354               (clobber (reg:CC FLAGS_REG))])]
7355   "TARGET_QIMODE_MATH"
7356 {
7357   rtx div, mod, insn;
7358   rtx tmp0, tmp1;
7359   
7360   tmp0 = gen_reg_rtx (HImode);
7361   tmp1 = gen_reg_rtx (HImode);
7362
7363   /* Extend operands[1] to HImode.  Generate 8bit divide.  Result is
7364      in AX.  */
7365   emit_insn (gen_zero_extendqihi2 (tmp1, operands[1]));
7366   emit_insn (gen_udivmodhiqi3 (tmp0, tmp1, operands[2]));
7367
7368   /* Extract remainder from AH.  */
7369   tmp1 = gen_rtx_ZERO_EXTRACT (SImode, tmp0, GEN_INT (8), GEN_INT (8));
7370   tmp1 = simplify_gen_subreg (QImode, tmp1, SImode, 0);
7371   insn = emit_move_insn (operands[3], tmp1);
7372
7373   mod = gen_rtx_UMOD (QImode, operands[1], operands[2]);
7374   set_unique_reg_note (insn, REG_EQUAL, mod);
7375
7376   /* Extract quotient from AL.  */
7377   insn = emit_move_insn (operands[0], gen_lowpart (QImode, tmp0));
7378
7379   div = gen_rtx_UDIV (QImode, operands[1], operands[2]);
7380   set_unique_reg_note (insn, REG_EQUAL, div);
7381
7382   DONE;
7383 })
7384
7385 (define_insn "udivmodhiqi3"
7386   [(set (match_operand:HI 0 "register_operand" "=a")
7387         (ior:HI
7388           (ashift:HI
7389             (zero_extend:HI
7390               (truncate:QI
7391                 (mod:HI (match_operand:HI 1 "register_operand" "0")
7392                         (zero_extend:HI
7393                           (match_operand:QI 2 "nonimmediate_operand" "qm")))))
7394             (const_int 8))
7395           (zero_extend:HI
7396             (truncate:QI
7397               (div:HI (match_dup 1) (zero_extend:HI (match_dup 2)))))))
7398    (clobber (reg:CC FLAGS_REG))]
7399   "TARGET_QIMODE_MATH"
7400   "div{b}\t%2"
7401   [(set_attr "type" "idiv")
7402    (set_attr "mode" "QI")])
7403
7404 ;; We cannot use div/idiv for double division, because it causes
7405 ;; "division by zero" on the overflow and that's not what we expect
7406 ;; from truncate.  Because true (non truncating) double division is
7407 ;; never generated, we can't create this insn anyway.
7408 ;
7409 ;(define_insn ""
7410 ;  [(set (match_operand:SI 0 "register_operand" "=a")
7411 ;       (truncate:SI
7412 ;         (udiv:DI (match_operand:DI 1 "register_operand" "A")
7413 ;                  (zero_extend:DI
7414 ;                    (match_operand:SI 2 "nonimmediate_operand" "rm")))))
7415 ;   (set (match_operand:SI 3 "register_operand" "=d")
7416 ;       (truncate:SI
7417 ;         (umod:DI (match_dup 1) (zero_extend:DI (match_dup 2)))))
7418 ;   (clobber (reg:CC FLAGS_REG))]
7419 ;  ""
7420 ;  "div{l}\t{%2, %0|%0, %2}"
7421 ;  [(set_attr "type" "idiv")])
7422 \f
7423 ;;- Logical AND instructions
7424
7425 ;; On Pentium, "test imm, reg" is pairable only with eax, ax, and al.
7426 ;; Note that this excludes ah.
7427
7428 (define_expand "testsi_ccno_1"
7429   [(set (reg:CCNO FLAGS_REG)
7430         (compare:CCNO
7431           (and:SI (match_operand:SI 0 "nonimmediate_operand")
7432                   (match_operand:SI 1 "x86_64_nonmemory_operand"))
7433           (const_int 0)))])
7434
7435 (define_expand "testqi_ccz_1"
7436   [(set (reg:CCZ FLAGS_REG)
7437         (compare:CCZ (and:QI (match_operand:QI 0 "nonimmediate_operand")
7438                              (match_operand:QI 1 "nonmemory_operand"))
7439                  (const_int 0)))])
7440
7441 (define_expand "testdi_ccno_1"
7442   [(set (reg:CCNO FLAGS_REG)
7443         (compare:CCNO
7444           (and:DI (match_operand:DI 0 "nonimmediate_operand")
7445                   (match_operand:DI 1 "x86_64_szext_general_operand"))
7446           (const_int 0)))]
7447   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))")
7448
7449 (define_insn "*testdi_1"
7450   [(set (reg FLAGS_REG)
7451         (compare
7452          (and:DI
7453           (match_operand:DI 0 "nonimmediate_operand" "%!*a,r,!*a,r,rm")
7454           (match_operand:DI 1 "x86_64_szext_general_operand" "Z,Z,e,e,re"))
7455          (const_int 0)))]
7456   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
7457    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7458   "@
7459    test{l}\t{%k1, %k0|%k0, %k1}
7460    test{l}\t{%k1, %k0|%k0, %k1}
7461    test{q}\t{%1, %0|%0, %1}
7462    test{q}\t{%1, %0|%0, %1}
7463    test{q}\t{%1, %0|%0, %1}"
7464   [(set_attr "type" "test")
7465    (set_attr "modrm" "0,1,0,1,1")
7466    (set_attr "mode" "SI,SI,DI,DI,DI")])
7467
7468 (define_insn "*testqi_1_maybe_si"
7469   [(set (reg FLAGS_REG)
7470         (compare
7471           (and:QI
7472             (match_operand:QI 0 "nonimmediate_operand" "%!*a,q,qm,r")
7473             (match_operand:QI 1 "general_operand" "n,n,qn,n"))
7474           (const_int 0)))]
7475    "!(MEM_P (operands[0]) && MEM_P (operands[1]))
7476     && ix86_match_ccmode (insn,
7477                          CONST_INT_P (operands[1])
7478                          && INTVAL (operands[1]) >= 0 ? CCNOmode : CCZmode)"
7479 {
7480   if (which_alternative == 3)
7481     {
7482       if (CONST_INT_P (operands[1]) && INTVAL (operands[1]) < 0)
7483         operands[1] = GEN_INT (INTVAL (operands[1]) & 0xff);
7484       return "test{l}\t{%1, %k0|%k0, %1}";
7485     }
7486   return "test{b}\t{%1, %0|%0, %1}";
7487 }
7488   [(set_attr "type" "test")
7489    (set_attr "modrm" "0,1,1,1")
7490    (set_attr "mode" "QI,QI,QI,SI")
7491    (set_attr "pent_pair" "uv,np,uv,np")])
7492
7493 (define_insn "*test<mode>_1"
7494   [(set (reg FLAGS_REG)
7495         (compare
7496          (and:SWI124
7497           (match_operand:SWI124 0 "nonimmediate_operand" "%!*a,<r>,<r>m")
7498           (match_operand:SWI124 1 "<general_operand>" "<i>,<i>,<r><i>"))
7499          (const_int 0)))]
7500   "ix86_match_ccmode (insn, CCNOmode)
7501    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7502   "test{<imodesuffix>}\t{%1, %0|%0, %1}"
7503   [(set_attr "type" "test")
7504    (set_attr "modrm" "0,1,1")
7505    (set_attr "mode" "<MODE>")
7506    (set_attr "pent_pair" "uv,np,uv")])
7507
7508 (define_expand "testqi_ext_ccno_0"
7509   [(set (reg:CCNO FLAGS_REG)
7510         (compare:CCNO
7511           (and:SI
7512             (zero_extract:SI
7513               (match_operand 0 "ext_register_operand")
7514               (const_int 8)
7515               (const_int 8))
7516             (match_operand 1 "const_int_operand"))
7517           (const_int 0)))])
7518
7519 (define_insn "*testqi_ext_0"
7520   [(set (reg FLAGS_REG)
7521         (compare
7522           (and:SI
7523             (zero_extract:SI
7524               (match_operand 0 "ext_register_operand" "Q")
7525               (const_int 8)
7526               (const_int 8))
7527             (match_operand 1 "const_int_operand" "n"))
7528           (const_int 0)))]
7529   "ix86_match_ccmode (insn, CCNOmode)"
7530   "test{b}\t{%1, %h0|%h0, %1}"
7531   [(set_attr "type" "test")
7532    (set_attr "mode" "QI")
7533    (set_attr "length_immediate" "1")
7534    (set_attr "modrm" "1")
7535    (set_attr "pent_pair" "np")])
7536
7537 (define_insn "*testqi_ext_1"
7538   [(set (reg FLAGS_REG)
7539         (compare
7540           (and:SI
7541             (zero_extract:SI
7542               (match_operand 0 "ext_register_operand" "Q,Q")
7543               (const_int 8)
7544               (const_int 8))
7545             (zero_extend:SI
7546               (match_operand:QI 1 "nonimmediate_x64nomem_operand" "Q,m")))
7547           (const_int 0)))]
7548   "ix86_match_ccmode (insn, CCNOmode)"
7549   "test{b}\t{%1, %h0|%h0, %1}"
7550   [(set_attr "isa" "*,nox64")
7551    (set_attr "type" "test")
7552    (set_attr "mode" "QI")])
7553
7554 (define_insn "*testqi_ext_2"
7555   [(set (reg FLAGS_REG)
7556         (compare
7557           (and:SI
7558             (zero_extract:SI
7559               (match_operand 0 "ext_register_operand" "Q")
7560               (const_int 8)
7561               (const_int 8))
7562             (zero_extract:SI
7563               (match_operand 1 "ext_register_operand" "Q")
7564               (const_int 8)
7565               (const_int 8)))
7566           (const_int 0)))]
7567   "ix86_match_ccmode (insn, CCNOmode)"
7568   "test{b}\t{%h1, %h0|%h0, %h1}"
7569   [(set_attr "type" "test")
7570    (set_attr "mode" "QI")])
7571
7572 ;; Combine likes to form bit extractions for some tests.  Humor it.
7573 (define_insn "*testqi_ext_3"
7574   [(set (reg FLAGS_REG)
7575         (compare (zero_extract:SWI48
7576                    (match_operand 0 "nonimmediate_operand" "rm")
7577                    (match_operand:SWI48 1 "const_int_operand")
7578                    (match_operand:SWI48 2 "const_int_operand"))
7579                  (const_int 0)))]
7580   "ix86_match_ccmode (insn, CCNOmode)
7581    && ((TARGET_64BIT && GET_MODE (operands[0]) == DImode)
7582        || GET_MODE (operands[0]) == SImode
7583        || GET_MODE (operands[0]) == HImode
7584        || GET_MODE (operands[0]) == QImode)
7585    /* Ensure that resulting mask is zero or sign extended operand.  */
7586    && INTVAL (operands[2]) >= 0
7587    && ((INTVAL (operands[1]) > 0
7588         && INTVAL (operands[1]) + INTVAL (operands[2]) <= 32)
7589        || (<MODE>mode == DImode
7590            && INTVAL (operands[1]) > 32
7591            && INTVAL (operands[1]) + INTVAL (operands[2]) == 64))"
7592   "#")
7593
7594 (define_split
7595   [(set (match_operand 0 "flags_reg_operand")
7596         (match_operator 1 "compare_operator"
7597           [(zero_extract
7598              (match_operand 2 "nonimmediate_operand")
7599              (match_operand 3 "const_int_operand")
7600              (match_operand 4 "const_int_operand"))
7601            (const_int 0)]))]
7602   "ix86_match_ccmode (insn, CCNOmode)"
7603   [(set (match_dup 0) (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
7604 {
7605   rtx val = operands[2];
7606   HOST_WIDE_INT len = INTVAL (operands[3]);
7607   HOST_WIDE_INT pos = INTVAL (operands[4]);
7608   HOST_WIDE_INT mask;
7609   machine_mode mode, submode;
7610
7611   mode = GET_MODE (val);
7612   if (MEM_P (val))
7613     {
7614       /* ??? Combine likes to put non-volatile mem extractions in QImode
7615          no matter the size of the test.  So find a mode that works.  */
7616       if (! MEM_VOLATILE_P (val))
7617         {
7618           mode = smallest_mode_for_size (pos + len, MODE_INT);
7619           val = adjust_address (val, mode, 0);
7620         }
7621     }
7622   else if (GET_CODE (val) == SUBREG
7623            && (submode = GET_MODE (SUBREG_REG (val)),
7624                GET_MODE_BITSIZE (mode) > GET_MODE_BITSIZE (submode))
7625            && pos + len <= GET_MODE_BITSIZE (submode)
7626            && GET_MODE_CLASS (submode) == MODE_INT)
7627     {
7628       /* Narrow a paradoxical subreg to prevent partial register stalls.  */
7629       mode = submode;
7630       val = SUBREG_REG (val);
7631     }
7632   else if (mode == HImode && pos + len <= 8)
7633     {
7634       /* Small HImode tests can be converted to QImode.  */
7635       mode = QImode;
7636       val = gen_lowpart (QImode, val);
7637     }
7638
7639   if (len == HOST_BITS_PER_WIDE_INT)
7640     mask = -1;
7641   else
7642     mask = ((HOST_WIDE_INT)1 << len) - 1;
7643   mask <<= pos;
7644
7645   operands[2] = gen_rtx_AND (mode, val, gen_int_mode (mask, mode));
7646 })
7647
7648 ;; Convert HImode/SImode test instructions with immediate to QImode ones.
7649 ;; i386 does not allow to encode test with 8bit sign extended immediate, so
7650 ;; this is relatively important trick.
7651 ;; Do the conversion only post-reload to avoid limiting of the register class
7652 ;; to QI regs.
7653 (define_split
7654   [(set (match_operand 0 "flags_reg_operand")
7655         (match_operator 1 "compare_operator"
7656           [(and (match_operand 2 "register_operand")
7657                 (match_operand 3 "const_int_operand"))
7658            (const_int 0)]))]
7659    "reload_completed
7660     && QI_REG_P (operands[2])
7661     && GET_MODE (operands[2]) != QImode
7662     && ((ix86_match_ccmode (insn, CCZmode)
7663          && !(INTVAL (operands[3]) & ~(255 << 8)))
7664         || (ix86_match_ccmode (insn, CCNOmode)
7665             && !(INTVAL (operands[3]) & ~(127 << 8))))"
7666   [(set (match_dup 0)
7667         (match_op_dup 1
7668           [(and:SI (zero_extract:SI (match_dup 2) (const_int 8) (const_int 8))
7669                    (match_dup 3))
7670            (const_int 0)]))]
7671 {
7672   operands[2] = gen_lowpart (SImode, operands[2]);
7673   operands[3] = gen_int_mode (INTVAL (operands[3]) >> 8, SImode);
7674 })
7675
7676 (define_split
7677   [(set (match_operand 0 "flags_reg_operand")
7678         (match_operator 1 "compare_operator"
7679           [(and (match_operand 2 "nonimmediate_operand")
7680                 (match_operand 3 "const_int_operand"))
7681            (const_int 0)]))]
7682    "reload_completed
7683     && GET_MODE (operands[2]) != QImode
7684     && (!REG_P (operands[2]) || ANY_QI_REG_P (operands[2]))
7685     && ((ix86_match_ccmode (insn, CCZmode)
7686          && !(INTVAL (operands[3]) & ~255))
7687         || (ix86_match_ccmode (insn, CCNOmode)
7688             && !(INTVAL (operands[3]) & ~127)))"
7689   [(set (match_dup 0)
7690         (match_op_dup 1 [(and:QI (match_dup 2) (match_dup 3))
7691                          (const_int 0)]))]
7692 {
7693   operands[2] = gen_lowpart (QImode, operands[2]);
7694   operands[3] = gen_lowpart (QImode, operands[3]);
7695 })
7696
7697 (define_split
7698   [(set (match_operand:SWI1248x 0 "mask_reg_operand")
7699         (any_logic:SWI1248x (match_operand:SWI1248x 1 "mask_reg_operand")
7700                             (match_operand:SWI1248x 2 "mask_reg_operand")))
7701    (clobber (reg:CC FLAGS_REG))]
7702   "TARGET_AVX512F && reload_completed"
7703   [(set (match_dup 0)
7704         (any_logic:SWI1248x (match_dup 1)
7705                             (match_dup 2)))])
7706
7707 (define_insn "*k<logic><mode>"
7708   [(set (match_operand:SWI1248_AVX512BW 0 "mask_reg_operand" "=k")
7709         (any_logic:SWI1248_AVX512BW (match_operand:SWI1248_AVX512BW 1 "mask_reg_operand" "k")
7710                           (match_operand:SWI1248_AVX512BW 2 "mask_reg_operand" "k")))]
7711   "TARGET_AVX512F"
7712   {
7713     if (!TARGET_AVX512DQ && <MODE>mode == QImode)
7714       return "k<logic>w\t{%2, %1, %0|%0, %1, %2}";
7715     else
7716       return "k<logic><mskmodesuffix>\t{%2, %1, %0|%0, %1, %2}";
7717   }
7718   [(set_attr "mode" "<MODE>")
7719    (set_attr "type" "msklog")
7720    (set_attr "prefix" "vex")])
7721
7722 ;; %%% This used to optimize known byte-wide and operations to memory,
7723 ;; and sometimes to QImode registers.  If this is considered useful,
7724 ;; it should be done with splitters.
7725
7726 (define_expand "and<mode>3"
7727   [(set (match_operand:SWIM 0 "nonimmediate_operand")
7728         (and:SWIM (match_operand:SWIM 1 "nonimmediate_operand")
7729                   (match_operand:SWIM 2 "<general_szext_operand>")))]
7730   ""
7731 {
7732   machine_mode mode = <MODE>mode;
7733   rtx (*insn) (rtx, rtx);
7734
7735   if (CONST_INT_P (operands[2]) && REG_P (operands[0]))
7736     {
7737       HOST_WIDE_INT ival = INTVAL (operands[2]);
7738
7739       if (ival == (HOST_WIDE_INT) 0xffffffff)
7740         mode = SImode;
7741       else if (ival == 0xffff)
7742         mode = HImode;
7743       else if (ival == 0xff)
7744         mode = QImode;
7745       }
7746
7747   if (mode == <MODE>mode)
7748     {
7749       ix86_expand_binary_operator (AND, <MODE>mode, operands);
7750       DONE;
7751     }
7752
7753   if (<MODE>mode == DImode)
7754     insn = (mode == SImode)
7755            ? gen_zero_extendsidi2
7756            : (mode == HImode)
7757            ? gen_zero_extendhidi2
7758            : gen_zero_extendqidi2;
7759   else if (<MODE>mode == SImode)
7760     insn = (mode == HImode)
7761            ? gen_zero_extendhisi2
7762            : gen_zero_extendqisi2;
7763   else if (<MODE>mode == HImode)
7764     insn = gen_zero_extendqihi2;
7765   else
7766     gcc_unreachable ();
7767
7768   emit_insn (insn (operands[0], gen_lowpart (mode, operands[1])));
7769   DONE;
7770 })
7771
7772 (define_insn "*anddi_1"
7773   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,rm,r,r,!k")
7774         (and:DI
7775          (match_operand:DI 1 "nonimmediate_operand" "%0,0,0,qm,k")
7776          (match_operand:DI 2 "x86_64_szext_general_operand" "Z,re,rm,L,k")))
7777    (clobber (reg:CC FLAGS_REG))]
7778   "TARGET_64BIT && ix86_binary_operator_ok (AND, DImode, operands)"
7779 {
7780   switch (get_attr_type (insn))
7781     {
7782     case TYPE_IMOVX:
7783       return "#";
7784
7785     case TYPE_MSKLOG:
7786       return "kandq\t{%2, %1, %0|%0, %1, %2}";
7787
7788     default:
7789       gcc_assert (rtx_equal_p (operands[0], operands[1]));
7790       if (get_attr_mode (insn) == MODE_SI)
7791         return "and{l}\t{%k2, %k0|%k0, %k2}";
7792       else
7793         return "and{q}\t{%2, %0|%0, %2}";
7794     }
7795 }
7796   [(set_attr "type" "alu,alu,alu,imovx,msklog")
7797    (set_attr "length_immediate" "*,*,*,0,0")
7798    (set (attr "prefix_rex")
7799      (if_then_else
7800        (and (eq_attr "type" "imovx")
7801             (and (match_test "INTVAL (operands[2]) == 0xff")
7802                  (match_operand 1 "ext_QIreg_operand")))
7803        (const_string "1")
7804        (const_string "*")))
7805    (set_attr "mode" "SI,DI,DI,SI,DI")])
7806
7807 (define_insn "*andsi_1"
7808   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,r,Ya,!k")
7809         (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,qm,k")
7810                 (match_operand:SI 2 "x86_64_general_operand" "re,rm,L,k")))
7811    (clobber (reg:CC FLAGS_REG))]
7812   "ix86_binary_operator_ok (AND, SImode, operands)"
7813 {
7814   switch (get_attr_type (insn))
7815     {
7816     case TYPE_IMOVX:
7817       return "#";
7818
7819     case TYPE_MSKLOG:
7820       return "kandd\t{%2, %1, %0|%0, %1, %2}";
7821
7822     default:
7823       gcc_assert (rtx_equal_p (operands[0], operands[1]));
7824       return "and{l}\t{%2, %0|%0, %2}";
7825     }
7826 }
7827   [(set_attr "type" "alu,alu,imovx,msklog")
7828    (set (attr "prefix_rex")
7829      (if_then_else
7830        (and (eq_attr "type" "imovx")
7831             (and (match_test "INTVAL (operands[2]) == 0xff")
7832                  (match_operand 1 "ext_QIreg_operand")))
7833        (const_string "1")
7834        (const_string "*")))
7835    (set_attr "length_immediate" "*,*,0,0")
7836    (set_attr "mode" "SI")])
7837
7838 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
7839 (define_insn "*andsi_1_zext"
7840   [(set (match_operand:DI 0 "register_operand" "=r")
7841         (zero_extend:DI
7842           (and:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
7843                   (match_operand:SI 2 "x86_64_general_operand" "rme"))))
7844    (clobber (reg:CC FLAGS_REG))]
7845   "TARGET_64BIT && ix86_binary_operator_ok (AND, SImode, operands)"
7846   "and{l}\t{%2, %k0|%k0, %2}"
7847   [(set_attr "type" "alu")
7848    (set_attr "mode" "SI")])
7849
7850 (define_insn "*andhi_1"
7851   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,r,Ya,!k")
7852         (and:HI (match_operand:HI 1 "nonimmediate_operand" "%0,0,qm,k")
7853                 (match_operand:HI 2 "general_operand" "rn,rm,L,k")))
7854    (clobber (reg:CC FLAGS_REG))]
7855   "ix86_binary_operator_ok (AND, HImode, operands)"
7856 {
7857   switch (get_attr_type (insn))
7858     {
7859     case TYPE_IMOVX:
7860       return "#";
7861
7862     case TYPE_MSKLOG:
7863       return "kandw\t{%2, %1, %0|%0, %1, %2}";
7864
7865     default:
7866       gcc_assert (rtx_equal_p (operands[0], operands[1]));
7867       return "and{w}\t{%2, %0|%0, %2}";
7868     }
7869 }
7870   [(set_attr "type" "alu,alu,imovx,msklog")
7871    (set_attr "length_immediate" "*,*,0,*")
7872    (set (attr "prefix_rex")
7873      (if_then_else
7874        (and (eq_attr "type" "imovx")
7875             (match_operand 1 "ext_QIreg_operand"))
7876        (const_string "1")
7877        (const_string "*")))
7878    (set_attr "mode" "HI,HI,SI,HI")])
7879
7880 ;; %%% Potential partial reg stall on alternative 2.  What to do?
7881 (define_insn "*andqi_1"
7882   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,q,r,!k")
7883         (and:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0,k")
7884                 (match_operand:QI 2 "general_operand" "qn,qmn,rn,k")))
7885    (clobber (reg:CC FLAGS_REG))]
7886   "ix86_binary_operator_ok (AND, QImode, operands)"
7887 {
7888   switch (which_alternative)
7889     {
7890     case 0:
7891     case 1:
7892       return "and{b}\t{%2, %0|%0, %2}";
7893     case 2:
7894       return "and{l}\t{%k2, %k0|%k0, %k2}";
7895     case 3:
7896       return TARGET_AVX512DQ ? "kandb\t{%2, %1, %0|%0, %1, %2}"
7897                              : "kandw\t{%2, %1, %0|%0, %1, %2}";
7898     default:
7899       gcc_unreachable ();
7900     }
7901 }
7902   [(set_attr "type" "alu,alu,alu,msklog")
7903    (set_attr "mode" "QI,QI,SI,HI")])
7904
7905 (define_insn "*andqi_1_slp"
7906   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm,q"))
7907         (and:QI (match_dup 0)
7908                 (match_operand:QI 1 "general_operand" "qn,qmn")))
7909    (clobber (reg:CC FLAGS_REG))]
7910   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
7911    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7912   "and{b}\t{%1, %0|%0, %1}"
7913   [(set_attr "type" "alu1")
7914    (set_attr "mode" "QI")])
7915
7916 (define_insn "kandn<mode>"
7917   [(set (match_operand:SWI12 0 "register_operand" "=r,&r,!k")
7918         (and:SWI12
7919           (not:SWI12
7920             (match_operand:SWI12 1 "register_operand" "r,0,k"))
7921           (match_operand:SWI12 2 "register_operand" "r,r,k")))
7922    (clobber (reg:CC FLAGS_REG))]
7923   "TARGET_AVX512F"
7924 {
7925   switch (which_alternative)
7926     {
7927     case 0:
7928       return "andn\t{%k2, %k1, %k0|%k0, %k1, %k2}";
7929     case 1:
7930       return "#";
7931     case 2:
7932       if (TARGET_AVX512DQ && <MODE>mode == QImode)
7933         return "kandnb\t{%2, %1, %0|%0, %1, %2}";
7934       else
7935         return "kandnw\t{%2, %1, %0|%0, %1, %2}";
7936     default:
7937       gcc_unreachable ();
7938     }
7939 }
7940   [(set_attr "isa" "bmi,*,avx512f")
7941    (set_attr "type" "bitmanip,*,msklog")
7942    (set_attr "prefix" "*,*,vex")
7943    (set_attr "btver2_decode" "direct,*,*")
7944    (set_attr "mode" "<MODE>")])
7945
7946 (define_split
7947   [(set (match_operand:SWI12 0 "general_reg_operand")
7948         (and:SWI12
7949           (not:SWI12
7950             (match_dup 0))
7951           (match_operand:SWI12 1 "general_reg_operand")))
7952    (clobber (reg:CC FLAGS_REG))]
7953   "TARGET_AVX512F && !TARGET_BMI && reload_completed"
7954   [(set (match_dup 0)
7955         (not:HI (match_dup 0)))
7956    (parallel [(set (match_dup 0)
7957                    (and:HI (match_dup 0)
7958                            (match_dup 1)))
7959               (clobber (reg:CC FLAGS_REG))])])
7960
7961 ;; Turn *anddi_1 into *andsi_1_zext if possible.
7962 (define_split
7963   [(set (match_operand:DI 0 "register_operand")
7964         (and:DI (subreg:DI (match_operand:SI 1 "register_operand") 0)
7965                 (match_operand:DI 2 "x86_64_zext_immediate_operand")))
7966    (clobber (reg:CC FLAGS_REG))]
7967   "TARGET_64BIT"
7968   [(parallel [(set (match_dup 0)
7969                    (zero_extend:DI (and:SI (match_dup 1) (match_dup 2))))
7970               (clobber (reg:CC FLAGS_REG))])]
7971   "operands[2] = gen_lowpart (SImode, operands[2]);")
7972
7973 (define_split
7974   [(set (match_operand:SWI248 0 "register_operand")
7975         (and:SWI248 (match_operand:SWI248 1 "nonimmediate_operand")
7976                     (match_operand:SWI248 2 "const_int_operand")))
7977    (clobber (reg:CC FLAGS_REG))]
7978   "reload_completed
7979    && true_regnum (operands[0]) != true_regnum (operands[1])"
7980   [(const_int 0)]
7981 {
7982   HOST_WIDE_INT ival = INTVAL (operands[2]);
7983   machine_mode mode;
7984   rtx (*insn) (rtx, rtx);
7985
7986   if (ival == (HOST_WIDE_INT) 0xffffffff)
7987     mode = SImode;
7988   else if (ival == 0xffff)
7989     mode = HImode;
7990   else
7991     {
7992       gcc_assert (ival == 0xff);
7993       mode = QImode;
7994     }
7995
7996   if (<MODE>mode == DImode)
7997     insn = (mode == SImode)
7998            ? gen_zero_extendsidi2
7999            : (mode == HImode)
8000            ? gen_zero_extendhidi2
8001            : gen_zero_extendqidi2;
8002   else
8003     {
8004       if (<MODE>mode != SImode)
8005         /* Zero extend to SImode to avoid partial register stalls.  */
8006         operands[0] = gen_lowpart (SImode, operands[0]);
8007
8008       insn = (mode == HImode)
8009              ? gen_zero_extendhisi2
8010              : gen_zero_extendqisi2;
8011     }
8012   emit_insn (insn (operands[0], gen_lowpart (mode, operands[1])));
8013   DONE;
8014 })
8015
8016 (define_split
8017   [(set (match_operand 0 "register_operand")
8018         (and (match_dup 0)
8019              (const_int -65536)))
8020    (clobber (reg:CC FLAGS_REG))]
8021   "(TARGET_FAST_PREFIX && !TARGET_PARTIAL_REG_STALL)
8022     || optimize_function_for_size_p (cfun)"
8023   [(set (strict_low_part (match_dup 1)) (const_int 0))]
8024   "operands[1] = gen_lowpart (HImode, operands[0]);")
8025
8026 (define_split
8027   [(set (match_operand 0 "ext_register_operand")
8028         (and (match_dup 0)
8029              (const_int -256)))
8030    (clobber (reg:CC FLAGS_REG))]
8031   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8032    && reload_completed"
8033   [(set (strict_low_part (match_dup 1)) (const_int 0))]
8034   "operands[1] = gen_lowpart (QImode, operands[0]);")
8035
8036 (define_split
8037   [(set (match_operand 0 "ext_register_operand")
8038         (and (match_dup 0)
8039              (const_int -65281)))
8040    (clobber (reg:CC FLAGS_REG))]
8041   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8042    && reload_completed"
8043   [(parallel [(set (zero_extract:SI (match_dup 0)
8044                                     (const_int 8)
8045                                     (const_int 8))
8046                    (xor:SI
8047                      (zero_extract:SI (match_dup 0)
8048                                       (const_int 8)
8049                                       (const_int 8))
8050                      (zero_extract:SI (match_dup 0)
8051                                       (const_int 8)
8052                                       (const_int 8))))
8053               (clobber (reg:CC FLAGS_REG))])]
8054   "operands[0] = gen_lowpart (SImode, operands[0]);")
8055
8056 (define_insn "*anddi_2"
8057   [(set (reg FLAGS_REG)
8058         (compare
8059          (and:DI
8060           (match_operand:DI 1 "nonimmediate_operand" "%0,0,0")
8061           (match_operand:DI 2 "x86_64_szext_general_operand" "Z,rem,re"))
8062          (const_int 0)))
8063    (set (match_operand:DI 0 "nonimmediate_operand" "=r,r,rm")
8064         (and:DI (match_dup 1) (match_dup 2)))]
8065   "TARGET_64BIT
8066    && ix86_match_ccmode
8067         (insn,
8068          /* If we are going to emit andl instead of andq, and the operands[2]
8069             constant might have the SImode sign bit set, make sure the sign
8070             flag isn't tested, because the instruction will set the sign flag
8071             based on bit 31 rather than bit 63.  If it isn't CONST_INT,
8072             conservatively assume it might have bit 31 set.  */
8073          (satisfies_constraint_Z (operands[2])
8074           && (!CONST_INT_P (operands[2])
8075               || val_signbit_known_set_p (SImode, INTVAL (operands[2]))))
8076          ? CCZmode : CCNOmode)
8077    && ix86_binary_operator_ok (AND, DImode, operands)"
8078   "@
8079    and{l}\t{%k2, %k0|%k0, %k2}
8080    and{q}\t{%2, %0|%0, %2}
8081    and{q}\t{%2, %0|%0, %2}"
8082   [(set_attr "type" "alu")
8083    (set_attr "mode" "SI,DI,DI")])
8084
8085 (define_insn "*andqi_2_maybe_si"
8086   [(set (reg FLAGS_REG)
8087         (compare (and:QI
8088                   (match_operand:QI 1 "nonimmediate_operand" "%0,0,0")
8089                   (match_operand:QI 2 "general_operand" "qmn,qn,n"))
8090                  (const_int 0)))
8091    (set (match_operand:QI 0 "nonimmediate_operand" "=q,qm,*r")
8092         (and:QI (match_dup 1) (match_dup 2)))]
8093   "ix86_binary_operator_ok (AND, QImode, operands)
8094    && ix86_match_ccmode (insn,
8095                          CONST_INT_P (operands[2])
8096                          && INTVAL (operands[2]) >= 0 ? CCNOmode : CCZmode)"
8097 {
8098   if (which_alternative == 2)
8099     {
8100       if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) < 0)
8101         operands[2] = GEN_INT (INTVAL (operands[2]) & 0xff);
8102       return "and{l}\t{%2, %k0|%k0, %2}";
8103     }
8104   return "and{b}\t{%2, %0|%0, %2}";
8105 }
8106   [(set_attr "type" "alu")
8107    (set_attr "mode" "QI,QI,SI")])
8108
8109 (define_insn "*and<mode>_2"
8110   [(set (reg FLAGS_REG)
8111         (compare (and:SWI124
8112                   (match_operand:SWI124 1 "nonimmediate_operand" "%0,0")
8113                   (match_operand:SWI124 2 "<general_operand>" "<g>,<r><i>"))
8114                  (const_int 0)))
8115    (set (match_operand:SWI124 0 "nonimmediate_operand" "=<r>,<r>m")
8116         (and:SWI124 (match_dup 1) (match_dup 2)))]
8117   "ix86_match_ccmode (insn, CCNOmode)
8118    && ix86_binary_operator_ok (AND, <MODE>mode, operands)"
8119   "and{<imodesuffix>}\t{%2, %0|%0, %2}"
8120   [(set_attr "type" "alu")
8121    (set_attr "mode" "<MODE>")])
8122
8123 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8124 (define_insn "*andsi_2_zext"
8125   [(set (reg FLAGS_REG)
8126         (compare (and:SI
8127                   (match_operand:SI 1 "nonimmediate_operand" "%0")
8128                   (match_operand:SI 2 "x86_64_general_operand" "rme"))
8129                  (const_int 0)))
8130    (set (match_operand:DI 0 "register_operand" "=r")
8131         (zero_extend:DI (and:SI (match_dup 1) (match_dup 2))))]
8132   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8133    && ix86_binary_operator_ok (AND, SImode, operands)"
8134   "and{l}\t{%2, %k0|%k0, %2}"
8135   [(set_attr "type" "alu")
8136    (set_attr "mode" "SI")])
8137
8138 (define_insn "*andqi_2_slp"
8139   [(set (reg FLAGS_REG)
8140         (compare (and:QI
8141                    (match_operand:QI 0 "nonimmediate_operand" "+q,qm")
8142                    (match_operand:QI 1 "nonimmediate_operand" "qmn,qn"))
8143                  (const_int 0)))
8144    (set (strict_low_part (match_dup 0))
8145         (and:QI (match_dup 0) (match_dup 1)))]
8146   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8147    && ix86_match_ccmode (insn, CCNOmode)
8148    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8149   "and{b}\t{%1, %0|%0, %1}"
8150   [(set_attr "type" "alu1")
8151    (set_attr "mode" "QI")])
8152
8153 ;; ??? A bug in recog prevents it from recognizing a const_int as an
8154 ;; operand to zero_extend in andqi_ext_1.  It was checking explicitly
8155 ;; for a QImode operand, which of course failed.
8156 (define_insn "andqi_ext_0"
8157   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8158                          (const_int 8)
8159                          (const_int 8))
8160         (and:SI
8161           (zero_extract:SI
8162             (match_operand 1 "ext_register_operand" "0")
8163             (const_int 8)
8164             (const_int 8))
8165           (match_operand 2 "const_int_operand" "n")))
8166    (clobber (reg:CC FLAGS_REG))]
8167   ""
8168   "and{b}\t{%2, %h0|%h0, %2}"
8169   [(set_attr "type" "alu")
8170    (set_attr "length_immediate" "1")
8171    (set_attr "modrm" "1")
8172    (set_attr "mode" "QI")])
8173
8174 ;; Generated by peephole translating test to and.  This shows up
8175 ;; often in fp comparisons.
8176 (define_insn "*andqi_ext_0_cc"
8177   [(set (reg FLAGS_REG)
8178         (compare
8179           (and:SI
8180             (zero_extract:SI
8181               (match_operand 1 "ext_register_operand" "0")
8182               (const_int 8)
8183               (const_int 8))
8184             (match_operand 2 "const_int_operand" "n"))
8185           (const_int 0)))
8186    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8187                          (const_int 8)
8188                          (const_int 8))
8189         (and:SI
8190           (zero_extract:SI
8191             (match_dup 1)
8192             (const_int 8)
8193             (const_int 8))
8194           (match_dup 2)))]
8195   "ix86_match_ccmode (insn, CCNOmode)"
8196   "and{b}\t{%2, %h0|%h0, %2}"
8197   [(set_attr "type" "alu")
8198    (set_attr "length_immediate" "1")
8199    (set_attr "modrm" "1")
8200    (set_attr "mode" "QI")])
8201
8202 (define_insn "*andqi_ext_1"
8203   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q,Q")
8204                          (const_int 8)
8205                          (const_int 8))
8206         (and:SI
8207           (zero_extract:SI
8208             (match_operand 1 "ext_register_operand" "0,0")
8209             (const_int 8)
8210             (const_int 8))
8211           (zero_extend:SI
8212             (match_operand:QI 2 "nonimmediate_x64nomem_operand" "Q,m"))))
8213    (clobber (reg:CC FLAGS_REG))]
8214   ""
8215   "and{b}\t{%2, %h0|%h0, %2}"
8216   [(set_attr "isa" "*,nox64")
8217    (set_attr "type" "alu")
8218    (set_attr "length_immediate" "0")
8219    (set_attr "mode" "QI")])
8220
8221 (define_insn "*andqi_ext_2"
8222   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8223                          (const_int 8)
8224                          (const_int 8))
8225         (and:SI
8226           (zero_extract:SI
8227             (match_operand 1 "ext_register_operand" "%0")
8228             (const_int 8)
8229             (const_int 8))
8230           (zero_extract:SI
8231             (match_operand 2 "ext_register_operand" "Q")
8232             (const_int 8)
8233             (const_int 8))))
8234    (clobber (reg:CC FLAGS_REG))]
8235   ""
8236   "and{b}\t{%h2, %h0|%h0, %h2}"
8237   [(set_attr "type" "alu")
8238    (set_attr "length_immediate" "0")
8239    (set_attr "mode" "QI")])
8240
8241 ;; Convert wide AND instructions with immediate operand to shorter QImode
8242 ;; equivalents when possible.
8243 ;; Don't do the splitting with memory operands, since it introduces risk
8244 ;; of memory mismatch stalls.  We may want to do the splitting for optimizing
8245 ;; for size, but that can (should?) be handled by generic code instead.
8246 (define_split
8247   [(set (match_operand 0 "register_operand")
8248         (and (match_operand 1 "register_operand")
8249              (match_operand 2 "const_int_operand")))
8250    (clobber (reg:CC FLAGS_REG))]
8251    "reload_completed
8252     && QI_REG_P (operands[0])
8253     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8254     && !(~INTVAL (operands[2]) & ~(255 << 8))
8255     && GET_MODE (operands[0]) != QImode"
8256   [(parallel [(set (zero_extract:SI (match_dup 0) (const_int 8) (const_int 8))
8257                    (and:SI (zero_extract:SI (match_dup 1)
8258                                             (const_int 8) (const_int 8))
8259                            (match_dup 2)))
8260               (clobber (reg:CC FLAGS_REG))])]
8261 {
8262   operands[0] = gen_lowpart (SImode, operands[0]);
8263   operands[1] = gen_lowpart (SImode, operands[1]);
8264   operands[2] = gen_int_mode ((INTVAL (operands[2]) >> 8) & 0xff, SImode);
8265 })
8266
8267 ;; Since AND can be encoded with sign extended immediate, this is only
8268 ;; profitable when 7th bit is not set.
8269 (define_split
8270   [(set (match_operand 0 "register_operand")
8271         (and (match_operand 1 "general_operand")
8272              (match_operand 2 "const_int_operand")))
8273    (clobber (reg:CC FLAGS_REG))]
8274    "reload_completed
8275     && ANY_QI_REG_P (operands[0])
8276     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8277     && !(~INTVAL (operands[2]) & ~255)
8278     && !(INTVAL (operands[2]) & 128)
8279     && GET_MODE (operands[0]) != QImode"
8280   [(parallel [(set (strict_low_part (match_dup 0))
8281                    (and:QI (match_dup 1)
8282                            (match_dup 2)))
8283               (clobber (reg:CC FLAGS_REG))])]
8284 {
8285   operands[0] = gen_lowpart (QImode, operands[0]);
8286   operands[1] = gen_lowpart (QImode, operands[1]);
8287   operands[2] = gen_lowpart (QImode, operands[2]);
8288 })
8289 \f
8290 ;; Logical inclusive and exclusive OR instructions
8291
8292 ;; %%% This used to optimize known byte-wide and operations to memory.
8293 ;; If this is considered useful, it should be done with splitters.
8294
8295 (define_expand "<code><mode>3"
8296   [(set (match_operand:SWIM 0 "nonimmediate_operand")
8297         (any_or:SWIM (match_operand:SWIM 1 "nonimmediate_operand")
8298                      (match_operand:SWIM 2 "<general_operand>")))]
8299   ""
8300   "ix86_expand_binary_operator (<CODE>, <MODE>mode, operands); DONE;")
8301
8302 (define_insn "*<code><mode>_1"
8303   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=r,rm,k")
8304         (any_or:SWI48
8305          (match_operand:SWI48 1 "nonimmediate_operand" "%0,0,k")
8306          (match_operand:SWI48 2 "<general_operand>" "<g>,r<i>,k")))
8307    (clobber (reg:CC FLAGS_REG))]
8308   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
8309   "@
8310    <logic>{<imodesuffix>}\t{%2, %0|%0, %2}
8311    <logic>{<imodesuffix>}\t{%2, %0|%0, %2}
8312    k<logic><mskmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
8313   [(set_attr "type" "alu,alu,msklog")
8314    (set_attr "mode" "<MODE>")])
8315
8316 (define_insn "*<code>hi_1"
8317   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,rm,!k")
8318         (any_or:HI
8319          (match_operand:HI 1 "nonimmediate_operand" "%0,0,k")
8320          (match_operand:HI 2 "general_operand" "<g>,r<i>,k")))
8321    (clobber (reg:CC FLAGS_REG))]
8322   "ix86_binary_operator_ok (<CODE>, HImode, operands)"
8323   "@
8324   <logic>{w}\t{%2, %0|%0, %2}
8325   <logic>{w}\t{%2, %0|%0, %2}
8326   k<logic>w\t{%2, %1, %0|%0, %1, %2}"
8327   [(set_attr "type" "alu,alu,msklog")
8328    (set_attr "mode" "HI")])
8329
8330 ;; %%% Potential partial reg stall on alternative 2.  What to do?
8331 (define_insn "*<code>qi_1"
8332   [(set (match_operand:QI 0 "nonimmediate_operand" "=q,m,r,!k")
8333         (any_or:QI (match_operand:QI 1 "nonimmediate_operand" "%0,0,0,k")
8334                    (match_operand:QI 2 "general_operand" "qmn,qn,rn,k")))
8335    (clobber (reg:CC FLAGS_REG))]
8336   "ix86_binary_operator_ok (<CODE>, QImode, operands)"
8337   "@
8338    <logic>{b}\t{%2, %0|%0, %2}
8339    <logic>{b}\t{%2, %0|%0, %2}
8340    <logic>{l}\t{%k2, %k0|%k0, %k2}
8341    k<logic>w\t{%2, %1, %0|%0, %1, %2}"
8342   [(set_attr "type" "alu,alu,alu,msklog")
8343    (set_attr "mode" "QI,QI,SI,HI")])
8344
8345 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8346 (define_insn "*<code>si_1_zext"
8347   [(set (match_operand:DI 0 "register_operand" "=r")
8348         (zero_extend:DI
8349          (any_or:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8350                     (match_operand:SI 2 "x86_64_general_operand" "rme"))))
8351    (clobber (reg:CC FLAGS_REG))]
8352   "TARGET_64BIT && ix86_binary_operator_ok (<CODE>, SImode, operands)"
8353   "<logic>{l}\t{%2, %k0|%k0, %2}"
8354   [(set_attr "type" "alu")
8355    (set_attr "mode" "SI")])
8356
8357 (define_insn "*<code>si_1_zext_imm"
8358   [(set (match_operand:DI 0 "register_operand" "=r")
8359         (any_or:DI
8360          (zero_extend:DI (match_operand:SI 1 "register_operand" "%0"))
8361          (match_operand:DI 2 "x86_64_zext_immediate_operand" "Z")))
8362    (clobber (reg:CC FLAGS_REG))]
8363   "TARGET_64BIT && ix86_binary_operator_ok (<CODE>, SImode, operands)"
8364   "<logic>{l}\t{%2, %k0|%k0, %2}"
8365   [(set_attr "type" "alu")
8366    (set_attr "mode" "SI")])
8367
8368 (define_insn "*<code>qi_1_slp"
8369   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+q,m"))
8370         (any_or:QI (match_dup 0)
8371                    (match_operand:QI 1 "general_operand" "qmn,qn")))
8372    (clobber (reg:CC FLAGS_REG))]
8373   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8374    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8375   "<logic>{b}\t{%1, %0|%0, %1}"
8376   [(set_attr "type" "alu1")
8377    (set_attr "mode" "QI")])
8378
8379 (define_insn "*<code><mode>_2"
8380   [(set (reg FLAGS_REG)
8381         (compare (any_or:SWI
8382                   (match_operand:SWI 1 "nonimmediate_operand" "%0,0")
8383                   (match_operand:SWI 2 "<general_operand>" "<g>,<r><i>"))
8384                  (const_int 0)))
8385    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>,<r>m")
8386         (any_or:SWI (match_dup 1) (match_dup 2)))]
8387   "ix86_match_ccmode (insn, CCNOmode)
8388    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
8389   "<logic>{<imodesuffix>}\t{%2, %0|%0, %2}"
8390   [(set_attr "type" "alu")
8391    (set_attr "mode" "<MODE>")])
8392
8393 (define_insn "kxnor<mode>"
8394   [(set (match_operand:SWI12 0 "register_operand" "=r,!k")
8395         (not:SWI12
8396           (xor:SWI12
8397             (match_operand:SWI12 1 "register_operand" "0,k")
8398             (match_operand:SWI12 2 "register_operand" "r,k"))))
8399    (clobber (reg:CC FLAGS_REG))]
8400   "TARGET_AVX512F"
8401 {
8402   if (which_alternative == 1 && <MODE>mode == QImode && TARGET_AVX512DQ)
8403     return "kxnorb\t{%2, %1, %0|%0, %1, %2}";
8404   return "kxnorw\t{%2, %1, %0|%0, %1, %2}";
8405 }
8406   [(set_attr "type" "*,msklog")
8407    (set_attr "prefix" "*,vex")
8408    (set_attr "mode" "<MODE>")])
8409
8410 (define_insn "kxnor<mode>"
8411   [(set (match_operand:SWI48x 0 "register_operand" "=r,!k")
8412         (not:SWI48x
8413           (xor:SWI48x
8414             (match_operand:SWI48x 1 "register_operand" "0,k")
8415             (match_operand:SWI48x 2 "register_operand" "r,k"))))
8416    (clobber (reg:CC FLAGS_REG))]
8417   "TARGET_AVX512BW"
8418   "@
8419    #
8420    kxnor<mskmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
8421   [(set_attr "type" "*,msklog")
8422    (set_attr "prefix" "*,vex")
8423    (set_attr "mode" "<MODE>")])
8424
8425 (define_split
8426   [(set (match_operand:SWI1248x 0 "general_reg_operand")
8427         (not:SWI1248x
8428           (xor:SWI1248x
8429             (match_dup 0)
8430             (match_operand:SWI1248x 1 "general_reg_operand"))))
8431    (clobber (reg:CC FLAGS_REG))]
8432   "TARGET_AVX512F && reload_completed"
8433    [(parallel [(set (match_dup 0)
8434                     (xor:HI (match_dup 0)
8435                             (match_dup 1)))
8436                (clobber (reg:CC FLAGS_REG))])
8437     (set (match_dup 0)
8438          (not:HI (match_dup 0)))])
8439
8440 ;;There are kortrest[bdq] but no intrinsics for them.
8441 ;;We probably don't need to implement them.
8442 (define_insn "kortestzhi"
8443   [(set (reg:CCZ FLAGS_REG)
8444         (compare:CCZ
8445           (ior:HI
8446             (match_operand:HI 0 "register_operand" "k")
8447             (match_operand:HI 1 "register_operand" "k"))
8448           (const_int 0)))]
8449   "TARGET_AVX512F && ix86_match_ccmode (insn, CCZmode)"
8450   "kortestw\t{%1, %0|%0, %1}"
8451   [(set_attr "mode" "HI")
8452    (set_attr "type" "msklog")
8453    (set_attr "prefix" "vex")])
8454
8455 (define_insn "kortestchi"
8456   [(set (reg:CCC FLAGS_REG)
8457         (compare:CCC
8458           (ior:HI
8459             (match_operand:HI 0 "register_operand" "k")
8460             (match_operand:HI 1 "register_operand" "k"))
8461           (const_int -1)))]
8462   "TARGET_AVX512F && ix86_match_ccmode (insn, CCCmode)"
8463   "kortestw\t{%1, %0|%0, %1}"
8464   [(set_attr "mode" "HI")
8465    (set_attr "type" "msklog")
8466    (set_attr "prefix" "vex")])
8467
8468 (define_insn "kunpckhi"
8469   [(set (match_operand:HI 0 "register_operand" "=k")
8470         (ior:HI
8471           (ashift:HI
8472             (match_operand:HI 1 "register_operand" "k")
8473             (const_int 8))
8474           (zero_extend:HI (match_operand:QI 2 "register_operand" "k"))))]
8475   "TARGET_AVX512F"
8476   "kunpckbw\t{%2, %1, %0|%0, %1, %2}"
8477   [(set_attr "mode" "HI")
8478    (set_attr "type" "msklog")
8479    (set_attr "prefix" "vex")])
8480
8481 (define_insn "kunpcksi"
8482   [(set (match_operand:SI 0 "register_operand" "=k")
8483         (ior:SI
8484           (ashift:SI
8485             (match_operand:SI 1 "register_operand" "k")
8486             (const_int 16))
8487           (zero_extend:SI (subreg:HI (match_operand:SI 2 "register_operand" "k") 0))))]
8488   "TARGET_AVX512BW"
8489   "kunpckwd\t{%2, %1, %0|%0, %1, %2}"
8490   [(set_attr "mode" "SI")])
8491
8492 (define_insn "kunpckdi"
8493   [(set (match_operand:DI 0 "register_operand" "=k")
8494         (ior:DI
8495           (ashift:DI
8496             (match_operand:DI 1 "register_operand" "k")
8497             (const_int 32))
8498           (zero_extend:DI (subreg:SI (match_operand:DI 2 "register_operand" "k") 0))))]
8499   "TARGET_AVX512BW"
8500   "kunpckdq\t{%2, %1, %0|%0, %1, %2}"
8501   [(set_attr "mode" "DI")])
8502
8503 ;; See comment for addsi_1_zext why we do use nonimmediate_operand
8504 ;; ??? Special case for immediate operand is missing - it is tricky.
8505 (define_insn "*<code>si_2_zext"
8506   [(set (reg FLAGS_REG)
8507         (compare (any_or:SI (match_operand:SI 1 "nonimmediate_operand" "%0")
8508                             (match_operand:SI 2 "x86_64_general_operand" "rme"))
8509                  (const_int 0)))
8510    (set (match_operand:DI 0 "register_operand" "=r")
8511         (zero_extend:DI (any_or:SI (match_dup 1) (match_dup 2))))]
8512   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8513    && ix86_binary_operator_ok (<CODE>, SImode, operands)"
8514   "<logic>{l}\t{%2, %k0|%k0, %2}"
8515   [(set_attr "type" "alu")
8516    (set_attr "mode" "SI")])
8517
8518 (define_insn "*<code>si_2_zext_imm"
8519   [(set (reg FLAGS_REG)
8520         (compare (any_or:SI
8521                   (match_operand:SI 1 "nonimmediate_operand" "%0")
8522                   (match_operand:SI 2 "x86_64_zext_immediate_operand" "Z"))
8523                  (const_int 0)))
8524    (set (match_operand:DI 0 "register_operand" "=r")
8525         (any_or:DI (zero_extend:DI (match_dup 1)) (match_dup 2)))]
8526   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
8527    && ix86_binary_operator_ok (<CODE>, SImode, operands)"
8528   "<logic>{l}\t{%2, %k0|%k0, %2}"
8529   [(set_attr "type" "alu")
8530    (set_attr "mode" "SI")])
8531
8532 (define_insn "*<code>qi_2_slp"
8533   [(set (reg FLAGS_REG)
8534         (compare (any_or:QI (match_operand:QI 0 "nonimmediate_operand" "+q,qm")
8535                             (match_operand:QI 1 "general_operand" "qmn,qn"))
8536                  (const_int 0)))
8537    (set (strict_low_part (match_dup 0))
8538         (any_or:QI (match_dup 0) (match_dup 1)))]
8539   "(!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8540    && ix86_match_ccmode (insn, CCNOmode)
8541    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8542   "<logic>{b}\t{%1, %0|%0, %1}"
8543   [(set_attr "type" "alu1")
8544    (set_attr "mode" "QI")])
8545
8546 (define_insn "*<code><mode>_3"
8547   [(set (reg FLAGS_REG)
8548         (compare (any_or:SWI
8549                   (match_operand:SWI 1 "nonimmediate_operand" "%0")
8550                   (match_operand:SWI 2 "<general_operand>" "<g>"))
8551                  (const_int 0)))
8552    (clobber (match_scratch:SWI 0 "=<r>"))]
8553   "ix86_match_ccmode (insn, CCNOmode)
8554    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
8555   "<logic>{<imodesuffix>}\t{%2, %0|%0, %2}"
8556   [(set_attr "type" "alu")
8557    (set_attr "mode" "<MODE>")])
8558
8559 (define_insn "*<code>qi_ext_0"
8560   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8561                          (const_int 8)
8562                          (const_int 8))
8563         (any_or:SI
8564           (zero_extract:SI
8565             (match_operand 1 "ext_register_operand" "0")
8566             (const_int 8)
8567             (const_int 8))
8568           (match_operand 2 "const_int_operand" "n")))
8569    (clobber (reg:CC FLAGS_REG))]
8570   "!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)"
8571   "<logic>{b}\t{%2, %h0|%h0, %2}"
8572   [(set_attr "type" "alu")
8573    (set_attr "length_immediate" "1")
8574    (set_attr "modrm" "1")
8575    (set_attr "mode" "QI")])
8576
8577 (define_insn "*<code>qi_ext_1"
8578   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q,Q")
8579                          (const_int 8)
8580                          (const_int 8))
8581         (any_or:SI
8582           (zero_extract:SI
8583             (match_operand 1 "ext_register_operand" "0,0")
8584             (const_int 8)
8585             (const_int 8))
8586           (zero_extend:SI
8587             (match_operand:QI 2 "nonimmediate_x64nomem_operand" "Q,m"))))
8588    (clobber (reg:CC FLAGS_REG))]
8589   "!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)"
8590   "<logic>{b}\t{%2, %h0|%h0, %2}"
8591   [(set_attr "isa" "*,nox64")
8592    (set_attr "type" "alu")
8593    (set_attr "length_immediate" "0")
8594    (set_attr "mode" "QI")])
8595
8596 (define_insn "*<code>qi_ext_2"
8597   [(set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q")
8598                          (const_int 8)
8599                          (const_int 8))
8600         (any_or:SI
8601           (zero_extract:SI (match_operand 1 "ext_register_operand" "0")
8602                            (const_int 8)
8603                            (const_int 8))
8604           (zero_extract:SI (match_operand 2 "ext_register_operand" "Q")
8605                            (const_int 8)
8606                            (const_int 8))))
8607    (clobber (reg:CC FLAGS_REG))]
8608   "!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun)"
8609   "<logic>{b}\t{%h2, %h0|%h0, %h2}"
8610   [(set_attr "type" "alu")
8611    (set_attr "length_immediate" "0")
8612    (set_attr "mode" "QI")])
8613
8614 (define_split
8615   [(set (match_operand 0 "register_operand")
8616         (any_or (match_operand 1 "register_operand")
8617                 (match_operand 2 "const_int_operand")))
8618    (clobber (reg:CC FLAGS_REG))]
8619    "reload_completed
8620     && QI_REG_P (operands[0])
8621     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8622     && !(INTVAL (operands[2]) & ~(255 << 8))
8623     && GET_MODE (operands[0]) != QImode"
8624   [(parallel [(set (zero_extract:SI (match_dup 0) (const_int 8) (const_int 8))
8625                    (any_or:SI (zero_extract:SI (match_dup 1)
8626                                                (const_int 8) (const_int 8))
8627                               (match_dup 2)))
8628               (clobber (reg:CC FLAGS_REG))])]
8629 {
8630   operands[0] = gen_lowpart (SImode, operands[0]);
8631   operands[1] = gen_lowpart (SImode, operands[1]);
8632   operands[2] = gen_int_mode ((INTVAL (operands[2]) >> 8) & 0xff, SImode);
8633 })
8634
8635 ;; Since OR can be encoded with sign extended immediate, this is only
8636 ;; profitable when 7th bit is set.
8637 (define_split
8638   [(set (match_operand 0 "register_operand")
8639         (any_or (match_operand 1 "general_operand")
8640                 (match_operand 2 "const_int_operand")))
8641    (clobber (reg:CC FLAGS_REG))]
8642    "reload_completed
8643     && ANY_QI_REG_P (operands[0])
8644     && (!TARGET_PARTIAL_REG_STALL || optimize_function_for_size_p (cfun))
8645     && !(INTVAL (operands[2]) & ~255)
8646     && (INTVAL (operands[2]) & 128)
8647     && GET_MODE (operands[0]) != QImode"
8648   [(parallel [(set (strict_low_part (match_dup 0))
8649                    (any_or:QI (match_dup 1)
8650                               (match_dup 2)))
8651               (clobber (reg:CC FLAGS_REG))])]
8652 {
8653   operands[0] = gen_lowpart (QImode, operands[0]);
8654   operands[1] = gen_lowpart (QImode, operands[1]);
8655   operands[2] = gen_lowpart (QImode, operands[2]);
8656 })
8657
8658 (define_expand "xorqi_cc_ext_1"
8659   [(parallel [
8660      (set (reg:CCNO FLAGS_REG)
8661           (compare:CCNO
8662             (xor:SI
8663               (zero_extract:SI
8664                 (match_operand 1 "ext_register_operand")
8665                 (const_int 8)
8666                 (const_int 8))
8667               (match_operand:QI 2 "const_int_operand"))
8668             (const_int 0)))
8669      (set (zero_extract:SI (match_operand 0 "ext_register_operand")
8670                            (const_int 8)
8671                            (const_int 8))
8672           (xor:SI
8673             (zero_extract:SI
8674              (match_dup 1)
8675              (const_int 8)
8676              (const_int 8))
8677             (match_dup 2)))])])
8678
8679 (define_insn "*xorqi_cc_ext_1"
8680   [(set (reg FLAGS_REG)
8681         (compare
8682           (xor:SI
8683             (zero_extract:SI
8684               (match_operand 1 "ext_register_operand" "0,0")
8685               (const_int 8)
8686               (const_int 8))
8687             (match_operand:QI 2 "general_x64nomem_operand" "Qn,m"))
8688           (const_int 0)))
8689    (set (zero_extract:SI (match_operand 0 "ext_register_operand" "=Q,Q")
8690                          (const_int 8)
8691                          (const_int 8))
8692         (xor:SI
8693           (zero_extract:SI
8694            (match_dup 1)
8695            (const_int 8)
8696            (const_int 8))
8697           (match_dup 2)))]
8698   "ix86_match_ccmode (insn, CCNOmode)"
8699   "xor{b}\t{%2, %h0|%h0, %2}"
8700   [(set_attr "isa" "*,nox64")
8701    (set_attr "type" "alu")
8702    (set_attr "modrm" "1")
8703    (set_attr "mode" "QI")])
8704 \f
8705 ;; Negation instructions
8706
8707 (define_expand "neg<mode>2"
8708   [(set (match_operand:SDWIM 0 "nonimmediate_operand")
8709         (neg:SDWIM (match_operand:SDWIM 1 "nonimmediate_operand")))]
8710   ""
8711   "ix86_expand_unary_operator (NEG, <MODE>mode, operands); DONE;")
8712
8713 (define_insn_and_split "*neg<dwi>2_doubleword"
8714   [(set (match_operand:<DWI> 0 "nonimmediate_operand" "=ro")
8715         (neg:<DWI> (match_operand:<DWI> 1 "nonimmediate_operand" "0")))
8716    (clobber (reg:CC FLAGS_REG))]
8717   "ix86_unary_operator_ok (NEG, <DWI>mode, operands)"
8718   "#"
8719   "reload_completed"
8720   [(parallel
8721     [(set (reg:CCZ FLAGS_REG)
8722           (compare:CCZ (neg:DWIH (match_dup 1)) (const_int 0)))
8723      (set (match_dup 0) (neg:DWIH (match_dup 1)))])
8724    (parallel
8725     [(set (match_dup 2)
8726           (plus:DWIH (match_dup 3)
8727                      (plus:DWIH (ltu:DWIH (reg:CC FLAGS_REG) (const_int 0))
8728                                 (const_int 0))))
8729      (clobber (reg:CC FLAGS_REG))])
8730    (parallel
8731     [(set (match_dup 2)
8732           (neg:DWIH (match_dup 2)))
8733      (clobber (reg:CC FLAGS_REG))])]
8734   "split_double_mode (<DWI>mode, &operands[0], 2, &operands[0], &operands[2]);")
8735
8736 (define_insn "*neg<mode>2_1"
8737   [(set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
8738         (neg:SWI (match_operand:SWI 1 "nonimmediate_operand" "0")))
8739    (clobber (reg:CC FLAGS_REG))]
8740   "ix86_unary_operator_ok (NEG, <MODE>mode, operands)"
8741   "neg{<imodesuffix>}\t%0"
8742   [(set_attr "type" "negnot")
8743    (set_attr "mode" "<MODE>")])
8744
8745 ;; Combine is quite creative about this pattern.
8746 (define_insn "*negsi2_1_zext"
8747   [(set (match_operand:DI 0 "register_operand" "=r")
8748         (lshiftrt:DI
8749           (neg:DI (ashift:DI (match_operand:DI 1 "register_operand" "0")
8750                              (const_int 32)))
8751         (const_int 32)))
8752    (clobber (reg:CC FLAGS_REG))]
8753   "TARGET_64BIT && ix86_unary_operator_ok (NEG, SImode, operands)"
8754   "neg{l}\t%k0"
8755   [(set_attr "type" "negnot")
8756    (set_attr "mode" "SI")])
8757
8758 ;; The problem with neg is that it does not perform (compare x 0),
8759 ;; it really performs (compare 0 x), which leaves us with the zero
8760 ;; flag being the only useful item.
8761
8762 (define_insn "*neg<mode>2_cmpz"
8763   [(set (reg:CCZ FLAGS_REG)
8764         (compare:CCZ
8765           (neg:SWI (match_operand:SWI 1 "nonimmediate_operand" "0"))
8766                    (const_int 0)))
8767    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
8768         (neg:SWI (match_dup 1)))]
8769   "ix86_unary_operator_ok (NEG, <MODE>mode, operands)"
8770   "neg{<imodesuffix>}\t%0"
8771   [(set_attr "type" "negnot")
8772    (set_attr "mode" "<MODE>")])
8773
8774 (define_insn "*negsi2_cmpz_zext"
8775   [(set (reg:CCZ FLAGS_REG)
8776         (compare:CCZ
8777           (lshiftrt:DI
8778             (neg:DI (ashift:DI
8779                       (match_operand:DI 1 "register_operand" "0")
8780                       (const_int 32)))
8781             (const_int 32))
8782           (const_int 0)))
8783    (set (match_operand:DI 0 "register_operand" "=r")
8784         (lshiftrt:DI (neg:DI (ashift:DI (match_dup 1)
8785                                         (const_int 32)))
8786                      (const_int 32)))]
8787   "TARGET_64BIT && ix86_unary_operator_ok (NEG, SImode, operands)"
8788   "neg{l}\t%k0"
8789   [(set_attr "type" "negnot")
8790    (set_attr "mode" "SI")])
8791
8792 ;; Negate with jump on overflow.
8793 (define_expand "negv<mode>3"
8794   [(parallel [(set (reg:CCO FLAGS_REG)
8795                    (ne:CCO (match_operand:SWI 1 "register_operand")
8796                            (match_dup 3)))
8797               (set (match_operand:SWI 0 "register_operand")
8798                    (neg:SWI (match_dup 1)))])
8799    (set (pc) (if_then_else
8800                (eq (reg:CCO FLAGS_REG) (const_int 0))
8801                (label_ref (match_operand 2))
8802                (pc)))]
8803   ""
8804 {
8805   operands[3]
8806     = gen_int_mode (HOST_WIDE_INT_1U << (GET_MODE_BITSIZE (<MODE>mode) - 1),
8807                     <MODE>mode);
8808 })
8809
8810 (define_insn "*negv<mode>3"
8811   [(set (reg:CCO FLAGS_REG)
8812         (ne:CCO (match_operand:SWI 1 "nonimmediate_operand" "0")
8813                 (match_operand:SWI 2 "const_int_operand")))
8814    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
8815         (neg:SWI (match_dup 1)))]
8816   "ix86_unary_operator_ok (NEG, <MODE>mode, operands)
8817    && mode_signbit_p (<MODE>mode, operands[2])"
8818   "neg{<imodesuffix>}\t%0"
8819   [(set_attr "type" "negnot")
8820    (set_attr "mode" "<MODE>")])
8821
8822 ;; Changing of sign for FP values is doable using integer unit too.
8823
8824 (define_expand "<code><mode>2"
8825   [(set (match_operand:X87MODEF 0 "register_operand")
8826         (absneg:X87MODEF (match_operand:X87MODEF 1 "register_operand")))]
8827   "TARGET_80387 || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
8828   "ix86_expand_fp_absneg_operator (<CODE>, <MODE>mode, operands); DONE;")
8829
8830 (define_insn "*absneg<mode>2_mixed"
8831   [(set (match_operand:MODEF 0 "register_operand" "=x,x,f,!r")
8832         (match_operator:MODEF 3 "absneg_operator"
8833           [(match_operand:MODEF 1 "register_operand" "0,x,0,0")]))
8834    (use (match_operand:<ssevecmode> 2 "nonimmediate_operand" "xm,0,X,X"))
8835    (clobber (reg:CC FLAGS_REG))]
8836   "TARGET_MIX_SSE_I387 && SSE_FLOAT_MODE_P (<MODE>mode)"
8837   "#")
8838
8839 (define_insn "*absneg<mode>2_sse"
8840   [(set (match_operand:MODEF 0 "register_operand" "=x,x,!r")
8841         (match_operator:MODEF 3 "absneg_operator"
8842           [(match_operand:MODEF 1 "register_operand" "0 ,x,0")]))
8843    (use (match_operand:<ssevecmode> 2 "register_operand" "xm,0,X"))
8844    (clobber (reg:CC FLAGS_REG))]
8845   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
8846   "#")
8847
8848 (define_insn "*absneg<mode>2_i387"
8849   [(set (match_operand:X87MODEF 0 "register_operand" "=f,!r")
8850         (match_operator:X87MODEF 3 "absneg_operator"
8851           [(match_operand:X87MODEF 1 "register_operand" "0,0")]))
8852    (use (match_operand 2))
8853    (clobber (reg:CC FLAGS_REG))]
8854   "TARGET_80387 && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
8855   "#")
8856
8857 (define_expand "<code>tf2"
8858   [(set (match_operand:TF 0 "register_operand")
8859         (absneg:TF (match_operand:TF 1 "register_operand")))]
8860   "TARGET_SSE"
8861   "ix86_expand_fp_absneg_operator (<CODE>, TFmode, operands); DONE;")
8862
8863 (define_insn "*absnegtf2_sse"
8864   [(set (match_operand:TF 0 "register_operand" "=x,x")
8865         (match_operator:TF 3 "absneg_operator"
8866           [(match_operand:TF 1 "register_operand" "0,x")]))
8867    (use (match_operand:TF 2 "nonimmediate_operand" "xm,0"))
8868    (clobber (reg:CC FLAGS_REG))]
8869   "TARGET_SSE"
8870   "#")
8871
8872 ;; Splitters for fp abs and neg.
8873
8874 (define_split
8875   [(set (match_operand 0 "fp_register_operand")
8876         (match_operator 1 "absneg_operator" [(match_dup 0)]))
8877    (use (match_operand 2))
8878    (clobber (reg:CC FLAGS_REG))]
8879   "reload_completed"
8880   [(set (match_dup 0) (match_op_dup 1 [(match_dup 0)]))])
8881
8882 (define_split
8883   [(set (match_operand 0 "register_operand")
8884         (match_operator 3 "absneg_operator"
8885           [(match_operand 1 "register_operand")]))
8886    (use (match_operand 2 "nonimmediate_operand"))
8887    (clobber (reg:CC FLAGS_REG))]
8888   "reload_completed && SSE_REG_P (operands[0])"
8889   [(set (match_dup 0) (match_dup 3))]
8890 {
8891   machine_mode mode = GET_MODE (operands[0]);
8892   machine_mode vmode = GET_MODE (operands[2]);
8893   rtx tmp;
8894
8895   operands[0] = simplify_gen_subreg (vmode, operands[0], mode, 0);
8896   operands[1] = simplify_gen_subreg (vmode, operands[1], mode, 0);
8897   if (operands_match_p (operands[0], operands[2]))
8898     std::swap (operands[1], operands[2]);
8899   if (GET_CODE (operands[3]) == ABS)
8900     tmp = gen_rtx_AND (vmode, operands[1], operands[2]);
8901   else
8902     tmp = gen_rtx_XOR (vmode, operands[1], operands[2]);
8903   operands[3] = tmp;
8904 })
8905
8906 (define_split
8907   [(set (match_operand:SF 0 "register_operand")
8908         (match_operator:SF 1 "absneg_operator" [(match_dup 0)]))
8909    (use (match_operand:V4SF 2))
8910    (clobber (reg:CC FLAGS_REG))]
8911   "reload_completed"
8912   [(parallel [(set (match_dup 0) (match_dup 1))
8913               (clobber (reg:CC FLAGS_REG))])]
8914 {
8915   rtx tmp;
8916   operands[0] = gen_lowpart (SImode, operands[0]);
8917   if (GET_CODE (operands[1]) == ABS)
8918     {
8919       tmp = gen_int_mode (0x7fffffff, SImode);
8920       tmp = gen_rtx_AND (SImode, operands[0], tmp);
8921     }
8922   else
8923     {
8924       tmp = gen_int_mode (0x80000000, SImode);
8925       tmp = gen_rtx_XOR (SImode, operands[0], tmp);
8926     }
8927   operands[1] = tmp;
8928 })
8929
8930 (define_split
8931   [(set (match_operand:DF 0 "register_operand")
8932         (match_operator:DF 1 "absneg_operator" [(match_dup 0)]))
8933    (use (match_operand 2))
8934    (clobber (reg:CC FLAGS_REG))]
8935   "reload_completed"
8936   [(parallel [(set (match_dup 0) (match_dup 1))
8937               (clobber (reg:CC FLAGS_REG))])]
8938 {
8939   rtx tmp;
8940   if (TARGET_64BIT)
8941     {
8942       tmp = gen_lowpart (DImode, operands[0]);
8943       tmp = gen_rtx_ZERO_EXTRACT (DImode, tmp, const1_rtx, GEN_INT (63));
8944       operands[0] = tmp;
8945
8946       if (GET_CODE (operands[1]) == ABS)
8947         tmp = const0_rtx;
8948       else
8949         tmp = gen_rtx_NOT (DImode, tmp);
8950     }
8951   else
8952     {
8953       operands[0] = gen_highpart (SImode, operands[0]);
8954       if (GET_CODE (operands[1]) == ABS)
8955         {
8956           tmp = gen_int_mode (0x7fffffff, SImode);
8957           tmp = gen_rtx_AND (SImode, operands[0], tmp);
8958         }
8959       else
8960         {
8961           tmp = gen_int_mode (0x80000000, SImode);
8962           tmp = gen_rtx_XOR (SImode, operands[0], tmp);
8963         }
8964     }
8965   operands[1] = tmp;
8966 })
8967
8968 (define_split
8969   [(set (match_operand:XF 0 "register_operand")
8970         (match_operator:XF 1 "absneg_operator" [(match_dup 0)]))
8971    (use (match_operand 2))
8972    (clobber (reg:CC FLAGS_REG))]
8973   "reload_completed"
8974   [(parallel [(set (match_dup 0) (match_dup 1))
8975               (clobber (reg:CC FLAGS_REG))])]
8976 {
8977   rtx tmp;
8978   operands[0] = gen_rtx_REG (SImode,
8979                              true_regnum (operands[0])
8980                              + (TARGET_64BIT ? 1 : 2));
8981   if (GET_CODE (operands[1]) == ABS)
8982     {
8983       tmp = GEN_INT (0x7fff);
8984       tmp = gen_rtx_AND (SImode, operands[0], tmp);
8985     }
8986   else
8987     {
8988       tmp = GEN_INT (0x8000);
8989       tmp = gen_rtx_XOR (SImode, operands[0], tmp);
8990     }
8991   operands[1] = tmp;
8992 })
8993
8994 ;; Conditionalize these after reload. If they match before reload, we
8995 ;; lose the clobber and ability to use integer instructions.
8996
8997 (define_insn "*<code><mode>2_1"
8998   [(set (match_operand:X87MODEF 0 "register_operand" "=f")
8999         (absneg:X87MODEF (match_operand:X87MODEF 1 "register_operand" "0")))]
9000   "TARGET_80387
9001    && (reload_completed
9002        || !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))"
9003   "f<absneg_mnemonic>"
9004   [(set_attr "type" "fsgn")
9005    (set_attr "mode" "<MODE>")])
9006
9007 (define_insn "*<code>extendsfdf2"
9008   [(set (match_operand:DF 0 "register_operand" "=f")
9009         (absneg:DF (float_extend:DF
9010                      (match_operand:SF 1 "register_operand" "0"))))]
9011   "TARGET_80387 && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387)"
9012   "f<absneg_mnemonic>"
9013   [(set_attr "type" "fsgn")
9014    (set_attr "mode" "DF")])
9015
9016 (define_insn "*<code>extendsfxf2"
9017   [(set (match_operand:XF 0 "register_operand" "=f")
9018         (absneg:XF (float_extend:XF
9019                      (match_operand:SF 1 "register_operand" "0"))))]
9020   "TARGET_80387"
9021   "f<absneg_mnemonic>"
9022   [(set_attr "type" "fsgn")
9023    (set_attr "mode" "XF")])
9024
9025 (define_insn "*<code>extenddfxf2"
9026   [(set (match_operand:XF 0 "register_operand" "=f")
9027         (absneg:XF (float_extend:XF
9028                      (match_operand:DF 1 "register_operand" "0"))))]
9029   "TARGET_80387"
9030   "f<absneg_mnemonic>"
9031   [(set_attr "type" "fsgn")
9032    (set_attr "mode" "XF")])
9033
9034 ;; Copysign instructions
9035
9036 (define_mode_iterator CSGNMODE [SF DF TF])
9037 (define_mode_attr CSGNVMODE [(SF "V4SF") (DF "V2DF") (TF "TF")])
9038
9039 (define_expand "copysign<mode>3"
9040   [(match_operand:CSGNMODE 0 "register_operand")
9041    (match_operand:CSGNMODE 1 "nonmemory_operand")
9042    (match_operand:CSGNMODE 2 "register_operand")]
9043   "(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
9044    || (TARGET_SSE && (<MODE>mode == TFmode))"
9045   "ix86_expand_copysign (operands); DONE;")
9046
9047 (define_insn_and_split "copysign<mode>3_const"
9048   [(set (match_operand:CSGNMODE 0 "register_operand" "=x")
9049         (unspec:CSGNMODE
9050           [(match_operand:<CSGNVMODE> 1 "vector_move_operand" "xmC")
9051            (match_operand:CSGNMODE 2 "register_operand" "0")
9052            (match_operand:<CSGNVMODE> 3 "nonimmediate_operand" "xm")]
9053           UNSPEC_COPYSIGN))]
9054   "(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
9055    || (TARGET_SSE && (<MODE>mode == TFmode))"
9056   "#"
9057   "&& reload_completed"
9058   [(const_int 0)]
9059   "ix86_split_copysign_const (operands); DONE;")
9060
9061 (define_insn "copysign<mode>3_var"
9062   [(set (match_operand:CSGNMODE 0 "register_operand" "=x,x,x,x,x")
9063         (unspec:CSGNMODE
9064           [(match_operand:CSGNMODE 2 "register_operand" "x,0,0,x,x")
9065            (match_operand:CSGNMODE 3 "register_operand" "1,1,x,1,x")
9066            (match_operand:<CSGNVMODE> 4 "nonimmediate_operand" "X,xm,xm,0,0")
9067            (match_operand:<CSGNVMODE> 5 "nonimmediate_operand" "0,xm,1,xm,1")]
9068           UNSPEC_COPYSIGN))
9069    (clobber (match_scratch:<CSGNVMODE> 1 "=x,x,x,x,x"))]
9070   "(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
9071    || (TARGET_SSE && (<MODE>mode == TFmode))"
9072   "#")
9073
9074 (define_split
9075   [(set (match_operand:CSGNMODE 0 "register_operand")
9076         (unspec:CSGNMODE
9077           [(match_operand:CSGNMODE 2 "register_operand")
9078            (match_operand:CSGNMODE 3 "register_operand")
9079            (match_operand:<CSGNVMODE> 4)
9080            (match_operand:<CSGNVMODE> 5)]
9081           UNSPEC_COPYSIGN))
9082    (clobber (match_scratch:<CSGNVMODE> 1))]
9083   "((SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
9084     || (TARGET_SSE && (<MODE>mode == TFmode)))
9085    && reload_completed"
9086   [(const_int 0)]
9087   "ix86_split_copysign_var (operands); DONE;")
9088 \f
9089 ;; One complement instructions
9090
9091 (define_expand "one_cmpl<mode>2"
9092   [(set (match_operand:SWIM 0 "nonimmediate_operand")
9093         (not:SWIM (match_operand:SWIM 1 "nonimmediate_operand")))]
9094   ""
9095   "ix86_expand_unary_operator (NOT, <MODE>mode, operands); DONE;")
9096
9097 (define_insn "*one_cmpl<mode>2_1"
9098   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,k")
9099         (not:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "0,k")))]
9100   "ix86_unary_operator_ok (NOT, <MODE>mode, operands)"
9101   "@
9102    not{<imodesuffix>}\t%0
9103    knot<mskmodesuffix>\t{%1, %0|%0, %1}"
9104   [(set_attr "isa" "*,avx512bw")
9105    (set_attr "type" "negnot,msklog")
9106    (set_attr "prefix" "*,vex")
9107    (set_attr "mode" "<MODE>")])
9108
9109 (define_insn "*one_cmplhi2_1"
9110   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,!k")
9111         (not:HI (match_operand:HI 1 "nonimmediate_operand" "0,k")))]
9112   "ix86_unary_operator_ok (NOT, HImode, operands)"
9113   "@
9114    not{w}\t%0
9115    knotw\t{%1, %0|%0, %1}"
9116   [(set_attr "isa" "*,avx512f")
9117    (set_attr "type" "negnot,msklog")
9118    (set_attr "prefix" "*,vex")
9119    (set_attr "mode" "HI")])
9120
9121 ;; %%% Potential partial reg stall on alternative 1.  What to do?
9122 (define_insn "*one_cmplqi2_1"
9123   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r,!k")
9124         (not:QI (match_operand:QI 1 "nonimmediate_operand" "0,0,k")))]
9125   "ix86_unary_operator_ok (NOT, QImode, operands)"
9126 {
9127   switch (which_alternative)
9128     {
9129     case 0:
9130       return "not{b}\t%0";
9131     case 1:
9132       return "not{l}\t%k0";
9133     case 2:
9134       if (TARGET_AVX512DQ)
9135         return "knotb\t{%1, %0|%0, %1}";
9136       return "knotw\t{%1, %0|%0, %1}";
9137     default:
9138       gcc_unreachable ();
9139     }
9140 }
9141   [(set_attr "isa" "*,*,avx512f")
9142    (set_attr "type" "negnot,negnot,msklog")
9143    (set_attr "prefix" "*,*,vex")
9144    (set_attr "mode" "QI,SI,QI")])
9145
9146 ;; ??? Currently never generated - xor is used instead.
9147 (define_insn "*one_cmplsi2_1_zext"
9148   [(set (match_operand:DI 0 "register_operand" "=r")
9149         (zero_extend:DI
9150           (not:SI (match_operand:SI 1 "register_operand" "0"))))]
9151   "TARGET_64BIT && ix86_unary_operator_ok (NOT, SImode, operands)"
9152   "not{l}\t%k0"
9153   [(set_attr "type" "negnot")
9154    (set_attr "mode" "SI")])
9155
9156 (define_insn "*one_cmpl<mode>2_2"
9157   [(set (reg FLAGS_REG)
9158         (compare (not:SWI (match_operand:SWI 1 "nonimmediate_operand" "0"))
9159                  (const_int 0)))
9160    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
9161         (not:SWI (match_dup 1)))]
9162   "ix86_match_ccmode (insn, CCNOmode)
9163    && ix86_unary_operator_ok (NOT, <MODE>mode, operands)"
9164   "#"
9165   [(set_attr "type" "alu1")
9166    (set_attr "mode" "<MODE>")])
9167
9168 (define_split
9169   [(set (match_operand 0 "flags_reg_operand")
9170         (match_operator 2 "compare_operator"
9171           [(not:SWI (match_operand:SWI 3 "nonimmediate_operand"))
9172            (const_int 0)]))
9173    (set (match_operand:SWI 1 "nonimmediate_operand")
9174         (not:SWI (match_dup 3)))]
9175   "ix86_match_ccmode (insn, CCNOmode)"
9176   [(parallel [(set (match_dup 0)
9177                    (match_op_dup 2 [(xor:SWI (match_dup 3) (const_int -1))
9178                                     (const_int 0)]))
9179               (set (match_dup 1)
9180                    (xor:SWI (match_dup 3) (const_int -1)))])])
9181
9182 ;; ??? Currently never generated - xor is used instead.
9183 (define_insn "*one_cmplsi2_2_zext"
9184   [(set (reg FLAGS_REG)
9185         (compare (not:SI (match_operand:SI 1 "register_operand" "0"))
9186                  (const_int 0)))
9187    (set (match_operand:DI 0 "register_operand" "=r")
9188         (zero_extend:DI (not:SI (match_dup 1))))]
9189   "TARGET_64BIT && ix86_match_ccmode (insn, CCNOmode)
9190    && ix86_unary_operator_ok (NOT, SImode, operands)"
9191   "#"
9192   [(set_attr "type" "alu1")
9193    (set_attr "mode" "SI")])
9194
9195 (define_split
9196   [(set (match_operand 0 "flags_reg_operand")
9197         (match_operator 2 "compare_operator"
9198           [(not:SI (match_operand:SI 3 "register_operand"))
9199            (const_int 0)]))
9200    (set (match_operand:DI 1 "register_operand")
9201         (zero_extend:DI (not:SI (match_dup 3))))]
9202   "ix86_match_ccmode (insn, CCNOmode)"
9203   [(parallel [(set (match_dup 0)
9204                    (match_op_dup 2 [(xor:SI (match_dup 3) (const_int -1))
9205                                     (const_int 0)]))
9206               (set (match_dup 1)
9207                    (zero_extend:DI (xor:SI (match_dup 3) (const_int -1))))])])
9208 \f
9209 ;; Shift instructions
9210
9211 ;; DImode shifts are implemented using the i386 "shift double" opcode,
9212 ;; which is written as "sh[lr]d[lw] imm,reg,reg/mem".  If the shift count
9213 ;; is variable, then the count is in %cl and the "imm" operand is dropped
9214 ;; from the assembler input.
9215 ;;
9216 ;; This instruction shifts the target reg/mem as usual, but instead of
9217 ;; shifting in zeros, bits are shifted in from reg operand.  If the insn
9218 ;; is a left shift double, bits are taken from the high order bits of
9219 ;; reg, else if the insn is a shift right double, bits are taken from the
9220 ;; low order bits of reg.  So if %eax is "1234" and %edx is "5678",
9221 ;; "shldl $8,%edx,%eax" leaves %edx unchanged and sets %eax to "2345".
9222 ;;
9223 ;; Since sh[lr]d does not change the `reg' operand, that is done
9224 ;; separately, making all shifts emit pairs of shift double and normal
9225 ;; shift.  Since sh[lr]d does not shift more than 31 bits, and we wish to
9226 ;; support a 63 bit shift, each shift where the count is in a reg expands
9227 ;; to a pair of shifts, a branch, a shift by 32 and a label.
9228 ;;
9229 ;; If the shift count is a constant, we need never emit more than one
9230 ;; shift pair, instead using moves and sign extension for counts greater
9231 ;; than 31.
9232
9233 (define_expand "ashl<mode>3"
9234   [(set (match_operand:SDWIM 0 "<shift_operand>")
9235         (ashift:SDWIM (match_operand:SDWIM 1 "<ashl_input_operand>")
9236                       (match_operand:QI 2 "nonmemory_operand")))]
9237   ""
9238   "ix86_expand_binary_operator (ASHIFT, <MODE>mode, operands); DONE;")
9239
9240 (define_insn "*ashl<mode>3_doubleword"
9241   [(set (match_operand:DWI 0 "register_operand" "=&r,r")
9242         (ashift:DWI (match_operand:DWI 1 "reg_or_pm1_operand" "n,0")
9243                     (match_operand:QI 2 "nonmemory_operand" "<S>c,<S>c")))
9244    (clobber (reg:CC FLAGS_REG))]
9245   ""
9246   "#"
9247   [(set_attr "type" "multi")])
9248
9249 (define_split
9250   [(set (match_operand:DWI 0 "register_operand")
9251         (ashift:DWI (match_operand:DWI 1 "nonmemory_operand")
9252                     (match_operand:QI 2 "nonmemory_operand")))
9253    (clobber (reg:CC FLAGS_REG))]
9254   "(optimize && flag_peephole2) ? epilogue_completed : reload_completed"
9255   [(const_int 0)]
9256   "ix86_split_ashl (operands, NULL_RTX, <MODE>mode); DONE;")
9257
9258 ;; By default we don't ask for a scratch register, because when DWImode
9259 ;; values are manipulated, registers are already at a premium.  But if
9260 ;; we have one handy, we won't turn it away.
9261
9262 (define_peephole2
9263   [(match_scratch:DWIH 3 "r")
9264    (parallel [(set (match_operand:<DWI> 0 "register_operand")
9265                    (ashift:<DWI>
9266                      (match_operand:<DWI> 1 "nonmemory_operand")
9267                      (match_operand:QI 2 "nonmemory_operand")))
9268               (clobber (reg:CC FLAGS_REG))])
9269    (match_dup 3)]
9270   "TARGET_CMOVE"
9271   [(const_int 0)]
9272   "ix86_split_ashl (operands, operands[3], <DWI>mode); DONE;")
9273
9274 (define_insn "x86_64_shld"
9275   [(set (match_operand:DI 0 "nonimmediate_operand" "+r*m")
9276         (ior:DI (ashift:DI (match_dup 0)
9277                   (match_operand:QI 2 "nonmemory_operand" "Jc"))
9278                 (lshiftrt:DI (match_operand:DI 1 "register_operand" "r")
9279                   (minus:QI (const_int 64) (match_dup 2)))))
9280    (clobber (reg:CC FLAGS_REG))]
9281   "TARGET_64BIT"
9282   "shld{q}\t{%s2%1, %0|%0, %1, %2}"
9283   [(set_attr "type" "ishift")
9284    (set_attr "prefix_0f" "1")
9285    (set_attr "mode" "DI")
9286    (set_attr "athlon_decode" "vector")
9287    (set_attr "amdfam10_decode" "vector")
9288    (set_attr "bdver1_decode" "vector")])
9289
9290 (define_insn "x86_shld"
9291   [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m")
9292         (ior:SI (ashift:SI (match_dup 0)
9293                   (match_operand:QI 2 "nonmemory_operand" "Ic"))
9294                 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
9295                   (minus:QI (const_int 32) (match_dup 2)))))
9296    (clobber (reg:CC FLAGS_REG))]
9297   ""
9298   "shld{l}\t{%s2%1, %0|%0, %1, %2}"
9299   [(set_attr "type" "ishift")
9300    (set_attr "prefix_0f" "1")
9301    (set_attr "mode" "SI")
9302    (set_attr "pent_pair" "np")
9303    (set_attr "athlon_decode" "vector")
9304    (set_attr "amdfam10_decode" "vector")
9305    (set_attr "bdver1_decode" "vector")])
9306
9307 (define_expand "x86_shift<mode>_adj_1"
9308   [(set (reg:CCZ FLAGS_REG)
9309         (compare:CCZ (and:QI (match_operand:QI 2 "register_operand")
9310                              (match_dup 4))
9311                      (const_int 0)))
9312    (set (match_operand:SWI48 0 "register_operand")
9313         (if_then_else:SWI48 (ne (reg:CCZ FLAGS_REG) (const_int 0))
9314                             (match_operand:SWI48 1 "register_operand")
9315                             (match_dup 0)))
9316    (set (match_dup 1)
9317         (if_then_else:SWI48 (ne (reg:CCZ FLAGS_REG) (const_int 0))
9318                             (match_operand:SWI48 3 "register_operand")
9319                             (match_dup 1)))]
9320   "TARGET_CMOVE"
9321   "operands[4] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));")
9322
9323 (define_expand "x86_shift<mode>_adj_2"
9324   [(use (match_operand:SWI48 0 "register_operand"))
9325    (use (match_operand:SWI48 1 "register_operand"))
9326    (use (match_operand:QI 2 "register_operand"))]
9327   ""
9328 {
9329   rtx_code_label *label = gen_label_rtx ();
9330   rtx tmp;
9331
9332   emit_insn (gen_testqi_ccz_1 (operands[2],
9333                                GEN_INT (GET_MODE_BITSIZE (<MODE>mode))));
9334
9335   tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
9336   tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
9337   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
9338                               gen_rtx_LABEL_REF (VOIDmode, label),
9339                               pc_rtx);
9340   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
9341   JUMP_LABEL (tmp) = label;
9342
9343   emit_move_insn (operands[0], operands[1]);
9344   ix86_expand_clear (operands[1]);
9345
9346   emit_label (label);
9347   LABEL_NUSES (label) = 1;
9348
9349   DONE;
9350 })
9351
9352 ;; Avoid useless masking of count operand.
9353 (define_insn "*ashl<mode>3_mask"
9354   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm")
9355         (ashift:SWI48
9356           (match_operand:SWI48 1 "nonimmediate_operand" "0")
9357           (subreg:QI
9358             (and:SI
9359               (match_operand:SI 2 "register_operand" "c")
9360               (match_operand:SI 3 "const_int_operand" "n")) 0)))
9361    (clobber (reg:CC FLAGS_REG))]
9362   "ix86_binary_operator_ok (ASHIFT, <MODE>mode, operands)
9363    && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode)-1))
9364       == GET_MODE_BITSIZE (<MODE>mode)-1"
9365 {
9366   return "sal{<imodesuffix>}\t{%b2, %0|%0, %b2}";
9367 }
9368   [(set_attr "type" "ishift")
9369    (set_attr "mode" "<MODE>")])
9370
9371 (define_insn "*bmi2_ashl<mode>3_1"
9372   [(set (match_operand:SWI48 0 "register_operand" "=r")
9373         (ashift:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "rm")
9374                       (match_operand:SWI48 2 "register_operand" "r")))]
9375   "TARGET_BMI2"
9376   "shlx\t{%2, %1, %0|%0, %1, %2}"
9377   [(set_attr "type" "ishiftx")
9378    (set_attr "mode" "<MODE>")])
9379
9380 (define_insn "*ashl<mode>3_1"
9381   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,r,r")
9382         (ashift:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "0,l,rm")
9383                       (match_operand:QI 2 "nonmemory_operand" "c<S>,M,r")))
9384    (clobber (reg:CC FLAGS_REG))]
9385   "ix86_binary_operator_ok (ASHIFT, <MODE>mode, operands)"
9386 {
9387   switch (get_attr_type (insn))
9388     {
9389     case TYPE_LEA:
9390     case TYPE_ISHIFTX:
9391       return "#";
9392
9393     case TYPE_ALU:
9394       gcc_assert (operands[2] == const1_rtx);
9395       gcc_assert (rtx_equal_p (operands[0], operands[1]));
9396       return "add{<imodesuffix>}\t%0, %0";
9397
9398     default:
9399       if (operands[2] == const1_rtx
9400           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9401         return "sal{<imodesuffix>}\t%0";
9402       else
9403         return "sal{<imodesuffix>}\t{%2, %0|%0, %2}";
9404     }
9405 }
9406   [(set_attr "isa" "*,*,bmi2")
9407    (set (attr "type")
9408      (cond [(eq_attr "alternative" "1")
9409               (const_string "lea")
9410             (eq_attr "alternative" "2")
9411               (const_string "ishiftx")
9412             (and (and (match_test "TARGET_DOUBLE_WITH_ADD")
9413                       (match_operand 0 "register_operand"))
9414                  (match_operand 2 "const1_operand"))
9415               (const_string "alu")
9416            ]
9417            (const_string "ishift")))
9418    (set (attr "length_immediate")
9419      (if_then_else
9420        (ior (eq_attr "type" "alu")
9421             (and (eq_attr "type" "ishift")
9422                  (and (match_operand 2 "const1_operand")
9423                       (ior (match_test "TARGET_SHIFT1")
9424                            (match_test "optimize_function_for_size_p (cfun)")))))
9425        (const_string "0")
9426        (const_string "*")))
9427    (set_attr "mode" "<MODE>")])
9428
9429 ;; Convert shift to the shiftx pattern to avoid flags dependency.
9430 (define_split
9431   [(set (match_operand:SWI48 0 "register_operand")
9432         (ashift:SWI48 (match_operand:SWI48 1 "nonimmediate_operand")
9433                       (match_operand:QI 2 "register_operand")))
9434    (clobber (reg:CC FLAGS_REG))]
9435   "TARGET_BMI2 && reload_completed"
9436   [(set (match_dup 0)
9437         (ashift:SWI48 (match_dup 1) (match_dup 2)))]
9438   "operands[2] = gen_lowpart (<MODE>mode, operands[2]);")
9439
9440 (define_insn "*bmi2_ashlsi3_1_zext"
9441   [(set (match_operand:DI 0 "register_operand" "=r")
9442         (zero_extend:DI
9443           (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "rm")
9444                      (match_operand:SI 2 "register_operand" "r"))))]
9445   "TARGET_64BIT && TARGET_BMI2"
9446   "shlx\t{%2, %1, %k0|%k0, %1, %2}"
9447   [(set_attr "type" "ishiftx")
9448    (set_attr "mode" "SI")])
9449
9450 (define_insn "*ashlsi3_1_zext"
9451   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
9452         (zero_extend:DI
9453           (ashift:SI (match_operand:SI 1 "nonimmediate_operand" "0,l,rm")
9454                      (match_operand:QI 2 "nonmemory_operand" "cI,M,r"))))
9455    (clobber (reg:CC FLAGS_REG))]
9456   "TARGET_64BIT && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
9457 {
9458   switch (get_attr_type (insn))
9459     {
9460     case TYPE_LEA:
9461     case TYPE_ISHIFTX:
9462       return "#";
9463
9464     case TYPE_ALU:
9465       gcc_assert (operands[2] == const1_rtx);
9466       return "add{l}\t%k0, %k0";
9467
9468     default:
9469       if (operands[2] == const1_rtx
9470           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9471         return "sal{l}\t%k0";
9472       else
9473         return "sal{l}\t{%2, %k0|%k0, %2}";
9474     }
9475 }
9476   [(set_attr "isa" "*,*,bmi2")
9477    (set (attr "type")
9478      (cond [(eq_attr "alternative" "1")
9479               (const_string "lea")
9480             (eq_attr "alternative" "2")
9481               (const_string "ishiftx")
9482             (and (match_test "TARGET_DOUBLE_WITH_ADD")
9483                  (match_operand 2 "const1_operand"))
9484               (const_string "alu")
9485            ]
9486            (const_string "ishift")))
9487    (set (attr "length_immediate")
9488      (if_then_else
9489        (ior (eq_attr "type" "alu")
9490             (and (eq_attr "type" "ishift")
9491                  (and (match_operand 2 "const1_operand")
9492                       (ior (match_test "TARGET_SHIFT1")
9493                            (match_test "optimize_function_for_size_p (cfun)")))))
9494        (const_string "0")
9495        (const_string "*")))
9496    (set_attr "mode" "SI")])
9497
9498 ;; Convert shift to the shiftx pattern to avoid flags dependency.
9499 (define_split
9500   [(set (match_operand:DI 0 "register_operand")
9501         (zero_extend:DI
9502           (ashift:SI (match_operand:SI 1 "nonimmediate_operand")
9503                      (match_operand:QI 2 "register_operand"))))
9504    (clobber (reg:CC FLAGS_REG))]
9505   "TARGET_64BIT && TARGET_BMI2 && reload_completed"
9506   [(set (match_dup 0)
9507         (zero_extend:DI (ashift:SI (match_dup 1) (match_dup 2))))]
9508   "operands[2] = gen_lowpart (SImode, operands[2]);")
9509
9510 (define_insn "*ashlhi3_1"
9511   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm,Yp")
9512         (ashift:HI (match_operand:HI 1 "nonimmediate_operand" "0,l")
9513                    (match_operand:QI 2 "nonmemory_operand" "cI,M")))
9514    (clobber (reg:CC FLAGS_REG))]
9515   "ix86_binary_operator_ok (ASHIFT, HImode, operands)"
9516 {
9517   switch (get_attr_type (insn))
9518     {
9519     case TYPE_LEA:
9520       return "#";
9521
9522     case TYPE_ALU:
9523       gcc_assert (operands[2] == const1_rtx);
9524       return "add{w}\t%0, %0";
9525
9526     default:
9527       if (operands[2] == const1_rtx
9528           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9529         return "sal{w}\t%0";
9530       else
9531         return "sal{w}\t{%2, %0|%0, %2}";
9532     }
9533 }
9534   [(set (attr "type")
9535      (cond [(eq_attr "alternative" "1")
9536               (const_string "lea")
9537             (and (and (match_test "TARGET_DOUBLE_WITH_ADD")
9538                       (match_operand 0 "register_operand"))
9539                  (match_operand 2 "const1_operand"))
9540               (const_string "alu")
9541            ]
9542            (const_string "ishift")))
9543    (set (attr "length_immediate")
9544      (if_then_else
9545        (ior (eq_attr "type" "alu")
9546             (and (eq_attr "type" "ishift")
9547                  (and (match_operand 2 "const1_operand")
9548                       (ior (match_test "TARGET_SHIFT1")
9549                            (match_test "optimize_function_for_size_p (cfun)")))))
9550        (const_string "0")
9551        (const_string "*")))
9552    (set_attr "mode" "HI,SI")])
9553
9554 ;; %%% Potential partial reg stall on alternative 1.  What to do?
9555 (define_insn "*ashlqi3_1"
9556   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm,r,Yp")
9557         (ashift:QI (match_operand:QI 1 "nonimmediate_operand" "0,0,l")
9558                    (match_operand:QI 2 "nonmemory_operand" "cI,cI,M")))
9559    (clobber (reg:CC FLAGS_REG))]
9560   "ix86_binary_operator_ok (ASHIFT, QImode, operands)"
9561 {
9562   switch (get_attr_type (insn))
9563     {
9564     case TYPE_LEA:
9565       return "#";
9566
9567     case TYPE_ALU:
9568       gcc_assert (operands[2] == const1_rtx);
9569       if (REG_P (operands[1]) && !ANY_QI_REG_P (operands[1]))
9570         return "add{l}\t%k0, %k0";
9571       else
9572         return "add{b}\t%0, %0";
9573
9574     default:
9575       if (operands[2] == const1_rtx
9576           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9577         {
9578           if (get_attr_mode (insn) == MODE_SI)
9579             return "sal{l}\t%k0";
9580           else
9581             return "sal{b}\t%0";
9582         }
9583       else
9584         {
9585           if (get_attr_mode (insn) == MODE_SI)
9586             return "sal{l}\t{%2, %k0|%k0, %2}";
9587           else
9588             return "sal{b}\t{%2, %0|%0, %2}";
9589         }
9590     }
9591 }
9592   [(set (attr "type")
9593      (cond [(eq_attr "alternative" "2")
9594               (const_string "lea")
9595             (and (and (match_test "TARGET_DOUBLE_WITH_ADD")
9596                       (match_operand 0 "register_operand"))
9597                  (match_operand 2 "const1_operand"))
9598               (const_string "alu")
9599            ]
9600            (const_string "ishift")))
9601    (set (attr "length_immediate")
9602      (if_then_else
9603        (ior (eq_attr "type" "alu")
9604             (and (eq_attr "type" "ishift")
9605                  (and (match_operand 2 "const1_operand")
9606                       (ior (match_test "TARGET_SHIFT1")
9607                            (match_test "optimize_function_for_size_p (cfun)")))))
9608        (const_string "0")
9609        (const_string "*")))
9610    (set_attr "mode" "QI,SI,SI")])
9611
9612 (define_insn "*ashlqi3_1_slp"
9613   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
9614         (ashift:QI (match_dup 0)
9615                    (match_operand:QI 1 "nonmemory_operand" "cI")))
9616    (clobber (reg:CC FLAGS_REG))]
9617   "(optimize_function_for_size_p (cfun)
9618     || !TARGET_PARTIAL_FLAG_REG_STALL
9619     || (operands[1] == const1_rtx
9620         && (TARGET_SHIFT1
9621             || (TARGET_DOUBLE_WITH_ADD && REG_P (operands[0])))))"
9622 {
9623   switch (get_attr_type (insn))
9624     {
9625     case TYPE_ALU:
9626       gcc_assert (operands[1] == const1_rtx);
9627       return "add{b}\t%0, %0";
9628
9629     default:
9630       if (operands[1] == const1_rtx
9631           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9632         return "sal{b}\t%0";
9633       else
9634         return "sal{b}\t{%1, %0|%0, %1}";
9635     }
9636 }
9637   [(set (attr "type")
9638      (cond [(and (and (match_test "TARGET_DOUBLE_WITH_ADD")
9639                       (match_operand 0 "register_operand"))
9640                  (match_operand 1 "const1_operand"))
9641               (const_string "alu")
9642            ]
9643            (const_string "ishift1")))
9644    (set (attr "length_immediate")
9645      (if_then_else
9646        (ior (eq_attr "type" "alu")
9647             (and (eq_attr "type" "ishift1")
9648                  (and (match_operand 1 "const1_operand")
9649                       (ior (match_test "TARGET_SHIFT1")
9650                            (match_test "optimize_function_for_size_p (cfun)")))))
9651        (const_string "0")
9652        (const_string "*")))
9653    (set_attr "mode" "QI")])
9654
9655 ;; Convert ashift to the lea pattern to avoid flags dependency.
9656 (define_split
9657   [(set (match_operand 0 "register_operand")
9658         (ashift (match_operand 1 "index_register_operand")
9659                 (match_operand:QI 2 "const_int_operand")))
9660    (clobber (reg:CC FLAGS_REG))]
9661   "GET_MODE (operands[0]) == GET_MODE (operands[1])
9662    && reload_completed
9663    && true_regnum (operands[0]) != true_regnum (operands[1])"
9664   [(const_int 0)]
9665 {
9666   machine_mode mode = GET_MODE (operands[0]);
9667   rtx pat;
9668
9669   if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (SImode))
9670     { 
9671       mode = SImode; 
9672       operands[0] = gen_lowpart (mode, operands[0]);
9673       operands[1] = gen_lowpart (mode, operands[1]);
9674     }
9675
9676   operands[2] = gen_int_mode (1 << INTVAL (operands[2]), mode);
9677
9678   pat = gen_rtx_MULT (mode, operands[1], operands[2]);
9679
9680   emit_insn (gen_rtx_SET (VOIDmode, operands[0], pat));
9681   DONE;
9682 })
9683
9684 ;; Convert ashift to the lea pattern to avoid flags dependency.
9685 (define_split
9686   [(set (match_operand:DI 0 "register_operand")
9687         (zero_extend:DI
9688           (ashift:SI (match_operand:SI 1 "index_register_operand")
9689                      (match_operand:QI 2 "const_int_operand"))))
9690    (clobber (reg:CC FLAGS_REG))]
9691   "TARGET_64BIT && reload_completed
9692    && true_regnum (operands[0]) != true_regnum (operands[1])"
9693   [(set (match_dup 0)
9694         (zero_extend:DI (mult:SI (match_dup 1) (match_dup 2))))]
9695 {
9696   operands[1] = gen_lowpart (SImode, operands[1]);
9697   operands[2] = gen_int_mode (1 << INTVAL (operands[2]), SImode);
9698 })
9699
9700 ;; This pattern can't accept a variable shift count, since shifts by
9701 ;; zero don't affect the flags.  We assume that shifts by constant
9702 ;; zero are optimized away.
9703 (define_insn "*ashl<mode>3_cmp"
9704   [(set (reg FLAGS_REG)
9705         (compare
9706           (ashift:SWI (match_operand:SWI 1 "nonimmediate_operand" "0")
9707                       (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
9708           (const_int 0)))
9709    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
9710         (ashift:SWI (match_dup 1) (match_dup 2)))]
9711   "(optimize_function_for_size_p (cfun)
9712     || !TARGET_PARTIAL_FLAG_REG_STALL
9713     || (operands[2] == const1_rtx
9714         && (TARGET_SHIFT1
9715             || (TARGET_DOUBLE_WITH_ADD && REG_P (operands[0])))))
9716    && ix86_match_ccmode (insn, CCGOCmode)
9717    && ix86_binary_operator_ok (ASHIFT, <MODE>mode, operands)"
9718 {
9719   switch (get_attr_type (insn))
9720     {
9721     case TYPE_ALU:
9722       gcc_assert (operands[2] == const1_rtx);
9723       return "add{<imodesuffix>}\t%0, %0";
9724
9725     default:
9726       if (operands[2] == const1_rtx
9727           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9728         return "sal{<imodesuffix>}\t%0";
9729       else
9730         return "sal{<imodesuffix>}\t{%2, %0|%0, %2}";
9731     }
9732 }
9733   [(set (attr "type")
9734      (cond [(and (and (match_test "TARGET_DOUBLE_WITH_ADD")
9735                       (match_operand 0 "register_operand"))
9736                  (match_operand 2 "const1_operand"))
9737               (const_string "alu")
9738            ]
9739            (const_string "ishift")))
9740    (set (attr "length_immediate")
9741      (if_then_else
9742        (ior (eq_attr "type" "alu")
9743             (and (eq_attr "type" "ishift")
9744                  (and (match_operand 2 "const1_operand")
9745                       (ior (match_test "TARGET_SHIFT1")
9746                            (match_test "optimize_function_for_size_p (cfun)")))))
9747        (const_string "0")
9748        (const_string "*")))
9749    (set_attr "mode" "<MODE>")])
9750
9751 (define_insn "*ashlsi3_cmp_zext"
9752   [(set (reg FLAGS_REG)
9753         (compare
9754           (ashift:SI (match_operand:SI 1 "register_operand" "0")
9755                      (match_operand:QI 2 "const_1_to_31_operand" "I"))
9756           (const_int 0)))
9757    (set (match_operand:DI 0 "register_operand" "=r")
9758         (zero_extend:DI (ashift:SI (match_dup 1) (match_dup 2))))]
9759   "TARGET_64BIT
9760    && (optimize_function_for_size_p (cfun)
9761        || !TARGET_PARTIAL_FLAG_REG_STALL
9762        || (operands[2] == const1_rtx
9763            && (TARGET_SHIFT1
9764                || TARGET_DOUBLE_WITH_ADD)))
9765    && ix86_match_ccmode (insn, CCGOCmode)
9766    && ix86_binary_operator_ok (ASHIFT, SImode, operands)"
9767 {
9768   switch (get_attr_type (insn))
9769     {
9770     case TYPE_ALU:
9771       gcc_assert (operands[2] == const1_rtx);
9772       return "add{l}\t%k0, %k0";
9773
9774     default:
9775       if (operands[2] == const1_rtx
9776           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9777         return "sal{l}\t%k0";
9778       else
9779         return "sal{l}\t{%2, %k0|%k0, %2}";
9780     }
9781 }
9782   [(set (attr "type")
9783      (cond [(and (match_test "TARGET_DOUBLE_WITH_ADD")
9784                  (match_operand 2 "const1_operand"))
9785               (const_string "alu")
9786            ]
9787            (const_string "ishift")))
9788    (set (attr "length_immediate")
9789      (if_then_else
9790        (ior (eq_attr "type" "alu")
9791             (and (eq_attr "type" "ishift")
9792                  (and (match_operand 2 "const1_operand")
9793                       (ior (match_test "TARGET_SHIFT1")
9794                            (match_test "optimize_function_for_size_p (cfun)")))))
9795        (const_string "0")
9796        (const_string "*")))
9797    (set_attr "mode" "SI")])
9798
9799 (define_insn "*ashl<mode>3_cconly"
9800   [(set (reg FLAGS_REG)
9801         (compare
9802           (ashift:SWI (match_operand:SWI 1 "register_operand" "0")
9803                       (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
9804           (const_int 0)))
9805    (clobber (match_scratch:SWI 0 "=<r>"))]
9806   "(optimize_function_for_size_p (cfun)
9807     || !TARGET_PARTIAL_FLAG_REG_STALL
9808     || (operands[2] == const1_rtx
9809         && (TARGET_SHIFT1
9810             || TARGET_DOUBLE_WITH_ADD)))
9811    && ix86_match_ccmode (insn, CCGOCmode)"
9812 {
9813   switch (get_attr_type (insn))
9814     {
9815     case TYPE_ALU:
9816       gcc_assert (operands[2] == const1_rtx);
9817       return "add{<imodesuffix>}\t%0, %0";
9818
9819     default:
9820       if (operands[2] == const1_rtx
9821           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
9822         return "sal{<imodesuffix>}\t%0";
9823       else
9824         return "sal{<imodesuffix>}\t{%2, %0|%0, %2}";
9825     }
9826 }
9827   [(set (attr "type")
9828      (cond [(and (and (match_test "TARGET_DOUBLE_WITH_ADD")
9829                       (match_operand 0 "register_operand"))
9830                  (match_operand 2 "const1_operand"))
9831               (const_string "alu")
9832            ]
9833            (const_string "ishift")))
9834    (set (attr "length_immediate")
9835      (if_then_else
9836        (ior (eq_attr "type" "alu")
9837             (and (eq_attr "type" "ishift")
9838                  (and (match_operand 2 "const1_operand")
9839                       (ior (match_test "TARGET_SHIFT1")
9840                            (match_test "optimize_function_for_size_p (cfun)")))))
9841        (const_string "0")
9842        (const_string "*")))
9843    (set_attr "mode" "<MODE>")])
9844
9845 ;; See comment above `ashl<mode>3' about how this works.
9846
9847 (define_expand "<shift_insn><mode>3"
9848   [(set (match_operand:SDWIM 0 "<shift_operand>")
9849         (any_shiftrt:SDWIM (match_operand:SDWIM 1 "<shift_operand>")
9850                            (match_operand:QI 2 "nonmemory_operand")))]
9851   ""
9852   "ix86_expand_binary_operator (<CODE>, <MODE>mode, operands); DONE;")
9853
9854 ;; Avoid useless masking of count operand.
9855 (define_insn "*<shift_insn><mode>3_mask"
9856   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm")
9857         (any_shiftrt:SWI48
9858           (match_operand:SWI48 1 "nonimmediate_operand" "0")
9859           (subreg:QI
9860             (and:SI
9861               (match_operand:SI 2 "register_operand" "c")
9862               (match_operand:SI 3 "const_int_operand" "n")) 0)))
9863    (clobber (reg:CC FLAGS_REG))]
9864   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)
9865    && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode)-1))
9866       == GET_MODE_BITSIZE (<MODE>mode)-1"
9867 {
9868   return "<shift>{<imodesuffix>}\t{%b2, %0|%0, %b2}";
9869 }
9870   [(set_attr "type" "ishift")
9871    (set_attr "mode" "<MODE>")])
9872
9873 (define_insn_and_split "*<shift_insn><mode>3_doubleword"
9874   [(set (match_operand:DWI 0 "register_operand" "=r")
9875         (any_shiftrt:DWI (match_operand:DWI 1 "register_operand" "0")
9876                          (match_operand:QI 2 "nonmemory_operand" "<S>c")))
9877    (clobber (reg:CC FLAGS_REG))]
9878   ""
9879   "#"
9880   "(optimize && flag_peephole2) ? epilogue_completed : reload_completed"
9881   [(const_int 0)]
9882   "ix86_split_<shift_insn> (operands, NULL_RTX, <MODE>mode); DONE;"
9883   [(set_attr "type" "multi")])
9884
9885 ;; By default we don't ask for a scratch register, because when DWImode
9886 ;; values are manipulated, registers are already at a premium.  But if
9887 ;; we have one handy, we won't turn it away.
9888
9889 (define_peephole2
9890   [(match_scratch:DWIH 3 "r")
9891    (parallel [(set (match_operand:<DWI> 0 "register_operand")
9892                    (any_shiftrt:<DWI>
9893                      (match_operand:<DWI> 1 "register_operand")
9894                      (match_operand:QI 2 "nonmemory_operand")))
9895               (clobber (reg:CC FLAGS_REG))])
9896    (match_dup 3)]
9897   "TARGET_CMOVE"
9898   [(const_int 0)]
9899   "ix86_split_<shift_insn> (operands, operands[3], <DWI>mode); DONE;")
9900
9901 (define_insn "x86_64_shrd"
9902   [(set (match_operand:DI 0 "nonimmediate_operand" "+r*m")
9903         (ior:DI (lshiftrt:DI (match_dup 0)
9904                   (match_operand:QI 2 "nonmemory_operand" "Jc"))
9905                 (ashift:DI (match_operand:DI 1 "register_operand" "r")
9906                   (minus:QI (const_int 64) (match_dup 2)))))
9907    (clobber (reg:CC FLAGS_REG))]
9908   "TARGET_64BIT"
9909   "shrd{q}\t{%s2%1, %0|%0, %1, %2}"
9910   [(set_attr "type" "ishift")
9911    (set_attr "prefix_0f" "1")
9912    (set_attr "mode" "DI")
9913    (set_attr "athlon_decode" "vector")
9914    (set_attr "amdfam10_decode" "vector")
9915    (set_attr "bdver1_decode" "vector")])
9916
9917 (define_insn "x86_shrd"
9918   [(set (match_operand:SI 0 "nonimmediate_operand" "+r*m")
9919         (ior:SI (lshiftrt:SI (match_dup 0)
9920                   (match_operand:QI 2 "nonmemory_operand" "Ic"))
9921                 (ashift:SI (match_operand:SI 1 "register_operand" "r")
9922                   (minus:QI (const_int 32) (match_dup 2)))))
9923    (clobber (reg:CC FLAGS_REG))]
9924   ""
9925   "shrd{l}\t{%s2%1, %0|%0, %1, %2}"
9926   [(set_attr "type" "ishift")
9927    (set_attr "prefix_0f" "1")
9928    (set_attr "mode" "SI")
9929    (set_attr "pent_pair" "np")
9930    (set_attr "athlon_decode" "vector")
9931    (set_attr "amdfam10_decode" "vector")
9932    (set_attr "bdver1_decode" "vector")])
9933
9934 (define_insn "ashrdi3_cvt"
9935   [(set (match_operand:DI 0 "nonimmediate_operand" "=*d,rm")
9936         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "*a,0")
9937                      (match_operand:QI 2 "const_int_operand")))
9938    (clobber (reg:CC FLAGS_REG))]
9939   "TARGET_64BIT && INTVAL (operands[2]) == 63
9940    && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
9941    && ix86_binary_operator_ok (ASHIFTRT, DImode, operands)"
9942   "@
9943    {cqto|cqo}
9944    sar{q}\t{%2, %0|%0, %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" "DI")])
9950
9951 (define_insn "ashrsi3_cvt"
9952   [(set (match_operand:SI 0 "nonimmediate_operand" "=*d,rm")
9953         (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "*a,0")
9954                      (match_operand:QI 2 "const_int_operand")))
9955    (clobber (reg:CC FLAGS_REG))]
9956   "INTVAL (operands[2]) == 31
9957    && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
9958    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
9959   "@
9960    {cltd|cdq}
9961    sar{l}\t{%2, %0|%0, %2}"
9962   [(set_attr "type" "imovx,ishift")
9963    (set_attr "prefix_0f" "0,*")
9964    (set_attr "length_immediate" "0,*")
9965    (set_attr "modrm" "0,1")
9966    (set_attr "mode" "SI")])
9967
9968 (define_insn "*ashrsi3_cvt_zext"
9969   [(set (match_operand:DI 0 "register_operand" "=*d,r")
9970         (zero_extend:DI
9971           (ashiftrt:SI (match_operand:SI 1 "register_operand" "*a,0")
9972                        (match_operand:QI 2 "const_int_operand"))))
9973    (clobber (reg:CC FLAGS_REG))]
9974   "TARGET_64BIT && INTVAL (operands[2]) == 31
9975    && (TARGET_USE_CLTD || optimize_function_for_size_p (cfun))
9976    && ix86_binary_operator_ok (ASHIFTRT, SImode, operands)"
9977   "@
9978    {cltd|cdq}
9979    sar{l}\t{%2, %k0|%k0, %2}"
9980   [(set_attr "type" "imovx,ishift")
9981    (set_attr "prefix_0f" "0,*")
9982    (set_attr "length_immediate" "0,*")
9983    (set_attr "modrm" "0,1")
9984    (set_attr "mode" "SI")])
9985
9986 (define_expand "x86_shift<mode>_adj_3"
9987   [(use (match_operand:SWI48 0 "register_operand"))
9988    (use (match_operand:SWI48 1 "register_operand"))
9989    (use (match_operand:QI 2 "register_operand"))]
9990   ""
9991 {
9992   rtx_code_label *label = gen_label_rtx ();
9993   rtx tmp;
9994
9995   emit_insn (gen_testqi_ccz_1 (operands[2],
9996                                GEN_INT (GET_MODE_BITSIZE (<MODE>mode))));
9997
9998   tmp = gen_rtx_REG (CCZmode, FLAGS_REG);
9999   tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
10000   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
10001                               gen_rtx_LABEL_REF (VOIDmode, label),
10002                               pc_rtx);
10003   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
10004   JUMP_LABEL (tmp) = label;
10005
10006   emit_move_insn (operands[0], operands[1]);
10007   emit_insn (gen_ashr<mode>3_cvt (operands[1], operands[1],
10008                                   GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1)));
10009   emit_label (label);
10010   LABEL_NUSES (label) = 1;
10011
10012   DONE;
10013 })
10014
10015 (define_insn "*bmi2_<shift_insn><mode>3_1"
10016   [(set (match_operand:SWI48 0 "register_operand" "=r")
10017         (any_shiftrt:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "rm")
10018                            (match_operand:SWI48 2 "register_operand" "r")))]
10019   "TARGET_BMI2"
10020   "<shift>x\t{%2, %1, %0|%0, %1, %2}"
10021   [(set_attr "type" "ishiftx")
10022    (set_attr "mode" "<MODE>")])
10023
10024 (define_insn "*<shift_insn><mode>3_1"
10025   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,r")
10026         (any_shiftrt:SWI48
10027           (match_operand:SWI48 1 "nonimmediate_operand" "0,rm")
10028           (match_operand:QI 2 "nonmemory_operand" "c<S>,r")))
10029    (clobber (reg:CC FLAGS_REG))]
10030   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10031 {
10032   switch (get_attr_type (insn))
10033     {
10034     case TYPE_ISHIFTX:
10035       return "#";
10036
10037     default:
10038       if (operands[2] == const1_rtx
10039           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10040         return "<shift>{<imodesuffix>}\t%0";
10041       else
10042         return "<shift>{<imodesuffix>}\t{%2, %0|%0, %2}";
10043     }
10044 }
10045   [(set_attr "isa" "*,bmi2")
10046    (set_attr "type" "ishift,ishiftx")
10047    (set (attr "length_immediate")
10048      (if_then_else
10049        (and (match_operand 2 "const1_operand")
10050             (ior (match_test "TARGET_SHIFT1")
10051                  (match_test "optimize_function_for_size_p (cfun)")))
10052        (const_string "0")
10053        (const_string "*")))
10054    (set_attr "mode" "<MODE>")])
10055
10056 ;; Convert shift to the shiftx pattern to avoid flags dependency.
10057 (define_split
10058   [(set (match_operand:SWI48 0 "register_operand")
10059         (any_shiftrt:SWI48 (match_operand:SWI48 1 "nonimmediate_operand")
10060                            (match_operand:QI 2 "register_operand")))
10061    (clobber (reg:CC FLAGS_REG))]
10062   "TARGET_BMI2 && reload_completed"
10063   [(set (match_dup 0)
10064         (any_shiftrt:SWI48 (match_dup 1) (match_dup 2)))]
10065   "operands[2] = gen_lowpart (<MODE>mode, operands[2]);")
10066
10067 (define_insn "*bmi2_<shift_insn>si3_1_zext"
10068   [(set (match_operand:DI 0 "register_operand" "=r")
10069         (zero_extend:DI
10070           (any_shiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "rm")
10071                           (match_operand:SI 2 "register_operand" "r"))))]
10072   "TARGET_64BIT && TARGET_BMI2"
10073   "<shift>x\t{%2, %1, %k0|%k0, %1, %2}"
10074   [(set_attr "type" "ishiftx")
10075    (set_attr "mode" "SI")])
10076
10077 (define_insn "*<shift_insn>si3_1_zext"
10078   [(set (match_operand:DI 0 "register_operand" "=r,r")
10079         (zero_extend:DI
10080           (any_shiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0,rm")
10081                           (match_operand:QI 2 "nonmemory_operand" "cI,r"))))
10082    (clobber (reg:CC FLAGS_REG))]
10083   "TARGET_64BIT && ix86_binary_operator_ok (<CODE>, SImode, operands)"
10084 {
10085   switch (get_attr_type (insn))
10086     {
10087     case TYPE_ISHIFTX:
10088       return "#";
10089
10090     default:
10091       if (operands[2] == const1_rtx
10092           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10093         return "<shift>{l}\t%k0";
10094       else
10095         return "<shift>{l}\t{%2, %k0|%k0, %2}";
10096     }
10097 }
10098   [(set_attr "isa" "*,bmi2")
10099    (set_attr "type" "ishift,ishiftx")
10100    (set (attr "length_immediate")
10101      (if_then_else
10102        (and (match_operand 2 "const1_operand")
10103             (ior (match_test "TARGET_SHIFT1")
10104                  (match_test "optimize_function_for_size_p (cfun)")))
10105        (const_string "0")
10106        (const_string "*")))
10107    (set_attr "mode" "SI")])
10108
10109 ;; Convert shift to the shiftx pattern to avoid flags dependency.
10110 (define_split
10111   [(set (match_operand:DI 0 "register_operand")
10112         (zero_extend:DI
10113           (any_shiftrt:SI (match_operand:SI 1 "nonimmediate_operand")
10114                           (match_operand:QI 2 "register_operand"))))
10115    (clobber (reg:CC FLAGS_REG))]
10116   "TARGET_64BIT && TARGET_BMI2 && reload_completed"
10117   [(set (match_dup 0)
10118         (zero_extend:DI (any_shiftrt:SI (match_dup 1) (match_dup 2))))]
10119   "operands[2] = gen_lowpart (SImode, operands[2]);")
10120
10121 (define_insn "*<shift_insn><mode>3_1"
10122   [(set (match_operand:SWI12 0 "nonimmediate_operand" "=<r>m")
10123         (any_shiftrt:SWI12
10124           (match_operand:SWI12 1 "nonimmediate_operand" "0")
10125           (match_operand:QI 2 "nonmemory_operand" "c<S>")))
10126    (clobber (reg:CC FLAGS_REG))]
10127   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10128 {
10129   if (operands[2] == const1_rtx
10130       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10131     return "<shift>{<imodesuffix>}\t%0";
10132   else
10133     return "<shift>{<imodesuffix>}\t{%2, %0|%0, %2}";
10134 }
10135   [(set_attr "type" "ishift")
10136    (set (attr "length_immediate")
10137      (if_then_else
10138        (and (match_operand 2 "const1_operand")
10139             (ior (match_test "TARGET_SHIFT1")
10140                  (match_test "optimize_function_for_size_p (cfun)")))
10141        (const_string "0")
10142        (const_string "*")))
10143    (set_attr "mode" "<MODE>")])
10144
10145 (define_insn "*<shift_insn>qi3_1_slp"
10146   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
10147         (any_shiftrt:QI (match_dup 0)
10148                         (match_operand:QI 1 "nonmemory_operand" "cI")))
10149    (clobber (reg:CC FLAGS_REG))]
10150   "(optimize_function_for_size_p (cfun)
10151     || !TARGET_PARTIAL_REG_STALL
10152     || (operands[1] == const1_rtx
10153         && TARGET_SHIFT1))"
10154 {
10155   if (operands[1] == const1_rtx
10156       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10157     return "<shift>{b}\t%0";
10158   else
10159     return "<shift>{b}\t{%1, %0|%0, %1}";
10160 }
10161   [(set_attr "type" "ishift1")
10162    (set (attr "length_immediate")
10163      (if_then_else
10164        (and (match_operand 1 "const1_operand")
10165             (ior (match_test "TARGET_SHIFT1")
10166                  (match_test "optimize_function_for_size_p (cfun)")))
10167        (const_string "0")
10168        (const_string "*")))
10169    (set_attr "mode" "QI")])
10170
10171 ;; This pattern can't accept a variable shift count, since shifts by
10172 ;; zero don't affect the flags.  We assume that shifts by constant
10173 ;; zero are optimized away.
10174 (define_insn "*<shift_insn><mode>3_cmp"
10175   [(set (reg FLAGS_REG)
10176         (compare
10177           (any_shiftrt:SWI
10178             (match_operand:SWI 1 "nonimmediate_operand" "0")
10179             (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
10180           (const_int 0)))
10181    (set (match_operand:SWI 0 "nonimmediate_operand" "=<r>m")
10182         (any_shiftrt:SWI (match_dup 1) (match_dup 2)))]
10183   "(optimize_function_for_size_p (cfun)
10184     || !TARGET_PARTIAL_FLAG_REG_STALL
10185     || (operands[2] == const1_rtx
10186         && TARGET_SHIFT1))
10187    && ix86_match_ccmode (insn, CCGOCmode)
10188    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10189 {
10190   if (operands[2] == const1_rtx
10191       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10192     return "<shift>{<imodesuffix>}\t%0";
10193   else
10194     return "<shift>{<imodesuffix>}\t{%2, %0|%0, %2}";
10195 }
10196   [(set_attr "type" "ishift")
10197    (set (attr "length_immediate")
10198      (if_then_else
10199        (and (match_operand 2 "const1_operand")
10200             (ior (match_test "TARGET_SHIFT1")
10201                  (match_test "optimize_function_for_size_p (cfun)")))
10202        (const_string "0")
10203        (const_string "*")))
10204    (set_attr "mode" "<MODE>")])
10205
10206 (define_insn "*<shift_insn>si3_cmp_zext"
10207   [(set (reg FLAGS_REG)
10208         (compare
10209           (any_shiftrt:SI (match_operand:SI 1 "register_operand" "0")
10210                           (match_operand:QI 2 "const_1_to_31_operand" "I"))
10211           (const_int 0)))
10212    (set (match_operand:DI 0 "register_operand" "=r")
10213         (zero_extend:DI (any_shiftrt:SI (match_dup 1) (match_dup 2))))]
10214   "TARGET_64BIT
10215    && (optimize_function_for_size_p (cfun)
10216        || !TARGET_PARTIAL_FLAG_REG_STALL
10217        || (operands[2] == const1_rtx
10218            && TARGET_SHIFT1))
10219    && ix86_match_ccmode (insn, CCGOCmode)
10220    && ix86_binary_operator_ok (<CODE>, SImode, operands)"
10221 {
10222   if (operands[2] == const1_rtx
10223       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10224     return "<shift>{l}\t%k0";
10225   else
10226     return "<shift>{l}\t{%2, %k0|%k0, %2}";
10227 }
10228   [(set_attr "type" "ishift")
10229    (set (attr "length_immediate")
10230      (if_then_else
10231        (and (match_operand 2 "const1_operand")
10232             (ior (match_test "TARGET_SHIFT1")
10233                  (match_test "optimize_function_for_size_p (cfun)")))
10234        (const_string "0")
10235        (const_string "*")))
10236    (set_attr "mode" "SI")])
10237
10238 (define_insn "*<shift_insn><mode>3_cconly"
10239   [(set (reg FLAGS_REG)
10240         (compare
10241           (any_shiftrt:SWI
10242             (match_operand:SWI 1 "register_operand" "0")
10243             (match_operand:QI 2 "<shift_immediate_operand>" "<S>"))
10244           (const_int 0)))
10245    (clobber (match_scratch:SWI 0 "=<r>"))]
10246   "(optimize_function_for_size_p (cfun)
10247     || !TARGET_PARTIAL_FLAG_REG_STALL
10248     || (operands[2] == const1_rtx
10249         && TARGET_SHIFT1))
10250    && ix86_match_ccmode (insn, CCGOCmode)"
10251 {
10252   if (operands[2] == const1_rtx
10253       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10254     return "<shift>{<imodesuffix>}\t%0";
10255   else
10256     return "<shift>{<imodesuffix>}\t{%2, %0|%0, %2}";
10257 }
10258   [(set_attr "type" "ishift")
10259    (set (attr "length_immediate")
10260      (if_then_else
10261        (and (match_operand 2 "const1_operand")
10262             (ior (match_test "TARGET_SHIFT1")
10263                  (match_test "optimize_function_for_size_p (cfun)")))
10264        (const_string "0")
10265        (const_string "*")))
10266    (set_attr "mode" "<MODE>")])
10267 \f
10268 ;; Rotate instructions
10269
10270 (define_expand "<rotate_insn>ti3"
10271   [(set (match_operand:TI 0 "register_operand")
10272         (any_rotate:TI (match_operand:TI 1 "register_operand")
10273                        (match_operand:QI 2 "nonmemory_operand")))]
10274   "TARGET_64BIT"
10275 {
10276   if (const_1_to_63_operand (operands[2], VOIDmode))
10277     emit_insn (gen_ix86_<rotate_insn>ti3_doubleword
10278                 (operands[0], operands[1], operands[2]));
10279   else
10280     FAIL;
10281
10282   DONE;
10283 })
10284
10285 (define_expand "<rotate_insn>di3"
10286   [(set (match_operand:DI 0 "shiftdi_operand")
10287         (any_rotate:DI (match_operand:DI 1 "shiftdi_operand")
10288                        (match_operand:QI 2 "nonmemory_operand")))]
10289  ""
10290 {
10291   if (TARGET_64BIT)
10292     ix86_expand_binary_operator (<CODE>, DImode, operands);
10293   else if (const_1_to_31_operand (operands[2], VOIDmode))
10294     emit_insn (gen_ix86_<rotate_insn>di3_doubleword
10295                 (operands[0], operands[1], operands[2]));
10296   else
10297     FAIL;
10298
10299   DONE;
10300 })
10301
10302 (define_expand "<rotate_insn><mode>3"
10303   [(set (match_operand:SWIM124 0 "nonimmediate_operand")
10304         (any_rotate:SWIM124 (match_operand:SWIM124 1 "nonimmediate_operand")
10305                             (match_operand:QI 2 "nonmemory_operand")))]
10306   ""
10307   "ix86_expand_binary_operator (<CODE>, <MODE>mode, operands); DONE;")
10308
10309 ;; Avoid useless masking of count operand.
10310 (define_insn "*<rotate_insn><mode>3_mask"
10311   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm")
10312         (any_rotate:SWI48
10313           (match_operand:SWI48 1 "nonimmediate_operand" "0")
10314           (subreg:QI
10315             (and:SI
10316               (match_operand:SI 2 "register_operand" "c")
10317               (match_operand:SI 3 "const_int_operand" "n")) 0)))
10318    (clobber (reg:CC FLAGS_REG))]
10319   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)
10320    && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode)-1))
10321       == GET_MODE_BITSIZE (<MODE>mode)-1"
10322 {
10323   return "<rotate>{<imodesuffix>}\t{%b2, %0|%0, %b2}";
10324 }
10325   [(set_attr "type" "rotate")
10326    (set_attr "mode" "<MODE>")])
10327
10328 ;; Implement rotation using two double-precision
10329 ;; shift instructions and a scratch register.
10330
10331 (define_insn_and_split "ix86_rotl<dwi>3_doubleword"
10332  [(set (match_operand:<DWI> 0 "register_operand" "=r")
10333        (rotate:<DWI> (match_operand:<DWI> 1 "register_operand" "0")
10334                      (match_operand:QI 2 "<shift_immediate_operand>" "<S>")))
10335   (clobber (reg:CC FLAGS_REG))
10336   (clobber (match_scratch:DWIH 3 "=&r"))]
10337  ""
10338  "#"
10339  "reload_completed"
10340  [(set (match_dup 3) (match_dup 4))
10341   (parallel
10342    [(set (match_dup 4)
10343          (ior:DWIH (ashift:DWIH (match_dup 4) (match_dup 2))
10344                    (lshiftrt:DWIH (match_dup 5)
10345                                   (minus:QI (match_dup 6) (match_dup 2)))))
10346     (clobber (reg:CC FLAGS_REG))])
10347   (parallel
10348    [(set (match_dup 5)
10349          (ior:DWIH (ashift:DWIH (match_dup 5) (match_dup 2))
10350                    (lshiftrt:DWIH (match_dup 3)
10351                                   (minus:QI (match_dup 6) (match_dup 2)))))
10352     (clobber (reg:CC FLAGS_REG))])]
10353 {
10354   operands[6] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
10355
10356   split_double_mode (<DWI>mode, &operands[0], 1, &operands[4], &operands[5]);
10357 })
10358
10359 (define_insn_and_split "ix86_rotr<dwi>3_doubleword"
10360  [(set (match_operand:<DWI> 0 "register_operand" "=r")
10361        (rotatert:<DWI> (match_operand:<DWI> 1 "register_operand" "0")
10362                        (match_operand:QI 2 "<shift_immediate_operand>" "<S>")))
10363   (clobber (reg:CC FLAGS_REG))
10364   (clobber (match_scratch:DWIH 3 "=&r"))]
10365  ""
10366  "#"
10367  "reload_completed"
10368  [(set (match_dup 3) (match_dup 4))
10369   (parallel
10370    [(set (match_dup 4)
10371          (ior:DWIH (lshiftrt:DWIH (match_dup 4) (match_dup 2))
10372                    (ashift:DWIH (match_dup 5)
10373                                 (minus:QI (match_dup 6) (match_dup 2)))))
10374     (clobber (reg:CC FLAGS_REG))])
10375   (parallel
10376    [(set (match_dup 5)
10377          (ior:DWIH (lshiftrt:DWIH (match_dup 5) (match_dup 2))
10378                    (ashift:DWIH (match_dup 3)
10379                                 (minus:QI (match_dup 6) (match_dup 2)))))
10380     (clobber (reg:CC FLAGS_REG))])]
10381 {
10382   operands[6] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode));
10383
10384   split_double_mode (<DWI>mode, &operands[0], 1, &operands[4], &operands[5]);
10385 })
10386
10387 (define_insn "*bmi2_rorx<mode>3_1"
10388   [(set (match_operand:SWI48 0 "register_operand" "=r")
10389         (rotatert:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "rm")
10390                         (match_operand:QI 2 "immediate_operand" "<S>")))]
10391   "TARGET_BMI2"
10392   "rorx\t{%2, %1, %0|%0, %1, %2}"
10393   [(set_attr "type" "rotatex")
10394    (set_attr "mode" "<MODE>")])
10395
10396 (define_insn "*<rotate_insn><mode>3_1"
10397   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,r")
10398         (any_rotate:SWI48
10399           (match_operand:SWI48 1 "nonimmediate_operand" "0,rm")
10400           (match_operand:QI 2 "nonmemory_operand" "c<S>,<S>")))
10401    (clobber (reg:CC FLAGS_REG))]
10402   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10403 {
10404   switch (get_attr_type (insn))
10405     {
10406     case TYPE_ROTATEX:
10407       return "#";
10408
10409     default:
10410       if (operands[2] == const1_rtx
10411           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10412         return "<rotate>{<imodesuffix>}\t%0";
10413       else
10414         return "<rotate>{<imodesuffix>}\t{%2, %0|%0, %2}";
10415     }
10416 }
10417   [(set_attr "isa" "*,bmi2")
10418    (set_attr "type" "rotate,rotatex")
10419    (set (attr "length_immediate")
10420      (if_then_else
10421        (and (eq_attr "type" "rotate")
10422             (and (match_operand 2 "const1_operand")
10423                  (ior (match_test "TARGET_SHIFT1")
10424                       (match_test "optimize_function_for_size_p (cfun)"))))
10425        (const_string "0")
10426        (const_string "*")))
10427    (set_attr "mode" "<MODE>")])
10428
10429 ;; Convert rotate to the rotatex pattern to avoid flags dependency.
10430 (define_split
10431   [(set (match_operand:SWI48 0 "register_operand")
10432         (rotate:SWI48 (match_operand:SWI48 1 "nonimmediate_operand")
10433                       (match_operand:QI 2 "immediate_operand")))
10434    (clobber (reg:CC FLAGS_REG))]
10435   "TARGET_BMI2 && reload_completed"
10436   [(set (match_dup 0)
10437         (rotatert:SWI48 (match_dup 1) (match_dup 2)))]
10438 {
10439   operands[2]
10440     = GEN_INT (GET_MODE_BITSIZE (<MODE>mode) - INTVAL (operands[2]));
10441 })
10442
10443 (define_split
10444   [(set (match_operand:SWI48 0 "register_operand")
10445         (rotatert:SWI48 (match_operand:SWI48 1 "nonimmediate_operand")
10446                         (match_operand:QI 2 "immediate_operand")))
10447    (clobber (reg:CC FLAGS_REG))]
10448   "TARGET_BMI2 && reload_completed"
10449   [(set (match_dup 0)
10450         (rotatert:SWI48 (match_dup 1) (match_dup 2)))])
10451
10452 (define_insn "*bmi2_rorxsi3_1_zext"
10453   [(set (match_operand:DI 0 "register_operand" "=r")
10454         (zero_extend:DI
10455           (rotatert:SI (match_operand:SI 1 "nonimmediate_operand" "rm")
10456                        (match_operand:QI 2 "immediate_operand" "I"))))]
10457   "TARGET_64BIT && TARGET_BMI2"
10458   "rorx\t{%2, %1, %k0|%k0, %1, %2}"
10459   [(set_attr "type" "rotatex")
10460    (set_attr "mode" "SI")])
10461
10462 (define_insn "*<rotate_insn>si3_1_zext"
10463   [(set (match_operand:DI 0 "register_operand" "=r,r")
10464         (zero_extend:DI
10465           (any_rotate:SI (match_operand:SI 1 "nonimmediate_operand" "0,rm")
10466                          (match_operand:QI 2 "nonmemory_operand" "cI,I"))))
10467    (clobber (reg:CC FLAGS_REG))]
10468   "TARGET_64BIT && ix86_binary_operator_ok (<CODE>, SImode, operands)"
10469 {
10470   switch (get_attr_type (insn))
10471     {
10472     case TYPE_ROTATEX:
10473       return "#";
10474
10475     default:
10476       if (operands[2] == const1_rtx
10477           && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10478         return "<rotate>{l}\t%k0";
10479       else
10480         return "<rotate>{l}\t{%2, %k0|%k0, %2}";
10481     }
10482 }
10483   [(set_attr "isa" "*,bmi2")
10484    (set_attr "type" "rotate,rotatex")
10485    (set (attr "length_immediate")
10486      (if_then_else
10487        (and (eq_attr "type" "rotate")
10488             (and (match_operand 2 "const1_operand")
10489                  (ior (match_test "TARGET_SHIFT1")
10490                       (match_test "optimize_function_for_size_p (cfun)"))))
10491        (const_string "0")
10492        (const_string "*")))
10493    (set_attr "mode" "SI")])
10494
10495 ;; Convert rotate to the rotatex pattern to avoid flags dependency.
10496 (define_split
10497   [(set (match_operand:DI 0 "register_operand")
10498         (zero_extend:DI
10499           (rotate:SI (match_operand:SI 1 "nonimmediate_operand")
10500                      (match_operand:QI 2 "immediate_operand"))))
10501    (clobber (reg:CC FLAGS_REG))]
10502   "TARGET_64BIT && TARGET_BMI2 && reload_completed"
10503   [(set (match_dup 0)
10504         (zero_extend:DI (rotatert:SI (match_dup 1) (match_dup 2))))]
10505 {
10506   operands[2]
10507     = GEN_INT (GET_MODE_BITSIZE (SImode) - INTVAL (operands[2]));
10508 })
10509
10510 (define_split
10511   [(set (match_operand:DI 0 "register_operand")
10512         (zero_extend:DI
10513           (rotatert:SI (match_operand:SI 1 "nonimmediate_operand")
10514                        (match_operand:QI 2 "immediate_operand"))))
10515    (clobber (reg:CC FLAGS_REG))]
10516   "TARGET_64BIT && TARGET_BMI2 && reload_completed"
10517   [(set (match_dup 0)
10518         (zero_extend:DI (rotatert:SI (match_dup 1) (match_dup 2))))])
10519
10520 (define_insn "*<rotate_insn><mode>3_1"
10521   [(set (match_operand:SWI12 0 "nonimmediate_operand" "=<r>m")
10522         (any_rotate:SWI12 (match_operand:SWI12 1 "nonimmediate_operand" "0")
10523                           (match_operand:QI 2 "nonmemory_operand" "c<S>")))
10524    (clobber (reg:CC FLAGS_REG))]
10525   "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10526 {
10527   if (operands[2] == const1_rtx
10528       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10529     return "<rotate>{<imodesuffix>}\t%0";
10530   else
10531     return "<rotate>{<imodesuffix>}\t{%2, %0|%0, %2}";
10532 }
10533   [(set_attr "type" "rotate")
10534    (set (attr "length_immediate")
10535      (if_then_else
10536        (and (match_operand 2 "const1_operand")
10537             (ior (match_test "TARGET_SHIFT1")
10538                  (match_test "optimize_function_for_size_p (cfun)")))
10539        (const_string "0")
10540        (const_string "*")))
10541    (set_attr "mode" "<MODE>")])
10542
10543 (define_insn "*<rotate_insn>qi3_1_slp"
10544   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
10545         (any_rotate:QI (match_dup 0)
10546                        (match_operand:QI 1 "nonmemory_operand" "cI")))
10547    (clobber (reg:CC FLAGS_REG))]
10548   "(optimize_function_for_size_p (cfun)
10549     || !TARGET_PARTIAL_REG_STALL
10550     || (operands[1] == const1_rtx
10551         && TARGET_SHIFT1))"
10552 {
10553   if (operands[1] == const1_rtx
10554       && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
10555     return "<rotate>{b}\t%0";
10556   else
10557     return "<rotate>{b}\t{%1, %0|%0, %1}";
10558 }
10559   [(set_attr "type" "rotate1")
10560    (set (attr "length_immediate")
10561      (if_then_else
10562        (and (match_operand 1 "const1_operand")
10563             (ior (match_test "TARGET_SHIFT1")
10564                  (match_test "optimize_function_for_size_p (cfun)")))
10565        (const_string "0")
10566        (const_string "*")))
10567    (set_attr "mode" "QI")])
10568
10569 (define_split
10570  [(set (match_operand:HI 0 "register_operand")
10571        (any_rotate:HI (match_dup 0) (const_int 8)))
10572   (clobber (reg:CC FLAGS_REG))]
10573  "reload_completed
10574   && (TARGET_USE_XCHGB || optimize_function_for_size_p (cfun))"
10575  [(parallel [(set (strict_low_part (match_dup 0))
10576                   (bswap:HI (match_dup 0)))
10577              (clobber (reg:CC FLAGS_REG))])])
10578 \f
10579 ;; Bit set / bit test instructions
10580
10581 (define_expand "extv"
10582   [(set (match_operand:SI 0 "register_operand")
10583         (sign_extract:SI (match_operand:SI 1 "register_operand")
10584                          (match_operand:SI 2 "const8_operand")
10585                          (match_operand:SI 3 "const8_operand")))]
10586   ""
10587 {
10588   /* Handle extractions from %ah et al.  */
10589   if (INTVAL (operands[2]) != 8 || INTVAL (operands[3]) != 8)
10590     FAIL;
10591
10592   /* From mips.md: extract_bit_field doesn't verify that our source
10593      matches the predicate, so check it again here.  */
10594   if (! ext_register_operand (operands[1], VOIDmode))
10595     FAIL;
10596 })
10597
10598 (define_expand "extzv"
10599   [(set (match_operand:SI 0 "register_operand")
10600         (zero_extract:SI (match_operand 1 "ext_register_operand")
10601                          (match_operand:SI 2 "const8_operand")
10602                          (match_operand:SI 3 "const8_operand")))]
10603   ""
10604 {
10605   /* Handle extractions from %ah et al.  */
10606   if (INTVAL (operands[2]) != 8 || INTVAL (operands[3]) != 8)
10607     FAIL;
10608
10609   /* From mips.md: extract_bit_field doesn't verify that our source
10610      matches the predicate, so check it again here.  */
10611   if (! ext_register_operand (operands[1], VOIDmode))
10612     FAIL;
10613 })
10614
10615 (define_expand "insv"
10616   [(set (zero_extract (match_operand 0 "register_operand")
10617                       (match_operand 1 "const_int_operand")
10618                       (match_operand 2 "const_int_operand"))
10619         (match_operand 3 "register_operand"))]
10620   ""
10621 {
10622   rtx (*gen_mov_insv_1) (rtx, rtx);
10623
10624   if (ix86_expand_pinsr (operands))
10625     DONE;
10626
10627   /* Handle insertions to %ah et al.  */
10628   if (INTVAL (operands[1]) != 8 || INTVAL (operands[2]) != 8)
10629     FAIL;
10630
10631   /* From mips.md: insert_bit_field doesn't verify that our source
10632      matches the predicate, so check it again here.  */
10633   if (! ext_register_operand (operands[0], VOIDmode))
10634     FAIL;
10635
10636   gen_mov_insv_1 = (TARGET_64BIT
10637                     ? gen_movdi_insv_1 : gen_movsi_insv_1);
10638
10639   emit_insn (gen_mov_insv_1 (operands[0], operands[3]));
10640   DONE;
10641 })
10642
10643 ;; %%% bts, btr, btc, bt.
10644 ;; In general these instructions are *slow* when applied to memory,
10645 ;; since they enforce atomic operation.  When applied to registers,
10646 ;; it depends on the cpu implementation.  They're never faster than
10647 ;; the corresponding and/ior/xor operations, so with 32-bit there's
10648 ;; no point.  But in 64-bit, we can't hold the relevant immediates
10649 ;; within the instruction itself, so operating on bits in the high
10650 ;; 32-bits of a register becomes easier.
10651 ;;
10652 ;; These are slow on Nocona, but fast on Athlon64.  We do require the use
10653 ;; of btrq and btcq for corner cases of post-reload expansion of absdf and
10654 ;; negdf respectively, so they can never be disabled entirely.
10655
10656 (define_insn "*btsq"
10657   [(set (zero_extract:DI (match_operand:DI 0 "register_operand" "+r")
10658                          (const_int 1)
10659                          (match_operand:DI 1 "const_0_to_63_operand"))
10660         (const_int 1))
10661    (clobber (reg:CC FLAGS_REG))]
10662   "TARGET_64BIT && (TARGET_USE_BT || reload_completed)"
10663   "bts{q}\t{%1, %0|%0, %1}"
10664   [(set_attr "type" "alu1")
10665    (set_attr "prefix_0f" "1")
10666    (set_attr "mode" "DI")])
10667
10668 (define_insn "*btrq"
10669   [(set (zero_extract:DI (match_operand:DI 0 "register_operand" "+r")
10670                          (const_int 1)
10671                          (match_operand:DI 1 "const_0_to_63_operand"))
10672         (const_int 0))
10673    (clobber (reg:CC FLAGS_REG))]
10674   "TARGET_64BIT && (TARGET_USE_BT || reload_completed)"
10675   "btr{q}\t{%1, %0|%0, %1}"
10676   [(set_attr "type" "alu1")
10677    (set_attr "prefix_0f" "1")
10678    (set_attr "mode" "DI")])
10679
10680 (define_insn "*btcq"
10681   [(set (zero_extract:DI (match_operand:DI 0 "register_operand" "+r")
10682                          (const_int 1)
10683                          (match_operand:DI 1 "const_0_to_63_operand"))
10684         (not:DI (zero_extract:DI (match_dup 0) (const_int 1) (match_dup 1))))
10685    (clobber (reg:CC FLAGS_REG))]
10686   "TARGET_64BIT && (TARGET_USE_BT || reload_completed)"
10687   "btc{q}\t{%1, %0|%0, %1}"
10688   [(set_attr "type" "alu1")
10689    (set_attr "prefix_0f" "1")
10690    (set_attr "mode" "DI")])
10691
10692 ;; Allow Nocona to avoid these instructions if a register is available.
10693
10694 (define_peephole2
10695   [(match_scratch:DI 2 "r")
10696    (parallel [(set (zero_extract:DI
10697                      (match_operand:DI 0 "register_operand")
10698                      (const_int 1)
10699                      (match_operand:DI 1 "const_0_to_63_operand"))
10700                    (const_int 1))
10701               (clobber (reg:CC FLAGS_REG))])]
10702   "TARGET_64BIT && !TARGET_USE_BT"
10703   [(const_int 0)]
10704 {
10705   HOST_WIDE_INT i = INTVAL (operands[1]), hi, lo;
10706   rtx op1;
10707
10708   if (HOST_BITS_PER_WIDE_INT >= 64)
10709     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10710   else if (i < HOST_BITS_PER_WIDE_INT)
10711     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10712   else
10713     lo = 0, hi = (HOST_WIDE_INT)1 << (i - HOST_BITS_PER_WIDE_INT);
10714
10715   op1 = immed_double_const (lo, hi, DImode);
10716   if (i >= 31)
10717     {
10718       emit_move_insn (operands[2], op1);
10719       op1 = operands[2];
10720     }
10721
10722   emit_insn (gen_iordi3 (operands[0], operands[0], op1));
10723   DONE;
10724 })
10725
10726 (define_peephole2
10727   [(match_scratch:DI 2 "r")
10728    (parallel [(set (zero_extract:DI
10729                      (match_operand:DI 0 "register_operand")
10730                      (const_int 1)
10731                      (match_operand:DI 1 "const_0_to_63_operand"))
10732                    (const_int 0))
10733               (clobber (reg:CC FLAGS_REG))])]
10734   "TARGET_64BIT && !TARGET_USE_BT"
10735   [(const_int 0)]
10736 {
10737   HOST_WIDE_INT i = INTVAL (operands[1]), hi, lo;
10738   rtx op1;
10739
10740   if (HOST_BITS_PER_WIDE_INT >= 64)
10741     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10742   else if (i < HOST_BITS_PER_WIDE_INT)
10743     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10744   else
10745     lo = 0, hi = (HOST_WIDE_INT)1 << (i - HOST_BITS_PER_WIDE_INT);
10746
10747   op1 = immed_double_const (~lo, ~hi, DImode);
10748   if (i >= 32)
10749     {
10750       emit_move_insn (operands[2], op1);
10751       op1 = operands[2];
10752     }
10753
10754   emit_insn (gen_anddi3 (operands[0], operands[0], op1));
10755   DONE;
10756 })
10757
10758 (define_peephole2
10759   [(match_scratch:DI 2 "r")
10760    (parallel [(set (zero_extract:DI
10761                      (match_operand:DI 0 "register_operand")
10762                      (const_int 1)
10763                      (match_operand:DI 1 "const_0_to_63_operand"))
10764               (not:DI (zero_extract:DI
10765                         (match_dup 0) (const_int 1) (match_dup 1))))
10766               (clobber (reg:CC FLAGS_REG))])]
10767   "TARGET_64BIT && !TARGET_USE_BT"
10768   [(const_int 0)]
10769 {
10770   HOST_WIDE_INT i = INTVAL (operands[1]), hi, lo;
10771   rtx op1;
10772
10773   if (HOST_BITS_PER_WIDE_INT >= 64)
10774     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10775   else if (i < HOST_BITS_PER_WIDE_INT)
10776     lo = (HOST_WIDE_INT)1 << i, hi = 0;
10777   else
10778     lo = 0, hi = (HOST_WIDE_INT)1 << (i - HOST_BITS_PER_WIDE_INT);
10779
10780   op1 = immed_double_const (lo, hi, DImode);
10781   if (i >= 31)
10782     {
10783       emit_move_insn (operands[2], op1);
10784       op1 = operands[2];
10785     }
10786
10787   emit_insn (gen_xordi3 (operands[0], operands[0], op1));
10788   DONE;
10789 })
10790
10791 (define_insn "*bt<mode>"
10792   [(set (reg:CCC FLAGS_REG)
10793         (compare:CCC
10794           (zero_extract:SWI48
10795             (match_operand:SWI48 0 "register_operand" "r")
10796             (const_int 1)
10797             (match_operand:SWI48 1 "x86_64_nonmemory_operand" "rN"))
10798           (const_int 0)))]
10799   "TARGET_USE_BT || optimize_function_for_size_p (cfun)"
10800   "bt{<imodesuffix>}\t{%1, %0|%0, %1}"
10801   [(set_attr "type" "alu1")
10802    (set_attr "prefix_0f" "1")
10803    (set_attr "mode" "<MODE>")])
10804 \f
10805 ;; Store-flag instructions.
10806
10807 ;; For all sCOND expanders, also expand the compare or test insn that
10808 ;; generates cc0.  Generate an equality comparison if `seq' or `sne'.
10809
10810 (define_insn_and_split "*setcc_di_1"
10811   [(set (match_operand:DI 0 "register_operand" "=q")
10812         (match_operator:DI 1 "ix86_comparison_operator"
10813           [(reg FLAGS_REG) (const_int 0)]))]
10814   "TARGET_64BIT && !TARGET_PARTIAL_REG_STALL"
10815   "#"
10816   "&& reload_completed"
10817   [(set (match_dup 2) (match_dup 1))
10818    (set (match_dup 0) (zero_extend:DI (match_dup 2)))]
10819 {
10820   PUT_MODE (operands[1], QImode);
10821   operands[2] = gen_lowpart (QImode, operands[0]);
10822 })
10823
10824 (define_insn_and_split "*setcc_si_1_and"
10825   [(set (match_operand:SI 0 "register_operand" "=q")
10826         (match_operator:SI 1 "ix86_comparison_operator"
10827           [(reg FLAGS_REG) (const_int 0)]))
10828    (clobber (reg:CC FLAGS_REG))]
10829   "!TARGET_PARTIAL_REG_STALL
10830    && TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun)"
10831   "#"
10832   "&& reload_completed"
10833   [(set (match_dup 2) (match_dup 1))
10834    (parallel [(set (match_dup 0) (zero_extend:SI (match_dup 2)))
10835               (clobber (reg:CC FLAGS_REG))])]
10836 {
10837   PUT_MODE (operands[1], QImode);
10838   operands[2] = gen_lowpart (QImode, operands[0]);
10839 })
10840
10841 (define_insn_and_split "*setcc_si_1_movzbl"
10842   [(set (match_operand:SI 0 "register_operand" "=q")
10843         (match_operator:SI 1 "ix86_comparison_operator"
10844           [(reg FLAGS_REG) (const_int 0)]))]
10845   "!TARGET_PARTIAL_REG_STALL
10846    && (!TARGET_ZERO_EXTEND_WITH_AND || optimize_function_for_size_p (cfun))"
10847   "#"
10848   "&& reload_completed"
10849   [(set (match_dup 2) (match_dup 1))
10850    (set (match_dup 0) (zero_extend:SI (match_dup 2)))]
10851 {
10852   PUT_MODE (operands[1], QImode);
10853   operands[2] = gen_lowpart (QImode, operands[0]);
10854 })
10855
10856 (define_insn "*setcc_qi"
10857   [(set (match_operand:QI 0 "nonimmediate_operand" "=qm")
10858         (match_operator:QI 1 "ix86_comparison_operator"
10859           [(reg FLAGS_REG) (const_int 0)]))]
10860   ""
10861   "set%C1\t%0"
10862   [(set_attr "type" "setcc")
10863    (set_attr "mode" "QI")])
10864
10865 (define_insn "*setcc_qi_slp"
10866   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+qm"))
10867         (match_operator:QI 1 "ix86_comparison_operator"
10868           [(reg FLAGS_REG) (const_int 0)]))]
10869   ""
10870   "set%C1\t%0"
10871   [(set_attr "type" "setcc")
10872    (set_attr "mode" "QI")])
10873
10874 ;; In general it is not safe to assume too much about CCmode registers,
10875 ;; so simplify-rtx stops when it sees a second one.  Under certain
10876 ;; conditions this is safe on x86, so help combine not create
10877 ;;
10878 ;;      seta    %al
10879 ;;      testb   %al, %al
10880 ;;      sete    %al
10881
10882 (define_split
10883   [(set (match_operand:QI 0 "nonimmediate_operand")
10884         (ne:QI (match_operator 1 "ix86_comparison_operator"
10885                  [(reg FLAGS_REG) (const_int 0)])
10886             (const_int 0)))]
10887   ""
10888   [(set (match_dup 0) (match_dup 1))]
10889   "PUT_MODE (operands[1], QImode);")
10890
10891 (define_split
10892   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand"))
10893         (ne:QI (match_operator 1 "ix86_comparison_operator"
10894                  [(reg FLAGS_REG) (const_int 0)])
10895             (const_int 0)))]
10896   ""
10897   [(set (match_dup 0) (match_dup 1))]
10898   "PUT_MODE (operands[1], QImode);")
10899
10900 (define_split
10901   [(set (match_operand:QI 0 "nonimmediate_operand")
10902         (eq:QI (match_operator 1 "ix86_comparison_operator"
10903                  [(reg FLAGS_REG) (const_int 0)])
10904             (const_int 0)))]
10905   ""
10906   [(set (match_dup 0) (match_dup 1))]
10907 {
10908   rtx new_op1 = copy_rtx (operands[1]);
10909   operands[1] = new_op1;
10910   PUT_MODE (new_op1, QImode);
10911   PUT_CODE (new_op1, ix86_reverse_condition (GET_CODE (new_op1),
10912                                              GET_MODE (XEXP (new_op1, 0))));
10913
10914   /* Make sure that (a) the CCmode we have for the flags is strong
10915      enough for the reversed compare or (b) we have a valid FP compare.  */
10916   if (! ix86_comparison_operator (new_op1, VOIDmode))
10917     FAIL;
10918 })
10919
10920 (define_split
10921   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand"))
10922         (eq:QI (match_operator 1 "ix86_comparison_operator"
10923                  [(reg FLAGS_REG) (const_int 0)])
10924             (const_int 0)))]
10925   ""
10926   [(set (match_dup 0) (match_dup 1))]
10927 {
10928   rtx new_op1 = copy_rtx (operands[1]);
10929   operands[1] = new_op1;
10930   PUT_MODE (new_op1, QImode);
10931   PUT_CODE (new_op1, ix86_reverse_condition (GET_CODE (new_op1),
10932                                              GET_MODE (XEXP (new_op1, 0))));
10933
10934   /* Make sure that (a) the CCmode we have for the flags is strong
10935      enough for the reversed compare or (b) we have a valid FP compare.  */
10936   if (! ix86_comparison_operator (new_op1, VOIDmode))
10937     FAIL;
10938 })
10939
10940 ;; The SSE store flag instructions saves 0 or 0xffffffff to the result.
10941 ;; subsequent logical operations are used to imitate conditional moves.
10942 ;; 0xffffffff is NaN, but not in normalized form, so we can't represent
10943 ;; it directly.
10944
10945 (define_insn "setcc_<mode>_sse"
10946   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
10947         (match_operator:MODEF 3 "sse_comparison_operator"
10948           [(match_operand:MODEF 1 "register_operand" "0,x")
10949            (match_operand:MODEF 2 "nonimmediate_operand" "xm,xm")]))]
10950   "SSE_FLOAT_MODE_P (<MODE>mode)"
10951   "@
10952    cmp%D3<ssemodesuffix>\t{%2, %0|%0, %2}
10953    vcmp%D3<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
10954   [(set_attr "isa" "noavx,avx")
10955    (set_attr "type" "ssecmp")
10956    (set_attr "length_immediate" "1")
10957    (set_attr "prefix" "orig,vex")
10958    (set_attr "mode" "<MODE>")])
10959 \f
10960 ;; Basic conditional jump instructions.
10961 ;; We ignore the overflow flag for signed branch instructions.
10962
10963 (define_insn "*jcc_1_bnd"
10964   [(set (pc)
10965         (if_then_else (match_operator 1 "ix86_comparison_operator"
10966                                       [(reg FLAGS_REG) (const_int 0)])
10967                       (label_ref (match_operand 0))
10968                       (pc)))]
10969   "TARGET_MPX && ix86_bnd_prefixed_insn_p (insn)"
10970   "bnd %+j%C1\t%l0"
10971   [(set_attr "type" "ibr")
10972    (set_attr "modrm" "0")
10973    (set (attr "length")
10974            (if_then_else (and (ge (minus (match_dup 0) (pc))
10975                                   (const_int -126))
10976                               (lt (minus (match_dup 0) (pc))
10977                                   (const_int 128)))
10978              (const_int 3)
10979              (const_int 7)))])
10980
10981 (define_insn "*jcc_1"
10982   [(set (pc)
10983         (if_then_else (match_operator 1 "ix86_comparison_operator"
10984                                       [(reg FLAGS_REG) (const_int 0)])
10985                       (label_ref (match_operand 0))
10986                       (pc)))]
10987   ""
10988   "%+j%C1\t%l0"
10989   [(set_attr "type" "ibr")
10990    (set_attr "modrm" "0")
10991    (set (attr "length")
10992            (if_then_else (and (ge (minus (match_dup 0) (pc))
10993                                   (const_int -126))
10994                               (lt (minus (match_dup 0) (pc))
10995                                   (const_int 128)))
10996              (const_int 2)
10997              (const_int 6)))])
10998
10999 (define_insn "*jcc_2_bnd"
11000   [(set (pc)
11001         (if_then_else (match_operator 1 "ix86_comparison_operator"
11002                                       [(reg FLAGS_REG) (const_int 0)])
11003                       (pc)
11004                       (label_ref (match_operand 0))))]
11005   "TARGET_MPX && ix86_bnd_prefixed_insn_p (insn)"
11006   "bnd %+j%c1\t%l0"
11007   [(set_attr "type" "ibr")
11008    (set_attr "modrm" "0")
11009    (set (attr "length")
11010            (if_then_else (and (ge (minus (match_dup 0) (pc))
11011                                   (const_int -126))
11012                               (lt (minus (match_dup 0) (pc))
11013                                   (const_int 128)))
11014              (const_int 3)
11015              (const_int 7)))])
11016
11017 (define_insn "*jcc_2"
11018   [(set (pc)
11019         (if_then_else (match_operator 1 "ix86_comparison_operator"
11020                                       [(reg FLAGS_REG) (const_int 0)])
11021                       (pc)
11022                       (label_ref (match_operand 0))))]
11023   ""
11024   "%+j%c1\t%l0"
11025   [(set_attr "type" "ibr")
11026    (set_attr "modrm" "0")
11027    (set (attr "length")
11028            (if_then_else (and (ge (minus (match_dup 0) (pc))
11029                                   (const_int -126))
11030                               (lt (minus (match_dup 0) (pc))
11031                                   (const_int 128)))
11032              (const_int 2)
11033              (const_int 6)))])
11034
11035 ;; In general it is not safe to assume too much about CCmode registers,
11036 ;; so simplify-rtx stops when it sees a second one.  Under certain
11037 ;; conditions this is safe on x86, so help combine not create
11038 ;;
11039 ;;      seta    %al
11040 ;;      testb   %al, %al
11041 ;;      je      Lfoo
11042
11043 (define_split
11044   [(set (pc)
11045         (if_then_else (ne (match_operator 0 "ix86_comparison_operator"
11046                                       [(reg FLAGS_REG) (const_int 0)])
11047                           (const_int 0))
11048                       (label_ref (match_operand 1))
11049                       (pc)))]
11050   ""
11051   [(set (pc)
11052         (if_then_else (match_dup 0)
11053                       (label_ref (match_dup 1))
11054                       (pc)))]
11055   "PUT_MODE (operands[0], VOIDmode);")
11056
11057 (define_split
11058   [(set (pc)
11059         (if_then_else (eq (match_operator 0 "ix86_comparison_operator"
11060                                       [(reg FLAGS_REG) (const_int 0)])
11061                           (const_int 0))
11062                       (label_ref (match_operand 1))
11063                       (pc)))]
11064   ""
11065   [(set (pc)
11066         (if_then_else (match_dup 0)
11067                       (label_ref (match_dup 1))
11068                       (pc)))]
11069 {
11070   rtx new_op0 = copy_rtx (operands[0]);
11071   operands[0] = new_op0;
11072   PUT_MODE (new_op0, VOIDmode);
11073   PUT_CODE (new_op0, ix86_reverse_condition (GET_CODE (new_op0),
11074                                              GET_MODE (XEXP (new_op0, 0))));
11075
11076   /* Make sure that (a) the CCmode we have for the flags is strong
11077      enough for the reversed compare or (b) we have a valid FP compare.  */
11078   if (! ix86_comparison_operator (new_op0, VOIDmode))
11079     FAIL;
11080 })
11081
11082 ;; zero_extend in SImode is correct also for DImode, since this is what combine
11083 ;; pass generates from shift insn with QImode operand.  Actually, the mode
11084 ;; of operand 2 (bit offset operand) doesn't matter since bt insn takes
11085 ;; appropriate modulo of the bit offset value.
11086
11087 (define_insn_and_split "*jcc_bt<mode>"
11088   [(set (pc)
11089         (if_then_else (match_operator 0 "bt_comparison_operator"
11090                         [(zero_extract:SWI48
11091                            (match_operand:SWI48 1 "register_operand" "r")
11092                            (const_int 1)
11093                            (zero_extend:SI
11094                              (match_operand:QI 2 "register_operand" "r")))
11095                          (const_int 0)])
11096                       (label_ref (match_operand 3))
11097                       (pc)))
11098    (clobber (reg:CC FLAGS_REG))]
11099   "TARGET_USE_BT || optimize_function_for_size_p (cfun)"
11100   "#"
11101   "&& 1"
11102   [(set (reg:CCC FLAGS_REG)
11103         (compare:CCC
11104           (zero_extract:SWI48
11105             (match_dup 1)
11106             (const_int 1)
11107             (match_dup 2))
11108           (const_int 0)))
11109    (set (pc)
11110         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
11111                       (label_ref (match_dup 3))
11112                       (pc)))]
11113 {
11114   operands[2] = simplify_gen_subreg (<MODE>mode, operands[2], QImode, 0);
11115
11116   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
11117 })
11118
11119 ;; Like *jcc_bt<mode>, but expect a SImode operand 2 instead of QImode
11120 ;; zero extended to SImode.
11121 (define_insn_and_split "*jcc_bt<mode>_1"
11122   [(set (pc)
11123         (if_then_else (match_operator 0 "bt_comparison_operator"
11124                         [(zero_extract:SWI48
11125                            (match_operand:SWI48 1 "register_operand" "r")
11126                            (const_int 1)
11127                            (match_operand:SI 2 "register_operand" "r"))
11128                          (const_int 0)])
11129                       (label_ref (match_operand 3))
11130                       (pc)))
11131    (clobber (reg:CC FLAGS_REG))]
11132   "TARGET_USE_BT || optimize_function_for_size_p (cfun)"
11133   "#"
11134   "&& 1"
11135   [(set (reg:CCC FLAGS_REG)
11136         (compare:CCC
11137           (zero_extract:SWI48
11138             (match_dup 1)
11139             (const_int 1)
11140             (match_dup 2))
11141           (const_int 0)))
11142    (set (pc)
11143         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
11144                       (label_ref (match_dup 3))
11145                       (pc)))]
11146 {
11147   operands[2] = simplify_gen_subreg (<MODE>mode, operands[2], SImode, 0);
11148
11149   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
11150 })
11151
11152 ;; Avoid useless masking of bit offset operand.  "and" in SImode is correct
11153 ;; also for DImode, this is what combine produces.
11154 (define_insn_and_split "*jcc_bt<mode>_mask"
11155   [(set (pc)
11156         (if_then_else (match_operator 0 "bt_comparison_operator"
11157                         [(zero_extract:SWI48
11158                            (match_operand:SWI48 1 "register_operand" "r")
11159                            (const_int 1)
11160                            (and:SI
11161                              (match_operand:SI 2 "register_operand" "r")
11162                              (match_operand:SI 3 "const_int_operand" "n")))])
11163                       (label_ref (match_operand 4))
11164                       (pc)))
11165    (clobber (reg:CC FLAGS_REG))]
11166   "(TARGET_USE_BT || optimize_function_for_size_p (cfun))
11167    && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode)-1))
11168       == GET_MODE_BITSIZE (<MODE>mode)-1"
11169   "#"
11170   "&& 1"
11171   [(set (reg:CCC FLAGS_REG)
11172         (compare:CCC
11173           (zero_extract:SWI48
11174             (match_dup 1)
11175             (const_int 1)
11176             (match_dup 2))
11177           (const_int 0)))
11178    (set (pc)
11179         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
11180                       (label_ref (match_dup 4))
11181                       (pc)))]
11182 {
11183   operands[2] = simplify_gen_subreg (<MODE>mode, operands[2], SImode, 0);
11184
11185   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
11186 })
11187
11188 (define_insn_and_split "*jcc_btsi_1"
11189   [(set (pc)
11190         (if_then_else (match_operator 0 "bt_comparison_operator"
11191                         [(and:SI
11192                            (lshiftrt:SI
11193                              (match_operand:SI 1 "register_operand" "r")
11194                              (match_operand:QI 2 "register_operand" "r"))
11195                            (const_int 1))
11196                          (const_int 0)])
11197                       (label_ref (match_operand 3))
11198                       (pc)))
11199    (clobber (reg:CC FLAGS_REG))]
11200   "TARGET_USE_BT || optimize_function_for_size_p (cfun)"
11201   "#"
11202   "&& 1"
11203   [(set (reg:CCC FLAGS_REG)
11204         (compare:CCC
11205           (zero_extract:SI
11206             (match_dup 1)
11207             (const_int 1)
11208             (match_dup 2))
11209           (const_int 0)))
11210    (set (pc)
11211         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
11212                       (label_ref (match_dup 3))
11213                       (pc)))]
11214 {
11215   operands[2] = simplify_gen_subreg (SImode, operands[2], QImode, 0);
11216
11217   PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));
11218 })
11219
11220 ;; avoid useless masking of bit offset operand
11221 (define_insn_and_split "*jcc_btsi_mask_1"
11222   [(set (pc)
11223         (if_then_else
11224           (match_operator 0 "bt_comparison_operator"
11225             [(and:SI
11226                (lshiftrt:SI
11227                  (match_operand:SI 1 "register_operand" "r")
11228                  (subreg:QI
11229                    (and:SI
11230                      (match_operand:SI 2 "register_operand" "r")
11231                      (match_operand:SI 3 "const_int_operand" "n")) 0))
11232                (const_int 1))
11233              (const_int 0)])
11234           (label_ref (match_operand 4))
11235           (pc)))
11236    (clobber (reg:CC FLAGS_REG))]
11237   "(TARGET_USE_BT || optimize_function_for_size_p (cfun))
11238    && (INTVAL (operands[3]) & 0x1f) == 0x1f"
11239   "#"
11240   "&& 1"
11241   [(set (reg:CCC FLAGS_REG)
11242         (compare:CCC
11243           (zero_extract:SI
11244             (match_dup 1)
11245             (const_int 1)
11246             (match_dup 2))
11247           (const_int 0)))
11248    (set (pc)
11249         (if_then_else (match_op_dup 0 [(reg:CCC FLAGS_REG) (const_int 0)])
11250                       (label_ref (match_dup 4))
11251                       (pc)))]
11252   "PUT_CODE (operands[0], reverse_condition (GET_CODE (operands[0])));")
11253
11254 ;; Define combination compare-and-branch fp compare instructions to help
11255 ;; combine.
11256
11257 (define_insn "*jcc<mode>_0_i387"
11258   [(set (pc)
11259         (if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
11260                         [(match_operand:X87MODEF 1 "register_operand" "f")
11261                          (match_operand:X87MODEF 2 "const0_operand")])
11262           (label_ref (match_operand 3))
11263           (pc)))
11264    (clobber (reg:CCFP FPSR_REG))
11265    (clobber (reg:CCFP FLAGS_REG))
11266    (clobber (match_scratch:HI 4 "=a"))]
11267   "TARGET_80387 && !TARGET_CMOVE"
11268   "#")
11269
11270 (define_insn "*jcc<mode>_0_r_i387"
11271   [(set (pc)
11272         (if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
11273                         [(match_operand:X87MODEF 1 "register_operand" "f")
11274                          (match_operand:X87MODEF 2 "const0_operand")])
11275           (pc)
11276           (label_ref (match_operand 3))))
11277    (clobber (reg:CCFP FPSR_REG))
11278    (clobber (reg:CCFP FLAGS_REG))
11279    (clobber (match_scratch:HI 4 "=a"))]
11280   "TARGET_80387 && !TARGET_CMOVE"
11281   "#")
11282
11283 (define_insn "*jccxf_i387"
11284   [(set (pc)
11285         (if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
11286                         [(match_operand:XF 1 "register_operand" "f")
11287                          (match_operand:XF 2 "register_operand" "f")])
11288           (label_ref (match_operand 3))
11289           (pc)))
11290    (clobber (reg:CCFP FPSR_REG))
11291    (clobber (reg:CCFP FLAGS_REG))
11292    (clobber (match_scratch:HI 4 "=a"))]
11293   "TARGET_80387 && !TARGET_CMOVE"
11294   "#")
11295
11296 (define_insn "*jccxf_r_i387"
11297   [(set (pc)
11298         (if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
11299                         [(match_operand:XF 1 "register_operand" "f")
11300                          (match_operand:XF 2 "register_operand" "f")])
11301           (pc)
11302           (label_ref (match_operand 3))))
11303    (clobber (reg:CCFP FPSR_REG))
11304    (clobber (reg:CCFP FLAGS_REG))
11305    (clobber (match_scratch:HI 4 "=a"))]
11306   "TARGET_80387 && !TARGET_CMOVE"
11307   "#")
11308
11309 (define_insn "*jcc<mode>_i387"
11310   [(set (pc)
11311         (if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
11312                         [(match_operand:MODEF 1 "register_operand" "f")
11313                          (match_operand:MODEF 2 "nonimmediate_operand" "fm")])
11314           (label_ref (match_operand 3))
11315           (pc)))
11316    (clobber (reg:CCFP FPSR_REG))
11317    (clobber (reg:CCFP FLAGS_REG))
11318    (clobber (match_scratch:HI 4 "=a"))]
11319   "TARGET_80387 && !TARGET_CMOVE"
11320   "#")
11321
11322 (define_insn "*jcc<mode>_r_i387"
11323   [(set (pc)
11324         (if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
11325                         [(match_operand:MODEF 1 "register_operand" "f")
11326                          (match_operand:MODEF 2 "nonimmediate_operand" "fm")])
11327           (pc)
11328           (label_ref (match_operand 3))))
11329    (clobber (reg:CCFP FPSR_REG))
11330    (clobber (reg:CCFP FLAGS_REG))
11331    (clobber (match_scratch:HI 4 "=a"))]
11332   "TARGET_80387 && !TARGET_CMOVE"
11333   "#")
11334
11335 (define_insn "*jccu<mode>_i387"
11336   [(set (pc)
11337         (if_then_else (match_operator:CCFPU 0 "ix86_fp_comparison_operator"
11338                         [(match_operand:X87MODEF 1 "register_operand" "f")
11339                          (match_operand:X87MODEF 2 "register_operand" "f")])
11340           (label_ref (match_operand 3))
11341           (pc)))
11342    (clobber (reg:CCFP FPSR_REG))
11343    (clobber (reg:CCFP FLAGS_REG))
11344    (clobber (match_scratch:HI 4 "=a"))]
11345   "TARGET_80387 && !TARGET_CMOVE"
11346   "#")
11347
11348 (define_insn "*jccu<mode>_r_i387"
11349   [(set (pc)
11350         (if_then_else (match_operator:CCFPU 0 "ix86_fp_comparison_operator"
11351                         [(match_operand:X87MODEF 1 "register_operand" "f")
11352                          (match_operand:X87MODEF 2 "register_operand" "f")])
11353           (pc)
11354           (label_ref (match_operand 3))))
11355    (clobber (reg:CCFP FPSR_REG))
11356    (clobber (reg:CCFP FLAGS_REG))
11357    (clobber (match_scratch:HI 4 "=a"))]
11358   "TARGET_80387 && !TARGET_CMOVE"
11359   "#")
11360
11361 (define_split
11362   [(set (pc)
11363         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
11364                         [(match_operand:X87MODEF 1 "register_operand")
11365                          (match_operand:X87MODEF 2 "nonimmediate_operand")])
11366           (match_operand 3)
11367           (match_operand 4)))
11368    (clobber (reg:CCFP FPSR_REG))
11369    (clobber (reg:CCFP FLAGS_REG))]
11370   "TARGET_80387 && !TARGET_CMOVE
11371    && reload_completed"
11372   [(const_int 0)]
11373 {
11374   ix86_split_fp_branch (GET_CODE (operands[0]), operands[1], operands[2],
11375                         operands[3], operands[4], NULL_RTX);
11376   DONE;
11377 })
11378
11379 (define_split
11380   [(set (pc)
11381         (if_then_else (match_operator 0 "ix86_fp_comparison_operator"
11382                         [(match_operand:X87MODEF 1 "register_operand")
11383                          (match_operand:X87MODEF 2 "general_operand")])
11384           (match_operand 3)
11385           (match_operand 4)))
11386    (clobber (reg:CCFP FPSR_REG))
11387    (clobber (reg:CCFP FLAGS_REG))
11388    (clobber (match_scratch:HI 5))]
11389   "TARGET_80387 && !TARGET_CMOVE
11390    && reload_completed"
11391   [(const_int 0)]
11392 {
11393   ix86_split_fp_branch (GET_CODE (operands[0]), operands[1], operands[2],
11394                         operands[3], operands[4], operands[5]);
11395   DONE;
11396 })
11397
11398 ;; The order of operands in *jcc<fp>_<int>_i387 is forced by combine in
11399 ;; simplify_comparison () function. Float operator is treated as RTX_OBJ
11400 ;; with a precedence over other operators and is always put in the first
11401 ;; place. Swap condition and operands to match ficom instruction.
11402
11403 (define_insn "*jcc<X87MODEF:mode>_<SWI24:mode>_i387"
11404   [(set (pc)
11405         (if_then_else
11406           (match_operator:CCFP 0 "ix86_swapped_fp_comparison_operator"
11407             [(match_operator:X87MODEF 1 "float_operator"
11408               [(match_operand:SWI24 2 "nonimmediate_operand" "m")])
11409              (match_operand:X87MODEF 3 "register_operand" "f")])
11410           (label_ref (match_operand 4))
11411           (pc)))
11412    (clobber (reg:CCFP FPSR_REG))
11413    (clobber (reg:CCFP FLAGS_REG))
11414    (clobber (match_scratch:HI 5 "=a"))]
11415   "TARGET_80387 && !TARGET_CMOVE
11416    && (TARGET_USE_<SWI24:MODE>MODE_FIOP
11417        || optimize_function_for_size_p (cfun))"
11418   "#")
11419
11420 (define_insn "*jcc<X87MODEF:mode>_<SWI24:mode>_r_i387"
11421   [(set (pc)
11422         (if_then_else
11423           (match_operator:CCFP 0 "ix86_swapped_fp_comparison_operator"
11424             [(match_operator:X87MODEF 1 "float_operator"
11425               [(match_operand:SWI24 2 "nonimmediate_operand" "m")])
11426              (match_operand:X87MODEF 3 "register_operand" "f")])
11427           (pc)
11428           (label_ref (match_operand 4))))
11429    (clobber (reg:CCFP FPSR_REG))
11430    (clobber (reg:CCFP FLAGS_REG))
11431    (clobber (match_scratch:HI 5 "=a"))]
11432   "TARGET_80387 && !TARGET_CMOVE
11433    && (TARGET_USE_<SWI24:MODE>MODE_FIOP
11434        || optimize_function_for_size_p (cfun))"
11435   "#")
11436
11437 (define_split
11438   [(set (pc)
11439         (if_then_else
11440           (match_operator:CCFP 0 "ix86_swapped_fp_comparison_operator"
11441             [(match_operator:X87MODEF 1 "float_operator"
11442               [(match_operand:SWI24 2 "memory_operand")])
11443              (match_operand:X87MODEF 3 "register_operand")])
11444           (match_operand 4)
11445           (match_operand 5)))
11446    (clobber (reg:CCFP FPSR_REG))
11447    (clobber (reg:CCFP FLAGS_REG))
11448    (clobber (match_scratch:HI 6))]
11449   "TARGET_80387 && !TARGET_CMOVE
11450    && reload_completed"
11451   [(const_int 0)]
11452 {
11453   ix86_split_fp_branch (swap_condition (GET_CODE (operands[0])), operands[3],
11454                         gen_rtx_FLOAT (GET_MODE (operands[1]), operands[2]),
11455                         operands[4], operands[5], operands[6]);
11456   DONE;
11457 })
11458 \f
11459 ;; Unconditional and other jump instructions
11460
11461 (define_insn "jump_bnd"
11462   [(set (pc)
11463         (label_ref (match_operand 0)))]
11464   "TARGET_MPX && ix86_bnd_prefixed_insn_p (insn)"
11465   "bnd jmp\t%l0"
11466   [(set_attr "type" "ibr")
11467    (set (attr "length")
11468            (if_then_else (and (ge (minus (match_dup 0) (pc))
11469                                   (const_int -126))
11470                               (lt (minus (match_dup 0) (pc))
11471                                   (const_int 128)))
11472              (const_int 3)
11473              (const_int 6)))
11474    (set_attr "modrm" "0")])
11475
11476 (define_insn "jump"
11477   [(set (pc)
11478         (label_ref (match_operand 0)))]
11479   ""
11480   "jmp\t%l0"
11481   [(set_attr "type" "ibr")
11482    (set (attr "length")
11483            (if_then_else (and (ge (minus (match_dup 0) (pc))
11484                                   (const_int -126))
11485                               (lt (minus (match_dup 0) (pc))
11486                                   (const_int 128)))
11487              (const_int 2)
11488              (const_int 5)))
11489    (set_attr "modrm" "0")])
11490
11491 (define_expand "indirect_jump"
11492   [(set (pc) (match_operand 0 "indirect_branch_operand"))]
11493   ""
11494 {
11495   if (TARGET_X32)
11496     operands[0] = convert_memory_address (word_mode, operands[0]);
11497 })
11498
11499 (define_insn "*indirect_jump"
11500   [(set (pc) (match_operand:W 0 "indirect_branch_operand" "rBw"))]
11501   ""
11502   "%!jmp\t%A0"
11503   [(set_attr "type" "ibr")
11504    (set_attr "length_immediate" "0")])
11505
11506 (define_expand "tablejump"
11507   [(parallel [(set (pc) (match_operand 0 "indirect_branch_operand"))
11508               (use (label_ref (match_operand 1)))])]
11509   ""
11510 {
11511   /* In PIC mode, the table entries are stored GOT (32-bit) or PC (64-bit)
11512      relative.  Convert the relative address to an absolute address.  */
11513   if (flag_pic)
11514     {
11515       rtx op0, op1;
11516       enum rtx_code code;
11517
11518       /* We can't use @GOTOFF for text labels on VxWorks;
11519          see gotoff_operand.  */
11520       if (TARGET_64BIT || TARGET_VXWORKS_RTP)
11521         {
11522           code = PLUS;
11523           op0 = operands[0];
11524           op1 = gen_rtx_LABEL_REF (Pmode, operands[1]);
11525         }
11526       else if (TARGET_MACHO || HAVE_AS_GOTOFF_IN_DATA)
11527         {
11528           code = PLUS;
11529           op0 = operands[0];
11530           op1 = pic_offset_table_rtx;
11531         }
11532       else
11533         {
11534           code = MINUS;
11535           op0 = pic_offset_table_rtx;
11536           op1 = operands[0];
11537         }
11538
11539       operands[0] = expand_simple_binop (Pmode, code, op0, op1, NULL_RTX, 0,
11540                                          OPTAB_DIRECT);
11541     }
11542
11543   if (TARGET_X32)
11544     operands[0] = convert_memory_address (word_mode, operands[0]);
11545 })
11546
11547 (define_insn "*tablejump_1"
11548   [(set (pc) (match_operand:W 0 "indirect_branch_operand" "rBw"))
11549    (use (label_ref (match_operand 1)))]
11550   ""
11551   "%!jmp\t%A0"
11552   [(set_attr "type" "ibr")
11553    (set_attr "length_immediate" "0")])
11554 \f
11555 ;; Convert setcc + movzbl to xor + setcc if operands don't overlap.
11556
11557 (define_peephole2
11558   [(set (reg FLAGS_REG) (match_operand 0))
11559    (set (match_operand:QI 1 "register_operand")
11560         (match_operator:QI 2 "ix86_comparison_operator"
11561           [(reg FLAGS_REG) (const_int 0)]))
11562    (set (match_operand 3 "q_regs_operand")
11563         (zero_extend (match_dup 1)))]
11564   "(peep2_reg_dead_p (3, operands[1])
11565     || operands_match_p (operands[1], operands[3]))
11566    && ! reg_overlap_mentioned_p (operands[3], operands[0])"
11567   [(set (match_dup 4) (match_dup 0))
11568    (set (strict_low_part (match_dup 5))
11569         (match_dup 2))]
11570 {
11571   operands[4] = gen_rtx_REG (GET_MODE (operands[0]), FLAGS_REG);
11572   operands[5] = gen_lowpart (QImode, operands[3]);
11573   ix86_expand_clear (operands[3]);
11574 })
11575
11576 (define_peephole2
11577   [(parallel [(set (reg FLAGS_REG) (match_operand 0))
11578               (match_operand 4)])
11579    (set (match_operand:QI 1 "register_operand")
11580         (match_operator:QI 2 "ix86_comparison_operator"
11581           [(reg FLAGS_REG) (const_int 0)]))
11582    (set (match_operand 3 "q_regs_operand")
11583         (zero_extend (match_dup 1)))]
11584   "(peep2_reg_dead_p (3, operands[1])
11585     || operands_match_p (operands[1], operands[3]))
11586    && ! reg_overlap_mentioned_p (operands[3], operands[0])"
11587   [(parallel [(set (match_dup 5) (match_dup 0))
11588               (match_dup 4)])
11589    (set (strict_low_part (match_dup 6))
11590         (match_dup 2))]
11591 {
11592   operands[5] = gen_rtx_REG (GET_MODE (operands[0]), FLAGS_REG);
11593   operands[6] = gen_lowpart (QImode, operands[3]);
11594   ix86_expand_clear (operands[3]);
11595 })
11596
11597 ;; Similar, but match zero extend with andsi3.
11598
11599 (define_peephole2
11600   [(set (reg FLAGS_REG) (match_operand 0))
11601    (set (match_operand:QI 1 "register_operand")
11602         (match_operator:QI 2 "ix86_comparison_operator"
11603           [(reg FLAGS_REG) (const_int 0)]))
11604    (parallel [(set (match_operand:SI 3 "q_regs_operand")
11605                    (and:SI (match_dup 3) (const_int 255)))
11606               (clobber (reg:CC FLAGS_REG))])]
11607   "REGNO (operands[1]) == REGNO (operands[3])
11608    && ! reg_overlap_mentioned_p (operands[3], operands[0])"
11609   [(set (match_dup 4) (match_dup 0))
11610    (set (strict_low_part (match_dup 5))
11611         (match_dup 2))]
11612 {
11613   operands[4] = gen_rtx_REG (GET_MODE (operands[0]), FLAGS_REG);
11614   operands[5] = gen_lowpart (QImode, operands[3]);
11615   ix86_expand_clear (operands[3]);
11616 })
11617
11618 (define_peephole2
11619   [(parallel [(set (reg FLAGS_REG) (match_operand 0))
11620               (match_operand 4)])
11621    (set (match_operand:QI 1 "register_operand")
11622         (match_operator:QI 2 "ix86_comparison_operator"
11623           [(reg FLAGS_REG) (const_int 0)]))
11624    (parallel [(set (match_operand 3 "q_regs_operand")
11625                    (zero_extend (match_dup 1)))
11626               (clobber (reg:CC FLAGS_REG))])]
11627   "(peep2_reg_dead_p (3, operands[1])
11628     || operands_match_p (operands[1], operands[3]))
11629    && ! reg_overlap_mentioned_p (operands[3], operands[0])"
11630   [(parallel [(set (match_dup 5) (match_dup 0))
11631               (match_dup 4)])
11632    (set (strict_low_part (match_dup 6))
11633         (match_dup 2))]
11634 {
11635   operands[5] = gen_rtx_REG (GET_MODE (operands[0]), FLAGS_REG);
11636   operands[6] = gen_lowpart (QImode, operands[3]);
11637   ix86_expand_clear (operands[3]);
11638 })
11639 \f
11640 ;; Call instructions.
11641
11642 ;; The predicates normally associated with named expanders are not properly
11643 ;; checked for calls.  This is a bug in the generic code, but it isn't that
11644 ;; easy to fix.  Ignore it for now and be prepared to fix things up.
11645
11646 ;; P6 processors will jump to the address after the decrement when %esp
11647 ;; is used as a call operand, so they will execute return address as a code.
11648 ;; See Pentium Pro errata 70, Pentium 2 errata A33 and Pentium 3 errata E17.
11649
11650 ;; Register constraint for call instruction.
11651 (define_mode_attr c [(SI "l") (DI "r")])
11652
11653 ;; Call subroutine returning no value.
11654
11655 (define_expand "call"
11656   [(call (match_operand:QI 0)
11657          (match_operand 1))
11658    (use (match_operand 2))]
11659   ""
11660 {
11661   ix86_expand_call (NULL, operands[0], operands[1],
11662                     operands[2], NULL, false);
11663   DONE;
11664 })
11665
11666 (define_expand "sibcall"
11667   [(call (match_operand:QI 0)
11668          (match_operand 1))
11669    (use (match_operand 2))]
11670   ""
11671 {
11672   ix86_expand_call (NULL, operands[0], operands[1],
11673                     operands[2], NULL, true);
11674   DONE;
11675 })
11676
11677 (define_insn "*call"
11678   [(call (mem:QI (match_operand:W 0 "call_insn_operand" "<c>BwBz"))
11679          (match_operand 1))]
11680   "!SIBLING_CALL_P (insn)"
11681   "* return ix86_output_call_insn (insn, operands[0]);"
11682   [(set_attr "type" "call")])
11683
11684 (define_insn "*sibcall"
11685   [(call (mem:QI (match_operand:W 0 "sibcall_insn_operand" "UBsBz"))
11686          (match_operand 1))]
11687   "SIBLING_CALL_P (insn)"
11688   "* return ix86_output_call_insn (insn, operands[0]);"
11689   [(set_attr "type" "call")])
11690
11691 (define_insn "*sibcall_memory"
11692   [(call (mem:QI (match_operand:W 0 "memory_operand" "m"))
11693          (match_operand 1))
11694    (unspec [(const_int 0)] UNSPEC_PEEPSIB)]
11695   "!TARGET_X32"
11696   "* return ix86_output_call_insn (insn, operands[0]);"
11697   [(set_attr "type" "call")])
11698
11699 (define_peephole2
11700   [(set (match_operand:W 0 "register_operand")
11701         (match_operand:W 1 "memory_operand"))
11702    (call (mem:QI (match_dup 0))
11703          (match_operand 3))]
11704   "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (1))
11705    && peep2_reg_dead_p (2, operands[0])"
11706   [(parallel [(call (mem:QI (match_dup 1))
11707                     (match_dup 3))
11708               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
11709
11710 (define_peephole2
11711   [(set (match_operand:W 0 "register_operand")
11712         (match_operand:W 1 "memory_operand"))
11713    (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
11714    (call (mem:QI (match_dup 0))
11715          (match_operand 3))]
11716   "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (2))
11717    && peep2_reg_dead_p (3, operands[0])"
11718   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
11719    (parallel [(call (mem:QI (match_dup 1))
11720                     (match_dup 3))
11721               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
11722
11723 (define_expand "call_pop"
11724   [(parallel [(call (match_operand:QI 0)
11725                     (match_operand:SI 1))
11726               (set (reg:SI SP_REG)
11727                    (plus:SI (reg:SI SP_REG)
11728                             (match_operand:SI 3)))])]
11729   "!TARGET_64BIT"
11730 {
11731   ix86_expand_call (NULL, operands[0], operands[1],
11732                     operands[2], operands[3], false);
11733   DONE;
11734 })
11735
11736 (define_insn "*call_pop"
11737   [(call (mem:QI (match_operand:SI 0 "call_insn_operand" "lmBz"))
11738          (match_operand 1))
11739    (set (reg:SI SP_REG)
11740         (plus:SI (reg:SI SP_REG)
11741                  (match_operand:SI 2 "immediate_operand" "i")))]
11742   "!TARGET_64BIT && !SIBLING_CALL_P (insn)"
11743   "* return ix86_output_call_insn (insn, operands[0]);"
11744   [(set_attr "type" "call")])
11745
11746 (define_insn "*sibcall_pop"
11747   [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "UBsBz"))
11748          (match_operand 1))
11749    (set (reg:SI SP_REG)
11750         (plus:SI (reg:SI SP_REG)
11751                  (match_operand:SI 2 "immediate_operand" "i")))]
11752   "!TARGET_64BIT && SIBLING_CALL_P (insn)"
11753   "* return ix86_output_call_insn (insn, operands[0]);"
11754   [(set_attr "type" "call")])
11755
11756 (define_insn "*sibcall_pop_memory"
11757   [(call (mem:QI (match_operand:SI 0 "memory_operand" "m"))
11758          (match_operand 1))
11759    (set (reg:SI SP_REG)
11760         (plus:SI (reg:SI SP_REG)
11761                  (match_operand:SI 2 "immediate_operand" "i")))
11762    (unspec [(const_int 0)] UNSPEC_PEEPSIB)]
11763   "!TARGET_64BIT"
11764   "* return ix86_output_call_insn (insn, operands[0]);"
11765   [(set_attr "type" "call")])
11766
11767 (define_peephole2
11768   [(set (match_operand:SI 0 "register_operand")
11769         (match_operand:SI 1 "memory_operand"))
11770    (parallel [(call (mem:QI (match_dup 0))
11771                     (match_operand 3))
11772               (set (reg:SI SP_REG)
11773                    (plus:SI (reg:SI SP_REG)
11774                             (match_operand:SI 4 "immediate_operand")))])]
11775   "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (1))
11776    && peep2_reg_dead_p (2, operands[0])"
11777   [(parallel [(call (mem:QI (match_dup 1))
11778                     (match_dup 3))
11779               (set (reg:SI SP_REG)
11780                    (plus:SI (reg:SI SP_REG)
11781                             (match_dup 4)))
11782               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
11783
11784 (define_peephole2
11785   [(set (match_operand:SI 0 "register_operand")
11786         (match_operand:SI 1 "memory_operand"))
11787    (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
11788    (parallel [(call (mem:QI (match_dup 0))
11789                     (match_operand 3))
11790               (set (reg:SI SP_REG)
11791                    (plus:SI (reg:SI SP_REG)
11792                             (match_operand:SI 4 "immediate_operand")))])]
11793   "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (2))
11794    && peep2_reg_dead_p (3, operands[0])"
11795   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
11796    (parallel [(call (mem:QI (match_dup 1))
11797                     (match_dup 3))
11798               (set (reg:SI SP_REG)
11799                    (plus:SI (reg:SI SP_REG)
11800                             (match_dup 4)))
11801               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
11802
11803 ;; Combining simple memory jump instruction
11804
11805 (define_peephole2
11806   [(set (match_operand:W 0 "register_operand")
11807         (match_operand:W 1 "memory_operand"))
11808    (set (pc) (match_dup 0))]
11809   "!TARGET_X32 && peep2_reg_dead_p (2, operands[0])"
11810   [(set (pc) (match_dup 1))])
11811
11812 ;; Call subroutine, returning value in operand 0
11813
11814 (define_expand "call_value"
11815   [(set (match_operand 0)
11816         (call (match_operand:QI 1)
11817               (match_operand 2)))
11818    (use (match_operand 3))]
11819   ""
11820 {
11821   ix86_expand_call (operands[0], operands[1], operands[2],
11822                     operands[3], NULL, false);
11823   DONE;
11824 })
11825
11826 (define_expand "sibcall_value"
11827   [(set (match_operand 0)
11828         (call (match_operand:QI 1)
11829               (match_operand 2)))
11830    (use (match_operand 3))]
11831   ""
11832 {
11833   ix86_expand_call (operands[0], operands[1], operands[2],
11834                     operands[3], NULL, true);
11835   DONE;
11836 })
11837
11838 (define_insn "*call_value"
11839   [(set (match_operand 0)
11840         (call (mem:QI (match_operand:W 1 "call_insn_operand" "<c>BwBz"))
11841               (match_operand 2)))]
11842   "!SIBLING_CALL_P (insn)"
11843   "* return ix86_output_call_insn (insn, operands[1]);"
11844   [(set_attr "type" "callv")])
11845
11846 (define_insn "*sibcall_value"
11847   [(set (match_operand 0)
11848         (call (mem:QI (match_operand:W 1 "sibcall_insn_operand" "UBsBz"))
11849               (match_operand 2)))]
11850   "SIBLING_CALL_P (insn)"
11851   "* return ix86_output_call_insn (insn, operands[1]);"
11852   [(set_attr "type" "callv")])
11853
11854 (define_insn "*sibcall_value_memory"
11855   [(set (match_operand 0)
11856         (call (mem:QI (match_operand:W 1 "memory_operand" "m"))
11857               (match_operand 2)))
11858    (unspec [(const_int 0)] UNSPEC_PEEPSIB)]
11859   "!TARGET_X32"
11860   "* return ix86_output_call_insn (insn, operands[1]);"
11861   [(set_attr "type" "callv")])
11862
11863 (define_peephole2
11864   [(set (match_operand:W 0 "register_operand")
11865         (match_operand:W 1 "memory_operand"))
11866    (set (match_operand 2)
11867    (call (mem:QI (match_dup 0))
11868                  (match_operand 3)))]
11869   "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (1))
11870    && peep2_reg_dead_p (2, operands[0])"
11871   [(parallel [(set (match_dup 2)
11872                    (call (mem:QI (match_dup 1))
11873                          (match_dup 3)))
11874               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
11875
11876 (define_peephole2
11877   [(set (match_operand:W 0 "register_operand")
11878         (match_operand:W 1 "memory_operand"))
11879    (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
11880    (set (match_operand 2)
11881         (call (mem:QI (match_dup 0))
11882               (match_operand 3)))]
11883   "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (2))
11884    && peep2_reg_dead_p (3, operands[0])"
11885   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
11886    (parallel [(set (match_dup 2)
11887                    (call (mem:QI (match_dup 1))
11888                          (match_dup 3)))
11889               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
11890
11891 (define_expand "call_value_pop"
11892   [(parallel [(set (match_operand 0)
11893                    (call (match_operand:QI 1)
11894                          (match_operand:SI 2)))
11895               (set (reg:SI SP_REG)
11896                    (plus:SI (reg:SI SP_REG)
11897                             (match_operand:SI 4)))])]
11898   "!TARGET_64BIT"
11899 {
11900   ix86_expand_call (operands[0], operands[1], operands[2],
11901                     operands[3], operands[4], false);
11902   DONE;
11903 })
11904
11905 (define_insn "*call_value_pop"
11906   [(set (match_operand 0)
11907         (call (mem:QI (match_operand:SI 1 "call_insn_operand" "lmBz"))
11908               (match_operand 2)))
11909    (set (reg:SI SP_REG)
11910         (plus:SI (reg:SI SP_REG)
11911                  (match_operand:SI 3 "immediate_operand" "i")))]
11912   "!TARGET_64BIT && !SIBLING_CALL_P (insn)"
11913   "* return ix86_output_call_insn (insn, operands[1]);"
11914   [(set_attr "type" "callv")])
11915
11916 (define_insn "*sibcall_value_pop"
11917   [(set (match_operand 0)
11918         (call (mem:QI (match_operand:SI 1 "sibcall_insn_operand" "UBsBz"))
11919               (match_operand 2)))
11920    (set (reg:SI SP_REG)
11921         (plus:SI (reg:SI SP_REG)
11922                  (match_operand:SI 3 "immediate_operand" "i")))]
11923   "!TARGET_64BIT && SIBLING_CALL_P (insn)"
11924   "* return ix86_output_call_insn (insn, operands[1]);"
11925   [(set_attr "type" "callv")])
11926
11927 (define_insn "*sibcall_value_pop_memory"
11928   [(set (match_operand 0)
11929         (call (mem:QI (match_operand:SI 1 "memory_operand" "m"))
11930               (match_operand 2)))
11931    (set (reg:SI SP_REG)
11932         (plus:SI (reg:SI SP_REG)
11933                  (match_operand:SI 3 "immediate_operand" "i")))
11934    (unspec [(const_int 0)] UNSPEC_PEEPSIB)]
11935   "!TARGET_64BIT"
11936   "* return ix86_output_call_insn (insn, operands[1]);"
11937   [(set_attr "type" "callv")])
11938
11939 (define_peephole2
11940   [(set (match_operand:SI 0 "register_operand")
11941         (match_operand:SI 1 "memory_operand"))
11942    (parallel [(set (match_operand 2)
11943                    (call (mem:QI (match_dup 0))
11944                          (match_operand 3)))
11945               (set (reg:SI SP_REG)
11946                    (plus:SI (reg:SI SP_REG)
11947                             (match_operand:SI 4 "immediate_operand")))])]
11948   "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (1))
11949    && peep2_reg_dead_p (2, operands[0])"
11950   [(parallel [(set (match_dup 2)
11951                    (call (mem:QI (match_dup 1))
11952                          (match_dup 3)))
11953               (set (reg:SI SP_REG)
11954                    (plus:SI (reg:SI SP_REG)
11955                             (match_dup 4)))
11956               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
11957
11958 (define_peephole2
11959   [(set (match_operand:SI 0 "register_operand")
11960         (match_operand:SI 1 "memory_operand"))
11961    (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
11962    (parallel [(set (match_operand 2)
11963                    (call (mem:QI (match_dup 0))
11964                          (match_operand 3)))
11965               (set (reg:SI SP_REG)
11966                    (plus:SI (reg:SI SP_REG)
11967                             (match_operand:SI 4 "immediate_operand")))])]
11968   "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (2))
11969    && peep2_reg_dead_p (3, operands[0])"
11970   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
11971    (parallel [(set (match_dup 2)
11972                    (call (mem:QI (match_dup 1))
11973                          (match_dup 3)))
11974               (set (reg:SI SP_REG)
11975                    (plus:SI (reg:SI SP_REG)
11976                             (match_dup 4)))
11977               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
11978
11979 ;; Call subroutine returning any type.
11980
11981 (define_expand "untyped_call"
11982   [(parallel [(call (match_operand 0)
11983                     (const_int 0))
11984               (match_operand 1)
11985               (match_operand 2)])]
11986   ""
11987 {
11988   int i;
11989
11990   /* In order to give reg-stack an easier job in validating two
11991      coprocessor registers as containing a possible return value,
11992      simply pretend the untyped call returns a complex long double
11993      value. 
11994
11995      We can't use SSE_REGPARM_MAX here since callee is unprototyped
11996      and should have the default ABI.  */
11997
11998   ix86_expand_call ((TARGET_FLOAT_RETURNS_IN_80387
11999                      ? gen_rtx_REG (XCmode, FIRST_FLOAT_REG) : NULL),
12000                     operands[0], const0_rtx,
12001                     GEN_INT ((TARGET_64BIT
12002                               ? (ix86_abi == SYSV_ABI
12003                                  ? X86_64_SSE_REGPARM_MAX
12004                                  : X86_64_MS_SSE_REGPARM_MAX)
12005                               : X86_32_SSE_REGPARM_MAX)
12006                              - 1),
12007                     NULL, false);
12008
12009   for (i = 0; i < XVECLEN (operands[2], 0); i++)
12010     {
12011       rtx set = XVECEXP (operands[2], 0, i);
12012       emit_move_insn (SET_DEST (set), SET_SRC (set));
12013     }
12014
12015   /* The optimizer does not know that the call sets the function value
12016      registers we stored in the result block.  We avoid problems by
12017      claiming that all hard registers are used and clobbered at this
12018      point.  */
12019   emit_insn (gen_blockage ());
12020
12021   DONE;
12022 })
12023 \f
12024 ;; Prologue and epilogue instructions
12025
12026 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
12027 ;; all of memory.  This blocks insns from being moved across this point.
12028
12029 (define_insn "blockage"
12030   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
12031   ""
12032   ""
12033   [(set_attr "length" "0")])
12034
12035 ;; Do not schedule instructions accessing memory across this point.
12036
12037 (define_expand "memory_blockage"
12038   [(set (match_dup 0)
12039         (unspec:BLK [(match_dup 0)] UNSPEC_MEMORY_BLOCKAGE))]
12040   ""
12041 {
12042   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
12043   MEM_VOLATILE_P (operands[0]) = 1;
12044 })
12045
12046 (define_insn "*memory_blockage"
12047   [(set (match_operand:BLK 0)
12048         (unspec:BLK [(match_dup 0)] UNSPEC_MEMORY_BLOCKAGE))]
12049   ""
12050   ""
12051   [(set_attr "length" "0")])
12052
12053 ;; As USE insns aren't meaningful after reload, this is used instead
12054 ;; to prevent deleting instructions setting registers for PIC code
12055 (define_insn "prologue_use"
12056   [(unspec_volatile [(match_operand 0)] UNSPECV_PROLOGUE_USE)]
12057   ""
12058   ""
12059   [(set_attr "length" "0")])
12060
12061 ;; Insn emitted into the body of a function to return from a function.
12062 ;; This is only done if the function's epilogue is known to be simple.
12063 ;; See comments for ix86_can_use_return_insn_p in i386.c.
12064
12065 (define_expand "return"
12066   [(simple_return)]
12067   "ix86_can_use_return_insn_p ()"
12068 {
12069   if (crtl->args.pops_args)
12070     {
12071       rtx popc = GEN_INT (crtl->args.pops_args);
12072       emit_jump_insn (gen_simple_return_pop_internal (popc));
12073       DONE;
12074     }
12075 })
12076
12077 ;; We need to disable this for TARGET_SEH, as otherwise
12078 ;; shrink-wrapped prologue gets enabled too.  This might exceed
12079 ;; the maximum size of prologue in unwind information.
12080
12081 (define_expand "simple_return"
12082   [(simple_return)]
12083   "!TARGET_SEH"
12084 {
12085   if (crtl->args.pops_args)
12086     {
12087       rtx popc = GEN_INT (crtl->args.pops_args);
12088       emit_jump_insn (gen_simple_return_pop_internal (popc));
12089       DONE;
12090     }
12091 })
12092
12093 (define_insn "simple_return_internal"
12094   [(simple_return)]
12095   "reload_completed"
12096   "%!ret"
12097   [(set_attr "length_nobnd" "1")
12098    (set_attr "atom_unit" "jeu")
12099    (set_attr "length_immediate" "0")
12100    (set_attr "modrm" "0")])
12101
12102 ;; Used by x86_machine_dependent_reorg to avoid penalty on single byte RET
12103 ;; instruction Athlon and K8 have.
12104
12105 (define_insn "simple_return_internal_long"
12106   [(simple_return)
12107    (unspec [(const_int 0)] UNSPEC_REP)]
12108   "reload_completed"
12109 {
12110   if (ix86_bnd_prefixed_insn_p (insn))
12111     return "%!ret";
12112
12113   return "rep%; ret";
12114 }
12115   [(set_attr "length" "2")
12116    (set_attr "atom_unit" "jeu")
12117    (set_attr "length_immediate" "0")
12118    (set_attr "prefix_rep" "1")
12119    (set_attr "modrm" "0")])
12120
12121 (define_insn "simple_return_pop_internal"
12122   [(simple_return)
12123    (use (match_operand:SI 0 "const_int_operand"))]
12124   "reload_completed"
12125   "%!ret\t%0"
12126   [(set_attr "length_nobnd" "3")
12127    (set_attr "atom_unit" "jeu")
12128    (set_attr "length_immediate" "2")
12129    (set_attr "modrm" "0")])
12130
12131 (define_insn "simple_return_indirect_internal"
12132   [(simple_return)
12133    (use (match_operand:SI 0 "register_operand" "r"))]
12134   "reload_completed"
12135   "%!jmp\t%A0"
12136   [(set_attr "type" "ibr")
12137    (set_attr "length_immediate" "0")])
12138
12139 (define_insn "nop"
12140   [(const_int 0)]
12141   ""
12142   "nop"
12143   [(set_attr "length" "1")
12144    (set_attr "length_immediate" "0")
12145    (set_attr "modrm" "0")])
12146
12147 ;; Generate nops.  Operand 0 is the number of nops, up to 8.
12148 (define_insn "nops"
12149   [(unspec_volatile [(match_operand 0 "const_int_operand")]
12150                     UNSPECV_NOPS)]
12151   "reload_completed"
12152 {
12153   int num = INTVAL (operands[0]);
12154
12155   gcc_assert (IN_RANGE (num, 1, 8));
12156
12157   while (num--)
12158     fputs ("\tnop\n", asm_out_file);
12159
12160   return "";
12161 }
12162   [(set (attr "length") (symbol_ref "INTVAL (operands[0])"))
12163    (set_attr "length_immediate" "0")
12164    (set_attr "modrm" "0")])
12165
12166 ;; Pad to 16-byte boundary, max skip in op0.  Used to avoid
12167 ;; branch prediction penalty for the third jump in a 16-byte
12168 ;; block on K8.
12169
12170 (define_insn "pad"
12171   [(unspec_volatile [(match_operand 0)] UNSPECV_ALIGN)]
12172   ""
12173 {
12174 #ifdef ASM_OUTPUT_MAX_SKIP_PAD
12175   ASM_OUTPUT_MAX_SKIP_PAD (asm_out_file, 4, (int)INTVAL (operands[0]));
12176 #else
12177   /* It is tempting to use ASM_OUTPUT_ALIGN here, but we don't want to do that.
12178      The align insn is used to avoid 3 jump instructions in the row to improve
12179      branch prediction and the benefits hardly outweigh the cost of extra 8
12180      nops on the average inserted by full alignment pseudo operation.  */
12181 #endif
12182   return "";
12183 }
12184   [(set_attr "length" "16")])
12185
12186 (define_expand "prologue"
12187   [(const_int 0)]
12188   ""
12189   "ix86_expand_prologue (); DONE;")
12190
12191 (define_insn "set_got"
12192   [(set (match_operand:SI 0 "register_operand" "=r")
12193         (unspec:SI [(const_int 0)] UNSPEC_SET_GOT))
12194    (clobber (reg:CC FLAGS_REG))]
12195   "!TARGET_64BIT"
12196   "* return output_set_got (operands[0], NULL_RTX);"
12197   [(set_attr "type" "multi")
12198    (set_attr "length" "12")])
12199
12200 (define_insn "set_got_labelled"
12201   [(set (match_operand:SI 0 "register_operand" "=r")
12202         (unspec:SI [(label_ref (match_operand 1))]
12203          UNSPEC_SET_GOT))
12204    (clobber (reg:CC FLAGS_REG))]
12205   "!TARGET_64BIT"
12206   "* return output_set_got (operands[0], operands[1]);"
12207   [(set_attr "type" "multi")
12208    (set_attr "length" "12")])
12209
12210 (define_insn "set_got_rex64"
12211   [(set (match_operand:DI 0 "register_operand" "=r")
12212         (unspec:DI [(const_int 0)] UNSPEC_SET_GOT))]
12213   "TARGET_64BIT"
12214   "lea{q}\t{_GLOBAL_OFFSET_TABLE_(%%rip), %0|%0, _GLOBAL_OFFSET_TABLE_[rip]}"
12215   [(set_attr "type" "lea")
12216    (set_attr "length_address" "4")
12217    (set_attr "mode" "DI")])
12218
12219 (define_insn "set_rip_rex64"
12220   [(set (match_operand:DI 0 "register_operand" "=r")
12221         (unspec:DI [(label_ref (match_operand 1))] UNSPEC_SET_RIP))]
12222   "TARGET_64BIT"
12223   "lea{q}\t{%l1(%%rip), %0|%0, %l1[rip]}"
12224   [(set_attr "type" "lea")
12225    (set_attr "length_address" "4")
12226    (set_attr "mode" "DI")])
12227
12228 (define_insn "set_got_offset_rex64"
12229   [(set (match_operand:DI 0 "register_operand" "=r")
12230         (unspec:DI
12231           [(label_ref (match_operand 1))]
12232           UNSPEC_SET_GOT_OFFSET))]
12233   "TARGET_LP64"
12234   "movabs{q}\t{$_GLOBAL_OFFSET_TABLE_-%l1, %0|%0, OFFSET FLAT:_GLOBAL_OFFSET_TABLE_-%l1}"
12235   [(set_attr "type" "imov")
12236    (set_attr "length_immediate" "0")
12237    (set_attr "length_address" "8")
12238    (set_attr "mode" "DI")])
12239
12240 (define_expand "epilogue"
12241   [(const_int 0)]
12242   ""
12243   "ix86_expand_epilogue (1); DONE;")
12244
12245 (define_expand "sibcall_epilogue"
12246   [(const_int 0)]
12247   ""
12248   "ix86_expand_epilogue (0); DONE;")
12249
12250 (define_expand "eh_return"
12251   [(use (match_operand 0 "register_operand"))]
12252   ""
12253 {
12254   rtx tmp, sa = EH_RETURN_STACKADJ_RTX, ra = operands[0];
12255
12256   /* Tricky bit: we write the address of the handler to which we will
12257      be returning into someone else's stack frame, one word below the
12258      stack address we wish to restore.  */
12259   tmp = gen_rtx_PLUS (Pmode, arg_pointer_rtx, sa);
12260   tmp = plus_constant (Pmode, tmp, -UNITS_PER_WORD);
12261   tmp = gen_rtx_MEM (Pmode, tmp);
12262   emit_move_insn (tmp, ra);
12263
12264   emit_jump_insn (gen_eh_return_internal ());
12265   emit_barrier ();
12266   DONE;
12267 })
12268
12269 (define_insn_and_split "eh_return_internal"
12270   [(eh_return)]
12271   ""
12272   "#"
12273   "epilogue_completed"
12274   [(const_int 0)]
12275   "ix86_expand_epilogue (2); DONE;")
12276
12277 (define_insn "leave"
12278   [(set (reg:SI SP_REG) (plus:SI (reg:SI BP_REG) (const_int 4)))
12279    (set (reg:SI BP_REG) (mem:SI (reg:SI BP_REG)))
12280    (clobber (mem:BLK (scratch)))]
12281   "!TARGET_64BIT"
12282   "leave"
12283   [(set_attr "type" "leave")])
12284
12285 (define_insn "leave_rex64"
12286   [(set (reg:DI SP_REG) (plus:DI (reg:DI BP_REG) (const_int 8)))
12287    (set (reg:DI BP_REG) (mem:DI (reg:DI BP_REG)))
12288    (clobber (mem:BLK (scratch)))]
12289   "TARGET_64BIT"
12290   "leave"
12291   [(set_attr "type" "leave")])
12292 \f
12293 ;; Handle -fsplit-stack.
12294
12295 (define_expand "split_stack_prologue"
12296   [(const_int 0)]
12297   ""
12298 {
12299   ix86_expand_split_stack_prologue ();
12300   DONE;
12301 })
12302
12303 ;; In order to support the call/return predictor, we use a return
12304 ;; instruction which the middle-end doesn't see.
12305 (define_insn "split_stack_return"
12306   [(unspec_volatile [(match_operand:SI 0 "const_int_operand")]
12307                      UNSPECV_SPLIT_STACK_RETURN)]
12308   ""
12309 {
12310   if (operands[0] == const0_rtx)
12311     return "ret";
12312   else
12313     return "ret\t%0";
12314 }
12315   [(set_attr "atom_unit" "jeu")
12316    (set_attr "modrm" "0")
12317    (set (attr "length")
12318         (if_then_else (match_operand:SI 0 "const0_operand")
12319                       (const_int 1)
12320                       (const_int 3)))
12321    (set (attr "length_immediate")
12322         (if_then_else (match_operand:SI 0 "const0_operand")
12323                       (const_int 0)
12324                       (const_int 2)))])
12325
12326 ;; If there are operand 0 bytes available on the stack, jump to
12327 ;; operand 1.
12328
12329 (define_expand "split_stack_space_check"
12330   [(set (pc) (if_then_else
12331               (ltu (minus (reg SP_REG)
12332                           (match_operand 0 "register_operand"))
12333                    (unspec [(const_int 0)] UNSPEC_STACK_CHECK))
12334               (label_ref (match_operand 1))
12335               (pc)))]
12336   ""
12337 {
12338   rtx reg, size, limit;
12339
12340   reg = gen_reg_rtx (Pmode);
12341   size = force_reg (Pmode, operands[0]);
12342   emit_insn (gen_sub3_insn (reg, stack_pointer_rtx, size));
12343   limit = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
12344                           UNSPEC_STACK_CHECK);
12345   limit = gen_rtx_MEM (Pmode, gen_rtx_CONST (Pmode, limit));
12346   ix86_expand_branch (GEU, reg, limit, operands[1]);
12347
12348   DONE;
12349 })
12350 \f
12351 ;; Bit manipulation instructions.
12352
12353 (define_expand "ffs<mode>2"
12354   [(set (match_dup 2) (const_int -1))
12355    (parallel [(set (match_dup 3) (match_dup 4))
12356               (set (match_operand:SWI48 0 "register_operand")
12357                    (ctz:SWI48
12358                      (match_operand:SWI48 1 "nonimmediate_operand")))])
12359    (set (match_dup 0) (if_then_else:SWI48
12360                         (eq (match_dup 3) (const_int 0))
12361                         (match_dup 2)
12362                         (match_dup 0)))
12363    (parallel [(set (match_dup 0) (plus:SWI48 (match_dup 0) (const_int 1)))
12364               (clobber (reg:CC FLAGS_REG))])]
12365   ""
12366 {
12367   machine_mode flags_mode;
12368
12369   if (<MODE>mode == SImode && !TARGET_CMOVE)
12370     {
12371       emit_insn (gen_ffssi2_no_cmove (operands[0], operands [1]));
12372       DONE;
12373     }
12374
12375   flags_mode
12376     = (TARGET_BMI && !TARGET_AVOID_FALSE_DEP_FOR_BMI) ? CCCmode : CCZmode;
12377
12378   operands[2] = gen_reg_rtx (<MODE>mode);
12379   operands[3] = gen_rtx_REG (flags_mode, FLAGS_REG);
12380   operands[4] = gen_rtx_COMPARE (flags_mode, operands[1], const0_rtx);
12381 })
12382
12383 (define_insn_and_split "ffssi2_no_cmove"
12384   [(set (match_operand:SI 0 "register_operand" "=r")
12385         (ffs:SI (match_operand:SI 1 "nonimmediate_operand" "rm")))
12386    (clobber (match_scratch:SI 2 "=&q"))
12387    (clobber (reg:CC FLAGS_REG))]
12388   "!TARGET_CMOVE"
12389   "#"
12390   "&& reload_completed"
12391   [(parallel [(set (match_dup 4) (match_dup 5))
12392               (set (match_dup 0) (ctz:SI (match_dup 1)))])
12393    (set (strict_low_part (match_dup 3))
12394         (eq:QI (match_dup 4) (const_int 0)))
12395    (parallel [(set (match_dup 2) (neg:SI (match_dup 2)))
12396               (clobber (reg:CC FLAGS_REG))])
12397    (parallel [(set (match_dup 0) (ior:SI (match_dup 0) (match_dup 2)))
12398               (clobber (reg:CC FLAGS_REG))])
12399    (parallel [(set (match_dup 0) (plus:SI (match_dup 0) (const_int 1)))
12400               (clobber (reg:CC FLAGS_REG))])]
12401 {
12402   machine_mode flags_mode
12403     = (TARGET_BMI && !TARGET_AVOID_FALSE_DEP_FOR_BMI) ? CCCmode : CCZmode;
12404
12405   operands[3] = gen_lowpart (QImode, operands[2]);
12406   operands[4] = gen_rtx_REG (flags_mode, FLAGS_REG);
12407   operands[5] = gen_rtx_COMPARE (flags_mode, operands[1], const0_rtx);
12408
12409   ix86_expand_clear (operands[2]);
12410 })
12411
12412 (define_insn "*tzcnt<mode>_1"
12413   [(set (reg:CCC FLAGS_REG)
12414         (compare:CCC (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12415                      (const_int 0)))
12416    (set (match_operand:SWI48 0 "register_operand" "=r")
12417         (ctz:SWI48 (match_dup 1)))]
12418   "TARGET_BMI && !TARGET_AVOID_FALSE_DEP_FOR_BMI"
12419   "tzcnt{<imodesuffix>}\t{%1, %0|%0, %1}"
12420   [(set_attr "type" "alu1")
12421    (set_attr "prefix_0f" "1")
12422    (set_attr "prefix_rep" "1")
12423    (set_attr "btver2_decode" "double")
12424    (set_attr "mode" "<MODE>")])
12425
12426 (define_insn "*bsf<mode>_1"
12427   [(set (reg:CCZ FLAGS_REG)
12428         (compare:CCZ (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12429                      (const_int 0)))
12430    (set (match_operand:SWI48 0 "register_operand" "=r")
12431         (ctz:SWI48 (match_dup 1)))]
12432   ""
12433   "bsf{<imodesuffix>}\t{%1, %0|%0, %1}"
12434   [(set_attr "type" "alu1")
12435    (set_attr "prefix_0f" "1")
12436    (set_attr "btver2_decode" "double")
12437    (set_attr "mode" "<MODE>")])
12438
12439 (define_expand "ctz<mode>2"
12440   [(parallel
12441     [(set (match_operand:SWI248 0 "register_operand")
12442           (ctz:SWI248
12443             (match_operand:SWI248 1 "nonimmediate_operand")))
12444      (clobber (reg:CC FLAGS_REG))])])
12445
12446 ; False dependency happens when destination is only updated by tzcnt,
12447 ; lzcnt or popcnt.  There is no false dependency when destination is
12448 ; also used in source.
12449 (define_insn_and_split "*ctz<mode>2_falsedep_1"
12450   [(set (match_operand:SWI48 0 "register_operand" "=r")
12451         (ctz:SWI48
12452           (match_operand:SWI48 1 "nonimmediate_operand" "rm")))
12453    (clobber (reg:CC FLAGS_REG))]
12454   "(TARGET_BMI || TARGET_GENERIC)
12455    && TARGET_AVOID_FALSE_DEP_FOR_BMI && optimize_function_for_speed_p (cfun)"
12456   "#"
12457   "&& reload_completed"
12458   [(parallel
12459     [(set (match_dup 0)
12460           (ctz:SWI48 (match_dup 1)))
12461      (unspec [(match_dup 0)] UNSPEC_INSN_FALSE_DEP)
12462      (clobber (reg:CC FLAGS_REG))])]
12463 {
12464   if (!reg_mentioned_p (operands[0], operands[1]))
12465     ix86_expand_clear (operands[0]);
12466 })
12467
12468 (define_insn "*ctz<mode>2_falsedep"
12469   [(set (match_operand:SWI48 0 "register_operand" "=r")
12470         (ctz:SWI48
12471           (match_operand:SWI48 1 "nonimmediate_operand" "rm")))
12472    (unspec [(match_operand:SWI48 2 "register_operand" "0")]
12473            UNSPEC_INSN_FALSE_DEP)
12474    (clobber (reg:CC FLAGS_REG))]
12475   ""
12476 {
12477   if (TARGET_BMI)
12478     return "tzcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
12479   else if (TARGET_GENERIC)
12480     /* tzcnt expands to 'rep bsf' and we can use it even if !TARGET_BMI.  */
12481     return "rep%; bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
12482   else
12483     gcc_unreachable ();
12484 }
12485   [(set_attr "type" "alu1")
12486    (set_attr "prefix_0f" "1")
12487    (set_attr "prefix_rep" "1")
12488    (set_attr "mode" "<MODE>")])
12489
12490 (define_insn "*ctz<mode>2"
12491   [(set (match_operand:SWI248 0 "register_operand" "=r")
12492         (ctz:SWI248 (match_operand:SWI248 1 "nonimmediate_operand" "rm")))
12493    (clobber (reg:CC FLAGS_REG))]
12494   ""
12495 {
12496   if (TARGET_BMI)
12497     return "tzcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
12498   else if (optimize_function_for_size_p (cfun))
12499     ;
12500   else if (TARGET_GENERIC)
12501     /* tzcnt expands to 'rep bsf' and we can use it even if !TARGET_BMI.  */
12502     return "rep%; bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
12503
12504   return "bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
12505 }
12506   [(set_attr "type" "alu1")
12507    (set_attr "prefix_0f" "1")
12508    (set (attr "prefix_rep")
12509      (if_then_else
12510        (ior (match_test "TARGET_BMI")
12511             (and (not (match_test "optimize_function_for_size_p (cfun)"))
12512                  (match_test "TARGET_GENERIC")))
12513        (const_string "1")
12514        (const_string "0")))
12515    (set_attr "mode" "<MODE>")])
12516
12517 (define_expand "clz<mode>2"
12518   [(parallel
12519      [(set (match_operand:SWI248 0 "register_operand")
12520            (minus:SWI248
12521              (match_dup 2)
12522              (clz:SWI248 (match_operand:SWI248 1 "nonimmediate_operand"))))
12523       (clobber (reg:CC FLAGS_REG))])
12524    (parallel
12525      [(set (match_dup 0) (xor:SWI248 (match_dup 0) (match_dup 2)))
12526       (clobber (reg:CC FLAGS_REG))])]
12527   ""
12528 {
12529   if (TARGET_LZCNT)
12530     {
12531       emit_insn (gen_clz<mode>2_lzcnt (operands[0], operands[1]));
12532       DONE;
12533     }
12534   operands[2] = GEN_INT (GET_MODE_BITSIZE (<MODE>mode)-1);
12535 })
12536
12537 (define_expand "clz<mode>2_lzcnt"
12538   [(parallel
12539     [(set (match_operand:SWI248 0 "register_operand")
12540           (clz:SWI248
12541             (match_operand:SWI248 1 "nonimmediate_operand")))
12542      (clobber (reg:CC FLAGS_REG))])]
12543   "TARGET_LZCNT")
12544
12545 (define_insn_and_split "*clz<mode>2_lzcnt_falsedep_1"
12546   [(set (match_operand:SWI48 0 "register_operand" "=r")
12547         (clz:SWI48
12548           (match_operand:SWI48 1 "nonimmediate_operand" "rm")))
12549    (clobber (reg:CC FLAGS_REG))]
12550   "TARGET_LZCNT
12551    && TARGET_AVOID_FALSE_DEP_FOR_BMI && optimize_function_for_speed_p (cfun)"
12552   "#"
12553   "&& reload_completed"
12554   [(parallel
12555     [(set (match_dup 0)
12556           (clz:SWI48 (match_dup 1)))
12557      (unspec [(match_dup 0)] UNSPEC_INSN_FALSE_DEP)
12558      (clobber (reg:CC FLAGS_REG))])]
12559 {
12560   if (!reg_mentioned_p (operands[0], operands[1]))
12561     ix86_expand_clear (operands[0]);
12562 })
12563
12564 (define_insn "*clz<mode>2_lzcnt_falsedep"
12565   [(set (match_operand:SWI48 0 "register_operand" "=r")
12566         (clz:SWI48
12567           (match_operand:SWI48 1 "nonimmediate_operand" "rm")))
12568    (unspec [(match_operand:SWI48 2 "register_operand" "0")]
12569            UNSPEC_INSN_FALSE_DEP)
12570    (clobber (reg:CC FLAGS_REG))]
12571   "TARGET_LZCNT"
12572   "lzcnt{<imodesuffix>}\t{%1, %0|%0, %1}"
12573   [(set_attr "prefix_rep" "1")
12574    (set_attr "type" "bitmanip")
12575    (set_attr "mode" "<MODE>")])
12576
12577 (define_insn "*clz<mode>2_lzcnt"
12578   [(set (match_operand:SWI248 0 "register_operand" "=r")
12579         (clz:SWI248 (match_operand:SWI248 1 "nonimmediate_operand" "rm")))
12580    (clobber (reg:CC FLAGS_REG))]
12581   "TARGET_LZCNT"
12582   "lzcnt{<imodesuffix>}\t{%1, %0|%0, %1}"
12583   [(set_attr "prefix_rep" "1")
12584    (set_attr "type" "bitmanip")
12585    (set_attr "mode" "<MODE>")])
12586
12587 ;; BMI instructions.
12588 (define_insn "*bmi_andn_<mode>"
12589   [(set (match_operand:SWI48 0 "register_operand" "=r,r")
12590         (and:SWI48
12591           (not:SWI48
12592             (match_operand:SWI48 1 "register_operand" "r,r"))
12593             (match_operand:SWI48 2 "nonimmediate_operand" "r,m")))
12594    (clobber (reg:CC FLAGS_REG))]
12595   "TARGET_BMI"
12596   "andn\t{%2, %1, %0|%0, %1, %2}"
12597   [(set_attr "type" "bitmanip")
12598    (set_attr "btver2_decode" "direct, double")
12599    (set_attr "mode" "<MODE>")])
12600
12601 (define_insn "bmi_bextr_<mode>"
12602   [(set (match_operand:SWI48 0 "register_operand" "=r,r")
12603         (unspec:SWI48 [(match_operand:SWI48 1 "nonimmediate_operand" "r,m")
12604                        (match_operand:SWI48 2 "register_operand" "r,r")]
12605                        UNSPEC_BEXTR))
12606    (clobber (reg:CC FLAGS_REG))]
12607   "TARGET_BMI"
12608   "bextr\t{%2, %1, %0|%0, %1, %2}"
12609   [(set_attr "type" "bitmanip")
12610    (set_attr "btver2_decode" "direct, double")
12611    (set_attr "mode" "<MODE>")])
12612
12613 (define_insn "*bmi_blsi_<mode>"
12614   [(set (match_operand:SWI48 0 "register_operand" "=r")
12615         (and:SWI48
12616           (neg:SWI48
12617             (match_operand:SWI48 1 "nonimmediate_operand" "rm"))
12618           (match_dup 1)))
12619    (clobber (reg:CC FLAGS_REG))]
12620   "TARGET_BMI"
12621   "blsi\t{%1, %0|%0, %1}"
12622   [(set_attr "type" "bitmanip")
12623    (set_attr "btver2_decode" "double")
12624    (set_attr "mode" "<MODE>")])
12625
12626 (define_insn "*bmi_blsmsk_<mode>"
12627   [(set (match_operand:SWI48 0 "register_operand" "=r")
12628         (xor:SWI48
12629           (plus:SWI48
12630             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12631             (const_int -1))
12632           (match_dup 1)))
12633    (clobber (reg:CC FLAGS_REG))]
12634   "TARGET_BMI"
12635   "blsmsk\t{%1, %0|%0, %1}"
12636   [(set_attr "type" "bitmanip")
12637    (set_attr "btver2_decode" "double")
12638    (set_attr "mode" "<MODE>")])
12639
12640 (define_insn "*bmi_blsr_<mode>"
12641   [(set (match_operand:SWI48 0 "register_operand" "=r")
12642         (and:SWI48
12643           (plus:SWI48
12644             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12645             (const_int -1))
12646           (match_dup 1)))
12647    (clobber (reg:CC FLAGS_REG))]
12648    "TARGET_BMI"
12649    "blsr\t{%1, %0|%0, %1}"
12650   [(set_attr "type" "bitmanip")
12651    (set_attr "btver2_decode" "double")
12652    (set_attr "mode" "<MODE>")])
12653
12654 ;; BMI2 instructions.
12655 (define_insn "bmi2_bzhi_<mode>3"
12656   [(set (match_operand:SWI48 0 "register_operand" "=r")
12657         (and:SWI48 (lshiftrt:SWI48 (const_int -1)
12658                                    (match_operand:SWI48 2 "register_operand" "r"))
12659                    (match_operand:SWI48 1 "nonimmediate_operand" "rm")))
12660    (clobber (reg:CC FLAGS_REG))]
12661   "TARGET_BMI2"
12662   "bzhi\t{%2, %1, %0|%0, %1, %2}"
12663   [(set_attr "type" "bitmanip")
12664    (set_attr "prefix" "vex")
12665    (set_attr "mode" "<MODE>")])
12666
12667 (define_insn "bmi2_pdep_<mode>3"
12668   [(set (match_operand:SWI48 0 "register_operand" "=r")
12669         (unspec:SWI48 [(match_operand:SWI48 1 "register_operand" "r")
12670                        (match_operand:SWI48 2 "nonimmediate_operand" "rm")]
12671                        UNSPEC_PDEP))]
12672   "TARGET_BMI2"
12673   "pdep\t{%2, %1, %0|%0, %1, %2}"
12674   [(set_attr "type" "bitmanip")
12675    (set_attr "prefix" "vex")
12676    (set_attr "mode" "<MODE>")])
12677
12678 (define_insn "bmi2_pext_<mode>3"
12679   [(set (match_operand:SWI48 0 "register_operand" "=r")
12680         (unspec:SWI48 [(match_operand:SWI48 1 "register_operand" "r")
12681                        (match_operand:SWI48 2 "nonimmediate_operand" "rm")]
12682                        UNSPEC_PEXT))]
12683   "TARGET_BMI2"
12684   "pext\t{%2, %1, %0|%0, %1, %2}"
12685   [(set_attr "type" "bitmanip")
12686    (set_attr "prefix" "vex")
12687    (set_attr "mode" "<MODE>")])
12688
12689 ;; TBM instructions.
12690 (define_insn "tbm_bextri_<mode>"
12691   [(set (match_operand:SWI48 0 "register_operand" "=r")
12692         (zero_extract:SWI48
12693           (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12694           (match_operand:SWI48 2 "const_0_to_255_operand" "n")
12695           (match_operand:SWI48 3 "const_0_to_255_operand" "n")))
12696    (clobber (reg:CC FLAGS_REG))]
12697    "TARGET_TBM"
12698 {
12699   operands[2] = GEN_INT (INTVAL (operands[2]) << 8 | INTVAL (operands[3]));
12700   return "bextr\t{%2, %1, %0|%0, %1, %2}";
12701 }
12702   [(set_attr "type" "bitmanip")
12703    (set_attr "mode" "<MODE>")])
12704
12705 (define_insn "*tbm_blcfill_<mode>"
12706   [(set (match_operand:SWI48 0 "register_operand" "=r")
12707         (and:SWI48
12708           (plus:SWI48
12709             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12710             (const_int 1))
12711           (match_dup 1)))
12712    (clobber (reg:CC FLAGS_REG))]
12713    "TARGET_TBM"
12714    "blcfill\t{%1, %0|%0, %1}"
12715   [(set_attr "type" "bitmanip")
12716    (set_attr "mode" "<MODE>")])
12717
12718 (define_insn "*tbm_blci_<mode>"
12719   [(set (match_operand:SWI48 0 "register_operand" "=r")
12720         (ior:SWI48
12721           (not:SWI48
12722             (plus:SWI48
12723               (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12724               (const_int 1)))
12725           (match_dup 1)))
12726    (clobber (reg:CC FLAGS_REG))]
12727    "TARGET_TBM"
12728    "blci\t{%1, %0|%0, %1}"
12729   [(set_attr "type" "bitmanip")
12730    (set_attr "mode" "<MODE>")])
12731
12732 (define_insn "*tbm_blcic_<mode>"
12733   [(set (match_operand:SWI48 0 "register_operand" "=r")
12734         (and:SWI48
12735           (plus:SWI48
12736             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12737             (const_int 1))
12738           (not:SWI48
12739             (match_dup 1))))
12740    (clobber (reg:CC FLAGS_REG))]
12741    "TARGET_TBM"
12742    "blcic\t{%1, %0|%0, %1}"
12743   [(set_attr "type" "bitmanip")
12744    (set_attr "mode" "<MODE>")])
12745
12746 (define_insn "*tbm_blcmsk_<mode>"
12747   [(set (match_operand:SWI48 0 "register_operand" "=r")
12748         (xor:SWI48
12749           (plus:SWI48
12750             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12751             (const_int 1))
12752           (match_dup 1)))
12753    (clobber (reg:CC FLAGS_REG))]
12754    "TARGET_TBM"
12755    "blcmsk\t{%1, %0|%0, %1}"
12756   [(set_attr "type" "bitmanip")
12757    (set_attr "mode" "<MODE>")])
12758
12759 (define_insn "*tbm_blcs_<mode>"
12760   [(set (match_operand:SWI48 0 "register_operand" "=r")
12761         (ior:SWI48
12762           (plus:SWI48
12763             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12764             (const_int 1))
12765           (match_dup 1)))
12766    (clobber (reg:CC FLAGS_REG))]
12767    "TARGET_TBM"
12768    "blcs\t{%1, %0|%0, %1}"
12769   [(set_attr "type" "bitmanip")
12770    (set_attr "mode" "<MODE>")])
12771
12772 (define_insn "*tbm_blsfill_<mode>"
12773   [(set (match_operand:SWI48 0 "register_operand" "=r")
12774         (ior:SWI48
12775           (plus:SWI48
12776             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12777             (const_int -1))
12778           (match_dup 1)))
12779    (clobber (reg:CC FLAGS_REG))]
12780    "TARGET_TBM"
12781    "blsfill\t{%1, %0|%0, %1}"
12782   [(set_attr "type" "bitmanip")
12783    (set_attr "mode" "<MODE>")])
12784
12785 (define_insn "*tbm_blsic_<mode>"
12786   [(set (match_operand:SWI48 0 "register_operand" "=r")
12787         (ior:SWI48
12788           (plus:SWI48
12789             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12790             (const_int -1))
12791           (not:SWI48
12792             (match_dup 1))))
12793    (clobber (reg:CC FLAGS_REG))]
12794    "TARGET_TBM"
12795    "blsic\t{%1, %0|%0, %1}"
12796   [(set_attr "type" "bitmanip")
12797    (set_attr "mode" "<MODE>")])
12798
12799 (define_insn "*tbm_t1mskc_<mode>"
12800   [(set (match_operand:SWI48 0 "register_operand" "=r")
12801         (ior:SWI48
12802           (plus:SWI48
12803             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12804             (const_int 1))
12805           (not:SWI48
12806             (match_dup 1))))
12807    (clobber (reg:CC FLAGS_REG))]
12808    "TARGET_TBM"
12809    "t1mskc\t{%1, %0|%0, %1}"
12810   [(set_attr "type" "bitmanip")
12811    (set_attr "mode" "<MODE>")])
12812
12813 (define_insn "*tbm_tzmsk_<mode>"
12814   [(set (match_operand:SWI48 0 "register_operand" "=r")
12815         (and:SWI48
12816           (plus:SWI48
12817             (match_operand:SWI48 1 "nonimmediate_operand" "rm")
12818             (const_int -1))
12819           (not:SWI48
12820             (match_dup 1))))
12821    (clobber (reg:CC FLAGS_REG))]
12822    "TARGET_TBM"
12823    "tzmsk\t{%1, %0|%0, %1}"
12824   [(set_attr "type" "bitmanip")
12825    (set_attr "mode" "<MODE>")])
12826
12827 (define_insn "bsr_rex64"
12828   [(set (match_operand:DI 0 "register_operand" "=r")
12829         (minus:DI (const_int 63)
12830                   (clz:DI (match_operand:DI 1 "nonimmediate_operand" "rm"))))
12831    (clobber (reg:CC FLAGS_REG))]
12832   "TARGET_64BIT"
12833   "bsr{q}\t{%1, %0|%0, %1}"
12834   [(set_attr "type" "alu1")
12835    (set_attr "prefix_0f" "1")
12836    (set_attr "mode" "DI")])
12837
12838 (define_insn "bsr"
12839   [(set (match_operand:SI 0 "register_operand" "=r")
12840         (minus:SI (const_int 31)
12841                   (clz:SI (match_operand:SI 1 "nonimmediate_operand" "rm"))))
12842    (clobber (reg:CC FLAGS_REG))]
12843   ""
12844   "bsr{l}\t{%1, %0|%0, %1}"
12845   [(set_attr "type" "alu1")
12846    (set_attr "prefix_0f" "1")
12847    (set_attr "mode" "SI")])
12848
12849 (define_insn "*bsrhi"
12850   [(set (match_operand:HI 0 "register_operand" "=r")
12851         (minus:HI (const_int 15)
12852                   (clz:HI (match_operand:HI 1 "nonimmediate_operand" "rm"))))
12853    (clobber (reg:CC FLAGS_REG))]
12854   ""
12855   "bsr{w}\t{%1, %0|%0, %1}"
12856   [(set_attr "type" "alu1")
12857    (set_attr "prefix_0f" "1")
12858    (set_attr "mode" "HI")])
12859
12860 (define_expand "popcount<mode>2"
12861   [(parallel
12862     [(set (match_operand:SWI248 0 "register_operand")
12863           (popcount:SWI248
12864             (match_operand:SWI248 1 "nonimmediate_operand")))
12865      (clobber (reg:CC FLAGS_REG))])]
12866   "TARGET_POPCNT")
12867
12868 (define_insn_and_split "*popcount<mode>2_falsedep_1"
12869   [(set (match_operand:SWI48 0 "register_operand" "=r")
12870         (popcount:SWI48
12871           (match_operand:SWI48 1 "nonimmediate_operand" "rm")))
12872    (clobber (reg:CC FLAGS_REG))]
12873   "TARGET_POPCNT
12874    && TARGET_AVOID_FALSE_DEP_FOR_BMI && optimize_function_for_speed_p (cfun)"
12875   "#"
12876   "&& reload_completed"
12877   [(parallel
12878     [(set (match_dup 0)
12879           (popcount:SWI48 (match_dup 1)))
12880      (unspec [(match_dup 0)] UNSPEC_INSN_FALSE_DEP)
12881      (clobber (reg:CC FLAGS_REG))])]
12882 {
12883   if (!reg_mentioned_p (operands[0], operands[1]))
12884     ix86_expand_clear (operands[0]);
12885 })
12886
12887 (define_insn "*popcount<mode>2_falsedep"
12888   [(set (match_operand:SWI48 0 "register_operand" "=r")
12889         (popcount:SWI48
12890           (match_operand:SWI48 1 "nonimmediate_operand" "rm")))
12891    (unspec [(match_operand:SWI48 2 "register_operand" "0")]
12892            UNSPEC_INSN_FALSE_DEP)
12893    (clobber (reg:CC FLAGS_REG))]
12894   "TARGET_POPCNT"
12895 {
12896 #if TARGET_MACHO
12897   return "popcnt\t{%1, %0|%0, %1}";
12898 #else
12899   return "popcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
12900 #endif
12901 }
12902   [(set_attr "prefix_rep" "1")
12903    (set_attr "type" "bitmanip")
12904    (set_attr "mode" "<MODE>")])
12905
12906 (define_insn "*popcount<mode>2"
12907   [(set (match_operand:SWI248 0 "register_operand" "=r")
12908         (popcount:SWI248
12909           (match_operand:SWI248 1 "nonimmediate_operand" "rm")))
12910    (clobber (reg:CC FLAGS_REG))]
12911   "TARGET_POPCNT"
12912 {
12913 #if TARGET_MACHO
12914   return "popcnt\t{%1, %0|%0, %1}";
12915 #else
12916   return "popcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
12917 #endif
12918 }
12919   [(set_attr "prefix_rep" "1")
12920    (set_attr "type" "bitmanip")
12921    (set_attr "mode" "<MODE>")])
12922
12923 (define_expand "bswapdi2"
12924   [(set (match_operand:DI 0 "register_operand")
12925         (bswap:DI (match_operand:DI 1 "nonimmediate_operand")))]
12926   "TARGET_64BIT"
12927 {
12928   if (!TARGET_MOVBE)
12929     operands[1] = force_reg (DImode, operands[1]);
12930 })
12931
12932 (define_expand "bswapsi2"
12933   [(set (match_operand:SI 0 "register_operand")
12934         (bswap:SI (match_operand:SI 1 "nonimmediate_operand")))]
12935   ""
12936 {
12937   if (TARGET_MOVBE)
12938     ;
12939   else if (TARGET_BSWAP)
12940     operands[1] = force_reg (SImode, operands[1]);
12941   else
12942     {
12943       rtx x = operands[0];
12944
12945       emit_move_insn (x, operands[1]);
12946       emit_insn (gen_bswaphi_lowpart (gen_lowpart (HImode, x)));
12947       emit_insn (gen_rotlsi3 (x, x, GEN_INT (16)));
12948       emit_insn (gen_bswaphi_lowpart (gen_lowpart (HImode, x)));
12949       DONE;
12950     }
12951 })
12952
12953 (define_insn "*bswap<mode>2_movbe"
12954   [(set (match_operand:SWI48 0 "nonimmediate_operand" "=r,r,m")
12955         (bswap:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "0,m,r")))]
12956   "TARGET_MOVBE
12957    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
12958   "@
12959     bswap\t%0
12960     movbe\t{%1, %0|%0, %1}
12961     movbe\t{%1, %0|%0, %1}"
12962   [(set_attr "type" "bitmanip,imov,imov")
12963    (set_attr "modrm" "0,1,1")
12964    (set_attr "prefix_0f" "*,1,1")
12965    (set_attr "prefix_extra" "*,1,1")
12966    (set_attr "mode" "<MODE>")])
12967
12968 (define_insn "*bswap<mode>2"
12969   [(set (match_operand:SWI48 0 "register_operand" "=r")
12970         (bswap:SWI48 (match_operand:SWI48 1 "register_operand" "0")))]
12971   "TARGET_BSWAP"
12972   "bswap\t%0"
12973   [(set_attr "type" "bitmanip")
12974    (set_attr "modrm" "0")
12975    (set_attr "mode" "<MODE>")])
12976
12977 (define_insn "*bswaphi_lowpart_1"
12978   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+Q,r"))
12979         (bswap:HI (match_dup 0)))
12980    (clobber (reg:CC FLAGS_REG))]
12981   "TARGET_USE_XCHGB || optimize_function_for_size_p (cfun)"
12982   "@
12983     xchg{b}\t{%h0, %b0|%b0, %h0}
12984     rol{w}\t{$8, %0|%0, 8}"
12985   [(set_attr "length" "2,4")
12986    (set_attr "mode" "QI,HI")])
12987
12988 (define_insn "bswaphi_lowpart"
12989   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+r"))
12990         (bswap:HI (match_dup 0)))
12991    (clobber (reg:CC FLAGS_REG))]
12992   ""
12993   "rol{w}\t{$8, %0|%0, 8}"
12994   [(set_attr "length" "4")
12995    (set_attr "mode" "HI")])
12996
12997 (define_expand "paritydi2"
12998   [(set (match_operand:DI 0 "register_operand")
12999         (parity:DI (match_operand:DI 1 "register_operand")))]
13000   "! TARGET_POPCNT"
13001 {
13002   rtx scratch = gen_reg_rtx (QImode);
13003   rtx cond;
13004
13005   emit_insn (gen_paritydi2_cmp (NULL_RTX, NULL_RTX,
13006                                 NULL_RTX, operands[1]));
13007
13008   cond = gen_rtx_fmt_ee (ORDERED, QImode,
13009                          gen_rtx_REG (CCmode, FLAGS_REG),
13010                          const0_rtx);
13011   emit_insn (gen_rtx_SET (VOIDmode, scratch, cond));
13012
13013   if (TARGET_64BIT)
13014     emit_insn (gen_zero_extendqidi2 (operands[0], scratch));
13015   else
13016     {
13017       rtx tmp = gen_reg_rtx (SImode);
13018
13019       emit_insn (gen_zero_extendqisi2 (tmp, scratch));
13020       emit_insn (gen_zero_extendsidi2 (operands[0], tmp));
13021     }
13022   DONE;
13023 })
13024
13025 (define_expand "paritysi2"
13026   [(set (match_operand:SI 0 "register_operand")
13027         (parity:SI (match_operand:SI 1 "register_operand")))]
13028   "! TARGET_POPCNT"
13029 {
13030   rtx scratch = gen_reg_rtx (QImode);
13031   rtx cond;
13032
13033   emit_insn (gen_paritysi2_cmp (NULL_RTX, NULL_RTX, operands[1]));
13034
13035   cond = gen_rtx_fmt_ee (ORDERED, QImode,
13036                          gen_rtx_REG (CCmode, FLAGS_REG),
13037                          const0_rtx);
13038   emit_insn (gen_rtx_SET (VOIDmode, scratch, cond));
13039
13040   emit_insn (gen_zero_extendqisi2 (operands[0], scratch));
13041   DONE;
13042 })
13043
13044 (define_insn_and_split "paritydi2_cmp"
13045   [(set (reg:CC FLAGS_REG)
13046         (unspec:CC [(match_operand:DI 3 "register_operand" "0")]
13047                    UNSPEC_PARITY))
13048    (clobber (match_scratch:DI 0 "=r"))
13049    (clobber (match_scratch:SI 1 "=&r"))
13050    (clobber (match_scratch:HI 2 "=Q"))]
13051   "! TARGET_POPCNT"
13052   "#"
13053   "&& reload_completed"
13054   [(parallel
13055      [(set (match_dup 1)
13056            (xor:SI (match_dup 1) (match_dup 4)))
13057       (clobber (reg:CC FLAGS_REG))])
13058    (parallel
13059      [(set (reg:CC FLAGS_REG)
13060            (unspec:CC [(match_dup 1)] UNSPEC_PARITY))
13061       (clobber (match_dup 1))
13062       (clobber (match_dup 2))])]
13063 {
13064   operands[4] = gen_lowpart (SImode, operands[3]);
13065
13066   if (TARGET_64BIT)
13067     {
13068       emit_move_insn (operands[1], gen_lowpart (SImode, operands[3]));
13069       emit_insn (gen_lshrdi3 (operands[3], operands[3], GEN_INT (32)));
13070     }
13071   else
13072     operands[1] = gen_highpart (SImode, operands[3]);
13073 })
13074
13075 (define_insn_and_split "paritysi2_cmp"
13076   [(set (reg:CC FLAGS_REG)
13077         (unspec:CC [(match_operand:SI 2 "register_operand" "0")]
13078                    UNSPEC_PARITY))
13079    (clobber (match_scratch:SI 0 "=r"))
13080    (clobber (match_scratch:HI 1 "=&Q"))]
13081   "! TARGET_POPCNT"
13082   "#"
13083   "&& reload_completed"
13084   [(parallel
13085      [(set (match_dup 1)
13086            (xor:HI (match_dup 1) (match_dup 3)))
13087       (clobber (reg:CC FLAGS_REG))])
13088    (parallel
13089      [(set (reg:CC FLAGS_REG)
13090            (unspec:CC [(match_dup 1)] UNSPEC_PARITY))
13091       (clobber (match_dup 1))])]
13092 {
13093   operands[3] = gen_lowpart (HImode, operands[2]);
13094
13095   emit_move_insn (operands[1], gen_lowpart (HImode, operands[2]));
13096   emit_insn (gen_lshrsi3 (operands[2], operands[2], GEN_INT (16)));
13097 })
13098
13099 (define_insn "*parityhi2_cmp"
13100   [(set (reg:CC FLAGS_REG)
13101         (unspec:CC [(match_operand:HI 1 "register_operand" "0")]
13102                    UNSPEC_PARITY))
13103    (clobber (match_scratch:HI 0 "=Q"))]
13104   "! TARGET_POPCNT"
13105   "xor{b}\t{%h0, %b0|%b0, %h0}"
13106   [(set_attr "length" "2")
13107    (set_attr "mode" "HI")])
13108
13109 \f
13110 ;; Thread-local storage patterns for ELF.
13111 ;;
13112 ;; Note that these code sequences must appear exactly as shown
13113 ;; in order to allow linker relaxation.
13114
13115 (define_insn "*tls_global_dynamic_32_gnu"
13116   [(set (match_operand:SI 0 "register_operand" "=a")
13117         (unspec:SI
13118          [(match_operand:SI 1 "register_operand" "b")
13119           (match_operand 2 "tls_symbolic_operand")
13120           (match_operand 3 "constant_call_address_operand" "Bz")
13121           (reg:SI SP_REG)]
13122          UNSPEC_TLS_GD))
13123    (clobber (match_scratch:SI 4 "=d"))
13124    (clobber (match_scratch:SI 5 "=c"))
13125    (clobber (reg:CC FLAGS_REG))]
13126   "!TARGET_64BIT && TARGET_GNU_TLS"
13127 {
13128   output_asm_insn
13129     ("lea{l}\t{%E2@tlsgd(,%1,1), %0|%0, %E2@tlsgd[%1*1]}", operands);
13130   if (TARGET_SUN_TLS)
13131 #ifdef HAVE_AS_IX86_TLSGDPLT
13132     return "call\t%a2@tlsgdplt";
13133 #else
13134     return "call\t%p3@plt";
13135 #endif
13136   return "call\t%P3";
13137 }
13138   [(set_attr "type" "multi")
13139    (set_attr "length" "12")])
13140
13141 (define_expand "tls_global_dynamic_32"
13142   [(parallel
13143     [(set (match_operand:SI 0 "register_operand")
13144           (unspec:SI [(match_operand:SI 2 "register_operand")
13145                       (match_operand 1 "tls_symbolic_operand")
13146                       (match_operand 3 "constant_call_address_operand")
13147                       (reg:SI SP_REG)]
13148                      UNSPEC_TLS_GD))
13149      (clobber (match_scratch:SI 4))
13150      (clobber (match_scratch:SI 5))
13151      (clobber (reg:CC FLAGS_REG))])]
13152   ""
13153   "ix86_tls_descriptor_calls_expanded_in_cfun = true;")
13154
13155 (define_insn "*tls_global_dynamic_64_<mode>"
13156   [(set (match_operand:P 0 "register_operand" "=a")
13157         (call:P
13158          (mem:QI (match_operand 2 "constant_call_address_operand" "Bz"))
13159          (match_operand 3)))
13160    (unspec:P [(match_operand 1 "tls_symbolic_operand")]
13161              UNSPEC_TLS_GD)]
13162   "TARGET_64BIT"
13163 {
13164   if (!TARGET_X32)
13165     fputs (ASM_BYTE "0x66\n", asm_out_file);
13166   output_asm_insn
13167     ("lea{q}\t{%E1@tlsgd(%%rip), %%rdi|rdi, %E1@tlsgd[rip]}", operands);
13168   fputs (ASM_SHORT "0x6666\n", asm_out_file);
13169   fputs ("\trex64\n", asm_out_file);
13170   if (TARGET_SUN_TLS)
13171     return "call\t%p2@plt";
13172   return "call\t%P2";
13173 }
13174   [(set_attr "type" "multi")
13175    (set (attr "length")
13176         (symbol_ref "TARGET_X32 ? 15 : 16"))])
13177
13178 (define_insn "*tls_global_dynamic_64_largepic"
13179   [(set (match_operand:DI 0 "register_operand" "=a")
13180         (call:DI
13181          (mem:QI (plus:DI (match_operand:DI 2 "register_operand" "b")
13182                           (match_operand:DI 3 "immediate_operand" "i")))
13183          (match_operand 4)))
13184    (unspec:DI [(match_operand 1 "tls_symbolic_operand")]
13185              UNSPEC_TLS_GD)]
13186   "TARGET_64BIT && ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF
13187    && GET_CODE (operands[3]) == CONST
13188    && GET_CODE (XEXP (operands[3], 0)) == UNSPEC
13189    && XINT (XEXP (operands[3], 0), 1) == UNSPEC_PLTOFF"
13190 {
13191   output_asm_insn
13192     ("lea{q}\t{%E1@tlsgd(%%rip), %%rdi|rdi, %E1@tlsgd[rip]}", operands);
13193   output_asm_insn ("movabs{q}\t{%3, %%rax|rax, %3}", operands);
13194   output_asm_insn ("add{q}\t{%2, %%rax|rax, %2}", operands);
13195   return "call\t{*%%rax|rax}";
13196 }
13197   [(set_attr "type" "multi")
13198    (set_attr "length" "22")])
13199
13200 (define_expand "tls_global_dynamic_64_<mode>"
13201   [(parallel
13202     [(set (match_operand:P 0 "register_operand")
13203           (call:P
13204            (mem:QI (match_operand 2))
13205            (const_int 0)))
13206      (unspec:P [(match_operand 1 "tls_symbolic_operand")]
13207                UNSPEC_TLS_GD)])]
13208   "TARGET_64BIT"
13209   "ix86_tls_descriptor_calls_expanded_in_cfun = true;")
13210
13211 (define_insn "*tls_local_dynamic_base_32_gnu"
13212   [(set (match_operand:SI 0 "register_operand" "=a")
13213         (unspec:SI
13214          [(match_operand:SI 1 "register_operand" "b")
13215           (match_operand 2 "constant_call_address_operand" "Bz")
13216           (reg:SI SP_REG)]
13217          UNSPEC_TLS_LD_BASE))
13218    (clobber (match_scratch:SI 3 "=d"))
13219    (clobber (match_scratch:SI 4 "=c"))
13220    (clobber (reg:CC FLAGS_REG))]
13221   "!TARGET_64BIT && TARGET_GNU_TLS"
13222 {
13223   output_asm_insn
13224     ("lea{l}\t{%&@tlsldm(%1), %0|%0, %&@tlsldm[%1]}", operands);
13225   if (TARGET_SUN_TLS)
13226     {
13227       if (HAVE_AS_IX86_TLSLDMPLT)
13228         return "call\t%&@tlsldmplt";
13229       else
13230         return "call\t%p2@plt";
13231     }
13232   return "call\t%P2";
13233 }
13234   [(set_attr "type" "multi")
13235    (set_attr "length" "11")])
13236
13237 (define_expand "tls_local_dynamic_base_32"
13238   [(parallel
13239      [(set (match_operand:SI 0 "register_operand")
13240            (unspec:SI
13241             [(match_operand:SI 1 "register_operand")
13242              (match_operand 2 "constant_call_address_operand")
13243              (reg:SI SP_REG)]
13244             UNSPEC_TLS_LD_BASE))
13245       (clobber (match_scratch:SI 3))
13246       (clobber (match_scratch:SI 4))
13247       (clobber (reg:CC FLAGS_REG))])]
13248   ""
13249   "ix86_tls_descriptor_calls_expanded_in_cfun = true;")
13250
13251 (define_insn "*tls_local_dynamic_base_64_<mode>"
13252   [(set (match_operand:P 0 "register_operand" "=a")
13253         (call:P
13254          (mem:QI (match_operand 1 "constant_call_address_operand" "Bz"))
13255          (match_operand 2)))
13256    (unspec:P [(const_int 0)] UNSPEC_TLS_LD_BASE)]
13257   "TARGET_64BIT"
13258 {
13259   output_asm_insn
13260     ("lea{q}\t{%&@tlsld(%%rip), %%rdi|rdi, %&@tlsld[rip]}", operands);
13261   if (TARGET_SUN_TLS)
13262     return "call\t%p1@plt";
13263   return "call\t%P1";
13264 }
13265   [(set_attr "type" "multi")
13266    (set_attr "length" "12")])
13267
13268 (define_insn "*tls_local_dynamic_base_64_largepic"
13269   [(set (match_operand:DI 0 "register_operand" "=a")
13270         (call:DI
13271          (mem:QI (plus:DI (match_operand:DI 1 "register_operand" "b")
13272                           (match_operand:DI 2 "immediate_operand" "i")))
13273          (match_operand 3)))
13274    (unspec:DI [(const_int 0)] UNSPEC_TLS_LD_BASE)]
13275   "TARGET_64BIT && ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF
13276    && GET_CODE (operands[2]) == CONST
13277    && GET_CODE (XEXP (operands[2], 0)) == UNSPEC
13278    && XINT (XEXP (operands[2], 0), 1) == UNSPEC_PLTOFF"
13279 {
13280   output_asm_insn
13281     ("lea{q}\t{%&@tlsld(%%rip), %%rdi|rdi, %&@tlsld[rip]}", operands);
13282   output_asm_insn ("movabs{q}\t{%2, %%rax|rax, %2}", operands);
13283   output_asm_insn ("add{q}\t{%1, %%rax|rax, %1}", operands);
13284   return "call\t{*%%rax|rax}";
13285 }
13286   [(set_attr "type" "multi")
13287    (set_attr "length" "22")])
13288
13289 (define_expand "tls_local_dynamic_base_64_<mode>"
13290   [(parallel
13291      [(set (match_operand:P 0 "register_operand")
13292            (call:P
13293             (mem:QI (match_operand 1))
13294             (const_int 0)))
13295       (unspec:P [(const_int 0)] UNSPEC_TLS_LD_BASE)])]
13296   "TARGET_64BIT"
13297   "ix86_tls_descriptor_calls_expanded_in_cfun = true;")
13298
13299 ;; Local dynamic of a single variable is a lose.  Show combine how
13300 ;; to convert that back to global dynamic.
13301
13302 (define_insn_and_split "*tls_local_dynamic_32_once"
13303   [(set (match_operand:SI 0 "register_operand" "=a")
13304         (plus:SI
13305          (unspec:SI [(match_operand:SI 1 "register_operand" "b")
13306                      (match_operand 2 "constant_call_address_operand" "Bz")
13307                      (reg:SI SP_REG)]
13308                     UNSPEC_TLS_LD_BASE)
13309          (const:SI (unspec:SI
13310                     [(match_operand 3 "tls_symbolic_operand")]
13311                     UNSPEC_DTPOFF))))
13312    (clobber (match_scratch:SI 4 "=d"))
13313    (clobber (match_scratch:SI 5 "=c"))
13314    (clobber (reg:CC FLAGS_REG))]
13315   ""
13316   "#"
13317   ""
13318   [(parallel
13319      [(set (match_dup 0)
13320            (unspec:SI [(match_dup 1) (match_dup 3) (match_dup 2)
13321                        (reg:SI SP_REG)]
13322                       UNSPEC_TLS_GD))
13323       (clobber (match_dup 4))
13324       (clobber (match_dup 5))
13325       (clobber (reg:CC FLAGS_REG))])])
13326
13327 ;; Segment register for the thread base ptr load
13328 (define_mode_attr tp_seg [(SI "gs") (DI "fs")])
13329
13330 ;; Load and add the thread base pointer from %<tp_seg>:0.
13331 (define_insn "*load_tp_x32"
13332   [(set (match_operand:SI 0 "register_operand" "=r")
13333         (unspec:SI [(const_int 0)] UNSPEC_TP))]
13334   "TARGET_X32"
13335   "mov{l}\t{%%fs:0, %0|%0, DWORD PTR fs:0}"
13336   [(set_attr "type" "imov")
13337    (set_attr "modrm" "0")
13338    (set_attr "length" "7")
13339    (set_attr "memory" "load")
13340    (set_attr "imm_disp" "false")])
13341
13342 (define_insn "*load_tp_x32_zext"
13343   [(set (match_operand:DI 0 "register_operand" "=r")
13344         (zero_extend:DI (unspec:SI [(const_int 0)] UNSPEC_TP)))]
13345   "TARGET_X32"
13346   "mov{l}\t{%%fs:0, %k0|%k0, DWORD PTR fs:0}"
13347   [(set_attr "type" "imov")
13348    (set_attr "modrm" "0")
13349    (set_attr "length" "7")
13350    (set_attr "memory" "load")
13351    (set_attr "imm_disp" "false")])
13352
13353 (define_insn "*load_tp_<mode>"
13354   [(set (match_operand:P 0 "register_operand" "=r")
13355         (unspec:P [(const_int 0)] UNSPEC_TP))]
13356   "!TARGET_X32"
13357   "mov{<imodesuffix>}\t{%%<tp_seg>:0, %0|%0, <iptrsize> PTR <tp_seg>:0}"
13358   [(set_attr "type" "imov")
13359    (set_attr "modrm" "0")
13360    (set_attr "length" "7")
13361    (set_attr "memory" "load")
13362    (set_attr "imm_disp" "false")])
13363
13364 (define_insn "*add_tp_x32"
13365   [(set (match_operand:SI 0 "register_operand" "=r")
13366         (plus:SI (unspec:SI [(const_int 0)] UNSPEC_TP)
13367                  (match_operand:SI 1 "register_operand" "0")))
13368    (clobber (reg:CC FLAGS_REG))]
13369   "TARGET_X32"
13370   "add{l}\t{%%fs:0, %0|%0, DWORD PTR fs:0}"
13371   [(set_attr "type" "alu")
13372    (set_attr "modrm" "0")
13373    (set_attr "length" "7")
13374    (set_attr "memory" "load")
13375    (set_attr "imm_disp" "false")])
13376
13377 (define_insn "*add_tp_x32_zext"
13378   [(set (match_operand:DI 0 "register_operand" "=r")
13379         (zero_extend:DI
13380           (plus:SI (unspec:SI [(const_int 0)] UNSPEC_TP)
13381                    (match_operand:SI 1 "register_operand" "0"))))
13382    (clobber (reg:CC FLAGS_REG))]
13383   "TARGET_X32"
13384   "add{l}\t{%%fs:0, %k0|%k0, DWORD PTR fs:0}"
13385   [(set_attr "type" "alu")
13386    (set_attr "modrm" "0")
13387    (set_attr "length" "7")
13388    (set_attr "memory" "load")
13389    (set_attr "imm_disp" "false")])
13390
13391 (define_insn "*add_tp_<mode>"
13392   [(set (match_operand:P 0 "register_operand" "=r")
13393         (plus:P (unspec:P [(const_int 0)] UNSPEC_TP)
13394                 (match_operand:P 1 "register_operand" "0")))
13395    (clobber (reg:CC FLAGS_REG))]
13396   "!TARGET_X32"
13397   "add{<imodesuffix>}\t{%%<tp_seg>:0, %0|%0, <iptrsize> PTR <tp_seg>:0}"
13398   [(set_attr "type" "alu")
13399    (set_attr "modrm" "0")
13400    (set_attr "length" "7")
13401    (set_attr "memory" "load")
13402    (set_attr "imm_disp" "false")])
13403
13404 ;; The Sun linker took the AMD64 TLS spec literally and can only handle
13405 ;; %rax as destination of the initial executable code sequence.
13406 (define_insn "tls_initial_exec_64_sun"
13407   [(set (match_operand:DI 0 "register_operand" "=a")
13408         (unspec:DI
13409          [(match_operand 1 "tls_symbolic_operand")]
13410          UNSPEC_TLS_IE_SUN))
13411    (clobber (reg:CC FLAGS_REG))]
13412   "TARGET_64BIT && TARGET_SUN_TLS"
13413 {
13414   output_asm_insn
13415     ("mov{q}\t{%%fs:0, %0|%0, QWORD PTR fs:0}", operands);
13416   return "add{q}\t{%a1@gottpoff(%%rip), %0|%0, %a1@gottpoff[rip]}";
13417 }
13418   [(set_attr "type" "multi")])
13419
13420 ;; GNU2 TLS patterns can be split.
13421
13422 (define_expand "tls_dynamic_gnu2_32"
13423   [(set (match_dup 3)
13424         (plus:SI (match_operand:SI 2 "register_operand")
13425                  (const:SI
13426                   (unspec:SI [(match_operand 1 "tls_symbolic_operand")]
13427                              UNSPEC_TLSDESC))))
13428    (parallel
13429     [(set (match_operand:SI 0 "register_operand")
13430           (unspec:SI [(match_dup 1) (match_dup 3)
13431                       (match_dup 2) (reg:SI SP_REG)]
13432                       UNSPEC_TLSDESC))
13433      (clobber (reg:CC FLAGS_REG))])]
13434   "!TARGET_64BIT && TARGET_GNU2_TLS"
13435 {
13436   operands[3] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
13437   ix86_tls_descriptor_calls_expanded_in_cfun = true;
13438 })
13439
13440 (define_insn "*tls_dynamic_gnu2_lea_32"
13441   [(set (match_operand:SI 0 "register_operand" "=r")
13442         (plus:SI (match_operand:SI 1 "register_operand" "b")
13443                  (const:SI
13444                   (unspec:SI [(match_operand 2 "tls_symbolic_operand")]
13445                               UNSPEC_TLSDESC))))]
13446   "!TARGET_64BIT && TARGET_GNU2_TLS"
13447   "lea{l}\t{%E2@TLSDESC(%1), %0|%0, %E2@TLSDESC[%1]}"
13448   [(set_attr "type" "lea")
13449    (set_attr "mode" "SI")
13450    (set_attr "length" "6")
13451    (set_attr "length_address" "4")])
13452
13453 (define_insn "*tls_dynamic_gnu2_call_32"
13454   [(set (match_operand:SI 0 "register_operand" "=a")
13455         (unspec:SI [(match_operand 1 "tls_symbolic_operand")
13456                     (match_operand:SI 2 "register_operand" "0")
13457                     ;; we have to make sure %ebx still points to the GOT
13458                     (match_operand:SI 3 "register_operand" "b")
13459                     (reg:SI SP_REG)]
13460                    UNSPEC_TLSDESC))
13461    (clobber (reg:CC FLAGS_REG))]
13462   "!TARGET_64BIT && TARGET_GNU2_TLS"
13463   "call\t{*%a1@TLSCALL(%2)|[DWORD PTR [%2+%a1@TLSCALL]]}"
13464   [(set_attr "type" "call")
13465    (set_attr "length" "2")
13466    (set_attr "length_address" "0")])
13467
13468 (define_insn_and_split "*tls_dynamic_gnu2_combine_32"
13469   [(set (match_operand:SI 0 "register_operand" "=&a")
13470         (plus:SI
13471          (unspec:SI [(match_operand 3 "tls_modbase_operand")
13472                      (match_operand:SI 4)
13473                      (match_operand:SI 2 "register_operand" "b")
13474                      (reg:SI SP_REG)]
13475                     UNSPEC_TLSDESC)
13476          (const:SI (unspec:SI
13477                     [(match_operand 1 "tls_symbolic_operand")]
13478                     UNSPEC_DTPOFF))))
13479    (clobber (reg:CC FLAGS_REG))]
13480   "!TARGET_64BIT && TARGET_GNU2_TLS"
13481   "#"
13482   ""
13483   [(set (match_dup 0) (match_dup 5))]
13484 {
13485   operands[5] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
13486   emit_insn (gen_tls_dynamic_gnu2_32 (operands[5], operands[1], operands[2]));
13487 })
13488
13489 (define_expand "tls_dynamic_gnu2_64"
13490   [(set (match_dup 2)
13491         (unspec:DI [(match_operand 1 "tls_symbolic_operand")]
13492                    UNSPEC_TLSDESC))
13493    (parallel
13494     [(set (match_operand:DI 0 "register_operand")
13495           (unspec:DI [(match_dup 1) (match_dup 2) (reg:DI SP_REG)]
13496                      UNSPEC_TLSDESC))
13497      (clobber (reg:CC FLAGS_REG))])]
13498   "TARGET_64BIT && TARGET_GNU2_TLS"
13499 {
13500   operands[2] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
13501   ix86_tls_descriptor_calls_expanded_in_cfun = true;
13502 })
13503
13504 (define_insn "*tls_dynamic_gnu2_lea_64"
13505   [(set (match_operand:DI 0 "register_operand" "=r")
13506         (unspec:DI [(match_operand 1 "tls_symbolic_operand")]
13507                    UNSPEC_TLSDESC))]
13508   "TARGET_64BIT && TARGET_GNU2_TLS"
13509   "lea{q}\t{%E1@TLSDESC(%%rip), %0|%0, %E1@TLSDESC[rip]}"
13510   [(set_attr "type" "lea")
13511    (set_attr "mode" "DI")
13512    (set_attr "length" "7")
13513    (set_attr "length_address" "4")])
13514
13515 (define_insn "*tls_dynamic_gnu2_call_64"
13516   [(set (match_operand:DI 0 "register_operand" "=a")
13517         (unspec:DI [(match_operand 1 "tls_symbolic_operand")
13518                     (match_operand:DI 2 "register_operand" "0")
13519                     (reg:DI SP_REG)]
13520                    UNSPEC_TLSDESC))
13521    (clobber (reg:CC FLAGS_REG))]
13522   "TARGET_64BIT && TARGET_GNU2_TLS"
13523   "call\t{*%a1@TLSCALL(%2)|[QWORD PTR [%2+%a1@TLSCALL]]}"
13524   [(set_attr "type" "call")
13525    (set_attr "length" "2")
13526    (set_attr "length_address" "0")])
13527
13528 (define_insn_and_split "*tls_dynamic_gnu2_combine_64"
13529   [(set (match_operand:DI 0 "register_operand" "=&a")
13530         (plus:DI
13531          (unspec:DI [(match_operand 2 "tls_modbase_operand")
13532                      (match_operand:DI 3)
13533                      (reg:DI SP_REG)]
13534                     UNSPEC_TLSDESC)
13535          (const:DI (unspec:DI
13536                     [(match_operand 1 "tls_symbolic_operand")]
13537                     UNSPEC_DTPOFF))))
13538    (clobber (reg:CC FLAGS_REG))]
13539   "TARGET_64BIT && TARGET_GNU2_TLS"
13540   "#"
13541   ""
13542   [(set (match_dup 0) (match_dup 4))]
13543 {
13544   operands[4] = can_create_pseudo_p () ? gen_reg_rtx (Pmode) : operands[0];
13545   emit_insn (gen_tls_dynamic_gnu2_64 (operands[4], operands[1]));
13546 })
13547 \f
13548 ;; These patterns match the binary 387 instructions for addM3, subM3,
13549 ;; mulM3 and divM3.  There are three patterns for each of DFmode and
13550 ;; SFmode.  The first is the normal insn, the second the same insn but
13551 ;; with one operand a conversion, and the third the same insn but with
13552 ;; the other operand a conversion.  The conversion may be SFmode or
13553 ;; SImode if the target mode DFmode, but only SImode if the target mode
13554 ;; is SFmode.
13555
13556 ;; Gcc is slightly more smart about handling normal two address instructions
13557 ;; so use special patterns for add and mull.
13558
13559 (define_insn "*fop_<mode>_comm_mixed"
13560   [(set (match_operand:MODEF 0 "register_operand" "=f,x,x")
13561         (match_operator:MODEF 3 "binary_fp_operator"
13562           [(match_operand:MODEF 1 "nonimmediate_operand" "%0,0,x")
13563            (match_operand:MODEF 2 "nonimmediate_operand" "fm,xm,xm")]))]
13564   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_MIX_SSE_I387
13565    && COMMUTATIVE_ARITH_P (operands[3])
13566    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
13567   "* return output_387_binary_op (insn, operands);"
13568   [(set (attr "type")
13569         (if_then_else (eq_attr "alternative" "1,2")
13570            (if_then_else (match_operand:MODEF 3 "mult_operator")
13571               (const_string "ssemul")
13572               (const_string "sseadd"))
13573            (if_then_else (match_operand:MODEF 3 "mult_operator")
13574               (const_string "fmul")
13575               (const_string "fop"))))
13576    (set_attr "isa" "*,noavx,avx")
13577    (set_attr "prefix" "orig,orig,vex")
13578    (set_attr "mode" "<MODE>")])
13579
13580 (define_insn "*fop_<mode>_comm_sse"
13581   [(set (match_operand:MODEF 0 "register_operand" "=x,v")
13582         (match_operator:MODEF 3 "binary_fp_operator"
13583           [(match_operand:MODEF 1 "nonimmediate_operand" "%0,v")
13584            (match_operand:MODEF 2 "nonimmediate_operand" "xm,vm")]))]
13585   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
13586    && COMMUTATIVE_ARITH_P (operands[3])
13587    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
13588   "* return output_387_binary_op (insn, operands);"
13589   [(set (attr "type")
13590         (if_then_else (match_operand:MODEF 3 "mult_operator")
13591            (const_string "ssemul")
13592            (const_string "sseadd")))
13593    (set_attr "isa" "noavx,avx")
13594    (set_attr "prefix" "orig,vex")
13595    (set_attr "mode" "<MODE>")])
13596
13597 (define_insn "*fop_<mode>_comm_i387"
13598   [(set (match_operand:MODEF 0 "register_operand" "=f")
13599         (match_operator:MODEF 3 "binary_fp_operator"
13600           [(match_operand:MODEF 1 "nonimmediate_operand" "%0")
13601            (match_operand:MODEF 2 "nonimmediate_operand" "fm")]))]
13602   "TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode)
13603    && COMMUTATIVE_ARITH_P (operands[3])
13604    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
13605   "* return output_387_binary_op (insn, operands);"
13606   [(set (attr "type")
13607         (if_then_else (match_operand:MODEF 3 "mult_operator")
13608            (const_string "fmul")
13609            (const_string "fop")))
13610    (set_attr "mode" "<MODE>")])
13611
13612 (define_insn "*fop_<mode>_1_mixed"
13613   [(set (match_operand:MODEF 0 "register_operand" "=f,f,x,x")
13614         (match_operator:MODEF 3 "binary_fp_operator"
13615           [(match_operand:MODEF 1 "nonimmediate_operand" "0,fm,0,x")
13616            (match_operand:MODEF 2 "nonimmediate_operand" "fm,0,xm,xm")]))]
13617   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_MIX_SSE_I387
13618    && !COMMUTATIVE_ARITH_P (operands[3])
13619    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
13620   "* return output_387_binary_op (insn, operands);"
13621   [(set (attr "type")
13622         (cond [(and (eq_attr "alternative" "2,3")
13623                     (match_operand:MODEF 3 "mult_operator"))
13624                  (const_string "ssemul")
13625                (and (eq_attr "alternative" "2,3")
13626                     (match_operand:MODEF 3 "div_operator"))
13627                  (const_string "ssediv")
13628                (eq_attr "alternative" "2,3")
13629                  (const_string "sseadd")
13630                (match_operand:MODEF 3 "mult_operator")
13631                  (const_string "fmul")
13632                (match_operand:MODEF 3 "div_operator")
13633                  (const_string "fdiv")
13634               ]
13635               (const_string "fop")))
13636    (set_attr "isa" "*,*,noavx,avx")
13637    (set_attr "prefix" "orig,orig,orig,vex")
13638    (set_attr "mode" "<MODE>")])
13639
13640 (define_insn "*rcpsf2_sse"
13641   [(set (match_operand:SF 0 "register_operand" "=x")
13642         (unspec:SF [(match_operand:SF 1 "nonimmediate_operand" "xm")]
13643                    UNSPEC_RCP))]
13644   "TARGET_SSE_MATH"
13645   "%vrcpss\t{%1, %d0|%d0, %1}"
13646   [(set_attr "type" "sse")
13647    (set_attr "atom_sse_attr" "rcp")
13648    (set_attr "btver2_sse_attr" "rcp")
13649    (set_attr "prefix" "maybe_vex")
13650    (set_attr "mode" "SF")])
13651
13652 (define_insn "*fop_<mode>_1_sse"
13653   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
13654         (match_operator:MODEF 3 "binary_fp_operator"
13655           [(match_operand:MODEF 1 "register_operand" "0,x")
13656            (match_operand:MODEF 2 "nonimmediate_operand" "xm,xm")]))]
13657   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
13658    && !COMMUTATIVE_ARITH_P (operands[3])"
13659   "* return output_387_binary_op (insn, operands);"
13660   [(set (attr "type")
13661         (cond [(match_operand:MODEF 3 "mult_operator")
13662                  (const_string "ssemul")
13663                (match_operand:MODEF 3 "div_operator")
13664                  (const_string "ssediv")
13665               ]
13666               (const_string "sseadd")))
13667    (set_attr "isa" "noavx,avx")
13668    (set_attr "prefix" "orig,vex")
13669    (set_attr "mode" "<MODE>")])
13670
13671 ;; This pattern is not fully shadowed by the pattern above.
13672 (define_insn "*fop_<mode>_1_i387"
13673   [(set (match_operand:MODEF 0 "register_operand" "=f,f")
13674         (match_operator:MODEF 3 "binary_fp_operator"
13675           [(match_operand:MODEF 1 "nonimmediate_operand" "0,fm")
13676            (match_operand:MODEF 2 "nonimmediate_operand" "fm,0")]))]
13677   "TARGET_80387 && X87_ENABLE_ARITH (<MODE>mode)
13678    && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
13679    && !COMMUTATIVE_ARITH_P (operands[3])
13680    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
13681   "* return output_387_binary_op (insn, operands);"
13682   [(set (attr "type")
13683         (cond [(match_operand:MODEF 3 "mult_operator")
13684                  (const_string "fmul")
13685                (match_operand:MODEF 3 "div_operator")
13686                  (const_string "fdiv")
13687               ]
13688               (const_string "fop")))
13689    (set_attr "mode" "<MODE>")])
13690
13691 ;; ??? Add SSE splitters for these!
13692 (define_insn "*fop_<MODEF:mode>_2_i387"
13693   [(set (match_operand:MODEF 0 "register_operand" "=f")
13694         (match_operator:MODEF 3 "binary_fp_operator"
13695           [(float:MODEF
13696              (match_operand:SWI24 1 "nonimmediate_operand" "m"))
13697            (match_operand:MODEF 2 "register_operand" "0")]))]
13698   "TARGET_80387 && X87_ENABLE_FLOAT (<MODEF:MODE>mode, <SWI24:MODE>mode)
13699    && !(SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH)
13700    && (TARGET_USE_<SWI24:MODE>MODE_FIOP
13701        || optimize_function_for_size_p (cfun))"
13702   { return output_387_binary_op (insn, operands); }
13703   [(set (attr "type")
13704         (cond [(match_operand:MODEF 3 "mult_operator")
13705                  (const_string "fmul")
13706                (match_operand:MODEF 3 "div_operator")
13707                  (const_string "fdiv")
13708               ]
13709               (const_string "fop")))
13710    (set_attr "fp_int_src" "true")
13711    (set_attr "mode" "<SWI24:MODE>")])
13712
13713 (define_insn "*fop_<MODEF:mode>_3_i387"
13714   [(set (match_operand:MODEF 0 "register_operand" "=f")
13715         (match_operator:MODEF 3 "binary_fp_operator"
13716           [(match_operand:MODEF 1 "register_operand" "0")
13717            (float:MODEF
13718              (match_operand:SWI24 2 "nonimmediate_operand" "m"))]))]
13719   "TARGET_80387 && X87_ENABLE_FLOAT (<MODEF:MODE>mode, <SWI24:MODE>mode)
13720    && !(SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH)
13721    && (TARGET_USE_<SWI24:MODE>MODE_FIOP
13722        || optimize_function_for_size_p (cfun))"
13723   { return output_387_binary_op (insn, operands); }
13724   [(set (attr "type")
13725         (cond [(match_operand:MODEF 3 "mult_operator")
13726                  (const_string "fmul")
13727                (match_operand:MODEF 3 "div_operator")
13728                  (const_string "fdiv")
13729               ]
13730               (const_string "fop")))
13731    (set_attr "fp_int_src" "true")
13732    (set_attr "mode" "<MODE>")])
13733
13734 (define_insn "*fop_df_4_i387"
13735   [(set (match_operand:DF 0 "register_operand" "=f,f")
13736         (match_operator:DF 3 "binary_fp_operator"
13737            [(float_extend:DF
13738              (match_operand:SF 1 "nonimmediate_operand" "fm,0"))
13739             (match_operand:DF 2 "register_operand" "0,f")]))]
13740   "TARGET_80387 && X87_ENABLE_ARITH (DFmode)
13741    && !(TARGET_SSE2 && TARGET_SSE_MATH)
13742    && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
13743   "* return output_387_binary_op (insn, operands);"
13744   [(set (attr "type")
13745         (cond [(match_operand:DF 3 "mult_operator")
13746                  (const_string "fmul")
13747                (match_operand:DF 3 "div_operator")
13748                  (const_string "fdiv")
13749               ]
13750               (const_string "fop")))
13751    (set_attr "mode" "SF")])
13752
13753 (define_insn "*fop_df_5_i387"
13754   [(set (match_operand:DF 0 "register_operand" "=f,f")
13755         (match_operator:DF 3 "binary_fp_operator"
13756           [(match_operand:DF 1 "register_operand" "0,f")
13757            (float_extend:DF
13758             (match_operand:SF 2 "nonimmediate_operand" "fm,0"))]))]
13759   "TARGET_80387 && X87_ENABLE_ARITH (DFmode)
13760    && !(TARGET_SSE2 && TARGET_SSE_MATH)"
13761   "* return output_387_binary_op (insn, operands);"
13762   [(set (attr "type")
13763         (cond [(match_operand:DF 3 "mult_operator")
13764                  (const_string "fmul")
13765                (match_operand:DF 3 "div_operator")
13766                  (const_string "fdiv")
13767               ]
13768               (const_string "fop")))
13769    (set_attr "mode" "SF")])
13770
13771 (define_insn "*fop_df_6_i387"
13772   [(set (match_operand:DF 0 "register_operand" "=f,f")
13773         (match_operator:DF 3 "binary_fp_operator"
13774           [(float_extend:DF
13775             (match_operand:SF 1 "register_operand" "0,f"))
13776            (float_extend:DF
13777             (match_operand:SF 2 "nonimmediate_operand" "fm,0"))]))]
13778   "TARGET_80387 && X87_ENABLE_ARITH (DFmode)
13779    && !(TARGET_SSE2 && TARGET_SSE_MATH)"
13780   "* return output_387_binary_op (insn, operands);"
13781   [(set (attr "type")
13782         (cond [(match_operand:DF 3 "mult_operator")
13783                  (const_string "fmul")
13784                (match_operand:DF 3 "div_operator")
13785                  (const_string "fdiv")
13786               ]
13787               (const_string "fop")))
13788    (set_attr "mode" "SF")])
13789
13790 (define_insn "*fop_xf_comm_i387"
13791   [(set (match_operand:XF 0 "register_operand" "=f")
13792         (match_operator:XF 3 "binary_fp_operator"
13793                         [(match_operand:XF 1 "register_operand" "%0")
13794                          (match_operand:XF 2 "register_operand" "f")]))]
13795   "TARGET_80387
13796    && COMMUTATIVE_ARITH_P (operands[3])"
13797   "* return output_387_binary_op (insn, operands);"
13798   [(set (attr "type")
13799         (if_then_else (match_operand:XF 3 "mult_operator")
13800            (const_string "fmul")
13801            (const_string "fop")))
13802    (set_attr "mode" "XF")])
13803
13804 (define_insn "*fop_xf_1_i387"
13805   [(set (match_operand:XF 0 "register_operand" "=f,f")
13806         (match_operator:XF 3 "binary_fp_operator"
13807                         [(match_operand:XF 1 "register_operand" "0,f")
13808                          (match_operand:XF 2 "register_operand" "f,0")]))]
13809   "TARGET_80387
13810    && !COMMUTATIVE_ARITH_P (operands[3])"
13811   "* return output_387_binary_op (insn, operands);"
13812   [(set (attr "type")
13813         (cond [(match_operand:XF 3 "mult_operator")
13814                  (const_string "fmul")
13815                (match_operand:XF 3 "div_operator")
13816                  (const_string "fdiv")
13817               ]
13818               (const_string "fop")))
13819    (set_attr "mode" "XF")])
13820
13821 (define_insn "*fop_xf_2_i387"
13822   [(set (match_operand:XF 0 "register_operand" "=f")
13823         (match_operator:XF 3 "binary_fp_operator"
13824           [(float:XF
13825              (match_operand:SWI24 1 "nonimmediate_operand" "m"))
13826            (match_operand:XF 2 "register_operand" "0")]))]
13827   "TARGET_80387
13828    && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))"
13829   { return output_387_binary_op (insn, operands); }
13830   [(set (attr "type")
13831         (cond [(match_operand:XF 3 "mult_operator")
13832                  (const_string "fmul")
13833                (match_operand:XF 3 "div_operator")
13834                  (const_string "fdiv")
13835               ]
13836               (const_string "fop")))
13837    (set_attr "fp_int_src" "true")
13838    (set_attr "mode" "<MODE>")])
13839
13840 (define_insn "*fop_xf_3_i387"
13841   [(set (match_operand:XF 0 "register_operand" "=f")
13842         (match_operator:XF 3 "binary_fp_operator"
13843           [(match_operand:XF 1 "register_operand" "0")
13844            (float:XF
13845              (match_operand:SWI24 2 "nonimmediate_operand" "m"))]))]
13846   "TARGET_80387
13847    && (TARGET_USE_<MODE>MODE_FIOP || optimize_function_for_size_p (cfun))"
13848   { return output_387_binary_op (insn, operands); }
13849   [(set (attr "type")
13850         (cond [(match_operand:XF 3 "mult_operator")
13851                  (const_string "fmul")
13852                (match_operand:XF 3 "div_operator")
13853                  (const_string "fdiv")
13854               ]
13855               (const_string "fop")))
13856    (set_attr "fp_int_src" "true")
13857    (set_attr "mode" "<MODE>")])
13858
13859 (define_insn "*fop_xf_4_i387"
13860   [(set (match_operand:XF 0 "register_operand" "=f,f")
13861         (match_operator:XF 3 "binary_fp_operator"
13862            [(float_extend:XF
13863               (match_operand:MODEF 1 "nonimmediate_operand" "fm,0"))
13864             (match_operand:XF 2 "register_operand" "0,f")]))]
13865   "TARGET_80387"
13866   "* return output_387_binary_op (insn, operands);"
13867   [(set (attr "type")
13868         (cond [(match_operand:XF 3 "mult_operator")
13869                  (const_string "fmul")
13870                (match_operand:XF 3 "div_operator")
13871                  (const_string "fdiv")
13872               ]
13873               (const_string "fop")))
13874    (set_attr "mode" "<MODE>")])
13875
13876 (define_insn "*fop_xf_5_i387"
13877   [(set (match_operand:XF 0 "register_operand" "=f,f")
13878         (match_operator:XF 3 "binary_fp_operator"
13879           [(match_operand:XF 1 "register_operand" "0,f")
13880            (float_extend:XF
13881              (match_operand:MODEF 2 "nonimmediate_operand" "fm,0"))]))]
13882   "TARGET_80387"
13883   "* return output_387_binary_op (insn, operands);"
13884   [(set (attr "type")
13885         (cond [(match_operand:XF 3 "mult_operator")
13886                  (const_string "fmul")
13887                (match_operand:XF 3 "div_operator")
13888                  (const_string "fdiv")
13889               ]
13890               (const_string "fop")))
13891    (set_attr "mode" "<MODE>")])
13892
13893 (define_insn "*fop_xf_6_i387"
13894   [(set (match_operand:XF 0 "register_operand" "=f,f")
13895         (match_operator:XF 3 "binary_fp_operator"
13896           [(float_extend:XF
13897              (match_operand:MODEF 1 "register_operand" "0,f"))
13898            (float_extend:XF
13899              (match_operand:MODEF 2 "nonimmediate_operand" "fm,0"))]))]
13900   "TARGET_80387"
13901   "* return output_387_binary_op (insn, operands);"
13902   [(set (attr "type")
13903         (cond [(match_operand:XF 3 "mult_operator")
13904                  (const_string "fmul")
13905                (match_operand:XF 3 "div_operator")
13906                  (const_string "fdiv")
13907               ]
13908               (const_string "fop")))
13909    (set_attr "mode" "<MODE>")])
13910 \f
13911 ;; FPU special functions.
13912
13913 ;; This pattern implements a no-op XFmode truncation for
13914 ;; all fancy i386 XFmode math functions.
13915
13916 (define_insn "truncxf<mode>2_i387_noop_unspec"
13917   [(set (match_operand:MODEF 0 "register_operand" "=f")
13918         (unspec:MODEF [(match_operand:XF 1 "register_operand" "f")]
13919         UNSPEC_TRUNC_NOOP))]
13920   "TARGET_USE_FANCY_MATH_387"
13921   "* return output_387_reg_move (insn, operands);"
13922   [(set_attr "type" "fmov")
13923    (set_attr "mode" "<MODE>")])
13924
13925 (define_insn "sqrtxf2"
13926   [(set (match_operand:XF 0 "register_operand" "=f")
13927         (sqrt:XF (match_operand:XF 1 "register_operand" "0")))]
13928   "TARGET_USE_FANCY_MATH_387"
13929   "fsqrt"
13930   [(set_attr "type" "fpspc")
13931    (set_attr "mode" "XF")
13932    (set_attr "athlon_decode" "direct")
13933    (set_attr "amdfam10_decode" "direct")
13934    (set_attr "bdver1_decode" "direct")])
13935
13936 (define_insn "sqrt_extend<mode>xf2_i387"
13937   [(set (match_operand:XF 0 "register_operand" "=f")
13938         (sqrt:XF
13939           (float_extend:XF
13940             (match_operand:MODEF 1 "register_operand" "0"))))]
13941   "TARGET_USE_FANCY_MATH_387"
13942   "fsqrt"
13943   [(set_attr "type" "fpspc")
13944    (set_attr "mode" "XF")
13945    (set_attr "athlon_decode" "direct")
13946    (set_attr "amdfam10_decode" "direct")
13947    (set_attr "bdver1_decode" "direct")])
13948
13949 (define_insn "*rsqrtsf2_sse"
13950   [(set (match_operand:SF 0 "register_operand" "=x")
13951         (unspec:SF [(match_operand:SF 1 "nonimmediate_operand" "xm")]
13952                    UNSPEC_RSQRT))]
13953   "TARGET_SSE_MATH"
13954   "%vrsqrtss\t{%1, %d0|%d0, %1}"
13955   [(set_attr "type" "sse")
13956    (set_attr "atom_sse_attr" "rcp")
13957    (set_attr "btver2_sse_attr" "rcp")
13958    (set_attr "prefix" "maybe_vex")
13959    (set_attr "mode" "SF")])
13960
13961 (define_expand "rsqrtsf2"
13962   [(set (match_operand:SF 0 "register_operand")
13963         (unspec:SF [(match_operand:SF 1 "nonimmediate_operand")]
13964                    UNSPEC_RSQRT))]
13965   "TARGET_SSE_MATH"
13966 {
13967   ix86_emit_swsqrtsf (operands[0], operands[1], SFmode, 1);
13968   DONE;
13969 })
13970
13971 (define_insn "*sqrt<mode>2_sse"
13972   [(set (match_operand:MODEF 0 "register_operand" "=x")
13973         (sqrt:MODEF
13974           (match_operand:MODEF 1 "nonimmediate_operand" "xm")))]
13975   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
13976   "%vsqrt<ssemodesuffix>\t{%1, %d0|%d0, %1}"
13977   [(set_attr "type" "sse")
13978    (set_attr "atom_sse_attr" "sqrt")
13979    (set_attr "btver2_sse_attr" "sqrt")
13980    (set_attr "prefix" "maybe_vex")
13981    (set_attr "mode" "<MODE>")
13982    (set_attr "athlon_decode" "*")
13983    (set_attr "amdfam10_decode" "*")
13984    (set_attr "bdver1_decode" "*")])
13985
13986 (define_expand "sqrt<mode>2"
13987   [(set (match_operand:MODEF 0 "register_operand")
13988         (sqrt:MODEF
13989           (match_operand:MODEF 1 "nonimmediate_operand")))]
13990   "(TARGET_USE_FANCY_MATH_387 && X87_ENABLE_ARITH (<MODE>mode))
13991    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
13992 {
13993   if (<MODE>mode == SFmode
13994       && TARGET_SSE_MATH
13995       && TARGET_RECIP_SQRT
13996       && !optimize_function_for_size_p (cfun)
13997       && flag_finite_math_only && !flag_trapping_math
13998       && flag_unsafe_math_optimizations)
13999     {
14000       ix86_emit_swsqrtsf (operands[0], operands[1], SFmode, 0);
14001       DONE;
14002     }
14003
14004   if (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH))
14005     {
14006       rtx op0 = gen_reg_rtx (XFmode);
14007       rtx op1 = force_reg (<MODE>mode, operands[1]);
14008
14009       emit_insn (gen_sqrt_extend<mode>xf2_i387 (op0, op1));
14010       emit_insn (gen_truncxf<mode>2_i387_noop_unspec (operands[0], op0));
14011       DONE;
14012    }
14013 })
14014
14015 (define_insn "fpremxf4_i387"
14016   [(set (match_operand:XF 0 "register_operand" "=f")
14017         (unspec:XF [(match_operand:XF 2 "register_operand" "0")
14018                     (match_operand:XF 3 "register_operand" "1")]
14019                    UNSPEC_FPREM_F))
14020    (set (match_operand:XF 1 "register_operand" "=u")
14021         (unspec:XF [(match_dup 2) (match_dup 3)]
14022                    UNSPEC_FPREM_U))
14023    (set (reg:CCFP FPSR_REG)
14024         (unspec:CCFP [(match_dup 2) (match_dup 3)]
14025                      UNSPEC_C2_FLAG))]
14026   "TARGET_USE_FANCY_MATH_387
14027    && flag_finite_math_only"
14028   "fprem"
14029   [(set_attr "type" "fpspc")
14030    (set_attr "mode" "XF")])
14031
14032 (define_expand "fmodxf3"
14033   [(use (match_operand:XF 0 "register_operand"))
14034    (use (match_operand:XF 1 "general_operand"))
14035    (use (match_operand:XF 2 "general_operand"))]
14036   "TARGET_USE_FANCY_MATH_387
14037    && flag_finite_math_only"
14038 {
14039   rtx_code_label *label = gen_label_rtx ();
14040
14041   rtx op1 = gen_reg_rtx (XFmode);
14042   rtx op2 = gen_reg_rtx (XFmode);
14043
14044   emit_move_insn (op2, operands[2]);
14045   emit_move_insn (op1, operands[1]);
14046
14047   emit_label (label);
14048   emit_insn (gen_fpremxf4_i387 (op1, op2, op1, op2));
14049   ix86_emit_fp_unordered_jump (label);
14050   LABEL_NUSES (label) = 1;
14051
14052   emit_move_insn (operands[0], op1);
14053   DONE;
14054 })
14055
14056 (define_expand "fmod<mode>3"
14057   [(use (match_operand:MODEF 0 "register_operand"))
14058    (use (match_operand:MODEF 1 "general_operand"))
14059    (use (match_operand:MODEF 2 "general_operand"))]
14060   "TARGET_USE_FANCY_MATH_387
14061    && flag_finite_math_only"
14062 {
14063   rtx (*gen_truncxf) (rtx, rtx);
14064
14065   rtx_code_label *label = gen_label_rtx ();
14066
14067   rtx op1 = gen_reg_rtx (XFmode);
14068   rtx op2 = gen_reg_rtx (XFmode);
14069
14070   emit_insn (gen_extend<mode>xf2 (op2, operands[2]));
14071   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14072
14073   emit_label (label);
14074   emit_insn (gen_fpremxf4_i387 (op1, op2, op1, op2));
14075   ix86_emit_fp_unordered_jump (label);
14076   LABEL_NUSES (label) = 1;
14077
14078   /* Truncate the result properly for strict SSE math.  */
14079   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
14080       && !TARGET_MIX_SSE_I387)
14081     gen_truncxf = gen_truncxf<mode>2;
14082   else
14083     gen_truncxf = gen_truncxf<mode>2_i387_noop_unspec;
14084
14085   emit_insn (gen_truncxf (operands[0], op1));
14086   DONE;
14087 })
14088
14089 (define_insn "fprem1xf4_i387"
14090   [(set (match_operand:XF 0 "register_operand" "=f")
14091         (unspec:XF [(match_operand:XF 2 "register_operand" "0")
14092                     (match_operand:XF 3 "register_operand" "1")]
14093                    UNSPEC_FPREM1_F))
14094    (set (match_operand:XF 1 "register_operand" "=u")
14095         (unspec:XF [(match_dup 2) (match_dup 3)]
14096                    UNSPEC_FPREM1_U))
14097    (set (reg:CCFP FPSR_REG)
14098         (unspec:CCFP [(match_dup 2) (match_dup 3)]
14099                      UNSPEC_C2_FLAG))]
14100   "TARGET_USE_FANCY_MATH_387
14101    && flag_finite_math_only"
14102   "fprem1"
14103   [(set_attr "type" "fpspc")
14104    (set_attr "mode" "XF")])
14105
14106 (define_expand "remainderxf3"
14107   [(use (match_operand:XF 0 "register_operand"))
14108    (use (match_operand:XF 1 "general_operand"))
14109    (use (match_operand:XF 2 "general_operand"))]
14110   "TARGET_USE_FANCY_MATH_387
14111    && flag_finite_math_only"
14112 {
14113   rtx_code_label *label = gen_label_rtx ();
14114
14115   rtx op1 = gen_reg_rtx (XFmode);
14116   rtx op2 = gen_reg_rtx (XFmode);
14117
14118   emit_move_insn (op2, operands[2]);
14119   emit_move_insn (op1, operands[1]);
14120
14121   emit_label (label);
14122   emit_insn (gen_fprem1xf4_i387 (op1, op2, op1, op2));
14123   ix86_emit_fp_unordered_jump (label);
14124   LABEL_NUSES (label) = 1;
14125
14126   emit_move_insn (operands[0], op1);
14127   DONE;
14128 })
14129
14130 (define_expand "remainder<mode>3"
14131   [(use (match_operand:MODEF 0 "register_operand"))
14132    (use (match_operand:MODEF 1 "general_operand"))
14133    (use (match_operand:MODEF 2 "general_operand"))]
14134   "TARGET_USE_FANCY_MATH_387
14135    && flag_finite_math_only"
14136 {
14137   rtx (*gen_truncxf) (rtx, rtx);
14138
14139   rtx_code_label *label = gen_label_rtx ();
14140
14141   rtx op1 = gen_reg_rtx (XFmode);
14142   rtx op2 = gen_reg_rtx (XFmode);
14143
14144   emit_insn (gen_extend<mode>xf2 (op2, operands[2]));
14145   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14146
14147   emit_label (label);
14148
14149   emit_insn (gen_fprem1xf4_i387 (op1, op2, op1, op2));
14150   ix86_emit_fp_unordered_jump (label);
14151   LABEL_NUSES (label) = 1;
14152
14153   /* Truncate the result properly for strict SSE math.  */
14154   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
14155       && !TARGET_MIX_SSE_I387)
14156     gen_truncxf = gen_truncxf<mode>2;
14157   else
14158     gen_truncxf = gen_truncxf<mode>2_i387_noop_unspec;
14159
14160   emit_insn (gen_truncxf (operands[0], op1));
14161   DONE;
14162 })
14163
14164 (define_int_iterator SINCOS
14165         [UNSPEC_SIN
14166          UNSPEC_COS])
14167
14168 (define_int_attr sincos
14169         [(UNSPEC_SIN "sin")
14170          (UNSPEC_COS "cos")])
14171
14172 (define_insn "*<sincos>xf2_i387"
14173   [(set (match_operand:XF 0 "register_operand" "=f")
14174         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
14175                    SINCOS))]
14176   "TARGET_USE_FANCY_MATH_387
14177    && flag_unsafe_math_optimizations"
14178   "f<sincos>"
14179   [(set_attr "type" "fpspc")
14180    (set_attr "mode" "XF")])
14181
14182 (define_insn "*<sincos>_extend<mode>xf2_i387"
14183   [(set (match_operand:XF 0 "register_operand" "=f")
14184         (unspec:XF [(float_extend:XF
14185                       (match_operand:MODEF 1 "register_operand" "0"))]
14186                    SINCOS))]
14187   "TARGET_USE_FANCY_MATH_387
14188    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14189        || TARGET_MIX_SSE_I387)
14190    && flag_unsafe_math_optimizations"
14191   "f<sincos>"
14192   [(set_attr "type" "fpspc")
14193    (set_attr "mode" "XF")])
14194
14195 ;; When sincos pattern is defined, sin and cos builtin functions will be
14196 ;; expanded to sincos pattern with one of its outputs left unused.
14197 ;; CSE pass will figure out if two sincos patterns can be combined,
14198 ;; otherwise sincos pattern will be split back to sin or cos pattern,
14199 ;; depending on the unused output.
14200
14201 (define_insn "sincosxf3"
14202   [(set (match_operand:XF 0 "register_operand" "=f")
14203         (unspec:XF [(match_operand:XF 2 "register_operand" "0")]
14204                    UNSPEC_SINCOS_COS))
14205    (set (match_operand:XF 1 "register_operand" "=u")
14206         (unspec:XF [(match_dup 2)] UNSPEC_SINCOS_SIN))]
14207   "TARGET_USE_FANCY_MATH_387
14208    && flag_unsafe_math_optimizations"
14209   "fsincos"
14210   [(set_attr "type" "fpspc")
14211    (set_attr "mode" "XF")])
14212
14213 (define_split
14214   [(set (match_operand:XF 0 "register_operand")
14215         (unspec:XF [(match_operand:XF 2 "register_operand")]
14216                    UNSPEC_SINCOS_COS))
14217    (set (match_operand:XF 1 "register_operand")
14218         (unspec:XF [(match_dup 2)] UNSPEC_SINCOS_SIN))]
14219   "find_regno_note (insn, REG_UNUSED, REGNO (operands[0]))
14220    && can_create_pseudo_p ()"
14221   [(set (match_dup 1) (unspec:XF [(match_dup 2)] UNSPEC_SIN))])
14222
14223 (define_split
14224   [(set (match_operand:XF 0 "register_operand")
14225         (unspec:XF [(match_operand:XF 2 "register_operand")]
14226                    UNSPEC_SINCOS_COS))
14227    (set (match_operand:XF 1 "register_operand")
14228         (unspec:XF [(match_dup 2)] UNSPEC_SINCOS_SIN))]
14229   "find_regno_note (insn, REG_UNUSED, REGNO (operands[1]))
14230    && can_create_pseudo_p ()"
14231   [(set (match_dup 0) (unspec:XF [(match_dup 2)] UNSPEC_COS))])
14232
14233 (define_insn "sincos_extend<mode>xf3_i387"
14234   [(set (match_operand:XF 0 "register_operand" "=f")
14235         (unspec:XF [(float_extend:XF
14236                       (match_operand:MODEF 2 "register_operand" "0"))]
14237                    UNSPEC_SINCOS_COS))
14238    (set (match_operand:XF 1 "register_operand" "=u")
14239         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SINCOS_SIN))]
14240   "TARGET_USE_FANCY_MATH_387
14241    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14242        || TARGET_MIX_SSE_I387)
14243    && flag_unsafe_math_optimizations"
14244   "fsincos"
14245   [(set_attr "type" "fpspc")
14246    (set_attr "mode" "XF")])
14247
14248 (define_split
14249   [(set (match_operand:XF 0 "register_operand")
14250         (unspec:XF [(float_extend:XF
14251                       (match_operand:MODEF 2 "register_operand"))]
14252                    UNSPEC_SINCOS_COS))
14253    (set (match_operand:XF 1 "register_operand")
14254         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SINCOS_SIN))]
14255   "find_regno_note (insn, REG_UNUSED, REGNO (operands[0]))
14256    && can_create_pseudo_p ()"
14257   [(set (match_dup 1)
14258         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SIN))])
14259
14260 (define_split
14261   [(set (match_operand:XF 0 "register_operand")
14262         (unspec:XF [(float_extend:XF
14263                       (match_operand:MODEF 2 "register_operand"))]
14264                    UNSPEC_SINCOS_COS))
14265    (set (match_operand:XF 1 "register_operand")
14266         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_SINCOS_SIN))]
14267   "find_regno_note (insn, REG_UNUSED, REGNO (operands[1]))
14268    && can_create_pseudo_p ()"
14269   [(set (match_dup 0)
14270         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_COS))])
14271
14272 (define_expand "sincos<mode>3"
14273   [(use (match_operand:MODEF 0 "register_operand"))
14274    (use (match_operand:MODEF 1 "register_operand"))
14275    (use (match_operand:MODEF 2 "register_operand"))]
14276   "TARGET_USE_FANCY_MATH_387
14277    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14278        || TARGET_MIX_SSE_I387)
14279    && flag_unsafe_math_optimizations"
14280 {
14281   rtx op0 = gen_reg_rtx (XFmode);
14282   rtx op1 = gen_reg_rtx (XFmode);
14283
14284   emit_insn (gen_sincos_extend<mode>xf3_i387 (op0, op1, operands[2]));
14285   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14286   emit_insn (gen_truncxf<mode>2_i387_noop (operands[1], op1));
14287   DONE;
14288 })
14289
14290 (define_insn "fptanxf4_i387"
14291   [(set (match_operand:XF 0 "register_operand" "=f")
14292         (match_operand:XF 3 "const_double_operand" "F"))
14293    (set (match_operand:XF 1 "register_operand" "=u")
14294         (unspec:XF [(match_operand:XF 2 "register_operand" "0")]
14295                    UNSPEC_TAN))]
14296   "TARGET_USE_FANCY_MATH_387
14297    && flag_unsafe_math_optimizations
14298    && standard_80387_constant_p (operands[3]) == 2"
14299   "fptan"
14300   [(set_attr "type" "fpspc")
14301    (set_attr "mode" "XF")])
14302
14303 (define_insn "fptan_extend<mode>xf4_i387"
14304   [(set (match_operand:MODEF 0 "register_operand" "=f")
14305         (match_operand:MODEF 3 "const_double_operand" "F"))
14306    (set (match_operand:XF 1 "register_operand" "=u")
14307         (unspec:XF [(float_extend:XF
14308                       (match_operand:MODEF 2 "register_operand" "0"))]
14309                    UNSPEC_TAN))]
14310   "TARGET_USE_FANCY_MATH_387
14311    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14312        || TARGET_MIX_SSE_I387)
14313    && flag_unsafe_math_optimizations
14314    && standard_80387_constant_p (operands[3]) == 2"
14315   "fptan"
14316   [(set_attr "type" "fpspc")
14317    (set_attr "mode" "XF")])
14318
14319 (define_expand "tanxf2"
14320   [(use (match_operand:XF 0 "register_operand"))
14321    (use (match_operand:XF 1 "register_operand"))]
14322   "TARGET_USE_FANCY_MATH_387
14323    && flag_unsafe_math_optimizations"
14324 {
14325   rtx one = gen_reg_rtx (XFmode);
14326   rtx op2 = CONST1_RTX (XFmode); /* fld1 */
14327
14328   emit_insn (gen_fptanxf4_i387 (one, operands[0], operands[1], op2));
14329   DONE;
14330 })
14331
14332 (define_expand "tan<mode>2"
14333   [(use (match_operand:MODEF 0 "register_operand"))
14334    (use (match_operand:MODEF 1 "register_operand"))]
14335   "TARGET_USE_FANCY_MATH_387
14336    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14337        || TARGET_MIX_SSE_I387)
14338    && flag_unsafe_math_optimizations"
14339 {
14340   rtx op0 = gen_reg_rtx (XFmode);
14341
14342   rtx one = gen_reg_rtx (<MODE>mode);
14343   rtx op2 = CONST1_RTX (<MODE>mode); /* fld1 */
14344
14345   emit_insn (gen_fptan_extend<mode>xf4_i387 (one, op0,
14346                                              operands[1], op2));
14347   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14348   DONE;
14349 })
14350
14351 (define_insn "*fpatanxf3_i387"
14352   [(set (match_operand:XF 0 "register_operand" "=f")
14353         (unspec:XF [(match_operand:XF 1 "register_operand" "0")
14354                     (match_operand:XF 2 "register_operand" "u")]
14355                    UNSPEC_FPATAN))
14356    (clobber (match_scratch:XF 3 "=2"))]
14357   "TARGET_USE_FANCY_MATH_387
14358    && flag_unsafe_math_optimizations"
14359   "fpatan"
14360   [(set_attr "type" "fpspc")
14361    (set_attr "mode" "XF")])
14362
14363 (define_insn "fpatan_extend<mode>xf3_i387"
14364   [(set (match_operand:XF 0 "register_operand" "=f")
14365         (unspec:XF [(float_extend:XF
14366                       (match_operand:MODEF 1 "register_operand" "0"))
14367                     (float_extend:XF
14368                       (match_operand:MODEF 2 "register_operand" "u"))]
14369                    UNSPEC_FPATAN))
14370    (clobber (match_scratch:XF 3 "=2"))]
14371   "TARGET_USE_FANCY_MATH_387
14372    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14373        || TARGET_MIX_SSE_I387)
14374    && flag_unsafe_math_optimizations"
14375   "fpatan"
14376   [(set_attr "type" "fpspc")
14377    (set_attr "mode" "XF")])
14378
14379 (define_expand "atan2xf3"
14380   [(parallel [(set (match_operand:XF 0 "register_operand")
14381                    (unspec:XF [(match_operand:XF 2 "register_operand")
14382                                (match_operand:XF 1 "register_operand")]
14383                               UNSPEC_FPATAN))
14384               (clobber (match_scratch:XF 3))])]
14385   "TARGET_USE_FANCY_MATH_387
14386    && flag_unsafe_math_optimizations")
14387
14388 (define_expand "atan2<mode>3"
14389   [(use (match_operand:MODEF 0 "register_operand"))
14390    (use (match_operand:MODEF 1 "register_operand"))
14391    (use (match_operand:MODEF 2 "register_operand"))]
14392   "TARGET_USE_FANCY_MATH_387
14393    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14394        || TARGET_MIX_SSE_I387)
14395    && flag_unsafe_math_optimizations"
14396 {
14397   rtx op0 = gen_reg_rtx (XFmode);
14398
14399   emit_insn (gen_fpatan_extend<mode>xf3_i387 (op0, operands[2], operands[1]));
14400   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14401   DONE;
14402 })
14403
14404 (define_expand "atanxf2"
14405   [(parallel [(set (match_operand:XF 0 "register_operand")
14406                    (unspec:XF [(match_dup 2)
14407                                (match_operand:XF 1 "register_operand")]
14408                               UNSPEC_FPATAN))
14409               (clobber (match_scratch:XF 3))])]
14410   "TARGET_USE_FANCY_MATH_387
14411    && flag_unsafe_math_optimizations"
14412 {
14413   operands[2] = gen_reg_rtx (XFmode);
14414   emit_move_insn (operands[2], CONST1_RTX (XFmode));  /* fld1 */
14415 })
14416
14417 (define_expand "atan<mode>2"
14418   [(use (match_operand:MODEF 0 "register_operand"))
14419    (use (match_operand:MODEF 1 "register_operand"))]
14420   "TARGET_USE_FANCY_MATH_387
14421    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14422        || TARGET_MIX_SSE_I387)
14423    && flag_unsafe_math_optimizations"
14424 {
14425   rtx op0 = gen_reg_rtx (XFmode);
14426
14427   rtx op2 = gen_reg_rtx (<MODE>mode);
14428   emit_move_insn (op2, CONST1_RTX (<MODE>mode));  /* fld1 */
14429
14430   emit_insn (gen_fpatan_extend<mode>xf3_i387 (op0, op2, operands[1]));
14431   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14432   DONE;
14433 })
14434
14435 (define_expand "asinxf2"
14436   [(set (match_dup 2)
14437         (mult:XF (match_operand:XF 1 "register_operand")
14438                  (match_dup 1)))
14439    (set (match_dup 4) (minus:XF (match_dup 3) (match_dup 2)))
14440    (set (match_dup 5) (sqrt:XF (match_dup 4)))
14441    (parallel [(set (match_operand:XF 0 "register_operand")
14442                    (unspec:XF [(match_dup 5) (match_dup 1)]
14443                               UNSPEC_FPATAN))
14444               (clobber (match_scratch:XF 6))])]
14445   "TARGET_USE_FANCY_MATH_387
14446    && flag_unsafe_math_optimizations"
14447 {
14448   int i;
14449
14450   if (optimize_insn_for_size_p ())
14451     FAIL;
14452
14453   for (i = 2; i < 6; i++)
14454     operands[i] = gen_reg_rtx (XFmode);
14455
14456   emit_move_insn (operands[3], CONST1_RTX (XFmode));  /* fld1 */
14457 })
14458
14459 (define_expand "asin<mode>2"
14460   [(use (match_operand:MODEF 0 "register_operand"))
14461    (use (match_operand:MODEF 1 "general_operand"))]
14462  "TARGET_USE_FANCY_MATH_387
14463    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14464        || TARGET_MIX_SSE_I387)
14465    && flag_unsafe_math_optimizations"
14466 {
14467   rtx op0 = gen_reg_rtx (XFmode);
14468   rtx op1 = gen_reg_rtx (XFmode);
14469
14470   if (optimize_insn_for_size_p ())
14471     FAIL;
14472
14473   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14474   emit_insn (gen_asinxf2 (op0, op1));
14475   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14476   DONE;
14477 })
14478
14479 (define_expand "acosxf2"
14480   [(set (match_dup 2)
14481         (mult:XF (match_operand:XF 1 "register_operand")
14482                  (match_dup 1)))
14483    (set (match_dup 4) (minus:XF (match_dup 3) (match_dup 2)))
14484    (set (match_dup 5) (sqrt:XF (match_dup 4)))
14485    (parallel [(set (match_operand:XF 0 "register_operand")
14486                    (unspec:XF [(match_dup 1) (match_dup 5)]
14487                               UNSPEC_FPATAN))
14488               (clobber (match_scratch:XF 6))])]
14489   "TARGET_USE_FANCY_MATH_387
14490    && flag_unsafe_math_optimizations"
14491 {
14492   int i;
14493
14494   if (optimize_insn_for_size_p ())
14495     FAIL;
14496
14497   for (i = 2; i < 6; i++)
14498     operands[i] = gen_reg_rtx (XFmode);
14499
14500   emit_move_insn (operands[3], CONST1_RTX (XFmode));  /* fld1 */
14501 })
14502
14503 (define_expand "acos<mode>2"
14504   [(use (match_operand:MODEF 0 "register_operand"))
14505    (use (match_operand:MODEF 1 "general_operand"))]
14506  "TARGET_USE_FANCY_MATH_387
14507    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14508        || TARGET_MIX_SSE_I387)
14509    && flag_unsafe_math_optimizations"
14510 {
14511   rtx op0 = gen_reg_rtx (XFmode);
14512   rtx op1 = gen_reg_rtx (XFmode);
14513
14514   if (optimize_insn_for_size_p ())
14515     FAIL;
14516
14517   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14518   emit_insn (gen_acosxf2 (op0, op1));
14519   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14520   DONE;
14521 })
14522
14523 (define_insn "fyl2xxf3_i387"
14524   [(set (match_operand:XF 0 "register_operand" "=f")
14525         (unspec:XF [(match_operand:XF 1 "register_operand" "0")
14526                     (match_operand:XF 2 "register_operand" "u")]
14527                    UNSPEC_FYL2X))
14528    (clobber (match_scratch:XF 3 "=2"))]
14529   "TARGET_USE_FANCY_MATH_387
14530    && flag_unsafe_math_optimizations"
14531   "fyl2x"
14532   [(set_attr "type" "fpspc")
14533    (set_attr "mode" "XF")])
14534
14535 (define_insn "fyl2x_extend<mode>xf3_i387"
14536   [(set (match_operand:XF 0 "register_operand" "=f")
14537         (unspec:XF [(float_extend:XF
14538                       (match_operand:MODEF 1 "register_operand" "0"))
14539                     (match_operand:XF 2 "register_operand" "u")]
14540                    UNSPEC_FYL2X))
14541    (clobber (match_scratch:XF 3 "=2"))]
14542   "TARGET_USE_FANCY_MATH_387
14543    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14544        || TARGET_MIX_SSE_I387)
14545    && flag_unsafe_math_optimizations"
14546   "fyl2x"
14547   [(set_attr "type" "fpspc")
14548    (set_attr "mode" "XF")])
14549
14550 (define_expand "logxf2"
14551   [(parallel [(set (match_operand:XF 0 "register_operand")
14552                    (unspec:XF [(match_operand:XF 1 "register_operand")
14553                                (match_dup 2)] UNSPEC_FYL2X))
14554               (clobber (match_scratch:XF 3))])]
14555   "TARGET_USE_FANCY_MATH_387
14556    && flag_unsafe_math_optimizations"
14557 {
14558   operands[2] = gen_reg_rtx (XFmode);
14559   emit_move_insn (operands[2], standard_80387_constant_rtx (4)); /* fldln2 */
14560 })
14561
14562 (define_expand "log<mode>2"
14563   [(use (match_operand:MODEF 0 "register_operand"))
14564    (use (match_operand:MODEF 1 "register_operand"))]
14565   "TARGET_USE_FANCY_MATH_387
14566    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14567        || TARGET_MIX_SSE_I387)
14568    && flag_unsafe_math_optimizations"
14569 {
14570   rtx op0 = gen_reg_rtx (XFmode);
14571
14572   rtx op2 = gen_reg_rtx (XFmode);
14573   emit_move_insn (op2, standard_80387_constant_rtx (4)); /* fldln2 */
14574
14575   emit_insn (gen_fyl2x_extend<mode>xf3_i387 (op0, operands[1], op2));
14576   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14577   DONE;
14578 })
14579
14580 (define_expand "log10xf2"
14581   [(parallel [(set (match_operand:XF 0 "register_operand")
14582                    (unspec:XF [(match_operand:XF 1 "register_operand")
14583                                (match_dup 2)] UNSPEC_FYL2X))
14584               (clobber (match_scratch:XF 3))])]
14585   "TARGET_USE_FANCY_MATH_387
14586    && flag_unsafe_math_optimizations"
14587 {
14588   operands[2] = gen_reg_rtx (XFmode);
14589   emit_move_insn (operands[2], standard_80387_constant_rtx (3)); /* fldlg2 */
14590 })
14591
14592 (define_expand "log10<mode>2"
14593   [(use (match_operand:MODEF 0 "register_operand"))
14594    (use (match_operand:MODEF 1 "register_operand"))]
14595   "TARGET_USE_FANCY_MATH_387
14596    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14597        || TARGET_MIX_SSE_I387)
14598    && flag_unsafe_math_optimizations"
14599 {
14600   rtx op0 = gen_reg_rtx (XFmode);
14601
14602   rtx op2 = gen_reg_rtx (XFmode);
14603   emit_move_insn (op2, standard_80387_constant_rtx (3)); /* fldlg2 */
14604
14605   emit_insn (gen_fyl2x_extend<mode>xf3_i387 (op0, operands[1], op2));
14606   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14607   DONE;
14608 })
14609
14610 (define_expand "log2xf2"
14611   [(parallel [(set (match_operand:XF 0 "register_operand")
14612                    (unspec:XF [(match_operand:XF 1 "register_operand")
14613                                (match_dup 2)] UNSPEC_FYL2X))
14614               (clobber (match_scratch:XF 3))])]
14615   "TARGET_USE_FANCY_MATH_387
14616    && flag_unsafe_math_optimizations"
14617 {
14618   operands[2] = gen_reg_rtx (XFmode);
14619   emit_move_insn (operands[2], CONST1_RTX (XFmode)); /* fld1 */
14620 })
14621
14622 (define_expand "log2<mode>2"
14623   [(use (match_operand:MODEF 0 "register_operand"))
14624    (use (match_operand:MODEF 1 "register_operand"))]
14625   "TARGET_USE_FANCY_MATH_387
14626    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14627        || TARGET_MIX_SSE_I387)
14628    && flag_unsafe_math_optimizations"
14629 {
14630   rtx op0 = gen_reg_rtx (XFmode);
14631
14632   rtx op2 = gen_reg_rtx (XFmode);
14633   emit_move_insn (op2, CONST1_RTX (XFmode)); /* fld1 */
14634
14635   emit_insn (gen_fyl2x_extend<mode>xf3_i387 (op0, operands[1], op2));
14636   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14637   DONE;
14638 })
14639
14640 (define_insn "fyl2xp1xf3_i387"
14641   [(set (match_operand:XF 0 "register_operand" "=f")
14642         (unspec:XF [(match_operand:XF 1 "register_operand" "0")
14643                     (match_operand:XF 2 "register_operand" "u")]
14644                    UNSPEC_FYL2XP1))
14645    (clobber (match_scratch:XF 3 "=2"))]
14646   "TARGET_USE_FANCY_MATH_387
14647    && flag_unsafe_math_optimizations"
14648   "fyl2xp1"
14649   [(set_attr "type" "fpspc")
14650    (set_attr "mode" "XF")])
14651
14652 (define_insn "fyl2xp1_extend<mode>xf3_i387"
14653   [(set (match_operand:XF 0 "register_operand" "=f")
14654         (unspec:XF [(float_extend:XF
14655                       (match_operand:MODEF 1 "register_operand" "0"))
14656                     (match_operand:XF 2 "register_operand" "u")]
14657                    UNSPEC_FYL2XP1))
14658    (clobber (match_scratch:XF 3 "=2"))]
14659   "TARGET_USE_FANCY_MATH_387
14660    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14661        || TARGET_MIX_SSE_I387)
14662    && flag_unsafe_math_optimizations"
14663   "fyl2xp1"
14664   [(set_attr "type" "fpspc")
14665    (set_attr "mode" "XF")])
14666
14667 (define_expand "log1pxf2"
14668   [(use (match_operand:XF 0 "register_operand"))
14669    (use (match_operand:XF 1 "register_operand"))]
14670   "TARGET_USE_FANCY_MATH_387
14671    && flag_unsafe_math_optimizations"
14672 {
14673   if (optimize_insn_for_size_p ())
14674     FAIL;
14675
14676   ix86_emit_i387_log1p (operands[0], operands[1]);
14677   DONE;
14678 })
14679
14680 (define_expand "log1p<mode>2"
14681   [(use (match_operand:MODEF 0 "register_operand"))
14682    (use (match_operand:MODEF 1 "register_operand"))]
14683   "TARGET_USE_FANCY_MATH_387
14684    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14685        || TARGET_MIX_SSE_I387)
14686    && flag_unsafe_math_optimizations"
14687 {
14688   rtx op0;
14689
14690   if (optimize_insn_for_size_p ())
14691     FAIL;
14692
14693   op0 = gen_reg_rtx (XFmode);
14694
14695   operands[1] = gen_rtx_FLOAT_EXTEND (XFmode, operands[1]);
14696
14697   ix86_emit_i387_log1p (op0, operands[1]);
14698   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14699   DONE;
14700 })
14701
14702 (define_insn "fxtractxf3_i387"
14703   [(set (match_operand:XF 0 "register_operand" "=f")
14704         (unspec:XF [(match_operand:XF 2 "register_operand" "0")]
14705                    UNSPEC_XTRACT_FRACT))
14706    (set (match_operand:XF 1 "register_operand" "=u")
14707         (unspec:XF [(match_dup 2)] UNSPEC_XTRACT_EXP))]
14708   "TARGET_USE_FANCY_MATH_387
14709    && flag_unsafe_math_optimizations"
14710   "fxtract"
14711   [(set_attr "type" "fpspc")
14712    (set_attr "mode" "XF")])
14713
14714 (define_insn "fxtract_extend<mode>xf3_i387"
14715   [(set (match_operand:XF 0 "register_operand" "=f")
14716         (unspec:XF [(float_extend:XF
14717                       (match_operand:MODEF 2 "register_operand" "0"))]
14718                    UNSPEC_XTRACT_FRACT))
14719    (set (match_operand:XF 1 "register_operand" "=u")
14720         (unspec:XF [(float_extend:XF (match_dup 2))] UNSPEC_XTRACT_EXP))]
14721   "TARGET_USE_FANCY_MATH_387
14722    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14723        || TARGET_MIX_SSE_I387)
14724    && flag_unsafe_math_optimizations"
14725   "fxtract"
14726   [(set_attr "type" "fpspc")
14727    (set_attr "mode" "XF")])
14728
14729 (define_expand "logbxf2"
14730   [(parallel [(set (match_dup 2)
14731                    (unspec:XF [(match_operand:XF 1 "register_operand")]
14732                               UNSPEC_XTRACT_FRACT))
14733               (set (match_operand:XF 0 "register_operand")
14734                    (unspec:XF [(match_dup 1)] UNSPEC_XTRACT_EXP))])]
14735   "TARGET_USE_FANCY_MATH_387
14736    && flag_unsafe_math_optimizations"
14737   "operands[2] = gen_reg_rtx (XFmode);")
14738
14739 (define_expand "logb<mode>2"
14740   [(use (match_operand:MODEF 0 "register_operand"))
14741    (use (match_operand:MODEF 1 "register_operand"))]
14742   "TARGET_USE_FANCY_MATH_387
14743    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14744        || TARGET_MIX_SSE_I387)
14745    && flag_unsafe_math_optimizations"
14746 {
14747   rtx op0 = gen_reg_rtx (XFmode);
14748   rtx op1 = gen_reg_rtx (XFmode);
14749
14750   emit_insn (gen_fxtract_extend<mode>xf3_i387 (op0, op1, operands[1]));
14751   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op1));
14752   DONE;
14753 })
14754
14755 (define_expand "ilogbxf2"
14756   [(use (match_operand:SI 0 "register_operand"))
14757    (use (match_operand:XF 1 "register_operand"))]
14758   "TARGET_USE_FANCY_MATH_387
14759    && flag_unsafe_math_optimizations"
14760 {
14761   rtx op0, op1;
14762
14763   if (optimize_insn_for_size_p ())
14764     FAIL;
14765
14766   op0 = gen_reg_rtx (XFmode);
14767   op1 = gen_reg_rtx (XFmode);
14768
14769   emit_insn (gen_fxtractxf3_i387 (op0, op1, operands[1]));
14770   emit_insn (gen_fix_truncxfsi2 (operands[0], op1));
14771   DONE;
14772 })
14773
14774 (define_expand "ilogb<mode>2"
14775   [(use (match_operand:SI 0 "register_operand"))
14776    (use (match_operand:MODEF 1 "register_operand"))]
14777   "TARGET_USE_FANCY_MATH_387
14778    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14779        || TARGET_MIX_SSE_I387)
14780    && flag_unsafe_math_optimizations"
14781 {
14782   rtx op0, op1;
14783
14784   if (optimize_insn_for_size_p ())
14785     FAIL;
14786
14787   op0 = gen_reg_rtx (XFmode);
14788   op1 = gen_reg_rtx (XFmode);
14789
14790   emit_insn (gen_fxtract_extend<mode>xf3_i387 (op0, op1, operands[1]));
14791   emit_insn (gen_fix_truncxfsi2 (operands[0], op1));
14792   DONE;
14793 })
14794
14795 (define_insn "*f2xm1xf2_i387"
14796   [(set (match_operand:XF 0 "register_operand" "=f")
14797         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
14798                    UNSPEC_F2XM1))]
14799   "TARGET_USE_FANCY_MATH_387
14800    && flag_unsafe_math_optimizations"
14801   "f2xm1"
14802   [(set_attr "type" "fpspc")
14803    (set_attr "mode" "XF")])
14804
14805 (define_insn "fscalexf4_i387"
14806   [(set (match_operand:XF 0 "register_operand" "=f")
14807         (unspec:XF [(match_operand:XF 2 "register_operand" "0")
14808                     (match_operand:XF 3 "register_operand" "1")]
14809                    UNSPEC_FSCALE_FRACT))
14810    (set (match_operand:XF 1 "register_operand" "=u")
14811         (unspec:XF [(match_dup 2) (match_dup 3)]
14812                    UNSPEC_FSCALE_EXP))]
14813   "TARGET_USE_FANCY_MATH_387
14814    && flag_unsafe_math_optimizations"
14815   "fscale"
14816   [(set_attr "type" "fpspc")
14817    (set_attr "mode" "XF")])
14818
14819 (define_expand "expNcorexf3"
14820   [(set (match_dup 3) (mult:XF (match_operand:XF 1 "register_operand")
14821                                (match_operand:XF 2 "register_operand")))
14822    (set (match_dup 4) (unspec:XF [(match_dup 3)] UNSPEC_FRNDINT))
14823    (set (match_dup 5) (minus:XF (match_dup 3) (match_dup 4)))
14824    (set (match_dup 6) (unspec:XF [(match_dup 5)] UNSPEC_F2XM1))
14825    (set (match_dup 8) (plus:XF (match_dup 6) (match_dup 7)))
14826    (parallel [(set (match_operand:XF 0 "register_operand")
14827                    (unspec:XF [(match_dup 8) (match_dup 4)]
14828                               UNSPEC_FSCALE_FRACT))
14829               (set (match_dup 9)
14830                    (unspec:XF [(match_dup 8) (match_dup 4)]
14831                               UNSPEC_FSCALE_EXP))])]
14832   "TARGET_USE_FANCY_MATH_387
14833    && flag_unsafe_math_optimizations"
14834 {
14835   int i;
14836
14837   if (optimize_insn_for_size_p ())
14838     FAIL;
14839
14840   for (i = 3; i < 10; i++)
14841     operands[i] = gen_reg_rtx (XFmode);
14842
14843   emit_move_insn (operands[7], CONST1_RTX (XFmode));  /* fld1 */
14844 })
14845
14846 (define_expand "expxf2"
14847   [(use (match_operand:XF 0 "register_operand"))
14848    (use (match_operand:XF 1 "register_operand"))]
14849   "TARGET_USE_FANCY_MATH_387
14850    && flag_unsafe_math_optimizations"
14851 {
14852   rtx op2;
14853
14854   if (optimize_insn_for_size_p ())
14855     FAIL;
14856
14857   op2 = gen_reg_rtx (XFmode);
14858   emit_move_insn (op2, standard_80387_constant_rtx (5)); /* fldl2e */
14859
14860   emit_insn (gen_expNcorexf3 (operands[0], operands[1], op2));
14861   DONE;
14862 })
14863
14864 (define_expand "exp<mode>2"
14865   [(use (match_operand:MODEF 0 "register_operand"))
14866    (use (match_operand:MODEF 1 "general_operand"))]
14867  "TARGET_USE_FANCY_MATH_387
14868    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14869        || TARGET_MIX_SSE_I387)
14870    && flag_unsafe_math_optimizations"
14871 {
14872   rtx op0, op1;
14873
14874   if (optimize_insn_for_size_p ())
14875     FAIL;
14876
14877   op0 = gen_reg_rtx (XFmode);
14878   op1 = gen_reg_rtx (XFmode);
14879
14880   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14881   emit_insn (gen_expxf2 (op0, op1));
14882   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14883   DONE;
14884 })
14885
14886 (define_expand "exp10xf2"
14887   [(use (match_operand:XF 0 "register_operand"))
14888    (use (match_operand:XF 1 "register_operand"))]
14889   "TARGET_USE_FANCY_MATH_387
14890    && flag_unsafe_math_optimizations"
14891 {
14892   rtx op2;
14893
14894   if (optimize_insn_for_size_p ())
14895     FAIL;
14896
14897   op2 = gen_reg_rtx (XFmode);
14898   emit_move_insn (op2, standard_80387_constant_rtx (6)); /* fldl2t */
14899
14900   emit_insn (gen_expNcorexf3 (operands[0], operands[1], op2));
14901   DONE;
14902 })
14903
14904 (define_expand "exp10<mode>2"
14905   [(use (match_operand:MODEF 0 "register_operand"))
14906    (use (match_operand:MODEF 1 "general_operand"))]
14907  "TARGET_USE_FANCY_MATH_387
14908    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14909        || TARGET_MIX_SSE_I387)
14910    && flag_unsafe_math_optimizations"
14911 {
14912   rtx op0, op1;
14913
14914   if (optimize_insn_for_size_p ())
14915     FAIL;
14916
14917   op0 = gen_reg_rtx (XFmode);
14918   op1 = gen_reg_rtx (XFmode);
14919
14920   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14921   emit_insn (gen_exp10xf2 (op0, op1));
14922   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14923   DONE;
14924 })
14925
14926 (define_expand "exp2xf2"
14927   [(use (match_operand:XF 0 "register_operand"))
14928    (use (match_operand:XF 1 "register_operand"))]
14929   "TARGET_USE_FANCY_MATH_387
14930    && flag_unsafe_math_optimizations"
14931 {
14932   rtx op2;
14933
14934   if (optimize_insn_for_size_p ())
14935     FAIL;
14936
14937   op2 = gen_reg_rtx (XFmode);
14938   emit_move_insn (op2, CONST1_RTX (XFmode));  /* fld1 */
14939
14940   emit_insn (gen_expNcorexf3 (operands[0], operands[1], op2));
14941   DONE;
14942 })
14943
14944 (define_expand "exp2<mode>2"
14945   [(use (match_operand:MODEF 0 "register_operand"))
14946    (use (match_operand:MODEF 1 "general_operand"))]
14947  "TARGET_USE_FANCY_MATH_387
14948    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
14949        || TARGET_MIX_SSE_I387)
14950    && flag_unsafe_math_optimizations"
14951 {
14952   rtx op0, op1;
14953
14954   if (optimize_insn_for_size_p ())
14955     FAIL;
14956
14957   op0 = gen_reg_rtx (XFmode);
14958   op1 = gen_reg_rtx (XFmode);
14959
14960   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
14961   emit_insn (gen_exp2xf2 (op0, op1));
14962   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
14963   DONE;
14964 })
14965
14966 (define_expand "expm1xf2"
14967   [(set (match_dup 3) (mult:XF (match_operand:XF 1 "register_operand")
14968                                (match_dup 2)))
14969    (set (match_dup 4) (unspec:XF [(match_dup 3)] UNSPEC_FRNDINT))
14970    (set (match_dup 5) (minus:XF (match_dup 3) (match_dup 4)))
14971    (set (match_dup 9) (float_extend:XF (match_dup 13)))
14972    (set (match_dup 6) (unspec:XF [(match_dup 5)] UNSPEC_F2XM1))
14973    (parallel [(set (match_dup 7)
14974                    (unspec:XF [(match_dup 6) (match_dup 4)]
14975                               UNSPEC_FSCALE_FRACT))
14976               (set (match_dup 8)
14977                    (unspec:XF [(match_dup 6) (match_dup 4)]
14978                               UNSPEC_FSCALE_EXP))])
14979    (parallel [(set (match_dup 10)
14980                    (unspec:XF [(match_dup 9) (match_dup 8)]
14981                               UNSPEC_FSCALE_FRACT))
14982               (set (match_dup 11)
14983                    (unspec:XF [(match_dup 9) (match_dup 8)]
14984                               UNSPEC_FSCALE_EXP))])
14985    (set (match_dup 12) (minus:XF (match_dup 10)
14986                                  (float_extend:XF (match_dup 13))))
14987    (set (match_operand:XF 0 "register_operand")
14988         (plus:XF (match_dup 12) (match_dup 7)))]
14989   "TARGET_USE_FANCY_MATH_387
14990    && flag_unsafe_math_optimizations"
14991 {
14992   int i;
14993
14994   if (optimize_insn_for_size_p ())
14995     FAIL;
14996
14997   for (i = 2; i < 13; i++)
14998     operands[i] = gen_reg_rtx (XFmode);
14999
15000   operands[13]
15001     = validize_mem (force_const_mem (SFmode, CONST1_RTX (SFmode))); /* fld1 */
15002
15003   emit_move_insn (operands[2], standard_80387_constant_rtx (5)); /* fldl2e */
15004 })
15005
15006 (define_expand "expm1<mode>2"
15007   [(use (match_operand:MODEF 0 "register_operand"))
15008    (use (match_operand:MODEF 1 "general_operand"))]
15009  "TARGET_USE_FANCY_MATH_387
15010    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15011        || TARGET_MIX_SSE_I387)
15012    && flag_unsafe_math_optimizations"
15013 {
15014   rtx op0, op1;
15015
15016   if (optimize_insn_for_size_p ())
15017     FAIL;
15018
15019   op0 = gen_reg_rtx (XFmode);
15020   op1 = gen_reg_rtx (XFmode);
15021
15022   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15023   emit_insn (gen_expm1xf2 (op0, op1));
15024   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15025   DONE;
15026 })
15027
15028 (define_expand "ldexpxf3"
15029   [(match_operand:XF 0 "register_operand")
15030    (match_operand:XF 1 "register_operand")
15031    (match_operand:SI 2 "register_operand")]
15032   "TARGET_USE_FANCY_MATH_387
15033    && flag_unsafe_math_optimizations"
15034 {
15035   rtx tmp1, tmp2;
15036   if (optimize_insn_for_size_p ())
15037     FAIL;
15038
15039   tmp1 = gen_reg_rtx (XFmode);
15040   tmp2 = gen_reg_rtx (XFmode);
15041
15042   emit_insn (gen_floatsixf2 (tmp1, operands[2]));
15043   emit_insn (gen_fscalexf4_i387 (operands[0], tmp2,
15044                                  operands[1], tmp1));
15045   DONE;
15046 })
15047
15048 (define_expand "ldexp<mode>3"
15049   [(use (match_operand:MODEF 0 "register_operand"))
15050    (use (match_operand:MODEF 1 "general_operand"))
15051    (use (match_operand:SI 2 "register_operand"))]
15052  "TARGET_USE_FANCY_MATH_387
15053    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15054        || TARGET_MIX_SSE_I387)
15055    && flag_unsafe_math_optimizations"
15056 {
15057   rtx op0, op1;
15058
15059   if (optimize_insn_for_size_p ())
15060     FAIL;
15061
15062   op0 = gen_reg_rtx (XFmode);
15063   op1 = gen_reg_rtx (XFmode);
15064
15065   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15066   emit_insn (gen_ldexpxf3 (op0, op1, operands[2]));
15067   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15068   DONE;
15069 })
15070
15071 (define_expand "scalbxf3"
15072   [(parallel [(set (match_operand:XF 0 " register_operand")
15073                    (unspec:XF [(match_operand:XF 1 "register_operand")
15074                                (match_operand:XF 2 "register_operand")]
15075                               UNSPEC_FSCALE_FRACT))
15076               (set (match_dup 3)
15077                    (unspec:XF [(match_dup 1) (match_dup 2)]
15078                               UNSPEC_FSCALE_EXP))])]
15079   "TARGET_USE_FANCY_MATH_387
15080    && flag_unsafe_math_optimizations"
15081 {
15082   if (optimize_insn_for_size_p ())
15083     FAIL;
15084
15085   operands[3] = gen_reg_rtx (XFmode);
15086 })
15087
15088 (define_expand "scalb<mode>3"
15089   [(use (match_operand:MODEF 0 "register_operand"))
15090    (use (match_operand:MODEF 1 "general_operand"))
15091    (use (match_operand:MODEF 2 "general_operand"))]
15092  "TARGET_USE_FANCY_MATH_387
15093    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15094        || TARGET_MIX_SSE_I387)
15095    && flag_unsafe_math_optimizations"
15096 {
15097   rtx op0, op1, op2;
15098
15099   if (optimize_insn_for_size_p ())
15100     FAIL;
15101
15102   op0 = gen_reg_rtx (XFmode);
15103   op1 = gen_reg_rtx (XFmode);
15104   op2 = gen_reg_rtx (XFmode);
15105
15106   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15107   emit_insn (gen_extend<mode>xf2 (op2, operands[2]));
15108   emit_insn (gen_scalbxf3 (op0, op1, op2));
15109   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15110   DONE;
15111 })
15112
15113 (define_expand "significandxf2"
15114   [(parallel [(set (match_operand:XF 0 "register_operand")
15115                    (unspec:XF [(match_operand:XF 1 "register_operand")]
15116                               UNSPEC_XTRACT_FRACT))
15117               (set (match_dup 2)
15118                    (unspec:XF [(match_dup 1)] UNSPEC_XTRACT_EXP))])]
15119   "TARGET_USE_FANCY_MATH_387
15120    && flag_unsafe_math_optimizations"
15121   "operands[2] = gen_reg_rtx (XFmode);")
15122
15123 (define_expand "significand<mode>2"
15124   [(use (match_operand:MODEF 0 "register_operand"))
15125    (use (match_operand:MODEF 1 "register_operand"))]
15126   "TARGET_USE_FANCY_MATH_387
15127    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15128        || TARGET_MIX_SSE_I387)
15129    && flag_unsafe_math_optimizations"
15130 {
15131   rtx op0 = gen_reg_rtx (XFmode);
15132   rtx op1 = gen_reg_rtx (XFmode);
15133
15134   emit_insn (gen_fxtract_extend<mode>xf3_i387 (op0, op1, operands[1]));
15135   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15136   DONE;
15137 })
15138 \f
15139
15140 (define_insn "sse4_1_round<mode>2"
15141   [(set (match_operand:MODEF 0 "register_operand" "=x")
15142         (unspec:MODEF [(match_operand:MODEF 1 "register_operand" "x")
15143                        (match_operand:SI 2 "const_0_to_15_operand" "n")]
15144                       UNSPEC_ROUND))]
15145   "TARGET_ROUND"
15146   "%vround<ssemodesuffix>\t{%2, %1, %d0|%d0, %1, %2}"
15147   [(set_attr "type" "ssecvt")
15148    (set_attr "prefix_extra" "1")
15149    (set_attr "prefix" "maybe_vex")
15150    (set_attr "mode" "<MODE>")])
15151
15152 (define_insn "rintxf2"
15153   [(set (match_operand:XF 0 "register_operand" "=f")
15154         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
15155                    UNSPEC_FRNDINT))]
15156   "TARGET_USE_FANCY_MATH_387
15157    && flag_unsafe_math_optimizations"
15158   "frndint"
15159   [(set_attr "type" "fpspc")
15160    (set_attr "mode" "XF")])
15161
15162 (define_expand "rint<mode>2"
15163   [(use (match_operand:MODEF 0 "register_operand"))
15164    (use (match_operand:MODEF 1 "register_operand"))]
15165   "(TARGET_USE_FANCY_MATH_387
15166     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15167         || TARGET_MIX_SSE_I387)
15168     && flag_unsafe_math_optimizations)
15169    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15170        && !flag_trapping_math)"
15171 {
15172   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15173       && !flag_trapping_math)
15174     {
15175       if (TARGET_ROUND)
15176         emit_insn (gen_sse4_1_round<mode>2
15177                    (operands[0], operands[1], GEN_INT (ROUND_MXCSR)));
15178       else if (optimize_insn_for_size_p ())
15179         FAIL;
15180       else
15181         ix86_expand_rint (operands[0], operands[1]);
15182     }
15183   else
15184     {
15185       rtx op0 = gen_reg_rtx (XFmode);
15186       rtx op1 = gen_reg_rtx (XFmode);
15187
15188       emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15189       emit_insn (gen_rintxf2 (op0, op1));
15190
15191       emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15192     }
15193   DONE;
15194 })
15195
15196 (define_expand "round<mode>2"
15197   [(match_operand:X87MODEF 0 "register_operand")
15198    (match_operand:X87MODEF 1 "nonimmediate_operand")]
15199   "(TARGET_USE_FANCY_MATH_387
15200     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15201         || TARGET_MIX_SSE_I387)
15202     && flag_unsafe_math_optimizations)
15203    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15204        && !flag_trapping_math && !flag_rounding_math)"
15205 {
15206   if (optimize_insn_for_size_p ())
15207     FAIL;
15208
15209   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15210       && !flag_trapping_math && !flag_rounding_math)
15211     {
15212       if (TARGET_ROUND)
15213         {
15214           operands[1] = force_reg (<MODE>mode, operands[1]);
15215           ix86_expand_round_sse4 (operands[0], operands[1]);
15216         }
15217       else if (TARGET_64BIT || (<MODE>mode != DFmode))
15218         ix86_expand_round (operands[0], operands[1]);
15219       else
15220         ix86_expand_rounddf_32 (operands[0], operands[1]);
15221     }
15222   else
15223     {
15224       operands[1] = force_reg (<MODE>mode, operands[1]);
15225       ix86_emit_i387_round (operands[0], operands[1]);
15226     }
15227   DONE;
15228 })
15229
15230 (define_insn_and_split "*fistdi2_1"
15231   [(set (match_operand:DI 0 "nonimmediate_operand")
15232         (unspec:DI [(match_operand:XF 1 "register_operand")]
15233                    UNSPEC_FIST))]
15234   "TARGET_USE_FANCY_MATH_387
15235    && can_create_pseudo_p ()"
15236   "#"
15237   "&& 1"
15238   [(const_int 0)]
15239 {
15240   if (memory_operand (operands[0], VOIDmode))
15241     emit_insn (gen_fistdi2 (operands[0], operands[1]));
15242   else
15243     {
15244       operands[2] = assign_386_stack_local (DImode, SLOT_TEMP);
15245       emit_insn (gen_fistdi2_with_temp (operands[0], operands[1],
15246                                          operands[2]));
15247     }
15248   DONE;
15249 }
15250   [(set_attr "type" "fpspc")
15251    (set_attr "mode" "DI")])
15252
15253 (define_insn "fistdi2"
15254   [(set (match_operand:DI 0 "memory_operand" "=m")
15255         (unspec:DI [(match_operand:XF 1 "register_operand" "f")]
15256                    UNSPEC_FIST))
15257    (clobber (match_scratch:XF 2 "=&1f"))]
15258   "TARGET_USE_FANCY_MATH_387"
15259   "* return output_fix_trunc (insn, operands, false);"
15260   [(set_attr "type" "fpspc")
15261    (set_attr "mode" "DI")])
15262
15263 (define_insn "fistdi2_with_temp"
15264   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
15265         (unspec:DI [(match_operand:XF 1 "register_operand" "f,f")]
15266                    UNSPEC_FIST))
15267    (clobber (match_operand:DI 2 "memory_operand" "=X,m"))
15268    (clobber (match_scratch:XF 3 "=&1f,&1f"))]
15269   "TARGET_USE_FANCY_MATH_387"
15270   "#"
15271   [(set_attr "type" "fpspc")
15272    (set_attr "mode" "DI")])
15273
15274 (define_split
15275   [(set (match_operand:DI 0 "register_operand")
15276         (unspec:DI [(match_operand:XF 1 "register_operand")]
15277                    UNSPEC_FIST))
15278    (clobber (match_operand:DI 2 "memory_operand"))
15279    (clobber (match_scratch 3))]
15280   "reload_completed"
15281   [(parallel [(set (match_dup 2) (unspec:DI [(match_dup 1)] UNSPEC_FIST))
15282               (clobber (match_dup 3))])
15283    (set (match_dup 0) (match_dup 2))])
15284
15285 (define_split
15286   [(set (match_operand:DI 0 "memory_operand")
15287         (unspec:DI [(match_operand:XF 1 "register_operand")]
15288                    UNSPEC_FIST))
15289    (clobber (match_operand:DI 2 "memory_operand"))
15290    (clobber (match_scratch 3))]
15291   "reload_completed"
15292   [(parallel [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_FIST))
15293               (clobber (match_dup 3))])])
15294
15295 (define_insn_and_split "*fist<mode>2_1"
15296   [(set (match_operand:SWI24 0 "register_operand")
15297         (unspec:SWI24 [(match_operand:XF 1 "register_operand")]
15298                       UNSPEC_FIST))]
15299   "TARGET_USE_FANCY_MATH_387
15300    && can_create_pseudo_p ()"
15301   "#"
15302   "&& 1"
15303   [(const_int 0)]
15304 {
15305   operands[2] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
15306   emit_insn (gen_fist<mode>2_with_temp (operands[0], operands[1],
15307                                         operands[2]));
15308   DONE;
15309 }
15310   [(set_attr "type" "fpspc")
15311    (set_attr "mode" "<MODE>")])
15312
15313 (define_insn "fist<mode>2"
15314   [(set (match_operand:SWI24 0 "memory_operand" "=m")
15315         (unspec:SWI24 [(match_operand:XF 1 "register_operand" "f")]
15316                       UNSPEC_FIST))]
15317   "TARGET_USE_FANCY_MATH_387"
15318   "* return output_fix_trunc (insn, operands, false);"
15319   [(set_attr "type" "fpspc")
15320    (set_attr "mode" "<MODE>")])
15321
15322 (define_insn "fist<mode>2_with_temp"
15323   [(set (match_operand:SWI24 0 "register_operand" "=r")
15324         (unspec:SWI24 [(match_operand:XF 1 "register_operand" "f")]
15325                       UNSPEC_FIST))
15326    (clobber (match_operand:SWI24 2 "memory_operand" "=m"))]
15327   "TARGET_USE_FANCY_MATH_387"
15328   "#"
15329   [(set_attr "type" "fpspc")
15330    (set_attr "mode" "<MODE>")])
15331
15332 (define_split
15333   [(set (match_operand:SWI24 0 "register_operand")
15334         (unspec:SWI24 [(match_operand:XF 1 "register_operand")]
15335                       UNSPEC_FIST))
15336    (clobber (match_operand:SWI24 2 "memory_operand"))]
15337   "reload_completed"
15338   [(set (match_dup 2) (unspec:SWI24 [(match_dup 1)] UNSPEC_FIST))
15339    (set (match_dup 0) (match_dup 2))])
15340
15341 (define_split
15342   [(set (match_operand:SWI24 0 "memory_operand")
15343         (unspec:SWI24 [(match_operand:XF 1 "register_operand")]
15344                       UNSPEC_FIST))
15345    (clobber (match_operand:SWI24 2 "memory_operand"))]
15346   "reload_completed"
15347   [(set (match_dup 0) (unspec:SWI24 [(match_dup 1)] UNSPEC_FIST))])
15348
15349 (define_expand "lrintxf<mode>2"
15350   [(set (match_operand:SWI248x 0 "nonimmediate_operand")
15351      (unspec:SWI248x [(match_operand:XF 1 "register_operand")]
15352                      UNSPEC_FIST))]
15353   "TARGET_USE_FANCY_MATH_387")
15354
15355 (define_expand "lrint<MODEF:mode><SWI48:mode>2"
15356   [(set (match_operand:SWI48 0 "nonimmediate_operand")
15357      (unspec:SWI48 [(match_operand:MODEF 1 "register_operand")]
15358                    UNSPEC_FIX_NOTRUNC))]
15359   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH")
15360
15361 (define_expand "lround<X87MODEF:mode><SWI248x:mode>2"
15362   [(match_operand:SWI248x 0 "nonimmediate_operand")
15363    (match_operand:X87MODEF 1 "register_operand")]
15364   "(TARGET_USE_FANCY_MATH_387
15365     && (!(SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH)
15366         || TARGET_MIX_SSE_I387)
15367     && flag_unsafe_math_optimizations)
15368    || (SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH
15369        && <SWI248x:MODE>mode != HImode 
15370        && ((<SWI248x:MODE>mode != DImode) || TARGET_64BIT)
15371        && !flag_trapping_math && !flag_rounding_math)"
15372 {
15373   if (optimize_insn_for_size_p ())
15374     FAIL;
15375
15376   if (SSE_FLOAT_MODE_P (<X87MODEF:MODE>mode) && TARGET_SSE_MATH
15377       && <SWI248x:MODE>mode != HImode
15378       && ((<SWI248x:MODE>mode != DImode) || TARGET_64BIT)
15379       && !flag_trapping_math && !flag_rounding_math)
15380     ix86_expand_lround (operands[0], operands[1]);
15381   else
15382     ix86_emit_i387_round (operands[0], operands[1]);
15383   DONE;
15384 })
15385
15386 (define_int_iterator FRNDINT_ROUNDING
15387         [UNSPEC_FRNDINT_FLOOR
15388          UNSPEC_FRNDINT_CEIL
15389          UNSPEC_FRNDINT_TRUNC])
15390
15391 (define_int_iterator FIST_ROUNDING
15392         [UNSPEC_FIST_FLOOR
15393          UNSPEC_FIST_CEIL])
15394
15395 ;; Base name for define_insn
15396 (define_int_attr rounding_insn
15397         [(UNSPEC_FRNDINT_FLOOR "floor")
15398          (UNSPEC_FRNDINT_CEIL "ceil")
15399          (UNSPEC_FRNDINT_TRUNC "btrunc")
15400          (UNSPEC_FIST_FLOOR "floor")
15401          (UNSPEC_FIST_CEIL "ceil")])
15402
15403 (define_int_attr rounding
15404         [(UNSPEC_FRNDINT_FLOOR "floor")
15405          (UNSPEC_FRNDINT_CEIL "ceil")
15406          (UNSPEC_FRNDINT_TRUNC "trunc")
15407          (UNSPEC_FIST_FLOOR "floor")
15408          (UNSPEC_FIST_CEIL "ceil")])
15409
15410 (define_int_attr ROUNDING
15411         [(UNSPEC_FRNDINT_FLOOR "FLOOR")
15412          (UNSPEC_FRNDINT_CEIL "CEIL")
15413          (UNSPEC_FRNDINT_TRUNC "TRUNC")
15414          (UNSPEC_FIST_FLOOR "FLOOR")
15415          (UNSPEC_FIST_CEIL "CEIL")])
15416
15417 ;; Rounding mode control word calculation could clobber FLAGS_REG.
15418 (define_insn_and_split "frndintxf2_<rounding>"
15419   [(set (match_operand:XF 0 "register_operand")
15420         (unspec:XF [(match_operand:XF 1 "register_operand")]
15421                    FRNDINT_ROUNDING))
15422    (clobber (reg:CC FLAGS_REG))]
15423   "TARGET_USE_FANCY_MATH_387
15424    && flag_unsafe_math_optimizations
15425    && can_create_pseudo_p ()"
15426   "#"
15427   "&& 1"
15428   [(const_int 0)]
15429 {
15430   ix86_optimize_mode_switching[I387_<ROUNDING>] = 1;
15431
15432   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
15433   operands[3] = assign_386_stack_local (HImode, SLOT_CW_<ROUNDING>);
15434
15435   emit_insn (gen_frndintxf2_<rounding>_i387 (operands[0], operands[1],
15436                                              operands[2], operands[3]));
15437   DONE;
15438 }
15439   [(set_attr "type" "frndint")
15440    (set_attr "i387_cw" "<rounding>")
15441    (set_attr "mode" "XF")])
15442
15443 (define_insn "frndintxf2_<rounding>_i387"
15444   [(set (match_operand:XF 0 "register_operand" "=f")
15445         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
15446                    FRNDINT_ROUNDING))
15447    (use (match_operand:HI 2 "memory_operand" "m"))
15448    (use (match_operand:HI 3 "memory_operand" "m"))]
15449   "TARGET_USE_FANCY_MATH_387
15450    && flag_unsafe_math_optimizations"
15451   "fldcw\t%3\n\tfrndint\n\tfldcw\t%2"
15452   [(set_attr "type" "frndint")
15453    (set_attr "i387_cw" "<rounding>")
15454    (set_attr "mode" "XF")])
15455
15456 (define_expand "<rounding_insn>xf2"
15457   [(parallel [(set (match_operand:XF 0 "register_operand")
15458                    (unspec:XF [(match_operand:XF 1 "register_operand")]
15459                               FRNDINT_ROUNDING))
15460               (clobber (reg:CC FLAGS_REG))])]
15461   "TARGET_USE_FANCY_MATH_387
15462    && flag_unsafe_math_optimizations
15463    && !optimize_insn_for_size_p ()")
15464
15465 (define_expand "<rounding_insn><mode>2"
15466   [(parallel [(set (match_operand:MODEF 0 "register_operand")
15467                    (unspec:MODEF [(match_operand:MODEF 1 "register_operand")]
15468                                  FRNDINT_ROUNDING))
15469               (clobber (reg:CC FLAGS_REG))])]
15470   "(TARGET_USE_FANCY_MATH_387
15471     && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15472         || TARGET_MIX_SSE_I387)
15473     && flag_unsafe_math_optimizations)
15474    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15475        && !flag_trapping_math)"
15476 {
15477   if (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH
15478       && !flag_trapping_math)
15479     {
15480       if (TARGET_ROUND)
15481         emit_insn (gen_sse4_1_round<mode>2
15482                    (operands[0], operands[1], GEN_INT (ROUND_<ROUNDING>)));
15483       else if (optimize_insn_for_size_p ())
15484         FAIL;
15485       else if (TARGET_64BIT || (<MODE>mode != DFmode))
15486         {
15487           if (ROUND_<ROUNDING> == ROUND_FLOOR)
15488             ix86_expand_floorceil (operands[0], operands[1], true);
15489           else if (ROUND_<ROUNDING> == ROUND_CEIL)
15490             ix86_expand_floorceil (operands[0], operands[1], false);
15491           else if (ROUND_<ROUNDING> == ROUND_TRUNC)
15492             ix86_expand_trunc (operands[0], operands[1]);
15493           else
15494             gcc_unreachable ();
15495         }
15496       else
15497         {
15498           if (ROUND_<ROUNDING> == ROUND_FLOOR)
15499             ix86_expand_floorceildf_32 (operands[0], operands[1], true);
15500           else if (ROUND_<ROUNDING> == ROUND_CEIL)
15501             ix86_expand_floorceildf_32 (operands[0], operands[1], false);
15502           else if (ROUND_<ROUNDING> == ROUND_TRUNC)
15503             ix86_expand_truncdf_32 (operands[0], operands[1]);
15504           else
15505             gcc_unreachable ();
15506         }
15507     }
15508   else
15509     {
15510       rtx op0, op1;
15511
15512       if (optimize_insn_for_size_p ())
15513         FAIL;
15514
15515       op0 = gen_reg_rtx (XFmode);
15516       op1 = gen_reg_rtx (XFmode);
15517       emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15518       emit_insn (gen_frndintxf2_<rounding> (op0, op1));
15519
15520       emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15521     }
15522   DONE;
15523 })
15524
15525 ;; Rounding mode control word calculation could clobber FLAGS_REG.
15526 (define_insn_and_split "frndintxf2_mask_pm"
15527   [(set (match_operand:XF 0 "register_operand")
15528         (unspec:XF [(match_operand:XF 1 "register_operand")]
15529                    UNSPEC_FRNDINT_MASK_PM))
15530    (clobber (reg:CC FLAGS_REG))]
15531   "TARGET_USE_FANCY_MATH_387
15532    && flag_unsafe_math_optimizations
15533    && can_create_pseudo_p ()"
15534   "#"
15535   "&& 1"
15536   [(const_int 0)]
15537 {
15538   ix86_optimize_mode_switching[I387_MASK_PM] = 1;
15539
15540   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
15541   operands[3] = assign_386_stack_local (HImode, SLOT_CW_MASK_PM);
15542
15543   emit_insn (gen_frndintxf2_mask_pm_i387 (operands[0], operands[1],
15544                                           operands[2], operands[3]));
15545   DONE;
15546 }
15547   [(set_attr "type" "frndint")
15548    (set_attr "i387_cw" "mask_pm")
15549    (set_attr "mode" "XF")])
15550
15551 (define_insn "frndintxf2_mask_pm_i387"
15552   [(set (match_operand:XF 0 "register_operand" "=f")
15553         (unspec:XF [(match_operand:XF 1 "register_operand" "0")]
15554                    UNSPEC_FRNDINT_MASK_PM))
15555    (use (match_operand:HI 2 "memory_operand" "m"))
15556    (use (match_operand:HI 3 "memory_operand" "m"))]
15557   "TARGET_USE_FANCY_MATH_387
15558    && flag_unsafe_math_optimizations"
15559   "fldcw\t%3\n\tfrndint\n\tfclex\n\tfldcw\t%2"
15560   [(set_attr "type" "frndint")
15561    (set_attr "i387_cw" "mask_pm")
15562    (set_attr "mode" "XF")])
15563
15564 (define_expand "nearbyintxf2"
15565   [(parallel [(set (match_operand:XF 0 "register_operand")
15566                    (unspec:XF [(match_operand:XF 1 "register_operand")]
15567                               UNSPEC_FRNDINT_MASK_PM))
15568               (clobber (reg:CC FLAGS_REG))])]
15569   "TARGET_USE_FANCY_MATH_387
15570    && flag_unsafe_math_optimizations")
15571
15572 (define_expand "nearbyint<mode>2"
15573   [(use (match_operand:MODEF 0 "register_operand"))
15574    (use (match_operand:MODEF 1 "register_operand"))]
15575   "TARGET_USE_FANCY_MATH_387
15576    && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
15577        || TARGET_MIX_SSE_I387)
15578    && flag_unsafe_math_optimizations"
15579 {
15580   rtx op0 = gen_reg_rtx (XFmode);
15581   rtx op1 = gen_reg_rtx (XFmode);
15582
15583   emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
15584   emit_insn (gen_frndintxf2_mask_pm (op0, op1));
15585
15586   emit_insn (gen_truncxf<mode>2_i387_noop (operands[0], op0));
15587   DONE;
15588 })
15589
15590 ;; Rounding mode control word calculation could clobber FLAGS_REG.
15591 (define_insn_and_split "*fist<mode>2_<rounding>_1"
15592   [(set (match_operand:SWI248x 0 "nonimmediate_operand")
15593         (unspec:SWI248x [(match_operand:XF 1 "register_operand")]
15594                         FIST_ROUNDING))
15595    (clobber (reg:CC FLAGS_REG))]
15596   "TARGET_USE_FANCY_MATH_387
15597    && flag_unsafe_math_optimizations
15598    && can_create_pseudo_p ()"
15599   "#"
15600   "&& 1"
15601   [(const_int 0)]
15602 {
15603   ix86_optimize_mode_switching[I387_<ROUNDING>] = 1;
15604
15605   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
15606   operands[3] = assign_386_stack_local (HImode, SLOT_CW_<ROUNDING>);
15607   if (memory_operand (operands[0], VOIDmode))
15608     emit_insn (gen_fist<mode>2_<rounding> (operands[0], operands[1],
15609                                            operands[2], operands[3]));
15610   else
15611     {
15612       operands[4] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
15613       emit_insn (gen_fist<mode>2_<rounding>_with_temp
15614                   (operands[0], operands[1], operands[2],
15615                    operands[3], operands[4]));
15616     }
15617   DONE;
15618 }
15619   [(set_attr "type" "fistp")
15620    (set_attr "i387_cw" "<rounding>")
15621    (set_attr "mode" "<MODE>")])
15622
15623 (define_insn "fistdi2_<rounding>"
15624   [(set (match_operand:DI 0 "memory_operand" "=m")
15625         (unspec:DI [(match_operand:XF 1 "register_operand" "f")]
15626                    FIST_ROUNDING))
15627    (use (match_operand:HI 2 "memory_operand" "m"))
15628    (use (match_operand:HI 3 "memory_operand" "m"))
15629    (clobber (match_scratch:XF 4 "=&1f"))]
15630   "TARGET_USE_FANCY_MATH_387
15631    && flag_unsafe_math_optimizations"
15632   "* return output_fix_trunc (insn, operands, false);"
15633   [(set_attr "type" "fistp")
15634    (set_attr "i387_cw" "<rounding>")
15635    (set_attr "mode" "DI")])
15636
15637 (define_insn "fistdi2_<rounding>_with_temp"
15638   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r")
15639         (unspec:DI [(match_operand:XF 1 "register_operand" "f,f")]
15640                    FIST_ROUNDING))
15641    (use (match_operand:HI 2 "memory_operand" "m,m"))
15642    (use (match_operand:HI 3 "memory_operand" "m,m"))
15643    (clobber (match_operand:DI 4 "memory_operand" "=X,m"))
15644    (clobber (match_scratch:XF 5 "=&1f,&1f"))]
15645   "TARGET_USE_FANCY_MATH_387
15646    && flag_unsafe_math_optimizations"
15647   "#"
15648   [(set_attr "type" "fistp")
15649    (set_attr "i387_cw" "<rounding>")
15650    (set_attr "mode" "DI")])
15651
15652 (define_split
15653   [(set (match_operand:DI 0 "register_operand")
15654         (unspec:DI [(match_operand:XF 1 "register_operand")]
15655                    FIST_ROUNDING))
15656    (use (match_operand:HI 2 "memory_operand"))
15657    (use (match_operand:HI 3 "memory_operand"))
15658    (clobber (match_operand:DI 4 "memory_operand"))
15659    (clobber (match_scratch 5))]
15660   "reload_completed"
15661   [(parallel [(set (match_dup 4)
15662                    (unspec:DI [(match_dup 1)] FIST_ROUNDING))
15663               (use (match_dup 2))
15664               (use (match_dup 3))
15665               (clobber (match_dup 5))])
15666    (set (match_dup 0) (match_dup 4))])
15667
15668 (define_split
15669   [(set (match_operand:DI 0 "memory_operand")
15670         (unspec:DI [(match_operand:XF 1 "register_operand")]
15671                    FIST_ROUNDING))
15672    (use (match_operand:HI 2 "memory_operand"))
15673    (use (match_operand:HI 3 "memory_operand"))
15674    (clobber (match_operand:DI 4 "memory_operand"))
15675    (clobber (match_scratch 5))]
15676   "reload_completed"
15677   [(parallel [(set (match_dup 0)
15678                    (unspec:DI [(match_dup 1)] FIST_ROUNDING))
15679               (use (match_dup 2))
15680               (use (match_dup 3))
15681               (clobber (match_dup 5))])])
15682
15683 (define_insn "fist<mode>2_<rounding>"
15684   [(set (match_operand:SWI24 0 "memory_operand" "=m")
15685         (unspec:SWI24 [(match_operand:XF 1 "register_operand" "f")]
15686                       FIST_ROUNDING))
15687    (use (match_operand:HI 2 "memory_operand" "m"))
15688    (use (match_operand:HI 3 "memory_operand" "m"))]
15689   "TARGET_USE_FANCY_MATH_387
15690    && flag_unsafe_math_optimizations"
15691   "* return output_fix_trunc (insn, operands, false);"
15692   [(set_attr "type" "fistp")
15693    (set_attr "i387_cw" "<rounding>")
15694    (set_attr "mode" "<MODE>")])
15695
15696 (define_insn "fist<mode>2_<rounding>_with_temp"
15697   [(set (match_operand:SWI24 0 "nonimmediate_operand" "=m,?r")
15698         (unspec:SWI24 [(match_operand:XF 1 "register_operand" "f,f")]
15699                       FIST_ROUNDING))
15700    (use (match_operand:HI 2 "memory_operand" "m,m"))
15701    (use (match_operand:HI 3 "memory_operand" "m,m"))
15702    (clobber (match_operand:SWI24 4 "memory_operand" "=X,m"))]
15703   "TARGET_USE_FANCY_MATH_387
15704    && flag_unsafe_math_optimizations"
15705   "#"
15706   [(set_attr "type" "fistp")
15707    (set_attr "i387_cw" "<rounding>")
15708    (set_attr "mode" "<MODE>")])
15709
15710 (define_split
15711   [(set (match_operand:SWI24 0 "register_operand")
15712         (unspec:SWI24 [(match_operand:XF 1 "register_operand")]
15713                       FIST_ROUNDING))
15714    (use (match_operand:HI 2 "memory_operand"))
15715    (use (match_operand:HI 3 "memory_operand"))
15716    (clobber (match_operand:SWI24 4 "memory_operand"))]
15717   "reload_completed"
15718   [(parallel [(set (match_dup 4)
15719                    (unspec:SWI24 [(match_dup 1)] FIST_ROUNDING))
15720               (use (match_dup 2))
15721               (use (match_dup 3))])
15722    (set (match_dup 0) (match_dup 4))])
15723
15724 (define_split
15725   [(set (match_operand:SWI24 0 "memory_operand")
15726         (unspec:SWI24 [(match_operand:XF 1 "register_operand")]
15727                       FIST_ROUNDING))
15728    (use (match_operand:HI 2 "memory_operand"))
15729    (use (match_operand:HI 3 "memory_operand"))
15730    (clobber (match_operand:SWI24 4 "memory_operand"))]
15731   "reload_completed"
15732   [(parallel [(set (match_dup 0)
15733                    (unspec:SWI24 [(match_dup 1)] FIST_ROUNDING))
15734               (use (match_dup 2))
15735               (use (match_dup 3))])])
15736
15737 (define_expand "l<rounding_insn>xf<mode>2"
15738   [(parallel [(set (match_operand:SWI248x 0 "nonimmediate_operand")
15739                    (unspec:SWI248x [(match_operand:XF 1 "register_operand")]
15740                                    FIST_ROUNDING))
15741               (clobber (reg:CC FLAGS_REG))])]
15742   "TARGET_USE_FANCY_MATH_387
15743    && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387)
15744    && flag_unsafe_math_optimizations")
15745
15746 (define_expand "l<rounding_insn><MODEF:mode><SWI48:mode>2"
15747   [(parallel [(set (match_operand:SWI48 0 "nonimmediate_operand")
15748                    (unspec:SWI48 [(match_operand:MODEF 1 "register_operand")]
15749                                  FIST_ROUNDING))
15750               (clobber (reg:CC FLAGS_REG))])]
15751   "SSE_FLOAT_MODE_P (<MODEF:MODE>mode) && TARGET_SSE_MATH
15752    && !flag_trapping_math"
15753 {
15754   if (TARGET_64BIT && optimize_insn_for_size_p ())
15755     FAIL;
15756
15757   if (ROUND_<ROUNDING> == ROUND_FLOOR)
15758     ix86_expand_lfloorceil (operands[0], operands[1], true);
15759   else if (ROUND_<ROUNDING> == ROUND_CEIL)
15760     ix86_expand_lfloorceil (operands[0], operands[1], false);
15761   else
15762     gcc_unreachable ();
15763
15764   DONE;
15765 })
15766
15767 (define_insn "fxam<mode>2_i387"
15768   [(set (match_operand:HI 0 "register_operand" "=a")
15769         (unspec:HI
15770           [(match_operand:X87MODEF 1 "register_operand" "f")]
15771           UNSPEC_FXAM))]
15772   "TARGET_USE_FANCY_MATH_387"
15773   "fxam\n\tfnstsw\t%0"
15774   [(set_attr "type" "multi")
15775    (set_attr "length" "4")
15776    (set_attr "unit" "i387")
15777    (set_attr "mode" "<MODE>")])
15778
15779 (define_insn_and_split "fxam<mode>2_i387_with_temp"
15780   [(set (match_operand:HI 0 "register_operand")
15781         (unspec:HI
15782           [(match_operand:MODEF 1 "memory_operand")]
15783           UNSPEC_FXAM_MEM))]
15784   "TARGET_USE_FANCY_MATH_387
15785    && can_create_pseudo_p ()"
15786   "#"
15787   "&& 1"
15788   [(set (match_dup 2)(match_dup 1))
15789    (set (match_dup 0)
15790         (unspec:HI [(match_dup 2)] UNSPEC_FXAM))]
15791 {
15792   operands[2] = gen_reg_rtx (<MODE>mode);
15793
15794   MEM_VOLATILE_P (operands[1]) = 1;
15795 }
15796   [(set_attr "type" "multi")
15797    (set_attr "unit" "i387")
15798    (set_attr "mode" "<MODE>")])
15799
15800 (define_expand "isinfxf2"
15801   [(use (match_operand:SI 0 "register_operand"))
15802    (use (match_operand:XF 1 "register_operand"))]
15803   "TARGET_USE_FANCY_MATH_387
15804    && ix86_libc_has_function (function_c99_misc)"
15805 {
15806   rtx mask = GEN_INT (0x45);
15807   rtx val = GEN_INT (0x05);
15808
15809   rtx cond;
15810
15811   rtx scratch = gen_reg_rtx (HImode);
15812   rtx res = gen_reg_rtx (QImode);
15813
15814   emit_insn (gen_fxamxf2_i387 (scratch, operands[1]));
15815
15816   emit_insn (gen_andqi_ext_0 (scratch, scratch, mask));
15817   emit_insn (gen_cmpqi_ext_3 (scratch, val));
15818   cond = gen_rtx_fmt_ee (EQ, QImode,
15819                          gen_rtx_REG (CCmode, FLAGS_REG),
15820                          const0_rtx);
15821   emit_insn (gen_rtx_SET (VOIDmode, res, cond));
15822   emit_insn (gen_zero_extendqisi2 (operands[0], res));
15823   DONE;
15824 })
15825
15826 (define_expand "isinf<mode>2"
15827   [(use (match_operand:SI 0 "register_operand"))
15828    (use (match_operand:MODEF 1 "nonimmediate_operand"))]
15829   "TARGET_USE_FANCY_MATH_387
15830    && ix86_libc_has_function (function_c99_misc)
15831    && !(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
15832 {
15833   rtx mask = GEN_INT (0x45);
15834   rtx val = GEN_INT (0x05);
15835
15836   rtx cond;
15837
15838   rtx scratch = gen_reg_rtx (HImode);
15839   rtx res = gen_reg_rtx (QImode);
15840
15841   /* Remove excess precision by forcing value through memory. */
15842   if (memory_operand (operands[1], VOIDmode))
15843     emit_insn (gen_fxam<mode>2_i387_with_temp (scratch, operands[1]));
15844   else
15845     {
15846       rtx temp = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
15847
15848       emit_move_insn (temp, operands[1]);
15849       emit_insn (gen_fxam<mode>2_i387_with_temp (scratch, temp));
15850     }
15851
15852   emit_insn (gen_andqi_ext_0 (scratch, scratch, mask));
15853   emit_insn (gen_cmpqi_ext_3 (scratch, val));
15854   cond = gen_rtx_fmt_ee (EQ, QImode,
15855                          gen_rtx_REG (CCmode, FLAGS_REG),
15856                          const0_rtx);
15857   emit_insn (gen_rtx_SET (VOIDmode, res, cond));
15858   emit_insn (gen_zero_extendqisi2 (operands[0], res));
15859   DONE;
15860 })
15861
15862 (define_expand "signbitxf2"
15863   [(use (match_operand:SI 0 "register_operand"))
15864    (use (match_operand:XF 1 "register_operand"))]
15865   "TARGET_USE_FANCY_MATH_387"
15866 {
15867   rtx scratch = gen_reg_rtx (HImode);
15868
15869   emit_insn (gen_fxamxf2_i387 (scratch, operands[1]));
15870   emit_insn (gen_andsi3 (operands[0],
15871              gen_lowpart (SImode, scratch), GEN_INT (0x200)));
15872   DONE;
15873 })
15874
15875 (define_insn "movmsk_df"
15876   [(set (match_operand:SI 0 "register_operand" "=r")
15877         (unspec:SI
15878           [(match_operand:DF 1 "register_operand" "x")]
15879           UNSPEC_MOVMSK))]
15880   "SSE_FLOAT_MODE_P (DFmode) && TARGET_SSE_MATH"
15881   "%vmovmskpd\t{%1, %0|%0, %1}"
15882   [(set_attr "type" "ssemov")
15883    (set_attr "prefix" "maybe_vex")
15884    (set_attr "mode" "DF")])
15885
15886 ;; Use movmskpd in SSE mode to avoid store forwarding stall
15887 ;; for 32bit targets and movq+shrq sequence for 64bit targets.
15888 (define_expand "signbitdf2"
15889   [(use (match_operand:SI 0 "register_operand"))
15890    (use (match_operand:DF 1 "register_operand"))]
15891   "TARGET_USE_FANCY_MATH_387
15892    || (SSE_FLOAT_MODE_P (DFmode) && TARGET_SSE_MATH)"
15893 {
15894   if (SSE_FLOAT_MODE_P (DFmode) && TARGET_SSE_MATH)
15895     {
15896       emit_insn (gen_movmsk_df (operands[0], operands[1]));
15897       emit_insn (gen_andsi3 (operands[0], operands[0], const1_rtx));
15898     }
15899   else
15900     {
15901       rtx scratch = gen_reg_rtx (HImode);
15902
15903       emit_insn (gen_fxamdf2_i387 (scratch, operands[1]));
15904       emit_insn (gen_andsi3 (operands[0],
15905                  gen_lowpart (SImode, scratch), GEN_INT (0x200)));
15906     }
15907   DONE;
15908 })
15909
15910 (define_expand "signbitsf2"
15911   [(use (match_operand:SI 0 "register_operand"))
15912    (use (match_operand:SF 1 "register_operand"))]
15913   "TARGET_USE_FANCY_MATH_387
15914    && !(SSE_FLOAT_MODE_P (SFmode) && TARGET_SSE_MATH)"
15915 {
15916   rtx scratch = gen_reg_rtx (HImode);
15917
15918   emit_insn (gen_fxamsf2_i387 (scratch, operands[1]));
15919   emit_insn (gen_andsi3 (operands[0],
15920              gen_lowpart (SImode, scratch), GEN_INT (0x200)));
15921   DONE;
15922 })
15923 \f
15924 ;; Block operation instructions
15925
15926 (define_insn "cld"
15927   [(unspec_volatile [(const_int 0)] UNSPECV_CLD)]
15928   ""
15929   "cld"
15930   [(set_attr "length" "1")
15931    (set_attr "length_immediate" "0")
15932    (set_attr "modrm" "0")])
15933
15934 (define_expand "movmem<mode>"
15935   [(use (match_operand:BLK 0 "memory_operand"))
15936    (use (match_operand:BLK 1 "memory_operand"))
15937    (use (match_operand:SWI48 2 "nonmemory_operand"))
15938    (use (match_operand:SWI48 3 "const_int_operand"))
15939    (use (match_operand:SI 4 "const_int_operand"))
15940    (use (match_operand:SI 5 "const_int_operand"))
15941    (use (match_operand:SI 6 ""))
15942    (use (match_operand:SI 7 ""))
15943    (use (match_operand:SI 8 ""))]
15944   ""
15945 {
15946  if (ix86_expand_set_or_movmem (operands[0], operands[1],
15947                                 operands[2], NULL, operands[3],
15948                                 operands[4], operands[5],
15949                                 operands[6], operands[7],
15950                                 operands[8], false))
15951    DONE;
15952  else
15953    FAIL;
15954 })
15955
15956 ;; Most CPUs don't like single string operations
15957 ;; Handle this case here to simplify previous expander.
15958
15959 (define_expand "strmov"
15960   [(set (match_dup 4) (match_operand 3 "memory_operand"))
15961    (set (match_operand 1 "memory_operand") (match_dup 4))
15962    (parallel [(set (match_operand 0 "register_operand") (match_dup 5))
15963               (clobber (reg:CC FLAGS_REG))])
15964    (parallel [(set (match_operand 2 "register_operand") (match_dup 6))
15965               (clobber (reg:CC FLAGS_REG))])]
15966   ""
15967 {
15968   rtx adjust = GEN_INT (GET_MODE_SIZE (GET_MODE (operands[1])));
15969
15970   /* If .md ever supports :P for Pmode, these can be directly
15971      in the pattern above.  */
15972   operands[5] = gen_rtx_PLUS (Pmode, operands[0], adjust);
15973   operands[6] = gen_rtx_PLUS (Pmode, operands[2], adjust);
15974
15975   /* Can't use this if the user has appropriated esi or edi.  */
15976   if ((TARGET_SINGLE_STRINGOP || optimize_insn_for_size_p ())
15977       && !(fixed_regs[SI_REG] || fixed_regs[DI_REG]))
15978     {
15979       emit_insn (gen_strmov_singleop (operands[0], operands[1],
15980                                       operands[2], operands[3],
15981                                       operands[5], operands[6]));
15982       DONE;
15983     }
15984
15985   operands[4] = gen_reg_rtx (GET_MODE (operands[1]));
15986 })
15987
15988 (define_expand "strmov_singleop"
15989   [(parallel [(set (match_operand 1 "memory_operand")
15990                    (match_operand 3 "memory_operand"))
15991               (set (match_operand 0 "register_operand")
15992                    (match_operand 4))
15993               (set (match_operand 2 "register_operand")
15994                    (match_operand 5))])]
15995   ""
15996   "ix86_current_function_needs_cld = 1;")
15997
15998 (define_insn "*strmovdi_rex_1"
15999   [(set (mem:DI (match_operand:P 2 "register_operand" "0"))
16000         (mem:DI (match_operand:P 3 "register_operand" "1")))
16001    (set (match_operand:P 0 "register_operand" "=D")
16002         (plus:P (match_dup 2)
16003                 (const_int 8)))
16004    (set (match_operand:P 1 "register_operand" "=S")
16005         (plus:P (match_dup 3)
16006                 (const_int 8)))]
16007   "TARGET_64BIT
16008    && !(fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16009   "%^movsq"
16010   [(set_attr "type" "str")
16011    (set_attr "memory" "both")
16012    (set_attr "mode" "DI")])
16013
16014 (define_insn "*strmovsi_1"
16015   [(set (mem:SI (match_operand:P 2 "register_operand" "0"))
16016         (mem:SI (match_operand:P 3 "register_operand" "1")))
16017    (set (match_operand:P 0 "register_operand" "=D")
16018         (plus:P (match_dup 2)
16019                 (const_int 4)))
16020    (set (match_operand:P 1 "register_operand" "=S")
16021         (plus:P (match_dup 3)
16022                 (const_int 4)))]
16023   "!(fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16024   "%^movs{l|d}"
16025   [(set_attr "type" "str")
16026    (set_attr "memory" "both")
16027    (set_attr "mode" "SI")])
16028
16029 (define_insn "*strmovhi_1"
16030   [(set (mem:HI (match_operand:P 2 "register_operand" "0"))
16031         (mem:HI (match_operand:P 3 "register_operand" "1")))
16032    (set (match_operand:P 0 "register_operand" "=D")
16033         (plus:P (match_dup 2)
16034                 (const_int 2)))
16035    (set (match_operand:P 1 "register_operand" "=S")
16036         (plus:P (match_dup 3)
16037                 (const_int 2)))]
16038   "!(fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16039   "%^movsw"
16040   [(set_attr "type" "str")
16041    (set_attr "memory" "both")
16042    (set_attr "mode" "HI")])
16043
16044 (define_insn "*strmovqi_1"
16045   [(set (mem:QI (match_operand:P 2 "register_operand" "0"))
16046         (mem:QI (match_operand:P 3 "register_operand" "1")))
16047    (set (match_operand:P 0 "register_operand" "=D")
16048         (plus:P (match_dup 2)
16049                 (const_int 1)))
16050    (set (match_operand:P 1 "register_operand" "=S")
16051         (plus:P (match_dup 3)
16052                 (const_int 1)))]
16053   "!(fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16054   "%^movsb"
16055   [(set_attr "type" "str")
16056    (set_attr "memory" "both")
16057    (set (attr "prefix_rex")
16058         (if_then_else
16059           (match_test "<P:MODE>mode == DImode")
16060           (const_string "0")
16061           (const_string "*")))
16062    (set_attr "mode" "QI")])
16063
16064 (define_expand "rep_mov"
16065   [(parallel [(set (match_operand 4 "register_operand") (const_int 0))
16066               (set (match_operand 0 "register_operand")
16067                    (match_operand 5))
16068               (set (match_operand 2 "register_operand")
16069                    (match_operand 6))
16070               (set (match_operand 1 "memory_operand")
16071                    (match_operand 3 "memory_operand"))
16072               (use (match_dup 4))])]
16073   ""
16074   "ix86_current_function_needs_cld = 1;")
16075
16076 (define_insn "*rep_movdi_rex64"
16077   [(set (match_operand:P 2 "register_operand" "=c") (const_int 0))
16078    (set (match_operand:P 0 "register_operand" "=D")
16079         (plus:P (ashift:P (match_operand:P 5 "register_operand" "2")
16080                           (const_int 3))
16081                 (match_operand:P 3 "register_operand" "0")))
16082    (set (match_operand:P 1 "register_operand" "=S")
16083         (plus:P (ashift:P (match_dup 5) (const_int 3))
16084                 (match_operand:P 4 "register_operand" "1")))
16085    (set (mem:BLK (match_dup 3))
16086         (mem:BLK (match_dup 4)))
16087    (use (match_dup 5))]
16088   "TARGET_64BIT
16089    && !(fixed_regs[CX_REG] || fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16090   "%^rep{%;} movsq"
16091   [(set_attr "type" "str")
16092    (set_attr "prefix_rep" "1")
16093    (set_attr "memory" "both")
16094    (set_attr "mode" "DI")])
16095
16096 (define_insn "*rep_movsi"
16097   [(set (match_operand:P 2 "register_operand" "=c") (const_int 0))
16098    (set (match_operand:P 0 "register_operand" "=D")
16099         (plus:P (ashift:P (match_operand:P 5 "register_operand" "2")
16100                           (const_int 2))
16101                  (match_operand:P 3 "register_operand" "0")))
16102    (set (match_operand:P 1 "register_operand" "=S")
16103         (plus:P (ashift:P (match_dup 5) (const_int 2))
16104                 (match_operand:P 4 "register_operand" "1")))
16105    (set (mem:BLK (match_dup 3))
16106         (mem:BLK (match_dup 4)))
16107    (use (match_dup 5))]
16108   "!(fixed_regs[CX_REG] || fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16109   "%^rep{%;} movs{l|d}"
16110   [(set_attr "type" "str")
16111    (set_attr "prefix_rep" "1")
16112    (set_attr "memory" "both")
16113    (set_attr "mode" "SI")])
16114
16115 (define_insn "*rep_movqi"
16116   [(set (match_operand:P 2 "register_operand" "=c") (const_int 0))
16117    (set (match_operand:P 0 "register_operand" "=D")
16118         (plus:P (match_operand:P 3 "register_operand" "0")
16119                 (match_operand:P 5 "register_operand" "2")))
16120    (set (match_operand:P 1 "register_operand" "=S")
16121         (plus:P (match_operand:P 4 "register_operand" "1") (match_dup 5)))
16122    (set (mem:BLK (match_dup 3))
16123         (mem:BLK (match_dup 4)))
16124    (use (match_dup 5))]
16125   "!(fixed_regs[CX_REG] || fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16126   "%^rep{%;} movsb"
16127   [(set_attr "type" "str")
16128    (set_attr "prefix_rep" "1")
16129    (set_attr "memory" "both")
16130    (set_attr "mode" "QI")])
16131
16132 (define_expand "setmem<mode>"
16133    [(use (match_operand:BLK 0 "memory_operand"))
16134     (use (match_operand:SWI48 1 "nonmemory_operand"))
16135     (use (match_operand:QI 2 "nonmemory_operand"))
16136     (use (match_operand 3 "const_int_operand"))
16137     (use (match_operand:SI 4 "const_int_operand"))
16138     (use (match_operand:SI 5 "const_int_operand"))
16139     (use (match_operand:SI 6 ""))
16140     (use (match_operand:SI 7 ""))
16141     (use (match_operand:SI 8 ""))]
16142   ""
16143 {
16144  if (ix86_expand_set_or_movmem (operands[0], NULL,
16145                                 operands[1], operands[2],
16146                                 operands[3], operands[4],
16147                                 operands[5], operands[6],
16148                                 operands[7], operands[8], true))
16149    DONE;
16150  else
16151    FAIL;
16152 })
16153
16154 ;; Most CPUs don't like single string operations
16155 ;; Handle this case here to simplify previous expander.
16156
16157 (define_expand "strset"
16158   [(set (match_operand 1 "memory_operand")
16159         (match_operand 2 "register_operand"))
16160    (parallel [(set (match_operand 0 "register_operand")
16161                    (match_dup 3))
16162               (clobber (reg:CC FLAGS_REG))])]
16163   ""
16164 {
16165   if (GET_MODE (operands[1]) != GET_MODE (operands[2]))
16166     operands[1] = adjust_address_nv (operands[1], GET_MODE (operands[2]), 0);
16167
16168   /* If .md ever supports :P for Pmode, this can be directly
16169      in the pattern above.  */
16170   operands[3] = gen_rtx_PLUS (Pmode, operands[0],
16171                               GEN_INT (GET_MODE_SIZE (GET_MODE
16172                                                       (operands[2]))));
16173   /* Can't use this if the user has appropriated eax or edi.  */
16174   if ((TARGET_SINGLE_STRINGOP || optimize_insn_for_size_p ())
16175       && !(fixed_regs[AX_REG] || fixed_regs[DI_REG]))
16176     {
16177       emit_insn (gen_strset_singleop (operands[0], operands[1], operands[2],
16178                                       operands[3]));
16179       DONE;
16180     }
16181 })
16182
16183 (define_expand "strset_singleop"
16184   [(parallel [(set (match_operand 1 "memory_operand")
16185                    (match_operand 2 "register_operand"))
16186               (set (match_operand 0 "register_operand")
16187                    (match_operand 3))
16188               (unspec [(const_int 0)] UNSPEC_STOS)])]
16189   ""
16190   "ix86_current_function_needs_cld = 1;")
16191
16192 (define_insn "*strsetdi_rex_1"
16193   [(set (mem:DI (match_operand:P 1 "register_operand" "0"))
16194         (match_operand:DI 2 "register_operand" "a"))
16195    (set (match_operand:P 0 "register_operand" "=D")
16196         (plus:P (match_dup 1)
16197                 (const_int 8)))
16198    (unspec [(const_int 0)] UNSPEC_STOS)]
16199   "TARGET_64BIT
16200    && !(fixed_regs[AX_REG] || fixed_regs[DI_REG])"
16201   "%^stosq"
16202   [(set_attr "type" "str")
16203    (set_attr "memory" "store")
16204    (set_attr "mode" "DI")])
16205
16206 (define_insn "*strsetsi_1"
16207   [(set (mem:SI (match_operand:P 1 "register_operand" "0"))
16208         (match_operand:SI 2 "register_operand" "a"))
16209    (set (match_operand:P 0 "register_operand" "=D")
16210         (plus:P (match_dup 1)
16211                 (const_int 4)))
16212    (unspec [(const_int 0)] UNSPEC_STOS)]
16213   "!(fixed_regs[AX_REG] || fixed_regs[DI_REG])"
16214   "%^stos{l|d}"
16215   [(set_attr "type" "str")
16216    (set_attr "memory" "store")
16217    (set_attr "mode" "SI")])
16218
16219 (define_insn "*strsethi_1"
16220   [(set (mem:HI (match_operand:P 1 "register_operand" "0"))
16221         (match_operand:HI 2 "register_operand" "a"))
16222    (set (match_operand:P 0 "register_operand" "=D")
16223         (plus:P (match_dup 1)
16224                 (const_int 2)))
16225    (unspec [(const_int 0)] UNSPEC_STOS)]
16226   "!(fixed_regs[AX_REG] || fixed_regs[DI_REG])"
16227   "%^stosw"
16228   [(set_attr "type" "str")
16229    (set_attr "memory" "store")
16230    (set_attr "mode" "HI")])
16231
16232 (define_insn "*strsetqi_1"
16233   [(set (mem:QI (match_operand:P 1 "register_operand" "0"))
16234         (match_operand:QI 2 "register_operand" "a"))
16235    (set (match_operand:P 0 "register_operand" "=D")
16236         (plus:P (match_dup 1)
16237                 (const_int 1)))
16238    (unspec [(const_int 0)] UNSPEC_STOS)]
16239   "!(fixed_regs[AX_REG] || fixed_regs[DI_REG])"
16240   "%^stosb"
16241   [(set_attr "type" "str")
16242    (set_attr "memory" "store")
16243    (set (attr "prefix_rex")
16244         (if_then_else
16245           (match_test "<P:MODE>mode == DImode")
16246           (const_string "0")
16247           (const_string "*")))
16248    (set_attr "mode" "QI")])
16249
16250 (define_expand "rep_stos"
16251   [(parallel [(set (match_operand 1 "register_operand") (const_int 0))
16252               (set (match_operand 0 "register_operand")
16253                    (match_operand 4))
16254               (set (match_operand 2 "memory_operand") (const_int 0))
16255               (use (match_operand 3 "register_operand"))
16256               (use (match_dup 1))])]
16257   ""
16258   "ix86_current_function_needs_cld = 1;")
16259
16260 (define_insn "*rep_stosdi_rex64"
16261   [(set (match_operand:P 1 "register_operand" "=c") (const_int 0))
16262    (set (match_operand:P 0 "register_operand" "=D")
16263         (plus:P (ashift:P (match_operand:P 4 "register_operand" "1")
16264                           (const_int 3))
16265                  (match_operand:P 3 "register_operand" "0")))
16266    (set (mem:BLK (match_dup 3))
16267         (const_int 0))
16268    (use (match_operand:DI 2 "register_operand" "a"))
16269    (use (match_dup 4))]
16270   "TARGET_64BIT
16271    && !(fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])"
16272   "%^rep{%;} stosq"
16273   [(set_attr "type" "str")
16274    (set_attr "prefix_rep" "1")
16275    (set_attr "memory" "store")
16276    (set_attr "mode" "DI")])
16277
16278 (define_insn "*rep_stossi"
16279   [(set (match_operand:P 1 "register_operand" "=c") (const_int 0))
16280    (set (match_operand:P 0 "register_operand" "=D")
16281         (plus:P (ashift:P (match_operand:P 4 "register_operand" "1")
16282                           (const_int 2))
16283                  (match_operand:P 3 "register_operand" "0")))
16284    (set (mem:BLK (match_dup 3))
16285         (const_int 0))
16286    (use (match_operand:SI 2 "register_operand" "a"))
16287    (use (match_dup 4))]
16288   "!(fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])"
16289   "%^rep{%;} stos{l|d}"
16290   [(set_attr "type" "str")
16291    (set_attr "prefix_rep" "1")
16292    (set_attr "memory" "store")
16293    (set_attr "mode" "SI")])
16294
16295 (define_insn "*rep_stosqi"
16296   [(set (match_operand:P 1 "register_operand" "=c") (const_int 0))
16297    (set (match_operand:P 0 "register_operand" "=D")
16298         (plus:P (match_operand:P 3 "register_operand" "0")
16299                 (match_operand:P 4 "register_operand" "1")))
16300    (set (mem:BLK (match_dup 3))
16301         (const_int 0))
16302    (use (match_operand:QI 2 "register_operand" "a"))
16303    (use (match_dup 4))]
16304   "!(fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])"
16305   "%^rep{%;} stosb"
16306   [(set_attr "type" "str")
16307    (set_attr "prefix_rep" "1")
16308    (set_attr "memory" "store")
16309    (set (attr "prefix_rex")
16310         (if_then_else
16311           (match_test "<P:MODE>mode == DImode")
16312           (const_string "0")
16313           (const_string "*")))
16314    (set_attr "mode" "QI")])
16315
16316 (define_expand "cmpstrnsi"
16317   [(set (match_operand:SI 0 "register_operand")
16318         (compare:SI (match_operand:BLK 1 "general_operand")
16319                     (match_operand:BLK 2 "general_operand")))
16320    (use (match_operand 3 "general_operand"))
16321    (use (match_operand 4 "immediate_operand"))]
16322   ""
16323 {
16324   rtx addr1, addr2, out, outlow, count, countreg, align;
16325
16326   if (optimize_insn_for_size_p () && !TARGET_INLINE_ALL_STRINGOPS)
16327     FAIL;
16328
16329   /* Can't use this if the user has appropriated ecx, esi or edi.  */
16330   if (fixed_regs[CX_REG] || fixed_regs[SI_REG] || fixed_regs[DI_REG])
16331     FAIL;
16332
16333   out = operands[0];
16334   if (!REG_P (out))
16335     out = gen_reg_rtx (SImode);
16336
16337   addr1 = copy_addr_to_reg (XEXP (operands[1], 0));
16338   addr2 = copy_addr_to_reg (XEXP (operands[2], 0));
16339   if (addr1 != XEXP (operands[1], 0))
16340     operands[1] = replace_equiv_address_nv (operands[1], addr1);
16341   if (addr2 != XEXP (operands[2], 0))
16342     operands[2] = replace_equiv_address_nv (operands[2], addr2);
16343
16344   count = operands[3];
16345   countreg = ix86_zero_extend_to_Pmode (count);
16346
16347   /* %%% Iff we are testing strict equality, we can use known alignment
16348      to good advantage.  This may be possible with combine, particularly
16349      once cc0 is dead.  */
16350   align = operands[4];
16351
16352   if (CONST_INT_P (count))
16353     {
16354       if (INTVAL (count) == 0)
16355         {
16356           emit_move_insn (operands[0], const0_rtx);
16357           DONE;
16358         }
16359       emit_insn (gen_cmpstrnqi_nz_1 (addr1, addr2, countreg, align,
16360                                      operands[1], operands[2]));
16361     }
16362   else
16363     {
16364       rtx (*gen_cmp) (rtx, rtx);
16365
16366       gen_cmp = (TARGET_64BIT
16367                  ? gen_cmpdi_1 : gen_cmpsi_1);
16368
16369       emit_insn (gen_cmp (countreg, countreg));
16370       emit_insn (gen_cmpstrnqi_1 (addr1, addr2, countreg, align,
16371                                   operands[1], operands[2]));
16372     }
16373
16374   outlow = gen_lowpart (QImode, out);
16375   emit_insn (gen_cmpintqi (outlow));
16376   emit_move_insn (out, gen_rtx_SIGN_EXTEND (SImode, outlow));
16377
16378   if (operands[0] != out)
16379     emit_move_insn (operands[0], out);
16380
16381   DONE;
16382 })
16383
16384 ;; Produce a tri-state integer (-1, 0, 1) from condition codes.
16385
16386 (define_expand "cmpintqi"
16387   [(set (match_dup 1)
16388         (gtu:QI (reg:CC FLAGS_REG) (const_int 0)))
16389    (set (match_dup 2)
16390         (ltu:QI (reg:CC FLAGS_REG) (const_int 0)))
16391    (parallel [(set (match_operand:QI 0 "register_operand")
16392                    (minus:QI (match_dup 1)
16393                              (match_dup 2)))
16394               (clobber (reg:CC FLAGS_REG))])]
16395   ""
16396 {
16397   operands[1] = gen_reg_rtx (QImode);
16398   operands[2] = gen_reg_rtx (QImode);
16399 })
16400
16401 ;; memcmp recognizers.  The `cmpsb' opcode does nothing if the count is
16402 ;; zero.  Emit extra code to make sure that a zero-length compare is EQ.
16403
16404 (define_expand "cmpstrnqi_nz_1"
16405   [(parallel [(set (reg:CC FLAGS_REG)
16406                    (compare:CC (match_operand 4 "memory_operand")
16407                                (match_operand 5 "memory_operand")))
16408               (use (match_operand 2 "register_operand"))
16409               (use (match_operand:SI 3 "immediate_operand"))
16410               (clobber (match_operand 0 "register_operand"))
16411               (clobber (match_operand 1 "register_operand"))
16412               (clobber (match_dup 2))])]
16413   ""
16414   "ix86_current_function_needs_cld = 1;")
16415
16416 (define_insn "*cmpstrnqi_nz_1"
16417   [(set (reg:CC FLAGS_REG)
16418         (compare:CC (mem:BLK (match_operand:P 4 "register_operand" "0"))
16419                     (mem:BLK (match_operand:P 5 "register_operand" "1"))))
16420    (use (match_operand:P 6 "register_operand" "2"))
16421    (use (match_operand:SI 3 "immediate_operand" "i"))
16422    (clobber (match_operand:P 0 "register_operand" "=S"))
16423    (clobber (match_operand:P 1 "register_operand" "=D"))
16424    (clobber (match_operand:P 2 "register_operand" "=c"))]
16425   "!(fixed_regs[CX_REG] || fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16426   "%^repz{%;} cmpsb"
16427   [(set_attr "type" "str")
16428    (set_attr "mode" "QI")
16429    (set (attr "prefix_rex")
16430         (if_then_else
16431           (match_test "<P:MODE>mode == DImode")
16432           (const_string "0")
16433           (const_string "*")))
16434    (set_attr "prefix_rep" "1")])
16435
16436 ;; The same, but the count is not known to not be zero.
16437
16438 (define_expand "cmpstrnqi_1"
16439   [(parallel [(set (reg:CC FLAGS_REG)
16440                 (if_then_else:CC (ne (match_operand 2 "register_operand")
16441                                      (const_int 0))
16442                   (compare:CC (match_operand 4 "memory_operand")
16443                               (match_operand 5 "memory_operand"))
16444                   (const_int 0)))
16445               (use (match_operand:SI 3 "immediate_operand"))
16446               (use (reg:CC FLAGS_REG))
16447               (clobber (match_operand 0 "register_operand"))
16448               (clobber (match_operand 1 "register_operand"))
16449               (clobber (match_dup 2))])]
16450   ""
16451   "ix86_current_function_needs_cld = 1;")
16452
16453 (define_insn "*cmpstrnqi_1"
16454   [(set (reg:CC FLAGS_REG)
16455         (if_then_else:CC (ne (match_operand:P 6 "register_operand" "2")
16456                              (const_int 0))
16457           (compare:CC (mem:BLK (match_operand:P 4 "register_operand" "0"))
16458                       (mem:BLK (match_operand:P 5 "register_operand" "1")))
16459           (const_int 0)))
16460    (use (match_operand:SI 3 "immediate_operand" "i"))
16461    (use (reg:CC FLAGS_REG))
16462    (clobber (match_operand:P 0 "register_operand" "=S"))
16463    (clobber (match_operand:P 1 "register_operand" "=D"))
16464    (clobber (match_operand:P 2 "register_operand" "=c"))]
16465   "!(fixed_regs[CX_REG] || fixed_regs[SI_REG] || fixed_regs[DI_REG])"
16466   "%^repz{%;} cmpsb"
16467   [(set_attr "type" "str")
16468    (set_attr "mode" "QI")
16469    (set (attr "prefix_rex")
16470         (if_then_else
16471           (match_test "<P:MODE>mode == DImode")
16472           (const_string "0")
16473           (const_string "*")))
16474    (set_attr "prefix_rep" "1")])
16475
16476 (define_expand "strlen<mode>"
16477   [(set (match_operand:P 0 "register_operand")
16478         (unspec:P [(match_operand:BLK 1 "general_operand")
16479                    (match_operand:QI 2 "immediate_operand")
16480                    (match_operand 3 "immediate_operand")]
16481                   UNSPEC_SCAS))]
16482   ""
16483 {
16484  if (ix86_expand_strlen (operands[0], operands[1], operands[2], operands[3]))
16485    DONE;
16486  else
16487    FAIL;
16488 })
16489
16490 (define_expand "strlenqi_1"
16491   [(parallel [(set (match_operand 0 "register_operand")
16492                    (match_operand 2))
16493               (clobber (match_operand 1 "register_operand"))
16494               (clobber (reg:CC FLAGS_REG))])]
16495   ""
16496   "ix86_current_function_needs_cld = 1;")
16497
16498 (define_insn "*strlenqi_1"
16499   [(set (match_operand:P 0 "register_operand" "=&c")
16500         (unspec:P [(mem:BLK (match_operand:P 5 "register_operand" "1"))
16501                    (match_operand:QI 2 "register_operand" "a")
16502                    (match_operand:P 3 "immediate_operand" "i")
16503                    (match_operand:P 4 "register_operand" "0")] UNSPEC_SCAS))
16504    (clobber (match_operand:P 1 "register_operand" "=D"))
16505    (clobber (reg:CC FLAGS_REG))]
16506   "!(fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])"
16507   "%^repnz{%;} scasb"
16508   [(set_attr "type" "str")
16509    (set_attr "mode" "QI")
16510    (set (attr "prefix_rex")
16511         (if_then_else
16512           (match_test "<P:MODE>mode == DImode")
16513           (const_string "0")
16514           (const_string "*")))
16515    (set_attr "prefix_rep" "1")])
16516
16517 ;; Peephole optimizations to clean up after cmpstrn*.  This should be
16518 ;; handled in combine, but it is not currently up to the task.
16519 ;; When used for their truth value, the cmpstrn* expanders generate
16520 ;; code like this:
16521 ;;
16522 ;;   repz cmpsb
16523 ;;   seta       %al
16524 ;;   setb       %dl
16525 ;;   cmpb       %al, %dl
16526 ;;   jcc        label
16527 ;;
16528 ;; The intermediate three instructions are unnecessary.
16529
16530 ;; This one handles cmpstrn*_nz_1...
16531 (define_peephole2
16532   [(parallel[
16533      (set (reg:CC FLAGS_REG)
16534           (compare:CC (mem:BLK (match_operand 4 "register_operand"))
16535                       (mem:BLK (match_operand 5 "register_operand"))))
16536      (use (match_operand 6 "register_operand"))
16537      (use (match_operand:SI 3 "immediate_operand"))
16538      (clobber (match_operand 0 "register_operand"))
16539      (clobber (match_operand 1 "register_operand"))
16540      (clobber (match_operand 2 "register_operand"))])
16541    (set (match_operand:QI 7 "register_operand")
16542         (gtu:QI (reg:CC FLAGS_REG) (const_int 0)))
16543    (set (match_operand:QI 8 "register_operand")
16544         (ltu:QI (reg:CC FLAGS_REG) (const_int 0)))
16545    (set (reg FLAGS_REG)
16546         (compare (match_dup 7) (match_dup 8)))
16547   ]
16548   "peep2_reg_dead_p (4, operands[7]) && peep2_reg_dead_p (4, operands[8])"
16549   [(parallel[
16550      (set (reg:CC FLAGS_REG)
16551           (compare:CC (mem:BLK (match_dup 4))
16552                       (mem:BLK (match_dup 5))))
16553      (use (match_dup 6))
16554      (use (match_dup 3))
16555      (clobber (match_dup 0))
16556      (clobber (match_dup 1))
16557      (clobber (match_dup 2))])])
16558
16559 ;; ...and this one handles cmpstrn*_1.
16560 (define_peephole2
16561   [(parallel[
16562      (set (reg:CC FLAGS_REG)
16563           (if_then_else:CC (ne (match_operand 6 "register_operand")
16564                                (const_int 0))
16565             (compare:CC (mem:BLK (match_operand 4 "register_operand"))
16566                         (mem:BLK (match_operand 5 "register_operand")))
16567             (const_int 0)))
16568      (use (match_operand:SI 3 "immediate_operand"))
16569      (use (reg:CC FLAGS_REG))
16570      (clobber (match_operand 0 "register_operand"))
16571      (clobber (match_operand 1 "register_operand"))
16572      (clobber (match_operand 2 "register_operand"))])
16573    (set (match_operand:QI 7 "register_operand")
16574         (gtu:QI (reg:CC FLAGS_REG) (const_int 0)))
16575    (set (match_operand:QI 8 "register_operand")
16576         (ltu:QI (reg:CC FLAGS_REG) (const_int 0)))
16577    (set (reg FLAGS_REG)
16578         (compare (match_dup 7) (match_dup 8)))
16579   ]
16580   "peep2_reg_dead_p (4, operands[7]) && peep2_reg_dead_p (4, operands[8])"
16581   [(parallel[
16582      (set (reg:CC FLAGS_REG)
16583           (if_then_else:CC (ne (match_dup 6)
16584                                (const_int 0))
16585             (compare:CC (mem:BLK (match_dup 4))
16586                         (mem:BLK (match_dup 5)))
16587             (const_int 0)))
16588      (use (match_dup 3))
16589      (use (reg:CC FLAGS_REG))
16590      (clobber (match_dup 0))
16591      (clobber (match_dup 1))
16592      (clobber (match_dup 2))])])
16593 \f
16594 ;; Conditional move instructions.
16595
16596 (define_expand "mov<mode>cc"
16597   [(set (match_operand:SWIM 0 "register_operand")
16598         (if_then_else:SWIM (match_operand 1 "comparison_operator")
16599                            (match_operand:SWIM 2 "<general_operand>")
16600                            (match_operand:SWIM 3 "<general_operand>")))]
16601   ""
16602   "if (ix86_expand_int_movcc (operands)) DONE; else FAIL;")
16603
16604 ;; Data flow gets confused by our desire for `sbbl reg,reg', and clearing
16605 ;; the register first winds up with `sbbl $0,reg', which is also weird.
16606 ;; So just document what we're doing explicitly.
16607
16608 (define_expand "x86_mov<mode>cc_0_m1"
16609   [(parallel
16610     [(set (match_operand:SWI48 0 "register_operand")
16611           (if_then_else:SWI48
16612             (match_operator:SWI48 2 "ix86_carry_flag_operator"
16613              [(match_operand 1 "flags_reg_operand")
16614               (const_int 0)])
16615             (const_int -1)
16616             (const_int 0)))
16617      (clobber (reg:CC FLAGS_REG))])])
16618
16619 (define_insn "*x86_mov<mode>cc_0_m1"
16620   [(set (match_operand:SWI48 0 "register_operand" "=r")
16621         (if_then_else:SWI48 (match_operator 1 "ix86_carry_flag_operator"
16622                              [(reg FLAGS_REG) (const_int 0)])
16623           (const_int -1)
16624           (const_int 0)))
16625    (clobber (reg:CC FLAGS_REG))]
16626   ""
16627   "sbb{<imodesuffix>}\t%0, %0"
16628   ; Since we don't have the proper number of operands for an alu insn,
16629   ; fill in all the blanks.
16630   [(set_attr "type" "alu")
16631    (set_attr "use_carry" "1")
16632    (set_attr "pent_pair" "pu")
16633    (set_attr "memory" "none")
16634    (set_attr "imm_disp" "false")
16635    (set_attr "mode" "<MODE>")
16636    (set_attr "length_immediate" "0")])
16637
16638 (define_insn "*x86_mov<mode>cc_0_m1_se"
16639   [(set (match_operand:SWI48 0 "register_operand" "=r")
16640         (sign_extract:SWI48 (match_operator 1 "ix86_carry_flag_operator"
16641                              [(reg FLAGS_REG) (const_int 0)])
16642                             (const_int 1)
16643                             (const_int 0)))
16644    (clobber (reg:CC FLAGS_REG))]
16645   ""
16646   "sbb{<imodesuffix>}\t%0, %0"
16647   [(set_attr "type" "alu")
16648    (set_attr "use_carry" "1")
16649    (set_attr "pent_pair" "pu")
16650    (set_attr "memory" "none")
16651    (set_attr "imm_disp" "false")
16652    (set_attr "mode" "<MODE>")
16653    (set_attr "length_immediate" "0")])
16654
16655 (define_insn "*x86_mov<mode>cc_0_m1_neg"
16656   [(set (match_operand:SWI48 0 "register_operand" "=r")
16657         (neg:SWI48 (match_operator 1 "ix86_carry_flag_operator"
16658                     [(reg FLAGS_REG) (const_int 0)])))
16659    (clobber (reg:CC FLAGS_REG))]
16660   ""
16661   "sbb{<imodesuffix>}\t%0, %0"
16662   [(set_attr "type" "alu")
16663    (set_attr "use_carry" "1")
16664    (set_attr "pent_pair" "pu")
16665    (set_attr "memory" "none")
16666    (set_attr "imm_disp" "false")
16667    (set_attr "mode" "<MODE>")
16668    (set_attr "length_immediate" "0")])
16669
16670 (define_insn "*mov<mode>cc_noc"
16671   [(set (match_operand:SWI248 0 "register_operand" "=r,r")
16672         (if_then_else:SWI248 (match_operator 1 "ix86_comparison_operator"
16673                                [(reg FLAGS_REG) (const_int 0)])
16674           (match_operand:SWI248 2 "nonimmediate_operand" "rm,0")
16675           (match_operand:SWI248 3 "nonimmediate_operand" "0,rm")))]
16676   "TARGET_CMOVE && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
16677   "@
16678    cmov%O2%C1\t{%2, %0|%0, %2}
16679    cmov%O2%c1\t{%3, %0|%0, %3}"
16680   [(set_attr "type" "icmov")
16681    (set_attr "mode" "<MODE>")])
16682
16683 ;; Don't do conditional moves with memory inputs.  This splitter helps
16684 ;; register starved x86_32 by forcing inputs into registers before reload.
16685 (define_split
16686   [(set (match_operand:SWI248 0 "register_operand")
16687         (if_then_else:SWI248 (match_operator 1 "ix86_comparison_operator"
16688                                [(reg FLAGS_REG) (const_int 0)])
16689           (match_operand:SWI248 2 "nonimmediate_operand")
16690           (match_operand:SWI248 3 "nonimmediate_operand")))]
16691   "!TARGET_64BIT && TARGET_CMOVE
16692    && TARGET_AVOID_MEM_OPND_FOR_CMOVE
16693    && (MEM_P (operands[2]) || MEM_P (operands[3]))
16694    && can_create_pseudo_p ()
16695    && optimize_insn_for_speed_p ()"
16696   [(set (match_dup 0)
16697         (if_then_else:SWI248 (match_dup 1) (match_dup 2) (match_dup 3)))]
16698 {
16699   if (MEM_P (operands[2]))
16700     operands[2] = force_reg (<MODE>mode, operands[2]);
16701   if (MEM_P (operands[3]))
16702     operands[3] = force_reg (<MODE>mode, operands[3]);
16703 })
16704
16705 (define_insn "*movqicc_noc"
16706   [(set (match_operand:QI 0 "register_operand" "=r,r")
16707         (if_then_else:QI (match_operator 1 "ix86_comparison_operator"
16708                            [(reg FLAGS_REG) (const_int 0)])
16709                       (match_operand:QI 2 "register_operand" "r,0")
16710                       (match_operand:QI 3 "register_operand" "0,r")))]
16711   "TARGET_CMOVE && !TARGET_PARTIAL_REG_STALL"
16712   "#"
16713   [(set_attr "type" "icmov")
16714    (set_attr "mode" "QI")])
16715
16716 (define_split
16717   [(set (match_operand:SWI12 0 "register_operand")
16718         (if_then_else:SWI12 (match_operator 1 "ix86_comparison_operator"
16719                               [(reg FLAGS_REG) (const_int 0)])
16720                       (match_operand:SWI12 2 "register_operand")
16721                       (match_operand:SWI12 3 "register_operand")))]
16722   "TARGET_CMOVE && !TARGET_PARTIAL_REG_STALL
16723    && reload_completed"
16724   [(set (match_dup 0)
16725         (if_then_else:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
16726 {
16727   operands[0] = gen_lowpart (SImode, operands[0]);
16728   operands[2] = gen_lowpart (SImode, operands[2]);
16729   operands[3] = gen_lowpart (SImode, operands[3]);
16730 })
16731
16732 ;; Don't do conditional moves with memory inputs
16733 (define_peephole2
16734   [(match_scratch:SWI248 2 "r")
16735    (set (match_operand:SWI248 0 "register_operand")
16736         (if_then_else:SWI248 (match_operator 1 "ix86_comparison_operator"
16737                                [(reg FLAGS_REG) (const_int 0)])
16738           (match_dup 0)
16739           (match_operand:SWI248 3 "memory_operand")))]
16740   "TARGET_CMOVE && TARGET_AVOID_MEM_OPND_FOR_CMOVE
16741    && optimize_insn_for_speed_p ()"
16742   [(set (match_dup 2) (match_dup 3))
16743    (set (match_dup 0)
16744         (if_then_else:SWI248 (match_dup 1) (match_dup 0) (match_dup 2)))])
16745
16746 (define_peephole2
16747   [(match_scratch:SWI248 2 "r")
16748    (set (match_operand:SWI248 0 "register_operand")
16749         (if_then_else:SWI248 (match_operator 1 "ix86_comparison_operator"
16750                                [(reg FLAGS_REG) (const_int 0)])
16751           (match_operand:SWI248 3 "memory_operand")
16752           (match_dup 0)))]
16753   "TARGET_CMOVE && TARGET_AVOID_MEM_OPND_FOR_CMOVE
16754    && optimize_insn_for_speed_p ()"
16755   [(set (match_dup 2) (match_dup 3))
16756    (set (match_dup 0)
16757         (if_then_else:SWI248 (match_dup 1) (match_dup 2) (match_dup 0)))])
16758
16759 (define_expand "mov<mode>cc"
16760   [(set (match_operand:X87MODEF 0 "register_operand")
16761         (if_then_else:X87MODEF
16762           (match_operand 1 "comparison_operator")
16763           (match_operand:X87MODEF 2 "register_operand")
16764           (match_operand:X87MODEF 3 "register_operand")))]
16765   "(TARGET_80387 && TARGET_CMOVE)
16766    || (SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)"
16767   "if (ix86_expand_fp_movcc (operands)) DONE; else FAIL;")
16768
16769 (define_insn "*movxfcc_1"
16770   [(set (match_operand:XF 0 "register_operand" "=f,f")
16771         (if_then_else:XF (match_operator 1 "fcmov_comparison_operator"
16772                                 [(reg FLAGS_REG) (const_int 0)])
16773                       (match_operand:XF 2 "register_operand" "f,0")
16774                       (match_operand:XF 3 "register_operand" "0,f")))]
16775   "TARGET_80387 && TARGET_CMOVE"
16776   "@
16777    fcmov%F1\t{%2, %0|%0, %2}
16778    fcmov%f1\t{%3, %0|%0, %3}"
16779   [(set_attr "type" "fcmov")
16780    (set_attr "mode" "XF")])
16781
16782 (define_insn "*movdfcc_1"
16783   [(set (match_operand:DF 0 "register_operand" "=f,f,&r,&r,r ,r")
16784         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator"
16785                                 [(reg FLAGS_REG) (const_int 0)])
16786                       (match_operand:DF 2 "nonimmediate_operand"
16787                                                "f ,0,rm,0 ,rm,0")
16788                       (match_operand:DF 3 "nonimmediate_operand"
16789                                                "0 ,f,0 ,rm,0, rm")))]
16790   "TARGET_80387 && TARGET_CMOVE
16791    && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
16792   "@
16793    fcmov%F1\t{%2, %0|%0, %2}
16794    fcmov%f1\t{%3, %0|%0, %3}
16795    #
16796    #
16797    cmov%O2%C1\t{%2, %0|%0, %2}
16798    cmov%O2%c1\t{%3, %0|%0, %3}"
16799   [(set_attr "isa" "*,*,nox64,nox64,x64,x64")
16800    (set_attr "type" "fcmov,fcmov,multi,multi,icmov,icmov")
16801    (set_attr "mode" "DF,DF,DI,DI,DI,DI")])
16802
16803 (define_split
16804   [(set (match_operand:DF 0 "register_and_not_any_fp_reg_operand")
16805         (if_then_else:DF (match_operator 1 "fcmov_comparison_operator"
16806                                 [(reg FLAGS_REG) (const_int 0)])
16807                       (match_operand:DF 2 "nonimmediate_operand")
16808                       (match_operand:DF 3 "nonimmediate_operand")))]
16809   "!TARGET_64BIT && reload_completed"
16810   [(set (match_dup 2)
16811         (if_then_else:SI (match_dup 1) (match_dup 4) (match_dup 5)))
16812    (set (match_dup 3)
16813         (if_then_else:SI (match_dup 1) (match_dup 6) (match_dup 7)))]
16814 {
16815   split_double_mode (DImode, &operands[2], 2, &operands[4], &operands[6]);
16816   split_double_mode (DImode, &operands[0], 1, &operands[2], &operands[3]);
16817 })
16818
16819 (define_insn "*movsfcc_1_387"
16820   [(set (match_operand:SF 0 "register_operand" "=f,f,r,r")
16821         (if_then_else:SF (match_operator 1 "fcmov_comparison_operator"
16822                                 [(reg FLAGS_REG) (const_int 0)])
16823                       (match_operand:SF 2 "nonimmediate_operand" "f,0,rm,0")
16824                       (match_operand:SF 3 "nonimmediate_operand" "0,f,0,rm")))]
16825   "TARGET_80387 && TARGET_CMOVE
16826    && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
16827   "@
16828    fcmov%F1\t{%2, %0|%0, %2}
16829    fcmov%f1\t{%3, %0|%0, %3}
16830    cmov%O2%C1\t{%2, %0|%0, %2}
16831    cmov%O2%c1\t{%3, %0|%0, %3}"
16832   [(set_attr "type" "fcmov,fcmov,icmov,icmov")
16833    (set_attr "mode" "SF,SF,SI,SI")])
16834
16835 ;; Don't do conditional moves with memory inputs.  This splitter helps
16836 ;; register starved x86_32 by forcing inputs into registers before reload.
16837 (define_split
16838   [(set (match_operand:MODEF 0 "register_operand")
16839         (if_then_else:MODEF (match_operator 1 "ix86_comparison_operator"
16840                               [(reg FLAGS_REG) (const_int 0)])
16841           (match_operand:MODEF 2 "nonimmediate_operand")
16842           (match_operand:MODEF 3 "nonimmediate_operand")))]
16843   "!TARGET_64BIT && TARGET_80387 && TARGET_CMOVE
16844    && TARGET_AVOID_MEM_OPND_FOR_CMOVE
16845    && (MEM_P (operands[2]) || MEM_P (operands[3]))
16846    && can_create_pseudo_p ()
16847    && optimize_insn_for_speed_p ()"
16848   [(set (match_dup 0)
16849         (if_then_else:MODEF (match_dup 1) (match_dup 2) (match_dup 3)))]
16850 {
16851   if (MEM_P (operands[2]))
16852     operands[2] = force_reg (<MODE>mode, operands[2]);
16853   if (MEM_P (operands[3]))
16854     operands[3] = force_reg (<MODE>mode, operands[3]);
16855 })
16856
16857 ;; Don't do conditional moves with memory inputs
16858 (define_peephole2
16859   [(match_scratch:MODEF 2 "r")
16860    (set (match_operand:MODEF 0 "register_and_not_any_fp_reg_operand")
16861         (if_then_else:MODEF (match_operator 1 "fcmov_comparison_operator"
16862                               [(reg FLAGS_REG) (const_int 0)])
16863           (match_dup 0)
16864           (match_operand:MODEF 3 "memory_operand")))]
16865   "(<MODE>mode != DFmode || TARGET_64BIT)
16866    && TARGET_80387 && TARGET_CMOVE
16867    && TARGET_AVOID_MEM_OPND_FOR_CMOVE
16868    && optimize_insn_for_speed_p ()"
16869   [(set (match_dup 2) (match_dup 3))
16870    (set (match_dup 0)
16871         (if_then_else:MODEF (match_dup 1) (match_dup 0) (match_dup 2)))])
16872
16873 (define_peephole2
16874   [(match_scratch:MODEF 2 "r")
16875    (set (match_operand:MODEF 0 "register_and_not_any_fp_reg_operand")
16876         (if_then_else:MODEF (match_operator 1 "fcmov_comparison_operator"
16877                               [(reg FLAGS_REG) (const_int 0)])
16878           (match_operand:MODEF 3 "memory_operand")
16879           (match_dup 0)))]
16880   "(<MODE>mode != DFmode || TARGET_64BIT)
16881    && TARGET_80387 && TARGET_CMOVE
16882    && TARGET_AVOID_MEM_OPND_FOR_CMOVE
16883    && optimize_insn_for_speed_p ()"
16884   [(set (match_dup 2) (match_dup 3))
16885    (set (match_dup 0)
16886         (if_then_else:MODEF (match_dup 1) (match_dup 2) (match_dup 0)))])
16887
16888 ;; All moves in XOP pcmov instructions are 128 bits and hence we restrict
16889 ;; the scalar versions to have only XMM registers as operands.
16890
16891 ;; XOP conditional move
16892 (define_insn "*xop_pcmov_<mode>"
16893   [(set (match_operand:MODEF 0 "register_operand" "=x")
16894         (if_then_else:MODEF
16895           (match_operand:MODEF 1 "register_operand" "x")
16896           (match_operand:MODEF 2 "register_operand" "x")
16897           (match_operand:MODEF 3 "register_operand" "x")))]
16898   "TARGET_XOP"
16899   "vpcmov\t{%1, %3, %2, %0|%0, %2, %3, %1}"
16900   [(set_attr "type" "sse4arg")])
16901
16902 ;; These versions of the min/max patterns are intentionally ignorant of
16903 ;; their behavior wrt -0.0 and NaN (via the commutative operand mark).
16904 ;; Since both the tree-level MAX_EXPR and the rtl-level SMAX operator
16905 ;; are undefined in this condition, we're certain this is correct.
16906
16907 (define_insn "<code><mode>3"
16908   [(set (match_operand:MODEF 0 "register_operand" "=x,v")
16909         (smaxmin:MODEF
16910           (match_operand:MODEF 1 "nonimmediate_operand" "%0,v")
16911           (match_operand:MODEF 2 "nonimmediate_operand" "xm,vm")))]
16912   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
16913   "@
16914    <maxmin_float><ssemodesuffix>\t{%2, %0|%0, %2}
16915    v<maxmin_float><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
16916   [(set_attr "isa" "noavx,avx")
16917    (set_attr "prefix" "orig,vex")
16918    (set_attr "type" "sseadd")
16919    (set_attr "mode" "<MODE>")])
16920
16921 ;; These versions of the min/max patterns implement exactly the operations
16922 ;;   min = (op1 < op2 ? op1 : op2)
16923 ;;   max = (!(op1 < op2) ? op1 : op2)
16924 ;; Their operands are not commutative, and thus they may be used in the
16925 ;; presence of -0.0 and NaN.
16926
16927 (define_int_iterator IEEE_MAXMIN
16928         [UNSPEC_IEEE_MAX
16929          UNSPEC_IEEE_MIN])
16930
16931 (define_int_attr ieee_maxmin
16932         [(UNSPEC_IEEE_MAX "max")
16933          (UNSPEC_IEEE_MIN "min")])
16934
16935 (define_insn "*ieee_s<ieee_maxmin><mode>3"
16936   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
16937         (unspec:MODEF
16938           [(match_operand:MODEF 1 "register_operand" "0,x")
16939            (match_operand:MODEF 2 "nonimmediate_operand" "xm,xm")]
16940           IEEE_MAXMIN))]
16941   "SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH"
16942   "@
16943    <ieee_maxmin><ssemodesuffix>\t{%2, %0|%0, %2}
16944    v<ieee_maxmin><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
16945   [(set_attr "isa" "noavx,avx")
16946    (set_attr "prefix" "orig,vex")
16947    (set_attr "type" "sseadd")
16948    (set_attr "mode" "<MODE>")])
16949
16950 ;; Make two stack loads independent:
16951 ;;   fld aa              fld aa
16952 ;;   fld %st(0)     ->   fld bb
16953 ;;   fmul bb             fmul %st(1), %st
16954 ;;
16955 ;; Actually we only match the last two instructions for simplicity.
16956 (define_peephole2
16957   [(set (match_operand 0 "fp_register_operand")
16958         (match_operand 1 "fp_register_operand"))
16959    (set (match_dup 0)
16960         (match_operator 2 "binary_fp_operator"
16961            [(match_dup 0)
16962             (match_operand 3 "memory_operand")]))]
16963   "REGNO (operands[0]) != REGNO (operands[1])"
16964   [(set (match_dup 0) (match_dup 3))
16965    (set (match_dup 0) (match_dup 4))]
16966
16967   ;; The % modifier is not operational anymore in peephole2's, so we have to
16968   ;; swap the operands manually in the case of addition and multiplication.
16969 {
16970   rtx op0, op1;
16971
16972   if (COMMUTATIVE_ARITH_P (operands[2]))
16973     op0 = operands[0], op1 = operands[1];
16974   else
16975     op0 = operands[1], op1 = operands[0];
16976
16977   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[2]),
16978                                 GET_MODE (operands[2]),
16979                                 op0, op1);
16980 })
16981
16982 ;; Conditional addition patterns
16983 (define_expand "add<mode>cc"
16984   [(match_operand:SWI 0 "register_operand")
16985    (match_operand 1 "ordered_comparison_operator")
16986    (match_operand:SWI 2 "register_operand")
16987    (match_operand:SWI 3 "const_int_operand")]
16988   ""
16989   "if (ix86_expand_int_addcc (operands)) DONE; else FAIL;")
16990 \f
16991 ;; Misc patterns (?)
16992
16993 ;; This pattern exists to put a dependency on all ebp-based memory accesses.
16994 ;; Otherwise there will be nothing to keep
16995 ;;
16996 ;; [(set (reg ebp) (reg esp))]
16997 ;; [(set (reg esp) (plus (reg esp) (const_int -160000)))
16998 ;;  (clobber (eflags)]
16999 ;; [(set (mem (plus (reg ebp) (const_int -160000))) (const_int 0))]
17000 ;;
17001 ;; in proper program order.
17002
17003 (define_insn "pro_epilogue_adjust_stack_<mode>_add"
17004   [(set (match_operand:P 0 "register_operand" "=r,r")
17005         (plus:P (match_operand:P 1 "register_operand" "0,r")
17006                 (match_operand:P 2 "<nonmemory_operand>" "r<i>,l<i>")))
17007    (clobber (reg:CC FLAGS_REG))
17008    (clobber (mem:BLK (scratch)))]
17009   ""
17010 {
17011   switch (get_attr_type (insn))
17012     {
17013     case TYPE_IMOV:
17014       return "mov{<imodesuffix>}\t{%1, %0|%0, %1}";
17015
17016     case TYPE_ALU:
17017       gcc_assert (rtx_equal_p (operands[0], operands[1]));
17018       if (x86_maybe_negate_const_int (&operands[2], <MODE>mode))
17019         return "sub{<imodesuffix>}\t{%2, %0|%0, %2}";
17020
17021       return "add{<imodesuffix>}\t{%2, %0|%0, %2}";
17022
17023     default:
17024       operands[2] = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
17025       return "lea{<imodesuffix>}\t{%E2, %0|%0, %E2}";
17026     }
17027 }
17028   [(set (attr "type")
17029         (cond [(and (eq_attr "alternative" "0")
17030                     (not (match_test "TARGET_OPT_AGU")))
17031                  (const_string "alu")
17032                (match_operand:<MODE> 2 "const0_operand")
17033                  (const_string "imov")
17034               ]
17035               (const_string "lea")))
17036    (set (attr "length_immediate")
17037         (cond [(eq_attr "type" "imov")
17038                  (const_string "0")
17039                (and (eq_attr "type" "alu")
17040                     (match_operand 2 "const128_operand"))
17041                  (const_string "1")
17042               ]
17043               (const_string "*")))
17044    (set_attr "mode" "<MODE>")])
17045
17046 (define_insn "pro_epilogue_adjust_stack_<mode>_sub"
17047   [(set (match_operand:P 0 "register_operand" "=r")
17048         (minus:P (match_operand:P 1 "register_operand" "0")
17049                  (match_operand:P 2 "register_operand" "r")))
17050    (clobber (reg:CC FLAGS_REG))
17051    (clobber (mem:BLK (scratch)))]
17052   ""
17053   "sub{<imodesuffix>}\t{%2, %0|%0, %2}"
17054   [(set_attr "type" "alu")
17055    (set_attr "mode" "<MODE>")])
17056
17057 (define_insn "allocate_stack_worker_probe_<mode>"
17058   [(set (match_operand:P 0 "register_operand" "=a")
17059         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")]
17060                             UNSPECV_STACK_PROBE))
17061    (clobber (reg:CC FLAGS_REG))]
17062   "ix86_target_stack_probe ()"
17063   "call\t___chkstk_ms"
17064   [(set_attr "type" "multi")
17065    (set_attr "length" "5")])
17066
17067 (define_expand "allocate_stack"
17068   [(match_operand 0 "register_operand")
17069    (match_operand 1 "general_operand")]
17070   "ix86_target_stack_probe ()"
17071 {
17072   rtx x;
17073
17074 #ifndef CHECK_STACK_LIMIT
17075 #define CHECK_STACK_LIMIT 0
17076 #endif
17077
17078   if (CHECK_STACK_LIMIT && CONST_INT_P (operands[1])
17079       && INTVAL (operands[1]) < CHECK_STACK_LIMIT)
17080     x = operands[1];
17081   else
17082     {
17083       rtx (*insn) (rtx, rtx);
17084
17085       x = copy_to_mode_reg (Pmode, operands[1]);
17086
17087       insn = (TARGET_64BIT
17088               ? gen_allocate_stack_worker_probe_di
17089               : gen_allocate_stack_worker_probe_si);
17090
17091       emit_insn (insn (x, x));
17092     }
17093
17094   x = expand_simple_binop (Pmode, MINUS, stack_pointer_rtx, x,
17095                            stack_pointer_rtx, 0, OPTAB_DIRECT);
17096
17097   if (x != stack_pointer_rtx)
17098     emit_move_insn (stack_pointer_rtx, x);
17099
17100   emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
17101   DONE;
17102 })
17103
17104 ;; Use IOR for stack probes, this is shorter.
17105 (define_expand "probe_stack"
17106   [(match_operand 0 "memory_operand")]
17107   ""
17108 {
17109   rtx (*gen_ior3) (rtx, rtx, rtx);
17110
17111   gen_ior3 = (GET_MODE (operands[0]) == DImode
17112               ? gen_iordi3 : gen_iorsi3);
17113
17114   emit_insn (gen_ior3 (operands[0], operands[0], const0_rtx));
17115   DONE;
17116 })
17117
17118 (define_insn "adjust_stack_and_probe<mode>"
17119   [(set (match_operand:P 0 "register_operand" "=r")
17120         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")]
17121                             UNSPECV_PROBE_STACK_RANGE))
17122    (set (reg:P SP_REG)
17123         (minus:P (reg:P SP_REG) (match_operand:P 2 "const_int_operand" "n")))
17124    (clobber (reg:CC FLAGS_REG))
17125    (clobber (mem:BLK (scratch)))]
17126   ""
17127   "* return output_adjust_stack_and_probe (operands[0]);"
17128   [(set_attr "type" "multi")])
17129
17130 (define_insn "probe_stack_range<mode>"
17131   [(set (match_operand:P 0 "register_operand" "=r")
17132         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
17133                             (match_operand:P 2 "const_int_operand" "n")]
17134                             UNSPECV_PROBE_STACK_RANGE))
17135    (clobber (reg:CC FLAGS_REG))]
17136   ""
17137   "* return output_probe_stack_range (operands[0], operands[2]);"
17138   [(set_attr "type" "multi")])
17139
17140 (define_expand "builtin_setjmp_receiver"
17141   [(label_ref (match_operand 0))]
17142   "!TARGET_64BIT && flag_pic"
17143 {
17144 #if TARGET_MACHO
17145   if (TARGET_MACHO)
17146     {
17147       rtx xops[3];
17148       rtx_code_label *label_rtx = gen_label_rtx ();
17149       emit_insn (gen_set_got_labelled (pic_offset_table_rtx, label_rtx));
17150       xops[0] = xops[1] = pic_offset_table_rtx;
17151       xops[2] = machopic_gen_offset (gen_rtx_LABEL_REF (SImode, label_rtx));
17152       ix86_expand_binary_operator (MINUS, SImode, xops);
17153     }
17154   else
17155 #endif
17156     emit_insn (gen_set_got (pic_offset_table_rtx));
17157   DONE;
17158 })
17159
17160 ;; Avoid redundant prefixes by splitting HImode arithmetic to SImode.
17161 ;; Do not split instructions with mask registers.
17162 (define_split
17163   [(set (match_operand 0 "general_reg_operand")
17164         (match_operator 3 "promotable_binary_operator"
17165            [(match_operand 1 "general_reg_operand")
17166             (match_operand 2 "aligned_operand")]))
17167    (clobber (reg:CC FLAGS_REG))]
17168   "! TARGET_PARTIAL_REG_STALL && reload_completed
17169    && ((GET_MODE (operands[0]) == HImode
17170         && ((optimize_function_for_speed_p (cfun) && !TARGET_FAST_PREFIX)
17171             /* ??? next two lines just !satisfies_constraint_K (...) */
17172             || !CONST_INT_P (operands[2])
17173             || satisfies_constraint_K (operands[2])))
17174        || (GET_MODE (operands[0]) == QImode
17175            && (TARGET_PROMOTE_QImode || optimize_function_for_size_p (cfun))))"
17176   [(parallel [(set (match_dup 0)
17177                    (match_op_dup 3 [(match_dup 1) (match_dup 2)]))
17178               (clobber (reg:CC FLAGS_REG))])]
17179 {
17180   operands[0] = gen_lowpart (SImode, operands[0]);
17181   operands[1] = gen_lowpart (SImode, operands[1]);
17182   if (GET_CODE (operands[3]) != ASHIFT)
17183     operands[2] = gen_lowpart (SImode, operands[2]);
17184   PUT_MODE (operands[3], SImode);
17185 })
17186
17187 ; Promote the QImode tests, as i386 has encoding of the AND
17188 ; instruction with 32-bit sign-extended immediate and thus the
17189 ; instruction size is unchanged, except in the %eax case for
17190 ; which it is increased by one byte, hence the ! optimize_size.
17191 (define_split
17192   [(set (match_operand 0 "flags_reg_operand")
17193         (match_operator 2 "compare_operator"
17194           [(and (match_operand 3 "aligned_operand")
17195                 (match_operand 4 "const_int_operand"))
17196            (const_int 0)]))
17197    (set (match_operand 1 "register_operand")
17198         (and (match_dup 3) (match_dup 4)))]
17199   "! TARGET_PARTIAL_REG_STALL && reload_completed
17200    && optimize_insn_for_speed_p ()
17201    && ((GET_MODE (operands[1]) == HImode && ! TARGET_FAST_PREFIX)
17202        || (GET_MODE (operands[1]) == QImode && TARGET_PROMOTE_QImode))
17203    /* Ensure that the operand will remain sign-extended immediate.  */
17204    && ix86_match_ccmode (insn, INTVAL (operands[4]) >= 0 ? CCNOmode : CCZmode)"
17205   [(parallel [(set (match_dup 0)
17206                    (match_op_dup 2 [(and:SI (match_dup 3) (match_dup 4))
17207                                     (const_int 0)]))
17208               (set (match_dup 1)
17209                    (and:SI (match_dup 3) (match_dup 4)))])]
17210 {
17211   operands[4]
17212     = gen_int_mode (INTVAL (operands[4])
17213                     & GET_MODE_MASK (GET_MODE (operands[1])), SImode);
17214   operands[1] = gen_lowpart (SImode, operands[1]);
17215   operands[3] = gen_lowpart (SImode, operands[3]);
17216 })
17217
17218 ; Don't promote the QImode tests, as i386 doesn't have encoding of
17219 ; the TEST instruction with 32-bit sign-extended immediate and thus
17220 ; the instruction size would at least double, which is not what we
17221 ; want even with ! optimize_size.
17222 (define_split
17223   [(set (match_operand 0 "flags_reg_operand")
17224         (match_operator 1 "compare_operator"
17225           [(and (match_operand:HI 2 "aligned_operand")
17226                 (match_operand:HI 3 "const_int_operand"))
17227            (const_int 0)]))]
17228   "! TARGET_PARTIAL_REG_STALL && reload_completed
17229    && ! TARGET_FAST_PREFIX
17230    && optimize_insn_for_speed_p ()
17231    /* Ensure that the operand will remain sign-extended immediate.  */
17232    && ix86_match_ccmode (insn, INTVAL (operands[3]) >= 0 ? CCNOmode : CCZmode)"
17233   [(set (match_dup 0)
17234         (match_op_dup 1 [(and:SI (match_dup 2) (match_dup 3))
17235                          (const_int 0)]))]
17236 {
17237   operands[3]
17238     = gen_int_mode (INTVAL (operands[3])
17239                     & GET_MODE_MASK (GET_MODE (operands[2])), SImode);
17240   operands[2] = gen_lowpart (SImode, operands[2]);
17241 })
17242
17243 (define_split
17244   [(set (match_operand 0 "register_operand")
17245         (neg (match_operand 1 "register_operand")))
17246    (clobber (reg:CC FLAGS_REG))]
17247   "! TARGET_PARTIAL_REG_STALL && reload_completed
17248    && (GET_MODE (operands[0]) == HImode
17249        || (GET_MODE (operands[0]) == QImode
17250            && (TARGET_PROMOTE_QImode
17251                || optimize_insn_for_size_p ())))"
17252   [(parallel [(set (match_dup 0)
17253                    (neg:SI (match_dup 1)))
17254               (clobber (reg:CC FLAGS_REG))])]
17255 {
17256   operands[0] = gen_lowpart (SImode, operands[0]);
17257   operands[1] = gen_lowpart (SImode, operands[1]);
17258 })
17259
17260 ;; Do not split instructions with mask regs.
17261 (define_split
17262   [(set (match_operand 0 "general_reg_operand")
17263         (not (match_operand 1 "general_reg_operand")))]
17264   "! TARGET_PARTIAL_REG_STALL && reload_completed
17265    && (GET_MODE (operands[0]) == HImode
17266        || (GET_MODE (operands[0]) == QImode
17267            && (TARGET_PROMOTE_QImode
17268                || optimize_insn_for_size_p ())))"
17269   [(set (match_dup 0)
17270         (not:SI (match_dup 1)))]
17271 {
17272   operands[0] = gen_lowpart (SImode, operands[0]);
17273   operands[1] = gen_lowpart (SImode, operands[1]);
17274 })
17275 \f
17276 ;; RTL Peephole optimizations, run before sched2.  These primarily look to
17277 ;; transform a complex memory operation into two memory to register operations.
17278
17279 ;; Don't push memory operands
17280 (define_peephole2
17281   [(set (match_operand:SWI 0 "push_operand")
17282         (match_operand:SWI 1 "memory_operand"))
17283    (match_scratch:SWI 2 "<r>")]
17284   "!(TARGET_PUSH_MEMORY || optimize_insn_for_size_p ())
17285    && !RTX_FRAME_RELATED_P (peep2_next_insn (0))"
17286   [(set (match_dup 2) (match_dup 1))
17287    (set (match_dup 0) (match_dup 2))])
17288
17289 ;; We need to handle SFmode only, because DFmode and XFmode are split to
17290 ;; SImode pushes.
17291 (define_peephole2
17292   [(set (match_operand:SF 0 "push_operand")
17293         (match_operand:SF 1 "memory_operand"))
17294    (match_scratch:SF 2 "r")]
17295   "!(TARGET_PUSH_MEMORY || optimize_insn_for_size_p ())
17296    && !RTX_FRAME_RELATED_P (peep2_next_insn (0))"
17297   [(set (match_dup 2) (match_dup 1))
17298    (set (match_dup 0) (match_dup 2))])
17299
17300 ;; Don't move an immediate directly to memory when the instruction
17301 ;; gets too big, or if LCP stalls are a problem for 16-bit moves.
17302 (define_peephole2
17303   [(match_scratch:SWI124 1 "<r>")
17304    (set (match_operand:SWI124 0 "memory_operand")
17305         (const_int 0))]
17306   "optimize_insn_for_speed_p ()
17307    && ((<MODE>mode == HImode
17308        && TARGET_LCP_STALL)
17309        || (!TARGET_USE_MOV0
17310           && TARGET_SPLIT_LONG_MOVES
17311           && get_attr_length (insn) >= ix86_cur_cost ()->large_insn))
17312    && peep2_regno_dead_p (0, FLAGS_REG)"
17313   [(parallel [(set (match_dup 2) (const_int 0))
17314               (clobber (reg:CC FLAGS_REG))])
17315    (set (match_dup 0) (match_dup 1))]
17316   "operands[2] = gen_lowpart (SImode, operands[1]);")
17317
17318 (define_peephole2
17319   [(match_scratch:SWI124 2 "<r>")
17320    (set (match_operand:SWI124 0 "memory_operand")
17321         (match_operand:SWI124 1 "immediate_operand"))]
17322   "optimize_insn_for_speed_p ()
17323    && ((<MODE>mode == HImode
17324        && TARGET_LCP_STALL)
17325        || (TARGET_SPLIT_LONG_MOVES
17326           && get_attr_length (insn) >= ix86_cur_cost ()->large_insn))"
17327   [(set (match_dup 2) (match_dup 1))
17328    (set (match_dup 0) (match_dup 2))])
17329
17330 ;; Don't compare memory with zero, load and use a test instead.
17331 (define_peephole2
17332   [(set (match_operand 0 "flags_reg_operand")
17333         (match_operator 1 "compare_operator"
17334           [(match_operand:SI 2 "memory_operand")
17335            (const_int 0)]))
17336    (match_scratch:SI 3 "r")]
17337   "optimize_insn_for_speed_p () && ix86_match_ccmode (insn, CCNOmode)"
17338   [(set (match_dup 3) (match_dup 2))
17339    (set (match_dup 0) (match_op_dup 1 [(match_dup 3) (const_int 0)]))])
17340
17341 ;; NOT is not pairable on Pentium, while XOR is, but one byte longer.
17342 ;; Don't split NOTs with a displacement operand, because resulting XOR
17343 ;; will not be pairable anyway.
17344 ;;
17345 ;; On AMD K6, NOT is vector decoded with memory operand that cannot be
17346 ;; represented using a modRM byte.  The XOR replacement is long decoded,
17347 ;; so this split helps here as well.
17348 ;;
17349 ;; Note: Can't do this as a regular split because we can't get proper
17350 ;; lifetime information then.
17351
17352 (define_peephole2
17353   [(set (match_operand:SWI124 0 "nonimmediate_operand")
17354         (not:SWI124 (match_operand:SWI124 1 "nonimmediate_operand")))]
17355   "optimize_insn_for_speed_p ()
17356    && ((TARGET_NOT_UNPAIRABLE
17357         && (!MEM_P (operands[0])
17358             || !memory_displacement_operand (operands[0], <MODE>mode)))
17359        || (TARGET_NOT_VECTORMODE
17360            && long_memory_operand (operands[0], <MODE>mode)))
17361    && peep2_regno_dead_p (0, FLAGS_REG)"
17362   [(parallel [(set (match_dup 0)
17363                    (xor:SWI124 (match_dup 1) (const_int -1)))
17364               (clobber (reg:CC FLAGS_REG))])])
17365
17366 ;; Non pairable "test imm, reg" instructions can be translated to
17367 ;; "and imm, reg" if reg dies.  The "and" form is also shorter (one
17368 ;; byte opcode instead of two, have a short form for byte operands),
17369 ;; so do it for other CPUs as well.  Given that the value was dead,
17370 ;; this should not create any new dependencies.  Pass on the sub-word
17371 ;; versions if we're concerned about partial register stalls.
17372
17373 (define_peephole2
17374   [(set (match_operand 0 "flags_reg_operand")
17375         (match_operator 1 "compare_operator"
17376           [(and:SI (match_operand:SI 2 "register_operand")
17377                    (match_operand:SI 3 "immediate_operand"))
17378            (const_int 0)]))]
17379   "ix86_match_ccmode (insn, CCNOmode)
17380    && (true_regnum (operands[2]) != AX_REG
17381        || satisfies_constraint_K (operands[3]))
17382    && peep2_reg_dead_p (1, operands[2])"
17383   [(parallel
17384      [(set (match_dup 0)
17385            (match_op_dup 1 [(and:SI (match_dup 2) (match_dup 3))
17386                             (const_int 0)]))
17387       (set (match_dup 2)
17388            (and:SI (match_dup 2) (match_dup 3)))])])
17389
17390 ;; We don't need to handle HImode case, because it will be promoted to SImode
17391 ;; on ! TARGET_PARTIAL_REG_STALL
17392
17393 (define_peephole2
17394   [(set (match_operand 0 "flags_reg_operand")
17395         (match_operator 1 "compare_operator"
17396           [(and:QI (match_operand:QI 2 "register_operand")
17397                    (match_operand:QI 3 "immediate_operand"))
17398            (const_int 0)]))]
17399   "! TARGET_PARTIAL_REG_STALL
17400    && ix86_match_ccmode (insn, CCNOmode)
17401    && true_regnum (operands[2]) != AX_REG
17402    && peep2_reg_dead_p (1, operands[2])"
17403   [(parallel
17404      [(set (match_dup 0)
17405            (match_op_dup 1 [(and:QI (match_dup 2) (match_dup 3))
17406                             (const_int 0)]))
17407       (set (match_dup 2)
17408            (and:QI (match_dup 2) (match_dup 3)))])])
17409
17410 (define_peephole2
17411   [(set (match_operand 0 "flags_reg_operand")
17412         (match_operator 1 "compare_operator"
17413           [(and:SI
17414              (zero_extract:SI
17415                (match_operand 2 "ext_register_operand")
17416                (const_int 8)
17417                (const_int 8))
17418              (match_operand 3 "const_int_operand"))
17419            (const_int 0)]))]
17420   "! TARGET_PARTIAL_REG_STALL
17421    && ix86_match_ccmode (insn, CCNOmode)
17422    && true_regnum (operands[2]) != AX_REG
17423    && peep2_reg_dead_p (1, operands[2])"
17424   [(parallel [(set (match_dup 0)
17425                    (match_op_dup 1
17426                      [(and:SI
17427                         (zero_extract:SI
17428                           (match_dup 2)
17429                           (const_int 8)
17430                           (const_int 8))
17431                         (match_dup 3))
17432                       (const_int 0)]))
17433               (set (zero_extract:SI (match_dup 2)
17434                                     (const_int 8)
17435                                     (const_int 8))
17436                    (and:SI
17437                      (zero_extract:SI
17438                        (match_dup 2)
17439                        (const_int 8)
17440                        (const_int 8))
17441                      (match_dup 3)))])])
17442
17443 ;; Don't do logical operations with memory inputs.
17444 (define_peephole2
17445   [(match_scratch:SI 2 "r")
17446    (parallel [(set (match_operand:SI 0 "register_operand")
17447                    (match_operator:SI 3 "arith_or_logical_operator"
17448                      [(match_dup 0)
17449                       (match_operand:SI 1 "memory_operand")]))
17450               (clobber (reg:CC FLAGS_REG))])]
17451   "!(TARGET_READ_MODIFY || optimize_insn_for_size_p ())"
17452   [(set (match_dup 2) (match_dup 1))
17453    (parallel [(set (match_dup 0)
17454                    (match_op_dup 3 [(match_dup 0) (match_dup 2)]))
17455               (clobber (reg:CC FLAGS_REG))])])
17456
17457 (define_peephole2
17458   [(match_scratch:SI 2 "r")
17459    (parallel [(set (match_operand:SI 0 "register_operand")
17460                    (match_operator:SI 3 "arith_or_logical_operator"
17461                      [(match_operand:SI 1 "memory_operand")
17462                       (match_dup 0)]))
17463               (clobber (reg:CC FLAGS_REG))])]
17464   "!(TARGET_READ_MODIFY || optimize_insn_for_size_p ())"
17465   [(set (match_dup 2) (match_dup 1))
17466    (parallel [(set (match_dup 0)
17467                    (match_op_dup 3 [(match_dup 2) (match_dup 0)]))
17468               (clobber (reg:CC FLAGS_REG))])])
17469
17470 ;; Prefer Load+RegOp to Mov+MemOp.  Watch out for cases when the memory address
17471 ;; refers to the destination of the load!
17472
17473 (define_peephole2
17474   [(set (match_operand:SI 0 "register_operand")
17475         (match_operand:SI 1 "register_operand"))
17476    (parallel [(set (match_dup 0)
17477                    (match_operator:SI 3 "commutative_operator"
17478                      [(match_dup 0)
17479                       (match_operand:SI 2 "memory_operand")]))
17480               (clobber (reg:CC FLAGS_REG))])]
17481   "REGNO (operands[0]) != REGNO (operands[1])
17482    && GENERAL_REGNO_P (REGNO (operands[0]))
17483    && GENERAL_REGNO_P (REGNO (operands[1]))"
17484   [(set (match_dup 0) (match_dup 4))
17485    (parallel [(set (match_dup 0)
17486                    (match_op_dup 3 [(match_dup 0) (match_dup 1)]))
17487               (clobber (reg:CC FLAGS_REG))])]
17488   "operands[4] = replace_rtx (operands[2], operands[0], operands[1]);")
17489
17490 (define_peephole2
17491   [(set (match_operand 0 "register_operand")
17492         (match_operand 1 "register_operand"))
17493    (set (match_dup 0)
17494                    (match_operator 3 "commutative_operator"
17495                      [(match_dup 0)
17496                       (match_operand 2 "memory_operand")]))]
17497   "REGNO (operands[0]) != REGNO (operands[1])
17498    && ((MMX_REG_P (operands[0]) && MMX_REG_P (operands[1])) 
17499        || (SSE_REG_P (operands[0]) && SSE_REG_P (operands[1])))"
17500   [(set (match_dup 0) (match_dup 2))
17501    (set (match_dup 0)
17502         (match_op_dup 3 [(match_dup 0) (match_dup 1)]))])
17503
17504 ; Don't do logical operations with memory outputs
17505 ;
17506 ; These two don't make sense for PPro/PII -- we're expanding a 4-uop
17507 ; instruction into two 1-uop insns plus a 2-uop insn.  That last has
17508 ; the same decoder scheduling characteristics as the original.
17509
17510 (define_peephole2
17511   [(match_scratch:SI 2 "r")
17512    (parallel [(set (match_operand:SI 0 "memory_operand")
17513                    (match_operator:SI 3 "arith_or_logical_operator"
17514                      [(match_dup 0)
17515                       (match_operand:SI 1 "nonmemory_operand")]))
17516               (clobber (reg:CC FLAGS_REG))])]
17517   "!(TARGET_READ_MODIFY_WRITE || optimize_insn_for_size_p ())
17518    /* Do not split stack checking probes.  */
17519    && GET_CODE (operands[3]) != IOR && operands[1] != const0_rtx"
17520   [(set (match_dup 2) (match_dup 0))
17521    (parallel [(set (match_dup 2)
17522                    (match_op_dup 3 [(match_dup 2) (match_dup 1)]))
17523               (clobber (reg:CC FLAGS_REG))])
17524    (set (match_dup 0) (match_dup 2))])
17525
17526 (define_peephole2
17527   [(match_scratch:SI 2 "r")
17528    (parallel [(set (match_operand:SI 0 "memory_operand")
17529                    (match_operator:SI 3 "arith_or_logical_operator"
17530                      [(match_operand:SI 1 "nonmemory_operand")
17531                       (match_dup 0)]))
17532               (clobber (reg:CC FLAGS_REG))])]
17533   "!(TARGET_READ_MODIFY_WRITE || optimize_insn_for_size_p ())
17534    /* Do not split stack checking probes.  */
17535    && GET_CODE (operands[3]) != IOR && operands[1] != const0_rtx"
17536   [(set (match_dup 2) (match_dup 0))
17537    (parallel [(set (match_dup 2)
17538                    (match_op_dup 3 [(match_dup 1) (match_dup 2)]))
17539               (clobber (reg:CC FLAGS_REG))])
17540    (set (match_dup 0) (match_dup 2))])
17541
17542 ;; Attempt to use arith or logical operations with memory outputs with
17543 ;; setting of flags.
17544 (define_peephole2
17545   [(set (match_operand:SWI 0 "register_operand")
17546         (match_operand:SWI 1 "memory_operand"))
17547    (parallel [(set (match_dup 0)
17548                    (match_operator:SWI 3 "plusminuslogic_operator"
17549                      [(match_dup 0)
17550                       (match_operand:SWI 2 "<nonmemory_operand>")]))
17551               (clobber (reg:CC FLAGS_REG))])
17552    (set (match_dup 1) (match_dup 0))
17553    (set (reg FLAGS_REG) (compare (match_dup 0) (const_int 0)))]
17554   "(TARGET_READ_MODIFY_WRITE || optimize_insn_for_size_p ())
17555    && peep2_reg_dead_p (4, operands[0])
17556    && !reg_overlap_mentioned_p (operands[0], operands[1])
17557    && !reg_overlap_mentioned_p (operands[0], operands[2])
17558    && (<MODE>mode != QImode
17559        || immediate_operand (operands[2], QImode)
17560        || q_regs_operand (operands[2], QImode))
17561    && ix86_match_ccmode (peep2_next_insn (3),
17562                          (GET_CODE (operands[3]) == PLUS
17563                           || GET_CODE (operands[3]) == MINUS)
17564                          ? CCGOCmode : CCNOmode)"
17565   [(parallel [(set (match_dup 4) (match_dup 5))
17566               (set (match_dup 1) (match_op_dup 3 [(match_dup 1)
17567                                                   (match_dup 2)]))])]
17568 {
17569   operands[4] = SET_DEST (PATTERN (peep2_next_insn (3)));
17570   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), <MODE>mode,
17571                                 copy_rtx (operands[1]),
17572                                 copy_rtx (operands[2]));
17573   operands[5] = gen_rtx_COMPARE (GET_MODE (operands[4]),
17574                                  operands[5], const0_rtx);
17575 })
17576
17577 (define_peephole2
17578   [(parallel [(set (match_operand:SWI 0 "register_operand")
17579                    (match_operator:SWI 2 "plusminuslogic_operator"
17580                      [(match_dup 0)
17581                       (match_operand:SWI 1 "memory_operand")]))
17582               (clobber (reg:CC FLAGS_REG))])
17583    (set (match_dup 1) (match_dup 0))
17584    (set (reg FLAGS_REG) (compare (match_dup 0) (const_int 0)))]
17585   "(TARGET_READ_MODIFY_WRITE || optimize_insn_for_size_p ())
17586    && GET_CODE (operands[2]) != MINUS
17587    && peep2_reg_dead_p (3, operands[0])
17588    && !reg_overlap_mentioned_p (operands[0], operands[1])
17589    && ix86_match_ccmode (peep2_next_insn (2),
17590                          GET_CODE (operands[2]) == PLUS
17591                          ? CCGOCmode : CCNOmode)"
17592   [(parallel [(set (match_dup 3) (match_dup 4))
17593               (set (match_dup 1) (match_op_dup 2 [(match_dup 1)
17594                                                   (match_dup 0)]))])]
17595 {
17596   operands[3] = SET_DEST (PATTERN (peep2_next_insn (2)));
17597   operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[2]), <MODE>mode,
17598                                 copy_rtx (operands[1]),
17599                                 copy_rtx (operands[0]));
17600   operands[4] = gen_rtx_COMPARE (GET_MODE (operands[3]),
17601                                  operands[4], const0_rtx);
17602 })
17603
17604 (define_peephole2
17605   [(set (match_operand:SWI12 0 "register_operand")
17606         (match_operand:SWI12 1 "memory_operand"))
17607    (parallel [(set (match_operand:SI 4 "register_operand")
17608                    (match_operator:SI 3 "plusminuslogic_operator"
17609                      [(match_dup 4)
17610                       (match_operand:SI 2 "nonmemory_operand")]))
17611               (clobber (reg:CC FLAGS_REG))])
17612    (set (match_dup 1) (match_dup 0))
17613    (set (reg FLAGS_REG) (compare (match_dup 0) (const_int 0)))]
17614   "(TARGET_READ_MODIFY_WRITE || optimize_insn_for_size_p ())
17615    && REG_P (operands[0]) && REG_P (operands[4])
17616    && REGNO (operands[0]) == REGNO (operands[4])
17617    && peep2_reg_dead_p (4, operands[0])
17618    && (<MODE>mode != QImode
17619        || immediate_operand (operands[2], SImode)
17620        || q_regs_operand (operands[2], SImode))
17621    && !reg_overlap_mentioned_p (operands[0], operands[1])
17622    && !reg_overlap_mentioned_p (operands[0], operands[2])
17623    && ix86_match_ccmode (peep2_next_insn (3),
17624                          (GET_CODE (operands[3]) == PLUS
17625                           || GET_CODE (operands[3]) == MINUS)
17626                          ? CCGOCmode : CCNOmode)"
17627   [(parallel [(set (match_dup 4) (match_dup 5))
17628               (set (match_dup 1) (match_dup 6))])]
17629 {
17630   operands[2] = gen_lowpart (<MODE>mode, operands[2]);
17631   operands[4] = SET_DEST (PATTERN (peep2_next_insn (3)));
17632   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), <MODE>mode,
17633                                 copy_rtx (operands[1]), operands[2]);
17634   operands[5] = gen_rtx_COMPARE (GET_MODE (operands[4]),
17635                                  operands[5], const0_rtx);
17636   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[3]), <MODE>mode,
17637                                 copy_rtx (operands[1]),
17638                                 copy_rtx (operands[2]));
17639 })
17640
17641 ;; Attempt to always use XOR for zeroing registers.
17642 (define_peephole2
17643   [(set (match_operand 0 "register_operand")
17644         (match_operand 1 "const0_operand"))]
17645   "GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
17646    && (! TARGET_USE_MOV0 || optimize_insn_for_size_p ())
17647    && GENERAL_REG_P (operands[0])
17648    && peep2_regno_dead_p (0, FLAGS_REG)"
17649   [(parallel [(set (match_dup 0) (const_int 0))
17650               (clobber (reg:CC FLAGS_REG))])]
17651   "operands[0] = gen_lowpart (word_mode, operands[0]);")
17652
17653 (define_peephole2
17654   [(set (strict_low_part (match_operand 0 "register_operand"))
17655         (const_int 0))]
17656   "(GET_MODE (operands[0]) == QImode
17657     || GET_MODE (operands[0]) == HImode)
17658    && (! TARGET_USE_MOV0 || optimize_insn_for_size_p ())
17659    && peep2_regno_dead_p (0, FLAGS_REG)"
17660   [(parallel [(set (strict_low_part (match_dup 0)) (const_int 0))
17661               (clobber (reg:CC FLAGS_REG))])])
17662
17663 ;; For HI, SI and DI modes, or $-1,reg is smaller than mov $-1,reg.
17664 (define_peephole2
17665   [(set (match_operand:SWI248 0 "register_operand")
17666         (const_int -1))]
17667   "(optimize_insn_for_size_p () || TARGET_MOVE_M1_VIA_OR)
17668    && peep2_regno_dead_p (0, FLAGS_REG)"
17669   [(parallel [(set (match_dup 0) (const_int -1))
17670               (clobber (reg:CC FLAGS_REG))])]
17671 {
17672   if (<MODE_SIZE> < GET_MODE_SIZE (SImode))
17673     operands[0] = gen_lowpart (SImode, operands[0]);
17674 })
17675
17676 ;; Attempt to convert simple lea to add/shift.
17677 ;; These can be created by move expanders.
17678 ;; Disable PLUS peepholes on TARGET_OPT_AGU, since all
17679 ;; relevant lea instructions were already split.
17680
17681 (define_peephole2
17682   [(set (match_operand:SWI48 0 "register_operand")
17683         (plus:SWI48 (match_dup 0)
17684                     (match_operand:SWI48 1 "<nonmemory_operand>")))]
17685   "!TARGET_OPT_AGU
17686    && peep2_regno_dead_p (0, FLAGS_REG)"
17687   [(parallel [(set (match_dup 0) (plus:SWI48 (match_dup 0) (match_dup 1)))
17688               (clobber (reg:CC FLAGS_REG))])])
17689
17690 (define_peephole2
17691   [(set (match_operand:SWI48 0 "register_operand")
17692         (plus:SWI48 (match_operand:SWI48 1 "<nonmemory_operand>")
17693                     (match_dup 0)))]
17694   "!TARGET_OPT_AGU
17695    && peep2_regno_dead_p (0, FLAGS_REG)"
17696   [(parallel [(set (match_dup 0) (plus:SWI48 (match_dup 0) (match_dup 1)))
17697               (clobber (reg:CC FLAGS_REG))])])
17698
17699 (define_peephole2
17700   [(set (match_operand:DI 0 "register_operand")
17701         (zero_extend:DI
17702           (plus:SI (match_operand:SI 1 "register_operand")
17703                    (match_operand:SI 2 "nonmemory_operand"))))]
17704   "TARGET_64BIT && !TARGET_OPT_AGU
17705    && REGNO (operands[0]) == REGNO (operands[1])
17706    && peep2_regno_dead_p (0, FLAGS_REG)"
17707   [(parallel [(set (match_dup 0)
17708                    (zero_extend:DI (plus:SI (match_dup 1) (match_dup 2))))
17709               (clobber (reg:CC FLAGS_REG))])])
17710
17711 (define_peephole2
17712   [(set (match_operand:DI 0 "register_operand")
17713         (zero_extend:DI
17714           (plus:SI (match_operand:SI 1 "nonmemory_operand")
17715                    (match_operand:SI 2 "register_operand"))))]
17716   "TARGET_64BIT && !TARGET_OPT_AGU
17717    && REGNO (operands[0]) == REGNO (operands[2])
17718    && peep2_regno_dead_p (0, FLAGS_REG)"
17719   [(parallel [(set (match_dup 0)
17720                    (zero_extend:DI (plus:SI (match_dup 2) (match_dup 1))))
17721               (clobber (reg:CC FLAGS_REG))])])
17722
17723 (define_peephole2
17724   [(set (match_operand:SWI48 0 "register_operand")
17725         (mult:SWI48 (match_dup 0)
17726                     (match_operand:SWI48 1 "const_int_operand")))]
17727   "exact_log2 (INTVAL (operands[1])) >= 0
17728    && peep2_regno_dead_p (0, FLAGS_REG)"
17729   [(parallel [(set (match_dup 0) (ashift:SWI48 (match_dup 0) (match_dup 1)))
17730               (clobber (reg:CC FLAGS_REG))])]
17731   "operands[1] = GEN_INT (exact_log2 (INTVAL (operands[1])));")
17732
17733 (define_peephole2
17734   [(set (match_operand:DI 0 "register_operand")
17735         (zero_extend:DI
17736           (mult:SI (match_operand:SI 1 "register_operand")
17737                    (match_operand:SI 2 "const_int_operand"))))]
17738   "TARGET_64BIT
17739    && exact_log2 (INTVAL (operands[2])) >= 0
17740    && REGNO (operands[0]) == REGNO (operands[1])
17741    && peep2_regno_dead_p (0, FLAGS_REG)"
17742   [(parallel [(set (match_dup 0)
17743                    (zero_extend:DI (ashift:SI (match_dup 1) (match_dup 2))))
17744               (clobber (reg:CC FLAGS_REG))])]
17745   "operands[2] = GEN_INT (exact_log2 (INTVAL (operands[2])));")
17746
17747 ;; The ESP adjustments can be done by the push and pop instructions.  Resulting
17748 ;; code is shorter, since push is only 1 byte, while add imm, %esp is 3 bytes.
17749 ;; On many CPUs it is also faster, since special hardware to avoid esp
17750 ;; dependencies is present.
17751
17752 ;; While some of these conversions may be done using splitters, we use
17753 ;; peepholes in order to allow combine_stack_adjustments pass to see
17754 ;; nonobfuscated RTL.
17755
17756 ;; Convert prologue esp subtractions to push.
17757 ;; We need register to push.  In order to keep verify_flow_info happy we have
17758 ;; two choices
17759 ;; - use scratch and clobber it in order to avoid dependencies
17760 ;; - use already live register
17761 ;; We can't use the second way right now, since there is no reliable way how to
17762 ;; verify that given register is live.  First choice will also most likely in
17763 ;; fewer dependencies.  On the place of esp adjustments it is very likely that
17764 ;; call clobbered registers are dead.  We may want to use base pointer as an
17765 ;; alternative when no register is available later.
17766
17767 (define_peephole2
17768   [(match_scratch:W 1 "r")
17769    (parallel [(set (reg:P SP_REG)
17770                    (plus:P (reg:P SP_REG)
17771                            (match_operand:P 0 "const_int_operand")))
17772               (clobber (reg:CC FLAGS_REG))
17773               (clobber (mem:BLK (scratch)))])]
17774   "(TARGET_SINGLE_PUSH || optimize_insn_for_size_p ())
17775    && INTVAL (operands[0]) == -GET_MODE_SIZE (word_mode)"
17776   [(clobber (match_dup 1))
17777    (parallel [(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
17778               (clobber (mem:BLK (scratch)))])])
17779
17780 (define_peephole2
17781   [(match_scratch:W 1 "r")
17782    (parallel [(set (reg:P SP_REG)
17783                    (plus:P (reg:P SP_REG)
17784                            (match_operand:P 0 "const_int_operand")))
17785               (clobber (reg:CC FLAGS_REG))
17786               (clobber (mem:BLK (scratch)))])]
17787   "(TARGET_DOUBLE_PUSH || optimize_insn_for_size_p ())
17788    && INTVAL (operands[0]) == -2*GET_MODE_SIZE (word_mode)"
17789   [(clobber (match_dup 1))
17790    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
17791    (parallel [(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
17792               (clobber (mem:BLK (scratch)))])])
17793
17794 ;; Convert esp subtractions to push.
17795 (define_peephole2
17796   [(match_scratch:W 1 "r")
17797    (parallel [(set (reg:P SP_REG)
17798                    (plus:P (reg:P SP_REG)
17799                            (match_operand:P 0 "const_int_operand")))
17800               (clobber (reg:CC FLAGS_REG))])]
17801   "(TARGET_SINGLE_PUSH || optimize_insn_for_size_p ())
17802    && INTVAL (operands[0]) == -GET_MODE_SIZE (word_mode)"
17803   [(clobber (match_dup 1))
17804    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))])
17805
17806 (define_peephole2
17807   [(match_scratch:W 1 "r")
17808    (parallel [(set (reg:P SP_REG)
17809                    (plus:P (reg:P SP_REG)
17810                            (match_operand:P 0 "const_int_operand")))
17811               (clobber (reg:CC FLAGS_REG))])]
17812   "(TARGET_DOUBLE_PUSH || optimize_insn_for_size_p ())
17813    && INTVAL (operands[0]) == -2*GET_MODE_SIZE (word_mode)"
17814   [(clobber (match_dup 1))
17815    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
17816    (set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))])
17817
17818 ;; Convert epilogue deallocator to pop.
17819 (define_peephole2
17820   [(match_scratch:W 1 "r")
17821    (parallel [(set (reg:P SP_REG)
17822                    (plus:P (reg:P SP_REG)
17823                            (match_operand:P 0 "const_int_operand")))
17824               (clobber (reg:CC FLAGS_REG))
17825               (clobber (mem:BLK (scratch)))])]
17826   "(TARGET_SINGLE_POP || optimize_insn_for_size_p ())
17827    && INTVAL (operands[0]) == GET_MODE_SIZE (word_mode)"
17828   [(parallel [(set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))
17829               (clobber (mem:BLK (scratch)))])])
17830
17831 ;; Two pops case is tricky, since pop causes dependency
17832 ;; on destination register.  We use two registers if available.
17833 (define_peephole2
17834   [(match_scratch:W 1 "r")
17835    (match_scratch:W 2 "r")
17836    (parallel [(set (reg:P SP_REG)
17837                    (plus:P (reg:P SP_REG)
17838                            (match_operand:P 0 "const_int_operand")))
17839               (clobber (reg:CC FLAGS_REG))
17840               (clobber (mem:BLK (scratch)))])]
17841   "(TARGET_DOUBLE_POP || optimize_insn_for_size_p ())
17842    && INTVAL (operands[0]) == 2*GET_MODE_SIZE (word_mode)"
17843   [(parallel [(set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))
17844               (clobber (mem:BLK (scratch)))])
17845    (set (match_dup 2) (mem:W (post_inc:P (reg:P SP_REG))))])
17846
17847 (define_peephole2
17848   [(match_scratch:W 1 "r")
17849    (parallel [(set (reg:P SP_REG)
17850                    (plus:P (reg:P SP_REG)
17851                            (match_operand:P 0 "const_int_operand")))
17852               (clobber (reg:CC FLAGS_REG))
17853               (clobber (mem:BLK (scratch)))])]
17854   "optimize_insn_for_size_p ()
17855    && INTVAL (operands[0]) == 2*GET_MODE_SIZE (word_mode)"
17856   [(parallel [(set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))
17857               (clobber (mem:BLK (scratch)))])
17858    (set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))])
17859
17860 ;; Convert esp additions to pop.
17861 (define_peephole2
17862   [(match_scratch:W 1 "r")
17863    (parallel [(set (reg:P SP_REG)
17864                    (plus:P (reg:P SP_REG)
17865                            (match_operand:P 0 "const_int_operand")))
17866               (clobber (reg:CC FLAGS_REG))])]
17867   "INTVAL (operands[0]) == GET_MODE_SIZE (word_mode)"
17868   [(set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))])
17869
17870 ;; Two pops case is tricky, since pop causes dependency
17871 ;; on destination register.  We use two registers if available.
17872 (define_peephole2
17873   [(match_scratch:W 1 "r")
17874    (match_scratch:W 2 "r")
17875    (parallel [(set (reg:P SP_REG)
17876                    (plus:P (reg:P SP_REG)
17877                            (match_operand:P 0 "const_int_operand")))
17878               (clobber (reg:CC FLAGS_REG))])]
17879   "INTVAL (operands[0]) == 2*GET_MODE_SIZE (word_mode)"
17880   [(set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))
17881    (set (match_dup 2) (mem:W (post_inc:P (reg:P SP_REG))))])
17882
17883 (define_peephole2
17884   [(match_scratch:W 1 "r")
17885    (parallel [(set (reg:P SP_REG)
17886                    (plus:P (reg:P SP_REG)
17887                            (match_operand:P 0 "const_int_operand")))
17888               (clobber (reg:CC FLAGS_REG))])]
17889   "optimize_insn_for_size_p ()
17890    && INTVAL (operands[0]) == 2*GET_MODE_SIZE (word_mode)"
17891   [(set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))
17892    (set (match_dup 1) (mem:W (post_inc:P (reg:P SP_REG))))])
17893 \f
17894 ;; Convert compares with 1 to shorter inc/dec operations when CF is not
17895 ;; required and register dies.  Similarly for 128 to -128.
17896 (define_peephole2
17897   [(set (match_operand 0 "flags_reg_operand")
17898         (match_operator 1 "compare_operator"
17899           [(match_operand 2 "register_operand")
17900            (match_operand 3 "const_int_operand")]))]
17901   "(((!TARGET_FUSE_CMP_AND_BRANCH || optimize_insn_for_size_p ())
17902      && incdec_operand (operands[3], GET_MODE (operands[3])))
17903     || (!TARGET_FUSE_CMP_AND_BRANCH
17904         && INTVAL (operands[3]) == 128))
17905    && ix86_match_ccmode (insn, CCGCmode)
17906    && peep2_reg_dead_p (1, operands[2])"
17907   [(parallel [(set (match_dup 0)
17908                    (match_op_dup 1 [(match_dup 2) (match_dup 3)]))
17909               (clobber (match_dup 2))])])
17910 \f
17911 ;; Convert imul by three, five and nine into lea
17912 (define_peephole2
17913   [(parallel
17914     [(set (match_operand:SWI48 0 "register_operand")
17915           (mult:SWI48 (match_operand:SWI48 1 "register_operand")
17916                       (match_operand:SWI48 2 "const359_operand")))
17917      (clobber (reg:CC FLAGS_REG))])]
17918   "!TARGET_PARTIAL_REG_STALL
17919    || <MODE>mode == SImode
17920    || optimize_function_for_size_p (cfun)"
17921   [(set (match_dup 0)
17922         (plus:SWI48 (mult:SWI48 (match_dup 1) (match_dup 2))
17923                     (match_dup 1)))]
17924   "operands[2] = GEN_INT (INTVAL (operands[2]) - 1);")
17925
17926 (define_peephole2
17927   [(parallel
17928     [(set (match_operand:SWI48 0 "register_operand")
17929           (mult:SWI48 (match_operand:SWI48 1 "nonimmediate_operand")
17930                       (match_operand:SWI48 2 "const359_operand")))
17931      (clobber (reg:CC FLAGS_REG))])]
17932   "optimize_insn_for_speed_p ()
17933    && (!TARGET_PARTIAL_REG_STALL || <MODE>mode == SImode)"
17934   [(set (match_dup 0) (match_dup 1))
17935    (set (match_dup 0)
17936         (plus:SWI48 (mult:SWI48 (match_dup 0) (match_dup 2))
17937                     (match_dup 0)))]
17938   "operands[2] = GEN_INT (INTVAL (operands[2]) - 1);")
17939
17940 ;; imul $32bit_imm, mem, reg is vector decoded, while
17941 ;; imul $32bit_imm, reg, reg is direct decoded.
17942 (define_peephole2
17943   [(match_scratch:SWI48 3 "r")
17944    (parallel [(set (match_operand:SWI48 0 "register_operand")
17945                    (mult:SWI48 (match_operand:SWI48 1 "memory_operand")
17946                                (match_operand:SWI48 2 "immediate_operand")))
17947               (clobber (reg:CC FLAGS_REG))])]
17948   "TARGET_SLOW_IMUL_IMM32_MEM && optimize_insn_for_speed_p ()
17949    && !satisfies_constraint_K (operands[2])"
17950   [(set (match_dup 3) (match_dup 1))
17951    (parallel [(set (match_dup 0) (mult:SWI48 (match_dup 3) (match_dup 2)))
17952               (clobber (reg:CC FLAGS_REG))])])
17953
17954 (define_peephole2
17955   [(match_scratch:SI 3 "r")
17956    (parallel [(set (match_operand:DI 0 "register_operand")
17957                    (zero_extend:DI
17958                      (mult:SI (match_operand:SI 1 "memory_operand")
17959                               (match_operand:SI 2 "immediate_operand"))))
17960               (clobber (reg:CC FLAGS_REG))])]
17961   "TARGET_64BIT
17962    && TARGET_SLOW_IMUL_IMM32_MEM && optimize_insn_for_speed_p ()
17963    && !satisfies_constraint_K (operands[2])"
17964   [(set (match_dup 3) (match_dup 1))
17965    (parallel [(set (match_dup 0)
17966                    (zero_extend:DI (mult:SI (match_dup 3) (match_dup 2))))
17967               (clobber (reg:CC FLAGS_REG))])])
17968
17969 ;; imul $8/16bit_imm, regmem, reg is vector decoded.
17970 ;; Convert it into imul reg, reg
17971 ;; It would be better to force assembler to encode instruction using long
17972 ;; immediate, but there is apparently no way to do so.
17973 (define_peephole2
17974   [(parallel [(set (match_operand:SWI248 0 "register_operand")
17975                    (mult:SWI248
17976                     (match_operand:SWI248 1 "nonimmediate_operand")
17977                     (match_operand:SWI248 2 "const_int_operand")))
17978               (clobber (reg:CC FLAGS_REG))])
17979    (match_scratch:SWI248 3 "r")]
17980   "TARGET_SLOW_IMUL_IMM8 && optimize_insn_for_speed_p ()
17981    && satisfies_constraint_K (operands[2])"
17982   [(set (match_dup 3) (match_dup 2))
17983    (parallel [(set (match_dup 0) (mult:SWI248 (match_dup 0) (match_dup 3)))
17984               (clobber (reg:CC FLAGS_REG))])]
17985 {
17986   if (!rtx_equal_p (operands[0], operands[1]))
17987     emit_move_insn (operands[0], operands[1]);
17988 })
17989
17990 ;; After splitting up read-modify operations, array accesses with memory
17991 ;; operands might end up in form:
17992 ;;  sall    $2, %eax
17993 ;;  movl    4(%esp), %edx
17994 ;;  addl    %edx, %eax
17995 ;; instead of pre-splitting:
17996 ;;  sall    $2, %eax
17997 ;;  addl    4(%esp), %eax
17998 ;; Turn it into:
17999 ;;  movl    4(%esp), %edx
18000 ;;  leal    (%edx,%eax,4), %eax
18001
18002 (define_peephole2
18003   [(match_scratch:W 5 "r")
18004    (parallel [(set (match_operand 0 "register_operand")
18005                    (ashift (match_operand 1 "register_operand")
18006                            (match_operand 2 "const_int_operand")))
18007                (clobber (reg:CC FLAGS_REG))])
18008    (parallel [(set (match_operand 3 "register_operand")
18009                    (plus (match_dup 0)
18010                          (match_operand 4 "x86_64_general_operand")))
18011                    (clobber (reg:CC FLAGS_REG))])]
18012   "IN_RANGE (INTVAL (operands[2]), 1, 3)
18013    /* Validate MODE for lea.  */
18014    && ((!TARGET_PARTIAL_REG_STALL
18015         && (GET_MODE (operands[0]) == QImode
18016             || GET_MODE (operands[0]) == HImode))
18017        || GET_MODE (operands[0]) == SImode
18018        || (TARGET_64BIT && GET_MODE (operands[0]) == DImode))
18019    && (rtx_equal_p (operands[0], operands[3])
18020        || peep2_reg_dead_p (2, operands[0]))
18021    /* We reorder load and the shift.  */
18022    && !reg_overlap_mentioned_p (operands[0], operands[4])"
18023   [(set (match_dup 5) (match_dup 4))
18024    (set (match_dup 0) (match_dup 1))]
18025 {
18026   machine_mode op1mode = GET_MODE (operands[1]);
18027   machine_mode mode = op1mode == DImode ? DImode : SImode;
18028   int scale = 1 << INTVAL (operands[2]);
18029   rtx index = gen_lowpart (word_mode, operands[1]);
18030   rtx base = gen_lowpart (word_mode, operands[5]);
18031   rtx dest = gen_lowpart (mode, operands[3]);
18032
18033   operands[1] = gen_rtx_PLUS (word_mode, base,
18034                               gen_rtx_MULT (word_mode, index, GEN_INT (scale)));
18035   operands[5] = base;
18036   if (mode != word_mode)
18037     operands[1] = gen_rtx_SUBREG (mode, operands[1], 0);
18038   if (op1mode != word_mode)
18039     operands[5] = gen_rtx_SUBREG (op1mode, operands[5], 0);
18040   operands[0] = dest;
18041 })
18042 \f
18043 ;; We used to use "int $5", in honor of #BR which maps to interrupt vector 5.
18044 ;; That, however, is usually mapped by the OS to SIGSEGV, which is often
18045 ;; caught for use by garbage collectors and the like.  Using an insn that
18046 ;; maps to SIGILL makes it more likely the program will rightfully die.
18047 ;; Keeping with tradition, "6" is in honor of #UD.
18048 (define_insn "trap"
18049   [(trap_if (const_int 1) (const_int 6))]
18050   ""
18051 {
18052 #ifdef HAVE_AS_IX86_UD2
18053   return "ud2";
18054 #else
18055   return ASM_SHORT "0x0b0f";
18056 #endif
18057 }
18058   [(set_attr "length" "2")])
18059
18060 (define_expand "prefetch"
18061   [(prefetch (match_operand 0 "address_operand")
18062              (match_operand:SI 1 "const_int_operand")
18063              (match_operand:SI 2 "const_int_operand"))]
18064   "TARGET_PREFETCH_SSE || TARGET_PRFCHW || TARGET_PREFETCHWT1"
18065 {
18066   bool write = INTVAL (operands[1]) != 0;
18067   int locality = INTVAL (operands[2]);
18068
18069   gcc_assert (IN_RANGE (locality, 0, 3));
18070
18071   /* Use 3dNOW prefetch in case we are asking for write prefetch not
18072      supported by SSE counterpart or the SSE prefetch is not available
18073      (K6 machines).  Otherwise use SSE prefetch as it allows specifying
18074      of locality.  */
18075   if (TARGET_PREFETCHWT1 && write && locality <= 2)
18076     operands[2] = const2_rtx;
18077   else if (TARGET_PRFCHW && (write || !TARGET_PREFETCH_SSE))
18078     operands[2] = GEN_INT (3);
18079   else
18080     operands[1] = const0_rtx;
18081 })
18082
18083 (define_insn "*prefetch_sse"
18084   [(prefetch (match_operand 0 "address_operand" "p")
18085              (const_int 0)
18086              (match_operand:SI 1 "const_int_operand"))]
18087   "TARGET_PREFETCH_SSE"
18088 {
18089   static const char * const patterns[4] = {
18090    "prefetchnta\t%a0", "prefetcht2\t%a0", "prefetcht1\t%a0", "prefetcht0\t%a0"
18091   };
18092
18093   int locality = INTVAL (operands[1]);
18094   gcc_assert (IN_RANGE (locality, 0, 3));
18095
18096   return patterns[locality];
18097 }
18098   [(set_attr "type" "sse")
18099    (set_attr "atom_sse_attr" "prefetch")
18100    (set (attr "length_address")
18101         (symbol_ref "memory_address_length (operands[0], false)"))
18102    (set_attr "memory" "none")])
18103
18104 (define_insn "*prefetch_3dnow"
18105   [(prefetch (match_operand 0 "address_operand" "p")
18106              (match_operand:SI 1 "const_int_operand" "n")
18107              (const_int 3))]
18108   "TARGET_PRFCHW"
18109 {
18110   if (INTVAL (operands[1]) == 0)
18111     return "prefetch\t%a0";
18112   else
18113     return "prefetchw\t%a0";
18114 }
18115   [(set_attr "type" "mmx")
18116    (set (attr "length_address")
18117         (symbol_ref "memory_address_length (operands[0], false)"))
18118    (set_attr "memory" "none")])
18119
18120 (define_insn "*prefetch_prefetchwt1"
18121   [(prefetch (match_operand 0 "address_operand" "p")
18122              (const_int 1)
18123              (const_int 2))]
18124   "TARGET_PREFETCHWT1"
18125   "prefetchwt1\t%a0";
18126   [(set_attr "type" "sse")
18127    (set (attr "length_address")
18128         (symbol_ref "memory_address_length (operands[0], false)"))
18129    (set_attr "memory" "none")])
18130
18131 (define_expand "stack_protect_set"
18132   [(match_operand 0 "memory_operand")
18133    (match_operand 1 "memory_operand")]
18134   "TARGET_SSP_TLS_GUARD"
18135 {
18136   rtx (*insn)(rtx, rtx);
18137
18138 #ifdef TARGET_THREAD_SSP_OFFSET
18139   operands[1] = GEN_INT (TARGET_THREAD_SSP_OFFSET);
18140   insn = (TARGET_LP64
18141           ? gen_stack_tls_protect_set_di
18142           : gen_stack_tls_protect_set_si);
18143 #else
18144   insn = (TARGET_LP64
18145           ? gen_stack_protect_set_di
18146           : gen_stack_protect_set_si);
18147 #endif
18148
18149   emit_insn (insn (operands[0], operands[1]));
18150   DONE;
18151 })
18152
18153 (define_insn "stack_protect_set_<mode>"
18154   [(set (match_operand:PTR 0 "memory_operand" "=m")
18155         (unspec:PTR [(match_operand:PTR 1 "memory_operand" "m")]
18156                     UNSPEC_SP_SET))
18157    (set (match_scratch:PTR 2 "=&r") (const_int 0))
18158    (clobber (reg:CC FLAGS_REG))]
18159   "TARGET_SSP_TLS_GUARD"
18160   "mov{<imodesuffix>}\t{%1, %2|%2, %1}\;mov{<imodesuffix>}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2"
18161   [(set_attr "type" "multi")])
18162
18163 (define_insn "stack_tls_protect_set_<mode>"
18164   [(set (match_operand:PTR 0 "memory_operand" "=m")
18165         (unspec:PTR [(match_operand:PTR 1 "const_int_operand" "i")]
18166                     UNSPEC_SP_TLS_SET))
18167    (set (match_scratch:PTR 2 "=&r") (const_int 0))
18168    (clobber (reg:CC FLAGS_REG))]
18169   ""
18170   "mov{<imodesuffix>}\t{%@:%P1, %2|%2, <iptrsize> PTR %@:%P1}\;mov{<imodesuffix>}\t{%2, %0|%0, %2}\;xor{l}\t%k2, %k2"
18171   [(set_attr "type" "multi")])
18172
18173 (define_expand "stack_protect_test"
18174   [(match_operand 0 "memory_operand")
18175    (match_operand 1 "memory_operand")
18176    (match_operand 2)]
18177   "TARGET_SSP_TLS_GUARD"
18178 {
18179   rtx flags = gen_rtx_REG (CCZmode, FLAGS_REG);
18180
18181   rtx (*insn)(rtx, rtx, rtx);
18182
18183 #ifdef TARGET_THREAD_SSP_OFFSET
18184   operands[1] = GEN_INT (TARGET_THREAD_SSP_OFFSET);
18185   insn = (TARGET_LP64
18186           ? gen_stack_tls_protect_test_di
18187           : gen_stack_tls_protect_test_si);
18188 #else
18189   insn = (TARGET_LP64
18190           ? gen_stack_protect_test_di
18191           : gen_stack_protect_test_si);
18192 #endif
18193
18194   emit_insn (insn (flags, operands[0], operands[1]));
18195
18196   emit_jump_insn (gen_cbranchcc4 (gen_rtx_EQ (VOIDmode, flags, const0_rtx),
18197                                   flags, const0_rtx, operands[2]));
18198   DONE;
18199 })
18200
18201 (define_insn "stack_protect_test_<mode>"
18202   [(set (match_operand:CCZ 0 "flags_reg_operand")
18203         (unspec:CCZ [(match_operand:PTR 1 "memory_operand" "m")
18204                      (match_operand:PTR 2 "memory_operand" "m")]
18205                     UNSPEC_SP_TEST))
18206    (clobber (match_scratch:PTR 3 "=&r"))]
18207   "TARGET_SSP_TLS_GUARD"
18208   "mov{<imodesuffix>}\t{%1, %3|%3, %1}\;xor{<imodesuffix>}\t{%2, %3|%3, %2}"
18209   [(set_attr "type" "multi")])
18210
18211 (define_insn "stack_tls_protect_test_<mode>"
18212   [(set (match_operand:CCZ 0 "flags_reg_operand")
18213         (unspec:CCZ [(match_operand:PTR 1 "memory_operand" "m")
18214                      (match_operand:PTR 2 "const_int_operand" "i")]
18215                     UNSPEC_SP_TLS_TEST))
18216    (clobber (match_scratch:PTR 3 "=r"))]
18217   ""
18218   "mov{<imodesuffix>}\t{%1, %3|%3, %1}\;xor{<imodesuffix>}\t{%@:%P2, %3|%3, <iptrsize> PTR %@:%P2}"
18219   [(set_attr "type" "multi")])
18220
18221 (define_insn "sse4_2_crc32<mode>"
18222   [(set (match_operand:SI 0 "register_operand" "=r")
18223         (unspec:SI
18224           [(match_operand:SI 1 "register_operand" "0")
18225            (match_operand:SWI124 2 "nonimmediate_operand" "<r>m")]
18226           UNSPEC_CRC32))]
18227   "TARGET_SSE4_2 || TARGET_CRC32"
18228   "crc32{<imodesuffix>}\t{%2, %0|%0, %2}"
18229   [(set_attr "type" "sselog1")
18230    (set_attr "prefix_rep" "1")
18231    (set_attr "prefix_extra" "1")
18232    (set (attr "prefix_data16")
18233      (if_then_else (match_operand:HI 2)
18234        (const_string "1")
18235        (const_string "*")))
18236    (set (attr "prefix_rex")
18237      (if_then_else (match_operand:QI 2 "ext_QIreg_operand")
18238        (const_string "1")
18239        (const_string "*")))
18240    (set_attr "mode" "SI")])
18241
18242 (define_insn "sse4_2_crc32di"
18243   [(set (match_operand:DI 0 "register_operand" "=r")
18244         (unspec:DI
18245           [(match_operand:DI 1 "register_operand" "0")
18246            (match_operand:DI 2 "nonimmediate_operand" "rm")]
18247           UNSPEC_CRC32))]
18248   "TARGET_64BIT && (TARGET_SSE4_2 || TARGET_CRC32)"
18249   "crc32{q}\t{%2, %0|%0, %2}"
18250   [(set_attr "type" "sselog1")
18251    (set_attr "prefix_rep" "1")
18252    (set_attr "prefix_extra" "1")
18253    (set_attr "mode" "DI")])
18254
18255 (define_insn "rdpmc"
18256   [(set (match_operand:DI 0 "register_operand" "=A")
18257         (unspec_volatile:DI [(match_operand:SI 1 "register_operand" "c")]
18258                             UNSPECV_RDPMC))]
18259   "!TARGET_64BIT"
18260   "rdpmc"
18261   [(set_attr "type" "other")
18262    (set_attr "length" "2")])
18263
18264 (define_insn "rdpmc_rex64"
18265   [(set (match_operand:DI 0 "register_operand" "=a")
18266         (unspec_volatile:DI [(match_operand:SI 2 "register_operand" "c")]
18267                             UNSPECV_RDPMC))
18268    (set (match_operand:DI 1 "register_operand" "=d")
18269         (unspec_volatile:DI [(match_dup 2)] UNSPECV_RDPMC))]
18270   "TARGET_64BIT"
18271   "rdpmc"
18272   [(set_attr "type" "other")
18273    (set_attr "length" "2")])
18274
18275 (define_insn "rdtsc"
18276   [(set (match_operand:DI 0 "register_operand" "=A")
18277         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSC))]
18278   "!TARGET_64BIT"
18279   "rdtsc"
18280   [(set_attr "type" "other")
18281    (set_attr "length" "2")])
18282
18283 (define_insn "rdtsc_rex64"
18284   [(set (match_operand:DI 0 "register_operand" "=a")
18285         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSC))
18286    (set (match_operand:DI 1 "register_operand" "=d")
18287         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSC))]
18288   "TARGET_64BIT"
18289   "rdtsc"
18290   [(set_attr "type" "other")
18291    (set_attr "length" "2")])
18292
18293 (define_insn "rdtscp"
18294   [(set (match_operand:DI 0 "register_operand" "=A")
18295         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSCP))
18296    (set (match_operand:SI 1 "register_operand" "=c")
18297         (unspec_volatile:SI [(const_int 0)] UNSPECV_RDTSCP))]
18298   "!TARGET_64BIT"
18299   "rdtscp"
18300   [(set_attr "type" "other")
18301    (set_attr "length" "3")])
18302
18303 (define_insn "rdtscp_rex64"
18304   [(set (match_operand:DI 0 "register_operand" "=a")
18305         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSCP))
18306    (set (match_operand:DI 1 "register_operand" "=d")
18307         (unspec_volatile:DI [(const_int 0)] UNSPECV_RDTSCP))
18308    (set (match_operand:SI 2 "register_operand" "=c")
18309         (unspec_volatile:SI [(const_int 0)] UNSPECV_RDTSCP))]
18310   "TARGET_64BIT"
18311   "rdtscp"
18312   [(set_attr "type" "other")
18313    (set_attr "length" "3")])
18314
18315 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18316 ;;
18317 ;; FXSR, XSAVE and XSAVEOPT instructions
18318 ;;
18319 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18320
18321 (define_insn "fxsave"
18322   [(set (match_operand:BLK 0 "memory_operand" "=m")
18323         (unspec_volatile:BLK [(const_int 0)] UNSPECV_FXSAVE))]
18324   "TARGET_FXSR"
18325   "fxsave\t%0"
18326   [(set_attr "type" "other")
18327    (set_attr "memory" "store")
18328    (set (attr "length")
18329         (symbol_ref "ix86_attr_length_address_default (insn) + 3"))])
18330
18331 (define_insn "fxsave64"
18332   [(set (match_operand:BLK 0 "memory_operand" "=m")
18333         (unspec_volatile:BLK [(const_int 0)] UNSPECV_FXSAVE64))]
18334   "TARGET_64BIT && TARGET_FXSR"
18335   "fxsave64\t%0"
18336   [(set_attr "type" "other")
18337    (set_attr "memory" "store")
18338    (set (attr "length")
18339         (symbol_ref "ix86_attr_length_address_default (insn) + 4"))])
18340
18341 (define_insn "fxrstor"
18342   [(unspec_volatile [(match_operand:BLK 0 "memory_operand" "m")]
18343                     UNSPECV_FXRSTOR)]
18344   "TARGET_FXSR"
18345   "fxrstor\t%0"
18346   [(set_attr "type" "other")
18347    (set_attr "memory" "load")
18348    (set (attr "length")
18349         (symbol_ref "ix86_attr_length_address_default (insn) + 3"))])
18350
18351 (define_insn "fxrstor64"
18352   [(unspec_volatile [(match_operand:BLK 0 "memory_operand" "m")]
18353                     UNSPECV_FXRSTOR64)]
18354   "TARGET_64BIT && TARGET_FXSR"
18355   "fxrstor64\t%0"
18356   [(set_attr "type" "other")
18357    (set_attr "memory" "load")
18358    (set (attr "length")
18359         (symbol_ref "ix86_attr_length_address_default (insn) + 4"))])
18360
18361 (define_int_iterator ANY_XSAVE
18362         [UNSPECV_XSAVE
18363          (UNSPECV_XSAVEOPT "TARGET_XSAVEOPT")
18364          (UNSPECV_XSAVEC "TARGET_XSAVEC")
18365          (UNSPECV_XSAVES "TARGET_XSAVES")])
18366
18367 (define_int_iterator ANY_XSAVE64
18368         [UNSPECV_XSAVE64
18369          (UNSPECV_XSAVEOPT64 "TARGET_XSAVEOPT")
18370          (UNSPECV_XSAVEC64 "TARGET_XSAVEC")
18371          (UNSPECV_XSAVES64 "TARGET_XSAVES")])
18372
18373 (define_int_attr xsave
18374         [(UNSPECV_XSAVE "xsave")
18375          (UNSPECV_XSAVE64 "xsave64")
18376          (UNSPECV_XSAVEOPT "xsaveopt")
18377          (UNSPECV_XSAVEOPT64 "xsaveopt64")
18378          (UNSPECV_XSAVEC "xsavec")
18379          (UNSPECV_XSAVEC64 "xsavec64")
18380          (UNSPECV_XSAVES "xsaves")
18381          (UNSPECV_XSAVES64 "xsaves64")])
18382
18383 (define_int_iterator ANY_XRSTOR
18384         [UNSPECV_XRSTOR
18385          (UNSPECV_XRSTORS "TARGET_XSAVES")])
18386
18387 (define_int_iterator ANY_XRSTOR64
18388         [UNSPECV_XRSTOR64
18389          (UNSPECV_XRSTORS64 "TARGET_XSAVES")])
18390
18391 (define_int_attr xrstor
18392         [(UNSPECV_XRSTOR "xrstor")
18393          (UNSPECV_XRSTOR64 "xrstor")
18394          (UNSPECV_XRSTORS "xrstors")
18395          (UNSPECV_XRSTORS64 "xrstors")])
18396
18397 (define_insn "<xsave>"
18398   [(set (match_operand:BLK 0 "memory_operand" "=m")
18399         (unspec_volatile:BLK
18400          [(match_operand:DI 1 "register_operand" "A")]
18401          ANY_XSAVE))]
18402   "!TARGET_64BIT && TARGET_XSAVE"
18403   "<xsave>\t%0"
18404   [(set_attr "type" "other")
18405    (set_attr "memory" "store")
18406    (set (attr "length")
18407         (symbol_ref "ix86_attr_length_address_default (insn) + 3"))])
18408
18409 (define_insn "<xsave>_rex64"
18410   [(set (match_operand:BLK 0 "memory_operand" "=m")
18411         (unspec_volatile:BLK
18412          [(match_operand:SI 1 "register_operand" "a")
18413           (match_operand:SI 2 "register_operand" "d")]
18414          ANY_XSAVE))]
18415   "TARGET_64BIT && TARGET_XSAVE"
18416   "<xsave>\t%0"
18417   [(set_attr "type" "other")
18418    (set_attr "memory" "store")
18419    (set (attr "length")
18420         (symbol_ref "ix86_attr_length_address_default (insn) + 3"))])
18421
18422 (define_insn "<xsave>"
18423   [(set (match_operand:BLK 0 "memory_operand" "=m")
18424         (unspec_volatile:BLK
18425          [(match_operand:SI 1 "register_operand" "a")
18426           (match_operand:SI 2 "register_operand" "d")]
18427          ANY_XSAVE64))]
18428   "TARGET_64BIT && TARGET_XSAVE"
18429   "<xsave>\t%0"
18430   [(set_attr "type" "other")
18431    (set_attr "memory" "store")
18432    (set (attr "length")
18433         (symbol_ref "ix86_attr_length_address_default (insn) + 4"))])
18434
18435 (define_insn "<xrstor>"
18436    [(unspec_volatile:BLK
18437      [(match_operand:BLK 0 "memory_operand" "m")
18438       (match_operand:DI 1 "register_operand" "A")]
18439      ANY_XRSTOR)]
18440   "!TARGET_64BIT && TARGET_XSAVE"
18441   "<xrstor>\t%0"
18442   [(set_attr "type" "other")
18443    (set_attr "memory" "load")
18444    (set (attr "length")
18445         (symbol_ref "ix86_attr_length_address_default (insn) + 3"))])
18446
18447 (define_insn "<xrstor>_rex64"
18448    [(unspec_volatile:BLK
18449      [(match_operand:BLK 0 "memory_operand" "m")
18450       (match_operand:SI 1 "register_operand" "a")
18451       (match_operand:SI 2 "register_operand" "d")]
18452      ANY_XRSTOR)]
18453   "TARGET_64BIT && TARGET_XSAVE"
18454   "<xrstor>\t%0"
18455   [(set_attr "type" "other")
18456    (set_attr "memory" "load")
18457    (set (attr "length")
18458         (symbol_ref "ix86_attr_length_address_default (insn) + 3"))])
18459
18460 (define_insn "<xrstor>64"
18461    [(unspec_volatile:BLK
18462      [(match_operand:BLK 0 "memory_operand" "m")
18463       (match_operand:SI 1 "register_operand" "a")
18464       (match_operand:SI 2 "register_operand" "d")]
18465      ANY_XRSTOR64)]
18466   "TARGET_64BIT && TARGET_XSAVE"
18467   "<xrstor>64\t%0"
18468   [(set_attr "type" "other")
18469    (set_attr "memory" "load")
18470    (set (attr "length")
18471         (symbol_ref "ix86_attr_length_address_default (insn) + 4"))])
18472
18473 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18474 ;;
18475 ;; Floating-point instructions for atomic compound assignments
18476 ;;
18477 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18478
18479 ; Clobber all floating-point registers on environment save and restore
18480 ; to ensure that the TOS value saved at fnstenv is valid after fldenv.
18481 (define_insn "fnstenv"
18482   [(set (match_operand:BLK 0 "memory_operand" "=m")
18483         (unspec_volatile:BLK [(const_int 0)] UNSPECV_FNSTENV))
18484    (clobber (reg:HI FPCR_REG))
18485    (clobber (reg:XF ST0_REG))
18486    (clobber (reg:XF ST1_REG))
18487    (clobber (reg:XF ST2_REG))
18488    (clobber (reg:XF ST3_REG))
18489    (clobber (reg:XF ST4_REG))
18490    (clobber (reg:XF ST5_REG))
18491    (clobber (reg:XF ST6_REG))
18492    (clobber (reg:XF ST7_REG))]
18493   "TARGET_80387"
18494   "fnstenv\t%0"
18495   [(set_attr "type" "other")
18496    (set_attr "memory" "store")
18497    (set (attr "length")
18498         (symbol_ref "ix86_attr_length_address_default (insn) + 2"))])
18499
18500 (define_insn "fldenv"
18501   [(unspec_volatile [(match_operand:BLK 0 "memory_operand" "m")]
18502                     UNSPECV_FLDENV)
18503    (clobber (reg:CCFP FPSR_REG))
18504    (clobber (reg:HI FPCR_REG))
18505    (clobber (reg:XF ST0_REG))
18506    (clobber (reg:XF ST1_REG))
18507    (clobber (reg:XF ST2_REG))
18508    (clobber (reg:XF ST3_REG))
18509    (clobber (reg:XF ST4_REG))
18510    (clobber (reg:XF ST5_REG))
18511    (clobber (reg:XF ST6_REG))
18512    (clobber (reg:XF ST7_REG))]
18513   "TARGET_80387"
18514   "fldenv\t%0"
18515   [(set_attr "type" "other")
18516    (set_attr "memory" "load")
18517    (set (attr "length")
18518         (symbol_ref "ix86_attr_length_address_default (insn) + 2"))])
18519
18520 (define_insn "fnstsw"
18521   [(set (match_operand:HI 0 "nonimmediate_operand" "=a,m")
18522         (unspec_volatile:HI [(const_int 0)] UNSPECV_FNSTSW))]
18523   "TARGET_80387"
18524   "fnstsw\t%0"
18525   [(set_attr "type" "other,other")
18526    (set_attr "memory" "none,store")
18527    (set (attr "length")
18528         (symbol_ref "ix86_attr_length_address_default (insn) + 2"))])
18529
18530 (define_insn "fnclex"
18531   [(unspec_volatile [(const_int 0)] UNSPECV_FNCLEX)]
18532   "TARGET_80387"
18533   "fnclex"
18534   [(set_attr "type" "other")
18535    (set_attr "memory" "none")
18536    (set_attr "length" "2")])
18537
18538 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18539 ;;
18540 ;; LWP instructions
18541 ;;
18542 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18543
18544 (define_expand "lwp_llwpcb"
18545   [(unspec_volatile [(match_operand 0 "register_operand" "r")]
18546                     UNSPECV_LLWP_INTRINSIC)]
18547   "TARGET_LWP")
18548
18549 (define_insn "*lwp_llwpcb<mode>1"
18550   [(unspec_volatile [(match_operand:P 0 "register_operand" "r")]
18551                     UNSPECV_LLWP_INTRINSIC)]
18552   "TARGET_LWP"
18553   "llwpcb\t%0"
18554   [(set_attr "type" "lwp")
18555    (set_attr "mode" "<MODE>")
18556    (set_attr "length" "5")])
18557
18558 (define_expand "lwp_slwpcb"
18559   [(set (match_operand 0 "register_operand" "=r")
18560         (unspec_volatile [(const_int 0)] UNSPECV_SLWP_INTRINSIC))]
18561   "TARGET_LWP"
18562 {
18563   rtx (*insn)(rtx);
18564
18565   insn = (Pmode == DImode
18566           ? gen_lwp_slwpcbdi
18567           : gen_lwp_slwpcbsi);
18568
18569   emit_insn (insn (operands[0]));
18570   DONE;
18571 })
18572
18573 (define_insn "lwp_slwpcb<mode>"
18574   [(set (match_operand:P 0 "register_operand" "=r")
18575         (unspec_volatile:P [(const_int 0)] UNSPECV_SLWP_INTRINSIC))]
18576   "TARGET_LWP"
18577   "slwpcb\t%0"
18578   [(set_attr "type" "lwp")
18579    (set_attr "mode" "<MODE>")
18580    (set_attr "length" "5")])
18581
18582 (define_expand "lwp_lwpval<mode>3"
18583   [(unspec_volatile [(match_operand:SWI48 1 "register_operand" "r")
18584                      (match_operand:SI 2 "nonimmediate_operand" "rm")
18585                      (match_operand:SI 3 "const_int_operand" "i")]
18586                     UNSPECV_LWPVAL_INTRINSIC)]
18587   "TARGET_LWP"
18588   ;; Avoid unused variable warning.
18589   "(void) operands[0];")
18590
18591 (define_insn "*lwp_lwpval<mode>3_1"
18592   [(unspec_volatile [(match_operand:SWI48 0 "register_operand" "r")
18593                      (match_operand:SI 1 "nonimmediate_operand" "rm")
18594                      (match_operand:SI 2 "const_int_operand" "i")]
18595                     UNSPECV_LWPVAL_INTRINSIC)]
18596   "TARGET_LWP"
18597   "lwpval\t{%2, %1, %0|%0, %1, %2}"
18598   [(set_attr "type" "lwp")
18599    (set_attr "mode" "<MODE>")
18600    (set (attr "length")
18601         (symbol_ref "ix86_attr_length_address_default (insn) + 9"))])
18602
18603 (define_expand "lwp_lwpins<mode>3"
18604   [(set (reg:CCC FLAGS_REG)
18605         (unspec_volatile:CCC [(match_operand:SWI48 1 "register_operand" "r")
18606                               (match_operand:SI 2 "nonimmediate_operand" "rm")
18607                               (match_operand:SI 3 "const_int_operand" "i")]
18608                              UNSPECV_LWPINS_INTRINSIC))
18609    (set (match_operand:QI 0 "nonimmediate_operand" "=qm")
18610         (eq:QI (reg:CCC FLAGS_REG) (const_int 0)))]
18611   "TARGET_LWP")
18612
18613 (define_insn "*lwp_lwpins<mode>3_1"
18614   [(set (reg:CCC FLAGS_REG)
18615         (unspec_volatile:CCC [(match_operand:SWI48 0 "register_operand" "r")
18616                               (match_operand:SI 1 "nonimmediate_operand" "rm")
18617                               (match_operand:SI 2 "const_int_operand" "i")]
18618                              UNSPECV_LWPINS_INTRINSIC))]
18619   "TARGET_LWP"
18620   "lwpins\t{%2, %1, %0|%0, %1, %2}"
18621   [(set_attr "type" "lwp")
18622    (set_attr "mode" "<MODE>")
18623    (set (attr "length")
18624         (symbol_ref "ix86_attr_length_address_default (insn) + 9"))])
18625
18626 (define_int_iterator RDFSGSBASE
18627         [UNSPECV_RDFSBASE
18628          UNSPECV_RDGSBASE])
18629
18630 (define_int_iterator WRFSGSBASE
18631         [UNSPECV_WRFSBASE
18632          UNSPECV_WRGSBASE])
18633
18634 (define_int_attr fsgs
18635         [(UNSPECV_RDFSBASE "fs")
18636          (UNSPECV_RDGSBASE "gs")
18637          (UNSPECV_WRFSBASE "fs")
18638          (UNSPECV_WRGSBASE "gs")])
18639
18640 (define_insn "rd<fsgs>base<mode>"
18641   [(set (match_operand:SWI48 0 "register_operand" "=r")
18642         (unspec_volatile:SWI48 [(const_int 0)] RDFSGSBASE))]
18643   "TARGET_64BIT && TARGET_FSGSBASE"
18644   "rd<fsgs>base\t%0"
18645   [(set_attr "type" "other")
18646    (set_attr "prefix_extra" "2")])
18647
18648 (define_insn "wr<fsgs>base<mode>"
18649   [(unspec_volatile [(match_operand:SWI48 0 "register_operand" "r")]
18650                     WRFSGSBASE)]
18651   "TARGET_64BIT && TARGET_FSGSBASE"
18652   "wr<fsgs>base\t%0"
18653   [(set_attr "type" "other")
18654    (set_attr "prefix_extra" "2")])
18655
18656 (define_insn "rdrand<mode>_1"
18657   [(set (match_operand:SWI248 0 "register_operand" "=r")
18658         (unspec_volatile:SWI248 [(const_int 0)] UNSPECV_RDRAND))
18659    (set (reg:CCC FLAGS_REG)
18660         (unspec_volatile:CCC [(const_int 0)] UNSPECV_RDRAND))]
18661   "TARGET_RDRND"
18662   "rdrand\t%0"
18663   [(set_attr "type" "other")
18664    (set_attr "prefix_extra" "1")])
18665
18666 (define_insn "rdseed<mode>_1"
18667   [(set (match_operand:SWI248 0 "register_operand" "=r")
18668         (unspec_volatile:SWI248 [(const_int 0)] UNSPECV_RDSEED))
18669    (set (reg:CCC FLAGS_REG)
18670         (unspec_volatile:CCC [(const_int 0)] UNSPECV_RDSEED))]
18671   "TARGET_RDSEED"
18672   "rdseed\t%0"
18673   [(set_attr "type" "other")
18674    (set_attr "prefix_extra" "1")])
18675
18676 (define_expand "pause"
18677   [(set (match_dup 0)
18678         (unspec:BLK [(match_dup 0)] UNSPEC_PAUSE))]
18679   ""
18680 {
18681   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
18682   MEM_VOLATILE_P (operands[0]) = 1;
18683 })
18684
18685 ;; Use "rep; nop", instead of "pause", to support older assemblers.
18686 ;; They have the same encoding.
18687 (define_insn "*pause"
18688   [(set (match_operand:BLK 0)
18689         (unspec:BLK [(match_dup 0)] UNSPEC_PAUSE))]
18690   ""
18691   "rep%; nop"
18692   [(set_attr "length" "2")
18693    (set_attr "memory" "unknown")])
18694
18695 (define_expand "xbegin"
18696   [(set (match_operand:SI 0 "register_operand")
18697         (unspec_volatile:SI [(const_int 0)] UNSPECV_XBEGIN))]
18698   "TARGET_RTM"
18699 {
18700   rtx_code_label *label = gen_label_rtx ();
18701
18702   /* xbegin is emitted as jump_insn, so reload won't be able
18703      to reload its operand.  Force the value into AX hard register.  */
18704   rtx ax_reg = gen_rtx_REG (SImode, AX_REG);
18705   emit_move_insn (ax_reg, constm1_rtx);
18706
18707   emit_jump_insn (gen_xbegin_1 (ax_reg, label));
18708
18709   emit_label (label);
18710   LABEL_NUSES (label) = 1;
18711
18712   emit_move_insn (operands[0], ax_reg);
18713
18714   DONE;
18715 })
18716
18717 (define_insn "xbegin_1"
18718   [(set (pc)
18719         (if_then_else (ne (unspec [(const_int 0)] UNSPEC_XBEGIN_ABORT)
18720                           (const_int 0))
18721                       (label_ref (match_operand 1))
18722                       (pc)))
18723    (set (match_operand:SI 0 "register_operand" "+a")
18724         (unspec_volatile:SI [(match_dup 0)] UNSPECV_XBEGIN))]
18725   "TARGET_RTM"
18726   "xbegin\t%l1"
18727   [(set_attr "type" "other")
18728    (set_attr "length" "6")])
18729
18730 (define_insn "xend"
18731   [(unspec_volatile [(const_int 0)] UNSPECV_XEND)]
18732   "TARGET_RTM"
18733   "xend"
18734   [(set_attr "type" "other")
18735    (set_attr "length" "3")])
18736
18737 (define_insn "xabort"
18738   [(unspec_volatile [(match_operand:SI 0 "const_0_to_255_operand" "n")]
18739                     UNSPECV_XABORT)]
18740   "TARGET_RTM"
18741   "xabort\t%0"
18742   [(set_attr "type" "other")
18743    (set_attr "length" "3")])
18744
18745 (define_expand "xtest"
18746   [(set (match_operand:QI 0 "register_operand")
18747         (unspec_volatile:QI [(const_int 0)] UNSPECV_XTEST))]
18748   "TARGET_RTM"
18749 {
18750   emit_insn (gen_xtest_1 ());
18751
18752   ix86_expand_setcc (operands[0], NE,
18753                      gen_rtx_REG (CCZmode, FLAGS_REG), const0_rtx);
18754   DONE;
18755 })
18756
18757 (define_insn "xtest_1"
18758   [(set (reg:CCZ FLAGS_REG)
18759         (unspec_volatile:CCZ [(const_int 0)] UNSPECV_XTEST))]
18760   "TARGET_RTM"
18761   "xtest"
18762   [(set_attr "type" "other")
18763    (set_attr "length" "3")])
18764
18765 (define_insn "pcommit"
18766   [(unspec_volatile [(const_int 0)] UNSPECV_PCOMMIT)]
18767   "TARGET_PCOMMIT"
18768   "pcommit"
18769   [(set_attr "type" "other")
18770    (set_attr "length" "4")])
18771
18772 (define_insn "clwb"
18773   [(unspec_volatile [(match_operand 0 "address_operand" "p")]
18774                    UNSPECV_CLWB)]
18775   "TARGET_CLWB"
18776   "clwb\t%a0"
18777   [(set_attr "type" "sse")
18778    (set_attr "atom_sse_attr" "fence")
18779    (set_attr "memory" "unknown")])
18780
18781 (define_insn "clflushopt"
18782   [(unspec_volatile [(match_operand 0 "address_operand" "p")]
18783                    UNSPECV_CLFLUSHOPT)]
18784   "TARGET_CLFLUSHOPT"
18785   "clflushopt\t%a0"
18786   [(set_attr "type" "sse")
18787    (set_attr "atom_sse_attr" "fence")
18788    (set_attr "memory" "unknown")])
18789
18790 ;; MPX instructions
18791
18792 (define_expand "<mode>_mk"
18793   [(set (match_operand:BND 0 "register_operand")
18794     (unspec:BND
18795       [(mem:<bnd_ptr>
18796        (match_par_dup 3
18797         [(match_operand:<bnd_ptr> 1 "register_operand")
18798          (match_operand:<bnd_ptr> 2 "address_mpx_no_base_operand")]))]
18799       UNSPEC_BNDMK))]
18800   "TARGET_MPX"
18801 {
18802   operands[3] = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, operands[1],
18803                                                   operands[2]),
18804                                 UNSPEC_BNDMK_ADDR);
18805 })
18806
18807 (define_insn "*<mode>_mk"
18808   [(set (match_operand:BND 0 "register_operand" "=w")
18809     (unspec:BND
18810       [(match_operator:<bnd_ptr> 3 "bnd_mem_operator"
18811         [(unspec:<bnd_ptr>
18812            [(match_operand:<bnd_ptr> 1 "register_operand" "r")
18813             (match_operand:<bnd_ptr> 2 "address_mpx_no_base_operand" "Tb")]
18814            UNSPEC_BNDMK_ADDR)])]
18815       UNSPEC_BNDMK))]
18816   "TARGET_MPX"
18817   "bndmk\t{%3, %0|%0, %3}"
18818   [(set_attr "type" "mpxmk")])
18819
18820 (define_expand "mov<mode>"
18821   [(set (match_operand:BND 0 "general_operand")
18822         (match_operand:BND 1 "general_operand"))]
18823   "TARGET_MPX"
18824 {
18825   ix86_expand_move (<MODE>mode, operands);DONE;
18826 })
18827
18828 (define_insn "*mov<mode>_internal_mpx"
18829   [(set (match_operand:BND 0 "nonimmediate_operand" "=w,m")
18830         (match_operand:BND 1 "general_operand" "wm,w"))]
18831   "TARGET_MPX"
18832   "bndmov\t{%1, %0|%0, %1}"
18833   [(set_attr "type" "mpxmov")])
18834
18835 (define_expand "<mode>_<bndcheck>"
18836   [(parallel [(unspec [(match_operand:BND 0 "register_operand")
18837                        (match_operand:<bnd_ptr> 1 "address_no_seg_operand")] BNDCHECK)
18838               (set (match_dup 2)
18839                    (unspec:BLK [(match_dup 2)] UNSPEC_MPX_FENCE))])]
18840   "TARGET_MPX"
18841 {
18842   operands[2] = gen_rtx_MEM (BLKmode, operands[1]);
18843   MEM_VOLATILE_P (operands[2]) = 1;
18844 })
18845
18846 (define_insn "*<mode>_<bndcheck>"
18847   [(parallel [(unspec [(match_operand:BND 0 "register_operand" "w")
18848                        (match_operand:<bnd_ptr> 1 "address_no_seg_operand" "Ts")] BNDCHECK)
18849               (set (match_operand:BLK 2 "bnd_mem_operator")
18850                    (unspec:BLK [(match_dup 2)] UNSPEC_MPX_FENCE))])]
18851   "TARGET_MPX"
18852   "bnd<bndcheck>\t{%a1, %0|%0, %a1}"
18853   [(set_attr "type" "mpxchk")])
18854
18855 (define_expand "<mode>_ldx"
18856   [(parallel [(set:BND (match_operand:BND 0 "register_operand")
18857                        (unspec:BND
18858                          [(mem:<bnd_ptr>
18859                            (match_par_dup 3
18860                              [(match_operand:<bnd_ptr> 1 "address_mpx_no_index_operand")
18861                               (match_operand:<bnd_ptr> 2 "register_operand")]))]
18862                          UNSPEC_BNDLDX))
18863               (use (mem:BLK (match_dup 1)))])]
18864   "TARGET_MPX"
18865 {
18866   /* Avoid registers which connot be used as index.  */
18867   if (!index_register_operand (operands[2], Pmode))
18868     {
18869       rtx temp = gen_reg_rtx (Pmode);
18870       emit_move_insn (temp, operands[2]);
18871       operands[2] = temp;
18872     }
18873
18874   /* If it was a register originally then it may have
18875      mode other than Pmode.  We need to extend in such
18876      case because bndldx may work only with Pmode regs.  */
18877   if (GET_MODE (operands[2]) != Pmode)
18878     operands[2] = ix86_zero_extend_to_Pmode (operands[2]);
18879
18880   operands[3] = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, operands[1],
18881                                                   operands[2]),
18882                                 UNSPEC_BNDLDX_ADDR);
18883 })
18884
18885 (define_insn "*<mode>_ldx"
18886   [(parallel [(set:BND (match_operand:BND 0 "register_operand" "=w")
18887                        (unspec:BND
18888                          [(match_operator:<bnd_ptr> 3 "bnd_mem_operator"
18889                            [(unspec:<bnd_ptr>
18890                              [(match_operand:<bnd_ptr> 1 "address_mpx_no_index_operand" "Ti")
18891                               (match_operand:<bnd_ptr> 2 "register_operand" "l")]
18892                             UNSPEC_BNDLDX_ADDR)])]
18893                          UNSPEC_BNDLDX))
18894               (use (mem:BLK (match_dup 1)))])]
18895   "TARGET_MPX"
18896   "bndldx\t{%3, %0|%0, %3}"
18897   [(set_attr "type" "mpxld")])
18898
18899 (define_expand "<mode>_stx"
18900   [(parallel [(unspec [(mem:<bnd_ptr>
18901                          (match_par_dup 3
18902                            [(match_operand:<bnd_ptr> 0 "address_mpx_no_index_operand")
18903                             (match_operand:<bnd_ptr> 1 "register_operand")]))
18904                        (match_operand:BND 2 "register_operand")] UNSPEC_BNDSTX)
18905               (set (match_dup 4)
18906                    (unspec:BLK [(match_dup 4)] UNSPEC_MPX_FENCE))])]
18907   "TARGET_MPX"
18908 {
18909   /* Avoid registers which connot be used as index.  */
18910   if (!index_register_operand (operands[1], Pmode))
18911     {
18912       rtx temp = gen_reg_rtx (Pmode);
18913       emit_move_insn (temp, operands[1]);
18914       operands[1] = temp;
18915     }
18916
18917   /* If it was a register originally then it may have
18918      mode other than Pmode.  We need to extend in such
18919      case because bndstx may work only with Pmode regs.  */
18920   if (GET_MODE (operands[1]) != Pmode)
18921     operands[1] = ix86_zero_extend_to_Pmode (operands[1]);
18922
18923   operands[3] = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, operands[0],
18924                                                   operands[1]),
18925                                 UNSPEC_BNDLDX_ADDR);
18926   operands[4] = gen_rtx_MEM (BLKmode, operands[0]);
18927   MEM_VOLATILE_P (operands[4]) = 1;
18928 })
18929
18930 (define_insn "*<mode>_stx"
18931   [(parallel [(unspec [(match_operator:<bnd_ptr> 3 "bnd_mem_operator"
18932                          [(unspec:<bnd_ptr>
18933                           [(match_operand:<bnd_ptr> 0 "address_mpx_no_index_operand" "Ti")
18934                            (match_operand:<bnd_ptr> 1 "register_operand" "l")]
18935                          UNSPEC_BNDLDX_ADDR)])
18936                        (match_operand:BND 2 "register_operand" "w")] UNSPEC_BNDSTX)
18937               (set (match_operand:BLK 4 "bnd_mem_operator")
18938                    (unspec:BLK [(match_dup 4)] UNSPEC_MPX_FENCE))])]
18939   "TARGET_MPX"
18940   "bndstx\t{%2, %3|%3, %2}"
18941   [(set_attr "type" "mpxst")])
18942
18943 (define_insn "move_size_reloc_<mode>"
18944   [(set (match_operand:SWI48 0 "register_operand" "=r")
18945        (unspec:SWI48
18946         [(match_operand:SWI48 1 "symbol_operand")]
18947         UNSPEC_SIZEOF))]
18948   "TARGET_MPX"
18949 {
18950   if (x86_64_immediate_size_operand (operands[1], VOIDmode))
18951     return "mov{l}\t{%1@SIZE, %k0|%k0, %1@SIZE}";
18952   else
18953     return "movabs{q}\t{%1@SIZE, %0|%0, %1@SIZE}";
18954 }
18955   [(set_attr "type" "imov")
18956    (set_attr "mode" "<MODE>")])
18957
18958 (include "mmx.md")
18959 (include "sse.md")
18960 (include "sync.md")